@assistant-ui/core 0.3.15 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/internal.d.ts +8 -2
  5. package/dist/internal.js +9 -3
  6. package/dist/model-context/frame/host.d.ts.map +1 -1
  7. package/dist/model-context/frame/host.js +3 -2
  8. package/dist/model-context/frame/host.js.map +1 -1
  9. package/dist/model-context/frame/provider.d.ts +5 -0
  10. package/dist/model-context/frame/provider.d.ts.map +1 -1
  11. package/dist/model-context/frame/provider.js +141 -28
  12. package/dist/model-context/frame/provider.js.map +1 -1
  13. package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
  14. package/dist/model-context/interactable-composer-metadata.js +1 -1
  15. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  16. package/dist/model-context/registry.d.ts +2 -2
  17. package/dist/model-context/registry.d.ts.map +1 -1
  18. package/dist/model-context/registry.js +9 -28
  19. package/dist/model-context/registry.js.map +1 -1
  20. package/dist/model-context/tool-call-text.d.ts +26 -0
  21. package/dist/model-context/tool-call-text.d.ts.map +1 -0
  22. package/dist/model-context/tool-call-text.js +18 -0
  23. package/dist/model-context/tool-call-text.js.map +1 -0
  24. package/dist/react/RuntimeAdapter.js +1 -1
  25. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  26. package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
  27. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  28. package/dist/react/client/AdaptedRemoteThread.js +1 -1
  29. package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
  30. package/dist/react/client/InMemoryThreadList.js +25 -21
  31. package/dist/react/client/InMemoryThreadList.js.map +1 -1
  32. package/dist/react/client/Interactables.d.ts.map +1 -1
  33. package/dist/react/client/Interactables.js +60 -178
  34. package/dist/react/client/Interactables.js.map +1 -1
  35. package/dist/react/client/RemoteThreadList.d.ts +15 -0
  36. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  37. package/dist/react/client/RemoteThreadList.js +263 -194
  38. package/dist/react/client/RemoteThreadList.js.map +1 -1
  39. package/dist/react/client/Tools.d.ts.map +1 -1
  40. package/dist/react/client/Tools.js +6 -2
  41. package/dist/react/client/Tools.js.map +1 -1
  42. package/dist/react/index.d.ts +4 -2
  43. package/dist/react/index.js +2 -1
  44. package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
  45. package/dist/react/interactables-legacy/Interactables.js +60 -178
  46. package/dist/react/interactables-legacy/Interactables.js.map +1 -1
  47. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
  48. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
  49. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
  50. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
  51. package/dist/react/model-context/toolbox.d.ts +2 -14
  52. package/dist/react/model-context/toolbox.d.ts.map +1 -1
  53. package/dist/react/model-context/toolbox.js +1 -13
  54. package/dist/react/model-context/toolbox.js.map +1 -1
  55. package/dist/react/model-context/useAssistantContext.js +37 -7
  56. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  57. package/dist/react/model-context/useAuiToolOverrides.js +31 -5
  58. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  59. package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
  60. package/dist/react/model-context/useInlineRender.js +10 -36
  61. package/dist/react/model-context/useInlineRender.js.map +1 -1
  62. package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
  63. package/dist/react/primitive-hooks/useMessageError.js +2 -8
  64. package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
  65. package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
  66. package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
  67. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  68. package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  69. package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
  70. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  71. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  72. package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
  73. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  74. package/dist/react/primitives/composer/ComposerQueue.js +4 -3
  75. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  76. package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
  77. package/dist/react/primitives/message/MessageAttachments.js +7 -6
  78. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  79. package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
  80. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  81. package/dist/react/primitives/message/MessageParts.js +3 -3
  82. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  83. package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  84. package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
  85. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  86. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -5
  87. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  88. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
  89. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  90. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -6
  91. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  92. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +102 -117
  93. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  94. package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
  95. package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
  96. package/dist/react/runtimes/RemoteThreadResource.js +3 -3
  97. package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
  98. package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
  99. package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
  100. package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
  101. package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
  102. package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
  103. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
  104. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  105. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +43 -85
  106. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  107. package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
  108. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  109. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  110. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
  111. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
  112. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
  113. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
  114. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
  115. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
  116. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
  117. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
  118. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
  119. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  120. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
  121. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  122. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
  123. package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
  124. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  125. package/dist/react/runtimes/external-message-converter.d.ts +6 -25
  126. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  127. package/dist/react/runtimes/external-message-converter.js +33 -233
  128. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  129. package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
  130. package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
  131. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  132. package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
  133. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  134. package/dist/react/types/scopes/tools.d.ts +2 -0
  135. package/dist/react/types/scopes/tools.d.ts.map +1 -1
  136. package/dist/runtime/api/composer-runtime.d.ts +1 -1
  137. package/dist/runtime/api/composer-runtime.js.map +1 -1
  138. package/dist/runtime/api/message-part-runtime.d.ts +2 -2
  139. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  140. package/dist/runtime/api/message-part-runtime.js +1 -1
  141. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  142. package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
  143. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  144. package/dist/runtime/api/thread-list-runtime.js +5 -0
  145. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  146. package/dist/runtime/api/thread-runtime.d.ts +2 -3
  147. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  148. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
  149. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  150. package/dist/runtime/base/base-composer-runtime-core.js +14 -29
  151. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  152. package/dist/runtime/base/base-thread-runtime-core.d.ts +4 -6
  153. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  154. package/dist/runtime/base/base-thread-runtime-core.js +5 -11
  155. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  156. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
  157. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  158. package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
  159. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  160. package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
  161. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
  162. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  163. package/dist/runtime/interfaces/thread-runtime-core.d.ts +16 -2
  164. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  165. package/dist/runtime/internal.d.ts +2 -1
  166. package/dist/runtime/internal.js +2 -1
  167. package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
  168. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  169. package/dist/runtime/queue/message-queue.js +1 -1
  170. package/dist/runtime/queue/message-queue.js.map +1 -1
  171. package/dist/runtime/queue/queue-item.d.ts +12 -0
  172. package/dist/runtime/queue/queue-item.d.ts.map +1 -0
  173. package/dist/runtime/queue/queue-item.js +6 -0
  174. package/dist/runtime/queue/queue-item.js.map +1 -0
  175. package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
  176. package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
  177. package/dist/runtime/utils/abortable-thread-load.js +35 -0
  178. package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
  179. package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
  180. package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
  181. package/dist/runtime/utils/attachment-add-operations.js +43 -0
  182. package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
  183. package/dist/runtime/utils/auto-status.d.ts +7 -2
  184. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  185. package/dist/runtime/utils/auto-status.js +13 -3
  186. package/dist/runtime/utils/auto-status.js.map +1 -1
  187. package/dist/runtime/utils/external-message-conversion.d.ts +48 -0
  188. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
  189. package/dist/runtime/utils/external-message-conversion.js +222 -0
  190. package/dist/runtime/utils/external-message-conversion.js.map +1 -0
  191. package/dist/runtime/utils/external-store-message.d.ts +2 -1
  192. package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
  193. package/dist/runtime/utils/external-store-message.js +2 -1
  194. package/dist/runtime/utils/external-store-message.js.map +1 -1
  195. package/dist/runtime/utils/message-repository-session.d.ts +30 -0
  196. package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
  197. package/dist/runtime/utils/message-repository-session.js +130 -0
  198. package/dist/runtime/utils/message-repository-session.js.map +1 -0
  199. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  200. package/dist/runtime/utils/message-repository.js +3 -4
  201. package/dist/runtime/utils/message-repository.js.map +1 -1
  202. package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
  203. package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
  204. package/dist/runtime/utils/pending-tool-calls.js +22 -0
  205. package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
  206. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
  207. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
  208. package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
  209. package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
  210. package/dist/runtime/utils/thread-message-like.d.ts +3 -10
  211. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  212. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  213. package/dist/runtime/utils/tool-call-tree.d.ts +39 -0
  214. package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
  215. package/dist/runtime/utils/tool-call-tree.js +85 -0
  216. package/dist/runtime/utils/tool-call-tree.js.map +1 -0
  217. package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
  218. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  219. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
  220. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  221. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +3 -10
  222. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  223. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +21 -2
  224. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  225. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +154 -46
  226. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  227. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
  228. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
  229. package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
  230. package/dist/runtimes/local/local-thread-runtime-core.d.ts +4 -2
  231. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  232. package/dist/runtimes/local/local-thread-runtime-core.js +23 -3
  233. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  234. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
  235. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  236. package/dist/runtimes/remote-thread-list/remote-thread-state.js +107 -14
  237. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  238. package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
  239. package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
  240. package/dist/runtimes/remote-thread-list/title.js +6 -0
  241. package/dist/runtimes/remote-thread-list/title.js.map +1 -0
  242. package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
  243. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  244. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
  245. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  246. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +98 -59
  247. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  248. package/dist/store/clients/external-thread.d.ts +1 -1
  249. package/dist/store/clients/external-thread.d.ts.map +1 -1
  250. package/dist/store/clients/external-thread.js +85 -103
  251. package/dist/store/clients/external-thread.js.map +1 -1
  252. package/dist/store/clients/single-thread-list.d.ts.map +1 -1
  253. package/dist/store/clients/single-thread-list.js +2 -2
  254. package/dist/store/clients/single-thread-list.js.map +1 -1
  255. package/dist/store/clients/suggestions.d.ts.map +1 -1
  256. package/dist/store/clients/suggestions.js +33 -12
  257. package/dist/store/clients/suggestions.js.map +1 -1
  258. package/dist/store/clients/thread-message-client.js +1 -1
  259. package/dist/store/clients/thread-selection-events.js +1 -1
  260. package/dist/store/index.d.ts +6 -3
  261. package/dist/store/index.js +2 -1
  262. package/dist/store/internal.d.ts +2 -2
  263. package/dist/store/internal.js +2 -2
  264. package/dist/store/primitive-predicates.d.ts +4 -1
  265. package/dist/store/primitive-predicates.d.ts.map +1 -1
  266. package/dist/store/primitive-predicates.js +9 -1
  267. package/dist/store/primitive-predicates.js.map +1 -1
  268. package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
  269. package/dist/store/runtime-clients/message-runtime-client.js +1 -1
  270. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
  271. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  272. package/dist/store/runtime-clients/thread-list-runtime-client.js +124 -105
  273. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  274. package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
  275. package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
  276. package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
  277. package/dist/store/runtime-clients/useSubscribable.js +1 -1
  278. package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
  279. package/dist/store/scope-registration.d.ts +1 -1
  280. package/dist/store/scopes/composer.d.ts +2 -1
  281. package/dist/store/scopes/composer.d.ts.map +1 -1
  282. package/dist/store/scopes/message.d.ts +1 -1
  283. package/dist/store/scopes/part.d.ts +6 -3
  284. package/dist/store/scopes/part.d.ts.map +1 -1
  285. package/dist/store/scopes/queue-item.d.ts +2 -9
  286. package/dist/store/scopes/queue-item.d.ts.map +1 -1
  287. package/dist/store/scopes/queue-item.js +0 -6
  288. package/dist/subscribable/subscribable.d.ts +8 -1
  289. package/dist/subscribable/subscribable.d.ts.map +1 -1
  290. package/dist/subscribable/subscribable.js +24 -16
  291. package/dist/subscribable/subscribable.js.map +1 -1
  292. package/dist/types/message.d.ts +47 -4
  293. package/dist/types/message.d.ts.map +1 -1
  294. package/dist/types/message.js +7 -1
  295. package/dist/types/message.js.map +1 -1
  296. package/dist/utils/data-url.d.ts +14 -1
  297. package/dist/utils/data-url.d.ts.map +1 -1
  298. package/dist/utils/data-url.js +13 -1
  299. package/dist/utils/data-url.js.map +1 -1
  300. package/dist/utils/invoke-user-callback.d.ts +5 -0
  301. package/dist/utils/invoke-user-callback.d.ts.map +1 -0
  302. package/dist/utils/invoke-user-callback.js +19 -0
  303. package/dist/utils/invoke-user-callback.js.map +1 -0
  304. package/dist/utils/normalizePartStatus.js.map +1 -1
  305. package/package.json +12 -17
  306. package/src/index.ts +6 -1
  307. package/src/internal.ts +20 -0
  308. package/src/model-context/frame/host.test.ts +91 -7
  309. package/src/model-context/frame/host.ts +7 -2
  310. package/src/model-context/frame/provider.test.ts +484 -13
  311. package/src/model-context/frame/provider.ts +205 -35
  312. package/src/model-context/interactable-composer-metadata.ts +1 -1
  313. package/src/model-context/registry.test.ts +44 -0
  314. package/src/model-context/registry.ts +13 -35
  315. package/src/model-context/tool-call-text.test.ts +67 -0
  316. package/src/model-context/tool-call-text.ts +67 -0
  317. package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
  318. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
  319. package/src/react/client/InMemoryThreadList.test.tsx +49 -0
  320. package/src/react/client/InMemoryThreadList.ts +7 -1
  321. package/src/react/client/Interactables.ts +19 -178
  322. package/src/react/client/RemoteThreadList.background.test.ts +384 -0
  323. package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
  324. package/src/react/client/RemoteThreadList.test.ts +369 -1
  325. package/src/react/client/RemoteThreadList.ts +320 -142
  326. package/src/react/client/Tools.ts +7 -1
  327. package/src/react/index.ts +4 -0
  328. package/src/react/interactables-legacy/Interactables.ts +20 -177
  329. package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
  330. package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
  331. package/src/react/model-context/modelContextHooks.test.tsx +131 -0
  332. package/src/react/model-context/toolbox.test.ts +9 -9
  333. package/src/react/model-context/toolbox.ts +9 -36
  334. package/src/react/model-context/useAssistantContext.ts +4 -2
  335. package/src/react/model-context/useAuiToolOverrides.ts +4 -2
  336. package/src/react/model-context/useInlineRender.test.tsx +48 -0
  337. package/src/react/model-context/useInlineRender.ts +14 -10
  338. package/src/react/primitive-hooks/useMessageError.ts +2 -19
  339. package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
  340. package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
  341. package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
  342. package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
  343. package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
  344. package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
  345. package/src/react/primitives/message/MessageAttachments.tsx +10 -7
  346. package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
  347. package/src/react/primitives/message/MessageParts.tsx +3 -3
  348. package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
  349. package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
  350. package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
  351. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
  352. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
  353. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +140 -124
  354. package/src/react/runtimes/RemoteThreadResource.ts +1 -4
  355. package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
  356. package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
  357. package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
  358. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
  359. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +157 -1
  360. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +82 -176
  361. package/src/react/runtimes/cloud/auiV0.ts +5 -0
  362. package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
  363. package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
  364. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
  365. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
  366. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
  367. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
  368. package/src/react/runtimes/external-message-converter.test.ts +0 -14
  369. package/src/react/runtimes/external-message-converter.test.tsx +77 -0
  370. package/src/react/runtimes/external-message-converter.ts +59 -481
  371. package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
  372. package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
  373. package/src/react/types/MessagePartComponentTypes.ts +7 -3
  374. package/src/react/types/scopes/tools.ts +2 -0
  375. package/src/runtime/api/composer-runtime.ts +1 -1
  376. package/src/runtime/api/message-part-runtime.ts +3 -3
  377. package/src/runtime/api/message-runtime.test.ts +28 -1
  378. package/src/runtime/api/thread-list-runtime.ts +25 -1
  379. package/src/runtime/base/base-composer-runtime-core.ts +20 -40
  380. package/src/runtime/base/base-thread-runtime-core.test.ts +110 -3
  381. package/src/runtime/base/base-thread-runtime-core.ts +16 -15
  382. package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
  383. package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
  384. package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
  385. package/src/runtime/interfaces/thread-runtime-core.ts +18 -2
  386. package/src/runtime/internal.ts +5 -0
  387. package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
  388. package/src/runtime/queue/message-queue.ts +1 -4
  389. package/src/runtime/queue/queue-item.ts +10 -0
  390. package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
  391. package/src/runtime/utils/abortable-thread-load.ts +53 -0
  392. package/src/runtime/utils/attachment-add-operations.ts +59 -0
  393. package/src/runtime/utils/auto-status.test.ts +57 -0
  394. package/src/runtime/utils/auto-status.ts +46 -1
  395. package/src/runtime/utils/external-message-conversion.test.ts +210 -0
  396. package/src/runtime/utils/external-message-conversion.ts +510 -0
  397. package/src/runtime/utils/external-store-message.ts +2 -0
  398. package/src/runtime/utils/message-repository-session.test.ts +195 -0
  399. package/src/runtime/utils/message-repository-session.ts +176 -0
  400. package/src/runtime/utils/message-repository.ts +7 -4
  401. package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
  402. package/src/runtime/utils/pending-tool-calls.ts +35 -0
  403. package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
  404. package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
  405. package/src/runtime/utils/thread-message-like.ts +4 -10
  406. package/src/runtime/utils/tool-call-tree.test.ts +191 -0
  407. package/src/runtime/utils/tool-call-tree.ts +97 -0
  408. package/src/runtimes/external-store/external-store-adapter.ts +38 -2
  409. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
  410. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +231 -61
  411. package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
  412. package/src/runtimes/local/local-thread-runtime-core.test.ts +201 -4
  413. package/src/runtimes/local/local-thread-runtime-core.ts +53 -4
  414. package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +149 -0
  415. package/src/runtimes/remote-thread-list/remote-thread-state.ts +178 -16
  416. package/src/runtimes/remote-thread-list/title.ts +3 -0
  417. package/src/runtimes/remote-thread-list/types.ts +6 -5
  418. package/src/runtimes/tool-invocations/EDGE_CASES.md +125 -3
  419. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +856 -102
  420. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +145 -89
  421. package/src/store/clients/external-thread.ts +30 -69
  422. package/src/store/clients/single-thread-list.ts +4 -1
  423. package/src/store/clients/suggestions.test.ts +185 -0
  424. package/src/store/clients/suggestions.ts +42 -35
  425. package/src/store/index.ts +4 -0
  426. package/src/store/internal.ts +2 -0
  427. package/src/store/primitive-predicates.ts +35 -0
  428. package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
  429. package/src/store/runtime-clients/useSubscribable.ts +8 -2
  430. package/src/store/scopes/message.ts +1 -1
  431. package/src/store/scopes/part.ts +6 -3
  432. package/src/store/scopes/queue-item.ts +2 -9
  433. package/src/subscribable/subscribable.test.ts +50 -0
  434. package/src/subscribable/subscribable.ts +33 -21
  435. package/src/tests/MessageRepository.test.ts +77 -0
  436. package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +305 -0
  437. package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
  438. package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
  439. package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
  440. package/src/tests/external-store-optimistic-id.test.ts +79 -0
  441. package/src/tests/external-store-repository-instance.test.ts +166 -0
  442. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +186 -16
  443. package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
  444. package/src/tests/external-thread-attachments.test.tsx +258 -1
  445. package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
  446. package/src/tests/single-thread-list-item.test.tsx +47 -0
  447. package/src/tests/thread-message-like.test.ts +39 -1
  448. package/src/tests/thread-switch-events.test.tsx +397 -2
  449. package/src/types/message.ts +58 -5
  450. package/src/utils/data-url.test.ts +52 -1
  451. package/src/utils/data-url.ts +21 -0
  452. package/src/utils/invoke-user-callback.test.ts +82 -0
  453. package/src/utils/invoke-user-callback.ts +31 -0
  454. package/src/utils/normalizePartStatus.ts +1 -1
  455. package/dist/store/scopes/queue-item.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { resolveToolCallText } from "../../model-context/tool-call-text.js";
1
2
  //#region src/react/model-context/toolbox.ts
2
3
  /**
3
4
  * Resolves whether a tool's UI should be presented standalone (outside the
@@ -12,19 +13,6 @@ const isStandaloneToolDisplay = (tool) => {
12
13
  if (tool.display !== void 0) return tool.display === "standalone";
13
14
  return tool.type === "human";
14
15
  };
15
- const resolveToolCallText = (text, part) => {
16
- if (!(part.status?.type === "running" || part.status?.type === "requires-action")) {
17
- const value = text.complete;
18
- if (typeof value !== "function") return value ?? null;
19
- return value({
20
- args: part.args,
21
- result: part.result
22
- });
23
- }
24
- const value = text.running;
25
- if (typeof value !== "function") return value ?? null;
26
- return value({ args: part.args });
27
- };
28
16
  const makeToolCallTextComponent = (text) => {
29
17
  return function ToolCallTextComponent(part) {
30
18
  return resolveToolCallText(text, part);
@@ -1 +1 @@
1
- {"version":3,"file":"toolbox.js","names":["Tool","ToolCallReader","ToolDeclaration","ToolModelOutputFunction","ReactNode","ToolCallMessagePartComponent","ToolCallMessagePartProps","isStandaloneToolDisplay","tool","Pick","display","undefined","type","WithRender","Record","T","render","TArgs","TResult","renderText","ToolCallText","ToolParameters","ToolExecuteContext","Parameters","NonNullable","ToolExecute","args","context","Promise","ToolStreamCall","reader","ToolCallRunningText","options","ToolCallCompleteText","result","running","complete","resolveToolCallText","text","part","isRunning","status","value","makeToolCallTextComponent","ToolCallTextComponent","ToolDefinition","Toolkit","OverrideOptionalField","TKey","Exclude","TValue","OverrideToolDeclarationCallbacks","streamCall","Omit","NoInfer","ToolkitDefinitionInput","ToolkitDefinitionEntry","ToolkitDefinitionEntryWithParameters","parameters","ToolkitDefinition","TArgsByName","K","TResultByName","ToolsConfig","toolkit"],"sources":["../../../src/react/model-context/toolbox.ts"],"sourcesContent":["import type {\n Tool,\n ToolCallReader,\n ToolDeclaration,\n ToolModelOutputFunction,\n} from \"assistant-stream\";\nimport type { ReactNode } from \"react\";\nimport type {\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n} from \"../types/MessagePartComponentTypes\";\n\n/**\n * Resolves whether a tool's UI should be presented standalone (outside the\n * chain-of-thought grouping), applying the type-based defaults.\n *\n * An explicit `display` wins. Otherwise `human` tools default to standalone\n * (they prompt the user), and every other tool defaults to inline (a trace of\n * what the model is doing). MCP-app tool calls are detected separately from\n * the part itself and are not resolved here.\n */\nexport const isStandaloneToolDisplay = (\n tool: Pick<Tool<any, any>, \"type\" | \"display\">,\n): boolean => {\n if (tool.display !== undefined) return tool.display === \"standalone\";\n return tool.type === \"human\";\n};\n\ntype WithRender<T, TArgs extends Record<string, unknown>, TResult> = T extends {\n type: \"frontend\" | \"human\";\n}\n ? T &\n (T extends { type: \"frontend\" }\n ?\n | { render: ToolCallMessagePartComponent<TArgs, TResult> }\n | {\n render?: ToolCallMessagePartComponent<TArgs, TResult>;\n renderText: ToolCallText<TArgs, TResult>;\n }\n : { render: ToolCallMessagePartComponent<TArgs, TResult> })\n : T & {\n render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;\n renderText?: ToolCallText<TArgs, TResult> | undefined;\n };\n\ntype ToolParameters<TArgs extends Record<string, unknown>> =\n ToolDeclaration<TArgs>[\"parameters\"];\n\n// ToolExecutionContext is not re-exported from assistant-stream's public entry.\ntype ToolExecuteContext = Parameters<\n NonNullable<ToolDeclaration[\"execute\"]>\n>[1];\n\ntype ToolExecute<TArgs extends Record<string, unknown>, TResult> = (\n args: TArgs,\n context: ToolExecuteContext,\n) => TResult | Promise<TResult>;\n\ntype ToolStreamCall<TArgs extends Record<string, unknown>, TResult> = (\n reader: ToolCallReader<TArgs, TResult>,\n context: ToolExecuteContext,\n) => void;\n\ntype ToolCallRunningText<TArgs extends Record<string, unknown>> =\n | ReactNode\n | ((options: { args: TArgs }) => ReactNode);\n\ntype ToolCallCompleteText<TArgs extends Record<string, unknown>, TResult> =\n | ReactNode\n | ((options: { args: TArgs; result: TResult | undefined }) => ReactNode);\n\nexport type ToolCallText<TArgs extends Record<string, unknown>, TResult> =\n | {\n running: ToolCallRunningText<TArgs>;\n complete?: ToolCallCompleteText<TArgs, TResult> | undefined;\n }\n | {\n running?: ToolCallRunningText<TArgs> | undefined;\n complete: ToolCallCompleteText<TArgs, TResult>;\n };\n\nconst resolveToolCallText = <TArgs extends Record<string, unknown>, TResult>(\n text: ToolCallText<TArgs, TResult>,\n part: ToolCallMessagePartProps<TArgs, TResult>,\n): ReactNode => {\n const isRunning =\n part.status?.type === \"running\" || part.status?.type === \"requires-action\";\n\n if (!isRunning) {\n const value = text.complete;\n if (typeof value !== \"function\") return value ?? null;\n return value({ args: part.args, result: part.result });\n }\n\n const value = text.running;\n if (typeof value !== \"function\") return value ?? null;\n return value({ args: part.args });\n};\n\nexport const makeToolCallTextComponent = <\n TArgs extends Record<string, unknown>,\n TResult,\n>(\n text: ToolCallText<TArgs, TResult>,\n): ((part: ToolCallMessagePartProps<TArgs, TResult>) => ReactNode) => {\n return function ToolCallTextComponent(part) {\n return resolveToolCallText(text, part);\n };\n};\n\n/**\n * Tool definition accepted by the React tool registry.\n *\n * Extends the core tool contract with tool-call display options. Human tools\n * rely on `render` to collect input from the user. Frontend tools execute in\n * the browser and require either `render` or `renderText` for their progress\n * and result. Backend tools execute server-side and may omit a renderer.\n */\nexport type ToolDefinition<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = WithRender<Tool<TArgs, TResult>, TArgs, TResult>;\n\n/**\n * Named collection of tools exposed to the assistant model.\n *\n * Keys are the tool names the model receives and uses in tool calls.\n *\n * @example\n * ```tsx\n * const toolkit = defineToolkit({\n * get_weather: {\n * type: \"frontend\",\n * description: \"Get the weather for a city.\",\n * parameters: weatherSchema,\n * execute: async ({ city }: { city: string }) => fetchWeather(city),\n * render: WeatherToolUI,\n * },\n * });\n * ```\n */\nexport type Toolkit = Record<string, ToolDefinition<any, any>>;\n\n/**\n * A tool as authored, before the build splits it: like {@link ToolDefinition}\n * but it may declare `description`, `parameters`, and a server-side `execute`\n * alongside its `render`. The `type` field is **not** authored — the\n * `\"use generative\"` compiler infers it (`execute: humanTool()` → human;\n * `execute: providerTool(...)` → provider; `execute` with a `\"use client\"`\n * directive → frontend; otherwise backend) and writes it back — so declaring it\n * here is a type error.\n */\ntype OverrideOptionalField<\n T,\n TKey extends keyof T,\n TValue,\n> = undefined extends T[TKey]\n ? // Preserve `?: undefined` fields (for variants that explicitly disallow a\n // callback) instead of widening them to accept the override value.\n Exclude<T[TKey], undefined> extends never\n ? { [K in TKey]?: undefined }\n : { [K in TKey]?: TValue | undefined }\n : { [K in TKey]: TValue };\n\ntype OverrideToolDeclarationCallbacks<\n T extends { streamCall?: unknown },\n TArgs extends Record<string, unknown>,\n TResult,\n> = Omit<\n T,\n | \"type\"\n | \"execute\"\n | \"toModelOutput\"\n | \"experimental_onSchemaValidationError\"\n | \"streamCall\"\n> & {\n type?: never;\n} & (\"execute\" extends keyof T\n ? OverrideOptionalField<T, \"execute\", ToolExecute<NoInfer<TArgs>, TResult>>\n : {}) &\n (\"toModelOutput\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"toModelOutput\",\n ToolModelOutputFunction<NoInfer<TArgs>, NoInfer<TResult>>\n >\n : {}) &\n (\"experimental_onSchemaValidationError\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"experimental_onSchemaValidationError\",\n (\n args: unknown,\n context: ToolExecuteContext,\n ) => NoInfer<TResult> | Promise<NoInfer<TResult>>\n >\n : {}) &\n OverrideOptionalField<T, \"streamCall\", ToolStreamCall<TArgs, unknown>>;\n\n// Keep the authored shape tied to ToolDeclaration's union variants while\n// overriding callback fields to avoid inference pollution.\ntype ToolkitDefinitionInput<\n TArgs extends Record<string, unknown>,\n TResult,\n> = WithRender<\n ToolDeclaration<TArgs, TResult> extends infer T\n ? T extends { streamCall?: unknown }\n ? OverrideToolDeclarationCallbacks<T, TArgs, TResult>\n : never\n : never,\n TArgs,\n TResult\n>;\n\n/**\n * A single entry in a {@link ToolkitDefinition}.\n *\n * Either authored inline (whose `type` the compiler infers) or an already-formed\n * {@link ToolDefinition} produced by a factory whose own build splits it across\n * targets — e.g. `new JSONGenerativeUI({ library }).present()`. The factory case\n * carries a `type`, so it can only match the {@link ToolDefinition} arm of this\n * union.\n */\nexport type ToolkitDefinitionEntry<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> | ToolDefinition<any, any>;\n\nexport type ToolkitDefinitionEntryWithParameters<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> & {\n parameters: NonNullable<ToolParameters<TArgs>>;\n};\n\n/**\n * The permissive, authoring-time counterpart to {@link Toolkit} — the input to\n * {@link defineToolkit}. Backend entries may carry their server `execute` here;\n * the canonical {@link Toolkit} keeps those fields `undefined`.\n */\nexport type ToolkitDefinition<\n TArgsByName extends {\n [K in keyof TArgsByName]: Record<string, unknown>;\n } = Record<string, any>,\n TResultByName extends { [K in keyof TArgsByName]: unknown } = {\n [K in keyof TArgsByName]: any;\n },\n> = {\n [K in keyof TArgsByName]: ToolkitDefinitionEntry<\n TArgsByName[K],\n TResultByName[K]\n >;\n};\n\n/** Configuration for the {@link Tools} resource. */\nexport type ToolsConfig = {\n /** Tools to register with model context and, when provided, message renderers. */\n toolkit: Toolkit;\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAaO,2BACXC,SACY;CACZ,IAAIA,KAAKE,YAAYC,KAAAA,GAAW,OAAOH,KAAKE,YAAY;CACxD,OAAOF,KAAKI,SAAS;AACvB;AAuDA,MAAMyB,uBACJC,MACAC,SACc;CAId,IAAI,EAFFA,KAAKE,QAAQ7B,SAAS,aAAa2B,KAAKE,QAAQ7B,SAAS,oBAE3C;EACd,MAAM8B,QAAQJ,KAAKF;EACnB,IAAI,OAAOM,UAAU,YAAY,OAAOA,SAAS;EACjD,OAAOA,MAAM;GAAEhB,MAAMa,KAAKb;GAAMQ,QAAQK,KAAKL;EAAO,CAAC;CACvD;CAEA,MAAMQ,QAAQJ,KAAKH;CACnB,IAAI,OAAOO,UAAU,YAAY,OAAOA,SAAS;CACjD,OAAOA,MAAM,EAAEhB,MAAMa,KAAKb,KAAK,CAAC;AAClC;AAEA,MAAaiB,6BAIXL,SACoE;CACpE,OAAO,SAASM,sBAAsBL,MAAM;EAC1C,OAAOF,oBAAoBC,MAAMC,IAAI;CACvC;AACF"}
1
+ {"version":3,"file":"toolbox.js","names":["Tool","ToolCallReader","ToolDeclaration","ToolModelOutputFunction","ReactNode","ToolCallMessagePartComponent","ToolCallMessagePartProps","resolveToolCallText","ToolCallText","NeutralToolCallText","Record","TArgs","TResult","isStandaloneToolDisplay","tool","Pick","display","undefined","type","WithRender","T","render","renderText","ToolParameters","ToolExecuteContext","Parameters","NonNullable","ToolExecute","args","context","Promise","ToolStreamCall","reader","makeToolCallTextComponent","text","part","ToolCallTextComponent","ToolDefinition","Toolkit","OverrideOptionalField","TKey","Exclude","TValue","OverrideToolDeclarationCallbacks","streamCall","Omit","NoInfer","ToolkitDefinitionInput","ToolkitDefinitionEntry","ToolkitDefinitionEntryWithParameters","parameters","ToolkitDefinition","TArgsByName","K","TResultByName","ToolsConfig","toolkit"],"sources":["../../../src/react/model-context/toolbox.ts"],"sourcesContent":["import type {\n Tool,\n ToolCallReader,\n ToolDeclaration,\n ToolModelOutputFunction,\n} from \"assistant-stream\";\nimport type { ReactNode } from \"react\";\nimport type {\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n} from \"../types/MessagePartComponentTypes\";\nimport {\n resolveToolCallText,\n type ToolCallText as NeutralToolCallText,\n} from \"../../model-context/tool-call-text\";\n\nexport type ToolCallText<\n TArgs extends Record<string, unknown>,\n TResult,\n> = NeutralToolCallText<TArgs, TResult, ReactNode>;\n\n/**\n * Resolves whether a tool's UI should be presented standalone (outside the\n * chain-of-thought grouping), applying the type-based defaults.\n *\n * An explicit `display` wins. Otherwise `human` tools default to standalone\n * (they prompt the user), and every other tool defaults to inline (a trace of\n * what the model is doing). MCP-app tool calls are detected separately from\n * the part itself and are not resolved here.\n */\nexport const isStandaloneToolDisplay = (\n tool: Pick<Tool<any, any>, \"type\" | \"display\">,\n): boolean => {\n if (tool.display !== undefined) return tool.display === \"standalone\";\n return tool.type === \"human\";\n};\n\ntype WithRender<T, TArgs extends Record<string, unknown>, TResult> = T extends {\n type: \"frontend\" | \"human\";\n}\n ? T &\n (T extends { type: \"frontend\" }\n ?\n | { render: ToolCallMessagePartComponent<TArgs, TResult> }\n | {\n render?: ToolCallMessagePartComponent<TArgs, TResult>;\n renderText: ToolCallText<TArgs, TResult>;\n }\n : { render: ToolCallMessagePartComponent<TArgs, TResult> })\n : T & {\n render?: ToolCallMessagePartComponent<TArgs, TResult> | undefined;\n renderText?: ToolCallText<TArgs, TResult> | undefined;\n };\n\ntype ToolParameters<TArgs extends Record<string, unknown>> =\n ToolDeclaration<TArgs>[\"parameters\"];\n\n// ToolExecutionContext is not re-exported from assistant-stream's public entry.\ntype ToolExecuteContext = Parameters<\n NonNullable<ToolDeclaration[\"execute\"]>\n>[1];\n\ntype ToolExecute<TArgs extends Record<string, unknown>, TResult> = (\n args: TArgs,\n context: ToolExecuteContext,\n) => TResult | Promise<TResult>;\n\ntype ToolStreamCall<TArgs extends Record<string, unknown>, TResult> = (\n reader: ToolCallReader<TArgs, TResult>,\n context: ToolExecuteContext,\n) => void;\n\nexport const makeToolCallTextComponent = <\n TArgs extends Record<string, unknown>,\n TResult,\n>(\n text: ToolCallText<TArgs, TResult>,\n): ((part: ToolCallMessagePartProps<TArgs, TResult>) => ReactNode) => {\n return function ToolCallTextComponent(part) {\n return resolveToolCallText(text, part);\n };\n};\n\n/**\n * Tool definition accepted by the React tool registry.\n *\n * Extends the core tool contract with tool-call display options. Human tools\n * rely on `render` to collect input from the user. Frontend tools execute in\n * the browser and require either `render` or `renderText` for their progress\n * and result. Backend tools execute server-side and may omit a renderer.\n */\nexport type ToolDefinition<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = WithRender<Tool<TArgs, TResult>, TArgs, TResult>;\n\n/**\n * Named collection of tools exposed to the assistant model.\n *\n * Keys are the tool names the model receives and uses in tool calls.\n *\n * @example\n * ```tsx\n * const toolkit = defineToolkit({\n * get_weather: {\n * type: \"frontend\",\n * description: \"Get the weather for a city.\",\n * parameters: weatherSchema,\n * execute: async ({ city }: { city: string }) => fetchWeather(city),\n * render: WeatherToolUI,\n * },\n * });\n * ```\n */\nexport type Toolkit = Record<string, ToolDefinition<any, any>>;\n\n/**\n * A tool as authored, before the build splits it: like {@link ToolDefinition}\n * but it may declare `description`, `parameters`, and a server-side `execute`\n * alongside its `render`. The `type` field is **not** authored — the\n * `\"use generative\"` compiler infers it (`execute: humanTool()` → human;\n * `execute: providerTool(...)` → provider; `execute` with a `\"use client\"`\n * directive → frontend; otherwise backend) and writes it back — so declaring it\n * here is a type error.\n */\ntype OverrideOptionalField<\n T,\n TKey extends keyof T,\n TValue,\n> = undefined extends T[TKey]\n ? // Preserve `?: undefined` fields (for variants that explicitly disallow a\n // callback) instead of widening them to accept the override value.\n Exclude<T[TKey], undefined> extends never\n ? { [K in TKey]?: undefined }\n : { [K in TKey]?: TValue | undefined }\n : { [K in TKey]: TValue };\n\ntype OverrideToolDeclarationCallbacks<\n T extends { streamCall?: unknown },\n TArgs extends Record<string, unknown>,\n TResult,\n> = Omit<\n T,\n | \"type\"\n | \"execute\"\n | \"toModelOutput\"\n | \"experimental_onSchemaValidationError\"\n | \"streamCall\"\n> & {\n type?: never;\n} & (\"execute\" extends keyof T\n ? OverrideOptionalField<T, \"execute\", ToolExecute<NoInfer<TArgs>, TResult>>\n : {}) &\n (\"toModelOutput\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"toModelOutput\",\n ToolModelOutputFunction<NoInfer<TArgs>, NoInfer<TResult>>\n >\n : {}) &\n (\"experimental_onSchemaValidationError\" extends keyof T\n ? OverrideOptionalField<\n T,\n \"experimental_onSchemaValidationError\",\n (\n args: unknown,\n context: ToolExecuteContext,\n ) => NoInfer<TResult> | Promise<NoInfer<TResult>>\n >\n : {}) &\n OverrideOptionalField<T, \"streamCall\", ToolStreamCall<TArgs, unknown>>;\n\n// Keep the authored shape tied to ToolDeclaration's union variants while\n// overriding callback fields to avoid inference pollution.\ntype ToolkitDefinitionInput<\n TArgs extends Record<string, unknown>,\n TResult,\n> = WithRender<\n ToolDeclaration<TArgs, TResult> extends infer T\n ? T extends { streamCall?: unknown }\n ? OverrideToolDeclarationCallbacks<T, TArgs, TResult>\n : never\n : never,\n TArgs,\n TResult\n>;\n\n/**\n * A single entry in a {@link ToolkitDefinition}.\n *\n * Either authored inline (whose `type` the compiler infers) or an already-formed\n * {@link ToolDefinition} produced by a factory whose own build splits it across\n * targets — e.g. `new JSONGenerativeUI({ library }).present()`. The factory case\n * carries a `type`, so it can only match the {@link ToolDefinition} arm of this\n * union.\n */\nexport type ToolkitDefinitionEntry<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> | ToolDefinition<any, any>;\n\nexport type ToolkitDefinitionEntryWithParameters<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = ToolkitDefinitionInput<TArgs, TResult> & {\n parameters: NonNullable<ToolParameters<TArgs>>;\n};\n\n/**\n * The permissive, authoring-time counterpart to {@link Toolkit} — the input to\n * {@link defineToolkit}. Backend entries may carry their server `execute` here;\n * the canonical {@link Toolkit} keeps those fields `undefined`.\n */\nexport type ToolkitDefinition<\n TArgsByName extends {\n [K in keyof TArgsByName]: Record<string, unknown>;\n } = Record<string, any>,\n TResultByName extends { [K in keyof TArgsByName]: unknown } = {\n [K in keyof TArgsByName]: any;\n },\n> = {\n [K in keyof TArgsByName]: ToolkitDefinitionEntry<\n TArgsByName[K],\n TResultByName[K]\n >;\n};\n\n/** Configuration for the {@link Tools} resource. */\nexport type ToolsConfig = {\n /** Tools to register with model context and, when provided, message renderers. */\n toolkit: Toolkit;\n};\n"],"mappings":";;;;;;;;;;;AA8BA,MAAaa,2BACXC,SACY;CACZ,IAAIA,KAAKE,YAAYC,KAAAA,GAAW,OAAOH,KAAKE,YAAY;CACxD,OAAOF,KAAKI,SAAS;AACvB;AAqCA,MAAae,6BAIXC,SACoE;CACpE,OAAO,SAASE,sBAAsBD,MAAM;EAC1C,OAAO5B,oBAAoB2B,MAAMC,IAAI;CACvC;AACF"}
@@ -1,15 +1,45 @@
1
- import { useEffect, useRef } from "@assistant-ui/tap/react-shim";
1
+ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
2
+ import { useEffect, useInsertionEffect, useRef } from "@assistant-ui/tap/react-shim";
2
3
  import { useAui } from "@assistant-ui/store";
3
4
  //#region src/react/model-context/useAssistantContext.ts
4
5
  const useAssistantContext = (config) => {
5
- const { getContext, disabled = false } = config;
6
+ const $ = c(7);
7
+ const { getContext, disabled: t0 } = config;
8
+ const disabled = t0 === void 0 ? false : t0;
6
9
  const aui = useAui();
7
10
  const getContextRef = useRef(getContext);
8
- getContextRef.current = getContext;
9
- useEffect(() => {
10
- if (disabled) return;
11
- return aui.modelContext.register({ getModelContext: () => ({ system: getContextRef.current() }) });
12
- }, [aui, disabled]);
11
+ let t1;
12
+ let t2;
13
+ if ($[0] !== getContext) {
14
+ t1 = () => {
15
+ getContextRef.current = getContext;
16
+ };
17
+ t2 = [getContext];
18
+ $[0] = getContext;
19
+ $[1] = t1;
20
+ $[2] = t2;
21
+ } else {
22
+ t1 = $[1];
23
+ t2 = $[2];
24
+ }
25
+ useInsertionEffect(t1, t2);
26
+ let t3;
27
+ let t4;
28
+ if ($[3] !== aui || $[4] !== disabled) {
29
+ t3 = () => {
30
+ if (disabled) return;
31
+ return aui.modelContext.register({ getModelContext: () => ({ system: getContextRef.current() }) });
32
+ };
33
+ t4 = [aui, disabled];
34
+ $[3] = aui;
35
+ $[4] = disabled;
36
+ $[5] = t3;
37
+ $[6] = t4;
38
+ } else {
39
+ t3 = $[5];
40
+ t4 = $[6];
41
+ }
42
+ useEffect(t3, t4);
13
43
  };
14
44
  //#endregion
15
45
  export { useAssistantContext };
@@ -1 +1 @@
1
- {"version":3,"file":"useAssistantContext.js","names":["useEffect","useRef","useAui","AssistantContextConfig","useAssistantContext","config","getContext","disabled","aui","getContextRef","current","modelContext","register","getModelContext","system"],"sources":["../../../src/react/model-context/useAssistantContext.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { AssistantContextConfig } from \"../..\";\n\nexport type { AssistantContextConfig };\n\nexport const useAssistantContext = (config: AssistantContextConfig) => {\n const { getContext, disabled = false } = config;\n const aui = useAui();\n const getContextRef = useRef(getContext);\n getContextRef.current = getContext;\n\n useEffect(() => {\n if (disabled) return;\n\n return aui.modelContext.register({\n getModelContext: () => ({\n system: getContextRef.current(),\n }),\n });\n }, [aui, disabled]);\n};\n"],"mappings":";;;AAMA,MAAaI,uBAAuBC,WAAmC;CACrE,MAAM,EAAEC,YAAYC,WAAW,UAAUF;CACzC,MAAMG,MAAMN,OAAO;CACnB,MAAMO,gBAAgBR,OAAOK,UAAU;CACvCG,cAAcC,UAAUJ;CAExBN,gBAAgB;EACd,IAAIO,UAAU;EAEd,OAAOC,IAAIG,aAAaC,SAAS,EAC/BC,wBAAwB,EACtBC,QAAQL,cAAcC,QAAQ,EAChC,GACF,CAAC;CACH,GAAG,CAACF,KAAKD,QAAQ,CAAC;AACpB"}
1
+ {"version":3,"file":"useAssistantContext.js","names":["useEffect","useInsertionEffect","useRef","useAui","AssistantContextConfig","useAssistantContext","config","$","_c","getContext","disabled","t0","undefined","aui","getContextRef","t1","t2","current","t3","t4","modelContext","register","getModelContext","system"],"sources":["../../../src/react/model-context/useAssistantContext.ts"],"sourcesContent":["import { useEffect, useInsertionEffect, useRef } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { AssistantContextConfig } from \"../..\";\n\nexport type { AssistantContextConfig };\n\nexport const useAssistantContext = (config: AssistantContextConfig) => {\n const { getContext, disabled = false } = config;\n const aui = useAui();\n const getContextRef = useRef(getContext);\n useInsertionEffect(() => {\n getContextRef.current = getContext;\n }, [getContext]);\n\n useEffect(() => {\n if (disabled) return;\n\n return aui.modelContext.register({\n getModelContext: () => ({\n system: getContextRef.current(),\n }),\n });\n }, [aui, disabled]);\n};\n"],"mappings":";;;;AAMA,MAAaK,uBAAsBC,WAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACjC,MAAA,EAAAC,YAAAC,UAAAC,OAAyCL;CAArB,MAAAI,WAAAC,OAAAC,KAAAA,IAAA,QAAAD;CACpB,MAAAE,MAAYV,OAAO;CACnB,MAAAW,gBAAsBZ,OAAOO,UAAU;CAAE,IAAAM;CAAA,IAAAC;CAAA,IAAAT,EAAA,OAAAE,YAAA;EACtBM,WAAA;GACjBD,cAAaG,UAAWR;EAAH;EACpBO,KAAA,CAACP,UAAU;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAQ;EAAAR,EAAA,KAAAS;CAAA,OAAA;EAAAD,KAAAR,EAAA;EAAAS,KAAAT,EAAA;CAAA;CAFfN,mBAAmBc,IAEhBC,EAAY;CAAC,IAAAE;CAAA,IAAAC;CAAA,IAAAZ,EAAA,OAAAM,OAAAN,EAAA,OAAAG,UAAA;EAENQ,WAAA;GACR,IAAIR,UAAQ;GAAS,OAEdG,IAAGO,aAAaC,SAAU,EAAAC,wBACP,EAAAC,QACdT,cAAaG,QAAS,EAChC,GACF,CAAC;EAAC;EACDE,KAAA,CAACN,KAAKH,QAAQ;EAACH,EAAA,KAAAM;EAAAN,EAAA,KAAAG;EAAAH,EAAA,KAAAW;EAAAX,EAAA,KAAAY;CAAA,OAAA;EAAAD,KAAAX,EAAA;EAAAY,KAAAZ,EAAA;CAAA;CARlBP,UAAUkB,IAQPC,EAAe;AAAC"}
@@ -1,4 +1,5 @@
1
- import { useEffect, useRef } from "@assistant-ui/tap/react-shim";
1
+ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
2
+ import { useEffect, useInsertionEffect, useRef } from "@assistant-ui/tap/react-shim";
2
3
  import { useAui } from "@assistant-ui/store";
3
4
  //#region src/react/model-context/useAuiToolOverrides.ts
4
5
  /**
@@ -15,15 +16,40 @@ import { useAui } from "@assistant-ui/store";
15
16
  * @deprecated Experimental, API may change.
16
17
  */
17
18
  function useAuiToolOverrides(overrides) {
19
+ const $ = c(7);
18
20
  const aui = useAui();
19
21
  const overridesRef = useRef(overrides);
20
- overridesRef.current = overrides;
21
- useEffect(() => {
22
- return aui.modelContext.register({ getModelContext: () => ({
22
+ let t0;
23
+ let t1;
24
+ if ($[0] !== overrides) {
25
+ t0 = () => {
26
+ overridesRef.current = overrides;
27
+ };
28
+ t1 = [overrides];
29
+ $[0] = overrides;
30
+ $[1] = t0;
31
+ $[2] = t1;
32
+ } else {
33
+ t0 = $[1];
34
+ t1 = $[2];
35
+ }
36
+ useInsertionEffect(t0, t1);
37
+ let t2;
38
+ if ($[3] !== aui.modelContext) {
39
+ t2 = () => aui.modelContext.register({ getModelContext: () => ({
23
40
  priority: 1e3,
24
41
  tools: overridesRef.current
25
42
  }) });
26
- }, [aui]);
43
+ $[3] = aui.modelContext;
44
+ $[4] = t2;
45
+ } else t2 = $[4];
46
+ let t3;
47
+ if ($[5] !== aui) {
48
+ t3 = [aui];
49
+ $[5] = aui;
50
+ $[6] = t3;
51
+ } else t3 = $[6];
52
+ useEffect(t2, t3);
27
53
  }
28
54
  //#endregion
29
55
  export { useAuiToolOverrides };
@@ -1 +1 @@
1
- {"version":3,"file":"useAuiToolOverrides.js","names":["useEffect","useRef","useAui","Tool","AuiToolOverride","Record","Partial","TArgs","TResult","AuiToolOverrides","useAuiToolOverrides","overrides","aui","overridesRef","current","modelContext","register","getModelContext","priority","tools"],"sources":["../../../src/react/model-context/useAuiToolOverrides.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { Tool } from \"assistant-stream\";\n\ntype AuiToolOverride<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = Partial<Tool<TArgs, TResult>>;\n\ntype AuiToolOverrides = Record<string, AuiToolOverride<any, any>>;\n\n/**\n * Overrides toolkit entries for the current assistant scope.\n *\n * This is intended for dynamic local-state tools whose model-facing contract is\n * declared in a `\"use generative\"` toolkit file with `execute: stubTool()`, but\n * whose actual executor must close over React state in the mounted component.\n * Keep the override keys stable after mount; dynamic key addition/removal is not\n * currently observed.\n * Overrides are registered at priority 1000, above toolkit defaults. Only one\n * mounted override provider may define a given tool name at a time.\n *\n * @deprecated Experimental, API may change.\n */\nexport function useAuiToolOverrides(overrides: AuiToolOverrides): void {\n const aui = useAui();\n const overridesRef = useRef(overrides);\n overridesRef.current = overrides;\n\n useEffect(() => {\n return aui.modelContext.register({\n getModelContext: () => ({\n priority: 1000,\n tools: overridesRef.current as Record<string, Tool<any, any>>,\n }),\n });\n }, [aui]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,SAAgBU,oBAAoBC,WAAmC;CACrE,MAAMC,MAAMV,OAAO;CACnB,MAAMW,eAAeZ,OAAOU,SAAS;CACrCE,aAAaC,UAAUH;CAEvBX,gBAAgB;EACd,OAAOY,IAAIG,aAAaC,SAAS,EAC/BC,wBAAwB;GACtBC,UAAU;GACVC,OAAON,aAAaC;EACtB,GACF,CAAC;CACH,GAAG,CAACF,GAAG,CAAC;AACV"}
1
+ {"version":3,"file":"useAuiToolOverrides.js","names":["useEffect","useInsertionEffect","useRef","useAui","Tool","AuiToolOverride","Record","Partial","TArgs","TResult","AuiToolOverrides","useAuiToolOverrides","overrides","$","_c","aui","overridesRef","t0","t1","current","t2","modelContext","register","getModelContext","priority","tools","t3"],"sources":["../../../src/react/model-context/useAuiToolOverrides.ts"],"sourcesContent":["import { useEffect, useInsertionEffect, useRef } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type { Tool } from \"assistant-stream\";\n\ntype AuiToolOverride<\n TArgs extends Record<string, unknown> = Record<string, unknown>,\n TResult = unknown,\n> = Partial<Tool<TArgs, TResult>>;\n\ntype AuiToolOverrides = Record<string, AuiToolOverride<any, any>>;\n\n/**\n * Overrides toolkit entries for the current assistant scope.\n *\n * This is intended for dynamic local-state tools whose model-facing contract is\n * declared in a `\"use generative\"` toolkit file with `execute: stubTool()`, but\n * whose actual executor must close over React state in the mounted component.\n * Keep the override keys stable after mount; dynamic key addition/removal is not\n * currently observed.\n * Overrides are registered at priority 1000, above toolkit defaults. Only one\n * mounted override provider may define a given tool name at a time.\n *\n * @deprecated Experimental, API may change.\n */\nexport function useAuiToolOverrides(overrides: AuiToolOverrides): void {\n const aui = useAui();\n const overridesRef = useRef(overrides);\n useInsertionEffect(() => {\n overridesRef.current = overrides;\n }, [overrides]);\n\n useEffect(() => {\n return aui.modelContext.register({\n getModelContext: () => ({\n priority: 1000,\n tools: overridesRef.current as Record<string, Tool<any, any>>,\n }),\n });\n }, [aui]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAOW,oBAAAC,WAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACL,MAAAC,MAAYZ,OAAO;CACnB,MAAAa,eAAqBd,OAAOU,SAAS;CAAE,IAAAK;CAAA,IAAAC;CAAA,IAAAL,EAAA,OAAAD,WAAA;EACpBK,WAAA;GACjBD,aAAYG,UAAWP;EAAH;EACnBM,KAAA,CAACN,SAAS;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAA;EAAAD,KAAAJ,EAAA;EAAAK,KAAAL,EAAA;CAAA;CAFdZ,mBAAmBgB,IAEhBC,EAAW;CAAC,IAAAE;CAAA,IAAAP,EAAA,OAAAE,IAAAM,cAAA;EAELD,WACDL,IAAGM,aAAaC,SAAU,EAAAC,wBACP;GAAAC,UACZ;GAAIC,OACPT,aAAYG;EACrB,GACF,CAAC;EACFN,EAAA,KAAAE,IAAAM;EAAAR,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,IAAAa;CAAA,IAAAb,EAAA,OAAAE,KAAA;EAAEW,KAAA,CAACX,GAAG;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAa;CAAA,OAAAA,KAAAb,EAAA;CAPRb,UAAUoB,IAOPM,EAAK;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useInlineRender.d.ts","names":[],"sources":["../../../src/react/model-context/useInlineRender.ts"],"mappings":";;;cAIa,kBAAmB,OAAO,SACrC,QAAQ,GAAG,yBAAyB,OAAO,cAC1C,GAAG,yBAAyB,OAAO"}
1
+ {"version":3,"file":"useInlineRender.d.ts","names":[],"sources":["../../../src/react/model-context/useInlineRender.ts"],"mappings":";;;cAKa,kBAAmB,OAAO,SACrC,QAAQ,GAAG,yBAAyB,OAAO,cAC1C,GAAG,yBAAyB,OAAO"}
@@ -1,41 +1,15 @@
1
- import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
2
- import { useEffect, useState } from "@assistant-ui/tap/react-shim";
3
- import { create } from "zustand";
1
+ import { WritableSubscribable } from "../../subscribable/subscribable.js";
2
+ import { useSubscribable } from "../../store/runtime-clients/useSubscribable.js";
3
+ import { useCallback, useEffect, useState } from "@assistant-ui/tap/react-shim";
4
4
  //#region src/react/model-context/useInlineRender.ts
5
5
  const useInlineRender = (toolUI) => {
6
- const $ = c(8);
7
- let t0;
8
- if ($[0] !== toolUI) {
9
- t0 = () => create(() => ({ toolUI }));
10
- $[0] = toolUI;
11
- $[1] = t0;
12
- } else t0 = $[1];
13
- const [useToolUIStore] = useState(t0);
14
- let t1;
15
- let t2;
16
- if ($[2] !== toolUI || $[3] !== useToolUIStore) {
17
- t1 = () => {
18
- useToolUIStore.setState({ toolUI });
19
- };
20
- t2 = [toolUI, useToolUIStore];
21
- $[2] = toolUI;
22
- $[3] = useToolUIStore;
23
- $[4] = t1;
24
- $[5] = t2;
25
- } else {
26
- t1 = $[4];
27
- t2 = $[5];
28
- }
29
- useEffect(t1, t2);
30
- let t3;
31
- if ($[6] !== useToolUIStore) {
32
- t3 = function ToolUI(args) {
33
- return useToolUIStore().toolUI(args);
34
- };
35
- $[6] = useToolUIStore;
36
- $[7] = t3;
37
- } else t3 = $[7];
38
- return t3;
6
+ const [toolUIStore] = useState(() => new WritableSubscribable(toolUI));
7
+ useEffect(() => {
8
+ toolUIStore.setState(toolUI);
9
+ }, [toolUI, toolUIStore]);
10
+ return useCallback(function ToolUI(args) {
11
+ return useSubscribable(toolUIStore)(args);
12
+ }, [toolUIStore]);
39
13
  };
40
14
  //#endregion
41
15
  export { useInlineRender };
@@ -1 +1 @@
1
- {"version":3,"file":"useInlineRender.js","names":["FC","useCallback","useEffect","useState","ToolCallMessagePartProps","create","useInlineRender","toolUI","$","_c","t0","useToolUIStore","t1","t2","setState","t3","ToolUI","args","store"],"sources":["../../../src/react/model-context/useInlineRender.ts"],"sourcesContent":["import { type FC, useCallback, useEffect, useState } from \"react\";\nimport type { ToolCallMessagePartProps } from \"../types/MessagePartComponentTypes\";\nimport { create } from \"zustand\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallMessagePartProps<TArgs, TResult>>,\n): FC<ToolCallMessagePartProps<TArgs, TResult>> => {\n const [useToolUIStore] = useState(() =>\n create(() => ({\n toolUI,\n })),\n );\n\n useEffect(() => {\n useToolUIStore.setState({ toolUI });\n }, [toolUI, useToolUIStore]);\n\n return useCallback(\n function ToolUI(args) {\n const store = useToolUIStore();\n return store.toolUI(args);\n },\n [useToolUIStore],\n );\n};\n"],"mappings":";;;;AAIA,MAAaM,mBAAkBC,WAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,QAAA;EAGKG,WAChCL,cAAc,EAAAE,OAEd,EAAE;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAHL,MAAA,CAAAG,kBAAyBR,SAASO,EAIlC;CAAE,IAAAE;CAAA,IAAAC;CAAA,IAAAL,EAAA,OAAAD,UAAAC,EAAA,OAAAG,gBAAA;EAEQC,WAAA;GACRD,eAAcG,SAAU,EAAAP,OAAS,CAAC;EAAC;EAClCM,KAAA,CAACN,QAAQI,cAAc;EAACH,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAA;EAAAD,KAAAJ,EAAA;EAAAK,KAAAL,EAAA;CAAA;CAF3BN,UAAUU,IAEPC,EAAwB;CAAC,IAAAE;CAAA,IAAAP,EAAA,OAAAG,gBAAA;EAG1BI,KAAA,SAAAC,OAAAC,MAAA;GACiC,OAAjBN,eACPO,CAAK,CAAAX,OAAQU,IAAI;EAAC;EAC1BT,EAAA,KAAAG;EAAAH,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAJIO;AAMN"}
1
+ {"version":3,"file":"useInlineRender.js","names":["FC","useCallback","useEffect","useState","ToolCallMessagePartProps","WritableSubscribable","useSubscribable","useInlineRender","toolUI","TArgs","TResult","toolUIStore","setState","ToolUI","args","currentToolUI"],"sources":["../../../src/react/model-context/useInlineRender.ts"],"sourcesContent":["import { type FC, useCallback, useEffect, useState } from \"react\";\nimport type { ToolCallMessagePartProps } from \"../types/MessagePartComponentTypes\";\nimport { WritableSubscribable } from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\n\nexport const useInlineRender = <TArgs, TResult>(\n toolUI: FC<ToolCallMessagePartProps<TArgs, TResult>>,\n): FC<ToolCallMessagePartProps<TArgs, TResult>> => {\n const [toolUIStore] = useState(\n () =>\n new WritableSubscribable<FC<ToolCallMessagePartProps<TArgs, TResult>>>(\n toolUI,\n ),\n );\n\n useEffect(() => {\n toolUIStore.setState(toolUI);\n }, [toolUI, toolUIStore]);\n\n return useCallback(\n function ToolUI(args) {\n // Invoked as a plain function so its hooks belong to this component,\n // which keeps its identity while `toolUI` changes underneath.\n const currentToolUI = useSubscribable(toolUIStore);\n return currentToolUI(args);\n },\n [toolUIStore],\n );\n};\n"],"mappings":";;;;AAKA,MAAaO,mBACXC,WACiD;CACjD,MAAM,CAACG,eAAeR,eAElB,IAAIE,qBACFG,MACF,CACJ;CAEAN,gBAAgB;EACdS,YAAYC,SAASJ,MAAM;CAC7B,GAAG,CAACA,QAAQG,WAAW,CAAC;CAExB,OAAOV,YACL,SAASY,OAAOC,MAAM;EAIpB,OADsBR,gBAAgBK,WAC/BI,CAAa,CAACD,IAAI;CAC3B,GACA,CAACH,WAAW,CACd;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMessageError.d.ts","names":[],"sources":["../../../src/react/primitive-hooks/useMessageError.ts"],"mappings":";cAEa,oFAAe,sDAAA"}
1
+ {"version":3,"file":"useMessageError.d.ts","names":[],"sources":["../../../src/react/primitive-hooks/useMessageError.ts"],"mappings":";cAGa,oFAAe,sDAAA"}
@@ -1,15 +1,9 @@
1
+ import { messageErrorText } from "../../store/primitive-predicates.js";
1
2
  import { useAuiState } from "@assistant-ui/store";
2
3
  //#region src/react/primitive-hooks/useMessageError.ts
3
4
  const useMessageError = () => {
4
- return useAuiState(_temp);
5
+ return useAuiState(messageErrorText);
5
6
  };
6
- function _temp(s) {
7
- if (s.message.status?.type !== "incomplete" || s.message.status.reason !== "error") return;
8
- const error = s.message.status.error;
9
- if (typeof error === "string") return error;
10
- if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") return error.message;
11
- return error ?? "An error occurred";
12
- }
13
7
  //#endregion
14
8
  export { useMessageError };
15
9
 
@@ -1 +1 @@
1
- {"version":3,"file":"useMessageError.js","names":["useAuiState","useMessageError","_temp","s","message","status","type","reason","error"],"sources":["../../../src/react/primitive-hooks/useMessageError.ts"],"sourcesContent":["import { useAuiState } from \"@assistant-ui/store\";\n\nexport const useMessageError = () => {\n return useAuiState((s) => {\n if (\n s.message.status?.type !== \"incomplete\" ||\n s.message.status.reason !== \"error\"\n ) {\n return undefined;\n }\n const error = s.message.status.error;\n if (typeof error === \"string\") return error;\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof error.message === \"string\"\n ) {\n return error.message;\n }\n return error ?? \"An error occurred\";\n });\n};\n"],"mappings":";;AAEA,MAAaC,wBAAkB;CAAA,OACtBD,YAAYE,KAkBlB;AAAC;AAnB2B,SAAAA,MAAAC,GAAA;CAE3B,IACEA,EAACC,QAAQC,QAAaC,SAAK,gBAC3BH,EAACC,QAAQC,OAAOE,WAAY,SAAO;CAIrC,MAAAC,QAAcL,EAACC,QAAQC,OAAOG;CAC9B,IAAI,OAAOA,UAAU,UAAQ,OAASA;CACtC,IACE,OAAOA,UAAU,YACjBA,UAAU,QACV,aAAaA,SACb,OAAOA,MAAKJ,YAAa,UAAQ,OAE1BI,MAAKJ;CACb,OACMI,SAAA;AAA4B"}
1
+ {"version":3,"file":"useMessageError.js","names":["useAuiState","messageErrorText","useMessageError"],"sources":["../../../src/react/primitive-hooks/useMessageError.ts"],"sourcesContent":["import { useAuiState } from \"@assistant-ui/store\";\nimport { messageErrorText } from \"../../store/primitive-predicates\";\n\nexport const useMessageError = () => {\n return useAuiState(messageErrorText);\n};\n"],"mappings":";;;AAGA,MAAaE,wBAAkB;CAAA,OACtBF,YAAYC,gBAAgB;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useThreadListLoadMore.d.ts","names":[],"sources":["../../../src/react/primitive-hooks/useThreadListLoadMore.ts"],"mappings":";cAGa;EAAA;EAAA"}
1
+ {"version":3,"file":"useThreadListLoadMore.d.ts","names":[],"sources":["../../../src/react/primitive-hooks/useThreadListLoadMore.ts"],"mappings":";cAIa;EAAA;EAAA"}
@@ -1,3 +1,4 @@
1
+ import { threadListLoadMoreDisabled } from "../../store/primitive-predicates.js";
1
2
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
2
3
  import "@assistant-ui/tap/react-shim";
3
4
  import { useAui, useAuiState } from "@assistant-ui/store";
@@ -5,7 +6,7 @@ import { useAui, useAuiState } from "@assistant-ui/store";
5
6
  const useThreadListLoadMore = () => {
6
7
  const $ = c(5);
7
8
  const aui = useAui();
8
- const disabled = useAuiState(_temp);
9
+ const disabled = useAuiState(threadListLoadMoreDisabled);
9
10
  let t0;
10
11
  if ($[0] !== aui) {
11
12
  t0 = () => {
@@ -27,9 +28,6 @@ const useThreadListLoadMore = () => {
27
28
  } else t1 = $[4];
28
29
  return t1;
29
30
  };
30
- function _temp(s) {
31
- return !s.threads.hasMore || s.threads.isLoading || s.threads.isLoadingMore;
32
- }
33
31
  //#endregion
34
32
  export { useThreadListLoadMore };
35
33
 
@@ -1 +1 @@
1
- {"version":3,"file":"useThreadListLoadMore.js","names":["useCallback","useAui","useAuiState","useThreadListLoadMore","$","_c","aui","disabled","_temp","t0","threads","loadMore","t1","s","hasMore","isLoading","isLoadingMore"],"sources":["../../../src/react/primitive-hooks/useThreadListLoadMore.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport const useThreadListLoadMore = () => {\n const aui = useAui();\n const disabled = useAuiState(\n (s) => !s.threads.hasMore || s.threads.isLoading || s.threads.isLoadingMore,\n );\n\n const loadMore = useCallback(() => {\n aui.threads.loadMore();\n }, [aui]);\n\n return { loadMore, disabled };\n};\n"],"mappings":";;;;AAGA,MAAaG,8BAAwB;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACnC,MAAAC,MAAYL,OAAO;CACnB,MAAAM,WAAiBL,YACfM,KACF;CAAE,IAAAC;CAAA,IAAAL,EAAA,OAAAE,KAAA;EAE2BG,WAAA;GAC3BH,IAAGI,QAAQC,SAAU;EAAC;EACvBP,EAAA,KAAAE;EAAAF,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAFD,MAAAO,WAAiBF;CAEP,IAAAG;CAAA,IAAAR,EAAA,OAAAG,YAAAH,EAAA,OAAAO,UAAA;EAEHC,KAAA;GAAAD;GAAAJ;EAAqB;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAO;EAAAP,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,OAAtBQ;AAAsB;AAVM,SAAAJ,MAAAK,GAAA;CAAA,OAG1B,CAACA,EAACH,QAAQI,WAAYD,EAACH,QAAQK,aAAcF,EAACH,QAAQM;AAAc"}
1
+ {"version":3,"file":"useThreadListLoadMore.js","names":["useCallback","useAui","useAuiState","threadListLoadMoreDisabled","useThreadListLoadMore","$","_c","aui","disabled","t0","threads","loadMore","t1"],"sources":["../../../src/react/primitive-hooks/useThreadListLoadMore.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { threadListLoadMoreDisabled } from \"../../store/primitive-predicates\";\n\nexport const useThreadListLoadMore = () => {\n const aui = useAui();\n const disabled = useAuiState(threadListLoadMoreDisabled);\n\n const loadMore = useCallback(() => {\n aui.threads.loadMore();\n }, [aui]);\n\n return { loadMore, disabled };\n};\n"],"mappings":";;;;;AAIA,MAAaI,8BAAwB;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACnC,MAAAC,MAAYN,OAAO;CACnB,MAAAO,WAAiBN,YAAYC,0BAA0B;CAAE,IAAAM;CAAA,IAAAJ,EAAA,OAAAE,KAAA;EAE5BE,WAAA;GAC3BF,IAAGG,QAAQC,SAAU;EAAC;EACvBN,EAAA,KAAAE;EAAAF,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAFD,MAAAM,WAAiBF;CAEP,IAAAG;CAAA,IAAAP,EAAA,OAAAG,YAAAH,EAAA,OAAAM,UAAA;EAEHC,KAAA;GAAAD;GAAAH;EAAqB;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAM;EAAAN,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAAtBO;AAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerAttachments.d.ts","names":[],"sources":["../../../../src/react/primitives/composer/ComposerAttachments.tsx"],"mappings":";;;KAWK;EACH,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;;kBAGE;OACH;;IAGN,YAAY;IACZ;;;IAIA,WAAW;MAAS,YAAY;UAAiB;IACjD;;;kBAgCS;OACH;IACV;IACA,aAAa;;;;;;cAOJ,oCAAoC,GAAG,mCAAmC;cAgD1E,8BAA8B,GACzC,6BAA6B"}
1
+ {"version":3,"file":"ComposerAttachments.d.ts","names":[],"sources":["../../../../src/react/primitives/composer/ComposerAttachments.tsx"],"mappings":";;;KAYK;EACH,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;;kBAGE;OACH;;IAGN,YAAY;IACZ;;;IAIA,WAAW;MAAS,YAAY;UAAiB;IACjD;;;kBAgCS;OACH;IACV;IACA,aAAa;;;;;;cAOJ,oCAAoC,GAAG,mCAAmC;cAoD1E,8BAA8B,GACzC,6BAA6B"}
@@ -2,6 +2,7 @@ import { ComposerAttachmentByIndexProvider } from "../../providers/AttachmentByI
2
2
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
3
3
  import { memo, useMemo } from "@assistant-ui/tap/react-shim";
4
4
  import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
5
+ import { useShallowSelector } from "@assistant-ui/store/internal";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  //#region src/react/primitives/composer/ComposerAttachments.tsx
7
8
  const getComponent = (components, attachment) => {
@@ -60,8 +61,8 @@ const ComposerPrimitiveAttachmentByIndex = memo((t0) => {
60
61
  }, (prev, next) => prev.index === next.index && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment);
61
62
  ComposerPrimitiveAttachmentByIndex.displayName = "ComposerPrimitive.AttachmentByIndex";
62
63
  const ComposerPrimitiveAttachmentsInner = ({ children }) => {
63
- const attachmentsCount = useAuiState((s) => s.composer.attachments.length);
64
- return useMemo(() => Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(ComposerAttachmentByIndexProvider, {
64
+ const attachmentIds = useAuiState(useShallowSelector((s) => s.composer.attachments.map((attachment) => attachment.id)));
65
+ return useMemo(() => attachmentIds.map((attachmentId, index) => /* @__PURE__ */ jsx(ComposerAttachmentByIndexProvider, {
65
66
  index,
66
67
  children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
67
68
  getItemState: (aui) => aui.composer.attachment({ index }).getState(),
@@ -69,7 +70,7 @@ const ComposerPrimitiveAttachmentsInner = ({ children }) => {
69
70
  return getItem();
70
71
  } })
71
72
  })
72
- }, index)), [attachmentsCount, children]);
73
+ }, attachmentId)), [attachmentIds, children]);
73
74
  };
74
75
  const ComposerPrimitiveAttachments = (t0) => {
75
76
  const $ = c(4);
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerAttachments.js","names":["Attachment","ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","ComposerAttachmentByIndexProvider","ComposerAttachmentsComponentConfig","Image","Document","File","ComposerPrimitiveAttachments","Props","components","children","value","attachment","getComponent","type","AttachmentComponent","t0","$","_c","_temp","t1","Component","t2","ComposerPrimitiveAttachmentByIndex","index","prev","next","displayName","ComposerPrimitiveAttachmentsInner","attachmentsCount","s","composer","attachments","length","Array","from","_","aui","getState","getItem"],"sources":["../../../../src/react/primitives/composer/ComposerAttachments.tsx"],"sourcesContent":["import type { Attachment } from \"../../../types/attachment\";\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { ComposerAttachmentByIndexProvider } from \"../../providers/AttachmentByIndexProvider\";\n\ntype ComposerAttachmentsComponentConfig = {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n};\n\nexport namespace ComposerPrimitiveAttachments {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: ComposerAttachmentsComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each attachment. Receives the attachment. */\n children: (value: { attachment: Attachment }) => ReactNode;\n components?: never;\n };\n}\n\nconst getComponent = (\n components: ComposerAttachmentsComponentConfig | undefined,\n attachment: Attachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n return components?.Attachment;\n }\n};\n\nconst AttachmentComponent: FC<{\n components: ComposerAttachmentsComponentConfig | undefined;\n}> = ({ components }) => {\n const attachment = useAuiState((s) => s.attachment);\n if (!attachment) return null;\n\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace ComposerPrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: ComposerAttachmentsComponentConfig;\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the composer.\n */\nexport const ComposerPrimitiveAttachmentByIndex: FC<ComposerPrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <ComposerAttachmentByIndexProvider index={index}>\n <AttachmentComponent components={components} />\n </ComposerAttachmentByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nComposerPrimitiveAttachmentByIndex.displayName =\n \"ComposerPrimitive.AttachmentByIndex\";\n\nconst ComposerPrimitiveAttachmentsInner: FC<{\n children: (value: { attachment: Attachment }) => ReactNode;\n}> = ({ children }) => {\n const attachmentsCount = useAuiState((s) => s.composer.attachments.length);\n\n return useMemo(\n () =>\n Array.from({ length: attachmentsCount }, (_, index) => (\n <ComposerAttachmentByIndexProvider key={index} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) =>\n aui.composer.attachment({ index }).getState()\n }\n >\n {(getItem) =>\n children({\n get attachment() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </ComposerAttachmentByIndexProvider>\n )),\n [attachmentsCount, children],\n );\n};\n\nexport const ComposerPrimitiveAttachments: FC<\n ComposerPrimitiveAttachments.Props\n> = ({ components, children }) => {\n if (components) {\n return (\n <ComposerPrimitiveAttachmentsInner>\n {({ attachment }) => {\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n }}\n </ComposerPrimitiveAttachmentsInner>\n );\n }\n return (\n <ComposerPrimitiveAttachmentsInner>\n {children}\n </ComposerPrimitiveAttachmentsInner>\n );\n};\n\nComposerPrimitiveAttachments.displayName = \"ComposerPrimitive.Attachments\";\n"],"mappings":";;;;;;AAgCA,MAAMmB,gBACJJ,YACAG,eACG;CAEH,QADaA,WAAWE,MACxB;EACE,KAAK,SACH,OAAOL,YAAYL,SAASK,YAAYf;EAC1C,KAAK,YACH,OAAOe,YAAYJ,YAAYI,YAAYf;EAC7C,KAAK,QACH,OAAOe,YAAYH,QAAQG,YAAYf;EACzC,SACE,OAAOe,YAAYf;CACvB;AACF;AAEA,MAAMqB,uBAEDC,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAT,eAAAO;CACJ,MAAAJ,aAAmBX,YAAYkB,KAAmB;CAClD,IAAI,CAACP,YAAU,OAAS;CAAK,IAAAQ;CAAA,IAAAH,EAAA,OAAAL,cAAAK,EAAA,OAAAR,YAAA;EAEXW,KAAAP,aAAaJ,YAAYG,UAAU;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAR;EAAAQ,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAtD,MAAAI,YAAkBD;CAClB,IAAI,CAACC,WAAS,OAAS;CAAK,IAAAC;CAAA,IAAAL,EAAA,OAAAI,WAAA;EACrBC,KAAA,oBAAC,WAAD,CAAU,CAAA;EAAGL,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAAbK;AAAa;;;;AAatB,MAAaC,qCACXzB,MACEkB,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAM,OAAAf,eAAAO;CAAqB,IAAAI;CAAA,IAAAH,EAAA,OAAAR,YAAA;EAGhBW,KAAA,oBAAC,qBAAD,EAAiCX,WAAU,CAAA;EAAIQ,EAAA,KAAAR;EAAAQ,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,OAAAO,SAAAP,EAAA,OAAAG,IAAA;EADjDE,KAAA,oBAAC,mCAAD;GAA0CE;GACxCJ,UAAAA;EADgC,CAAA;EAEEH,EAAA,KAAAO;EAAAP,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAFpCK;AAEoC,IAGvCG,MAAMC,SACLD,KAAKD,UAAUE,KAAKF,SACpBC,KAAKhB,YAAYL,UAAUsB,KAAKjB,YAAYL,SAC5CqB,KAAKhB,YAAYJ,aAAaqB,KAAKjB,YAAYJ,YAC/CoB,KAAKhB,YAAYH,SAASoB,KAAKjB,YAAYH,QAC3CmB,KAAKhB,YAAYf,eAAegC,KAAKjB,YAAYf,UACrD;AAEF6B,mCAAmCI,cACjC;AAEF,MAAMC,qCAEA,EAAElB,eAAe;CACrB,MAAMmB,mBAAmB5B,aAAa6B,MAAMA,EAAEC,SAASC,YAAYC,MAAM;CAEzE,OAAOlC,cAEHmC,MAAMC,KAAK,EAAEF,QAAQJ,iBAAiB,IAAIO,GAAGZ,UAC3C,oBAAC,mCAAD;EAAsDA;EACpD,UAAA,oBAAC,4BAAD;GACE,eAAea,QACbA,IAAIN,SAASnB,WAAW,EAAEY,MAAM,CAAC,CAAC,CAACc,SAAS;GAG5CC,WAAAA,YACA7B,SAAS,EACP,IAAIE,aAAa;IACf,OAAO2B,QAAQ;GACjB,EACF,CAAC;EAEuB,CAAA;CACK,GAdKf,KAcL,CACpC,GACH,CAACK,kBAAkBnB,QAAQ,CAC7B;AACF;AAEA,MAAaH,gCAETS,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAT,YAAAC,aAAAM;CACH,IAAIP,YAAU;EAAA,IAAAW;EAAA,IAAAH,EAAA,OAAAR,YAAA;GAEVW,KAAA,oBAAC,mCAAD,EAAA,WACGE,OAAA;IAAC,MAAA,EAAAV,eAAAU;IACA,MAAAD,YAAkBR,aAAaJ,YAAYG,UAAU;IACrD,IAAI,CAACS,WAAS,OAAS;IAAK,OACrB,oBAAC,WAAD,CAAU,CAAA;GAAG,EAJU,CAAA;GAMEJ,EAAA,KAAAR;GAAAQ,EAAA,KAAAG;EAAA,OAAAA,KAAAH,EAAA;EAAA,OANpCG;CAMoC;CAEvC,IAAAA;CAAA,IAAAH,EAAA,OAAAP,UAAA;EAECU,KAAA,oBAAC,mCAAD,EACGV,SAD+B,CAAA;EAEEO,EAAA,KAAAP;EAAAO,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OAFpCG;AAEoC;AAIxCb,6BAA6BoB,cAAc;AAxFtC,SAAAR,MAAAW,GAAA;CAAA,OACmCA,EAAClB;AAAW"}
1
+ {"version":3,"file":"ComposerAttachments.js","names":["Attachment","ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","useShallowSelector","ComposerAttachmentByIndexProvider","ComposerAttachmentsComponentConfig","Image","Document","File","ComposerPrimitiveAttachments","Props","components","children","value","attachment","getComponent","type","AttachmentComponent","t0","$","_c","_temp","t1","Component","t2","ComposerPrimitiveAttachmentByIndex","index","prev","next","displayName","ComposerPrimitiveAttachmentsInner","attachmentIds","s","composer","attachments","map","id","attachmentId","aui","getState","getItem"],"sources":["../../../../src/react/primitives/composer/ComposerAttachments.tsx"],"sourcesContent":["import type { Attachment } from \"../../../types/attachment\";\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport { ComposerAttachmentByIndexProvider } from \"../../providers/AttachmentByIndexProvider\";\n\ntype ComposerAttachmentsComponentConfig = {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n};\n\nexport namespace ComposerPrimitiveAttachments {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: ComposerAttachmentsComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each attachment. Receives the attachment. */\n children: (value: { attachment: Attachment }) => ReactNode;\n components?: never;\n };\n}\n\nconst getComponent = (\n components: ComposerAttachmentsComponentConfig | undefined,\n attachment: Attachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n return components?.Attachment;\n }\n};\n\nconst AttachmentComponent: FC<{\n components: ComposerAttachmentsComponentConfig | undefined;\n}> = ({ components }) => {\n const attachment = useAuiState((s) => s.attachment);\n if (!attachment) return null;\n\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace ComposerPrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: ComposerAttachmentsComponentConfig;\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the composer.\n */\nexport const ComposerPrimitiveAttachmentByIndex: FC<ComposerPrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <ComposerAttachmentByIndexProvider index={index}>\n <AttachmentComponent components={components} />\n </ComposerAttachmentByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nComposerPrimitiveAttachmentByIndex.displayName =\n \"ComposerPrimitive.AttachmentByIndex\";\n\nconst ComposerPrimitiveAttachmentsInner: FC<{\n children: (value: { attachment: Attachment }) => ReactNode;\n}> = ({ children }) => {\n const attachmentIds = useAuiState(\n useShallowSelector((s) =>\n s.composer.attachments.map((attachment) => attachment.id),\n ),\n );\n\n return useMemo(\n () =>\n attachmentIds.map((attachmentId, index) => (\n <ComposerAttachmentByIndexProvider key={attachmentId} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) =>\n aui.composer.attachment({ index }).getState()\n }\n >\n {(getItem) =>\n children({\n get attachment() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </ComposerAttachmentByIndexProvider>\n )),\n [attachmentIds, children],\n );\n};\n\nexport const ComposerPrimitiveAttachments: FC<\n ComposerPrimitiveAttachments.Props\n> = ({ components, children }) => {\n if (components) {\n return (\n <ComposerPrimitiveAttachmentsInner>\n {({ attachment }) => {\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n }}\n </ComposerPrimitiveAttachmentsInner>\n );\n }\n return (\n <ComposerPrimitiveAttachmentsInner>\n {children}\n </ComposerPrimitiveAttachmentsInner>\n );\n};\n\nComposerPrimitiveAttachments.displayName = \"ComposerPrimitive.Attachments\";\n"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerIf.js","names":["FC","PropsWithChildren","useAuiState","ComposerIfFilters","editing","dictation","RequireAtLeastOne","T","Pick","Exclude","Keys","Required","K","Partial","UseComposerIfProps","useComposerIf","props","$","_c","t0","s","composer","isEditing","isDictating","ComposerPrimitiveIf","Props","children","query","result","displayName"],"sources":["../../../../src/react/primitives/composer/ComposerIf.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\ntype ComposerIfFilters = {\n /** Whether the composer is in editing mode */\n editing: boolean | undefined;\n /** Whether dictation is currently active */\n dictation: boolean | undefined;\n};\n\nexport type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<\n T,\n Exclude<keyof T, Keys>\n> &\n {\n [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;\n }[Keys];\n\nexport type UseComposerIfProps = RequireAtLeastOne<ComposerIfFilters>;\n\nconst useComposerIf = (props: UseComposerIfProps) => {\n return useAuiState((s) => {\n if (props.editing === true && !s.composer.isEditing) return false;\n if (props.editing === false && s.composer.isEditing) return false;\n\n const isDictating = s.composer.dictation != null;\n if (props.dictation === true && !isDictating) return false;\n if (props.dictation === false && isDictating) return false;\n\n return true;\n });\n};\n\nexport namespace ComposerPrimitiveIf {\n export type Props = PropsWithChildren<UseComposerIfProps>;\n}\n\n/**\n * @deprecated Use `<AuiIf condition={(s) => s.composer...} />` instead.\n */\nexport const ComposerPrimitiveIf: FC<ComposerPrimitiveIf.Props> = ({\n children,\n ...query\n}) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n\nComposerPrimitiveIf.displayName = \"ComposerPrimitive.If\";\n"],"mappings":";;;AAoBA,MAAMe,iBAAgBC,UAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,MAAAX,aAAAY,EAAA,OAAAD,MAAAZ,SAAA;EACDe,MAAAC,MAAA;GACjB,IAAIJ,MAAKZ,YAAa,QAAlB,CAA2BgB,EAACC,SAASC,WAAU,OAAS;GAC5D,IAAIN,MAAKZ,YAAa,SAASgB,EAACC,SAASC,WAAU,OAAS;GAE5D,MAAAC,cAAoBH,EAACC,SAAShB,aAAc;GAC5C,IAAIW,MAAKX,cAAe,QAApB,CAA6BkB,aAAW,OAAS;GACrD,IAAIP,MAAKX,cAAe,SAApBkB,aAAwC,OAAS;GAAM,OAEpD;EAAI;EACZN,EAAA,KAAAD,MAAAX;EAAAY,EAAA,KAAAD,MAAAZ;EAAAa,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OATMf,YAAYiB,EASlB;AAAC;;;;AAUJ,MAAaK,uBAAqDL,OAAA;CAAA,MAAAF,IAAAC,EAAA,CAAA;CAAA,IAAAQ;CAAA,IAAAC;CAAA,IAAAV,EAAA,OAAAE,IAAA;EAAC,CAAA,CAAAO,aAAAC,SAAAR;EAGlEF,EAAA,KAAAE;EAAAF,EAAA,KAAAS;EAAAT,EAAA,KAAAU;CAAA,OAAA;EAAAD,WAAAT,EAAA;EAAAU,QAAAV,EAAA;CAAA;CACqC,OAArBF,cAAcY,KACtBC,IAAAF,WAAA;AAAwB;AAGjCF,oBAAoBK,cAAc"}
1
+ {"version":3,"file":"ComposerIf.js","names":["FC","PropsWithChildren","useAuiState","ComposerIfFilters","editing","dictation","RequireAtLeastOne","T","Pick","Exclude","Keys","Required","K","Partial","UseComposerIfProps","useComposerIf","props","$","_c","t0","s","composer","isEditing","isDictating","ComposerPrimitiveIf","Props","children","query","result","displayName"],"sources":["../../../../src/react/primitives/composer/ComposerIf.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\ntype ComposerIfFilters = {\n /** Whether the composer is in editing mode */\n editing: boolean | undefined;\n /** Whether dictation is currently active */\n dictation: boolean | undefined;\n};\n\nexport type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<\n T,\n Exclude<keyof T, Keys>\n> &\n {\n [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;\n }[Keys];\n\nexport type UseComposerIfProps = RequireAtLeastOne<ComposerIfFilters>;\n\nconst useComposerIf = (props: UseComposerIfProps) => {\n return useAuiState((s) => {\n if (props.editing === true && !s.composer.isEditing) return false;\n if (props.editing === false && s.composer.isEditing) return false;\n\n const isDictating = s.composer.dictation != null;\n if (props.dictation === true && !isDictating) return false;\n if (props.dictation === false && isDictating) return false;\n\n return true;\n });\n};\n\nexport namespace ComposerPrimitiveIf {\n export type Props = PropsWithChildren<UseComposerIfProps>;\n}\n\n/**\n * @deprecated Use `<AuiIf condition={(s) => s.composer...} />` instead.\n */\nexport const ComposerPrimitiveIf: FC<ComposerPrimitiveIf.Props> = ({\n children,\n ...query\n}) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n\nComposerPrimitiveIf.displayName = \"ComposerPrimitive.If\";\n"],"mappings":";;;AAoBA,MAAMe,iBAAgBC,UAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,MAAAX,aAAAY,EAAA,OAAAD,MAAAZ,SAAA;EACDe,MAAAC,MAAA;GACjB,IAAIJ,MAAKZ,YAAa,QAAlB,CAA2BgB,EAACC,SAASC,WAAU,OAAS;GAC5D,IAAIN,MAAKZ,YAAa,SAASgB,EAACC,SAASC,WAAU,OAAS;GAE5D,MAAAC,cAAoBH,EAACC,SAAShB,aAAc;GAC5C,IAAIW,MAAKX,cAAe,QAApB,CAA6BkB,aAAW,OAAS;GACrD,IAAIP,MAAKX,cAAe,SAApBkB,aAAwC,OAAS;GAAM,OAEpD;EAAI;EACZN,EAAA,KAAAD,MAAAX;EAAAY,EAAA,KAAAD,MAAAZ;EAAAa,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OATMf,YAAYiB,EASlB;AAAC;;;;AAUJ,MAAaK,uBAAqDL,OAAA;CAAA,MAAAF,IAAAC,EAAA,CAAA;CAAA,IAAAQ;CAAA,IAAAC;CAAA,IAAAV,EAAA,OAAAE,IAAA;EAAC,CAAA,CAAAO,UAAA,GAAAC,SAAAR;EAGlEF,EAAA,KAAAE;EAAAF,EAAA,KAAAS;EAAAT,EAAA,KAAAU;CAAA,OAAA;EAAAD,WAAAT,EAAA;EAAAU,QAAAV,EAAA;CAAA;CACqC,OAArBF,cAAcY,KACtBC,IAAAF,WAAA;AAAwB;AAGjCF,oBAAoBK,cAAc"}
@@ -1,4 +1,5 @@
1
- import { QueueItemState } from "../../../store/scopes/queue-item.js";
1
+ import { QueueItemState } from "../../../runtime/queue/queue-item.js";
2
+ import "../../../store/scopes/queue-item.js";
2
3
  import { ReactNode } from "react";
3
4
  //#region src/react/primitives/composer/ComposerQueue.d.ts
4
5
  declare namespace ComposerPrimitiveQueue {
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerQueue.d.ts","names":[],"sources":["../../../../src/react/primitives/composer/ComposerQueue.tsx"],"mappings":";;;kBAKiB;OACH;;IAEV,WAAW;MAAS,WAAW;UAAqB;;;;;;;;;;;;;;;;;;cA6C3C,wCAAsB;EAxCvB,WAAC;IAAS,WAAW;QAAqB"}
1
+ {"version":3,"file":"ComposerQueue.d.ts","names":[],"sources":["../../../../src/react/primitives/composer/ComposerQueue.tsx"],"mappings":";;;;kBAMiB;OACH;;IAEV,WAAW;MAAS,WAAW;UAAqB;;;;;;;;;;;;;;;;;;cA+C3C,wCAAsB;EA1CvB,WAAC;IAAS,WAAW;QAAqB"}
@@ -1,11 +1,12 @@
1
1
  import { QueueItemByIndexProvider } from "../../providers/QueueItemByIndexProvider.js";
2
2
  import { memo, useMemo } from "@assistant-ui/tap/react-shim";
3
3
  import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
4
+ import { useShallowSelector } from "@assistant-ui/store/internal";
4
5
  import { jsx } from "react/jsx-runtime";
5
6
  //#region src/react/primitives/composer/ComposerQueue.tsx
6
7
  const ComposerPrimitiveQueueInner = ({ children }) => {
7
- const queue = useAuiState((s) => s.composer.queue.length);
8
- return useMemo(() => Array.from({ length: queue }, (_, index) => /* @__PURE__ */ jsx(QueueItemByIndexProvider, {
8
+ const queueItemIds = useAuiState(useShallowSelector((s) => s.composer.queue.map((item) => item.id)));
9
+ return useMemo(() => queueItemIds.map((queueItemId, index) => /* @__PURE__ */ jsx(QueueItemByIndexProvider, {
9
10
  index,
10
11
  children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
11
12
  getItemState: (aui) => aui.composer.queueItem({ index }).getState(),
@@ -13,7 +14,7 @@ const ComposerPrimitiveQueueInner = ({ children }) => {
13
14
  return getItem();
14
15
  } })
15
16
  })
16
- }, index)), [queue, children]);
17
+ }, queueItemId)), [queueItemIds, children]);
17
18
  };
18
19
  /**
19
20
  * Renders all queue items in the composer.
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerQueue.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","QueueItemState","QueueItemByIndexProvider","ComposerPrimitiveQueue","Props","children","value","queueItem","ComposerPrimitiveQueueInner","queue","s","composer","length","Array","from","_","index","aui","getState","getItem","displayName"],"sources":["../../../../src/react/primitives/composer/ComposerQueue.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport type { QueueItemState } from \"../../../store/scopes/queue-item\";\nimport { QueueItemByIndexProvider } from \"../../providers/QueueItemByIndexProvider\";\n\nexport namespace ComposerPrimitiveQueue {\n export type Props = {\n /** Render function called for each queue item. Receives the queue item state. */\n children: (value: { queueItem: QueueItemState }) => ReactNode;\n };\n}\n\nconst ComposerPrimitiveQueueInner: FC<{\n children: (value: { queueItem: QueueItemState }) => ReactNode;\n}> = ({ children }) => {\n const queue = useAuiState((s) => s.composer.queue.length);\n\n return useMemo(\n () =>\n Array.from({ length: queue }, (_, index) => (\n <QueueItemByIndexProvider key={index} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.composer.queueItem({ index }).getState()}\n >\n {(getItem) =>\n children({\n get queueItem() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </QueueItemByIndexProvider>\n )),\n [queue, children],\n );\n};\n\n/**\n * Renders all queue items in the composer.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Queue>\n * {({ queueItem }) => (\n * <div>\n * <QueueItemPrimitive.Text />\n * <QueueItemPrimitive.Steer>Run Now</QueueItemPrimitive.Steer>\n * </div>\n * )}\n * </ComposerPrimitive.Queue>\n * ```\n */\nexport const ComposerPrimitiveQueue = memo(ComposerPrimitiveQueueInner);\n\nComposerPrimitiveQueue.displayName = \"ComposerPrimitive.Queue\";\n"],"mappings":";;;;;AAYA,MAAMa,+BAEA,EAAEH,eAAe;CACrB,MAAMI,QAAQT,aAAaU,MAAMA,EAAEC,SAASF,MAAMG,MAAM;CAExD,OAAOd,cAEHe,MAAMC,KAAK,EAAEF,QAAQH,MAAM,IAAIM,GAAGC,UAChC,oBAAC,0BAAD;EAA6CA;EAC3C,UAAA,oBAAC,4BAAD;GACE,eAAeC,QAAQA,IAAIN,SAASJ,UAAU,EAAES,MAAM,CAAC,CAAC,CAACE,SAAS;GAEhEC,WAAAA,YACAd,SAAS,EACP,IAAIE,YAAY;IACd,OAAOY,QAAQ;GACjB,EACF,CAAC;EAEuB,CAAA;CACJ,GAZKH,KAYL,CAC3B,GACH,CAACP,OAAOJ,QAAQ,CAClB;AACF;;;;;;;;;;;;;;;;AAiBA,MAAaF,yBAAyBN,KAAKW,2BAA2B;AAEtEL,uBAAuBiB,cAAc"}
1
+ {"version":3,"file":"ComposerQueue.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","useShallowSelector","QueueItemState","QueueItemByIndexProvider","ComposerPrimitiveQueue","Props","children","value","queueItem","ComposerPrimitiveQueueInner","queueItemIds","s","composer","queue","map","item","id","queueItemId","index","aui","getState","getItem","displayName"],"sources":["../../../../src/react/primitives/composer/ComposerQueue.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport type { QueueItemState } from \"../../../store/scopes/queue-item\";\nimport { QueueItemByIndexProvider } from \"../../providers/QueueItemByIndexProvider\";\n\nexport namespace ComposerPrimitiveQueue {\n export type Props = {\n /** Render function called for each queue item. Receives the queue item state. */\n children: (value: { queueItem: QueueItemState }) => ReactNode;\n };\n}\n\nconst ComposerPrimitiveQueueInner: FC<{\n children: (value: { queueItem: QueueItemState }) => ReactNode;\n}> = ({ children }) => {\n const queueItemIds = useAuiState(\n useShallowSelector((s) => s.composer.queue.map((item) => item.id)),\n );\n\n return useMemo(\n () =>\n queueItemIds.map((queueItemId, index) => (\n <QueueItemByIndexProvider key={queueItemId} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.composer.queueItem({ index }).getState()}\n >\n {(getItem) =>\n children({\n get queueItem() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </QueueItemByIndexProvider>\n )),\n [queueItemIds, children],\n );\n};\n\n/**\n * Renders all queue items in the composer.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Queue>\n * {({ queueItem }) => (\n * <div>\n * <QueueItemPrimitive.Text />\n * <QueueItemPrimitive.Steer>Run Now</QueueItemPrimitive.Steer>\n * </div>\n * )}\n * </ComposerPrimitive.Queue>\n * ```\n */\nexport const ComposerPrimitiveQueue = memo(ComposerPrimitiveQueueInner);\n\nComposerPrimitiveQueue.displayName = \"ComposerPrimitive.Queue\";\n"],"mappings":";;;;;;AAaA,MAAMc,+BAEA,EAAEH,eAAe;CACrB,MAAMI,eAAeV,YACnBC,oBAAoBU,MAAMA,EAAEC,SAASC,MAAMC,KAAKC,SAASA,KAAKC,EAAE,CAAC,CACnE;CAEA,OAAOlB,cAEHY,aAAaI,KAAKG,aAAaC,UAC7B,oBAAC,0BAAD;EAAmDA;EACjD,UAAA,oBAAC,4BAAD;GACE,eAAeC,QAAQA,IAAIP,SAASJ,UAAU,EAAEU,MAAM,CAAC,CAAC,CAACE,SAAS;GAEhEC,WAAAA,YACAf,SAAS,EACP,IAAIE,YAAY;IACd,OAAOa,QAAQ;GACjB,EACF,CAAC;EAEuB,CAAA;CACJ,GAZKJ,WAYL,CAC3B,GACH,CAACP,cAAcJ,QAAQ,CACzB;AACF;;;;;;;;;;;;;;;;AAiBA,MAAaF,yBAAyBP,KAAKY,2BAA2B;AAEtEL,uBAAuBkB,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"MessageAttachments.d.ts","names":[],"sources":["../../../../src/react/primitives/message/MessageAttachments.tsx"],"mappings":";;;KAWK;EACH,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;;kBAGE;OACH;;IAGN,YAAY;IACZ;;;IAIA,WAAW;MAAS,YAAY;UAAyB;IACzD;;;kBAgCS;OACH;IACV;IACA,aAAa;;;;;;cAOJ,mCAAmC,GAAG,kCAAkC;cAiDxE,6BAA6B,GACxC,4BAA4B"}
1
+ {"version":3,"file":"MessageAttachments.d.ts","names":[],"sources":["../../../../src/react/primitives/message/MessageAttachments.tsx"],"mappings":";;;KAYK;EACH,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;;kBAGE;OACH;;IAGN,YAAY;IACZ;;;IAIA,WAAW;MAAS,YAAY;UAAyB;IACzD;;;kBAgCS;OACH;IACV;IACA,aAAa;;;;;;cAOJ,mCAAmC,GAAG,kCAAkC;cAmDxE,6BAA6B,GACxC,4BAA4B"}
@@ -2,6 +2,7 @@ import { MessageAttachmentByIndexProvider } from "../../providers/AttachmentByIn
2
2
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
3
3
  import { memo, useMemo } from "@assistant-ui/tap/react-shim";
4
4
  import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
5
+ import { useShallowSelector } from "@assistant-ui/store/internal";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  //#region src/react/primitives/message/MessageAttachments.tsx
7
8
  const getComponent = (components, attachment) => {
@@ -61,11 +62,11 @@ const MessagePrimitiveAttachmentByIndex = memo((t0) => {
61
62
  }, (prev, next) => prev.index === next.index && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment);
62
63
  MessagePrimitiveAttachmentByIndex.displayName = "MessagePrimitive.AttachmentByIndex";
63
64
  const MessagePrimitiveAttachmentsInner = ({ children }) => {
64
- const attachmentsCount = useAuiState((s) => {
65
- if (s.message.role !== "user") return 0;
66
- return (s.message.attachments ?? []).length;
67
- });
68
- return useMemo(() => Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(MessageAttachmentByIndexProvider, {
65
+ const attachmentIds = useAuiState(useShallowSelector((s) => {
66
+ if (s.message.role !== "user") return [];
67
+ return (s.message.attachments ?? []).map((attachment) => attachment.id);
68
+ }));
69
+ return useMemo(() => attachmentIds.map((attachmentId, index) => /* @__PURE__ */ jsx(MessageAttachmentByIndexProvider, {
69
70
  index,
70
71
  children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
71
72
  getItemState: (aui) => aui.message.attachment({ index }).getState(),
@@ -73,7 +74,7 @@ const MessagePrimitiveAttachmentsInner = ({ children }) => {
73
74
  return getItem();
74
75
  } })
75
76
  })
76
- }, index)), [attachmentsCount, children]);
77
+ }, attachmentId)), [attachmentIds, children]);
77
78
  };
78
79
  const MessagePrimitiveAttachments = (t0) => {
79
80
  const $ = c(4);
@@ -1 +1 @@
1
- {"version":3,"file":"MessageAttachments.js","names":["CompleteAttachment","ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","MessageAttachmentByIndexProvider","MessageAttachmentsComponentConfig","Image","Document","File","Attachment","MessagePrimitiveAttachments","Props","components","children","value","attachment","getComponent","type","AttachmentComponent","t0","$","_c","_temp","t1","t2","Component","t3","MessagePrimitiveAttachmentByIndex","index","prev","next","displayName","MessagePrimitiveAttachmentsInner","attachmentsCount","s","message","role","attachments","length","Array","from","_","aui","getState","getItem"],"sources":["../../../../src/react/primitives/message/MessageAttachments.tsx"],"sourcesContent":["import type { CompleteAttachment } from \"../../../types/attachment\";\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { MessageAttachmentByIndexProvider } from \"../../providers/AttachmentByIndexProvider\";\n\ntype MessageAttachmentsComponentConfig = {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n};\n\nexport namespace MessagePrimitiveAttachments {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: MessageAttachmentsComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each attachment. Receives the attachment. */\n children: (value: { attachment: CompleteAttachment }) => ReactNode;\n components?: never;\n };\n}\n\nconst getComponent = (\n components: MessageAttachmentsComponentConfig | undefined,\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n return components?.Attachment;\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessageAttachmentsComponentConfig | undefined;\n}> = ({ components }) => {\n const attachment = useAuiState((s) => s.attachment);\n if (!attachment) return null;\n\n const Component = getComponent(components, attachment as CompleteAttachment);\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace MessagePrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: MessageAttachmentsComponentConfig;\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the current message.\n */\nexport const MessagePrimitiveAttachmentByIndex: FC<MessagePrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <MessageAttachmentByIndexProvider index={index}>\n <AttachmentComponent components={components} />\n </MessageAttachmentByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nMessagePrimitiveAttachmentByIndex.displayName =\n \"MessagePrimitive.AttachmentByIndex\";\n\nconst MessagePrimitiveAttachmentsInner: FC<{\n children: (value: { attachment: CompleteAttachment }) => ReactNode;\n}> = ({ children }) => {\n const attachmentsCount = useAuiState((s) => {\n if (s.message.role !== \"user\") return 0;\n return (s.message.attachments ?? []).length;\n });\n\n return useMemo(\n () =>\n Array.from({ length: attachmentsCount }, (_, index) => (\n <MessageAttachmentByIndexProvider key={index} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.message.attachment({ index }).getState()}\n >\n {(getItem) =>\n children({\n get attachment() {\n return getItem() as CompleteAttachment;\n },\n })\n }\n </RenderChildrenWithAccessor>\n </MessageAttachmentByIndexProvider>\n )),\n [attachmentsCount, children],\n );\n};\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components, children }) => {\n if (components) {\n return (\n <MessagePrimitiveAttachmentsInner>\n {({ attachment }) => {\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n }}\n </MessagePrimitiveAttachmentsInner>\n );\n }\n return (\n <MessagePrimitiveAttachmentsInner>\n {children}\n </MessagePrimitiveAttachmentsInner>\n );\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":"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"}
1
+ {"version":3,"file":"MessageAttachments.js","names":["CompleteAttachment","ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","useShallowSelector","MessageAttachmentByIndexProvider","MessageAttachmentsComponentConfig","Image","Document","File","Attachment","MessagePrimitiveAttachments","Props","components","children","value","attachment","getComponent","type","AttachmentComponent","t0","$","_c","_temp","t1","t2","Component","t3","MessagePrimitiveAttachmentByIndex","index","prev","next","displayName","MessagePrimitiveAttachmentsInner","attachmentIds","s","message","role","attachments","map","id","attachmentId","aui","getState","getItem"],"sources":["../../../../src/react/primitives/message/MessageAttachments.tsx"],"sourcesContent":["import type { CompleteAttachment } from \"../../../types/attachment\";\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport { MessageAttachmentByIndexProvider } from \"../../providers/AttachmentByIndexProvider\";\n\ntype MessageAttachmentsComponentConfig = {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n};\n\nexport namespace MessagePrimitiveAttachments {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: MessageAttachmentsComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each attachment. Receives the attachment. */\n children: (value: { attachment: CompleteAttachment }) => ReactNode;\n components?: never;\n };\n}\n\nconst getComponent = (\n components: MessageAttachmentsComponentConfig | undefined,\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n return components?.Attachment;\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessageAttachmentsComponentConfig | undefined;\n}> = ({ components }) => {\n const attachment = useAuiState((s) => s.attachment);\n if (!attachment) return null;\n\n const Component = getComponent(components, attachment as CompleteAttachment);\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace MessagePrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: MessageAttachmentsComponentConfig;\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the current message.\n */\nexport const MessagePrimitiveAttachmentByIndex: FC<MessagePrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <MessageAttachmentByIndexProvider index={index}>\n <AttachmentComponent components={components} />\n </MessageAttachmentByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nMessagePrimitiveAttachmentByIndex.displayName =\n \"MessagePrimitive.AttachmentByIndex\";\n\nconst MessagePrimitiveAttachmentsInner: FC<{\n children: (value: { attachment: CompleteAttachment }) => ReactNode;\n}> = ({ children }) => {\n const attachmentIds = useAuiState(\n useShallowSelector((s) => {\n if (s.message.role !== \"user\") return [];\n return (s.message.attachments ?? []).map((attachment) => attachment.id);\n }),\n );\n\n return useMemo(\n () =>\n attachmentIds.map((attachmentId, index) => (\n <MessageAttachmentByIndexProvider key={attachmentId} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.message.attachment({ index }).getState()}\n >\n {(getItem) =>\n children({\n get attachment() {\n return getItem() as CompleteAttachment;\n },\n })\n }\n </RenderChildrenWithAccessor>\n </MessageAttachmentByIndexProvider>\n )),\n [attachmentIds, children],\n );\n};\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components, children }) => {\n if (components) {\n return (\n <MessagePrimitiveAttachmentsInner>\n {({ attachment }) => {\n const Component = getComponent(components, attachment);\n if (!Component) return null;\n return <Component />;\n }}\n </MessagePrimitiveAttachmentsInner>\n );\n }\n return (\n <MessagePrimitiveAttachmentsInner>\n {children}\n </MessagePrimitiveAttachmentsInner>\n );\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":"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"}