"use client"; import { Badge } from "@/components/ui/badge"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import { cn } from "@/lib/utils"; import type { DynamicToolUIPart, ToolUIPart } from "ai"; import { CheckCircleIcon, ChevronDownIcon, CircleIcon, ClockIcon, WrenchIcon, XCircleIcon, } from "lucide-react"; import type { ComponentProps, ReactNode } from "react"; import { isValidElement } from "react"; import { CodeBlock } from "./code-block"; export type ToolProps = ComponentProps; export const Tool = ({ className, ...props }: ToolProps) => ( ); export type ToolPart = ToolUIPart | DynamicToolUIPart; export type ToolHeaderProps = { title?: string; className?: string; } & ( | { type: ToolUIPart["type"]; state: ToolUIPart["state"]; toolName?: never } | { type: DynamicToolUIPart["type"]; state: DynamicToolUIPart["state"]; toolName: string; } ); const statusLabels: Record = { "approval-requested": "Awaiting Approval", "approval-responded": "Responded", "input-available": "Running", "input-streaming": "Pending", "output-available": "Completed", "output-denied": "Denied", "output-error": "Error", }; const statusIcons: Record = { "approval-requested": , "approval-responded": , "input-available": , "input-streaming": , "output-available": , "output-denied": , "output-error": , }; export const getStatusBadge = (status: ToolPart["state"]) => ( {statusIcons[status]} {statusLabels[status]} ); export const ToolHeader = ({ className, title, type, state, toolName, ...props }: ToolHeaderProps) => { const derivedName = type === "dynamic-tool" ? toolName : type.split("-").slice(1).join("-"); return (
{title ?? derivedName} {getStatusBadge(state)}
); }; export type ToolContentProps = ComponentProps; export const ToolContent = ({ className, ...props }: ToolContentProps) => ( ); export type ToolInputProps = ComponentProps<"div"> & { input: ToolPart["input"]; }; export const ToolInput = ({ className, input, ...props }: ToolInputProps) => (

Parameters

); export type ToolOutputProps = ComponentProps<"div"> & { output: ToolPart["output"]; errorText: ToolPart["errorText"]; }; export const ToolOutput = ({ className, output, errorText, ...props }: ToolOutputProps) => { if (!(output || errorText)) { return null; } let Output =
{output as ReactNode}
; if (typeof output === "object" && !isValidElement(output)) { Output = ( ); } else if (typeof output === "string") { Output = ; } return (

{errorText ? "Error" : "Result"}

{errorText &&
{errorText}
} {Output}
); };