StealThis .dev

Tool Call Card

A self-contained card for visualizing a single LLM tool call: it names the function, pretty-prints the arguments as syntax-highlighted JSON, and drives a pending to running to success or error state machine with an animated status pill. The returned result collapses into a disclosure panel, latency and token badges summarize the call cost, and a retry button re-runs failed or completed calls, with several seeded examples covering each state.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

The Tool Call Card renders one function invocation from an LLM the way an agent runtime would surface it: a monospace function name and a color-coded status pill up top, a pretty-printed and lightly syntax-highlighted JSON block of the arguments, and a collapsible result panel that reveals whatever the tool returned. Each card walks a real state machine — pending, running, success, or error — with the pill, spinner, and accent color all reacting to the current state, and a footer of badges reporting wall-clock latency and prompt/completion token counts.

Press Run on an idle card to watch it move through running into a resolved state, or hit Retry on a finished or failed card to replay the call with fresh latency. The disclosure panel is a real ARIA disclosure — keyboard operable with visible focus — and the result body can be copied to the clipboard in one click. Four seeded examples ship in different states (a successful weather lookup, a live-running database query, a failed HTTP request with an error payload, and an idle web search) so every branch of the machine is visible at once.

The demo showcases the browser Clipboard API (navigator.clipboard.writeText) for copying results, with a graceful document.execCommand fallback for insecure contexts, alongside requestAnimationFrame-timed latency counters and a hand-rolled ARIA disclosure so the collapse animation and state transitions stay fully under script control.