Skip to content
signoff-uiv0.14.1

Docs

Components

ApprovalCard

Human-in-the-loop approval: what will run, how risky it is, and deny with a reason.

Example

Approval required

High risk

Run command

Installs a package from the npm registry and updates package.json and pnpm-lock.yaml.

~/acme/chat-app
pnpm add @upstash/ratelimit
Calls a lasting decision covers

Remembered for run_command calls where:

* matches any text but shell operators (; & | > < and backticks); ** matches anything.

Interactive, and the same on the components page. Try the keyboard below on it.

Installation

npm i signoff-ui ai
TSX
import {
  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';

The styles are once per app; Getting started has the Tailwind v4 and plain CSS options.

Usage

TSX
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

toolNamerequired
string

Name of the tool or action that needs approval.

title
ReactNode

Heading. Defaults to the humanized tool name.

description
ReactNode

Why the agent wants to do this, e.g. the SDK's approval.requestReason.

input
unknown

Arguments the action will run with.

risk
RiskLevel

How risky the action is, shown as a badge. Without it the card shows no risk level.

preview
ReactNode

Custom arguments preview. Defaults to a command line for { command } inputs, with any other arguments as JSON below it, else JSON. Your content, like AgentMessage's renderTool: 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.

status
ApprovalStatusDefault '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 until status changes, the promise the handler returned settles, or the handler throws.

reason
string

Reason recorded with the decision, shown once resolved.

automatic
booleanDefault false

A 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".

decision
ApprovalDecision

How the resolved decision was made, to say so: allow-session reads "Approved for this session", deny-always "Always denied", and so on.

decidedByRule
string

The rule that decided, in words, shown once resolved: "Allowed by your rule: …".

decisions
readonly ApprovalDecision[]Default ['allow-once', 'deny-once']

The choices to offer, from allow-once, allow-session, allow-always, deny-once and deny-always. Session and always decisions come to onDecide with 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, onApprove and onDeny are not called. May return a promise.

onApprove
() => void | PromiseLike<void>

Fires once per decision: see status. May return a promise. Not called with onDecide.

onDeny
(reason?: string) => void | PromiseLike<void>

Fires once per decision: see status. May return a promise. Not called with onDecide.

editable
booleanDefault false

Let 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 the input it was made against: new input, or a new status, drops it.

ruleArgs
Record<string, string>

The argument patterns a session or always rule starts with. Default: from the input.

ruleScope
booleanDefault true

Show which calls a session or always decision covers, editable. Pass false when the agent keeps what "always" means, as with ACP's allow_always: the card then shows no argument patterns, and the decision comes without args.

shortcuts
booleanDefault true

Y / N shortcuts while focus is inside the card (and S, A, Shift+N when offered), but not in a custom preview.

globalShortcut
booleanDefault false

Also 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.

autoFocus
booleanDefault false

Move 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.

allowReason
booleanDefault true

Offer an optional free-text reason when denying.

reasonPlaceholder
stringDefault 'What should the agent do instead?'

Placeholder of the reason field. Without one, the card uses labels.approvalCard.reasonPlaceholder.

approveLabel
stringDefault 'Approve'

The approve button's text. Without one, the card uses labels.approvalCard.approve.

denyLabel
stringDefault 'Deny'

The deny button's text. Without one, the card uses labels.approvalCard.deny.

headingLevel
HeadingLevelDefault 3

Heading level for the title, to fit your document outline.

labels
SignoffLabelsInput

Words 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

partrequired
ToolPart

The AI SDK tool part to answer, from message.parts (isToolPart finds 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.

meta
ToolMeta

How to show this tool, as in AgentMessage's tools: without title, the card takes its label (after the part's own title), and without risk, its risk, a level or a function of the input.

policy
ApprovalPolicy

Approval rules from useApprovalPolicy. The card then offers once, this session and always (unless decisions says otherwise), answers a request a rule already decides without asking, and records every decision.

decisions
readonly ApprovalDecision[]

The choices to offer, from allow-once, allow-session, allow-always, deny-once and deny-always. Without it, all five with a policy, else allow-once and deny-once.

onEditInput
(toolCallId: string, input: unknown) => void

Apply 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)). With useAgUiAgent: its editInput.

editable
booleanDefault true

Let the person edit the arguments before approving, as on ApprovalCard. Only with onEditInput, which applies the edit: without it the card never offers editing, and with it false turns 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

partsrequired
readonly 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.

policy
ApprovalPolicy

Approval 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.

tools
Record<string, ToolMeta>

The tools' ToolMeta, by tool name, as in AgentMessage's tools. Their risk counts: with a critical call waiting, Approve all asks for a second press.

min
numberDefault 2

Shown from this many waiting approvals.

labels
SignoffLabelsInput

Words 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.

decisionrequired
ApprovalDecision
'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-once or deny-always.

reason
string

The denial's reason, when the person gave one.

input
unknown

The arguments to run with, when the person edited them (editable).

args
Record<string, string>

For a session or always decision: the argument patterns its rule covers, or undefined for every call of the tool ("Any arguments").

ApprovalDecision

What a person can decide about a tool call, and for how long it holds.

TypeScript
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.

idrequired
string

The approval request's id, part.approval.id: not the tool call's id.

approvedrequired
boolean

true to run the call, false to deny it.

reason
string

The reason given with the decision, such as the one the person typed when denying.

RiskLevel

TypeScript
type RiskLevel = 'low' | 'medium' | 'high' | 'critical';

ApprovalStatus

TypeScript
type ApprovalStatus = 'denied' | 'pending' | 'approved';

Accessibility

Keyboard
KeysAction
YApprove, once
SApprove for this session, when offered
AAlways approve, when offered
NDeny
⇧NAlways deny, when offered
⌘/Ctrl↵Approve (page-wide with globalShortcut)
EscClose 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 custom preview, 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.
  • critical actions 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. autoFocus puts focus on a card that arrives pending.
  • Each pending approval sends one decision: a double click, or Y then N, is ignored until status changes 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 risk the card shows none rather than guessing. headingLevel fits 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-statuson signoff-approval-card'denied' | 'pending' | 'approved'data-riskon signoff-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
app/globals.css
/* 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);
}
Edit this page on GitHubReport an issue

Last updated