{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message-solid",
  "title": "Message (Solid)",
  "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/solid@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-toolbar-solid",
    "@kind-ui/internal-menu-solid"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/solid/message.tsx",
      "content": "import {\n  type MessageOptions,\n  type MessageRegenerateContentState,\n  messagePrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport type { ComponentProps, JSX } from \"@solidjs/web\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@ui-sdk/solid/avatar\";\nimport { MenuTrigger } from \"@ui-sdk/solid/menu\";\nimport { createParts } from \"@ui-sdk/solid/primitive\";\nimport { createMemo, For, omit, Show } from \"solid-js\";\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 | JSX.Element;\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 as ComponentProps<typeof message.Root>)} />;\n}\n\nexport type MessageAvatarProps = ComponentProps<typeof message.Avatar>;\n\ntype AvatarState = { name: string; initials: string; src: string | undefined };\n\nconst defaultAvatar = (state: AvatarState) => (\n  <Show when={state.name}>\n    <Avatar>\n      <Show when={state.src}>{(src) => <AvatarImage src={src()} alt=\"\" />}</Show>\n      <AvatarFallback>{state.initials}</AvatarFallback>\n    </Avatar>\n  </Show>\n);\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(props: MessageAvatarProps) {\n  return <message.Avatar {...omit(props, \"children\")}>{props.children ?? defaultAvatar}</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}>{(state) => state.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}>{(state) => state.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}>{(state) => state.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}>{(state) => state.text}</message.OutcomeText>;\n}\n\n/** Shown while `onRetry` is set and the message failed. */\nexport function MessageRetry(props: ComponentProps<typeof message.Retry>) {\n  return <message.Retry {...omit(props, \"children\")}>{props.children ?? \"Retry\"}</message.Retry>;\n}\n\n/** Shown while `onContinue` is set and the message stopped. */\nexport function MessageContinue(props: ComponentProps<typeof message.Continue>) {\n  return <message.Continue {...omit(props, \"children\")}>{props.children ?? \"Continue\"}</message.Continue>;\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(props: ComponentProps<typeof message.Outcome>) {\n  return (\n    <message.Outcome {...omit(props, \"children\")}>\n      {props.children ?? (\n        <>\n          <MessageOutcomeIcon />\n          <MessageOutcomeText />\n          <MessageRetry />\n          <MessageContinue />\n        </>\n      )}\n    </message.Outcome>\n  );\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}>{(state) => state.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(props: ComponentProps<typeof message.Withdraw>) {\n  return (\n    <message.Withdraw {...omit(props, \"children\")}>\n      {props.children ?? ((state) => state.label)}\n    </message.Withdraw>\n  );\n}\n\n/** Shown while `onResend` is set and the message wasn't sent. \"Retry\", unless you pass children. */\nexport function MessageResend(props: ComponentProps<typeof message.Resend>) {\n  return (\n    <message.Resend {...omit(props, \"children\")}>{props.children ?? ((state) => state.label)}</message.Resend>\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(props: ComponentProps<typeof message.Delivery>) {\n  return (\n    <message.Delivery {...omit(props, \"children\")}>\n      {props.children ?? (\n        <>\n          <MessageDeliveryText />\n          <MessageWithdraw />\n          <MessageResend />\n        </>\n      )}\n    </message.Delivery>\n  );\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}>{(state) => state.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}>{(state) => state.text}</message.RetryingText>;\n}\n\n/** Shown while `onRetryNow` is set. \"Retry now\", unless you pass children. */\nexport function MessageRetryNow(props: ComponentProps<typeof message.RetryNow>) {\n  return (\n    <message.RetryNow {...omit(props, \"children\")}>\n      {props.children ?? ((state) => state.label)}\n    </message.RetryNow>\n  );\n}\n\n/** Shown while `onCancelRetry` is set. \"Cancel\", unless you pass children. */\nexport function MessageCancelRetry(props: ComponentProps<typeof message.CancelRetry>) {\n  return (\n    <message.CancelRetry {...omit(props, \"children\")}>\n      {props.children ?? ((state) => state.label)}\n    </message.CancelRetry>\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(props: ComponentProps<typeof message.Retrying>) {\n  return (\n    <message.Retrying {...omit(props, \"children\")}>\n      {props.children ?? (\n        <>\n          <MessageRetryingIcon />\n          <span>\n            <MessageRetryingReason /> <MessageRetryingText />\n          </span>\n          <MessageRetryNow />\n          <MessageCancelRetry />\n        </>\n      )}\n    </message.Retrying>\n  );\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?: JSX.Element;\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(props: MessageEditorProps) {\n  const child = createMemo(() => props.children);\n  return (\n    <>\n      <message.Editor {...omit(props, \"children\")} />\n      {child() === undefined ? <MessageEditActions /> : child()}\n    </>\n  );\n}\n\n/** Cancel and Save, shown while the message is edited. Enter and Escape do the same. */\nexport function MessageEditActions(props: ComponentProps<typeof message.EditActions>) {\n  return (\n    <message.EditActions {...omit(props, \"children\")}>\n      {props.children ?? (\n        <>\n          <MessageEditCancel />\n          <MessageEditSave />\n        </>\n      )}\n    </message.EditActions>\n  );\n}\n\n/** Ends the edit without saving, as Escape does. \"Cancel\", unless you pass children. */\nexport function MessageEditCancel(props: ComponentProps<typeof message.EditCancel>) {\n  return <message.EditCancel {...omit(props, \"children\")}>{props.children ?? \"Cancel\"}</message.EditCancel>;\n}\n\n/** Saves the edit, as Enter does. \"Save\", unless you pass children. */\nexport function MessageEditSave(props: ComponentProps<typeof message.EditSave>) {\n  return <message.EditSave {...omit(props, \"children\")}>{props.children ?? \"Save\"}</message.EditSave>;\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\n/** Renders the toolbar button, given the props it needs to open the regenerate menu (none without a menu). */\nexport type MessageRegenerateButton = (props: Record<string, unknown>) => JSX.Element;\n\nexport type MessageRegenerateProps = Omit<ComponentProps<typeof message.Regenerate>, \"children\"> & {\n  /**\n   * The `KindToolbarButton` that regenerates, or opens the menu while there are `regenerateOptions`. Pass it as a\n   * function of the props it spreads, `{(props) => <KindToolbarButton aria-label=\"Regenerate\" {...props} />}`, so it\n   * can be the menu's trigger; an element only regenerates.\n   */\n  children?: JSX.Element | MessageRegenerateButton;\n  /** The menu, while there are `regenerateOptions`: `<MessageRegenerateContent />` by default. */\n  menuContent?: JSX.Element;\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(props: MessageRegenerateProps) {\n  // Read once: each read of an element child builds it again.\n  const child = createMemo(() => props.children);\n  const button = () => {\n    const value = child();\n    return typeof value === \"function\" ? (value as MessageRegenerateButton) : undefined;\n  };\n  const plain = () => {\n    const render = button();\n    return render ? render({}) : (child() as JSX.Element);\n  };\n  return (\n    <message.Regenerate {...omit(props, \"children\", \"menuContent\")}>\n      {(state) => (\n        <Show when={button() && state.menu} fallback={plain()}>\n          <KindMenu {...state.menu}>\n            <message.RegenerateTrigger>\n              <MenuTrigger render={(trigger: Record<string, unknown>) => button()?.(trigger)} />\n            </message.RegenerateTrigger>\n            {props.menuContent ?? <MessageRegenerateContent />}\n          </KindMenu>\n        </Show>\n      )}\n    </message.Regenerate>\n  );\n}\n\nfunction Rows(props: { options: MessageRegenerateContentState[\"options\"] }) {\n  return (\n    <For each={props.options} keyed={(option) => option.id}>\n      {(option) => (\n        <Show\n          when={option().items}\n          fallback={\n            <KindMenuItem value={option().id} label={option().label}>\n              <KindMenuItemContent\n                icon={option().icon}\n                label={option().label}\n                description={option().description}\n              />\n            </KindMenuItem>\n          }\n        >\n          {(items) => (\n            <KindMenuSub>\n              <KindMenuSubTrigger>\n                <KindMenuItemContent\n                  icon={option().icon}\n                  label={option().label}\n                  description={option().description}\n                />\n                <span data-menu-chevron=\"\" />\n              </KindMenuSubTrigger>\n              <KindMenuSubContent>\n                <Rows options={items()} />\n              </KindMenuSubContent>\n            </KindMenuSub>\n          )}\n        </Show>\n      )}\n    </For>\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(props: MessageRegenerateRowsProps) {\n  return (\n    <>\n      <Rows options={[props.tryAgain]} />\n      <KindMenuSeparator />\n      <Rows options={props.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?: JSX.Element | ((state: MessageRegenerateContentState) => JSX.Element);\n};\n\n/** The regenerate menu: UI SDK's `MenuContent` holding the rows unless you pass children. Props go to it. */\nexport function MessageRegenerateContent(props: MessageRegenerateContentProps) {\n  const child = createMemo(() => props.children);\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\n          align=\"start\"\n          sideOffset={6}\n          keepMounted\n          data-agent-hidden=\"\"\n          {...omit(props, \"children\")}\n        >\n          {(() => {\n            const value = child();\n            return typeof value === \"function\"\n              ? value(state)\n              : (value ?? <MessageRegenerateRows tryAgain={state.tryAgain} options={state.options} />);\n          })()}\n        </KindMenuContent>\n      )}\n    </message.RegenerateContent>\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 function MessageBranchLabel(props: Omit<ComponentProps<typeof message.BranchLabel>, \"children\">) {\n  return <message.BranchLabel {...props}>{(state) => state.label}</message.BranchLabel>;\n}\nexport const MessageBranchNext = message.BranchNext;\n",
      "type": "registry:ui",
      "target": "@ui/solid/message.tsx"
    }
  ],
  "meta": {
    "layer": "solid"
  },
  "type": "registry:ui"
}
