import type { ToolCallMessagePartComponent } from "@assistant-ui/react"; import { CheckIcon, ChevronDownIcon, ChevronUpIcon, XCircleIcon } from "lucide-react"; import { useState } from "react"; import { cn } from "@/lib/utils"; import { getToolIcon } from "@/contracts/enums/toolIcons"; function formatToolName(name: string): string { return name .replace(/_/g, " ") .replace(/\b\w/g, (c) => c.toUpperCase()); } export const ToolFallback: 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 cancelledReason = isCancelled && status.error ? typeof status.error === "string" ? status.error : JSON.stringify(status.error) : null; const errorReason = isError && status.error ? typeof status.error === "string" ? status.error : JSON.stringify(status.error) : null; const Icon = getToolIcon(toolName); const displayName = formatToolName(toolName); return (
Arguments
{argsText}
Result
{typeof result === "string" ? result : JSON.stringify(result, null, 2)}