|
| 1 | +import { Terminal } from "lucide-react"; |
| 2 | +import type { BlockConfig } from "@/blocks/types"; |
| 3 | + |
| 4 | +export const commandBlock: BlockConfig = { |
| 5 | + type: "command", |
| 6 | + name: "Command", |
| 7 | + description: "Execute bash commands in a specified working directory with optional timeout and shell configuration.", |
| 8 | + category: "tools", |
| 9 | + bgColor: "#10B981", |
| 10 | + icon: Terminal, |
| 11 | + subBlocks: [ |
| 12 | + { |
| 13 | + id: "command", |
| 14 | + title: "Command", |
| 15 | + type: "long-input", |
| 16 | + placeholder: 'echo "Hello World"', |
| 17 | + required: true, |
| 18 | + }, |
| 19 | + { |
| 20 | + id: "workingDirectory", |
| 21 | + title: "Working Directory", |
| 22 | + type: "short-input", |
| 23 | + placeholder: "/path/to/directory (optional)", |
| 24 | + required: false, |
| 25 | + }, |
| 26 | + { |
| 27 | + id: "timeout", |
| 28 | + title: "Timeout (ms)", |
| 29 | + type: "short-input", |
| 30 | + placeholder: "30000", |
| 31 | + value: () => "30000", |
| 32 | + required: false, |
| 33 | + }, |
| 34 | + { |
| 35 | + id: "shell", |
| 36 | + title: "Shell", |
| 37 | + type: "short-input", |
| 38 | + placeholder: "/bin/bash", |
| 39 | + value: () => "/bin/bash", |
| 40 | + required: false, |
| 41 | + }, |
| 42 | + ], |
| 43 | + tools: { |
| 44 | + access: ["command_exec"], |
| 45 | + config: { |
| 46 | + tool: () => "command_exec", |
| 47 | + params: (params: Record<string, any>) => { |
| 48 | + const transformed: Record<string, any> = { |
| 49 | + command: params.command, |
| 50 | + }; |
| 51 | + |
| 52 | + if (params.workingDirectory) { |
| 53 | + transformed.workingDirectory = params.workingDirectory; |
| 54 | + } |
| 55 | + |
| 56 | + if (params.timeout) { |
| 57 | + const timeoutNum = Number.parseInt(params.timeout as string, 10); |
| 58 | + if (!Number.isNaN(timeoutNum)) { |
| 59 | + transformed.timeout = timeoutNum; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + if (params.shell) { |
| 64 | + transformed.shell = params.shell; |
| 65 | + } |
| 66 | + |
| 67 | + return transformed; |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + inputs: { |
| 72 | + command: { type: "string", description: "The bash command to execute" }, |
| 73 | + workingDirectory: { type: "string", description: "Directory where the command will be executed" }, |
| 74 | + timeout: { type: "number", description: "Maximum execution time in milliseconds" }, |
| 75 | + shell: { type: "string", description: "Shell to use for execution" }, |
| 76 | + }, |
| 77 | + outputs: { |
| 78 | + stdout: { type: "string", description: "Standard output from the command" }, |
| 79 | + stderr: { type: "string", description: "Standard error from the command" }, |
| 80 | + exitCode: { type: "number", description: "Command exit code (0 = success)" }, |
| 81 | + duration: { type: "number", description: "Execution time in milliseconds" }, |
| 82 | + command: { type: "string", description: "The executed command" }, |
| 83 | + workingDirectory: { type: "string", description: "The directory where command was executed" }, |
| 84 | + timedOut: { type: "boolean", description: "Whether the command exceeded the timeout" }, |
| 85 | + }, |
| 86 | +}; |
0 commit comments