- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
"use client"
import * as React from "react"Confirmation asks the person for a yes or no before a tool runs. The question is an Item with Deny and Approve buttons. Once the person answers, the call becomes a Tool line.
Installation#
Confirmation is built with the Item and Button components.
pnpm dlx shadcn@latest add item button
Usage#
<Item variant="outline" size="sm">
<ItemMedia variant="icon">
<TerminalIcon />
</ItemMedia>
<ItemContent>
<ItemTitle>Run {part.input.command}?</ItemTitle>
<ItemDescription>The command runs in this project.</ItemDescription>
</ItemContent>
<ItemActions>
<Button size="sm" variant="outline" onClick={deny}>
Deny
</Button>
<Button size="sm" onClick={approve}>
Approve
</Button>
</ItemActions>
</Item>AI SDK#
While the part is approval-requested, answer with the approval id. Pass sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses so the chat continues once every approval has an answer.
addToolApprovalResponse({
id: part.approval.id,
approved: true,
})useChat({
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
})Approve streams the tool output. Deny streams output-denied. Either way, the part becomes a Tool line.
See Tool.
AI SDK Helper#
To script an approval with createChat, set needsApproval on the tool. The output streams after approval, and the next agent turn reads toolCall.approved.
const chat = createChat()
.user("Clean up the build folder.")
.assistant(({ writer }) => {
writer.tool("runCommand", {
input: { command: "rm -rf dist" },
needsApproval: true,
output: { stdout: "" },
})
})
.assistant(({ writer, toolCall }) => {
writer.text(
toolCall?.approved
? "Removed the dist folder."
: "Okay, I left the dist folder in place."
)
})Migrating from AI SDK Elements#
If you added Confirmation from AI SDK Elements, your project has a components/ai-elements/confirmation.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Item and Button. Every export keeps its name and props, so the code that uses it keeps working.
Migrate components/ai-elements/confirmation.tsx from AI SDK Elements to the shadcn/ui Item and Button components.
Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.
1. Install the components: npx shadcn@latest add item button
2. Read https://ui.shadcn.com/docs/ai-elements/base/confirmation.md and build Confirmation the same way.
3. Rebuild each part:
- Confirmation renders an Item with variant="outline" and size="sm", instead of an Alert. Keep the approval and state props and the context they feed.
- ConfirmationTitle renders an ItemContent with an ItemTitle.
- ConfirmationActions renders an ItemActions.
- ConfirmationAction renders a Button with size="sm".
- Keep ConfirmationRequest, ConfirmationAccepted and ConfirmationRejected as they are.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.