{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "approval-mode",
  "title": "Approval Mode",
  "description": "A button showing how much the agent may do without asking, opening a menu of modes with a risky one marked.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-menu"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/approval-mode.tsx",
      "content": "\"use client\";\n\nimport {\n  APPROVAL_MODE_GROUP,\n  APPROVAL_MODE_LEARN_MORE,\n  type ApprovalModeContentState,\n  type ApprovalModeRow,\n  type ApprovalModeTriggerState,\n  approvalModePrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { MenuTrigger } from \"@ui-sdk/react/menu\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport {\n  KindMenu,\n  KindMenuContent,\n  KindMenuGroupLabel,\n  KindMenuItem,\n  KindMenuItemContent,\n  KindMenuItemIndicator,\n  KindMenuRadioGroup,\n  KindMenuRadioItem,\n  KindMenuSeparator,\n} from \"./internal/menu\";\n\nconst parts = createParts(approvalModePrimitive, { root: \"div\", trigger: \"span\", content: \"div\" });\n\nexport type ApprovalModeProps = Omit<ComponentProps<typeof parts.Root>, \"children\"> & {\n  children?: ReactNode;\n};\n\n/**\n * A button showing the approval mode, named \"Approvals, <mode>\", that opens a menu of modes: radio items with a\n * description each, a risky one marked, and an optional Learn more link after them. Any `children` replace the\n * trigger and the content, inside UI SDK Menu.\n */\nexport function ApprovalMode({ children = DEFAULT_PARTS, ...props }: ApprovalModeProps) {\n  return <parts.Root {...props}>{(menu) => <KindMenu {...menu}>{children}</KindMenu>}</parts.Root>;\n}\n\nconst RISKY = <span data-approval-mode-risk=\"\">Risky</span>;\n\nexport type ApprovalModeRowsProps = Pick<ApprovalModeContentState, \"rows\">;\n\n/** The modes' radio items, a risky one marked \"Risky\". Choosing one closes the menu. */\nexport function ApprovalModeRows({ rows }: ApprovalModeRowsProps) {\n  return rows.map((row) => (\n    <KindMenuRadioItem\n      key={row.value}\n      value={row.value}\n      label={row.label}\n      closeOnSelect\n      data-danger={row.danger ? \"\" : undefined}\n    >\n      <KindMenuItemIndicator keepMounted>\n        <span data-menu-check=\"\" aria-hidden=\"true\" />\n      </KindMenuItemIndicator>\n      <KindMenuItemContent label={row.label} description={row.description} />\n      {row.danger ? RISKY : null}\n    </KindMenuRadioItem>\n  ));\n}\n\nfunction TriggerValue({ mode }: { mode: ApprovalModeRow | undefined }) {\n  return (\n    <>\n      <span data-menu-trigger-icon=\"\" aria-hidden=\"true\" />\n      {mode ? <span data-approval-mode-value=\"\">{mode.label}</span> : null}\n      {mode?.danger ? <span data-status-mark=\"\" data-status=\"warning\" aria-hidden=\"true\" /> : null}\n    </>\n  );\n}\n\nexport type ApprovalModeTriggerProps = Omit<ComponentProps<typeof MenuTrigger>, \"children\"> & {\n  /** What the button shows, or a function of its state: a shield, the mode's label and a risky mode's mark. */\n  children?: ReactNode | ((state: ApprovalModeTriggerState) => ReactNode);\n};\n\n/** Opens the menu: UI SDK's `MenuTrigger`, named by the `label` and the mode. Props go to it. */\nexport function ApprovalModeTrigger({ children, ...props }: ApprovalModeTriggerProps) {\n  return (\n    <parts.Trigger>\n      {({ mode, ...trigger }) => (\n        // Hidden from agents, which use the Approval Mode's own actions.\n        <MenuTrigger {...trigger} data-agent-hidden=\"\" {...props}>\n          {typeof children === \"function\"\n            ? children({ mode, ...trigger })\n            : (children ?? <TriggerValue mode={mode} />)}\n        </MenuTrigger>\n      )}\n    </parts.Trigger>\n  );\n}\n\nexport type ApprovalModeContentProps = Omit<ComponentProps<typeof KindMenuContent>, \"children\"> & {\n  /** What the radio group holds after its header, or a function of the content's state: the modes by default. */\n  children?: ReactNode | ((state: ApprovalModeContentState) => ReactNode);\n};\n\n/**\n * The menu: UI SDK's `MenuContent` holding one radio group, headed by the `label`, of the modes unless you pass\n * children, then a Learn more item (a link with `learnMoreHref`). Props go to the content.\n */\nexport function ApprovalModeContent({ children = DEFAULT_ROWS, ...props }: ApprovalModeContentProps) {\n  return (\n    <parts.Content>\n      {(state) => (\n        <KindMenuContent align=\"start\" sideOffset={6} {...props}>\n          <KindMenuRadioGroup name={APPROVAL_MODE_GROUP} value={state.value}>\n            <div data-approval-mode-header=\"\">\n              <KindMenuGroupLabel>{state.label}</KindMenuGroupLabel>\n            </div>\n            {typeof children === \"function\" ? children(state) : children}\n          </KindMenuRadioGroup>\n          {state.learnMore ? (\n            <>\n              <KindMenuSeparator data-approval-mode-learn-more=\"\" />\n              <KindMenuItem\n                value={APPROVAL_MODE_LEARN_MORE}\n                data-approval-mode-learn-more=\"\"\n                data-menu-inset=\"\"\n                // biome-ignore lint/a11y/useAnchorContent: UI SDK renders the item's children into the link.\n                render={state.learnMoreHref ? <a href={state.learnMoreHref} /> : undefined}\n              >\n                Learn more\n              </KindMenuItem>\n            </>\n          ) : null}\n        </KindMenuContent>\n      )}\n    </parts.Content>\n  );\n}\n\nconst DEFAULT_ROWS = ({ rows }: ApprovalModeContentState) => <ApprovalModeRows rows={rows} />;\n\n// Shared, so an update doesn't render the default parts' wrappers again.\nconst DEFAULT_PARTS = (\n  <>\n    <ApprovalModeTrigger />\n    <ApprovalModeContent />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/approval-mode.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
