@langchain/langgraph 1.0.12 → 1.0.14

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 (381) hide show
  1. package/dist/channels/any_value.cjs +46 -0
  2. package/dist/channels/any_value.cjs.map +1 -0
  3. package/dist/channels/any_value.d.cts +23 -0
  4. package/dist/channels/any_value.d.cts.map +1 -0
  5. package/dist/channels/any_value.d.ts +23 -0
  6. package/dist/channels/any_value.d.ts.map +1 -0
  7. package/dist/channels/any_value.js +46 -0
  8. package/dist/channels/any_value.js.map +1 -0
  9. package/dist/channels/base.cjs +101 -0
  10. package/dist/channels/base.cjs.map +1 -0
  11. package/dist/channels/base.d.cts +79 -0
  12. package/dist/channels/base.d.cts.map +1 -0
  13. package/dist/channels/base.d.ts +79 -0
  14. package/dist/channels/base.d.ts.map +1 -0
  15. package/dist/channels/base.js +97 -0
  16. package/dist/channels/base.js.map +1 -0
  17. package/dist/channels/binop.cjs +49 -0
  18. package/dist/channels/binop.cjs.map +1 -0
  19. package/dist/channels/binop.d.cts +22 -0
  20. package/dist/channels/binop.d.cts.map +1 -0
  21. package/dist/channels/binop.d.ts +22 -0
  22. package/dist/channels/binop.d.ts.map +1 -0
  23. package/dist/channels/binop.js +49 -0
  24. package/dist/channels/binop.js.map +1 -0
  25. package/dist/channels/dynamic_barrier_value.cjs +75 -0
  26. package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
  27. package/dist/channels/dynamic_barrier_value.d.cts +40 -0
  28. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  29. package/dist/channels/dynamic_barrier_value.d.ts +40 -0
  30. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  31. package/dist/channels/dynamic_barrier_value.js +75 -0
  32. package/dist/channels/dynamic_barrier_value.js.map +1 -0
  33. package/dist/channels/ephemeral_value.cjs +46 -0
  34. package/dist/channels/ephemeral_value.cjs.map +1 -0
  35. package/dist/channels/ephemeral_value.d.cts +21 -0
  36. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  37. package/dist/channels/ephemeral_value.d.ts +21 -0
  38. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  39. package/dist/channels/ephemeral_value.js +46 -0
  40. package/dist/channels/ephemeral_value.js.map +1 -0
  41. package/dist/channels/index.cjs +21 -0
  42. package/dist/channels/index.d.cts +9 -0
  43. package/dist/channels/index.d.ts +9 -0
  44. package/dist/channels/index.js +10 -0
  45. package/dist/channels/last_value.cjs +98 -0
  46. package/dist/channels/last_value.cjs.map +1 -0
  47. package/dist/channels/last_value.d.cts +42 -0
  48. package/dist/channels/last_value.d.cts.map +1 -0
  49. package/dist/channels/last_value.d.ts +42 -0
  50. package/dist/channels/last_value.d.ts.map +1 -0
  51. package/dist/channels/last_value.js +97 -0
  52. package/dist/channels/last_value.js.map +1 -0
  53. package/dist/channels/named_barrier_value.cjs +116 -0
  54. package/dist/channels/named_barrier_value.cjs.map +1 -0
  55. package/dist/channels/named_barrier_value.d.cts +44 -0
  56. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  57. package/dist/channels/named_barrier_value.d.ts +44 -0
  58. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  59. package/dist/channels/named_barrier_value.js +114 -0
  60. package/dist/channels/named_barrier_value.js.map +1 -0
  61. package/dist/channels/topic.cjs +65 -0
  62. package/dist/channels/topic.cjs.map +1 -0
  63. package/dist/channels/topic.d.cts +32 -0
  64. package/dist/channels/topic.d.cts.map +1 -0
  65. package/dist/channels/topic.d.ts +32 -0
  66. package/dist/channels/topic.d.ts.map +1 -0
  67. package/dist/channels/topic.js +65 -0
  68. package/dist/channels/topic.js.map +1 -0
  69. package/dist/constants.cjs +406 -0
  70. package/dist/constants.cjs.map +1 -0
  71. package/dist/constants.d.cts +281 -0
  72. package/dist/constants.d.cts.map +1 -0
  73. package/dist/constants.d.ts +281 -0
  74. package/dist/constants.d.ts.map +1 -0
  75. package/dist/constants.js +362 -0
  76. package/dist/constants.js.map +1 -0
  77. package/dist/errors.cjs +163 -0
  78. package/dist/errors.cjs.map +1 -0
  79. package/dist/errors.d.cts +77 -0
  80. package/dist/errors.d.cts.map +1 -0
  81. package/dist/errors.d.ts +77 -0
  82. package/dist/errors.d.ts.map +1 -0
  83. package/dist/errors.js +146 -0
  84. package/dist/errors.js.map +1 -0
  85. package/dist/func/index.cjs +299 -0
  86. package/dist/func/index.cjs.map +1 -0
  87. package/dist/func/index.d.cts +288 -0
  88. package/dist/func/index.d.cts.map +1 -0
  89. package/dist/func/index.d.ts +288 -0
  90. package/dist/func/index.d.ts.map +1 -0
  91. package/dist/func/index.js +297 -0
  92. package/dist/func/index.js.map +1 -0
  93. package/dist/func/types.d.cts +62 -0
  94. package/dist/func/types.d.cts.map +1 -0
  95. package/dist/func/types.d.ts +62 -0
  96. package/dist/func/types.d.ts.map +1 -0
  97. package/dist/graph/annotation.cjs +101 -0
  98. package/dist/graph/annotation.cjs.map +1 -0
  99. package/dist/graph/annotation.d.cts +116 -0
  100. package/dist/graph/annotation.d.cts.map +1 -0
  101. package/dist/graph/annotation.d.ts +116 -0
  102. package/dist/graph/annotation.d.ts.map +1 -0
  103. package/dist/graph/annotation.js +99 -0
  104. package/dist/graph/annotation.js.map +1 -0
  105. package/dist/graph/graph.cjs +420 -0
  106. package/dist/graph/graph.cjs.map +1 -0
  107. package/dist/graph/graph.d.cts +108 -0
  108. package/dist/graph/graph.d.cts.map +1 -0
  109. package/dist/graph/graph.d.ts +108 -0
  110. package/dist/graph/graph.d.ts.map +1 -0
  111. package/dist/graph/graph.js +418 -0
  112. package/dist/graph/graph.js.map +1 -0
  113. package/dist/graph/index.cjs +5 -0
  114. package/dist/graph/index.js +7 -0
  115. package/dist/graph/message.cjs +97 -0
  116. package/dist/graph/message.cjs.map +1 -0
  117. package/dist/graph/message.d.cts +40 -0
  118. package/dist/graph/message.d.cts.map +1 -0
  119. package/dist/graph/message.d.ts +40 -0
  120. package/dist/graph/message.d.ts.map +1 -0
  121. package/dist/graph/message.js +94 -0
  122. package/dist/graph/message.js.map +1 -0
  123. package/dist/graph/messages_annotation.cjs +109 -0
  124. package/dist/graph/messages_annotation.cjs.map +1 -0
  125. package/dist/graph/messages_annotation.d.cts +112 -0
  126. package/dist/graph/messages_annotation.d.cts.map +1 -0
  127. package/dist/graph/messages_annotation.d.ts +112 -0
  128. package/dist/graph/messages_annotation.d.ts.map +1 -0
  129. package/dist/graph/messages_annotation.js +107 -0
  130. package/dist/graph/messages_annotation.js.map +1 -0
  131. package/dist/graph/state.cjs +494 -0
  132. package/dist/graph/state.cjs.map +1 -0
  133. package/dist/graph/state.d.cts +229 -0
  134. package/dist/graph/state.d.cts.map +1 -0
  135. package/dist/graph/state.d.ts +229 -0
  136. package/dist/graph/state.d.ts.map +1 -0
  137. package/dist/graph/state.js +493 -0
  138. package/dist/graph/state.js.map +1 -0
  139. package/dist/graph/zod/index.cjs +10 -0
  140. package/dist/graph/zod/index.d.cts +3 -0
  141. package/dist/graph/zod/index.d.ts +3 -0
  142. package/dist/graph/zod/index.js +5 -0
  143. package/dist/graph/zod/meta.cjs +144 -0
  144. package/dist/graph/zod/meta.cjs.map +1 -0
  145. package/dist/graph/zod/meta.d.cts +115 -0
  146. package/dist/graph/zod/meta.d.cts.map +1 -0
  147. package/dist/graph/zod/meta.d.ts +115 -0
  148. package/dist/graph/zod/meta.d.ts.map +1 -0
  149. package/dist/graph/zod/meta.js +141 -0
  150. package/dist/graph/zod/meta.js.map +1 -0
  151. package/dist/graph/zod/plugin.cjs +39 -0
  152. package/dist/graph/zod/plugin.cjs.map +1 -0
  153. package/dist/graph/zod/plugin.js +40 -0
  154. package/dist/graph/zod/plugin.js.map +1 -0
  155. package/dist/graph/zod/schema.cjs +98 -0
  156. package/dist/graph/zod/schema.cjs.map +1 -0
  157. package/dist/graph/zod/schema.d.cts +38 -0
  158. package/dist/graph/zod/schema.d.cts.map +1 -0
  159. package/dist/graph/zod/schema.d.ts +38 -0
  160. package/dist/graph/zod/schema.d.ts.map +1 -0
  161. package/dist/graph/zod/schema.js +94 -0
  162. package/dist/graph/zod/schema.js.map +1 -0
  163. package/dist/graph/zod/zod-registry.cjs +42 -0
  164. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  165. package/dist/graph/zod/zod-registry.d.cts +49 -0
  166. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  167. package/dist/graph/zod/zod-registry.d.ts +49 -0
  168. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  169. package/dist/graph/zod/zod-registry.js +41 -0
  170. package/dist/graph/zod/zod-registry.js.map +1 -0
  171. package/dist/hash.cjs +265 -0
  172. package/dist/hash.cjs.map +1 -0
  173. package/dist/hash.js +263 -0
  174. package/dist/hash.js.map +1 -0
  175. package/dist/index.cjs +111 -0
  176. package/dist/index.cjs.map +1 -0
  177. package/dist/index.d.cts +26 -0
  178. package/dist/index.d.ts +26 -0
  179. package/dist/index.js +22 -0
  180. package/dist/index.js.map +1 -0
  181. package/dist/interrupt.cjs +79 -0
  182. package/dist/interrupt.cjs.map +1 -0
  183. package/dist/interrupt.d.cts +55 -0
  184. package/dist/interrupt.d.cts.map +1 -0
  185. package/dist/interrupt.d.ts +55 -0
  186. package/dist/interrupt.d.ts.map +1 -0
  187. package/dist/interrupt.js +79 -0
  188. package/dist/interrupt.js.map +1 -0
  189. package/dist/prebuilt/agentName.cjs +148 -0
  190. package/dist/prebuilt/agentName.cjs.map +1 -0
  191. package/dist/prebuilt/agentName.d.cts +42 -0
  192. package/dist/prebuilt/agentName.d.cts.map +1 -0
  193. package/dist/prebuilt/agentName.d.ts +42 -0
  194. package/dist/prebuilt/agentName.d.ts.map +1 -0
  195. package/dist/prebuilt/agentName.js +148 -0
  196. package/dist/prebuilt/agentName.js.map +1 -0
  197. package/dist/prebuilt/agent_executor.cjs +41 -0
  198. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  199. package/dist/prebuilt/agent_executor.d.cts +58 -0
  200. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  201. package/dist/prebuilt/agent_executor.d.ts +58 -0
  202. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  203. package/dist/prebuilt/agent_executor.js +41 -0
  204. package/dist/prebuilt/agent_executor.js.map +1 -0
  205. package/dist/prebuilt/chat_agent_executor.cjs +62 -0
  206. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  207. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  208. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  209. package/dist/prebuilt/chat_agent_executor.d.ts +23 -0
  210. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  211. package/dist/prebuilt/chat_agent_executor.js +62 -0
  212. package/dist/prebuilt/chat_agent_executor.js.map +1 -0
  213. package/dist/prebuilt/index.cjs +15 -0
  214. package/dist/prebuilt/index.d.cts +8 -0
  215. package/dist/prebuilt/index.d.ts +8 -0
  216. package/dist/prebuilt/index.js +8 -0
  217. package/dist/prebuilt/interrupt.d.cts +60 -0
  218. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  219. package/dist/prebuilt/interrupt.d.ts +60 -0
  220. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  221. package/dist/prebuilt/react_agent_executor.cjs +339 -0
  222. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  223. package/dist/prebuilt/react_agent_executor.d.cts +211 -0
  224. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  225. package/dist/prebuilt/react_agent_executor.d.ts +211 -0
  226. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  227. package/dist/prebuilt/react_agent_executor.js +338 -0
  228. package/dist/prebuilt/react_agent_executor.js.map +1 -0
  229. package/dist/prebuilt/tool_executor.cjs +43 -0
  230. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  231. package/dist/prebuilt/tool_executor.d.cts +40 -0
  232. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  233. package/dist/prebuilt/tool_executor.d.ts +40 -0
  234. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  235. package/dist/prebuilt/tool_executor.js +43 -0
  236. package/dist/prebuilt/tool_executor.js.map +1 -0
  237. package/dist/prebuilt/tool_node.cjs +247 -0
  238. package/dist/prebuilt/tool_node.cjs.map +1 -0
  239. package/dist/prebuilt/tool_node.d.cts +180 -0
  240. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  241. package/dist/prebuilt/tool_node.d.ts +180 -0
  242. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  243. package/dist/prebuilt/tool_node.js +246 -0
  244. package/dist/prebuilt/tool_node.js.map +1 -0
  245. package/dist/pregel/algo.cjs +565 -0
  246. package/dist/pregel/algo.cjs.map +1 -0
  247. package/dist/pregel/algo.d.cts +13 -0
  248. package/dist/pregel/algo.d.cts.map +1 -0
  249. package/dist/pregel/algo.d.ts +13 -0
  250. package/dist/pregel/algo.d.ts.map +1 -0
  251. package/dist/pregel/algo.js +560 -0
  252. package/dist/pregel/algo.js.map +1 -0
  253. package/dist/pregel/call.cjs +50 -0
  254. package/dist/pregel/call.cjs.map +1 -0
  255. package/dist/pregel/call.js +48 -0
  256. package/dist/pregel/call.js.map +1 -0
  257. package/dist/pregel/debug.cjs +172 -0
  258. package/dist/pregel/debug.cjs.map +1 -0
  259. package/dist/pregel/debug.js +166 -0
  260. package/dist/pregel/debug.js.map +1 -0
  261. package/dist/pregel/index.cjs +1163 -0
  262. package/dist/pregel/index.cjs.map +1 -0
  263. package/dist/pregel/index.d.cts +498 -0
  264. package/dist/pregel/index.d.cts.map +1 -0
  265. package/dist/pregel/index.d.ts +498 -0
  266. package/dist/pregel/index.d.ts.map +1 -0
  267. package/dist/pregel/index.js +1162 -0
  268. package/dist/pregel/index.js.map +1 -0
  269. package/dist/pregel/io.cjs +140 -0
  270. package/dist/pregel/io.cjs.map +1 -0
  271. package/dist/pregel/io.js +135 -0
  272. package/dist/pregel/io.js.map +1 -0
  273. package/dist/pregel/loop.cjs +545 -0
  274. package/dist/pregel/loop.cjs.map +1 -0
  275. package/dist/pregel/loop.js +545 -0
  276. package/dist/pregel/loop.js.map +1 -0
  277. package/dist/pregel/messages.cjs +107 -0
  278. package/dist/pregel/messages.cjs.map +1 -0
  279. package/dist/pregel/messages.js +107 -0
  280. package/dist/pregel/messages.js.map +1 -0
  281. package/dist/pregel/read.cjs +151 -0
  282. package/dist/pregel/read.cjs.map +1 -0
  283. package/dist/pregel/read.d.cts +45 -0
  284. package/dist/pregel/read.d.cts.map +1 -0
  285. package/dist/pregel/read.d.ts +45 -0
  286. package/dist/pregel/read.d.ts.map +1 -0
  287. package/dist/pregel/read.js +150 -0
  288. package/dist/pregel/read.js.map +1 -0
  289. package/dist/pregel/remote.cjs +341 -0
  290. package/dist/pregel/remote.cjs.map +1 -0
  291. package/dist/pregel/remote.d.cts +118 -0
  292. package/dist/pregel/remote.d.cts.map +1 -0
  293. package/dist/pregel/remote.d.ts +118 -0
  294. package/dist/pregel/remote.d.ts.map +1 -0
  295. package/dist/pregel/remote.js +341 -0
  296. package/dist/pregel/remote.js.map +1 -0
  297. package/dist/pregel/retry.cjs +91 -0
  298. package/dist/pregel/retry.cjs.map +1 -0
  299. package/dist/pregel/retry.js +91 -0
  300. package/dist/pregel/retry.js.map +1 -0
  301. package/dist/pregel/runnable_types.d.cts +43 -0
  302. package/dist/pregel/runnable_types.d.cts.map +1 -0
  303. package/dist/pregel/runnable_types.d.ts +43 -0
  304. package/dist/pregel/runnable_types.d.ts.map +1 -0
  305. package/dist/pregel/runner.cjs +228 -0
  306. package/dist/pregel/runner.cjs.map +1 -0
  307. package/dist/pregel/runner.js +228 -0
  308. package/dist/pregel/runner.js.map +1 -0
  309. package/dist/pregel/stream.cjs +197 -0
  310. package/dist/pregel/stream.cjs.map +1 -0
  311. package/dist/pregel/stream.js +195 -0
  312. package/dist/pregel/stream.js.map +1 -0
  313. package/dist/pregel/types.cjs +27 -0
  314. package/dist/pregel/types.cjs.map +1 -0
  315. package/dist/pregel/types.d.cts +440 -0
  316. package/dist/pregel/types.d.cts.map +1 -0
  317. package/dist/pregel/types.d.ts +440 -0
  318. package/dist/pregel/types.d.ts.map +1 -0
  319. package/dist/pregel/types.js +25 -0
  320. package/dist/pregel/types.js.map +1 -0
  321. package/dist/pregel/utils/config.cjs +121 -0
  322. package/dist/pregel/utils/config.cjs.map +1 -0
  323. package/dist/pregel/utils/config.d.cts +36 -0
  324. package/dist/pregel/utils/config.d.cts.map +1 -0
  325. package/dist/pregel/utils/config.d.ts +36 -0
  326. package/dist/pregel/utils/config.d.ts.map +1 -0
  327. package/dist/pregel/utils/config.js +115 -0
  328. package/dist/pregel/utils/config.js.map +1 -0
  329. package/dist/pregel/utils/index.cjs +102 -0
  330. package/dist/pregel/utils/index.cjs.map +1 -0
  331. package/dist/pregel/utils/index.d.cts +51 -0
  332. package/dist/pregel/utils/index.d.cts.map +1 -0
  333. package/dist/pregel/utils/index.d.ts +51 -0
  334. package/dist/pregel/utils/index.d.ts.map +1 -0
  335. package/dist/pregel/utils/index.js +96 -0
  336. package/dist/pregel/utils/index.js.map +1 -0
  337. package/dist/pregel/utils/subgraph.cjs +18 -0
  338. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  339. package/dist/pregel/utils/subgraph.js +16 -0
  340. package/dist/pregel/utils/subgraph.js.map +1 -0
  341. package/dist/pregel/validate.cjs +45 -0
  342. package/dist/pregel/validate.cjs.map +1 -0
  343. package/dist/pregel/validate.js +44 -0
  344. package/dist/pregel/validate.js.map +1 -0
  345. package/dist/pregel/write.cjs +96 -0
  346. package/dist/pregel/write.cjs.map +1 -0
  347. package/dist/pregel/write.d.cts +31 -0
  348. package/dist/pregel/write.d.cts.map +1 -0
  349. package/dist/pregel/write.d.ts +31 -0
  350. package/dist/pregel/write.d.ts.map +1 -0
  351. package/dist/pregel/write.js +95 -0
  352. package/dist/pregel/write.js.map +1 -0
  353. package/dist/remote.cjs +3 -0
  354. package/dist/remote.d.cts +2 -0
  355. package/dist/remote.d.ts +2 -0
  356. package/dist/remote.js +3 -0
  357. package/dist/setup/async_local_storage.cjs +11 -0
  358. package/dist/setup/async_local_storage.cjs.map +1 -0
  359. package/dist/setup/async_local_storage.js +11 -0
  360. package/dist/setup/async_local_storage.js.map +1 -0
  361. package/dist/utils.cjs +86 -0
  362. package/dist/utils.cjs.map +1 -0
  363. package/dist/utils.d.cts +25 -0
  364. package/dist/utils.d.cts.map +1 -0
  365. package/dist/utils.d.ts +25 -0
  366. package/dist/utils.d.ts.map +1 -0
  367. package/dist/utils.js +80 -0
  368. package/dist/utils.js.map +1 -0
  369. package/dist/web.cjs +95 -0
  370. package/dist/web.d.cts +23 -0
  371. package/dist/web.d.ts +23 -0
  372. package/dist/web.js +15 -0
  373. package/dist/writer.cjs +14 -0
  374. package/dist/writer.cjs.map +1 -0
  375. package/dist/writer.d.cts +6 -0
  376. package/dist/writer.d.cts.map +1 -0
  377. package/dist/writer.d.ts +6 -0
  378. package/dist/writer.d.ts.map +1 -0
  379. package/dist/writer.js +14 -0
  380. package/dist/writer.js.map +1 -0
  381. package/package.json +25 -27
@@ -0,0 +1,545 @@
1
+ const require_errors = require('../errors.cjs');
2
+ const require_base = require('../channels/base.cjs');
3
+ const require_constants = require('../constants.cjs');
4
+ const require_utils = require('../utils.cjs');
5
+ const require_hash = require('../hash.cjs');
6
+ const require_io = require('./io.cjs');
7
+ const require_index = require('./utils/index.cjs');
8
+ const require_algo = require('./algo.cjs');
9
+ const require_debug = require('./debug.cjs');
10
+ const require_stream = require('./stream.cjs');
11
+ let _langchain_langgraph_checkpoint = require("@langchain/langgraph-checkpoint");
12
+
13
+ //#region src/pregel/loop.ts
14
+ const INPUT_DONE = Symbol.for("INPUT_DONE");
15
+ const INPUT_RESUMING = Symbol.for("INPUT_RESUMING");
16
+ const DEFAULT_LOOP_LIMIT = 25;
17
+ function createDuplexStream(...streams) {
18
+ return new require_stream.IterableReadableWritableStream({
19
+ passthroughFn: (value) => {
20
+ for (const stream of streams) if (stream.modes.has(value[1])) stream.push(value);
21
+ },
22
+ modes: new Set(streams.flatMap((s) => Array.from(s.modes)))
23
+ });
24
+ }
25
+ var AsyncBatchedCache = class extends _langchain_langgraph_checkpoint.BaseCache {
26
+ cache;
27
+ queue = Promise.resolve();
28
+ constructor(cache) {
29
+ super();
30
+ this.cache = cache;
31
+ }
32
+ async get(keys) {
33
+ return this.enqueueOperation("get", keys);
34
+ }
35
+ async set(pairs) {
36
+ return this.enqueueOperation("set", pairs);
37
+ }
38
+ async clear(namespaces) {
39
+ return this.enqueueOperation("clear", namespaces);
40
+ }
41
+ async stop() {
42
+ await this.queue;
43
+ }
44
+ enqueueOperation(type, ...args) {
45
+ const newPromise = this.queue.then(() => {
46
+ return this.cache[type](...args);
47
+ });
48
+ this.queue = newPromise.then(() => void 0, () => void 0);
49
+ return newPromise;
50
+ }
51
+ };
52
+ var PregelLoop = class PregelLoop {
53
+ input;
54
+ output;
55
+ config;
56
+ checkpointer;
57
+ checkpointerGetNextVersion;
58
+ channels;
59
+ checkpoint;
60
+ checkpointIdSaved;
61
+ checkpointConfig;
62
+ checkpointMetadata;
63
+ checkpointNamespace;
64
+ checkpointPendingWrites = [];
65
+ checkpointPreviousVersions;
66
+ step;
67
+ stop;
68
+ durability;
69
+ outputKeys;
70
+ streamKeys;
71
+ nodes;
72
+ skipDoneTasks;
73
+ prevCheckpointConfig;
74
+ updatedChannels;
75
+ status = "pending";
76
+ tasks = {};
77
+ stream;
78
+ checkpointerPromises = [];
79
+ isNested;
80
+ _checkpointerChainedPromise = Promise.resolve();
81
+ store;
82
+ cache;
83
+ manager;
84
+ interruptAfter;
85
+ interruptBefore;
86
+ toInterrupt = [];
87
+ debug = false;
88
+ triggerToNodes;
89
+ get isResuming() {
90
+ let hasChannelVersions = false;
91
+ if (require_constants.START in this.checkpoint.channel_versions) hasChannelVersions = true;
92
+ else for (const chan in this.checkpoint.channel_versions) if (Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions, chan)) {
93
+ hasChannelVersions = true;
94
+ break;
95
+ }
96
+ const configIsResuming = this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING] !== void 0 && this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING];
97
+ const inputIsNullOrUndefined = this.input === null || this.input === void 0;
98
+ const inputIsCommandResuming = require_constants.isCommand(this.input) && this.input.resume != null;
99
+ const inputIsResuming = this.input === INPUT_RESUMING;
100
+ const runIdMatchesPrevious = !this.isNested && this.config.metadata?.run_id !== void 0 && this.checkpointMetadata?.run_id !== void 0 && this.config.metadata.run_id === this.checkpointMetadata?.run_id;
101
+ return hasChannelVersions && (configIsResuming || inputIsNullOrUndefined || inputIsCommandResuming || inputIsResuming || runIdMatchesPrevious);
102
+ }
103
+ constructor(params) {
104
+ this.input = params.input;
105
+ this.checkpointer = params.checkpointer;
106
+ if (this.checkpointer !== void 0) this.checkpointerGetNextVersion = this.checkpointer.getNextVersion.bind(this.checkpointer);
107
+ else this.checkpointerGetNextVersion = require_algo.increment;
108
+ this.checkpoint = params.checkpoint;
109
+ this.checkpointMetadata = params.checkpointMetadata;
110
+ this.checkpointPreviousVersions = params.checkpointPreviousVersions;
111
+ this.channels = params.channels;
112
+ this.checkpointPendingWrites = params.checkpointPendingWrites;
113
+ this.step = params.step;
114
+ this.stop = params.stop;
115
+ this.config = params.config;
116
+ this.checkpointConfig = params.checkpointConfig;
117
+ this.isNested = params.isNested;
118
+ this.manager = params.manager;
119
+ this.outputKeys = params.outputKeys;
120
+ this.streamKeys = params.streamKeys;
121
+ this.nodes = params.nodes;
122
+ this.skipDoneTasks = params.skipDoneTasks;
123
+ this.store = params.store;
124
+ this.cache = params.cache ? new AsyncBatchedCache(params.cache) : void 0;
125
+ this.stream = params.stream;
126
+ this.checkpointNamespace = params.checkpointNamespace;
127
+ this.prevCheckpointConfig = params.prevCheckpointConfig;
128
+ this.interruptAfter = params.interruptAfter;
129
+ this.interruptBefore = params.interruptBefore;
130
+ this.durability = params.durability;
131
+ this.debug = params.debug;
132
+ this.triggerToNodes = params.triggerToNodes;
133
+ }
134
+ static async initialize(params) {
135
+ let { config, stream } = params;
136
+ if (stream !== void 0 && config.configurable?.[require_constants.CONFIG_KEY_STREAM] !== void 0) stream = createDuplexStream(stream, config.configurable[require_constants.CONFIG_KEY_STREAM]);
137
+ const skipDoneTasks = config.configurable ? !("checkpoint_id" in config.configurable) : true;
138
+ const scratchpad = config.configurable?.[require_constants.CONFIG_KEY_SCRATCHPAD];
139
+ if (config.configurable && scratchpad) {
140
+ if (scratchpad.subgraphCounter > 0) config = require_index.patchConfigurable(config, { [require_constants.CONFIG_KEY_CHECKPOINT_NS]: [config.configurable[require_constants.CONFIG_KEY_CHECKPOINT_NS], scratchpad.subgraphCounter.toString()].join(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR) });
141
+ scratchpad.subgraphCounter += 1;
142
+ }
143
+ const isNested = require_constants.CONFIG_KEY_READ in (config.configurable ?? {});
144
+ if (!isNested && config.configurable?.checkpoint_ns !== void 0 && config.configurable?.checkpoint_ns !== "") config = require_index.patchConfigurable(config, {
145
+ checkpoint_ns: "",
146
+ checkpoint_id: void 0
147
+ });
148
+ let checkpointConfig = config;
149
+ if (config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINT_MAP] !== void 0 && config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINT_MAP]?.[config.configurable?.checkpoint_ns]) checkpointConfig = require_index.patchConfigurable(config, { checkpoint_id: config.configurable[require_constants.CONFIG_KEY_CHECKPOINT_MAP][config.configurable?.checkpoint_ns] });
150
+ const checkpointNamespace = config.configurable?.checkpoint_ns?.split(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR) ?? [];
151
+ const saved = await params.checkpointer?.getTuple(checkpointConfig) ?? {
152
+ config,
153
+ checkpoint: (0, _langchain_langgraph_checkpoint.emptyCheckpoint)(),
154
+ metadata: {
155
+ source: "input",
156
+ step: -2,
157
+ parents: {}
158
+ },
159
+ pendingWrites: []
160
+ };
161
+ checkpointConfig = {
162
+ ...config,
163
+ ...saved.config,
164
+ configurable: {
165
+ checkpoint_ns: "",
166
+ ...config.configurable,
167
+ ...saved.config.configurable
168
+ }
169
+ };
170
+ const prevCheckpointConfig = saved.parentConfig;
171
+ const checkpoint = (0, _langchain_langgraph_checkpoint.copyCheckpoint)(saved.checkpoint);
172
+ const checkpointMetadata = { ...saved.metadata };
173
+ const checkpointPendingWrites = saved.pendingWrites ?? [];
174
+ const channels = require_base.emptyChannels(params.channelSpecs, checkpoint);
175
+ const step = (checkpointMetadata.step ?? 0) + 1;
176
+ const stop = step + (config.recursionLimit ?? DEFAULT_LOOP_LIMIT) + 1;
177
+ const checkpointPreviousVersions = { ...checkpoint.channel_versions };
178
+ const store = params.store ? new _langchain_langgraph_checkpoint.AsyncBatchedStore(params.store) : void 0;
179
+ if (store) await store.start();
180
+ return new PregelLoop({
181
+ input: params.input,
182
+ config,
183
+ checkpointer: params.checkpointer,
184
+ checkpoint,
185
+ checkpointMetadata,
186
+ checkpointConfig,
187
+ prevCheckpointConfig,
188
+ checkpointNamespace,
189
+ channels,
190
+ isNested,
191
+ manager: params.manager,
192
+ skipDoneTasks,
193
+ step,
194
+ stop,
195
+ checkpointPreviousVersions,
196
+ checkpointPendingWrites,
197
+ outputKeys: params.outputKeys ?? [],
198
+ streamKeys: params.streamKeys ?? [],
199
+ nodes: params.nodes,
200
+ stream,
201
+ store,
202
+ cache: params.cache,
203
+ interruptAfter: params.interruptAfter,
204
+ interruptBefore: params.interruptBefore,
205
+ durability: params.durability,
206
+ debug: params.debug,
207
+ triggerToNodes: params.triggerToNodes
208
+ });
209
+ }
210
+ _checkpointerPutAfterPrevious(input) {
211
+ this._checkpointerChainedPromise = this._checkpointerChainedPromise.then(() => {
212
+ return this.checkpointer?.put(input.config, input.checkpoint, input.metadata, input.newVersions);
213
+ });
214
+ this.checkpointerPromises.push(this._checkpointerChainedPromise);
215
+ }
216
+ /**
217
+ * Put writes for a task, to be read by the next tick.
218
+ * @param taskId
219
+ * @param writes
220
+ */
221
+ putWrites(taskId, writes) {
222
+ let writesCopy = writes;
223
+ if (writesCopy.length === 0) return;
224
+ if (writesCopy.every(([key]) => key in _langchain_langgraph_checkpoint.WRITES_IDX_MAP)) writesCopy = Array.from(new Map(writesCopy.map((w) => [w[0], w])).values());
225
+ this.checkpointPendingWrites = this.checkpointPendingWrites.filter((w) => w[0] !== taskId);
226
+ for (const [c, v] of writesCopy) this.checkpointPendingWrites.push([
227
+ taskId,
228
+ c,
229
+ v
230
+ ]);
231
+ const config = require_index.patchConfigurable(this.checkpointConfig, {
232
+ [require_constants.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
233
+ [require_constants.CONFIG_KEY_CHECKPOINT_ID]: this.checkpoint.id
234
+ });
235
+ if (this.durability !== "exit" && this.checkpointer != null) this.checkpointerPromises.push(this.checkpointer.putWrites(config, writesCopy, taskId));
236
+ if (this.tasks) this._outputWrites(taskId, writesCopy);
237
+ if (!writes.length || !this.cache || !this.tasks) return;
238
+ const task = this.tasks[taskId];
239
+ if (task == null || task.cache_key == null) return;
240
+ if (writes[0][0] === require_constants.ERROR || writes[0][0] === require_constants.INTERRUPT) return;
241
+ this.cache.set([{
242
+ key: [task.cache_key.ns, task.cache_key.key],
243
+ value: task.writes,
244
+ ttl: task.cache_key.ttl
245
+ }]);
246
+ }
247
+ _outputWrites(taskId, writes, cached = false) {
248
+ const task = this.tasks[taskId];
249
+ if (task !== void 0) {
250
+ if (task.config !== void 0 && (task.config.tags ?? []).includes(require_constants.TAG_HIDDEN)) return;
251
+ if (writes.length > 0) {
252
+ if (writes[0][0] === require_constants.INTERRUPT) {
253
+ if (task.path?.[0] === require_constants.PUSH && task.path?.at(-1) === true) return;
254
+ const interruptWrites = writes.filter((w) => w[0] === require_constants.INTERRUPT).flatMap((w) => w[1]);
255
+ this._emit([["updates", { [require_constants.INTERRUPT]: interruptWrites }], ["values", { [require_constants.INTERRUPT]: interruptWrites }]]);
256
+ } else if (writes[0][0] !== require_constants.ERROR) this._emit(require_utils.gatherIteratorSync(require_utils.prefixGenerator(require_io.mapOutputUpdates(this.outputKeys, [[task, writes]], cached), "updates")));
257
+ }
258
+ if (!cached) this._emit(require_utils.gatherIteratorSync(require_utils.prefixGenerator(require_debug.mapDebugTaskResults([[task, writes]], this.streamKeys), "tasks")));
259
+ }
260
+ }
261
+ async _matchCachedWrites() {
262
+ if (!this.cache) return [];
263
+ const matched = [];
264
+ const serializeKey = ([ns, key]) => {
265
+ return `ns:${ns.join(",")}|key:${key}`;
266
+ };
267
+ const keys = [];
268
+ const keyMap = {};
269
+ for (const task of Object.values(this.tasks)) if (task.cache_key != null && !task.writes.length) {
270
+ keys.push([task.cache_key.ns, task.cache_key.key]);
271
+ keyMap[serializeKey([task.cache_key.ns, task.cache_key.key])] = task;
272
+ }
273
+ if (keys.length === 0) return [];
274
+ const cache = await this.cache.get(keys);
275
+ for (const { key, value } of cache) {
276
+ const task = keyMap[serializeKey(key)];
277
+ if (task != null) {
278
+ task.writes.push(...value);
279
+ matched.push({
280
+ task,
281
+ result: value
282
+ });
283
+ }
284
+ }
285
+ return matched;
286
+ }
287
+ /**
288
+ * Execute a single iteration of the Pregel loop.
289
+ * Returns true if more iterations are needed.
290
+ * @param params
291
+ */
292
+ async tick(params) {
293
+ if (this.store && !this.store.isRunning) await this.store?.start();
294
+ const { inputKeys = [] } = params;
295
+ if (this.status !== "pending") throw new Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);
296
+ if (![INPUT_DONE, INPUT_RESUMING].includes(this.input)) await this._first(inputKeys);
297
+ else if (this.toInterrupt.length > 0) {
298
+ this.status = "interrupt_before";
299
+ throw new require_errors.GraphInterrupt();
300
+ } else if (Object.values(this.tasks).every((task) => task.writes.length > 0)) {
301
+ const writes = Object.values(this.tasks).flatMap((t) => t.writes);
302
+ this.updatedChannels = require_algo._applyWrites(this.checkpoint, this.channels, Object.values(this.tasks), this.checkpointerGetNextVersion, this.triggerToNodes);
303
+ const valuesOutput = await require_utils.gatherIterator(require_utils.prefixGenerator(require_io.mapOutputValues(this.outputKeys, writes, this.channels), "values"));
304
+ this._emit(valuesOutput);
305
+ this.checkpointPendingWrites = [];
306
+ await this._putCheckpoint({ source: "loop" });
307
+ if (require_algo.shouldInterrupt(this.checkpoint, this.interruptAfter, Object.values(this.tasks))) {
308
+ this.status = "interrupt_after";
309
+ throw new require_errors.GraphInterrupt();
310
+ }
311
+ if (this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING] !== void 0) delete this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING];
312
+ } else return false;
313
+ if (this.step > this.stop) {
314
+ this.status = "out_of_steps";
315
+ return false;
316
+ }
317
+ this.tasks = require_algo._prepareNextTasks(this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, this.config, true, {
318
+ step: this.step,
319
+ checkpointer: this.checkpointer,
320
+ isResuming: this.isResuming,
321
+ manager: this.manager,
322
+ store: this.store,
323
+ stream: this.stream,
324
+ triggerToNodes: this.triggerToNodes,
325
+ updatedChannels: this.updatedChannels
326
+ });
327
+ if (this.checkpointer) this._emit(await require_utils.gatherIterator(require_utils.prefixGenerator(require_debug.mapDebugCheckpoint(this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites, this.prevCheckpointConfig, this.outputKeys), "checkpoints")));
328
+ if (Object.values(this.tasks).length === 0) {
329
+ this.status = "done";
330
+ return false;
331
+ }
332
+ if (this.skipDoneTasks && this.checkpointPendingWrites.length > 0) {
333
+ for (const [tid, k, v] of this.checkpointPendingWrites) {
334
+ if (k === require_constants.ERROR || k === require_constants.INTERRUPT || k === require_constants.RESUME) continue;
335
+ const task = Object.values(this.tasks).find((t) => t.id === tid);
336
+ if (task) task.writes.push([k, v]);
337
+ }
338
+ for (const task of Object.values(this.tasks)) if (task.writes.length > 0) this._outputWrites(task.id, task.writes, true);
339
+ }
340
+ if (Object.values(this.tasks).every((task) => task.writes.length > 0)) return this.tick({ inputKeys });
341
+ if (require_algo.shouldInterrupt(this.checkpoint, this.interruptBefore, Object.values(this.tasks))) {
342
+ this.status = "interrupt_before";
343
+ throw new require_errors.GraphInterrupt();
344
+ }
345
+ const debugOutput = await require_utils.gatherIterator(require_utils.prefixGenerator(require_debug.mapDebugTasks(Object.values(this.tasks)), "tasks"));
346
+ this._emit(debugOutput);
347
+ return true;
348
+ }
349
+ async finishAndHandleError(error) {
350
+ if (this.durability === "exit" && (!this.isNested || typeof error !== "undefined" || this.checkpointNamespace.every((part) => !part.includes(require_constants.CHECKPOINT_NAMESPACE_END)))) {
351
+ this._putCheckpoint(this.checkpointMetadata);
352
+ this._flushPendingWrites();
353
+ }
354
+ const suppress = this._suppressInterrupt(error);
355
+ if (suppress || error === void 0) this.output = require_io.readChannels(this.channels, this.outputKeys);
356
+ if (suppress) {
357
+ if (this.tasks !== void 0 && this.checkpointPendingWrites.length > 0 && Object.values(this.tasks).some((task) => task.writes.length > 0)) {
358
+ this.updatedChannels = require_algo._applyWrites(this.checkpoint, this.channels, Object.values(this.tasks), this.checkpointerGetNextVersion, this.triggerToNodes);
359
+ this._emit(require_utils.gatherIteratorSync(require_utils.prefixGenerator(require_io.mapOutputValues(this.outputKeys, Object.values(this.tasks).flatMap((t) => t.writes), this.channels), "values")));
360
+ }
361
+ if (require_errors.isGraphInterrupt(error) && !error.interrupts.length) this._emit([["updates", { [require_constants.INTERRUPT]: [] }], ["values", { [require_constants.INTERRUPT]: [] }]]);
362
+ }
363
+ return suppress;
364
+ }
365
+ async acceptPush(task, writeIdx, call) {
366
+ if (this.interruptAfter?.length > 0 && require_algo.shouldInterrupt(this.checkpoint, this.interruptAfter, [task])) {
367
+ this.toInterrupt.push(task);
368
+ return;
369
+ }
370
+ const pushed = require_algo._prepareSingleTask([
371
+ require_constants.PUSH,
372
+ task.path ?? [],
373
+ writeIdx,
374
+ task.id,
375
+ call
376
+ ], this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, task.config ?? {}, true, {
377
+ step: this.step,
378
+ checkpointer: this.checkpointer,
379
+ manager: this.manager,
380
+ store: this.store,
381
+ stream: this.stream
382
+ });
383
+ if (!pushed) return;
384
+ if (this.interruptBefore?.length > 0 && require_algo.shouldInterrupt(this.checkpoint, this.interruptBefore, [pushed])) {
385
+ this.toInterrupt.push(pushed);
386
+ return;
387
+ }
388
+ this._emit(require_utils.gatherIteratorSync(require_utils.prefixGenerator(require_debug.mapDebugTasks([pushed]), "tasks")));
389
+ if (this.debug) require_debug.printStepTasks(this.step, [pushed]);
390
+ this.tasks[pushed.id] = pushed;
391
+ if (this.skipDoneTasks) this._matchWrites({ [pushed.id]: pushed });
392
+ const tasks = await this._matchCachedWrites();
393
+ for (const { task: task$1 } of tasks) this._outputWrites(task$1.id, task$1.writes, true);
394
+ return pushed;
395
+ }
396
+ _suppressInterrupt(e) {
397
+ return require_errors.isGraphInterrupt(e) && !this.isNested;
398
+ }
399
+ async _first(inputKeys) {
400
+ const { configurable } = this.config;
401
+ const scratchpad = configurable?.[require_constants.CONFIG_KEY_SCRATCHPAD];
402
+ if (scratchpad && scratchpad.nullResume !== void 0) this.putWrites(require_constants.NULL_TASK_ID, [[require_constants.RESUME, scratchpad.nullResume]]);
403
+ if (require_constants.isCommand(this.input)) {
404
+ const hasResume = this.input.resume != null;
405
+ if (this.input.resume != null && typeof this.input.resume === "object" && Object.keys(this.input.resume).every(require_hash.isXXH3)) {
406
+ this.config.configurable ??= {};
407
+ this.config.configurable[require_constants.CONFIG_KEY_RESUME_MAP] = this.input.resume;
408
+ }
409
+ if (hasResume && this.checkpointer == null) throw new Error("Cannot use Command(resume=...) without checkpointer");
410
+ const writes = {};
411
+ for (const [tid, key, value] of require_io.mapCommand(this.input, this.checkpointPendingWrites)) {
412
+ writes[tid] ??= [];
413
+ writes[tid].push([key, value]);
414
+ }
415
+ if (Object.keys(writes).length === 0) throw new require_errors.EmptyInputError("Received empty Command input");
416
+ for (const [tid, ws] of Object.entries(writes)) this.putWrites(tid, ws);
417
+ }
418
+ const nullWrites = (this.checkpointPendingWrites ?? []).filter((w) => w[0] === require_constants.NULL_TASK_ID).map((w) => w.slice(1));
419
+ if (nullWrites.length > 0) require_algo._applyWrites(this.checkpoint, this.channels, [{
420
+ name: require_constants.INPUT,
421
+ writes: nullWrites,
422
+ triggers: []
423
+ }], this.checkpointerGetNextVersion, this.triggerToNodes);
424
+ const isCommandUpdateOrGoto = require_constants.isCommand(this.input) && nullWrites.length > 0;
425
+ if (this.isResuming || isCommandUpdateOrGoto) {
426
+ for (const channelName in this.channels) {
427
+ if (!Object.prototype.hasOwnProperty.call(this.channels, channelName)) continue;
428
+ if (this.checkpoint.channel_versions[channelName] !== void 0) {
429
+ const version = this.checkpoint.channel_versions[channelName];
430
+ this.checkpoint.versions_seen[require_constants.INTERRUPT] = {
431
+ ...this.checkpoint.versions_seen[require_constants.INTERRUPT],
432
+ [channelName]: version
433
+ };
434
+ }
435
+ }
436
+ const valuesOutput = await require_utils.gatherIterator(require_utils.prefixGenerator(require_io.mapOutputValues(this.outputKeys, true, this.channels), "values"));
437
+ this._emit(valuesOutput);
438
+ }
439
+ if (this.isResuming) this.input = INPUT_RESUMING;
440
+ else if (isCommandUpdateOrGoto) {
441
+ await this._putCheckpoint({ source: "input" });
442
+ this.input = INPUT_DONE;
443
+ } else {
444
+ const inputWrites = await require_utils.gatherIterator(require_io.mapInput(inputKeys, this.input));
445
+ if (inputWrites.length > 0) {
446
+ const discardTasks = require_algo._prepareNextTasks(this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, this.config, true, { step: this.step });
447
+ this.updatedChannels = require_algo._applyWrites(this.checkpoint, this.channels, Object.values(discardTasks).concat([{
448
+ name: require_constants.INPUT,
449
+ writes: inputWrites,
450
+ triggers: []
451
+ }]), this.checkpointerGetNextVersion, this.triggerToNodes);
452
+ await this._putCheckpoint({ source: "input" });
453
+ this.input = INPUT_DONE;
454
+ } else if (!(require_constants.CONFIG_KEY_RESUMING in (this.config.configurable ?? {}))) throw new require_errors.EmptyInputError(`Received no input writes for ${JSON.stringify(inputKeys, null, 2)}`);
455
+ else this.input = INPUT_DONE;
456
+ }
457
+ if (!this.isNested) this.config = require_index.patchConfigurable(this.config, { [require_constants.CONFIG_KEY_RESUMING]: this.isResuming });
458
+ }
459
+ _emit(values) {
460
+ for (const [mode, payload] of values) {
461
+ if (this.stream.modes.has(mode)) this.stream.push([
462
+ this.checkpointNamespace,
463
+ mode,
464
+ payload
465
+ ]);
466
+ if ((mode === "checkpoints" || mode === "tasks") && this.stream.modes.has("debug")) {
467
+ const step = mode === "checkpoints" ? this.step - 1 : this.step;
468
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
469
+ const type = (() => {
470
+ if (mode === "checkpoints") return "checkpoint";
471
+ else if (typeof payload === "object" && payload != null && "result" in payload) return "task_result";
472
+ else return "task";
473
+ })();
474
+ this.stream.push([
475
+ this.checkpointNamespace,
476
+ "debug",
477
+ {
478
+ step,
479
+ type,
480
+ timestamp,
481
+ payload
482
+ }
483
+ ]);
484
+ }
485
+ }
486
+ }
487
+ _putCheckpoint(inputMetadata) {
488
+ const exiting = this.checkpointMetadata === inputMetadata;
489
+ const doCheckpoint = this.checkpointer != null && (this.durability !== "exit" || exiting);
490
+ const storeCheckpoint = (checkpoint) => {
491
+ this.prevCheckpointConfig = this.checkpointConfig?.configurable?.checkpoint_id ? this.checkpointConfig : void 0;
492
+ this.checkpointConfig = require_index.patchConfigurable(this.checkpointConfig, { [require_constants.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "" });
493
+ const channelVersions = { ...this.checkpoint.channel_versions };
494
+ const newVersions = require_index.getNewChannelVersions(this.checkpointPreviousVersions, channelVersions);
495
+ this.checkpointPreviousVersions = channelVersions;
496
+ this._checkpointerPutAfterPrevious({
497
+ config: { ...this.checkpointConfig },
498
+ checkpoint: (0, _langchain_langgraph_checkpoint.copyCheckpoint)(checkpoint),
499
+ metadata: { ...this.checkpointMetadata },
500
+ newVersions
501
+ });
502
+ this.checkpointConfig = {
503
+ ...this.checkpointConfig,
504
+ configurable: {
505
+ ...this.checkpointConfig.configurable,
506
+ checkpoint_id: this.checkpoint.id
507
+ }
508
+ };
509
+ };
510
+ if (!exiting) this.checkpointMetadata = {
511
+ ...inputMetadata,
512
+ step: this.step,
513
+ parents: this.config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINT_MAP] ?? {}
514
+ };
515
+ this.checkpoint = require_base.createCheckpoint(this.checkpoint, doCheckpoint ? this.channels : void 0, this.step, exiting ? { id: this.checkpoint.id } : void 0);
516
+ if (doCheckpoint) storeCheckpoint(this.checkpoint);
517
+ if (!exiting) this.step += 1;
518
+ }
519
+ _flushPendingWrites() {
520
+ if (this.checkpointer == null) return;
521
+ if (this.checkpointPendingWrites.length === 0) return;
522
+ const config = require_index.patchConfigurable(this.checkpointConfig, {
523
+ [require_constants.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
524
+ [require_constants.CONFIG_KEY_CHECKPOINT_ID]: this.checkpoint.id
525
+ });
526
+ const byTask = {};
527
+ for (const [tid, key, value] of this.checkpointPendingWrites) {
528
+ byTask[tid] ??= [];
529
+ byTask[tid].push([key, value]);
530
+ }
531
+ for (const [tid, ws] of Object.entries(byTask)) this.checkpointerPromises.push(this.checkpointer.putWrites(config, ws, tid));
532
+ }
533
+ _matchWrites(tasks) {
534
+ for (const [tid, k, v] of this.checkpointPendingWrites) {
535
+ if (k === require_constants.ERROR || k === require_constants.INTERRUPT || k === require_constants.RESUME) continue;
536
+ const task = Object.values(tasks).find((t) => t.id === tid);
537
+ if (task) task.writes.push([k, v]);
538
+ }
539
+ for (const task of Object.values(tasks)) if (task.writes.length > 0) this._outputWrites(task.id, task.writes, true);
540
+ }
541
+ };
542
+
543
+ //#endregion
544
+ exports.PregelLoop = PregelLoop;
545
+ //# sourceMappingURL=loop.cjs.map