@assistant-ui/core 0.3.15 → 0.3.17

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 (455) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/internal.d.ts +8 -2
  5. package/dist/internal.js +9 -3
  6. package/dist/model-context/frame/host.d.ts.map +1 -1
  7. package/dist/model-context/frame/host.js +3 -2
  8. package/dist/model-context/frame/host.js.map +1 -1
  9. package/dist/model-context/frame/provider.d.ts +5 -0
  10. package/dist/model-context/frame/provider.d.ts.map +1 -1
  11. package/dist/model-context/frame/provider.js +141 -28
  12. package/dist/model-context/frame/provider.js.map +1 -1
  13. package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
  14. package/dist/model-context/interactable-composer-metadata.js +1 -1
  15. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  16. package/dist/model-context/registry.d.ts +2 -2
  17. package/dist/model-context/registry.d.ts.map +1 -1
  18. package/dist/model-context/registry.js +9 -28
  19. package/dist/model-context/registry.js.map +1 -1
  20. package/dist/model-context/tool-call-text.d.ts +26 -0
  21. package/dist/model-context/tool-call-text.d.ts.map +1 -0
  22. package/dist/model-context/tool-call-text.js +18 -0
  23. package/dist/model-context/tool-call-text.js.map +1 -0
  24. package/dist/react/RuntimeAdapter.js +1 -1
  25. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  26. package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
  27. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  28. package/dist/react/client/AdaptedRemoteThread.js +1 -1
  29. package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
  30. package/dist/react/client/InMemoryThreadList.js +25 -21
  31. package/dist/react/client/InMemoryThreadList.js.map +1 -1
  32. package/dist/react/client/Interactables.d.ts.map +1 -1
  33. package/dist/react/client/Interactables.js +60 -178
  34. package/dist/react/client/Interactables.js.map +1 -1
  35. package/dist/react/client/RemoteThreadList.d.ts +15 -0
  36. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  37. package/dist/react/client/RemoteThreadList.js +263 -194
  38. package/dist/react/client/RemoteThreadList.js.map +1 -1
  39. package/dist/react/client/Tools.d.ts.map +1 -1
  40. package/dist/react/client/Tools.js +6 -2
  41. package/dist/react/client/Tools.js.map +1 -1
  42. package/dist/react/index.d.ts +4 -2
  43. package/dist/react/index.js +2 -1
  44. package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
  45. package/dist/react/interactables-legacy/Interactables.js +60 -178
  46. package/dist/react/interactables-legacy/Interactables.js.map +1 -1
  47. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
  48. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
  49. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
  50. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
  51. package/dist/react/model-context/toolbox.d.ts +2 -14
  52. package/dist/react/model-context/toolbox.d.ts.map +1 -1
  53. package/dist/react/model-context/toolbox.js +1 -13
  54. package/dist/react/model-context/toolbox.js.map +1 -1
  55. package/dist/react/model-context/useAssistantContext.js +37 -7
  56. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  57. package/dist/react/model-context/useAuiToolOverrides.js +31 -5
  58. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  59. package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
  60. package/dist/react/model-context/useInlineRender.js +10 -36
  61. package/dist/react/model-context/useInlineRender.js.map +1 -1
  62. package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
  63. package/dist/react/primitive-hooks/useMessageError.js +2 -8
  64. package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
  65. package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
  66. package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
  67. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  68. package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  69. package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
  70. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  71. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  72. package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
  73. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  74. package/dist/react/primitives/composer/ComposerQueue.js +4 -3
  75. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  76. package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
  77. package/dist/react/primitives/message/MessageAttachments.js +7 -6
  78. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  79. package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
  80. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  81. package/dist/react/primitives/message/MessageParts.js +3 -3
  82. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  83. package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  84. package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
  85. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  86. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -5
  87. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  88. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
  89. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  90. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -6
  91. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  92. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +102 -117
  93. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  94. package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
  95. package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
  96. package/dist/react/runtimes/RemoteThreadResource.js +3 -3
  97. package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
  98. package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
  99. package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
  100. package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
  101. package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
  102. package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
  103. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
  104. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  105. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +43 -85
  106. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  107. package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
  108. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  109. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  110. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
  111. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
  112. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
  113. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
  114. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
  115. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
  116. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
  117. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
  118. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
  119. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  120. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
  121. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  122. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
  123. package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
  124. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  125. package/dist/react/runtimes/external-message-converter.d.ts +6 -25
  126. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  127. package/dist/react/runtimes/external-message-converter.js +33 -233
  128. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  129. package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
  130. package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
  131. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  132. package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
  133. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  134. package/dist/react/types/scopes/tools.d.ts +2 -0
  135. package/dist/react/types/scopes/tools.d.ts.map +1 -1
  136. package/dist/runtime/api/composer-runtime.d.ts +1 -1
  137. package/dist/runtime/api/composer-runtime.js.map +1 -1
  138. package/dist/runtime/api/message-part-runtime.d.ts +2 -2
  139. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  140. package/dist/runtime/api/message-part-runtime.js +1 -1
  141. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  142. package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
  143. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  144. package/dist/runtime/api/thread-list-runtime.js +5 -0
  145. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  146. package/dist/runtime/api/thread-runtime.d.ts +2 -3
  147. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  148. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
  149. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  150. package/dist/runtime/base/base-composer-runtime-core.js +14 -29
  151. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  152. package/dist/runtime/base/base-thread-runtime-core.d.ts +4 -6
  153. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  154. package/dist/runtime/base/base-thread-runtime-core.js +5 -11
  155. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  156. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
  157. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  158. package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
  159. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  160. package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
  161. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
  162. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  163. package/dist/runtime/interfaces/thread-runtime-core.d.ts +16 -2
  164. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  165. package/dist/runtime/internal.d.ts +2 -1
  166. package/dist/runtime/internal.js +2 -1
  167. package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
  168. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  169. package/dist/runtime/queue/message-queue.js +1 -1
  170. package/dist/runtime/queue/message-queue.js.map +1 -1
  171. package/dist/runtime/queue/queue-item.d.ts +12 -0
  172. package/dist/runtime/queue/queue-item.d.ts.map +1 -0
  173. package/dist/runtime/queue/queue-item.js +6 -0
  174. package/dist/runtime/queue/queue-item.js.map +1 -0
  175. package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
  176. package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
  177. package/dist/runtime/utils/abortable-thread-load.js +35 -0
  178. package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
  179. package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
  180. package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
  181. package/dist/runtime/utils/attachment-add-operations.js +43 -0
  182. package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
  183. package/dist/runtime/utils/auto-status.d.ts +7 -2
  184. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  185. package/dist/runtime/utils/auto-status.js +13 -3
  186. package/dist/runtime/utils/auto-status.js.map +1 -1
  187. package/dist/runtime/utils/external-message-conversion.d.ts +48 -0
  188. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
  189. package/dist/runtime/utils/external-message-conversion.js +222 -0
  190. package/dist/runtime/utils/external-message-conversion.js.map +1 -0
  191. package/dist/runtime/utils/external-store-message.d.ts +2 -1
  192. package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
  193. package/dist/runtime/utils/external-store-message.js +2 -1
  194. package/dist/runtime/utils/external-store-message.js.map +1 -1
  195. package/dist/runtime/utils/message-repository-session.d.ts +30 -0
  196. package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
  197. package/dist/runtime/utils/message-repository-session.js +130 -0
  198. package/dist/runtime/utils/message-repository-session.js.map +1 -0
  199. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  200. package/dist/runtime/utils/message-repository.js +3 -4
  201. package/dist/runtime/utils/message-repository.js.map +1 -1
  202. package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
  203. package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
  204. package/dist/runtime/utils/pending-tool-calls.js +22 -0
  205. package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
  206. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
  207. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
  208. package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
  209. package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
  210. package/dist/runtime/utils/thread-message-like.d.ts +3 -10
  211. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  212. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  213. package/dist/runtime/utils/tool-call-tree.d.ts +39 -0
  214. package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
  215. package/dist/runtime/utils/tool-call-tree.js +85 -0
  216. package/dist/runtime/utils/tool-call-tree.js.map +1 -0
  217. package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
  218. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  219. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
  220. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  221. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +3 -10
  222. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  223. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +21 -2
  224. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  225. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +154 -46
  226. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  227. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
  228. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
  229. package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
  230. package/dist/runtimes/local/local-thread-runtime-core.d.ts +4 -2
  231. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  232. package/dist/runtimes/local/local-thread-runtime-core.js +23 -3
  233. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  234. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
  235. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  236. package/dist/runtimes/remote-thread-list/remote-thread-state.js +107 -14
  237. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  238. package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
  239. package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
  240. package/dist/runtimes/remote-thread-list/title.js +6 -0
  241. package/dist/runtimes/remote-thread-list/title.js.map +1 -0
  242. package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
  243. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  244. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
  245. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  246. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +98 -59
  247. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  248. package/dist/store/clients/external-thread.d.ts +1 -1
  249. package/dist/store/clients/external-thread.d.ts.map +1 -1
  250. package/dist/store/clients/external-thread.js +85 -103
  251. package/dist/store/clients/external-thread.js.map +1 -1
  252. package/dist/store/clients/single-thread-list.d.ts.map +1 -1
  253. package/dist/store/clients/single-thread-list.js +2 -2
  254. package/dist/store/clients/single-thread-list.js.map +1 -1
  255. package/dist/store/clients/suggestions.d.ts.map +1 -1
  256. package/dist/store/clients/suggestions.js +33 -12
  257. package/dist/store/clients/suggestions.js.map +1 -1
  258. package/dist/store/clients/thread-message-client.js +1 -1
  259. package/dist/store/clients/thread-selection-events.js +1 -1
  260. package/dist/store/index.d.ts +6 -3
  261. package/dist/store/index.js +2 -1
  262. package/dist/store/internal.d.ts +2 -2
  263. package/dist/store/internal.js +2 -2
  264. package/dist/store/primitive-predicates.d.ts +4 -1
  265. package/dist/store/primitive-predicates.d.ts.map +1 -1
  266. package/dist/store/primitive-predicates.js +9 -1
  267. package/dist/store/primitive-predicates.js.map +1 -1
  268. package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
  269. package/dist/store/runtime-clients/message-runtime-client.js +1 -1
  270. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
  271. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  272. package/dist/store/runtime-clients/thread-list-runtime-client.js +124 -105
  273. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  274. package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
  275. package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
  276. package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
  277. package/dist/store/runtime-clients/useSubscribable.js +1 -1
  278. package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
  279. package/dist/store/scope-registration.d.ts +1 -1
  280. package/dist/store/scopes/composer.d.ts +2 -1
  281. package/dist/store/scopes/composer.d.ts.map +1 -1
  282. package/dist/store/scopes/message.d.ts +1 -1
  283. package/dist/store/scopes/part.d.ts +6 -3
  284. package/dist/store/scopes/part.d.ts.map +1 -1
  285. package/dist/store/scopes/queue-item.d.ts +2 -9
  286. package/dist/store/scopes/queue-item.d.ts.map +1 -1
  287. package/dist/store/scopes/queue-item.js +0 -6
  288. package/dist/subscribable/subscribable.d.ts +8 -1
  289. package/dist/subscribable/subscribable.d.ts.map +1 -1
  290. package/dist/subscribable/subscribable.js +24 -16
  291. package/dist/subscribable/subscribable.js.map +1 -1
  292. package/dist/types/message.d.ts +47 -4
  293. package/dist/types/message.d.ts.map +1 -1
  294. package/dist/types/message.js +7 -1
  295. package/dist/types/message.js.map +1 -1
  296. package/dist/utils/data-url.d.ts +14 -1
  297. package/dist/utils/data-url.d.ts.map +1 -1
  298. package/dist/utils/data-url.js +13 -1
  299. package/dist/utils/data-url.js.map +1 -1
  300. package/dist/utils/invoke-user-callback.d.ts +5 -0
  301. package/dist/utils/invoke-user-callback.d.ts.map +1 -0
  302. package/dist/utils/invoke-user-callback.js +19 -0
  303. package/dist/utils/invoke-user-callback.js.map +1 -0
  304. package/dist/utils/normalizePartStatus.js.map +1 -1
  305. package/package.json +12 -17
  306. package/src/index.ts +6 -1
  307. package/src/internal.ts +20 -0
  308. package/src/model-context/frame/host.test.ts +91 -7
  309. package/src/model-context/frame/host.ts +7 -2
  310. package/src/model-context/frame/provider.test.ts +484 -13
  311. package/src/model-context/frame/provider.ts +205 -35
  312. package/src/model-context/interactable-composer-metadata.ts +1 -1
  313. package/src/model-context/registry.test.ts +44 -0
  314. package/src/model-context/registry.ts +13 -35
  315. package/src/model-context/tool-call-text.test.ts +67 -0
  316. package/src/model-context/tool-call-text.ts +67 -0
  317. package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
  318. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
  319. package/src/react/client/InMemoryThreadList.test.tsx +49 -0
  320. package/src/react/client/InMemoryThreadList.ts +7 -1
  321. package/src/react/client/Interactables.ts +19 -178
  322. package/src/react/client/RemoteThreadList.background.test.ts +384 -0
  323. package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
  324. package/src/react/client/RemoteThreadList.test.ts +369 -1
  325. package/src/react/client/RemoteThreadList.ts +320 -142
  326. package/src/react/client/Tools.ts +7 -1
  327. package/src/react/index.ts +4 -0
  328. package/src/react/interactables-legacy/Interactables.ts +20 -177
  329. package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
  330. package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
  331. package/src/react/model-context/modelContextHooks.test.tsx +131 -0
  332. package/src/react/model-context/toolbox.test.ts +9 -9
  333. package/src/react/model-context/toolbox.ts +9 -36
  334. package/src/react/model-context/useAssistantContext.ts +4 -2
  335. package/src/react/model-context/useAuiToolOverrides.ts +4 -2
  336. package/src/react/model-context/useInlineRender.test.tsx +48 -0
  337. package/src/react/model-context/useInlineRender.ts +14 -10
  338. package/src/react/primitive-hooks/useMessageError.ts +2 -19
  339. package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
  340. package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
  341. package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
  342. package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
  343. package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
  344. package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
  345. package/src/react/primitives/message/MessageAttachments.tsx +10 -7
  346. package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
  347. package/src/react/primitives/message/MessageParts.tsx +3 -3
  348. package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
  349. package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
  350. package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
  351. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
  352. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
  353. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +140 -124
  354. package/src/react/runtimes/RemoteThreadResource.ts +1 -4
  355. package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
  356. package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
  357. package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
  358. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
  359. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +157 -1
  360. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +82 -176
  361. package/src/react/runtimes/cloud/auiV0.ts +5 -0
  362. package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
  363. package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
  364. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
  365. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
  366. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
  367. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
  368. package/src/react/runtimes/external-message-converter.test.ts +0 -14
  369. package/src/react/runtimes/external-message-converter.test.tsx +77 -0
  370. package/src/react/runtimes/external-message-converter.ts +59 -481
  371. package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
  372. package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
  373. package/src/react/types/MessagePartComponentTypes.ts +7 -3
  374. package/src/react/types/scopes/tools.ts +2 -0
  375. package/src/runtime/api/composer-runtime.ts +1 -1
  376. package/src/runtime/api/message-part-runtime.ts +3 -3
  377. package/src/runtime/api/message-runtime.test.ts +28 -1
  378. package/src/runtime/api/thread-list-runtime.ts +25 -1
  379. package/src/runtime/base/base-composer-runtime-core.ts +20 -40
  380. package/src/runtime/base/base-thread-runtime-core.test.ts +110 -3
  381. package/src/runtime/base/base-thread-runtime-core.ts +16 -15
  382. package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
  383. package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
  384. package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
  385. package/src/runtime/interfaces/thread-runtime-core.ts +18 -2
  386. package/src/runtime/internal.ts +5 -0
  387. package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
  388. package/src/runtime/queue/message-queue.ts +1 -4
  389. package/src/runtime/queue/queue-item.ts +10 -0
  390. package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
  391. package/src/runtime/utils/abortable-thread-load.ts +53 -0
  392. package/src/runtime/utils/attachment-add-operations.ts +59 -0
  393. package/src/runtime/utils/auto-status.test.ts +57 -0
  394. package/src/runtime/utils/auto-status.ts +46 -1
  395. package/src/runtime/utils/external-message-conversion.test.ts +210 -0
  396. package/src/runtime/utils/external-message-conversion.ts +510 -0
  397. package/src/runtime/utils/external-store-message.ts +2 -0
  398. package/src/runtime/utils/message-repository-session.test.ts +195 -0
  399. package/src/runtime/utils/message-repository-session.ts +176 -0
  400. package/src/runtime/utils/message-repository.ts +7 -4
  401. package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
  402. package/src/runtime/utils/pending-tool-calls.ts +35 -0
  403. package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
  404. package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
  405. package/src/runtime/utils/thread-message-like.ts +4 -10
  406. package/src/runtime/utils/tool-call-tree.test.ts +191 -0
  407. package/src/runtime/utils/tool-call-tree.ts +97 -0
  408. package/src/runtimes/external-store/external-store-adapter.ts +38 -2
  409. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
  410. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +231 -61
  411. package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
  412. package/src/runtimes/local/local-thread-runtime-core.test.ts +201 -4
  413. package/src/runtimes/local/local-thread-runtime-core.ts +53 -4
  414. package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +149 -0
  415. package/src/runtimes/remote-thread-list/remote-thread-state.ts +178 -16
  416. package/src/runtimes/remote-thread-list/title.ts +3 -0
  417. package/src/runtimes/remote-thread-list/types.ts +6 -5
  418. package/src/runtimes/tool-invocations/EDGE_CASES.md +125 -3
  419. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +856 -102
  420. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +145 -89
  421. package/src/store/clients/external-thread.ts +30 -69
  422. package/src/store/clients/single-thread-list.ts +4 -1
  423. package/src/store/clients/suggestions.test.ts +185 -0
  424. package/src/store/clients/suggestions.ts +42 -35
  425. package/src/store/index.ts +4 -0
  426. package/src/store/internal.ts +2 -0
  427. package/src/store/primitive-predicates.ts +35 -0
  428. package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
  429. package/src/store/runtime-clients/useSubscribable.ts +8 -2
  430. package/src/store/scopes/message.ts +1 -1
  431. package/src/store/scopes/part.ts +6 -3
  432. package/src/store/scopes/queue-item.ts +2 -9
  433. package/src/subscribable/subscribable.test.ts +50 -0
  434. package/src/subscribable/subscribable.ts +33 -21
  435. package/src/tests/MessageRepository.test.ts +77 -0
  436. package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +305 -0
  437. package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
  438. package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
  439. package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
  440. package/src/tests/external-store-optimistic-id.test.ts +79 -0
  441. package/src/tests/external-store-repository-instance.test.ts +166 -0
  442. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +186 -16
  443. package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
  444. package/src/tests/external-thread-attachments.test.tsx +258 -1
  445. package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
  446. package/src/tests/single-thread-list-item.test.tsx +47 -0
  447. package/src/tests/thread-message-like.test.ts +39 -1
  448. package/src/tests/thread-switch-events.test.tsx +397 -2
  449. package/src/types/message.ts +58 -5
  450. package/src/utils/data-url.test.ts +52 -1
  451. package/src/utils/data-url.ts +21 -0
  452. package/src/utils/invoke-user-callback.test.ts +82 -0
  453. package/src/utils/invoke-user-callback.ts +31 -0
  454. package/src/utils/normalizePartStatus.ts +1 -1
  455. package/dist/store/scopes/queue-item.js.map +0 -1
@@ -21,12 +21,33 @@ const mocks = vi.hoisted(() => {
21
21
  };
22
22
  return {
23
23
  threadListItem,
24
- threads: { item: vi.fn(() => threadListItem) },
24
+ threads: {
25
+ item: vi.fn(() => threadListItem),
26
+ getState: () => ({ threadItems: [{ id, remoteId }] }),
27
+ },
28
+ } as unknown as import("@assistant-ui/store").AssistantClient;
29
+ };
30
+
31
+ const makeSplitClient = (remoteId: string) => {
32
+ const itemShape = () => ({
33
+ source: "threads",
34
+ getState: () => ({ id: remoteId, remoteId }),
35
+ initialize: async () => ({ remoteId, externalId: undefined }),
36
+ });
37
+ const live = itemShape();
38
+ const listItem = itemShape();
39
+ return {
40
+ threadListItem: live,
41
+ threads: {
42
+ item: vi.fn(() => listItem),
43
+ getState: () => ({ threadItems: [{ id: remoteId, remoteId }] }),
44
+ },
25
45
  } as unknown as import("@assistant-ui/store").AssistantClient;
26
46
  };
27
47
 
28
48
  return {
29
49
  makeClient,
50
+ makeSplitClient,
30
51
  aui: makeClient("thread-1"),
31
52
  };
32
53
  });
@@ -188,6 +209,98 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
188
209
  );
189
210
  });
190
211
 
212
+ it("reports frontend and MCP sources for ai-sdk/v6 tool calls", () => {
213
+ mocks.aui = mocks.makeClient("thread-1");
214
+ const cloud = makeCloud();
215
+ const cloudRef = { current: cloud };
216
+ const { result } = renderHook(() =>
217
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
218
+ );
219
+ const formatted = result.current.withFormat({
220
+ format: "ai-sdk/v6",
221
+ encode: ({ message }) => message,
222
+ decode: ({ parent_id, content }) => ({
223
+ parentId: parent_id,
224
+ message: content as { id: string },
225
+ }),
226
+ getId: (message: { id: string }) => message.id,
227
+ });
228
+
229
+ formatted.reportTelemetry([
230
+ {
231
+ parentId: null,
232
+ message: {
233
+ id: "message-1",
234
+ role: "assistant",
235
+ parts: [
236
+ { type: "step-start" },
237
+ {
238
+ type: "tool-search",
239
+ toolCallId: "static-1",
240
+ input: { query: "test" },
241
+ output: { result: "ok" },
242
+ },
243
+ {
244
+ type: "dynamic-tool",
245
+ toolName: "mcp-search",
246
+ toolCallId: "dynamic-1",
247
+ input: { query: "test" },
248
+ output: { result: "ok" },
249
+ },
250
+ { type: "step-start" },
251
+ {
252
+ type: "tool-search",
253
+ toolCallId: "static-2",
254
+ input: { query: "again" },
255
+ output: { result: "ok" },
256
+ },
257
+ ],
258
+ },
259
+ },
260
+ ]);
261
+
262
+ expect(cloud.runs.report).toHaveBeenCalledWith(
263
+ expect.objectContaining({
264
+ tool_calls: [
265
+ expect.objectContaining({
266
+ tool_call_id: "static-1",
267
+ tool_source: "frontend",
268
+ }),
269
+ expect.objectContaining({
270
+ tool_call_id: "dynamic-1",
271
+ tool_source: "mcp",
272
+ }),
273
+ expect.objectContaining({
274
+ tool_call_id: "static-2",
275
+ tool_source: "frontend",
276
+ }),
277
+ ],
278
+ steps: [
279
+ {
280
+ tool_calls: [
281
+ expect.objectContaining({
282
+ tool_call_id: "static-1",
283
+ tool_source: "frontend",
284
+ }),
285
+ expect.objectContaining({
286
+ tool_call_id: "dynamic-1",
287
+ tool_source: "mcp",
288
+ }),
289
+ ],
290
+ },
291
+ {
292
+ tool_calls: [
293
+ expect.objectContaining({
294
+ tool_call_id: "static-2",
295
+ tool_source: "frontend",
296
+ }),
297
+ ],
298
+ },
299
+ ],
300
+ }),
301
+ );
302
+ });
303
+
191
304
  it("initializes the pinned item instead of the new main thread", async () => {
192
305
  mocks.aui = mocks.makeClient(undefined, "new-thread", "thread-1");
193
306
  const cloud = makeCloud();
@@ -216,4 +329,47 @@ describe("useAssistantCloudThreadHistoryAdapter", () => {
216
329
  expect.anything(),
217
330
  );
218
331
  });
332
+
333
+ it("updates a history-loaded message when the list item identity differs from the live item", async () => {
334
+ mocks.aui = mocks.makeSplitClient("thread-split");
335
+ const cloud = makeCloud();
336
+ (cloud.threads.messages.list as ReturnType<typeof vi.fn>).mockResolvedValue(
337
+ {
338
+ messages: [
339
+ {
340
+ id: "m1",
341
+ parent_id: null,
342
+ format: "test",
343
+ content: { id: "m1" },
344
+ },
345
+ ],
346
+ },
347
+ );
348
+ const cloudRef = { current: cloud };
349
+ const { result } = renderHook(() =>
350
+ useAssistantCloudThreadHistoryAdapter(cloudRef),
351
+ );
352
+ const formatted = result.current.withFormat<
353
+ { id: string },
354
+ Record<string, unknown>
355
+ >({
356
+ format: "test",
357
+ encode: ({ message }) => message,
358
+ decode: ({ parent_id, content }) => ({
359
+ parentId: parent_id,
360
+ message: content as { id: string },
361
+ }),
362
+ getId: (message) => message.id,
363
+ });
364
+
365
+ formatted.pin!();
366
+ await formatted.load();
367
+ await formatted.update!({ parentId: null, message: { id: "m1" } }, "m1");
368
+
369
+ expect(cloud.threads.messages.update).toHaveBeenCalledWith(
370
+ "thread-split",
371
+ "m1",
372
+ expect.anything(),
373
+ );
374
+ });
219
375
  });
@@ -9,8 +9,13 @@ import type {
9
9
  import type { ExportedMessageRepositoryItem } from "../../../runtime/utils/message-repository";
10
10
  import {
11
11
  type AssistantCloud,
12
+ type AssistantCloudRunReportToolCall,
12
13
  CloudMessagePersistence,
13
14
  createFormattedPersistence,
15
+ createRunTelemetryToolCall,
16
+ normalizeRunTelemetryUsage,
17
+ type RunTelemetryUsageInit,
18
+ truncateRunTelemetryText,
14
19
  } from "assistant-cloud";
15
20
  import { auiV0Decode, auiV0Encode } from "./auiV0";
16
21
  import { type AssistantClient, getClientId, useAui } from "@assistant-ui/store";
@@ -64,7 +69,12 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
64
69
  if (!live.source) return undefined;
65
70
  const id = live.getState().id;
66
71
  if (id === undefined) return undefined;
67
- return this.aui.threads.item({ id });
72
+ // A body can resolve before the list's committed items include its
73
+ // thread; the live item is already the per-thread anchor in that window.
74
+ const listed = this.aui.threads
75
+ .getState()
76
+ .threadItems.some((item) => item.id === id || item.remoteId === id);
77
+ return listed ? this.aui.threads.item({ id }) : live;
68
78
  }
69
79
 
70
80
  withFormat<TMessage, TStorageFormat extends Record<string, unknown>>(
@@ -78,8 +88,6 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
78
88
  return threadListItem;
79
89
  };
80
90
  const resolvePinned = () => threadListItem ?? pinCurrent();
81
- const getFormatted = () =>
82
- createFormattedPersistence(adapter._persistence, formatAdapter);
83
91
  const getTargetFormatted = (item: CloudThreadListItem) =>
84
92
  createFormattedPersistence(adapter.getPersistence(item), formatAdapter);
85
93
  return {
@@ -130,11 +138,14 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
130
138
  );
131
139
  },
132
140
  async load(): Promise<MessageFormatRepository<TMessage>> {
133
- pinCurrent();
141
+ // Loads re-pin and resolve through the pinned item, so the id mapping
142
+ // they populate lives on the same persistence instance later writes
143
+ // resolve, whichever of the list item or the live graft won the pin.
144
+ const pinned = pinCurrent();
134
145
  const live = adapter.aui.threadListItem;
135
146
  const remoteId = live.source ? live.getState().remoteId : undefined;
136
147
  if (!remoteId) return { messages: [] };
137
- return getFormatted().load(remoteId);
148
+ return getTargetFormatted(pinned ?? live).load(remoteId);
138
149
  },
139
150
  };
140
151
  }
@@ -268,85 +279,12 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
268
279
  }
269
280
  }
270
281
 
271
- const MAX_SPAN_CONTENT = 50_000;
272
-
273
- function truncateStr(value: string): string {
274
- if (value.length <= MAX_SPAN_CONTENT) return value;
275
- return value.slice(0, MAX_SPAN_CONTENT);
276
- }
277
-
278
- function safeStringify(value: unknown): string | undefined {
279
- if (value == null) return undefined;
280
- try {
281
- return truncateStr(JSON.stringify(value));
282
- } catch {
283
- return undefined;
284
- }
285
- }
286
-
287
- type TelemetryToolCall = {
288
- tool_name: string;
289
- tool_call_id: string;
290
- tool_args?: string;
291
- tool_result?: string;
292
- tool_source?: "mcp" | "frontend" | "backend";
293
- };
294
-
295
- const BASE64_PATTERN = /^[A-Za-z0-9+/]{100,}={0,2}$/;
296
-
297
- function summarizeMcpResult(value: unknown): string | undefined {
298
- if (value == null) return undefined;
299
- try {
300
- const parsed = typeof value === "string" ? JSON.parse(value) : value;
301
- if (Array.isArray(parsed)) {
302
- const summarized = parsed.map((item) => {
303
- if (item && typeof item === "object" && item.type) {
304
- if (
305
- (item.type === "image" || item.type === "audio") &&
306
- typeof item.data === "string" &&
307
- BASE64_PATTERN.test(item.data.slice(0, 200))
308
- ) {
309
- const sizeKB = ((item.data.length * 3) / 4 / 1024).toFixed(1);
310
- return { ...item, data: `[${item.type}: ${sizeKB}KB]` };
311
- }
312
- }
313
- return item;
314
- });
315
- return truncateStr(JSON.stringify(summarized));
316
- }
317
- } catch {
318
- // not JSON array, fall through
319
- }
320
- return safeStringify(value);
321
- }
322
-
323
- function buildToolCall(
324
- toolName: string,
325
- toolCallId: string,
326
- args: unknown,
327
- result: unknown,
328
- argsText?: string,
329
- toolSource?: "mcp" | "frontend" | "backend",
330
- ): TelemetryToolCall {
331
- const call: TelemetryToolCall = {
332
- tool_name: toolName,
333
- tool_call_id: toolCallId,
334
- };
335
- const toolArgs = argsText ?? safeStringify(args);
336
- if (toolArgs !== undefined) call.tool_args = toolArgs;
337
- const toolResult =
338
- toolSource === "mcp" ? summarizeMcpResult(result) : safeStringify(result);
339
- if (toolResult !== undefined) call.tool_result = toolResult;
340
- if (toolSource) call.tool_source = toolSource;
341
- return call;
342
- }
343
-
344
282
  type TelemetryStepData = {
345
283
  input_tokens?: number;
346
284
  output_tokens?: number;
347
285
  reasoning_tokens?: number;
348
286
  cached_input_tokens?: number;
349
- tool_calls?: TelemetryToolCall[];
287
+ tool_calls?: AssistantCloudRunReportToolCall[];
350
288
  start_ms?: number;
351
289
  end_ms?: number;
352
290
  };
@@ -369,7 +307,7 @@ function mergeStepTimestamps(
369
307
 
370
308
  type TelemetryData = {
371
309
  status: "completed" | "incomplete" | "error";
372
- toolCalls?: TelemetryToolCall[];
310
+ toolCalls?: AssistantCloudRunReportToolCall[];
373
311
  totalSteps?: number;
374
312
  inputTokens?: number;
375
313
  outputTokens?: number;
@@ -426,14 +364,7 @@ export function extractAuiV0<T>(content: T): TelemetryData | null {
426
364
  }[];
427
365
  metadata?: {
428
366
  modelId?: string;
429
- steps?: readonly {
430
- usage?: {
431
- inputTokens?: number;
432
- outputTokens?: number;
433
- reasoningTokens?: number;
434
- cachedInputTokens?: number;
435
- };
436
- }[];
367
+ steps?: readonly { usage?: RunTelemetryUsageInit }[];
437
368
  custom?: Record<string, unknown> & { modelId?: string };
438
369
  };
439
370
  };
@@ -446,13 +377,19 @@ export function extractAuiV0<T>(content: T): TelemetryData | null {
446
377
  const toolCalls = msg.content
447
378
  ?.filter((p) => p.type === "tool-call" && p.toolName && p.toolCallId)
448
379
  .map((p) =>
449
- buildToolCall(p.toolName!, p.toolCallId!, p.args, p.result, p.argsText),
380
+ createRunTelemetryToolCall({
381
+ toolName: p.toolName!,
382
+ toolCallId: p.toolCallId!,
383
+ args: p.args,
384
+ result: p.result,
385
+ argsText: p.argsText,
386
+ }),
450
387
  );
451
388
 
452
389
  const textParts = msg.content?.filter((p) => p.type === "text" && p.text);
453
390
  const outputText =
454
391
  textParts && textParts.length > 0
455
- ? truncateStr(textParts.map((p) => p.text).join(""))
392
+ ? truncateRunTelemetryText(textParts.map((p) => p.text).join(""))
456
393
  : undefined;
457
394
 
458
395
  const steps = msg.metadata?.steps;
@@ -470,20 +407,23 @@ export function extractAuiV0<T>(content: T): TelemetryData | null {
470
407
  let hasReasoning = false;
471
408
  let hasCachedInput = false;
472
409
  for (const step of steps) {
473
- if (step.usage?.inputTokens != null) {
474
- totalInput += step.usage.inputTokens;
410
+ if (!step.usage) continue;
411
+ const usage = normalizeRunTelemetryUsage(step.usage);
412
+ if (!usage) continue;
413
+ if (usage.inputTokens != null) {
414
+ totalInput += usage.inputTokens;
475
415
  hasInput = true;
476
416
  }
477
- if (step.usage?.outputTokens != null) {
478
- totalOutput += step.usage.outputTokens;
417
+ if (usage.outputTokens != null) {
418
+ totalOutput += usage.outputTokens;
479
419
  hasOutput = true;
480
420
  }
481
- if (step.usage?.reasoningTokens != null) {
482
- totalReasoning += step.usage.reasoningTokens;
421
+ if (usage.reasoningTokens != null) {
422
+ totalReasoning += usage.reasoningTokens;
483
423
  hasReasoning = true;
484
424
  }
485
- if (step.usage?.cachedInputTokens != null) {
486
- totalCachedInput += step.usage.cachedInputTokens;
425
+ if (usage.cachedInputTokens != null) {
426
+ totalCachedInput += usage.cachedInputTokens;
487
427
  hasCachedInput = true;
488
428
  }
489
429
  }
@@ -506,20 +446,25 @@ export function extractAuiV0<T>(content: T): TelemetryData | null {
506
446
 
507
447
  const telemetrySteps: TelemetryStepData[] | undefined =
508
448
  steps && steps.length > 1
509
- ? steps.map((s) => ({
510
- ...(s.usage?.inputTokens != null
511
- ? { input_tokens: s.usage.inputTokens }
512
- : undefined),
513
- ...(s.usage?.outputTokens != null
514
- ? { output_tokens: s.usage.outputTokens }
515
- : undefined),
516
- ...(s.usage?.reasoningTokens != null
517
- ? { reasoning_tokens: s.usage.reasoningTokens }
518
- : undefined),
519
- ...(s.usage?.cachedInputTokens != null
520
- ? { cached_input_tokens: s.usage.cachedInputTokens }
521
- : undefined),
522
- }))
449
+ ? steps.map((s) => {
450
+ const usage = s.usage
451
+ ? normalizeRunTelemetryUsage(s.usage)
452
+ : undefined;
453
+ return {
454
+ ...(usage?.inputTokens != null
455
+ ? { input_tokens: usage.inputTokens }
456
+ : undefined),
457
+ ...(usage?.outputTokens != null
458
+ ? { output_tokens: usage.outputTokens }
459
+ : undefined),
460
+ ...(usage?.reasoningTokens != null
461
+ ? { reasoning_tokens: usage.reasoningTokens }
462
+ : undefined),
463
+ ...(usage?.cachedInputTokens != null
464
+ ? { cached_input_tokens: usage.cachedInputTokens }
465
+ : undefined),
466
+ };
467
+ })
523
468
  : undefined;
524
469
 
525
470
  return {
@@ -564,29 +509,28 @@ function isDynamicToolPart(p: AiSdkV6Part): boolean {
564
509
  return p.type === "dynamic-tool" || p.type.startsWith("dynamic-tool-");
565
510
  }
566
511
 
567
- function partToToolCall(p: AiSdkV6Part): TelemetryToolCall {
568
- const toolSource: "mcp" | undefined = isDynamicToolPart(p)
512
+ function partToToolCall(p: AiSdkV6Part): AssistantCloudRunReportToolCall {
513
+ const toolSource: "mcp" | "frontend" = isDynamicToolPart(p)
569
514
  ? "mcp"
570
- : undefined;
571
- return buildToolCall(
572
- p.toolName ?? p.type.slice(5),
573
- p.toolCallId!,
574
- p.args ?? p.input,
575
- p.result ?? p.output,
576
- undefined,
515
+ : "frontend";
516
+ return createRunTelemetryToolCall({
517
+ toolName: p.toolName ?? p.type.slice(5),
518
+ toolCallId: p.toolCallId!,
519
+ args: p.args ?? p.input,
520
+ result: p.result ?? p.output,
577
521
  toolSource,
578
- );
522
+ });
579
523
  }
580
524
 
581
525
  function collectAiSdkV6Parts(parts: readonly AiSdkV6Part[]): {
582
526
  textParts: string[];
583
- toolCalls: TelemetryToolCall[];
584
- stepsData: { tool_calls: TelemetryToolCall[] }[];
527
+ toolCalls: AssistantCloudRunReportToolCall[];
528
+ stepsData: { tool_calls: AssistantCloudRunReportToolCall[] }[];
585
529
  } {
586
530
  const textParts: string[] = [];
587
- const toolCalls: TelemetryToolCall[] = [];
588
- const stepsData: { tool_calls: TelemetryToolCall[] }[] = [];
589
- let currentStepToolCalls: TelemetryToolCall[] | null = null;
531
+ const toolCalls: AssistantCloudRunReportToolCall[] = [];
532
+ const stepsData: { tool_calls: AssistantCloudRunReportToolCall[] }[] = [];
533
+ let currentStepToolCalls: AssistantCloudRunReportToolCall[] | null = null;
590
534
 
591
535
  for (const p of parts) {
592
536
  if (p.type === "step-start") {
@@ -624,10 +568,10 @@ function extractModelId(
624
568
 
625
569
  function buildAiSdkV6Result(
626
570
  textParts: string[],
627
- toolCalls: TelemetryToolCall[],
571
+ toolCalls: AssistantCloudRunReportToolCall[],
628
572
  totalSteps: number,
629
573
  metadata?: Record<string, unknown>,
630
- stepsData?: { tool_calls: TelemetryToolCall[] }[],
574
+ stepsData?: { tool_calls: AssistantCloudRunReportToolCall[] }[],
631
575
  usage?: {
632
576
  inputTokens?: number;
633
577
  outputTokens?: number;
@@ -636,7 +580,9 @@ function buildAiSdkV6Result(
636
580
  },
637
581
  ): TelemetryData {
638
582
  const hasText = textParts.length > 0;
639
- const outputText = hasText ? truncateStr(textParts.join("")) : undefined;
583
+ const outputText = hasText
584
+ ? truncateRunTelemetryText(textParts.join(""))
585
+ : undefined;
640
586
  const modelId = extractModelId(metadata);
641
587
 
642
588
  const steps: TelemetryStepData[] | undefined =
@@ -671,46 +617,6 @@ function buildAiSdkV6Result(
671
617
  };
672
618
  }
673
619
 
674
- type UsageFields = {
675
- inputTokens?: number;
676
- outputTokens?: number;
677
- promptTokens?: number;
678
- completionTokens?: number;
679
- reasoningTokens?: number;
680
- cachedInputTokens?: number;
681
- };
682
-
683
- function normalizeUsage(u: UsageFields):
684
- | {
685
- inputTokens?: number;
686
- outputTokens?: number;
687
- reasoningTokens?: number;
688
- cachedInputTokens?: number;
689
- }
690
- | undefined {
691
- const input = u.inputTokens ?? u.promptTokens;
692
- const output = u.outputTokens ?? u.completionTokens;
693
- if (
694
- input == null &&
695
- output == null &&
696
- u.reasoningTokens == null &&
697
- u.cachedInputTokens == null
698
- ) {
699
- return undefined;
700
- }
701
-
702
- return {
703
- ...(input != null ? { inputTokens: input } : undefined),
704
- ...(output != null ? { outputTokens: output } : undefined),
705
- ...(u.reasoningTokens != null
706
- ? { reasoningTokens: u.reasoningTokens }
707
- : undefined),
708
- ...(u.cachedInputTokens != null
709
- ? { cachedInputTokens: u.cachedInputTokens }
710
- : undefined),
711
- };
712
- }
713
-
714
620
  function extractAiSdkV6Usage(metadata?: Record<string, unknown>):
715
621
  | {
716
622
  inputTokens?: number;
@@ -720,15 +626,15 @@ function extractAiSdkV6Usage(metadata?: Record<string, unknown>):
720
626
  }
721
627
  | undefined {
722
628
  // Try top-level metadata.usage
723
- const usage = metadata?.usage as UsageFields | undefined;
629
+ const usage = metadata?.usage as RunTelemetryUsageInit | undefined;
724
630
  if (usage) {
725
- const normalized = normalizeUsage(usage);
631
+ const normalized = normalizeRunTelemetryUsage(usage);
726
632
  if (normalized) return normalized;
727
633
  }
728
634
 
729
635
  // Try aggregating from metadata.steps[].usage
730
636
  const steps = metadata?.steps as
731
- | readonly { usage?: UsageFields }[]
637
+ | readonly { usage?: RunTelemetryUsageInit }[]
732
638
  | undefined;
733
639
  if (steps && steps.length > 0) {
734
640
  let inputTokens = 0;
@@ -742,7 +648,7 @@ function extractAiSdkV6Usage(metadata?: Record<string, unknown>):
742
648
  let hasAny = false;
743
649
  for (const s of steps) {
744
650
  if (!s.usage) continue;
745
- const n = normalizeUsage(s.usage);
651
+ const n = normalizeRunTelemetryUsage(s.usage);
746
652
  if (n) {
747
653
  if (n.inputTokens != null) {
748
654
  inputTokens += n.inputTokens;
@@ -795,8 +701,8 @@ function extractAiSdkV6<T>(content: T): TelemetryData | null {
795
701
 
796
702
  function aggregateAiSdkV6RunSteps<T>(stepMessages: T[]): TelemetryData | null {
797
703
  const allTextParts: string[] = [];
798
- const allToolCalls: TelemetryToolCall[] = [];
799
- const allStepsData: { tool_calls: TelemetryToolCall[] }[] = [];
704
+ const allToolCalls: AssistantCloudRunReportToolCall[] = [];
705
+ const allStepsData: { tool_calls: AssistantCloudRunReportToolCall[] }[] = [];
800
706
  let hasAssistant = false;
801
707
  let metadata: Record<string, unknown> | undefined;
802
708
  let inputTokens = 0;
@@ -2,6 +2,7 @@ import type {
2
2
  MessageStatus,
3
3
  SourceProviderMetadata,
4
4
  ThreadMessage,
5
+ ToolApprovalDisplay,
5
6
  ToolApprovalOption,
6
7
  } from "../../../types/message";
7
8
  import type { CompleteAttachment } from "../../../types/attachment";
@@ -16,11 +17,15 @@ import type { ExportedMessageRepositoryItem } from "../../../runtime/utils/messa
16
17
 
17
18
  type AuiV0ToolApproval = {
18
19
  readonly id: string;
20
+ readonly prompt?: string;
21
+ readonly display?: ToolApprovalDisplay;
22
+ readonly allowFreeform?: boolean;
19
23
  readonly approved?: boolean;
20
24
  readonly reason?: string;
21
25
  readonly isAutomatic?: boolean;
22
26
  readonly options?: readonly ToolApprovalOption[];
23
27
  readonly optionId?: string;
28
+ readonly text?: string;
24
29
  readonly resolution?: "cancelled" | "expired";
25
30
  };
26
31