@assistant-ui/core 0.2.10 → 0.2.11

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 (362) hide show
  1. package/dist/adapters/attachment.d.ts.map +1 -1
  2. package/dist/adapters/attachment.js +22 -12
  3. package/dist/adapters/attachment.js.map +1 -1
  4. package/dist/adapters/directive-formatter.js.map +1 -1
  5. package/dist/adapters/speech.js.map +1 -1
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.js +2 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal.js +1 -1
  10. package/dist/model-context/frame/host.js.map +1 -1
  11. package/dist/model-context/frame/provider.js.map +1 -1
  12. package/dist/model-context/registry.js.map +1 -1
  13. package/dist/model-context/types.js.map +1 -1
  14. package/dist/react/AssistantProvider.js +1 -1
  15. package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
  16. package/dist/react/AssistantRuntimeProvider.d.ts.map +1 -1
  17. package/dist/react/AssistantRuntimeProvider.js +1 -1
  18. package/dist/react/RuntimeAdapter.js +4 -2
  19. package/dist/react/RuntimeAdapter.js.map +1 -1
  20. package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
  21. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  22. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  23. package/dist/react/client/DataRenderers.js +6 -5
  24. package/dist/react/client/DataRenderers.js.map +1 -1
  25. package/dist/react/client/Interactables.d.ts.map +1 -1
  26. package/dist/react/client/Interactables.js +30 -29
  27. package/dist/react/client/Interactables.js.map +1 -1
  28. package/dist/react/client/Tools.d.ts.map +1 -1
  29. package/dist/react/client/Tools.js +10 -9
  30. package/dist/react/client/Tools.js.map +1 -1
  31. package/dist/react/index.d.ts +5 -4
  32. package/dist/react/index.js +3 -2
  33. package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
  34. package/dist/react/model-context/define-toolkit.d.ts +9 -12
  35. package/dist/react/model-context/define-toolkit.d.ts.map +1 -1
  36. package/dist/react/model-context/define-toolkit.js +1 -1
  37. package/dist/react/model-context/define-toolkit.js.map +1 -1
  38. package/dist/react/model-context/external-tool.d.ts +14 -0
  39. package/dist/react/model-context/external-tool.d.ts.map +1 -0
  40. package/dist/react/model-context/external-tool.js +17 -0
  41. package/dist/react/model-context/external-tool.js.map +1 -0
  42. package/dist/react/model-context/human-tool.d.ts +27 -0
  43. package/dist/react/model-context/human-tool.d.ts.map +1 -0
  44. package/dist/react/model-context/human-tool.js +30 -0
  45. package/dist/react/model-context/human-tool.js.map +1 -0
  46. package/dist/react/model-context/toolbox.d.ts +3 -3
  47. package/dist/react/model-context/toolbox.js.map +1 -1
  48. package/dist/react/model-context/useAssistantContext.js +1 -1
  49. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  50. package/dist/react/model-context/useAssistantDataUI.js +1 -1
  51. package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
  52. package/dist/react/model-context/useAssistantInstructions.js +1 -1
  53. package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
  54. package/dist/react/model-context/useAssistantInteractable.js +1 -1
  55. package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
  56. package/dist/react/model-context/useAssistantTool.js +1 -1
  57. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  58. package/dist/react/model-context/useAssistantToolUI.js +1 -1
  59. package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
  60. package/dist/react/model-context/useAuiToolOverrides.js +1 -1
  61. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  62. package/dist/react/model-context/useInlineRender.js +1 -1
  63. package/dist/react/model-context/useInlineRender.js.map +1 -1
  64. package/dist/react/model-context/useInteractableState.js +1 -1
  65. package/dist/react/model-context/useInteractableState.js.map +1 -1
  66. package/dist/react/model-context/useToolArgsStatus.js +1 -1
  67. package/dist/react/primitive-hooks/useActionBarCopy.js +1 -1
  68. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  69. package/dist/react/primitive-hooks/useActionBarEdit.js +1 -1
  70. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  71. package/dist/react/primitive-hooks/useActionBarFeedback.js +1 -1
  72. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  73. package/dist/react/primitive-hooks/useActionBarReload.js +1 -1
  74. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  75. package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -1
  76. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  77. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -1
  78. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  79. package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -1
  80. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  81. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -1
  82. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  83. package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -1
  84. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  85. package/dist/react/primitive-hooks/useComposerCancel.js +1 -1
  86. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  87. package/dist/react/primitive-hooks/useComposerDictate.js +1 -1
  88. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  89. package/dist/react/primitive-hooks/useComposerSend.js +1 -1
  90. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  91. package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -1
  92. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  93. package/dist/react/primitive-hooks/useEditComposerSend.js +1 -1
  94. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  95. package/dist/react/primitive-hooks/useMessageBranching.js +1 -1
  96. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  97. package/dist/react/primitive-hooks/useMessageReload.js +1 -1
  98. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  99. package/dist/react/primitive-hooks/useSuggestionTrigger.js +1 -1
  100. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  101. package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -1
  102. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  103. package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -1
  104. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  105. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -1
  106. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  107. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -1
  108. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  109. package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -1
  110. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  111. package/dist/react/primitive-hooks/useThreadListNew.js +1 -1
  112. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  113. package/dist/react/primitive-hooks/useVoice.js +1 -1
  114. package/dist/react/primitive-hooks/useVoice.js.map +1 -1
  115. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts +1 -1
  116. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
  117. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  118. package/dist/react/primitives/composer/ComposerAttachments.js +1 -1
  119. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  120. package/dist/react/primitives/composer/ComposerQueue.js +1 -1
  121. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  122. package/dist/react/primitives/generativeUI/GenerativeUI.js +1 -1
  123. package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
  124. package/dist/react/primitives/message/MessageAttachments.js +1 -1
  125. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  126. package/dist/react/primitives/message/MessageGroupedParts.js +1 -1
  127. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  128. package/dist/react/primitives/message/MessageParts.d.ts +1 -1
  129. package/dist/react/primitives/message/MessageParts.js +1 -1
  130. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  131. package/dist/react/primitives/message/MessageQuote.js +1 -1
  132. package/dist/react/primitives/part/PartMessages.d.ts +2 -2
  133. package/dist/react/primitives/part/PartMessages.js +3 -3
  134. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  135. package/dist/react/primitives/thread/ThreadMessages.js +1 -1
  136. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  137. package/dist/react/primitives/thread/ThreadSuggestions.js +1 -1
  138. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  139. package/dist/react/primitives/threadList/ThreadListItems.js +1 -1
  140. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  141. package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
  142. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  143. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  144. package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
  145. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  146. package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
  147. package/dist/react/providers/ReadonlyThreadProvider.js +1 -1
  148. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  149. package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
  150. package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
  151. package/dist/react/providers/TextMessagePartProvider.js +4 -3
  152. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  153. package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
  154. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -0
  155. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  156. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -1
  157. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  158. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -0
  159. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  160. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -1
  161. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  162. package/dist/react/runtimes/RuntimeAdapterProvider.js +1 -1
  163. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +1 -1
  164. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  165. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +1 -1
  166. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  167. package/dist/react/runtimes/createMessageConverter.d.ts +2 -2
  168. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  169. package/dist/react/runtimes/createMessageConverter.js.map +1 -1
  170. package/dist/react/runtimes/external-message-converter.d.ts +4 -3
  171. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  172. package/dist/react/runtimes/external-message-converter.js +1 -1
  173. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  174. package/dist/react/runtimes/useExternalStoreRuntime.js +1 -1
  175. package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -1
  176. package/dist/react/runtimes/useLocalRuntime.d.ts +2 -1
  177. package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
  178. package/dist/react/runtimes/useLocalRuntime.js +4 -3
  179. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  180. package/dist/react/runtimes/useRemoteThreadListRuntime.js +1 -1
  181. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  182. package/dist/react/utils/groupParts.d.ts +1 -1
  183. package/dist/react/utils/groupParts.js.map +1 -1
  184. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  185. package/dist/runtime/api/composer-runtime.d.ts +8 -2
  186. package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
  187. package/dist/runtime/api/composer-runtime.js +14 -0
  188. package/dist/runtime/api/composer-runtime.js.map +1 -1
  189. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  190. package/dist/runtime/api/message-runtime.js +1 -1
  191. package/dist/runtime/api/message-runtime.js.map +1 -1
  192. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  193. package/dist/runtime/api/thread-runtime.d.ts +7 -0
  194. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  195. package/dist/runtime/api/thread-runtime.js.map +1 -1
  196. package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -0
  197. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  198. package/dist/runtime/base/base-composer-runtime-core.js +7 -1
  199. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  200. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  201. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +4 -0
  202. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  203. package/dist/runtime/base/default-thread-composer-runtime-core.js +17 -1
  204. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  205. package/dist/runtime/interfaces/composer-runtime-core.d.ts +6 -1
  206. package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
  207. package/dist/runtime/interfaces/thread-runtime-core.d.ts +4 -0
  208. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  209. package/dist/runtime/queue/external-thread-queue-adapter.d.ts +20 -0
  210. package/dist/runtime/queue/external-thread-queue-adapter.d.ts.map +1 -0
  211. package/dist/runtime/queue/external-thread-queue-adapter.js +0 -0
  212. package/dist/runtime/queue/message-queue.d.ts +20 -0
  213. package/dist/runtime/queue/message-queue.d.ts.map +1 -0
  214. package/dist/runtime/queue/message-queue.js +97 -0
  215. package/dist/runtime/queue/message-queue.js.map +1 -0
  216. package/dist/runtime/utils/message-repository.js.map +1 -1
  217. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  218. package/dist/runtimes/external-store/external-store-adapter.d.ts +3 -1
  219. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  220. package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
  221. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +4 -0
  222. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  223. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +20 -2
  224. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  225. package/dist/runtimes/local/local-runtime-core.js.map +1 -1
  226. package/dist/runtimes/local/local-runtime-options.d.ts +5 -0
  227. package/dist/runtimes/local/local-runtime-options.d.ts.map +1 -1
  228. package/dist/runtimes/local/local-thread-runtime-core.d.ts +7 -0
  229. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  230. package/dist/runtimes/local/local-thread-runtime-core.js +45 -0
  231. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  232. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +3 -0
  233. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  234. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +3 -0
  235. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  236. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
  237. package/dist/runtimes/remote-thread-list/empty-thread-core.js +3 -0
  238. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  239. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  240. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  241. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  242. package/dist/store/clients/chain-of-thought-client.js +6 -5
  243. package/dist/store/clients/chain-of-thought-client.js.map +1 -1
  244. package/dist/store/clients/model-context-client.d.ts.map +1 -1
  245. package/dist/store/clients/model-context-client.js +6 -5
  246. package/dist/store/clients/model-context-client.js.map +1 -1
  247. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
  248. package/dist/store/clients/no-op-composer-client.js +4 -3
  249. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  250. package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
  251. package/dist/store/clients/runtime-adapter.js +7 -6
  252. package/dist/store/clients/runtime-adapter.js.map +1 -1
  253. package/dist/store/clients/suggestions.d.ts.map +1 -1
  254. package/dist/store/clients/suggestions.js +7 -6
  255. package/dist/store/clients/suggestions.js.map +1 -1
  256. package/dist/store/clients/thread-message-client.d.ts.map +1 -1
  257. package/dist/store/clients/thread-message-client.js +13 -12
  258. package/dist/store/clients/thread-message-client.js.map +1 -1
  259. package/dist/store/index.d.ts +1 -1
  260. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  261. package/dist/store/runtime-clients/attachment-runtime-client.js +3 -3
  262. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
  263. package/dist/store/runtime-clients/composer-runtime-client.d.ts +12 -5
  264. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  265. package/dist/store/runtime-clients/composer-runtime-client.js +32 -16
  266. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
  267. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
  268. package/dist/store/runtime-clients/message-part-runtime-client.js +3 -3
  269. package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
  270. package/dist/store/runtime-clients/message-runtime-client.d.ts +6 -3
  271. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  272. package/dist/store/runtime-clients/message-runtime-client.js +17 -16
  273. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
  274. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  275. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +8 -7
  276. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  277. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  278. package/dist/store/runtime-clients/thread-list-runtime-client.js +11 -10
  279. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  280. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  281. package/dist/store/runtime-clients/thread-runtime-client.js +15 -14
  282. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  283. package/dist/store/runtime-clients/useSubscribable.d.ts +7 -0
  284. package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -0
  285. package/dist/store/runtime-clients/useSubscribable.js +16 -0
  286. package/dist/store/runtime-clients/useSubscribable.js.map +1 -0
  287. package/dist/store/scope-registration.d.ts +1 -1
  288. package/dist/store/scopes/composer.d.ts +1 -1
  289. package/dist/store/scopes/queue-item.d.ts +2 -1
  290. package/dist/store/scopes/queue-item.d.ts.map +1 -1
  291. package/dist/store/scopes/queue-item.js +6 -0
  292. package/dist/store/scopes/queue-item.js.map +1 -0
  293. package/dist/store/scopes/thread.d.ts +1 -1
  294. package/dist/store/scopes/threads.d.ts +1 -1
  295. package/dist/types/message.d.ts +2 -1
  296. package/dist/types/message.d.ts.map +1 -1
  297. package/dist/types/message.js.map +1 -1
  298. package/dist/utils/composite-context-provider.d.ts +1 -1
  299. package/dist/utils/composite-context-provider.js +3 -1
  300. package/dist/utils/composite-context-provider.js.map +1 -1
  301. package/dist/utils/json/is-json.js.map +1 -1
  302. package/dist/utils/text.js.map +1 -1
  303. package/package.json +14 -10
  304. package/src/adapters/attachment.ts +24 -4
  305. package/src/index.ts +8 -0
  306. package/src/react/RuntimeAdapter.ts +6 -4
  307. package/src/react/client/DataRenderers.ts +48 -42
  308. package/src/react/client/Interactables.ts +263 -267
  309. package/src/react/client/Tools.ts +122 -129
  310. package/src/react/index.ts +3 -1
  311. package/src/react/model-context/define-toolkit.test.ts +14 -7
  312. package/src/react/model-context/define-toolkit.ts +18 -19
  313. package/src/react/model-context/external-tool.ts +16 -0
  314. package/src/react/model-context/{hitl.ts → human-tool.ts} +13 -8
  315. package/src/react/model-context/toolbox.ts +3 -3
  316. package/src/react/primitives/message/MessageGroupedParts.tsx +1 -1
  317. package/src/react/primitives/part/PartMessages.tsx +2 -2
  318. package/src/react/providers/TextMessagePartProvider.tsx +31 -32
  319. package/src/react/runtimes/createMessageConverter.ts +2 -1
  320. package/src/react/runtimes/external-message-converter.ts +5 -3
  321. package/src/react/runtimes/useLocalRuntime.ts +2 -0
  322. package/src/runtime/api/composer-runtime.ts +26 -0
  323. package/src/runtime/base/base-composer-runtime-core.ts +11 -0
  324. package/src/runtime/base/default-thread-composer-runtime-core.ts +22 -0
  325. package/src/runtime/interfaces/composer-runtime-core.ts +7 -0
  326. package/src/runtime/interfaces/thread-runtime-core.ts +5 -0
  327. package/src/runtime/queue/external-thread-queue-adapter.ts +14 -0
  328. package/src/runtime/queue/message-queue.ts +128 -0
  329. package/src/runtimes/external-store/external-store-adapter.ts +3 -0
  330. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -2
  331. package/src/runtimes/local/local-runtime-options.ts +6 -0
  332. package/src/runtimes/local/local-thread-runtime-core.ts +70 -0
  333. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +4 -0
  334. package/src/runtimes/remote-thread-list/empty-thread-core.ts +4 -0
  335. package/src/store/clients/chain-of-thought-client.ts +24 -25
  336. package/src/store/clients/model-context-client.ts +22 -19
  337. package/src/store/clients/no-op-composer-client.ts +69 -66
  338. package/src/store/clients/runtime-adapter.ts +9 -6
  339. package/src/store/clients/suggestions.ts +41 -40
  340. package/src/store/clients/thread-message-client.ts +127 -132
  341. package/src/store/runtime-clients/attachment-runtime-client.ts +7 -3
  342. package/src/store/runtime-clients/composer-runtime-client.ts +142 -113
  343. package/src/store/runtime-clients/message-part-runtime-client.ts +16 -14
  344. package/src/store/runtime-clients/message-runtime-client.ts +124 -122
  345. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +44 -45
  346. package/src/store/runtime-clients/thread-list-runtime-client.ts +83 -80
  347. package/src/store/runtime-clients/thread-runtime-client.ts +113 -119
  348. package/src/store/runtime-clients/{tap-subscribable.ts → useSubscribable.ts} +4 -4
  349. package/src/store/scopes/queue-item.ts +2 -0
  350. package/src/tests/attachment-adapters.test.ts +86 -0
  351. package/src/tests/external-store-thread-runtime-core.test.ts +125 -0
  352. package/src/tests/message-queue.test.ts +168 -0
  353. package/src/types/message.ts +2 -0
  354. package/src/utils/composite-context-provider.ts +3 -1
  355. package/dist/react/model-context/hitl.d.ts +0 -23
  356. package/dist/react/model-context/hitl.d.ts.map +0 -1
  357. package/dist/react/model-context/hitl.js +0 -26
  358. package/dist/react/model-context/hitl.js.map +0 -1
  359. package/dist/store/runtime-clients/tap-subscribable.d.ts +0 -7
  360. package/dist/store/runtime-clients/tap-subscribable.d.ts.map +0 -1
  361. package/dist/store/runtime-clients/tap-subscribable.js +0 -16
  362. package/dist/store/runtime-clients/tap-subscribable.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ToolInvocationTracker.js","names":[],"sources":["../../../src/runtimes/tool-invocations/ToolInvocationTracker.ts"],"sourcesContent":["declare const process: { env: { NODE_ENV?: string } };\n\nimport {\n createAssistantStreamController,\n type ToolCallStreamController,\n ToolResponse,\n unstable_toolResultStream,\n type Tool,\n type ToolModelContentPart,\n} from \"assistant-stream\";\nimport {\n AssistantMetaTransformStream,\n type ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport { isJSONValueEqual } from \"../../utils/json/is-json-equal\";\nimport type { ThreadMessage } from \"../../types/message\";\n\n/**\n * Streaming execution state for a frontend tool.\n */\nexport type ToolExecutionStatus =\n | { type: \"executing\" }\n | {\n type: \"interrupt\";\n payload: { type: \"human\"; payload: unknown };\n };\n\nexport type AddToolResultCommand = {\n readonly type: \"add-tool-result\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly result: ReadonlyJSONValue;\n readonly isError: boolean;\n readonly artifact?: ReadonlyJSONValue;\n readonly modelContent?: readonly ToolModelContentPart[];\n};\n\nexport type ToolInvocationTrackerSnapshot = {\n readonly messages: readonly ThreadMessage[];\n /** Whether the producing runtime is currently streaming new output. */\n readonly isRunning: boolean;\n /**\n * Whether the producing runtime is still loading historical state.\n * When `true`, every snapshot is treated as historical (no `streamCall` /\n * `execute` fires). When `false`, processing resumes as live.\n */\n readonly isLoading?: boolean;\n};\n\nexport type ToolInvocationTrackerCallbacks = {\n /**\n * Invoked when a client-side `execute()` returns a result and the runtime\n * needs to feed it back into the conversation.\n */\n onResult: (command: AddToolResultCommand) => void;\n /**\n * Invoked whenever the per-tool-call status map changes (executing /\n * interrupt / cleared). The callback receives a fresh map; mutating the\n * argument is not supported.\n */\n onStatusesChange: (\n statuses: ReadonlyMap<string, ToolExecutionStatus>,\n ) => void;\n};\n\ntype ToolCallEntry = {\n toolName: string;\n argsText: string;\n hasResult: boolean;\n} & (\n | {\n /** Restored phase — observed during a history-load snapshot. */\n controller?: undefined;\n argsComplete?: undefined;\n }\n | {\n /** Active phase — chunks are flowing through `controller`. */\n controller: ToolCallStreamController;\n argsComplete: boolean;\n }\n);\n\nconst isArgsTextComplete = (argsText: string) => {\n try {\n JSON.parse(argsText);\n return true;\n } catch {\n return false;\n }\n};\n\nconst parseArgsText = (argsText: string) => {\n try {\n return JSON.parse(argsText);\n } catch {\n return undefined;\n }\n};\n\nconst isEquivalentCompleteArgsText = (previous: string, next: string) => {\n const previousValue = parseArgsText(previous);\n const nextValue = parseArgsText(next);\n if (previousValue === undefined || nextValue === undefined) return false;\n return isJSONValueEqual(previousValue, nextValue);\n};\n\n/**\n * Plain-class port of the former `useToolInvocations` React hook. Owns the\n * assistant-stream pipeline that drives client-side `streamCall` / `execute`\n * for tool-call parts surfaced by a thread runtime, plus the per-tool-call\n * status map that consumers render against.\n *\n * **Contract**: `streamCall` (and `execute`) fires exactly once per logical\n * `toolCallId`. Args mutations after first completion, result replacement,\n * and result clearing are *not* surfaced through additional `streamCall`\n * invocations — by design — so hosts cannot observe spurious re-fires of\n * side effects. The follow-up `reader.events()` API will expose those\n * post-completion transitions to consumers that opt in.\n *\n * State-transition safety: every public method that observes runtime state\n * (`setState`, `reset`, `abort`, `resume`) wraps its work in try/catch and\n * logs to `console.error` rather than throwing. The tracker is built into\n * the hot message-processing path, so a malformed snapshot must never crash\n * the host runtime. See ./EDGE_CASES.md for the known non-trivial state\n * transitions and what each does today.\n */\nexport class ToolInvocationTracker {\n private readonly _getTools: () => Record<string, Tool> | undefined;\n private readonly _callbacks: ToolInvocationTrackerCallbacks;\n\n private readonly _entries = new Map<string, ToolCallEntry>();\n /**\n * Tool call ids whose `execute` should be short-circuited in the wrapper.\n * Populated when an entry is created with a result already attached\n * (history reload, mid-run resume, etc.) — `execute` is suppressed so\n * client-side side effects don't double-run. Membership outlives the\n * entry: `reset()` deliberately does *not* clear this so post-abort\n * cancellation `result` chunks for pre-resolved entries can still be\n * recognized and dropped. Growth is bounded by the number of pre-resolved\n * tool calls observed in the session.\n */\n private readonly _skipExecuteStreamIds = new Set<string>();\n private readonly _humanInput = new Map<\n string,\n {\n resolve: (payload: unknown) => void;\n reject: (reason: unknown) => void;\n }\n >();\n /** In-flight `execute` invocations keyed by tool call id. */\n private readonly _executing = new Set<string>();\n private readonly _settledResolvers: Array<() => void> = [];\n\n private _statuses = new Map<string, ToolExecutionStatus>();\n\n private _ac: AbortController = new AbortController();\n private _pendingRestore = true;\n\n /** Cached last snapshot, used to skip processing on identical re-renders. */\n private _lastSnapshot: ToolInvocationTrackerSnapshot | null = null;\n private _isRunning = false;\n\n private _controller!: ReturnType<typeof createAssistantStreamController>[1];\n\n /**\n * Set when the assistant-stream pipeline has died (errored out via\n * `.pipeTo(...).catch(...)`). The next `setState` re-initializes the\n * pipeline and demotes all active entries to restored so they survive\n * across the restart without re-firing `streamCall` (preserves the\n * \"exactly once\" contract). Capped at a single auto-restart per session\n * — repeated failures keep the tracker dead with a more visible error.\n */\n private _pipelineDead = false;\n private _pipelineRestartUsed = false;\n\n constructor(\n getTools: () => Record<string, Tool> | undefined,\n callbacks: ToolInvocationTrackerCallbacks,\n ) {\n this._getTools = getTools;\n this._callbacks = callbacks;\n\n this._initPipeline();\n }\n\n /**\n * Build the assistant-stream pipeline. Called once from the constructor\n * and at most once again if `_pipelineDead` is set (see F.4 in\n * EDGE_CASES.md).\n */\n private _initPipeline(): void {\n const [stream, controller] = createAssistantStreamController();\n this._controller = controller;\n\n const transform = unstable_toolResultStream(\n () => this._getWrappedTools(),\n () => this._ac.signal,\n (toolCallId, payload) => this._onHumanInput(toolCallId, payload),\n {\n onExecutionStart: (id) => this._onExecutionStart(id),\n onExecutionEnd: (id) => this._onExecutionEnd(id),\n },\n );\n\n stream\n .pipeThrough(transform)\n .pipeThrough(new AssistantMetaTransformStream())\n .pipeTo(\n new WritableStream({\n write: (chunk) => {\n try {\n if (chunk.type !== \"result\") return;\n this._handleResultChunk(chunk);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] result chunk handling failed\",\n err,\n );\n }\n },\n }),\n )\n .catch((err) => {\n console.error(\n \"[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState\",\n err,\n );\n this._pipelineDead = true;\n });\n }\n\n // ───────────────────────── public API ─────────────────────────\n\n /**\n * Feed the next observed snapshot into the tracker. Called from the host\n * runtime whenever its message list / running state changes.\n */\n public setState(snapshot: ToolInvocationTrackerSnapshot): void {\n try {\n // Recover from a dead pipeline before processing anything. We demote\n // all active entries to \"restored\" so the rebuilt pipeline does not\n // re-fire `streamCall` for tool calls that already fired pre-death;\n // preserves the \"exactly once per toolCallId\" contract.\n if (this._pipelineDead) {\n if (this._pipelineRestartUsed) {\n // Already retried once and failed again. Stay dead.\n return;\n }\n this._pipelineRestartUsed = true;\n this._pipelineDead = false;\n this._demoteEntriesToRestored();\n this._executing.clear();\n this._ac = new AbortController();\n this._initPipeline();\n // Fall through and process the snapshot against the fresh pipeline.\n }\n\n // Identical snapshot — skip processing entirely. Note: external-store\n // runtimes rebuild the messages array on every adapter update, so this\n // fast-path rarely triggers there; it's primarily for the React-hook\n // shim where state references are stable.\n if (\n this._lastSnapshot &&\n this._lastSnapshot.messages === snapshot.messages &&\n this._lastSnapshot.isRunning === snapshot.isRunning &&\n this._lastSnapshot.isLoading === snapshot.isLoading\n ) {\n return;\n }\n\n // While the host is still loading initial state, treat every snapshot\n // as historical: tool calls are recorded so the next live snapshot can\n // diff against them, but `streamCall` / `execute` do not fire.\n const restoreFromLoading = snapshot.isLoading === true;\n if (restoreFromLoading) {\n this._pendingRestore = true;\n }\n\n // E.4 / AF3 — only mark `_lastSnapshot`/`_isRunning` as observed after\n // processing succeeds. If `_processMessages` throws, the next snapshot\n // (even if identical) gets re-processed against the recovered state.\n const previousIsRunning = this._isRunning;\n this._isRunning = snapshot.isRunning;\n try {\n this._processMessages(snapshot.messages);\n } catch (err) {\n this._isRunning = previousIsRunning;\n throw err;\n }\n this._lastSnapshot = snapshot;\n this._pendingRestore = false;\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] setState failed; snapshot dropped\",\n err,\n );\n }\n }\n\n /**\n * Reset the tracker so the next observed snapshot is treated as historical.\n * Clears entries and aborts any in-flight executions. Used by callers like\n * `importExternalState` to mark a freshly loaded state as restored.\n */\n public reset(): void {\n try {\n this._pendingRestore = true;\n this._entries.clear();\n this._lastSnapshot = null;\n // `_skipExecuteStreamIds` is intentionally not cleared — see field doc.\n void this.abort().finally(() => {\n this._executing.clear();\n });\n } catch (err) {\n console.error(\"[ToolInvocationTracker] reset failed\", err);\n }\n }\n\n /**\n * Abort any in-flight `execute()` invocations. Resolves once all of them\n * have settled (or immediately if none are running).\n */\n public abort(): Promise<void> {\n try {\n this._humanInput.forEach(({ reject }) => {\n try {\n reject(new Error(\"Tool execution aborted\"));\n } catch {\n // host rejection handler threw — already in the abort path,\n // swallow so we continue cleaning up.\n }\n });\n this._humanInput.clear();\n\n this._ac.abort();\n this._ac = new AbortController();\n\n if (this._executing.size === 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve) => {\n this._settledResolvers.push(resolve);\n });\n } catch (err) {\n console.error(\"[ToolInvocationTracker] abort failed\", err);\n return Promise.resolve();\n }\n }\n\n /**\n * Resolve a pending human-input request for the given tool call. Returns\n * `true` if a pending request was resumed, `false` if the tracker has no\n * outstanding request for that id (the caller should fall back to its own\n * dispatch path).\n */\n public resume(toolCallId: string, payload: unknown): boolean {\n try {\n const handlers = this._humanInput.get(toolCallId);\n if (!handlers) return false;\n this._humanInput.delete(toolCallId);\n this._setStatus(toolCallId, { type: \"executing\" });\n handlers.resolve(payload);\n return true;\n } catch (err) {\n console.error(\"[ToolInvocationTracker] resume failed\", err);\n return false;\n }\n }\n\n /**\n * Returns the current tool execution status map. The returned `Map` is\n * the tracker's internal store — do not mutate it. Treat the reference\n * as a snapshot that may be replaced wholesale on the next status\n * transition.\n */\n public getStatuses(): ReadonlyMap<string, ToolExecutionStatus> {\n return this._statuses;\n }\n\n // ───────────────────── internal: tool wrapping ─────────────────────\n\n private _getWrappedTools(): Record<string, Tool> | undefined {\n const tools = this._getTools();\n if (!tools) return undefined;\n\n return Object.fromEntries(\n Object.entries(tools).map(([name, tool]) => {\n const execute = tool.execute;\n if (execute === undefined) return [name, tool];\n\n const wrappedTool = {\n ...tool,\n execute: (\n ...[args, context]: Parameters<NonNullable<typeof execute>>\n ) => {\n if (this._skipExecuteStreamIds.has(context.toolCallId)) {\n // Pre-resolved tool call: never invoke the host's execute.\n // Returning a never-settling Promise keeps the executor's\n // pending entry alive but enqueues nothing.\n return new Promise(() => {}) as never;\n }\n return execute(args, context);\n },\n } as Tool;\n return [name, wrappedTool];\n }),\n ) as Record<string, Tool>;\n }\n\n // ──────────────── internal: execution lifecycle callbacks ────────────────\n\n private _onHumanInput(\n toolCallId: string,\n payload: unknown,\n ): Promise<unknown> {\n return new Promise<unknown>((resolve, reject) => {\n const previous = this._humanInput.get(toolCallId);\n if (previous) {\n try {\n previous.reject(\n new Error(\"Human input request was superseded by a new request\"),\n );\n } catch {\n // host rejection handler threw; ignore and proceed\n }\n }\n this._humanInput.set(toolCallId, { resolve, reject });\n this._setStatus(toolCallId, {\n type: \"interrupt\",\n payload: { type: \"human\", payload },\n });\n });\n }\n\n private _onExecutionStart(toolCallId: string): void {\n if (this._skipExecuteStreamIds.has(toolCallId)) return;\n\n this._executing.add(toolCallId);\n this._setStatus(toolCallId, { type: \"executing\" });\n }\n\n private _onExecutionEnd(toolCallId: string): void {\n if (!this._executing.delete(toolCallId)) return;\n\n this._deleteStatus(toolCallId);\n\n if (this._executing.size === 0) {\n const resolvers = this._settledResolvers.splice(0);\n resolvers.forEach((resolve) => {\n try {\n resolve();\n } catch {\n // ignore — settled-resolver consumer threw\n }\n });\n }\n }\n\n private _handleResultChunk(chunk: {\n type: \"result\";\n result: ReadonlyJSONValue;\n isError: boolean;\n artifact?: ReadonlyJSONValue;\n modelContent?: readonly ToolModelContentPart[];\n meta: { toolCallId: string; toolName: string };\n }): void {\n const toolCallId = chunk.meta.toolCallId;\n const entry = this._entries.get(toolCallId);\n\n // Pre-resolved tool call whose entry has been cleared by `reset()`.\n // The post-abort cancellation chunk lands here after the entry is\n // gone; suppress via the long-lived skip-execute marker.\n if (!entry && this._skipExecuteStreamIds.has(toolCallId)) {\n return;\n }\n\n // The host already set the result (via the live snapshot's\n // `setResponse` path). Suppress the executor's redundant emit.\n if (entry?.hasResult) return;\n\n this._invokeOnResult({\n type: \"add-tool-result\",\n toolCallId,\n toolName: chunk.meta.toolName,\n result: chunk.result,\n isError: chunk.isError,\n ...(chunk.artifact !== undefined && { artifact: chunk.artifact }),\n ...(chunk.modelContent !== undefined && {\n modelContent: chunk.modelContent,\n }),\n });\n }\n\n // ──────────────── internal: callback invocation (AF1/AF2) ────────────────\n\n private _invokeOnResult(command: AddToolResultCommand): void {\n try {\n this._callbacks.onResult(command);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] onResult callback threw; result dropped\",\n err,\n );\n }\n }\n\n private _invokeOnStatusesChange(): void {\n try {\n this._callbacks.onStatusesChange(this._statuses);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated\",\n err,\n );\n }\n }\n\n // ──────────────── internal: status map mutations ────────────────\n\n private _setStatus(toolCallId: string, status: ToolExecutionStatus): void {\n const next = new Map(this._statuses);\n next.set(toolCallId, status);\n this._statuses = next;\n this._invokeOnStatusesChange();\n }\n\n private _deleteStatus(toolCallId: string): void {\n if (!this._statuses.has(toolCallId)) return;\n const next = new Map(this._statuses);\n next.delete(toolCallId);\n this._statuses = next;\n this._invokeOnStatusesChange();\n }\n\n // ──────────────── internal: snapshot processing ────────────────\n\n private _hasExecutableTool(toolName: string): boolean {\n const tool = this._getTools()?.[toolName];\n return tool?.execute !== undefined || tool?.streamCall !== undefined;\n }\n\n private _shouldCloseArgsStream({\n toolName,\n argsText,\n hasResult,\n }: {\n toolName: string;\n argsText: string;\n hasResult: boolean;\n }): boolean {\n if (hasResult) return true;\n if (!this._hasExecutableTool(toolName)) {\n return !this._isRunning && isArgsTextComplete(argsText);\n }\n return isArgsTextComplete(argsText);\n }\n\n private _startActiveEntry(\n toolCallId: string,\n toolName: string,\n skipExecute: boolean,\n ): ToolCallEntry {\n const toolCallController = this._controller.addToolCallPart({\n toolName,\n toolCallId,\n });\n if (skipExecute) {\n this._skipExecuteStreamIds.add(toolCallId);\n }\n const entry: ToolCallEntry = {\n toolName,\n controller: toolCallController,\n argsText: \"\",\n hasResult: false,\n argsComplete: false,\n };\n this._entries.set(toolCallId, entry);\n return entry;\n }\n\n /**\n * Demote every active entry back to the restored phase. Used by the\n * pipeline-restart path so that, after a fresh pipeline is built, the\n * next observed snapshot does not re-fire `streamCall` for tool calls\n * that already fired pre-death. Args / hasResult tracking is preserved\n * so signature comparisons still work.\n */\n private _demoteEntriesToRestored(): void {\n for (const [toolCallId, entry] of this._entries) {\n if (!entry.controller) continue;\n this._entries.set(toolCallId, {\n toolName: entry.toolName,\n argsText: entry.argsText,\n hasResult: entry.hasResult,\n });\n }\n }\n\n private _processArgsText(\n entry: ToolCallEntry,\n content: {\n toolCallId: string;\n toolName: string;\n argsText: string;\n result?: unknown;\n },\n ): void {\n if (!entry.controller) return;\n const hasResult = content.result !== undefined;\n\n if (content.argsText !== entry.argsText) {\n let shouldWriteArgsText = true;\n\n if (entry.argsComplete) {\n if (isEquivalentCompleteArgsText(entry.argsText, content.argsText)) {\n // A.3 — key reorder. Track new text, no re-fire needed.\n entry.argsText = content.argsText;\n shouldWriteArgsText = false;\n } else {\n // A.4 — args changed after first completion. Under the\n // \"exactly once per toolCallId\" contract we do not restart the\n // stream. The host's existing `streamCall` keeps its original\n // args view; the snapshot's new text is recorded for diffing\n // but not surfaced. Events API in a follow-up will expose this\n // to consumers that opt in.\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n \"[ToolInvocationTracker] argsText changed after first completion; not re-firing streamCall (see EDGE_CASES.md A.4)\",\n {\n previous: entry.argsText,\n next: content.argsText,\n toolCallId: content.toolCallId,\n },\n );\n }\n shouldWriteArgsText = false;\n }\n } else if (!content.argsText.startsWith(entry.argsText)) {\n if (\n isArgsTextComplete(entry.argsText) &&\n isArgsTextComplete(content.argsText) &&\n isEquivalentCompleteArgsText(entry.argsText, content.argsText)\n ) {\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = shouldClose;\n shouldWriteArgsText = false;\n } else {\n // A.2 — args regressed mid-stream. Under the \"exactly once\"\n // contract we do not restart. The controller keeps whatever\n // prefix we already streamed; subsequent prefix-respecting\n // updates can still flow against it. Snapshots that never\n // re-converge to a prefix will leave the controller's args\n // view stale relative to the snapshot. Events API in a\n // follow-up will expose this to consumers that opt in.\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n \"[ToolInvocationTracker] argsText regressed mid-stream; not restarting (see EDGE_CASES.md A.2)\",\n {\n previous: entry.argsText,\n next: content.argsText,\n toolCallId: content.toolCallId,\n },\n );\n }\n shouldWriteArgsText = false;\n }\n }\n\n if (shouldWriteArgsText && entry.controller) {\n const delta = content.argsText.slice(entry.argsText.length);\n entry.controller.argsText.append(delta);\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = shouldClose;\n }\n }\n\n if (!entry.argsComplete && entry.controller) {\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) {\n entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = true;\n }\n }\n }\n\n private _processMessages(messages: readonly ThreadMessage[]): void {\n const isRestore = this._pendingRestore;\n\n for (const message of messages) {\n if (!message || !Array.isArray((message as ThreadMessage).content)) {\n continue;\n }\n for (const content of message.content as readonly ThreadMessage[\"content\"][number][]) {\n if (!content || content.type !== \"tool-call\") continue;\n\n const existing = this._entries.get(content.toolCallId);\n\n if (isRestore) {\n // Don't overwrite an already-active entry (e.g. live tool-call\n // observed before this restore snapshot landed). Restore can\n // only seed entries the runtime has never seen.\n if (!existing?.controller) {\n this._entries.set(content.toolCallId, {\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult: content.result !== undefined,\n });\n }\n if (content.messages) this._processMessages(content.messages);\n continue;\n }\n\n // Live snapshot.\n let entry = existing;\n\n if (entry && !entry.controller) {\n // Restored entry observed in a live snapshot. Promote if its\n // signature has changed; otherwise treat as still-historical.\n const signatureChanged =\n content.argsText !== entry.argsText ||\n (content.result !== undefined) !== entry.hasResult;\n if (!signatureChanged) {\n if (content.messages) this._processMessages(content.messages);\n continue;\n }\n this._entries.delete(content.toolCallId);\n entry = undefined;\n }\n\n if (!entry) {\n entry = this._startActiveEntry(\n content.toolCallId,\n content.toolName,\n content.result !== undefined,\n );\n }\n\n this._processArgsText(entry, content);\n\n if (content.result !== undefined && !entry.hasResult) {\n // `entry` is in active phase from this point — either just\n // created by `_startActiveEntry`, or pre-existing with a live\n // controller. Narrow once instead of asserting at every use.\n const { controller: activeController } = entry;\n if (!activeController) continue;\n entry.hasResult = true;\n entry.argsComplete = true;\n activeController.setResponse(\n new ToolResponse({\n result: content.result as ReadonlyJSONValue,\n artifact: content.artifact as ReadonlyJSONValue | undefined,\n isError: content.isError,\n ...(content.modelContent !== undefined\n ? { modelContent: content.modelContent }\n : {}),\n }),\n );\n activeController.close();\n }\n\n if (content.messages) this._processMessages(content.messages);\n }\n }\n }\n}\n"],"mappings":";;;;AAkFA,MAAM,sBAAsB,aAAqB;CAC/C,IAAI;EACF,KAAK,MAAM,QAAQ;EACnB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,iBAAiB,aAAqB;CAC1C,IAAI;EACF,OAAO,KAAK,MAAM,QAAQ;CAC5B,QAAQ;EACN;CACF;AACF;AAEA,MAAM,gCAAgC,UAAkB,SAAiB;CACvE,MAAM,gBAAgB,cAAc,QAAQ;CAC5C,MAAM,YAAY,cAAc,IAAI;CACpC,IAAI,kBAAkB,KAAA,KAAa,cAAc,KAAA,GAAW,OAAO;CACnE,OAAO,iBAAiB,eAAe,SAAS;AAClD;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,wBAAb,MAAmC;CACjC;CACA;CAEA,2BAA4B,IAAI,IAA2B;;;;;;;;;;;CAW3D,wCAAyC,IAAI,IAAY;CACzD,8BAA+B,IAAI,IAMjC;;CAEF,6BAA8B,IAAI,IAAY;CAC9C,oBAAwD,CAAC;CAEzD,4BAAoB,IAAI,IAAiC;CAEzD,MAA+B,IAAI,gBAAgB;CACnD,kBAA0B;;CAG1B,gBAA8D;CAC9D,aAAqB;CAErB;;;;;;;;;CAUA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B,IAAI,QAAQ,UAAU,KAAK,iBAAiB,QAAQ,QAAQ;MAC5D;KACF;KACA,KAAK,SAAS,OAAO,QAAQ,UAAU;KACvC,QAAQ,KAAA;IACV;IAEA,IAAI,CAAC,OACH,QAAQ,KAAK,kBACX,QAAQ,YACR,QAAQ,UACR,QAAQ,WAAW,KAAA,CACrB;IAGF,KAAK,iBAAiB,OAAO,OAAO;IAEpC,IAAI,QAAQ,WAAW,KAAA,KAAa,CAAC,MAAM,WAAW;KAIpD,MAAM,EAAE,YAAY,qBAAqB;KACzC,IAAI,CAAC,kBAAkB;KACvB,MAAM,YAAY;KAClB,MAAM,eAAe;KACrB,iBAAiB,YACf,IAAI,aAAa;MACf,QAAQ,QAAQ;MAChB,UAAU,QAAQ;MAClB,SAAS,QAAQ;MACjB,GAAI,QAAQ,iBAAiB,KAAA,IACzB,EAAE,cAAc,QAAQ,aAAa,IACrC,CAAC;KACP,CAAC,CACH;KACA,iBAAiB,MAAM;IACzB;IAEA,IAAI,QAAQ,UAAU,KAAK,iBAAiB,QAAQ,QAAQ;GAC9D;EACF;CACF;AACF"}
1
+ {"version":3,"file":"ToolInvocationTracker.js","names":[],"sources":["../../../src/runtimes/tool-invocations/ToolInvocationTracker.ts"],"sourcesContent":["declare const process: { env: { NODE_ENV?: string } };\n\nimport {\n createAssistantStreamController,\n type ToolCallStreamController,\n ToolResponse,\n unstable_toolResultStream,\n type Tool,\n type ToolModelContentPart,\n} from \"assistant-stream\";\nimport {\n AssistantMetaTransformStream,\n type ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport { isJSONValueEqual } from \"../../utils/json/is-json-equal\";\nimport type { ThreadMessage } from \"../../types/message\";\n\n/**\n * Streaming execution state for a frontend tool.\n */\nexport type ToolExecutionStatus =\n | { type: \"executing\" }\n | {\n type: \"interrupt\";\n payload: { type: \"human\"; payload: unknown };\n };\n\nexport type AddToolResultCommand = {\n readonly type: \"add-tool-result\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly result: ReadonlyJSONValue;\n readonly isError: boolean;\n readonly artifact?: ReadonlyJSONValue;\n readonly modelContent?: readonly ToolModelContentPart[];\n};\n\nexport type ToolInvocationTrackerSnapshot = {\n readonly messages: readonly ThreadMessage[];\n /** Whether the producing runtime is currently streaming new output. */\n readonly isRunning: boolean;\n /**\n * Whether the producing runtime is still loading historical state.\n * When `true`, every snapshot is treated as historical (no `streamCall` /\n * `execute` fires). When `false`, processing resumes as live.\n */\n readonly isLoading?: boolean;\n};\n\nexport type ToolInvocationTrackerCallbacks = {\n /**\n * Invoked when a client-side `execute()` returns a result and the runtime\n * needs to feed it back into the conversation.\n */\n onResult: (command: AddToolResultCommand) => void;\n /**\n * Invoked whenever the per-tool-call status map changes (executing /\n * interrupt / cleared). The callback receives a fresh map; mutating the\n * argument is not supported.\n */\n onStatusesChange: (\n statuses: ReadonlyMap<string, ToolExecutionStatus>,\n ) => void;\n};\n\ntype ToolCallEntry = {\n toolName: string;\n argsText: string;\n hasResult: boolean;\n} & (\n | {\n /** Restored phase — observed during a history-load snapshot. */\n controller?: undefined;\n argsComplete?: undefined;\n }\n | {\n /** Active phase — chunks are flowing through `controller`. */\n controller: ToolCallStreamController;\n argsComplete: boolean;\n }\n);\n\nconst isArgsTextComplete = (argsText: string) => {\n try {\n JSON.parse(argsText);\n return true;\n } catch {\n return false;\n }\n};\n\nconst parseArgsText = (argsText: string) => {\n try {\n return JSON.parse(argsText);\n } catch {\n return undefined;\n }\n};\n\nconst isEquivalentCompleteArgsText = (previous: string, next: string) => {\n const previousValue = parseArgsText(previous);\n const nextValue = parseArgsText(next);\n if (previousValue === undefined || nextValue === undefined) return false;\n return isJSONValueEqual(previousValue, nextValue);\n};\n\n/**\n * Plain-class port of the former `useToolInvocations` React hook. Owns the\n * assistant-stream pipeline that drives client-side `streamCall` / `execute`\n * for tool-call parts surfaced by a thread runtime, plus the per-tool-call\n * status map that consumers render against.\n *\n * **Contract**: `streamCall` (and `execute`) fires exactly once per logical\n * `toolCallId`. Args mutations after first completion, result replacement,\n * and result clearing are *not* surfaced through additional `streamCall`\n * invocations — by design — so hosts cannot observe spurious re-fires of\n * side effects. The follow-up `reader.events()` API will expose those\n * post-completion transitions to consumers that opt in.\n *\n * State-transition safety: every public method that observes runtime state\n * (`setState`, `reset`, `abort`, `resume`) wraps its work in try/catch and\n * logs to `console.error` rather than throwing. The tracker is built into\n * the hot message-processing path, so a malformed snapshot must never crash\n * the host runtime. See ./EDGE_CASES.md for the known non-trivial state\n * transitions and what each does today.\n */\nexport class ToolInvocationTracker {\n private readonly _getTools: () => Record<string, Tool> | undefined;\n private readonly _callbacks: ToolInvocationTrackerCallbacks;\n\n private readonly _entries = new Map<string, ToolCallEntry>();\n /**\n * Tool call ids whose `execute` should be short-circuited in the wrapper.\n * Populated when an entry is created with a result already attached\n * (history reload, mid-run resume, etc.) — `execute` is suppressed so\n * client-side side effects don't double-run. Membership outlives the\n * entry: `reset()` deliberately does *not* clear this so post-abort\n * cancellation `result` chunks for pre-resolved entries can still be\n * recognized and dropped. Growth is bounded by the number of pre-resolved\n * tool calls observed in the session.\n */\n private readonly _skipExecuteStreamIds = new Set<string>();\n private readonly _humanInput = new Map<\n string,\n {\n resolve: (payload: unknown) => void;\n reject: (reason: unknown) => void;\n }\n >();\n /** In-flight `execute` invocations keyed by tool call id. */\n private readonly _executing = new Set<string>();\n private readonly _settledResolvers: Array<() => void> = [];\n\n private _statuses = new Map<string, ToolExecutionStatus>();\n\n private _ac: AbortController = new AbortController();\n private _pendingRestore = true;\n\n /** Cached last snapshot, used to skip processing on identical re-renders. */\n private _lastSnapshot: ToolInvocationTrackerSnapshot | null = null;\n private _isRunning = false;\n\n private _controller!: ReturnType<typeof createAssistantStreamController>[1];\n\n /**\n * Set when the assistant-stream pipeline has died (errored out via\n * `.pipeTo(...).catch(...)`). The next `setState` re-initializes the\n * pipeline and demotes all active entries to restored so they survive\n * across the restart without re-firing `streamCall` (preserves the\n * \"exactly once\" contract). Capped at a single auto-restart per session\n * — repeated failures keep the tracker dead with a more visible error.\n */\n private _pipelineDead = false;\n private _pipelineRestartUsed = false;\n\n constructor(\n getTools: () => Record<string, Tool> | undefined,\n callbacks: ToolInvocationTrackerCallbacks,\n ) {\n this._getTools = getTools;\n this._callbacks = callbacks;\n\n this._initPipeline();\n }\n\n /**\n * Build the assistant-stream pipeline. Called once from the constructor\n * and at most once again if `_pipelineDead` is set (see F.4 in\n * EDGE_CASES.md).\n */\n private _initPipeline(): void {\n const [stream, controller] = createAssistantStreamController();\n this._controller = controller;\n\n const transform = unstable_toolResultStream(\n () => this._getWrappedTools(),\n () => this._ac.signal,\n (toolCallId, payload) => this._onHumanInput(toolCallId, payload),\n {\n onExecutionStart: (id) => this._onExecutionStart(id),\n onExecutionEnd: (id) => this._onExecutionEnd(id),\n },\n );\n\n stream\n .pipeThrough(transform)\n .pipeThrough(new AssistantMetaTransformStream())\n .pipeTo(\n new WritableStream({\n write: (chunk) => {\n try {\n if (chunk.type !== \"result\") return;\n this._handleResultChunk(chunk);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] result chunk handling failed\",\n err,\n );\n }\n },\n }),\n )\n .catch((err) => {\n console.error(\n \"[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState\",\n err,\n );\n this._pipelineDead = true;\n });\n }\n\n // ───────────────────────── public API ─────────────────────────\n\n /**\n * Feed the next observed snapshot into the tracker. Called from the host\n * runtime whenever its message list / running state changes.\n */\n public setState(snapshot: ToolInvocationTrackerSnapshot): void {\n try {\n // Recover from a dead pipeline before processing anything. We demote\n // all active entries to \"restored\" so the rebuilt pipeline does not\n // re-fire `streamCall` for tool calls that already fired pre-death;\n // preserves the \"exactly once per toolCallId\" contract.\n if (this._pipelineDead) {\n if (this._pipelineRestartUsed) {\n // Already retried once and failed again. Stay dead.\n return;\n }\n this._pipelineRestartUsed = true;\n this._pipelineDead = false;\n this._demoteEntriesToRestored();\n this._executing.clear();\n this._ac = new AbortController();\n this._initPipeline();\n // Fall through and process the snapshot against the fresh pipeline.\n }\n\n // Identical snapshot — skip processing entirely. Note: external-store\n // runtimes rebuild the messages array on every adapter update, so this\n // fast-path rarely triggers there; it's primarily for the React-hook\n // shim where state references are stable.\n if (\n this._lastSnapshot &&\n this._lastSnapshot.messages === snapshot.messages &&\n this._lastSnapshot.isRunning === snapshot.isRunning &&\n this._lastSnapshot.isLoading === snapshot.isLoading\n ) {\n return;\n }\n\n // While the host is still loading initial state, treat every snapshot\n // as historical: tool calls are recorded so the next live snapshot can\n // diff against them, but `streamCall` / `execute` do not fire.\n const restoreFromLoading = snapshot.isLoading === true;\n if (restoreFromLoading) {\n this._pendingRestore = true;\n }\n\n // E.4 / AF3 — only mark `_lastSnapshot`/`_isRunning` as observed after\n // processing succeeds. If `_processMessages` throws, the next snapshot\n // (even if identical) gets re-processed against the recovered state.\n const previousIsRunning = this._isRunning;\n this._isRunning = snapshot.isRunning;\n try {\n this._processMessages(snapshot.messages);\n } catch (err) {\n this._isRunning = previousIsRunning;\n throw err;\n }\n this._lastSnapshot = snapshot;\n this._pendingRestore = false;\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] setState failed; snapshot dropped\",\n err,\n );\n }\n }\n\n /**\n * Reset the tracker so the next observed snapshot is treated as historical.\n * Clears entries and aborts any in-flight executions. Used by callers like\n * `importExternalState` to mark a freshly loaded state as restored.\n */\n public reset(): void {\n try {\n this._pendingRestore = true;\n this._entries.clear();\n this._lastSnapshot = null;\n // `_skipExecuteStreamIds` is intentionally not cleared — see field doc.\n void this.abort().finally(() => {\n this._executing.clear();\n });\n } catch (err) {\n console.error(\"[ToolInvocationTracker] reset failed\", err);\n }\n }\n\n /**\n * Abort any in-flight `execute()` invocations. Resolves once all of them\n * have settled (or immediately if none are running).\n */\n public abort(): Promise<void> {\n try {\n this._humanInput.forEach(({ reject }) => {\n try {\n reject(new Error(\"Tool execution aborted\"));\n } catch {\n // host rejection handler threw — already in the abort path,\n // swallow so we continue cleaning up.\n }\n });\n this._humanInput.clear();\n\n this._ac.abort();\n this._ac = new AbortController();\n\n if (this._executing.size === 0) {\n return Promise.resolve();\n }\n return new Promise<void>((resolve) => {\n this._settledResolvers.push(resolve);\n });\n } catch (err) {\n console.error(\"[ToolInvocationTracker] abort failed\", err);\n return Promise.resolve();\n }\n }\n\n /**\n * Resolve a pending human-input request for the given tool call. Returns\n * `true` if a pending request was resumed, `false` if the tracker has no\n * outstanding request for that id (the caller should fall back to its own\n * dispatch path).\n */\n public resume(toolCallId: string, payload: unknown): boolean {\n try {\n const handlers = this._humanInput.get(toolCallId);\n if (!handlers) return false;\n this._humanInput.delete(toolCallId);\n this._setStatus(toolCallId, { type: \"executing\" });\n handlers.resolve(payload);\n return true;\n } catch (err) {\n console.error(\"[ToolInvocationTracker] resume failed\", err);\n return false;\n }\n }\n\n /**\n * Returns the current tool execution status map. The returned `Map` is\n * the tracker's internal store — do not mutate it. Treat the reference\n * as a snapshot that may be replaced wholesale on the next status\n * transition.\n */\n public getStatuses(): ReadonlyMap<string, ToolExecutionStatus> {\n return this._statuses;\n }\n\n // ───────────────────── internal: tool wrapping ─────────────────────\n\n private _getWrappedTools(): Record<string, Tool> | undefined {\n const tools = this._getTools();\n if (!tools) return undefined;\n\n return Object.fromEntries(\n Object.entries(tools).map(([name, tool]) => {\n const execute = tool.execute;\n if (execute === undefined) return [name, tool];\n\n const wrappedTool = {\n ...tool,\n execute: (\n ...[args, context]: Parameters<NonNullable<typeof execute>>\n ) => {\n if (this._skipExecuteStreamIds.has(context.toolCallId)) {\n // Pre-resolved tool call: never invoke the host's execute.\n // Returning a never-settling Promise keeps the executor's\n // pending entry alive but enqueues nothing.\n return new Promise(() => {}) as never;\n }\n return execute(args, context);\n },\n } as Tool;\n return [name, wrappedTool];\n }),\n ) as Record<string, Tool>;\n }\n\n // ──────────────── internal: execution lifecycle callbacks ────────────────\n\n private _onHumanInput(\n toolCallId: string,\n payload: unknown,\n ): Promise<unknown> {\n return new Promise<unknown>((resolve, reject) => {\n const previous = this._humanInput.get(toolCallId);\n if (previous) {\n try {\n previous.reject(\n new Error(\"Human input request was superseded by a new request\"),\n );\n } catch {\n // host rejection handler threw; ignore and proceed\n }\n }\n this._humanInput.set(toolCallId, { resolve, reject });\n this._setStatus(toolCallId, {\n type: \"interrupt\",\n payload: { type: \"human\", payload },\n });\n });\n }\n\n private _onExecutionStart(toolCallId: string): void {\n if (this._skipExecuteStreamIds.has(toolCallId)) return;\n\n this._executing.add(toolCallId);\n this._setStatus(toolCallId, { type: \"executing\" });\n }\n\n private _onExecutionEnd(toolCallId: string): void {\n if (!this._executing.delete(toolCallId)) return;\n\n this._deleteStatus(toolCallId);\n\n if (this._executing.size === 0) {\n const resolvers = this._settledResolvers.splice(0);\n resolvers.forEach((resolve) => {\n try {\n resolve();\n } catch {\n // ignore — settled-resolver consumer threw\n }\n });\n }\n }\n\n private _handleResultChunk(chunk: {\n type: \"result\";\n result: ReadonlyJSONValue;\n isError: boolean;\n artifact?: ReadonlyJSONValue;\n modelContent?: readonly ToolModelContentPart[];\n meta: { toolCallId: string; toolName: string };\n }): void {\n const toolCallId = chunk.meta.toolCallId;\n const entry = this._entries.get(toolCallId);\n\n // Pre-resolved tool call whose entry has been cleared by `reset()`.\n // The post-abort cancellation chunk lands here after the entry is\n // gone; suppress via the long-lived skip-execute marker.\n if (!entry && this._skipExecuteStreamIds.has(toolCallId)) {\n return;\n }\n\n // The host already set the result (via the live snapshot's\n // `setResponse` path). Suppress the executor's redundant emit.\n if (entry?.hasResult) return;\n\n this._invokeOnResult({\n type: \"add-tool-result\",\n toolCallId,\n toolName: chunk.meta.toolName,\n result: chunk.result,\n isError: chunk.isError,\n ...(chunk.artifact !== undefined && { artifact: chunk.artifact }),\n ...(chunk.modelContent !== undefined && {\n modelContent: chunk.modelContent,\n }),\n });\n }\n\n // ──────────────── internal: callback invocation (AF1/AF2) ────────────────\n\n private _invokeOnResult(command: AddToolResultCommand): void {\n try {\n this._callbacks.onResult(command);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] onResult callback threw; result dropped\",\n err,\n );\n }\n }\n\n private _invokeOnStatusesChange(): void {\n try {\n this._callbacks.onStatusesChange(this._statuses);\n } catch (err) {\n console.error(\n \"[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated\",\n err,\n );\n }\n }\n\n // ──────────────── internal: status map mutations ────────────────\n\n private _setStatus(toolCallId: string, status: ToolExecutionStatus): void {\n const next = new Map(this._statuses);\n next.set(toolCallId, status);\n this._statuses = next;\n this._invokeOnStatusesChange();\n }\n\n private _deleteStatus(toolCallId: string): void {\n if (!this._statuses.has(toolCallId)) return;\n const next = new Map(this._statuses);\n next.delete(toolCallId);\n this._statuses = next;\n this._invokeOnStatusesChange();\n }\n\n // ──────────────── internal: snapshot processing ────────────────\n\n private _hasExecutableTool(toolName: string): boolean {\n const tool = this._getTools()?.[toolName];\n return tool?.execute !== undefined || tool?.streamCall !== undefined;\n }\n\n private _shouldCloseArgsStream({\n toolName,\n argsText,\n hasResult,\n }: {\n toolName: string;\n argsText: string;\n hasResult: boolean;\n }): boolean {\n if (hasResult) return true;\n if (!this._hasExecutableTool(toolName)) {\n return !this._isRunning && isArgsTextComplete(argsText);\n }\n return isArgsTextComplete(argsText);\n }\n\n private _startActiveEntry(\n toolCallId: string,\n toolName: string,\n skipExecute: boolean,\n ): ToolCallEntry {\n const toolCallController = this._controller.addToolCallPart({\n toolName,\n toolCallId,\n });\n if (skipExecute) {\n this._skipExecuteStreamIds.add(toolCallId);\n }\n const entry: ToolCallEntry = {\n toolName,\n controller: toolCallController,\n argsText: \"\",\n hasResult: false,\n argsComplete: false,\n };\n this._entries.set(toolCallId, entry);\n return entry;\n }\n\n /**\n * Demote every active entry back to the restored phase. Used by the\n * pipeline-restart path so that, after a fresh pipeline is built, the\n * next observed snapshot does not re-fire `streamCall` for tool calls\n * that already fired pre-death. Args / hasResult tracking is preserved\n * so signature comparisons still work.\n */\n private _demoteEntriesToRestored(): void {\n for (const [toolCallId, entry] of this._entries) {\n if (!entry.controller) continue;\n this._entries.set(toolCallId, {\n toolName: entry.toolName,\n argsText: entry.argsText,\n hasResult: entry.hasResult,\n });\n }\n }\n\n private _processArgsText(\n entry: ToolCallEntry,\n content: {\n toolCallId: string;\n toolName: string;\n argsText: string;\n result?: unknown;\n },\n ): void {\n if (!entry.controller) return;\n const hasResult = content.result !== undefined;\n\n if (content.argsText !== entry.argsText) {\n let shouldWriteArgsText = true;\n\n if (entry.argsComplete) {\n if (isEquivalentCompleteArgsText(entry.argsText, content.argsText)) {\n // A.3 — key reorder. Track new text, no re-fire needed.\n entry.argsText = content.argsText;\n shouldWriteArgsText = false;\n } else {\n // A.4 — args changed after first completion. Under the\n // \"exactly once per toolCallId\" contract we do not restart the\n // stream. The host's existing `streamCall` keeps its original\n // args view; the snapshot's new text is recorded for diffing\n // but not surfaced. Events API in a follow-up will expose this\n // to consumers that opt in.\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n \"[ToolInvocationTracker] argsText changed after first completion; not re-firing streamCall (see EDGE_CASES.md A.4)\",\n {\n previous: entry.argsText,\n next: content.argsText,\n toolCallId: content.toolCallId,\n },\n );\n }\n shouldWriteArgsText = false;\n }\n } else if (!content.argsText.startsWith(entry.argsText)) {\n if (\n isArgsTextComplete(entry.argsText) &&\n isArgsTextComplete(content.argsText) &&\n isEquivalentCompleteArgsText(entry.argsText, content.argsText)\n ) {\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = shouldClose;\n shouldWriteArgsText = false;\n } else {\n // A.2 — args regressed mid-stream. Under the \"exactly once\"\n // contract we do not restart. The controller keeps whatever\n // prefix we already streamed; subsequent prefix-respecting\n // updates can still flow against it. Snapshots that never\n // re-converge to a prefix will leave the controller's args\n // view stale relative to the snapshot. Events API in a\n // follow-up will expose this to consumers that opt in.\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n \"[ToolInvocationTracker] argsText regressed mid-stream; not restarting (see EDGE_CASES.md A.2)\",\n {\n previous: entry.argsText,\n next: content.argsText,\n toolCallId: content.toolCallId,\n },\n );\n }\n shouldWriteArgsText = false;\n }\n }\n\n if (shouldWriteArgsText && entry.controller) {\n const delta = content.argsText.slice(entry.argsText.length);\n entry.controller.argsText.append(delta);\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = shouldClose;\n }\n }\n\n if (!entry.argsComplete && entry.controller) {\n const shouldClose = this._shouldCloseArgsStream({\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult,\n });\n if (shouldClose) {\n entry.controller.argsText.close();\n entry.argsText = content.argsText;\n entry.argsComplete = true;\n }\n }\n }\n\n private _processMessages(messages: readonly ThreadMessage[]): void {\n const isRestore = this._pendingRestore;\n\n for (const message of messages) {\n if (!message || !Array.isArray((message as ThreadMessage).content)) {\n continue;\n }\n for (const content of message.content as readonly ThreadMessage[\"content\"][number][]) {\n if (!content || content.type !== \"tool-call\") continue;\n\n const existing = this._entries.get(content.toolCallId);\n\n if (isRestore) {\n // Don't overwrite an already-active entry (e.g. live tool-call\n // observed before this restore snapshot landed). Restore can\n // only seed entries the runtime has never seen.\n if (!existing?.controller) {\n this._entries.set(content.toolCallId, {\n toolName: content.toolName,\n argsText: content.argsText,\n hasResult: content.result !== undefined,\n });\n }\n if (content.messages) this._processMessages(content.messages);\n continue;\n }\n\n // Live snapshot.\n let entry = existing;\n\n if (entry && !entry.controller) {\n // Restored entry observed in a live snapshot. Promote if its\n // signature has changed; otherwise treat as still-historical.\n const signatureChanged =\n content.argsText !== entry.argsText ||\n (content.result !== undefined) !== entry.hasResult;\n if (!signatureChanged) {\n if (content.messages) this._processMessages(content.messages);\n continue;\n }\n this._entries.delete(content.toolCallId);\n entry = undefined;\n }\n\n if (!entry) {\n entry = this._startActiveEntry(\n content.toolCallId,\n content.toolName,\n content.result !== undefined,\n );\n }\n\n this._processArgsText(entry, content);\n\n if (content.result !== undefined && !entry.hasResult) {\n // `entry` is in active phase from this point — either just\n // created by `_startActiveEntry`, or pre-existing with a live\n // controller. Narrow once instead of asserting at every use.\n const { controller: activeController } = entry;\n if (!activeController) continue;\n entry.hasResult = true;\n entry.argsComplete = true;\n activeController.setResponse(\n new ToolResponse({\n result: content.result as ReadonlyJSONValue,\n artifact: content.artifact as ReadonlyJSONValue | undefined,\n isError: content.isError,\n ...(content.modelContent !== undefined\n ? { modelContent: content.modelContent }\n : {}),\n }),\n );\n activeController.close();\n }\n\n if (content.messages) this._processMessages(content.messages);\n }\n }\n }\n}\n"],"mappings":";;;;AAkFA,MAAM,sBAAsB,aAAqB;CAC/C,IAAI;EACF,KAAK,MAAM,QAAQ;EACnB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,iBAAiB,aAAqB;CAC1C,IAAI;EACF,OAAO,KAAK,MAAM,QAAQ;CAC5B,QAAQ;EACN;CACF;AACF;AAEA,MAAM,gCAAgC,UAAkB,SAAiB;CACvE,MAAM,gBAAgB,cAAc,QAAQ;CAC5C,MAAM,YAAY,cAAc,IAAI;CACpC,IAAI,kBAAkB,KAAA,KAAa,cAAc,KAAA,GAAW,OAAO;CACnE,OAAO,iBAAiB,eAAe,SAAS;AAClD;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,wBAAb,MAAmC;CACjC;CACA;CAEA,2BAA4B,IAAI,IAA2B;;;;;;;;;;;CAW3D,wCAAyC,IAAI,IAAY;CACzD,8BAA+B,IAAI,IAMjC;;CAEF,6BAA8B,IAAI,IAAY;CAC9C,oBAAwD,CAAC;CAEzD,4BAAoB,IAAI,IAAiC;CAEzD,MAA+B,IAAI,gBAAgB;CACnD,kBAA0B;;CAG1B,gBAA8D;CAC9D,aAAqB;CAErB;;;;;;;;;CAUA,gBAAwB;CACxB,uBAA+B;CAE/B,YACE,UACA,WACA;E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AI,QAAQ,UAAU,KAAK,iBAAiB,QAAQ,QAAQ;MAC5D;KACF;KACA,KAAK,SAAS,OAAO,QAAQ,UAAU;KACvC,QAAQ,KAAA;IACV;IAEA,IAAI,CAAC,OACH,QAAQ,KAAK,kBACX,QAAQ,YACR,QAAQ,UACR,QAAQ,WAAW,KAAA,CACrB;IAGF,KAAK,iBAAiB,OAAO,OAAO;IAEpC,IAAI,QAAQ,WAAW,KAAA,KAAa,CAAC,MAAM,WAAW;KAIpD,MAAM,EAAE,YAAY,qBAAqB;KACzC,IAAI,CAAC,kBAAkB;KACvB,MAAM,YAAY;KAClB,MAAM,eAAe;KACrB,iBAAiB,YACf,IAAI,aAAa;MACf,QAAQ,QAAQ;MAChB,UAAU,QAAQ;MAClB,SAAS,QAAQ;MACjB,GAAI,QAAQ,iBAAiB,KAAA,IACzB,EAAE,cAAc,QAAQ,aAAa,IACrC,CAAC;KACP,CAAC,CACH;KACA,iBAAiB,MAAM;IACzB;IAEA,IAAI,QAAQ,UAAU,KAAK,iBAAiB,QAAQ,QAAQ;GAC9D;EACF;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;;cAaa,oBAAA,GAAoB,KAAA;kBAKb,kBAAA;mBACC,QAAA;IAAY,KAAA;EAAA,MAAoB,WAAA;AAAA;kBADjC,kBAAA;mBACC,QAAA;IAAY,KAAA;EAAA,MAAoB,WAAA;AAAA"}
1
+ {"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;;cAca,oBAAA,GAAoB,KAAA;kBAIf,kBAAA;mBACC,QAAA;IAAY,KAAA;EAAA,MAAoB,WAAA;AAAA;kBADjC,kBAAA;mBACC,QAAA;IAAY,KAAA;EAAA,MAAoB,WAAA;AAAA"}
@@ -1,12 +1,13 @@
1
- import { resource, tapMemo, tapState } from "@assistant-ui/tap";
1
+ import { useMemo, useState } from "@assistant-ui/tap/react-shim";
2
+ import { resource } from "@assistant-ui/tap";
2
3
  //#region src/store/clients/chain-of-thought-client.ts
3
4
  const COMPLETE_STATUS = Object.freeze({ type: "complete" });
4
- const ChainOfThoughtClient = resource(({ parts, getMessagePart }) => {
5
- const [collapsed, setCollapsed] = tapState(true);
6
- const status = tapMemo(() => {
5
+ const ChainOfThoughtClient = resource(function ChainOfThoughtClient({ parts, getMessagePart }) {
6
+ const [collapsed, setCollapsed] = useState(true);
7
+ const status = useMemo(() => {
7
8
  return parts[parts.length - 1]?.status ?? COMPLETE_STATUS;
8
9
  }, [parts]);
9
- const state = tapMemo(() => ({
10
+ const state = useMemo(() => ({
10
11
  parts,
11
12
  collapsed,
12
13
  status
@@ -1 +1 @@
1
- {"version":3,"file":"chain-of-thought-client.js","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"sourcesContent":["import { resource, tapMemo, tapState } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n ChainOfThoughtState,\n ChainOfThoughtPart,\n} from \"../scopes/chain-of-thought\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { PartMethods } from \"../scopes/part\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const ChainOfThoughtClient = resource(\n ({\n parts,\n getMessagePart,\n }: {\n parts: readonly ChainOfThoughtPart[];\n getMessagePart: (selector: { index: number }) => PartMethods;\n }): ClientOutput<\"chainOfThought\"> => {\n const [collapsed, setCollapsed] = tapState(true);\n\n const status = tapMemo(() => {\n const lastPart = parts[parts.length - 1];\n return lastPart?.status ?? COMPLETE_STATUS;\n }, [parts]);\n\n const state = tapMemo<ChainOfThoughtState>(\n () => ({ parts, collapsed, status }),\n [parts, collapsed, status],\n );\n\n return {\n getState: () => state,\n setCollapsed,\n part: getMessagePart,\n };\n },\n);\n"],"mappings":";;AASA,MAAM,kBAAqC,OAAO,OAAO,EACvD,MAAM,WACR,CAAC;AAED,MAAa,uBAAuB,UACjC,EACC,OACA,qBAIoC;CACpC,MAAM,CAAC,WAAW,gBAAgB,SAAS,IAAI;CAE/C,MAAM,SAAS,cAAc;EAE3B,OADiB,MAAM,MAAM,SAAS,IACrB,UAAU;CAC7B,GAAG,CAAC,KAAK,CAAC;CAEV,MAAM,QAAQ,eACL;EAAE;EAAO;EAAW;CAAO,IAClC;EAAC;EAAO;EAAW;CAAM,CAC3B;CAEA,OAAO;EACL,gBAAgB;EAChB;EACA,MAAM;CACR;AACF,CACF"}
1
+ {"version":3,"file":"chain-of-thought-client.js","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n ChainOfThoughtState,\n ChainOfThoughtPart,\n} from \"../scopes/chain-of-thought\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { PartMethods } from \"../scopes/part\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const ChainOfThoughtClient = resource(function ChainOfThoughtClient({\n parts,\n getMessagePart,\n}: {\n parts: readonly ChainOfThoughtPart[];\n getMessagePart: (selector: { index: number }) => PartMethods;\n}): ClientOutput<\"chainOfThought\"> {\n const [collapsed, setCollapsed] = useState(true);\n\n const status = useMemo(() => {\n const lastPart = parts[parts.length - 1];\n return lastPart?.status ?? COMPLETE_STATUS;\n }, [parts]);\n\n const state = useMemo<ChainOfThoughtState>(\n () => ({ parts, collapsed, status }),\n [parts, collapsed, status],\n );\n\n return {\n getState: () => state,\n setCollapsed,\n part: getMessagePart,\n };\n});\n"],"mappings":";;;AAUA,MAAM,kBAAqC,OAAO,OAAO,EACvD,MAAM,WACR,CAAC;AAED,MAAa,uBAAuB,SAAS,SAAS,qBAAqB,EACzE,OACA,kBAIiC;CACjC,MAAM,CAAC,WAAW,gBAAgB,SAAS,IAAI;CAE/C,MAAM,SAAS,cAAc;EAE3B,OADiB,MAAM,MAAM,SAAS,EACvB,EAAE,UAAU;CAC7B,GAAG,CAAC,KAAK,CAAC;CAEV,MAAM,QAAQ,eACL;EAAE;EAAO;EAAW;CAAO,IAClC;EAAC;EAAO;EAAW;CAAM,CAC3B;CAEA,OAAO;EACL,gBAAgB;EAChB;EACA,MAAM;CACR;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"model-context-client.d.ts","names":[],"sources":["../../../src/store/clients/model-context-client.ts"],"mappings":";;;cA8Ba,YAAA,oCAAY,eAAA,CAAA,YAAA"}
1
+ {"version":3,"file":"model-context-client.d.ts","names":[],"sources":["../../../src/store/clients/model-context-client.ts"],"mappings":";;;cA+Ba,YAAA,oCAAY,eAAA,CAAA,YAAA"}
@@ -1,5 +1,6 @@
1
1
  import { CompositeContextProvider } from "../../utils/composite-context-provider.js";
2
- import { resource, tapEffect, tapMemo, tapState } from "@assistant-ui/tap";
2
+ import { useEffect, useMemo, useState } from "@assistant-ui/tap/react-shim";
3
+ import { resource } from "@assistant-ui/tap";
3
4
  //#region src/store/clients/model-context-client.ts
4
5
  const EMPTY_TOOL_NAMES = [];
5
6
  const INITIAL_STATE = {
@@ -18,10 +19,10 @@ const deriveState = (composite, prev) => {
18
19
  toolNames
19
20
  };
20
21
  };
21
- const ModelContext = resource(() => {
22
- const composite = tapMemo(() => new CompositeContextProvider(), []);
23
- const [state, setState] = tapState(() => deriveState(composite, INITIAL_STATE));
24
- tapEffect(() => {
22
+ const ModelContext = resource(function ModelContext() {
23
+ const composite = useMemo(() => new CompositeContextProvider(), []);
24
+ const [state, setState] = useState(() => deriveState(composite, INITIAL_STATE));
25
+ useEffect(() => {
25
26
  setState((prev) => deriveState(composite, prev));
26
27
  return composite.subscribe(() => {
27
28
  setState((prev) => deriveState(composite, prev));
@@ -1 +1 @@
1
- {"version":3,"file":"model-context-client.js","names":[],"sources":["../../../src/store/clients/model-context-client.ts"],"sourcesContent":["import { resource, tapEffect, tapMemo, tapState } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { CompositeContextProvider } from \"../../utils/composite-context-provider\";\nimport type { ModelContextState } from \"../scopes/model-context\";\n\nconst EMPTY_TOOL_NAMES: readonly string[] = [];\n\nconst INITIAL_STATE: ModelContextState = {\n modelName: undefined,\n toolNames: EMPTY_TOOL_NAMES,\n};\n\nconst toolNamesEqual = (a: readonly string[], b: readonly string[]): boolean =>\n a === b || (a.length === b.length && a.every((v, i) => v === b[i]));\n\nconst deriveState = (\n composite: CompositeContextProvider,\n prev: ModelContextState,\n): ModelContextState => {\n const ctx = composite.getModelContext();\n const modelName = ctx.config?.modelName;\n const keys = ctx.tools ? Object.keys(ctx.tools).sort() : EMPTY_TOOL_NAMES;\n const toolNames = keys.length ? keys : EMPTY_TOOL_NAMES;\n\n if (modelName === prev.modelName && toolNamesEqual(toolNames, prev.toolNames))\n return prev;\n\n return { modelName, toolNames };\n};\n\nexport const ModelContext = resource((): ClientOutput<\"modelContext\"> => {\n const composite = tapMemo(() => new CompositeContextProvider(), []);\n const [state, setState] = tapState<ModelContextState>(() =>\n deriveState(composite, INITIAL_STATE),\n );\n\n tapEffect(() => {\n setState((prev) => deriveState(composite, prev));\n return composite.subscribe(() => {\n setState((prev) => deriveState(composite, prev));\n });\n }, [composite]);\n\n return {\n getState: () => deriveState(composite, state),\n getModelContext: () => composite.getModelContext(),\n subscribe: (callback) => composite.subscribe(callback),\n register: (provider) => composite.registerModelContextProvider(provider),\n };\n});\n"],"mappings":";;;AAKA,MAAM,mBAAsC,CAAC;AAE7C,MAAM,gBAAmC;CACvC,WAAW,KAAA;CACX,WAAW;AACb;AAEA,MAAM,kBAAkB,GAAsB,MAC5C,MAAM,KAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE;AAEnE,MAAM,eACJ,WACA,SACsB;CACtB,MAAM,MAAM,UAAU,gBAAgB;CACtC,MAAM,YAAY,IAAI,QAAQ;CAC9B,MAAM,OAAO,IAAI,QAAQ,OAAO,KAAK,IAAI,KAAK,EAAE,KAAK,IAAI;CACzD,MAAM,YAAY,KAAK,SAAS,OAAO;CAEvC,IAAI,cAAc,KAAK,aAAa,eAAe,WAAW,KAAK,SAAS,GAC1E,OAAO;CAET,OAAO;EAAE;EAAW;CAAU;AAChC;AAEA,MAAa,eAAe,eAA6C;CACvE,MAAM,YAAY,cAAc,IAAI,yBAAyB,GAAG,CAAC,CAAC;CAClE,MAAM,CAAC,OAAO,YAAY,eACxB,YAAY,WAAW,aAAa,CACtC;CAEA,gBAAgB;EACd,UAAU,SAAS,YAAY,WAAW,IAAI,CAAC;EAC/C,OAAO,UAAU,gBAAgB;GAC/B,UAAU,SAAS,YAAY,WAAW,IAAI,CAAC;EACjD,CAAC;CACH,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;EACL,gBAAgB,YAAY,WAAW,KAAK;EAC5C,uBAAuB,UAAU,gBAAgB;EACjD,YAAY,aAAa,UAAU,UAAU,QAAQ;EACrD,WAAW,aAAa,UAAU,6BAA6B,QAAQ;CACzE;AACF,CAAC"}
1
+ {"version":3,"file":"model-context-client.js","names":[],"sources":["../../../src/store/clients/model-context-client.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { CompositeContextProvider } from \"../../utils/composite-context-provider\";\nimport type { ModelContextState } from \"../scopes/model-context\";\n\nconst EMPTY_TOOL_NAMES: readonly string[] = [];\n\nconst INITIAL_STATE: ModelContextState = {\n modelName: undefined,\n toolNames: EMPTY_TOOL_NAMES,\n};\n\nconst toolNamesEqual = (a: readonly string[], b: readonly string[]): boolean =>\n a === b || (a.length === b.length && a.every((v, i) => v === b[i]));\n\nconst deriveState = (\n composite: CompositeContextProvider,\n prev: ModelContextState,\n): ModelContextState => {\n const ctx = composite.getModelContext();\n const modelName = ctx.config?.modelName;\n const keys = ctx.tools ? Object.keys(ctx.tools).sort() : EMPTY_TOOL_NAMES;\n const toolNames = keys.length ? keys : EMPTY_TOOL_NAMES;\n\n if (modelName === prev.modelName && toolNamesEqual(toolNames, prev.toolNames))\n return prev;\n\n return { modelName, toolNames };\n};\n\nexport const ModelContext = resource(\n function ModelContext(): ClientOutput<\"modelContext\"> {\n const composite = useMemo(() => new CompositeContextProvider(), []);\n const [state, setState] = useState<ModelContextState>(() =>\n deriveState(composite, INITIAL_STATE),\n );\n\n useEffect(() => {\n setState((prev) => deriveState(composite, prev));\n return composite.subscribe(() => {\n setState((prev) => deriveState(composite, prev));\n });\n }, [composite]);\n\n return {\n getState: () => deriveState(composite, state),\n getModelContext: () => composite.getModelContext(),\n subscribe: (callback) => composite.subscribe(callback),\n register: (provider) => composite.registerModelContextProvider(provider),\n };\n },\n);\n"],"mappings":";;;;AAMA,MAAM,mBAAsC,CAAC;AAE7C,MAAM,gBAAmC;CACvC,WAAW,KAAA;CACX,WAAW;AACb;AAEA,MAAM,kBAAkB,GAAsB,MAC5C,MAAM,KAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE;AAEnE,MAAM,eACJ,WACA,SACsB;CACtB,MAAM,MAAM,UAAU,gBAAgB;CACtC,MAAM,YAAY,IAAI,QAAQ;CAC9B,MAAM,OAAO,IAAI,QAAQ,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,IAAI;CACzD,MAAM,YAAY,KAAK,SAAS,OAAO;CAEvC,IAAI,cAAc,KAAK,aAAa,eAAe,WAAW,KAAK,SAAS,GAC1E,OAAO;CAET,OAAO;EAAE;EAAW;CAAU;AAChC;AAEA,MAAa,eAAe,SAC1B,SAAS,eAA6C;CACpD,MAAM,YAAY,cAAc,IAAI,yBAAyB,GAAG,CAAC,CAAC;CAClE,MAAM,CAAC,OAAO,YAAY,eACxB,YAAY,WAAW,aAAa,CACtC;CAEA,gBAAgB;EACd,UAAU,SAAS,YAAY,WAAW,IAAI,CAAC;EAC/C,OAAO,UAAU,gBAAgB;GAC/B,UAAU,SAAS,YAAY,WAAW,IAAI,CAAC;EACjD,CAAC;CACH,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;EACL,gBAAgB,YAAY,WAAW,KAAK;EAC5C,uBAAuB,UAAU,gBAAgB;EACjD,YAAY,aAAa,UAAU,UAAU,QAAQ;EACrD,WAAW,aAAa,UAAU,6BAA6B,QAAQ;CACzE;AACF,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-op-composer-client.d.ts","names":[],"sources":["../../../src/store/clients/no-op-composer-client.ts"],"mappings":";;;cAIa,kBAAA,GAAkB,KAAA;;kDAkE9B,YAAA"}
1
+ {"version":3,"file":"no-op-composer-client.d.ts","names":[],"sources":["../../../src/store/clients/no-op-composer-client.ts"],"mappings":";;;cAKa,kBAAA,GAAkB,KAAA;;kDAoE7B,YAAA"}
@@ -1,7 +1,8 @@
1
- import { resource, tapMemo } from "@assistant-ui/tap";
1
+ import { useMemo } from "@assistant-ui/tap/react-shim";
2
+ import { resource } from "@assistant-ui/tap";
2
3
  //#region src/store/clients/no-op-composer-client.ts
3
- const NoOpComposerClient = resource(({ type }) => {
4
- const state = tapMemo(() => {
4
+ const NoOpComposerClient = resource(function NoOpComposerClient({ type }) {
5
+ const state = useMemo(() => {
5
6
  return {
6
7
  isEditing: false,
7
8
  isEmpty: true,
@@ -1 +1 @@
1
- {"version":3,"file":"no-op-composer-client.js","names":[],"sources":["../../../src/store/clients/no-op-composer-client.ts"],"sourcesContent":["import { resource, tapMemo } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type { ComposerState } from \"../scopes/composer\";\n\nexport const NoOpComposerClient = resource(\n ({ type }: { type: \"edit\" | \"thread\" }): ClientOutput<\"composer\"> => {\n const state = tapMemo<ComposerState>(() => {\n return {\n isEditing: false,\n isEmpty: true,\n text: \"\",\n attachmentAccept: \"*\",\n attachments: [],\n role: \"user\",\n runConfig: {},\n canCancel: false,\n canSend: false,\n type: type,\n dictation: undefined,\n quote: undefined,\n queue: [],\n };\n }, [type]);\n\n return {\n getState: () => state,\n setText: () => {\n throw new Error(\"Not supported\");\n },\n setRole: () => {\n throw new Error(\"Not supported\");\n },\n setRunConfig: () => {\n throw new Error(\"Not supported\");\n },\n addAttachment: () => {\n throw new Error(\"Not supported\");\n },\n clearAttachments: () => {\n throw new Error(\"Not supported\");\n },\n attachment: () => {\n throw new Error(\"Not supported\");\n },\n reset: () => {\n throw new Error(\"Not supported\");\n },\n send: () => {\n throw new Error(\"Not supported\");\n },\n cancel: () => {\n throw new Error(\"Not supported\");\n },\n startDictation: () => {\n throw new Error(\"Not supported\");\n },\n stopDictation: () => {\n throw new Error(\"Not supported\");\n },\n beginEdit: () => {\n throw new Error(\"Not supported\");\n },\n setQuote: () => {\n throw new Error(\"Not supported\");\n },\n queueItem: () => {\n throw new Error(\"Not supported\");\n },\n };\n },\n);\n"],"mappings":";;AAIA,MAAa,qBAAqB,UAC/B,EAAE,WAAkE;CACnE,MAAM,QAAQ,cAA6B;EACzC,OAAO;GACL,WAAW;GACX,SAAS;GACT,MAAM;GACN,kBAAkB;GAClB,aAAa,CAAC;GACd,MAAM;GACN,WAAW,CAAC;GACZ,WAAW;GACX,SAAS;GACH;GACN,WAAW,KAAA;GACX,OAAO,KAAA;GACP,OAAO,CAAC;EACV;CACF,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;EACL,gBAAgB;EAChB,eAAe;GACb,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,eAAe;GACb,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,oBAAoB;GAClB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,wBAAwB;GACtB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,kBAAkB;GAChB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,aAAa;GACX,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,YAAY;GACV,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,cAAc;GACZ,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,iBAAiB;GACf,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,gBAAgB;GACd,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,iBAAiB;GACf,MAAM,IAAI,MAAM,eAAe;EACjC;CACF;AACF,CACF"}
1
+ {"version":3,"file":"no-op-composer-client.js","names":[],"sources":["../../../src/store/clients/no-op-composer-client.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type { ComposerState } from \"../scopes/composer\";\n\nexport const NoOpComposerClient = resource(function NoOpComposerClient({\n type,\n}: {\n type: \"edit\" | \"thread\";\n}): ClientOutput<\"composer\"> {\n const state = useMemo<ComposerState>(() => {\n return {\n isEditing: false,\n isEmpty: true,\n text: \"\",\n attachmentAccept: \"*\",\n attachments: [],\n role: \"user\",\n runConfig: {},\n canCancel: false,\n canSend: false,\n type: type,\n dictation: undefined,\n quote: undefined,\n queue: [],\n };\n }, [type]);\n\n return {\n getState: () => state,\n setText: () => {\n throw new Error(\"Not supported\");\n },\n setRole: () => {\n throw new Error(\"Not supported\");\n },\n setRunConfig: () => {\n throw new Error(\"Not supported\");\n },\n addAttachment: () => {\n throw new Error(\"Not supported\");\n },\n clearAttachments: () => {\n throw new Error(\"Not supported\");\n },\n attachment: () => {\n throw new Error(\"Not supported\");\n },\n reset: () => {\n throw new Error(\"Not supported\");\n },\n send: () => {\n throw new Error(\"Not supported\");\n },\n cancel: () => {\n throw new Error(\"Not supported\");\n },\n startDictation: () => {\n throw new Error(\"Not supported\");\n },\n stopDictation: () => {\n throw new Error(\"Not supported\");\n },\n beginEdit: () => {\n throw new Error(\"Not supported\");\n },\n setQuote: () => {\n throw new Error(\"Not supported\");\n },\n queueItem: () => {\n throw new Error(\"Not supported\");\n },\n };\n});\n"],"mappings":";;;AAKA,MAAa,qBAAqB,SAAS,SAAS,mBAAmB,EACrE,QAG2B;CAC3B,MAAM,QAAQ,cAA6B;EACzC,OAAO;GACL,WAAW;GACX,SAAS;GACT,MAAM;GACN,kBAAkB;GAClB,aAAa,CAAC;GACd,MAAM;GACN,WAAW,CAAC;GACZ,WAAW;GACX,SAAS;GACH;GACN,WAAW,KAAA;GACX,OAAO,KAAA;GACP,OAAO,CAAC;EACV;CACF,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;EACL,gBAAgB;EAChB,eAAe;GACb,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,eAAe;GACb,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,oBAAoB;GAClB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,wBAAwB;GACtB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,kBAAkB;GAChB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,aAAa;GACX,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,YAAY;GACV,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,cAAc;GACZ,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,iBAAiB;GACf,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,gBAAgB;GACd,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,iBAAiB;GACf,MAAM,IAAI,MAAM,eAAe;EACjC;CACF;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-adapter.d.ts","names":[],"sources":["../../../src/store/clients/runtime-adapter.ts"],"mappings":";;;;cAYa,sBAAA,GAAsB,KAAA,EAAA,gBAAA,iCAAA,eAAA,+BAAA,YAAA,aAAA,gBAAA;AAAA,cAiBtB,iCAAA,GACX,MAAA,EAAQ,YAAA,EACR,MAAA,EAAQ,eAAe"}
1
+ {"version":3,"file":"runtime-adapter.d.ts","names":[],"sources":["../../../src/store/clients/runtime-adapter.ts"],"mappings":";;;;cAaa,sBAAA,GAAsB,KAAA,EAAA,gBAAA,iCAAA,eAAA,+BAAA,YAAA,aAAA,gBAAA;AAAA,cAmBtB,iCAAA,GACX,MAAA,EAAQ,YAAA,EACR,MAAA,EAAQ,eAAe"}
@@ -1,15 +1,16 @@
1
1
  import { ThreadListClient } from "../runtime-clients/thread-list-runtime-client.js";
2
2
  import { ModelContext } from "./model-context-client.js";
3
3
  import { Suggestions } from "./suggestions.js";
4
- import { Derived, tapAssistantClientRef } from "@assistant-ui/store";
5
- import { resource, tapEffect, tapResource } from "@assistant-ui/tap";
4
+ import { useEffect } from "@assistant-ui/tap/react-shim";
5
+ import { Derived, useAssistantClientRef } from "@assistant-ui/store";
6
+ import { resource, useResource } from "@assistant-ui/tap";
6
7
  //#region src/store/clients/runtime-adapter.ts
7
- const RuntimeAdapterResource = resource((runtime) => {
8
- const clientRef = tapAssistantClientRef();
9
- tapEffect(() => {
8
+ const RuntimeAdapterResource = resource(function RuntimeAdapterResource(runtime) {
9
+ const clientRef = useAssistantClientRef();
10
+ useEffect(() => {
10
11
  return runtime.registerModelContextProvider(clientRef.current.modelContext());
11
12
  }, [runtime, clientRef]);
12
- return tapResource(ThreadListClient({
13
+ return useResource(ThreadListClient({
13
14
  runtime: runtime.threads,
14
15
  __internal_assistantRuntime: runtime
15
16
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-adapter.js","names":[],"sources":["../../../src/store/clients/runtime-adapter.ts"],"sourcesContent":["import { resource, tapEffect, tapResource } from \"@assistant-ui/tap\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { ThreadListClient } from \"../runtime-clients/thread-list-runtime-client\";\nimport {\n tapAssistantClientRef,\n Derived,\n type ScopesConfig,\n type AssistantClient,\n} from \"@assistant-ui/store\";\nimport { ModelContext } from \"./model-context-client\";\nimport { Suggestions } from \"./suggestions\";\n\nexport const RuntimeAdapterResource = resource((runtime: AssistantRuntime) => {\n const clientRef = tapAssistantClientRef();\n\n tapEffect(() => {\n return runtime.registerModelContextProvider(\n clientRef.current!.modelContext(),\n );\n }, [runtime, clientRef]);\n\n return tapResource(\n ThreadListClient({\n runtime: runtime.threads,\n __internal_assistantRuntime: runtime,\n }),\n );\n});\n\nexport const baseRuntimeAdapterTransformScopes = (\n scopes: ScopesConfig,\n parent: AssistantClient,\n): void => {\n scopes.thread ??= Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().thread(\"main\"),\n });\n scopes.threadListItem ??= Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().item(\"main\"),\n });\n scopes.composer ??= Derived({\n source: \"thread\",\n query: {},\n get: (aui) => aui.threads().thread(\"main\").composer(),\n });\n\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n if (!scopes.suggestions && parent.suggestions.source === null) {\n scopes.suggestions = Suggestions();\n }\n};\n"],"mappings":";;;;;;AAYA,MAAa,yBAAyB,UAAU,YAA8B;CAC5E,MAAM,YAAY,sBAAsB;CAExC,gBAAgB;EACd,OAAO,QAAQ,6BACb,UAAU,QAAS,aAAa,CAClC;CACF,GAAG,CAAC,SAAS,SAAS,CAAC;CAEvB,OAAO,YACL,iBAAiB;EACf,SAAS,QAAQ;EACjB,6BAA6B;CAC/B,CAAC,CACH;AACF,CAAC;AAED,MAAa,qCACX,QACA,WACS;CACT,OAAO,WAAW,QAAQ;EACxB,QAAQ;EACR,OAAO,EAAE,MAAM,OAAO;EACtB,MAAM,QAAQ,IAAI,QAAQ,EAAE,OAAO,MAAM;CAC3C,CAAC;CACD,OAAO,mBAAmB,QAAQ;EAChC,QAAQ;EACR,OAAO,EAAE,MAAM,OAAO;EACtB,MAAM,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM;CACzC,CAAC;CACD,OAAO,aAAa,QAAQ;EAC1B,QAAQ;EACR,OAAO,CAAC;EACR,MAAM,QAAQ,IAAI,QAAQ,EAAE,OAAO,MAAM,EAAE,SAAS;CACtD,CAAC;CAED,IAAI,CAAC,OAAO,gBAAgB,OAAO,aAAa,WAAW,MACzD,OAAO,eAAe,aAAa;CAErC,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,WAAW,MACvD,OAAO,cAAc,YAAY;AAErC"}
1
+ {"version":3,"file":"runtime-adapter.js","names":[],"sources":["../../../src/store/clients/runtime-adapter.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useResource, resource } from \"@assistant-ui/tap\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { ThreadListClient } from \"../runtime-clients/thread-list-runtime-client\";\nimport {\n useAssistantClientRef,\n Derived,\n type ScopesConfig,\n type AssistantClient,\n} from \"@assistant-ui/store\";\nimport { ModelContext } from \"./model-context-client\";\nimport { Suggestions } from \"./suggestions\";\n\nexport const RuntimeAdapterResource = resource(function RuntimeAdapterResource(\n runtime: AssistantRuntime,\n) {\n const clientRef = useAssistantClientRef();\n\n useEffect(() => {\n return runtime.registerModelContextProvider(\n clientRef.current!.modelContext(),\n );\n }, [runtime, clientRef]);\n\n return useResource(\n ThreadListClient({\n runtime: runtime.threads,\n __internal_assistantRuntime: runtime,\n }),\n );\n});\n\nexport const baseRuntimeAdapterTransformScopes = (\n scopes: ScopesConfig,\n parent: AssistantClient,\n): void => {\n scopes.thread ??= Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().thread(\"main\"),\n });\n scopes.threadListItem ??= Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().item(\"main\"),\n });\n scopes.composer ??= Derived({\n source: \"thread\",\n query: {},\n get: (aui) => aui.threads().thread(\"main\").composer(),\n });\n\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n if (!scopes.suggestions && parent.suggestions.source === null) {\n scopes.suggestions = Suggestions();\n }\n};\n"],"mappings":";;;;;;;AAaA,MAAa,yBAAyB,SAAS,SAAS,uBACtD,SACA;CACA,MAAM,YAAY,sBAAsB;CAExC,gBAAgB;EACd,OAAO,QAAQ,6BACb,UAAU,QAAS,aAAa,CAClC;CACF,GAAG,CAAC,SAAS,SAAS,CAAC;CAEvB,OAAO,YACL,iBAAiB;EACf,SAAS,QAAQ;EACjB,6BAA6B;CAC/B,CAAC,CACH;AACF,CAAC;AAED,MAAa,qCACX,QACA,WACS;CACT,OAAO,WAAW,QAAQ;EACxB,QAAQ;EACR,OAAO,EAAE,MAAM,OAAO;EACtB,MAAM,QAAQ,IAAI,QAAQ,CAAC,CAAC,OAAO,MAAM;CAC3C,CAAC;CACD,OAAO,mBAAmB,QAAQ;EAChC,QAAQ;EACR,OAAO,EAAE,MAAM,OAAO;EACtB,MAAM,QAAQ,IAAI,QAAQ,CAAC,CAAC,KAAK,MAAM;CACzC,CAAC;CACD,OAAO,aAAa,QAAQ;EAC1B,QAAQ;EACR,OAAO,CAAC;EACR,MAAM,QAAQ,IAAI,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,SAAS;CACtD,CAAC;CAED,IAAI,CAAC,OAAO,gBAAgB,OAAO,aAAa,WAAW,MACzD,OAAO,eAAe,aAAa;CAErC,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,WAAW,MACvD,OAAO,cAAc,YAAY;AAErC"}
@@ -1 +1 @@
1
- {"version":3,"file":"suggestions.d.ts","names":[],"sources":["../../../src/store/clients/suggestions.ts"],"mappings":";;;KAMY,gBAAA;EAEN,KAAA;EAAe,KAAA;EAAe,MAAA;AAAA;AAAA,cAkDvB,WAAA;EAAA,gCACqB,eAAA,CAC9B,YAAA;EAAA,CAIA,WAAA,EAAa,gBAAA,iCACgB,eAAA,CAC7B,YAAA,iBACA,gBAAA;AAAA"}
1
+ {"version":3,"file":"suggestions.d.ts","names":[],"sources":["../../../src/store/clients/suggestions.ts"],"mappings":";;;KAOY,gBAAA;EAEN,KAAA;EAAe,KAAA;EAAe,MAAA;AAAA;AAAA,cAkDvB,WAAA;EAAA,gCACqB,eAAA,CAC9B,YAAA;EAAA,CAIA,WAAA,EAAa,gBAAA,iCACgB,eAAA,CAC7B,YAAA,iBACA,gBAAA;AAAA"}
@@ -1,11 +1,12 @@
1
- import { tapClientLookup } from "@assistant-ui/store";
2
- import { resource, tapState, withKey } from "@assistant-ui/tap";
1
+ import { useState } from "@assistant-ui/tap/react-shim";
2
+ import { useClientLookup } from "@assistant-ui/store";
3
+ import { resource, withKey } from "@assistant-ui/tap";
3
4
  //#region src/store/clients/suggestions.ts
4
- const SuggestionClient = resource((state) => {
5
+ const SuggestionClient = resource(function SuggestionClient(state) {
5
6
  return { getState: () => state };
6
7
  });
7
- const Suggestions = resource((suggestions) => {
8
- const [state] = tapState(() => {
8
+ const Suggestions = resource(function SuggestionsResource(suggestions) {
9
+ const [state] = useState(() => {
9
10
  return { suggestions: (suggestions ?? []).map((s) => {
10
11
  if (typeof s === "string") return {
11
12
  title: s,
@@ -19,7 +20,7 @@ const Suggestions = resource((suggestions) => {
19
20
  };
20
21
  }) };
21
22
  });
22
- const suggestionClients = tapClientLookup(() => state.suggestions.map((suggestion, index) => withKey(index, SuggestionClient(suggestion))), [state.suggestions]);
23
+ const suggestionClients = useClientLookup(() => state.suggestions.map((suggestion, index) => withKey(index, SuggestionClient(suggestion))), [state.suggestions]);
23
24
  return {
24
25
  getState: () => state,
25
26
  suggestion: ({ index }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"suggestions.js","names":[],"sources":["../../../src/store/clients/suggestions.ts"],"sourcesContent":["import { resource, tapState, withKey } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { tapClientLookup } from \"@assistant-ui/store\";\nimport type { SuggestionsState } from \"../scopes/suggestions\";\nimport type { SuggestionState } from \"../scopes/suggestion\";\n\nexport type SuggestionConfig =\n | string\n | { title: string; label: string; prompt: string };\n\nconst SuggestionClient = resource(\n (state: SuggestionState): ClientOutput<\"suggestion\"> => {\n return {\n getState: () => state,\n };\n },\n);\n\nconst SuggestionsResource = resource(\n (suggestions?: SuggestionConfig[]): ClientOutput<\"suggestions\"> => {\n const [state] = tapState<SuggestionsState>(() => {\n const normalizedSuggestions = (suggestions ?? []).map((s) => {\n if (typeof s === \"string\") {\n return {\n title: s,\n label: \"\",\n prompt: s,\n };\n }\n return {\n title: s.title,\n label: s.label,\n prompt: s.prompt,\n };\n });\n\n return {\n suggestions: normalizedSuggestions,\n };\n });\n\n const suggestionClients = tapClientLookup(\n () =>\n state.suggestions.map((suggestion, index) =>\n withKey(index, SuggestionClient(suggestion)),\n ),\n [state.suggestions],\n );\n\n return {\n getState: () => state,\n suggestion: ({ index }: { index: number }) => {\n return suggestionClients.get({ index });\n },\n };\n },\n);\n\nexport const Suggestions: {\n (): import(\"@assistant-ui/tap\").ResourceElement<\n ClientOutput<\"suggestions\">,\n undefined\n >;\n (\n suggestions: SuggestionConfig[],\n ): import(\"@assistant-ui/tap\").ResourceElement<\n ClientOutput<\"suggestions\">,\n SuggestionConfig[]\n >;\n} = SuggestionsResource as any;\n"],"mappings":";;;AAUA,MAAM,mBAAmB,UACtB,UAAuD;CACtD,OAAO,EACL,gBAAgB,MAClB;AACF,CACF;AA0CA,MAAa,cAxCe,UACzB,gBAAkE;CACjE,MAAM,CAAC,SAAS,eAAiC;EAgB/C,OAAO,EACL,cAhB6B,eAAe,CAAC,GAAG,KAAK,MAAM;GAC3D,IAAI,OAAO,MAAM,UACf,OAAO;IACL,OAAO;IACP,OAAO;IACP,QAAQ;GACV;GAEF,OAAO;IACL,OAAO,EAAE;IACT,OAAO,EAAE;IACT,QAAQ,EAAE;GACZ;EACF,CAGmC,EACnC;CACF,CAAC;CAED,MAAM,oBAAoB,sBAEtB,MAAM,YAAY,KAAK,YAAY,UACjC,QAAQ,OAAO,iBAAiB,UAAU,CAAC,CAC7C,GACF,CAAC,MAAM,WAAW,CACpB;CAEA,OAAO;EACL,gBAAgB;EAChB,aAAa,EAAE,YAA+B;GAC5C,OAAO,kBAAkB,IAAI,EAAE,MAAM,CAAC;EACxC;CACF;AACF,CAcE"}
1
+ {"version":3,"file":"suggestions.js","names":[],"sources":["../../../src/store/clients/suggestions.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { resource, withKey } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { useClientLookup } from \"@assistant-ui/store\";\nimport type { SuggestionsState } from \"../scopes/suggestions\";\nimport type { SuggestionState } from \"../scopes/suggestion\";\n\nexport type SuggestionConfig =\n | string\n | { title: string; label: string; prompt: string };\n\nconst SuggestionClient = resource(function SuggestionClient(\n state: SuggestionState,\n): ClientOutput<\"suggestion\"> {\n return {\n getState: () => state,\n };\n});\n\nconst SuggestionsResource = resource(function SuggestionsResource(\n suggestions?: SuggestionConfig[],\n): ClientOutput<\"suggestions\"> {\n const [state] = useState<SuggestionsState>(() => {\n const normalizedSuggestions = (suggestions ?? []).map((s) => {\n if (typeof s === \"string\") {\n return {\n title: s,\n label: \"\",\n prompt: s,\n };\n }\n return {\n title: s.title,\n label: s.label,\n prompt: s.prompt,\n };\n });\n\n return {\n suggestions: normalizedSuggestions,\n };\n });\n\n const suggestionClients = useClientLookup(\n () =>\n state.suggestions.map((suggestion, index) =>\n withKey(index, SuggestionClient(suggestion)),\n ),\n [state.suggestions],\n );\n\n return {\n getState: () => state,\n suggestion: ({ index }: { index: number }) => {\n return suggestionClients.get({ index });\n },\n };\n});\n\nexport const Suggestions: {\n (): import(\"@assistant-ui/tap\").ResourceElement<\n ClientOutput<\"suggestions\">,\n undefined\n >;\n (\n suggestions: SuggestionConfig[],\n ): import(\"@assistant-ui/tap\").ResourceElement<\n ClientOutput<\"suggestions\">,\n SuggestionConfig[]\n >;\n} = SuggestionsResource as any;\n"],"mappings":";;;;AAWA,MAAM,mBAAmB,SAAS,SAAS,iBACzC,OAC4B;CAC5B,OAAO,EACL,gBAAgB,MAClB;AACF,CAAC;AA0CD,MAAa,cAxCe,SAAS,SAAS,oBAC5C,aAC6B;CAC7B,MAAM,CAAC,SAAS,eAAiC;EAgB/C,OAAO,EACL,cAhB6B,eAAe,CAAC,EAAA,CAAG,KAAK,MAAM;GAC3D,IAAI,OAAO,MAAM,UACf,OAAO;IACL,OAAO;IACP,OAAO;IACP,QAAQ;GACV;GAEF,OAAO;IACL,OAAO,EAAE;IACT,OAAO,EAAE;IACT,QAAQ,EAAE;GACZ;EACF,CAGmC,EACnC;CACF,CAAC;CAED,MAAM,oBAAoB,sBAEtB,MAAM,YAAY,KAAK,YAAY,UACjC,QAAQ,OAAO,iBAAiB,UAAU,CAAC,CAC7C,GACF,CAAC,MAAM,WAAW,CACpB;CAEA,OAAO;EACL,gBAAgB;EAChB,aAAa,EAAE,YAA+B;GAC5C,OAAO,kBAAkB,IAAI,EAAE,MAAM,CAAC;EACxC;CACF;AACF,CAaI"}
@@ -1 +1 @@
1
- {"version":3,"file":"thread-message-client.d.ts","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"mappings":";;;;KAyDY,wBAAA;EACV,OAAA,EAAS,aAAa;EACtB,KAAA;EACA,MAAA;EACA,YAAA;EACA,WAAA;AAAA;AAAA,cAGW,mBAAA,GAAmB,KAAA,EAAA,wBAAA,iCAAA,eAAA,CAAA,YAAA,aAAA,wBAAA"}
1
+ {"version":3,"file":"thread-message-client.d.ts","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"mappings":";;;;KAsDY,wBAAA;EACV,OAAA,EAAS,aAAa;EACtB,KAAA;EACA,MAAA;EACA,YAAA;EACA,WAAA;AAAA;AAAA,cAGW,mBAAA,GAAmB,KAAA,EAAA,wBAAA,iCAAA,eAAA,CAAA,YAAA,aAAA,wBAAA"}
@@ -1,9 +1,10 @@
1
1
  import { NoOpComposerClient } from "./no-op-composer-client.js";
2
- import { tapClientLookup } from "@assistant-ui/store";
3
- import { resource, tapMemo, tapResource, tapState, withKey } from "@assistant-ui/tap";
2
+ import { useMemo, useState } from "@assistant-ui/tap/react-shim";
3
+ import { useClientLookup } from "@assistant-ui/store";
4
+ import { resource, useResource, withKey } from "@assistant-ui/tap";
4
5
  //#region src/store/clients/thread-message-client.ts
5
- const ThreadMessagePartClient = resource(({ part }) => {
6
- const state = tapMemo(() => {
6
+ const ThreadMessagePartClient = resource(function ThreadMessagePartClient({ part }) {
7
+ const state = useMemo(() => {
7
8
  return {
8
9
  ...part,
9
10
  status: { type: "complete" }
@@ -22,7 +23,7 @@ const ThreadMessagePartClient = resource(({ part }) => {
22
23
  }
23
24
  };
24
25
  });
25
- const ThreadMessageAttachmentClient = resource(({ attachment }) => {
26
+ const ThreadMessageAttachmentClient = resource(function ThreadMessageAttachmentClient({ attachment }) {
26
27
  return {
27
28
  getState: () => attachment,
28
29
  remove: () => {
@@ -30,14 +31,14 @@ const ThreadMessageAttachmentClient = resource(({ attachment }) => {
30
31
  }
31
32
  };
32
33
  });
33
- const ThreadMessageClient = resource(({ message, index, isLast = true, branchNumber = 1, branchCount = 1 }) => {
34
- const [isCopiedState, setIsCopied] = tapState(false);
35
- const [isHoveringState, setIsHovering] = tapState(false);
36
- const parts = tapClientLookup(() => message.content.map((part, idx) => withKey("toolCallId" in part && part.toolCallId != null ? `toolCallId-${part.toolCallId}` : `index-${idx}`, ThreadMessagePartClient({ part }))), [message.content]);
37
- const attachments = tapClientLookup(() => (message.attachments ?? []).map((attachment) => withKey(attachment.id, ThreadMessageAttachmentClient({ attachment }))), [message.attachments]);
38
- const composer = tapResource(NoOpComposerClient({ type: "edit" }));
34
+ const ThreadMessageClient = resource(function ThreadMessageClient({ message, index, isLast = true, branchNumber = 1, branchCount = 1 }) {
35
+ const [isCopiedState, setIsCopied] = useState(false);
36
+ const [isHoveringState, setIsHovering] = useState(false);
37
+ const parts = useClientLookup(() => message.content.map((part, idx) => withKey("toolCallId" in part && part.toolCallId != null ? `toolCallId-${part.toolCallId}` : `index-${idx}`, ThreadMessagePartClient({ part }))), [message.content]);
38
+ const attachments = useClientLookup(() => (message.attachments ?? []).map((attachment) => withKey(attachment.id, ThreadMessageAttachmentClient({ attachment }))), [message.attachments]);
39
+ const composer = useResource(NoOpComposerClient({ type: "edit" }));
39
40
  const composerState = composer.getState();
40
- const state = tapMemo(() => {
41
+ const state = useMemo(() => {
41
42
  return {
42
43
  ...message,
43
44
  parts: parts.state,
@@ -1 +1 @@
1
- {"version":3,"file":"thread-message-client.js","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ThreadMessage,\n} from \"../../types/message\";\nimport type { Attachment } from \"../../types/attachment\";\nimport {\n resource,\n tapMemo,\n tapState,\n tapResource,\n withKey,\n} from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { tapClientLookup } from \"@assistant-ui/store\";\nimport type { MessageState } from \"../scopes/message\";\nimport type { PartState } from \"../scopes/part\";\nimport { NoOpComposerClient } from \"./no-op-composer-client\";\n\nconst ThreadMessagePartClient = resource(\n ({\n part,\n }: {\n part: ThreadAssistantMessagePart | ThreadUserMessagePart;\n }): ClientOutput<\"part\"> => {\n const state = tapMemo<PartState>(() => {\n return {\n ...part,\n status: { type: \"complete\" },\n };\n }, [part]);\n\n return {\n getState: () => state,\n addToolResult: () => {\n throw new Error(\"Not supported\");\n },\n resumeToolCall: () => {\n throw new Error(\"Not supported\");\n },\n respondToToolApproval: () => {\n throw new Error(\"Not supported\");\n },\n };\n },\n);\n\nconst ThreadMessageAttachmentClient = resource(\n ({ attachment }: { attachment: Attachment }): ClientOutput<\"attachment\"> => {\n return {\n getState: () => attachment,\n remove: () => {\n throw new Error(\"Not supported\");\n },\n };\n },\n);\nexport type ThreadMessageClientProps = {\n message: ThreadMessage;\n index: number;\n isLast?: boolean;\n branchNumber?: number;\n branchCount?: number;\n};\n\nexport const ThreadMessageClient = resource(\n ({\n message,\n index,\n isLast = true,\n branchNumber = 1,\n branchCount = 1,\n }: ThreadMessageClientProps): ClientOutput<\"message\"> => {\n const [isCopiedState, setIsCopied] = tapState(false);\n const [isHoveringState, setIsHovering] = tapState(false);\n\n const parts = tapClientLookup(\n () =>\n message.content.map((part, idx) =>\n withKey(\n \"toolCallId\" in part && part.toolCallId != null\n ? `toolCallId-${part.toolCallId}`\n : `index-${idx}`,\n ThreadMessagePartClient({ part }),\n ),\n ),\n [message.content],\n );\n\n const attachments = tapClientLookup(\n () =>\n (message.attachments ?? []).map((attachment) =>\n withKey(attachment.id, ThreadMessageAttachmentClient({ attachment })),\n ),\n [message.attachments],\n );\n\n const composer = tapResource(NoOpComposerClient({ type: \"edit\" }));\n const composerState = composer.getState();\n\n const state = tapMemo<MessageState>(() => {\n return {\n ...message,\n parts: parts.state,\n composer: composerState,\n parentId: null,\n index,\n isLast,\n branchNumber,\n branchCount,\n speech: undefined,\n isCopied: isCopiedState,\n isHovering: isHoveringState,\n };\n }, [\n message,\n index,\n isCopiedState,\n isHoveringState,\n isLast,\n parts.state,\n composerState,\n branchNumber,\n branchCount,\n ]);\n\n return {\n getState: () => state,\n composer: () => composer,\n part: (selector) => {\n if (\"index\" in selector) {\n return parts.get({ index: selector.index });\n } else {\n return parts.get({ key: `toolCallId-${selector.toolCallId}` });\n }\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachments.get({ key: selector.id });\n } else {\n return attachments.get(selector);\n }\n },\n reload: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n speak: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n stopSpeaking: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n submitFeedback: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n switchToBranch: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n getCopyText: () => {\n return message.content\n .map((part) => {\n if (\"text\" in part && typeof part.text === \"string\") {\n return part.text;\n }\n return \"\";\n })\n .join(\"\\n\");\n },\n setIsCopied,\n setIsHovering,\n };\n },\n);\n"],"mappings":";;;;AAmBA,MAAM,0BAA0B,UAC7B,EACC,WAG0B;CAC1B,MAAM,QAAQ,cAAyB;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,EAAE,MAAM,WAAW;EAC7B;CACF,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;EACL,gBAAgB;EAChB,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,6BAA6B;GAC3B,MAAM,IAAI,MAAM,eAAe;EACjC;CACF;AACF,CACF;AAEA,MAAM,gCAAgC,UACnC,EAAE,iBAAyE;CAC1E,OAAO;EACL,gBAAgB;EAChB,cAAc;GACZ,MAAM,IAAI,MAAM,eAAe;EACjC;CACF;AACF,CACF;AASA,MAAa,sBAAsB,UAChC,EACC,SACA,OACA,SAAS,MACT,eAAe,GACf,cAAc,QACyC;CACvD,MAAM,CAAC,eAAe,eAAe,SAAS,KAAK;CACnD,MAAM,CAAC,iBAAiB,iBAAiB,SAAS,KAAK;CAEvD,MAAM,QAAQ,sBAEV,QAAQ,QAAQ,KAAK,MAAM,QACzB,QACE,gBAAgB,QAAQ,KAAK,cAAc,OACvC,cAAc,KAAK,eACnB,SAAS,OACb,wBAAwB,EAAE,KAAK,CAAC,CAClC,CACF,GACF,CAAC,QAAQ,OAAO,CAClB;CAEA,MAAM,cAAc,uBAEf,QAAQ,eAAe,CAAC,GAAG,KAAK,eAC/B,QAAQ,WAAW,IAAI,8BAA8B,EAAE,WAAW,CAAC,CAAC,CACtE,GACF,CAAC,QAAQ,WAAW,CACtB;CAEA,MAAM,WAAW,YAAY,mBAAmB,EAAE,MAAM,OAAO,CAAC,CAAC;CACjE,MAAM,gBAAgB,SAAS,SAAS;CAExC,MAAM,QAAQ,cAA4B;EACxC,OAAO;GACL,GAAG;GACH,OAAO,MAAM;GACb,UAAU;GACV,UAAU;GACV;GACA;GACA;GACA;GACA,QAAQ,KAAA;GACR,UAAU;GACV,YAAY;EACd;CACF,GAAG;EACD;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA;EACA;CACF,CAAC;CAED,OAAO;EACL,gBAAgB;EAChB,gBAAgB;EAChB,OAAO,aAAa;GAClB,IAAI,WAAW,UACb,OAAO,MAAM,IAAI,EAAE,OAAO,SAAS,MAAM,CAAC;QAE1C,OAAO,MAAM,IAAI,EAAE,KAAK,cAAc,SAAS,aAAa,CAAC;EAEjE;EACA,aAAa,aAAa;GACxB,IAAI,QAAQ,UACV,OAAO,YAAY,IAAI,EAAE,KAAK,SAAS,GAAG,CAAC;QAE3C,OAAO,YAAY,IAAI,QAAQ;EAEnC;EACA,cAAc;GACZ,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,aAAa;GACX,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,oBAAoB;GAClB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,mBAAmB;GACjB,OAAO,QAAQ,QACZ,KAAK,SAAS;IACb,IAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UACzC,OAAO,KAAK;IAEd,OAAO;GACT,CAAC,EACA,KAAK,IAAI;EACd;EACA;EACA;CACF;AACF,CACF"}
1
+ {"version":3,"file":"thread-message-client.js","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ThreadMessage,\n} from \"../../types/message\";\nimport type { Attachment } from \"../../types/attachment\";\nimport { useMemo, useState } from \"react\";\nimport { useResource, resource, withKey } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { useClientLookup } from \"@assistant-ui/store\";\nimport type { MessageState } from \"../scopes/message\";\nimport type { PartState } from \"../scopes/part\";\nimport { NoOpComposerClient } from \"./no-op-composer-client\";\n\nconst ThreadMessagePartClient = resource(function ThreadMessagePartClient({\n part,\n}: {\n part: ThreadAssistantMessagePart | ThreadUserMessagePart;\n}): ClientOutput<\"part\"> {\n const state = useMemo<PartState>(() => {\n return {\n ...part,\n status: { type: \"complete\" },\n };\n }, [part]);\n\n return {\n getState: () => state,\n addToolResult: () => {\n throw new Error(\"Not supported\");\n },\n resumeToolCall: () => {\n throw new Error(\"Not supported\");\n },\n respondToToolApproval: () => {\n throw new Error(\"Not supported\");\n },\n };\n});\n\nconst ThreadMessageAttachmentClient = resource(\n function ThreadMessageAttachmentClient({\n attachment,\n }: {\n attachment: Attachment;\n }): ClientOutput<\"attachment\"> {\n return {\n getState: () => attachment,\n remove: () => {\n throw new Error(\"Not supported\");\n },\n };\n },\n);\nexport type ThreadMessageClientProps = {\n message: ThreadMessage;\n index: number;\n isLast?: boolean;\n branchNumber?: number;\n branchCount?: number;\n};\n\nexport const ThreadMessageClient = resource(function ThreadMessageClient({\n message,\n index,\n isLast = true,\n branchNumber = 1,\n branchCount = 1,\n}: ThreadMessageClientProps): ClientOutput<\"message\"> {\n const [isCopiedState, setIsCopied] = useState(false);\n const [isHoveringState, setIsHovering] = useState(false);\n\n const parts = useClientLookup(\n () =>\n message.content.map((part, idx) =>\n withKey(\n \"toolCallId\" in part && part.toolCallId != null\n ? `toolCallId-${part.toolCallId}`\n : `index-${idx}`,\n ThreadMessagePartClient({ part }),\n ),\n ),\n [message.content],\n );\n\n const attachments = useClientLookup(\n () =>\n (message.attachments ?? []).map((attachment) =>\n withKey(attachment.id, ThreadMessageAttachmentClient({ attachment })),\n ),\n [message.attachments],\n );\n\n const composer = useResource(NoOpComposerClient({ type: \"edit\" }));\n const composerState = composer.getState();\n\n const state = useMemo<MessageState>(() => {\n return {\n ...message,\n parts: parts.state,\n composer: composerState,\n parentId: null,\n index,\n isLast,\n branchNumber,\n branchCount,\n speech: undefined,\n isCopied: isCopiedState,\n isHovering: isHoveringState,\n };\n }, [\n message,\n index,\n isCopiedState,\n isHoveringState,\n isLast,\n parts.state,\n composerState,\n branchNumber,\n branchCount,\n ]);\n\n return {\n getState: () => state,\n composer: () => composer,\n part: (selector) => {\n if (\"index\" in selector) {\n return parts.get({ index: selector.index });\n } else {\n return parts.get({ key: `toolCallId-${selector.toolCallId}` });\n }\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachments.get({ key: selector.id });\n } else {\n return attachments.get(selector);\n }\n },\n reload: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n speak: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n stopSpeaking: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n submitFeedback: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n switchToBranch: () => {\n throw new Error(\"Not supported in ThreadMessageProvider\");\n },\n getCopyText: () => {\n return message.content\n .map((part) => {\n if (\"text\" in part && typeof part.text === \"string\") {\n return part.text;\n }\n return \"\";\n })\n .join(\"\\n\");\n },\n setIsCopied,\n setIsHovering,\n };\n});\n"],"mappings":";;;;;AAcA,MAAM,0BAA0B,SAAS,SAAS,wBAAwB,EACxE,QAGuB;CACvB,MAAM,QAAQ,cAAyB;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,EAAE,MAAM,WAAW;EAC7B;CACF,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;EACL,gBAAgB;EAChB,qBAAqB;GACnB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,eAAe;EACjC;EACA,6BAA6B;GAC3B,MAAM,IAAI,MAAM,eAAe;EACjC;CACF;AACF,CAAC;AAED,MAAM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AI,EAAE,KAAK,SAAS,GAAG,CAAC;QAE3C,OAAO,YAAY,IAAI,QAAQ;EAEnC;EACA,cAAc;GACZ,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,aAAa;GACX,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,oBAAoB;GAClB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,sBAAsB;GACpB,MAAM,IAAI,MAAM,wCAAwC;EAC1D;EACA,mBAAmB;GACjB,OAAO,QAAQ,QACZ,KAAK,SAAS;IACb,IAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UACzC,OAAO,KAAK;IAEd,OAAO;GACT,CAAC,CAAC,CACD,KAAK,IAAI;EACd;EACA;EACA;CACF;AACF,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./scope-registration.d.ts" />
2
+ import { QueueItemClientSchema, QueueItemMeta, QueueItemMethods, QueueItemState } from "./scopes/queue-item.js";
2
3
  import { ThreadListItemClientSchema, ThreadListItemEvents, ThreadListItemMeta, ThreadListItemMethods, ThreadListItemState } from "./scopes/thread-list-item.js";
3
4
  import { AttachmentClientSchema, AttachmentMeta, AttachmentMethods, AttachmentState } from "./scopes/attachment.js";
4
- import { QueueItemClientSchema, QueueItemMeta, QueueItemMethods, QueueItemState } from "./scopes/queue-item.js";
5
5
  import { ComposerClientSchema, ComposerEvents, ComposerMeta, ComposerMethods, ComposerSendOptions, ComposerState } from "./scopes/composer.js";
6
6
  import { PartClientSchema, PartMeta, PartMethods, PartState } from "./scopes/part.js";
7
7
  import { MessageClientSchema, MessageMeta, MessageMethods, MessageState } from "./scopes/message.js";
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"mappings":";;;;cAKa,uBAAA,GAAuB,KAAA;WACT,iBAAA;AAAA;WAAA,iBAAA;AAAA"}
1
+ {"version":3,"file":"attachment-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"mappings":";;;;cAKa,uBAAA,GAAuB,KAAA;WAIvB,iBAAA;AAAA;WAAA,iBAAA;AAAA"}
@@ -1,8 +1,8 @@
1
- import { tapSubscribable } from "./tap-subscribable.js";
1
+ import { useSubscribable } from "./useSubscribable.js";
2
2
  import { resource } from "@assistant-ui/tap";
3
3
  //#region src/store/runtime-clients/attachment-runtime-client.ts
4
- const AttachmentRuntimeClient = resource(({ runtime }) => {
5
- const state = tapSubscribable(runtime);
4
+ const AttachmentRuntimeClient = resource(function AttachmentRuntimeClient({ runtime }) {
5
+ const state = useSubscribable(runtime);
6
6
  return {
7
7
  getState: () => state,
8
8
  remove: runtime.remove,
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-runtime-client.js","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type { AttachmentRuntime } from \"../../runtime/api/attachment-runtime\";\nimport { tapSubscribable } from \"./tap-subscribable\";\n\nexport const AttachmentRuntimeClient = resource(\n ({ runtime }: { runtime: AttachmentRuntime }): ClientOutput<\"attachment\"> => {\n const state = tapSubscribable(runtime);\n\n return {\n getState: () => state,\n remove: runtime.remove,\n __internal_getRuntime: () => runtime,\n };\n },\n);\n"],"mappings":";;;AAKA,MAAa,0BAA0B,UACpC,EAAE,cAA0E;CAC3E,MAAM,QAAQ,gBAAgB,OAAO;CAErC,OAAO;EACL,gBAAgB;EAChB,QAAQ,QAAQ;EAChB,6BAA6B;CAC/B;AACF,CACF"}
1
+ {"version":3,"file":"attachment-runtime-client.js","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type { AttachmentRuntime } from \"../../runtime/api/attachment-runtime\";\nimport { useSubscribable } from \"./useSubscribable\";\n\nexport const AttachmentRuntimeClient = resource(\n function AttachmentRuntimeClient({\n runtime,\n }: {\n runtime: AttachmentRuntime;\n }): ClientOutput<\"attachment\"> {\n const state = useSubscribable(runtime);\n\n return {\n getState: () => state,\n remove: runtime.remove,\n __internal_getRuntime: () => runtime,\n };\n },\n);\n"],"mappings":";;;AAKA,MAAa,0BAA0B,SACrC,SAAS,wBAAwB,EAC/B,WAG6B;CAC7B,MAAM,QAAQ,gBAAgB,OAAO;CAErC,OAAO;EACL,gBAAgB;EAChB,QAAQ,QAAQ;EAChB,6BAA6B;CAC/B;AACF,CACF"}
@@ -1,15 +1,22 @@
1
1
  import { ComposerRuntime } from "../../runtime/api/composer-runtime.js";
2
2
  import { ClientOutput } from "@assistant-ui/store";
3
- import { tapRef } from "@assistant-ui/tap";
4
3
 
5
4
  //#region src/store/runtime-clients/composer-runtime-client.d.ts
6
5
  declare const ComposerClient: (props: {
7
- threadIdRef: tapRef.RefObject<string>;
8
- messageIdRef?: tapRef.RefObject<string>;
6
+ threadIdRef: {
7
+ current: string;
8
+ };
9
+ messageIdRef?: {
10
+ current: string;
11
+ };
9
12
  runtime: ComposerRuntime;
10
13
  }) => import("@assistant-ui/tap").ResourceElement<ClientOutput<"composer">, {
11
- threadIdRef: tapRef.RefObject<string>;
12
- messageIdRef?: tapRef.RefObject<string>;
14
+ threadIdRef: {
15
+ current: string;
16
+ };
17
+ messageIdRef?: {
18
+ current: string;
19
+ };
13
20
  runtime: ComposerRuntime;
14
21
  }>;
15
22
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"composer-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/composer-runtime-client.ts"],"mappings":";;;;;cAqCa,cAAA,GAAc,KAAA;eAMV,MAAA,CAAO,SAAA;iBACL,MAAA,CAAO,SAAA;WACb,eAAA;AAAA;eAFI,MAAA,CAAO,SAAA;iBACL,MAAA,CAAO,SAAA;WACb,eAAA;AAAA"}
1
+ {"version":3,"file":"composer-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/composer-runtime-client.ts"],"mappings":";;;;cAsDa,cAAA,GAAc,KAAA;;IAKV,OAAA;EAAA;;IACE,OAAA;EAAA;WACR,eAAA;AAAA;;IAFM,OAAA;EAAA;;IACE,OAAA;EAAA;WACR,eAAA;AAAA"}