import type { ToolCallMessagePartComponent } from "@assistant-ui/react"; import { CheckIcon, ChevronDownIcon, ChevronUpIcon, XCircleIcon } from "lucide-react"; import { useMemo, useState } from "react"; import { GenericHitlApprovalToolUI } from "@/components/tool-ui/generic-hitl-approval"; import { getToolIcon } from "@/contracts/enums/toolIcons"; import { isInterruptResult } from "@/lib/hitl"; import { cn } from "@/lib/utils"; function formatToolName(name: string): string { return name.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()); } const DefaultToolFallbackInner: ToolCallMessagePartComponent = ({ toolName, argsText, result, status, }) => { const [isExpanded, setIsExpanded] = useState(false); const isCancelled = status?.type === "incomplete" && status.reason === "cancelled"; const isError = status?.type === "incomplete" && status.reason === "error"; const isRunning = status?.type === "running" || status?.type === "requires-action"; const errorData = status?.type === "incomplete" ? status.error : undefined; const serializedError = useMemo( () => (errorData && typeof errorData !== "string" ? JSON.stringify(errorData) : null), [errorData] ); const serializedResult = useMemo( () => result !== undefined && typeof result !== "string" ? JSON.stringify(result, null, 2) : null, [result] ); const cancelledReason = isCancelled && status.error ? typeof status.error === "string" ? status.error : serializedError : null; const errorReason = isError && status.error ? typeof status.error === "string" ? status.error : serializedError : null; const Icon = getToolIcon(toolName); const displayName = formatToolName(toolName); return (
{isExpanded && !isRunning && ( <>
{argsText && (

Arguments

									{argsText}
								
)} {!isCancelled && result !== undefined && ( <>

Result

										{typeof result === "string" ? result : serializedResult}
									
)}
)}
); }; export const ToolFallback: ToolCallMessagePartComponent = (props) => { if (isInterruptResult(props.result)) { return ; } return ; };