页面简介
Asks for approval before a tool runs.
正文摘录
SectionsIntroductionComponentsAI ElementsInstallationThemingCLITypesetSkillsRegistryChangelogComponentsAccordionAlertAlert DialogAspect RatioAttachmentAvatarBadgeBreadcrumbBubbleButtonButton GroupCalendarCardCarouselChartCheckboxCode BlockCollapsibleComboboxCommandContext MenuData TableDate PickerDialogDirectionDrawerDropdown MenuEmptyFieldHover CardInputInput GroupInput OTPItemKbdLabelMarkerMenubarMessageMessage ScrollerNative SelectNavigation MenuPaginationPopoverProgressQuestionnaireRadio GroupResizableScroll AreaSelectSeparatorSheetSidebarSkeletonSliderSonnerSpinnerSwitchTableTabsTextareaToastToggleToggle GroupTooltipTraceTypographyAI ElementsIntroductionChain of ThoughtChatCheckpointConfirmationContextFile TreeInline CitationMessageModel SelectorPlanPrompt InputQueueReasoningSourcesStack TraceSubagentSuggestionTaskTerminalTest ResultsToolGet StartedInstallationcomponents.jsonPackage ImportsThemingTypesetDark ModeCLIMonorepoSkillsJavaScriptFigmallms.txtLegacy Docs@shadcn/reactMessage ScrollerQuestionnaire@shadcn/helpersAI SDKTanStack AIFormsReact Hook FormTanStack FormFormischUtilitiesscroll-fadeshimmerRegistryIntroductionGetting StartedGitHub RegistriesRegistry DirectoryRegistry HealthExamplesNamespacesAuthenticationDynamic SearchMCP ServerOpen in v0FAQAPI Referenceregistry.jsonregistry-item.jsonConfirmationCopy PagePreviousNextAsks for approval before a tool runs.Base UIReact AriaRadix UISend messageCopy"use client" import * as React from "react"View Code 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. CommandManualpnpmnpmyarnbunpnpm dlx shadcn@latest add item buttonCopy Usage Copy<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. CopyaddToolApprovalResponse({ id: part.approval.id, approved: true, }) CopyuseChat({ 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. Copyconst 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. PromptCopyMigrate 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/radix/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.Expand CheckpointContext On This PageInstallationUsageAI SDKAI SDK HelperMigrating from AI SDK ElementsDeploy your shadcn/ui app on VercelTrusted by OpenAI, Sonos, Adobe, and more.Vercel provides tools and infrastructure to deploy apps and features at scale.Deploy NowDeploy to Vercel