aiellie

Search

Find a component, template or page

GitHub
Components

Tool Call

A tool the model called, folded behind one row that names it and says whether it is queued, waiting on approval, running, done or failed, opening to show what went in and came out.

Run pnpm test?

Command

pnpm test
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/tool-call"

shadcn needs the @aiellie registry in components.json first. npx aiellie add tool-call adds it on its first run, then installs the same way.

Tool Call shows a tool the model called as one quiet row: what it called, the one detail worth reading, like the query, and whether it's queued, waiting on approval, running, done or failed. The row opens to show what went in and what came back. A call that needs approval asks for it under the row.

Getting started

  1. Show a call

    components/search-call.tsx
    import { Globe02Icon } from "@hugeicons/core-free-icons"
    
    import {
      ToolCall,
      ToolCallCode,
      ToolCallContent,
      ToolCallSection,
      ToolCallTrigger,
    } from "@/components/aiellie/tool-call"
    
    export function SearchCall({ query, results }: { query: string; results: unknown }) {
      return (
        <ToolCall status="done">
          <ToolCallTrigger icon={Globe02Icon} name="Searched the web" summary={query} />
          <ToolCallContent>
            <ToolCallSection title="Output">
              <ToolCallCode value={results} />
            </ToolCallSection>
          </ToolCallContent>
        </ToolCall>
      )
    }
  2. Map the AI SDK's tool parts

    A tool part's state maps onto status. ToolCallCode shows a string as it is and anything else as JSON.

    import { getToolOrDynamicToolName, isToolUIPart } from "ai"
    
    const STATUS = {
      "input-streaming": "pending",
      "input-available": "running",
      "approval-requested": "awaiting",
      "approval-responded": "running",
      "output-available": "done",
      "output-error": "error",
      "output-denied": "error",
    } as const
    
    {message.parts.filter(isToolUIPart).map((part) => (
      <ToolCall key={part.toolCallId} status={STATUS[part.state] ?? "done"}>
        <ToolCallTrigger name={getToolOrDynamicToolName(part)} />
        <ToolCallContent>
          <ToolCallSection title="Input">
            <ToolCallCode value={part.input} />
          </ToolCallSection>
          {part.output ? (
            <ToolCallSection title="Output">
              <ToolCallCode value={part.output} />
            </ToolCallSection>
          ) : null}
        </ToolCallContent>
      </ToolCall>
    ))}

Anatomy

<div data-slot="tool-call" data-status="pending | awaiting | running | done | error">
  <button data-slot="tool-call-trigger" /> {/* icon, name, summary, status, chevron */}
  <div data-slot="tool-call-approval" /> {/* optional, Deny and Allow */}
  <div data-slot="tool-call-content">
    <section data-slot="tool-call-section">
      <h4 /> <pre data-slot="tool-call-code" />
    </section>
  </div>
</div>

It's a Base UI collapsible, so open, defaultOpen and onOpenChange work as they do there. The panel folds at 280 ms and sits beside a hairline on the start side, like the thoughts in Reasoning.

While it runs the name shimmers and a pulsing live dot follows it. Done is a tick; failed is a destructive mark with the word Failed; waiting says Needs approval. The status is read out after the name, so it never rests on the mark alone.

Examples

A call that failed

Show what went wrong in a section of its own.

Input

{
  "path": "app/missing.tsx"
}

Error

ENOENT: no such file or directory

Ask before it runs

Put ToolCallApproval under the trigger while the call is awaiting, and move the status on when the person answers.

<ToolCall status={status}>
  <ToolCallTrigger name="Run" summary="pnpm test" />
  {status === "awaiting" ? (
    <ToolCallApproval
      onApprove={() => approve(call.id)}
      onDeny={() => deny(call.id)}
    />
  ) : null}
</ToolCall>

Your own words

labels renames any status.

<ToolCallTrigger name="Deploy" labels={{ awaiting: "Waiting for you" }} />

API reference

ToolCall

PropTypeDefaultDescription
status"pending" | "awaiting" | "running" | "done" | "error""done"Where the call is.

All other Base UI Collapsible.Root props are forwarded.

ToolCallTrigger

PropTypeDefaultDescription
nameReactNoderequiredWhat was called.
summaryReactNodeThe one detail worth reading without opening it.
iconIconSvgElementa wrenchA Hugeicons glyph.
labelsPartial<Record<ToolCallStatus, string>>Words of your own for each status.

ToolCallSection

PropTypeDefaultDescription
titleReactNoderequiredLike "Input" or "Output".

ToolCallCode

PropTypeDefaultDescription
valueunknownrequiredA string shows as it is; anything else as JSON.

ToolCallApproval

PropTypeDefaultDescription
onApprove() => voidrequired
onDeny() => voidrequired
approveLabelstring"Allow"
denyLabelstring"Deny"
childrenReactNode"Allow this tool to run?"The question.