Approval Mode
Let someone choose how much the agent may do before it asks, from a button that shows the current mode.
Use an approval mode beside a composer when people decide how often the agent stops to ask, like approving every tool call or letting it edit files on its own. It's a button that shows the current mode and opens a menu of modes, each with a description, and it marks a risky one.
Installation
npx shadcn@latest add @kind-ui/approval-modeComposition
ApprovalMode
├── ApprovalModeTrigger
└── ApprovalModeContent
└── ApprovalModeRowsApprovalMode is a group named by its label and the current mode, around UI SDK's Menu. ApprovalModeTrigger is UI SDK's MenuTrigger, a button that shows a shield icon, the mode's label and, for a risky mode, a warning mark, unless you pass children. ApprovalModeContent is UI SDK's MenuContent: one radio group headed by the label, then an optional Learn more item. ApprovalModeRows draws the modes inside it as radio items. ApprovalMode renders the trigger and content when you pass no children.
Usage
Modes
Pass modes, in order. Each has a value, which must be unique, a label and an optional description, a second line under the label. A mode with danger: true lets the agent do more without asking: its row says "Risky" in the danger color, and when it's chosen the button shows a warning mark.
The button is named by the label and the mode, like "Approvals, Ask every time", with ", risky" after a risky mode. The label is "Approvals" by default and also heads the menu.
Value
Pass value and onValueChange to control the mode, or defaultValue to start with one. Choosing a mode closes the menu, and onValueChange gets the new value with the reason item-press. Call details.cancel() to keep the old mode. To have a person confirm a risky mode first, cancel the change in onValueChange, ask, and set value once they agree.
<ApprovalMode
modes={modes}
value={value}
onValueChange={(next, details) => {
if (modes.find((mode) => mode.value === next)?.danger) {
details.cancel();
confirmFullAccess().then((ok) => ok && setValue(next));
} else setValue(next);
}}
/>The Approval Mode doesn't act on the mode. Your app reads it and decides which tool calls need approval.
Learn More
Pass learnMoreHref to add a Learn more link after the modes, or onLearnMore to handle it yourself. onLearnMore gets the learnMoreHref, if there is one, and the reason item-press.
Opening
Pass open and onOpenChange to control whether the menu is open, or defaultOpen to start open. onOpenChange gets UI SDK Menu's reason, like trigger-press or escape-key. Set disabled to keep the button from opening the menu; it also closes an open one.
Keyboard
The button is one Tab stop. Enter, Space or Down Arrow opens the menu with focus on the first mode, and the arrow keys move between the modes and Learn more. Typing a letter moves to the next mode whose label starts with it. Enter or Space chooses a mode and closes the menu. Escape closes it without a change, with focus back on the button.
Presentation and Motion
The menu opens as a popover below the button. With presentation="auto", the default, it's a bottom sheet on small touch screens instead; pass "popover" or "sheet" to choose one. The popover rises and fades in. Under prefers-reduced-motion, or with motion="reduced", it only fades, over 120 ms, and with motion="none" it opens at once.
API Reference
Prop
Type
Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:
| React | Vue | Svelte | Solid |
|---|---|---|---|
open, onOpenChange | v-model:open, @open-change | bind:open, onOpenChange | open, onOpenChange |
value, onValueChange | v-model:value, @value-change | bind:value, onValueChange | value, onValueChange |
onLearnMore | @learn-more | onLearnMore | onLearnMore |
Agent
An agent connected with createAgent finds the approval mode by its name, like "Approvals, Ask every time", and reads open and value. It lists every mode by value and label. setValue takes a mode's value and refuses an unknown one; it's offered only while the menu is enabled and holds a mode, and it changes the mode whether the menu is open or closed. open is offered while the menu is closed and enabled, and close while it's open.
Changing the mode widens or narrows what the agent may do without asking, so with agentConfirm, on by default, the root renders data-agent-confirm and every action needs a person to confirm it. Set agentConfirm={false} only when your app confirms these changes another way.
Prop
Type
Runs in React, Vue, Svelte, Solid and Web Components. On <kind-approval-mode>, set modes, value and open as properties and learn-more-href and agent-confirm as attributes, and listen for modechange, with the mode as event.detail.value, and openchange. Add the can-learn-more attribute to listen for learnmore instead of following a link. The element fills in its button and menu when it has no children.