|
| 1 | +import { Library } from '@/components/emcn/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | + |
| 4 | +export const LogsBlock: BlockConfig = { |
| 5 | + type: 'logs', |
| 6 | + name: 'Logs', |
| 7 | + description: 'Query workflow execution logs', |
| 8 | + longDescription: |
| 9 | + 'Search workflow execution logs in the current workspace, fetch a single log by id, or load full execution details with the per-block state snapshot.', |
| 10 | + bgColor: '#EAB308', |
| 11 | + bestPractices: ` |
| 12 | + - The block always operates on the current workspace; you cannot query other workspaces. |
| 13 | + - 'Query Logs' returns summary rows. To get a full log entry (executionData, files), use 'Get Log by ID' on a row's id. |
| 14 | + - Use 'Get Execution Details' (with an executionId) to inspect per-block state for a single run. |
| 15 | + - Pagination is cursor-based: pass the previous response's nextCursor as Cursor to fetch the next page. |
| 16 | + `, |
| 17 | + icon: Library, |
| 18 | + category: 'blocks', |
| 19 | + docsLink: 'https://docs.sim.ai/api-reference/logs/getExecutionDetails', |
| 20 | + subBlocks: [ |
| 21 | + { |
| 22 | + id: 'operation', |
| 23 | + title: 'Operation', |
| 24 | + type: 'dropdown', |
| 25 | + options: [ |
| 26 | + { label: 'Query Logs', id: 'query' }, |
| 27 | + { label: 'Get Log by ID', id: 'get_log' }, |
| 28 | + { label: 'Get Execution Details', id: 'get_execution' }, |
| 29 | + ], |
| 30 | + placeholder: 'Select operation', |
| 31 | + value: () => 'query', |
| 32 | + }, |
| 33 | + { |
| 34 | + id: 'workflowIds', |
| 35 | + title: 'Workflow IDs', |
| 36 | + type: 'short-input', |
| 37 | + placeholder: 'Comma-separated workflow IDs', |
| 38 | + condition: { field: 'operation', value: 'query' }, |
| 39 | + }, |
| 40 | + { |
| 41 | + id: 'executionId', |
| 42 | + title: 'Execution ID', |
| 43 | + type: 'short-input', |
| 44 | + placeholder: 'Filter by a single execution ID', |
| 45 | + condition: { field: 'operation', value: 'query' }, |
| 46 | + }, |
| 47 | + { |
| 48 | + id: 'level', |
| 49 | + title: 'Level', |
| 50 | + type: 'dropdown', |
| 51 | + options: [ |
| 52 | + { label: 'All', id: 'all' }, |
| 53 | + { label: 'Info', id: 'info' }, |
| 54 | + { label: 'Error', id: 'error' }, |
| 55 | + { label: 'Running', id: 'running' }, |
| 56 | + { label: 'Pending', id: 'pending' }, |
| 57 | + ], |
| 58 | + value: () => 'all', |
| 59 | + condition: { field: 'operation', value: 'query' }, |
| 60 | + }, |
| 61 | + { |
| 62 | + id: 'triggers', |
| 63 | + title: 'Triggers', |
| 64 | + type: 'short-input', |
| 65 | + placeholder: 'api,webhook,schedule,manual,chat,mothership', |
| 66 | + condition: { field: 'operation', value: 'query' }, |
| 67 | + }, |
| 68 | + { |
| 69 | + id: 'limit', |
| 70 | + title: 'Limit', |
| 71 | + type: 'short-input', |
| 72 | + placeholder: '100 (max 200)', |
| 73 | + condition: { field: 'operation', value: 'query' }, |
| 74 | + }, |
| 75 | + { |
| 76 | + id: 'startDate', |
| 77 | + title: 'Start Date', |
| 78 | + type: 'short-input', |
| 79 | + placeholder: 'ISO 8601 timestamp', |
| 80 | + mode: 'advanced', |
| 81 | + wandConfig: { |
| 82 | + enabled: true, |
| 83 | + prompt: |
| 84 | + 'Generate an ISO 8601 timestamp from the user description. Return ONLY the timestamp string.', |
| 85 | + generationType: 'timestamp', |
| 86 | + }, |
| 87 | + condition: { field: 'operation', value: 'query' }, |
| 88 | + }, |
| 89 | + { |
| 90 | + id: 'endDate', |
| 91 | + title: 'End Date', |
| 92 | + type: 'short-input', |
| 93 | + placeholder: 'ISO 8601 timestamp', |
| 94 | + mode: 'advanced', |
| 95 | + wandConfig: { |
| 96 | + enabled: true, |
| 97 | + prompt: |
| 98 | + 'Generate an ISO 8601 timestamp from the user description. Return ONLY the timestamp string.', |
| 99 | + generationType: 'timestamp', |
| 100 | + }, |
| 101 | + condition: { field: 'operation', value: 'query' }, |
| 102 | + }, |
| 103 | + { |
| 104 | + id: 'search', |
| 105 | + title: 'Search', |
| 106 | + type: 'short-input', |
| 107 | + placeholder: 'Free-text search', |
| 108 | + mode: 'advanced', |
| 109 | + condition: { field: 'operation', value: 'query' }, |
| 110 | + }, |
| 111 | + { |
| 112 | + id: 'sortBy', |
| 113 | + title: 'Sort By', |
| 114 | + type: 'dropdown', |
| 115 | + options: [ |
| 116 | + { label: 'Date', id: 'date' }, |
| 117 | + { label: 'Duration', id: 'duration' }, |
| 118 | + { label: 'Cost', id: 'cost' }, |
| 119 | + { label: 'Status', id: 'status' }, |
| 120 | + ], |
| 121 | + value: () => 'date', |
| 122 | + mode: 'advanced', |
| 123 | + condition: { field: 'operation', value: 'query' }, |
| 124 | + }, |
| 125 | + { |
| 126 | + id: 'sortOrder', |
| 127 | + title: 'Sort Order', |
| 128 | + type: 'dropdown', |
| 129 | + options: [ |
| 130 | + { label: 'Descending', id: 'desc' }, |
| 131 | + { label: 'Ascending', id: 'asc' }, |
| 132 | + ], |
| 133 | + value: () => 'desc', |
| 134 | + mode: 'advanced', |
| 135 | + condition: { field: 'operation', value: 'query' }, |
| 136 | + }, |
| 137 | + { |
| 138 | + id: 'cursor', |
| 139 | + title: 'Cursor', |
| 140 | + type: 'short-input', |
| 141 | + placeholder: 'nextCursor from a previous response', |
| 142 | + mode: 'advanced', |
| 143 | + condition: { field: 'operation', value: 'query' }, |
| 144 | + }, |
| 145 | + { |
| 146 | + id: 'logId', |
| 147 | + title: 'Log ID', |
| 148 | + type: 'short-input', |
| 149 | + placeholder: 'Log entry ID', |
| 150 | + condition: { field: 'operation', value: 'get_log' }, |
| 151 | + required: true, |
| 152 | + }, |
| 153 | + { |
| 154 | + id: 'executionIdLookup', |
| 155 | + title: 'Execution ID', |
| 156 | + type: 'short-input', |
| 157 | + placeholder: 'Execution ID', |
| 158 | + condition: { field: 'operation', value: 'get_execution' }, |
| 159 | + required: true, |
| 160 | + }, |
| 161 | + ], |
| 162 | + tools: { |
| 163 | + access: ['logs_query', 'logs_get', 'logs_get_execution'], |
| 164 | + config: { |
| 165 | + tool: (params: Record<string, any>) => { |
| 166 | + const operation = params.operation || 'query' |
| 167 | + if (operation === 'get_log') return 'logs_get' |
| 168 | + if (operation === 'get_execution') return 'logs_get_execution' |
| 169 | + return 'logs_query' |
| 170 | + }, |
| 171 | + params: (params: Record<string, any>) => { |
| 172 | + const operation = params.operation || 'query' |
| 173 | + |
| 174 | + if (operation === 'get_log') { |
| 175 | + if (!params.logId) { |
| 176 | + throw new Error('Logs Block Error: Log ID is required for get_log operation') |
| 177 | + } |
| 178 | + return { id: params.logId } |
| 179 | + } |
| 180 | + |
| 181 | + if (operation === 'get_execution') { |
| 182 | + if (!params.executionIdLookup) { |
| 183 | + throw new Error( |
| 184 | + 'Logs Block Error: Execution ID is required for get_execution operation' |
| 185 | + ) |
| 186 | + } |
| 187 | + return { executionId: params.executionIdLookup } |
| 188 | + } |
| 189 | + |
| 190 | + const rawLimit = |
| 191 | + params.limit !== undefined && params.limit !== null && params.limit !== '' |
| 192 | + ? Number(params.limit) |
| 193 | + : undefined |
| 194 | + const limit = Number.isFinite(rawLimit) ? rawLimit : undefined |
| 195 | + |
| 196 | + return { |
| 197 | + workflowIds: params.workflowIds || undefined, |
| 198 | + executionId: params.executionId || undefined, |
| 199 | + level: params.level && params.level !== 'all' ? params.level : undefined, |
| 200 | + triggers: params.triggers || undefined, |
| 201 | + limit, |
| 202 | + startDate: params.startDate || undefined, |
| 203 | + endDate: params.endDate || undefined, |
| 204 | + search: params.search || undefined, |
| 205 | + cursor: params.cursor || undefined, |
| 206 | + sortBy: params.sortBy || undefined, |
| 207 | + sortOrder: params.sortOrder || undefined, |
| 208 | + } |
| 209 | + }, |
| 210 | + }, |
| 211 | + }, |
| 212 | + inputs: { |
| 213 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 214 | + workflowIds: { type: 'string', description: 'Comma-separated workflow IDs' }, |
| 215 | + executionId: { type: 'string', description: 'Execution ID filter (query operation)' }, |
| 216 | + level: { type: 'string', description: 'Log level filter' }, |
| 217 | + triggers: { type: 'string', description: 'Comma-separated triggers' }, |
| 218 | + limit: { type: 'number', description: 'Max logs to return (default 100, max 200)' }, |
| 219 | + startDate: { type: 'string', description: 'ISO 8601 lower bound' }, |
| 220 | + endDate: { type: 'string', description: 'ISO 8601 upper bound' }, |
| 221 | + search: { type: 'string', description: 'Free-text search term' }, |
| 222 | + sortBy: { type: 'string', description: "'date' | 'duration' | 'cost' | 'status'" }, |
| 223 | + sortOrder: { type: 'string', description: "'desc' | 'asc'" }, |
| 224 | + cursor: { type: 'string', description: 'Pagination cursor' }, |
| 225 | + logId: { type: 'string', description: 'Log entry ID (get_log operation)' }, |
| 226 | + executionIdLookup: { |
| 227 | + type: 'string', |
| 228 | + description: 'Execution ID (get_execution operation)', |
| 229 | + }, |
| 230 | + }, |
| 231 | + outputs: { |
| 232 | + logs: { type: 'json', description: 'Array of log summary entries (query operation)' }, |
| 233 | + nextCursor: { |
| 234 | + type: 'string', |
| 235 | + description: 'Cursor for next page; null when no more results (query operation)', |
| 236 | + }, |
| 237 | + log: { type: 'json', description: 'Full log entry (get_log operation)' }, |
| 238 | + executionId: { type: 'string', description: 'Execution ID (get_execution operation)' }, |
| 239 | + workflowId: { type: 'string', description: 'Workflow ID (get_execution operation)' }, |
| 240 | + workflowState: { |
| 241 | + type: 'json', |
| 242 | + description: 'Per-block state snapshot (get_execution operation)', |
| 243 | + }, |
| 244 | + childWorkflowSnapshots: { |
| 245 | + type: 'json', |
| 246 | + description: 'Snapshots for child workflows (get_execution operation)', |
| 247 | + }, |
| 248 | + executionMetadata: { |
| 249 | + type: 'json', |
| 250 | + description: 'Trigger, timestamps, totalDurationMs, cost (get_execution operation)', |
| 251 | + }, |
| 252 | + }, |
| 253 | +} |
0 commit comments