@assistant-ui/core 0.2.23 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/react/adapters/LocalStorageThreadListAdapter.js +2 -2
  2. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  3. package/dist/react/client/Tools.d.ts.map +1 -1
  4. package/dist/react/client/Tools.js +40 -55
  5. package/dist/react/client/Tools.js.map +1 -1
  6. package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
  7. package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
  8. package/dist/react/interactables-legacy/useInteractableState.js +3 -3
  9. package/dist/react/interactables-legacy/useInteractableState.js.map +1 -1
  10. package/dist/react/model-context/useAssistantContext.js +1 -1
  11. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  12. package/dist/react/model-context/useAssistantDataUI.js +1 -1
  13. package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
  14. package/dist/react/model-context/useAssistantInstructions.js +1 -1
  15. package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
  16. package/dist/react/model-context/useAssistantTool.js +29 -25
  17. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  18. package/dist/react/model-context/useAssistantToolUI.js +1 -1
  19. package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
  20. package/dist/react/model-context/useAuiToolOverrides.js +1 -1
  21. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  22. package/dist/react/model-context/useInteractable.d.ts.map +1 -1
  23. package/dist/react/model-context/useInteractable.js +3 -5
  24. package/dist/react/model-context/useInteractable.js.map +1 -1
  25. package/dist/react/model-context/useInteractableState.js +2 -2
  26. package/dist/react/model-context/useInteractableState.js.map +1 -1
  27. package/dist/react/primitive-hooks/useActionBarCopy.js +3 -3
  28. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  29. package/dist/react/primitive-hooks/useActionBarEdit.js +1 -1
  30. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  31. package/dist/react/primitive-hooks/useActionBarFeedback.js +2 -2
  32. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  33. package/dist/react/primitive-hooks/useActionBarReload.js +1 -1
  34. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  35. package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -1
  36. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  37. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -1
  38. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  39. package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -1
  40. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  41. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -1
  42. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  43. package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -1
  44. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  45. package/dist/react/primitive-hooks/useComposerCancel.js +1 -1
  46. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  47. package/dist/react/primitive-hooks/useComposerDictate.js +1 -1
  48. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  49. package/dist/react/primitive-hooks/useComposerSend.js +1 -1
  50. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  51. package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -1
  52. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  53. package/dist/react/primitive-hooks/useEditComposerSend.js +1 -1
  54. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  55. package/dist/react/primitive-hooks/useMessageBranching.js +2 -2
  56. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  57. package/dist/react/primitive-hooks/useMessageReload.js +1 -1
  58. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  59. package/dist/react/primitive-hooks/useSuggestionTrigger.js +7 -7
  60. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  61. package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -1
  62. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  63. package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -1
  64. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  65. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -1
  66. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  67. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -1
  68. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  69. package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -1
  70. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  71. package/dist/react/primitive-hooks/useThreadListNew.js +1 -1
  72. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  73. package/dist/react/primitive-hooks/useVoice.js +5 -13
  74. package/dist/react/primitive-hooks/useVoice.js.map +1 -1
  75. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
  76. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  77. package/dist/react/primitives/composer/ComposerAttachments.js +1 -1
  78. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  79. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  80. package/dist/react/primitives/composer/ComposerQueue.js +1 -1
  81. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  82. package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
  83. package/dist/react/primitives/message/MessageAttachments.js +1 -1
  84. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  85. package/dist/react/primitives/message/MessageParts.js +84 -122
  86. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  87. package/dist/react/primitives/thread/ThreadMessages.js +1 -1
  88. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  89. package/dist/react/primitives/thread/ThreadSuggestions.js +1 -1
  90. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  91. package/dist/react/primitives/threadList/ThreadListItems.js +1 -1
  92. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  93. package/dist/react/providers/AttachmentByIndexProvider.js +2 -2
  94. package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
  95. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
  96. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  97. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
  98. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +30 -18
  99. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  100. package/dist/react/providers/MessageByIdProvider.js +2 -2
  101. package/dist/react/providers/MessageByIdProvider.js.map +1 -1
  102. package/dist/react/providers/MessageByIndexProvider.js +2 -2
  103. package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
  104. package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
  105. package/dist/react/providers/PartByIndexProvider.js +30 -18
  106. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  107. package/dist/react/providers/QueueItemByIndexProvider.js +1 -1
  108. package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
  109. package/dist/react/providers/ReadonlyThreadProvider.js +1 -1
  110. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  111. package/dist/react/providers/SuggestionByIndexProvider.js +1 -1
  112. package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
  113. package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
  114. package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
  115. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +3 -3
  116. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  117. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  118. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +32 -20
  119. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  120. package/dist/react/runtimes/createRuntimeExtras.js +1 -1
  121. package/dist/react/runtimes/createRuntimeExtras.js.map +1 -1
  122. package/dist/react/types/scopes/tools.d.ts +0 -6
  123. package/dist/react/types/scopes/tools.d.ts.map +1 -1
  124. package/dist/react/utils/groupParts.d.ts +1 -3
  125. package/dist/react/utils/groupParts.d.ts.map +1 -1
  126. package/dist/react/utils/groupParts.js +1 -3
  127. package/dist/react/utils/groupParts.js.map +1 -1
  128. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  129. package/dist/runtimes/local/local-thread-runtime-core.js +4 -3
  130. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  131. package/dist/store/clients/runtime-adapter.js +3 -3
  132. package/dist/store/clients/runtime-adapter.js.map +1 -1
  133. package/package.json +5 -5
  134. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +2 -2
  135. package/src/react/client/Tools.ts +0 -7
  136. package/src/react/interactables-legacy/useAssistantInteractable.ts +1 -1
  137. package/src/react/interactables-legacy/useInteractableState.ts +3 -3
  138. package/src/react/model-context/useAssistantContext.ts +1 -1
  139. package/src/react/model-context/useAssistantDataUI.ts +1 -1
  140. package/src/react/model-context/useAssistantInstructions.ts +1 -1
  141. package/src/react/model-context/useAssistantTool.ts +2 -2
  142. package/src/react/model-context/useAssistantToolUI.ts +1 -1
  143. package/src/react/model-context/useAuiToolOverrides.ts +1 -1
  144. package/src/react/model-context/useInteractable.ts +3 -7
  145. package/src/react/model-context/useInteractableState.ts +2 -2
  146. package/src/react/primitive-hooks/useActionBarCopy.test.ts +2 -2
  147. package/src/react/primitive-hooks/useActionBarCopy.ts +3 -3
  148. package/src/react/primitive-hooks/useActionBarEdit.ts +1 -1
  149. package/src/react/primitive-hooks/useActionBarFeedback.ts +2 -2
  150. package/src/react/primitive-hooks/useActionBarReload.ts +1 -1
  151. package/src/react/primitive-hooks/useActionBarSpeak.ts +1 -1
  152. package/src/react/primitive-hooks/useActionBarStopSpeaking.ts +1 -1
  153. package/src/react/primitive-hooks/useBranchPickerNext.ts +1 -1
  154. package/src/react/primitive-hooks/useBranchPickerPrevious.ts +1 -1
  155. package/src/react/primitive-hooks/useComposerAddAttachment.ts +1 -1
  156. package/src/react/primitive-hooks/useComposerCancel.ts +1 -1
  157. package/src/react/primitive-hooks/useComposerDictate.ts +1 -1
  158. package/src/react/primitive-hooks/useComposerSend.ts +1 -1
  159. package/src/react/primitive-hooks/useEditComposerCancel.ts +1 -1
  160. package/src/react/primitive-hooks/useEditComposerSend.ts +1 -1
  161. package/src/react/primitive-hooks/useMessageBranching.ts +2 -2
  162. package/src/react/primitive-hooks/useMessageReload.ts +1 -1
  163. package/src/react/primitive-hooks/useSuggestionTrigger.ts +9 -9
  164. package/src/react/primitive-hooks/useThreadListItemArchive.ts +1 -1
  165. package/src/react/primitive-hooks/useThreadListItemDelete.ts +1 -1
  166. package/src/react/primitive-hooks/useThreadListItemTrigger.ts +1 -1
  167. package/src/react/primitive-hooks/useThreadListItemUnarchive.ts +1 -1
  168. package/src/react/primitive-hooks/useThreadListLoadMore.ts +1 -1
  169. package/src/react/primitive-hooks/useThreadListNew.ts +1 -1
  170. package/src/react/primitive-hooks/useVoice.ts +5 -5
  171. package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -1
  172. package/src/react/primitives/composer/ComposerAttachments.tsx +1 -1
  173. package/src/react/primitives/composer/ComposerQueue.tsx +1 -3
  174. package/src/react/primitives/message/MessageAttachments.tsx +1 -3
  175. package/src/react/primitives/message/MessageParts.tsx +9 -9
  176. package/src/react/primitives/thread/ThreadMessages.tsx +1 -1
  177. package/src/react/primitives/thread/ThreadSuggestions.tsx +1 -1
  178. package/src/react/primitives/threadList/ThreadListItems.tsx +1 -1
  179. package/src/react/providers/AttachmentByIndexProvider.tsx +2 -2
  180. package/src/react/providers/ChainOfThoughtByIndicesProvider.tsx +1 -1
  181. package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +2 -19
  182. package/src/react/providers/MessageByIdProvider.tsx +2 -2
  183. package/src/react/providers/MessageByIndexProvider.tsx +2 -2
  184. package/src/react/providers/PartByIndexProvider.tsx +2 -16
  185. package/src/react/providers/QueueItemByIndexProvider.tsx +1 -1
  186. package/src/react/providers/ReadonlyThreadProvider.tsx +1 -1
  187. package/src/react/providers/SuggestionByIndexProvider.tsx +1 -1
  188. package/src/react/providers/ThreadListItemByIndexProvider.tsx +1 -1
  189. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +3 -3
  190. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +32 -7
  191. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +26 -16
  192. package/src/react/runtimes/createRuntimeExtras.test.ts +1 -1
  193. package/src/react/runtimes/createRuntimeExtras.ts +1 -1
  194. package/src/react/types/scopes/tools.ts +0 -6
  195. package/src/react/utils/groupParts.ts +1 -7
  196. package/src/runtimes/local/local-thread-runtime-core.test.ts +38 -0
  197. package/src/runtimes/local/local-thread-runtime-core.ts +6 -3
  198. package/src/store/clients/runtime-adapter.ts +3 -3
  199. package/src/tests/groupParts.test.ts +3 -48
@@ -6,7 +6,7 @@ export const useEditComposerSend = () => {
6
6
  const disabled = useAuiState((s) => s.composer.isEmpty);
7
7
 
8
8
  const send = useCallback(() => {
9
- aui.composer().send();
9
+ aui.composer.send();
10
10
  }, [aui]);
11
11
 
12
12
  return { send, disabled };
@@ -7,11 +7,11 @@ export const useMessageBranching = () => {
7
7
  const branchCount = useAuiState((s) => s.message.branchCount);
8
8
 
9
9
  const goToPrev = useCallback(() => {
10
- aui.message().switchToBranch({ position: "previous" });
10
+ aui.message.switchToBranch({ position: "previous" });
11
11
  }, [aui]);
12
12
 
13
13
  const goToNext = useCallback(() => {
14
- aui.message().switchToBranch({ position: "next" });
14
+ aui.message.switchToBranch({ position: "next" });
15
15
  }, [aui]);
16
16
 
17
17
  return { branchNumber, branchCount, goToPrev, goToNext };
@@ -6,7 +6,7 @@ export const useMessageReload = () => {
6
6
  const canReload = useAuiState((s) => s.message.role === "assistant");
7
7
 
8
8
  const reload = useCallback(() => {
9
- aui.message().reload();
9
+ aui.message.reload();
10
10
  }, [aui]);
11
11
 
12
12
  return { reload, canReload };
@@ -17,24 +17,24 @@ export const useSuggestionTrigger = ({
17
17
  const resolvedSend = send ?? false;
18
18
 
19
19
  const trigger = useCallback(() => {
20
- const isRunning = aui.thread().getState().isRunning;
20
+ const isRunning = aui.thread.getState().isRunning;
21
21
 
22
22
  if (resolvedSend && !isRunning) {
23
- aui.thread().append({
23
+ aui.thread.append({
24
24
  content: [{ type: "text", text: prompt }],
25
- runConfig: aui.composer().getState().runConfig,
25
+ runConfig: aui.composer.getState().runConfig,
26
26
  });
27
27
  if (clearComposer) {
28
- aui.composer().setText("");
28
+ aui.composer.setText("");
29
29
  }
30
30
  } else {
31
31
  if (clearComposer) {
32
- aui.composer().setText(prompt);
32
+ aui.composer.setText(prompt);
33
33
  } else {
34
- const currentText = aui.composer().getState().text;
35
- aui
36
- .composer()
37
- .setText(currentText.trim() ? `${currentText} ${prompt}` : prompt);
34
+ const currentText = aui.composer.getState().text;
35
+ aui.composer.setText(
36
+ currentText.trim() ? `${currentText} ${prompt}` : prompt,
37
+ );
38
38
  }
39
39
  }
40
40
  }, [aui, resolvedSend, clearComposer, prompt]);
@@ -5,7 +5,7 @@ export const useThreadListItemArchive = () => {
5
5
  const aui = useAui();
6
6
 
7
7
  const archive = useCallback(() => {
8
- aui.threadListItem().archive();
8
+ aui.threadListItem.archive();
9
9
  }, [aui]);
10
10
 
11
11
  return { archive };
@@ -5,7 +5,7 @@ export const useThreadListItemDelete = () => {
5
5
  const aui = useAui();
6
6
 
7
7
  const deleteThread = useCallback(() => {
8
- aui.threadListItem().delete();
8
+ aui.threadListItem.delete();
9
9
  }, [aui]);
10
10
 
11
11
  return { delete: deleteThread };
@@ -5,7 +5,7 @@ export const useThreadListItemTrigger = () => {
5
5
  const aui = useAui();
6
6
 
7
7
  const switchTo = useCallback(() => {
8
- aui.threadListItem().switchTo();
8
+ aui.threadListItem.switchTo();
9
9
  }, [aui]);
10
10
 
11
11
  return { switchTo };
@@ -5,7 +5,7 @@ export const useThreadListItemUnarchive = () => {
5
5
  const aui = useAui();
6
6
 
7
7
  const unarchive = useCallback(() => {
8
- aui.threadListItem().unarchive();
8
+ aui.threadListItem.unarchive();
9
9
  }, [aui]);
10
10
 
11
11
  return { unarchive };
@@ -8,7 +8,7 @@ export const useThreadListLoadMore = () => {
8
8
  );
9
9
 
10
10
  const loadMore = useCallback(() => {
11
- aui.threads().loadMore();
11
+ aui.threads.loadMore();
12
12
  }, [aui]);
13
13
 
14
14
  return { loadMore, disabled };
@@ -5,7 +5,7 @@ export const useThreadListNew = () => {
5
5
  const aui = useAui();
6
6
 
7
7
  const switchToNewThread = useCallback(() => {
8
- aui.threads().switchToNewThread();
8
+ aui.threads.switchToNewThread();
9
9
  }, [aui]);
10
10
 
11
11
  return { switchToNewThread };
@@ -10,7 +10,7 @@ const getServerVolume = () => 0;
10
10
 
11
11
  export const useVoiceVolume = (): number => {
12
12
  const aui = useAui();
13
- const thread = aui.thread();
13
+ const thread = aui.thread;
14
14
  return useSyncExternalStore(
15
15
  thread.subscribeVoiceVolume,
16
16
  thread.getVoiceVolume,
@@ -22,19 +22,19 @@ export const useVoiceControls = () => {
22
22
  const aui = useAui();
23
23
 
24
24
  const connect = useCallback(() => {
25
- aui.thread().connectVoice();
25
+ aui.thread.connectVoice();
26
26
  }, [aui]);
27
27
 
28
28
  const disconnect = useCallback(() => {
29
- aui.thread().disconnectVoice();
29
+ aui.thread.disconnectVoice();
30
30
  }, [aui]);
31
31
 
32
32
  const mute = useCallback(() => {
33
- aui.thread().muteVoice();
33
+ aui.thread.muteVoice();
34
34
  }, [aui]);
35
35
 
36
36
  const unmute = useCallback(() => {
37
- aui.thread().unmuteVoice();
37
+ aui.thread.unmuteVoice();
38
38
  }, [aui]);
39
39
 
40
40
  return { connect, disconnect, mute, unmute };
@@ -51,7 +51,7 @@ const ChainOfThoughtPrimitivePartsInner: FC<{
51
51
  Array.from({ length: partsLength }, (_, index) => (
52
52
  <ChainOfThoughtPartByIndexProvider key={index} index={index}>
53
53
  <RenderChildrenWithAccessor
54
- getItemState={(aui) => aui.part().getState()}
54
+ getItemState={(aui) => aui.part.getState()}
55
55
  >
56
56
  {(getItem) =>
57
57
  children({
@@ -99,7 +99,7 @@ const ComposerPrimitiveAttachmentsInner: FC<{
99
99
  <ComposerAttachmentByIndexProvider key={index} index={index}>
100
100
  <RenderChildrenWithAccessor
101
101
  getItemState={(aui) =>
102
- aui.composer().attachment({ index }).getState()
102
+ aui.composer.attachment({ index }).getState()
103
103
  }
104
104
  >
105
105
  {(getItem) =>
@@ -20,9 +20,7 @@ const ComposerPrimitiveQueueInner: FC<{
20
20
  Array.from({ length: queue }, (_, index) => (
21
21
  <QueueItemByIndexProvider key={index} index={index}>
22
22
  <RenderChildrenWithAccessor
23
- getItemState={(aui) =>
24
- aui.composer().queueItem({ index }).getState()
25
- }
23
+ getItemState={(aui) => aui.composer.queueItem({ index }).getState()}
26
24
  >
27
25
  {(getItem) =>
28
26
  children({
@@ -101,9 +101,7 @@ const MessagePrimitiveAttachmentsInner: FC<{
101
101
  Array.from({ length: attachmentsCount }, (_, index) => (
102
102
  <MessageAttachmentByIndexProvider key={index} index={index}>
103
103
  <RenderChildrenWithAccessor
104
- getItemState={(aui) =>
105
- aui.message().attachment({ index }).getState()
106
- }
104
+ getItemState={(aui) => aui.message.attachment({ index }).getState()}
107
105
  >
108
106
  {(getItem) =>
109
107
  children({
@@ -415,9 +415,9 @@ export const MessagePartComponent: FC<MessagePartComponentProps> = ({
415
415
 
416
416
  const type = part.type;
417
417
  if (type === "tool-call") {
418
- const addResult = aui.part().addToolResult;
419
- const resume = aui.part().resumeToolCall;
420
- const respondToApproval = aui.part().respondToToolApproval;
418
+ const addResult = aui.part.addToolResult;
419
+ const resume = aui.part.resumeToolCall;
420
+ const respondToApproval = aui.part.respondToToolApproval;
421
421
  if ("Override" in tools)
422
422
  return (
423
423
  <tools.Override
@@ -636,9 +636,9 @@ const RegisteredToolUI: FC = () => {
636
636
  return (
637
637
  <Render
638
638
  {...part}
639
- addResult={aui.part().addToolResult}
640
- resume={aui.part().resumeToolCall}
641
- respondToApproval={aui.part().respondToToolApproval}
639
+ addResult={aui.part.addToolResult}
640
+ resume={aui.part.resumeToolCall}
641
+ respondToApproval={aui.part.respondToToolApproval}
642
642
  />
643
643
  );
644
644
  };
@@ -743,16 +743,16 @@ const MessagePartChildrenInner: FC<
743
743
 
744
744
  return (
745
745
  <RenderChildrenWithAccessor
746
- getItemState={(client) => client.part().getState()}
746
+ getItemState={(client) => client.part.getState()}
747
747
  >
748
748
  {(getItem) =>
749
749
  children({
750
750
  get part() {
751
751
  const state = getItem();
752
752
  if (state.type === "tool-call") {
753
- const toolsState = aui.tools().getState();
753
+ const toolsState = aui.tools.getState();
754
754
  const hasUI = resolveToolRender(toolsState, state) !== null;
755
- const partMethods = aui.part();
755
+ const partMethods = aui.part;
756
756
  return {
757
757
  ...state,
758
758
  toolUI: hasUI ? <RegisteredToolUI /> : null,
@@ -247,7 +247,7 @@ const ThreadPrimitiveMessagesInner: FC<{
247
247
  return Array.from({ length: messagesLength }, (_, index) => (
248
248
  <MessageByIndexProvider key={index} index={index}>
249
249
  <RenderChildrenWithAccessor
250
- getItemState={(aui) => aui.thread().message({ index }).getState()}
250
+ getItemState={(aui) => aui.thread.message({ index }).getState()}
251
251
  >
252
252
  {(getItem) =>
253
253
  children({
@@ -77,7 +77,7 @@ const ThreadPrimitiveSuggestionsInner: FC<{
77
77
  <SuggestionByIndexProvider key={index} index={index}>
78
78
  <RenderChildrenWithAccessor
79
79
  getItemState={(aui) =>
80
- aui.suggestions().suggestion({ index }).getState()
80
+ aui.suggestions.suggestion({ index }).getState()
81
81
  }
82
82
  >
83
83
  {(getItem) =>
@@ -78,7 +78,7 @@ const ThreadListPrimitiveItemsInner: FC<{
78
78
  >
79
79
  <RenderChildrenWithAccessor
80
80
  getItemState={(aui) =>
81
- aui.threads().item({ index, archived }).getState()
81
+ aui.threads.item({ index, archived }).getState()
82
82
  }
83
83
  >
84
84
  {(getItem) =>
@@ -10,7 +10,7 @@ export const MessageAttachmentByIndexProvider: FC<
10
10
  attachment: Derived({
11
11
  source: "message",
12
12
  query: { type: "index", index },
13
- get: (aui) => aui.message().attachment({ index }),
13
+ get: (aui) => aui.message.attachment({ index }),
14
14
  }),
15
15
  });
16
16
 
@@ -26,7 +26,7 @@ export const ComposerAttachmentByIndexProvider: FC<
26
26
  attachment: Derived({
27
27
  source: "composer",
28
28
  query: { type: "index", index },
29
- get: (aui) => aui.composer().attachment({ index }),
29
+ get: (aui) => aui.composer.attachment({ index }),
30
30
  }),
31
31
  });
32
32
 
@@ -25,7 +25,7 @@ export const ChainOfThoughtByIndicesProvider: FC<
25
25
  `ChainOfThought part index ${index} is out of bounds (0..${parts.length - 1})`,
26
26
  );
27
27
  }
28
- return parentAui.message().part({ index: startIndex + index });
28
+ return parentAui.message.part({ index: startIndex + index });
29
29
  },
30
30
  }),
31
31
  });
@@ -1,33 +1,16 @@
1
- import { useMemo, type FC, type PropsWithChildren } from "react";
1
+ import type { FC, PropsWithChildren } from "react";
2
2
  import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
3
- import type { PartMethods } from "../../store/scopes/part";
4
3
 
5
4
  export const ChainOfThoughtPartByIndexProvider: FC<
6
5
  PropsWithChildren<{
7
6
  index: number;
8
7
  }>
9
8
  > = ({ index, children }) => {
10
- const lastPartRef = useMemo(
11
- () => ({ index, current: null as PartMethods | null }),
12
- [index],
13
- );
14
9
  const aui = useAui({
15
10
  part: Derived({
16
11
  source: "chainOfThought",
17
12
  query: { type: "index", index },
18
- get: (aui) => {
19
- const chainOfThought = aui.chainOfThought();
20
- if (
21
- index >= chainOfThought.getState().parts.length &&
22
- lastPartRef.current
23
- ) {
24
- return lastPartRef.current;
25
- }
26
-
27
- const part = chainOfThought.part({ index });
28
- lastPartRef.current = part;
29
- return part;
30
- },
13
+ get: (aui) => aui.chainOfThought.part({ index }),
31
14
  }),
32
15
  });
33
16
 
@@ -10,12 +10,12 @@ export const MessageByIdProvider: FC<
10
10
  message: Derived({
11
11
  source: "thread",
12
12
  query: { type: "id", id },
13
- get: (aui) => aui.thread().message({ id }),
13
+ get: (aui) => aui.thread.message({ id }),
14
14
  }),
15
15
  composer: Derived({
16
16
  source: "message",
17
17
  query: {},
18
- get: (aui) => aui.thread().message({ id }).composer(),
18
+ get: (aui) => aui.thread.message({ id }).composer(),
19
19
  }),
20
20
  });
21
21
 
@@ -10,12 +10,12 @@ export const MessageByIndexProvider: FC<
10
10
  message: Derived({
11
11
  source: "thread",
12
12
  query: { type: "index", index },
13
- get: (aui) => aui.thread().message({ index }),
13
+ get: (aui) => aui.thread.message({ index }),
14
14
  }),
15
15
  composer: Derived({
16
16
  source: "message",
17
17
  query: {},
18
- get: (aui) => aui.thread().message({ index }).composer(),
18
+ get: (aui) => aui.thread.message({ index }).composer(),
19
19
  }),
20
20
  });
21
21
 
@@ -1,30 +1,16 @@
1
- import { useMemo, type FC, type PropsWithChildren } from "react";
1
+ import type { FC, PropsWithChildren } from "react";
2
2
  import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
3
- import type { PartMethods } from "../../store/scopes/part";
4
3
 
5
4
  export const PartByIndexProvider: FC<
6
5
  PropsWithChildren<{
7
6
  index: number;
8
7
  }>
9
8
  > = ({ index, children }) => {
10
- const lastPartRef = useMemo(
11
- () => ({ index, current: null as PartMethods | null }),
12
- [index],
13
- );
14
9
  const aui = useAui({
15
10
  part: Derived({
16
11
  source: "message",
17
12
  query: { type: "index", index },
18
- get: (aui) => {
19
- const message = aui.message();
20
- if (index >= message.getState().parts.length && lastPartRef.current) {
21
- return lastPartRef.current;
22
- }
23
-
24
- const part = message.part({ index });
25
- lastPartRef.current = part;
26
- return part;
27
- },
13
+ get: (aui) => aui.message.part({ index }),
28
14
  }),
29
15
  });
30
16
 
@@ -13,7 +13,7 @@ export const QueueItemByIndexProvider: FC<QueueItemByIndexProviderProps> = ({
13
13
  queueItem: Derived({
14
14
  source: "composer",
15
15
  query: { index },
16
- get: (aui) => aui.composer().queueItem({ index }),
16
+ get: (aui) => aui.composer.queueItem({ index }),
17
17
  }),
18
18
  });
19
19
 
@@ -76,7 +76,7 @@ export const ReadonlyThreadProvider: FC<ReadonlyThreadProvider.Props> = ({
76
76
  composer: Derived({
77
77
  source: "thread",
78
78
  query: {},
79
- get: (aui) => aui.thread().composer(),
79
+ get: (aui) => aui.thread.composer(),
80
80
  }),
81
81
  });
82
82
 
@@ -13,7 +13,7 @@ export const SuggestionByIndexProvider: FC<SuggestionByIndexProviderProps> = ({
13
13
  suggestion: Derived({
14
14
  source: "suggestions",
15
15
  query: { index },
16
- get: (aui) => aui.suggestions().suggestion({ index }),
16
+ get: (aui) => aui.suggestions.suggestion({ index }),
17
17
  }),
18
18
  });
19
19
 
@@ -11,7 +11,7 @@ export const ThreadListItemByIndexProvider: FC<
11
11
  threadListItem: Derived({
12
12
  source: "threads",
13
13
  query: { type: "index", index, archived },
14
- get: (aui) => aui.threads().item({ index, archived }),
14
+ get: (aui) => aui.threads.item({ index, archived }),
15
15
  }),
16
16
  });
17
17
 
@@ -147,15 +147,15 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
147
147
  return runtime.threads.main.unstable_on("initialize", () => {
148
148
  if (hasInitializedRef.current) return;
149
149
 
150
- const state = aui.threadListItem().getState();
150
+ const state = aui.threadListItem.getState();
151
151
  if (state.status !== "new") return;
152
152
  hasInitializedRef.current = true;
153
153
 
154
- initPromiseRef.current = aui.threadListItem().initialize();
154
+ initPromiseRef.current = aui.threadListItem.initialize();
155
155
 
156
156
  const dispose = runtime.thread.unstable_on("runEnd", () => {
157
157
  dispose();
158
- aui.threadListItem().generateTitle();
158
+ aui.threadListItem.generateTitle();
159
159
  });
160
160
  });
161
161
  }, [runtime, aui]);
@@ -6,20 +6,22 @@ import { describe, expect, it, vi } from "vitest";
6
6
  import { useAssistantCloudThreadHistoryAdapter } from "./AssistantCloudThreadHistoryAdapter";
7
7
 
8
8
  const mocks = vi.hoisted(() => {
9
- const threadListItem = {
10
- getState: () => ({ remoteId: "thread-1" }),
11
- };
9
+ const makeClient = (remoteId: string) =>
10
+ ({
11
+ threadListItem: {
12
+ getState: () => ({ remoteId }),
13
+ },
14
+ }) as unknown as import("@assistant-ui/store").AssistantClient;
12
15
 
13
16
  return {
14
- assistantClient: {
15
- threadListItem: () => threadListItem,
16
- },
17
+ makeClient,
18
+ aui: makeClient("thread-1"),
17
19
  };
18
20
  });
19
21
 
20
22
  vi.mock("@assistant-ui/store", async (importOriginal) => ({
21
23
  ...(await importOriginal<typeof import("@assistant-ui/store")>()),
22
- useAui: () => mocks.assistantClient,
24
+ useAui: () => mocks.aui,
23
25
  }));
24
26
 
25
27
  const makeCloud = () =>
@@ -33,6 +35,7 @@ const makeCloud = () =>
33
35
 
34
36
  describe("useAssistantCloudThreadHistoryAdapter", () => {
35
37
  it("refreshes formatted persistence when the Cloud client changes", async () => {
38
+ mocks.aui = mocks.makeClient("thread-1");
36
39
  const firstCloud = makeCloud();
37
40
  const secondCloud = makeCloud();
38
41
  const cloudRef = { current: firstCloud };
@@ -66,4 +69,26 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
66
69
  format: "test",
67
70
  });
68
71
  });
72
+
73
+ it("resolves the aui client at call time instead of capturing it", async () => {
74
+ mocks.aui = mocks.makeClient("thread-1");
75
+ const cloud = makeCloud();
76
+ const cloudRef = { current: cloud };
77
+ const { result, rerender } = renderHook(() =>
78
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
79
+ );
80
+
81
+ await result.current.load();
82
+ expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
83
+ format: "aui/v0",
84
+ });
85
+
86
+ mocks.aui = mocks.makeClient("thread-2");
87
+ rerender();
88
+
89
+ await result.current.load();
90
+ expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-2", {
91
+ format: "aui/v0",
92
+ });
93
+ });
69
94
  });
@@ -1,4 +1,4 @@
1
- import { type RefObject, useState } from "react";
1
+ import { type RefObject, useEffect, useRef, useState } from "react";
2
2
  import type {
3
3
  GenericThreadHistoryAdapter,
4
4
  ThreadHistoryAdapter,
@@ -13,25 +13,31 @@ import {
13
13
  createFormattedPersistence,
14
14
  } from "assistant-cloud";
15
15
  import { auiV0Decode, auiV0Encode } from "./auiV0";
16
- import { type AssistantClient, useAui } from "@assistant-ui/store";
17
- import type { ThreadListItemMethods } from "../../../store/scopes/thread-list-item";
16
+ import { type AssistantClient, getClientId, useAui } from "@assistant-ui/store";
18
17
 
19
18
  const globalPersistence = new WeakMap<
20
- ThreadListItemMethods,
19
+ getClientId.ClientId,
21
20
  CloudMessagePersistence
22
21
  >();
23
22
 
24
23
  class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
25
24
  private cloudRef: RefObject<AssistantCloud>;
26
- private aui: AssistantClient;
25
+ private auiRef: RefObject<AssistantClient>;
27
26
 
28
- constructor(cloudRef: RefObject<AssistantCloud>, aui: AssistantClient) {
27
+ constructor(
28
+ cloudRef: RefObject<AssistantCloud>,
29
+ auiRef: RefObject<AssistantClient>,
30
+ ) {
29
31
  this.cloudRef = cloudRef;
30
- this.aui = aui;
32
+ this.auiRef = auiRef;
33
+ }
34
+
35
+ private get aui(): AssistantClient {
36
+ return this.auiRef.current;
31
37
  }
32
38
 
33
39
  private get _persistence(): CloudMessagePersistence {
34
- const key = this.aui.threadListItem();
40
+ const key = getClientId(this.aui.threadListItem);
35
41
  if (!globalPersistence.has(key)) {
36
42
  globalPersistence.set(
37
43
  key,
@@ -52,11 +58,11 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
52
58
  return {
53
59
  // Note: callers must also call reportTelemetry() for run tracking
54
60
  async append(item: MessageFormatItem<TMessage>) {
55
- const { remoteId } = await adapter.aui.threadListItem().initialize();
61
+ const { remoteId } = await adapter.aui.threadListItem.initialize();
56
62
  await formatted.append(remoteId, item);
57
63
  },
58
64
  async update(item: MessageFormatItem<TMessage>, localMessageId: string) {
59
- const remoteId = adapter.aui.threadListItem().getState().remoteId;
65
+ const remoteId = adapter.aui.threadListItem.getState().remoteId;
60
66
  if (!remoteId) return;
61
67
  await formatted.update?.(remoteId, item, localMessageId);
62
68
  },
@@ -82,7 +88,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
82
88
  );
83
89
  },
84
90
  async load(): Promise<MessageFormatRepository<TMessage>> {
85
- const remoteId = adapter.aui.threadListItem().getState().remoteId;
91
+ const remoteId = adapter.aui.threadListItem.getState().remoteId;
86
92
  if (!remoteId) return { messages: [] };
87
93
  return formatted.load(remoteId);
88
94
  },
@@ -90,7 +96,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
90
96
  }
91
97
 
92
98
  async append({ parentId, message }: ExportedMessageRepositoryItem) {
93
- const { remoteId } = await this.aui.threadListItem().initialize();
99
+ const { remoteId } = await this.aui.threadListItem.initialize();
94
100
  const encoded = auiV0Encode(message);
95
101
  await this._persistence.append(
96
102
  remoteId,
@@ -110,7 +116,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
110
116
  return this.append(item);
111
117
  }
112
118
  const { message } = item;
113
- const remoteId = this.aui.threadListItem().getState().remoteId;
119
+ const remoteId = this.aui.threadListItem.getState().remoteId;
114
120
  if (!remoteId) return;
115
121
  const encoded = auiV0Encode(message);
116
122
  await this._persistence.update(remoteId, message.id, "aui/v0", encoded);
@@ -127,7 +133,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
127
133
  }
128
134
 
129
135
  async load() {
130
- const remoteId = this.aui.threadListItem().getState().remoteId;
136
+ const remoteId = this.aui.threadListItem.getState().remoteId;
131
137
  if (!remoteId) return { messages: [] };
132
138
  const messages = await this._persistence.load(remoteId, "aui/v0");
133
139
  return {
@@ -150,7 +156,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
150
156
  ) {
151
157
  if (!this.cloudRef.current.telemetry.enabled) return;
152
158
 
153
- const remoteId = this.aui.threadListItem().getState().remoteId;
159
+ const remoteId = this.aui.threadListItem.getState().remoteId;
154
160
  if (!remoteId) return;
155
161
 
156
162
  const extracted = extractRunTelemetry(format, runMessages);
@@ -810,8 +816,12 @@ export function useAssistantCloudThreadHistoryAdapter(
810
816
  cloudRef: RefObject<AssistantCloud>,
811
817
  ): ThreadHistoryAdapter {
812
818
  const aui = useAui();
819
+ const auiRef = useRef(aui);
820
+ useEffect(() => {
821
+ auiRef.current = aui;
822
+ });
813
823
  const [adapter] = useState(
814
- () => new AssistantCloudThreadHistoryAdapter(cloudRef, aui),
824
+ () => new AssistantCloudThreadHistoryAdapter(cloudRef, auiRef),
815
825
  );
816
826
  return adapter;
817
827
  }