Tool Call
Shows an agent's function call moving from queued to running to done or failed.
Code
components/thinking-ui/tool-call.tsx
"use client";
import { AnimatePresence, motion } from "motion/react";
import { useState, type ReactNode } from "react";
import { useMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
/** `stopped`: the user stopped the turn before the tool finished. Neutral, not a failure. */
export type ToolCallStatus = "pending" | "running" | "success" | "error" | "stopped";
export type ToolCallProps = {
/** Tool or function name, e.g. `search_web`. */
name: string;
status: ToolCallStatus;
args?: Record<string, unknown>;
result?: ReactNode;
defaultOpen?: boolean;
className?: string;
};
const labels: Record<ToolCallStatus, string> = {
pending: "Queued",
running: "Running",
success: "Done",
error: "Failed",
stopped: "Stopped",
};
export function ToolCall({ name, status, args, result, defaultOpen = false, className }: ToolCallProps) {
const [open, setOpen] = useState(defaultOpen);
const m = useMotion();
const hasDetails = args != null || result != null;
return (
<div
className={cn(
"relative w-full overflow-hidden rounded-card border border-card-line bg-card text-sm shadow-card",
className,
)}
>
<button
type="button"
disabled={!hasDetails}
aria-expanded={hasDetails ? open : undefined}
onClick={() => setOpen((o) => !o)}
className="flex w-full items-center gap-2.5 px-3 py-2.5 text-left"
>
<StatusIcon status={status} />
<span className="truncate font-mono text-sm text-fg">{name}</span>
<span className="relative ml-auto text-xs text-fg-muted">
<AnimatePresence mode="popLayout" initial={false}>
<motion.span key={status} className="block" {...m.swap()}>
{labels[status]}
</motion.span>
</AnimatePresence>
</span>
{hasDetails && (
<motion.svg
aria-hidden
viewBox="0 0 16 16"
className="size-icon-sm text-fg-muted"
animate={{ rotate: open ? 180 : 0 }}
transition={m.spring("micro")}
>
<path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</motion.svg>
)}
</button>
<AnimatePresence initial={false}>
{open && hasDetails && (
<motion.div className="overflow-hidden" {...m.collapse()}>
<div className="space-y-2 border-t border-line-subtle px-3 py-2.5">
{args != null && (
<pre className="overflow-x-auto font-mono text-xs leading-relaxed text-fg-tertiary">
{JSON.stringify(args, null, 2)}
</pre>
)}
{result != null && <div className="text-xs text-fg-secondary">{result}</div>}
</div>
</motion.div>
)}
</AnimatePresence>
<AnimatePresence>
{status === "running" && (
<motion.span
aria-hidden
className="absolute inset-x-0 bottom-0 h-px overflow-hidden"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
<motion.span
className="block h-full w-1/3 bg-gradient-to-r from-transparent via-fill-contrast to-transparent"
initial={{ x: "-100%" }}
animate={{ x: "300%" }}
transition={{ duration: 1.2 * m.scale, ease: m.personality.ease.inOut, repeat: Infinity }}
/>
</motion.span>
)}
</AnimatePresence>
</div>
);
}
function StatusIcon({ status }: { status: ToolCallStatus }) {
const m = useMotion();
const pop = m.pop();
const draw = { initial: { pathLength: 0 }, animate: { pathLength: 1 }, transition: { ...m.tween("slow"), delay: m.stagger(1) } };
return (
// Every icon sits in the same grid cell, so the outgoing one crossfades in
// place: popLayout can't measure SVG elements and would stack them
<span className="relative grid size-icon shrink-0 place-items-center [&>*]:[grid-area:1/1]">
<AnimatePresence mode="popLayout" initial={false}>
{status === "pending" && (
<motion.svg key="pending" viewBox="0 0 16 16" className="size-icon text-fg-muted" {...pop}>
<circle cx="8" cy="8" r="6.25" fill="none" stroke="currentColor" strokeWidth="1.5" strokeDasharray="2 2.6" />
</motion.svg>
)}
{status === "running" && (
<motion.svg key="running" viewBox="0 0 16 16" className="size-icon text-fg" {...pop}>
<circle cx="8" cy="8" r="6.25" fill="none" stroke="var(--border-strong)" strokeWidth="1.5" />
<motion.circle
cx="8"
cy="8"
r="6.25"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeDasharray="10 40"
style={{ originX: "50%", originY: "50%" }}
animate={{ rotate: 360 }}
transition={{ duration: 0.8 * m.scale, ease: "linear", repeat: Infinity }}
/>
</motion.svg>
)}
{status === "success" && (
<motion.svg key="success" viewBox="0 0 16 16" className="size-icon text-success" {...pop}>
<circle cx="8" cy="8" r="7" fill="currentColor" />
<motion.path d="M5 8.2l2 2 4-4.2" fill="none" stroke="var(--text-on-status)" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...draw} />
</motion.svg>
)}
{status === "stopped" && (
<motion.svg key="stopped" viewBox="0 0 16 16" className="size-icon text-fg-muted" {...pop}>
<circle cx="8" cy="8" r="6.25" fill="none" stroke="currentColor" strokeWidth="1.5" />
<rect x="5.75" y="5.75" width="4.5" height="4.5" rx="1" fill="currentColor" />
</motion.svg>
)}
{status === "error" && (
<motion.svg key="error" viewBox="0 0 16 16" className="size-icon text-danger" {...pop}>
<circle cx="8" cy="8" r="7" fill="currentColor" />
<motion.path d="M5.75 5.75l4.5 4.5M10.25 5.75l-4.5 4.5" fill="none" stroke="var(--text-on-status)" strokeWidth="1.6" strokeLinecap="round" {...draw} />
</motion.svg>
)}
</AnimatePresence>
</span>
);
}Motion notes
- Each status has its own icon. They swap with scale and blur, and the check or cross draws itself.
- A thin light sweeps along the bottom edge while running, so there's motion without a big spinner.
- The status label slides up, so a change of status reads as forward progress.
Installation
- 1
Install dependencies
Terminalnpm install motion clsx tailwind-merge - 2
Add the design tokens and motion system (once per project)
Copy
styles/tokens/*,lib/motion.tsxandlib/utils.tsfrom Get started. - 3
Paste the source into components/thinking-ui/tool-call.tsx
Copy it from the Code tab, or use Copy prompt to let your coding agent do all of this.
Usage
Example
<ToolCall
name="search_web"
status="running"
args={{ query: "vector databases" }}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | — | Tool name, e.g. search_web. |
| status | "pending" | "running" | "success" | "error" | "stopped" | — | Current call state. stopped: the user ended the turn first; neutral, not a failure. |
| args | Record<string, unknown> | — | Arguments, shown as JSON when expanded. |
| result | ReactNode | — | Result, shown when expanded. |
| defaultOpen | boolean | false | Start expanded. |