@assistant-ui/core 0.2.21 → 0.2.23

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 (345) hide show
  1. package/dist/adapters/attachment.d.ts.map +1 -1
  2. package/dist/adapters/speech.d.ts.map +1 -1
  3. package/dist/adapters/speech.js +9 -2
  4. package/dist/adapters/speech.js.map +1 -1
  5. package/dist/adapters/thread-history.d.ts +8 -0
  6. package/dist/adapters/thread-history.d.ts.map +1 -1
  7. package/dist/adapters/voice.d.ts.map +1 -1
  8. package/dist/adapters/voice.js +13 -5
  9. package/dist/adapters/voice.js.map +1 -1
  10. package/dist/internal.d.ts +5 -2
  11. package/dist/internal.js +5 -2
  12. package/dist/model-context/frame/host.d.ts +1 -0
  13. package/dist/model-context/frame/host.d.ts.map +1 -1
  14. package/dist/model-context/frame/host.js +41 -21
  15. package/dist/model-context/frame/host.js.map +1 -1
  16. package/dist/model-context/frame/provider.d.ts.map +1 -1
  17. package/dist/model-context/frame/provider.js +1 -0
  18. package/dist/model-context/frame/provider.js.map +1 -1
  19. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  20. package/dist/model-context/types.d.ts.map +1 -1
  21. package/dist/model-context/types.js +13 -4
  22. package/dist/model-context/types.js.map +1 -1
  23. package/dist/react/AssistantProvider.js.map +1 -1
  24. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  25. package/dist/react/adapters/LocalStorageThreadListAdapter.js +78 -50
  26. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  27. package/dist/react/client/Interactables.js.map +1 -1
  28. package/dist/react/client/Tools.d.ts.map +1 -1
  29. package/dist/react/client/interactable-model-context.d.ts.map +1 -1
  30. package/dist/react/client/interactable-model-context.js +1 -0
  31. package/dist/react/client/interactable-model-context.js.map +1 -1
  32. package/dist/react/interactables-legacy/useInteractableState.js +1 -0
  33. package/dist/react/interactables-legacy/useInteractableState.js.map +1 -1
  34. package/dist/react/model-context/useInteractable.js.map +1 -1
  35. package/dist/react/model-context/useInteractableState.js +1 -0
  36. package/dist/react/model-context/useInteractableState.js.map +1 -1
  37. package/dist/react/model-context/useInteractableVersions.js +1 -0
  38. package/dist/react/model-context/useInteractableVersions.js.map +1 -1
  39. package/dist/react/model-context/useToolArgsStatus.js +1 -0
  40. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  41. package/dist/react/primitive-hooks/useActionBarCopy.js +14 -13
  42. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  43. package/dist/react/primitive-hooks/useActionBarEdit.js +1 -0
  44. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  45. package/dist/react/primitive-hooks/useActionBarFeedback.js +1 -0
  46. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  47. package/dist/react/primitive-hooks/useActionBarReload.js +1 -0
  48. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  49. package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -0
  50. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  51. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -0
  52. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  53. package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -0
  54. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  55. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -0
  56. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  57. package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -1
  58. package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -0
  59. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  60. package/dist/react/primitive-hooks/useComposerCancel.js +1 -0
  61. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  62. package/dist/react/primitive-hooks/useComposerDictate.js +1 -0
  63. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  64. package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
  65. package/dist/react/primitive-hooks/useComposerSend.js +1 -0
  66. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  67. package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -0
  68. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  69. package/dist/react/primitive-hooks/useEditComposerSend.js +1 -0
  70. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  71. package/dist/react/primitive-hooks/useMessageBranching.js +1 -0
  72. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  73. package/dist/react/primitive-hooks/useMessageReload.js +1 -0
  74. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  75. package/dist/react/primitive-hooks/useSuggestionTrigger.js +1 -0
  76. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  77. package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -0
  78. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  79. package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -0
  80. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  81. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -0
  82. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  83. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -0
  84. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  85. package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -0
  86. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  87. package/dist/react/primitive-hooks/useThreadListNew.js +1 -0
  88. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  89. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
  90. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
  91. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  92. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  93. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  94. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  95. package/dist/react/primitives/generativeUI/GenerativeUI.d.ts.map +1 -1
  96. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  97. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  98. package/dist/react/primitives/message/MessageParts.d.ts +2 -1
  99. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  100. package/dist/react/primitives/message/MessageParts.js +46 -36
  101. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  102. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  103. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  104. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  105. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  106. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
  107. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +18 -30
  108. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  109. package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
  110. package/dist/react/providers/PartByIndexProvider.js +18 -30
  111. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  112. package/dist/react/providers/TextMessagePartProvider.js +1 -0
  113. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  114. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  115. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -0
  116. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  117. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +9 -2
  118. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  119. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +55 -12
  120. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  121. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +31 -1
  122. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  123. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +12 -2
  124. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  125. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -1
  126. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  127. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -2
  128. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  129. package/dist/react/runtimes/cloud/auiV0.d.ts +12 -1
  130. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  131. package/dist/react/runtimes/cloud/auiV0.js +2 -1
  132. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  133. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +75 -73
  134. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  135. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  136. package/dist/react/runtimes/external-message-converter.js +2 -2
  137. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  138. package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -0
  139. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  140. package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
  141. package/dist/react/runtimes/useLocalRuntime.js +9 -1
  142. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  143. package/dist/runtime/api/assistant-runtime.d.ts +1 -1
  144. package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
  145. package/dist/runtime/api/assistant-runtime.js +1 -1
  146. package/dist/runtime/api/assistant-runtime.js.map +1 -1
  147. package/dist/runtime/api/attachment-runtime.d.ts +1 -1
  148. package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
  149. package/dist/runtime/api/attachment-runtime.js +1 -1
  150. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  151. package/dist/runtime/api/composer-runtime.d.ts +2 -2
  152. package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
  153. package/dist/runtime/api/composer-runtime.js +2 -2
  154. package/dist/runtime/api/composer-runtime.js.map +1 -1
  155. package/dist/runtime/api/message-part-runtime.d.ts +4 -4
  156. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  157. package/dist/runtime/api/message-part-runtime.js +3 -3
  158. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  159. package/dist/runtime/api/message-runtime.d.ts +1 -1
  160. package/dist/runtime/api/message-runtime.d.ts.map +1 -1
  161. package/dist/runtime/api/message-runtime.js +6 -6
  162. package/dist/runtime/api/message-runtime.js.map +1 -1
  163. package/dist/runtime/api/thread-list-item-runtime.d.ts +1 -1
  164. package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
  165. package/dist/runtime/api/thread-list-item-runtime.js +4 -3
  166. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  167. package/dist/runtime/api/thread-list-runtime.d.ts +1 -1
  168. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  169. package/dist/runtime/api/thread-list-runtime.js +1 -1
  170. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  171. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  172. package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -1
  173. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  174. package/dist/runtime/base/base-composer-runtime-core.js +41 -14
  175. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  176. package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -1
  177. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  178. package/dist/runtime/base/base-thread-runtime-core.js +3 -2
  179. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  180. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +2 -2
  181. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
  182. package/dist/runtime/base/default-edit-composer-runtime-core.js +6 -4
  183. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
  184. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
  185. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  186. package/dist/runtime/base/default-thread-composer-runtime-core.js +3 -3
  187. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  188. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  189. package/dist/runtime/utils/message-repository.js +4 -2
  190. package/dist/runtime/utils/message-repository.js.map +1 -1
  191. package/dist/runtime/utils/thread-message-like.js +4 -1
  192. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  193. package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -1
  194. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -1
  195. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  196. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +1 -1
  197. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  198. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  199. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +12 -0
  200. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  201. package/dist/runtimes/internal.d.ts +2 -1
  202. package/dist/runtimes/internal.js +2 -1
  203. package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -1
  204. package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -1
  205. package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
  206. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  207. package/dist/runtimes/local/local-thread-runtime-core.js +49 -15
  208. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  209. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  210. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +4 -4
  211. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
  212. package/dist/runtimes/remote-thread-list/optimistic-state.js +22 -9
  213. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  214. package/dist/runtimes/remote-thread-list/types.d.ts +1 -1
  215. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +32 -27
  216. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  217. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +3 -2
  218. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  219. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  220. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
  221. package/dist/store/clients/no-op-composer-client.js +1 -0
  222. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  223. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  224. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  225. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
  226. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  227. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  228. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  229. package/dist/store/runtime-clients/thread-list-runtime-client.js +1 -0
  230. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  231. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  232. package/dist/store/runtime-clients/thread-runtime-client.js +17 -15
  233. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  234. package/dist/store/scopes/thread.d.ts +1 -0
  235. package/dist/store/scopes/thread.d.ts.map +1 -1
  236. package/dist/subscribable/subscribable.d.ts +4 -4
  237. package/dist/subscribable/subscribable.d.ts.map +1 -1
  238. package/dist/subscribable/subscribable.js +14 -6
  239. package/dist/subscribable/subscribable.js.map +1 -1
  240. package/dist/tests/remote-thread-list-test-helpers.d.ts +2 -1
  241. package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
  242. package/dist/tests/remote-thread-list-test-helpers.js +5 -2
  243. package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
  244. package/dist/types/attachment.d.ts +2 -1
  245. package/dist/types/attachment.d.ts.map +1 -1
  246. package/dist/types/attachment.js +6 -0
  247. package/dist/types/attachment.js.map +1 -0
  248. package/dist/types/message.d.ts +1 -0
  249. package/dist/types/message.d.ts.map +1 -1
  250. package/dist/types/message.js.map +1 -1
  251. package/dist/utils/data-url.d.ts +9 -0
  252. package/dist/utils/data-url.d.ts.map +1 -0
  253. package/dist/utils/data-url.js +14 -0
  254. package/dist/utils/data-url.js.map +1 -0
  255. package/dist/utils/notify-event-listeners.d.ts +6 -0
  256. package/dist/utils/notify-event-listeners.d.ts.map +1 -0
  257. package/dist/utils/notify-event-listeners.js +16 -0
  258. package/dist/utils/notify-event-listeners.js.map +1 -0
  259. package/package.json +10 -9
  260. package/src/adapters/speech.test.ts +88 -0
  261. package/src/adapters/speech.ts +17 -2
  262. package/src/adapters/thread-history.ts +8 -0
  263. package/src/adapters/voice.test.ts +130 -0
  264. package/src/adapters/voice.ts +26 -6
  265. package/src/internal.ts +6 -1
  266. package/src/model-context/frame/host.test.ts +147 -0
  267. package/src/model-context/frame/host.ts +56 -19
  268. package/src/model-context/frame/provider.test.ts +83 -0
  269. package/src/model-context/frame/provider.ts +1 -0
  270. package/src/model-context/types.ts +16 -6
  271. package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +82 -0
  272. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +108 -58
  273. package/src/react/primitive-hooks/useActionBarCopy.test.ts +79 -0
  274. package/src/react/primitive-hooks/useActionBarCopy.ts +4 -3
  275. package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -3
  276. package/src/react/primitives/message/MessageParts.tsx +48 -35
  277. package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +19 -2
  278. package/src/react/providers/PartByIndexProvider.tsx +16 -2
  279. package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +18 -0
  280. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +1 -0
  281. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +68 -13
  282. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +34 -0
  283. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +69 -0
  284. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +27 -6
  285. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +16 -0
  286. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +7 -2
  287. package/src/react/runtimes/cloud/auiV0.ts +14 -0
  288. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +90 -88
  289. package/src/react/runtimes/external-message-converter.test.ts +346 -0
  290. package/src/react/runtimes/external-message-converter.test.tsx +21 -0
  291. package/src/react/runtimes/external-message-converter.ts +2 -2
  292. package/src/react/runtimes/useLocalRuntime.test.tsx +99 -0
  293. package/src/react/runtimes/useLocalRuntime.ts +13 -1
  294. package/src/runtime/api/assistant-runtime.ts +4 -1
  295. package/src/runtime/api/attachment-runtime.ts +8 -2
  296. package/src/runtime/api/composer-runtime.ts +9 -5
  297. package/src/runtime/api/message-part-runtime.ts +10 -3
  298. package/src/runtime/api/message-runtime.test.ts +81 -0
  299. package/src/runtime/api/message-runtime.ts +11 -8
  300. package/src/runtime/api/thread-list-item-runtime.ts +13 -3
  301. package/src/runtime/api/thread-list-runtime.ts +10 -2
  302. package/src/runtime/base/base-composer-runtime-core.ts +77 -31
  303. package/src/runtime/base/base-thread-runtime-core.ts +7 -2
  304. package/src/runtime/base/default-edit-composer-runtime-core.ts +18 -4
  305. package/src/runtime/base/default-thread-composer-runtime-core.ts +13 -3
  306. package/src/runtime/utils/message-repository.ts +19 -13
  307. package/src/runtime/utils/thread-message-like.ts +1 -0
  308. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
  309. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +15 -0
  310. package/src/runtimes/internal.ts +3 -0
  311. package/src/runtimes/local/local-thread-runtime-core.test.ts +746 -1
  312. package/src/runtimes/local/local-thread-runtime-core.ts +89 -23
  313. package/src/runtimes/local/should-continue.test.ts +122 -0
  314. package/src/runtimes/remote-thread-list/optimistic-state.test.ts +63 -0
  315. package/src/runtimes/remote-thread-list/optimistic-state.ts +49 -17
  316. package/src/runtimes/remote-thread-list/types.ts +1 -1
  317. package/src/runtimes/tool-invocations/EDGE_CASES.md +13 -19
  318. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +128 -8
  319. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +42 -34
  320. package/src/store/clients/model-context-client.test.ts +21 -1
  321. package/src/store/runtime-clients/thread-runtime-client.ts +2 -1
  322. package/src/store/scopes/thread.ts +1 -0
  323. package/src/subscribable/subscribable.test.ts +58 -0
  324. package/src/subscribable/subscribable.ts +29 -11
  325. package/src/tests/MessageRepository.test.ts +12 -0
  326. package/src/tests/OptimisticState-list-race.test.ts +33 -0
  327. package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +223 -0
  328. package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-position.test.ts +121 -0
  329. package/src/tests/auiV0Encode.test.ts +74 -0
  330. package/src/tests/base-composer-runtime-core-addAttachment.test.ts +44 -0
  331. package/src/tests/base-composer-runtime-core-send.test.ts +433 -5
  332. package/src/tests/base-composer-runtime-core.test.ts +422 -0
  333. package/src/tests/default-edit-composer-runtime-core.test.ts +43 -5
  334. package/src/tests/event-subscription-listener-errors.test.ts +205 -0
  335. package/src/tests/external-store-thread-list-runtime-core.test.ts +6 -6
  336. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +575 -0
  337. package/src/tests/external-store-thread-runtime-core.test.ts +55 -1
  338. package/src/tests/remote-thread-list-test-helpers.ts +14 -7
  339. package/src/tests/thread-message-like.test.ts +57 -0
  340. package/src/types/attachment.ts +5 -0
  341. package/src/types/message.ts +1 -0
  342. package/src/utils/data-url.test.ts +50 -0
  343. package/src/utils/data-url.ts +9 -0
  344. package/src/utils/notify-event-listeners.ts +30 -0
  345. package/src/tests/OptimisticState-delete-crash.test.ts +0 -208
@@ -76,94 +76,96 @@ export const useCloudThreadListAdapter = (
76
76
  );
77
77
 
78
78
  const cloud = adapter.cloud ?? autoCloud;
79
- if (!cloud) {
80
- const ref = adapterRef;
81
- const inMemory = new InMemoryThreadListAdapter();
82
- inMemory.initialize = async (threadId: string) => {
83
- const result = await ref.current.create?.();
84
- return { remoteId: threadId, externalId: result?.externalId };
85
- };
86
- return inMemory;
87
- }
88
-
89
- return {
90
- list: async () => {
91
- const { threads } = await cloud.threads.list();
92
- return {
93
- threads: threads.map((t) => ({
94
- status: t.is_archived ? "archived" : "regular",
95
- remoteId: t.id,
96
- title: t.title,
97
- lastMessageAt: t.last_message_at
98
- ? new Date(t.last_message_at)
99
- : undefined,
100
- externalId: t.external_id ?? undefined,
101
- custom: toCustom(t.metadata),
102
- })),
79
+ return useMemo<RemoteThreadListAdapter>(() => {
80
+ if (!cloud) {
81
+ const ref = adapterRef;
82
+ const inMemory = new InMemoryThreadListAdapter();
83
+ inMemory.initialize = async (threadId: string) => {
84
+ const result = await ref.current.create?.();
85
+ return { remoteId: threadId, externalId: result?.externalId };
103
86
  };
104
- },
105
-
106
- initialize: async () => {
107
- const createTask = adapter.create?.() ?? Promise.resolve();
108
- const t = await createTask;
109
- const external_id = t ? t.externalId : undefined;
110
- const { thread_id: remoteId } = await cloud.threads.create({
111
- last_message_at: new Date(),
112
- external_id,
113
- });
114
-
115
- return { externalId: external_id, remoteId: remoteId };
116
- },
117
-
118
- rename: async (threadId, newTitle) => {
119
- return cloud.threads.update(threadId, { title: newTitle });
120
- },
121
- updateCustom: async (threadId, custom) => {
122
- return cloud.threads.update(threadId, { metadata: custom ?? null });
123
- },
124
- archive: async (threadId) => {
125
- return cloud.threads.update(threadId, { is_archived: true });
126
- },
127
- unarchive: async (threadId) => {
128
- return cloud.threads.update(threadId, { is_archived: false });
129
- },
130
- delete: async (threadId) => {
131
- await adapter.delete?.(threadId);
132
- return cloud.threads.delete(threadId);
133
- },
134
-
135
- generateTitle: async (threadId, messages) => {
136
- // Filter messages to only include content types the title generator understands
137
- // (reasoning, source, etc. are not needed for title generation)
138
- // TODO serialize these to a more efficient format
139
- const filteredMessages = messages.map((msg) => ({
140
- ...msg,
141
- content: msg.content.filter(
142
- (part) => part.type === "text" || part.type === "tool-call",
143
- ),
144
- }));
145
-
146
- return cloud.runs.stream({
147
- thread_id: threadId,
148
- assistant_id: "system/thread_title",
149
- messages: filteredMessages,
150
- });
151
- },
152
-
153
- fetch: async (threadId: string) => {
154
- const thread = await cloud.threads.get(threadId);
155
- return {
156
- status: thread.is_archived ? "archived" : "regular",
157
- remoteId: thread.id,
158
- title: thread.title,
159
- lastMessageAt: thread.last_message_at
160
- ? new Date(thread.last_message_at)
161
- : undefined,
162
- externalId: thread.external_id ?? undefined,
163
- custom: toCustom(thread.metadata),
164
- };
165
- },
87
+ return inMemory;
88
+ }
89
+
90
+ return {
91
+ list: async () => {
92
+ const { threads } = await cloud.threads.list();
93
+ return {
94
+ threads: threads.map((t) => ({
95
+ status: t.is_archived ? "archived" : "regular",
96
+ remoteId: t.id,
97
+ title: t.title,
98
+ lastMessageAt: t.last_message_at
99
+ ? new Date(t.last_message_at)
100
+ : undefined,
101
+ externalId: t.external_id ?? undefined,
102
+ custom: toCustom(t.metadata),
103
+ })),
104
+ };
105
+ },
106
+
107
+ initialize: async () => {
108
+ const createTask = adapterRef.current.create?.() ?? Promise.resolve();
109
+ const t = await createTask;
110
+ const external_id = t ? t.externalId : undefined;
111
+ const { thread_id: remoteId } = await cloud.threads.create({
112
+ last_message_at: new Date(),
113
+ external_id,
114
+ });
115
+
116
+ return { externalId: external_id, remoteId: remoteId };
117
+ },
118
+
119
+ rename: async (threadId, newTitle) => {
120
+ return cloud.threads.update(threadId, { title: newTitle });
121
+ },
122
+ updateCustom: async (threadId, custom) => {
123
+ return cloud.threads.update(threadId, { metadata: custom ?? null });
124
+ },
125
+ archive: async (threadId) => {
126
+ return cloud.threads.update(threadId, { is_archived: true });
127
+ },
128
+ unarchive: async (threadId) => {
129
+ return cloud.threads.update(threadId, { is_archived: false });
130
+ },
131
+ delete: async (threadId) => {
132
+ await adapterRef.current.delete?.(threadId);
133
+ return cloud.threads.delete(threadId);
134
+ },
135
+
136
+ generateTitle: async (threadId, messages) => {
137
+ // Filter messages to only include content types the title generator understands
138
+ // (reasoning, source, etc. are not needed for title generation)
139
+ // TODO serialize these to a more efficient format
140
+ const filteredMessages = messages.map((msg) => ({
141
+ ...msg,
142
+ content: msg.content.filter(
143
+ (part) => part.type === "text" || part.type === "tool-call",
144
+ ),
145
+ }));
146
+
147
+ return cloud.runs.stream({
148
+ thread_id: threadId,
149
+ assistant_id: "system/thread_title",
150
+ messages: filteredMessages,
151
+ });
152
+ },
153
+
154
+ fetch: async (threadId: string) => {
155
+ const thread = await cloud.threads.get(threadId);
156
+ return {
157
+ status: thread.is_archived ? "archived" : "regular",
158
+ remoteId: thread.id,
159
+ title: thread.title,
160
+ lastMessageAt: thread.last_message_at
161
+ ? new Date(thread.last_message_at)
162
+ : undefined,
163
+ externalId: thread.external_id ?? undefined,
164
+ custom: toCustom(thread.metadata),
165
+ };
166
+ },
166
167
 
167
- unstable_Provider,
168
- };
168
+ unstable_Provider,
169
+ };
170
+ }, [cloud, unstable_Provider]);
169
171
  };
@@ -0,0 +1,346 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { convertExternalMessages } from "./external-message-converter";
3
+ import type { useExternalMessageConverter } from "./external-message-converter";
4
+ import { isErrorMessageId } from "../../utils/id";
5
+
6
+ describe("convertExternalMessages", () => {
7
+ describe("reasoning part merging", () => {
8
+ it("should merge reasoning parts with the same parentId", () => {
9
+ const messages = [
10
+ {
11
+ id: "msg1",
12
+ role: "assistant" as const,
13
+ content: [
14
+ {
15
+ type: "reasoning" as const,
16
+ text: "First reasoning",
17
+ parentId: "parent1",
18
+ },
19
+ ],
20
+ },
21
+ {
22
+ id: "msg2",
23
+ role: "assistant" as const,
24
+ content: [
25
+ {
26
+ type: "reasoning" as const,
27
+ text: "Second reasoning",
28
+ parentId: "parent1",
29
+ },
30
+ ],
31
+ },
32
+ ];
33
+
34
+ const callback: useExternalMessageConverter.Callback<
35
+ (typeof messages)[number]
36
+ > = (msg) => msg;
37
+
38
+ const result = convertExternalMessages(messages, callback, false, {});
39
+
40
+ expect(result).toHaveLength(1);
41
+ expect(result[0]!.role).toBe("assistant");
42
+
43
+ const reasoningParts = result[0]!.content.filter(
44
+ (p) => p.type === "reasoning",
45
+ );
46
+ expect(reasoningParts).toHaveLength(1);
47
+ expect((reasoningParts[0] as any).text).toBe(
48
+ "First reasoning\n\nSecond reasoning",
49
+ );
50
+ expect((reasoningParts[0] as any).parentId).toBe("parent1");
51
+ });
52
+
53
+ it("should keep reasoning parts without parentId separate", () => {
54
+ const messages = [
55
+ {
56
+ id: "msg1",
57
+ role: "assistant" as const,
58
+ content: [{ type: "reasoning" as const, text: "First reasoning" }],
59
+ },
60
+ {
61
+ id: "msg2",
62
+ role: "assistant" as const,
63
+ content: [{ type: "reasoning" as const, text: "Second reasoning" }],
64
+ },
65
+ ];
66
+
67
+ const callback: useExternalMessageConverter.Callback<
68
+ (typeof messages)[number]
69
+ > = (msg) => msg;
70
+
71
+ const result = convertExternalMessages(messages, callback, false, {});
72
+
73
+ expect(result).toHaveLength(1);
74
+
75
+ const reasoningParts = result[0]!.content.filter(
76
+ (p) => p.type === "reasoning",
77
+ );
78
+ expect(reasoningParts).toHaveLength(2);
79
+ expect((reasoningParts[0] as any).text).toBe("First reasoning");
80
+ expect((reasoningParts[1] as any).text).toBe("Second reasoning");
81
+ });
82
+
83
+ it("should keep reasoning parts with different parentIds separate", () => {
84
+ const messages = [
85
+ {
86
+ id: "msg1",
87
+ role: "assistant" as const,
88
+ content: [
89
+ {
90
+ type: "reasoning" as const,
91
+ text: "Reasoning for parent1",
92
+ parentId: "parent1",
93
+ },
94
+ ],
95
+ },
96
+ {
97
+ id: "msg2",
98
+ role: "assistant" as const,
99
+ content: [
100
+ {
101
+ type: "reasoning" as const,
102
+ text: "Reasoning for parent2",
103
+ parentId: "parent2",
104
+ },
105
+ ],
106
+ },
107
+ ];
108
+
109
+ const callback: useExternalMessageConverter.Callback<
110
+ (typeof messages)[number]
111
+ > = (msg) => msg;
112
+
113
+ const result = convertExternalMessages(messages, callback, false, {});
114
+
115
+ expect(result).toHaveLength(1);
116
+
117
+ const reasoningParts = result[0]!.content.filter(
118
+ (p) => p.type === "reasoning",
119
+ );
120
+ expect(reasoningParts).toHaveLength(2);
121
+ expect((reasoningParts[0] as any).parentId).toBe("parent1");
122
+ expect((reasoningParts[1] as any).parentId).toBe("parent2");
123
+ });
124
+
125
+ it("should still merge tool results with matching tool calls", () => {
126
+ const messages = [
127
+ {
128
+ id: "msg1",
129
+ role: "assistant" as const,
130
+ content: [
131
+ {
132
+ type: "tool-call" as const,
133
+ toolCallId: "tc1",
134
+ toolName: "search",
135
+ args: { query: "test" },
136
+ argsText: '{"query":"test"}',
137
+ },
138
+ ],
139
+ },
140
+ {
141
+ role: "tool" as const,
142
+ toolCallId: "tc1",
143
+ result: { data: "result" },
144
+ },
145
+ ];
146
+
147
+ const callback: useExternalMessageConverter.Callback<
148
+ (typeof messages)[number]
149
+ > = (msg) => msg;
150
+
151
+ const result = convertExternalMessages(messages, callback, false, {});
152
+
153
+ expect(result).toHaveLength(1);
154
+
155
+ const toolCallParts = result[0]!.content.filter(
156
+ (p) => p.type === "tool-call",
157
+ );
158
+ expect(toolCallParts).toHaveLength(1);
159
+ expect((toolCallParts[0] as any).result).toEqual({ data: "result" });
160
+ });
161
+
162
+ it("should merge duplicate tool calls by toolCallId across assistant messages", () => {
163
+ const messages = [
164
+ {
165
+ id: "msg1",
166
+ role: "assistant" as const,
167
+ content: [
168
+ {
169
+ type: "tool-call" as const,
170
+ toolCallId: "tc1",
171
+ toolName: "search",
172
+ args: { query: "old" },
173
+ argsText: '{"query":"old"',
174
+ },
175
+ ],
176
+ },
177
+ {
178
+ id: "msg2",
179
+ role: "assistant" as const,
180
+ content: [
181
+ {
182
+ type: "tool-call" as const,
183
+ toolCallId: "tc1",
184
+ toolName: "search",
185
+ args: { query: "new" },
186
+ argsText: '{"query":"new"}',
187
+ },
188
+ ],
189
+ },
190
+ ];
191
+
192
+ const callback: useExternalMessageConverter.Callback<
193
+ (typeof messages)[number]
194
+ > = (msg) => msg;
195
+
196
+ const result = convertExternalMessages(messages, callback, false, {});
197
+
198
+ expect(result).toHaveLength(1);
199
+ expect(result[0]!.role).toBe("assistant");
200
+ const toolCallParts = result[0]!.content.filter(
201
+ (p) => p.type === "tool-call",
202
+ );
203
+ expect(toolCallParts).toHaveLength(1);
204
+ expect((toolCallParts[0] as any).args).toEqual({ query: "new" });
205
+ expect((toolCallParts[0] as any).argsText).toBe('{"query":"new"}');
206
+ });
207
+
208
+ it("should ignore orphaned tool results without throwing", () => {
209
+ const messages = [
210
+ {
211
+ id: "msg1",
212
+ role: "assistant" as const,
213
+ content: "First response",
214
+ },
215
+ {
216
+ role: "tool" as const,
217
+ toolCallId: "missing-tool-call",
218
+ toolName: "search",
219
+ result: { data: "orphan result" },
220
+ },
221
+ {
222
+ id: "msg2",
223
+ role: "assistant" as const,
224
+ content: "Second response",
225
+ },
226
+ ];
227
+
228
+ const callback: useExternalMessageConverter.Callback<
229
+ (typeof messages)[number]
230
+ > = (msg) => msg;
231
+
232
+ const result = convertExternalMessages(messages, callback, false, {});
233
+ expect(result).toHaveLength(1);
234
+ expect(result[0]!.role).toBe("assistant");
235
+
236
+ const textParts = result[0]!.content.filter((p) => p.type === "text");
237
+ expect(textParts).toHaveLength(2);
238
+ expect((textParts[0] as any).text).toBe("First response");
239
+ expect((textParts[1] as any).text).toBe("Second response");
240
+ });
241
+ });
242
+
243
+ describe("synthetic error message", () => {
244
+ it("should create synthetic error message when error exists and no messages", () => {
245
+ const messages: never[] = [];
246
+ const callback: useExternalMessageConverter.Callback<never> = (msg) =>
247
+ msg;
248
+
249
+ const result = convertExternalMessages(messages, callback, false, {
250
+ error: "API key is missing",
251
+ });
252
+
253
+ expect(result).toHaveLength(1);
254
+ expect(result[0]!.role).toBe("assistant");
255
+ expect(result[0]!.content).toHaveLength(0);
256
+ expect(result[0]!.status).toEqual({
257
+ type: "incomplete",
258
+ reason: "error",
259
+ error: "API key is missing",
260
+ });
261
+ expect(isErrorMessageId(result[0]!.id)).toBe(true);
262
+ });
263
+
264
+ it("should create synthetic error message when error exists and last message is user", () => {
265
+ const messages = [
266
+ {
267
+ id: "user1",
268
+ role: "user" as const,
269
+ content: "Hello",
270
+ },
271
+ ];
272
+
273
+ const callback: useExternalMessageConverter.Callback<
274
+ (typeof messages)[number]
275
+ > = (msg) => msg;
276
+
277
+ const result = convertExternalMessages(messages, callback, false, {
278
+ error: { message: "Invalid API key" },
279
+ });
280
+
281
+ expect(result).toHaveLength(2);
282
+ expect(result[0]!.role).toBe("user");
283
+ expect(result[1]!.role).toBe("assistant");
284
+ expect(result[1]!.content).toHaveLength(0);
285
+ expect(result[1]!.status).toEqual({
286
+ type: "incomplete",
287
+ reason: "error",
288
+ error: { message: "Invalid API key" },
289
+ });
290
+ expect(isErrorMessageId(result[1]!.id)).toBe(true);
291
+ });
292
+
293
+ it("should not create synthetic error message when last message is assistant", () => {
294
+ const messages = [
295
+ {
296
+ id: "user1",
297
+ role: "user" as const,
298
+ content: "Hello",
299
+ },
300
+ {
301
+ id: "assistant1",
302
+ role: "assistant" as const,
303
+ content: "Hi there",
304
+ },
305
+ ];
306
+
307
+ const callback: useExternalMessageConverter.Callback<
308
+ (typeof messages)[number]
309
+ > = (msg) => msg;
310
+
311
+ const result = convertExternalMessages(messages, callback, false, {
312
+ error: "Connection error",
313
+ });
314
+
315
+ expect(result).toHaveLength(2);
316
+ expect(result[0]!.role).toBe("user");
317
+ expect(result[1]!.role).toBe("assistant");
318
+ expect(result[1]!.id).toBe("assistant1");
319
+ expect(result[1]!.status).toMatchObject({
320
+ type: "incomplete",
321
+ reason: "error",
322
+ error: "Connection error",
323
+ });
324
+ expect(isErrorMessageId(result[1]!.id)).toBe(false);
325
+ });
326
+
327
+ it("should not create synthetic message when no error", () => {
328
+ const messages = [
329
+ {
330
+ id: "user1",
331
+ role: "user" as const,
332
+ content: "Hello",
333
+ },
334
+ ];
335
+
336
+ const callback: useExternalMessageConverter.Callback<
337
+ (typeof messages)[number]
338
+ > = (msg) => msg;
339
+
340
+ const result = convertExternalMessages(messages, callback, false, {});
341
+
342
+ expect(result).toHaveLength(1);
343
+ expect(result[0]!.role).toBe("user");
344
+ });
345
+ });
346
+ });
@@ -99,4 +99,25 @@ describe("useExternalMessageConverter", () => {
99
99
  text: "HELLO",
100
100
  });
101
101
  });
102
+
103
+ it.each([
104
+ ["false", false],
105
+ ["zero", 0],
106
+ ["an empty string", ""],
107
+ ])("preserves %s assistant state", (_label, state) => {
108
+ const callback: useExternalMessageConverter.Callback<TestMessage> = (
109
+ message,
110
+ ) => ({
111
+ role: message.role,
112
+ id: message.id,
113
+ content: [{ type: "text", text: message.text }],
114
+ ...(message.role === "assistant"
115
+ ? { metadata: { unstable_state: state } }
116
+ : undefined),
117
+ });
118
+
119
+ const { result } = renderConverter({ callback });
120
+
121
+ expect(result.current[1]?.metadata.unstable_state).toBe(state);
122
+ });
102
123
  });
@@ -118,7 +118,7 @@ const joinExternalMessages = (
118
118
  const toolCall = assistantMessage.content[
119
119
  toolCallIdx
120
120
  ]! as ToolCallMessagePart;
121
- if (output.toolName !== undefined) {
121
+ if (output.toolName != null) {
122
122
  if (toolCall.toolName !== output.toolName)
123
123
  throw new Error(
124
124
  `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,
@@ -170,7 +170,7 @@ const joinExternalMessages = (
170
170
 
171
171
  if (output.metadata) {
172
172
  assistantMessage.metadata ??= {};
173
- if (output.metadata.unstable_state) {
173
+ if (output.metadata.unstable_state !== undefined) {
174
174
  assistantMessage.metadata.unstable_state =
175
175
  output.metadata.unstable_state;
176
176
  }
@@ -0,0 +1,99 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { render, waitFor } from "@testing-library/react";
4
+ import { StrictMode } from "react";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import type { AssistantCloud } from "assistant-cloud";
7
+ import type { ChatModelAdapter } from "../../runtime/utils/chat-model-adapter";
8
+ import { AssistantRuntimeProvider } from "../AssistantRuntimeProvider";
9
+ import { useLocalRuntime } from "./useLocalRuntime";
10
+
11
+ const chatModel: ChatModelAdapter = {
12
+ run: async () => ({ content: [] }),
13
+ };
14
+
15
+ const makeCloud = () =>
16
+ ({
17
+ threads: {
18
+ list: vi.fn().mockResolvedValue({ threads: [] }),
19
+ },
20
+ }) as unknown as AssistantCloud;
21
+
22
+ afterEach(() => {
23
+ vi.restoreAllMocks();
24
+ });
25
+
26
+ describe("useLocalRuntime", () => {
27
+ it("keeps the Cloud thread list loaded across unrelated rerenders", async () => {
28
+ const firstCloud = makeCloud();
29
+ const secondCloud = makeCloud();
30
+
31
+ const App = ({
32
+ cloud,
33
+ label,
34
+ }: {
35
+ cloud: AssistantCloud;
36
+ label: string;
37
+ }) => {
38
+ const runtime = useLocalRuntime(chatModel, { cloud });
39
+ return (
40
+ <AssistantRuntimeProvider runtime={runtime}>
41
+ <div>{label}</div>
42
+ </AssistantRuntimeProvider>
43
+ );
44
+ };
45
+
46
+ const { rerender } = render(<App cloud={firstCloud} label="first" />);
47
+
48
+ await waitFor(() => {
49
+ expect(firstCloud.threads.list).toHaveBeenCalledOnce();
50
+ });
51
+
52
+ rerender(<App cloud={firstCloud} label="second" />);
53
+ expect(firstCloud.threads.list).toHaveBeenCalledOnce();
54
+
55
+ rerender(<App cloud={secondCloud} label="third" />);
56
+ await waitFor(() => {
57
+ expect(secondCloud.threads.list).toHaveBeenCalledOnce();
58
+ });
59
+ expect(firstCloud.threads.list).toHaveBeenCalledOnce();
60
+ });
61
+
62
+ it("handles rejected history loads", async () => {
63
+ const error = new Error("history unavailable");
64
+ const consoleError = vi
65
+ .spyOn(console, "error")
66
+ .mockImplementation(() => {});
67
+ const history = {
68
+ load: vi.fn().mockRejectedValue(error),
69
+ append: vi.fn().mockResolvedValue(undefined),
70
+ };
71
+
72
+ const App = () => {
73
+ const runtime = useLocalRuntime(chatModel, { adapters: { history } });
74
+ return (
75
+ <AssistantRuntimeProvider runtime={runtime}>
76
+ <div />
77
+ </AssistantRuntimeProvider>
78
+ );
79
+ };
80
+
81
+ const renderApp = () => (
82
+ <StrictMode>
83
+ <App />
84
+ </StrictMode>
85
+ );
86
+ const { rerender } = render(renderApp());
87
+
88
+ await waitFor(() => {
89
+ expect(consoleError).toHaveBeenCalledWith(
90
+ "[assistant-ui] local thread history load failed:",
91
+ error,
92
+ );
93
+ });
94
+
95
+ rerender(renderApp());
96
+ expect(history.load).toHaveBeenCalledTimes(1);
97
+ expect(consoleError).toHaveBeenCalledTimes(1);
98
+ });
99
+ });