|
| 1 | +import { ApifyIcon } from '@/components/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | +import type { RunActorResult } from '@/tools/apify/types' |
| 4 | + |
| 5 | +export const ApifyBlock: BlockConfig<RunActorResult> = { |
| 6 | + type: 'apify', |
| 7 | + name: 'Apify', |
| 8 | + description: 'Run Apify actors and retrieve results', |
| 9 | + longDescription: |
| 10 | + 'Integrate Apify into your workflow. Run any Apify actor with custom input and retrieve results. Supports both synchronous and asynchronous execution with automatic dataset fetching.', |
| 11 | + docsLink: 'https://docs.sim.ai/tools/apify', |
| 12 | + category: 'tools', |
| 13 | + bgColor: '#E0E0E0', |
| 14 | + icon: ApifyIcon, |
| 15 | + |
| 16 | + subBlocks: [ |
| 17 | + { |
| 18 | + id: 'operation', |
| 19 | + title: 'Operation', |
| 20 | + type: 'dropdown', |
| 21 | + options: [ |
| 22 | + { label: 'Run Actor', id: 'apify_run_actor_sync' }, |
| 23 | + { label: 'Run Actor (Async)', id: 'apify_run_actor_async' }, |
| 24 | + ], |
| 25 | + value: () => 'apify_run_actor_sync', |
| 26 | + }, |
| 27 | + { |
| 28 | + id: 'apiKey', |
| 29 | + title: 'Apify API Token', |
| 30 | + type: 'short-input', |
| 31 | + password: true, |
| 32 | + placeholder: 'Enter your Apify API token', |
| 33 | + required: true, |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 'actorId', |
| 37 | + title: 'Actor ID', |
| 38 | + type: 'short-input', |
| 39 | + placeholder: 'e.g., janedoe/my-actor or actor ID', |
| 40 | + required: true, |
| 41 | + }, |
| 42 | + { |
| 43 | + id: 'input', |
| 44 | + title: 'Actor Input', |
| 45 | + type: 'code', |
| 46 | + language: 'json', |
| 47 | + placeholder: '{\n "startUrl": "https://example.com",\n "maxPages": 10\n}', |
| 48 | + required: false, |
| 49 | + }, |
| 50 | + { |
| 51 | + id: 'timeout', |
| 52 | + title: 'Timeout', |
| 53 | + type: 'short-input', |
| 54 | + placeholder: 'Actor timeout in seconds', |
| 55 | + required: false, |
| 56 | + }, |
| 57 | + { |
| 58 | + id: 'build', |
| 59 | + title: 'Build', |
| 60 | + type: 'short-input', |
| 61 | + placeholder: 'Actor build (e.g., "latest", "beta", or build tag)', |
| 62 | + required: false, |
| 63 | + }, |
| 64 | + { |
| 65 | + id: 'waitForFinish', |
| 66 | + title: 'Wait For Finish', |
| 67 | + type: 'short-input', |
| 68 | + placeholder: 'Initial wait time in seconds (0-60)', |
| 69 | + required: false, |
| 70 | + condition: { |
| 71 | + field: 'operation', |
| 72 | + value: 'apify_run_actor_async', |
| 73 | + }, |
| 74 | + }, |
| 75 | + { |
| 76 | + id: 'itemLimit', |
| 77 | + title: 'Item Limit', |
| 78 | + type: 'short-input', |
| 79 | + placeholder: 'Max dataset items to fetch (1-250000)', |
| 80 | + required: false, |
| 81 | + condition: { |
| 82 | + field: 'operation', |
| 83 | + value: 'apify_run_actor_async', |
| 84 | + }, |
| 85 | + }, |
| 86 | + ], |
| 87 | + |
| 88 | + tools: { |
| 89 | + access: ['apify_run_actor_sync', 'apify_run_actor_async'], |
| 90 | + config: { |
| 91 | + tool: (params) => params.operation, |
| 92 | + params: (params: Record<string, any>) => { |
| 93 | + const { operation, ...rest } = params |
| 94 | + const result: Record<string, any> = { |
| 95 | + apiKey: rest.apiKey, |
| 96 | + actorId: rest.actorId, |
| 97 | + } |
| 98 | + |
| 99 | + if (rest.input) { |
| 100 | + result.input = rest.input |
| 101 | + } |
| 102 | + |
| 103 | + if (rest.timeout) { |
| 104 | + result.timeout = Number(rest.timeout) |
| 105 | + } |
| 106 | + |
| 107 | + if (rest.build) { |
| 108 | + result.build = rest.build |
| 109 | + } |
| 110 | + |
| 111 | + if (rest.waitForFinish) { |
| 112 | + result.waitForFinish = Number(rest.waitForFinish) |
| 113 | + } |
| 114 | + |
| 115 | + if (rest.itemLimit) { |
| 116 | + result.itemLimit = Number(rest.itemLimit) |
| 117 | + } |
| 118 | + |
| 119 | + return result |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + |
| 124 | + inputs: { |
| 125 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 126 | + apiKey: { type: 'string', description: 'Apify API token' }, |
| 127 | + actorId: { type: 'string', description: 'Actor ID or username/actor-name' }, |
| 128 | + input: { type: 'string', description: 'Actor input as JSON string' }, |
| 129 | + timeout: { type: 'number', description: 'Timeout in seconds' }, |
| 130 | + build: { type: 'string', description: 'Actor build version' }, |
| 131 | + waitForFinish: { type: 'number', description: 'Initial wait time in seconds' }, |
| 132 | + itemLimit: { type: 'number', description: 'Max dataset items to fetch' }, |
| 133 | + }, |
| 134 | + |
| 135 | + outputs: { |
| 136 | + success: { type: 'boolean', description: 'Whether the actor run succeeded' }, |
| 137 | + runId: { type: 'string', description: 'Apify run ID' }, |
| 138 | + status: { type: 'string', description: 'Run status (SUCCEEDED, FAILED, etc.)' }, |
| 139 | + datasetId: { type: 'string', description: 'Dataset ID containing results' }, |
| 140 | + items: { type: 'json', description: 'Dataset items (if completed)' }, |
| 141 | + }, |
| 142 | +} |
0 commit comments