Skip to content

Commit a1ef5ab

Browse files
committed
updates
1 parent 186c54f commit a1ef5ab

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

apps/sim/blocks/blocks/tinybird.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
8484
{
8585
id: 'wait',
8686
title: 'Wait for Acknowledgment',
87-
type: 'dropdown',
88-
options: [
89-
{ label: 'No (faster, default)', id: 'false' },
90-
{ label: 'Yes (safer retries)', id: 'true' },
91-
],
87+
type: 'switch',
9288
value: () => 'false',
89+
mode: 'advanced',
9390
condition: { field: 'operation', value: 'tinybird_events' },
9491
},
9592
// Query operation inputs
@@ -113,6 +110,45 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
113110
access: ['tinybird_events', 'tinybird_query'],
114111
config: {
115112
tool: (params) => params.operation || 'tinybird_events',
113+
params: (params) => {
114+
const operation = params.operation || 'tinybird_events'
115+
const result: Record<string, any> = {
116+
base_url: params.base_url,
117+
token: params.token,
118+
}
119+
120+
if (operation === 'tinybird_events') {
121+
// Send Events operation
122+
if (!params.datasource) {
123+
throw new Error('Data Source is required for Send Events operation')
124+
}
125+
if (!params.data) {
126+
throw new Error('Data is required for Send Events operation')
127+
}
128+
129+
result.datasource = params.datasource
130+
result.data = params.data
131+
result.format = params.format || 'ndjson'
132+
result.compression = params.compression || 'none'
133+
134+
// Convert wait from string to boolean
135+
if (params.wait !== undefined) {
136+
result.wait = params.wait === 'true' || params.wait === true || params.wait === 'True'
137+
}
138+
} else if (operation === 'tinybird_query') {
139+
// Query operation
140+
if (!params.query) {
141+
throw new Error('SQL Query is required for Query operation')
142+
}
143+
144+
result.query = params.query
145+
if (params.pipeline) {
146+
result.pipeline = params.pipeline
147+
}
148+
}
149+
150+
return result
151+
},
116152
},
117153
},
118154
inputs: {

apps/sim/tools/tinybird/events.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { gzipSync } from 'zlib'
12
import { createLogger } from '@sim/logger'
23
import type { TinybirdEventsParams, TinybirdEventsResponse } from '@/tools/tinybird/types'
34
import type { ToolConfig } from '@/tools/types'
@@ -8,7 +9,7 @@ export const eventsTool: ToolConfig<TinybirdEventsParams, TinybirdEventsResponse
89
id: 'tinybird_events',
910
name: 'Tinybird Events',
1011
description:
11-
'Send events to a Tinybird Data Source using the Events API. Supports JSON and NDJSON formats with optional compression.',
12+
'Send events to a Tinybird Data Source using the Events API. Supports JSON and NDJSON formats with optional gzip compression.',
1213
version: '1.0.0',
1314

1415
params: {
@@ -87,7 +88,13 @@ export const eventsTool: ToolConfig<TinybirdEventsParams, TinybirdEventsResponse
8788

8889
return headers
8990
},
90-
body: (params) => params.data,
91+
body: (params) => {
92+
const data = params.data
93+
if (params.compression === 'gzip') {
94+
return gzipSync(Buffer.from(data, 'utf-8'))
95+
}
96+
return data
97+
},
9198
},
9299

93100
transformResponse: async (response: Response) => {

0 commit comments

Comments
 (0)