Agent approval

Slant / People & chat

A tool request that says what and why, answered with Reject, Allow once or Allow always.

Demo

Usage

@tuttn/slant
import { AgentApproval, CodeBlock } from '@tuttn/slant'

// Uncontrolled: the card keeps its own decision and reports it.
<AgentApproval tool="Bash" title="Run a shell command" reason="To run the failing test on its own."
  onValueChange={decision => respond(decision)}>
  <CodeBlock language="sh" code="npm test -- retry.test.ts" />
</AgentApproval>

// Controlled: null while it waits. Two answers, the Allow button renamed.
const [decision, setDecision] = useState<AgentApprovalDecision | null>(null)
<AgentApproval title="Push to main" allowAlways={false} allowLabel="Push" value={decision} onValueChange={setDecision} />

// Plain text is drawn as a monospace block; the title joins the page's outline.
<AgentApproval tool="Files" title="Delete a folder" heading="h4">rm -rf build/</AgentApproval>

Props

PropTypeDefaultDescription
titleReactNode—What the agent wants to do: "Run a shell command". Also the card's accessible name.
reasonReactNode—Why it wants to: "To run the failing test on its own."
toolReactNode—The tool or subject asking, shown above the title in monospace: "Bash", "GitHub".
childrenReactNode—The exact request: the command, the path, the diff. A CodeBlock or plain text; it scrolls past a few lines.
valueAgentApprovalDecision | null—The decision, for a controlled card: `null` while it waits for one.
defaultValueAgentApprovalDecision | null—The decision it starts with when uncontrolled; leave it out for a card that waits.
onValueChange(decision: AgentApprovalDecision) => void—Called with the decision when Reject, Allow once or Allow always is pressed, or Enter or Escape is used.
allowAlwaysbooleantrueOffers Allow always. False leaves Reject and Allow once, and Allow once becomes the primary button.
allowLabelstring—Replaces the Allow once button's text, e.g. "Run it".
heading'h3' | 'h4' | 'div''div'The element wrapping the title, so the request sits in the page's outline.
AgentApprovalDecision'reject' | 'once' | 'always'—How the request was answered.
…restHTMLAttributes<HTMLDivElement>—className, style, the ref and other attributes go on the root <div>, which carries data-state (waiting, rejected or allowed) and, once answered, data-decision.

Keyboard

Tabmoves through the request (when there is one) and the answers
Enterallows once, with focus anywhere in the card but a button, link or text field; on a button it presses that button
Escaperejects, with focus anywhere in the card but a text field, and goes no further, so a Dialog around it stays open
↑ ↓ PgUp PgDnscroll a long request while it has focus

Accessibility

  • The root is a group named by the title, and described by the reason when there is one.
  • The request sits in its own group, named messages.approvalDetail (“Request details”), with tabIndex={0}, so a long command scrolls from the keyboard.
  • The buttons are named messages.approvalReject, approvalAllowOnce (or allowLabel) and approvalAllowAlways; the hint beside them reads messages.approvalKeys. On a touch screen, which has neither key, the hint is hidden.
  • Answered, the buttons give way to a status line, messages.approvalDecided(decision) (“Allowed once”), which the root’s announcer says politely. A card that mounts answered, or a controlled one whose value comes in answered, says nothing.
  • Focus on a pressed button would be lost with it, so it moves to the card, which takes tabIndex={-1} while answered.
  • Enter and Escape ignore held keys, modifiers and an IME’s composition.

Answering

Reject, Allow once and Allow always each call onValueChange with 'reject', 'once' or 'always'. Uncontrolled, the card then shows how it was answered. Controlled, pass value (null while it waits) and it shows whatever you pass, so a decision that has to reach a server can wait for it, and a new request can reset the card to null. allowAlways={false} leaves two answers and makes Allow once the primary one.

The request

children is the exact request: a CodeBlock, a diff, a path. A plain string is drawn as a monospace block that wraps. Past about eight lines the region scrolls on its own, so a long command never pushes the answers out of view.

In a conversation

Put it inside the assistant’s Message in a Thread. Its keys stay inside the card, so Escape rejects without closing a Dialog around the conversation. The waiting pixel pulses, and rests under prefers-reduced-motion. Under dir="rtl" the strip, the text and the answers mirror.