import React, { useState } from "react"; import { LLMContent } from "../types"; // Display data from the bash tool backend interface BashDisplayData { workingDir: string; } interface BashToolProps { // For tool_use (pending state) toolInput?: unknown; isRunning?: boolean; // For tool_result (completed state) toolResult?: LLMContent[]; hasError?: boolean; executionTime?: string; display?: unknown; } function BashTool({ toolInput, isRunning, toolResult, hasError, executionTime, display, }: BashToolProps) { const [isExpanded, setIsExpanded] = useState(false); // Extract working directory from display data const displayData: BashDisplayData | null = display && typeof display === "object" && "workingDir" in display && typeof display.workingDir === "string" ? (display as BashDisplayData) : null; // Extract command from toolInput const command = typeof toolInput === "object" && toolInput !== null && "command" in toolInput && typeof toolInput.command === "string" ? toolInput.command : typeof toolInput === "string" ? toolInput : ""; // Extract output from toolResult const output = toolResult && toolResult.length > 0 && toolResult[0].Text ? toolResult[0].Text : ""; // Check if this was a cancelled operation const isCancelled = hasError && output.toLowerCase().includes("cancel"); // Truncate command for display const truncateCommand = (cmd: string, maxLen: number = 300) => { if (cmd.length <= maxLen) return cmd; return cmd.substring(0, maxLen) + "..."; }; const displayCommand = truncateCommand(command); const isComplete = !isRunning && toolResult !== undefined; return (
{displayData.workingDir}
{command}
{output || "(no output)"}