@assistant-ui/react 0.10.23 → 0.10.24

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 (189) hide show
  1. package/dist/cloud/AssistantCloudThreadHistoryAdapter.d.ts +1 -1
  2. package/dist/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  3. package/dist/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  4. package/dist/cloud/auiV0.d.ts +1 -1
  5. package/dist/cloud/auiV0.d.ts.map +1 -1
  6. package/dist/cloud/auiV0.js.map +1 -1
  7. package/dist/cloud/index.d.ts +1 -1
  8. package/dist/cloud/index.d.ts.map +1 -1
  9. package/dist/cloud/index.js +1 -1
  10. package/dist/cloud/index.js.map +1 -1
  11. package/dist/cloud/useCloudThreadListRuntime.d.ts +1 -1
  12. package/dist/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
  13. package/dist/cloud/useCloudThreadListRuntime.js.map +1 -1
  14. package/dist/context/react/AssistantContext.d.ts +23 -0
  15. package/dist/context/react/AssistantContext.d.ts.map +1 -1
  16. package/dist/context/react/AssistantContext.js.map +1 -1
  17. package/dist/context/react/ComposerContext.d.ts +64 -0
  18. package/dist/context/react/ComposerContext.d.ts.map +1 -1
  19. package/dist/context/react/ComposerContext.js.map +1 -1
  20. package/dist/context/react/MessageContext.d.ts +56 -0
  21. package/dist/context/react/MessageContext.d.ts.map +1 -1
  22. package/dist/context/react/MessageContext.js.map +1 -1
  23. package/dist/context/react/ThreadContext.d.ts +42 -0
  24. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  25. package/dist/context/react/ThreadContext.js.map +1 -1
  26. package/dist/primitives/actionBar/ActionBarCopy.d.ts +42 -0
  27. package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
  28. package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
  29. package/dist/primitives/actionBar/ActionBarEdit.d.ts +38 -0
  30. package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
  31. package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
  32. package/dist/primitives/actionBar/ActionBarReload.d.ts +39 -0
  33. package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
  34. package/dist/primitives/actionBar/ActionBarReload.js.map +1 -1
  35. package/dist/primitives/actionBar/ActionBarRoot.d.ts +56 -0
  36. package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
  37. package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
  38. package/dist/primitives/attachment/AttachmentRoot.d.ts +18 -0
  39. package/dist/primitives/attachment/AttachmentRoot.d.ts.map +1 -1
  40. package/dist/primitives/attachment/AttachmentRoot.js.map +1 -1
  41. package/dist/primitives/branchPicker/BranchPickerCount.d.ts +17 -0
  42. package/dist/primitives/branchPicker/BranchPickerCount.d.ts.map +1 -1
  43. package/dist/primitives/branchPicker/BranchPickerCount.js.map +1 -1
  44. package/dist/primitives/branchPicker/BranchPickerNext.d.ts +17 -0
  45. package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
  46. package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
  47. package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts +38 -0
  48. package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
  49. package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
  50. package/dist/primitives/branchPicker/BranchPickerRoot.d.ts +27 -0
  51. package/dist/primitives/branchPicker/BranchPickerRoot.d.ts.map +1 -1
  52. package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
  53. package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  54. package/dist/primitives/composer/ComposerAttachments.js +11 -8
  55. package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
  56. package/dist/primitives/composer/ComposerCancel.d.ts +17 -0
  57. package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
  58. package/dist/primitives/composer/ComposerCancel.js.map +1 -1
  59. package/dist/primitives/composer/ComposerInput.d.ts +72 -0
  60. package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
  61. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  62. package/dist/primitives/composer/ComposerRoot.d.ts +19 -0
  63. package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
  64. package/dist/primitives/composer/ComposerRoot.js.map +1 -1
  65. package/dist/primitives/composer/ComposerSend.d.ts +18 -0
  66. package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
  67. package/dist/primitives/composer/ComposerSend.js.map +1 -1
  68. package/dist/primitives/contentPart/ContentPartImage.d.ts +19 -0
  69. package/dist/primitives/contentPart/ContentPartImage.d.ts.map +1 -1
  70. package/dist/primitives/contentPart/ContentPartImage.js.map +1 -1
  71. package/dist/primitives/contentPart/ContentPartText.d.ts +34 -0
  72. package/dist/primitives/contentPart/ContentPartText.d.ts.map +1 -1
  73. package/dist/primitives/contentPart/ContentPartText.js.map +1 -1
  74. package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
  75. package/dist/primitives/message/MessageAttachments.js +11 -8
  76. package/dist/primitives/message/MessageAttachments.js.map +1 -1
  77. package/dist/primitives/message/MessageContent.d.ts +41 -0
  78. package/dist/primitives/message/MessageContent.d.ts.map +1 -1
  79. package/dist/primitives/message/MessageContent.js +14 -11
  80. package/dist/primitives/message/MessageContent.js.map +1 -1
  81. package/dist/primitives/message/MessageRoot.d.ts +22 -0
  82. package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
  83. package/dist/primitives/message/MessageRoot.js.map +1 -1
  84. package/dist/primitives/thread/ThreadMessages.d.ts +44 -0
  85. package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
  86. package/dist/primitives/thread/ThreadMessages.js +5 -2
  87. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  88. package/dist/primitives/thread/ThreadRoot.d.ts +19 -0
  89. package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
  90. package/dist/primitives/thread/ThreadRoot.js.map +1 -1
  91. package/dist/primitives/thread/ThreadViewport.d.ts +24 -0
  92. package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
  93. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  94. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  95. package/dist/primitives/threadList/ThreadListItems.js +12 -9
  96. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  97. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts +54 -0
  98. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -1
  99. package/dist/runtimes/adapters/feedback/FeedbackAdapter.d.ts +33 -0
  100. package/dist/runtimes/adapters/feedback/FeedbackAdapter.d.ts.map +1 -1
  101. package/dist/runtimes/adapters/speech/SpeechAdapterTypes.d.ts +47 -0
  102. package/dist/runtimes/adapters/speech/SpeechAdapterTypes.d.ts.map +1 -1
  103. package/dist/runtimes/local/LocalRuntimeOptions.d.ts +2 -2
  104. package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
  105. package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
  106. package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts +1 -1
  107. package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -1
  108. package/dist/runtimes/remote-thread-list/adapter/cloud.js +1 -1
  109. package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -1
  110. package/dist/tests/setup.js +8 -8
  111. package/dist/tests/setup.js.map +1 -1
  112. package/package.json +8 -7
  113. package/src/cloud/AssistantCloudThreadHistoryAdapter.tsx +1 -1
  114. package/src/cloud/auiV0.ts +1 -1
  115. package/src/cloud/index.ts +1 -1
  116. package/src/cloud/useCloudThreadListRuntime.tsx +1 -1
  117. package/src/context/react/AssistantContext.ts +23 -0
  118. package/src/context/react/ComposerContext.ts +64 -0
  119. package/src/context/react/MessageContext.ts +56 -0
  120. package/src/context/react/ThreadContext.ts +42 -0
  121. package/src/primitives/actionBar/ActionBarCopy.tsx +42 -0
  122. package/src/primitives/actionBar/ActionBarEdit.tsx +38 -0
  123. package/src/primitives/actionBar/ActionBarReload.tsx +39 -0
  124. package/src/primitives/actionBar/ActionBarRoot.tsx +38 -0
  125. package/src/primitives/attachment/AttachmentRoot.tsx +18 -0
  126. package/src/primitives/branchPicker/BranchPickerCount.tsx +17 -0
  127. package/src/primitives/branchPicker/BranchPickerNext.tsx +17 -0
  128. package/src/primitives/branchPicker/BranchPickerPrevious.tsx +38 -0
  129. package/src/primitives/branchPicker/BranchPickerRoot.tsx +22 -0
  130. package/src/primitives/composer/ComposerAttachments.tsx +11 -7
  131. package/src/primitives/composer/ComposerCancel.tsx +17 -0
  132. package/src/primitives/composer/ComposerInput.tsx +44 -0
  133. package/src/primitives/composer/ComposerRoot.tsx +19 -0
  134. package/src/primitives/composer/ComposerSend.tsx +18 -0
  135. package/src/primitives/contentPart/ContentPartImage.tsx +19 -0
  136. package/src/primitives/contentPart/ContentPartText.tsx +25 -0
  137. package/src/primitives/message/MessageAttachments.tsx +11 -7
  138. package/src/primitives/message/MessageContent.tsx +54 -18
  139. package/src/primitives/message/MessageRoot.tsx +22 -0
  140. package/src/primitives/thread/ThreadMessages.tsx +52 -4
  141. package/src/primitives/thread/ThreadRoot.tsx +19 -0
  142. package/src/primitives/thread/ThreadViewport.tsx +19 -0
  143. package/src/primitives/threadList/ThreadListItems.tsx +12 -8
  144. package/src/runtimes/adapters/attachment/AttachmentAdapter.ts +56 -0
  145. package/src/runtimes/adapters/feedback/FeedbackAdapter.ts +33 -0
  146. package/src/runtimes/adapters/speech/SpeechAdapterTypes.ts +47 -0
  147. package/src/runtimes/local/LocalRuntimeOptions.tsx +1 -1
  148. package/src/runtimes/remote-thread-list/adapter/cloud.tsx +1 -1
  149. package/dist/cloud/AssistantCloud.d.ts +0 -15
  150. package/dist/cloud/AssistantCloud.d.ts.map +0 -1
  151. package/dist/cloud/AssistantCloud.js +0 -25
  152. package/dist/cloud/AssistantCloud.js.map +0 -1
  153. package/dist/cloud/AssistantCloudAPI.d.ts +0 -28
  154. package/dist/cloud/AssistantCloudAPI.d.ts.map +0 -1
  155. package/dist/cloud/AssistantCloudAPI.js +0 -87
  156. package/dist/cloud/AssistantCloudAPI.js.map +0 -1
  157. package/dist/cloud/AssistantCloudAuthStrategy.d.ts +0 -30
  158. package/dist/cloud/AssistantCloudAuthStrategy.d.ts.map +0 -1
  159. package/dist/cloud/AssistantCloudAuthStrategy.js +0 -139
  160. package/dist/cloud/AssistantCloudAuthStrategy.js.map +0 -1
  161. package/dist/cloud/AssistantCloudAuthTokens.d.ts +0 -11
  162. package/dist/cloud/AssistantCloudAuthTokens.d.ts.map +0 -1
  163. package/dist/cloud/AssistantCloudAuthTokens.js +0 -13
  164. package/dist/cloud/AssistantCloudAuthTokens.js.map +0 -1
  165. package/dist/cloud/AssistantCloudFiles.d.ts +0 -27
  166. package/dist/cloud/AssistantCloudFiles.d.ts.map +0 -1
  167. package/dist/cloud/AssistantCloudFiles.js +0 -25
  168. package/dist/cloud/AssistantCloudFiles.js.map +0 -1
  169. package/dist/cloud/AssistantCloudRuns.d.ts +0 -26
  170. package/dist/cloud/AssistantCloudRuns.d.ts.map +0 -1
  171. package/dist/cloud/AssistantCloudRuns.js +0 -39
  172. package/dist/cloud/AssistantCloudRuns.js.map +0 -1
  173. package/dist/cloud/AssistantCloudThreadMessages.d.ts +0 -30
  174. package/dist/cloud/AssistantCloudThreadMessages.d.ts.map +0 -1
  175. package/dist/cloud/AssistantCloudThreadMessages.js +0 -21
  176. package/dist/cloud/AssistantCloudThreadMessages.js.map +0 -1
  177. package/dist/cloud/AssistantCloudThreads.d.ts +0 -48
  178. package/dist/cloud/AssistantCloudThreads.d.ts.map +0 -1
  179. package/dist/cloud/AssistantCloudThreads.js +0 -30
  180. package/dist/cloud/AssistantCloudThreads.js.map +0 -1
  181. package/src/cloud/AssistantCloud.tsx +0 -22
  182. package/src/cloud/AssistantCloudAPI.tsx +0 -121
  183. package/src/cloud/AssistantCloudAuthStrategy.tsx +0 -193
  184. package/src/cloud/AssistantCloudAuthTokens.tsx +0 -13
  185. package/src/cloud/AssistantCloudFiles.tsx +0 -48
  186. package/src/cloud/AssistantCloudRuns.tsx +0 -45
  187. package/src/cloud/AssistantCloudThreadMessages.tsx +0 -48
  188. package/src/cloud/AssistantCloudThreads.tsx +0 -79
  189. package/src/tests/AssistantCloudFiles.test.ts +0 -564
@@ -2,22 +2,94 @@ import { type TextareaAutosizeProps } from "react-textarea-autosize";
2
2
  export declare namespace ComposerPrimitiveInput {
3
3
  type Element = HTMLTextAreaElement;
4
4
  type Props = TextareaAutosizeProps & {
5
+ /**
6
+ * Whether to render as a child component using Slot.
7
+ * When true, the component will merge its props with its child.
8
+ */
5
9
  asChild?: boolean | undefined;
10
+ /**
11
+ * Whether to submit the message when Enter is pressed (without Shift).
12
+ * @default true
13
+ */
6
14
  submitOnEnter?: boolean | undefined;
15
+ /**
16
+ * Whether to cancel message composition when Escape is pressed.
17
+ * @default true
18
+ */
7
19
  cancelOnEscape?: boolean | undefined;
20
+ /**
21
+ * Whether to automatically focus the input when a new run starts.
22
+ * @default true
23
+ */
8
24
  unstable_focusOnRunStart?: boolean | undefined;
25
+ /**
26
+ * Whether to automatically focus the input when scrolling to bottom.
27
+ * @default true
28
+ */
9
29
  unstable_focusOnScrollToBottom?: boolean | undefined;
30
+ /**
31
+ * Whether to automatically focus the input when switching threads.
32
+ * @default true
33
+ */
10
34
  unstable_focusOnThreadSwitched?: boolean | undefined;
35
+ /**
36
+ * Whether to automatically add pasted files as attachments.
37
+ * @default true
38
+ */
11
39
  addAttachmentOnPaste?: boolean | undefined;
12
40
  };
13
41
  }
42
+ /**
43
+ * A text input component for composing messages.
44
+ *
45
+ * This component provides a rich text input experience with automatic resizing,
46
+ * keyboard shortcuts, file paste support, and intelligent focus management.
47
+ * It integrates with the composer context to manage message state and submission.
48
+ *
49
+ * @example
50
+ * ```tsx
51
+ * <ComposerPrimitive.Input
52
+ * placeholder="Type your message..."
53
+ * submitOnEnter={true}
54
+ * addAttachmentOnPaste={true}
55
+ * />
56
+ * ```
57
+ */
14
58
  export declare const ComposerPrimitiveInput: import("react").ForwardRefExoticComponent<TextareaAutosizeProps & {
59
+ /**
60
+ * Whether to render as a child component using Slot.
61
+ * When true, the component will merge its props with its child.
62
+ */
15
63
  asChild?: boolean | undefined;
64
+ /**
65
+ * Whether to submit the message when Enter is pressed (without Shift).
66
+ * @default true
67
+ */
16
68
  submitOnEnter?: boolean | undefined;
69
+ /**
70
+ * Whether to cancel message composition when Escape is pressed.
71
+ * @default true
72
+ */
17
73
  cancelOnEscape?: boolean | undefined;
74
+ /**
75
+ * Whether to automatically focus the input when a new run starts.
76
+ * @default true
77
+ */
18
78
  unstable_focusOnRunStart?: boolean | undefined;
79
+ /**
80
+ * Whether to automatically focus the input when scrolling to bottom.
81
+ * @default true
82
+ */
19
83
  unstable_focusOnScrollToBottom?: boolean | undefined;
84
+ /**
85
+ * Whether to automatically focus the input when switching threads.
86
+ * @default true
87
+ */
20
88
  unstable_focusOnThreadSwitched?: boolean | undefined;
89
+ /**
90
+ * Whether to automatically add pasted files as attachments.
91
+ * @default true
92
+ */
21
93
  addAttachmentOnPaste?: boolean | undefined;
22
94
  } & import("react").RefAttributes<HTMLTextAreaElement>>;
23
95
  //# sourceMappingURL=ComposerInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerInput.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerInput.tsx"],"names":[],"mappings":"AAaA,OAAyB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAUjC,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C,KAAY,KAAK,GAAG,qBAAqB,GAAG;QAC1C,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC9B,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACp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ACH,eAAO,MAAM,sBAAsB;IAtD/B;;;OAGG;cACO,OAAO,GAAG,SAAS;IAC7B;;;OAGG;oBACa,OAAO,GAAG,SAAS;IACnC;;;OAGG;qBACc,OAAO,GAAG,SAAS;IACpC;;;OAGG;+BACwB,OAAO,GAAG,SAAS;IAC9C;;;OAGG;qCAC8B,OAAO,GAAG,SAAS;IACpD;;;OAGG;qCAC8B,OAAO,GAAG,SAAS;IACpD;;;OAGG;2BACoB,OAAO,GAAG,SAAS;uDAwJ7C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n ClipboardEvent,\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport {\n useComposer,\n useComposerRuntime,\n} from \"../../context/react/ComposerContext\";\nimport { useThread, useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useThreadListItemRuntime } from \"../../context/react/ThreadListItemContext\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n export type Props = TextareaAutosizeProps & {\n asChild?: boolean | undefined;\n submitOnEnter?: boolean | undefined;\n cancelOnEscape?: boolean | undefined;\n unstable_focusOnRunStart?: boolean | undefined;\n unstable_focusOnScrollToBottom?: boolean | undefined;\n unstable_focusOnThreadSwitched?: boolean | undefined;\n addAttachmentOnPaste?: boolean | undefined;\n };\n}\n\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n submitOnEnter = true,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n addAttachmentOnPaste = true,\n ...rest\n },\n forwardedRef,\n ) => {\n const threadListItemRuntime = useThreadListItemRuntime();\n const threadRuntime = useThreadRuntime();\n const composerRuntime = useComposerRuntime();\n\n const value = useComposer((c) => {\n if (!c.isEditing) return \"\";\n return c.text;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const isDisabled = Boolean(useThread((t) => t.isDisabled) || disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n if (!cancelOnEscape) return;\n\n if (composerRuntime.getState().canCancel) {\n composerRuntime.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled || !submitOnEnter) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const { isRunning } = threadRuntime.getState();\n\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = threadRuntime.getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n try {\n e.preventDefault();\n await Promise.all(\n files.map((file) => composerRuntime.addAttachment(file)),\n );\n } catch (error) {\n console.error(\"Error adding attachment:\", error);\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (composerRuntime.type === \"thread\" && unstable_focusOnScrollToBottom) {\n focus();\n }\n });\n\n useEffect(() => {\n if (composerRuntime.type !== \"thread\" || !unstable_focusOnRunStart)\n return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", focus);\n }, [unstable_focusOnRunStart, focus, composerRuntime, threadRuntime]);\n\n useEffect(() => {\n if (composerRuntime.type !== \"thread\" || !unstable_focusOnThreadSwitched)\n return undefined;\n\n return threadListItemRuntime.unstable_on(\"switched-to\", focus);\n }, [\n unstable_focusOnThreadSwitched,\n focus,\n composerRuntime,\n threadListItemRuntime,\n ]);\n\n return (\n <Component\n name=\"input\"\n value={value}\n {...rest}\n ref={ref}\n disabled={isDisabled}\n onChange={composeEventHandlers(onChange, (e) => {\n if (!composerRuntime.getState().isEditing) return;\n return composerRuntime.setText(e.target.value);\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n onPaste={composeEventHandlers(onPaste, handlePaste)}\n />\n );\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAEA;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,wBAAwB;AAC5C,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AAoInC;AArHC,IAAM,yBAAyB;AAAA,EAIpC,CACE;AAAA,IACE,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,2BAA2B;AAAA,IAC3B,iCAAiC;AAAA,IACjC,iCAAiC;AAAA,IACjC,uBAAu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,"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n ClipboardEvent,\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport {\n useComposer,\n useComposerRuntime,\n} from \"../../context/react/ComposerContext\";\nimport { useThread, useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useThreadListItemRuntime } from \"../../context/react/ThreadListItemContext\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n export type Props = TextareaAutosizeProps & {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n */\n submitOnEnter?: boolean | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * addAttachmentOnPaste={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n submitOnEnter = true,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n addAttachmentOnPaste = true,\n ...rest\n },\n forwardedRef,\n ) => {\n const threadListItemRuntime = useThreadListItemRuntime();\n const threadRuntime = useThreadRuntime();\n const composerRuntime = useComposerRuntime();\n\n const value = useComposer((c) => {\n if (!c.isEditing) return \"\";\n return c.text;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const isDisabled = Boolean(useThread((t) => t.isDisabled) || disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n if (!cancelOnEscape) return;\n\n if (composerRuntime.getState().canCancel) {\n composerRuntime.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled || !submitOnEnter) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const { isRunning } = threadRuntime.getState();\n\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = threadRuntime.getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n try {\n e.preventDefault();\n await Promise.all(\n files.map((file) => composerRuntime.addAttachment(file)),\n );\n } catch (error) {\n console.error(\"Error adding attachment:\", error);\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (composerRuntime.type === \"thread\" && unstable_focusOnScrollToBottom) {\n focus();\n }\n });\n\n useEffect(() => {\n if (composerRuntime.type !== \"thread\" || !unstable_focusOnRunStart)\n return undefined;\n\n return threadRuntime.unstable_on(\"run-start\", focus);\n }, [unstable_focusOnRunStart, focus, composerRuntime, threadRuntime]);\n\n useEffect(() => {\n if (composerRuntime.type !== \"thread\" || !unstable_focusOnThreadSwitched)\n return undefined;\n\n return threadListItemRuntime.unstable_on(\"switched-to\", focus);\n }, [\n unstable_focusOnThreadSwitched,\n focus,\n composerRuntime,\n threadListItemRuntime,\n ]);\n\n return (\n <Component\n name=\"input\"\n value={value}\n {...rest}\n ref={ref}\n disabled={isDisabled}\n onChange={composeEventHandlers(onChange, (e) => {\n if (!composerRuntime.getState().isEditing) return;\n return composerRuntime.setText(e.target.value);\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n onPaste={composeEventHandlers(onPaste, handlePaste)}\n />\n );\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAEA;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,wBAAwB;AAC5C,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AAgLnC;AArHC,IAAM,yBAAyB;AAAA,EAIpC,CACE;AAAA,IACE,YAAY;AAAA,IAC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K;AAAA,QAC/C,CAAC;AAAA,QACD,WAAW,qBAAqB,WAAW,cAAc;AAAA,QACzD,SAAS,qBAAqB,SAAS,WAAW;AAAA;AAAA,IACpD;AAAA,EAEJ;AACF;AAEA,uBAAuB,cAAc;","names":[]}
@@ -2,8 +2,27 @@ import { Primitive } from "@radix-ui/react-primitive";
2
2
  import { type ComponentRef, ComponentPropsWithoutRef } from "react";
3
3
  export declare namespace ComposerPrimitiveRoot {
4
4
  type Element = ComponentRef<typeof Primitive.form>;
5
+ /**
6
+ * Props for the ComposerPrimitive.Root component.
7
+ * Accepts all standard form element props.
8
+ */
5
9
  type Props = ComponentPropsWithoutRef<typeof Primitive.form>;
6
10
  }
11
+ /**
12
+ * The root form container for message composition.
13
+ *
14
+ * This component provides a form wrapper that handles message submission when the form
15
+ * is submitted (e.g., via Enter key or submit button). It automatically prevents the
16
+ * default form submission and triggers the composer's send functionality.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * <ComposerPrimitive.Root>
21
+ * <ComposerPrimitive.Input placeholder="Type your message..." />
22
+ * <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
23
+ * </ComposerPrimitive.Root>
24
+ * ```
25
+ */
7
26
  export declare const ComposerPrimitiveRoot: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLFormElement> & import("react").FormHTMLAttributes<HTMLFormElement> & {
8
27
  asChild?: boolean;
9
28
  }, "ref"> & import("react").RefAttributes<HTMLFormElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAGjB,wBAAwB,EACzB,MAAM,OAAO,CAAC;AAGf,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1D,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,eAAO,MAAM,qBAAqB;;2DAoBhC,CAAC"}
1
+ {"version":3,"file":"ComposerRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAGjB,wBAAwB,EACzB,MAAM,OAAO,CAAC;AAGf,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1D;;;OAGG;IACH,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;CACrE;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB;;2DAoBhC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n type FormEvent,\n forwardRef,\n ComponentPropsWithoutRef,\n} from \"react\";\nimport { useComposerSend } from \"./ComposerSend\";\n\nexport namespace ComposerPrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.form>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.form>;\n}\n\nexport const ComposerPrimitiveRoot = forwardRef<\n ComposerPrimitiveRoot.Element,\n ComposerPrimitiveRoot.Props\n>(({ onSubmit, ...rest }, forwardedRef) => {\n const send = useComposerSend();\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n\n if (!send) return;\n send();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={forwardedRef}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n});\n\nComposerPrimitiveRoot.displayName = \"ComposerPrimitive.Root\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,iBAAiB;AAC1B;AAAA,EAGE;AAAA,OAEK;AACP,SAAS,uBAAuB;AAqB5B;AAdG,IAAM,wBAAwB,WAGnC,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,iBAAiB;AACzC,QAAM,OAAO,gBAAgB;AAE7B,QAAM,eAAe,CAAC,MAAiB;AACrC,MAAE,eAAe;AAEjB,QAAI,CAAC,KAAM;AACX,SAAK;AAAA,EACP;AAEA,SACE;AAAA,IAAC,UAAU;AAAA,IAAV;AAAA,MACE,GAAG;AAAA,MACJ,KAAK;AAAA,MACL,UAAU,qBAAqB,UAAU,YAAY;AAAA;AAAA,EACvD;AAEJ,CAAC;AAED,sBAAsB,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n type FormEvent,\n forwardRef,\n ComponentPropsWithoutRef,\n} from \"react\";\nimport { useComposerSend } from \"./ComposerSend\";\n\nexport namespace ComposerPrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.form>;\n /**\n * Props for the ComposerPrimitive.Root component.\n * Accepts all standard form element props.\n */\n export type Props = ComponentPropsWithoutRef<typeof Primitive.form>;\n}\n\n/**\n * The root form container for message composition.\n *\n * This component provides a form wrapper that handles message submission when the form\n * is submitted (e.g., via Enter key or submit button). It automatically prevents the\n * default form submission and triggers the composer's send functionality.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Root>\n * <ComposerPrimitive.Input placeholder=\"Type your message...\" />\n * <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>\n * </ComposerPrimitive.Root>\n * ```\n */\nexport const ComposerPrimitiveRoot = forwardRef<\n ComposerPrimitiveRoot.Element,\n ComposerPrimitiveRoot.Props\n>(({ onSubmit, ...rest }, forwardedRef) => {\n const send = useComposerSend();\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n\n if (!send) return;\n send();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={forwardedRef}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n});\n\nComposerPrimitiveRoot.displayName = \"ComposerPrimitive.Root\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,iBAAiB;AAC1B;AAAA,EAGE;AAAA,OAEK;AACP,SAAS,uBAAuB;AAwC5B;AAdG,IAAM,wBAAwB,WAGnC,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,iBAAiB;AACzC,QAAM,OAAO,gBAAgB;AAE7B,QAAM,eAAe,CAAC,MAAiB;AACrC,MAAE,eAAe;AAEjB,QAAI,CAAC,KAAM;AACX,SAAK;AAAA,EACP;AAEA,SACE;AAAA,IAAC,UAAU;AAAA,IAAV;AAAA,MACE,GAAG;AAAA,MACJ,KAAK;AAAA,MACL,UAAU,qBAAqB,UAAU,YAAY;AAAA;AAAA,EACvD;AAEJ,CAAC;AAED,sBAAsB,cAAc;","names":[]}
@@ -2,8 +2,26 @@ import { ActionButtonElement, ActionButtonProps } from "../../utils/createAction
2
2
  export declare const useComposerSend: () => (() => void) | null;
3
3
  export declare namespace ComposerPrimitiveSend {
4
4
  type Element = ActionButtonElement;
5
+ /**
6
+ * Props for the ComposerPrimitive.Send component.
7
+ * Inherits all button element props and action button functionality.
8
+ */
5
9
  type Props = ActionButtonProps<typeof useComposerSend>;
6
10
  }
11
+ /**
12
+ * A button component that sends the current message in the composer.
13
+ *
14
+ * This component automatically handles the send functionality and is disabled
15
+ * when sending is not available (e.g., when the thread is running, the composer
16
+ * is empty, or not in editing mode).
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * <ComposerPrimitive.Send>
21
+ * Send Message
22
+ * </ComposerPrimitive.Send>
23
+ * ```
24
+ */
7
25
  export declare const ComposerPrimitiveSend: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
8
26
  asChild?: boolean;
9
27
  }, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerSend.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerSend.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAMxC,eAAO,MAAM,eAAe,2BAe3B,CAAC;AAEF,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,eAAe,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,qBAAqB;;6DAGjC,CAAC"}
1
+ {"version":3,"file":"ComposerSend.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerSend.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAMxC,eAAO,MAAM,eAAe,2BAe3B,CAAC;AAEF,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C;;;OAGG;IACH,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,eAAe,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB;;6DAGjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/composer/ComposerSend.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ActionButtonElement,\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useCallback } from \"react\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\nimport { useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useComposerRuntime } from \"../../context\";\n\nexport const useComposerSend = () => {\n const composerRuntime = useComposerRuntime();\n const threadRuntime = useThreadRuntime();\n\n const disabled = useCombinedStore(\n [threadRuntime, composerRuntime],\n (t, c) => t.isRunning || !c.isEditing || c.isEmpty,\n );\n\n const callback = useCallback(() => {\n composerRuntime.send();\n }, [composerRuntime]);\n\n if (disabled) return null;\n return callback;\n};\n\nexport namespace ComposerPrimitiveSend {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useComposerSend>;\n}\n\nexport const ComposerPrimitiveSend = createActionButton(\n \"ComposerPrimitive.Send\",\n useComposerSend,\n);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAE5B,IAAM,kBAAkB,MAAM;AACnC,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,gBAAgB,iBAAiB;AAEvC,QAAM,WAAW;AAAA,IACf,CAAC,eAAe,eAAe;AAAA,IAC/B,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,EAAE,aAAa,EAAE;AAAA,EAC7C;AAEA,QAAM,WAAW,YAAY,MAAM;AACjC,oBAAgB,KAAK;AAAA,EACvB,GAAG,CAAC,eAAe,CAAC;AAEpB,MAAI,SAAU,QAAO;AACrB,SAAO;AACT;AAOO,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/composer/ComposerSend.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ActionButtonElement,\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useCallback } from \"react\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\nimport { useThreadRuntime } from \"../../context/react/ThreadContext\";\nimport { useComposerRuntime } from \"../../context\";\n\nexport const useComposerSend = () => {\n const composerRuntime = useComposerRuntime();\n const threadRuntime = useThreadRuntime();\n\n const disabled = useCombinedStore(\n [threadRuntime, composerRuntime],\n (t, c) => t.isRunning || !c.isEditing || c.isEmpty,\n );\n\n const callback = useCallback(() => {\n composerRuntime.send();\n }, [composerRuntime]);\n\n if (disabled) return null;\n return callback;\n};\n\nexport namespace ComposerPrimitiveSend {\n export type Element = ActionButtonElement;\n /**\n * Props for the ComposerPrimitive.Send component.\n * Inherits all button element props and action button functionality.\n */\n export type Props = ActionButtonProps<typeof useComposerSend>;\n}\n\n/**\n * A button component that sends the current message in the composer.\n *\n * This component automatically handles the send functionality and is disabled\n * when sending is not available (e.g., when the thread is running, the composer\n * is empty, or not in editing mode).\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Send>\n * Send Message\n * </ComposerPrimitive.Send>\n * ```\n */\nexport const ComposerPrimitiveSend = createActionButton(\n \"ComposerPrimitive.Send\",\n useComposerSend,\n);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAE5B,IAAM,kBAAkB,MAAM;AACnC,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,gBAAgB,iBAAiB;AAEvC,QAAM,WAAW;AAAA,IACf,CAAC,eAAe,eAAe;AAAA,IAC/B,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,EAAE,aAAa,EAAE;AAAA,EAC7C;AAEA,QAAM,WAAW,YAAY,MAAM;AACjC,oBAAgB,KAAK;AAAA,EACvB,GAAG,CAAC,eAAe,CAAC;AAEpB,MAAI,SAAU,QAAO;AACrB,SAAO;AACT;AAyBO,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AACF;","names":[]}
@@ -2,8 +2,27 @@ import { Primitive } from "@radix-ui/react-primitive";
2
2
  import { type ComponentRef, ComponentPropsWithoutRef } from "react";
3
3
  export declare namespace ContentPartPrimitiveImage {
4
4
  type Element = ComponentRef<typeof Primitive.img>;
5
+ /**
6
+ * Props for the ContentPartPrimitive.Image component.
7
+ * Accepts all standard img element props.
8
+ */
5
9
  type Props = ComponentPropsWithoutRef<typeof Primitive.img>;
6
10
  }
11
+ /**
12
+ * Renders an image from the current content part context.
13
+ *
14
+ * This component displays image content from the current content part,
15
+ * automatically setting the src attribute from the content part's image data.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * <ContentPartPrimitive.Image
20
+ * alt="Generated image"
21
+ * className="message-image"
22
+ * style={{ maxWidth: '100%' }}
23
+ * />
24
+ * ```
25
+ */
7
26
  export declare const ContentPartPrimitiveImage: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLImageElement> & import("react").ImgHTMLAttributes<HTMLImageElement> & {
8
27
  asChild?: boolean;
9
28
  }, "ref"> & import("react").RefAttributes<HTMLImageElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"ContentPartImage.d.ts","sourceRoot":"","sources":["../../../src/primitives/contentPart/ContentPartImage.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,KAAK,YAAY,EAAc,wBAAwB,EAAE,MAAM,OAAO,CAAC;AAGhF,yBAAiB,yBAAyB,CAAC;IACzC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,yBAAyB;;4DAMpC,CAAC"}
1
+ {"version":3,"file":"ContentPartImage.d.ts","sourceRoot":"","sources":["../../../src/primitives/contentPart/ContentPartImage.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,KAAK,YAAY,EAAc,wBAAwB,EAAE,MAAM,OAAO,CAAC;AAGhF,yBAAiB,yBAAyB,CAAC;IACzC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD;;;OAGG;IACH,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB;;4DAMpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/contentPart/ContentPartImage.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartImage } from \"./useContentPartImage\";\n\nexport namespace ContentPartPrimitiveImage {\n export type Element = ComponentRef<typeof Primitive.img>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.img>;\n}\n\nexport const ContentPartPrimitiveImage = forwardRef<\n ContentPartPrimitiveImage.Element,\n ContentPartPrimitiveImage.Props\n>((props, forwardedRef) => {\n const { image } = useContentPartImage();\n return <Primitive.img src={image} {...props} ref={forwardedRef} />;\n});\n\nContentPartPrimitiveImage.displayName = \"ContentPartPrimitive.Image\";\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAA4B,kBAA4C;AACxE,SAAS,2BAA2B;AAY3B;AALF,IAAM,4BAA4B,WAGvC,CAAC,OAAO,iBAAiB;AACzB,QAAM,EAAE,MAAM,IAAI,oBAAoB;AACtC,SAAO,oBAAC,UAAU,KAAV,EAAc,KAAK,OAAQ,GAAG,OAAO,KAAK,cAAc;AAClE,CAAC;AAED,0BAA0B,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/contentPart/ContentPartImage.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartImage } from \"./useContentPartImage\";\n\nexport namespace ContentPartPrimitiveImage {\n export type Element = ComponentRef<typeof Primitive.img>;\n /**\n * Props for the ContentPartPrimitive.Image component.\n * Accepts all standard img element props.\n */\n export type Props = ComponentPropsWithoutRef<typeof Primitive.img>;\n}\n\n/**\n * Renders an image from the current content part context.\n *\n * This component displays image content from the current content part,\n * automatically setting the src attribute from the content part's image data.\n *\n * @example\n * ```tsx\n * <ContentPartPrimitive.Image\n * alt=\"Generated image\"\n * className=\"message-image\"\n * style={{ maxWidth: '100%' }}\n * />\n * ```\n */\nexport const ContentPartPrimitiveImage = forwardRef<\n ContentPartPrimitiveImage.Element,\n ContentPartPrimitiveImage.Props\n>((props, forwardedRef) => {\n const { image } = useContentPartImage();\n return <Primitive.img src={image} {...props} ref={forwardedRef} />;\n});\n\nContentPartPrimitiveImage.displayName = \"ContentPartPrimitive.Image\";\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAA4B,kBAA4C;AACxE,SAAS,2BAA2B;AA+B3B;AALF,IAAM,4BAA4B,WAGvC,CAAC,OAAO,iBAAiB;AACzB,QAAM,EAAE,MAAM,IAAI,oBAAoB;AACtC,SAAO,oBAAC,UAAU,KAAV,EAAc,KAAK,OAAQ,GAAG,OAAO,KAAK,cAAc;AAClE,CAAC;AAED,0BAA0B,cAAc;","names":[]}
@@ -3,14 +3,48 @@ import { type ComponentRef, ComponentPropsWithoutRef, ElementType } from "react"
3
3
  export declare namespace ContentPartPrimitiveText {
4
4
  type Element = ComponentRef<typeof Primitive.span>;
5
5
  type Props = Omit<ComponentPropsWithoutRef<typeof Primitive.span>, "children" | "asChild"> & {
6
+ /**
7
+ * Whether to enable smooth text streaming animation.
8
+ * When enabled, text appears with a typing effect as it streams in.
9
+ * @default true
10
+ */
6
11
  smooth?: boolean;
12
+ /**
13
+ * The HTML element or React component to render as.
14
+ * @default "span"
15
+ */
7
16
  component?: ElementType;
8
17
  };
9
18
  }
19
+ /**
20
+ * Renders the text content of a content part with optional smooth streaming.
21
+ *
22
+ * This component displays text content from the current content part context,
23
+ * with support for smooth streaming animation that shows text appearing
24
+ * character by character as it's generated.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * <ContentPartPrimitive.Text
29
+ * smooth={true}
30
+ * component="p"
31
+ * className="message-text"
32
+ * />
33
+ * ```
34
+ */
10
35
  export declare const ContentPartPrimitiveText: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").ClassAttributes<HTMLSpanElement> & import("react").HTMLAttributes<HTMLSpanElement> & {
11
36
  asChild?: boolean;
12
37
  }, "ref">, "children" | "asChild"> & {
38
+ /**
39
+ * Whether to enable smooth text streaming animation.
40
+ * When enabled, text appears with a typing effect as it streams in.
41
+ * @default true
42
+ */
13
43
  smooth?: boolean;
44
+ /**
45
+ * The HTML element or React component to render as.
46
+ * @default "span"
47
+ */
14
48
  component?: ElementType;
15
49
  } & import("react").RefAttributes<HTMLSpanElement>>;
16
50
  //# sourceMappingURL=ContentPartText.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentPartText.d.ts","sourceRoot":"","sources":["../../../src/primitives/contentPart/ContentPartText.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EACxB,WAAW,EACZ,MAAM,OAAO,CAAC;AAIf,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1D,KAAY,KAAK,GAAG,IAAI,CACtB,wBAAwB,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,EAC/C,UAAU,GAAG,SAAS,CACvB,GAAG;QACF,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,WAAW,CAAC;KACzB,CAAC;CACH;AAED,eAAO,MAAM,wBAAwB;;;aALxB,OAAO;gBACJ,WAAW;mDAezB,CAAC"}
1
+ {"version":3,"file":"ContentPartText.d.ts","sourceRoot":"","sources":["../../../src/primitives/contentPart/ContentPartText.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EACxB,WAAW,EACZ,MAAM,OAAO,CAAC;AAIf,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1D,KAAY,KAAK,GAAG,IAAI,CACtB,wBAAwB,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,EAC/C,UAAU,GAAG,SAAS,CACvB,GAAG;QACF;;;;WAIG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,SAAS,CAAC,EAAE,WAAW,CAAC;KACzB,CAAC;CACH;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB;;;IA9BjC;;;;OAIG;aACM,OAAO;IAChB;;;OAGG;gBACS,WAAW;mDA+BzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/contentPart/ContentPartText.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n ElementType,\n} from \"react\";\nimport { useContentPartText } from \"./useContentPartText\";\nimport { useSmooth } from \"../../utils/smooth/useSmooth\";\n\nexport namespace ContentPartPrimitiveText {\n export type Element = ComponentRef<typeof Primitive.span>;\n export type Props = Omit<\n ComponentPropsWithoutRef<typeof Primitive.span>,\n \"children\" | \"asChild\"\n > & {\n smooth?: boolean;\n component?: ElementType;\n };\n}\n\nexport const ContentPartPrimitiveText = forwardRef<\n ContentPartPrimitiveText.Element,\n ContentPartPrimitiveText.Props\n>(({ smooth = true, component: Component = \"span\", ...rest }, forwardedRef) => {\n const { text, status } = useSmooth(useContentPartText(), smooth);\n\n return (\n <Component data-status={status.type} {...rest} ref={forwardedRef}>\n {text}\n </Component>\n );\n});\n\nContentPartPrimitiveText.displayName = \"ContentPartPrimitive.Text\";\n"],"mappings":";;;AAGA;AAAA,EAEE;AAAA,OAGK;AACP,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAoBtB;AAPG,IAAM,2BAA2B,WAGtC,CAAC,EAAE,SAAS,MAAM,WAAW,YAAY,QAAQ,GAAG,KAAK,GAAG,iBAAiB;AAC7E,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU,mBAAmB,GAAG,MAAM;AAE/D,SACE,oBAAC,aAAU,eAAa,OAAO,MAAO,GAAG,MAAM,KAAK,cACjD,gBACH;AAEJ,CAAC;AAED,yBAAyB,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/contentPart/ContentPartText.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n ElementType,\n} from \"react\";\nimport { useContentPartText } from \"./useContentPartText\";\nimport { useSmooth } from \"../../utils/smooth/useSmooth\";\n\nexport namespace ContentPartPrimitiveText {\n export type Element = ComponentRef<typeof Primitive.span>;\n export type Props = Omit<\n ComponentPropsWithoutRef<typeof Primitive.span>,\n \"children\" | \"asChild\"\n > & {\n /**\n * Whether to enable smooth text streaming animation.\n * When enabled, text appears with a typing effect as it streams in.\n * @default true\n */\n smooth?: boolean;\n /**\n * The HTML element or React component to render as.\n * @default \"span\"\n */\n component?: ElementType;\n };\n}\n\n/**\n * Renders the text content of a content part with optional smooth streaming.\n *\n * This component displays text content from the current content part context,\n * with support for smooth streaming animation that shows text appearing\n * character by character as it's generated.\n *\n * @example\n * ```tsx\n * <ContentPartPrimitive.Text\n * smooth={true}\n * component=\"p\"\n * className=\"message-text\"\n * />\n * ```\n */\nexport const ContentPartPrimitiveText = forwardRef<\n ContentPartPrimitiveText.Element,\n ContentPartPrimitiveText.Props\n>(({ smooth = true, component: Component = \"span\", ...rest }, forwardedRef) => {\n const { text, status } = useSmooth(useContentPartText(), smooth);\n\n return (\n <Component data-status={status.type} {...rest} ref={forwardedRef}>\n {text}\n </Component>\n );\n});\n\nContentPartPrimitiveText.displayName = \"ContentPartPrimitive.Text\";\n"],"mappings":";;;AAGA;AAAA,EAEE;AAAA,OAGK;AACP,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AA6CtB;AAPG,IAAM,2BAA2B,WAGtC,CAAC,EAAE,SAAS,MAAM,WAAW,YAAY,QAAQ,GAAG,KAAK,GAAG,iBAAiB;AAC7E,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU,mBAAmB,GAAG,MAAM;AAE/D,SACE,oBAAC,aAAU,eAAa,OAAO,MAAO,GAAG,MAAM,KAAK,cACjD,gBACH;AAEJ,CAAC;AAED,yBAAyB,cAAc;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"MessageAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAuDD,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CAclC,CAAC"}
1
+ {"version":3,"file":"MessageAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAuDD,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CAkBlC,CAAC"}
@@ -42,14 +42,17 @@ var MessagePrimitiveAttachments = ({ components }) => {
42
42
  if (message.role !== "user") return 0;
43
43
  return message.attachments.length;
44
44
  });
45
- return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(
46
- MessageAttachment,
47
- {
48
- attachmentIndex: index,
49
- components
50
- },
51
- index
52
- ));
45
+ const attachmentElements = useMemo(() => {
46
+ return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(
47
+ MessageAttachment,
48
+ {
49
+ attachmentIndex: index,
50
+ components
51
+ },
52
+ index
53
+ ));
54
+ }, [attachmentsCount, components]);
55
+ return attachmentElements;
53
56
  };
54
57
  MessagePrimitiveAttachments.displayName = "MessagePrimitive.Attachments";
55
58
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { useMessage, useMessageRuntime } from \"../../context\";\nimport { useMessageAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\nimport { CompleteAttachment } from \"../../types\";\n\nexport namespace MessagePrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: MessagePrimitiveAttachments.Props[\"components\"],\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessagePrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useMessageAttachment((a) => getComponent(components, a));\n\n if (!Component) return null;\n return <Component />;\n};\n\nconst MessageAttachmentImpl: FC<\n MessagePrimitiveAttachments.Props & { attachmentIndex: number }\n> = ({ components, attachmentIndex }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getAttachmentByIndex(attachmentIndex),\n [messageRuntime, attachmentIndex],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n};\n\nconst MessageAttachment = memo(\n MessageAttachmentImpl,\n (prev, next) =>\n prev.attachmentIndex === next.attachmentIndex &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n);\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useMessage((message) => {\n if (message.role !== \"user\") return 0;\n return message.attachments.length;\n });\n\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <MessageAttachment\n key={index}\n attachmentIndex={index}\n components={components}\n />\n ));\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AACtD,SAAS,YAAY,yBAAyB;AAC9C,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAwCjC;AAxBT,IAAM,eAAe,CACnB,YACA,eACG;A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AFK;AAAA,EAGP,CACD;AACH;AAEA,4BAA4B,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/message/MessageAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { useMessage, useMessageRuntime } from \"../../context\";\nimport { useMessageAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\nimport { CompleteAttachment } from \"../../types\";\n\nexport namespace MessagePrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: MessagePrimitiveAttachments.Props[\"components\"],\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessagePrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useMessageAttachment((a) => getComponent(components, a));\n\n if (!Component) return null;\n return <Component />;\n};\n\nconst MessageAttachmentImpl: FC<\n MessagePrimitiveAttachments.Props & { attachmentIndex: number }\n> = ({ components, attachmentIndex }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getAttachmentByIndex(attachmentIndex),\n [messageRuntime, attachmentIndex],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n};\n\nconst MessageAttachment = memo(\n MessageAttachmentImpl,\n (prev, next) =>\n prev.attachmentIndex === next.attachmentIndex &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n);\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useMessage((message) => {\n if (message.role !== \"user\") return 0;\n return message.attachments.length;\n });\n\n const attachmentElements = useMemo(() => {\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <MessageAttachment\n key={index}\n attachmentIndex={index}\n components={components}\n />\n ));\n }, [attachmentsCount, components]);\n\n return attachmentElements;\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AACtD,SAAS,YAAY,yBAAyB;AAC9C,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAwCjC;AAxBT,IAAM,eAAe,CACnB,YACA,eACG;AACH,QAAM,OAAO,WAAW;AACxB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,YAAY,SAAS,YAAY;AAAA,IAC1C,KAAK;AACH,aAAO,YAAY,YAAY,YAAY;AAAA,IAC7C,KAAK;AACH,aAAO,YAAY,QAAQ,YAAY;AAAA,IACzC;AACE,YAAM,mBAA0B;AAChC,YAAM,IAAI,MAAM,4BAA4B,gBAAgB,EAAE;AAAA,EAClE;AACF;AAEA,IAAM,sBAED,CAAC,EAAE,WAAW,MAAM;AACvB,QAAM,YAAY,qBAAqB,CAAC,MAAM,aAAa,YAAY,CAAC,CAAC;AAEzE,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,oBAAC,aAAU;AACpB;AAEA,IAAM,wBAEF,CAAC,EAAE,YAAY,gBAAgB,MAAM;AACvC,QAAM,iBAAiB,kBAAkB;AACzC,QAAM,UAAU;AAAA,IACd,MAAM,eAAe,qBAAqB,eAAe;AAAA,IACzD,CAAC,gBAAgB,eAAe;AAAA,EAClC;AAEA,SACE,oBAAC,6BAA0B,SACzB,8BAAC,uBAAoB,YAAwB,GAC/C;AAEJ;AAEA,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA,CAAC,MAAM,SACL,KAAK,oBAAoB,KAAK,mBAC9B,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,aAAa,KAAK,YAAY,YAC/C,KAAK,YAAY,SAAS,KAAK,YAAY,QAC3C,KAAK,YAAY,eAAe,KAAK,YAAY;AACrD;AAEO,IAAM,8BAET,CAAC,EAAE,WAAW,MAAM;AACtB,QAAM,mBAAmB,WAAW,CAAC,YAAY;AAC/C,QAAI,QAAQ,SAAS,OAAQ,QAAO;AACpC,WAAO,QAAQ,YAAY;AAAA,EAC7B,CAAC;AAED,QAAM,qBAAqB,QAAQ,MAAM;AACvC,WAAO,MAAM,KAAK,EAAE,QAAQ,iBAAiB,GAAG,CAAC,GAAG,UAClD;AAAA,MAAC;AAAA;AAAA,QAEC,iBAAiB;AAAA,QACjB;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,kBAAkB,UAAU,CAAC;AAEjC,SAAO;AACT;AAEA,4BAA4B,cAAc;","names":[]}
@@ -2,22 +2,63 @@ import { type ComponentType, type FC } from "react";
2
2
  import type { Unstable_AudioContentPartComponent, EmptyContentPartComponent, TextContentPartComponent, ImageContentPartComponent, SourceContentPartComponent, ToolCallContentPartComponent, ToolCallContentPartProps, FileContentPartComponent, ReasoningContentPartComponent } from "../../types/ContentPartComponentTypes";
3
3
  export declare namespace MessagePrimitiveContent {
4
4
  type Props = {
5
+ /**
6
+ * Component configuration for rendering different types of message content.
7
+ *
8
+ * You can provide custom components for each content type (text, image, file, etc.)
9
+ * and configure tool rendering behavior. If not provided, default components will be used.
10
+ */
5
11
  components?: {
12
+ /** Component for rendering empty messages */
6
13
  Empty?: EmptyContentPartComponent | undefined;
14
+ /** Component for rendering text content */
7
15
  Text?: TextContentPartComponent | undefined;
16
+ /** Component for rendering reasoning content (typically hidden) */
8
17
  Reasoning?: ReasoningContentPartComponent | undefined;
18
+ /** Component for rendering source content */
9
19
  Source?: SourceContentPartComponent | undefined;
20
+ /** Component for rendering image content */
10
21
  Image?: ImageContentPartComponent | undefined;
22
+ /** Component for rendering file content */
11
23
  File?: FileContentPartComponent | undefined;
24
+ /** Component for rendering audio content (experimental) */
12
25
  Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;
26
+ /** Configuration for tool call rendering */
13
27
  tools?: {
28
+ /** Map of tool names to their specific components */
14
29
  by_name?: Record<string, ToolCallContentPartComponent | undefined> | undefined;
30
+ /** Fallback component for unregistered tools */
15
31
  Fallback?: ComponentType<ToolCallContentPartProps> | undefined;
16
32
  } | {
33
+ /** Override component that handles all tool calls */
17
34
  Override: ComponentType<ToolCallContentPartProps>;
18
35
  } | undefined;
19
36
  } | undefined;
20
37
  };
21
38
  }
39
+ /**
40
+ * Renders the content of a message with support for multiple content types.
41
+ *
42
+ * This component automatically handles different types of message content including
43
+ * text, images, files, tool calls, and more. It provides a flexible component
44
+ * system for customizing how each content type is rendered.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * <MessagePrimitive.Content
49
+ * components={{
50
+ * Text: ({ text }) => <p className="message-text">{text}</p>,
51
+ * Image: ({ image }) => <img src={image} alt="Message image" />,
52
+ * tools: {
53
+ * by_name: {
54
+ * calculator: CalculatorTool,
55
+ * weather: WeatherTool,
56
+ * },
57
+ * Fallback: DefaultToolComponent
58
+ * }
59
+ * }}
60
+ * />
61
+ * ```
62
+ */
22
63
  export declare const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props>;
23
64
  //# sourceMappingURL=MessageContent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessageContent.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageContent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAcnE,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,uCAAuC,CAAC;AAI/C,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG;QAClB,UAAU,CAAC,EACP;YACE,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,SAAS,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;YACtD,MAAM,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;YAChD,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,KAAK,CAAC,EACF;gBACE,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;SACf,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA+JD,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAwBrE,CAAC"}
1
+ {"version":3,"file":"MessageContent.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageContent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAcnE,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,uCAAuC,CAAC;AAI/C,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG;QAClB;;;;;WAKG;QACH,UAAU,CAAC,EACP;YACE,6CAA6C;YAC7C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,mEAAmE;YACnE,SAAS,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;YACtD,6CAA6C;YAC7C,MAAM,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;YAChD,4CAA4C;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,2DAA2D;YAC3D,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,4CAA4C;YAC5C,KAAK,CAAC,EACF;gBACE,qDAAqD;gBACrD,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,gDAAgD;gBAChD,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,qDAAqD;gBACrD,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;SACf,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA+JD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAmBrE,CAAC"}
@@ -119,17 +119,20 @@ var MessagePrimitiveContent = ({
119
119
  components
120
120
  }) => {
121
121
  const contentLength = useMessage((s) => s.content.length);
122
- if (contentLength === 0) {
123
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(EmptyContent, { components }) });
124
- }
125
- return /* @__PURE__ */ jsx(Fragment, { children: Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ jsx(
126
- MessageContentPart,
127
- {
128
- partIndex: index,
129
- components
130
- },
131
- index
132
- )) });
122
+ const contentElements = useMemo(() => {
123
+ if (contentLength === 0) {
124
+ return /* @__PURE__ */ jsx(EmptyContent, { components });
125
+ }
126
+ return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ jsx(
127
+ MessageContentPart,
128
+ {
129
+ partIndex: index,
130
+ components
131
+ },
132
+ index
133
+ ));
134
+ }, [contentLength, components]);
135
+ return /* @__PURE__ */ jsx(Fragment, { children: contentElements });
133
136
  };
134
137
  MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
135
138
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n TextContentPartProvider,\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n TextContentPartComponent,\n ImageContentPartComponent,\n SourceContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n FileContentPartComponent,\n ReasoningContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n components?:\n | {\n Empty?: EmptyContentPartComponent | undefined;\n Text?: TextContentPartComponent | undefined;\n Reasoning?: ReasoningContentPartComponent | undefined;\n Source?: SourceContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n File?: FileContentPartComponent | undefined;\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n tools?:\n | {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\n }\n\n if (part.status.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentFallback: FC<{\n status: ContentPartStatus;\n component: TextContentPartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextContentPartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextContentPartProvider>\n );\n};\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyContentFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n if (contentLength === 0) {\n return (\n <>\n <EmptyContent components={components} />\n </>\n );\n }\n\n return (\n <>\n {Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart\n key={index}\n partIndex={index}\n components={components}\n />\n ))}\n </>\n );\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;AAEA,SAAsC,MAAM,eAAe;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAY1C,SAAS,sCAAsC;AAsCtC,SA4JH,UA5JG,KAKL,YALK;AART,IAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA,GAAG;AACL,MAEiC;AAC/B,QAAM,SAAS,WAAW,CAAC,MAAM,EAAE,UAAU,MAAM,QAAQ,CAAC,KAAK;AACjE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,oBAAC,UAAQ,GAAG,OAAO;AAC5B;AAEA,IAAM,oBAAoB;AAAA,EACxB,MAAM,MACJ,qBAAC,OAAE,OAAO,EAAE,YAAY,WAAW,GACjC;AAAA,wBAAC,4BAAyB;AAAA,IAC1B,oBAAC,kCACC,8BAAC,UAAK,OAAO,EAAE,YAAY,SAAS,GAAI,qBAAU,GACpD;AAAA,KACF;AAAA,EAEF,WAAW,MAAM;AAAA,EACjB,QAAQ,MAA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YAAY,SAAS,KAAK,YAAY;AAC/C;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AACF,MAAM;AACJ,QAAM,gBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AAExD,MAAI,kBAAkB,GAAG;AACvB,WACE,gCACE,8BAAC,gBAAa,YAAwB,GACxC;AAAA,EAEJ;AAEA,SACE,gCACG,gBAAM,KAAK,EAAE,QAAQ,cAAc,GAAG,CAAC,GAAG,UACzC;AAAA,IAAC;AAAA;AAAA,MAEC,WAAW;AAAA,MACX;AAAA;AAAA,IAFK;AAAA,EAGP,CACD,GACH;AAEJ;AAEA,wBAAwB,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n TextContentPartProvider,\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n TextContentPartComponent,\n ImageContentPartComponent,\n SourceContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n FileContentPartComponent,\n ReasoningContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components?:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyContentPartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextContentPartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningContentPartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceContentPartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageContentPartComponent | undefined;\n /** Component for rendering file content */\n File?: FileContentPartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\n }\n\n if (part.status.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentFallback: FC<{\n status: ContentPartStatus;\n component: TextContentPartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextContentPartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextContentPartProvider>\n );\n};\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyContentFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the content of a message with support for multiple content types.\n *\n * This component automatically handles different types of message content including\n * text, images, files, tool calls, and more. It provides a flexible component\n * system for customizing how each content type is rendered.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Content\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * tools: {\n * by_name: {\n * calculator: CalculatorTool,\n * weather: WeatherTool,\n * },\n * Fallback: DefaultToolComponent\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n const contentElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyContent components={components} />;\n }\n return Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart\n key={index}\n partIndex={index}\n components={components}\n />\n ));\n }, [contentLength, components]);\n\n return <>{contentElements}</>;\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;AAEA,SAAsC,MAAM,eAAe;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC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;AACR,CAAC;AAED,IAAM,uBAGD,CAAC,EAAE,QAAQ,WAAW,UAAU,MAAM;AACzC,SACE,oBAAC,2BAAwB,MAAK,IAAG,WAAW,OAAO,SAAS,WAC1D,8BAAC,aAAU,MAAK,QAAO,MAAK,IAAG,QAAgB,GACjD;AAEJ;AAEA,IAAM,mBAAyD,CAAC;AAAA,EAC9D;AACF,MAAM;AACJ,QAAM,SACJ,WAAW,CAAC,MAAM,EAAE,MAA2B,KAAK;AAEtD,MAAI,YAAY,MAAO,QAAO,oBAAC,WAAW,OAAX,EAAiB,QAAgB;AAEhE,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,YAAY,QAAQ,kBAAkB;AAAA;AAAA,EACnD;AAEJ;AAEA,IAAM,eAAe;AAAA,EACnB;AAAA,EACA,CAAC,MAAM,SACL,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,SAAS,KAAK,YAAY;AAC/C;AA0BO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AACF,MAAM;AACJ,QAAM,gBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AAExD,QAAM,kBAAkB,QAAQ,MAAM;AACpC,QAAI,kBAAkB,GAAG;AACvB,aAAO,oBAAC,gBAAa,YAAwB;AAAA,IAC/C;AACA,WAAO,MAAM,KAAK,EAAE,QAAQ,cAAc,GAAG,CAAC,GAAG,UAC/C;AAAA,MAAC;AAAA;AAAA,QAEC,WAAW;AAAA,QACX;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,eAAe,UAAU,CAAC;AAE9B,SAAO,gCAAG,2BAAgB;AAC5B;AAEA,wBAAwB,cAAc;","names":[]}
@@ -2,8 +2,30 @@ import { Primitive } from "@radix-ui/react-primitive";
2
2
  import { type ComponentRef, ComponentPropsWithoutRef } from "react";
3
3
  export declare namespace MessagePrimitiveRoot {
4
4
  type Element = ComponentRef<typeof Primitive.div>;
5
+ /**
6
+ * Props for the MessagePrimitive.Root component.
7
+ * Accepts all standard div element props.
8
+ */
5
9
  type Props = ComponentPropsWithoutRef<typeof Primitive.div>;
6
10
  }
11
+ /**
12
+ * The root container component for a message.
13
+ *
14
+ * This component provides the foundational wrapper for message content and handles
15
+ * hover state management for the message. It automatically tracks when the user
16
+ * is hovering over the message, which can be used by child components like action bars.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * <MessagePrimitive.Root>
21
+ * <MessagePrimitive.Content />
22
+ * <ActionBarPrimitive.Root>
23
+ * <ActionBarPrimitive.Copy />
24
+ * <ActionBarPrimitive.Edit />
25
+ * </ActionBarPrimitive.Root>
26
+ * </MessagePrimitive.Root>
27
+ * ```
28
+ */
7
29
  export declare const MessagePrimitiveRoot: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
8
30
  asChild?: boolean;
9
31
  }, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"MessageRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;AAiCf,yBAAiB,oBAAoB,CAAC;IACpC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,oBAAoB;;0DAQ/B,CAAC"}
1
+ {"version":3,"file":"MessageRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;AAiCf,yBAAiB,oBAAoB,CAAC;IACpC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD;;;OAGG;IACH,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB;;0DAQ/B,CAAC"}