| 1 | import { ToolCallState } from "core"; |
| 2 | import { UnifiedTerminalCommand } from "../../../components/UnifiedTerminal/UnifiedTerminal"; |
| 3 | |
| 4 | interface RunTerminalCommandToolCallProps { |
| 5 | command: string; |
| 6 | toolCallState: ToolCallState; |
| 7 | toolCallId: string | undefined; |
| 8 | } |
| 9 | |
| 10 | export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { |
| 11 | // For errored status, show any output (error messages) |
| 12 | // Otherwise look for terminal output specifically |
| 13 | const isErrored = props.toolCallState.status === "errored"; |
| 14 | const outputItem = isErrored |
| 15 | ? props.toolCallState.output?.[0] // Get first output item for errors |
| 16 | : props.toolCallState.output?.find((item) => item.name === "Terminal"); |
| 17 | |
| 18 | const terminalContent = outputItem?.content || ""; |
| 19 | const statusMessage = outputItem?.status || ""; |
| 20 | const isRunning = props.toolCallState.status === "calling"; |
| 21 | |
| 22 | // Determine status type |
| 23 | let statusType: "running" | "completed" | "failed" | "background" = |
| 24 | "completed"; |
| 25 | if (isRunning) { |
| 26 | statusType = "running"; |
| 27 | } else if (isErrored || statusMessage?.includes("failed")) { |
| 28 | statusType = "failed"; |
| 29 | } else if (statusMessage?.includes("background")) { |
| 30 | statusType = "background"; |
| 31 | } |
| 32 | |
| 33 | return ( |
| 34 | <UnifiedTerminalCommand |
| 35 | command={props.command} |
| 36 | output={terminalContent} |
| 37 | status={statusType} |
| 38 | statusMessage={statusMessage} |
| 39 | toolCallState={props.toolCallState} |
| 40 | toolCallId={props.toolCallId} |
| 41 | /> |
| 42 | ); |
| 43 | } |