{"$schema":"https://ui.shadcn.com/schema/registry-item.json","dependencies":["ai"],"description":"AI-powered confirmation component.","devDependencies":[],"files":[{"content":"\"use client\";\n\nimport { Alert, AlertDescription } from \"@/registry/default/ui/alert\";\nimport { Button } from \"@/registry/default/ui/button\";\nimport { cn } from \"@/lib/utils\";\nimport type { ToolUIPart } from \"ai\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport { createContext, useContext, useMemo } 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: false;\n      reason?: string;\n    }\n  | undefined;\n\ninterface 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  const contextValue = useMemo(() => ({ approval, state }), [approval, state]);\n\n  if (!approval || state === \"input-streaming\" || state === \"input-available\") {\n    return null;\n  }\n\n  return (\n    <ConfirmationContext.Provider value={contextValue}>\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 interface ConfirmationRequestProps {\n  children?: ReactNode;\n}\n\nexport const ConfirmationRequest = ({ children }: ConfirmationRequestProps) => {\n  const { state } = useConfirmation();\n\n  // Only show when approval is requested\n  if (state !== \"approval-requested\") {\n    return null;\n  }\n\n  return children;\n};\n\nexport interface 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    (state !== \"approval-responded\" &&\n      state !== \"output-denied\" &&\n      state !== \"output-available\")\n  ) {\n    return null;\n  }\n\n  return children;\n};\n\nexport interface 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    (state !== \"approval-responded\" &&\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  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","path":"registry/default/ai-elements/confirmation.tsx","target":"components/ai-elements/confirmation.tsx","type":"registry:component"}],"name":"confirmation","registryDependencies":["alert","button"],"title":"Confirmation","type":"registry:component"}