|
| 1 | +import { TinybirdIcon } from '@/components/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | +import { AuthMode } from '@/blocks/types' |
| 4 | +import type { TinybirdResponse } from '@/tools/tinybird/types' |
| 5 | + |
| 6 | +export const TinybirdBlock: BlockConfig<TinybirdResponse> = { |
| 7 | + type: 'tinybird', |
| 8 | + name: 'Tinybird', |
| 9 | + description: 'Send events and query data with Tinybird', |
| 10 | + authMode: AuthMode.ApiKey, |
| 11 | + longDescription: |
| 12 | + 'Interact with Tinybird using the Events API to stream JSON or NDJSON events, or use the Query API to execute SQL queries against Pipes and Data Sources.', |
| 13 | + docsLink: 'https://www.tinybird.co/docs/api-reference', |
| 14 | + category: 'tools', |
| 15 | + bgColor: '#2EF598', |
| 16 | + icon: TinybirdIcon, |
| 17 | + subBlocks: [ |
| 18 | + { |
| 19 | + id: 'operation', |
| 20 | + title: 'Operation', |
| 21 | + type: 'dropdown', |
| 22 | + options: [ |
| 23 | + { label: 'Send Events', id: 'tinybird_events' }, |
| 24 | + { label: 'Query', id: 'tinybird_query' }, |
| 25 | + ], |
| 26 | + value: () => 'tinybird_events', |
| 27 | + }, |
| 28 | + { |
| 29 | + id: 'base_url', |
| 30 | + title: 'Base URL', |
| 31 | + type: 'short-input', |
| 32 | + placeholder: 'https://api.tinybird.co', |
| 33 | + required: true, |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 'token', |
| 37 | + title: 'API Token', |
| 38 | + type: 'short-input', |
| 39 | + placeholder: 'Enter your Tinybird API token', |
| 40 | + password: true, |
| 41 | + required: true, |
| 42 | + }, |
| 43 | + // Send Events operation inputs |
| 44 | + { |
| 45 | + id: 'datasource', |
| 46 | + title: 'Data Source', |
| 47 | + type: 'short-input', |
| 48 | + placeholder: 'my_events_datasource', |
| 49 | + condition: { field: 'operation', value: 'tinybird_events' }, |
| 50 | + required: true, |
| 51 | + }, |
| 52 | + { |
| 53 | + id: 'data', |
| 54 | + title: 'Data', |
| 55 | + type: 'long-input', |
| 56 | + placeholder: |
| 57 | + '{"event": "click", "timestamp": "2024-01-01T12:00:00Z"}\n{"event": "view", "timestamp": "2024-01-01T12:00:01Z"}', |
| 58 | + condition: { field: 'operation', value: 'tinybird_events' }, |
| 59 | + required: true, |
| 60 | + }, |
| 61 | + { |
| 62 | + id: 'format', |
| 63 | + title: 'Format', |
| 64 | + type: 'dropdown', |
| 65 | + options: [ |
| 66 | + { label: 'NDJSON (Newline-delimited JSON)', id: 'ndjson' }, |
| 67 | + { label: 'JSON', id: 'json' }, |
| 68 | + ], |
| 69 | + value: () => 'ndjson', |
| 70 | + condition: { field: 'operation', value: 'tinybird_events' }, |
| 71 | + }, |
| 72 | + { |
| 73 | + id: 'compression', |
| 74 | + title: 'Compression', |
| 75 | + type: 'dropdown', |
| 76 | + options: [ |
| 77 | + { label: 'None', id: 'none' }, |
| 78 | + { label: 'Gzip', id: 'gzip' }, |
| 79 | + ], |
| 80 | + value: () => 'none', |
| 81 | + mode: 'advanced', |
| 82 | + condition: { field: 'operation', value: 'tinybird_events' }, |
| 83 | + }, |
| 84 | + { |
| 85 | + id: 'wait', |
| 86 | + title: 'Wait for Acknowledgment', |
| 87 | + type: 'dropdown', |
| 88 | + options: [ |
| 89 | + { label: 'No (faster, default)', id: 'false' }, |
| 90 | + { label: 'Yes (safer retries)', id: 'true' }, |
| 91 | + ], |
| 92 | + value: () => 'false', |
| 93 | + condition: { field: 'operation', value: 'tinybird_events' }, |
| 94 | + }, |
| 95 | + // Query operation inputs |
| 96 | + { |
| 97 | + id: 'query', |
| 98 | + title: 'SQL Query', |
| 99 | + type: 'long-input', |
| 100 | + placeholder: 'SELECT * FROM my_pipe FORMAT JSON\nOR\nSELECT * FROM my_pipe FORMAT CSV', |
| 101 | + condition: { field: 'operation', value: 'tinybird_query' }, |
| 102 | + required: true, |
| 103 | + }, |
| 104 | + { |
| 105 | + id: 'pipeline', |
| 106 | + title: 'Pipeline Name', |
| 107 | + type: 'short-input', |
| 108 | + placeholder: 'my_pipe (optional)', |
| 109 | + condition: { field: 'operation', value: 'tinybird_query' }, |
| 110 | + }, |
| 111 | + ], |
| 112 | + tools: { |
| 113 | + access: ['tinybird_events', 'tinybird_query'], |
| 114 | + config: { |
| 115 | + tool: (params) => params.operation || 'tinybird_events', |
| 116 | + }, |
| 117 | + }, |
| 118 | + inputs: { |
| 119 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 120 | + base_url: { type: 'string', description: 'Tinybird API base URL' }, |
| 121 | + // Send Events inputs |
| 122 | + datasource: { |
| 123 | + type: 'string', |
| 124 | + description: 'Name of the Tinybird Data Source', |
| 125 | + }, |
| 126 | + data: { |
| 127 | + type: 'string', |
| 128 | + description: 'Data to send as JSON or NDJSON string', |
| 129 | + }, |
| 130 | + wait: { type: 'boolean', description: 'Wait for database acknowledgment' }, |
| 131 | + format: { |
| 132 | + type: 'string', |
| 133 | + description: 'Format of the events (ndjson or json)', |
| 134 | + }, |
| 135 | + compression: { |
| 136 | + type: 'string', |
| 137 | + description: 'Compression format (none or gzip)', |
| 138 | + }, |
| 139 | + // Query inputs |
| 140 | + query: { type: 'string', description: 'SQL query to execute' }, |
| 141 | + pipeline: { type: 'string', description: 'Optional pipeline name' }, |
| 142 | + // Common |
| 143 | + token: { type: 'string', description: 'Tinybird API Token' }, |
| 144 | + }, |
| 145 | + outputs: { |
| 146 | + // Send Events outputs |
| 147 | + successful_rows: { |
| 148 | + type: 'number', |
| 149 | + description: 'Number of rows successfully ingested', |
| 150 | + }, |
| 151 | + quarantined_rows: { |
| 152 | + type: 'number', |
| 153 | + description: 'Number of rows quarantined (failed validation)', |
| 154 | + }, |
| 155 | + // Query outputs |
| 156 | + data: { |
| 157 | + type: 'json', |
| 158 | + description: |
| 159 | + 'Query result data. FORMAT JSON: array of objects. Other formats (CSV, TSV, etc.): raw text string.', |
| 160 | + }, |
| 161 | + rows: { type: 'number', description: 'Number of rows returned (only with FORMAT JSON)' }, |
| 162 | + statistics: { |
| 163 | + type: 'json', |
| 164 | + description: |
| 165 | + 'Query execution statistics - elapsed time, rows read, bytes read (only with FORMAT JSON)', |
| 166 | + }, |
| 167 | + }, |
| 168 | +} |
0 commit comments