{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message",
  "title": "Message",
  "description": "A chat message with copy, regenerate, edit and branch controls.",
  "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-toolbar",
    "@kind-ui/internal-menu"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/message.tsx",
      "content": "\"use client\";\n\nimport {\n  type MessageOptions,\n  type MessageRegenerateContentState,\n  messagePrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@ui-sdk/react/avatar\";\nimport { MenuTrigger } from \"@ui-sdk/react/menu\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, isValidElement, type ReactElement, type ReactNode } from \"react\";\nimport {\n  KindMenu,\n  KindMenuContent,\n  KindMenuItem,\n  KindMenuItemContent,\n  KindMenuSeparator,\n  KindMenuSub,\n  KindMenuSubContent,\n  KindMenuSubTrigger,\n} from \"./internal/menu\";\n\nconst message = createParts(messagePrimitive, {\n  root: \"div\",\n  avatar: \"div\",\n  content: \"div\",\n  editor: \"textarea\",\n  \"edit-actions\": \"div\",\n  \"edit-cancel\": \"button\",\n  \"edit-save\": \"button\",\n  toolbar: \"div\",\n  copy: \"span\",\n  regenerate: \"span\",\n  \"regenerate-trigger\": \"span\",\n  \"regenerate-content\": \"span\",\n  edit: \"span\",\n  branch: \"div\",\n  \"branch-previous\": \"button\",\n  \"branch-label\": \"span\",\n  \"branch-next\": \"button\",\n  header: \"div\",\n  author: \"span\",\n  time: \"time\",\n  duration: \"span\",\n  outcome: \"div\",\n  \"outcome-icon\": \"span\",\n  \"outcome-text\": \"span\",\n  retry: \"button\",\n  continue: \"button\",\n  delivery: \"div\",\n  \"delivery-text\": \"span\",\n  withdraw: \"button\",\n  resend: \"button\",\n  retrying: \"div\",\n  \"retrying-icon\": \"span\",\n  \"retrying-reason\": \"span\",\n  \"retrying-text\": \"span\",\n  \"retry-now\": \"button\",\n  \"cancel-retry\": \"button\",\n});\n\n/** A regenerate option, whose `icon` is an image URL or an element such as an inline `svg`. */\nexport type MessageRegenerateOption = Omit<\n  NonNullable<MessageOptions[\"regenerateOptions\"]>[number],\n  \"icon\" | \"items\"\n> & {\n  icon?: string | ReactElement;\n  items?: MessageRegenerateOption[];\n};\n\nexport type MessageProps = Omit<ComponentProps<typeof message.Root>, \"regenerateOptions\"> & {\n  regenerateOptions?: MessageRegenerateOption[];\n};\n\n/** Name it with `aria-label`, like \"Assistant message\". */\nexport function Message(props: MessageProps) {\n  return <message.Root {...props} />;\n}\n\nexport type MessageAvatarProps = ComponentProps<typeof message.Avatar>;\n\n/** With an `author`, a UI SDK Avatar of their image, showing their initials until it loads, unless you pass children. */\nexport function MessageAvatar({\n  children = ({ name, initials, src }) =>\n    name ? (\n      <Avatar>\n        {src ? <AvatarImage src={src} alt=\"\" /> : null}\n        <AvatarFallback>{initials}</AvatarFallback>\n      </Avatar>\n    ) : null,\n  ...props\n}: MessageAvatarProps) {\n  return <message.Avatar {...props}>{children}</message.Avatar>;\n}\n\n/** Holds the author, time and duration, while any of them shows. */\nexport const MessageHeader = message.Header;\n\n/** The `author`'s name, unless the message is `continued`. */\nexport function MessageAuthor(props: Omit<ComponentProps<typeof message.Author>, \"children\">) {\n  return <message.Author {...props}>{({ name }) => name}</message.Author>;\n}\n\n/** A `<time>` of `createdAt`: the time of day, with the date when it isn't today. */\nexport function MessageTime(props: Omit<ComponentProps<typeof message.Time>, \"children\">) {\n  return <message.Time {...props}>{({ label }) => label}</message.Time>;\n}\n\n/** How long the response took, like \"1 min 12 sec\". */\nexport function MessageDuration(props: Omit<ComponentProps<typeof message.Duration>, \"children\">) {\n  return <message.Duration {...props}>{({ label }) => label}</message.Duration>;\n}\n\nexport const MessageOutcomeIcon = message.OutcomeIcon;\n\n/** \"Stopped\", \"Failed after 5 attempts\" while `retry` is still set, or the `error` option's words. */\nexport function MessageOutcomeText(props: Omit<ComponentProps<typeof message.OutcomeText>, \"children\">) {\n  return <message.OutcomeText {...props}>{({ text }) => text}</message.OutcomeText>;\n}\n\n/** Shown while `onRetry` is set and the message failed. */\nexport function MessageRetry({ children = \"Retry\", ...props }: ComponentProps<typeof message.Retry>) {\n  return <message.Retry {...props}>{children}</message.Retry>;\n}\n\n/** Shown while `onContinue` is set and the message stopped. */\nexport function MessageContinue({\n  children = \"Continue\",\n  ...props\n}: ComponentProps<typeof message.Continue>) {\n  return <message.Continue {...props}>{children}</message.Continue>;\n}\n\nconst OUTCOME = (\n  <>\n    <MessageOutcomeIcon />\n    <MessageOutcomeText />\n    <MessageRetry />\n    <MessageContinue />\n  </>\n);\n\n/**\n * Shown after the content once the response stopped or failed: its mark, its words, then Retry or Continue, unless\n * you pass children.\n */\nexport function MessageOutcome({ children = OUTCOME, ...props }: ComponentProps<typeof message.Outcome>) {\n  return <message.Outcome {...props}>{children}</message.Outcome>;\n}\n\n/** \"Steering…\", \"Queued, not sent\" or \"Not sent\": the message's accessible description while it isn't delivered. */\nexport function MessageDeliveryText(props: Omit<ComponentProps<typeof message.DeliveryText>, \"children\">) {\n  return <message.DeliveryText {...props}>{({ text }) => text}</message.DeliveryText>;\n}\n\n/** Shown while `onWithdraw` is set and the message is queued or steering. \"Withdraw\", unless you pass children. */\nexport function MessageWithdraw({\n  children = ({ label }) => label,\n  ...props\n}: ComponentProps<typeof message.Withdraw>) {\n  return <message.Withdraw {...props}>{children}</message.Withdraw>;\n}\n\n/** Shown while `onResend` is set and the message wasn't sent. \"Retry\", unless you pass children. */\nexport function MessageResend({\n  children = ({ label }) => label,\n  ...props\n}: ComponentProps<typeof message.Resend>) {\n  return <message.Resend {...props}>{children}</message.Resend>;\n}\n\nconst DELIVERY = (\n  <>\n    <MessageDeliveryText />\n    <MessageWithdraw />\n    <MessageResend />\n  </>\n);\n\n/** Under a user message that isn't delivered yet: its words, then Withdraw or Retry, unless you pass children. */\nexport function MessageDelivery({ children = DELIVERY, ...props }: ComponentProps<typeof message.Delivery>) {\n  return <message.Delivery {...props}>{children}</message.Delivery>;\n}\n\nexport const MessageRetryingIcon = message.RetryingIcon;\n\n/** The retry's `reason`, as a sentence: \"Rate limited.\". */\nexport function MessageRetryingReason(\n  props: Omit<ComponentProps<typeof message.RetryingReason>, \"children\">,\n) {\n  return <message.RetryingReason {...props}>{({ reason }) => reason}</message.RetryingReason>;\n}\n\n/** \"Retrying in 4 sec, attempt 2 of 5\", counting down. */\nexport function MessageRetryingText(props: Omit<ComponentProps<typeof message.RetryingText>, \"children\">) {\n  return <message.RetryingText {...props}>{({ text }) => text}</message.RetryingText>;\n}\n\n/** Shown while `onRetryNow` is set. \"Retry now\", unless you pass children. */\nexport function MessageRetryNow({\n  children = ({ label }) => label,\n  ...props\n}: ComponentProps<typeof message.RetryNow>) {\n  return <message.RetryNow {...props}>{children}</message.RetryNow>;\n}\n\n/** Shown while `onCancelRetry` is set. \"Cancel\", unless you pass children. */\nexport function MessageCancelRetry({\n  children = ({ label }) => label,\n  ...props\n}: ComponentProps<typeof message.CancelRetry>) {\n  return <message.CancelRetry {...props}>{children}</message.CancelRetry>;\n}\n\nconst RETRYING = (\n  <>\n    <MessageRetryingIcon />\n    <span>\n      <MessageRetryingReason /> <MessageRetryingText />\n    </span>\n    <MessageRetryNow />\n    <MessageCancelRetry />\n  </>\n);\n\n/**\n * Shown after the content while `retry` is set and the request hasn't failed: a running mark, the reason, the\n * countdown and attempt, then Retry now and Cancel, unless you pass children.\n */\nexport function MessageRetrying({ children = RETRYING, ...props }: ComponentProps<typeof message.Retrying>) {\n  return <message.Retrying {...props}>{children}</message.Retrying>;\n}\n\nexport const MessageContent = message.Content;\nexport type MessageEditorProps = Omit<ComponentProps<typeof message.Editor>, \"children\"> & {\n  /** What follows the text area: `<MessageEditActions />` by default. Pass your own, or `null` for none. */\n  children?: ReactNode;\n};\n\n/** Shown in place of the content while a user message is edited, with Cancel and Save after it unless you pass children. */\nexport function MessageEditor({ children = DEFAULT_EDIT_ACTIONS, ...props }: MessageEditorProps) {\n  return (\n    <>\n      <message.Editor {...props} />\n      {children}\n    </>\n  );\n}\n\n/** Cancel and Save, shown while the message is edited. Enter and Escape do the same. */\nexport function MessageEditActions({\n  children = EDIT_ACTIONS,\n  ...props\n}: ComponentProps<typeof message.EditActions>) {\n  return <message.EditActions {...props}>{children}</message.EditActions>;\n}\n\n/** Ends the edit without saving, as Escape does. \"Cancel\", unless you pass children. */\nexport function MessageEditCancel({\n  children = \"Cancel\",\n  ...props\n}: ComponentProps<typeof message.EditCancel>) {\n  return <message.EditCancel {...props}>{children}</message.EditCancel>;\n}\n\n/** Saves the edit, as Enter does. \"Save\", unless you pass children. */\nexport function MessageEditSave({ children = \"Save\", ...props }: ComponentProps<typeof message.EditSave>) {\n  return <message.EditSave {...props}>{children}</message.EditSave>;\n}\n\nconst EDIT_ACTIONS = (\n  <>\n    <MessageEditCancel />\n    <MessageEditSave />\n  </>\n);\nconst DEFAULT_EDIT_ACTIONS = <MessageEditActions />;\n/** Shown once the message settles. Holds the branch switcher and a `KindToolbar` of actions. */\nexport const MessageToolbar = message.Toolbar;\n/** Wrap a `KindToolbarButton` in each action: `<MessageCopy><KindToolbarButton aria-label=\"Copy\" /></MessageCopy>`. */\nexport const MessageCopy = message.Copy;\n\nexport type MessageRegenerateProps = Omit<ComponentProps<typeof message.Regenerate>, \"children\"> & {\n  /** The `KindToolbarButton` that regenerates, or opens the menu while there are `regenerateOptions`. */\n  children?: ReactNode;\n  /** The menu, while there are `regenerateOptions`: `<MessageRegenerateContent />` by default. */\n  menuContent?: ReactNode;\n};\n\n/**\n * Wraps the toolbar button that regenerates. While the message has `regenerateOptions`, the button opens a menu of\n * them instead, rendered through UI SDK's `MenuTrigger`, so it keeps its place in the toolbar's arrow-key order.\n */\nexport function MessageRegenerate({\n  children,\n  menuContent = DEFAULT_CONTENT,\n  ...props\n}: MessageRegenerateProps) {\n  return (\n    <message.Regenerate {...props}>\n      {({ menu }) =>\n        menu && isValidElement<Record<string, unknown>>(children) ? (\n          <KindMenu {...menu}>\n            <message.RegenerateTrigger>\n              <MenuTrigger render={children} />\n            </message.RegenerateTrigger>\n            {menuContent}\n          </KindMenu>\n        ) : (\n          children\n        )\n      }\n    </message.Regenerate>\n  );\n}\n\nfunction Rows({ options }: { options: MessageRegenerateContentState[\"options\"] }) {\n  return options.map((option) =>\n    option.items ? (\n      <KindMenuSub key={option.id}>\n        <KindMenuSubTrigger>\n          <KindMenuItemContent icon={option.icon} label={option.label} description={option.description} />\n          <span data-menu-chevron=\"\" />\n        </KindMenuSubTrigger>\n        <KindMenuSubContent>\n          <Rows options={option.items} />\n        </KindMenuSubContent>\n      </KindMenuSub>\n    ) : (\n      <KindMenuItem key={option.id} value={option.id} label={option.label}>\n        <KindMenuItemContent icon={option.icon} label={option.label} description={option.description} />\n      </KindMenuItem>\n    ),\n  );\n}\n\nexport type MessageRegenerateRowsProps = MessageRegenerateContentState;\n\n/** The regenerate menu's rows: \"Try again\", a separator, then the options, a submenu for each with `items`. */\nexport function MessageRegenerateRows({ tryAgain, options }: MessageRegenerateRowsProps) {\n  return (\n    <>\n      <Rows options={[tryAgain]} />\n      <KindMenuSeparator />\n      <Rows options={options} />\n    </>\n  );\n}\n\nexport type MessageRegenerateContentProps = Omit<ComponentProps<typeof KindMenuContent>, \"children\"> & {\n  /** What the menu holds, or a function of its rows: the rows by default. */\n  children?: ReactNode | ((state: MessageRegenerateContentState) => ReactNode);\n};\n\n/** The regenerate menu: UI SDK's `MenuContent` holding the rows unless you pass children. Props go to it. */\nexport function MessageRegenerateContent({\n  children = DEFAULT_ROWS,\n  ...props\n}: MessageRegenerateContentProps) {\n  return (\n    <message.RegenerateContent>\n      {(state) => (\n        // Hidden from agents, which use the Message's own `regenerate`. Kept in the page while closed, as on web, so\n        // the mark keeps Menu out of the snapshot while only its trigger would show.\n        <KindMenuContent align=\"start\" sideOffset={6} keepMounted data-agent-hidden=\"\" {...props}>\n          {typeof children === \"function\" ? children(state) : children}\n        </KindMenuContent>\n      )}\n    </message.RegenerateContent>\n  );\n}\n\nconst DEFAULT_ROWS = (state: MessageRegenerateContentState) => <MessageRegenerateRows {...state} />;\n// Shared, so an update doesn't render the default content's wrapper again.\nconst DEFAULT_CONTENT = <MessageRegenerateContent />;\n\nexport const MessageEdit = message.Edit;\nexport const MessageBranch = message.Branch;\nexport const MessageBranchPrevious = message.BranchPrevious;\n/** Shows the branch, like \"2 of 3\". */\nexport function MessageBranchLabel(props: Omit<ComponentProps<typeof message.BranchLabel>, \"children\">) {\n  return <message.BranchLabel {...props}>{({ label }) => label}</message.BranchLabel>;\n}\nexport const MessageBranchNext = message.BranchNext;\n",
      "type": "registry:ui",
      "target": "@ui/message.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
