"use client"; import { useEffect, useRef } from "react"; import { Wrench, Check, ChevronDown } from "lucide-react"; import { Spinner } from "@/components/ui/spinner"; interface ToolReasoningProps { name: string; args?: object | unknown; status: string; } function formatValue(value: unknown): string { if (Array.isArray(value)) return `[${value.length} items]`; if (typeof value === "object" && value !== null) return `{${Object.keys(value).length} keys}`; if (typeof value === "string") return `"${value}"`; return String(value); } export function ToolReasoning({ name, args, status }: ToolReasoningProps) { const entries = args ? Object.entries(args) : []; const detailsRef = useRef(null); const isRunning = status === "executing" || status === "inProgress"; // Auto-open while executing, auto-close when complete useEffect(() => { if (!detailsRef.current) return; detailsRef.current.open = isRunning; }, [isRunning]); const statusIcon = isRunning ? ( ) : ( ); return (
{entries.length > 0 ? (
{statusIcon} {name}
{entries.map(([key, value]) => (
{key}: {formatValue(value)}
))}
) : (
{statusIcon} {name}
)}
); }