{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"confirmation","type":"registry:component","title":"Confirmation","description":"AI-powered confirmation component.","files":[{"path":"registry/default/ai-elements/confirmation.tsx","type":"registry:component","content":"\"use client\";\n\nimport { Alert, AlertDescription } from \"@/components/ui/alert\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\nimport type { ToolUIPart } from \"ai\";\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  useContext,\n} from \"react\";\n\ntype ToolUIPartApproval =\n  | {\n      id: string;\n      approved?: never;\n      reason?: never;\n    }\n  | {\n      id: string;\n      approved: boolean;\n      reason?: string;\n    }\n  | {\n      id: string;\n      approved: true;\n      reason?: string;\n    }\n  | {\n      id: string;\n      approved: true;\n      reason?: string;\n    }\n  | {\n      id: string;\n      approved: false;\n      reason?: string;\n    }\n  | undefined;\n\ntype ConfirmationContextValue = {\n  approval: ToolUIPartApproval;\n  state: ToolUIPart[\"state\"];\n};\n\nconst ConfirmationContext = createContext<ConfirmationContextValue | null>(\n  null\n);\n\nconst useConfirmation = () => {\n  const context = useContext(ConfirmationContext);\n\n  if (!context) {\n    throw new Error(\"Confirmation components must be used within Confirmation\");\n  }\n\n  return context;\n};\n\nexport type ConfirmationProps = ComponentProps<typeof Alert> & {\n  approval?: ToolUIPartApproval;\n  state: ToolUIPart[\"state\"];\n};\n\nexport const Confirmation = ({\n  className,\n  approval,\n  state,\n  ...props\n}: ConfirmationProps) => {\n  if (!approval || state === \"input-streaming\" || state === \"input-available\") {\n    return null;\n  }\n\n  return (\n    <ConfirmationContext.Provider value={{ approval, state }}>\n      <Alert className={cn(\"flex flex-col gap-2\", className)} {...props} />\n    </ConfirmationContext.Provider>\n  );\n};\n\nexport type ConfirmationTitleProps = ComponentProps<typeof AlertDescription>;\n\nexport const ConfirmationTitle = ({\n  className,\n  ...props\n}: ConfirmationTitleProps) => (\n  <AlertDescription className={cn(\"inline\", className)} {...props} />\n);\n\nexport type ConfirmationRequestProps = {\n  children?: ReactNode;\n};\n\nexport const ConfirmationRequest = ({ children }: ConfirmationRequestProps) => {\n  const { state } = useConfirmation();\n\n  // Only show when approval is requested\n  // @ts-expect-error state only available in AI SDK v6\n  if (state !== \"approval-requested\") {\n    return null;\n  }\n\n  return children;\n};\n\nexport type ConfirmationAcceptedProps = {\n  children?: ReactNode;\n};\n\nexport const ConfirmationAccepted = ({\n  children,\n}: ConfirmationAcceptedProps) => {\n  const { approval, state } = useConfirmation();\n\n  // Only show when approved and in response states\n  if (\n    !approval?.approved ||\n        // @ts-expect-error state only available in AI SDK v6\n    (state !== \"approval-responded\" &&\n        // @ts-expect-error state only available in AI SDK v6\n      state !== \"output-denied\" &&\n      state !== \"output-available\")\n  ) {\n    return null;\n  }\n\n  return children;\n};\n\nexport type ConfirmationRejectedProps = {\n  children?: ReactNode;\n};\n\nexport const ConfirmationRejected = ({\n  children,\n}: ConfirmationRejectedProps) => {\n  const { approval, state } = useConfirmation();\n\n  // Only show when rejected and in response states\n  if (\n    approval?.approved !== false ||\n        // @ts-expect-error state only available in AI SDK v6\n    (state !== \"approval-responded\" &&\n        // @ts-expect-error state only available in AI SDK v6\n      state !== \"output-denied\" &&\n      state !== \"output-available\")\n  ) {\n    return null;\n  }\n\n  return children;\n};\n\nexport type ConfirmationActionsProps = ComponentProps<\"div\">;\n\nexport const ConfirmationActions = ({\n  className,\n  ...props\n}: ConfirmationActionsProps) => {\n  const { state } = useConfirmation();\n\n  // Only show when approval is requested\n  // @ts-expect-error state only available in AI SDK v6\n  if (state !== \"approval-requested\") {\n    return null;\n  }\n\n  return (\n    <div\n      className={cn(\"flex items-center justify-end gap-2 self-end\", className)}\n      {...props}\n    />\n  );\n};\n\nexport type ConfirmationActionProps = ComponentProps<typeof Button>;\n\nexport const ConfirmationAction = (props: ConfirmationActionProps) => (\n  <Button className=\"h-8 px-3 text-sm\" type=\"button\" {...props} />\n);\n","target":"components/ai-elements/confirmation.tsx"}],"dependencies":["ai"],"devDependencies":[],"registryDependencies":["alert","button"]}