AI tool calls
Sequential chat tool-call trace with live per-step timers that collapses into a summary row above the final recommendation.
pnpm dlx shadcn@latest add @haze/ai-tool-calls---
import { Calendar, Check, ChevronDown, LoaderCircle, RotateCcw, Search, SlidersHorizontal } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface ToolCallStep {
id: string;
label: string;
detail: string;
durationMs: number;
result: string;
icon: "search" | "calendar" | "filter";
}
interface Props {
id?: string;
heading?: string;
userPrompt?: string;
steps?: ToolCallStep[];
class?: string;
}
const {
id = "haze-ai-tool-calls",
heading = "Streaming tool calls",
userPrompt = "Find a quiet boutique hotel in Porto for Nov 14–16, under €200",
steps = [
{
id: "listings",
label: "Searching listings",
detail: "quiet hotels Ribeira Porto",
durationMs: 800,
result: "18 properties matched",
icon: "search",
},
{
id: "availability",
label: "Checking availability",
detail: "Nov 14–16 · 2 nights",
durationMs: 900,
result: "6 rooms under €200",
icon: "calendar",
},
{
id: "reviews",
label: "Filtering reviews",
detail: "noise score & transit",
durationMs: 700,
result: "3 quiet stays ranked",
icon: "filter",
},
],
class: className,
} = Astro.props;
const totalSec = (steps.reduce((acc, s) => acc + s.durationMs, 0) / 1000).toFixed(1);
---
<section aria-labelledby={`${id}-title`} data-haze-ai-tool-calls class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<h2 id={`${id}-title`} class="sr-only">{heading}</h2>
<div class="mx-auto max-w-md space-y-4">
{/* User bubble */}
<div class="flex justify-end">
<p class="max-w-[85%] rounded-2xl rounded-br-sm bg-muted px-4 py-2.5 text-sm/6 text-foreground">
{userPrompt}
</p>
</div>
{/* Borderless vertical stem tool trace */}
<details data-atc-details class="group">
<summary class="flex min-h-8 cursor-pointer list-none items-center gap-2.5 rounded-md text-sm/5 select-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
<span data-atc-header-spinner hidden class="inline-flex size-4 shrink-0 items-center justify-center text-muted-foreground" aria-hidden="true">
<LoaderCircle class="size-4 animate-spin" />
</span>
<span data-atc-header-done class="inline-flex size-4 shrink-0 items-center justify-center text-success" aria-hidden="true">
<Check class="size-4" />
</span>
<span data-atc-header-title class="font-semibold text-foreground">Used {steps.length} tools</span>
<span data-atc-header-time class="font-mono text-xs text-muted-foreground tabular-nums">· {totalSec}s</span>
<span data-atc-header-chevron class="inline-flex text-muted-foreground" aria-hidden="true">
<ChevronDown class="size-3.5 transition-transform duration-150 ease-snappy group-open:rotate-180" />
</span>
</summary>
<ol role="list" class="mt-2 ml-2 space-y-2.5 border-l border-border pl-4">
{
steps.map((step) => (
<li
data-atc-row={step.id}
data-duration={String(step.durationMs)}
data-state="done"
class="flex items-baseline justify-between gap-3 text-sm/5"
>
<div class="flex min-w-0 flex-1 items-baseline gap-2">
<span data-atc-step-icon class="inline-flex shrink-0 translate-y-0.5 text-foreground" aria-hidden="true">
{step.icon === "search" && <Search class="size-3.5" />}
{step.icon === "calendar" && <Calendar class="size-3.5" />}
{step.icon === "filter" && <SlidersHorizontal class="size-3.5" />}
</span>
<span class="shrink-0 font-medium text-foreground">{step.label}</span>
<span class="min-w-0 truncate font-mono text-xs text-muted-foreground">{step.detail}</span>
</div>
<span data-atc-timer class="shrink-0 font-mono text-xs text-muted-foreground tabular-nums">
{(step.durationMs / 1000).toFixed(1)}s
</span>
</li>
))
}
</ol>
</details>
{/* Clean borderless assistant reply */}
<div data-atc-answer class="space-y-3 text-sm/6 text-foreground animate-rise">
<p>
<span class="font-semibold">Casa do Miradouro</span> in Cedofeita is the quietest match for Nov 14–16 at
<span class="font-medium tabular-nums"> €178/night</span> (€356 total). Guests rate it 9.4 for quietness thanks to its double-glazed courtyard rooms, and it is a seven-minute walk from the Ribeira tram with free cancellation.
</p>
<div>
<button
type="button"
data-atc-replay
class="inline-flex min-h-8 cursor-pointer items-center gap-1.5 rounded-md text-xs font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<RotateCcw class="size-3" aria-hidden="true" />
Replay
</button>
</div>
</div>
</div>
<p data-atc-status role="status" class="sr-only"></p>
</section>
<script>
function initAiToolCalls() {
document.querySelectorAll<HTMLElement>("[data-haze-ai-tool-calls]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const details = root.querySelector<HTMLDetailsElement>("[data-atc-details]");
const headerTitle = root.querySelector<HTMLElement>("[data-atc-header-title]");
const headerTime = root.querySelector<HTMLElement>("[data-atc-header-time]");
const headerSpinner = root.querySelector<HTMLElement>("[data-atc-header-spinner]");
const headerDone = root.querySelector<HTMLElement>("[data-atc-header-done]");
const headerChevron = root.querySelector<HTMLElement>("[data-atc-header-chevron]");
const answer = root.querySelector<HTMLElement>("[data-atc-answer]");
const replayBtn = root.querySelector<HTMLButtonElement>("[data-atc-replay]");
const status = root.querySelector<HTMLElement>("[data-atc-status]");
const rows = Array.from(root.querySelectorAll<HTMLElement>("[data-atc-row]"));
if (!details || !headerTitle || !headerTime || !headerSpinner || !headerDone || !answer || !rows.length) return;
let runId = 0;
let frame = 0;
const setRowState = (row: HTMLElement, state: "pending" | "running" | "done", elapsedSec: string) => {
const prev = row.getAttribute("data-state");
row.setAttribute("data-state", state);
row.hidden = state === "pending";
if (prev === "pending" && state !== "pending") {
row.classList.add("animate-rise");
}
const iconWrap = row.querySelector<HTMLElement>("[data-atc-step-icon]");
const timer = row.querySelector<HTMLElement>("[data-atc-timer]");
if (iconWrap) {
iconWrap.className =
state === "running"
? "inline-flex shrink-0 translate-y-0.5 text-foreground"
: "inline-flex shrink-0 translate-y-0.5 text-muted-foreground";
}
if (timer) timer.textContent = `${elapsedSec}s`;
};
const finishImmediate = (announce: boolean) => {
cancelAnimationFrame(frame);
let totalMs = 0;
rows.forEach((row) => {
const ms = Number(row.dataset.duration ?? 800);
totalMs += ms;
setRowState(row, "done", (ms / 1000).toFixed(1));
});
const totalStr = (totalMs / 1000).toFixed(1);
headerSpinner.hidden = true;
headerDone.hidden = false;
if (headerChevron) headerChevron.hidden = false;
headerTitle.textContent = `Used ${rows.length} tools`;
headerTime.textContent = `\u00b7 ${totalStr}s`;
details.open = false;
answer.hidden = false;
if (announce && status) {
status.textContent = `Used ${rows.length} tools in ${totalStr}s. Recommendation ready.`;
}
};
const play = (announce: boolean) => {
const myRun = ++runId;
cancelAnimationFrame(frame);
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
finishImmediate(announce);
return;
}
const durations = rows.map((row) => Number(row.dataset.duration ?? 800));
const totalMs = durations.reduce((a, b) => a + b, 0);
const start = performance.now();
details.open = true;
answer.hidden = true;
headerSpinner.hidden = false;
headerDone.hidden = true;
if (headerChevron) headerChevron.hidden = true;
headerTitle.textContent = "Working";
headerTime.textContent = "0.0s";
rows.forEach((row) => {
row.classList.remove("animate-rise");
setRowState(row, "pending", "0.0");
});
if (announce && status) status.textContent = "Running tool calls for Porto hotel search.";
const step = (now: number) => {
if (myRun !== runId) return;
const elapsed = now - start;
const clamped = Math.min(elapsed, totalMs);
headerTime.textContent = `${(clamped / 1000).toFixed(1)}s`;
let offset = 0;
rows.forEach((row, idx) => {
const dur = durations[idx];
if (elapsed < offset) {
setRowState(row, "pending", "0.0");
} else if (elapsed < offset + dur) {
setRowState(row, "running", ((elapsed - offset) / 1000).toFixed(1));
} else {
setRowState(row, "done", (dur / 1000).toFixed(1));
}
offset += dur;
});
if (elapsed < totalMs) {
frame = requestAnimationFrame(step);
} else {
finishImmediate(true);
}
};
frame = requestAnimationFrame(step);
};
replayBtn?.addEventListener("click", () => play(true));
play(false);
});
}
initAiToolCalls();
document.addEventListener("astro:page-load", initAiToolCalls);
</script>When to use
- Streaming multi-step search, availability or filter tool calls inside an assistant reply
- Collapsing finished tool logs into a single expandable summary line once the final answer arrives
- Letting users inspect individual tool timings or replay the full execution sequence
When not to use
- Pausing execution to request human permission before a tool runs; use ai-tool-approval
- Showing an indeterminate loading shimmer without discrete tool steps; use ai-loading
Installation
Add the Haze registry to components.json once, then install AI tool calls with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/ai-tool-callsnpx shadcn@latest add @haze/ai-tool-callsyarn dlx shadcn@latest add @haze/ai-tool-callsbunx --bun shadcn@latest add @haze/ai-tool-callsFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-ai-tool-calls" | Unique prefix for section heading IDs. |
| heading | string | "Streaming tool calls" | Card header title. |
| userPrompt | string | "Find a quiet boutique hotel in Porto for Nov 14–16 under €200" | User question displayed above the tool trace. |
| steps | ToolCallStep[] | 3 sequential hotel search steps | Ordered tool calls with labels, queries, durations and summary results. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move between the Replay button and the expandable tool summary header
- EnterSpace
- Toggle the tool-call trace list or replay the streaming sequence
Accessibility
- Tool traces live inside a native details disclosure so keyboard and screen-reader users can expand or collapse finished steps at any time.
- Reduced-motion preferences skip intermediate timer frames and settle immediately into the completed summary while announcing completion via role="status".
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "AI tool calls" with `npx shadcn@latest add @haze/ai-tool-calls`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AiToolCalls from "@/components/haze/blocks/ai-tool-calls.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/ai-tool-calls.md
Customize with real content
Adapt the Haze ai-tool-calls block for our product. Replace the demo values of these props with our real content: id, heading, userPrompt, steps, class. Keep the layout, the heading level rules and these accessibility details: Tool traces live inside a native details disclosure so keyboard and screen-reader users can expand or collapse finished steps at any time. Reduced-motion preferences skip intermediate timer frames and settle immediately into the completed summary while announcing completion via role="status". Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using ai-tool-calls, check it fits: use it when streaming multi-step search, availability or filter tool calls inside an assistant reply; collapsing finished tool logs into a single expandable summary line once the final answer arrives; letting users inspect individual tool timings or replay the full execution sequence. Avoid it when pausing execution to request human permission before a tool runs; use ai-tool-approval; showing an indeterminate loading shimmer without discrete tool steps; use ai-loading. Alternatives: @haze/ai-loading, @haze/ai-tool-approval, @haze/agent-run.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.