Confirmation
Ask the reader to approve or deny an action before the agent runs it.
NewInstallation
Copy and paste the following code into your project.
Update the import paths to match your project structure.
Anatomy
Use it when an agent wants to do something the reader should decide on first: send an email, run a command, spend money, change data. Once the reader answers, the buttons go away and a short line says what was decided, so the thread keeps a record of it.
It works on its own or inside a Tool with
status="awaiting-approval".Composition
Async approval
onClick on Confirmation.Approve or Confirmation.Deny can return a promise. While it runs, the button shows a spinner, the other one is disabled and the group is aria-busy. When the promise resolves, the state changes; when it rejects, the confirmation stays pending so the reader can try again.Merge pull request #482 into main?
All 13 checks passed. The branch is up to date.
Accessibility
- The root is a
groupnamed byConfirmation.Titleand described byConfirmation.Description. - The result line is a
statusregion, so screen readers announce "Approved" or "Denied" without moving focus. - Approve is the only filled button. Deny comes first in reading order, so a stray Enter on the first focus does not approve.
API Reference
Confirmation
| Prop | Type | Default | Description |
|---|---|---|---|
state | 'pending' | 'approved' | 'denied' | - | Controlled state |
defaultState | 'pending' | 'approved' | 'denied' | 'pending' | Initial state when uncontrolled |
onStateChange | (state: ConfirmationState) => void | - | Called when the reader approves or denies |
approvedLabel | string | 'Approved' | Result line after approving |
deniedLabel | string | 'Denied' | Result line after denying |
className | string | - | Additional CSS classes |
Confirmation.Approve, Confirmation.Deny
Accept every Button prop. Approve defaults to
variant="default" and the label "Approve"; Deny to variant="outline" and "Deny".| Prop | Type | Default | Description |
|---|---|---|---|
onClick | (event) => void | PromiseLike<unknown> | - | Runs before the state changes; may wait |
Confirmation.Title, Confirmation.Description, Confirmation.Actions
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.