@langchain/langgraph-sdk 1.8.9 → 1.9.0

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 (444) 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 +8 -6
  212. package/dist/react/stream.lgp.cjs.map +1 -1
  213. package/dist/react/stream.lgp.js +6 -4
  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 +2 -2
  397. package/dist/ui/manager.cjs.map +1 -1
  398. package/dist/ui/manager.d.cts +1 -0
  399. package/dist/ui/manager.d.cts.map +1 -1
  400. package/dist/ui/manager.d.ts +1 -0
  401. package/dist/ui/manager.d.ts.map +1 -1
  402. package/dist/ui/manager.js +2 -2
  403. package/dist/ui/manager.js.map +1 -1
  404. package/dist/ui/messages.cjs +50 -7
  405. package/dist/ui/messages.cjs.map +1 -1
  406. package/dist/ui/messages.d.cts.map +1 -1
  407. package/dist/ui/messages.d.ts.map +1 -1
  408. package/dist/ui/messages.js +51 -9
  409. package/dist/ui/messages.js.map +1 -1
  410. package/dist/ui/orchestrator-custom.cjs +1 -1
  411. package/dist/ui/orchestrator-custom.js +1 -1
  412. package/dist/ui/orchestrator.cjs +4 -3
  413. package/dist/ui/orchestrator.cjs.map +1 -1
  414. package/dist/ui/orchestrator.d.cts +1 -1
  415. package/dist/ui/orchestrator.d.cts.map +1 -1
  416. package/dist/ui/orchestrator.d.ts +1 -1
  417. package/dist/ui/orchestrator.d.ts.map +1 -1
  418. package/dist/ui/orchestrator.js +4 -3
  419. package/dist/ui/orchestrator.js.map +1 -1
  420. package/dist/ui/stream/agent.d.cts +1 -1
  421. package/dist/ui/stream/agent.d.cts.map +1 -1
  422. package/dist/ui/stream/agent.d.ts +1 -1
  423. package/dist/ui/stream/agent.d.ts.map +1 -1
  424. package/dist/ui/stream/base.d.cts +7 -6
  425. package/dist/ui/stream/base.d.cts.map +1 -1
  426. package/dist/ui/stream/base.d.ts +7 -6
  427. package/dist/ui/stream/base.d.ts.map +1 -1
  428. package/dist/ui/stream/deep-agent.d.cts +1 -1
  429. package/dist/ui/stream/deep-agent.d.cts.map +1 -1
  430. package/dist/ui/stream/deep-agent.d.ts +1 -1
  431. package/dist/ui/stream/deep-agent.d.ts.map +1 -1
  432. package/dist/ui/stream/index.d.cts +4 -4
  433. package/dist/ui/stream/index.d.cts.map +1 -1
  434. package/dist/ui/stream/index.d.ts +4 -4
  435. package/dist/ui/stream/index.d.ts.map +1 -1
  436. package/dist/ui/types.d.cts +3 -2
  437. package/dist/ui/types.d.cts.map +1 -1
  438. package/dist/ui/types.d.ts +2 -1
  439. package/dist/ui/types.d.ts.map +1 -1
  440. package/package.json +18 -8
  441. package/dist/client.cjs.map +0 -1
  442. package/dist/client.d.cts.map +0 -1
  443. package/dist/client.d.ts.map +0 -1
  444. package/dist/client.js.map +0 -1
@@ -0,0 +1,933 @@
1
+ const require_messages = require("../ui/messages.cjs");
2
+ const require_tools = require("../client/stream/handles/tools.cjs");
3
+ const require_store = require("./store.cjs");
4
+ const require_channel_registry = require("./channel-registry.cjs");
5
+ const require_namespace = require("./namespace.cjs");
6
+ const require_subagents = require("./discovery/subagents.cjs");
7
+ const require_subgraphs = require("./discovery/subgraphs.cjs");
8
+ const require_message_metadata_tracker = require("./message-metadata-tracker.cjs");
9
+ const require_lifecycle_loading_tracker = require("./lifecycle-loading-tracker.cjs");
10
+ const require_root_message_projection = require("./root-message-projection.cjs");
11
+ const require_submit_coordinator = require("./submit-coordinator.cjs");
12
+ const require_tool_calls = require("./tool-calls.cjs");
13
+ require("@langchain/core/messages");
14
+ //#region src/stream/controller.ts
15
+ /**
16
+ * Framework-agnostic controller for the experimental v2 stream.
17
+ *
18
+ * Responsibilities:
19
+ * - Owns at most one {@link ThreadStream} at a time (swapped on
20
+ * `hydrate(newThreadId)` or `dispose`).
21
+ * - Exposes three always-on observable surfaces via {@link StreamStore}:
22
+ * - `rootStore` : root values/messages/toolCalls/interrupts/…
23
+ * - `subagentStore` : discovery map of subagents (no content)
24
+ * - `subgraphStore` : discovery map of subgraphs (no content)
25
+ * - Owns a {@link ChannelRegistry} that framework selector hooks
26
+ * (`useMessages`, `useToolCalls`, `useExtension`, `useChannel`)
27
+ * use to lazily open per-namespace subscriptions.
28
+ * - Imperative run surface: `submit`, `stop`, `respond`, `joinStream`.
29
+ *
30
+ * A single multi-channel subscription (`values`, `lifecycle`, `input`,
31
+ * `messages`, `tools`) powers every always-on projection and both
32
+ * discovery runners. Selector hooks add their own (deduped)
33
+ * subscriptions on top — so even a UI with many subagents only opens
34
+ * one extra subscription per `(channels, namespace)` actually
35
+ * rendered on screen.
36
+ */
37
+ function isAbortLikeError(error) {
38
+ if (error == null || typeof error !== "object") return false;
39
+ const maybeError = error;
40
+ return maybeError.name === "AbortError" || typeof maybeError.message === "string" && maybeError.message.includes("aborted");
41
+ }
42
+ const ROOT_NAMESPACE = [];
43
+ /**
44
+ * Channel set covered by the always-on root subscription. Exported so
45
+ * projections (and transports) can reason about what the root pump
46
+ * already delivers before opening additional server subscriptions.
47
+ */
48
+ const ROOT_PUMP_CHANNELS = [
49
+ "values",
50
+ "checkpoints",
51
+ "lifecycle",
52
+ "input",
53
+ "messages",
54
+ "tools"
55
+ ];
56
+ /**
57
+ * Coordinates one thread's protocol-v2 stream and exposes stable
58
+ * observable projections for framework bindings.
59
+ *
60
+ * The controller owns the root subscription, lazily binds scoped
61
+ * projections through {@link ChannelRegistry}, and normalizes protocol
62
+ * events into class-message, tool-call, discovery, interrupt, and queue
63
+ * stores.
64
+ *
65
+ * @typeParam StateType - Shape of the graph state exposed on `values`.
66
+ * @typeParam InterruptType - Shape of protocol interrupt payloads.
67
+ * @typeParam ConfigurableType - Shape of `config.configurable` accepted by submit.
68
+ */
69
+ var StreamController = class {
70
+ rootStore;
71
+ subagentStore;
72
+ subgraphStore;
73
+ subgraphByNodeStore;
74
+ messageMetadataStore;
75
+ queueStore;
76
+ registry;
77
+ #options;
78
+ #messagesKey;
79
+ #subagents = new require_subagents.SubagentDiscovery();
80
+ #subgraphs = new require_subgraphs.SubgraphDiscovery();
81
+ #messageMetadata = new require_message_metadata_tracker.MessageMetadataTracker();
82
+ #thread;
83
+ #currentThreadId;
84
+ #rootSubscription;
85
+ #rootPump;
86
+ #rootPumpReady;
87
+ #threadEventUnsubscribe;
88
+ #disposed = false;
89
+ #pendingDisposeTimer = null;
90
+ #resolvedInterrupts = /* @__PURE__ */ new Set();
91
+ /**
92
+ * Thread ids we minted client-side on first `submit()`. Keeping them
93
+ * here lets `hydrate()` skip the `threads.getState()` round-trip —
94
+ * we know there is nothing checkpointed server-side yet (and the
95
+ * request would 404 and surface a spurious error to the UI).
96
+ */
97
+ #selfCreatedThreadIds = /* @__PURE__ */ new Set();
98
+ #rootEventListeners = /* @__PURE__ */ new Set();
99
+ #rootBus;
100
+ /**
101
+ * Single-shot hydration promise. Exposed via `hydrationPromise`
102
+ * so Suspense wrappers can throw it until the first hydrate
103
+ * completes (resolve) or fails (reject). Reset whenever a new
104
+ * hydrate cycle begins so `<Suspense>` boundaries re-suspend on
105
+ * thread switch.
106
+ */
107
+ #hydrationPromise;
108
+ #resolveHydration;
109
+ #rejectHydration;
110
+ /**
111
+ * Tool assembler lives for the lifetime of a thread; reset on
112
+ * rebind so a fresh thread starts with a clean slate.
113
+ */
114
+ #rootToolAssembler = new require_tools.ToolCallAssembler();
115
+ #rootMessages;
116
+ #lifecycleLoading;
117
+ #submitter;
118
+ #threadListeners = /* @__PURE__ */ new Set();
119
+ /**
120
+ * Create a controller around a LangGraph client and optional initial thread.
121
+ *
122
+ * @param options - Runtime configuration, client, thread id, and initial state.
123
+ */
124
+ constructor(options) {
125
+ this.#options = options;
126
+ this.#messagesKey = options.messagesKey ?? "messages";
127
+ this.#currentThreadId = options.threadId ?? null;
128
+ this.#rootBus = {
129
+ channels: ROOT_PUMP_CHANNELS,
130
+ subscribe: (listener) => {
131
+ this.#rootEventListeners.add(listener);
132
+ return () => {
133
+ this.#rootEventListeners.delete(listener);
134
+ };
135
+ }
136
+ };
137
+ this.registry = new require_channel_registry.ChannelRegistry(this.#rootBus);
138
+ this.subagentStore = this.#subagents.store;
139
+ this.subgraphStore = this.#subgraphs.store;
140
+ this.subgraphByNodeStore = this.#subgraphs.byNodeStore;
141
+ this.rootStore = new require_store.StreamStore(this.#createInitialSnapshot());
142
+ this.#rootMessages = new require_root_message_projection.RootMessageProjection({
143
+ messagesKey: this.#messagesKey,
144
+ store: this.rootStore,
145
+ subagents: this.#subagents
146
+ });
147
+ this.#lifecycleLoading = new require_lifecycle_loading_tracker.LifecycleLoadingTracker({
148
+ store: this.rootStore,
149
+ isDisposed: () => this.#disposed
150
+ });
151
+ this.messageMetadataStore = this.#messageMetadata.store;
152
+ this.queueStore = new require_store.StreamStore(require_submit_coordinator.EMPTY_QUEUE);
153
+ this.#submitter = new require_submit_coordinator.SubmitCoordinator({
154
+ options: this.#options,
155
+ rootStore: this.rootStore,
156
+ queueStore: this.queueStore,
157
+ getDisposed: () => this.#disposed,
158
+ getCurrentThreadId: () => this.#currentThreadId,
159
+ setCurrentThreadId: (threadId) => {
160
+ this.#currentThreadId = threadId;
161
+ },
162
+ rememberSelfCreatedThreadId: (threadId) => {
163
+ this.#selfCreatedThreadIds.add(threadId);
164
+ },
165
+ hydrate: (threadId) => this.hydrate(threadId),
166
+ ensureThread: (threadId) => this.#ensureThread(threadId),
167
+ waitForRootPumpReady: () => this.#rootPumpReady,
168
+ awaitNextTerminal: (signal) => this.#awaitNextTerminal(signal),
169
+ latestUnresolvedInterrupt: () => this.#latestUnresolvedInterrupt(),
170
+ markInterruptResolved: (interruptId) => {
171
+ this.#resolvedInterrupts.add(interruptId);
172
+ }
173
+ });
174
+ this.#hydrationPromise = this.#createHydrationPromise();
175
+ /**
176
+ * Attach a default no-op catch so orphaned hydrationPromise
177
+ * rejections (e.g. controllers spawned during Suspense retries
178
+ * whose promise never gets subscribed to because the suspense
179
+ * cache already holds an earlier one) don't surface as unhandled
180
+ * rejections. Callers that attach their own handlers via .then()
181
+ * still receive the rejection on their derived promise.
182
+ */
183
+ this.#hydrationPromise.catch(() => void 0);
184
+ /**
185
+ * Kick off the initial hydrate eagerly when a caller-supplied
186
+ * thread id is present. Suspense consumers throw
187
+ * `hydrationPromise` on the very first render, which unmounts the
188
+ * subtree before any `useEffect` can run — so if we waited for an
189
+ * effect to drive the hydrate we'd deadlock. Firing here makes
190
+ * the promise settle independently of the component lifecycle.
191
+ */
192
+ if (this.#currentThreadId != null) this.hydrate(this.#currentThreadId);
193
+ else this.#resolveHydration();
194
+ }
195
+ /**
196
+ * Promise that settles the first time {@link hydrate} finishes on
197
+ * the current thread. Resolves on a clean hydration, rejects when
198
+ * the thread-state fetch errors. A fresh promise is installed on
199
+ * every thread swap so `<Suspense>` wrappers re-suspend on
200
+ * `switchThread`.
201
+ */
202
+ get hydrationPromise() {
203
+ return this.#hydrationPromise;
204
+ }
205
+ /**
206
+ * Create the deferred promise backing the current hydration cycle.
207
+ */
208
+ #createHydrationPromise() {
209
+ return new Promise((resolve, reject) => {
210
+ this.#resolveHydration = resolve;
211
+ this.#rejectHydration = reject;
212
+ });
213
+ }
214
+ /**
215
+ * Replace the current hydration promise before a thread swap.
216
+ */
217
+ #resetHydrationPromise() {
218
+ /**
219
+ * Swallow rejection on the orphaned promise so Node doesn't
220
+ * flag it as unhandled; Suspense callers that still hold a
221
+ * reference see the rejection they subscribed to.
222
+ */
223
+ this.#hydrationPromise.catch(() => void 0);
224
+ this.#hydrationPromise = this.#createHydrationPromise();
225
+ }
226
+ /**
227
+ * Fetch the checkpointed thread state and seed the root snapshot.
228
+ * Re-calling with a different `threadId` swaps the underlying
229
+ * {@link ThreadStream}, rewires the registry to the new thread, and
230
+ * resets assemblers.
231
+ *
232
+ * @param threadId - Optional replacement thread id; `null` clears the active thread.
233
+ */
234
+ async hydrate(threadId) {
235
+ if (this.#disposed) return;
236
+ const target = threadId === void 0 ? this.#currentThreadId : threadId;
237
+ const changed = target !== this.#currentThreadId;
238
+ this.#currentThreadId = target ?? null;
239
+ this.rootStore.setState((s) => ({
240
+ ...s,
241
+ threadId: this.#currentThreadId
242
+ }));
243
+ if (changed) {
244
+ /**
245
+ * Swap to a new thread: re-arm the hydration promise so any
246
+ * Suspense boundary remounted against the new id suspends again.
247
+ */
248
+ this.#resetHydrationPromise();
249
+ await this.#teardownThread();
250
+ /**
251
+ * Reset UI-facing snapshot so stale messages/values/tool-calls
252
+ * from the previous thread don't bleed into the new one. The
253
+ * new thread's state (if any) is then populated below via
254
+ * `#applyValues`.
255
+ */
256
+ this.rootStore.setState(() => ({
257
+ ...this.#createInitialSnapshot(),
258
+ threadId: this.#currentThreadId
259
+ }));
260
+ /**
261
+ * Drop queued submissions — they were targeted at the previous
262
+ * thread so dispatching them against the new thread would be
263
+ * surprising. Mirrors the legacy `StreamOrchestrator` behaviour.
264
+ */
265
+ this.queueStore.setState(() => require_submit_coordinator.EMPTY_QUEUE);
266
+ }
267
+ if (this.#currentThreadId == null) {
268
+ this.rootStore.setState((s) => ({
269
+ ...s,
270
+ isThreadLoading: false
271
+ }));
272
+ this.#resolveHydration();
273
+ return;
274
+ }
275
+ /**
276
+ * Self-generated thread ids have nothing to fetch server-side yet
277
+ * — the thread is created lazily by the first `run.start`. Calling
278
+ * `threads.getState()` here would return a 404 and surface a
279
+ * spurious error to the UI.
280
+ */
281
+ if (this.#selfCreatedThreadIds.has(this.#currentThreadId)) {
282
+ this.rootStore.setState((s) => ({
283
+ ...s,
284
+ isThreadLoading: false
285
+ }));
286
+ this.#resolveHydration();
287
+ return;
288
+ }
289
+ this.rootStore.setState((s) => ({
290
+ ...s,
291
+ isThreadLoading: true
292
+ }));
293
+ let hydrationError;
294
+ try {
295
+ const state = await this.#options.client.threads.getState(this.#currentThreadId);
296
+ if (state?.values != null) {
297
+ /**
298
+ * `threads.getState()` returns the legacy `ThreadState` shape
299
+ * where `parent_checkpoint` is an object (`{ thread_id,
300
+ * checkpoint_id, checkpoint_ns }`). Synthesize the v2
301
+ * `Checkpoint` envelope (matching the `checkpoints` channel
302
+ * payload) so hydrated messages also get their
303
+ * `parentCheckpointId` populated for fork / edit flows.
304
+ */
305
+ const checkpointId = state.checkpoint?.checkpoint_id;
306
+ const parentCheckpointId = state.parent_checkpoint?.checkpoint_id ?? void 0;
307
+ const syntheticCheckpoint = typeof checkpointId === "string" ? {
308
+ id: checkpointId,
309
+ ...parentCheckpointId != null ? { parent_id: parentCheckpointId } : {}
310
+ } : void 0;
311
+ this.#applyValues(state.values, syntheticCheckpoint);
312
+ }
313
+ } catch (error) {
314
+ if (error?.status !== 404) {
315
+ hydrationError = error;
316
+ this.rootStore.setState((s) => ({
317
+ ...s,
318
+ error
319
+ }));
320
+ }
321
+ } finally {
322
+ this.rootStore.setState((s) => ({
323
+ ...s,
324
+ isThreadLoading: false
325
+ }));
326
+ if (hydrationError != null) this.#rejectHydration(hydrationError);
327
+ else this.#resolveHydration();
328
+ }
329
+ /**
330
+ * P0 fix: open the shared subscription on mount so in-flight
331
+ * server-side runs are observed even when no local `submit()` is
332
+ * active. The transport replays the run from `seq=0` on a rotating
333
+ * subscribe, so late-joining is free once the subscription exists.
334
+ * `isLoading` transitions are driven by the persistent root
335
+ * lifecycle listener registered in `#startRootPump`.
336
+ */
337
+ this.#ensureThread(this.#currentThreadId);
338
+ }
339
+ /**
340
+ * Submit input or a resume command to the active thread.
341
+ *
342
+ * @param input - Input payload for a new run; `null`/`undefined` submits no input.
343
+ * @param options - Per-run config, metadata, multitask behavior, and callbacks.
344
+ */
345
+ async submit(input, options) {
346
+ await this.#submitter.submit(input, options);
347
+ }
348
+ /**
349
+ * Abort the currently tracked run and mark the controller idle.
350
+ */
351
+ async stop() {
352
+ await this.#submitter.stop();
353
+ }
354
+ /**
355
+ * Cancel a queued submission by id. Returns `true` when the entry
356
+ * was found and removed, `false` otherwise.
357
+ *
358
+ * Today this only removes the entry from the client-side mirror —
359
+ * once the server exposes queue cancel (roadmap A0.3) the
360
+ * controller will additionally issue a cancel call against the
361
+ * active transport.
362
+ *
363
+ * @param id - Client-side queue entry id to remove.
364
+ */
365
+ async cancelQueued(id) {
366
+ return this.#submitter.cancelQueued(id);
367
+ }
368
+ /**
369
+ * Drop every queued submission. Server-side cancel arrives with A0.3.
370
+ */
371
+ async clearQueue() {
372
+ await this.#submitter.clearQueue();
373
+ }
374
+ /**
375
+ * Respond to a pending protocol interrupt.
376
+ *
377
+ * @param response - Payload to send back to the interrupted namespace.
378
+ * @param target - Optional explicit interrupt id and namespace; defaults to the latest unresolved interrupt.
379
+ */
380
+ async respond(response, target) {
381
+ if (this.#disposed || this.#thread == null) throw new Error("No active thread to respond to.");
382
+ const resolved = target != null ? {
383
+ interruptId: target.interruptId,
384
+ namespace: target.namespace ?? [...ROOT_NAMESPACE]
385
+ } : this.#latestUnresolvedInterrupt();
386
+ if (resolved == null) throw new Error("No pending interrupt to respond to.");
387
+ try {
388
+ await this.#thread.respondInput({
389
+ namespace: resolved.namespace,
390
+ interrupt_id: resolved.interruptId,
391
+ response
392
+ });
393
+ this.#resolvedInterrupts.add(resolved.interruptId);
394
+ } catch (error) {
395
+ if (this.#disposed && isAbortLikeError(error)) return;
396
+ throw error;
397
+ }
398
+ }
399
+ /**
400
+ * Dispose the active thread, subscriptions, registry entries, and listeners.
401
+ */
402
+ async dispose() {
403
+ if (this.#disposed) return;
404
+ this.#cancelPendingDispose();
405
+ this.#disposed = true;
406
+ this.#submitter.abortActiveRun();
407
+ await this.#teardownThread();
408
+ await this.registry.dispose();
409
+ this.#threadListeners.clear();
410
+ }
411
+ /**
412
+ * StrictMode-safe lifecycle hook for framework bindings.
413
+ *
414
+ * React 18+ `StrictMode` intentionally mounts → unmounts → remounts
415
+ * components in dev to surface effect-cleanup bugs. A naive
416
+ * `useEffect(() => () => controller.dispose())` would permanently
417
+ * tear the controller down on that first synthetic unmount, leaving
418
+ * every subsequent `submit()` a silent no-op.
419
+ *
420
+ * Call {@link activate} from the bind site's effect and return the
421
+ * result as the effect's cleanup. The controller uses deferred
422
+ * disposal: a `release()` only schedules a dispose on the next
423
+ * microtask, which is cancelled if another `activate()` arrives
424
+ * before it fires (the normal StrictMode remount path).
425
+ */
426
+ activate() {
427
+ this.#cancelPendingDispose();
428
+ return () => {
429
+ if (this.#disposed) return;
430
+ this.#pendingDisposeTimer = setTimeout(() => {
431
+ this.#pendingDisposeTimer = null;
432
+ this.dispose().catch(() => void 0);
433
+ }, 0);
434
+ };
435
+ }
436
+ /**
437
+ * Cancel a deferred dispose scheduled by {@link activate}.
438
+ */
439
+ #cancelPendingDispose() {
440
+ if (this.#pendingDisposeTimer != null) {
441
+ clearTimeout(this.#pendingDisposeTimer);
442
+ this.#pendingDisposeTimer = null;
443
+ }
444
+ }
445
+ /**
446
+ * Current underlying {@link ThreadStream} (v2 escape hatch).
447
+ */
448
+ getThread() {
449
+ return this.#thread;
450
+ }
451
+ /**
452
+ * Listen for `ThreadStream` lifecycle (swap on thread-id change,
453
+ * detach on dispose). The listener fires immediately with the
454
+ * current thread (may be `undefined`).
455
+ *
456
+ * @param listener - Callback invoked immediately and on every thread swap.
457
+ */
458
+ subscribeThread(listener) {
459
+ this.#threadListeners.add(listener);
460
+ listener(this.#thread);
461
+ return () => {
462
+ this.#threadListeners.delete(listener);
463
+ };
464
+ }
465
+ /**
466
+ * Build the initial root snapshot from configured initial values.
467
+ */
468
+ #createInitialSnapshot() {
469
+ const values = this.#options.initialValues ?? {};
470
+ return {
471
+ values,
472
+ messages: extractAndCoerceMessages(values, this.#messagesKey),
473
+ toolCalls: [],
474
+ interrupts: [],
475
+ interrupt: void 0,
476
+ isLoading: false,
477
+ isThreadLoading: this.#currentThreadId != null && !this.#selfCreatedThreadIds.has(this.#currentThreadId),
478
+ error: void 0,
479
+ threadId: this.#currentThreadId
480
+ };
481
+ }
482
+ /**
483
+ * Return the active thread stream, creating and binding one when needed.
484
+ *
485
+ * @param threadId - Thread id used when constructing the stream.
486
+ */
487
+ #ensureThread(threadId) {
488
+ if (this.#thread != null) return this.#thread;
489
+ this.#thread = this.#options.client.threads.stream(threadId, {
490
+ assistantId: this.#options.assistantId,
491
+ transport: this.#options.transport,
492
+ fetch: this.#options.fetch,
493
+ webSocketFactory: this.#options.webSocketFactory
494
+ });
495
+ this.registry.bind(this.#thread);
496
+ this.#startRootPump(this.#thread);
497
+ this.#notifyThreadListeners();
498
+ return this.#thread;
499
+ }
500
+ /**
501
+ * Close the current thread stream and reset per-thread assembly state.
502
+ */
503
+ async #teardownThread() {
504
+ const thread = this.#thread;
505
+ this.#thread = void 0;
506
+ this.registry.bind(void 0);
507
+ this.#threadEventUnsubscribe?.();
508
+ this.#threadEventUnsubscribe = void 0;
509
+ /**
510
+ * Persistent lifecycle driver is scoped to the current thread
511
+ * stream. Remove it so a swap to a new thread starts with a clean
512
+ * listener set (a new one is installed in `#startRootPump`).
513
+ */
514
+ this.#rootEventListeners.delete(this.#lifecycleLoading.listener);
515
+ try {
516
+ await this.#rootSubscription?.unsubscribe();
517
+ } catch {}
518
+ this.#rootSubscription = void 0;
519
+ this.#rootPumpReady = void 0;
520
+ try {
521
+ await this.#rootPump;
522
+ } catch {}
523
+ this.#rootPump = void 0;
524
+ this.#rootMessages.reset();
525
+ this.#rootToolAssembler = new require_tools.ToolCallAssembler();
526
+ this.#lifecycleLoading.reset();
527
+ this.#messageMetadata.reset();
528
+ this.queueStore.setState(() => require_submit_coordinator.EMPTY_QUEUE);
529
+ if (thread != null) {
530
+ try {
531
+ await thread.close();
532
+ } catch {}
533
+ this.#notifyThreadListeners();
534
+ }
535
+ }
536
+ /**
537
+ * Determine whether the configured transport uses the resumable event-stream path.
538
+ */
539
+ #usesEventStreamTransport() {
540
+ const transport = this.#options.transport;
541
+ if (transport === "websocket") return false;
542
+ if (transport == null || transport === "sse") return true;
543
+ return typeof transport.openEventStream === "function";
544
+ }
545
+ /**
546
+ * Start the always-on root subscription pump for the provided thread.
547
+ *
548
+ * @param thread - Thread stream to subscribe to and fan out from.
549
+ */
550
+ #startRootPump(thread) {
551
+ if (this.#rootPump != null) return;
552
+ let resolveReady;
553
+ this.#rootPumpReady = new Promise((resolve) => {
554
+ resolveReady = resolve;
555
+ });
556
+ /**
557
+ * Wildcard discovery + interrupt tracking is delivered via the
558
+ * thread's dedicated lifecycle watcher (see `ThreadStream.onEvent`).
559
+ * This callback fires once per globally-unique event across both
560
+ * the content pump AND the watcher, so we can drive discovery
561
+ * runners and nested HITL capture without widening the content
562
+ * pump's narrow filter.
563
+ */
564
+ this.#threadEventUnsubscribe = thread.onEvent((event) => this.#onWildcardEvent(event));
565
+ /**
566
+ * Persistent isLoading driver. Drives `isLoading` from
567
+ * root-namespace lifecycle events so that in-flight runs observed
568
+ * via `hydrate()` (not initiated by a local `submit()`) still flip
569
+ * the UI to loading. `running` → true; terminals → false. The
570
+ * optimistic `isLoading = true` inside `submit()` stays because
571
+ * that fires before any subscription event arrives.
572
+ */
573
+ this.#rootEventListeners.add(this.#lifecycleLoading.listener);
574
+ this.#rootPump = (async () => {
575
+ try {
576
+ /**
577
+ * Narrow the content pump to the root namespace, depth 1:
578
+ * this is enough to observe root LLM deltas and first-level
579
+ * discovery hints (tool-started for task:* / subgraph
580
+ * boundaries) without downloading content from every nested
581
+ * subagent / subgraph. Deeper content is pulled in lazily by
582
+ * per-namespace selector projections (e.g. `useMessages(sub)`),
583
+ * which expand `#computeUnionFilter` progressively.
584
+ */
585
+ const subscriptionPromise = thread.subscribe({
586
+ channels: [...ROOT_PUMP_CHANNELS],
587
+ namespaces: [[]],
588
+ depth: 1
589
+ });
590
+ if (this.#usesEventStreamTransport())
591
+ /**
592
+ * SSE streams can legitimately withhold response headers until
593
+ * the first event is available. Waiting for `subscribe()` here
594
+ * would deadlock new-thread submits: the run is not dispatched
595
+ * until the root pump is "ready", but the pump does not become
596
+ * ready until the run emits. `thread.subscribe()` has already
597
+ * registered the local subscription and scheduled the stream
598
+ * rotation by this point; waiting one microtask lets the fetch
599
+ * get kicked off without requiring headers to arrive.
600
+ */
601
+ queueMicrotask(() => {
602
+ resolveReady?.();
603
+ resolveReady = void 0;
604
+ });
605
+ const subscription = await subscriptionPromise;
606
+ resolveReady?.();
607
+ resolveReady = void 0;
608
+ this.#rootSubscription = subscription;
609
+ /**
610
+ * The SSE transport pauses the underlying subscription when
611
+ * a terminal root lifecycle event arrives (so `for await`
612
+ * loops observing a single run exit cleanly) and re-opens
613
+ * the next run's server stream on `#prepareForNextRun`,
614
+ * resuming the subscription handle. The root pump needs to
615
+ * survive that hand-off: we re-enter the inner `for await`
616
+ * for every resumed iteration until the subscription is
617
+ * permanently closed or the controller is disposed.
618
+ */
619
+ while (!this.#disposed) {
620
+ for await (const event of subscription) {
621
+ if (this.#disposed) break;
622
+ /**
623
+ * Resilience: isolate per-event dispatch from the pump loop.
624
+ *
625
+ * `#onRootEvent` runs synchronously and, transitively,
626
+ * invokes every root-bus listener (selector projections that
627
+ * opted into the shared stream) plus every `rootStore`
628
+ * subscriber. Some of those subscribers live in a React
629
+ * render tree — `useStream` drives
630
+ * `useSyncExternalStore`, so a misbehaving component can
631
+ * surface a render-phase error ("Maximum update depth
632
+ * exceeded", "The result of getSnapshot should be cached",
633
+ * etc.) that propagates out here.
634
+ *
635
+ * Without this guard, a single throw bubbles through the
636
+ * `for await` loop and terminates the root pump permanently.
637
+ * That is catastrophic: no more root events get processed —
638
+ * the terminal `lifecycle: completed` never lands, so
639
+ * `#awaitNextTerminal` never resolves, `isLoading` stays
640
+ * `true`, composers stay disabled, and the final assistant
641
+ * turn never commits to `stream.messages`. The UI looks
642
+ * hung even though the server is still emitting events
643
+ * (and `ThreadStream.onEvent` keeps firing).
644
+ *
645
+ * We therefore swallow the error and keep pumping. The
646
+ * the pump's correctness guarantees do not depend on any
647
+ * consumer behaving well.
648
+ */
649
+ try {
650
+ this.#onRootEvent(event);
651
+ } catch {}
652
+ }
653
+ if (this.#disposed) break;
654
+ if (!subscription.isPaused) break;
655
+ await subscription.waitForResume();
656
+ }
657
+ } catch {
658
+ resolveReady?.();
659
+ resolveReady = void 0;
660
+ }
661
+ })();
662
+ }
663
+ /**
664
+ * Handle an event delivered via {@link ThreadStream.onEvent}.
665
+ *
666
+ * `onEvent` fires once per globally-unique event across the content
667
+ * pump and the wildcard lifecycle watcher, so this is the single
668
+ * entry point for wildcard discovery / interrupt tracking. It does
669
+ * NOT fan events out to the root bus (that's driven by the content
670
+ * pump iterator so root-bus short-circuits stay depth-1 scoped) and
671
+ * it does NOT process root content — messages/tools/values at root
672
+ * are handled by `#onRootEvent` off the content pump.
673
+ *
674
+ * @param event - Raw protocol event observed by the thread-wide listener.
675
+ */
676
+ #onWildcardEvent(event) {
677
+ try {
678
+ this.#subagents.push(event);
679
+ } catch {}
680
+ this.#subgraphs.push(event);
681
+ this.#lifecycleLoading.handle(event);
682
+ /**
683
+ * Nested `input.requested` events (HITL inside a subagent /
684
+ * subgraph) are not observable via the narrow content pump. The
685
+ * `ThreadStream` itself already records them into
686
+ * `thread.interrupts`, which `#latestUnresolvedInterrupt()`
687
+ * consults — so HITL respond() works for any depth. Root-level
688
+ * interrupts are also mirrored into `rootStore.interrupts` here so
689
+ * UI state does not depend on the narrower content pump being the
690
+ * first consumer to see the event.
691
+ */
692
+ this.#recordRootInterrupt(event);
693
+ }
694
+ /**
695
+ * Process one root-pump event and update all root projections.
696
+ *
697
+ * @param event - Event yielded by the root subscription.
698
+ */
699
+ #onRootEvent(event) {
700
+ try {
701
+ this.#subagents.push(event);
702
+ } catch {}
703
+ /**
704
+ * Fan root-pump events out to every root-bus listener (selector
705
+ * projections that opted into the shared stream,
706
+ * `#awaitTerminal`, etc.). The root bus mirrors the content
707
+ * pump's narrow scope (depth 1 at root) so projections that
708
+ * short-circuit via the bus stay bounded.
709
+ */
710
+ if (this.#rootEventListeners.size > 0) for (const listener of this.#rootEventListeners) try {
711
+ listener(event);
712
+ } catch {}
713
+ /**
714
+ * `messages` and `tools` events are emitted under a node's
715
+ * namespace — for a typical StateGraph the LLM's token deltas
716
+ * land on `["model:<uuid>"]`, tool executions on
717
+ * `["tools:<uuid>"]`, etc. The orchestrator's own turns (root
718
+ * agent, or an orchestrator-scoped subgraph like `model:*` /
719
+ * `model_request:*`) belong in `root.messages` and
720
+ * `root.toolCalls`.
721
+ *
722
+ * Subagent / tool-internal branches do NOT:
723
+ * - `task:*` segment — legacy subagent convention.
724
+ * - `tools:*` segment — every tool execution is wrapped in a
725
+ * `tools` subgraph. For simple tools its only content is
726
+ * the eventual tool result (also echoed verbatim by
727
+ * `values.messages` so we don't lose anything). For the
728
+ * deep-agent `task` tool its content IS the spawned
729
+ * subagent's full message + tool stream, which is surfaced
730
+ * separately via `useMessages(stream, subagent)` /
731
+ * `useToolCalls(stream, subagent)`.
732
+ *
733
+ * We therefore drop `messages` events from any namespace that
734
+ * contains a `task:*` or `tools:*` segment; the authoritative
735
+ * tool-result text lands in `root.messages` via the root
736
+ * `values.messages` snapshot merge in `#applyValues`.
737
+ */
738
+ const isInternalNamespace = require_namespace.isInternalWorkNamespace(event.params.namespace);
739
+ const hasLegacySubagentNamespace = require_namespace.isLegacySubagentNamespace(event.params.namespace);
740
+ if (event.method === "messages") {
741
+ if (!isInternalNamespace) this.#rootMessages.handleMessage(event);
742
+ return;
743
+ }
744
+ if (event.method === "tools") {
745
+ if (event.params.namespace.length <= 1 && !hasLegacySubagentNamespace) {
746
+ /**
747
+ * Record the `namespace → tool_call_id` association so that
748
+ * the ensuing `message-start` (role: "tool") at the same
749
+ * namespace can recover the `tool_call_id` (the `messages`
750
+ * channel's start event doesn't carry it directly).
751
+ */
752
+ const toolData = event.params.data;
753
+ if (toolData.event === "tool-started" && typeof toolData.tool_call_id === "string") this.#rootMessages.recordToolCallNamespace(event.params.namespace, toolData.tool_call_id);
754
+ const tc = this.#rootToolAssembler.consume(event);
755
+ if (tc != null) this.rootStore.setState((s) => ({
756
+ ...s,
757
+ toolCalls: require_tool_calls.upsertToolCall(s.toolCalls, tc)
758
+ }));
759
+ }
760
+ return;
761
+ }
762
+ /**
763
+ * The `checkpoints` channel carries the lightweight envelope
764
+ * (`id`, `parent_id`, `step`, `source`) emitted immediately
765
+ * before its companion `values` event on the same superstep.
766
+ * Buffer the envelope per-namespace so the ensuing `values`
767
+ * event at the same namespace can pair with it in `#applyValues`.
768
+ * The buffer is read-and-cleared on consumption so a subsequent
769
+ * `values` event without a new checkpoint doesn't reuse stale
770
+ * metadata.
771
+ */
772
+ if (event.method === "checkpoints") {
773
+ const data = event.params.data;
774
+ this.#messageMetadata.bufferCheckpoint(event.params.namespace, data);
775
+ return;
776
+ }
777
+ if (!require_namespace.isRootNamespace(event.params.namespace)) return;
778
+ if (event.method === "values") {
779
+ const valuesEvent = event;
780
+ const bufferedCheckpoint = this.#messageMetadata.consumeCheckpoint(event.params.namespace);
781
+ this.#applyValues(valuesEvent.params.data, bufferedCheckpoint);
782
+ return;
783
+ }
784
+ if (event.method === "input.requested") {
785
+ this.#recordRootInterrupt(event);
786
+ return;
787
+ }
788
+ if (event.method === "lifecycle") event.params.data;
789
+ }
790
+ /**
791
+ * Merge a `values` payload into root values and root messages.
792
+ *
793
+ * @param raw - Raw `values` channel payload.
794
+ * @param checkpoint - Optional checkpoint envelope paired with the values event.
795
+ */
796
+ #applyValues(raw, checkpoint) {
797
+ if (raw == null || typeof raw !== "object" || Array.isArray(raw)) return;
798
+ const state = raw;
799
+ /**
800
+ * Surface parent_checkpoint per-message when the values event
801
+ * carries the lightweight checkpoint envelope (populated by
802
+ * `@langchain/langgraph-core`'s `_emitValuesWithCheckpointMeta` and
803
+ * forwarded through `convertToProtocolEvent`). Consumers surface
804
+ * this as `useMessageMetadata(stream, msg.id).parentCheckpointId`
805
+ * for fork / edit flows.
806
+ */
807
+ const parentCheckpointId = checkpoint?.parent_id;
808
+ if (parentCheckpointId != null && Array.isArray(state[this.#messagesKey])) this.#messageMetadata.recordMessages(state[this.#messagesKey], { parentCheckpointId });
809
+ const maybeMessages = state[this.#messagesKey];
810
+ let nextValues;
811
+ let nextMessages;
812
+ if (Array.isArray(maybeMessages)) {
813
+ const coerced = require_messages.ensureMessageInstances(maybeMessages);
814
+ nextValues = {
815
+ ...state,
816
+ [this.#messagesKey]: coerced
817
+ };
818
+ nextMessages = coerced;
819
+ } else {
820
+ nextValues = state;
821
+ nextMessages = [];
822
+ }
823
+ this.#rootMessages.applyValues(nextValues, nextMessages);
824
+ }
825
+ /**
826
+ * Mirror root protocol interrupts into the root snapshot.
827
+ *
828
+ * This can be called from both the wildcard lifecycle/input watcher and the
829
+ * root content pump. Store-level dedup keeps the user-facing list stable.
830
+ */
831
+ #recordRootInterrupt(event) {
832
+ if (event.method !== "input.requested") return;
833
+ if (!require_namespace.isRootNamespace(event.params.namespace)) return;
834
+ const data = event.params.data;
835
+ const interruptId = data?.interrupt_id;
836
+ if (typeof interruptId !== "string" || this.#resolvedInterrupts.has(interruptId)) return;
837
+ const interrupt = {
838
+ id: interruptId,
839
+ value: data.payload
840
+ };
841
+ this.rootStore.setState((s) => {
842
+ if (s.interrupts.some((entry) => entry.id === interruptId)) return s;
843
+ const interrupts = [...s.interrupts, interrupt];
844
+ return {
845
+ ...s,
846
+ interrupts,
847
+ interrupt: interrupts[0]
848
+ };
849
+ });
850
+ }
851
+ /**
852
+ * Resolve on the next root-namespace terminal lifecycle event
853
+ * (`completed` / `failed` / `interrupted`) or on abort.
854
+ *
855
+ * Attaches to the controller's root event bus instead of opening
856
+ * a second server subscription. Callers should register the
857
+ * returned promise **before** dispatching the command that
858
+ * triggers the run (`thread.run.start` / `thread.input.respond`)
859
+ * — the root pump fans events out synchronously on arrival, so a
860
+ * late registration would miss the terminal for fast runs.
861
+ *
862
+ * @param signal - Abort signal for the local submit lifecycle.
863
+ */
864
+ #awaitNextTerminal(signal) {
865
+ return new Promise((resolve) => {
866
+ let settled = false;
867
+ function finish(result) {
868
+ if (settled) return;
869
+ settled = true;
870
+ unsubscribeRoot?.();
871
+ unsubscribeThread?.();
872
+ signal.removeEventListener("abort", finishAborted);
873
+ resolve(result);
874
+ }
875
+ const finishAborted = () => finish({ event: "aborted" });
876
+ const onEvent = (event) => {
877
+ if (settled) return;
878
+ if (event.method !== "lifecycle") return;
879
+ if (!require_namespace.isRootNamespace(event.params.namespace)) return;
880
+ const lifecycle = event.params.data;
881
+ if (lifecycle?.event === "completed") setTimeout(() => finish({ event: "completed" }), 0);
882
+ else if (lifecycle?.event === "failed") setTimeout(() => finish({
883
+ event: "failed",
884
+ error: lifecycle.error
885
+ }), 0);
886
+ else if (lifecycle?.event === "interrupted") setTimeout(() => finish({ event: "interrupted" }), 0);
887
+ };
888
+ const unsubscribeRoot = this.#rootBus.subscribe(onEvent);
889
+ const unsubscribeThread = this.#thread?.onEvent(onEvent);
890
+ if (signal.aborted) finishAborted();
891
+ else signal.addEventListener("abort", finishAborted, { once: true });
892
+ });
893
+ }
894
+ /**
895
+ * Find the newest unresolved interrupt recorded on the active thread.
896
+ */
897
+ #latestUnresolvedInterrupt() {
898
+ const thread = this.#thread;
899
+ if (thread == null) return null;
900
+ for (let i = thread.interrupts.length - 1; i >= 0; i -= 1) {
901
+ const entry = thread.interrupts[i];
902
+ if (entry == null) continue;
903
+ if (this.#resolvedInterrupts.has(entry.interruptId)) continue;
904
+ return {
905
+ interruptId: entry.interruptId,
906
+ namespace: entry.namespace
907
+ };
908
+ }
909
+ return null;
910
+ }
911
+ /**
912
+ * Notify listeners that the underlying thread stream changed.
913
+ */
914
+ #notifyThreadListeners() {
915
+ for (const listener of this.#threadListeners) listener(this.#thread);
916
+ }
917
+ };
918
+ /**
919
+ * Extract and coerce the configured messages key from a values object.
920
+ *
921
+ * @param values - State values object to read from.
922
+ * @param messagesKey - Key that contains the message array.
923
+ */
924
+ function extractAndCoerceMessages(values, messagesKey) {
925
+ const raw = values[messagesKey];
926
+ if (!Array.isArray(raw)) return [];
927
+ return require_messages.ensureMessageInstances(raw);
928
+ }
929
+ //#endregion
930
+ exports.ROOT_PUMP_CHANNELS = ROOT_PUMP_CHANNELS;
931
+ exports.StreamController = StreamController;
932
+
933
+ //# sourceMappingURL=controller.cjs.map