@anvia/react-ui 1.2.2 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/attachment/index.d.ts +3 -21
  2. package/dist/attachment/index.js +3 -12
  3. package/dist/attachment-DsKTPumt.js +89 -0
  4. package/dist/attachment-DsKTPumt.js.map +1 -0
  5. package/dist/chat/index.d.ts +3 -144
  6. package/dist/chat/index.js +3 -25
  7. package/dist/chat-CAnvUEAv.js +1210 -0
  8. package/dist/chat-CAnvUEAv.js.map +1 -0
  9. package/dist/completion/index.d.ts +3 -29
  10. package/dist/completion/index.js +3 -16
  11. package/dist/completion-DDTKoZRJ.js +124 -0
  12. package/dist/completion-DDTKoZRJ.js.map +1 -0
  13. package/dist/connection-DeNq8wHS.js +203 -0
  14. package/dist/connection-DeNq8wHS.js.map +1 -0
  15. package/dist/contexts-B4ijG24z.js +212 -0
  16. package/dist/contexts-B4ijG24z.js.map +1 -0
  17. package/dist/elements-D4vmkkF8.js +19 -0
  18. package/dist/elements-D4vmkkF8.js.map +1 -0
  19. package/dist/graph-explorer/index.d.ts +54 -73
  20. package/dist/graph-explorer/index.d.ts.map +1 -0
  21. package/dist/graph-explorer/index.js +181 -248
  22. package/dist/graph-explorer/index.js.map +1 -1
  23. package/dist/human-input/index.d.ts +3 -78
  24. package/dist/human-input/index.js +3 -21
  25. package/dist/human-input-CsCbZomZ.js +314 -0
  26. package/dist/human-input-CsCbZomZ.js.map +1 -0
  27. package/dist/image/index.d.ts +3 -40
  28. package/dist/image/index.js +3 -12
  29. package/dist/image-D_7vaQCR.js +302 -0
  30. package/dist/image-D_7vaQCR.js.map +1 -0
  31. package/dist/index-B1Qs2Cjv.d.ts +145 -0
  32. package/dist/index-B1Qs2Cjv.d.ts.map +1 -0
  33. package/dist/index-BCBVcl0D.d.ts +277 -0
  34. package/dist/index-BCBVcl0D.d.ts.map +1 -0
  35. package/dist/index-CE22tsua.d.ts +20 -0
  36. package/dist/index-CE22tsua.d.ts.map +1 -0
  37. package/dist/index-CGqtpc6b.d.ts +25 -0
  38. package/dist/index-CGqtpc6b.d.ts.map +1 -0
  39. package/dist/index-DqdyM0Jm.d.ts +7 -0
  40. package/dist/index-DqdyM0Jm.d.ts.map +1 -0
  41. package/dist/index-Mw3ltwSG.d.ts +318 -0
  42. package/dist/index-Mw3ltwSG.d.ts.map +1 -0
  43. package/dist/index.d.ts +7 -40
  44. package/dist/index.js +34 -118
  45. package/dist/index.js.map +1 -1
  46. package/dist/message/index.d.ts +3 -105
  47. package/dist/message/index.js +3 -20
  48. package/dist/message-Dn3wW6yy.js +783 -0
  49. package/dist/message-Dn3wW6yy.js.map +1 -0
  50. package/dist/primitives-xfE7zfwJ.js +15 -0
  51. package/dist/primitives-xfE7zfwJ.js.map +1 -0
  52. package/dist/refs-Djj9rSvB.js +10 -0
  53. package/dist/refs-Djj9rSvB.js.map +1 -0
  54. package/dist/sandbox-desktop/index.d.ts +100 -104
  55. package/dist/sandbox-desktop/index.d.ts.map +1 -0
  56. package/dist/sandbox-desktop/index.js +344 -342
  57. package/dist/sandbox-desktop/index.js.map +1 -1
  58. package/dist/sandbox-terminal/index.d.ts +52 -56
  59. package/dist/sandbox-terminal/index.d.ts.map +1 -0
  60. package/dist/sandbox-terminal/index.js +217 -208
  61. package/dist/sandbox-terminal/index.js.map +1 -1
  62. package/dist/selection-toolbar/index.d.ts +3 -21
  63. package/dist/selection-toolbar/index.js +3 -13
  64. package/dist/selection-toolbar-CIkOoM-7.js +171 -0
  65. package/dist/selection-toolbar-CIkOoM-7.js.map +1 -0
  66. package/dist/shared-BSYElFU2.d.ts +2 -0
  67. package/dist/shared.d.ts +4 -14
  68. package/dist/shared.js +1 -43
  69. package/dist/stream/index.d.ts +2 -22
  70. package/dist/stream/index.js +1 -8
  71. package/dist/stream-CAO0x8_1.js +298 -0
  72. package/dist/stream-CAO0x8_1.js.map +1 -0
  73. package/dist/thread-list/index.d.ts +3 -47
  74. package/dist/thread-list/index.js +3 -18
  75. package/dist/thread-list-xJbGXFrE.js +228 -0
  76. package/dist/thread-list-xJbGXFrE.js.map +1 -0
  77. package/dist/ticket-CoJHBpdF.d.ts +32 -0
  78. package/dist/ticket-CoJHBpdF.d.ts.map +1 -0
  79. package/dist/value-BGGrx72L.js +13 -0
  80. package/dist/value-BGGrx72L.js.map +1 -0
  81. package/package.json +22 -22
  82. package/dist/attachment/index.js.map +0 -1
  83. package/dist/attachment-mbjsroli.d.ts +0 -9
  84. package/dist/chat/index.js.map +0 -1
  85. package/dist/chat-PSj1Fo4W.d.ts +0 -88
  86. package/dist/chunk-22EZJUPM.js +0 -120
  87. package/dist/chunk-22EZJUPM.js.map +0 -1
  88. package/dist/chunk-5FZKTDZR.js +0 -201
  89. package/dist/chunk-5FZKTDZR.js.map +0 -1
  90. package/dist/chunk-6XOJFLX4.js +0 -22
  91. package/dist/chunk-6XOJFLX4.js.map +0 -1
  92. package/dist/chunk-CKA4CE26.js +0 -25
  93. package/dist/chunk-CKA4CE26.js.map +0 -1
  94. package/dist/chunk-DLBNFBXQ.js +0 -425
  95. package/dist/chunk-DLBNFBXQ.js.map +0 -1
  96. package/dist/chunk-E73S3SOF.js +0 -404
  97. package/dist/chunk-E73S3SOF.js.map +0 -1
  98. package/dist/chunk-F6AKBUO3.js +0 -380
  99. package/dist/chunk-F6AKBUO3.js.map +0 -1
  100. package/dist/chunk-HGOPGZNQ.js +0 -195
  101. package/dist/chunk-HGOPGZNQ.js.map +0 -1
  102. package/dist/chunk-KHB5CHAU.js +0 -220
  103. package/dist/chunk-KHB5CHAU.js.map +0 -1
  104. package/dist/chunk-LHABOAOP.js +0 -316
  105. package/dist/chunk-LHABOAOP.js.map +0 -1
  106. package/dist/chunk-N5XQU36W.js +0 -410
  107. package/dist/chunk-N5XQU36W.js.map +0 -1
  108. package/dist/chunk-T3ZFZ3NP.js +0 -30
  109. package/dist/chunk-T3ZFZ3NP.js.map +0 -1
  110. package/dist/chunk-W2AHKMRS.js +0 -1092
  111. package/dist/chunk-W2AHKMRS.js.map +0 -1
  112. package/dist/chunk-Y2KAMPVJ.js +0 -1582
  113. package/dist/chunk-Y2KAMPVJ.js.map +0 -1
  114. package/dist/completion/index.js.map +0 -1
  115. package/dist/completion-input-DHlwrhxB.d.ts +0 -24
  116. package/dist/composer-6iCSIq6L.d.ts +0 -111
  117. package/dist/human-input/index.js.map +0 -1
  118. package/dist/human-input-CkLrZ8IC.d.ts +0 -27
  119. package/dist/image/index.js.map +0 -1
  120. package/dist/image-VZv6Ddsn.d.ts +0 -14
  121. package/dist/message/index.js.map +0 -1
  122. package/dist/message-CNRnZQwU.d.ts +0 -14
  123. package/dist/render-CRKWam2v.d.ts +0 -8
  124. package/dist/selection-toolbar/index.js.map +0 -1
  125. package/dist/selection-toolbar-Cwjbuv5S.d.ts +0 -14
  126. package/dist/shared.js.map +0 -1
  127. package/dist/stream/index.js.map +0 -1
  128. package/dist/thread-Bz6-1zaJ.d.ts +0 -12
  129. package/dist/thread-list/index.js.map +0 -1
  130. package/dist/thread-list-On8db4XL.d.ts +0 -34
  131. package/dist/ticket-pexI1zIa.d.ts +0 -33
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-Dn3wW6yy.js","names":[],"sources":["../src/strict-json.ts","../src/entities.ts","../src/format/message.ts","../src/message/actions.tsx","../src/message/entity.tsx","../src/message/markdown-entities.ts","../src/message/parts.tsx","../src/message/root.tsx","../src/message/index.ts"],"sourcesContent":["import type { ComposerEntityData } from \"./contexts/composer\";\n\nexport function isComposerEntityData(value: unknown): value is ComposerEntityData {\n return isComposerEntityDataWithAncestors(value, new WeakSet<object>());\n}\n\nfunction isComposerEntityDataWithAncestors(\n value: unknown,\n ancestors: WeakSet<object>,\n): value is ComposerEntityData {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n if (typeof value === \"number\") return Number.isFinite(value);\n if (typeof value !== \"object\" || ancestors.has(value)) return false;\n\n ancestors.add(value);\n try {\n if (Array.isArray(value)) {\n if (Object.getPrototypeOf(value) !== Array.prototype || !hasOnlyDenseArrayProperties(value)) {\n return false;\n }\n for (let index = 0; index < value.length; index += 1) {\n if (!isComposerEntityDataWithAncestors(value[index], ancestors)) return false;\n }\n return true;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) return false;\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key !== \"string\") return false;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (\n descriptor === undefined ||\n !descriptor.enumerable ||\n !(\"value\" in descriptor) ||\n !isComposerEntityDataWithAncestors(descriptor.value, ancestors)\n ) {\n return false;\n }\n }\n return true;\n } catch {\n return false;\n } finally {\n ancestors.delete(value);\n }\n}\n\nfunction hasOnlyDenseArrayProperties(value: unknown[]): boolean {\n const keys = Reflect.ownKeys(value);\n if (keys.length !== value.length + 1 || keys.at(-1) !== \"length\") return false;\n for (let index = 0; index < value.length; index += 1) {\n const key = String(index);\n if (keys[index] !== key) return false;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n return false;\n }\n }\n return true;\n}\n","import type { UIMessagePart } from \"@anvia/client\";\nimport type { ComposerEntity } from \"./contexts/composer\";\nimport { isComposerEntityData } from \"./strict-json\";\n\nexport type MessageTextSegment = {\n part: Extract<UIMessagePart, { type: \"text\" }>;\n from: number;\n to: number;\n};\n\nexport type MessageTextLayout = {\n text: string;\n segments: MessageTextSegment[];\n};\n\nexport function messageTextLayout(parts: readonly UIMessagePart[]): MessageTextLayout {\n const textParts = parts.filter(\n (part): part is Extract<UIMessagePart, { type: \"text\" }> => part.type === \"text\",\n );\n const segments: MessageTextSegment[] = [];\n let offset = 0;\n\n for (const [index, part] of textParts.entries()) {\n const from = offset;\n const to = from + part.text.length;\n segments.push({ part, from, to });\n offset = to + (index === textParts.length - 1 ? 0 : 2);\n }\n\n return {\n text: textParts.map((part) => part.text).join(\"\\n\\n\"),\n segments,\n };\n}\n\nexport function validComposerEntities(text: string, metadata: unknown): ComposerEntity[] {\n const candidates = composerEntityCandidates(metadata);\n const individuallyValid = candidates.flatMap((candidate, index) => {\n const entity = parseComposerEntity(candidate, text);\n return entity === undefined ? [] : [{ entity, index }];\n });\n individuallyValid.sort(\n (left, right) =>\n left.entity.range.from - right.entity.range.from ||\n left.entity.range.to - right.entity.range.to ||\n left.index - right.index,\n );\n\n const overlapping = new Set<number>();\n let groupStart = 0;\n let groupEnd = individuallyValid[0]?.entity.range.to ?? 0;\n let groupHasOverlap = false;\n for (let index = 1; index <= individuallyValid.length; index += 1) {\n const current = individuallyValid[index];\n if (current !== undefined && current.entity.range.from < groupEnd) {\n groupHasOverlap = true;\n groupEnd = Math.max(groupEnd, current.entity.range.to);\n continue;\n }\n if (groupHasOverlap) {\n for (let groupIndex = groupStart; groupIndex < index; groupIndex += 1) {\n const candidate = individuallyValid[groupIndex];\n if (candidate !== undefined) {\n overlapping.add(candidate.index);\n }\n }\n }\n groupStart = index;\n groupEnd = current?.entity.range.to ?? 0;\n groupHasOverlap = false;\n }\n\n return individuallyValid\n .filter((candidate) => !overlapping.has(candidate.index))\n .map((candidate) => candidate.entity);\n}\n\nexport function entitiesForTextSegment(\n entities: ComposerEntity[],\n segment: MessageTextSegment,\n): ComposerEntity[] {\n return entities.flatMap((entity) => {\n if (entity.range.from < segment.from || entity.range.to > segment.to) {\n return [];\n }\n return [\n {\n ...entity,\n range: {\n from: entity.range.from - segment.from,\n to: entity.range.to - segment.from,\n },\n },\n ];\n });\n}\n\nexport function shiftComposerEntityRanges(\n entities: ComposerEntity[],\n offset: number,\n): ComposerEntity[] {\n if (offset === 0) {\n return entities;\n }\n return entities.map((entity) => ({\n ...entity,\n range: {\n from: entity.range.from + offset,\n to: entity.range.to + offset,\n },\n }));\n}\n\nfunction composerEntityCandidates(metadata: unknown): unknown[] {\n if (!isRecord(metadata) || !isRecord(metadata.composer)) {\n return [];\n }\n return Array.isArray(metadata.composer.entities) ? metadata.composer.entities : [];\n}\n\nfunction parseComposerEntity(value: unknown, text: string): ComposerEntity | undefined {\n if (!isRecord(value) || !isRecord(value.range)) {\n return undefined;\n }\n if (\n !isNonEmptyString(value.id) ||\n !isNonEmptyString(value.triggerId) ||\n !isNonEmptyString(value.trigger) ||\n !isNonEmptyString(value.label) ||\n !isNonEmptyString(value.text)\n ) {\n return undefined;\n }\n const { from, to } = value.range;\n if (\n typeof from !== \"number\" ||\n typeof to !== \"number\" ||\n !Number.isInteger(from) ||\n !Number.isInteger(to) ||\n from < 0 ||\n to <= from ||\n to > text.length ||\n text.slice(from, to) !== value.text\n ) {\n return undefined;\n }\n if (value.data !== undefined && !isComposerEntityData(value.data)) return undefined;\n const entity: ComposerEntity = {\n id: value.id,\n triggerId: value.triggerId,\n trigger: value.trigger,\n label: value.label,\n text: value.text,\n range: { from, to },\n };\n if (value.data !== undefined) entity.data = value.data;\n return entity;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import type { UIMessage, UIMessagePart } from \"@anvia/client\";\n\nexport function messageText(message: UIMessage): string {\n return message.parts\n .filter((part): part is Extract<UIMessagePart, { type: \"text\" }> => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n}\n","import { forwardRef, type MouseEvent, useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { useChatContext, useMessage } from \"../contexts\";\nimport { messageText } from \"../format\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\nconst MessageActions = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function MessageActions(props, ref) {\n const chat = useChatContext();\n const { message } = useMessage();\n const index = chat.messages.findIndex((item) => item.id === message.id);\n if (\n message.role !== \"assistant\" ||\n index < 0 ||\n ((props.children == null || typeof props.children === \"boolean\") &&\n messageText(message).trim().length === 0)\n ) {\n return null;\n }\n const following = chat.messages.slice(index + 1);\n const nextUserIndex = following.findIndex((item) => item.role === \"user\");\n const exchangeRemainder = nextUserIndex < 0 ? following : following.slice(0, nextUserIndex);\n if (\n exchangeRemainder.some((item) => item.role === \"assistant\") ||\n (nextUserIndex < 0 && (chat.status === \"submitted\" || chat.status === \"streaming\"))\n ) {\n return null;\n }\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? (\n <>\n <MessageCopy />\n <MessageRegenerate />\n </>\n ),\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype MessageCopyState = \"idle\" | \"copied\" | \"error\";\n\nconst MessageCopy = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(function MessageCopy(\n { onClick, ...props },\n ref,\n) {\n const { message } = useMessage();\n const [copyState, setCopyState] = useState<MessageCopyState>(\"idle\");\n const text = messageText(message);\n const previousTextRef = useRef(text);\n const disabled = props.disabled ?? text.length === 0;\n\n useEffect(() => {\n if (previousTextRef.current !== text) {\n previousTextRef.current = text;\n setCopyState(\"idle\");\n }\n }, [text]);\n\n const handleClick = useCallback(\n async (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n const writeText = navigator.clipboard?.writeText;\n if (writeText === undefined) {\n setCopyState(\"error\");\n return;\n }\n try {\n await writeText.call(navigator.clipboard, text);\n setCopyState(\"copied\");\n } catch {\n setCopyState(\"error\");\n }\n },\n [disabled, onClick, text],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Copy\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": copyState,\n } as PrimitiveProps<\"button\">,\n ref,\n );\n});\n\nconst MessageRegenerate = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function MessageRegenerate({ onClick, ...props }, ref) {\n const chat = useChatContext();\n const { message } = useMessage();\n const latestAssistantMessage = [...chat.messages]\n .reverse()\n .find((item) => item.role === \"assistant\");\n const disabled =\n props.disabled ??\n (chat.status === \"submitted\" ||\n chat.status === \"streaming\" ||\n message.role !== \"assistant\" ||\n latestAssistantMessage?.id !== message.id);\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n void chat.regenerate();\n },\n [chat, disabled, onClick],\n );\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Regenerate\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"idle\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nexport { MessageActions, MessageCopy, MessageRegenerate };\n","import { forwardRef, type HTMLAttributes } from \"react\";\nimport type { ComposerEntity } from \"../contexts\";\n\nexport type MessageEntityProps = HTMLAttributes<HTMLSpanElement> & {\n entity: ComposerEntity;\n};\n\nconst MessageEntity = forwardRef<HTMLSpanElement, MessageEntityProps>(function MessageEntity(\n { children, entity, ...props },\n ref,\n) {\n return (\n <span {...props} data-role=\"entity\" ref={ref}>\n {children ?? entity.text}\n </span>\n );\n});\n\nexport { MessageEntity };\n","import type { Options as ReactMarkdownOptions } from \"react-markdown\";\nimport type { ComposerEntity } from \"../contexts\";\n\ntype MarkdownPoint = {\n offset?: number | undefined;\n};\n\ntype MarkdownPosition = {\n start: MarkdownPoint;\n end: MarkdownPoint;\n};\n\ntype MarkdownNode = {\n type: string;\n value?: string | undefined;\n children?: MarkdownNode[] | undefined;\n position?: MarkdownPosition | undefined;\n entityIndex?: number | undefined;\n};\n\nconst phrasingParentTypes = new Set([\n \"paragraph\",\n \"heading\",\n \"emphasis\",\n \"strong\",\n \"delete\",\n \"link\",\n \"linkReference\",\n \"tableCell\",\n]);\nconst literalNodeTypes = new Set([\"code\", \"inlineCode\", \"html\", \"yaml\"]);\n\nexport function createMessageEntityRemarkPlugin(markdown: string, entities: ComposerEntity[]) {\n return function messageEntityRemarkPlugin() {\n return (tree: MarkdownNode): void => {\n const rendered = new Set<number>();\n transformNode(tree, markdown, entities, rendered);\n };\n };\n}\n\nexport function messageEntityRehypeOptions(): ReactMarkdownOptions[\"remarkRehypeOptions\"] {\n return {\n handlers: {\n messageEntity(_state: unknown, node: MarkdownNode) {\n const entityIndex = node.entityIndex;\n return {\n type: \"element\",\n tagName: \"span\",\n properties: {\n dataEntityIndex: entityIndex === undefined ? \"\" : String(entityIndex),\n },\n children: [{ type: \"text\", value: node.value ?? \"\" }],\n };\n },\n } as never,\n };\n}\n\nfunction transformNode(\n node: MarkdownNode,\n markdown: string,\n entities: ComposerEntity[],\n rendered: Set<number>,\n): void {\n if (literalNodeTypes.has(node.type) || node.children === undefined) {\n return;\n }\n\n for (const child of node.children) {\n transformNode(child, markdown, entities, rendered);\n }\n if (!phrasingParentTypes.has(node.type)) {\n return;\n }\n\n for (let entityIndex = entities.length - 1; entityIndex >= 0; entityIndex -= 1) {\n if (rendered.has(entityIndex)) {\n continue;\n }\n const entity = entities[entityIndex];\n if (entity !== undefined && replaceEntity(node, markdown, entity, entityIndex)) {\n rendered.add(entityIndex);\n }\n }\n}\n\nfunction replaceEntity(\n parent: MarkdownNode,\n markdown: string,\n entity: ComposerEntity,\n entityIndex: number,\n): boolean {\n const children = parent.children;\n if (children === undefined) {\n return false;\n }\n const firstIndex = children.findIndex((child) => containsStart(child, entity.range.from));\n const lastIndex = findLastIndex(children, (child) => containsEnd(child, entity.range.to));\n if (firstIndex < 0 || lastIndex < firstIndex) {\n return false;\n }\n\n const first = children[firstIndex];\n const last = children[lastIndex];\n const firstPosition = offsets(first);\n const lastPosition = offsets(last);\n if (\n first === undefined ||\n last === undefined ||\n firstPosition === undefined ||\n lastPosition === undefined ||\n entity.range.from < firstPosition.from ||\n entity.range.to > lastPosition.to\n ) {\n return false;\n }\n\n if (firstIndex === lastIndex && literalNodeTypes.has(first.type)) {\n return false;\n }\n const before = contentBefore(first, markdown, entity);\n const after = contentAfter(last, markdown, entity);\n if (before === undefined || after === undefined) {\n return false;\n }\n\n const replacement: MarkdownNode[] = [];\n replacement.push(...before);\n replacement.push({\n type: \"messageEntity\",\n value: entity.text,\n entityIndex,\n position: {\n start: { offset: entity.range.from },\n end: { offset: entity.range.to },\n },\n });\n replacement.push(...after);\n children.splice(firstIndex, lastIndex - firstIndex + 1, ...replacement);\n return true;\n}\n\nfunction contentBefore(\n node: MarkdownNode,\n markdown: string,\n entity: ComposerEntity,\n): MarkdownNode[] | undefined {\n const position = offsets(node);\n if (position === undefined) {\n return undefined;\n }\n if (entity.range.from === position.from) {\n return [];\n }\n if (node.type !== \"text\" || node.value === undefined) {\n if (node.children === undefined || literalNodeTypes.has(node.type)) {\n return undefined;\n }\n const childIndex = node.children.findIndex((child) => containsStart(child, entity.range.from));\n const child = node.children[childIndex];\n if (child === undefined) {\n return undefined;\n }\n const childContent = contentBefore(child, markdown, entity);\n return childContent === undefined\n ? undefined\n : [...node.children.slice(0, childIndex), ...childContent];\n }\n const split = textValueRange(node, markdown, entity);\n if (split === undefined) {\n return undefined;\n }\n return [\n {\n ...node,\n value: node.value.slice(0, split.from),\n position: {\n start: node.position?.start ?? {},\n end: { offset: entity.range.from },\n },\n },\n ];\n}\n\nfunction contentAfter(\n node: MarkdownNode,\n markdown: string,\n entity: ComposerEntity,\n): MarkdownNode[] | undefined {\n const position = offsets(node);\n if (position === undefined) {\n return undefined;\n }\n if (entity.range.to === position.to) {\n return [];\n }\n if (node.type !== \"text\" || node.value === undefined) {\n if (node.children === undefined || literalNodeTypes.has(node.type)) {\n return undefined;\n }\n const childIndex = findLastIndex(node.children, (child) => containsEnd(child, entity.range.to));\n const child = node.children[childIndex];\n if (child === undefined) {\n return undefined;\n }\n const childContent = contentAfter(child, markdown, entity);\n return childContent === undefined\n ? undefined\n : [...childContent, ...node.children.slice(childIndex + 1)];\n }\n const split = textValueRange(node, markdown, entity);\n if (split === undefined) {\n return undefined;\n }\n return [\n {\n ...node,\n value: node.value.slice(split.to),\n position: {\n start: { offset: entity.range.to },\n end: node.position?.end ?? {},\n },\n },\n ];\n}\n\nfunction textValueRange(\n node: MarkdownNode,\n markdown: string,\n entity: ComposerEntity,\n): { from: number; to: number } | undefined {\n const position = offsets(node);\n const value = node.value;\n if (position === undefined || value === undefined) {\n return undefined;\n }\n const raw = markdown.slice(position.from, position.to);\n const relativeFrom = entity.range.from - position.from;\n const relativeTo = entity.range.to - position.from;\n if (raw === value) {\n return { from: relativeFrom, to: relativeTo };\n }\n\n const occurrence = countOccurrences(raw.slice(0, relativeFrom), entity.text);\n const valueFrom = occurrenceIndex(value, entity.text, occurrence);\n return valueFrom === undefined\n ? undefined\n : { from: valueFrom, to: valueFrom + entity.text.length };\n}\n\nfunction countOccurrences(value: string, search: string): number {\n let count = 0;\n let offset = 0;\n while (offset <= value.length - search.length) {\n const index = value.indexOf(search, offset);\n if (index < 0) {\n break;\n }\n count += 1;\n offset = index + search.length;\n }\n return count;\n}\n\nfunction occurrenceIndex(value: string, search: string, occurrence: number): number | undefined {\n let offset = 0;\n for (let index = 0; index <= occurrence; index += 1) {\n const found = value.indexOf(search, offset);\n if (found < 0) {\n return undefined;\n }\n if (index === occurrence) {\n return found;\n }\n offset = found + search.length;\n }\n return undefined;\n}\n\nfunction containsStart(node: MarkdownNode, offset: number): boolean {\n const position = offsets(node);\n return position !== undefined && offset >= position.from && offset < position.to;\n}\n\nfunction containsEnd(node: MarkdownNode, offset: number): boolean {\n const position = offsets(node);\n return position !== undefined && offset > position.from && offset <= position.to;\n}\n\nfunction offsets(node: MarkdownNode | undefined): { from: number; to: number } | undefined {\n const from = node?.position?.start.offset;\n const to = node?.position?.end.offset;\n return typeof from === \"number\" && typeof to === \"number\" ? { from, to } : undefined;\n}\n\nfunction findLastIndex<T>(items: T[], predicate: (item: T) => boolean): number {\n for (let index = items.length - 1; index >= 0; index -= 1) {\n const item = items[index];\n if (item !== undefined && predicate(item)) {\n return index;\n }\n }\n return -1;\n}\n","import type { UIAttachment, UIMessagePart } from \"@anvia/client\";\nimport {\n type SmoothStreamItemAdapter,\n type StreamSmoothingLifecycle,\n useSmoothStreamItems,\n useSmoothStreamText,\n} from \"@anvia/react\";\nimport {\n type ComponentPropsWithoutRef,\n createElement,\n forwardRef,\n type ReactNode,\n useMemo,\n} from \"react\";\nimport type { Components, Options as ReactMarkdownOptions } from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\n\nimport { AttachmentPrimitive } from \"../attachment/index\";\nimport type { ComposerEntity } from \"../contexts\";\nimport {\n InternalAttachmentProvider,\n InternalMessagePartProvider,\n useMessage,\n useMessagePart,\n useOptionalMessagePart,\n} from \"../contexts\";\nimport { entitiesForTextSegment, messageTextLayout, validComposerEntities } from \"../entities\";\nimport { stringifyValue } from \"../format\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\nimport { StreamMarkdown } from \"../stream\";\nimport { MessageEntity } from \"./entity\";\nimport { createMessageEntityRemarkPlugin, messageEntityRehypeOptions } from \"./markdown-entities\";\n\ntype MessagePartChildren = ReactNode | ((part: UIMessagePart) => ReactNode);\nexport type MessagePartsFilter = (part: UIMessagePart) => boolean;\nexport type MessageToolPart = Extract<UIMessagePart, { type: \"tool\" }>;\ntype MessageToolChildren = ReactNode | ((part: MessageToolPart) => ReactNode);\nexport type MessageToolRenderWhen = \"always\" | \"pending\" | \"settled\";\nexport type MessageAttachmentPart = Extract<UIMessagePart, { type: \"attachment\" }>;\ntype MessageAttachmentChildren = ReactNode | ((attachment: UIAttachment) => ReactNode);\n\nexport type MessageStreamOptions = StreamSmoothingLifecycle;\n\ntype MessageStreamProps = {\n stream?: MessageStreamOptions;\n};\n\nconst messagePartStreamAdapter: SmoothStreamItemAdapter<UIMessagePart> = {\n getKey: (part) => part.id,\n getText: (part) => (part.type === \"text\" || part.type === \"reasoning\" ? part.text : undefined),\n withText: (part, text) => {\n if (part.type === \"text\" || part.type === \"reasoning\") {\n return part.text === text ? part : { ...part, text };\n }\n return part;\n },\n};\n\ntype MessagePartsProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: MessagePartChildren;\n filter?: MessagePartsFilter;\n} & MessageStreamProps;\n\nconst MessageParts = forwardRef<HTMLDivElement, MessagePartsProps>(function MessageParts(\n { children, filter, stream, ...props },\n ref,\n) {\n const { message } = useMessage();\n const parts = filter === undefined ? message.parts : message.parts.filter(filter);\n if (stream !== undefined) {\n return (\n <SmoothedMessageParts {...props} parts={parts} ref={ref} stream={stream}>\n {children}\n </SmoothedMessageParts>\n );\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderMessagePartNodes(parts, children),\n \"data-role\": \"parts\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\ntype SmoothedMessagePartsProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: MessagePartChildren;\n parts: readonly UIMessagePart[];\n stream: MessageStreamOptions;\n};\n\nconst SmoothedMessageParts = forwardRef<HTMLDivElement, SmoothedMessagePartsProps>(\n function SmoothedMessageParts({ children, parts, stream, ...props }, ref) {\n const streamOptions = {\n adapter: messagePartStreamAdapter,\n isStreaming: stream.isStreaming,\n resetKey: stream.resetKey,\n };\n if (stream.flushImmediately !== undefined) {\n Object.assign(streamOptions, { flushImmediately: stream.flushImmediately });\n }\n const smooth = useSmoothStreamItems(parts, streamOptions);\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderMessagePartNodes(smooth.items, children, smooth.liveItemKey),\n \"data-role\": \"parts\",\n \"data-state\": smooth.isDraining ? \"draining\" : stream.isStreaming ? \"streaming\" : \"idle\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nfunction renderMessagePartNodes(\n parts: readonly UIMessagePart[],\n children: MessagePartChildren | undefined,\n liveItemKey?: string | null,\n): ReactNode[] {\n return parts.map((part) => (\n <InternalMessagePartProvider\n isLive={liveItemKey === part.id}\n key={part.id}\n part={part}\n streamControlled={liveItemKey !== undefined}\n >\n {typeof children === \"function\" ? children(part) : (children ?? <MessagePart />)}\n </InternalMessagePartProvider>\n ));\n}\n\ntype MessagePartProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: MessagePartChildren;\n};\n\nconst MessagePart = forwardRef<HTMLDivElement, MessagePartProps>(function MessagePart(\n { children, ...props },\n ref,\n) {\n const { part } = useMessagePart();\n const renderedChildren =\n typeof children === \"function\" ? children(part) : (children ?? defaultPart(part));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n \"data-role\": part.type,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\ntype MessageTextProps = PrimitiveProps<\"span\"> & MessageStreamProps;\n\nconst MessageText = forwardRef<HTMLSpanElement, MessageTextProps>(function MessageText(props, ref) {\n const { part, streamControlled } = useMessagePart();\n if (part.type !== \"text\") {\n return null;\n }\n\n return (\n <MessageTextContent\n {...props}\n content={part.text}\n partId={part.id}\n ref={ref}\n streamControlled={streamControlled}\n />\n );\n});\n\ntype MessageTextContentProps = MessageTextProps & {\n content: string;\n partId: string;\n streamControlled: boolean;\n};\n\nconst MessageTextContent = forwardRef<HTMLSpanElement, MessageTextContentProps>(\n function MessageTextContent({ content, partId, stream, streamControlled, ...props }, ref) {\n const ownsStream = stream !== undefined && !streamControlled && props.children === undefined;\n const streamOptions = {\n isStreaming: ownsStream ? stream.isStreaming : false,\n resetKey: ownsStream ? stream.resetKey : partId,\n };\n if (ownsStream && stream.flushImmediately !== undefined) {\n Object.assign(streamOptions, { flushImmediately: stream.flushImmediately });\n }\n const smooth = useSmoothStreamText(content, streamOptions);\n\n return renderPrimitive(\n \"span\",\n {\n ...props,\n children: props.children ?? (ownsStream ? smooth.text : content),\n \"data-role\": \"text\",\n \"data-state\": ownsStream\n ? smooth.isDraining\n ? \"draining\"\n : stream.isStreaming\n ? \"streaming\"\n : \"idle\"\n : undefined,\n } as PrimitiveProps<\"span\">,\n ref,\n );\n },\n);\n\ntype MessageMarkdownProps = Omit<PrimitiveProps<\"div\">, \"children\"> &\n MessageStreamProps & {\n children?: string;\n components?: Components;\n renderEntity?: ((entity: ComposerEntity) => ReactNode) | undefined;\n remarkPlugins?: ReactMarkdownOptions[\"remarkPlugins\"];\n };\n\nconst MessageMarkdown = forwardRef<HTMLDivElement, MessageMarkdownProps>(function MessageMarkdown(\n { children, ...props },\n ref,\n) {\n const { message } = useMessage();\n const partContext = useOptionalMessagePart();\n const part = partContext?.part;\n if (part !== undefined && part.type !== \"text\") {\n return null;\n }\n\n const layout = messageTextLayout(message.parts);\n const markdown = children ?? (part?.type === \"text\" ? part.text : layout.text);\n const expectedMarkdown = part?.type === \"text\" ? part.text : layout.text;\n const validEntities =\n children === undefined || children === expectedMarkdown\n ? validComposerEntities(layout.text, message.metadata)\n : [];\n const segment =\n part?.type === \"text\"\n ? layout.segments.find((candidate) => candidate.part.id === part.id)\n : undefined;\n const entities =\n segment === undefined ? validEntities : entitiesForTextSegment(validEntities, segment);\n const lastPart = message.parts.at(-1);\n const liveEligible = part?.type === \"text\" ? lastPart?.id === part.id : lastPart?.type === \"text\";\n\n return (\n <MessageMarkdownContent\n {...props}\n entities={entities}\n liveEligible={liveEligible}\n markdown={markdown}\n ref={ref}\n resetKey={message.id}\n streamControlled={partContext?.streamControlled ?? false}\n streamLive={partContext?.isLive ?? false}\n />\n );\n});\n\ntype MessageMarkdownContentProps = Omit<MessageMarkdownProps, \"children\"> & {\n entities: ComposerEntity[];\n liveEligible: boolean;\n markdown: string;\n resetKey: string;\n streamControlled: boolean;\n streamLive: boolean;\n};\n\nconst MessageMarkdownContent = forwardRef<HTMLDivElement, MessageMarkdownContentProps>(\n function MessageMarkdownContent(\n {\n components,\n renderEntity,\n remarkPlugins,\n entities,\n liveEligible,\n markdown,\n resetKey,\n stream,\n streamControlled,\n streamLive,\n ...props\n },\n ref,\n ) {\n const ownsStream = stream !== undefined && !streamControlled;\n const streamOptions = {\n isStreaming: ownsStream ? stream.isStreaming : false,\n resetKey: ownsStream ? stream.resetKey : resetKey,\n };\n if (ownsStream && stream.flushImmediately !== undefined) {\n Object.assign(streamOptions, { flushImmediately: stream.flushImmediately });\n }\n const smooth = useSmoothStreamText(markdown, streamOptions);\n const renderedMarkdown = ownsStream ? smooth.text : markdown;\n const renderedEntities = useMemo(\n () =>\n entities.length === 0\n ? entities\n : validComposerEntities(renderedMarkdown, {\n composer: { entities },\n }),\n [entities, renderedMarkdown],\n );\n const renderedComponents = useMemo(\n () => markdownComponents(components, renderedEntities, renderEntity),\n [components, renderEntity, renderedEntities],\n );\n const renderedRemarkPlugins = useMemo(\n () =>\n renderedEntities.length === 0\n ? remarkPlugins\n : [\n createMessageEntityRemarkPlugin(renderedMarkdown, renderedEntities),\n ...(remarkPlugins ?? [remarkGfm]),\n ],\n [remarkPlugins, renderedEntities, renderedMarkdown],\n );\n const live = streamControlled\n ? streamLive\n : ownsStream && liveEligible && (stream.isStreaming || smooth.isDraining);\n\n return (\n <StreamMarkdown\n {...props}\n components={renderedComponents}\n content={renderedMarkdown}\n data-state={\n ownsStream && smooth.isDraining\n ? \"draining\"\n : ownsStream && stream.isStreaming\n ? \"streaming\"\n : \"idle\"\n }\n live={live}\n ref={ref}\n remarkPlugins={renderedRemarkPlugins}\n remarkRehypeOptions={\n renderedEntities.length === 0 ? undefined : messageEntityRehypeOptions()\n }\n />\n );\n },\n);\n\nfunction markdownComponents(\n components: Components | undefined,\n entities: ComposerEntity[],\n renderEntity: ((entity: ComposerEntity) => ReactNode) | undefined,\n): Components {\n const consumerSpan = components?.span;\n return {\n code: defaultCodeComponent,\n pre: defaultPreComponent,\n ...components,\n span(spanProps) {\n const internalProps = spanProps as typeof spanProps & {\n \"data-entity-index\"?: string | undefined;\n };\n const entityIndexValue = internalProps[\"data-entity-index\"];\n const entityIndex =\n typeof entityIndexValue === \"string\" && /^\\d+$/.test(entityIndexValue)\n ? Number(entityIndexValue)\n : undefined;\n const entity = entityIndex === undefined ? undefined : entities[entityIndex];\n const consumerProps = { ...internalProps };\n delete consumerProps[\"data-entity-index\"];\n\n if (entity !== undefined) {\n if (renderEntity !== undefined) {\n return renderEntity(entity);\n }\n const entityProps = {\n ...consumerProps,\n \"data-role\": \"entity\",\n };\n if (consumerSpan !== undefined) {\n return createElement(consumerSpan, entityProps);\n }\n const { node: _node, ...elementProps } = entityProps;\n return <MessageEntity {...elementProps} entity={entity} />;\n }\n\n if (consumerSpan !== undefined) {\n return createElement(consumerSpan, consumerProps);\n }\n const { node: _node, ...elementProps } = consumerProps;\n return <span {...elementProps} />;\n },\n };\n}\n\ntype MessageCodeBlockProps = Omit<PrimitiveProps<\"pre\">, \"children\"> & {\n children?: ReactNode;\n code?: string;\n language?: string;\n};\n\nconst MessageCodeBlock = forwardRef<HTMLPreElement, MessageCodeBlockProps>(\n function MessageCodeBlock({ children, code, language, ...props }, ref) {\n return renderPrimitive(\n \"pre\",\n {\n ...props,\n \"data-role\": \"code-block\",\n children: children ?? (\n <code className={language === undefined ? undefined : `language-${language}`}>\n {code ?? \"\"}\n </code>\n ),\n } as PrimitiveProps<\"pre\">,\n ref,\n );\n },\n);\n\nconst MessageReasoning = forwardRef<HTMLDetailsElement, PrimitiveProps<\"details\">>(\n function MessageReasoning(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"reasoning\") {\n return null;\n }\n\n return renderPrimitive(\n \"details\",\n {\n ...props,\n children: props.children ?? (\n <>\n <summary>Reasoning</summary>\n <pre>{part.text}</pre>\n </>\n ),\n } as PrimitiveProps<\"details\">,\n ref,\n );\n },\n);\n\ntype MessageToolProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: MessageToolChildren;\n renderWhen?: MessageToolRenderWhen;\n};\n\nconst MessageTool = forwardRef<HTMLDivElement, MessageToolProps>(function MessageTool(\n { children, renderWhen = \"always\", ...props },\n ref,\n) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\" || !shouldRenderTool(part, renderWhen)) {\n return null;\n }\n const renderedChildren =\n typeof children === \"function\" ? children(part) : (children ?? defaultToolContent());\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n \"data-role\": \"tool\",\n \"data-state\": part.state,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n\nconst MessageToolName = forwardRef<HTMLSpanElement, PrimitiveProps<\"span\">>(\n function MessageToolName(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\") {\n return null;\n }\n\n return renderPrimitive(\n \"span\",\n {\n ...props,\n children: props.children ?? part.toolName,\n } as PrimitiveProps<\"span\">,\n ref,\n );\n },\n);\n\nconst MessageToolStatus = forwardRef<HTMLSpanElement, PrimitiveProps<\"span\">>(\n function MessageToolStatus(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\") {\n return null;\n }\n\n return renderPrimitive(\n \"span\",\n {\n ...props,\n children: props.children ?? toolStateLabel(part.state),\n \"data-state\": part.state,\n } as PrimitiveProps<\"span\">,\n ref,\n );\n },\n);\n\nconst MessageToolInput = forwardRef<HTMLPreElement, PrimitiveProps<\"pre\">>(\n function MessageToolInput(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\") {\n return null;\n }\n\n return renderPrimitive(\n \"pre\",\n {\n ...props,\n children: props.children ?? stringifyValue(part.input),\n } as PrimitiveProps<\"pre\">,\n ref,\n );\n },\n);\n\nconst MessageToolOutput = forwardRef<HTMLPreElement, PrimitiveProps<\"pre\">>(\n function MessageToolOutput(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\" || part.state !== \"output-available\") {\n return null;\n }\n\n return renderPrimitive(\n \"pre\",\n {\n ...props,\n children: props.children ?? stringifyValue(part.output),\n } as PrimitiveProps<\"pre\">,\n ref,\n );\n },\n);\n\nconst MessageToolError = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function MessageToolError(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"tool\" || part.state !== \"error\") {\n return null;\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? part.error.message,\n role: props.role ?? \"alert\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\ntype MessageAttachmentProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: MessageAttachmentChildren;\n};\n\nconst MessageAttachment = forwardRef<HTMLDivElement, MessageAttachmentProps>(\n function MessageAttachment({ children, ...props }, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"attachment\") {\n return null;\n }\n const renderedChildren =\n typeof children === \"function\"\n ? children(part.attachment)\n : (children ?? <AttachmentPrimitive.Root />);\n\n return (\n <InternalAttachmentProvider value={{ attachment: part.attachment }}>\n {renderPrimitive(\n \"div\",\n {\n ...props,\n children: renderedChildren,\n } as PrimitiveProps<\"div\">,\n ref,\n )}\n </InternalAttachmentProvider>\n );\n },\n);\n\nconst MessageData = forwardRef<HTMLPreElement, PrimitiveProps<\"pre\">>(\n function MessageData(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"data\") {\n return null;\n }\n\n return renderPrimitive(\n \"pre\",\n {\n ...props,\n children: props.children ?? stringifyValue(part.data),\n } as PrimitiveProps<\"pre\">,\n ref,\n );\n },\n);\n\nconst MessageError = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function MessageError(props, ref) {\n const { part } = useMessagePart();\n if (part.type !== \"error\") {\n return null;\n }\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: props.children ?? part.error.message,\n role: props.role ?? \"alert\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nfunction defaultPart(part: UIMessagePart): ReactNode {\n if (part.type === \"text\") {\n return <MessageText />;\n }\n if (part.type === \"reasoning\") {\n return <MessageReasoning />;\n }\n if (part.type === \"tool\") {\n return <MessageTool />;\n }\n if (part.type === \"attachment\") {\n return <MessageAttachment />;\n }\n if (part.type === \"data\") {\n return <MessageData />;\n }\n return <MessageError />;\n}\n\nfunction defaultToolContent(): ReactNode {\n return (\n <>\n <MessageToolName />\n <MessageToolStatus />\n <MessageToolInput />\n <MessageToolOutput />\n <MessageToolError />\n </>\n );\n}\n\nfunction defaultCodeComponent({\n children,\n className,\n node: _node,\n ...props\n}: ComponentPropsWithoutRef<\"code\"> & { node?: unknown }): ReactNode {\n return (\n <code className={className} {...props}>\n {children}\n </code>\n );\n}\n\nfunction defaultPreComponent({\n children,\n node: _node,\n ...props\n}: ComponentPropsWithoutRef<\"pre\"> & { node?: unknown }): ReactNode {\n return <MessageCodeBlock {...props}>{children}</MessageCodeBlock>;\n}\n\nfunction shouldRenderTool(part: MessageToolPart, renderWhen: MessageToolRenderWhen): boolean {\n if (renderWhen === \"always\") {\n return true;\n }\n if (renderWhen === \"pending\") {\n return part.state === \"input-streaming\" || part.state === \"input-available\";\n }\n return part.state === \"output-available\" || part.state === \"error\";\n}\n\nfunction toolStateLabel(state: MessageToolPart[\"state\"]): string {\n if (state === \"output-available\") {\n return \"Done\";\n }\n if (state === \"error\") {\n return \"Error\";\n }\n return \"Running\";\n}\n\nexport {\n MessageAttachment,\n MessageCodeBlock,\n MessageData,\n MessageError,\n MessageMarkdown,\n MessagePart,\n MessageParts,\n MessageReasoning,\n MessageText,\n MessageTool,\n MessageToolError,\n MessageToolInput,\n MessageToolName,\n MessageToolOutput,\n MessageToolStatus,\n};\n","import type { UIMessage } from \"@anvia/client\";\nimport { forwardRef, type ReactNode, useCallback, useMemo } from \"react\";\n\nimport { useMessage } from \"../contexts\";\nimport { composeRefs, type PrimitiveProps, renderPrimitive } from \"../primitives\";\nimport { registerMessageElement } from \"./elements\";\n\ntype MessageChildren = ReactNode | ((message: UIMessage) => ReactNode);\n\ntype MessageRootProps = Omit<PrimitiveProps<\"article\">, \"children\"> & {\n children?: MessageChildren;\n};\n\nconst MessageRoot = forwardRef<HTMLElement, MessageRootProps>(function MessageRoot(\n { children, ...props },\n ref,\n) {\n const { message } = useMessage();\n const renderedChildren = typeof children === \"function\" ? children(message) : children;\n const registerElement = useCallback(\n (element: HTMLElement | null) => {\n if (element !== null) registerMessageElement(element, message.id);\n },\n [message.id],\n );\n const composedRef = useMemo(() => composeRefs(ref, registerElement), [ref, registerElement]);\n\n return renderPrimitive(\n \"article\",\n {\n ...props,\n children: renderedChildren,\n \"data-role\": message.role,\n } as PrimitiveProps<\"article\">,\n composedRef,\n );\n});\n\nconst MessageContent = forwardRef<HTMLDivElement, PrimitiveProps<\"div\">>(\n function MessageContent(props, ref) {\n return renderPrimitive(\n \"div\",\n {\n ...props,\n } as PrimitiveProps<\"div\">,\n ref,\n );\n },\n);\n\nexport { MessageContent, MessageRoot };\n","import { MessageActions, MessageCopy, MessageRegenerate } from \"./actions\";\nimport { MessageEntity } from \"./entity\";\nimport {\n MessageAttachment,\n MessageCodeBlock,\n MessageData,\n MessageError,\n MessageMarkdown,\n MessagePart,\n MessageParts,\n MessageReasoning,\n MessageText,\n MessageTool,\n MessageToolError,\n MessageToolInput,\n MessageToolName,\n MessageToolOutput,\n MessageToolStatus,\n} from \"./parts\";\nimport { MessageContent, MessageRoot } from \"./root\";\n\nexport const MessagePrimitive = {\n Root: MessageRoot,\n Content: MessageContent,\n Parts: MessageParts,\n Part: MessagePart,\n Text: MessageText,\n Markdown: MessageMarkdown,\n Entity: MessageEntity,\n CodeBlock: MessageCodeBlock,\n Reasoning: MessageReasoning,\n Tool: MessageTool,\n ToolName: MessageToolName,\n ToolInput: MessageToolInput,\n ToolOutput: MessageToolOutput,\n ToolError: MessageToolError,\n ToolStatus: MessageToolStatus,\n Attachment: MessageAttachment,\n Data: MessageData,\n Error: MessageError,\n Actions: MessageActions,\n Copy: MessageCopy,\n Regenerate: MessageRegenerate,\n} as const;\n\nexport type { MessageContextValue, MessagePartContextValue } from \"../contexts\";\nexport { useChatContext, useMessage, useMessagePart } from \"../contexts\";\nexport type { MessageEntityProps } from \"./entity\";\nexport type {\n MessageAttachmentPart,\n MessagePartsFilter,\n MessageStreamOptions,\n MessageToolPart,\n MessageToolRenderWhen,\n} from \"./parts\";\n"],"mappings":";;;;;;;;;;;;AAEA,SAAgB,qBAAqB,OAA6C;CAChF,OAAO,kCAAkC,uBAAO,IA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AAc,cAAc,YAAY,KAAK,eAAe,GAAG,CAAC,KAAK,eAAe,CAAC;EAE3F,OAAO,gBACL,WACA;GACE,GAAG;GACH,UAAU;GACV,aAAa,QAAQ;EACvB,GACA,WACF;CACF,CCdQ;CACN,SDeqB,WACrB,SAAS,eAAe,OAAO,KAAK;EAClC,OAAO,gBACL,OACA,EACE,GAAG,MACL,GACA,GACF;CACF,CCxBS;CACT,OAAO;CACP,MAAM;CACN,MAAM;CACN,UAAU;CACV,QAAQ;CACR,WAAW;CACX,WAAW;CACX,MAAM;CACN,UAAU;CACV,WAAW;CACX,YAAY;CACZ,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,MAAM;CACN,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;AACd"}
@@ -0,0 +1,15 @@
1
+ import { createElement } from "react";
2
+ import { Slot } from "@radix-ui/react-slot";
3
+ // src/primitives/render.tsx
4
+ function renderPrimitive(element, props, ref) {
5
+ const { asChild, ...rest } = props;
6
+ const Component = asChild ? Slot : element;
7
+ const nextProps = ref === void 0 ? rest : {
8
+ ...rest,
9
+ ref
10
+ };
11
+ return createElement(Component, nextProps);
12
+ }
13
+ export { renderPrimitive as t };
14
+
15
+ //# sourceMappingURL=primitives-xfE7zfwJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives-xfE7zfwJ.js","names":[],"sources":["../src/primitives/render.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport {\n type ComponentPropsWithoutRef,\n type ComponentPropsWithRef,\n createElement,\n type ElementType,\n type ReactElement,\n type Ref,\n} from \"react\";\n\nexport type PrimitiveProps<TElement extends ElementType = \"div\"> = Omit<\n ComponentPropsWithoutRef<TElement>,\n \"asChild\"\n> & {\n asChild?: boolean;\n};\n\nexport type PrimitiveRef<TElement extends ElementType> = ComponentPropsWithRef<TElement>[\"ref\"];\n\nexport function renderPrimitive<TElement extends ElementType>(\n element: TElement,\n props: PrimitiveProps<TElement>,\n ref?: Ref<unknown>,\n): ReactElement {\n const { asChild, ...rest } = props;\n const Component = asChild ? Slot : element;\n const nextProps = ref === undefined ? rest : { ...rest, ref };\n return createElement(Component, nextProps);\n}\n"],"mappings":";;;AAmBA,SAAgB,gBACd,SACA,OACA,KACc;CACd,MAAM,EAAE,SAAS,GAAG,SAAS;CAC7B,MAAM,YAAY,UAAU,OAAO;CACnC,MAAM,YAAY,QAAQ,KAAA,IAAY,OAAO;EAAE,GAAG;EAAM;CAAI;CAC5D,OAAO,cAAc,WAAW,SAAS;AAC3C"}
@@ -0,0 +1,10 @@
1
+ // src/primitives/refs.ts
2
+ function composeRefs(...refs) {
3
+ return (node) => {
4
+ for (const ref of refs) if (typeof ref === "function") ref(node);
5
+ else if (ref !== void 0 && ref !== null) ref.current = node;
6
+ };
7
+ }
8
+ export { composeRefs as t };
9
+
10
+ //# sourceMappingURL=refs-Djj9rSvB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs-Djj9rSvB.js","names":[],"sources":["../src/primitives/refs.ts"],"sourcesContent":["import type { Ref, RefCallback } from \"react\";\n\nexport function composeRefs<T>(...refs: Array<Ref<T> | undefined>): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref !== undefined && ref !== null) {\n ref.current = node;\n }\n }\n };\n}\n"],"mappings":";AAEA,SAAgB,YAAe,GAAG,MAAiD;CACjF,QAAQ,SAAS;EACf,KAAK,MAAM,OAAO,MAChB,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI;OACH,IAAI,QAAQ,KAAA,KAAa,QAAQ,MACtC,IAAI,UAAU;CAGpB;AACF"}
@@ -1,122 +1,118 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { P as PrimitiveProps } from '../render-CRKWam2v.js';
4
- import { T as TicketSource, R as RelayReconnectOptions, a as RelayStatus } from '../ticket-pexI1zIa.js';
5
- export { b as SandboxDesktopState, t as ticketSubprotocolPrefix } from '../ticket-pexI1zIa.js';
6
-
1
+ import { t as PrimitiveProps } from "../index-DqdyM0Jm.js";
2
+ import { a as ticketSubprotocolPrefix, i as RelayStatus, n as RelayReconnectOptions, r as RelayState, t as TicketSource } from "../ticket-CoJHBpdF.js";
3
+ import { ReactNode } from "react";
7
4
  /** Subprotocol the hub's `handleDesktopUpgrade` selects. */
8
- declare const desktopSubprotocol = "anvia.desktop.v1";
5
+ export declare const desktopSubprotocol = "anvia.desktop.v1";
9
6
  /** Who is driving the desktop, as the relay reports it to this viewer. */
10
7
  interface SandboxDesktopControl {
11
- /** Someone has taken control, which pauses the agent. */
12
- held: boolean;
13
- /** Who. Present when `held`. */
14
- holder?: string;
15
- /** When the hold lapses unless renewed. */
16
- expiresAt?: string;
17
- /** This viewer is the holder. */
18
- you: boolean;
19
- /** This viewer may only watch. */
20
- readOnly: boolean;
8
+ /** Someone has taken control, which pauses the agent. */
9
+ held: boolean;
10
+ /** Who. Present when `held`. */
11
+ holder?: string;
12
+ /** When the hold lapses unless renewed. */
13
+ expiresAt?: string;
14
+ /** This viewer is the holder. */
15
+ you: boolean;
16
+ /** This viewer may only watch. */
17
+ readOnly: boolean;
21
18
  }
22
-
23
19
  interface SandboxDesktopHandle {
24
- focus(): void;
25
- /** Reconnect now, after the viewer gave up. */
26
- reconnect(): void;
27
- /** Take control, which pauses the agent. */
28
- takeOver(): void;
29
- /** Hand control back. */
30
- release(): void;
20
+ focus(): void;
21
+ /** Reconnect now, after the viewer gave up. */
22
+ reconnect(): void;
23
+ /** Take control, which pauses the agent. */
24
+ takeOver(): void;
25
+ /** Hand control back. */
26
+ release(): void;
31
27
  }
32
28
  interface SandboxDesktopNotice {
33
- code: string;
34
- message: string;
29
+ code: string;
30
+ message: string;
35
31
  }
36
32
  /** What `renderControls` is given to draw its own take-over bar. */
37
33
  interface SandboxDesktopControlsState {
38
- status: RelayStatus;
39
- /** Undefined until the relay has said who has control. */
40
- control: SandboxDesktopControl | undefined;
41
- /** This viewer cannot send input, because of the prop or because the ticket says so. */
42
- readOnly: boolean;
43
- /** The latest failed request, such as taking over while someone else holds control. */
44
- notice: SandboxDesktopNotice | undefined;
45
- takeOver(): void;
46
- release(): void;
34
+ status: RelayStatus;
35
+ /** Undefined until the relay has said who has control. */
36
+ control: SandboxDesktopControl | undefined;
37
+ /** This viewer cannot send input, because of the prop or because the ticket says so. */
38
+ readOnly: boolean;
39
+ /** The latest failed request, such as taking over while someone else holds control. */
40
+ notice: SandboxDesktopNotice | undefined;
41
+ takeOver(): void;
42
+ release(): void;
47
43
  }
48
44
  type SandboxDesktopProps = Omit<PrimitiveProps<"div">, "children" | "onError"> & {
49
- /**
50
- * The hub's desktop endpoint (`hub.handleDesktopUpgrade`): `ws:`/`wss:`, `http:`/`https:`, or a
51
- * path relative to this page.
52
- */
53
- url: string;
54
- /**
55
- * A one-time ticket, or a function returning one. Pass a function: tickets are single use, so
56
- * each reconnect needs a fresh one. It travels as a WebSocket subprotocol, not in the URL.
57
- */
58
- ticket?: TicketSource;
59
- /** Watch only. The server enforces it too; this also stops the viewer sending input. */
60
- readOnly?: boolean;
61
- /** Scale the desktop to fit the element. Default true. */
62
- scaleToFit?: boolean;
63
- /**
64
- * JPEG quality asked of the server, 0 (smallest, blockiest) to 9 (best, most data). Default 6.
65
- * Lower it for a slow link; it applies to the live connection.
66
- */
67
- qualityLevel?: number;
68
- /**
69
- * How hard the server compresses, 0 (fastest, most data) to 9 (slowest, least data). Default 2,
70
- * which keeps the server's CPU low. Raise it for a slow link; it applies to the live connection.
71
- */
72
- compressionLevel?: number;
73
- reconnect?: RelayReconnectOptions;
74
- onStatusChange?: (status: RelayStatus) => void;
75
- /** Called whenever the relay reports who has control. */
76
- onControlChange?: (control: SandboxDesktopControl) => void;
77
- /** Replace the default status line. Return null to show nothing. */
78
- renderStatus?: (status: RelayStatus, retry: () => void) => ReactNode;
79
- /** Replace the default take-over bar. Return null to show nothing. */
80
- renderControls?: (state: SandboxDesktopControlsState) => ReactNode;
45
+ /**
46
+ * The hub's desktop endpoint (`hub.handleDesktopUpgrade`): `ws:`/`wss:`, `http:`/`https:`, or a
47
+ * path relative to this page.
48
+ */
49
+ url: string;
50
+ /**
51
+ * A one-time ticket, or a function returning one. Pass a function: tickets are single use, so
52
+ * each reconnect needs a fresh one. It travels as a WebSocket subprotocol, not in the URL.
53
+ */
54
+ ticket?: TicketSource;
55
+ /** Watch only. The server enforces it too; this also stops the viewer sending input. */
56
+ readOnly?: boolean;
57
+ /** Scale the desktop to fit the element. Default true. */
58
+ scaleToFit?: boolean;
59
+ /**
60
+ * JPEG quality asked of the server, 0 (smallest, blockiest) to 9 (best, most data). Default 6.
61
+ * Lower it for a slow link; it applies to the live connection.
62
+ */
63
+ qualityLevel?: number;
64
+ /**
65
+ * How hard the server compresses, 0 (fastest, most data) to 9 (slowest, least data). Default 2,
66
+ * which keeps the server's CPU low. Raise it for a slow link; it applies to the live connection.
67
+ */
68
+ compressionLevel?: number;
69
+ reconnect?: RelayReconnectOptions;
70
+ onStatusChange?: (status: RelayStatus) => void;
71
+ /** Called whenever the relay reports who has control. */
72
+ onControlChange?: (control: SandboxDesktopControl) => void;
73
+ /** Replace the default status line. Return null to show nothing. */
74
+ renderStatus?: (status: RelayStatus, retry: () => void) => ReactNode;
75
+ /** Replace the default take-over bar. Return null to show nothing. */
76
+ renderControls?: (state: SandboxDesktopControlsState) => ReactNode;
81
77
  };
82
78
  /**
83
79
  * A viewer for a remote sandbox's desktop, drawn with noVNC. noVNC is loaded on demand, so it costs
84
80
  * nothing until a desktop mounts. It connects to the hub's desktop relay, reconnects with a fresh
85
81
  * ticket when the link drops, and lets a person take over control from the agent.
86
82
  */
87
- declare const SandboxDesktop: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children" | "onError"> & {
88
- /**
89
- * The hub's desktop endpoint (`hub.handleDesktopUpgrade`): `ws:`/`wss:`, `http:`/`https:`, or a
90
- * path relative to this page.
91
- */
92
- url: string;
93
- /**
94
- * A one-time ticket, or a function returning one. Pass a function: tickets are single use, so
95
- * each reconnect needs a fresh one. It travels as a WebSocket subprotocol, not in the URL.
96
- */
97
- ticket?: TicketSource;
98
- /** Watch only. The server enforces it too; this also stops the viewer sending input. */
99
- readOnly?: boolean;
100
- /** Scale the desktop to fit the element. Default true. */
101
- scaleToFit?: boolean;
102
- /**
103
- * JPEG quality asked of the server, 0 (smallest, blockiest) to 9 (best, most data). Default 6.
104
- * Lower it for a slow link; it applies to the live connection.
105
- */
106
- qualityLevel?: number;
107
- /**
108
- * How hard the server compresses, 0 (fastest, most data) to 9 (slowest, least data). Default 2,
109
- * which keeps the server's CPU low. Raise it for a slow link; it applies to the live connection.
110
- */
111
- compressionLevel?: number;
112
- reconnect?: RelayReconnectOptions;
113
- onStatusChange?: (status: RelayStatus) => void;
114
- /** Called whenever the relay reports who has control. */
115
- onControlChange?: (control: SandboxDesktopControl) => void;
116
- /** Replace the default status line. Return null to show nothing. */
117
- renderStatus?: (status: RelayStatus, retry: () => void) => ReactNode;
118
- /** Replace the default take-over bar. Return null to show nothing. */
119
- renderControls?: (state: SandboxDesktopControlsState) => ReactNode;
120
- } & react.RefAttributes<SandboxDesktopHandle>>;
121
-
122
- export { SandboxDesktop, type SandboxDesktopControl, type SandboxDesktopControlsState, type SandboxDesktopHandle, type SandboxDesktopNotice, type SandboxDesktopProps, RelayReconnectOptions as SandboxDesktopReconnectOptions, RelayStatus as SandboxDesktopStatus, desktopSubprotocol };
83
+ export declare const SandboxDesktop: import("react").ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children" | "onError"> & {
84
+ /**
85
+ * The hub's desktop endpoint (`hub.handleDesktopUpgrade`): `ws:`/`wss:`, `http:`/`https:`, or a
86
+ * path relative to this page.
87
+ */
88
+ url: string;
89
+ /**
90
+ * A one-time ticket, or a function returning one. Pass a function: tickets are single use, so
91
+ * each reconnect needs a fresh one. It travels as a WebSocket subprotocol, not in the URL.
92
+ */
93
+ ticket?: TicketSource;
94
+ /** Watch only. The server enforces it too; this also stops the viewer sending input. */
95
+ readOnly?: boolean;
96
+ /** Scale the desktop to fit the element. Default true. */
97
+ scaleToFit?: boolean;
98
+ /**
99
+ * JPEG quality asked of the server, 0 (smallest, blockiest) to 9 (best, most data). Default 6.
100
+ * Lower it for a slow link; it applies to the live connection.
101
+ */
102
+ qualityLevel?: number;
103
+ /**
104
+ * How hard the server compresses, 0 (fastest, most data) to 9 (slowest, least data). Default 2,
105
+ * which keeps the server's CPU low. Raise it for a slow link; it applies to the live connection.
106
+ */
107
+ compressionLevel?: number;
108
+ reconnect?: RelayReconnectOptions;
109
+ onStatusChange?: (status: RelayStatus) => void;
110
+ /** Called whenever the relay reports who has control. */
111
+ onControlChange?: (control: SandboxDesktopControl) => void;
112
+ /** Replace the default status line. Return null to show nothing. */
113
+ renderStatus?: (status: RelayStatus, retry: () => void) => ReactNode;
114
+ /** Replace the default take-over bar. Return null to show nothing. */
115
+ renderControls?: (state: SandboxDesktopControlsState) => ReactNode;
116
+ } & import("react").RefAttributes<SandboxDesktopHandle>>;
117
+ export { type SandboxDesktopControl, type SandboxDesktopControlsState, type SandboxDesktopHandle, type SandboxDesktopNotice, type SandboxDesktopProps, type RelayReconnectOptions as SandboxDesktopReconnectOptions, type RelayState as SandboxDesktopState, type RelayStatus as SandboxDesktopStatus, ticketSubprotocolPrefix };
118
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/sandbox-desktop/connection.ts","../../src/sandbox-desktop/desktop.tsx"],"mappings":";;;;qBAUa;;UAGI;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;UCNe;EACf;;EAEA;;EAEA;;EAEA;;UAGe;EACf;EACA;;;UAIe;EACf,QAAQ;;EAER,SAAS;;EAET;;EAEA,QAAQ;EACR;EACA;;KAGU,sBAAsB,KAAK;;;;;EAKrC;;;;;EAKA,SAAS;;EAET;;EAEA;;;;;EAKA;;;;;EAKA;EACA,YAAY;EACZ,kBAAkB,QAAQ;;EAE1B,mBAAmB,SAAS;;EAE5B,gBAAgB,QAAQ,aAAa,sBAAsB;;EAE3D,kBAAkB,OAAO,gCAAgC;;;;;;;qBAoB9C,gCAAc,0BAAA,KAAA;;;;;EA/CpB;;;;;EAKI,SAAA;;EAEE;;EAEE;;;;;EAKE;;;;;EAKI;EACP,YAAA;EACK,kBAAC,QAAQ;;EAER,mBAAC,SAAS;;EAEb,gBAAC,QAAQ,aAAa,sBAAsB;;EAE1C,kBAAC,OAAO,gCAAgC;oBA8M1D,cAAA"}