# ToolCall

Compact, expandable step for tool and function invocations in chat and agent streams. Shows a status mark, a human summary, an optional identifier and duration, and expands to reveal `input`, `output` or custom details.

**Dependencies:** npm: 1 direct, 3 total; registry: 4 direct, 4 total.

## Usage

### When to use

- Display individual tool or function invocations in an assistant stream with status, duration and expandable details.
- Let readers inspect raw arguments and outputs on demand without cluttering the conversation.

### When not to use

- General chronological events such as an order history or activity feed. Use Timeline.
- Standalone syntax-highlighted code with a copy button. Use CodeBlock.
- General page FAQ sections or form disclosures. Use Accordion.

## Variants

### status

Invocation state: `running` shows a small Spinner, `success` shows a check, `error` shows a warning triangle.

Values: `running`, `success`, `error`. Default: `success`.

## Examples

### Expanded tool call

Completed step opened by default to inspect its input query and output summary.

```tsx
<ToolCall defaultOpen status="success" title="Search documentation" tool="search_docs" duration="420ms" input="query: color-accent" output="Found 4 matching pages." className="max-w-md" />
```

### Running and failed steps

Active invocation without details stays static while a failed step expands to show the error output.

```tsx
<div className="flex w-full max-w-md flex-col gap-sm">
  <ToolCall status="running" title="Indexing files" tool="index_workspace" />
  <ToolCall defaultOpen status="error" title="Fetch release notes" tool="fetch_url" duration="1.8s" input="https://werewolf-ui.dev/releases" output="Request timed out after 1800ms" />
</div>
```

### Static step

Without input, output or children, no chevron or disclosure button is rendered.

```tsx
<ToolCall status="success" title="Read tokens.css" tool="read_file" duration="18ms" className="max-w-md" />
```

## Do and don't

### Do

- Write a plain human summary in title and keep the raw function name in tool.
- Omit input, output and children when there is nothing to inspect so the row stays static.
- Translate labels when the interface is not in English.

### Don't

- Do not nest ToolCall inside a raised Card; its sunken surface sits cleanly on the page or in a message stream.
- Do not leave a step in running status after the stream stops.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `title` (required) | `node` |  |  | Human-readable summary of the step, such as Search documentation. |
| `tool` | `string` |  |  | Optional technical or function identifier shown in monospace tertiary text, such as `search_docs`. |
| `status` | `enum` | `running`, `success`, `error` | `success` | Invocation state: `running` shows a small Spinner, `success` shows a check, `error` shows a warning triangle. |
| `duration` | `string` |  |  | Optional formatted elapsed time shown at the trailing edge, such as `420ms`. |
| `input` | `node` |  |  | Optional arguments or query payload shown inside the expanded panel. |
| `output` | `node` |  |  | Optional result or error message shown inside the expanded panel. |
| `children` | `node` |  |  | Optional custom detail body rendered inside the expanded panel. |
| `open` | `boolean` |  |  | Controlled open state. Pair with `onOpenChange`. |
| `defaultOpen` | `boolean` |  | `false` | Initial open state when uncontrolled. |
| `onOpenChange` | `(open: boolean) => void` |  |  | Called with the next open state when the user toggles the header. |
| `labels` | `{ input?: string; output?: string; running?: string; success?: string; error?: string }` |  |  | Section and screen-reader status labels. Defaults: `Input`, `Output`, `Running`, `Completed`, `Failed`. |

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `title` | yes | Human-readable summary of the tool invocation. |
| `input` | no | Optional arguments or query payload. |
| `output` | no | Optional result or error message. |
| `children` | no | Optional custom detail content. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | The outer container: sunken fill, border and container corners, without drop shadows. |
| `header` | Summary row holding the status mark, title, optional tool name, duration and chevron. A button when expandable, static otherwise. |
| `hitArea` | Transparent ::before centered on the header button, at least `size-target-min` (24px on mouse, 44px on touch). |
| `status` | Status mark at the start: a small Spinner while running, a check in `color-text-success` on success, a warning triangle in `color-text-danger` on error. |
| `title` | Human-readable summary in medium primary text. |
| `tool` | Optional function identifier in monospace tertiary text. |
| `duration` | Optional elapsed time at the trailing edge in monospace tertiary text with tabular digits. |
| `chevron` | Turning 16px right chevron shown when the step can expand. |
| `content` | Collapsible panel below the header that opens with `duration-medium` and `ease-enter` and exits with `animate-exit-collapse`. |
| `body` | Inner wrapper carrying the top divider and `spacing-md` padding so the collapsing container shrinks cleanly to zero. |
| `label` | Section label (`Input`, `Output`) in small medium secondary text. |
| `payload` | Monospace block on page fill with inner corners for arguments or output; switches to danger tokens on error. |

## Accessibility

Role: `generic`

| Keys | Action |
| --- | --- |
| `Tab` | Moves focus to the header button when `input`, `output` or `children` are present, then to any controls inside the expanded panel. |
| `Enter, Space` | On the header button, expands or collapses the detail panel. |

- When `input`, `output` or `children` is omitted, the header renders as static text without a button or chevron.
- Status icons are hidden from screen readers (`aria-hidden`) and paired with visually hidden status words (`Running`, `Completed`, `Failed`), customizable via `labels`.

## Install

```bash
npx werewolf-ui add https://www.werewolf-ui.dev/r/tool-call.json
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.
