{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tool-call",
  "title": "Tool call",
  "description": "Collapsible card for an agent's tool call: name and arguments in the header, a status that morphs from spinner to drawn check or error, a live duration while running, and argument and output panes inside.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/ai/tool-call.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { ChevronRight, CircleAlert, Wrench } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring as springs } from \"@/lib/goodui-motion\"\n\n/*\n * A tool call made by an agent: name and arguments in the header, a status that goes spinner → drawn check or\n * error, a live duration while running, and a collapsible body with the arguments and the output pane.\n */\n\nconst CSS = `\n@keyframes pc-tool-spin{to{transform:rotate(360deg)}}\n.pc-tool-spin{animation:pc-tool-spin .8s linear infinite}\n@keyframes pc-tool-sweep{from{transform:translateX(-100%)}to{transform:translateX(250%)}}\n.pc-tool-sweep{animation:pc-tool-sweep 1.4s ease-in-out infinite}\n[dir=rtl] .pc-tool-sweep{animation-direction:reverse}\n@media (prefers-reduced-motion:reduce){.pc-tool-spin{animation-duration:2s}.pc-tool-sweep{animation:none;display:none}}\n`\n\nexport type ToolCallStatus = \"pending\" | \"running\" | \"success\" | \"error\"\n\nexport type ToolCallLabels = {\n  arguments: string\n  output: string\n  error: string\n  pending: string\n  running: string\n  success: string\n  failed: string\n  toggle: string\n}\nconst DEFAULT_LABELS: ToolCallLabels = { arguments: \"Arguments\", output: \"Output\", error: \"Error\", pending: \"Waiting\", running: \"Running\", success: \"Done\", failed: \"Failed\", toggle: \"Toggle details\" }\n\nexport type ToolCallProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** Tool name, shown in monospace. */\n  name: string\n  /** Friendlier text shown instead of the name. */\n  title?: React.ReactNode\n  /** Arguments as an object (rendered as a key/value grid) or a preformatted string. */\n  args?: Record<string, unknown> | string\n  status?: ToolCallStatus\n  /** Result; strings render in a scrollable monospace pane, nodes as-is. */\n  output?: React.ReactNode\n  /** Error message shown in the body when status is \"error\". */\n  error?: string\n  /** Duration in ms. When omitted it is measured from the moment status becomes \"running\". */\n  duration?: number\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Replaces the wrench icon. */\n  icon?: React.ReactNode\n  /** card: bordered; inline: a quiet row for inside a message. */\n  variant?: \"card\" | \"inline\"\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<ToolCallLabels>\n}\n\nexport function formatDuration(ms: number) {\n  return ms < 1000 ? `${Math.round(ms)}ms` : ms < 60000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.floor(ms / 60000)}m ${Math.round((ms % 60000) / 1000)}s`\n}\n\nfunction preview(args: ToolCallProps[\"args\"]) {\n  if (!args) return \"\"\n  if (typeof args === \"string\") return args\n  return Object.entries(args)\n    .slice(0, 3)\n    .map(([k, v]) => `${k}: ${typeof v === \"string\" ? v : JSON.stringify(v)}`)\n    .join(\", \")\n}\n\nfunction StatusIcon({ status, reduce }: { status: ToolCallStatus; reduce: boolean }) {\n  const spring = reduce ? { duration: 0 } : springs.play\n  return (\n    <span className=\"relative grid size-5 shrink-0 place-items-center\">\n      <AnimatePresence mode=\"popLayout\" initial={false}>\n        {status === \"pending\" && (\n          <motion.span key=\"pending\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={spring} className=\"size-3.5 rounded-full border-2 border-dashed border-muted-foreground/50\" />\n        )}\n        {status === \"running\" && (\n          <motion.svg key=\"running\" viewBox=\"0 0 24 24\" initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"pc-tool-spin size-4 text-foreground\" fill=\"none\" aria-hidden=\"true\">\n            <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeOpacity=\".2\" strokeWidth=\"3\" />\n            <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" />\n          </motion.svg>\n        )}\n        {status === \"success\" && (\n          <motion.svg key=\"success\" viewBox=\"0 0 24 24\" initial={{ opacity: 0, scale: 0.5 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"size-5 text-emerald-600 dark:text-emerald-400\" fill=\"none\" aria-hidden=\"true\">\n            <circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"currentColor\" fillOpacity=\".15\" />\n            <motion.path d=\"M7.5 12.5l3 3 6-7\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={{ pathLength: reduce ? 1 : 0 }} animate={{ pathLength: 1 }} transition={reduce ? { duration: 0 } : { duration: 0.3, delay: 0.1, ease: \"easeOut\" }} />\n          </motion.svg>\n        )}\n        {status === \"error\" && (\n          <motion.span key=\"error\" initial={{ opacity: 0, scale: 0.5 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"grid size-5 place-items-center rounded-full bg-rose-500/15 text-rose-600 dark:text-rose-400\">\n            <svg viewBox=\"0 0 24 24\" className=\"size-3.5\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"M8 8l8 8M16 8l-8 8\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" />\n            </svg>\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  )\n}\n\n/** Collapsible card for an agent's tool call: name, args, live status and duration, output and error panes. */\nexport function ToolCall({\n  name,\n  title,\n  args,\n  status = \"pending\",\n  output,\n  error,\n  duration,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  icon,\n  variant = \"card\",\n  labels,\n  className,\n  ...props\n}: ToolCallProps) {\n  const l = useLabels(\"tool-call\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const uid = React.useId()\n  const [openInner, setOpenInner] = React.useState(defaultOpen)\n  const open = openProp ?? openInner\n  const [elapsed, setElapsed] = React.useState(0)\n  const started = React.useRef<number | null>(null)\n\n  // Live timer while running; the final value stays once the call settles.\n  React.useEffect(() => {\n    if (status !== \"running\") return\n    started.current = performance.now()\n    setElapsed(0)\n    const id = window.setInterval(() => setElapsed(performance.now() - (started.current ?? 0)), 100)\n    return () => {\n      window.clearInterval(id)\n      if (started.current !== null) setElapsed(performance.now() - started.current)\n    }\n  }, [status])\n\n  const toggle = () => {\n    if (openProp === undefined) setOpenInner(!open)\n    onOpenChange?.(!open)\n  }\n\n  const shownMs = duration ?? (status === \"pending\" ? undefined : elapsed)\n  const statusText = status === \"pending\" ? l.pending : status === \"running\" ? l.running : status === \"success\" ? l.success : l.failed\n  const argEntries = args && typeof args === \"object\" ? Object.entries(args) : []\n  const hasBody = argEntries.length > 0 || (typeof args === \"string\" && args.length > 0) || output !== undefined || (status === \"error\" && !!error)\n\n  return (\n    <div\n      data-status={status}\n      className={cn(\"pc-tool text-sm\", variant === \"card\" && \"overflow-hidden rounded-xl border bg-card text-card-foreground\", className)}\n      {...props}\n    >\n      <GooduiTokens />\n      <style href=\"pc-tool-call\" precedence=\"default\">\n        {CSS}\n      </style>\n      <button\n        type=\"button\"\n        aria-expanded={open}\n        aria-controls={`${uid}-body`}\n        onClick={toggle}\n        disabled={!hasBody}\n        className={cn(\n          \"pc-press pc-press-soft relative flex w-full items-center gap-2.5 overflow-hidden text-start outline-none focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset disabled:cursor-default\",\n          variant === \"card\" ? \"px-3 py-2.5 hover:bg-muted/50 disabled:hover:bg-transparent\" : \"rounded-lg px-2 py-1.5 hover:bg-muted/60 disabled:hover:bg-transparent\",\n        )}\n      >\n        <span className=\"grid size-6 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground [&_svg]:size-3.5\">{icon ?? <Wrench aria-hidden=\"true\" />}</span>\n        <span className=\"flex min-w-0 flex-1 items-baseline gap-2\">\n          <span className={cn(\"min-w-[8ch] truncate font-medium\", !title && \"font-mono text-[13px]\")}>{title ?? name}</span>\n          {args !== undefined && <span className=\"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground\">{preview(args)}</span>}\n        </span>\n        <span className=\"sr-only\">{statusText}</span>\n        <AnimatePresence initial={false}>\n          {shownMs !== undefined && (\n            <motion.span\n              key=\"dur\"\n              initial={{ opacity: 0, width: 0 }}\n              animate={{ opacity: 1, width: \"auto\" }}\n              exit={{ opacity: 0, width: 0 }}\n              transition={reduce ? { duration: 0 } : { duration: 0.2 }}\n              className={cn(\"shrink-0 overflow-hidden text-xs whitespace-nowrap tabular-nums\", status === \"error\" ? \"text-rose-700 dark:text-rose-400\" : \"text-muted-foreground\")}\n              aria-hidden=\"true\"\n            >\n              {formatDuration(shownMs)}\n            </motion.span>\n          )}\n        </AnimatePresence>\n        <StatusIcon status={status} reduce={reduce} />\n        {hasBody && <ChevronRight className={cn(\"size-4 shrink-0 text-muted-foreground transition-transform duration-200 rtl:rotate-180\", open && \"rotate-90 rtl:rotate-90\")} aria-hidden=\"true\" />}\n        {status === \"running\" && (\n          <span className=\"absolute inset-x-0 bottom-0 h-px overflow-hidden\" aria-hidden=\"true\">\n            <span className=\"pc-tool-sweep block h-full w-1/3 bg-[linear-gradient(90deg,transparent,var(--foreground),transparent)] opacity-40\" />\n          </span>\n        )}\n      </button>\n      <AnimatePresence initial={false}>\n        {open && hasBody && (\n          <motion.div\n            key=\"body\"\n            id={`${uid}-body`}\n            initial={{ height: 0, opacity: 0 }}\n            animate={{ height: \"auto\", opacity: 1 }}\n            exit={{ height: 0, opacity: 0 }}\n            transition={reduce ? { duration: 0 } : springs.ui}\n            className=\"overflow-hidden\"\n          >\n            <div className={cn(\"flex flex-col gap-3\", variant === \"card\" ? \"border-t px-3 py-3\" : \"px-2 pt-1 pb-2\")}>\n              {(argEntries.length > 0 || typeof args === \"string\") && (\n                <section>\n                  <h4 className=\"mb-1.5 text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">{l.arguments}</h4>\n                  {typeof args === \"string\" ? (\n                    <pre className=\"overflow-x-auto rounded-lg bg-muted/60 p-3 font-mono text-xs leading-5 whitespace-pre-wrap\">{args}</pre>\n                  ) : (\n                    <dl className=\"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 font-mono text-xs leading-5\">\n                      {argEntries.map(([k, v]) => (\n                        <React.Fragment key={k}>\n                          <dt className=\"text-muted-foreground\">{k}</dt>\n                          <dd className=\"break-all\">{typeof v === \"string\" ? v : JSON.stringify(v)}</dd>\n                        </React.Fragment>\n                      ))}\n                    </dl>\n                  )}\n                </section>\n              )}\n              {output !== undefined && (\n                <section>\n                  <h4 className=\"mb-1.5 text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">{l.output}</h4>\n                  {typeof output === \"string\" ? (\n                    <pre tabIndex={0} className=\"max-h-56 overflow-auto rounded-lg bg-muted/60 p-3 font-mono text-xs leading-5 whitespace-pre-wrap outline-none focus-visible:ring-3 focus-visible:ring-ring/50\">\n                      {output}\n                    </pre>\n                  ) : (\n                    output\n                  )}\n                </section>\n              )}\n              {status === \"error\" && error && (\n                <section className=\"flex items-start gap-2 rounded-lg bg-rose-500/10 p-3 text-xs leading-5 text-rose-700 dark:text-rose-300\">\n                  <CircleAlert className=\"mt-0.5 size-3.5 shrink-0\" aria-hidden=\"true\" />\n                  <span>\n                    <span className=\"sr-only\">{l.error}: </span>\n                    {error}\n                  </span>\n                </section>\n              )}\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/tool-call.tsx"
    }
  ],
  "categories": [
    "components",
    "ai"
  ],
  "type": "registry:component"
}