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 (
setIsExpanded(!isExpanded)}>
🛠️ {displayCommand} {displayData?.workingDir && ( in {displayData.workingDir} )} {isComplete && isCancelled && ✗ cancelled} {isComplete && hasError && !isCancelled && } {isComplete && !hasError && }
{isExpanded && (
{displayData?.workingDir && (
Working Directory:
{displayData.workingDir}
)}
Command:
{command}
{isComplete && (
Output{hasError ? " (Error)" : ""}: {executionTime && {executionTime}}
                {output || "(no output)"}
              
)}
)}
); } export default BashTool;