Skip to content

Commit 8c29fd2

Browse files
committed
feat(tinybird): validate integration against API, add job-status polling, scope block outputs
- Validated all 6 existing tools against Tinybird's live REST API docs - Added tinybird_get_job tool to poll async import/delete jobs - Scoped block outputs with per-operation condition
1 parent e5b9432 commit 8c29fd2

5 files changed

Lines changed: 327 additions & 15 deletions

File tree

apps/sim/blocks/blocks/tinybird.ts

Lines changed: 157 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
99
description: 'Send events, query data, and manage Data Sources with Tinybird',
1010
authMode: AuthMode.ApiKey,
1111
longDescription:
12-
'Interact with Tinybird: stream JSON or NDJSON events with the Events API, run SQL with the Query API, call published Pipe API Endpoints by name with dynamic parameters, and manage Data Sources by appending from a URL, truncating, or deleting rows by condition.',
12+
'Interact with Tinybird: stream JSON or NDJSON events with the Events API, run SQL with the Query API, call published Pipe API Endpoints by name with dynamic parameters, manage Data Sources by appending from a URL, truncating, or deleting rows by condition, and poll the status of asynchronous jobs.',
1313
docsLink: 'https://docs.sim.ai/integrations/tinybird',
1414
category: 'tools',
1515
integrationType: IntegrationType.Analytics,
@@ -27,6 +27,7 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
2727
{ label: 'Append Data Source (from URL)', id: 'tinybird_append_datasource' },
2828
{ label: 'Truncate Data Source', id: 'tinybird_truncate_datasource' },
2929
{ label: 'Delete Data Source Rows', id: 'tinybird_delete_datasource_rows' },
30+
{ label: 'Get Job Status', id: 'tinybird_get_job' },
3031
],
3132
value: () => 'tinybird_events',
3233
},
@@ -195,6 +196,15 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
195196
mode: 'advanced',
196197
condition: { field: 'operation', value: 'tinybird_delete_datasource_rows' },
197198
},
199+
// Get Job Status operation inputs
200+
{
201+
id: 'job_id',
202+
title: 'Job ID',
203+
type: 'short-input',
204+
placeholder: 'Job ID returned by an append or delete operation',
205+
condition: { field: 'operation', value: 'tinybird_get_job' },
206+
required: true,
207+
},
198208
],
199209
tools: {
200210
access: [
@@ -204,6 +214,7 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
204214
'tinybird_append_datasource',
205215
'tinybird_truncate_datasource',
206216
'tinybird_delete_datasource_rows',
217+
'tinybird_get_job',
207218
],
208219
config: {
209220
tool: (params) => params.operation || 'tinybird_events',
@@ -294,6 +305,13 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
294305
typeof params.dry_run === 'string' ? params.dry_run.toLowerCase() : params.dry_run
295306
result.dry_run = dryRunValue === 'true' || dryRunValue === true
296307
}
308+
} else if (operation === 'tinybird_get_job') {
309+
// Get Job Status operation
310+
if (!params.job_id) {
311+
throw new Error('Job ID is required for Get Job Status operation')
312+
}
313+
314+
result.job_id = params.job_id
297315
}
298316

299317
return result
@@ -334,6 +352,8 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
334352
// Delete Data Source Rows inputs
335353
delete_condition: { type: 'string', description: 'SQL condition selecting rows to delete' },
336354
dry_run: { type: 'boolean', description: 'Test the delete without removing data' },
355+
// Get Job Status inputs
356+
job_id: { type: 'string', description: 'ID of the job to check' },
337357
// Common
338358
token: { type: 'string', description: 'Tinybird API Token' },
339359
},
@@ -342,45 +362,160 @@ export const TinybirdBlock: BlockConfig<TinybirdResponse> = {
342362
successful_rows: {
343363
type: 'number',
344364
description: 'Number of rows successfully ingested',
365+
condition: { field: 'operation', value: 'tinybird_events' },
345366
},
346367
quarantined_rows: {
347368
type: 'number',
348369
description: 'Number of rows quarantined (failed validation)',
370+
condition: { field: 'operation', value: 'tinybird_events' },
349371
},
350-
// Query outputs
372+
// Query / Query Pipe outputs
351373
data: {
352374
type: 'json',
353375
description:
354376
'Query result data. FORMAT JSON: array of objects. Other formats (CSV, TSV, etc.): raw text string.',
377+
condition: { field: 'operation', value: ['tinybird_query', 'tinybird_query_pipe'] },
355378
},
356379
meta: {
357380
type: 'json',
358381
description: 'Column metadata for the result set: [{name, type}] (only with FORMAT JSON)',
382+
condition: { field: 'operation', value: ['tinybird_query', 'tinybird_query_pipe'] },
383+
},
384+
rows: {
385+
type: 'number',
386+
description: 'Number of rows returned (only with FORMAT JSON)',
387+
condition: { field: 'operation', value: ['tinybird_query', 'tinybird_query_pipe'] },
359388
},
360-
rows: { type: 'number', description: 'Number of rows returned (only with FORMAT JSON)' },
361389
rows_before_limit_at_least: {
362390
type: 'number',
363391
description: 'Minimum rows without a LIMIT clause (only with FORMAT JSON)',
392+
condition: { field: 'operation', value: ['tinybird_query', 'tinybird_query_pipe'] },
364393
},
365394
statistics: {
366395
type: 'json',
367396
description:
368397
'Query execution statistics - elapsed time, rows read, bytes read (only with FORMAT JSON)',
398+
condition: { field: 'operation', value: ['tinybird_query', 'tinybird_query_pipe'] },
399+
},
400+
// Data Source management outputs (append / truncate / delete / get job)
401+
id: {
402+
type: 'string',
403+
description: 'Operation identifier',
404+
condition: {
405+
field: 'operation',
406+
value: [
407+
'tinybird_append_datasource',
408+
'tinybird_delete_datasource_rows',
409+
'tinybird_get_job',
410+
],
411+
},
412+
},
413+
import_id: {
414+
type: 'string',
415+
description: 'Import identifier (append)',
416+
condition: { field: 'operation', value: 'tinybird_append_datasource' },
417+
},
418+
job_id: {
419+
type: 'string',
420+
description:
421+
'Job identifier to poll with the Get Job Status operation (append/delete/get job)',
422+
condition: {
423+
field: 'operation',
424+
value: [
425+
'tinybird_append_datasource',
426+
'tinybird_delete_datasource_rows',
427+
'tinybird_get_job',
428+
],
429+
},
430+
},
431+
delete_id: {
432+
type: 'string',
433+
description: 'Deletion identifier (delete)',
434+
condition: { field: 'operation', value: 'tinybird_delete_datasource_rows' },
435+
},
436+
job_url: {
437+
type: 'string',
438+
description: 'URL to query job status (append/delete/get job)',
439+
condition: {
440+
field: 'operation',
441+
value: [
442+
'tinybird_append_datasource',
443+
'tinybird_delete_datasource_rows',
444+
'tinybird_get_job',
445+
],
446+
},
447+
},
448+
status: {
449+
type: 'string',
450+
description: 'Current job status (append/delete/get job)',
451+
condition: {
452+
field: 'operation',
453+
value: [
454+
'tinybird_append_datasource',
455+
'tinybird_delete_datasource_rows',
456+
'tinybird_get_job',
457+
],
458+
},
369459
},
370-
// Data Source management outputs (append / truncate / delete)
371-
id: { type: 'string', description: 'Operation identifier (append/delete)' },
372-
import_id: { type: 'string', description: 'Import identifier (append)' },
373-
job_id: { type: 'string', description: 'Job identifier to poll status (append/delete)' },
374-
delete_id: { type: 'string', description: 'Deletion identifier (delete)' },
375-
job_url: { type: 'string', description: 'URL to query job status (append/delete)' },
376-
status: { type: 'string', description: 'Current job status (append/delete)' },
377460
job: {
378461
type: 'json',
379-
description: 'Full job details: kind, id, status, datasource, rows_affected (append/delete)',
462+
description:
463+
'Full job details: kind, id, status, datasource, rows_affected (append/delete/get job)',
464+
condition: {
465+
field: 'operation',
466+
value: [
467+
'tinybird_append_datasource',
468+
'tinybird_delete_datasource_rows',
469+
'tinybird_get_job',
470+
],
471+
},
472+
},
473+
datasource: {
474+
type: 'json',
475+
description: 'Target Data Source metadata (append)',
476+
condition: { field: 'operation', value: 'tinybird_append_datasource' },
477+
},
478+
truncated: {
479+
type: 'boolean',
480+
description: 'Whether the Data Source was truncated',
481+
condition: { field: 'operation', value: 'tinybird_truncate_datasource' },
482+
},
483+
result: {
484+
type: 'json',
485+
description: 'Raw truncate response body, if any',
486+
condition: { field: 'operation', value: 'tinybird_truncate_datasource' },
487+
},
488+
// Get Job Status outputs
489+
kind: {
490+
type: 'string',
491+
description: 'Job kind (e.g., "import", "delete_data", "populateview", "copy")',
492+
condition: { field: 'operation', value: 'tinybird_get_job' },
493+
},
494+
created_at: {
495+
type: 'string',
496+
description: 'Timestamp the job was created',
497+
condition: { field: 'operation', value: 'tinybird_get_job' },
498+
},
499+
started_at: {
500+
type: 'string',
501+
description: 'Timestamp the job started running',
502+
condition: { field: 'operation', value: 'tinybird_get_job' },
503+
},
504+
updated_at: {
505+
type: 'string',
506+
description: 'Timestamp of the last job status update',
507+
condition: { field: 'operation', value: 'tinybird_get_job' },
508+
},
509+
is_cancellable: {
510+
type: 'boolean',
511+
description: 'Whether the job can still be cancelled',
512+
condition: { field: 'operation', value: 'tinybird_get_job' },
513+
},
514+
error: {
515+
type: 'string',
516+
description: 'Error message, present only when the job status is "error"',
517+
condition: { field: 'operation', value: 'tinybird_get_job' },
380518
},
381-
datasource: { type: 'json', description: 'Target Data Source metadata (append)' },
382-
truncated: { type: 'boolean', description: 'Whether the Data Source was truncated' },
383-
result: { type: 'json', description: 'Raw truncate response body, if any' },
384519
},
385520
}
386521

@@ -484,7 +619,14 @@ export const TinybirdBlockMeta = {
484619
description:
485620
'Append from a URL, truncate, or delete rows by condition in a Tinybird Data Source.',
486621
content:
487-
"# Manage Tinybird Data Source Rows\n\nMaintain a Data Source by loading, clearing, or pruning its rows.\n\n## Steps\n1. To load data, use Append Data Source (from URL) with the Data Source name, a Source File URL, and the source format (CSV, NDJSON, or Parquet).\n2. To clear everything, use Truncate Data Source with the Data Source name.\n3. To remove specific rows, use Delete Data Source Rows with a SQL Delete Condition such as event_date < '2024-01-01'.\n4. Enable Dry Run on a delete first to preview how many rows would be removed.\n\n## Output\nReturn the job ID and status for append and delete operations so you can poll for completion, or confirm the truncate succeeded.",
622+
"# Manage Tinybird Data Source Rows\n\nMaintain a Data Source by loading, clearing, or pruning its rows.\n\n## Steps\n1. To load data, use Append Data Source (from URL) with the Data Source name, a Source File URL, and the source format (CSV, NDJSON, or Parquet).\n2. To clear everything, use Truncate Data Source with the Data Source name.\n3. To remove specific rows, use Delete Data Source Rows with a SQL Delete Condition such as event_date < '2024-01-01'.\n4. Enable Dry Run on a delete first to preview how many rows would be removed.\n\n## Output\nReturn the job ID and status for append and delete operations so you can poll with Get Job Status, or confirm the truncate succeeded.",
623+
},
624+
{
625+
name: 'poll-job-status',
626+
description:
627+
'Check the status of an asynchronous Tinybird job, such as an append import or a delete-by-condition job.',
628+
content:
629+
'# Poll a Tinybird Job\n\nAppend Data Source and Delete Data Source Rows start asynchronous jobs that need to be polled for completion.\n\n## Steps\n1. Take the Job ID returned by Append Data Source or Delete Data Source Rows.\n2. Use the Get Job Status operation with the Base URL, API Token, and Job ID.\n3. Loop or wait until status is "done" (or "error"), checking again on a delay if still "waiting" or "working".\n\n## Output\nReturn the job kind, status, and full job details so you can confirm completion or surface the error message.',
488630
},
489631
],
490632
} as const satisfies BlockMeta

apps/sim/tools/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,6 +3961,7 @@ import {
39613961
tinybirdAppendDatasourceTool,
39623962
tinybirdDeleteDatasourceRowsTool,
39633963
tinybirdEventsTool,
3964+
tinybirdGetJobTool,
39643965
tinybirdQueryPipeTool,
39653966
tinybirdQueryTool,
39663967
tinybirdTruncateDatasourceTool,
@@ -7009,6 +7010,7 @@ export const tools: Record<string, ToolConfig> = {
70097010
tinybird_append_datasource: tinybirdAppendDatasourceTool,
70107011
tinybird_truncate_datasource: tinybirdTruncateDatasourceTool,
70117012
tinybird_delete_datasource_rows: tinybirdDeleteDatasourceRowsTool,
7013+
tinybird_get_job: tinybirdGetJobTool,
70127014
stagehand_extract: stagehandExtractTool,
70137015
stagehand_agent: stagehandAgentTool,
70147016
mem0_add_memories: mem0AddMemoriesTool,

0 commit comments

Comments
 (0)