@assistant-ui/core 0.3.17 → 0.3.19

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 (470) hide show
  1. package/dist/adapters/attachment.d.ts.map +1 -1
  2. package/dist/adapters/attachment.js +5 -4
  3. package/dist/adapters/attachment.js.map +1 -1
  4. package/dist/adapters/speech.d.ts.map +1 -1
  5. package/dist/adapters/speech.js +13 -3
  6. package/dist/adapters/speech.js.map +1 -1
  7. package/dist/adapters/thread-history.d.ts +4 -0
  8. package/dist/adapters/thread-history.d.ts.map +1 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal.d.ts +4 -3
  12. package/dist/internal.js +3 -2
  13. package/dist/model-context/frame/host.d.ts.map +1 -1
  14. package/dist/model-context/frame/host.js +35 -14
  15. package/dist/model-context/frame/host.js.map +1 -1
  16. package/dist/model-context/frame/provider.d.ts +2 -0
  17. package/dist/model-context/frame/provider.d.ts.map +1 -1
  18. package/dist/model-context/frame/provider.js +30 -7
  19. package/dist/model-context/frame/provider.js.map +1 -1
  20. package/dist/model-context/interactable-composer-metadata.d.ts.map +1 -1
  21. package/dist/model-context/interactable-composer-metadata.js +27 -18
  22. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  23. package/dist/model-context/registry.d.ts.map +1 -1
  24. package/dist/model-context/registry.js +3 -5
  25. package/dist/model-context/registry.js.map +1 -1
  26. package/dist/model-context/types.d.ts.map +1 -1
  27. package/dist/model-context/types.js +5 -4
  28. package/dist/model-context/types.js.map +1 -1
  29. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  30. package/dist/react/adapters/LocalStorageThreadListAdapter.js +45 -7
  31. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  32. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  33. package/dist/react/client/DataRenderers.js +20 -15
  34. package/dist/react/client/DataRenderers.js.map +1 -1
  35. package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
  36. package/dist/react/client/InMemoryThreadList.js +62 -56
  37. package/dist/react/client/InMemoryThreadList.js.map +1 -1
  38. package/dist/react/client/Interactables.d.ts.map +1 -1
  39. package/dist/react/client/Interactables.js +35 -32
  40. package/dist/react/client/Interactables.js.map +1 -1
  41. package/dist/react/client/RemoteThreadList.d.ts +1 -0
  42. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  43. package/dist/react/client/RemoteThreadList.js +154 -143
  44. package/dist/react/client/RemoteThreadList.js.map +1 -1
  45. package/dist/react/client/Tools.d.ts.map +1 -1
  46. package/dist/react/client/Tools.js +18 -16
  47. package/dist/react/client/Tools.js.map +1 -1
  48. package/dist/react/client/interactable-model-context.d.ts.map +1 -1
  49. package/dist/react/client/interactable-model-context.js +3 -2
  50. package/dist/react/client/interactable-model-context.js.map +1 -1
  51. package/dist/react/index.d.ts +2 -2
  52. package/dist/react/index.js +2 -2
  53. package/dist/react/interactables-legacy/Interactables.js +242 -121
  54. package/dist/react/interactables-legacy/Interactables.js.map +1 -1
  55. package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -1
  56. package/dist/react/interactables-legacy/useAssistantInteractable.js +3 -0
  57. package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
  58. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -1
  59. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +11 -9
  60. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -1
  61. package/dist/react/model-context/makeAssistantTool.d.ts +2 -2
  62. package/dist/react/model-context/makeAssistantTool.js +1 -1
  63. package/dist/react/model-context/makeAssistantTool.js.map +1 -1
  64. package/dist/react/model-context/useAssistantTool.d.ts +2 -2
  65. package/dist/react/model-context/useAssistantTool.js +1 -1
  66. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  67. package/dist/react/model-context/useInteractable.d.ts.map +1 -1
  68. package/dist/react/model-context/useInteractable.js +4 -1
  69. package/dist/react/model-context/useInteractable.js.map +1 -1
  70. package/dist/react/model-context/useInteractableVersions.js +1 -1
  71. package/dist/react/model-context/useToolArgsStatus.d.ts.map +1 -1
  72. package/dist/react/model-context/useToolArgsStatus.js +2 -1
  73. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  74. package/dist/react/primitives/message/MessageGroupedParts.d.ts +11 -2
  75. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  76. package/dist/react/primitives/message/MessageGroupedParts.js +3 -2
  77. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  78. package/dist/react/primitives/part/PartMessages.d.ts +1 -0
  79. package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
  80. package/dist/react/primitives/part/PartMessages.js +1 -0
  81. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  82. package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
  83. package/dist/react/primitives/thread/ThreadMessages.js +6 -5
  84. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  85. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  86. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +16 -8
  87. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  88. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +5 -1
  89. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  90. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +105 -104
  91. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  92. package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -0
  93. package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
  94. package/dist/react/runtimes/RemoteThreadResource.js +13 -11
  95. package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
  96. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +5 -24
  97. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  98. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +354 -226
  99. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  100. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -0
  101. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  102. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +22 -2
  103. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  104. package/dist/react/runtimes/cloud/auiV0.d.ts +40 -15
  105. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  106. package/dist/react/runtimes/cloud/auiV0.js +62 -15
  107. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  108. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +2 -1
  109. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -1
  110. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +6 -1
  111. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -1
  112. package/dist/react/runtimes/cloud/sdkIdentity.d.ts +6 -0
  113. package/dist/react/runtimes/cloud/sdkIdentity.d.ts.map +1 -0
  114. package/dist/react/runtimes/cloud/sdkIdentity.js +9 -0
  115. package/dist/react/runtimes/cloud/sdkIdentity.js.map +1 -0
  116. package/dist/react/runtimes/external-message-converter.d.ts +12 -2
  117. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  118. package/dist/react/runtimes/external-message-converter.js +26 -61
  119. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  120. package/dist/react/runtimes/useExternalStoreRuntime.js +75 -46
  121. package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
  122. package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
  123. package/dist/react/runtimes/useRemoteThreadListRuntime.js +64 -24
  124. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  125. package/dist/react/utils/groupParts.d.ts +6 -1
  126. package/dist/react/utils/groupParts.d.ts.map +1 -1
  127. package/dist/react/utils/groupParts.js +6 -0
  128. package/dist/react/utils/groupParts.js.map +1 -1
  129. package/dist/react/utils/useJSONEqual.d.ts +3 -1
  130. package/dist/react/utils/useJSONEqual.d.ts.map +1 -1
  131. package/dist/react/utils/useJSONEqual.js +6 -1
  132. package/dist/react/utils/useJSONEqual.js.map +1 -1
  133. package/dist/react/utils/useJSONSchemaDependency.d.ts +7 -0
  134. package/dist/react/utils/useJSONSchemaDependency.d.ts.map +1 -0
  135. package/dist/react/utils/useJSONSchemaDependency.js +20 -0
  136. package/dist/react/utils/useJSONSchemaDependency.js.map +1 -0
  137. package/dist/runtime/api/thread-list-item-runtime.d.ts +7 -3
  138. package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
  139. package/dist/runtime/api/thread-list-item-runtime.js +2 -2
  140. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  141. package/dist/runtime/api/thread-list-runtime.d.ts +3 -0
  142. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  143. package/dist/runtime/api/thread-list-runtime.js +18 -14
  144. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  145. package/dist/runtime/api/thread-runtime.d.ts +4 -0
  146. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  147. package/dist/runtime/api/thread-runtime.js +3 -6
  148. package/dist/runtime/api/thread-runtime.js.map +1 -1
  149. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -0
  150. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  151. package/dist/runtime/base/base-composer-runtime-core.js +62 -22
  152. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  153. package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -0
  154. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  155. package/dist/runtime/base/base-thread-runtime-core.js +161 -69
  156. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  157. package/dist/runtime/interfaces/composer-runtime-core.d.ts +12 -5
  158. package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
  159. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +4 -1
  160. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  161. package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
  162. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  163. package/dist/runtime/queue/message-queue.d.ts +5 -0
  164. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  165. package/dist/runtime/queue/message-queue.js +61 -6
  166. package/dist/runtime/queue/message-queue.js.map +1 -1
  167. package/dist/runtime/utils/auto-status.d.ts +6 -2
  168. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  169. package/dist/runtime/utils/auto-status.js +12 -4
  170. package/dist/runtime/utils/auto-status.js.map +1 -1
  171. package/dist/runtime/utils/external-message-conversion.d.ts +16 -4
  172. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
  173. package/dist/runtime/utils/external-message-conversion.js +49 -13
  174. package/dist/runtime/utils/external-message-conversion.js.map +1 -1
  175. package/dist/runtime/utils/message-repository.d.ts +1 -0
  176. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  177. package/dist/runtime/utils/message-repository.js +18 -9
  178. package/dist/runtime/utils/message-repository.js.map +1 -1
  179. package/dist/runtime/utils/thread-message-like.d.ts +2 -1
  180. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  181. package/dist/runtime/utils/thread-message-like.js +5 -3
  182. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  183. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  184. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +21 -27
  185. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  186. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  187. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +8 -1
  188. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  189. package/dist/runtimes/internal.d.ts +3 -3
  190. package/dist/runtimes/internal.js +2 -2
  191. package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
  192. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  193. package/dist/runtimes/local/local-thread-runtime-core.js +4 -1
  194. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  195. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +18 -1
  196. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  197. package/dist/runtimes/remote-thread-list/remote-thread-state.js +130 -42
  198. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  199. package/dist/runtimes/remote-thread-list/title-generation.d.ts +49 -0
  200. package/dist/runtimes/remote-thread-list/title-generation.d.ts.map +1 -0
  201. package/dist/runtimes/remote-thread-list/title-generation.js +197 -0
  202. package/dist/runtimes/remote-thread-list/title-generation.js.map +1 -0
  203. package/dist/runtimes/remote-thread-list/title.d.ts +3 -1
  204. package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -1
  205. package/dist/runtimes/remote-thread-list/title.js +9 -1
  206. package/dist/runtimes/remote-thread-list/title.js.map +1 -1
  207. package/dist/runtimes/remote-thread-list/types.d.ts +10 -0
  208. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  209. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  210. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -1
  211. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  212. package/dist/store/clients/external-thread.d.ts.map +1 -1
  213. package/dist/store/clients/external-thread.js +260 -203
  214. package/dist/store/clients/external-thread.js.map +1 -1
  215. package/dist/store/clients/model-context-client.d.ts.map +1 -1
  216. package/dist/store/clients/model-context-client.js +2 -1
  217. package/dist/store/clients/model-context-client.js.map +1 -1
  218. package/dist/store/clients/single-thread-list.d.ts.map +1 -1
  219. package/dist/store/clients/single-thread-list.js +1 -0
  220. package/dist/store/clients/single-thread-list.js.map +1 -1
  221. package/dist/store/clients/suggestions.d.ts.map +1 -1
  222. package/dist/store/clients/suggestions.js +5 -4
  223. package/dist/store/clients/suggestions.js.map +1 -1
  224. package/dist/store/clients/thread-tasks.d.ts +13 -0
  225. package/dist/store/clients/thread-tasks.d.ts.map +1 -0
  226. package/dist/store/clients/thread-tasks.js +69 -0
  227. package/dist/store/clients/thread-tasks.js.map +1 -0
  228. package/dist/store/index.d.ts +3 -2
  229. package/dist/store/index.js +3 -3
  230. package/dist/store/primitive-predicates.d.ts.map +1 -1
  231. package/dist/store/primitive-predicates.js +4 -4
  232. package/dist/store/primitive-predicates.js.map +1 -1
  233. package/dist/store/runtime-clients/composer-runtime-client.d.ts +1 -0
  234. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  235. package/dist/store/runtime-clients/composer-runtime-client.js +97 -61
  236. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
  237. package/dist/store/runtime-clients/message-runtime-client.d.ts +1 -0
  238. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  239. package/dist/store/runtime-clients/message-runtime-client.js +221 -144
  240. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
  241. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  242. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
  243. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  244. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  245. package/dist/store/runtime-clients/thread-list-runtime-client.js +54 -52
  246. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  247. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  248. package/dist/store/runtime-clients/thread-runtime-client.js +246 -126
  249. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  250. package/dist/store/scope-registration.d.ts +2 -0
  251. package/dist/store/scope-registration.d.ts.map +1 -1
  252. package/dist/store/scopes/composer.d.ts +10 -2
  253. package/dist/store/scopes/composer.d.ts.map +1 -1
  254. package/dist/store/scopes/message.d.ts +30 -1
  255. package/dist/store/scopes/message.d.ts.map +1 -1
  256. package/dist/store/scopes/task.d.ts +36 -0
  257. package/dist/store/scopes/task.d.ts.map +1 -0
  258. package/dist/store/scopes/task.js +0 -0
  259. package/dist/store/scopes/thread-list-item.d.ts +2 -2
  260. package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
  261. package/dist/store/scopes/thread.d.ts +28 -0
  262. package/dist/store/scopes/thread.d.ts.map +1 -1
  263. package/dist/store/scopes/threads.d.ts +1 -0
  264. package/dist/store/scopes/threads.d.ts.map +1 -1
  265. package/dist/subscribable/subscribable.d.ts +2 -1
  266. package/dist/subscribable/subscribable.d.ts.map +1 -1
  267. package/dist/subscribable/subscribable.js +23 -15
  268. package/dist/subscribable/subscribable.js.map +1 -1
  269. package/dist/types/attachment.d.ts +2 -1
  270. package/dist/types/attachment.d.ts.map +1 -1
  271. package/dist/types/attachment.js +2 -1
  272. package/dist/types/attachment.js.map +1 -1
  273. package/dist/types/index.d.ts +2 -2
  274. package/dist/types/message.d.ts +8 -1
  275. package/dist/types/message.d.ts.map +1 -1
  276. package/dist/types/message.js.map +1 -1
  277. package/dist/utils/abortable-iterable.d.ts +19 -0
  278. package/dist/utils/abortable-iterable.d.ts.map +1 -0
  279. package/dist/utils/abortable-iterable.js +88 -0
  280. package/dist/utils/abortable-iterable.js.map +1 -0
  281. package/dist/utils/composite-context-provider.d.ts.map +1 -1
  282. package/dist/utils/composite-context-provider.js +20 -2
  283. package/dist/utils/composite-context-provider.js.map +1 -1
  284. package/dist/utils/getGroupStatus.d.ts +18 -2
  285. package/dist/utils/getGroupStatus.d.ts.map +1 -1
  286. package/dist/utils/getGroupStatus.js +32 -7
  287. package/dist/utils/getGroupStatus.js.map +1 -1
  288. package/dist/utils/record.d.ts +11 -0
  289. package/dist/utils/record.d.ts.map +1 -0
  290. package/dist/utils/record.js +12 -0
  291. package/dist/utils/record.js.map +1 -0
  292. package/dist/utils/wire-media.d.ts.map +1 -1
  293. package/dist/utils/wire-media.js +2 -2
  294. package/dist/utils/wire-media.js.map +1 -1
  295. package/package.json +11 -11
  296. package/src/adapters/attachment.test.ts +50 -1
  297. package/src/adapters/attachment.ts +7 -4
  298. package/src/adapters/speech.test.ts +236 -0
  299. package/src/adapters/speech.ts +17 -10
  300. package/src/adapters/thread-history.ts +3 -0
  301. package/src/index.ts +2 -0
  302. package/src/internal.ts +4 -0
  303. package/src/model-context/frame/host.test.ts +137 -1
  304. package/src/model-context/frame/host.ts +49 -16
  305. package/src/model-context/frame/provider.test.ts +71 -0
  306. package/src/model-context/frame/provider.ts +37 -7
  307. package/src/model-context/interactable-composer-metadata.test.ts +58 -0
  308. package/src/model-context/interactable-composer-metadata.ts +19 -13
  309. package/src/model-context/registry.test.ts +12 -0
  310. package/src/model-context/registry.ts +3 -2
  311. package/src/model-context/types.test.ts +25 -0
  312. package/src/model-context/types.ts +9 -4
  313. package/src/react/RuntimeAdapter.test.ts +34 -0
  314. package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +244 -0
  315. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +104 -7
  316. package/src/react/client/DataRenderers.test.tsx +45 -0
  317. package/src/react/client/DataRenderers.ts +13 -9
  318. package/src/react/client/InMemoryThreadList.ts +1 -0
  319. package/src/react/client/Interactables.test.ts +72 -1
  320. package/src/react/client/Interactables.ts +22 -14
  321. package/src/react/client/RemoteThreadList.background.test.ts +148 -6
  322. package/src/react/client/RemoteThreadList.concurrent.test.tsx +42 -1
  323. package/src/react/client/RemoteThreadList.test.ts +386 -4
  324. package/src/react/client/RemoteThreadList.ts +181 -112
  325. package/src/react/client/Tools.ts +22 -11
  326. package/src/react/client/interactable-model-context.test.ts +44 -0
  327. package/src/react/client/interactable-model-context.ts +3 -2
  328. package/src/react/index.ts +5 -1
  329. package/src/react/interactables-legacy/Interactables.ts +16 -16
  330. package/src/react/interactables-legacy/useAssistantInteractable.test.tsx +132 -0
  331. package/src/react/interactables-legacy/useAssistantInteractable.ts +10 -1
  332. package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +9 -10
  333. package/src/react/model-context/makeAssistantTool.ts +2 -2
  334. package/src/react/model-context/useAssistantTool.ts +2 -2
  335. package/src/react/model-context/useInteractable.test.tsx +177 -0
  336. package/src/react/model-context/useInteractable.ts +3 -0
  337. package/src/react/model-context/useToolArgsStatus.test.tsx +30 -0
  338. package/src/react/model-context/useToolArgsStatus.ts +2 -1
  339. package/src/react/primitive-hooks/useActionBarCopy.test.ts +0 -1
  340. package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +0 -1
  341. package/src/react/primitives/message/MessageGroupedParts.test.tsx +96 -0
  342. package/src/react/primitives/message/MessageGroupedParts.tsx +15 -4
  343. package/src/react/primitives/part/PartMessages.test.tsx +104 -1
  344. package/src/react/primitives/part/PartMessages.tsx +1 -0
  345. package/src/react/primitives/thread/ThreadMessages.test.tsx +142 -0
  346. package/src/react/primitives/thread/ThreadMessages.tsx +8 -5
  347. package/src/react/providers/ReadonlyThreadProvider.test.tsx +56 -0
  348. package/src/react/runtimes/RemoteThreadListHookInstanceManager.destroy.test.tsx +172 -0
  349. package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +33 -0
  350. package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +7 -1
  351. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +28 -5
  352. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.load-error.test.ts +132 -0
  353. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +105 -0
  354. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +143 -112
  355. package/src/react/runtimes/RemoteThreadResource.test.ts +9 -0
  356. package/src/react/runtimes/RemoteThreadResource.ts +19 -12
  357. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +20 -14
  358. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +703 -6
  359. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +492 -402
  360. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +77 -0
  361. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +27 -1
  362. package/src/react/runtimes/cloud/auiV0.ts +160 -25
  363. package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +36 -0
  364. package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +8 -1
  365. package/src/react/runtimes/cloud/sdkIdentity.ts +9 -0
  366. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +18 -4
  367. package/src/react/runtimes/external-message-converter.test.ts +136 -1
  368. package/src/react/runtimes/external-message-converter.ts +39 -93
  369. package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +41 -0
  370. package/src/react/runtimes/useExternalStoreRuntime.ts +10 -4
  371. package/src/react/runtimes/useLocalRuntime.test.tsx +20 -0
  372. package/src/react/runtimes/useRemoteThreadListRuntime.load-error.test.tsx +108 -0
  373. package/src/react/runtimes/useRemoteThreadListRuntime.ts +34 -1
  374. package/src/react/utils/groupParts.ts +12 -1
  375. package/src/react/utils/useJSONEqual.ts +9 -0
  376. package/src/react/utils/useJSONSchemaDependency.ts +22 -0
  377. package/src/runtime/api/message-runtime.test.ts +75 -0
  378. package/src/runtime/api/thread-list-item-runtime.ts +10 -3
  379. package/src/runtime/api/thread-list-runtime.ts +21 -11
  380. package/src/runtime/api/thread-runtime.test.ts +136 -0
  381. package/src/runtime/api/thread-runtime.ts +10 -5
  382. package/src/runtime/base/base-composer-runtime-core.ts +105 -24
  383. package/src/runtime/base/base-thread-runtime-core.test.ts +1063 -2
  384. package/src/runtime/base/base-thread-runtime-core.ts +228 -87
  385. package/src/runtime/interfaces/composer-runtime-core.ts +10 -5
  386. package/src/runtime/interfaces/thread-list-runtime-core.ts +5 -1
  387. package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
  388. package/src/runtime/queue/message-queue.ts +68 -6
  389. package/src/runtime/utils/auto-status.test.ts +112 -1
  390. package/src/runtime/utils/auto-status.ts +31 -5
  391. package/src/runtime/utils/external-message-conversion.test.ts +202 -0
  392. package/src/runtime/utils/external-message-conversion.ts +123 -32
  393. package/src/runtime/utils/message-repository.test.ts +49 -0
  394. package/src/runtime/utils/message-repository.ts +32 -20
  395. package/src/runtime/utils/thread-message-like.test.ts +52 -0
  396. package/src/runtime/utils/thread-message-like.ts +5 -1
  397. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +18 -13
  398. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -1
  399. package/src/runtimes/internal.ts +1 -0
  400. package/src/runtimes/local/local-thread-runtime-core.test.ts +21 -0
  401. package/src/runtimes/local/local-thread-runtime-core.ts +11 -1
  402. package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +128 -2
  403. package/src/runtimes/remote-thread-list/remote-thread-state.ts +182 -42
  404. package/src/runtimes/remote-thread-list/title-generation.test.ts +602 -0
  405. package/src/runtimes/remote-thread-list/title-generation.ts +329 -0
  406. package/src/runtimes/remote-thread-list/title.test.ts +62 -0
  407. package/src/runtimes/remote-thread-list/title.ts +13 -0
  408. package/src/runtimes/remote-thread-list/types.ts +10 -0
  409. package/src/runtimes/tool-invocations/EDGE_CASES.md +2 -6
  410. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +133 -0
  411. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +10 -6
  412. package/src/store/clients/external-thread.ts +67 -4
  413. package/src/store/clients/model-context-client.ts +5 -1
  414. package/src/store/clients/single-thread-list.ts +1 -0
  415. package/src/store/clients/suggestions.test.ts +40 -0
  416. package/src/store/clients/suggestions.ts +13 -10
  417. package/src/store/clients/thread-tasks.test.ts +274 -0
  418. package/src/store/clients/thread-tasks.ts +138 -0
  419. package/src/store/index.ts +8 -0
  420. package/src/store/primitive-predicates.test.ts +48 -5
  421. package/src/store/primitive-predicates.ts +7 -2
  422. package/src/store/runtime-clients/composer-runtime-client.ts +42 -9
  423. package/src/store/runtime-clients/message-runtime-client.ts +54 -6
  424. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +4 -2
  425. package/src/store/runtime-clients/thread-list-runtime-client.ts +1 -0
  426. package/src/store/runtime-clients/thread-runtime-client.ts +89 -11
  427. package/src/store/scope-registration.ts +2 -0
  428. package/src/store/scopes/composer.ts +16 -4
  429. package/src/store/scopes/message.ts +14 -0
  430. package/src/store/scopes/task.ts +34 -0
  431. package/src/store/scopes/thread-list-item.ts +5 -2
  432. package/src/store/scopes/thread.ts +20 -0
  433. package/src/store/scopes/threads.ts +1 -0
  434. package/src/store/thread-tasks.test.tsx +209 -0
  435. package/src/subscribable/subscribable.test.ts +156 -1
  436. package/src/subscribable/subscribable.ts +25 -15
  437. package/src/tests/MessageRepository.test.ts +117 -5
  438. package/src/tests/OptimisticState-list-race.test.ts +1 -0
  439. package/src/tests/RemoteThreadListThreadListRuntimeCore-initialize-adapter-change.test.ts +38 -0
  440. package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +47 -0
  441. package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +89 -0
  442. package/src/tests/attachment-adapters.test.ts +14 -0
  443. package/src/tests/auiV0Encode.test.ts +300 -0
  444. package/src/tests/base-composer-runtime-core-send.test.ts +51 -0
  445. package/src/tests/base-composer-runtime-core.test.ts +353 -2
  446. package/src/tests/external-store-thread-list-runtime-core.test.ts +83 -0
  447. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +178 -18
  448. package/src/tests/external-thread-attachments.test.tsx +208 -0
  449. package/src/tests/external-thread-parity.test.tsx +57 -0
  450. package/src/tests/groupParts.test.ts +71 -0
  451. package/src/tests/message-queue.test.ts +253 -0
  452. package/src/tests/remote-thread-list-isLoading.test.ts +1 -0
  453. package/src/tests/remote-thread-list-reactive-threadId.test.ts +51 -0
  454. package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
  455. package/src/tests/thread-switch-events.test.tsx +78 -0
  456. package/src/tests/tools-scope-migration.test.tsx +28 -0
  457. package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +43 -0
  458. package/src/types/attachment.ts +4 -0
  459. package/src/types/index.ts +1 -0
  460. package/src/types/message.ts +8 -0
  461. package/src/utils/abortable-iterable.test.ts +328 -0
  462. package/src/utils/abortable-iterable.ts +104 -0
  463. package/src/utils/composite-context-provider.test.ts +25 -0
  464. package/src/utils/composite-context-provider.ts +23 -2
  465. package/src/utils/getGroupStatus.test.ts +70 -4
  466. package/src/utils/getGroupStatus.ts +35 -12
  467. package/src/utils/record.test.ts +48 -0
  468. package/src/utils/record.ts +11 -0
  469. package/src/utils/wire-media.test.ts +10 -0
  470. package/src/utils/wire-media.ts +6 -2
@@ -1,8 +1,9 @@
1
1
  // @vitest-environment jsdom
2
2
 
3
- import { renderHook } from "@testing-library/react";
3
+ import { renderHook, waitFor } from "@testing-library/react";
4
4
  import type { AssistantCloud } from "assistant-cloud";
5
- import { describe, expect, it, vi } from "vitest";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import type { ThreadAssistantMessage } from "../../../types/message";
6
7
  import { useAssistantCloudThreadHistoryAdapter } from "./AssistantCloudThreadHistoryAdapter";
7
8
 
8
9
  const mocks = vi.hoisted(() => {
@@ -23,8 +24,14 @@ const mocks = vi.hoisted(() => {
23
24
  threadListItem,
24
25
  threads: {
25
26
  item: vi.fn(() => threadListItem),
26
- getState: () => ({ threadItems: [{ id, remoteId }] }),
27
+ getState: () => ({
28
+ mainThreadId: id,
29
+ threadItems: [{ id, remoteId }],
30
+ }),
27
31
  },
32
+ thread: { getState: () => ({ isEmpty: false, suggestions: [] }) },
33
+ on: () => () => {},
34
+ subscribe: () => () => {},
28
35
  } as unknown as import("@assistant-ui/store").AssistantClient;
29
36
  };
30
37
 
@@ -40,8 +47,14 @@ const mocks = vi.hoisted(() => {
40
47
  threadListItem: live,
41
48
  threads: {
42
49
  item: vi.fn(() => listItem),
43
- getState: () => ({ threadItems: [{ id: remoteId, remoteId }] }),
50
+ getState: () => ({
51
+ mainThreadId: remoteId,
52
+ threadItems: [{ id: remoteId, remoteId }],
53
+ }),
44
54
  },
55
+ thread: { getState: () => ({ isEmpty: false, suggestions: [] }) },
56
+ on: () => () => {},
57
+ subscribe: () => () => {},
45
58
  } as unknown as import("@assistant-ui/store").AssistantClient;
46
59
  };
47
60
 
@@ -57,20 +70,223 @@ vi.mock("@assistant-ui/store", async (importOriginal) => ({
57
70
  useAui: () => mocks.aui,
58
71
  }));
59
72
 
60
- const makeCloud = () =>
73
+ const makeCloud = (telemetry: Partial<AssistantCloud["telemetry"]> = {}) =>
61
74
  ({
62
75
  threads: {
63
76
  messages: {
64
77
  list: vi.fn().mockResolvedValue({ messages: [] }),
65
78
  create: vi.fn().mockResolvedValue({ message_id: "remote-message-1" }),
66
79
  update: vi.fn().mockResolvedValue(undefined),
80
+ feedback: vi.fn().mockResolvedValue({
81
+ feedback_id: "feedback-1",
82
+ type: "positive",
83
+ }),
67
84
  },
68
85
  },
69
- telemetry: { enabled: true },
86
+ events: { track: vi.fn() },
87
+ telemetry: { enabled: true, ...telemetry },
70
88
  runs: { report: vi.fn().mockResolvedValue(undefined) },
71
89
  }) as unknown as AssistantCloud;
72
90
 
91
+ const makeAssistantMessage = (id: string): ThreadAssistantMessage => ({
92
+ id,
93
+ role: "assistant",
94
+ content: [{ type: "text", text: "done" }],
95
+ status: { type: "complete", reason: "stop" },
96
+ createdAt: new Date(0),
97
+ metadata: {
98
+ unstable_state: null,
99
+ unstable_annotations: [],
100
+ unstable_data: [],
101
+ steps: [],
102
+ custom: {},
103
+ },
104
+ });
105
+
106
+ afterEach(() => {
107
+ vi.restoreAllMocks();
108
+ });
109
+
73
110
  describe("useAssistantCloudThreadHistoryAdapter", () => {
111
+ it("tracks cloud engagement events without message content", async () => {
112
+ const now = vi.spyOn(Date, "now").mockReturnValue(100);
113
+ const listeners = new Map<string, (payload: any) => void>();
114
+ let notify: (() => void) | undefined;
115
+ const threadState = {
116
+ isEmpty: false,
117
+ suggestions: [] as { prompt: string }[],
118
+ };
119
+ const threadListItem = {
120
+ source: "threads",
121
+ getState: () => ({ id: "thread-1", remoteId: "thread-1" }),
122
+ initialize: async () => ({ remoteId: "thread-1", externalId: undefined }),
123
+ };
124
+ mocks.aui = {
125
+ threadListItem,
126
+ threads: {
127
+ item: vi.fn(() => threadListItem),
128
+ getState: () => ({
129
+ mainThreadId: "thread-1",
130
+ threadItems: [{ id: "thread-1", remoteId: "thread-1" }],
131
+ }),
132
+ },
133
+ thread: { getState: () => threadState },
134
+ on: vi.fn((selector, callback) => {
135
+ listeners.set(selector.event, callback);
136
+ return () => listeners.delete(selector.event);
137
+ }),
138
+ subscribe: vi.fn((callback) => {
139
+ notify = callback;
140
+ return () => {};
141
+ }),
142
+ } as unknown as import("@assistant-ui/store").AssistantClient;
143
+ const cloud = makeCloud();
144
+ const { result } = renderHook(() =>
145
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
146
+ );
147
+ const message = makeAssistantMessage("local-message-1");
148
+
149
+ await result.current.append({ parentId: null, message });
150
+ await waitFor(() => expect(listeners.size).toBeGreaterThan(0));
151
+
152
+ listeners.get("thread.runEnd")!({ threadId: "thread-1" });
153
+ now.mockReturnValue(125);
154
+ listeners.get("composer.send")!({
155
+ threadId: "thread-1",
156
+ chars: 5,
157
+ attachments: 1,
158
+ suggestion: true,
159
+ });
160
+ listeners.get("composer.send")!({
161
+ threadId: "thread-1",
162
+ messageId: "local-message-1",
163
+ chars: 7,
164
+ attachments: 0,
165
+ });
166
+ listeners.get("thread.runStart")!({ threadId: "thread-1" });
167
+ now.mockReturnValue(150);
168
+ listeners.get("thread.cancelRun")!({ threadId: "thread-1" });
169
+ listeners.get("message.reload")!({
170
+ threadId: "thread-1",
171
+ messageId: "local-message-1",
172
+ });
173
+ listeners.get("message.branchSwitched")!({
174
+ threadId: "thread-1",
175
+ messageId: "local-message-1",
176
+ });
177
+ listeners.get("message.copied")!({
178
+ threadId: "thread-1",
179
+ messageId: "local-message-1",
180
+ });
181
+ listeners.get("thread.toolApprovalAnswered")!({
182
+ threadId: "thread-1",
183
+ messageId: "local-message-1",
184
+ toolCallId: "tool-approved",
185
+ toolName: "send_email",
186
+ approved: true,
187
+ });
188
+ listeners.get("thread.toolApprovalAnswered")!({
189
+ threadId: "thread-1",
190
+ messageId: "local-message-1",
191
+ toolCallId: "tool-rejected",
192
+ toolName: "delete_account",
193
+ approved: false,
194
+ });
195
+ listeners.get("composer.attachmentAdd")!({
196
+ threadId: "thread-1",
197
+ contentType: "image/png",
198
+ });
199
+ listeners.get("composer.attachmentAddError")!({
200
+ threadId: "thread-1",
201
+ reason: "adapter-error",
202
+ message: "not sent",
203
+ contentType: "application/pdf",
204
+ });
205
+ listeners.get("threads.selectionChanged")!({
206
+ threadId: "thread-1",
207
+ previousThreadId: "thread-0",
208
+ });
209
+ listeners.get("message.speak")!({
210
+ threadId: "thread-1",
211
+ messageId: "local-message-1",
212
+ });
213
+ listeners.get("thread.voiceStarted")!({ threadId: "thread-1" });
214
+ listeners.get("message.error")!({
215
+ threadId: "thread-1",
216
+ messageId: "local-message-1",
217
+ reason: "error",
218
+ });
219
+ listeners.get("message.error")!({
220
+ threadId: "thread-1",
221
+ messageId: "local-message-2",
222
+ reason: "error",
223
+ });
224
+ threadState.isEmpty = true;
225
+ threadState.suggestions = [{ prompt: "one" }, { prompt: "two" }];
226
+ notify!();
227
+ await waitFor(() =>
228
+ expect(vi.mocked(cloud.events.track).mock.calls.length).toBeGreaterThan(
229
+ 12,
230
+ ),
231
+ );
232
+
233
+ expect(
234
+ vi.mocked(cloud.events.track).mock.calls.map(([event]) => event),
235
+ ).toEqual(
236
+ expect.arrayContaining([
237
+ expect.objectContaining({
238
+ kind: "message_sent",
239
+ thread_id: "thread-1",
240
+ value: 25,
241
+ props: { chars: 5, attachments: 1 },
242
+ }),
243
+ expect.objectContaining({
244
+ kind: "message_edited",
245
+ thread_id: "thread-1",
246
+ message_id: "remote-message-1",
247
+ props: { chars: 7 },
248
+ }),
249
+ expect.objectContaining({ kind: "suggestion_clicked" }),
250
+ expect.objectContaining({ kind: "run_stopped", value: 25 }),
251
+ expect.objectContaining({ kind: "message_regenerated" }),
252
+ expect.objectContaining({ kind: "branch_switched" }),
253
+ expect.objectContaining({ kind: "message_copied" }),
254
+ expect.objectContaining({
255
+ kind: "tool_approved",
256
+ message_id: "remote-message-1",
257
+ props: { toolCallId: "tool-approved", toolName: "send_email" },
258
+ }),
259
+ expect.objectContaining({
260
+ kind: "tool_rejected",
261
+ message_id: "remote-message-1",
262
+ props: { toolCallId: "tool-rejected", toolName: "delete_account" },
263
+ }),
264
+ expect.objectContaining({
265
+ kind: "attachment_added",
266
+ props: { type: "image/png" },
267
+ }),
268
+ expect.objectContaining({
269
+ kind: "attachment_failed",
270
+ props: { type: "application/pdf" },
271
+ }),
272
+ expect.objectContaining({ kind: "thread_switched" }),
273
+ expect.objectContaining({ kind: "speech_started" }),
274
+ expect.objectContaining({ kind: "voice_started" }),
275
+ expect.objectContaining({
276
+ kind: "error_shown",
277
+ props: { reason: "error" },
278
+ }),
279
+ expect.objectContaining({ kind: "suggestions_shown", value: 2 }),
280
+ ]),
281
+ );
282
+ expect(
283
+ vi
284
+ .mocked(cloud.events.track)
285
+ .mock.calls.map(([event]) => event)
286
+ .filter((event) => event.kind === "error_shown"),
287
+ ).toHaveLength(1);
288
+ });
289
+
74
290
  it("refreshes formatted persistence when the Cloud client changes", async () => {
75
291
  mocks.aui = mocks.makeClient("thread-1");
76
292
  const firstCloud = makeCloud();
@@ -104,6 +320,7 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
104
320
  expect(secondCloud.threads.messages.list).toHaveBeenCalledOnce();
105
321
  expect(secondCloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
106
322
  format: "test",
323
+ limit: 200,
107
324
  });
108
325
  });
109
326
 
@@ -130,6 +347,7 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
130
347
  await formatted.load();
131
348
  expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
132
349
  format: "test",
350
+ limit: 200,
133
351
  });
134
352
 
135
353
  mocks.aui = mocks.makeClient("thread-2");
@@ -137,6 +355,7 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
137
355
  await formatted.load();
138
356
  expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-2", {
139
357
  format: "test",
358
+ limit: 200,
140
359
  });
141
360
  });
142
361
 
@@ -151,6 +370,7 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
151
370
  await result.current.load();
152
371
  expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
153
372
  format: "aui/v0",
373
+ limit: 200,
154
374
  });
155
375
 
156
376
  mocks.aui = mocks.makeClient("thread-2");
@@ -159,6 +379,92 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
159
379
  await result.current.load();
160
380
  expect(cloud.threads.messages.list).toHaveBeenCalledWith("thread-2", {
161
381
  format: "aui/v0",
382
+ limit: 200,
383
+ });
384
+ });
385
+
386
+ it("submits feedback with the mapped cloud message ID", async () => {
387
+ mocks.aui = mocks.makeClient("thread-1");
388
+ const cloud = makeCloud();
389
+ const cloudRef = { current: cloud };
390
+ const { result } = renderHook(() =>
391
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
392
+ );
393
+ const message = makeAssistantMessage("local-message-1");
394
+
395
+ await result.current.append({ parentId: null, message });
396
+ result.current.feedback.submit({ message, type: "positive" });
397
+
398
+ await waitFor(() => {
399
+ expect(cloud.threads.messages.feedback).toHaveBeenCalledWith(
400
+ "thread-1",
401
+ "remote-message-1",
402
+ { type: "positive" },
403
+ );
404
+ });
405
+ });
406
+
407
+ it("warns and skips feedback before the thread has a remote ID", async () => {
408
+ mocks.aui = mocks.makeClient(undefined, "local-thread", "thread-1");
409
+ const cloud = makeCloud();
410
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
411
+ const { result } = renderHook(() =>
412
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
413
+ );
414
+ const message = makeAssistantMessage("local-message-1");
415
+
416
+ result.current.feedback.submit({ message, type: "negative" });
417
+
418
+ await waitFor(() => {
419
+ expect(warn).toHaveBeenCalledWith(
420
+ "[assistant-ui] Skipping feedback for message local-message-1: the thread has no remote id.",
421
+ );
422
+ });
423
+ expect(cloud.threads.messages.feedback).not.toHaveBeenCalled();
424
+ });
425
+
426
+ it("warns and skips feedback before the message has a cloud ID", async () => {
427
+ mocks.aui = mocks.makeClient("thread-1");
428
+ const cloud = makeCloud();
429
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
430
+ const { result } = renderHook(() =>
431
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
432
+ );
433
+ const message = makeAssistantMessage("local-message-1");
434
+
435
+ result.current.feedback.submit({ message, type: "negative" });
436
+
437
+ await waitFor(() => {
438
+ expect(warn).toHaveBeenCalledWith(
439
+ "[assistant-ui] Skipping feedback for message local-message-1: no cloud message id is mapped.",
440
+ );
441
+ });
442
+ expect(cloud.threads.messages.feedback).not.toHaveBeenCalled();
443
+ });
444
+
445
+ it("reports cloud feedback errors without throwing them into the UI", async () => {
446
+ mocks.aui = mocks.makeClient("thread-1");
447
+ const cloud = makeCloud();
448
+ const error = new Error("feedback unavailable");
449
+ vi.mocked(cloud.threads.messages.feedback).mockRejectedValue(error);
450
+ const consoleError = vi
451
+ .spyOn(console, "error")
452
+ .mockImplementation(() => {});
453
+ const { result } = renderHook(() =>
454
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
455
+ );
456
+ const message = makeAssistantMessage("local-message-1");
457
+
458
+ await result.current.append({ parentId: null, message });
459
+ expect(() =>
460
+ result.current.feedback.submit({ message, type: "positive" }),
461
+ ).not.toThrow();
462
+
463
+ await waitFor(() => {
464
+ expect(consoleError).toHaveBeenCalledWith(
465
+ "[assistant-ui] Cloud feedback submission failed:",
466
+ error,
467
+ );
162
468
  });
163
469
  });
164
470
 
@@ -209,6 +515,132 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
209
515
  );
210
516
  });
211
517
 
518
+ it("reports persisted assistant telemetry dimensions", async () => {
519
+ mocks.aui = mocks.makeClient("thread-1");
520
+ const cloud = makeCloud({
521
+ release: "web-2026.09.08",
522
+ environment: "production",
523
+ tags: ["region:sg", "tier:paid"],
524
+ });
525
+ const { result } = renderHook(() =>
526
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
527
+ );
528
+ const message: ThreadAssistantMessage = {
529
+ ...makeAssistantMessage("local-message-1"),
530
+ status: { type: "incomplete", reason: "length" },
531
+ metadata: {
532
+ ...makeAssistantMessage("local-message-1").metadata,
533
+ custom: {
534
+ traceId: "AABBCCDDEEFF00112233445566778899",
535
+ provider: "openai",
536
+ },
537
+ timing: {
538
+ streamStartTime: 100,
539
+ firstTokenTime: 55.6,
540
+ totalChunks: 1,
541
+ toolCallCount: 0,
542
+ },
543
+ },
544
+ };
545
+
546
+ await result.current.append({ parentId: null, message });
547
+
548
+ expect(cloud.runs.report).toHaveBeenCalledWith(
549
+ expect.objectContaining({
550
+ thread_id: "thread-1",
551
+ status: "incomplete",
552
+ outcome_type: "length",
553
+ message_id: "remote-message-1",
554
+ first_token_ms: 56,
555
+ trace_id: "aabbccddeeff00112233445566778899",
556
+ provider: "openai",
557
+ provider_type: "openai",
558
+ release: "web-2026.09.08",
559
+ environment: "production",
560
+ tags: ["region:sg", "tier:paid"],
561
+ }),
562
+ );
563
+ });
564
+
565
+ it("reports the error message and code of a failed run", async () => {
566
+ mocks.aui = mocks.makeClient("thread-1");
567
+ const cloud = makeCloud();
568
+ const { result } = renderHook(() =>
569
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
570
+ );
571
+ const error = new Error("Rate limited");
572
+ error.name = "AI_APICallError";
573
+ const message: ThreadAssistantMessage = {
574
+ ...makeAssistantMessage("local-message-1"),
575
+ status: { type: "incomplete", reason: "error", error },
576
+ };
577
+
578
+ await result.current.append({ parentId: null, message });
579
+
580
+ expect(cloud.runs.report).toHaveBeenCalledWith(
581
+ expect.objectContaining({
582
+ status: "error",
583
+ error: "Rate limited",
584
+ error_code: "AI_APICallError",
585
+ }),
586
+ );
587
+ });
588
+
589
+ it.each([
590
+ ["cancelled", "aborted"],
591
+ ["length", "length"],
592
+ ["content-filter", "content_filter"],
593
+ ] as const)("maps incomplete %s to outcome %s", async (reason, outcome) => {
594
+ mocks.aui = mocks.makeClient("thread-1");
595
+ const cloud = makeCloud();
596
+ const { result } = renderHook(() =>
597
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
598
+ );
599
+ const message: ThreadAssistantMessage = {
600
+ ...makeAssistantMessage("local-message-1"),
601
+ status: { type: "incomplete", reason },
602
+ };
603
+
604
+ await result.current.append({ parentId: null, message });
605
+
606
+ expect(cloud.runs.report).toHaveBeenCalledWith(
607
+ expect.objectContaining({ outcome_type: outcome }),
608
+ );
609
+ });
610
+
611
+ it("omits a clean outcome and an unknown cloud message ID", () => {
612
+ mocks.aui = mocks.makeClient("thread-1");
613
+ const cloud = makeCloud();
614
+ const { result } = renderHook(() =>
615
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
616
+ );
617
+ const formatted = result.current.withFormat({
618
+ format: "aui/v0",
619
+ encode: ({ message }) => message,
620
+ decode: ({ parent_id, content }) => ({
621
+ parentId: parent_id,
622
+ message: content as { id: string },
623
+ }),
624
+ getId: (message: { id: string }) => message.id,
625
+ });
626
+
627
+ formatted.reportTelemetry([
628
+ {
629
+ parentId: null,
630
+ message: {
631
+ id: "local-message-1",
632
+ role: "assistant",
633
+ content: [{ type: "text", text: "done" }],
634
+ status: { type: "complete", reason: "stop" },
635
+ },
636
+ },
637
+ ]);
638
+
639
+ const report = vi.mocked(cloud.runs.report).mock.calls[0]![0]!;
640
+ expect(report).not.toHaveProperty("outcome_type");
641
+ expect(report).not.toHaveProperty("message_id");
642
+ });
643
+
212
644
  it("reports frontend and MCP sources for ai-sdk/v6 tool calls", () => {
213
645
  mocks.aui = mocks.makeClient("thread-1");
214
646
  const cloud = makeCloud();
@@ -255,6 +687,10 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
255
687
  output: { result: "ok" },
256
688
  },
257
689
  ],
690
+ metadata: {
691
+ traceId: "00112233445566778899AABBCCDDEEFF",
692
+ provider: "anthropic",
693
+ },
258
694
  },
259
695
  },
260
696
  ]);
@@ -287,6 +723,7 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
287
723
  tool_source: "mcp",
288
724
  }),
289
725
  ],
726
+ finish_reason: "tool-calls",
290
727
  },
291
728
  {
292
729
  tool_calls: [
@@ -295,12 +732,272 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
295
732
  tool_source: "frontend",
296
733
  }),
297
734
  ],
735
+ finish_reason: "tool-calls",
298
736
  },
299
737
  ],
738
+ trace_id: "00112233445566778899aabbccddeeff",
739
+ provider: "anthropic",
740
+ provider_type: "anthropic",
300
741
  }),
301
742
  );
302
743
  });
303
744
 
745
+ it("reports a single ai-sdk/v6 step with its tool calls", () => {
746
+ mocks.aui = mocks.makeClient("thread-1");
747
+ const cloud = makeCloud();
748
+ const { result } = renderHook(() =>
749
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
750
+ );
751
+ const formatted = result.current.withFormat({
752
+ format: "ai-sdk/v6",
753
+ encode: ({ message }) => message,
754
+ decode: ({ parent_id, content }) => ({
755
+ parentId: parent_id,
756
+ message: content as { id: string },
757
+ }),
758
+ getId: (message: { id: string }) => message.id,
759
+ });
760
+
761
+ formatted.reportTelemetry([
762
+ {
763
+ parentId: null,
764
+ message: {
765
+ id: "message-1",
766
+ role: "assistant",
767
+ parts: [
768
+ { type: "step-start" },
769
+ {
770
+ type: "tool-search",
771
+ toolCallId: "search-1",
772
+ input: { query: "test" },
773
+ output: { result: "ok" },
774
+ },
775
+ ],
776
+ },
777
+ },
778
+ ]);
779
+
780
+ expect(cloud.runs.report).toHaveBeenCalledWith(
781
+ expect.objectContaining({
782
+ total_steps: 1,
783
+ steps: [
784
+ {
785
+ tool_calls: [
786
+ expect.objectContaining({
787
+ tool_call_id: "search-1",
788
+ tool_source: "frontend",
789
+ }),
790
+ ],
791
+ finish_reason: "tool-calls",
792
+ },
793
+ ],
794
+ }),
795
+ );
796
+ });
797
+
798
+ it("reads the status of an ai-sdk/v6 run from its finish reason", () => {
799
+ mocks.aui = mocks.makeClient("thread-1");
800
+ const cloud = makeCloud();
801
+ const { result } = renderHook(() =>
802
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
803
+ );
804
+ const formatted = result.current.withFormat({
805
+ format: "ai-sdk/v6",
806
+ encode: ({ message }) => message,
807
+ decode: ({ parent_id, content }) => ({
808
+ parentId: parent_id,
809
+ message: content as { id: string },
810
+ }),
811
+ getId: (message: { id: string }) => message.id,
812
+ });
813
+
814
+ formatted.reportTelemetry([
815
+ {
816
+ parentId: null,
817
+ message: {
818
+ id: "message-1",
819
+ role: "assistant",
820
+ parts: [{ type: "text", text: "cut" }],
821
+ metadata: { finishReason: "length" },
822
+ },
823
+ },
824
+ ]);
825
+
826
+ expect(cloud.runs.report).toHaveBeenCalledWith(
827
+ expect.objectContaining({ status: "incomplete", outcome_type: "length" }),
828
+ );
829
+ });
830
+
831
+ it("reads the error and timing of an ai-sdk/v6 run from the thread message", () => {
832
+ mocks.aui = mocks.makeClient("thread-1");
833
+ const cloud = makeCloud();
834
+ const { result } = renderHook(() =>
835
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
836
+ );
837
+ const formatted = result.current.withFormat({
838
+ format: "ai-sdk/v6",
839
+ encode: ({ message }) => message,
840
+ decode: ({ parent_id, content }) => ({
841
+ parentId: parent_id,
842
+ message: content as { id: string },
843
+ }),
844
+ getId: (message: { id: string }) => message.id,
845
+ });
846
+ const base = makeAssistantMessage("assistant-1");
847
+ const message: ThreadAssistantMessage = {
848
+ ...base,
849
+ status: {
850
+ type: "incomplete",
851
+ reason: "error",
852
+ error: Object.assign(new Error("model unavailable"), {
853
+ code: "model_unavailable",
854
+ }),
855
+ },
856
+ metadata: {
857
+ ...base.metadata,
858
+ timing: {
859
+ streamStartTime: 100,
860
+ firstTokenTime: 240,
861
+ totalChunks: 3,
862
+ toolCallCount: 0,
863
+ },
864
+ },
865
+ };
866
+
867
+ formatted.reportTelemetry(
868
+ [
869
+ {
870
+ parentId: null,
871
+ message: {
872
+ id: "message-1",
873
+ role: "assistant",
874
+ parts: [{ type: "text", text: "partial" }],
875
+ },
876
+ },
877
+ ],
878
+ { message },
879
+ );
880
+
881
+ expect(cloud.runs.report).toHaveBeenCalledWith(
882
+ expect.objectContaining({
883
+ status: "error",
884
+ error: "model unavailable",
885
+ error_code: "model_unavailable",
886
+ first_token_ms: 240,
887
+ }),
888
+ );
889
+ });
890
+
891
+ it("reports a run that failed before any assistant message was stored", () => {
892
+ mocks.aui = mocks.makeClient("thread-1");
893
+ const cloud = makeCloud();
894
+ const { result } = renderHook(() =>
895
+ useAssistantCloudThreadHistoryAdapter({ current: cloud }),
896
+ );
897
+ const formatted = result.current.withFormat({
898
+ format: "ai-sdk/v6",
899
+ encode: ({ message }) => message,
900
+ decode: ({ parent_id, content }) => ({
901
+ parentId: parent_id,
902
+ message: content as { id: string },
903
+ }),
904
+ getId: (message: { id: string }) => message.id,
905
+ });
906
+ const message: ThreadAssistantMessage = {
907
+ ...makeAssistantMessage("assistant-1"),
908
+ content: [],
909
+ status: {
910
+ type: "incomplete",
911
+ reason: "error",
912
+ error: { code: "AI_APICallError", message: "upstream failed" },
913
+ },
914
+ };
915
+
916
+ formatted.reportTelemetry([], { message, durationMs: 120 });
917
+
918
+ expect(cloud.runs.report).toHaveBeenCalledWith(
919
+ expect.objectContaining({
920
+ status: "error",
921
+ error: "upstream failed",
922
+ error_code: "AI_APICallError",
923
+ duration_ms: 120,
924
+ }),
925
+ );
926
+ });
927
+
928
+ it("reports the model ID carried by aui/v0 step metadata", () => {
929
+ mocks.aui = mocks.makeClient("thread-1");
930
+ const cloud = makeCloud();
931
+ const cloudRef = { current: cloud };
932
+ const { result } = renderHook(() =>
933
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
934
+ );
935
+ const formatted = result.current.withFormat({
936
+ format: "aui/v0",
937
+ encode: ({ message }) => message,
938
+ decode: ({ parent_id, content }) => ({
939
+ parentId: parent_id,
940
+ message: content as { id: string },
941
+ }),
942
+ getId: (message: { id: string }) => message.id,
943
+ });
944
+
945
+ formatted.reportTelemetry([
946
+ {
947
+ parentId: null,
948
+ message: {
949
+ id: "message-1",
950
+ role: "assistant",
951
+ content: [{ type: "text", text: "done" }],
952
+ status: { type: "complete" },
953
+ metadata: {
954
+ steps: [{ response: { modelId: "provider/model-1" } }],
955
+ },
956
+ },
957
+ },
958
+ ]);
959
+
960
+ expect(cloud.runs.report).toHaveBeenCalledWith(
961
+ expect.objectContaining({ model_id: "provider/model-1" }),
962
+ );
963
+ });
964
+
965
+ it("reports the model ID carried by ai-sdk/v6 step metadata", () => {
966
+ mocks.aui = mocks.makeClient("thread-1");
967
+ const cloud = makeCloud();
968
+ const cloudRef = { current: cloud };
969
+ const { result } = renderHook(() =>
970
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
971
+ );
972
+ const formatted = result.current.withFormat({
973
+ format: "ai-sdk/v6",
974
+ encode: ({ message }) => message,
975
+ decode: ({ parent_id, content }) => ({
976
+ parentId: parent_id,
977
+ message: content as { id: string },
978
+ }),
979
+ getId: (message: { id: string }) => message.id,
980
+ });
981
+
982
+ formatted.reportTelemetry([
983
+ {
984
+ parentId: null,
985
+ message: {
986
+ id: "message-1",
987
+ role: "assistant",
988
+ parts: [{ type: "text", text: "done" }],
989
+ metadata: {
990
+ steps: [{ response: { modelId: "provider/model-1" } }],
991
+ },
992
+ },
993
+ },
994
+ ]);
995
+
996
+ expect(cloud.runs.report).toHaveBeenCalledWith(
997
+ expect.objectContaining({ model_id: "provider/model-1" }),
998
+ );
999
+ });
1000
+
304
1001
  it("initializes the pinned item instead of the new main thread", async () => {
305
1002
  mocks.aui = mocks.makeClient(undefined, "new-thread", "thread-1");
306
1003
  const cloud = makeCloud();