shadimage
mischief
exampletool-call-demosource: ok · hit

Tool Call Demo

A worked example of Tool Call: A compact record of one tool invocation: name, status, duration, and the input and output behind a disclosure.

npx shadcn add "https://ui.tinkererslabs.com/r/tool-call-demo.json"
free

Where it goes

stats

Interaction

animated-counter

Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light
lucide-react@^1.31.0

Registry dependencies

https://ui.tinkererslabs.com/r/tool-call.json

Files4 · source cached 10/9/2026, 2:40:18 PM

components/demos/tool-call-demo.tsx
"use client"

import { DemoVariants } from "@/components/demos/demo-variants"
import { RestartButton } from "@/components/demos/restart-button"
import {
  useScriptedTimeline,
  type TimelineStep,
} from "@/components/demos/use-scripted-timeline"
import {
  ToolCall,
  type ToolCallStatus,
} from "@/registry/default/tool-call/tool-call"

const steps: [TimelineStep<ToolCallStatus>, ...TimelineStep<ToolCallStatus>[]] =
  [
    { state: "pending", holdMs: 900 },
    { state: "running", holdMs: 2400 },
    { state: "success", holdMs: 0 },
  ]

const input = { pattern: "nullable email", path: "migrations/", limit: 5 }

function LiveRun() {
  const { state, elapsedMs, isFinished, restart, runId } =
    useScriptedTimeline(steps)

  return (
    <div className="grid gap-4">
      <ToolCall
        key={runId}
        name="search_files"
        status={state}
        durationMs={state === "pending" ? undefined : elapsedMs}
        input={input}
        output={
          isFinished ? (
            <p>
              2 matches in <code>0004_add_email_index.sql</code>
            </p>
          ) : undefined
        }
        defaultOpen
      />

      {isFinished ? <RestartButton onClick={restart} /> : null}
    </div>
  )
}

export function ToolCallDemo() {
  return (
    <DemoVariants
      label="Tool call state"
      variants={[
        { id: "live", label: "Live run", render: () => <LiveRun /> },
        {
          id: "queued",
          label: "Queued",
          render: () => (
            <ToolCall name="search_files" status="pending" input={input} />
          ),
        },
        {
          id: "error",
          label: "Failed",
          render: () => (
            <ToolCall
              name="write_file"
              status="error"
              input={{ path: "migrations/0004_add_email_index.sql" }}
              error="Permission denied. The migrations directory is read-only."
              durationMs={120}
              defaultOpen
            />
          ),
        },
      ]}
    />
  )
}
components/demos/demo-variants.tsx
"use client"

import * as React from "react"

export type DemoVariant = {
  id: string
  label: string
  render: () => React.ReactNode
}

export function DemoVariants({
  variants,
  label = "Demo variant",
}: {
  variants: [DemoVariant, ...DemoVariant[]]
  label?: string
}) {
  const [activeId, setActiveId] = React.useState(variants[0].id)
  const active =
    variants.find((variant) => variant.id === activeId) ?? variants[0]

  return (
    <div className="grid w-full justify-items-center gap-6">
      {/* Centres whatever the variant renders. Without this a demo that caps
          its own width sits against the left edge while the switch below it
          is centred, which reads as a mistake. */}
      <div className="flex w-full justify-center">{active.render()}</div>

      <div
        role="group"
        aria-label={label}
        className="border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1"
      >
        {variants.map((variant) => {
          const isActive = variant.id === active.id

          return (
            <button
              key={variant.id}
              type="button"
              aria-pressed={isActive}
              className={
                isActive
                  ? "bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold"
                  : "text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold"
              }
              onClick={() => setActiveId(variant.id)}
            >
              {variant.label}
            </button>
          )
        })}
      </div>
    </div>
  )
}
components/demos/restart-button.tsx
"use client"

import { RotateCcw } from "lucide-react"

export function RestartButton({ onClick }: { onClick: () => void }) {
  return (
    <button className="restore-button" type="button" onClick={onClick}>
      <RotateCcw aria-hidden="true" size={15} /> Replay
    </button>
  )
}
components/demos/use-scripted-timeline.ts
"use client"

import * as React from "react"

const TICK_MS = 100

export type TimelineStep<TState> = {
  state: TState
  holdMs: number
}

export function useScriptedTimeline<TState>(
  steps: [TimelineStep<TState>, ...TimelineStep<TState>[]]
) {
  const [index, setIndex] = React.useState(0)
  const [elapsedMs, setElapsedMs] = React.useState(0)
  const [runId, setRunId] = React.useState(0)

  const isFinished = index >= steps.length - 1

  React.useEffect(() => {
    if (isFinished) return

    const timer = window.setTimeout(
      () => setIndex((current) => current + 1),
      (steps[index] ?? steps[0]).holdMs
    )

    return () => window.clearTimeout(timer)
  }, [index, isFinished, steps])

  React.useEffect(() => {
    if (isFinished) return

    const timer = window.setInterval(
      () => setElapsedMs((current) => current + TICK_MS),
      TICK_MS
    )

    return () => window.clearInterval(timer)
  }, [isFinished])

  const restart = React.useCallback(() => {
    setIndex(0)
    setElapsedMs(0)
    setRunId((current) => current + 1)
  }, [])

  return {
    state: (steps[index] ?? steps[0]).state,
    elapsedMs,
    isFinished,
    restart,
    runId,
  }
}

More from mischief

Browse all components in this library →