@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
@@ -7,10 +7,32 @@ import { If } from "../message";
7
7
  export namespace BranchPickerPrimitiveRoot {
8
8
  export type Element = ComponentRef<typeof Primitive.div>;
9
9
  export type Props = ComponentPropsWithoutRef<typeof Primitive.div> & {
10
+ /**
11
+ * Whether to hide the branch picker when there's only one branch available.
12
+ * When true, the component will only render when multiple branches exist.
13
+ * @default false
14
+ */
10
15
  hideWhenSingleBranch?: boolean | undefined;
11
16
  };
12
17
  }
13
18
 
19
+ /**
20
+ * The root container for branch picker components.
21
+ *
22
+ * This component provides a container for branch navigation controls,
23
+ * with optional conditional rendering based on the number of available branches.
24
+ * It integrates with the message branching system to allow users to navigate
25
+ * between different response variations.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * <BranchPickerPrimitive.Root hideWhenSingleBranch={true}>
30
+ * <BranchPickerPrimitive.Previous />
31
+ * <BranchPickerPrimitive.Count />
32
+ * <BranchPickerPrimitive.Next />
33
+ * </BranchPickerPrimitive.Root>
34
+ * ```
35
+ */
14
36
  export const BranchPickerPrimitiveRoot = forwardRef<
15
37
  BranchPickerPrimitiveRoot.Element,
16
38
  BranchPickerPrimitiveRoot.Props
@@ -79,13 +79,17 @@ export const ComposerPrimitiveAttachments: FC<
79
79
  > = ({ components }) => {
80
80
  const attachmentsCount = useComposer((s) => s.attachments.length);
81
81
 
82
- return Array.from({ length: attachmentsCount }, (_, index) => (
83
- <ComposerAttachment
84
- key={index}
85
- attachmentIndex={index}
86
- components={components}
87
- />
88
- ));
82
+ const attachmentElements = useMemo(() => {
83
+ return Array.from({ length: attachmentsCount }, (_, index) => (
84
+ <ComposerAttachment
85
+ key={index}
86
+ attachmentIndex={index}
87
+ components={components}
88
+ />
89
+ ));
90
+ }, [attachmentsCount, components]);
91
+
92
+ return attachmentElements;
89
93
  };
90
94
 
91
95
  ComposerPrimitiveAttachments.displayName = "ComposerPrimitive.Attachments";
@@ -22,9 +22,26 @@ const useComposerCancel = () => {
22
22
 
23
23
  export namespace ComposerPrimitiveCancel {
24
24
  export type Element = ActionButtonElement;
25
+ /**
26
+ * Props for the ComposerPrimitive.Cancel component.
27
+ * Inherits all button element props and action button functionality.
28
+ */
25
29
  export type Props = ActionButtonProps<typeof useComposerCancel>;
26
30
  }
27
31
 
32
+ /**
33
+ * A button component that cancels the current message composition.
34
+ *
35
+ * This component automatically handles the cancel functionality and is disabled
36
+ * when canceling is not available.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * <ComposerPrimitive.Cancel>
41
+ * Cancel
42
+ * </ComposerPrimitive.Cancel>
43
+ * ```
44
+ */
28
45
  export const ComposerPrimitiveCancel = createActionButton(
29
46
  "ComposerPrimitive.Cancel",
30
47
  useComposerCancel,
@@ -26,16 +26,60 @@ import { useThreadListItemRuntime } from "../../context/react/ThreadListItemCont
26
26
  export namespace ComposerPrimitiveInput {
27
27
  export type Element = HTMLTextAreaElement;
28
28
  export type Props = TextareaAutosizeProps & {
29
+ /**
30
+ * Whether to render as a child component using Slot.
31
+ * When true, the component will merge its props with its child.
32
+ */
29
33
  asChild?: boolean | undefined;
34
+ /**
35
+ * Whether to submit the message when Enter is pressed (without Shift).
36
+ * @default true
37
+ */
30
38
  submitOnEnter?: boolean | undefined;
39
+ /**
40
+ * Whether to cancel message composition when Escape is pressed.
41
+ * @default true
42
+ */
31
43
  cancelOnEscape?: boolean | undefined;
44
+ /**
45
+ * Whether to automatically focus the input when a new run starts.
46
+ * @default true
47
+ */
32
48
  unstable_focusOnRunStart?: boolean | undefined;
49
+ /**
50
+ * Whether to automatically focus the input when scrolling to bottom.
51
+ * @default true
52
+ */
33
53
  unstable_focusOnScrollToBottom?: boolean | undefined;
54
+ /**
55
+ * Whether to automatically focus the input when switching threads.
56
+ * @default true
57
+ */
34
58
  unstable_focusOnThreadSwitched?: boolean | undefined;
59
+ /**
60
+ * Whether to automatically add pasted files as attachments.
61
+ * @default true
62
+ */
35
63
  addAttachmentOnPaste?: boolean | undefined;
36
64
  };
37
65
  }
38
66
 
67
+ /**
68
+ * A text input component for composing messages.
69
+ *
70
+ * This component provides a rich text input experience with automatic resizing,
71
+ * keyboard shortcuts, file paste support, and intelligent focus management.
72
+ * It integrates with the composer context to manage message state and submission.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * <ComposerPrimitive.Input
77
+ * placeholder="Type your message..."
78
+ * submitOnEnter={true}
79
+ * addAttachmentOnPaste={true}
80
+ * />
81
+ * ```
82
+ */
39
83
  export const ComposerPrimitiveInput = forwardRef<
40
84
  ComposerPrimitiveInput.Element,
41
85
  ComposerPrimitiveInput.Props
@@ -12,9 +12,28 @@ import { useComposerSend } from "./ComposerSend";
12
12
 
13
13
  export namespace ComposerPrimitiveRoot {
14
14
  export type Element = ComponentRef<typeof Primitive.form>;
15
+ /**
16
+ * Props for the ComposerPrimitive.Root component.
17
+ * Accepts all standard form element props.
18
+ */
15
19
  export type Props = ComponentPropsWithoutRef<typeof Primitive.form>;
16
20
  }
17
21
 
22
+ /**
23
+ * The root form container for message composition.
24
+ *
25
+ * This component provides a form wrapper that handles message submission when the form
26
+ * is submitted (e.g., via Enter key or submit button). It automatically prevents the
27
+ * default form submission and triggers the composer's send functionality.
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * <ComposerPrimitive.Root>
32
+ * <ComposerPrimitive.Input placeholder="Type your message..." />
33
+ * <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
34
+ * </ComposerPrimitive.Root>
35
+ * ```
36
+ */
18
37
  export const ComposerPrimitiveRoot = forwardRef<
19
38
  ComposerPrimitiveRoot.Element,
20
39
  ComposerPrimitiveRoot.Props
@@ -29,9 +29,27 @@ export const useComposerSend = () => {
29
29
 
30
30
  export namespace ComposerPrimitiveSend {
31
31
  export type Element = ActionButtonElement;
32
+ /**
33
+ * Props for the ComposerPrimitive.Send component.
34
+ * Inherits all button element props and action button functionality.
35
+ */
32
36
  export type Props = ActionButtonProps<typeof useComposerSend>;
33
37
  }
34
38
 
39
+ /**
40
+ * A button component that sends the current message in the composer.
41
+ *
42
+ * This component automatically handles the send functionality and is disabled
43
+ * when sending is not available (e.g., when the thread is running, the composer
44
+ * is empty, or not in editing mode).
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * <ComposerPrimitive.Send>
49
+ * Send Message
50
+ * </ComposerPrimitive.Send>
51
+ * ```
52
+ */
35
53
  export const ComposerPrimitiveSend = createActionButton(
36
54
  "ComposerPrimitive.Send",
37
55
  useComposerSend,
@@ -6,9 +6,28 @@ import { useContentPartImage } from "./useContentPartImage";
6
6
 
7
7
  export namespace ContentPartPrimitiveImage {
8
8
  export type Element = ComponentRef<typeof Primitive.img>;
9
+ /**
10
+ * Props for the ContentPartPrimitive.Image component.
11
+ * Accepts all standard img element props.
12
+ */
9
13
  export type Props = ComponentPropsWithoutRef<typeof Primitive.img>;
10
14
  }
11
15
 
16
+ /**
17
+ * Renders an image from the current content part context.
18
+ *
19
+ * This component displays image content from the current content part,
20
+ * automatically setting the src attribute from the content part's image data.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * <ContentPartPrimitive.Image
25
+ * alt="Generated image"
26
+ * className="message-image"
27
+ * style={{ maxWidth: '100%' }}
28
+ * />
29
+ * ```
30
+ */
12
31
  export const ContentPartPrimitiveImage = forwardRef<
13
32
  ContentPartPrimitiveImage.Element,
14
33
  ContentPartPrimitiveImage.Props
@@ -16,11 +16,36 @@ export namespace ContentPartPrimitiveText {
16
16
  ComponentPropsWithoutRef<typeof Primitive.span>,
17
17
  "children" | "asChild"
18
18
  > & {
19
+ /**
20
+ * Whether to enable smooth text streaming animation.
21
+ * When enabled, text appears with a typing effect as it streams in.
22
+ * @default true
23
+ */
19
24
  smooth?: boolean;
25
+ /**
26
+ * The HTML element or React component to render as.
27
+ * @default "span"
28
+ */
20
29
  component?: ElementType;
21
30
  };
22
31
  }
23
32
 
33
+ /**
34
+ * Renders the text content of a content part with optional smooth streaming.
35
+ *
36
+ * This component displays text content from the current content part context,
37
+ * with support for smooth streaming animation that shows text appearing
38
+ * character by character as it's generated.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * <ContentPartPrimitive.Text
43
+ * smooth={true}
44
+ * component="p"
45
+ * className="message-text"
46
+ * />
47
+ * ```
48
+ */
24
49
  export const ContentPartPrimitiveText = forwardRef<
25
50
  ContentPartPrimitiveText.Element,
26
51
  ContentPartPrimitiveText.Props
@@ -80,13 +80,17 @@ export const MessagePrimitiveAttachments: FC<
80
80
  return message.attachments.length;
81
81
  });
82
82
 
83
- return Array.from({ length: attachmentsCount }, (_, index) => (
84
- <MessageAttachment
85
- key={index}
86
- attachmentIndex={index}
87
- components={components}
88
- />
89
- ));
83
+ const attachmentElements = useMemo(() => {
84
+ return Array.from({ length: attachmentsCount }, (_, index) => (
85
+ <MessageAttachment
86
+ key={index}
87
+ attachmentIndex={index}
88
+ components={components}
89
+ />
90
+ ));
91
+ }, [attachmentsCount, components]);
92
+
93
+ return attachmentElements;
90
94
  };
91
95
 
92
96
  MessagePrimitiveAttachments.displayName = "MessagePrimitive.Attachments";
@@ -30,23 +30,40 @@ import { ContentPartStatus } from "../../types/AssistantTypes";
30
30
 
31
31
  export namespace MessagePrimitiveContent {
32
32
  export type Props = {
33
+ /**
34
+ * Component configuration for rendering different types of message content.
35
+ *
36
+ * You can provide custom components for each content type (text, image, file, etc.)
37
+ * and configure tool rendering behavior. If not provided, default components will be used.
38
+ */
33
39
  components?:
34
40
  | {
41
+ /** Component for rendering empty messages */
35
42
  Empty?: EmptyContentPartComponent | undefined;
43
+ /** Component for rendering text content */
36
44
  Text?: TextContentPartComponent | undefined;
45
+ /** Component for rendering reasoning content (typically hidden) */
37
46
  Reasoning?: ReasoningContentPartComponent | undefined;
47
+ /** Component for rendering source content */
38
48
  Source?: SourceContentPartComponent | undefined;
49
+ /** Component for rendering image content */
39
50
  Image?: ImageContentPartComponent | undefined;
51
+ /** Component for rendering file content */
40
52
  File?: FileContentPartComponent | undefined;
53
+ /** Component for rendering audio content (experimental) */
41
54
  Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;
55
+ /** Configuration for tool call rendering */
42
56
  tools?:
43
57
  | {
58
+ /** Map of tool names to their specific components */
44
59
  by_name?:
45
60
  | Record<string, ToolCallContentPartComponent | undefined>
46
61
  | undefined;
62
+ /** Fallback component for unregistered tools */
47
63
  Fallback?: ComponentType<ToolCallContentPartProps> | undefined;
48
64
  }
49
65
  | {
66
+ /** Override component that handles all tool calls */
50
67
  Override: ComponentType<ToolCallContentPartProps>;
51
68
  }
52
69
  | undefined;
@@ -212,30 +229,49 @@ const EmptyContent = memo(
212
229
  prev.components?.Text === next.components?.Text,
213
230
  );
214
231
 
232
+ /**
233
+ * Renders the content of a message with support for multiple content types.
234
+ *
235
+ * This component automatically handles different types of message content including
236
+ * text, images, files, tool calls, and more. It provides a flexible component
237
+ * system for customizing how each content type is rendered.
238
+ *
239
+ * @example
240
+ * ```tsx
241
+ * <MessagePrimitive.Content
242
+ * components={{
243
+ * Text: ({ text }) => <p className="message-text">{text}</p>,
244
+ * Image: ({ image }) => <img src={image} alt="Message image" />,
245
+ * tools: {
246
+ * by_name: {
247
+ * calculator: CalculatorTool,
248
+ * weather: WeatherTool,
249
+ * },
250
+ * Fallback: DefaultToolComponent
251
+ * }
252
+ * }}
253
+ * />
254
+ * ```
255
+ */
215
256
  export const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({
216
257
  components,
217
258
  }) => {
218
259
  const contentLength = useMessage((s) => s.content.length);
219
260
 
220
- if (contentLength === 0) {
221
- return (
222
- <>
223
- <EmptyContent components={components} />
224
- </>
225
- );
226
- }
261
+ const contentElements = useMemo(() => {
262
+ if (contentLength === 0) {
263
+ return <EmptyContent components={components} />;
264
+ }
265
+ return Array.from({ length: contentLength }, (_, index) => (
266
+ <MessageContentPart
267
+ key={index}
268
+ partIndex={index}
269
+ components={components}
270
+ />
271
+ ));
272
+ }, [contentLength, components]);
227
273
 
228
- return (
229
- <>
230
- {Array.from({ length: contentLength }, (_, index) => (
231
- <MessageContentPart
232
- key={index}
233
- partIndex={index}
234
- components={components}
235
- />
236
- ))}
237
- </>
238
- );
274
+ return <>{contentElements}</>;
239
275
  };
240
276
 
241
277
  MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
@@ -41,9 +41,31 @@ const useIsHoveringRef = () => {
41
41
 
42
42
  export namespace MessagePrimitiveRoot {
43
43
  export type Element = ComponentRef<typeof Primitive.div>;
44
+ /**
45
+ * Props for the MessagePrimitive.Root component.
46
+ * Accepts all standard div element props.
47
+ */
44
48
  export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;
45
49
  }
46
50
 
51
+ /**
52
+ * The root container component for a message.
53
+ *
54
+ * This component provides the foundational wrapper for message content and handles
55
+ * hover state management for the message. It automatically tracks when the user
56
+ * is hovering over the message, which can be used by child components like action bars.
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * <MessagePrimitive.Root>
61
+ * <MessagePrimitive.Content />
62
+ * <ActionBarPrimitive.Root>
63
+ * <ActionBarPrimitive.Copy />
64
+ * <ActionBarPrimitive.Edit />
65
+ * </ActionBarPrimitive.Root>
66
+ * </MessagePrimitive.Root>
67
+ * ```
68
+ */
47
69
  export const MessagePrimitiveRoot = forwardRef<
48
70
  MessagePrimitiveRoot.Element,
49
71
  MessagePrimitiveRoot.Props
@@ -8,25 +8,51 @@ import { ThreadMessage as ThreadMessageType } from "../../types";
8
8
 
9
9
  export namespace ThreadPrimitiveMessages {
10
10
  export type Props = {
11
+ /**
12
+ * Component configuration for rendering different types of messages and composers.
13
+ *
14
+ * You can provide either:
15
+ * 1. A single `Message` component that handles all message types
16
+ * 2. Specific components for `UserMessage` and `AssistantMessage` (with optional `SystemMessage`)
17
+ *
18
+ * Optional edit composer components can be provided to customize the editing experience
19
+ * for different message types when users edit their messages.
20
+ */
11
21
  components:
12
22
  | {
23
+ /** Component used to render all message types */
13
24
  Message: ComponentType;
25
+ /** Component used when editing any message type */
14
26
  EditComposer?: ComponentType | undefined;
27
+ /** Component used when editing user messages specifically */
15
28
  UserEditComposer?: ComponentType | undefined;
29
+ /** Component used when editing assistant messages specifically */
16
30
  AssistantEditComposer?: ComponentType | undefined;
31
+ /** Component used when editing system messages specifically */
17
32
  SystemEditComposer?: ComponentType | undefined;
33
+ /** Component used to render user messages specifically */
18
34
  UserMessage?: ComponentType | undefined;
35
+ /** Component used to render assistant messages specifically */
19
36
  AssistantMessage?: ComponentType | undefined;
37
+ /** Component used to render system messages specifically */
20
38
  SystemMessage?: ComponentType | undefined;
21
39
  }
22
40
  | {
41
+ /** Component used to render all message types (fallback) */
23
42
  Message?: ComponentType | undefined;
43
+ /** Component used when editing any message type */
24
44
  EditComposer?: ComponentType | undefined;
45
+ /** Component used when editing user messages specifically */
25
46
  UserEditComposer?: ComponentType | undefined;
47
+ /** Component used when editing assistant messages specifically */
26
48
  AssistantEditComposer?: ComponentType | undefined;
49
+ /** Component used when editing system messages specifically */
27
50
  SystemEditComposer?: ComponentType | undefined;
51
+ /** Component used to render user messages */
28
52
  UserMessage: ComponentType;
53
+ /** Component used to render assistant messages */
29
54
  AssistantMessage: ComponentType;
55
+ /** Component used to render system messages */
30
56
  SystemMessage?: ComponentType | undefined;
31
57
  };
32
58
  };
@@ -140,15 +166,37 @@ const ThreadMessage = memo(
140
166
  isComponentsSame(prev.components, next.components),
141
167
  );
142
168
 
169
+ /**
170
+ * Renders all messages in the current thread using the provided component configuration.
171
+ *
172
+ * This component automatically renders all messages in the thread, providing the appropriate
173
+ * message context for each message. It handles different message types (user, assistant, system)
174
+ * and supports editing mode through the provided edit composer components.
175
+ *
176
+ * @example
177
+ * ```tsx
178
+ * <ThreadPrimitive.Messages
179
+ * components={{
180
+ * UserMessage: MyUserMessage,
181
+ * AssistantMessage: MyAssistantMessage,
182
+ * EditComposer: MyEditComposer
183
+ * }}
184
+ * />
185
+ * ```
186
+ */
143
187
  export const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessages.Props> = ({
144
188
  components,
145
189
  }) => {
146
190
  const messagesLength = useThread((t) => t.messages.length);
147
- if (messagesLength === 0) return null;
148
191
 
149
- return Array.from({ length: messagesLength }, (_, index) => (
150
- <ThreadMessage key={index} messageIndex={index} components={components} />
151
- ));
192
+ const messageElements = useMemo(() => {
193
+ if (messagesLength === 0) return null;
194
+ return Array.from({ length: messagesLength }, (_, index) => (
195
+ <ThreadMessage key={index} messageIndex={index} components={components} />
196
+ ));
197
+ }, [messagesLength, components]);
198
+
199
+ return messageElements;
152
200
  };
153
201
 
154
202
  ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
@@ -5,9 +5,28 @@ import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
5
5
 
6
6
  export namespace ThreadPrimitiveRoot {
7
7
  export type Element = ComponentRef<typeof Primitive.div>;
8
+ /**
9
+ * Props for the ThreadPrimitive.Root component.
10
+ * Accepts all standard div element props.
11
+ */
8
12
  export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;
9
13
  }
10
14
 
15
+ /**
16
+ * The root container component for a thread.
17
+ *
18
+ * This component serves as the foundational wrapper for all thread-related components.
19
+ * It provides the basic structure and context needed for thread functionality.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * <ThreadPrimitive.Root>
24
+ * <ThreadPrimitive.Viewport>
25
+ * <ThreadPrimitive.Messages components={{ Message: MyMessage }} />
26
+ * </ThreadPrimitive.Viewport>
27
+ * </ThreadPrimitive.Root>
28
+ * ```
29
+ */
11
30
  export const ThreadPrimitiveRoot = forwardRef<
12
31
  ThreadPrimitiveRoot.Element,
13
32
  ThreadPrimitiveRoot.Props
@@ -9,6 +9,11 @@ import { ThreadViewportProvider } from "../../context/providers/ThreadViewportPr
9
9
  export namespace ThreadPrimitiveViewport {
10
10
  export type Element = ComponentRef<typeof Primitive.div>;
11
11
  export type Props = ComponentPropsWithoutRef<typeof Primitive.div> & {
12
+ /**
13
+ * Whether to automatically scroll to the bottom when new messages are added.
14
+ * When enabled, the viewport will automatically scroll to show the latest content.
15
+ * @default true
16
+ */
12
17
  autoScroll?: boolean | undefined;
13
18
  };
14
19
  }
@@ -33,6 +38,20 @@ const ThreadPrimitiveViewportScrollable = forwardRef<
33
38
  ThreadPrimitiveViewportScrollable.displayName =
34
39
  "ThreadPrimitive.ViewportScrollable";
35
40
 
41
+ /**
42
+ * A scrollable viewport container for thread messages.
43
+ *
44
+ * This component provides a scrollable area for displaying thread messages with
45
+ * automatic scrolling capabilities. It manages the viewport state and provides
46
+ * context for child components to access viewport-related functionality.
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * <ThreadPrimitive.Viewport autoScroll={true}>
51
+ * <ThreadPrimitive.Messages components={{ Message: MyMessage }} />
52
+ * </ThreadPrimitive.Viewport>
53
+ * ```
54
+ */
36
55
  export const ThreadPrimitiveViewport = forwardRef<
37
56
  ThreadPrimitiveViewport.Element,
38
57
  ThreadPrimitiveViewport.Props
@@ -58,14 +58,18 @@ export const ThreadListPrimitiveItems: FC<ThreadListPrimitiveItems.Props> = ({
58
58
  archived ? s.archivedThreads.length : s.threads.length,
59
59
  );
60
60
 
61
- return Array.from({ length: contentLength }, (_, index) => (
62
- <ThreadListItem
63
- key={index}
64
- partIndex={index}
65
- archived={archived}
66
- components={components}
67
- />
68
- ));
61
+ const listElements = useMemo(() => {
62
+ return Array.from({ length: contentLength }, (_, index) => (
63
+ <ThreadListItem
64
+ key={index}
65
+ partIndex={index}
66
+ archived={archived}
67
+ components={components}
68
+ />
69
+ ));
70
+ }, [contentLength, archived, components]);
71
+
72
+ return listElements;
69
73
  };
70
74
 
71
75
  ThreadListPrimitiveItems.displayName = "ThreadListPrimitive.Items";