"use client"; import { memo, useState } from "react"; import type { ToolCallMessagePartComponent } from "@assistant-ui/react"; import { ChevronRightIcon, DollarSignIcon, XCircleIcon } from "lucide-react"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/radix/collapsible"; import { cn } from "@/lib/utils"; import { ToolStatusIcon, isCancelledToolStatus, truncate, } from "@/components/tools/tool-ui-shared"; const parseResult = (result: unknown) => { if (!result) return {}; if (typeof result === "string") { try { const parsed = JSON.parse(result); if (typeof parsed === "object" && parsed !== null) return parsed; } catch { // plain text output } return { stdout: result }; } if (typeof result === "object") return result as Record; return {}; }; export const BashTerminal: ToolCallMessagePartComponent = memo( ({ args, result, status }) => { const [open, setOpen] = useState(false); const command = typeof args?.command === "string" ? args.command : ""; const description = typeof args?.description === "string" ? args.description : ""; const isRunning = status?.type === "running"; const isCancelled = isCancelledToolStatus(status); const parsed = isRunning ? {} : parseResult(result); const stdout = typeof parsed.stdout === "string" ? parsed.stdout : undefined; const stderr = typeof parsed.stderr === "string" ? parsed.stderr : undefined; const exitCode = typeof parsed.exitCode === "number" ? parsed.exitCode : 0; const hasOutput = Boolean(stdout || stderr); const isError = !isRunning && exitCode !== 0; const summaryText = description || truncate(command); return ( {hasOutput && (
{command && (
$ {command}
)} {stdout && (
                  {stdout}
                
)} {stderr && (
                  {stderr}
                
)}
)}
); }, ); BashTerminal.displayName = "BashTerminal";