"use client" import * as React from "react" import { cn } from "cn" import { Badge } from "@/registry/bases/radix/ui/badge" import { Separator } from "@/registry/bases/radix/ui/separator" import { IconPlaceholder } from "@/app/(app)/create/components/icon-placeholder" type ToolPart = { type: `tool-${string}` | "dynamic-tool" toolName?: string toolCallId: string title?: string state: string input?: unknown output?: unknown errorText?: string } function getToolName(part: ToolPart) { return part.type === "dynamic-tool" ? (part.toolName ?? "dynamicTool") : part.type.replace("tool-", "") } function getToolTitle(part: ToolPart) { if ("title" in part && typeof part.title === "string") { return part.title } return getToolName(part) .replace(/([a-z0-9])([A-Z])/g, "$1 $2") .replace(/[-_]/g, " ") .replace(/\b\w/g, (letter) => letter.toUpperCase()) } function formatValue(value: unknown) { if (typeof value === "string") { return value } return JSON.stringify(value, null, 2) } export function PartTool({ part, className, }: { part: ToolPart } & Omit, "part">) { if (part.type !== "dynamic-tool" && !part.type.startsWith("tool-")) { return null } const input = "input" in part ? part.input : undefined const output = "output" in part ? part.output : undefined const errorText = "errorText" in part ? part.errorText : undefined const stateLabel = part.state.replace(/-/g, " ") return (
{getToolTitle(part)}
{getToolName(part)}
{stateLabel}
{input !== undefined || output !== undefined || errorText ? ( <>
{input !== undefined ? (
Input
                  {formatValue(input)}
                
) : null} {output !== undefined ? (
Output
                  {formatValue(output)}
                
) : null} {errorText ? (
{errorText}
) : null}
) : null}
) }