@langchain/langgraph-sdk 1.8.10 → 1.9.1

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 (435) hide show
  1. package/README.md +90 -43
  2. package/dist/client/assistants/index.cjs +180 -0
  3. package/dist/client/assistants/index.cjs.map +1 -0
  4. package/dist/client/assistants/index.d.cts +155 -0
  5. package/dist/client/assistants/index.d.cts.map +1 -0
  6. package/dist/client/assistants/index.d.ts +155 -0
  7. package/dist/client/assistants/index.d.ts.map +1 -0
  8. package/dist/client/assistants/index.js +180 -0
  9. package/dist/client/assistants/index.js.map +1 -0
  10. package/dist/client/base.cjs +190 -0
  11. package/dist/client/base.cjs.map +1 -0
  12. package/dist/client/base.d.cts +84 -0
  13. package/dist/client/base.d.cts.map +1 -0
  14. package/dist/client/base.d.ts +84 -0
  15. package/dist/client/base.d.ts.map +1 -0
  16. package/dist/client/base.js +188 -0
  17. package/dist/client/base.js.map +1 -0
  18. package/dist/client/crons/index.cjs +159 -0
  19. package/dist/client/crons/index.cjs.map +1 -0
  20. package/dist/client/crons/index.d.cts +71 -0
  21. package/dist/client/crons/index.d.cts.map +1 -0
  22. package/dist/client/crons/index.d.ts +71 -0
  23. package/dist/client/crons/index.d.ts.map +1 -0
  24. package/dist/client/crons/index.js +159 -0
  25. package/dist/client/crons/index.js.map +1 -0
  26. package/dist/client/index.cjs +84 -0
  27. package/dist/client/index.cjs.map +1 -0
  28. package/dist/client/index.d.cts +63 -0
  29. package/dist/client/index.d.cts.map +1 -0
  30. package/dist/client/index.d.ts +63 -0
  31. package/dist/client/index.d.ts.map +1 -0
  32. package/dist/client/index.js +83 -0
  33. package/dist/client/index.js.map +1 -0
  34. package/dist/client/runs/index.cjs +275 -0
  35. package/dist/client/runs/index.cjs.map +1 -0
  36. package/dist/client/runs/index.d.cts +123 -0
  37. package/dist/client/runs/index.d.cts.map +1 -0
  38. package/dist/client/runs/index.d.ts +123 -0
  39. package/dist/client/runs/index.d.ts.map +1 -0
  40. package/dist/client/runs/index.js +275 -0
  41. package/dist/client/runs/index.js.map +1 -0
  42. package/dist/client/store/index.cjs +128 -0
  43. package/dist/client/store/index.cjs.map +1 -0
  44. package/dist/client/store/index.d.cts +75 -0
  45. package/dist/client/store/index.d.cts.map +1 -0
  46. package/dist/client/store/index.d.ts +75 -0
  47. package/dist/client/store/index.d.ts.map +1 -0
  48. package/dist/client/store/index.js +128 -0
  49. package/dist/client/store/index.js.map +1 -0
  50. package/dist/client/stream/error.cjs +18 -0
  51. package/dist/client/stream/error.cjs.map +1 -0
  52. package/dist/client/stream/error.d.cts +14 -0
  53. package/dist/client/stream/error.d.cts.map +1 -0
  54. package/dist/client/stream/error.d.ts +14 -0
  55. package/dist/client/stream/error.d.ts.map +1 -0
  56. package/dist/client/stream/error.js +18 -0
  57. package/dist/client/stream/error.js.map +1 -0
  58. package/dist/client/stream/handles/index.cjs +3 -0
  59. package/dist/client/stream/handles/index.d.ts +3 -0
  60. package/dist/client/stream/handles/index.js +4 -0
  61. package/dist/client/stream/handles/subagents.cjs +263 -0
  62. package/dist/client/stream/handles/subagents.cjs.map +1 -0
  63. package/dist/client/stream/handles/subagents.d.cts +45 -0
  64. package/dist/client/stream/handles/subagents.d.cts.map +1 -0
  65. package/dist/client/stream/handles/subagents.d.ts +45 -0
  66. package/dist/client/stream/handles/subagents.d.ts.map +1 -0
  67. package/dist/client/stream/handles/subagents.js +262 -0
  68. package/dist/client/stream/handles/subagents.js.map +1 -0
  69. package/dist/client/stream/handles/subgraphs.cjs +352 -0
  70. package/dist/client/stream/handles/subgraphs.cjs.map +1 -0
  71. package/dist/client/stream/handles/subgraphs.d.cts +82 -0
  72. package/dist/client/stream/handles/subgraphs.d.cts.map +1 -0
  73. package/dist/client/stream/handles/subgraphs.d.ts +82 -0
  74. package/dist/client/stream/handles/subgraphs.d.ts.map +1 -0
  75. package/dist/client/stream/handles/subgraphs.js +351 -0
  76. package/dist/client/stream/handles/subgraphs.js.map +1 -0
  77. package/dist/client/stream/handles/tools.cjs +92 -0
  78. package/dist/client/stream/handles/tools.cjs.map +1 -0
  79. package/dist/client/stream/handles/tools.d.cts +26 -0
  80. package/dist/client/stream/handles/tools.d.cts.map +1 -0
  81. package/dist/client/stream/handles/tools.d.ts +26 -0
  82. package/dist/client/stream/handles/tools.d.ts.map +1 -0
  83. package/dist/client/stream/handles/tools.js +92 -0
  84. package/dist/client/stream/handles/tools.js.map +1 -0
  85. package/dist/client/stream/index.cjs +1368 -0
  86. package/dist/client/stream/index.cjs.map +1 -0
  87. package/dist/client/stream/index.d.cts +238 -0
  88. package/dist/client/stream/index.d.cts.map +1 -0
  89. package/dist/client/stream/index.d.ts +238 -0
  90. package/dist/client/stream/index.d.ts.map +1 -0
  91. package/dist/client/stream/index.js +1367 -0
  92. package/dist/client/stream/index.js.map +1 -0
  93. package/dist/client/stream/media.cjs +506 -0
  94. package/dist/client/stream/media.cjs.map +1 -0
  95. package/dist/client/stream/media.d.cts +164 -0
  96. package/dist/client/stream/media.d.cts.map +1 -0
  97. package/dist/client/stream/media.d.ts +164 -0
  98. package/dist/client/stream/media.d.ts.map +1 -0
  99. package/dist/client/stream/media.js +505 -0
  100. package/dist/client/stream/media.js.map +1 -0
  101. package/dist/client/stream/messages.cjs +635 -0
  102. package/dist/client/stream/messages.cjs.map +1 -0
  103. package/dist/client/stream/messages.d.cts +139 -0
  104. package/dist/client/stream/messages.d.cts.map +1 -0
  105. package/dist/client/stream/messages.d.ts +139 -0
  106. package/dist/client/stream/messages.d.ts.map +1 -0
  107. package/dist/client/stream/messages.js +631 -0
  108. package/dist/client/stream/messages.js.map +1 -0
  109. package/dist/client/stream/multi-cursor-buffer.cjs +55 -0
  110. package/dist/client/stream/multi-cursor-buffer.cjs.map +1 -0
  111. package/dist/client/stream/multi-cursor-buffer.js +55 -0
  112. package/dist/client/stream/multi-cursor-buffer.js.map +1 -0
  113. package/dist/client/stream/subscription.cjs +85 -0
  114. package/dist/client/stream/subscription.cjs.map +1 -0
  115. package/dist/client/stream/subscription.d.cts +22 -0
  116. package/dist/client/stream/subscription.d.cts.map +1 -0
  117. package/dist/client/stream/subscription.d.ts +22 -0
  118. package/dist/client/stream/subscription.d.ts.map +1 -0
  119. package/dist/client/stream/subscription.js +84 -0
  120. package/dist/client/stream/subscription.js.map +1 -0
  121. package/dist/client/stream/transport/agent-server.cjs +45 -0
  122. package/dist/client/stream/transport/agent-server.cjs.map +1 -0
  123. package/dist/client/stream/transport/agent-server.d.cts +39 -0
  124. package/dist/client/stream/transport/agent-server.d.cts.map +1 -0
  125. package/dist/client/stream/transport/agent-server.d.ts +39 -0
  126. package/dist/client/stream/transport/agent-server.d.ts.map +1 -0
  127. package/dist/client/stream/transport/agent-server.js +45 -0
  128. package/dist/client/stream/transport/agent-server.js.map +1 -0
  129. package/dist/client/stream/transport/constants.cjs +10 -0
  130. package/dist/client/stream/transport/constants.cjs.map +1 -0
  131. package/dist/client/stream/transport/constants.js +10 -0
  132. package/dist/client/stream/transport/constants.js.map +1 -0
  133. package/dist/client/stream/transport/decoder.cjs +115 -0
  134. package/dist/client/stream/transport/decoder.cjs.map +1 -0
  135. package/dist/client/stream/transport/decoder.js +114 -0
  136. package/dist/client/stream/transport/decoder.js.map +1 -0
  137. package/dist/client/stream/transport/http.cjs +183 -0
  138. package/dist/client/stream/transport/http.cjs.map +1 -0
  139. package/dist/client/stream/transport/http.d.cts +45 -0
  140. package/dist/client/stream/transport/http.d.cts.map +1 -0
  141. package/dist/client/stream/transport/http.d.ts +45 -0
  142. package/dist/client/stream/transport/http.d.ts.map +1 -0
  143. package/dist/client/stream/transport/http.js +183 -0
  144. package/dist/client/stream/transport/http.js.map +1 -0
  145. package/dist/client/stream/transport/index.cjs +3 -0
  146. package/dist/client/stream/transport/index.js +4 -0
  147. package/dist/client/stream/transport/queue.cjs +55 -0
  148. package/dist/client/stream/transport/queue.cjs.map +1 -0
  149. package/dist/client/stream/transport/queue.js +55 -0
  150. package/dist/client/stream/transport/queue.js.map +1 -0
  151. package/dist/client/stream/transport/stream.cjs +79 -0
  152. package/dist/client/stream/transport/stream.cjs.map +1 -0
  153. package/dist/client/stream/transport/stream.js +79 -0
  154. package/dist/client/stream/transport/stream.js.map +1 -0
  155. package/dist/client/stream/transport/types.d.cts +29 -0
  156. package/dist/client/stream/transport/types.d.cts.map +1 -0
  157. package/dist/client/stream/transport/types.d.ts +29 -0
  158. package/dist/client/stream/transport/types.d.ts.map +1 -0
  159. package/dist/client/stream/transport/utils.cjs +45 -0
  160. package/dist/client/stream/transport/utils.cjs.map +1 -0
  161. package/dist/client/stream/transport/utils.js +39 -0
  162. package/dist/client/stream/transport/utils.js.map +1 -0
  163. package/dist/client/stream/transport/websocket.cjs +155 -0
  164. package/dist/client/stream/transport/websocket.cjs.map +1 -0
  165. package/dist/client/stream/transport/websocket.d.cts +36 -0
  166. package/dist/client/stream/transport/websocket.d.cts.map +1 -0
  167. package/dist/client/stream/transport/websocket.d.ts +36 -0
  168. package/dist/client/stream/transport/websocket.d.ts.map +1 -0
  169. package/dist/client/stream/transport/websocket.js +155 -0
  170. package/dist/client/stream/transport/websocket.js.map +1 -0
  171. package/dist/client/stream/transport.d.cts +104 -0
  172. package/dist/client/stream/transport.d.cts.map +1 -0
  173. package/dist/client/stream/transport.d.ts +104 -0
  174. package/dist/client/stream/transport.d.ts.map +1 -0
  175. package/dist/client/stream/types.d.cts +208 -0
  176. package/dist/client/stream/types.d.cts.map +1 -0
  177. package/dist/client/stream/types.d.ts +208 -0
  178. package/dist/client/stream/types.d.ts.map +1 -0
  179. package/dist/client/threads/index.cjs +271 -0
  180. package/dist/client/threads/index.cjs.map +1 -0
  181. package/dist/client/threads/index.d.cts +235 -0
  182. package/dist/client/threads/index.d.cts.map +1 -0
  183. package/dist/client/threads/index.d.ts +235 -0
  184. package/dist/client/threads/index.d.ts.map +1 -0
  185. package/dist/client/threads/index.js +270 -0
  186. package/dist/client/threads/index.js.map +1 -0
  187. package/dist/client/ui-internal/index.cjs +29 -0
  188. package/dist/client/ui-internal/index.cjs.map +1 -0
  189. package/dist/client/ui-internal/index.d.cts +11 -0
  190. package/dist/client/ui-internal/index.d.cts.map +1 -0
  191. package/dist/client/ui-internal/index.d.ts +11 -0
  192. package/dist/client/ui-internal/index.d.ts.map +1 -0
  193. package/dist/client/ui-internal/index.js +29 -0
  194. package/dist/client/ui-internal/index.js.map +1 -0
  195. package/dist/client.cjs +35 -1308
  196. package/dist/client.d.cts +19 -857
  197. package/dist/client.d.ts +19 -857
  198. package/dist/client.js +16 -1301
  199. package/dist/index.cjs +25 -4
  200. package/dist/index.d.cts +15 -3
  201. package/dist/index.d.ts +15 -3
  202. package/dist/index.js +14 -3
  203. package/dist/react/stream.cjs.map +1 -1
  204. package/dist/react/stream.custom.cjs +1 -1
  205. package/dist/react/stream.custom.js +1 -1
  206. package/dist/react/stream.d.cts +2 -1
  207. package/dist/react/stream.d.cts.map +1 -1
  208. package/dist/react/stream.d.ts +2 -1
  209. package/dist/react/stream.d.ts.map +1 -1
  210. package/dist/react/stream.js.map +1 -1
  211. package/dist/react/stream.lgp.cjs +6 -5
  212. package/dist/react/stream.lgp.cjs.map +1 -1
  213. package/dist/react/stream.lgp.js +4 -3
  214. package/dist/react/stream.lgp.js.map +1 -1
  215. package/dist/react/types.d.cts +1 -1
  216. package/dist/react/types.d.ts +1 -1
  217. package/dist/react/types.d.ts.map +1 -1
  218. package/dist/react-ui/server/server.cjs +1 -1
  219. package/dist/react-ui/server/server.cjs.map +1 -1
  220. package/dist/react-ui/server/server.js +1 -1
  221. package/dist/react-ui/server/server.js.map +1 -1
  222. package/dist/react-ui/types.cjs.map +1 -1
  223. package/dist/react-ui/types.d.cts +1 -1
  224. package/dist/react-ui/types.d.cts.map +1 -1
  225. package/dist/react-ui/types.d.ts +1 -1
  226. package/dist/react-ui/types.d.ts.map +1 -1
  227. package/dist/react-ui/types.js.map +1 -1
  228. package/dist/stream/assembled-to-message.cjs +121 -0
  229. package/dist/stream/assembled-to-message.cjs.map +1 -0
  230. package/dist/stream/assembled-to-message.d.cts +35 -0
  231. package/dist/stream/assembled-to-message.d.cts.map +1 -0
  232. package/dist/stream/assembled-to-message.d.ts +35 -0
  233. package/dist/stream/assembled-to-message.d.ts.map +1 -0
  234. package/dist/stream/assembled-to-message.js +119 -0
  235. package/dist/stream/assembled-to-message.js.map +1 -0
  236. package/dist/stream/channel-registry.cjs +224 -0
  237. package/dist/stream/channel-registry.cjs.map +1 -0
  238. package/dist/stream/channel-registry.d.cts +102 -0
  239. package/dist/stream/channel-registry.d.cts.map +1 -0
  240. package/dist/stream/channel-registry.d.ts +102 -0
  241. package/dist/stream/channel-registry.d.ts.map +1 -0
  242. package/dist/stream/channel-registry.js +224 -0
  243. package/dist/stream/channel-registry.js.map +1 -0
  244. package/dist/stream/constants.cjs +11 -0
  245. package/dist/stream/constants.cjs.map +1 -0
  246. package/dist/stream/constants.d.cts +10 -0
  247. package/dist/stream/constants.d.cts.map +1 -0
  248. package/dist/stream/constants.d.ts +10 -0
  249. package/dist/stream/constants.d.ts.map +1 -0
  250. package/dist/stream/constants.js +11 -0
  251. package/dist/stream/constants.js.map +1 -0
  252. package/dist/stream/controller.cjs +933 -0
  253. package/dist/stream/controller.cjs.map +1 -0
  254. package/dist/stream/controller.d.cts +135 -0
  255. package/dist/stream/controller.d.cts.map +1 -0
  256. package/dist/stream/controller.d.ts +135 -0
  257. package/dist/stream/controller.d.ts.map +1 -0
  258. package/dist/stream/controller.js +910 -0
  259. package/dist/stream/controller.js.map +1 -0
  260. package/dist/stream/discovery/index.d.ts +2 -0
  261. package/dist/stream/discovery/subagents.cjs +235 -0
  262. package/dist/stream/discovery/subagents.cjs.map +1 -0
  263. package/dist/stream/discovery/subagents.d.cts +18 -0
  264. package/dist/stream/discovery/subagents.d.cts.map +1 -0
  265. package/dist/stream/discovery/subagents.d.ts +18 -0
  266. package/dist/stream/discovery/subagents.d.ts.map +1 -0
  267. package/dist/stream/discovery/subagents.js +235 -0
  268. package/dist/stream/discovery/subagents.js.map +1 -0
  269. package/dist/stream/discovery/subgraphs.cjs +153 -0
  270. package/dist/stream/discovery/subgraphs.cjs.map +1 -0
  271. package/dist/stream/discovery/subgraphs.d.cts +19 -0
  272. package/dist/stream/discovery/subgraphs.d.cts.map +1 -0
  273. package/dist/stream/discovery/subgraphs.d.ts +19 -0
  274. package/dist/stream/discovery/subgraphs.d.ts.map +1 -0
  275. package/dist/stream/discovery/subgraphs.js +153 -0
  276. package/dist/stream/discovery/subgraphs.js.map +1 -0
  277. package/dist/stream/index.cjs +36 -0
  278. package/dist/stream/index.d.cts +25 -0
  279. package/dist/stream/index.d.ts +25 -0
  280. package/dist/stream/index.js +16 -0
  281. package/dist/stream/lifecycle-loading-tracker.cjs +83 -0
  282. package/dist/stream/lifecycle-loading-tracker.cjs.map +1 -0
  283. package/dist/stream/lifecycle-loading-tracker.js +83 -0
  284. package/dist/stream/lifecycle-loading-tracker.js.map +1 -0
  285. package/dist/stream/message-metadata-tracker.cjs +165 -0
  286. package/dist/stream/message-metadata-tracker.cjs.map +1 -0
  287. package/dist/stream/message-metadata-tracker.d.cts +24 -0
  288. package/dist/stream/message-metadata-tracker.d.cts.map +1 -0
  289. package/dist/stream/message-metadata-tracker.d.ts +24 -0
  290. package/dist/stream/message-metadata-tracker.d.ts.map +1 -0
  291. package/dist/stream/message-metadata-tracker.js +165 -0
  292. package/dist/stream/message-metadata-tracker.js.map +1 -0
  293. package/dist/stream/message-reconciliation.cjs +118 -0
  294. package/dist/stream/message-reconciliation.cjs.map +1 -0
  295. package/dist/stream/message-reconciliation.js +115 -0
  296. package/dist/stream/message-reconciliation.js.map +1 -0
  297. package/dist/stream/namespace.cjs +54 -0
  298. package/dist/stream/namespace.cjs.map +1 -0
  299. package/dist/stream/namespace.js +49 -0
  300. package/dist/stream/namespace.js.map +1 -0
  301. package/dist/stream/projections/channel.cjs +53 -0
  302. package/dist/stream/projections/channel.cjs.map +1 -0
  303. package/dist/stream/projections/channel.d.cts +22 -0
  304. package/dist/stream/projections/channel.d.cts.map +1 -0
  305. package/dist/stream/projections/channel.d.ts +22 -0
  306. package/dist/stream/projections/channel.d.ts.map +1 -0
  307. package/dist/stream/projections/channel.js +53 -0
  308. package/dist/stream/projections/channel.js.map +1 -0
  309. package/dist/stream/projections/extension.cjs +29 -0
  310. package/dist/stream/projections/extension.cjs.map +1 -0
  311. package/dist/stream/projections/extension.d.cts +7 -0
  312. package/dist/stream/projections/extension.d.cts.map +1 -0
  313. package/dist/stream/projections/extension.d.ts +7 -0
  314. package/dist/stream/projections/extension.d.ts.map +1 -0
  315. package/dist/stream/projections/extension.js +29 -0
  316. package/dist/stream/projections/extension.js.map +1 -0
  317. package/dist/stream/projections/index.cjs +6 -0
  318. package/dist/stream/projections/index.d.ts +6 -0
  319. package/dist/stream/projections/index.js +7 -0
  320. package/dist/stream/projections/media.cjs +81 -0
  321. package/dist/stream/projections/media.cjs.map +1 -0
  322. package/dist/stream/projections/media.d.cts +18 -0
  323. package/dist/stream/projections/media.d.cts.map +1 -0
  324. package/dist/stream/projections/media.d.ts +18 -0
  325. package/dist/stream/projections/media.d.ts.map +1 -0
  326. package/dist/stream/projections/media.js +78 -0
  327. package/dist/stream/projections/media.js.map +1 -0
  328. package/dist/stream/projections/messages.cjs +121 -0
  329. package/dist/stream/projections/messages.cjs.map +1 -0
  330. package/dist/stream/projections/messages.d.cts +8 -0
  331. package/dist/stream/projections/messages.d.cts.map +1 -0
  332. package/dist/stream/projections/messages.d.ts +8 -0
  333. package/dist/stream/projections/messages.d.ts.map +1 -0
  334. package/dist/stream/projections/messages.js +121 -0
  335. package/dist/stream/projections/messages.js.map +1 -0
  336. package/dist/stream/projections/runtime.cjs +44 -0
  337. package/dist/stream/projections/runtime.cjs.map +1 -0
  338. package/dist/stream/projections/runtime.js +44 -0
  339. package/dist/stream/projections/runtime.js.map +1 -0
  340. package/dist/stream/projections/tool-calls.cjs +50 -0
  341. package/dist/stream/projections/tool-calls.cjs.map +1 -0
  342. package/dist/stream/projections/tool-calls.d.cts +8 -0
  343. package/dist/stream/projections/tool-calls.d.cts.map +1 -0
  344. package/dist/stream/projections/tool-calls.d.ts +8 -0
  345. package/dist/stream/projections/tool-calls.d.ts.map +1 -0
  346. package/dist/stream/projections/tool-calls.js +50 -0
  347. package/dist/stream/projections/tool-calls.js.map +1 -0
  348. package/dist/stream/projections/values.cjs +52 -0
  349. package/dist/stream/projections/values.cjs.map +1 -0
  350. package/dist/stream/projections/values.d.cts +7 -0
  351. package/dist/stream/projections/values.d.cts.map +1 -0
  352. package/dist/stream/projections/values.d.ts +6 -0
  353. package/dist/stream/projections/values.d.ts.map +1 -0
  354. package/dist/stream/projections/values.js +52 -0
  355. package/dist/stream/projections/values.js.map +1 -0
  356. package/dist/stream/root-message-projection.cjs +256 -0
  357. package/dist/stream/root-message-projection.cjs.map +1 -0
  358. package/dist/stream/root-message-projection.js +256 -0
  359. package/dist/stream/root-message-projection.js.map +1 -0
  360. package/dist/stream/store.cjs +32 -0
  361. package/dist/stream/store.cjs.map +1 -0
  362. package/dist/stream/store.d.cts +37 -0
  363. package/dist/stream/store.d.cts.map +1 -0
  364. package/dist/stream/store.d.ts +37 -0
  365. package/dist/stream/store.d.ts.map +1 -0
  366. package/dist/stream/store.js +32 -0
  367. package/dist/stream/store.js.map +1 -0
  368. package/dist/stream/submit-coordinator.cjs +399 -0
  369. package/dist/stream/submit-coordinator.cjs.map +1 -0
  370. package/dist/stream/submit-coordinator.d.cts +27 -0
  371. package/dist/stream/submit-coordinator.d.cts.map +1 -0
  372. package/dist/stream/submit-coordinator.d.ts +27 -0
  373. package/dist/stream/submit-coordinator.d.ts.map +1 -0
  374. package/dist/stream/submit-coordinator.js +397 -0
  375. package/dist/stream/submit-coordinator.js.map +1 -0
  376. package/dist/stream/tool-calls.cjs +15 -0
  377. package/dist/stream/tool-calls.cjs.map +1 -0
  378. package/dist/stream/tool-calls.js +15 -0
  379. package/dist/stream/tool-calls.js.map +1 -0
  380. package/dist/stream/types-inference.d.cts +43 -0
  381. package/dist/stream/types-inference.d.cts.map +1 -0
  382. package/dist/stream/types-inference.d.ts +43 -0
  383. package/dist/stream/types-inference.d.ts.map +1 -0
  384. package/dist/stream/types.d.cts +354 -0
  385. package/dist/stream/types.d.cts.map +1 -0
  386. package/dist/stream/types.d.ts +354 -0
  387. package/dist/stream/types.d.ts.map +1 -0
  388. package/dist/types.d.cts +2 -1
  389. package/dist/types.d.cts.map +1 -1
  390. package/dist/types.d.ts +2 -1
  391. package/dist/types.d.ts.map +1 -1
  392. package/dist/ui/index.cjs +1 -1
  393. package/dist/ui/index.d.cts +3 -3
  394. package/dist/ui/index.d.ts +3 -3
  395. package/dist/ui/index.js +1 -1
  396. package/dist/ui/manager.cjs +1 -1
  397. package/dist/ui/manager.js +1 -1
  398. package/dist/ui/messages.cjs +50 -7
  399. package/dist/ui/messages.cjs.map +1 -1
  400. package/dist/ui/messages.d.cts.map +1 -1
  401. package/dist/ui/messages.d.ts.map +1 -1
  402. package/dist/ui/messages.js +51 -9
  403. package/dist/ui/messages.js.map +1 -1
  404. package/dist/ui/orchestrator-custom.cjs +1 -1
  405. package/dist/ui/orchestrator-custom.js +1 -1
  406. package/dist/ui/orchestrator.cjs +2 -2
  407. package/dist/ui/orchestrator.d.cts +1 -1
  408. package/dist/ui/orchestrator.d.ts +1 -1
  409. package/dist/ui/orchestrator.d.ts.map +1 -1
  410. package/dist/ui/orchestrator.js +2 -2
  411. package/dist/ui/stream/agent.d.cts +1 -1
  412. package/dist/ui/stream/agent.d.cts.map +1 -1
  413. package/dist/ui/stream/agent.d.ts +1 -1
  414. package/dist/ui/stream/agent.d.ts.map +1 -1
  415. package/dist/ui/stream/base.d.cts +7 -6
  416. package/dist/ui/stream/base.d.cts.map +1 -1
  417. package/dist/ui/stream/base.d.ts +7 -6
  418. package/dist/ui/stream/base.d.ts.map +1 -1
  419. package/dist/ui/stream/deep-agent.d.cts +1 -1
  420. package/dist/ui/stream/deep-agent.d.cts.map +1 -1
  421. package/dist/ui/stream/deep-agent.d.ts +1 -1
  422. package/dist/ui/stream/deep-agent.d.ts.map +1 -1
  423. package/dist/ui/stream/index.d.cts +4 -4
  424. package/dist/ui/stream/index.d.cts.map +1 -1
  425. package/dist/ui/stream/index.d.ts +4 -4
  426. package/dist/ui/stream/index.d.ts.map +1 -1
  427. package/dist/ui/types.d.cts +3 -2
  428. package/dist/ui/types.d.cts.map +1 -1
  429. package/dist/ui/types.d.ts +2 -1
  430. package/dist/ui/types.d.ts.map +1 -1
  431. package/package.json +18 -8
  432. package/dist/client.cjs.map +0 -1
  433. package/dist/client.d.cts.map +0 -1
  434. package/dist/client.d.ts.map +0 -1
  435. package/dist/client.js.map +0 -1
@@ -0,0 +1,37 @@
1
+ //#region src/stream/store.d.ts
2
+ /**
3
+ * Minimal observable store backing every framework binding.
4
+ *
5
+ * The shape is intentionally tiny:
6
+ *
7
+ * - `subscribe(listener) → unsubscribe` lines up with React's
8
+ * `useSyncExternalStore`.
9
+ * - `getSnapshot()` returns a referentially-stable value for
10
+ * unchanged state so React can bail out of renders.
11
+ * - Vue/Svelte/Angular bindings wrap `subscribe` + `getSnapshot` in
12
+ * their own reactivity primitive (`shallowRef` / `writable` /
13
+ * `signal`) in ~10 lines.
14
+ *
15
+ * Snapshot identity matters: a listener is only useful if
16
+ * `getSnapshot()` returns a *different* reference when state changes.
17
+ * Callers MUST pass a freshly-constructed value to {@link setState};
18
+ * mutating the previous snapshot in place will break React's bail-out
19
+ * and cause infinite re-renders.
20
+ */
21
+ type StoreListener = () => void;
22
+ declare class StreamStore<T> {
23
+ #private;
24
+ constructor(initial: T);
25
+ subscribe: (listener: StoreListener) => () => void;
26
+ getSnapshot: () => T;
27
+ /** Replace the snapshot and notify every listener. */
28
+ setValue: (next: T) => void;
29
+ /**
30
+ * Functional update. The `updater` receives the current snapshot and
31
+ * MUST return a new object. Returning the same reference is a no-op.
32
+ */
33
+ setState: (updater: (previous: T) => T) => void;
34
+ }
35
+ //#endregion
36
+ export { StoreListener, StreamStore };
37
+ //# sourceMappingURL=store.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.cts","names":[],"sources":["../../src/stream/store.ts"],"mappings":";;AAoBA;;;;;AAEA;;;;;;;;;;;;;KAFY,aAAA;AAAA,cAEC,WAAA;EAAA;EAIX,WAAA,CAAY,OAAA,EAAS,CAAA;EAIrB,SAAA,GAAS,QAAA,EAAA,aAAA;EAOT,WAAA,QAAW,CAAA;EAAX;EAGA,QAAA,GAAQ,IAAA,EAAA,CAAA;EAAR;;;;EAUA,QAAA,GAAQ,OAAA,GAAA,QAAA,EAAA,CAAA,KAAA,CAAA;AAAA"}
@@ -0,0 +1,37 @@
1
+ //#region src/stream/store.d.ts
2
+ /**
3
+ * Minimal observable store backing every framework binding.
4
+ *
5
+ * The shape is intentionally tiny:
6
+ *
7
+ * - `subscribe(listener) → unsubscribe` lines up with React's
8
+ * `useSyncExternalStore`.
9
+ * - `getSnapshot()` returns a referentially-stable value for
10
+ * unchanged state so React can bail out of renders.
11
+ * - Vue/Svelte/Angular bindings wrap `subscribe` + `getSnapshot` in
12
+ * their own reactivity primitive (`shallowRef` / `writable` /
13
+ * `signal`) in ~10 lines.
14
+ *
15
+ * Snapshot identity matters: a listener is only useful if
16
+ * `getSnapshot()` returns a *different* reference when state changes.
17
+ * Callers MUST pass a freshly-constructed value to {@link setState};
18
+ * mutating the previous snapshot in place will break React's bail-out
19
+ * and cause infinite re-renders.
20
+ */
21
+ type StoreListener = () => void;
22
+ declare class StreamStore<T> {
23
+ #private;
24
+ constructor(initial: T);
25
+ subscribe: (listener: StoreListener) => () => void;
26
+ getSnapshot: () => T;
27
+ /** Replace the snapshot and notify every listener. */
28
+ setValue: (next: T) => void;
29
+ /**
30
+ * Functional update. The `updater` receives the current snapshot and
31
+ * MUST return a new object. Returning the same reference is a no-op.
32
+ */
33
+ setState: (updater: (previous: T) => T) => void;
34
+ }
35
+ //#endregion
36
+ export { StoreListener, StreamStore };
37
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","names":[],"sources":["../../src/stream/store.ts"],"mappings":";;AAoBA;;;;;AAEA;;;;;;;;;;;;;KAFY,aAAA;AAAA,cAEC,WAAA;EAAA;EAIX,WAAA,CAAY,OAAA,EAAS,CAAA;EAIrB,SAAA,GAAS,QAAA,EAAA,aAAA;EAOT,WAAA,QAAW,CAAA;EAAX;EAGA,QAAA,GAAQ,IAAA,EAAA,CAAA;EAAR;;;;EAUA,QAAA,GAAQ,OAAA,GAAA,QAAA,EAAA,CAAA,KAAA,CAAA;AAAA"}
@@ -0,0 +1,32 @@
1
+ //#region src/stream/store.ts
2
+ var StreamStore = class {
3
+ #snapshot;
4
+ #listeners = /* @__PURE__ */ new Set();
5
+ constructor(initial) {
6
+ this.#snapshot = initial;
7
+ }
8
+ subscribe = (listener) => {
9
+ this.#listeners.add(listener);
10
+ return () => {
11
+ this.#listeners.delete(listener);
12
+ };
13
+ };
14
+ getSnapshot = () => this.#snapshot;
15
+ /** Replace the snapshot and notify every listener. */
16
+ setValue = (next) => {
17
+ if (Object.is(next, this.#snapshot)) return;
18
+ this.#snapshot = next;
19
+ for (const listener of this.#listeners) listener();
20
+ };
21
+ /**
22
+ * Functional update. The `updater` receives the current snapshot and
23
+ * MUST return a new object. Returning the same reference is a no-op.
24
+ */
25
+ setState = (updater) => {
26
+ this.setValue(updater(this.#snapshot));
27
+ };
28
+ };
29
+ //#endregion
30
+ export { StreamStore };
31
+
32
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","names":["#listeners","#snapshot"],"sources":["../../src/stream/store.ts"],"sourcesContent":["/**\n * Minimal observable store backing every framework binding.\n *\n * The shape is intentionally tiny:\n *\n * - `subscribe(listener) → unsubscribe` lines up with React's\n * `useSyncExternalStore`.\n * - `getSnapshot()` returns a referentially-stable value for\n * unchanged state so React can bail out of renders.\n * - Vue/Svelte/Angular bindings wrap `subscribe` + `getSnapshot` in\n * their own reactivity primitive (`shallowRef` / `writable` /\n * `signal`) in ~10 lines.\n *\n * Snapshot identity matters: a listener is only useful if\n * `getSnapshot()` returns a *different* reference when state changes.\n * Callers MUST pass a freshly-constructed value to {@link setState};\n * mutating the previous snapshot in place will break React's bail-out\n * and cause infinite re-renders.\n */\n\nexport type StoreListener = () => void;\n\nexport class StreamStore<T> {\n #snapshot: T;\n readonly #listeners = new Set<StoreListener>();\n\n constructor(initial: T) {\n this.#snapshot = initial;\n }\n\n subscribe = (listener: StoreListener): (() => void) => {\n this.#listeners.add(listener);\n return () => {\n this.#listeners.delete(listener);\n };\n };\n\n getSnapshot = (): T => this.#snapshot;\n\n /** Replace the snapshot and notify every listener. */\n setValue = (next: T): void => {\n if (Object.is(next, this.#snapshot)) return;\n this.#snapshot = next;\n for (const listener of this.#listeners) listener();\n };\n\n /**\n * Functional update. The `updater` receives the current snapshot and\n * MUST return a new object. Returning the same reference is a no-op.\n */\n setState = (updater: (previous: T) => T): void => {\n this.setValue(updater(this.#snapshot));\n };\n}\n"],"mappings":";AAsBA,IAAa,cAAb,MAA4B;CAC1B;CACA,6BAAsB,IAAI,KAAoB;CAE9C,YAAY,SAAY;AACtB,QAAA,WAAiB;;CAGnB,aAAa,aAA0C;AACrD,QAAA,UAAgB,IAAI,SAAS;AAC7B,eAAa;AACX,SAAA,UAAgB,OAAO,SAAS;;;CAIpC,oBAAuB,MAAA;;CAGvB,YAAY,SAAkB;AAC5B,MAAI,OAAO,GAAG,MAAM,MAAA,SAAe,CAAE;AACrC,QAAA,WAAiB;AACjB,OAAK,MAAM,YAAY,MAAA,UAAiB,WAAU;;;;;;CAOpD,YAAY,YAAsC;AAChD,OAAK,SAAS,QAAQ,MAAA,SAAe,CAAC"}
@@ -0,0 +1,399 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ let uuid = require("uuid");
3
+ //#region src/stream/submit-coordinator.ts
4
+ /**
5
+ * Owns the run-submission lifecycle for a single
6
+ * {@link StreamController}.
7
+ *
8
+ * # What this module is
9
+ *
10
+ * The {@link SubmitCoordinator} is the piece of the controller that
11
+ * dispatches runs (`submit()`), enforces multitask strategies, queues
12
+ * deferred submissions, races dispatch against terminal lifecycle
13
+ * events, and surfaces errors back through the per-submit `onError`
14
+ * callback and the root snapshot.
15
+ *
16
+ * Conceptually a submit looks like:
17
+ *
18
+ * 1. Optionally rebind to a different thread (`options.threadId`).
19
+ * 2. Mint a thread id if one isn't bound yet.
20
+ * 3. Wait for the controller's root pump to be ready (so the
21
+ * transport is subscribed before the run is dispatched —
22
+ * otherwise we could miss replayed events).
23
+ * 4. Apply the {@link StreamSubmitOptions.multitaskStrategy} to
24
+ * decide whether to abort, enqueue, reject, or proceed.
25
+ * 5. Race the dispatch promise (`thread.submitRun()` or
26
+ * `thread.respondInput()` for resumes) against the next root
27
+ * terminal lifecycle event.
28
+ * 6. Settle the resulting state (loading flag, error slot) and
29
+ * drain the next queued submission, if any.
30
+ *
31
+ * # Why it lives in its own class
32
+ *
33
+ * The submit lifecycle is the most state-heavy part of the
34
+ * controller — six promises, an abort controller, a queue, a
35
+ * terminal-vs-command race, and bidirectional callback wiring with
36
+ * the controller. Splitting it out keeps `controller.ts` focused on
37
+ * subscription / projection wiring while letting the submit logic
38
+ * evolve independently.
39
+ *
40
+ * # Why we race "command" against "terminal"
41
+ *
42
+ * For fast runs, the server's terminal lifecycle event can arrive
43
+ * *before* the dispatch HTTP response has resolved. Racing the two
44
+ * lets us detect terminal early and not block waiting for a now-stale
45
+ * dispatch response. The dispatch response is still consumed (via
46
+ * `.then(notifyCreated).catch(reportError)`) so `onCreated` still
47
+ * fires and dispatch errors still surface through `onError`.
48
+ *
49
+ * # Queue semantics (`multitaskStrategy: "enqueue"`)
50
+ *
51
+ * When a run is already in flight, an `"enqueue"` submit is recorded
52
+ * into {@link queueStore} and the call returns immediately. After the
53
+ * active run terminates, `#drainQueue` schedules the head of the
54
+ * queue as a fresh submit on the next macrotask. Each drained
55
+ * submission has its own `multitaskStrategy` cleared so it doesn't
56
+ * recursively re-enqueue.
57
+ *
58
+ * @see StreamController - The owner; injects every collaborator dep.
59
+ */
60
+ /**
61
+ * Frozen empty queue value used as the initial / cleared snapshot.
62
+ *
63
+ * Reusing one frozen reference keeps store identity stable across
64
+ * empty resets, so React's `useSyncExternalStore` doesn't think the
65
+ * queue changed when it actually didn't.
66
+ */
67
+ const EMPTY_QUEUE = Object.freeze([]);
68
+ /**
69
+ * Coordinates one controller's run-submission lifecycle.
70
+ *
71
+ * The constructor takes a bag of callbacks rather than a reference to
72
+ * the parent {@link StreamController} on purpose:
73
+ *
74
+ * - It keeps the dependency surface explicit and testable — every
75
+ * piece of controller state the submit lifecycle touches is one
76
+ * of these closures.
77
+ * - It avoids a cyclic dependency between controller and coordinator.
78
+ * - Tests can construct one with stub callbacks and assert behavior
79
+ * without mocking the entire controller.
80
+ *
81
+ * @typeParam StateType - Root state shape.
82
+ * @typeParam InterruptType - Root interrupt payload shape.
83
+ * @typeParam ConfigurableType - `config.configurable` shape accepted
84
+ * by submit (usually `Record<string, unknown>`).
85
+ */
86
+ var SubmitCoordinator = class {
87
+ /** Controller-level options forwarded into `submitRun` / callbacks. */
88
+ #options;
89
+ /** Root snapshot store; written for `isLoading`, `error`, `interrupts`. */
90
+ #rootStore;
91
+ /** Pending submissions awaiting the active run to terminate. */
92
+ #queueStore;
93
+ /** Probes the controller's `disposed` flag from deferred work. */
94
+ #getDisposed;
95
+ /** Reads the controller's currently-bound thread id. */
96
+ #getCurrentThreadId;
97
+ /** Updates the controller's thread id (used when minting a new id). */
98
+ #setCurrentThreadId;
99
+ /** Records a thread id we created client-side so hydrate can skip a 404 round-trip. */
100
+ #rememberSelfCreatedThreadId;
101
+ /** Triggers a hydrate on the controller (used by `options.threadId` rebinds). */
102
+ #hydrate;
103
+ /** Lazily creates / returns the active {@link ThreadStream}. */
104
+ #ensureThread;
105
+ /** Resolves once the controller's root subscription pump is up. */
106
+ #waitForRootPumpReady;
107
+ /** Resolves on the next root terminal lifecycle (or on abort). */
108
+ #awaitNextTerminal;
109
+ /** Returns the most recent unresolved root interrupt, for resumes. */
110
+ #latestUnresolvedInterrupt;
111
+ /** Marks an interrupt id as resolved so it isn't re-targeted. */
112
+ #markInterruptResolved;
113
+ /**
114
+ * Active submission's abort controller. `undefined` between submits.
115
+ *
116
+ * Used both for `multitaskStrategy: "rollback"` (abort the previous
117
+ * controller's signal) and `stop()` (abort the current one without
118
+ * starting a new one).
119
+ */
120
+ #runAbort;
121
+ constructor(params) {
122
+ this.#options = params.options;
123
+ this.#rootStore = params.rootStore;
124
+ this.#queueStore = params.queueStore;
125
+ this.#getDisposed = params.getDisposed;
126
+ this.#getCurrentThreadId = params.getCurrentThreadId;
127
+ this.#setCurrentThreadId = params.setCurrentThreadId;
128
+ this.#rememberSelfCreatedThreadId = params.rememberSelfCreatedThreadId;
129
+ this.#hydrate = params.hydrate;
130
+ this.#ensureThread = params.ensureThread;
131
+ this.#waitForRootPumpReady = params.waitForRootPumpReady;
132
+ this.#awaitNextTerminal = params.awaitNextTerminal;
133
+ this.#latestUnresolvedInterrupt = params.latestUnresolvedInterrupt;
134
+ this.#markInterruptResolved = params.markInterruptResolved;
135
+ }
136
+ /**
137
+ * Submit input or a resume command to the active thread.
138
+ *
139
+ * Honours {@link StreamSubmitOptions.multitaskStrategy}:
140
+ *
141
+ * - `"rollback"` (default) — aborts any in-flight run and
142
+ * dispatches immediately.
143
+ * - `"reject"` — throws synchronously when a run is
144
+ * already in flight.
145
+ * - `"enqueue"` — defers via {@link #enqueueSubmission};
146
+ * the call returns without dispatching.
147
+ * - `"interrupt"` — falls through to the default path
148
+ * (server-side cancellation lands with roadmap A0.3).
149
+ *
150
+ * Errors are routed through both the per-submit `onError` callback
151
+ * and `rootStore.error`. Aborts (controller dispose / rollback) are
152
+ * silently dropped.
153
+ *
154
+ * @param input - Input payload, or `null`/`undefined` for no input
155
+ * (typical for resume commands).
156
+ * @param options - Per-submit options (config, metadata, callbacks,
157
+ * strategy, etc).
158
+ */
159
+ async submit(input, options) {
160
+ if (this.#getDisposed()) return;
161
+ const overrideThreadId = options?.threadId;
162
+ if (overrideThreadId !== void 0 && overrideThreadId !== this.#getCurrentThreadId()) await this.#hydrate(overrideThreadId);
163
+ if (this.#getCurrentThreadId() == null) {
164
+ const threadId = (0, uuid.v7)();
165
+ this.#setCurrentThreadId(threadId);
166
+ this.#rememberSelfCreatedThreadId(threadId);
167
+ this.#options.onThreadId?.(threadId);
168
+ this.#rootStore.setState((s) => ({
169
+ ...s,
170
+ threadId
171
+ }));
172
+ }
173
+ const currentThreadId = this.#getCurrentThreadId();
174
+ if (currentThreadId == null) return;
175
+ const thread = this.#ensureThread(currentThreadId);
176
+ const activeThreadId = currentThreadId;
177
+ await this.#waitForRootPumpReady();
178
+ const strategy = options?.multitaskStrategy ?? "rollback";
179
+ const hasActiveRun = this.#runAbort != null && !this.#runAbort.signal.aborted;
180
+ if (hasActiveRun && strategy === "reject") throw new Error("submit() rejected: a run is already in flight and multitaskStrategy is 'reject'.");
181
+ if (hasActiveRun && strategy === "enqueue") {
182
+ this.#enqueueSubmission(input, options);
183
+ return;
184
+ }
185
+ this.#runAbort?.abort();
186
+ const abort = new AbortController();
187
+ this.#runAbort = abort;
188
+ const resumeCommand = options?.command?.resume;
189
+ const isResume = resumeCommand !== void 0;
190
+ this.#rootStore.setState((s) => ({
191
+ ...s,
192
+ interrupts: [],
193
+ interrupt: void 0,
194
+ error: void 0,
195
+ isLoading: true
196
+ }));
197
+ const boundConfig = bindThreadConfig(options?.config, currentThreadId);
198
+ const terminalPromise = this.#awaitNextTerminal(abort.signal);
199
+ let terminalSettled = false;
200
+ const reportError = (error) => {
201
+ if (abort.signal.aborted) return;
202
+ this.#rootStore.setState((s) => ({
203
+ ...s,
204
+ error
205
+ }));
206
+ try {
207
+ options?.onError?.(error);
208
+ } catch {}
209
+ };
210
+ try {
211
+ let terminal;
212
+ if (isResume) {
213
+ const target = this.#latestUnresolvedInterrupt();
214
+ if (target == null) throw new Error("submit({ command: { resume } }) called but no pending protocol interrupt is available.");
215
+ const commandPromise = thread.respondInput({
216
+ namespace: target.namespace,
217
+ interrupt_id: target.interruptId,
218
+ response: resumeCommand
219
+ });
220
+ this.#markInterruptResolved(target.interruptId);
221
+ const first = await Promise.race([terminalPromise.then((value) => ({
222
+ type: "terminal",
223
+ value
224
+ })), commandPromise.then(() => ({ type: "command" }), (error) => ({
225
+ type: "error",
226
+ error
227
+ }))]);
228
+ if (first.type === "error") throw first.error;
229
+ if (first.type === "terminal") {
230
+ terminal = first.value;
231
+ terminalSettled = true;
232
+ commandPromise.catch((error) => {
233
+ if (!terminalSettled) reportError(error);
234
+ });
235
+ }
236
+ } else {
237
+ const commandPromise = thread.submitRun({
238
+ input: input ?? null,
239
+ config: boundConfig,
240
+ metadata: options?.metadata ?? void 0,
241
+ forkFrom: options?.forkFrom,
242
+ multitaskStrategy: options?.multitaskStrategy === "enqueue" ? "enqueue" : options?.multitaskStrategy
243
+ });
244
+ const notifyCreated = (result) => {
245
+ this.#options.onCreated?.({
246
+ run_id: result.run_id,
247
+ thread_id: activeThreadId
248
+ });
249
+ };
250
+ const first = await Promise.race([terminalPromise.then((value) => ({
251
+ type: "terminal",
252
+ value
253
+ })), commandPromise.then((result) => ({
254
+ type: "command",
255
+ result
256
+ }), (error) => ({
257
+ type: "error",
258
+ error
259
+ }))]);
260
+ if (first.type === "error") throw first.error;
261
+ if (first.type === "command") notifyCreated(first.result);
262
+ else {
263
+ terminal = first.value;
264
+ terminalSettled = true;
265
+ commandPromise.then(notifyCreated).catch((error) => {
266
+ if (!terminalSettled) reportError(error);
267
+ });
268
+ }
269
+ }
270
+ terminal ??= await terminalPromise;
271
+ terminalSettled = true;
272
+ if (terminal.event === "failed" && !abort.signal.aborted) {
273
+ const runError = new Error(terminal.error ?? "Run failed with no error message");
274
+ this.#rootStore.setState((s) => ({
275
+ ...s,
276
+ error: runError
277
+ }));
278
+ try {
279
+ options?.onError?.(runError);
280
+ } catch {}
281
+ }
282
+ } catch (error) {
283
+ reportError(error);
284
+ } finally {
285
+ this.#rootStore.setState((s) => ({
286
+ ...s,
287
+ isLoading: false
288
+ }));
289
+ if (this.#runAbort === abort) this.#runAbort = void 0;
290
+ setTimeout(() => this.#drainQueue(), 0);
291
+ }
292
+ }
293
+ /**
294
+ * Abort the current run (if any) and force `isLoading=false`.
295
+ *
296
+ * Does NOT issue a server-side cancel — that lands with roadmap
297
+ * A0.3. Today this is a client-side stop only: subsequent events
298
+ * for the aborted run are ignored by the controller's pump because
299
+ * the abort signal is the same one `#awaitNextTerminal` is wired
300
+ * to.
301
+ */
302
+ async stop() {
303
+ this.abortActiveRun();
304
+ this.#rootStore.setState((s) => ({
305
+ ...s,
306
+ isLoading: false
307
+ }));
308
+ }
309
+ /**
310
+ * Abort the current run without forcing the loading flag down.
311
+ *
312
+ * Used by {@link StreamController.dispose}: disposal already tears
313
+ * down the root store, so flipping `isLoading` here is unnecessary
314
+ * and would race the dispose path.
315
+ */
316
+ abortActiveRun() {
317
+ this.#runAbort?.abort();
318
+ this.#runAbort = void 0;
319
+ }
320
+ /**
321
+ * Cancel a queued submission by id.
322
+ *
323
+ * @param id - Client-side queue entry id to remove.
324
+ * @returns `true` when the entry was found and dropped, `false` otherwise.
325
+ */
326
+ async cancelQueued(id) {
327
+ const current = this.#queueStore.getSnapshot();
328
+ const next = current.filter((entry) => entry.id !== id);
329
+ if (next.length === current.length) return false;
330
+ this.#queueStore.setState(() => next);
331
+ return true;
332
+ }
333
+ /**
334
+ * Drop every queued submission. Server-side cancel arrives with A0.3.
335
+ */
336
+ async clearQueue() {
337
+ this.#queueStore.setState(() => EMPTY_QUEUE);
338
+ }
339
+ /**
340
+ * Append a submission to the queue without dispatching.
341
+ *
342
+ * The drained submission is later run via {@link #drainQueue} after
343
+ * the active run terminates.
344
+ */
345
+ #enqueueSubmission(input, options) {
346
+ const entry = {
347
+ id: (0, uuid.v7)(),
348
+ values: input ?? void 0,
349
+ options,
350
+ createdAt: /* @__PURE__ */ new Date()
351
+ };
352
+ this.#queueStore.setState((current) => [...current, entry]);
353
+ }
354
+ /**
355
+ * Drain the head of the queue if no run is active.
356
+ *
357
+ * Called from the `finally` block of `submit()` on the next
358
+ * macrotask (so the just-finished run's state flushes first).
359
+ * Strips the strategy off the dequeued options to prevent infinite
360
+ * re-enqueueing.
361
+ */
362
+ #drainQueue() {
363
+ if (this.#getDisposed()) return;
364
+ if (this.#runAbort != null && !this.#runAbort.signal.aborted) return;
365
+ const current = this.#queueStore.getSnapshot();
366
+ if (current.length === 0) return;
367
+ const [next, ...rest] = current;
368
+ this.#queueStore.setState(() => rest);
369
+ const nextOptions = {
370
+ ...next.options ?? {},
371
+ multitaskStrategy: void 0
372
+ };
373
+ this.submit(next.values, nextOptions).catch(() => {});
374
+ }
375
+ };
376
+ /**
377
+ * Merge `thread_id` into a user-supplied `config.configurable` blob.
378
+ *
379
+ * The platform expects `config.configurable.thread_id` on every run
380
+ * dispatch; we set it last so user-supplied values can't accidentally
381
+ * override the active thread id (which would route the run to a
382
+ * different thread).
383
+ */
384
+ function bindThreadConfig(config, threadId) {
385
+ const base = config != null && typeof config === "object" ? config : {};
386
+ const configurable = base.configurable != null && typeof base.configurable === "object" ? base.configurable : {};
387
+ return {
388
+ ...base,
389
+ configurable: {
390
+ ...configurable,
391
+ thread_id: threadId
392
+ }
393
+ };
394
+ }
395
+ //#endregion
396
+ exports.EMPTY_QUEUE = EMPTY_QUEUE;
397
+ exports.SubmitCoordinator = SubmitCoordinator;
398
+
399
+ //# sourceMappingURL=submit-coordinator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-coordinator.cjs","names":["#options","#rootStore","#queueStore","#getDisposed","#getCurrentThreadId","#setCurrentThreadId","#rememberSelfCreatedThreadId","#hydrate","#ensureThread","#waitForRootPumpReady","#awaitNextTerminal","#latestUnresolvedInterrupt","#markInterruptResolved","#runAbort","#enqueueSubmission","#drainQueue"],"sources":["../../src/stream/submit-coordinator.ts"],"sourcesContent":["/**\n * Owns the run-submission lifecycle for a single\n * {@link StreamController}.\n *\n * # What this module is\n *\n * The {@link SubmitCoordinator} is the piece of the controller that\n * dispatches runs (`submit()`), enforces multitask strategies, queues\n * deferred submissions, races dispatch against terminal lifecycle\n * events, and surfaces errors back through the per-submit `onError`\n * callback and the root snapshot.\n *\n * Conceptually a submit looks like:\n *\n * 1. Optionally rebind to a different thread (`options.threadId`).\n * 2. Mint a thread id if one isn't bound yet.\n * 3. Wait for the controller's root pump to be ready (so the\n * transport is subscribed before the run is dispatched —\n * otherwise we could miss replayed events).\n * 4. Apply the {@link StreamSubmitOptions.multitaskStrategy} to\n * decide whether to abort, enqueue, reject, or proceed.\n * 5. Race the dispatch promise (`thread.submitRun()` or\n * `thread.respondInput()` for resumes) against the next root\n * terminal lifecycle event.\n * 6. Settle the resulting state (loading flag, error slot) and\n * drain the next queued submission, if any.\n *\n * # Why it lives in its own class\n *\n * The submit lifecycle is the most state-heavy part of the\n * controller — six promises, an abort controller, a queue, a\n * terminal-vs-command race, and bidirectional callback wiring with\n * the controller. Splitting it out keeps `controller.ts` focused on\n * subscription / projection wiring while letting the submit logic\n * evolve independently.\n *\n * # Why we race \"command\" against \"terminal\"\n *\n * For fast runs, the server's terminal lifecycle event can arrive\n * *before* the dispatch HTTP response has resolved. Racing the two\n * lets us detect terminal early and not block waiting for a now-stale\n * dispatch response. The dispatch response is still consumed (via\n * `.then(notifyCreated).catch(reportError)`) so `onCreated` still\n * fires and dispatch errors still surface through `onError`.\n *\n * # Queue semantics (`multitaskStrategy: \"enqueue\"`)\n *\n * When a run is already in flight, an `\"enqueue\"` submit is recorded\n * into {@link queueStore} and the call returns immediately. After the\n * active run terminates, `#drainQueue` schedules the head of the\n * queue as a fresh submit on the next macrotask. Each drained\n * submission has its own `multitaskStrategy` cleared so it doesn't\n * recursively re-enqueue.\n *\n * @see StreamController - The owner; injects every collaborator dep.\n */\nimport { v7 as uuidv7 } from \"uuid\";\nimport type { ThreadStream } from \"../client/stream/index.js\";\nimport { StreamStore } from \"./store.js\";\nimport type {\n RootSnapshot,\n StreamControllerOptions,\n StreamSubmitOptions,\n} from \"./types.js\";\n\n/**\n * Pointer to a pending root protocol interrupt. Used to target\n * `respondInput` for resume submissions.\n */\ninterface ResolvedInterrupt {\n interruptId: string;\n namespace: string[];\n}\n\n/**\n * Result of awaiting the next root terminal lifecycle event. Mirrors\n * the four terminal lifecycle states the protocol surfaces, plus a\n * synthetic `\"aborted\"` for client-side cancellation.\n */\ntype TerminalResult = {\n event: \"completed\" | \"failed\" | \"interrupted\" | \"aborted\";\n error?: string;\n};\n\n/**\n * Queued submission entry mirrored from the server-side run queue.\n *\n * Surfaces the deferred submission to UI consumers via\n * {@link StreamController.queueStore}.\n */\nexport interface SubmissionQueueEntry<\n StateType extends object = Record<string, unknown>,\n> {\n /** Stable id minted on enqueue (uuidv7 — sortable by creation time). */\n readonly id: string;\n /** Original submit input, narrowed to the partial state shape. */\n readonly values: Partial<StateType> | null | undefined;\n /** Original submit options, minus the strategy slot which is reset on drain. */\n readonly options?: StreamSubmitOptions<StateType>;\n /** Wall-clock timestamp at enqueue. */\n readonly createdAt: Date;\n}\n\n/**\n * Read-only snapshot of the queue. The queue store hands this out\n * directly; consumers must not mutate the array.\n */\nexport type SubmissionQueueSnapshot<\n StateType extends object = Record<string, unknown>,\n> = ReadonlyArray<SubmissionQueueEntry<StateType>>;\n\n/**\n * Frozen empty queue value used as the initial / cleared snapshot.\n *\n * Reusing one frozen reference keeps store identity stable across\n * empty resets, so React's `useSyncExternalStore` doesn't think the\n * queue changed when it actually didn't.\n */\nexport const EMPTY_QUEUE: SubmissionQueueSnapshot<never> = Object.freeze([]);\n\n/**\n * Coordinates one controller's run-submission lifecycle.\n *\n * The constructor takes a bag of callbacks rather than a reference to\n * the parent {@link StreamController} on purpose:\n *\n * - It keeps the dependency surface explicit and testable — every\n * piece of controller state the submit lifecycle touches is one\n * of these closures.\n * - It avoids a cyclic dependency between controller and coordinator.\n * - Tests can construct one with stub callbacks and assert behavior\n * without mocking the entire controller.\n *\n * @typeParam StateType - Root state shape.\n * @typeParam InterruptType - Root interrupt payload shape.\n * @typeParam ConfigurableType - `config.configurable` shape accepted\n * by submit (usually `Record<string, unknown>`).\n */\nexport class SubmitCoordinator<\n StateType extends object = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> {\n /** Controller-level options forwarded into `submitRun` / callbacks. */\n readonly #options: StreamControllerOptions<StateType>;\n /** Root snapshot store; written for `isLoading`, `error`, `interrupts`. */\n readonly #rootStore: StreamStore<RootSnapshot<StateType, InterruptType>>;\n /** Pending submissions awaiting the active run to terminate. */\n readonly #queueStore: StreamStore<SubmissionQueueSnapshot<StateType>>;\n /** Probes the controller's `disposed` flag from deferred work. */\n readonly #getDisposed: () => boolean;\n /** Reads the controller's currently-bound thread id. */\n readonly #getCurrentThreadId: () => string | null;\n /** Updates the controller's thread id (used when minting a new id). */\n readonly #setCurrentThreadId: (threadId: string | null) => void;\n /** Records a thread id we created client-side so hydrate can skip a 404 round-trip. */\n readonly #rememberSelfCreatedThreadId: (threadId: string) => void;\n /** Triggers a hydrate on the controller (used by `options.threadId` rebinds). */\n readonly #hydrate: (threadId?: string | null) => Promise<void>;\n /** Lazily creates / returns the active {@link ThreadStream}. */\n readonly #ensureThread: (threadId: string) => ThreadStream;\n /** Resolves once the controller's root subscription pump is up. */\n readonly #waitForRootPumpReady: () => Promise<void> | undefined;\n /** Resolves on the next root terminal lifecycle (or on abort). */\n readonly #awaitNextTerminal: (signal: AbortSignal) => Promise<TerminalResult>;\n /** Returns the most recent unresolved root interrupt, for resumes. */\n readonly #latestUnresolvedInterrupt: () => ResolvedInterrupt | null;\n /** Marks an interrupt id as resolved so it isn't re-targeted. */\n readonly #markInterruptResolved: (interruptId: string) => void;\n\n /**\n * Active submission's abort controller. `undefined` between submits.\n *\n * Used both for `multitaskStrategy: \"rollback\"` (abort the previous\n * controller's signal) and `stop()` (abort the current one without\n * starting a new one).\n */\n #runAbort: AbortController | undefined;\n\n constructor(params: {\n options: StreamControllerOptions<StateType>;\n rootStore: StreamStore<RootSnapshot<StateType, InterruptType>>;\n queueStore: StreamStore<SubmissionQueueSnapshot<StateType>>;\n getDisposed: () => boolean;\n getCurrentThreadId: () => string | null;\n setCurrentThreadId: (threadId: string | null) => void;\n rememberSelfCreatedThreadId: (threadId: string) => void;\n hydrate: (threadId?: string | null) => Promise<void>;\n ensureThread: (threadId: string) => ThreadStream;\n waitForRootPumpReady: () => Promise<void> | undefined;\n awaitNextTerminal: (signal: AbortSignal) => Promise<TerminalResult>;\n latestUnresolvedInterrupt: () => ResolvedInterrupt | null;\n markInterruptResolved: (interruptId: string) => void;\n }) {\n this.#options = params.options;\n this.#rootStore = params.rootStore;\n this.#queueStore = params.queueStore;\n this.#getDisposed = params.getDisposed;\n this.#getCurrentThreadId = params.getCurrentThreadId;\n this.#setCurrentThreadId = params.setCurrentThreadId;\n this.#rememberSelfCreatedThreadId = params.rememberSelfCreatedThreadId;\n this.#hydrate = params.hydrate;\n this.#ensureThread = params.ensureThread;\n this.#waitForRootPumpReady = params.waitForRootPumpReady;\n this.#awaitNextTerminal = params.awaitNextTerminal;\n this.#latestUnresolvedInterrupt = params.latestUnresolvedInterrupt;\n this.#markInterruptResolved = params.markInterruptResolved;\n }\n\n /**\n * Submit input or a resume command to the active thread.\n *\n * Honours {@link StreamSubmitOptions.multitaskStrategy}:\n *\n * - `\"rollback\"` (default) — aborts any in-flight run and\n * dispatches immediately.\n * - `\"reject\"` — throws synchronously when a run is\n * already in flight.\n * - `\"enqueue\"` — defers via {@link #enqueueSubmission};\n * the call returns without dispatching.\n * - `\"interrupt\"` — falls through to the default path\n * (server-side cancellation lands with roadmap A0.3).\n *\n * Errors are routed through both the per-submit `onError` callback\n * and `rootStore.error`. Aborts (controller dispose / rollback) are\n * silently dropped.\n *\n * @param input - Input payload, or `null`/`undefined` for no input\n * (typical for resume commands).\n * @param options - Per-submit options (config, metadata, callbacks,\n * strategy, etc).\n */\n async submit(\n input: unknown,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void> {\n if (this.#getDisposed()) return;\n\n // Per-submit thread override: rebind first so the rest of the\n // submit operates against the new thread.\n const overrideThreadId = options?.threadId;\n if (\n overrideThreadId !== undefined &&\n overrideThreadId !== this.#getCurrentThreadId()\n ) {\n await this.#hydrate(overrideThreadId);\n }\n\n // Self-created thread id path: mint client-side so the controller\n // (and Suspense boundaries) get a stable id even before the run\n // is dispatched.\n if (this.#getCurrentThreadId() == null) {\n const threadId = uuidv7();\n this.#setCurrentThreadId(threadId);\n this.#rememberSelfCreatedThreadId(threadId);\n this.#options.onThreadId?.(threadId);\n this.#rootStore.setState((s) => ({\n ...s,\n threadId,\n }));\n }\n\n const currentThreadId = this.#getCurrentThreadId();\n if (currentThreadId == null) return;\n const thread = this.#ensureThread(currentThreadId);\n const activeThreadId = currentThreadId;\n // Wait for the root subscription to be live; otherwise the\n // dispatch could resolve before we're listening for events and\n // we'd miss the terminal that ends the run.\n await this.#waitForRootPumpReady();\n\n const strategy = options?.multitaskStrategy ?? \"rollback\";\n const hasActiveRun =\n this.#runAbort != null && !this.#runAbort.signal.aborted;\n if (hasActiveRun && strategy === \"reject\") {\n throw new Error(\n \"submit() rejected: a run is already in flight and multitaskStrategy is 'reject'.\"\n );\n }\n if (hasActiveRun && strategy === \"enqueue\") {\n this.#enqueueSubmission(input, options);\n return;\n }\n\n // Rollback: abort the previous run before starting a new one.\n this.#runAbort?.abort();\n const abort = new AbortController();\n this.#runAbort = abort;\n\n const resumeCommand = options?.command?.resume;\n const isResume = resumeCommand !== undefined;\n\n // Optimistically clear interrupts/error and flip loading. The\n // root pump's lifecycle listener will re-flip these as the run\n // terminates.\n this.#rootStore.setState((s) => ({\n ...s,\n interrupts: [],\n interrupt: undefined,\n error: undefined,\n isLoading: true,\n }));\n\n const boundConfig = bindThreadConfig(options?.config, currentThreadId);\n // Subscribe to the next terminal *before* dispatching so a fast\n // run's terminal can't race us.\n const terminalPromise = this.#awaitNextTerminal(abort.signal);\n\n let terminalSettled = false;\n const reportError = (error: unknown): void => {\n if (abort.signal.aborted) return;\n this.#rootStore.setState((s) => ({ ...s, error }));\n try {\n options?.onError?.(error);\n } catch {\n /* caller-supplied callback errors must not crash the submit */\n }\n };\n\n try {\n let terminal: TerminalResult | undefined;\n\n if (isResume) {\n const target = this.#latestUnresolvedInterrupt();\n if (target == null) {\n throw new Error(\n \"submit({ command: { resume } }) called but no pending protocol interrupt is available.\"\n );\n }\n const commandPromise = thread.respondInput({\n namespace: target.namespace,\n interrupt_id: target.interruptId,\n response: resumeCommand,\n });\n // Mark resolved synchronously: even if the response races and\n // the command settles after the terminal, we don't want to\n // re-target this same interrupt on the next submit.\n this.#markInterruptResolved(target.interruptId);\n const first = await Promise.race([\n terminalPromise.then((value) => ({\n type: \"terminal\" as const,\n value,\n })),\n commandPromise.then(\n () => ({ type: \"command\" as const }),\n (error) => ({ type: \"error\" as const, error })\n ),\n ]);\n if (first.type === \"error\") throw first.error;\n if (first.type === \"terminal\") {\n terminal = first.value;\n terminalSettled = true;\n // Stale command response — surface as error only if it\n // arrives with a real failure (not just our own abort).\n void commandPromise.catch((error) => {\n if (!terminalSettled) reportError(error);\n });\n }\n } else {\n const commandPromise = thread.submitRun({\n input: input ?? null,\n config: boundConfig,\n metadata: (options?.metadata ?? undefined) as Record<string, unknown>,\n forkFrom: options?.forkFrom,\n multitaskStrategy:\n options?.multitaskStrategy === \"enqueue\"\n ? \"enqueue\"\n : options?.multitaskStrategy,\n });\n const notifyCreated = (result: { run_id?: unknown }) => {\n this.#options.onCreated?.({\n run_id: result.run_id as string,\n thread_id: activeThreadId,\n });\n };\n const first = await Promise.race([\n terminalPromise.then((value) => ({\n type: \"terminal\" as const,\n value,\n })),\n commandPromise.then(\n (result) => ({ type: \"command\" as const, result }),\n (error) => ({ type: \"error\" as const, error })\n ),\n ]);\n if (first.type === \"error\") throw first.error;\n if (first.type === \"command\") {\n notifyCreated(first.result);\n } else {\n // Terminal landed first (very fast runs). Wait for the\n // dispatch response in the background so onCreated fires\n // and dispatch errors still surface.\n terminal = first.value;\n terminalSettled = true;\n void commandPromise.then(notifyCreated).catch((error) => {\n if (!terminalSettled) reportError(error);\n });\n }\n }\n\n terminal ??= await terminalPromise;\n terminalSettled = true;\n if (terminal.event === \"failed\" && !abort.signal.aborted) {\n const runError = new Error(\n terminal.error ?? \"Run failed with no error message\"\n );\n this.#rootStore.setState((s) => ({ ...s, error: runError }));\n try {\n options?.onError?.(runError);\n } catch {\n /* caller-supplied callback errors must not crash the submit */\n }\n }\n } catch (error) {\n reportError(error);\n } finally {\n // Always settle loading and clear our slot of the abort\n // controller. Schedule queue drain on the next macrotask so any\n // late state updates from this run finish flushing first.\n this.#rootStore.setState((s) => ({ ...s, isLoading: false }));\n if (this.#runAbort === abort) this.#runAbort = undefined;\n setTimeout(() => this.#drainQueue(), 0);\n }\n }\n\n /**\n * Abort the current run (if any) and force `isLoading=false`.\n *\n * Does NOT issue a server-side cancel — that lands with roadmap\n * A0.3. Today this is a client-side stop only: subsequent events\n * for the aborted run are ignored by the controller's pump because\n * the abort signal is the same one `#awaitNextTerminal` is wired\n * to.\n */\n async stop(): Promise<void> {\n this.abortActiveRun();\n this.#rootStore.setState((s) => ({ ...s, isLoading: false }));\n }\n\n /**\n * Abort the current run without forcing the loading flag down.\n *\n * Used by {@link StreamController.dispose}: disposal already tears\n * down the root store, so flipping `isLoading` here is unnecessary\n * and would race the dispose path.\n */\n abortActiveRun(): void {\n this.#runAbort?.abort();\n this.#runAbort = undefined;\n }\n\n /**\n * Cancel a queued submission by id.\n *\n * @param id - Client-side queue entry id to remove.\n * @returns `true` when the entry was found and dropped, `false` otherwise.\n */\n async cancelQueued(id: string): Promise<boolean> {\n const current = this.#queueStore.getSnapshot();\n const next = current.filter((entry) => entry.id !== id);\n if (next.length === current.length) return false;\n this.#queueStore.setState(() => next);\n return true;\n }\n\n /**\n * Drop every queued submission. Server-side cancel arrives with A0.3.\n */\n async clearQueue(): Promise<void> {\n this.#queueStore.setState(\n () => EMPTY_QUEUE as SubmissionQueueSnapshot<StateType>\n );\n }\n\n /**\n * Append a submission to the queue without dispatching.\n *\n * The drained submission is later run via {@link #drainQueue} after\n * the active run terminates.\n */\n #enqueueSubmission(\n input: unknown,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): void {\n const entry: SubmissionQueueEntry<StateType> = {\n id: uuidv7(),\n values: (input ?? undefined) as Partial<StateType> | null | undefined,\n options: options as StreamSubmitOptions<StateType> | undefined,\n createdAt: new Date(),\n };\n this.#queueStore.setState((current) => [...current, entry]);\n }\n\n /**\n * Drain the head of the queue if no run is active.\n *\n * Called from the `finally` block of `submit()` on the next\n * macrotask (so the just-finished run's state flushes first).\n * Strips the strategy off the dequeued options to prevent infinite\n * re-enqueueing.\n */\n #drainQueue(): void {\n if (this.#getDisposed()) return;\n if (this.#runAbort != null && !this.#runAbort.signal.aborted) return;\n const current = this.#queueStore.getSnapshot();\n if (current.length === 0) return;\n const [next, ...rest] = current;\n this.#queueStore.setState(() => rest);\n const nextOptions: StreamSubmitOptions<StateType, ConfigurableType> = {\n ...((next.options ?? {}) as StreamSubmitOptions<\n StateType,\n ConfigurableType\n >),\n multitaskStrategy: undefined,\n };\n void this.submit(next.values, nextOptions).catch(() => {\n /* submit() already routes errors through the per-submit onError\n * hook and the root store; swallow here so a failing drain does\n * not surface as an unhandled rejection. */\n });\n }\n}\n\n/**\n * Merge `thread_id` into a user-supplied `config.configurable` blob.\n *\n * The platform expects `config.configurable.thread_id` on every run\n * dispatch; we set it last so user-supplied values can't accidentally\n * override the active thread id (which would route the run to a\n * different thread).\n */\nfunction bindThreadConfig(\n config: unknown,\n threadId: string\n): Record<string, unknown> {\n const base =\n config != null && typeof config === \"object\"\n ? (config as Record<string, unknown>)\n : {};\n const configurable =\n base.configurable != null && typeof base.configurable === \"object\"\n ? (base.configurable as Record<string, unknown>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O,WAAW,WAC/B,SACD,EAAE;CACR,MAAM,eACJ,KAAK,gBAAgB,QAAQ,OAAO,KAAK,iBAAiB,WACrD,KAAK,eACN,EAAE;AACR,QAAO;EACL,GAAG;EACH,cAAc;GACZ,GAAG;GACH,WAAW;GACZ;EACF"}
@@ -0,0 +1,27 @@
1
+ import { StreamSubmitOptions } from "./types.cjs";
2
+
3
+ //#region src/stream/submit-coordinator.d.ts
4
+ /**
5
+ * Queued submission entry mirrored from the server-side run queue.
6
+ *
7
+ * Surfaces the deferred submission to UI consumers via
8
+ * {@link StreamController.queueStore}.
9
+ */
10
+ interface SubmissionQueueEntry<StateType extends object = Record<string, unknown>> {
11
+ /** Stable id minted on enqueue (uuidv7 — sortable by creation time). */
12
+ readonly id: string;
13
+ /** Original submit input, narrowed to the partial state shape. */
14
+ readonly values: Partial<StateType> | null | undefined;
15
+ /** Original submit options, minus the strategy slot which is reset on drain. */
16
+ readonly options?: StreamSubmitOptions<StateType>;
17
+ /** Wall-clock timestamp at enqueue. */
18
+ readonly createdAt: Date;
19
+ }
20
+ /**
21
+ * Read-only snapshot of the queue. The queue store hands this out
22
+ * directly; consumers must not mutate the array.
23
+ */
24
+ type SubmissionQueueSnapshot<StateType extends object = Record<string, unknown>> = ReadonlyArray<SubmissionQueueEntry<StateType>>;
25
+ //#endregion
26
+ export { SubmissionQueueEntry, SubmissionQueueSnapshot };
27
+ //# sourceMappingURL=submit-coordinator.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-coordinator.d.cts","names":[],"sources":["../../src/stream/submit-coordinator.ts"],"mappings":";;;;;;;;;UA0FiB,oBAAA,4BACY,MAAA;EAgBjB;EAAA,SAbD,EAAA;EAawB;EAAA,SAXxB,MAAA,EAAQ,OAAA,CAAQ,SAAA;EAaY;EAAA,SAX5B,OAAA,GAAU,mBAAA,CAAoB,SAAA;EAWrC;EAAA,SATO,SAAA,EAAW,IAAA;AAAA;;;;;KAOV,uBAAA,4BACiB,MAAA,qBACzB,aAAA,CAAc,oBAAA,CAAqB,SAAA"}
@@ -0,0 +1,27 @@
1
+ import { StreamSubmitOptions } from "./types.js";
2
+
3
+ //#region src/stream/submit-coordinator.d.ts
4
+ /**
5
+ * Queued submission entry mirrored from the server-side run queue.
6
+ *
7
+ * Surfaces the deferred submission to UI consumers via
8
+ * {@link StreamController.queueStore}.
9
+ */
10
+ interface SubmissionQueueEntry<StateType extends object = Record<string, unknown>> {
11
+ /** Stable id minted on enqueue (uuidv7 — sortable by creation time). */
12
+ readonly id: string;
13
+ /** Original submit input, narrowed to the partial state shape. */
14
+ readonly values: Partial<StateType> | null | undefined;
15
+ /** Original submit options, minus the strategy slot which is reset on drain. */
16
+ readonly options?: StreamSubmitOptions<StateType>;
17
+ /** Wall-clock timestamp at enqueue. */
18
+ readonly createdAt: Date;
19
+ }
20
+ /**
21
+ * Read-only snapshot of the queue. The queue store hands this out
22
+ * directly; consumers must not mutate the array.
23
+ */
24
+ type SubmissionQueueSnapshot<StateType extends object = Record<string, unknown>> = ReadonlyArray<SubmissionQueueEntry<StateType>>;
25
+ //#endregion
26
+ export { SubmissionQueueEntry, SubmissionQueueSnapshot };
27
+ //# sourceMappingURL=submit-coordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-coordinator.d.ts","names":[],"sources":["../../src/stream/submit-coordinator.ts"],"mappings":";;;;;;;;;UA0FiB,oBAAA,4BACY,MAAA;EASH;EAAA,SANf,EAAA;EAawB;EAAA,SAXxB,MAAA,EAAQ,OAAA,CAAQ,SAAA;EAYE;EAAA,SAVlB,OAAA,GAAU,mBAAA,CAAoB,SAAA;EAWvB;EAAA,SATP,SAAA,EAAW,IAAA;AAAA;;;;;KAOV,uBAAA,4BACiB,MAAA,qBACzB,aAAA,CAAc,oBAAA,CAAqB,SAAA"}