{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tool-call-demo",
  "title": "Tool Call Demo",
  "description": "A worked example of Tool Call: A compact record of one tool invocation: name, status, duration, and the input and output behind a disclosure.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/tool-call.json"
  ],
  "files": [
    {
      "path": "components/demos/tool-call-demo.tsx",
      "content": "\"use client\"\n\nimport { DemoVariants } from \"@/components/demos/demo-variants\"\nimport { RestartButton } from \"@/components/demos/restart-button\"\nimport {\n  useScriptedTimeline,\n  type TimelineStep,\n} from \"@/components/demos/use-scripted-timeline\"\nimport {\n  ToolCall,\n  type ToolCallStatus,\n} from \"@/registry/default/tool-call/tool-call\"\n\nconst steps: [TimelineStep<ToolCallStatus>, ...TimelineStep<ToolCallStatus>[]] =\n  [\n    { state: \"pending\", holdMs: 900 },\n    { state: \"running\", holdMs: 2400 },\n    { state: \"success\", holdMs: 0 },\n  ]\n\nconst input = { pattern: \"nullable email\", path: \"migrations/\", limit: 5 }\n\nfunction LiveRun() {\n  const { state, elapsedMs, isFinished, restart, runId } =\n    useScriptedTimeline(steps)\n\n  return (\n    <div className=\"grid gap-4\">\n      <ToolCall\n        key={runId}\n        name=\"search_files\"\n        status={state}\n        durationMs={state === \"pending\" ? undefined : elapsedMs}\n        input={input}\n        output={\n          isFinished ? (\n            <p>\n              2 matches in <code>0004_add_email_index.sql</code>\n            </p>\n          ) : undefined\n        }\n        defaultOpen\n      />\n\n      {isFinished ? <RestartButton onClick={restart} /> : null}\n    </div>\n  )\n}\n\nexport function ToolCallDemo() {\n  return (\n    <DemoVariants\n      label=\"Tool call state\"\n      variants={[\n        { id: \"live\", label: \"Live run\", render: () => <LiveRun /> },\n        {\n          id: \"queued\",\n          label: \"Queued\",\n          render: () => (\n            <ToolCall name=\"search_files\" status=\"pending\" input={input} />\n          ),\n        },\n        {\n          id: \"error\",\n          label: \"Failed\",\n          render: () => (\n            <ToolCall\n              name=\"write_file\"\n              status=\"error\"\n              input={{ path: \"migrations/0004_add_email_index.sql\" }}\n              error=\"Permission denied. The migrations directory is read-only.\"\n              durationMs={120}\n              defaultOpen\n            />\n          ),\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/demo-variants.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type DemoVariant = {\n  id: string\n  label: string\n  render: () => React.ReactNode\n}\n\nexport function DemoVariants({\n  variants,\n  label = \"Demo variant\",\n}: {\n  variants: [DemoVariant, ...DemoVariant[]]\n  label?: string\n}) {\n  const [activeId, setActiveId] = React.useState(variants[0].id)\n  const active =\n    variants.find((variant) => variant.id === activeId) ?? variants[0]\n\n  return (\n    <div className=\"grid w-full justify-items-center gap-6\">\n      {/* Centres whatever the variant renders. Without this a demo that caps\n          its own width sits against the left edge while the switch below it\n          is centred, which reads as a mistake. */}\n      <div className=\"flex w-full justify-center\">{active.render()}</div>\n\n      <div\n        role=\"group\"\n        aria-label={label}\n        className=\"border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1\"\n      >\n        {variants.map((variant) => {\n          const isActive = variant.id === active.id\n\n          return (\n            <button\n              key={variant.id}\n              type=\"button\"\n              aria-pressed={isActive}\n              className={\n                isActive\n                  ? \"bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold\"\n                  : \"text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold\"\n              }\n              onClick={() => setActiveId(variant.id)}\n            >\n              {variant.label}\n            </button>\n          )\n        })}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/restart-button.tsx",
      "content": "\"use client\"\n\nimport { RotateCcw } from \"lucide-react\"\n\nexport function RestartButton({ onClick }: { onClick: () => void }) {\n  return (\n    <button className=\"restore-button\" type=\"button\" onClick={onClick}>\n      <RotateCcw aria-hidden=\"true\" size={15} /> Replay\n    </button>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/use-scripted-timeline.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nconst TICK_MS = 100\n\nexport type TimelineStep<TState> = {\n  state: TState\n  holdMs: number\n}\n\nexport function useScriptedTimeline<TState>(\n  steps: [TimelineStep<TState>, ...TimelineStep<TState>[]]\n) {\n  const [index, setIndex] = React.useState(0)\n  const [elapsedMs, setElapsedMs] = React.useState(0)\n  const [runId, setRunId] = React.useState(0)\n\n  const isFinished = index >= steps.length - 1\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setTimeout(\n      () => setIndex((current) => current + 1),\n      (steps[index] ?? steps[0]).holdMs\n    )\n\n    return () => window.clearTimeout(timer)\n  }, [index, isFinished, steps])\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setInterval(\n      () => setElapsedMs((current) => current + TICK_MS),\n      TICK_MS\n    )\n\n    return () => window.clearInterval(timer)\n  }, [isFinished])\n\n  const restart = React.useCallback(() => {\n    setIndex(0)\n    setElapsedMs(0)\n    setRunId((current) => current + 1)\n  }, [])\n\n  return {\n    state: (steps[index] ?? steps[0]).state,\n    elapsedMs,\n    isFinished,\n    restart,\n    runId,\n  }\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}