@assistant-ui/core 0.3.18 → 0.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/dist/adapters/speech.d.ts.map +1 -1
  2. package/dist/adapters/speech.js +13 -3
  3. package/dist/adapters/speech.js.map +1 -1
  4. package/dist/adapters/thread-history.d.ts +4 -0
  5. package/dist/adapters/thread-history.d.ts.map +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/internal.d.ts +1 -1
  9. package/dist/model-context/frame/host.d.ts.map +1 -1
  10. package/dist/model-context/frame/host.js +26 -11
  11. package/dist/model-context/frame/host.js.map +1 -1
  12. package/dist/model-context/interactable-composer-metadata.js +11 -9
  13. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  14. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  15. package/dist/react/adapters/LocalStorageThreadListAdapter.js +45 -7
  16. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  17. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  18. package/dist/react/client/DataRenderers.js +20 -15
  19. package/dist/react/client/DataRenderers.js.map +1 -1
  20. package/dist/react/client/Interactables.d.ts.map +1 -1
  21. package/dist/react/client/Interactables.js +11 -5
  22. package/dist/react/client/Interactables.js.map +1 -1
  23. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  24. package/dist/react/client/RemoteThreadList.js +3 -2
  25. package/dist/react/client/RemoteThreadList.js.map +1 -1
  26. package/dist/react/client/interactable-model-context.d.ts.map +1 -1
  27. package/dist/react/client/interactable-model-context.js +3 -2
  28. package/dist/react/client/interactable-model-context.js.map +1 -1
  29. package/dist/react/index.d.ts +2 -2
  30. package/dist/react/index.js +2 -2
  31. package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -1
  32. package/dist/react/interactables-legacy/useAssistantInteractable.js +3 -0
  33. package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
  34. package/dist/react/model-context/useInteractable.d.ts.map +1 -1
  35. package/dist/react/model-context/useInteractable.js +4 -1
  36. package/dist/react/model-context/useInteractable.js.map +1 -1
  37. package/dist/react/model-context/useInteractableVersions.js +1 -1
  38. package/dist/react/primitives/message/MessageGroupedParts.d.ts +11 -2
  39. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  40. package/dist/react/primitives/message/MessageGroupedParts.js +3 -2
  41. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  42. package/dist/react/primitives/part/PartMessages.d.ts +1 -0
  43. package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
  44. package/dist/react/primitives/part/PartMessages.js +1 -0
  45. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  46. package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
  47. package/dist/react/primitives/thread/ThreadMessages.js +6 -5
  48. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  49. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  50. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +2 -1
  51. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  52. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +2 -24
  53. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  54. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +135 -374
  55. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  56. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -0
  57. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  58. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +22 -2
  59. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  60. package/dist/react/runtimes/cloud/auiV0.d.ts +40 -15
  61. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  62. package/dist/react/runtimes/cloud/auiV0.js +62 -15
  63. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  64. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +2 -1
  65. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -1
  66. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +4 -0
  67. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -1
  68. package/dist/react/runtimes/cloud/sdkIdentity.d.ts +6 -0
  69. package/dist/react/runtimes/cloud/sdkIdentity.d.ts.map +1 -0
  70. package/dist/react/runtimes/cloud/sdkIdentity.js +9 -0
  71. package/dist/react/runtimes/cloud/sdkIdentity.js.map +1 -0
  72. package/dist/react/runtimes/external-message-converter.d.ts +12 -2
  73. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  74. package/dist/react/runtimes/external-message-converter.js +26 -61
  75. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  76. package/dist/react/runtimes/useRemoteThreadListRuntime.js +1 -1
  77. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  78. package/dist/react/utils/groupParts.d.ts +6 -1
  79. package/dist/react/utils/groupParts.d.ts.map +1 -1
  80. package/dist/react/utils/groupParts.js +6 -0
  81. package/dist/react/utils/groupParts.js.map +1 -1
  82. package/dist/react/utils/useJSONEqual.d.ts +3 -1
  83. package/dist/react/utils/useJSONEqual.d.ts.map +1 -1
  84. package/dist/react/utils/useJSONEqual.js +6 -1
  85. package/dist/react/utils/useJSONEqual.js.map +1 -1
  86. package/dist/react/utils/useJSONSchemaDependency.d.ts +7 -0
  87. package/dist/react/utils/useJSONSchemaDependency.d.ts.map +1 -0
  88. package/dist/react/utils/useJSONSchemaDependency.js +20 -0
  89. package/dist/react/utils/useJSONSchemaDependency.js.map +1 -0
  90. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  91. package/dist/runtime/api/thread-runtime.js +2 -5
  92. package/dist/runtime/api/thread-runtime.js.map +1 -1
  93. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -0
  94. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  95. package/dist/runtime/base/base-composer-runtime-core.js +46 -10
  96. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  97. package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -0
  98. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  99. package/dist/runtime/base/base-thread-runtime-core.js +155 -64
  100. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  101. package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
  102. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  103. package/dist/runtime/queue/message-queue.d.ts +5 -0
  104. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  105. package/dist/runtime/queue/message-queue.js +61 -6
  106. package/dist/runtime/queue/message-queue.js.map +1 -1
  107. package/dist/runtime/utils/auto-status.d.ts +6 -2
  108. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  109. package/dist/runtime/utils/auto-status.js +12 -4
  110. package/dist/runtime/utils/auto-status.js.map +1 -1
  111. package/dist/runtime/utils/external-message-conversion.d.ts +16 -4
  112. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
  113. package/dist/runtime/utils/external-message-conversion.js +48 -12
  114. package/dist/runtime/utils/external-message-conversion.js.map +1 -1
  115. package/dist/runtime/utils/message-repository.js +3 -3
  116. package/dist/runtime/utils/message-repository.js.map +1 -1
  117. package/dist/runtime/utils/thread-message-like.d.ts +2 -1
  118. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  119. package/dist/runtime/utils/thread-message-like.js +4 -2
  120. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  121. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  122. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +8 -1
  123. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  124. package/dist/runtimes/internal.d.ts +1 -1
  125. package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
  126. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  127. package/dist/runtimes/local/local-thread-runtime-core.js +4 -1
  128. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  129. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  130. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -1
  131. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  132. package/dist/store/clients/external-thread.d.ts.map +1 -1
  133. package/dist/store/clients/external-thread.js +241 -200
  134. package/dist/store/clients/external-thread.js.map +1 -1
  135. package/dist/store/clients/thread-tasks.d.ts +13 -0
  136. package/dist/store/clients/thread-tasks.d.ts.map +1 -0
  137. package/dist/store/clients/thread-tasks.js +69 -0
  138. package/dist/store/clients/thread-tasks.js.map +1 -0
  139. package/dist/store/index.d.ts +3 -2
  140. package/dist/store/index.js +3 -3
  141. package/dist/store/primitive-predicates.d.ts.map +1 -1
  142. package/dist/store/primitive-predicates.js +4 -4
  143. package/dist/store/primitive-predicates.js.map +1 -1
  144. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  145. package/dist/store/runtime-clients/thread-runtime-client.js +176 -128
  146. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  147. package/dist/store/scope-registration.d.ts +2 -0
  148. package/dist/store/scope-registration.d.ts.map +1 -1
  149. package/dist/store/scopes/task.d.ts +36 -0
  150. package/dist/store/scopes/task.d.ts.map +1 -0
  151. package/dist/store/scopes/task.js +0 -0
  152. package/dist/store/scopes/thread.d.ts +20 -0
  153. package/dist/store/scopes/thread.d.ts.map +1 -1
  154. package/dist/subscribable/subscribable.d.ts +2 -1
  155. package/dist/subscribable/subscribable.d.ts.map +1 -1
  156. package/dist/subscribable/subscribable.js +23 -15
  157. package/dist/subscribable/subscribable.js.map +1 -1
  158. package/dist/types/index.d.ts +2 -2
  159. package/dist/types/message.d.ts +8 -1
  160. package/dist/types/message.d.ts.map +1 -1
  161. package/dist/types/message.js.map +1 -1
  162. package/dist/utils/abortable-iterable.d.ts.map +1 -1
  163. package/dist/utils/abortable-iterable.js +30 -14
  164. package/dist/utils/abortable-iterable.js.map +1 -1
  165. package/dist/utils/getGroupStatus.d.ts +18 -2
  166. package/dist/utils/getGroupStatus.d.ts.map +1 -1
  167. package/dist/utils/getGroupStatus.js +32 -7
  168. package/dist/utils/getGroupStatus.js.map +1 -1
  169. package/dist/utils/wire-media.d.ts.map +1 -1
  170. package/dist/utils/wire-media.js +2 -2
  171. package/dist/utils/wire-media.js.map +1 -1
  172. package/package.json +6 -6
  173. package/src/adapters/speech.test.ts +236 -0
  174. package/src/adapters/speech.ts +17 -10
  175. package/src/adapters/thread-history.ts +3 -0
  176. package/src/index.ts +1 -0
  177. package/src/model-context/frame/host.test.ts +113 -1
  178. package/src/model-context/frame/host.ts +39 -12
  179. package/src/model-context/interactable-composer-metadata.test.ts +30 -0
  180. package/src/model-context/interactable-composer-metadata.ts +10 -10
  181. package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +244 -0
  182. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +104 -7
  183. package/src/react/client/DataRenderers.test.tsx +45 -0
  184. package/src/react/client/DataRenderers.ts +13 -9
  185. package/src/react/client/Interactables.test.ts +44 -1
  186. package/src/react/client/Interactables.ts +7 -1
  187. package/src/react/client/RemoteThreadList.test.ts +41 -1
  188. package/src/react/client/RemoteThreadList.ts +15 -2
  189. package/src/react/client/interactable-model-context.test.ts +44 -0
  190. package/src/react/client/interactable-model-context.ts +3 -2
  191. package/src/react/index.ts +5 -1
  192. package/src/react/interactables-legacy/useAssistantInteractable.test.tsx +132 -0
  193. package/src/react/interactables-legacy/useAssistantInteractable.ts +10 -1
  194. package/src/react/model-context/useInteractable.test.tsx +177 -0
  195. package/src/react/model-context/useInteractable.ts +3 -0
  196. package/src/react/primitive-hooks/useActionBarCopy.test.ts +0 -1
  197. package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +0 -1
  198. package/src/react/primitives/message/MessageGroupedParts.test.tsx +96 -0
  199. package/src/react/primitives/message/MessageGroupedParts.tsx +15 -4
  200. package/src/react/primitives/part/PartMessages.test.tsx +104 -1
  201. package/src/react/primitives/part/PartMessages.tsx +1 -0
  202. package/src/react/primitives/thread/ThreadMessages.test.tsx +142 -0
  203. package/src/react/primitives/thread/ThreadMessages.tsx +8 -5
  204. package/src/react/providers/ReadonlyThreadProvider.test.tsx +56 -0
  205. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +7 -1
  206. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +20 -14
  207. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +221 -1
  208. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +166 -512
  209. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +77 -0
  210. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +27 -1
  211. package/src/react/runtimes/cloud/auiV0.ts +160 -25
  212. package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +21 -0
  213. package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +7 -1
  214. package/src/react/runtimes/cloud/sdkIdentity.ts +9 -0
  215. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +18 -4
  216. package/src/react/runtimes/external-message-converter.test.ts +136 -1
  217. package/src/react/runtimes/external-message-converter.ts +39 -93
  218. package/src/react/runtimes/useRemoteThreadListRuntime.ts +1 -1
  219. package/src/react/utils/groupParts.ts +12 -1
  220. package/src/react/utils/useJSONEqual.ts +9 -0
  221. package/src/react/utils/useJSONSchemaDependency.ts +22 -0
  222. package/src/runtime/api/thread-runtime.test.ts +58 -0
  223. package/src/runtime/api/thread-runtime.ts +2 -4
  224. package/src/runtime/base/base-composer-runtime-core.ts +69 -16
  225. package/src/runtime/base/base-thread-runtime-core.test.ts +1008 -1
  226. package/src/runtime/base/base-thread-runtime-core.ts +222 -83
  227. package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
  228. package/src/runtime/queue/message-queue.ts +68 -6
  229. package/src/runtime/utils/auto-status.test.ts +112 -1
  230. package/src/runtime/utils/auto-status.ts +31 -5
  231. package/src/runtime/utils/external-message-conversion.test.ts +134 -0
  232. package/src/runtime/utils/external-message-conversion.ts +122 -31
  233. package/src/runtime/utils/message-repository.test.ts +49 -0
  234. package/src/runtime/utils/message-repository.ts +3 -3
  235. package/src/runtime/utils/thread-message-like.test.ts +52 -0
  236. package/src/runtime/utils/thread-message-like.ts +4 -0
  237. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -1
  238. package/src/runtimes/local/local-thread-runtime-core.test.ts +21 -0
  239. package/src/runtimes/local/local-thread-runtime-core.ts +11 -1
  240. package/src/runtimes/tool-invocations/EDGE_CASES.md +2 -6
  241. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +133 -0
  242. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +10 -6
  243. package/src/store/clients/external-thread.ts +19 -1
  244. package/src/store/clients/thread-tasks.test.ts +274 -0
  245. package/src/store/clients/thread-tasks.ts +138 -0
  246. package/src/store/index.ts +8 -0
  247. package/src/store/primitive-predicates.test.ts +48 -5
  248. package/src/store/primitive-predicates.ts +7 -2
  249. package/src/store/runtime-clients/thread-runtime-client.ts +31 -1
  250. package/src/store/scope-registration.ts +2 -0
  251. package/src/store/scopes/task.ts +34 -0
  252. package/src/store/scopes/thread.ts +16 -0
  253. package/src/store/thread-tasks.test.tsx +209 -0
  254. package/src/subscribable/subscribable.test.ts +156 -1
  255. package/src/subscribable/subscribable.ts +25 -15
  256. package/src/tests/MessageRepository.test.ts +1 -5
  257. package/src/tests/auiV0Encode.test.ts +300 -0
  258. package/src/tests/base-composer-runtime-core-send.test.ts +51 -0
  259. package/src/tests/base-composer-runtime-core.test.ts +314 -2
  260. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +151 -0
  261. package/src/tests/external-thread-attachments.test.tsx +69 -0
  262. package/src/tests/external-thread-parity.test.tsx +34 -0
  263. package/src/tests/groupParts.test.ts +71 -0
  264. package/src/tests/message-queue.test.ts +253 -0
  265. package/src/tests/remote-thread-list-reactive-threadId.test.ts +51 -0
  266. package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +43 -0
  267. package/src/types/index.ts +1 -0
  268. package/src/types/message.ts +8 -0
  269. package/src/utils/abortable-iterable.test.ts +115 -0
  270. package/src/utils/abortable-iterable.ts +34 -23
  271. package/src/utils/getGroupStatus.test.ts +70 -4
  272. package/src/utils/getGroupStatus.ts +35 -12
  273. package/src/utils/wire-media.test.ts +10 -0
  274. package/src/utils/wire-media.ts +6 -2
@@ -17,6 +17,7 @@ type EventSubscribable<TEvent extends string> = {
17
17
  } | undefined, unknown>;
18
18
  };
19
19
  declare const notifySubscribers: <TArgs extends unknown[]>(subscribers: Iterable<(...args: TArgs) => void>, ...args: TArgs) => void;
20
+ declare const runCleanups: (cleanups: Iterable<Unsubscribe>) => void;
20
21
  declare class BaseSubscribable {
21
22
  private _subscribers;
22
23
  subscribe(callback: () => void): Unsubscribe;
@@ -75,5 +76,5 @@ declare class EventSubscriptionSubject<TEvent extends string> extends BaseSubjec
75
76
  protected _connect(): Unsubscribe;
76
77
  }
77
78
  //#endregion
78
- export { BaseSubject, BaseSubscribable, EventSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscribable, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject, Subscribable, SubscribableWithState, WritableSubscribable, notifySubscribers };
79
+ export { BaseSubject, BaseSubscribable, EventSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscribable, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject, Subscribable, SubscribableWithState, WritableSubscribable, notifySubscribers, runCleanups };
79
80
  //# sourceMappingURL=subscribable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscribable.d.ts","names":[],"sources":["../../src/subscribable/subscribable.ts"],"mappings":";;cAIa;KACD,qBAAqB;KAErB;EACV,YAAY,yBAAyB;;KAG3B,sBAAsB,QAAQ,SAAS;EACjD,MAAM;EACN,gBAAgB;;KAGN,mBACV,eAAe,0BACf,SACE,sBAAsB,QAAQ;KAEtB,kBAAkB;EAC5B,OAAO;EACP,SAAS;IAEH,cACE,OAAO,QACP,WAAW,+BACR;;;cAOA,oBAAqB,yBAChC,aAAa,aAAa,MAAM,oBAC7B,MAAM;cA4BE;UACH;EAED,UAAU,uBAAuB;EAKjC,iBAAa;YASV;;cAKC,qBAAqB,gBAAgB;UACxC;EAEI,YAAA,OAAO;EAUZ,YAAY;EAIZ,yBAAyB;EAEzB,SAAS,OAAO;;uBAQH;UACZ;UACA;gBAEM;qBAIK,YAAY;YAErB,kBAAkB,mBAAmB;UASvC;EAUD,UAAU,WAAW;;cAWjB,sBAAsB,uBAAuB,eAChD,uBACG,sBAAsB,QAAQ;MAE9B,QAAI;UAIP;EAEI,YAAA,SAAS,sBAAsB,SAAS,aAAa;UASzD;EACD,gBAAQ;UAKP;YAQE,YAAQ;;cAaP,mBAAmB,uBAAuB,eAC7C,uBACG,sBAAsB,QAAQ;MAE9B,QAAI;UAIP;EAEI,YAAA,SAAS,sBAAsB,SAAS,aAAa;UAKzD;UACA;EACD,gBAAQ;YAiBL,YAAQ;;cAYP,0BACX,eAAe,0BACf,eAEQ,uBAEN,sBAAsB,QAAQ,QAC9B,mBAAmB,QAAQ;MAElB,QAAI;UAIP;EAEI,YAAA,SAAS,mBAAmB,QAAQ;EAKzC,YAAQ;EAIR,eAAe,uBAAoB;YAIhC,YAAY;;cA0BX,yBACX,+BACQ;UACA;EAEI,YAAA,QAAQ,kBAAkB;EAK/B;IA3RW,cAAA,OAAA,QAAA,W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AqSJ,eAAe,uBAAoB;YAIhC,YAAY"}
@@ -15,6 +15,9 @@ const notifySubscribers = (subscribers, ...args) => {
15
15
  throw new AggregateError(errors);
16
16
  }
17
17
  };
18
+ const runCleanups = (cleanups) => {
19
+ notifySubscribers(cleanups);
20
+ };
18
21
  const shallowEqualOrUndefined = (a, b) => a === void 0 || b === void 0 ? a === b : shallowEqual(a, b);
19
22
  var BaseSubscribable = class {
20
23
  _subscribers = /* @__PURE__ */ new Set();
@@ -71,8 +74,9 @@ var BaseSubject = class {
71
74
  if (this._connection) return;
72
75
  this._connection = this._connect();
73
76
  } else {
74
- this._connection?.();
77
+ const connection = this._connection;
75
78
  this._connection = void 0;
79
+ connection?.();
76
80
  }
77
81
  }
78
82
  subscribe(callback) {
@@ -172,15 +176,17 @@ var NestedSubscriptionSubject = class extends BaseSubject {
172
176
  const newState = this.binding.getState();
173
177
  if (newState === lastState) return;
174
178
  lastState = newState;
175
- innerUnsubscribe?.();
176
- innerUnsubscribe = newState?.subscribe(callback);
177
- callback();
179
+ const previousInner = innerUnsubscribe;
180
+ innerUnsubscribe = void 0;
181
+ try {
182
+ previousInner?.();
183
+ } finally {
184
+ innerUnsubscribe = newState?.subscribe(callback);
185
+ callback();
186
+ }
178
187
  };
179
188
  const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);
180
- return () => {
181
- outerUnsubscribe?.();
182
- innerUnsubscribe?.();
183
- };
189
+ return () => runCleanups([() => outerUnsubscribe?.(), () => innerUnsubscribe?.()]);
184
190
  }
185
191
  };
186
192
  var EventSubscriptionSubject = class extends BaseSubject {
@@ -206,17 +212,19 @@ var EventSubscriptionSubject = class extends BaseSubject {
206
212
  const newState = this.config.binding.getState();
207
213
  if (newState === lastState) return;
208
214
  lastState = newState;
209
- innerUnsubscribe?.();
210
- innerUnsubscribe = newState?.unstable_on(this.config.event, callback);
215
+ const previousInner = innerUnsubscribe;
216
+ innerUnsubscribe = void 0;
217
+ try {
218
+ previousInner?.();
219
+ } finally {
220
+ innerUnsubscribe = newState?.unstable_on(this.config.event, callback);
221
+ }
211
222
  };
212
223
  const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);
213
- return () => {
214
- outerUnsubscribe?.();
215
- innerUnsubscribe?.();
216
- };
224
+ return () => runCleanups([() => outerUnsubscribe?.(), () => innerUnsubscribe?.()]);
217
225
  }
218
226
  };
219
227
  //#endregion
220
- export { BaseSubject, BaseSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject, WritableSubscribable, notifySubscribers };
228
+ export { BaseSubject, BaseSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject, WritableSubscribable, notifySubscribers, runCleanups };
221
229
 
222
230
  //# sourceMappingURL=subscribable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscribable.js","names":["shallowEqual","Unsubscribe","notifyEventListeners","SKIP_UPDATE","Symbol","Subscribable","subscribe","callback","SubscribableWithState","path","TPath","getState","TState","NestedSubscribable","EventSubscribable","event","TEvent","binding","unstable_on","payload","notifySubscribers","subscribers","Iterable","args","TArgs","errors","error","push","length","console","AggregateError","shallowEqualOrUndefined","a","T","b","undefined","BaseSubscribable","_subscribers","Set","add","delete","waitForUpdate","Promise","resolve","unsubscribe","_notifySubscribers","WritableSubscribable","_state","constructor","state","bind","getServerSnapshot","setState","Object","is","BaseSubject","_subscriptions","_connection","isConnected","_connect","errorContext","_updateConnection","size","ShallowMemoizeSubject","Error","_previousState","_syncState","LazyMemoizeSubject","_previousStateDirty","newState","NestedSubscriptionSubject","outerSubscribe","lastState","innerUnsubscribe","onRuntimeUpdate","outerUnsubscribe","EventSubscriptionSubject","config"],"sources":["../../src/subscribable/subscribable.ts"],"sourcesContent":["import { shallowEqual } from \"@assistant-ui/store/client\";\nimport type { Unsubscribe } from \"../types/unsubscribe\";\nimport { notifyEventListeners } from \"../utils/notify-event-listeners\";\n\nexport const SKIP_UPDATE = Symbol(\"skip-update\");\nexport type SKIP_UPDATE = typeof SKIP_UPDATE;\n\nexport type Subscribable = {\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport type SubscribableWithState<TState, TPath> = Subscribable & {\n path: TPath;\n getState: () => TState;\n};\n\nexport type NestedSubscribable<\n TState extends Subscribable | undefined,\n TPath,\n> = SubscribableWithState<TState, TPath>;\n\nexport type EventSubscribable<TEvent extends string> = {\n event: TEvent;\n binding: SubscribableWithState<\n | {\n unstable_on: (\n event: TEvent,\n callback: (payload?: unknown) => void,\n ) => Unsubscribe;\n }\n | undefined,\n unknown\n >;\n};\n\nexport const notifySubscribers = <TArgs extends unknown[]>(\n subscribers: Iterable<(...args: TArgs) => void>,\n ...args: TArgs\n): void => {\n const errors: unknown[] = [];\n for (const callback of subscribers) {\n try {\n callback(...args);\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length === 1) {\n throw errors[0];\n }\n\n if (errors.length > 1) {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(errors);\n }\n};\n\nconst shallowEqualOrUndefined = <T extends object>(\n a: T | undefined,\n b: T | undefined,\n) => (a === undefined || b === undefined ? a === b : shallowEqual(a, b));\n\nexport class BaseSubscribable {\n private _subscribers = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscribers.add(callback);\n return () => this._subscribers.delete(callback);\n }\n\n public waitForUpdate() {\n return new Promise<void>((resolve) => {\n const unsubscribe = this.subscribe(() => {\n unsubscribe();\n resolve();\n });\n });\n }\n\n protected _notifySubscribers() {\n notifySubscribers(this._subscribers);\n }\n}\n\nexport class WritableSubscribable<TState> extends BaseSubscribable {\n private _state: TState;\n\n constructor(state: TState) {\n super();\n this._state = state;\n this.subscribe = this.subscribe.bind(this);\n this.getState = this.getState.bind(this);\n // Hydration has to agree with what the server rendered, so the server\n // snapshot stays at the creation-time state rather than following writes.\n this.getServerSnapshot = () => state;\n }\n\n public getState(): TState {\n return this._state;\n }\n\n public getServerSnapshot: () => TState;\n\n public setState(state: TState): void {\n if (Object.is(state, this._state)) return;\n this._state = state;\n this._notifySubscribers();\n }\n}\n\n// lazy connect/disconnect: only opens upstream subscription while it has subscribers\nexport abstract class BaseSubject {\n private _subscriptions = new Set<(payload?: unknown) => void>();\n private _connection: Unsubscribe | undefined;\n\n protected get isConnected() {\n return !!this._connection;\n }\n\n protected abstract _connect(): Unsubscribe;\n\n protected notifySubscribers(payload?: unknown, errorContext?: string) {\n if (errorContext) {\n notifyEventListeners(this._subscriptions, payload, errorContext);\n return;\n }\n\n notifySubscribers(this._subscriptions, payload);\n }\n\n private _updateConnection() {\n if (this._subscriptions.size > 0) {\n if (this._connection) return;\n this._connection = this._connect();\n } else {\n this._connection?.();\n this._connection = undefined;\n }\n }\n\n public subscribe(callback: (payload?: unknown) => void) {\n this._subscriptions.add(callback);\n this._updateConnection();\n\n return () => {\n this._subscriptions.delete(callback);\n this._updateConnection();\n };\n }\n}\n\nexport class ShallowMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>;\n\n constructor(binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>) {\n super();\n this.binding = binding;\n const state = binding.getState();\n if (state === SKIP_UPDATE)\n throw new Error(\"Entry not available in the store\");\n this._previousState = state;\n }\n\n private _previousState: TState;\n public getState = () => {\n if (!this.isConnected) this._syncState();\n return this._previousState;\n };\n\n private _syncState() {\n const state = this.binding.getState();\n if (state === SKIP_UPDATE) return false;\n if (shallowEqualOrUndefined(state, this._previousState)) return false;\n this._previousState = state;\n return true;\n }\n\n protected _connect() {\n const callback = () => {\n if (this._syncState()) {\n this.notifySubscribers();\n }\n };\n\n const unsubscribe = this.binding.subscribe(callback);\n this._syncState();\n return unsubscribe;\n }\n}\n\nexport class LazyMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>;\n\n constructor(binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>) {\n super();\n this.binding = binding;\n }\n\n private _previousStateDirty = true;\n private _previousState: TState | undefined;\n public getState = () => {\n if (!this.isConnected || this._previousStateDirty) {\n const newState = this.binding.getState();\n if (\n newState !== SKIP_UPDATE &&\n (this._previousState === undefined ||\n !shallowEqualOrUndefined(newState, this._previousState))\n ) {\n this._previousState = newState;\n }\n this._previousStateDirty = false;\n }\n if (this._previousState === undefined)\n throw new Error(\"Entry not available in the store\");\n return this._previousState;\n };\n\n protected _connect() {\n const callback = () => {\n this._previousStateDirty = true;\n this.notifySubscribers();\n };\n\n const unsubscribe = this.binding.subscribe(callback);\n this._previousStateDirty = true;\n return unsubscribe;\n }\n}\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n>\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: NestedSubscribable<TState, TPath>;\n\n constructor(binding: NestedSubscribable<TState, TPath>) {\n super();\n this.binding = binding;\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.subscribe(callback);\n\n callback();\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n\nexport class EventSubscriptionSubject<\n TEvent extends string,\n> extends BaseSubject {\n private config: EventSubscribable<TEvent>;\n\n constructor(config: EventSubscribable<TEvent>) {\n super();\n this.config = config;\n }\n\n public getState() {\n return this.config.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.config.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const errorContext = `Runtime event \"${this.config.event}\"`;\n const callback = (payload?: unknown) => {\n this.notifySubscribers(payload, errorContext);\n };\n\n let lastState = this.config.binding.getState();\n let innerUnsubscribe = lastState?.unstable_on(this.config.event, callback);\n const onRuntimeUpdate = () => {\n const newState = this.config.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.unstable_on(this.config.event, callback);\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n"],"mappings":";;;AAIA,MAAaG,cAAcC,OAAO,aAAa;AA+B/C,MAAagB,qBACXC,aACA,GAAGE,SACM;CACT,MAAME,SAAoB,CAAA;CAC1B,KAAK,MAAMlB,YAAYc,aACrB,IAAI;EACFd,SAAS,GAAGgB,IAAI;CAClB,SAASG,OAAO;EACdD,OAAOE,KAAKD,KAAK;CACnB;CAGF,IAAID,OAAOG,WAAW,GACpB,MAAMH,OAAO;CAGf,IAAIA,OAAOG,SAAS,GAAG;EACrB,KAAK,MAAMF,SAASD,QAClBI,QAAQH,MAAMA,KAAK;EAErB,MAAM,IAAII,eAAeL,MAAM;CACjC;AACF;AAEA,MAAMM,2BACJC,GACAE,MACIF,MAAMG,KAAAA,KAAaD,MAAMC,KAAAA,IAAYH,MAAME,IAAIlC,aAAagC,GAAGE,CAAC;AAEtE,IAAaE,mBAAb,MAA8B;CAC5B,+BAAuB,IAAIE,IAAgB;CAE3C,UAAiB/B,UAAmC;EAClD,KAAK8B,aAAaE,IAAIhC,QAAQ;EAC9B,aAAa,KAAK8B,aAAaG,OAAOjC,QAAQ;CAChD;CAEA,gBAAuB;EACrB,OA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B;GACtC,KAAKC,kBAAkBD,SAASyC,YAAY;EAC9C;EAEA,IAAIY,YAAY,KAAKK,OAAO5D,QAAQN,SAAS;EAC7C,IAAI8D,mBAAmBD,WAAWtD,YAAY,KAAK2D,OAAO9D,OAAOR,QAAQ;EACzE,MAAMmE,wBAAwB;GAC5B,MAAML,WAAW,KAAKQ,OAAO5D,QAAQN,SAAS;GAC9C,IAAI0D,aAAaG,WAAW;GAC5BA,YAAYH;GAEZI,mBAAmB;GACnBA,mBAAmBJ,UAAUnD,YAAY,KAAK2D,OAAO9D,OAAOR,QAAQ;EACtE;EAEA,MAAMoE,mBAAmB,KAAKJ,eAAeG,eAAe;EAC5D,aAAa;GACXC,mBAAmB;GACnBF,mBAAmB;EACrB;CACF;AACF"}
1
+ {"version":3,"file":"subscribable.js","names":["shallowEqual","Unsubscribe","notifyEventListeners","SKIP_UPDATE","Symbol","Subscribable","subscribe","callback","SubscribableWithState","path","TPath","getState","TState","NestedSubscribable","EventSubscribable","event","TEvent","binding","unstable_on","payload","notifySubscribers","subscribers","Iterable","args","TArgs","errors","error","push","length","console","AggregateError","runCleanups","cleanups","shallowEqualOrUndefined","a","T","b","undefined","BaseSubscribable","_subscribers","Set","add","delete","waitForUpdate","Promise","resolve","unsubscribe","_notifySubscribers","WritableSubscribable","_state","constructor","state","bind","getServerSnapshot","setState","Object","is","BaseSubject","_subscriptions","_connection","isConnected","_connect","errorContext","_updateConnection","size","connection","ShallowMemoizeSubject","Error","_previousState","_syncState","LazyMemoizeSubject","_previousStateDirty","newState","NestedSubscriptionSubject","outerSubscribe","lastState","innerUnsubscribe","onRuntimeUpdate","previousInner","outerUnsubscribe","EventSubscriptionSubject","config"],"sources":["../../src/subscribable/subscribable.ts"],"sourcesContent":["import { shallowEqual } from \"@assistant-ui/store/client\";\nimport type { Unsubscribe } from \"../types/unsubscribe\";\nimport { notifyEventListeners } from \"../utils/notify-event-listeners\";\n\nexport const SKIP_UPDATE = Symbol(\"skip-update\");\nexport type SKIP_UPDATE = typeof SKIP_UPDATE;\n\nexport type Subscribable = {\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport type SubscribableWithState<TState, TPath> = Subscribable & {\n path: TPath;\n getState: () => TState;\n};\n\nexport type NestedSubscribable<\n TState extends Subscribable | undefined,\n TPath,\n> = SubscribableWithState<TState, TPath>;\n\nexport type EventSubscribable<TEvent extends string> = {\n event: TEvent;\n binding: SubscribableWithState<\n | {\n unstable_on: (\n event: TEvent,\n callback: (payload?: unknown) => void,\n ) => Unsubscribe;\n }\n | undefined,\n unknown\n >;\n};\n\nexport const notifySubscribers = <TArgs extends unknown[]>(\n subscribers: Iterable<(...args: TArgs) => void>,\n ...args: TArgs\n): void => {\n const errors: unknown[] = [];\n for (const callback of subscribers) {\n try {\n callback(...args);\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length === 1) {\n throw errors[0];\n }\n\n if (errors.length > 1) {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(errors);\n }\n};\n\nexport const runCleanups = (cleanups: Iterable<Unsubscribe>): void => {\n notifySubscribers(cleanups);\n};\n\nconst shallowEqualOrUndefined = <T extends object>(\n a: T | undefined,\n b: T | undefined,\n) => (a === undefined || b === undefined ? a === b : shallowEqual(a, b));\n\nexport class BaseSubscribable {\n private _subscribers = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscribers.add(callback);\n return () => this._subscribers.delete(callback);\n }\n\n public waitForUpdate() {\n return new Promise<void>((resolve) => {\n const unsubscribe = this.subscribe(() => {\n unsubscribe();\n resolve();\n });\n });\n }\n\n protected _notifySubscribers() {\n notifySubscribers(this._subscribers);\n }\n}\n\nexport class WritableSubscribable<TState> extends BaseSubscribable {\n private _state: TState;\n\n constructor(state: TState) {\n super();\n this._state = state;\n this.subscribe = this.subscribe.bind(this);\n this.getState = this.getState.bind(this);\n // Hydration has to agree with what the server rendered, so the server\n // snapshot stays at the creation-time state rather than following writes.\n this.getServerSnapshot = () => state;\n }\n\n public getState(): TState {\n return this._state;\n }\n\n public getServerSnapshot: () => TState;\n\n public setState(state: TState): void {\n if (Object.is(state, this._state)) return;\n this._state = state;\n this._notifySubscribers();\n }\n}\n\n// lazy connect/disconnect: only opens upstream subscription while it has subscribers\nexport abstract class BaseSubject {\n private _subscriptions = new Set<(payload?: unknown) => void>();\n private _connection: Unsubscribe | undefined;\n\n protected get isConnected() {\n return !!this._connection;\n }\n\n protected abstract _connect(): Unsubscribe;\n\n protected notifySubscribers(payload?: unknown, errorContext?: string) {\n if (errorContext) {\n notifyEventListeners(this._subscriptions, payload, errorContext);\n return;\n }\n\n notifySubscribers(this._subscriptions, payload);\n }\n\n private _updateConnection() {\n if (this._subscriptions.size > 0) {\n if (this._connection) return;\n this._connection = this._connect();\n } else {\n const connection = this._connection;\n this._connection = undefined;\n connection?.();\n }\n }\n\n public subscribe(callback: (payload?: unknown) => void) {\n this._subscriptions.add(callback);\n this._updateConnection();\n\n return () => {\n this._subscriptions.delete(callback);\n this._updateConnection();\n };\n }\n}\n\nexport class ShallowMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>;\n\n constructor(binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>) {\n super();\n this.binding = binding;\n const state = binding.getState();\n if (state === SKIP_UPDATE)\n throw new Error(\"Entry not available in the store\");\n this._previousState = state;\n }\n\n private _previousState: TState;\n public getState = () => {\n if (!this.isConnected) this._syncState();\n return this._previousState;\n };\n\n private _syncState() {\n const state = this.binding.getState();\n if (state === SKIP_UPDATE) return false;\n if (shallowEqualOrUndefined(state, this._previousState)) return false;\n this._previousState = state;\n return true;\n }\n\n protected _connect() {\n const callback = () => {\n if (this._syncState()) {\n this.notifySubscribers();\n }\n };\n\n const unsubscribe = this.binding.subscribe(callback);\n this._syncState();\n return unsubscribe;\n }\n}\n\nexport class LazyMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>;\n\n constructor(binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>) {\n super();\n this.binding = binding;\n }\n\n private _previousStateDirty = true;\n private _previousState: TState | undefined;\n public getState = () => {\n if (!this.isConnected || this._previousStateDirty) {\n const newState = this.binding.getState();\n if (\n newState !== SKIP_UPDATE &&\n (this._previousState === undefined ||\n !shallowEqualOrUndefined(newState, this._previousState))\n ) {\n this._previousState = newState;\n }\n this._previousStateDirty = false;\n }\n if (this._previousState === undefined)\n throw new Error(\"Entry not available in the store\");\n return this._previousState;\n };\n\n protected _connect() {\n const callback = () => {\n this._previousStateDirty = true;\n this.notifySubscribers();\n };\n\n const unsubscribe = this.binding.subscribe(callback);\n this._previousStateDirty = true;\n return unsubscribe;\n }\n}\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n>\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n private binding: NestedSubscribable<TState, TPath>;\n\n constructor(binding: NestedSubscribable<TState, TPath>) {\n super();\n this.binding = binding;\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n const previousInner = innerUnsubscribe;\n innerUnsubscribe = undefined;\n try {\n previousInner?.();\n } finally {\n innerUnsubscribe = newState?.subscribe(callback);\n callback();\n }\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () =>\n runCleanups([() => outerUnsubscribe?.(), () => innerUnsubscribe?.()]);\n }\n}\n\nexport class EventSubscriptionSubject<\n TEvent extends string,\n> extends BaseSubject {\n private config: EventSubscribable<TEvent>;\n\n constructor(config: EventSubscribable<TEvent>) {\n super();\n this.config = config;\n }\n\n public getState() {\n return this.config.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.config.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const errorContext = `Runtime event \"${this.config.event}\"`;\n const callback = (payload?: unknown) => {\n this.notifySubscribers(payload, errorContext);\n };\n\n let lastState = this.config.binding.getState();\n let innerUnsubscribe = lastState?.unstable_on(this.config.event, callback);\n const onRuntimeUpdate = () => {\n const newState = this.config.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n const previousInner = innerUnsubscribe;\n innerUnsubscribe = undefined;\n try {\n previousInner?.();\n } finally {\n innerUnsubscribe = newState?.unstable_on(this.config.event, callback);\n }\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () =>\n runCleanups([() => outerUnsubscribe?.(), () => innerUnsubscribe?.()]);\n }\n}\n"],"mappings":";;;AAIA,MAAaG,cAAcC,OAAO,aAAa;AA+B/C,MAAagB,qBACXC,aACA,GAAGE,SACM;CACT,MAAME,SAAoB,CAAA;CAC1B,KAAK,MAAMlB,YAAYc,aACrB,IAAI;EACFd,SAAS,GAAGgB,IAAI;CAClB,SAASG,OAAO;EACdD,OAAOE,KAAKD,KAAK;CACnB;CAGF,IAAID,OAAOG,WAAW,GACpB,MAAMH,OAAO;CAGf,IAAIA,OAAOG,SAAS,GAAG;EACrB,KAAK,MAAMF,SAASD,QAClBI,QAAQH,MAAMA,KAAK;EAErB,MAAM,IAAII,eAAeL,MAAM;CACjC;AACF;AAEA,MAAaM,eAAeC,aAA0C;CACpEZ,kBAAkBY,QAAQ;AAC5B;AAEA,MAAMC,2BACJC,GACAE,MACIF,MAAMG,KAAAA,KAAaD,MAAMC,KAAAA,IAAYH,MAAME,IAAIpC,aAAak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aI,2BAAb,cAEUvB,YAAY;CACpB;CAEAP,YAAY+B,QAAmC;EAC7C,MAAM;EACN,KAAKA,SAASA;CAChB;CAEA,WAAkB;EAChB,OAAO,KAAKA,OAAOhE,QAAQN,SAAS;CACtC;CAEA,eAAsBJ,UAAsB;EAC1C,OAAO,KAAK0E,OAAOhE,QAAQX,UAAUC,QAAQ;CAC/C;CAEA,WAAkC;EAChC,MAAMuD,eAAe,kBAAkB,KAAKmB,OAAOlE,MAAK;EACxD,MAAMR,YAAYY,YAAsB;GACtC,KAAKC,kBAAkBD,SAAS2C,YAAY;EAC9C;EAEA,IAAIa,YAAY,KAAKM,OAAOhE,QAAQN,SAAS;EAC7C,IAAIiE,mBAAmBD,WAAWzD,YAAY,KAAK+D,OAAOlE,OAAOR,QAAQ;EACzE,MAAMsE,wBAAwB;GAC5B,MAAML,WAAW,KAAKS,OAAOhE,QAAQN,SAAS;GAC9C,IAAI6D,aAAaG,WAAW;GAC5BA,YAAYH;GAEZ,MAAMM,gBAAgBF;GACtBA,mBAAmBvC,KAAAA;GACnB,IAAI;IACFyC,gBAAgB;GAClB,UAAU;IACRF,mBAAmBJ,UAAUtD,YAAY,KAAK+D,OAAOlE,OAAOR,QAAQ;GACtE;EACF;EAEA,MAAMwE,mBAAmB,KAAKL,eAAeG,eAAe;EAC5D,aACE9C,YAAY,OAAOgD,mBAAmB,SAASH,mBAAmB,CAAC,CAAC;CACxE;AACF"}
@@ -1,7 +1,7 @@
1
- import { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolCallMessagePart, ToolCallMessagePartStatus, ToolModelContentPart, Unstable_AudioMessagePart } from "./message.js";
1
+ import { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MessageModality, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolCallMessagePart, ToolCallMessagePartStatus, ToolModelContentPart, Unstable_AudioMessagePart } from "./message.js";
2
2
  import { Attachment, AttachmentStatus, CompleteAttachment, CreateAttachment, PendingAttachment } from "./attachment.js";
3
3
  import { Unstable_TriggerCategory, Unstable_TriggerItem } from "./trigger.js";
4
4
  import { Unstable_DirectiveFormatter, Unstable_DirectiveSegment } from "./directive.js";
5
5
  import { Unsubscribe } from "./unsubscribe.js";
6
6
  import { QuoteInfo } from "./quote.js";
7
- export type { AppendMessage, Attachment, AttachmentStatus, CompleteAttachment, CreateAttachment, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, PendingAttachment, QuoteInfo, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolCallMessagePart, ToolCallMessagePartStatus, ToolModelContentPart, Unstable_AudioMessagePart, Unstable_DirectiveFormatter, Unstable_DirectiveSegment, Unstable_TriggerCategory, Unstable_TriggerItem, Unsubscribe };
7
+ export type { AppendMessage, Attachment, AttachmentStatus, CompleteAttachment, CreateAttachment, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MessageModality, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, PendingAttachment, QuoteInfo, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolCallMessagePart, ToolCallMessagePartStatus, ToolModelContentPart, Unstable_AudioMessagePart, Unstable_DirectiveFormatter, Unstable_DirectiveSegment, Unstable_TriggerCategory, Unstable_TriggerItem, Unsubscribe };
@@ -309,6 +309,7 @@ type MessageTiming = {
309
309
  readonly totalChunks: number;
310
310
  readonly toolCallCount: number;
311
311
  };
312
+ type MessageModality = "voice";
312
313
  type ThreadStep = {
313
314
  readonly messageId?: string;
314
315
  readonly usage?: {
@@ -330,6 +331,7 @@ type ThreadSystemMessage = MessageCommonProps & {
330
331
  readonly steps?: undefined;
331
332
  readonly submittedFeedback?: undefined;
332
333
  readonly timing?: undefined;
334
+ readonly modality?: undefined;
333
335
  readonly custom: Record<string, unknown>;
334
336
  };
335
337
  };
@@ -345,6 +347,8 @@ type ThreadUserMessage = MessageCommonProps & {
345
347
  readonly submittedFeedback?: undefined;
346
348
  readonly timing?: undefined;
347
349
  readonly isOptimistic?: boolean;
350
+ /** Set when the message was produced by a voice session rather than typed. */
351
+ readonly modality?: MessageModality;
348
352
  readonly custom: Record<string, unknown>;
349
353
  };
350
354
  };
@@ -366,6 +370,8 @@ type ThreadAssistantMessage = MessageCommonProps & {
366
370
  * once off the head branch and are never persisted.
367
371
  */
368
372
  readonly isOptimistic?: boolean;
373
+ /** Set when the message was produced by a voice session rather than typed. */
374
+ readonly modality?: MessageModality;
369
375
  readonly custom: Record<string, unknown>;
370
376
  };
371
377
  };
@@ -381,6 +387,7 @@ type BaseThreadMessage = {
381
387
  };
382
388
  readonly timing?: MessageTiming;
383
389
  readonly isOptimistic?: boolean;
390
+ readonly modality?: MessageModality;
384
391
  readonly custom: Record<string, unknown>;
385
392
  };
386
393
  readonly attachments?: ThreadUserMessage["attachments"];
@@ -400,5 +407,5 @@ type AppendMessage = Omit<ThreadMessage, "id"> & {
400
407
  steer?: boolean | undefined;
401
408
  };
402
409
  //#endregion
403
- export { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MCP_APP_URI_SCHEME, McpAppMetadata, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalDisplay, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartMcpMetadata, ToolCallMessagePartStatus, type ToolCallTiming, type ToolModelContentPart, Unstable_AudioMessagePart, isMcpAppUri, toolApprovalAcceptsText };
410
+ export { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MCP_APP_URI_SCHEME, McpAppMetadata, MessageModality, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalDisplay, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartMcpMetadata, ToolCallMessagePartStatus, type ToolCallTiming, type ToolModelContentPart, Unstable_AudioMessagePart, isMcpAppUri, toolApprovalAcceptsText };
404
411
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC;WACD;WACA;WACA,SAAS;WACT;WACA,mBAAmB;WACnB;;KAGC,yBAAyB;KAEzB;WAEG;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;WAGA;WACA;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;KAGH;WACD;WACA;WACA;WACA,mBAAmB;;KAGlB;WACD;WACA;WACA;WACA;;WAEA;WACA,mBAAmB;WACnB;;;;;;;;;;;KAYC;WACD;WACA;aACE;aACA;;;KAID,gBAAgB;WACjB;WACA;WACA,MAAM;;;;;;;;;;;KAYL;;WAIG;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;;;;KAMH;;WAED,MAAM,4BAA4B;;;;;;;;;;KAWjC;WACD;;WAEA,MAAM;;WAEN;WACA;;KAGC;WACD;WACA;WACA;;WAEA;;cAGE;cAEA,cAAe;KAGhB;WACD,MAAM;;KAGL;KAMA;;WAED;;;;;;;WAOA,MAAM;;WAEN;WACA;;WAEA;;WAEA;IAAsB;IAAgB;;;;;;;;;;;;;KAarC;;;;;;cAOC,0BAA2B;WAC7B,UAAU;WACV;;KAGC;WAEG;WACA;WACA;;WAGA;WACA;WACA;;WAGA;WACA;WACA;WACA;;;WAIA;WACA;;KAGH,oBACV,QAAQ,oBACR;;WAGS;;WAEA;;WAEA;;;;;;WAMA,MAAM;;WAEN,SAAS;;WAET;;WAEA;;WAEA;;WAEA,SAAS;;WAET,MAAM;;WAEN,mBAAmB;;WAEnB,wBAAwB;;WAExB;IAAc;IAAe;;;WAE7B;aACE;;;;;;aAMA;;aAEA,UAAU;;aAEV;aACA;aACA;aACA;;aAEA,mBAAmB;;aAEnB;;aAEA;;aAEA;;;WAGF;;;;;WAKA,oBAAoB;;KAGnB,wBACR,kBACA,mBACA,kBACA,kBACA;KAEQ,6BACR,kBACA,uBACA,sBACA,oBACA,kBACA,mBACA,kBACA;KAEQ;WAEG;;WAGA;;WAGA;WACA;WAMA;;KAGH;WAEG;;WAGA;;WAGA;WACA;;KAQH;;WAGG;;WAEA;;WAGA;WACA;WACA,QAAQ;IAEnB;KAEQ;WAEG;;WAGA;WACA;;WAGA;WACA;;WAGA;WACA;WAOA,QAAQ;;KAGX;WACD;WACA;WACA;WACA;WACA;WACA;WACA;;KAGC;WACD;WACA;aAEM;aACA;;;KAKZ;WACM;WACA,WAAW;;KAGV,sBAAsB;WACvB;WACA,mBAAmB;WACnB;aACE;aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,oBAAoB;WACrB;WACA,kBAAkB;WAClB,sBAAsB;WACtB;aACE;aACA;aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,yBAAyB;WAC1B;WACA,kBAAkB;WAClB,QAAQ;WACR;aACE,gBAAgB;aAChB,+BAA+B;aAC/B,wBAAwB;aACxB,gBAAgB;aAChB;eAA+B;;aAC/B,SAAS;;;;;aAKT;aACA,QAAQ;;;KAIhB;WACM,SAAS;WACT;aACE,iBAAiB;aACjB,gCAAgC;aAChC,yBAAyB;aACzB,iBAAiB;aACjB;eAA+B;;aAC/B,SAAS;aACT;aACA,QAAQ;;WAEV,cAAc;;KAGb,gBAAgB,qBACzB,sBAAsB,oBAAoB;KAEjC,cAAc;KAEd;WACD,SAAS;;KAGR,gBAAgB,KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
1
+ {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC;WACD;WACA;WACA,SAAS;WACT;WACA,mBAAmB;WACnB;;KAGC,yBAAyB;KAEzB;WAEG;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;WAGA;WACA;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;KAG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M;aACA;;;KAKZ;WACM;WACA,WAAW;;KAGV,sBAAsB;WACvB;WACA,mBAAmB;WACnB;aACE;aACA;aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,oBAAoB;WACrB;WACA,kBAAkB;WAClB,sBAAsB;WACtB;aACE;aACA;aACA;aACA;aACA;aACA;aACA;;aAEA,WAAW;aACX,QAAQ;;;KAIT,yBAAyB;WAC1B;WACA,kBAAkB;WAClB,QAAQ;WACR;aACE,gBAAgB;aAChB,+BAA+B;aAC/B,wBAAwB;aACxB,gBAAgB;aAChB;eAA+B;;aAC/B,SAAS;;;;;aAKT;;aAEA,WAAW;aACX,QAAQ;;;KAIhB;WACM,SAAS;WACT;aACE,iBAAiB;aACjB,gCAAgC;aAChC,yBAAyB;aACzB,iBAAiB;aACjB;eAA+B;;aAC/B,SAAS;aACT;aACA,WAAW;aACX,QAAQ;;WAEV,cAAc;;KAGb,gBAAgB,qBACzB,sBAAsB,oBAAoB;KAEjC,cAAc;KAEd;WACD,SAAS;;KAGR,gBAAgB,KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","unstable_summary","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalDisplay","toolApprovalAcceptsText","approval","display","allowFreeform","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","prompt","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly unstable_summary?: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n readonly providerMetadata?: PartProviderMetadata;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). \"url\" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; \"id\" by the LangChain family only. */\n readonly sourceType?: \"url\" | \"id\";\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\n/**\n * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`\n * is the carrier for every non-image binary modality: it is a member of both\n * the user and assistant unions, carries a filename, and can declare how its\n * payload goes on the wire, none of which this shape can express. The payload\n * form a `file` part needs is still adapter specific; see the Part Types\n * section of the message primitive docs. Honored everywhere it is accepted; it\n * will not gain fields.\n */\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved; they must\n * be answered with an explicit `approved` value (optionally alongside the\n * `optionId`), which is what the default kit sends when one is chosen.\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\n/**\n * How an approval request should be presented, and which answers it accepts.\n * Absent: `\"decision\"`.\n *\n * The approval seam carries a host-owned request addressed by its own id and\n * resolved once; a request wanting an answer these modes cannot express stays\n * on the `interrupt` seam, which hands the tool an arbitrary payload instead.\n * Unlike {@link ToolApprovalOptionKind} the set is closed, because a renderer\n * that cannot cover every mode exhaustively is back to guessing the affordance.\n */\nexport type ToolApprovalDisplay = \"decision\" | \"select\" | \"text\";\n\n/**\n * Whether the request asks for a free-form answer, on its own or alongside its\n * options. Renderers read this to decide whether to offer a text affordance,\n * and the runtime reads it to reject a `text` response the host cannot record.\n */\nexport const toolApprovalAcceptsText = (approval: {\n readonly display?: ToolApprovalDisplay;\n readonly allowFreeform?: boolean;\n}): boolean => approval.display === \"text\" || approval.allowFreeform === true;\n\nexport type ToolApprovalResponse =\n | {\n readonly approved: boolean;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n readonly optionId: string;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n /** Answer to a request that asks a question rather than for a decision. */\n readonly text: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n /**\n * The question put to the user. A request that asks for something other\n * than permission carries it here, so a renderer can show the question\n * rather than inferring a decision from the tool name.\n */\n readonly prompt?: string;\n /** How the request should be presented. Absent: a plain decision. */\n readonly display?: ToolApprovalDisplay;\n /** Whether a free-form answer is accepted alongside the options. */\n readonly allowFreeform?: boolean;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** The free-form answer recorded at resolution, when one was given. */\n readonly text?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason: \"tool-calls\";\n readonly error?: ReadonlyJSONValue;\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAsJA,MAAaiD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB;;;;;;AAgDtC,MAAac,2BAA2BC,aAGzBA,SAASC,YAAY,UAAUD,SAASE,kBAAkB"}
1
+ {"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","unstable_summary","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalDisplay","toolApprovalAcceptsText","approval","display","allowFreeform","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","prompt","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","MessageModality","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","modality","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly unstable_summary?: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n readonly providerMetadata?: PartProviderMetadata;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). \"url\" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; \"id\" by the LangChain family only. */\n readonly sourceType?: \"url\" | \"id\";\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\n/**\n * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`\n * is the carrier for every non-image binary modality: it is a member of both\n * the user and assistant unions, carries a filename, and can declare how its\n * payload goes on the wire, none of which this shape can express. The payload\n * form a `file` part needs is still adapter specific; see the Part Types\n * section of the message primitive docs. Honored everywhere it is accepted; it\n * will not gain fields.\n */\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved; they must\n * be answered with an explicit `approved` value (optionally alongside the\n * `optionId`), which is what the default kit sends when one is chosen.\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\n/**\n * How an approval request should be presented, and which answers it accepts.\n * Absent: `\"decision\"`.\n *\n * The approval seam carries a host-owned request addressed by its own id and\n * resolved once; a request wanting an answer these modes cannot express stays\n * on the `interrupt` seam, which hands the tool an arbitrary payload instead.\n * Unlike {@link ToolApprovalOptionKind} the set is closed, because a renderer\n * that cannot cover every mode exhaustively is back to guessing the affordance.\n */\nexport type ToolApprovalDisplay = \"decision\" | \"select\" | \"text\";\n\n/**\n * Whether the request asks for a free-form answer, on its own or alongside its\n * options. Renderers read this to decide whether to offer a text affordance,\n * and the runtime reads it to reject a `text` response the host cannot record.\n */\nexport const toolApprovalAcceptsText = (approval: {\n readonly display?: ToolApprovalDisplay;\n readonly allowFreeform?: boolean;\n}): boolean => approval.display === \"text\" || approval.allowFreeform === true;\n\nexport type ToolApprovalResponse =\n | {\n readonly approved: boolean;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n readonly optionId: string;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly text?: string;\n readonly reason?: string;\n }\n | {\n /** Answer to a request that asks a question rather than for a decision. */\n readonly text: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n /**\n * The question put to the user. A request that asks for something other\n * than permission carries it here, so a renderer can show the question\n * rather than inferring a decision from the tool name.\n */\n readonly prompt?: string;\n /** How the request should be presented. Absent: a plain decision. */\n readonly display?: ToolApprovalDisplay;\n /** Whether a free-form answer is accepted alongside the options. */\n readonly allowFreeform?: boolean;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** The free-form answer recorded at resolution, when one was given. */\n readonly text?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason: \"tool-calls\";\n readonly error?: ReadonlyJSONValue;\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type MessageModality = \"voice\";\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly modality?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n /** Set when the message was produced by a voice session rather than typed. */\n readonly modality?: MessageModality;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n /** Set when the message was produced by a voice session rather than typed. */\n readonly modality?: MessageModality;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly modality?: MessageModality;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAsJA,MAAaiD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB;;;;;;AAgDtC,MAAac,2BAA2BC,aAGzBA,SAASC,YAAY,UAAUD,SAASE,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"abortable-iterable.d.ts","names":[],"sources":["../../src/utils/abortable-iterable.ts"],"mappings":";cASa,wBAA+B,GAC1C,QAAQ,cAAc,KAAK,QAAQ,cAAc,KACjD,QAAQ,gBACP,QAAQ,cAAc;;;;;;;;;;;;;;cAwBZ,oBAAqB,GAChC,QAAQ,cAAc,IACtB,QAAQ,gBACP,cAAc"}
1
+ {"version":3,"file":"abortable-iterable.d.ts","names":[],"sources":["../../src/utils/abortable-iterable.ts"],"mappings":";cAEa,wBAA+B,GAC1C,QAAQ,cAAc,KAAK,QAAQ,cAAc,KACjD,QAAQ,gBACP,QAAQ,cAAc;;;;;;;;;;;;;;cAmCZ,oBAAqB,GAChC,QAAQ,cAAc,IACtB,QAAQ,gBACP,cAAc"}
@@ -3,16 +3,22 @@ const done = () => ({
3
3
  done: true,
4
4
  value: void 0
5
5
  });
6
- /** Resolves at cancellation, so an await on a stream can stop being the only way out. */
7
- const whenAborted = (signal) => new Promise((resolve) => {
8
- if (signal.aborted) return resolve(void 0);
9
- signal.addEventListener("abort", () => resolve(void 0), { once: true });
10
- });
11
6
  const openAbortableIterable = async (source, signal) => {
12
7
  const opened = Promise.resolve(source);
13
- const iterable = await Promise.race([opened, whenAborted(signal)]);
14
- if (!iterable) opened.then((late) => late[Symbol.asyncIterator]().return?.(void 0)).catch(() => {});
15
- return iterable;
8
+ let release = () => {};
9
+ const aborted = new Promise((resolve) => {
10
+ const onAbort = () => resolve(void 0);
11
+ if (signal.aborted) return onAbort();
12
+ signal.addEventListener("abort", onAbort, { once: true });
13
+ release = () => signal.removeEventListener("abort", onAbort);
14
+ });
15
+ try {
16
+ const iterable = await Promise.race([opened, aborted]);
17
+ if (!iterable) opened.then((late) => late[Symbol.asyncIterator]().return?.(void 0)).catch(() => {});
18
+ return iterable;
19
+ } finally {
20
+ release();
21
+ }
16
22
  };
17
23
  /**
18
24
  * Presents a stream as exhausted once the signal aborts, so a consumer stops
@@ -29,7 +35,10 @@ const openAbortableIterable = async (source, signal) => {
29
35
  */
30
36
  const abortableIterable = (source, signal) => ({ [Symbol.asyncIterator]: () => {
31
37
  const iterator = source[Symbol.asyncIterator]();
38
+ let finished = false;
32
39
  const finalize = () => {
40
+ if (finished) return;
41
+ finished = true;
33
42
  try {
34
43
  iterator.return?.(void 0)?.catch(() => {});
35
44
  } catch {}
@@ -39,7 +48,7 @@ const abortableIterable = (source, signal) => ({ [Symbol.asyncIterator]: () => {
39
48
  return this;
40
49
  },
41
50
  next: () => {
42
- if (signal.aborted) {
51
+ if (finished || signal.aborted) {
43
52
  finalize();
44
53
  return Promise.resolve(done());
45
54
  }
@@ -50,14 +59,21 @@ const abortableIterable = (source, signal) => ({ [Symbol.asyncIterator]: () => {
50
59
  };
51
60
  signal.addEventListener("abort", onAbort, { once: true });
52
61
  const release = () => signal.removeEventListener("abort", onAbort);
53
- iterator.next().then((result) => {
54
- release();
55
- resolve(result);
56
- }, (error) => {
62
+ const onError = (error) => {
57
63
  release();
58
64
  finalize();
59
65
  reject(error);
60
- });
66
+ };
67
+ try {
68
+ iterator.next().then((result) => {
69
+ release();
70
+ if (finished) return resolve(done());
71
+ if (result.done) finished = true;
72
+ resolve(result);
73
+ }, onError);
74
+ } catch (error) {
75
+ onError(error);
76
+ }
61
77
  });
62
78
  },
63
79
  return: async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"abortable-iterable.js","names":["done","IteratorResult","T","value","undefined","whenAborted","signal","AbortSignal","Promise","resolve","aborted","addEventListener","once","openAbortableIterable","source","AsyncIterable","opened","iterable","race","then","late","Symbol","asyncIterator","return","catch","abortableIterable","iterator","finalize","next","reject","onAbort","release","removeEventListener","result","error"],"sources":["../../src/utils/abortable-iterable.ts"],"sourcesContent":["const done = <T>(): IteratorResult<T> => ({ done: true, value: undefined });\n\n/** Resolves at cancellation, so an await on a stream can stop being the only way out. */\nconst whenAborted = (signal: AbortSignal): Promise<undefined> =>\n new Promise((resolve) => {\n if (signal.aborted) return resolve(undefined);\n signal.addEventListener(\"abort\", () => resolve(undefined), { once: true });\n });\n\nexport const openAbortableIterable = async <T>(\n source: AsyncIterable<T> | Promise<AsyncIterable<T>>,\n signal: AbortSignal,\n): Promise<AsyncIterable<T> | undefined> => {\n const opened = Promise.resolve(source);\n const iterable = await Promise.race([opened, whenAborted(signal)]);\n if (!iterable) {\n void opened\n .then((late) => late[Symbol.asyncIterator]().return?.(undefined))\n .catch(() => {});\n }\n return iterable;\n};\n\n/**\n * Presents a stream as exhausted once the signal aborts, so a consumer stops\n * waiting on it.\n *\n * A caller's stream is free to ignore the abort signal it is handed. One that\n * also stops yielding, because it is awaiting its own work, leaves `for await`\n * parked on `next()` with nothing left to wake it: the run never settles and\n * whatever is serialized behind it never starts. Reporting the stream as\n * exhausted ends the loop at cancellation instead.\n *\n * The source is finalized on the way out, but never awaited, since a stream\n * that is already parked would not settle that either.\n */\nexport const abortableIterable = <T>(\n source: AsyncIterable<T>,\n signal: AbortSignal,\n): AsyncIterable<T> => ({\n [Symbol.asyncIterator]: () => {\n const iterator = source[Symbol.asyncIterator]();\n const finalize = () => {\n try {\n iterator.return?.(undefined)?.catch(() => {});\n } catch {\n // a source that throws on finalize has nothing left to clean up\n }\n };\n\n return {\n [Symbol.asyncIterator]() {\n return this;\n },\n next: () => {\n if (signal.aborted) {\n finalize();\n return Promise.resolve(done<T>());\n }\n\n return new Promise<IteratorResult<T>>((resolve, reject) => {\n // Registered per chunk and released as soon as the chunk settles, so\n // a long stream does not accumulate one reaction per chunk.\n const onAbort = () => {\n finalize();\n resolve(done<T>());\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n const release = () => signal.removeEventListener(\"abort\", onAbort);\n\n iterator.next().then(\n (result) => {\n release();\n resolve(result);\n },\n (error: unknown) => {\n release();\n finalize();\n reject(error);\n },\n );\n });\n },\n // The consumer breaks out of the loop to stop a cancelled run, so this is\n // reached on the same path as an abort and finalizes the same way: a\n // source whose own cleanup parks must not stall the break either.\n return: async () => {\n finalize();\n return done<T>();\n },\n };\n },\n});\n"],"mappings":";AAAA,MAAMA,cAAoC;CAAEA,MAAM;CAAMG,OAAOC,KAAAA;AAAU;;AAGzE,MAAMC,eAAeC,WACnB,IAAIE,SAASC,YAAY;CACvB,IAAIH,OAAOI,SAAS,OAAOD,QAAQL,KAAAA,CAAS;CAC5CE,OAAOK,iBAAiB,eAAeF,QAAQL,KAAAA,CAAS,GAAG,EAAEQ,MAAM,KAAK,CAAC;AAC3E,CAAC;AAEH,MAAaC,wBAAwB,OACnCC,QACAR,WAC0C;CAC1C,MAAMU,SAASR,QAAQC,QAAQK,MAAM;CACrC,MAAMG,WAAW,MAAMT,QAAQU,KAAK,CAACF,QAAQX,YAAYC,MAAM,CAAC,CAAC;CACjE,IAAI,CAACW,UACH,OACGE,MAAMC,SAASA,KAAKC,OAAOC,cAAc,CAAC,CAAC,CAACC,SAASnB,KAAAA,CAAS,CAAC,CAAC,CAChEoB,YAAY,CAAC,CAAC;CAEnB,OAAOP;AACT;;;;;;;;;;;;;;AAeA,MAAaQ,qBACXX,QACAR,YACsB,GACrBe,OAAOC,sBAAsB;CAC5B,MAAMI,WAAWZ,OAAOO,OAAOC,cAAc,CAAC;CAC9C,MAAMK,iBAAiB;EACrB,IAAI;GACFD,SAASH,SAASnB,KAAAA,CAAS,CAAC,EAAEoB,YAAY,CAAC,CAAC;EAC9C,QAAQ,CACN;CAEJ;CAEA,OAAO;EACL,CAACH,OAAOC,iBAAiB;GACvB,OAAO;EACT;EACAM,YAAY;GACV,IAAItB,OAAOI,SAAS;IAClBiB,SAAS;IACT,OAAOnB,QAAQC,QAAQT,KAAQ,CAAC;GAClC;GAEA,OAAO,IAAIQ,SAA4BC,SAASoB,WAAW;IAGzD,MAAMC,gBAAgB;KACpBH,SAAS;KACTlB,QAAQT,KAAQ,CAAC;IACnB;IACAM,OAAOK,iBAAiB,SAASmB,SAAS,EAAElB,MAAM,KAAK,CAAC;IACxD,MAAMmB,gBAAgBzB,OAAO0B,oBAAoB,SAASF,OAAO;IAEjEJ,SAASE,KAAK,CAAC,CAACT,MACbc,WAAW;KACVF,QAAQ;KACRtB,QAAQwB,MAAM;IAChB,IACCC,UAAmB;KAClBH,QAAQ;KACRJ,SAAS;KACTE,OAAOK,KAAK;IACd,CACF;GACF,CAAC;EACH;EAIAX,QAAQ,YAAY;GAClBI,SAAS;GACT,OAAO3B,KAAQ;EACjB;CACF;AACF,EACF"}
1
+ {"version":3,"file":"abortable-iterable.js","names":["done","IteratorResult","T","value","undefined","openAbortableIterable","source","AsyncIterable","Promise","signal","AbortSignal","opened","resolve","release","aborted","onAbort","addEventListener","once","removeEventListener","iterable","race","then","late","Symbol","asyncIterator","return","catch","abortableIterable","iterator","finished","finalize","next","reject","onError","error","result"],"sources":["../../src/utils/abortable-iterable.ts"],"sourcesContent":["const done = <T>(): IteratorResult<T> => ({ done: true, value: undefined });\n\nexport const openAbortableIterable = async <T>(\n source: AsyncIterable<T> | Promise<AsyncIterable<T>>,\n signal: AbortSignal,\n): Promise<AsyncIterable<T> | undefined> => {\n const opened = Promise.resolve(source);\n let release = () => {};\n const aborted = new Promise<undefined>((resolve) => {\n const onAbort = () => resolve(undefined);\n if (signal.aborted) return onAbort();\n signal.addEventListener(\"abort\", onAbort, { once: true });\n release = () => signal.removeEventListener(\"abort\", onAbort);\n });\n try {\n const iterable = await Promise.race([opened, aborted]);\n if (!iterable) {\n void opened\n .then((late) => late[Symbol.asyncIterator]().return?.(undefined))\n .catch(() => {});\n }\n return iterable;\n } finally {\n release();\n }\n};\n\n/**\n * Presents a stream as exhausted once the signal aborts, so a consumer stops\n * waiting on it.\n *\n * A caller's stream is free to ignore the abort signal it is handed. One that\n * also stops yielding, because it is awaiting its own work, leaves `for await`\n * parked on `next()` with nothing left to wake it: the run never settles and\n * whatever is serialized behind it never starts. Reporting the stream as\n * exhausted ends the loop at cancellation instead.\n *\n * The source is finalized on the way out, but never awaited, since a stream\n * that is already parked would not settle that either.\n */\nexport const abortableIterable = <T>(\n source: AsyncIterable<T>,\n signal: AbortSignal,\n): AsyncIterable<T> => ({\n [Symbol.asyncIterator]: () => {\n const iterator = source[Symbol.asyncIterator]();\n let finished = false;\n const finalize = () => {\n if (finished) return;\n finished = true;\n try {\n iterator.return?.(undefined)?.catch(() => {});\n } catch {\n // a source that throws on finalize has nothing left to clean up\n }\n };\n\n return {\n [Symbol.asyncIterator]() {\n return this;\n },\n next: () => {\n if (finished || signal.aborted) {\n finalize();\n return Promise.resolve(done<T>());\n }\n\n return new Promise<IteratorResult<T>>((resolve, reject) => {\n // Registered per chunk and released as soon as the chunk settles, so\n // a long stream does not accumulate one reaction per chunk.\n const onAbort = () => {\n finalize();\n resolve(done<T>());\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n const release = () => signal.removeEventListener(\"abort\", onAbort);\n\n const onError = (error: unknown) => {\n release();\n finalize();\n reject(error);\n };\n try {\n void iterator.next().then((result) => {\n release();\n if (finished) return resolve(done<T>());\n if (result.done) finished = true;\n resolve(result);\n }, onError);\n } catch (error) {\n onError(error);\n }\n });\n },\n // The consumer breaks out of the loop to stop a cancelled run, so this is\n // reached on the same path as an abort and finalizes the same way: a\n // source whose own cleanup parks must not stall the break either.\n return: async () => {\n finalize();\n return done<T>();\n },\n };\n },\n});\n"],"mappings":";AAAA,MAAMA,cAAoC;CAAEA,MAAM;CAAMG,OAAOC,KAAAA;AAAU;AAEzE,MAAaC,wBAAwB,OACnCC,QACAG,WAC0C;CAC1C,MAAME,SAASH,QAAQI,QAAQN,MAAM;CACrC,IAAIO,gBAAgB,CAAC;CACrB,MAAMC,UAAU,IAAIN,SAAoBI,YAAY;EAClD,MAAMG,gBAAgBH,QAAQR,KAAAA,CAAS;EACvC,IAAIK,OAAOK,SAAS,OAAOC,QAAQ;EACnCN,OAAOO,iBAAiB,SAASD,SAAS,EAAEE,MAAM,KAAK,CAAC;EACxDJ,gBAAgBJ,OAAOS,oBAAoB,SAASH,OAAO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AAGF,OAAO;IACZ,SAASC,OAAO;KACdD,QAAQC,KAAK;IACf;GACF,CAAC;EACH;EAIAT,QAAQ,YAAY;GAClBK,SAAS;GACT,OAAO9B,KAAQ;EACjB;CACF;AACF,EACF"}
@@ -3,7 +3,23 @@ import { MessagePartStatus, ToolCallMessagePartStatus } from "../types/message.j
3
3
  type PartWithStatus = {
4
4
  readonly status: MessagePartStatus | ToolCallMessagePartStatus;
5
5
  };
6
- declare const getGroupStatus: (parts: readonly (PartWithStatus | undefined)[], indices?: readonly number[]) => MessagePartStatus | ToolCallMessagePartStatus;
6
+ declare const getGroupStatus: (parts: readonly (PartWithStatus | undefined)[]) => MessagePartStatus | ToolCallMessagePartStatus;
7
+ declare const getGroupSummary: (parts: readonly (PartWithStatus | undefined)[], indices: readonly number[]) => {
8
+ status: MessagePartStatus | {
9
+ readonly type: "requires-action";
10
+ readonly reason: "tool-calls" | "interrupt";
11
+ } | {
12
+ readonly type: "incomplete";
13
+ readonly reason: "tool-calls";
14
+ readonly error?: import("assistant-stream/utils").ReadonlyJSONValue;
15
+ };
16
+ counts: {
17
+ running: number;
18
+ complete: number;
19
+ incomplete: number;
20
+ requiresAction: number;
21
+ };
22
+ };
7
23
  //#endregion
8
- export { getGroupStatus };
24
+ export { getGroupStatus, getGroupSummary };
9
25
  //# sourceMappingURL=getGroupStatus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGroupStatus.d.ts","names":[],"sources":["../../src/utils/getGroupStatus.ts"],"mappings":";;KAMK;WACM,QAAQ,oBAAoB;;cAG1B,iBACX,iBAAiB,+BACjB,gCACC,oBAAoB"}
1
+ {"version":3,"file":"getGroupStatus.d.ts","names":[],"sources":["../../src/utils/getGroupStatus.ts"],"mappings":";;KAMK;WACM,QAAQ,oBAAoB;;cAG1B,iBACX,iBAAiB,kCAChB,oBAAoB;cAQV,kBACX,iBAAiB,+BACjB;UADiB"}
@@ -1,15 +1,40 @@
1
1
  import { COMPLETE_STATUS, RUNNING_STATUS } from "./normalizePartStatus.js";
2
2
  //#region src/utils/getGroupStatus.ts
3
- const getGroupStatus = (parts, indices) => {
4
- if (indices) {
5
- for (const index of indices) if (parts[index]?.status.type === "running") return RUNNING_STATUS;
6
- const lastIndex = indices.at(-1);
7
- return lastIndex === void 0 ? COMPLETE_STATUS : parts[lastIndex]?.status ?? COMPLETE_STATUS;
8
- }
3
+ const getGroupStatus = (parts) => {
9
4
  for (const part of parts) if (part?.status.type === "running") return RUNNING_STATUS;
10
5
  return parts.at(-1)?.status ?? COMPLETE_STATUS;
11
6
  };
7
+ const getGroupSummary = (parts, indices) => {
8
+ const counts = {
9
+ running: 0,
10
+ complete: 0,
11
+ incomplete: 0,
12
+ requiresAction: 0
13
+ };
14
+ let status = COMPLETE_STATUS;
15
+ let isRunning = false;
16
+ for (const index of indices) {
17
+ status = parts[index]?.status ?? COMPLETE_STATUS;
18
+ switch (status.type) {
19
+ case "running":
20
+ counts.running++;
21
+ isRunning = true;
22
+ break;
23
+ case "complete":
24
+ counts.complete++;
25
+ break;
26
+ case "incomplete":
27
+ counts.incomplete++;
28
+ break;
29
+ case "requires-action": counts.requiresAction++;
30
+ }
31
+ }
32
+ return {
33
+ status: isRunning ? RUNNING_STATUS : status,
34
+ counts
35
+ };
36
+ };
12
37
  //#endregion
13
- export { getGroupStatus };
38
+ export { getGroupStatus, getGroupSummary };
14
39
 
15
40
  //# sourceMappingURL=getGroupStatus.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGroupStatus.js","names":["MessagePartStatus","ToolCallMessagePartStatus","COMPLETE_STATUS","RUNNING_STATUS","PartWithStatus","status","getGroupStatus","parts","indices","index","type","lastIndex","at","undefined","part"],"sources":["../../src/utils/getGroupStatus.ts"],"sourcesContent":["import type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../types/message\";\nimport { COMPLETE_STATUS, RUNNING_STATUS } from \"./normalizePartStatus\";\n\ntype PartWithStatus = {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\nexport const getGroupStatus = (\n parts: readonly (PartWithStatus | undefined)[],\n indices?: readonly number[],\n): MessagePartStatus | ToolCallMessagePartStatus => {\n if (indices) {\n for (const index of indices) {\n if (parts[index]?.status.type === \"running\") return RUNNING_STATUS;\n }\n\n const lastIndex = indices.at(-1);\n return lastIndex === undefined\n ? COMPLETE_STATUS\n : (parts[lastIndex]?.status ?? COMPLETE_STATUS);\n }\n\n for (const part of parts) {\n if (part?.status.type === \"running\") return RUNNING_STATUS;\n }\n\n return parts.at(-1)?.status ?? COMPLETE_STATUS;\n};\n"],"mappings":";;AAUA,MAAaM,kBACXC,OACAC,YACkD;CAClD,IAAIA,SAAS;EACX,KAAK,MAAMC,SAASD,SAClB,IAAID,MAAME,MAAM,EAAEJ,OAAOK,SAAS,WAAW,OAAOP;EAGtD,MAAMQ,YAAYH,QAAQI,GAAG,EAAE;EAC/B,OAAOD,cAAcE,KAAAA,IACjBX,kBACCK,MAAMI,UAAU,EAAEN,UAAUH;CACnC;CAEA,KAAK,MAAMY,QAAQP,OACjB,IAAIO,MAAMT,OAAOK,SAAS,WAAW,OAAOP;CAG9C,OAAOI,MAAMK,GAAG,EAAE,CAAC,EAAEP,UAAUH;AACjC"}
1
+ {"version":3,"file":"getGroupStatus.js","names":["MessagePartStatus","ToolCallMessagePartStatus","COMPLETE_STATUS","RUNNING_STATUS","PartWithStatus","status","getGroupStatus","parts","part","type","at","getGroupSummary","indices","counts","running","complete","incomplete","requiresAction","isRunning","index"],"sources":["../../src/utils/getGroupStatus.ts"],"sourcesContent":["import type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../types/message\";\nimport { COMPLETE_STATUS, RUNNING_STATUS } from \"./normalizePartStatus\";\n\ntype PartWithStatus = {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\nexport const getGroupStatus = (\n parts: readonly (PartWithStatus | undefined)[],\n): MessagePartStatus | ToolCallMessagePartStatus => {\n for (const part of parts) {\n if (part?.status.type === \"running\") return RUNNING_STATUS;\n }\n\n return parts.at(-1)?.status ?? COMPLETE_STATUS;\n};\n\nexport const getGroupSummary = (\n parts: readonly (PartWithStatus | undefined)[],\n indices: readonly number[],\n) => {\n const counts = {\n running: 0,\n complete: 0,\n incomplete: 0,\n requiresAction: 0,\n };\n let status: MessagePartStatus | ToolCallMessagePartStatus = COMPLETE_STATUS;\n let isRunning = false;\n\n for (const index of indices) {\n status = parts[index]?.status ?? COMPLETE_STATUS;\n switch (status.type) {\n case \"running\":\n counts.running++;\n isRunning = true;\n break;\n case \"complete\":\n counts.complete++;\n break;\n case \"incomplete\":\n counts.incomplete++;\n break;\n case \"requires-action\":\n counts.requiresAction++;\n break;\n }\n }\n\n return { status: isRunning ? RUNNING_STATUS : status, counts };\n};\n"],"mappings":";;AAUA,MAAaM,kBACXC,UACkD;CAClD,KAAK,MAAMC,QAAQD,OACjB,IAAIC,MAAMH,OAAOI,SAAS,WAAW,OAAON;CAG9C,OAAOI,MAAMG,GAAG,EAAE,CAAC,EAAEL,UAAUH;AACjC;AAEA,MAAaS,mBACXJ,OACAK,YACG;CACH,MAAMC,SAAS;EACbC,SAAS;EACTC,UAAU;EACVC,YAAY;EACZC,gBAAgB;CAClB;CACA,IAAIZ,SAAwDH;CAC5D,IAAIgB,YAAY;CAEhB,KAAK,MAAMC,SAASP,SAAS;EAC3BP,SAASE,MAAMY,MAAM,EAAEd,UAAUH;EACjC,QAAQG,OAAOI,MAAf;GACE,KAAK;IACHI,OAAOC;IACPI,YAAY;IACZ;GACF,KAAK;IACHL,OAAOE;IACP;GACF,KAAK;IACHF,OAAOG;IACP;GACF,KAAK,mBACHH,OAAOI;EAEX;CACF;CAEA,OAAO;EAAEZ,QAAQa,YAAYf,iBAAiBE;EAAQQ;CAAO;AAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"wire-media.d.ts","names":[],"sources":["../../src/utils/wire-media.ts"],"mappings":";;;;;;;;;;iBAYgB,sBACd,eACA;;;;;;;;iBA2Bc,qBACd,cACA;;;;;;;;;;;;;iBAiBc,eAAe,iBAAiB"}
1
+ {"version":3,"file":"wire-media.d.ts","names":[],"sources":["../../src/utils/wire-media.ts"],"mappings":";;;;;;;;;;iBAYgB,sBACd,eACA;;;;;;;;iBA+Bc,qBACd,cACA;;;;;;;;;;;;;iBAiBc,eAAe,iBAAiB"}
@@ -11,9 +11,9 @@ import { detectImageMediaType } from "./image-media-type.js";
11
11
  * where a fallback is needed.
12
12
  */
13
13
  function resolveImageMediaType(image, contentType) {
14
- if (contentType?.startsWith("image/")) return contentType;
14
+ if (contentType?.startsWith("image/") && !contentType.includes("*")) return contentType;
15
15
  const declared = dataUrlMediaType(image);
16
- if (declared?.startsWith("image/")) return declared;
16
+ if (declared?.startsWith("image/") && !declared.includes("*")) return declared;
17
17
  const payload = parseDataUrl(image)?.data ?? (isParsableUrl(image) ? void 0 : image);
18
18
  if (payload !== void 0) {
19
19
  const sniffed = detectImageMediaType(payload);