Components
ApprovalCard
Human-in-the-loop approval: what will run, how risky it is, and deny with a reason.
Example
Approval required
High riskRun command
Installs a package from the npm registry and updates package.json and pnpm-lock.yaml.
High risk. Runs pnpm add @upstash/ratelimit in ~/acme/chat-app. A lasting decision covers run_command with command pnpm add*.
Interactive, and the same on the components page. Try the keyboard below on it.
Installation
npm i signoff-ui aiimport {
ApprovalCard,
ToolApprovalCard,
ToolApprovalBatch,
isToolPart,
setToolInput,
useApprovalPolicy,
type ApprovalChoice,
} from 'signoff-ui';
// Once per app (with Tailwind v4: @import 'signoff-ui/tailwind.css'; in your CSS)
import 'signoff-ui/styles.css';npx shadcn@latest add https://signoff-ui.vercel.app/r/approval-card.jsonimport { ApprovalCard, ToolApprovalCard, ToolApprovalBatch, type ApprovalChoice } from '@/components/signoff-ui/approval-card';
import { useApprovalPolicy } from '@/components/signoff-ui/use-approval-policy';
import { isToolPart } from '@/components/signoff-ui/lib/ai';
import { setToolInput } from '@/components/signoff-ui/lib/policy';The styles are once per app; Getting started has the Tailwind v4 and plain CSS options.
Usage
import { useChat } from '@ai-sdk/react';
import { useState } from 'react';
// Bound to the AI SDK tool parts in the approval flow, with rules from useApprovalPolicy. It
// renders nothing for a call that needs no approval.
export function Approvals() {
const { messages, setMessages, addToolApprovalResponse } = useChat();
const policy = useApprovalPolicy();
return messages.flatMap((m) =>
m.parts.filter(isToolPart).map((part) => (
<ToolApprovalCard
key={part.toolCallId}
part={part}
onRespond={addToolApprovalResponse}
policy={policy}
// Edit the arguments before approving (AI SDK 7: the call runs with the edited input).
onEditInput={(id, input) => setMessages((all) => setToolInput(all, id, input))}
risk="high"
/>
)),
);
}
// Or on its own, with every choice. The card shows the outcome you pass back as `status`.
export function RunCommandApproval() {
const [choice, setChoice] = useState<ApprovalChoice>();
return (
<ApprovalCard
toolName="run_command"
input={{ command: 'pnpm add @upstash/ratelimit' }}
risk="high"
decisions={['allow-once', 'allow-session', 'allow-always', 'deny-once', 'deny-always']}
editable
status={!choice ? 'pending' : choice.decision.startsWith('allow') ? 'approved' : 'denied'}
decision={choice?.decision}
reason={choice?.reason}
// { decision, reason, input, args }: keep it for the outcome, and send it on to your agent.
onDecide={setChoice}
/>
);
}How it works
Human-in-the-loop approval with a command or argument preview, a risk level when you give one (without risk, no badge rather than a guess), and deny with feedback. Y and N work while focus is in the card; ⌘ or Ctrl + Enter approves, optionally page-wide. critical actions need a second, confirming press.
A call with a command shows it as a command line, with its cwd above it, and every other argument as JSON below it: { command: 'npm test', env: { NODE_OPTIONS: '…' } } shows the env it runs with, not only npm test. Any other input shows as JSON.
Each pending approval sends one decision: a double click, or Y then N, is ignored until status changes, the handler's promise settles or the handler throws. ToolApprovalCard binds the card to a tool part and to addToolApprovalResponse, including the denial reason, and renders nothing for calls that need no approval.
Decisions that a toolApproval rule makes on its own (approval.isAutomatic) never prompt or take focus, and read "Auto-approved" or "Blocked by policy" rather than as a person's decision. A custom preview is your content: with styles.css, the kit's rules don't reach into it, and the shortcuts don't act on keys pressed in it, or in a menu it opens in a portal, so its controls keep their keys. With globalShortcut, ⌘ or Ctrl + Enter still approves from it, as from anywhere on the page but a text field.
Once, for the session or always
decisions sets the choices: allow-once, allow-session, allow-always, deny-once and deny-always. The default is Approve and Deny, once. A lasting choice says what it will cover: the tool, and argument patterns the person can edit. For a command, the pattern is its program and subcommand (npm test*), or the whole command when it has no subcommand or runs what its arguments say (rm -rf build, node -e "…"); for other calls, it starts at each argument as it is. "Any arguments" covers every call of the tool. onDecide receives { decision, reason, input, args }; when you pass it, onApprove and onDeny are not called. With a policy from useApprovalPolicy, ToolApprovalCard offers every choice, records the rule a person makes, and answers a call a rule already covers without showing a card. Once answered, that call reads "Allowed by your rule" and shows the rule.
Edit the arguments, then approve
With editable (on ApprovalCard) or onEditInput (on ToolApprovalCard), "Edit arguments" opens the arguments for editing. An object of strings, numbers and booleans gets a form; any other input gets JSON, which must parse before anything can be approved. The edited input goes out with the approval, with the editor open or closed: "Done editing" closes the editor and keeps the edit, and the card then shows the edited arguments, in its own preview in place of a custom preview, with the note "Edited: approving runs the new arguments." "Undo edits" drops the edit. While the JSON doesn't parse, "Done editing" leaves the editor open with its error. An edit belongs to the call it was made for: new input, or a new status, drops it. ToolApprovalCard offers editing only with onEditInput, the function that applies the edit, so an edit approved on its card reaches the agent. With AI SDK 7, onEditInput={(id, input) => setMessages((m) => setToolInput(m, id, input))} puts the edited input in the messages; the server runs the call with it after checking it against the tool's schema and its toolApproval again. With useAgUiAgent, pass its editInput, and the approval's resume payload carries the edit as editedArgs, the field AG-UI agents read.
Approve all
ToolApprovalBatch answers every approval a run is waiting on at once, such as parallel calls; with a critical one among them it asks for a second press. It answers with the agent's arguments and doesn't see an edit made on a card, so approve an edited call on its own card. AgentMessage shows it above its cards when two or more approvals are waiting.
Held keys, focus and the page-wide shortcut
A held key decides once: its repeats don't answer again or confirm a critical action, and neither does Enter held on a focused button, Approve all included, or the second click of a double click. The first press on a critical action stays armed, with no time limit, until the second press, Escape, or focus leaving the card (or Approve all); the Escape that closes the reason field closes only the field. The press is for the arguments it would approve, so new ones from the agent, or an edit made after it, need a new first press. autoFocus moves focus to a card that arrives pending, but not out of a text field, so the letters someone is typing in a chat composer don't land on the card as shortcuts. globalShortcut approves with ⌘ or Ctrl + Enter from anywhere on the page except a text field, where the keys stay the field's, such as a chat composer's send; the text fields of the card's own argument editor count too. A press it arms on a critical card from outside the card ends when focus or a click goes anywhere but the card, so after typing in a composer and sending, the next ⌘/Ctrl+Enter is a first press again. With several pending, as when AgentMessage's approvalProps turns it on for parallel calls, the keys answer one card: the one they're pressed in, or else the latest to ask. When a newer card takes them over, a press they armed on a critical card from outside it is dropped.
API reference
Generated from the types the package ships, so it matches the version you install.
ApprovalCard
Human-in-the-loop approval for a pending agent action. Shows what will run,
how risky it is, and lets the user approve or deny by mouse or keyboard, once,
for the session or always, with the arguments edited first when editable.
Critical actions require a second confirming press: the first stays armed, with no time limit,
until Escape, or focus or a click goes outside the card.
The card is a group named by its title, not a landmark, so a run with many approvals doesn't
fill landmark navigation; pass role="region" to make it one.
Props
toolNamerequiredstringName of the tool or action that needs approval.
titleReactNodeHeading. Defaults to the humanized tool name.
descriptionReactNodeWhy the agent wants to do this, e.g. the SDK's
approval.requestReason.inputunknownArguments the action will run with.
riskRiskLevelHow risky the action is, shown as a badge. Without it the card shows no risk level.
previewReactNodeCustom arguments preview. Defaults to a command line for
{ command }inputs, with any other arguments as JSON below it, else JSON. Your content, likeAgentMessage'srenderTool: keys pressed in it, or in a menu it opens in a portal, are yours, not the card's shortcuts. Once the person edits the arguments (editable), the card shows the edited ones in its default preview instead.statusApprovalStatusDefault'pending''denied' | 'pending' | 'approved'Where the approval stands: the card offers the choices while
pending, and shows the outcome you pass back. Approve and deny fire once: further presses (a double click, Y then N) are ignored untilstatuschanges, the promise the handler returned settles, or the handler throws.reasonstringReason recorded with the decision, shown once resolved.
automaticbooleanDefaultfalseA policy, not a person, made the decision (the SDK's
approval.isAutomatic): once resolved, the card reads "Auto-approved" or "Blocked by policy" instead of "Approved" or "Denied".decisionApprovalDecisionHow the resolved decision was made, to say so:
allow-sessionreads "Approved for this session",deny-always"Always denied", and so on.decidedByRulestringThe rule that decided, in words, shown once resolved: "Allowed by your rule: …".
decisionsreadonly ApprovalDecision[]Default['allow-once', 'deny-once']The choices to offer, from
allow-once,allow-session,allow-always,deny-onceanddeny-always. Session and always decisions come toonDecidewith the arguments their rule covers.onDecide(choice: ApprovalChoice) => void | PromiseLike<void>Every decision with what goes with it: its scope, the reason, edited arguments and the rule's argument patterns. When you pass it,
onApproveandonDenyare not called. May return a promise.onApprove() => void | PromiseLike<void>Fires once per decision: see
status. May return a promise. Not called withonDecide.onDeny(reason?: string) => void | PromiseLike<void>Fires once per decision: see
status. May return a promise. Not called withonDecide.editablebooleanDefaultfalseLet the person edit the arguments before approving: a form for an object of strings, numbers and booleans, JSON otherwise. The edited input comes to
onDecide: "Done editing" closes the editor and keeps the edit, "Undo edits" drops it. An edit is for theinputit was made against: newinput, or a newstatus, drops it.ruleArgsRecord<string, string>The argument patterns a session or always rule starts with. Default: from the input.
ruleScopebooleanDefaulttrueShow which calls a session or always decision covers, editable. Pass
falsewhen the agent keeps what "always" means, as with ACP'sallow_always: the card then shows no argument patterns, and the decision comes withoutargs.shortcutsbooleanDefaulttrueY / N shortcuts while focus is inside the card (and S, A, Shift+N when offered), but not in a custom
preview.globalShortcutbooleanDefaultfalseAlso approve with ⌘/Ctrl+Enter from anywhere on the page while pending, except a text field, where the keys are the field's (a chat composer's send, say). With several cards pending, one answers: the card the keys are pressed in, else the latest to ask. A critical press armed from outside the card ends when focus or a click goes anywhere but the card.
autoFocusbooleanDefaultfalseMove focus to the card when it mounts in the pending state, unless focus is in a text field: the person's next keys would land on the card as shortcuts.
allowReasonbooleanDefaulttrueOffer an optional free-text reason when denying.
reasonPlaceholderstringDefault'What should the agent do instead?'Placeholder of the reason field. Without one, the card uses
labels.approvalCard.reasonPlaceholder.approveLabelstringDefault'Approve'The approve button's text. Without one, the card uses
labels.approvalCard.approve.denyLabelstringDefault'Deny'The deny button's text. Without one, the card uses
labels.approvalCard.deny.headingLevelHeadingLevelDefault3Heading level for the title, to fit your document outline.
labelsSignoffLabelsInputWords to use instead of the English defaults: see
SignoffLabelsProvider.
Other props go to the root <section>: className (merged with tailwind-merge), id, aria-*, data-* and event handlers.
ToolApprovalCard
ApprovalCard bound to an AI SDK tool part in the approval flow. Renders nothing for parts without
one, or while a policy's automatic decision is still arriving: nobody needs to act on it.
Props
partrequiredToolPartThe AI SDK tool part to answer, from
message.parts(isToolPartfinds them). The card reads the tool's name, input, approval request and outcome from it, and renders nothing for a part with no approval request.onRespondrequired(response: ToolApprovalResponse) => void | PromiseLike<void>Matches
useChat().addToolApprovalResponse, so you can pass it directly.metaToolMetaHow to show this tool, as in
AgentMessage'stools: withouttitle, the card takes itslabel(after the part's owntitle), and withoutrisk, itsrisk, a level or a function of the input.policyApprovalPolicyApproval rules from
useApprovalPolicy. The card then offers once, this session and always (unlessdecisionssays otherwise), answers a request a rule already decides without asking, and records every decision.decisionsreadonly ApprovalDecision[]The choices to offer, from
allow-once,allow-session,allow-always,deny-onceanddeny-always. Without it, all five with apolicy, elseallow-onceanddeny-once.onEditInput(toolCallId: string, input: unknown) => voidApply edited arguments before the approval goes out; the card offers editing only with it. With AI SDK 7:
(id, input) => setMessages((m) => setToolInput(m, id, input)). WithuseAgUiAgent: itseditInput.editablebooleanDefaulttrueLet the person edit the arguments before approving, as on
ApprovalCard. Only withonEditInput, which applies the edit: without it the card never offers editing, and with itfalseturns editing off.
Also takes every ApprovalCardProps prop above, except toolName, input, status, onApprove, onDeny, onDecide, reason, automatic, decision, decidedByRule, decisions and editable.
ToolApprovalBatch
"Approve all" and "Deny all" for the approvals a run is waiting on together, such as parallel
calls. Each is answered once, as Approve or Deny on its own card would; with a critical one among
them, Approve all asks for a second press. Approve all runs each call with the agent's arguments:
it does not see an edit made on a card (editable), so approve an edited call on its own card.
Once the answers reach the parts, the bar goes. What it did is still announced, and focus, which
was on its button, moves to the first of their ToolApprovalCards, as deciding on a card keeps
focus on that card.
Props
partsrequiredreadonly ToolPart[]Tool parts; those waiting on a person count.
onRespondrequired(response: ToolApprovalResponse) => void | PromiseLike<void>Called once for each waiting call when Approve all or Deny all answers them. Matches
useChat().addToolApprovalResponse, so you can pass it directly.policyApprovalPolicyApproval rules from
useApprovalPolicy, the ones the cards get: a call a rule decides isn't waiting on a person, and each answer is recorded as a once decision.toolsRecord<string, ToolMeta>The tools'
ToolMeta, by tool name, as inAgentMessage'stools. Theirriskcounts: with a critical call waiting, Approve all asks for a second press.minnumberDefault2Shown from this many waiting approvals.
labelsSignoffLabelsInputWords to use instead of the English defaults: see
SignoffLabelsProvider.
Other props go to the root <div>: className (merged with tailwind-merge), id, aria-*, data-* and event handlers.
ApprovalChoice
A decision as the card makes it: what was chosen, and what goes with it.
decisionrequiredApprovalDecision'allow-once' | 'allow-session' | 'allow-always' | 'deny-once' | 'deny-always'What was chosen, and how long it holds:
allow-once,allow-session,allow-always,deny-onceordeny-always.reasonstringThe denial's reason, when the person gave one.
inputunknownThe arguments to run with, when the person edited them (
editable).argsRecord<string, string>For a session or always decision: the argument patterns its rule covers, or
undefinedfor every call of the tool ("Any arguments").
ApprovalDecision
What a person can decide about a tool call, and for how long it holds.
type ApprovalDecision = 'allow-once' | 'allow-session' | 'allow-always' | 'deny-once' | 'deny-always';ToolApprovalResponse
The answer to one approval request, as the AI SDK's addToolApprovalResponse takes it.
idrequiredstringThe approval request's id,
part.approval.id: not the tool call's id.approvedrequiredbooleantrueto run the call,falseto deny it.reasonstringThe reason given with the decision, such as the one the person typed when denying.
RiskLevel
type RiskLevel = 'low' | 'medium' | 'high' | 'critical';ApprovalStatus
type ApprovalStatus = 'denied' | 'pending' | 'approved';Accessibility
| Keys | Action |
|---|---|
| Y | Approve, once |
| S | Approve for this session, when offered |
| A | Always approve, when offered |
| N | Deny |
| ⇧N | Always deny, when offered |
| ⌘/Ctrl↵ | Approve (page-wide with globalShortcut) |
| Esc | Close the reason field and return to the card, or cancel a critical confirmation |
- A group named by its title and described by its description and a visually hidden line that spells out the shortcuts on offer. It is not a landmark, so a run with many approvals doesn’t fill landmark navigation; pass
role="region"to make it one. - Every choice is a button with its key in
aria-keyshortcuts. Y, S, A, N and Shift+N only work while focus is inside the card, with no other modifier, not while typing and not on the controls of a custompreview, which keeps them within WCAG 2.1.4. - A lasting choice says what it will cover, in a labeled group: the tool, and a text field per argument pattern ("command matches"), or "Any arguments".
- Editing arguments opens a form with a labeled field per argument, or a JSON text area; JSON that does not parse is marked
aria-invalid, its error is the field’s description, and approving says "The arguments are not valid JSON." instead of approving. criticalactions need a second press of the same choice, and say so: "Critical action. Press approve again to confirm." The first press stays armed, with no time limit, until the second, Escape, or focus leaving the card; the second click of a double click doesn’t count. Approve all asks for one when any of the calls is critical.- Deciding announces the outcome ("Approved for this session") and moves focus to the card, so it isn’t lost when the buttons go away; the announcement then clears, so the decided card reads its outcome once.
autoFocusputs focus on a card that arrives pending. - Each pending approval sends one decision: a double click, or Y then N, is ignored until
statuschanges or the handler’s promise settles. A call a rule decides is answered without showing a card, and reads "Allowed by your rule" with the rule once it is. - The risk level is spelled out, not shown by color alone, and only when you give one: without
riskthe card shows none rather than guessing.headingLevelfits the title into your outline.
Theming
Every color, radius and font is a CSS variable, so the overrides in Theming apply, on :root or scoped to any element. These hooks are read from the component's markup.
- Slots (data-slot)
- signoff-approval-commandsignoff-approval-cardsignoff-approval-risksignoff-approval-batch-statussignoff-approval-batch
- State attributes
- data-decision
'allow-once' | 'allow-session' | 'allow-always' | 'deny-once' | 'deny-always'data-statusonsignoff-approval-card'denied' | 'pending' | 'approved'data-riskonsignoff-approval-card'low' | 'medium' | 'high' | 'critical'data-approval-id - Tokens it uses
- --signoff-accent--signoff-accent-fg--signoff-bg--signoff-border--signoff-border-strong--signoff-fg--signoff-fg-muted--signoff-fg-subtle--signoff-font-mono--signoff-font-sans--signoff-hot--signoff-hot-fg--signoff-on-accent--signoff-on-hot--signoff-radius--signoff-ring--signoff-surface--signoff-surface-2--signoff-warn--signoff-warn-fg
/* Only this component, and only inside .settings-panel */
.settings-panel [data-slot='signoff-approval-command'] {
--signoff-radius: 4px;
}
[data-slot='signoff-approval-card'][data-status='denied'] {
outline: 1px solid var(--signoff-accent);
}