{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message-vue",
  "title": "Message (Vue)",
  "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/vue@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-toolbar-vue",
    "@kind-ui/internal-menu-vue"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/vue/message.ts",
      "content": "import {\n  type MessageAvatarState,\n  type MessageRegenerateContentState,\n  type MessageRegenerateState,\n  messagePrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@ui-sdk/vue/avatar\";\nimport { MenuTrigger } from \"@ui-sdk/vue/menu\";\nimport { createParts } from \"@ui-sdk/vue/primitive\";\nimport {\n  Comment,\n  cloneVNode,\n  defineComponent,\n  Fragment,\n  type FunctionalComponent,\n  h,\n  isVNode,\n  type PropType,\n  Text,\n  type VNode,\n} from \"vue\";\nimport {\n  KindMenu,\n  KindMenuContent,\n  KindMenuItem,\n  KindMenuItemContent,\n  KindMenuSeparator,\n  KindMenuSub,\n  KindMenuSubContent,\n  KindMenuSubTrigger,\n} from \"./internal/menu\";\n\n// `@ui-sdk/vue`'s `createParts` hands the primitive an emitter for every callback, whether or not anything listens, so\n// `onRegenerate` and `onEdit`, whose presence offers Regenerate and Edit, are declared function props instead, which\n// `@regenerate` and `@edit` bind. `@branch-change` and `@copy` stay events.\nconst primitive = Object.defineProperty(\n  Object.assign((options: never) => messagePrimitive(options), messagePrimitive, {\n    options: { ...messagePrimitive.options, onRegenerate: \"action\", onEdit: \"action\" },\n  }),\n  \"name\",\n  { value: messagePrimitive.name },\n) as typeof messagePrimitive;\n\nconst message = createParts(primitive, {\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/**\n * Name it with `aria-label`, like \"Assistant message\". A `regenerateOptions` row's `icon` is an image URL or a node\n * such as an inline `svg`. Regenerate and Edit are offered while `@regenerate` and `@edit` are bound.\n */\nexport const Message = message.Root;\n\n/** With an `author`, a UI SDK Avatar of their image, showing their initials until it loads, unless you pass children. */\nexport const MessageAvatar = defineComponent({\n  name: \"MessageAvatar\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.Avatar, attrs, {\n        ...slots,\n        default:\n          slots.default ??\n          (({ state }: { state: MessageAvatarState }) =>\n            state.name\n              ? h(Avatar, null, () => [\n                  state.src ? h(AvatarImage, { src: state.src, alt: \"\" }) : null,\n                  h(AvatarFallback, null, () => state.initials),\n                ])\n              : null),\n      });\n  },\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 const MessageAuthor = defineComponent({\n  name: \"MessageAuthor\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.Author, attrs, { ...slots, default: ({ state }: { state: { name: string } }) => state.name });\n  },\n});\n\n/** A `<time>` of `createdAt`: the time of day, with the date when it isn't today. */\nexport const MessageTime = defineComponent({\n  name: \"MessageTime\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.Time, attrs, { ...slots, default: ({ state }: { state: { label: string } }) => state.label });\n  },\n});\n\n/** How long the response took, like \"1 min 12 sec\". */\nexport const MessageDuration = defineComponent({\n  name: \"MessageDuration\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.Duration, attrs, {\n        ...slots,\n        default: ({ state }: { state: { label: string } }) => state.label,\n      });\n  },\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 const MessageOutcomeText = defineComponent({\n  name: \"MessageOutcomeText\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.OutcomeText, attrs, {\n        ...slots,\n        default: ({ state }: { state: { text: string } }) => state.text,\n      });\n  },\n});\n\n/** Shown while `onRetry` is set and the message failed. */\nexport const MessageRetry = defineComponent({\n  name: \"MessageRetry\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Retry, attrs, { ...slots, default: slots.default ?? (() => \"Retry\") });\n  },\n});\n\n/** Shown while `onContinue` is set and the message stopped. */\nexport const MessageContinue = defineComponent({\n  name: \"MessageContinue\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Continue, attrs, { ...slots, default: slots.default ?? (() => \"Continue\") });\n  },\n});\n\nconst outcome = () => [h(MessageOutcomeIcon), h(MessageOutcomeText), h(MessageRetry), h(MessageContinue)];\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 const MessageOutcome = defineComponent({\n  name: \"MessageOutcome\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Outcome, attrs, { ...slots, default: slots.default ?? outcome });\n  },\n});\n\n/** \"Steering…\", \"Queued, not sent\" or \"Not sent\": the message's accessible description while it isn't delivered. */\nexport const MessageDeliveryText = defineComponent({\n  name: \"MessageDeliveryText\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.DeliveryText, attrs, {\n        ...slots,\n        default: ({ state }: { state: { text: string } }) => state.text,\n      });\n  },\n});\n\nconst labelled = ({ state }: { state: { label: string } }) => state.label;\n\n/** Shown while `onWithdraw` is set and the message is queued or steering. \"Withdraw\", unless you pass children. */\nexport const MessageWithdraw = defineComponent({\n  name: \"MessageWithdraw\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Withdraw, attrs, { ...slots, default: slots.default ?? labelled });\n  },\n});\n\n/** Shown while `onResend` is set and the message wasn't sent. \"Retry\", unless you pass children. */\nexport const MessageResend = defineComponent({\n  name: \"MessageResend\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Resend, attrs, { ...slots, default: slots.default ?? labelled });\n  },\n});\n\nconst delivery = () => [h(MessageDeliveryText), h(MessageWithdraw), h(MessageResend)];\n\n/** Under a user message that isn't delivered yet: its words, then Withdraw or Retry, unless you pass children. */\nexport const MessageDelivery = defineComponent({\n  name: \"MessageDelivery\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Delivery, attrs, { ...slots, default: slots.default ?? delivery });\n  },\n});\n\nexport const MessageRetryingIcon = message.RetryingIcon;\n\n/** The retry's `reason`, as a sentence: \"Rate limited.\". */\nexport const MessageRetryingReason = defineComponent({\n  name: \"MessageRetryingReason\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.RetryingReason, attrs, {\n        ...slots,\n        default: ({ state }: { state: { reason: string } }) => state.reason,\n      });\n  },\n});\n\n/** \"Retrying in 4 sec, attempt 2 of 5\", counting down. */\nexport const MessageRetryingText = defineComponent({\n  name: \"MessageRetryingText\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.RetryingText, attrs, {\n        ...slots,\n        default: ({ state }: { state: { text: string } }) => state.text,\n      });\n  },\n});\n\n/** Shown while `onRetryNow` is set. \"Retry now\", unless you pass children. */\nexport const MessageRetryNow = defineComponent({\n  name: \"MessageRetryNow\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.RetryNow, attrs, { ...slots, default: slots.default ?? labelled });\n  },\n});\n\n/** Shown while `onCancelRetry` is set. \"Cancel\", unless you pass children. */\nexport const MessageCancelRetry = defineComponent({\n  name: \"MessageCancelRetry\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.CancelRetry, attrs, { ...slots, default: slots.default ?? labelled });\n  },\n});\n\nconst retrying = () => [\n  h(MessageRetryingIcon),\n  h(\"span\", null, [h(MessageRetryingReason), \" \", h(MessageRetryingText)]),\n  h(MessageRetryNow),\n  h(MessageCancelRetry),\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 const MessageRetrying = defineComponent({\n  name: \"MessageRetrying\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.Retrying, attrs, { ...slots, default: slots.default ?? retrying });\n  },\n});\n\nexport const MessageContent = message.Content;\n\n/** Ends the edit without saving, as Escape does. \"Cancel\", unless you pass children. */\nexport const MessageEditCancel = defineComponent({\n  name: \"MessageEditCancel\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.EditCancel, attrs, { ...slots, default: slots.default ?? (() => \"Cancel\") });\n  },\n});\n\n/** Saves the edit, as Enter does. \"Save\", unless you pass children. */\nexport const MessageEditSave = defineComponent({\n  name: \"MessageEditSave\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.EditSave, attrs, { ...slots, default: slots.default ?? (() => \"Save\") });\n  },\n});\n\nconst editActions = () => [h(MessageEditCancel), h(MessageEditSave)];\n\n/** Cancel and Save, shown while the message is edited. Enter and Escape do the same. */\nexport const MessageEditActions = defineComponent({\n  name: \"MessageEditActions\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(message.EditActions, attrs, { ...slots, default: slots.default ?? editActions });\n  },\n});\n\n/**\n * Shown in place of the content while a user message is edited. Its default slot is what follows the text area:\n * `<MessageEditActions />` unless you pass your own, or an empty slot for none.\n */\nexport const MessageEditor = defineComponent({\n  name: \"MessageEditor\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => [\n      h(message.Editor, attrs, slots.render ? { render: slots.render } : undefined),\n      slots.default ? slots.default() : h(MessageEditActions),\n    ];\n  },\n});\n\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\ntype RegenerateOption = MessageRegenerateContentState[\"options\"][number];\n\nconst Rows: FunctionalComponent<{ options: RegenerateOption[] }> = ({ options }): VNode[] =>\n  options.map((option) =>\n    option.items\n      ? h(KindMenuSub, { key: option.id }, () => [\n          h(KindMenuSubTrigger, null, () => [\n            h(KindMenuItemContent, {\n              icon: option.icon,\n              label: option.label,\n              description: option.description,\n            }),\n            h(\"span\", { \"data-menu-chevron\": \"\" }),\n          ]),\n          h(KindMenuSubContent, null, () => h(Rows, { options: option.items as RegenerateOption[] })),\n        ])\n      : h(KindMenuItem, { key: option.id, value: option.id, label: option.label }, () =>\n          h(KindMenuItemContent, { icon: option.icon, label: option.label, description: option.description }),\n        ),\n  );\nRows.props = [\"options\"];\n\n/** The regenerate menu's rows: \"Try again\", a separator, then the options, a submenu for each with `items`. */\nexport const MessageRegenerateRows = defineComponent({\n  name: \"MessageRegenerateRows\",\n  props: {\n    tryAgain: { type: Object as PropType<RegenerateOption>, required: true },\n    options: { type: Array as PropType<RegenerateOption[]>, required: true },\n  },\n  setup(props) {\n    return () => [\n      h(Rows, { options: [props.tryAgain] }),\n      h(KindMenuSeparator),\n      h(Rows, { options: props.options }),\n    ];\n  },\n});\n\n/**\n * The regenerate menu: UI SDK's `MenuContent` holding the rows unless you pass a default slot, which gets the rows'\n * state (`v-slot=\"{ state }\"`, with `state.tryAgain` and `state.options`). Attributes go to it.\n */\nexport const MessageRegenerateContent = defineComponent({\n  name: \"MessageRegenerateContent\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.RegenerateContent, null, {\n        render: slots.render,\n        default: ({ state }: { state: MessageRegenerateContentState }) => {\n          // Each key by name: the slot's state lists none, so a spread or `v-bind` would be empty.\n          const rows: MessageRegenerateContentState = { tryAgain: state.tryAgain, options: state.options };\n          // Hidden from agents, which use the Message's own `regenerate`. Kept in the page while closed, as on web,\n          // so the mark keeps Menu out of the snapshot while only its trigger would show.\n          return h(\n            KindMenuContent,\n            { align: \"start\", sideOffset: 6, keepMounted: true, \"data-agent-hidden\": \"\", ...attrs },\n            () => (slots.default ? slots.default({ state: rows }) : h(MessageRegenerateRows, rows)),\n          );\n        },\n      });\n  },\n});\n\n// The first element the slot holds, the toolbar button the trigger renders as.\nconst firstElement = (nodes: VNode[]): VNode | undefined => {\n  for (const node of nodes) {\n    if (!isVNode(node) || node.type === Comment || node.type === Text) continue;\n    if (node.type === Fragment) {\n      const inner = firstElement(node.children as VNode[]);\n      if (inner) return inner;\n      continue;\n    }\n    return node;\n  }\n  return undefined;\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. The\n * `#menuContent` slot replaces the menu, `<MessageRegenerateContent />` by default.\n */\nexport const MessageRegenerate = defineComponent({\n  name: \"MessageRegenerate\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.Regenerate, attrs, {\n        render: slots.render,\n        default: ({ state }: { state: MessageRegenerateState }) => {\n          const children = slots.default?.() ?? [];\n          const menu = state.menu;\n          const button = menu ? firstElement(children) : undefined;\n          if (!menu || !button) return children;\n          // Each key by name: the slot's state lists none, so a spread would be empty.\n          const menuProps = {\n            controller: menu.controller,\n            presentation: menu.presentation,\n            open: menu.open,\n            onOpenChange: menu.onOpenChange,\n            onAction: menu.onAction,\n            onCheckedChange: menu.onCheckedChange,\n            onValueChange: menu.onValueChange,\n          };\n          return h(KindMenu, menuProps, () => [\n            h(message.RegenerateTrigger, null, () =>\n              h(MenuTrigger, null, {\n                render: ({ props }: { props: Record<string, unknown> }) => cloneVNode(button, props, true),\n              }),\n            ),\n            slots.menuContent ? slots.menuContent() : h(MessageRegenerateContent),\n          ]);\n        },\n      });\n  },\n});\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 const MessageBranchLabel = defineComponent({\n  name: \"MessageBranchLabel\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () =>\n      h(message.BranchLabel, attrs, {\n        ...slots,\n        default: ({ state }: { state: { label: string } }) => state.label,\n      });\n  },\n});\nexport const MessageBranchNext = message.BranchNext;\n",
      "type": "registry:ui",
      "target": "@ui/vue/message.ts"
    }
  ],
  "meta": {
    "layer": "vue"
  },
  "type": "registry:ui"
}
