@assistant-ui/react 0.10.42 → 0.10.43

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 (46) hide show
  1. package/dist/primitives/composer/ComposerAttachments.d.ts +24 -0
  2. package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  3. package/dist/primitives/composer/ComposerAttachments.js +14 -13
  4. package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
  5. package/dist/primitives/composer/index.d.ts +1 -0
  6. package/dist/primitives/composer/index.d.ts.map +1 -1
  7. package/dist/primitives/composer/index.js +2 -0
  8. package/dist/primitives/composer/index.js.map +1 -1
  9. package/dist/primitives/message/MessageAttachments.d.ts +24 -0
  10. package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
  11. package/dist/primitives/message/MessageAttachments.js +14 -13
  12. package/dist/primitives/message/MessageAttachments.js.map +1 -1
  13. package/dist/primitives/message/MessageParts.d.ts +24 -0
  14. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  15. package/dist/primitives/message/MessageParts.js +16 -15
  16. package/dist/primitives/message/MessageParts.js.map +1 -1
  17. package/dist/primitives/message/index.d.ts +2 -0
  18. package/dist/primitives/message/index.d.ts.map +1 -1
  19. package/dist/primitives/message/index.js +4 -0
  20. package/dist/primitives/message/index.js.map +1 -1
  21. package/dist/primitives/thread/ThreadMessages.d.ts +24 -0
  22. package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
  23. package/dist/primitives/thread/ThreadMessages.js +20 -15
  24. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  25. package/dist/primitives/thread/index.d.ts +1 -0
  26. package/dist/primitives/thread/index.d.ts.map +1 -1
  27. package/dist/primitives/thread/index.js +2 -0
  28. package/dist/primitives/thread/index.js.map +1 -1
  29. package/dist/primitives/threadList/ThreadListItems.d.ts +24 -0
  30. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  31. package/dist/primitives/threadList/ThreadListItems.js +15 -18
  32. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  33. package/dist/primitives/threadList/index.d.ts +1 -0
  34. package/dist/primitives/threadList/index.d.ts.map +1 -1
  35. package/dist/primitives/threadList/index.js +2 -0
  36. package/dist/primitives/threadList/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/primitives/composer/ComposerAttachments.tsx +48 -24
  39. package/src/primitives/composer/index.ts +1 -0
  40. package/src/primitives/message/MessageAttachments.tsx +48 -24
  41. package/src/primitives/message/MessageParts.tsx +53 -33
  42. package/src/primitives/message/index.ts +2 -0
  43. package/src/primitives/thread/ThreadMessages.tsx +47 -27
  44. package/src/primitives/thread/index.ts +1 -0
  45. package/src/primitives/threadList/ThreadListItems.tsx +48 -33
  46. package/src/primitives/threadList/index.ts +1 -0
@@ -136,35 +136,51 @@ const ThreadMessageComponent: FC<ThreadMessageComponentProps> = ({
136
136
 
137
137
  return <Component />;
138
138
  };
139
+ export namespace ThreadPrimitiveMessageByIndex {
140
+ export type Props = {
141
+ index: number;
142
+ components: ThreadPrimitiveMessages.Props["components"];
143
+ };
144
+ }
139
145
 
140
- type ThreadMessageProps = {
141
- messageIndex: number;
142
- components: ThreadPrimitiveMessages.Props["components"];
143
- };
144
-
145
- const ThreadMessageImpl: FC<ThreadMessageProps> = ({
146
- messageIndex,
147
- components,
148
- }) => {
149
- const threadRuntime = useThreadRuntime();
150
- const runtime = useMemo(
151
- () => threadRuntime.getMesssageByIndex(messageIndex),
152
- [threadRuntime, messageIndex],
153
- );
154
-
155
- return (
156
- <MessageRuntimeProvider runtime={runtime}>
157
- <ThreadMessageComponent components={components} />
158
- </MessageRuntimeProvider>
146
+ /**
147
+ * Renders a single message at the specified index in the current thread.
148
+ *
149
+ * This component provides message context for a specific message in the thread
150
+ * and renders it using the provided component configuration.
151
+ *
152
+ * @example
153
+ * ```tsx
154
+ * <ThreadPrimitive.MessageByIndex
155
+ * index={0}
156
+ * components={{
157
+ * UserMessage: MyUserMessage,
158
+ * AssistantMessage: MyAssistantMessage
159
+ * }}
160
+ * />
161
+ * ```
162
+ */
163
+ export const ThreadPrimitiveMessageByIndex: FC<ThreadPrimitiveMessageByIndex.Props> =
164
+ memo(
165
+ ({ index, components }) => {
166
+ const threadRuntime = useThreadRuntime();
167
+ const runtime = useMemo(
168
+ () => threadRuntime.getMesssageByIndex(index),
169
+ [threadRuntime, index],
170
+ );
171
+
172
+ return (
173
+ <MessageRuntimeProvider runtime={runtime}>
174
+ <ThreadMessageComponent components={components} />
175
+ </MessageRuntimeProvider>
176
+ );
177
+ },
178
+ (prev, next) =>
179
+ prev.index === next.index &&
180
+ isComponentsSame(prev.components, next.components),
159
181
  );
160
- };
161
182
 
162
- const ThreadMessage = memo(
163
- ThreadMessageImpl,
164
- (prev, next) =>
165
- prev.messageIndex === next.messageIndex &&
166
- isComponentsSame(prev.components, next.components),
167
- );
183
+ ThreadPrimitiveMessageByIndex.displayName = "ThreadPrimitive.MessageByIndex";
168
184
 
169
185
  /**
170
186
  * Renders all messages in the current thread using the provided component configuration.
@@ -192,7 +208,11 @@ export const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessages.Props> = ({
192
208
  const messageElements = useMemo(() => {
193
209
  if (messagesLength === 0) return null;
194
210
  return Array.from({ length: messagesLength }, (_, index) => (
195
- <ThreadMessage key={index} messageIndex={index} components={components} />
211
+ <ThreadPrimitiveMessageByIndex
212
+ key={index}
213
+ index={index}
214
+ components={components}
215
+ />
196
216
  ));
197
217
  }, [messagesLength, components]);
198
218
 
@@ -3,5 +3,6 @@ export { ThreadPrimitiveEmpty as Empty } from "./ThreadEmpty";
3
3
  export { ThreadPrimitiveIf as If } from "./ThreadIf";
4
4
  export { ThreadPrimitiveViewport as Viewport } from "./ThreadViewport";
5
5
  export { ThreadPrimitiveMessages as Messages } from "./ThreadMessages";
6
+ export { ThreadPrimitiveMessageByIndex as MessageByIndex } from "./ThreadMessages";
6
7
  export { ThreadPrimitiveScrollToBottom as ScrollToBottom } from "./ThreadScrollToBottom";
7
8
  export { ThreadPrimitiveSuggestion as Suggestion } from "./ThreadSuggestion";
@@ -13,42 +13,57 @@ export namespace ThreadListPrimitiveItems {
13
13
  };
14
14
  }
15
15
 
16
- type ThreadListItemProps = {
17
- partIndex: number;
18
- archived: boolean;
19
- components: ThreadListPrimitiveItems.Props["components"];
20
- };
16
+ export namespace ThreadListPrimitiveItemByIndex {
17
+ export type Props = {
18
+ index: number;
19
+ archived?: boolean | undefined;
20
+ components: ThreadListPrimitiveItems.Props["components"];
21
+ };
22
+ }
21
23
 
22
- const ThreadListItemImpl: FC<ThreadListItemProps> = ({
23
- partIndex,
24
- archived,
25
- components,
26
- }) => {
27
- const assistantRuntime = useAssistantRuntime();
28
- const runtime = useMemo(
29
- () =>
30
- archived
31
- ? assistantRuntime.threads.getArchivedItemByIndex(partIndex)
32
- : assistantRuntime.threads.getItemByIndex(partIndex),
33
- [assistantRuntime, partIndex, archived],
34
- );
24
+ /**
25
+ * Renders a single thread list item at the specified index.
26
+ *
27
+ * This component provides direct access to render a specific thread
28
+ * from the thread list using the provided component configuration.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * <ThreadListPrimitive.ItemByIndex
33
+ * index={0}
34
+ * components={{
35
+ * ThreadListItem: MyThreadListItem
36
+ * }}
37
+ * />
38
+ * ```
39
+ */
40
+ export const ThreadListPrimitiveItemByIndex: FC<ThreadListPrimitiveItemByIndex.Props> =
41
+ memo(
42
+ ({ index, archived = false, components }) => {
43
+ const assistantRuntime = useAssistantRuntime();
44
+ const runtime = useMemo(
45
+ () =>
46
+ archived
47
+ ? assistantRuntime.threads.getArchivedItemByIndex(index)
48
+ : assistantRuntime.threads.getItemByIndex(index),
49
+ [assistantRuntime, index, archived],
50
+ );
35
51
 
36
- const ThreadListItemComponent = components.ThreadListItem;
52
+ const ThreadListItemComponent = components.ThreadListItem;
37
53
 
38
- return (
39
- <ThreadListItemRuntimeProvider runtime={runtime}>
40
- <ThreadListItemComponent />
41
- </ThreadListItemRuntimeProvider>
54
+ return (
55
+ <ThreadListItemRuntimeProvider runtime={runtime}>
56
+ <ThreadListItemComponent />
57
+ </ThreadListItemRuntimeProvider>
58
+ );
59
+ },
60
+ (prev, next) =>
61
+ prev.index === next.index &&
62
+ prev.archived === next.archived &&
63
+ prev.components.ThreadListItem === next.components.ThreadListItem,
42
64
  );
43
- };
44
65
 
45
- const ThreadListItem = memo(
46
- ThreadListItemImpl,
47
- (prev, next) =>
48
- prev.partIndex === next.partIndex &&
49
- prev.archived === next.archived &&
50
- prev.components.ThreadListItem === next.components.ThreadListItem,
51
- );
66
+ ThreadListPrimitiveItemByIndex.displayName = "ThreadListPrimitive.ItemByIndex";
52
67
 
53
68
  export const ThreadListPrimitiveItems: FC<ThreadListPrimitiveItems.Props> = ({
54
69
  archived = false,
@@ -60,9 +75,9 @@ export const ThreadListPrimitiveItems: FC<ThreadListPrimitiveItems.Props> = ({
60
75
 
61
76
  const listElements = useMemo(() => {
62
77
  return Array.from({ length: contentLength }, (_, index) => (
63
- <ThreadListItem
78
+ <ThreadListPrimitiveItemByIndex
64
79
  key={index}
65
- partIndex={index}
80
+ index={index}
66
81
  archived={archived}
67
82
  components={components}
68
83
  />
@@ -1,3 +1,4 @@
1
1
  export { ThreadListPrimitiveNew as New } from "./ThreadListNew";
2
2
  export { ThreadListPrimitiveItems as Items } from "./ThreadListItems";
3
+ export { ThreadListPrimitiveItemByIndex as ItemByIndex } from "./ThreadListItems";
3
4
  export { ThreadListPrimitiveRoot as Root } from "./ThreadListRoot";