# Action receipts

> What the agent actually did, one quiet line each, with Undo while a ring drains. Several stack into one.

Agents that act on people’s behalf need to show their work and offer a way back. Each action your tools perform becomes a quiet line: what happened and where, with Undo and a small ring that drains while the window is open. Undo is one button that never gets swapped out: the ring blurs into a spinner as it morphs to "Undoing", then a strike draws itself across the line and it settles on "Undone". When the window closes, Undo folds away. Failures say why and offer Retry. From three actions on, they fold into "4 actions · Undo all", whose counts roll as things change.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/action-receipt.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/action-receipt
- Registry item (source): https://hairlineui.com/r/action-receipt.json

## Usage

```tsx
import { ActionReceipts } from "@/components/action-receipt";

<ActionReceipts
  actions={[{ id: "evt_1", title: "Added “Soft launch” to Saturday", detail: "Calendar · 9:00 am", undoUntil: Date.now() + 10_000 }]}
  onUndo={(id) => undoAction(id)}
/>
```

## With the AI SDK

```tsx
// Server: tools return a receipt, including how long they can be undone
const addEvent = tool({
  description: "Add an event to the user's calendar",
  inputSchema: z.object({ title: z.string(), start: z.string() }),
  execute: async ({ title, start }) => {
    const event = await calendar.create({ title, start });
    return { id: event.id, title: `Added “${title}” to ${formatDay(start)}`, detail: "Calendar", undoUntil: Date.now() + 10_000 };
  },
});

// Client: every finished tool call in the message becomes a receipt
import type { UIMessage } from "ai";
import { ActionReceipts, type Receipt } from "@/components/action-receipt";

function Receipts({ message, undone }: { message: UIMessage; undone: Set<string> }) {
  const actions: Receipt[] = message.parts.flatMap((p) => {
    if (!p.type.startsWith("tool-") || !("state" in p)) return [];
    if (p.state === "output-error") return [{ id: p.toolCallId, title: "Couldn’t finish an action", status: "failed", error: p.errorText }];
    if (p.state !== "output-available") return [];
    const r = p.output as Receipt;
    return [{ ...r, status: undone.has(r.id) ? "undone" : "done" }];
  });
  if (!actions.length) return null;
  return <ActionReceipts actions={actions} onUndo={(id) => fetch(`/api/undo/${id}`, { method: "POST" })} />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `actions` | `{ id; title; detail?; icon?; status?; error?; undoUntil? }[]` | – | One per action. status is "done", "undoing", "undone" or "failed"; undoUntil (ms) enables Undo. |
| `onUndo` | `(id) => void \| Promise<void>` | – | Shows Undo while the window is open, with a spinner until the promise settles. Set the action’s status to "undone" after. |
| `onUndoAll` | `() => void \| Promise<void>` | – | For the stacked "Undo all"; defaults to calling onUndo for each undoable action. |
| `onRetry` | `(id) => void` | – | Shows Retry on failed actions. |
| `stackFrom` | `number` | `3` | Fold into a summary from this many actions; 0 never folds. |
| `undoWindow` | `number` | `10000` | Length of the undo window (ms), so the ring drains at the right pace. |

## States

- **done**: Icon, what happened and where. Undo with a ring that drains until undoUntil, then Undo folds away (420ms).
- **undoing**: The ring blurs into a spinner and "Undo" morphs to "Undoing" while your onUndo promise runs.
- **undone**: A strike draws itself across the title (480ms) as it fades to muted; the button settles on "Undone".
- **failed**: The icon swaps to a red cross, the reason replaces the detail, and the button reads Retry.
- **stacked**: From stackFrom actions: overlapping icons and "4 actions · 1 undone", where counts roll and parts open in as they apply. Undo all spins and morphs to "Undoing all" while it runs.

## What it handles

An agent that acts for people loses their trust the first time something changes and nobody can see it. This puts the action and the way back into the conversation, where the person is already looking.

- **Every action is a line**: What happened and where, with an icon, as soon as your tool finishes.
- **Undo for a limited time**: A small ring drains while the window is open, then Undo folds away. Your server still decides what can be undone.
- **Undo shows its progress**: Undo becomes Undoing with a spinner, then a strike draws across the line and it reads Undone.
- **Failures say why**: A failed action shows the reason in place of the detail and offers Retry.
- **Many actions fold into one**: From three actions on they become “4 actions · Undo all”, with the counts updating as things change.
- **Labelled for screen readers**: Each Undo button names its action, and undoing, undone and failures are announced.

## Replaces

an undo toast, a countdown timer, an activity log row, a Retry handler, a bulk-undo summary

## Where it fits

- **AI agent chats**: Show each thing the agent did, such as sending an email or moving a file, as a line the person can check.
- **Calendar and inbox assistants**: Assistants that change real data, where a wrong action needs a quick way back.
- **Automation run logs**: After a workflow runs, list what it changed, with a short window to undo each step.
- **Bulk actions**: “Archived 12 customers” with Undo all, instead of a confirm dialog before the fact.

## Notes

- Undo buttons are labelled with the action ("Undo: Added “Soft launch” to Saturday"); undoing, undone and failures are announced.
- The ring drains with a CSS animation, so nothing re-renders every frame; Undo folds away exactly when the window closes, and the ring pauses once it has faded out.
- Installs Number roll and Text morph. With reduced motion, states change in place.
- Colour is never the only signal: failed lines show the reason, and undone lines are struck through and labelled.
- Always enforce the undo window on the server too; the ring only shows it.

License: MIT (https://hairlineui.com/license#components)
