@langchain/langgraph 0.4.8 → 1.0.0-alpha.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 (494) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/README.md +1 -2
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/channels/any_value.d.cts +26 -0
  5. package/dist/channels/any_value.d.cts.map +1 -0
  6. package/dist/channels/any_value.d.ts +16 -9
  7. package/dist/channels/any_value.d.ts.map +1 -0
  8. package/dist/channels/base.cjs +97 -133
  9. package/dist/channels/base.cjs.map +1 -0
  10. package/dist/channels/base.d.cts +73 -0
  11. package/dist/channels/base.d.cts.map +1 -0
  12. package/dist/channels/base.d.ts +73 -74
  13. package/dist/channels/base.d.ts.map +1 -0
  14. package/dist/channels/base.js +94 -127
  15. package/dist/channels/base.js.map +1 -1
  16. package/dist/channels/binop.cjs +47 -77
  17. package/dist/channels/binop.cjs.map +1 -0
  18. package/dist/channels/binop.d.cts +22 -0
  19. package/dist/channels/binop.d.cts.map +1 -0
  20. package/dist/channels/binop.d.ts +17 -12
  21. package/dist/channels/binop.d.ts.map +1 -0
  22. package/dist/channels/binop.js +45 -71
  23. package/dist/channels/binop.js.map +1 -1
  24. package/dist/channels/dynamic_barrier_value.d.cts +43 -0
  25. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  26. package/dist/channels/dynamic_barrier_value.d.ts +20 -34
  27. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  28. package/dist/channels/ephemeral_value.cjs +46 -70
  29. package/dist/channels/ephemeral_value.cjs.map +1 -0
  30. package/dist/channels/ephemeral_value.d.cts +23 -0
  31. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  32. package/dist/channels/ephemeral_value.d.ts +18 -11
  33. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  34. package/dist/channels/ephemeral_value.js +45 -65
  35. package/dist/channels/ephemeral_value.js.map +1 -1
  36. package/dist/channels/index.cjs +2 -10
  37. package/dist/channels/index.js +4 -3
  38. package/dist/channels/last_value.cjs +91 -140
  39. package/dist/channels/last_value.cjs.map +1 -0
  40. package/dist/channels/last_value.d.cts +30 -0
  41. package/dist/channels/last_value.d.cts.map +1 -0
  42. package/dist/channels/last_value.d.ts +15 -23
  43. package/dist/channels/last_value.d.ts.map +1 -0
  44. package/dist/channels/last_value.js +88 -133
  45. package/dist/channels/last_value.js.map +1 -1
  46. package/dist/channels/named_barrier_value.cjs +114 -170
  47. package/dist/channels/named_barrier_value.cjs.map +1 -0
  48. package/dist/channels/named_barrier_value.d.cts +33 -0
  49. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  50. package/dist/channels/named_barrier_value.d.ts +19 -29
  51. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  52. package/dist/channels/named_barrier_value.js +112 -163
  53. package/dist/channels/named_barrier_value.js.map +1 -1
  54. package/dist/channels/topic.cjs +63 -96
  55. package/dist/channels/topic.cjs.map +1 -0
  56. package/dist/channels/topic.d.cts +26 -0
  57. package/dist/channels/topic.d.cts.map +1 -0
  58. package/dist/channels/topic.d.ts +21 -18
  59. package/dist/channels/topic.d.ts.map +1 -0
  60. package/dist/channels/topic.js +61 -90
  61. package/dist/channels/topic.js.map +1 -1
  62. package/dist/constants.cjs +373 -452
  63. package/dist/constants.cjs.map +1 -0
  64. package/dist/constants.d.cts +284 -0
  65. package/dist/constants.d.cts.map +1 -0
  66. package/dist/constants.d.ts +112 -148
  67. package/dist/constants.d.ts.map +1 -0
  68. package/dist/constants.js +333 -444
  69. package/dist/constants.js.map +1 -1
  70. package/dist/errors.cjs +150 -179
  71. package/dist/errors.cjs.map +1 -0
  72. package/dist/errors.d.cts +80 -0
  73. package/dist/errors.d.cts.map +1 -0
  74. package/dist/errors.d.ts +55 -46
  75. package/dist/errors.d.ts.map +1 -0
  76. package/dist/errors.js +139 -165
  77. package/dist/errors.js.map +1 -1
  78. package/dist/func/index.cjs +289 -290
  79. package/dist/func/index.cjs.map +1 -0
  80. package/dist/func/index.d.cts +289 -0
  81. package/dist/func/index.d.cts.map +1 -0
  82. package/dist/func/index.d.ts +81 -71
  83. package/dist/func/index.d.ts.map +1 -0
  84. package/dist/func/index.js +285 -284
  85. package/dist/func/index.js.map +1 -1
  86. package/dist/func/types.d.cts +64 -0
  87. package/dist/func/types.d.cts.map +1 -0
  88. package/dist/func/types.d.ts +24 -19
  89. package/dist/func/types.d.ts.map +1 -0
  90. package/dist/graph/annotation.cjs +96 -120
  91. package/dist/graph/annotation.cjs.map +1 -0
  92. package/dist/graph/annotation.d.cts +116 -0
  93. package/dist/graph/annotation.d.cts.map +1 -0
  94. package/dist/graph/annotation.d.ts +33 -34
  95. package/dist/graph/annotation.d.ts.map +1 -0
  96. package/dist/graph/annotation.js +91 -112
  97. package/dist/graph/annotation.js.map +1 -1
  98. package/dist/graph/graph.cjs +419 -723
  99. package/dist/graph/graph.cjs.map +1 -0
  100. package/dist/graph/graph.d.cts +131 -0
  101. package/dist/graph/graph.d.cts.map +1 -0
  102. package/dist/graph/graph.d.ts +122 -91
  103. package/dist/graph/graph.d.ts.map +1 -0
  104. package/dist/graph/graph.js +412 -713
  105. package/dist/graph/graph.js.map +1 -1
  106. package/dist/graph/index.cjs +4 -17
  107. package/dist/graph/index.js +6 -5
  108. package/dist/graph/message.cjs +59 -104
  109. package/dist/graph/message.cjs.map +1 -0
  110. package/dist/graph/message.d.cts +19 -0
  111. package/dist/graph/message.d.cts.map +1 -0
  112. package/dist/graph/message.d.ts +11 -10
  113. package/dist/graph/message.d.ts.map +1 -0
  114. package/dist/graph/message.js +56 -98
  115. package/dist/graph/message.js.map +1 -1
  116. package/dist/graph/messages_annotation.cjs +106 -106
  117. package/dist/graph/messages_annotation.cjs.map +1 -0
  118. package/dist/graph/messages_annotation.d.cts +111 -0
  119. package/dist/graph/messages_annotation.d.cts.map +1 -0
  120. package/dist/graph/messages_annotation.d.ts +18 -9
  121. package/dist/graph/messages_annotation.d.ts.map +1 -0
  122. package/dist/graph/messages_annotation.js +100 -100
  123. package/dist/graph/messages_annotation.js.map +1 -1
  124. package/dist/graph/state.cjs +476 -777
  125. package/dist/graph/state.cjs.map +1 -0
  126. package/dist/graph/state.d.cts +216 -0
  127. package/dist/graph/state.d.cts.map +1 -0
  128. package/dist/graph/state.d.ts +129 -134
  129. package/dist/graph/state.d.ts.map +1 -0
  130. package/dist/graph/state.js +470 -768
  131. package/dist/graph/state.js.map +1 -1
  132. package/dist/graph/zod/index.cjs +10 -21
  133. package/dist/graph/zod/index.d.cts +3 -0
  134. package/dist/graph/zod/index.d.ts +3 -3
  135. package/dist/graph/zod/index.js +4 -4
  136. package/dist/graph/zod/meta.cjs +142 -177
  137. package/dist/graph/zod/meta.cjs.map +1 -0
  138. package/dist/graph/zod/meta.d.cts +116 -0
  139. package/dist/graph/zod/meta.d.cts.map +1 -0
  140. package/dist/graph/zod/meta.d.ts +99 -97
  141. package/dist/graph/zod/meta.d.ts.map +1 -0
  142. package/dist/graph/zod/meta.js +136 -170
  143. package/dist/graph/zod/meta.js.map +1 -1
  144. package/dist/graph/zod/plugin.cjs +36 -39
  145. package/dist/graph/zod/plugin.cjs.map +1 -0
  146. package/dist/graph/zod/plugin.js +34 -35
  147. package/dist/graph/zod/plugin.js.map +1 -1
  148. package/dist/graph/zod/schema.cjs +82 -110
  149. package/dist/graph/zod/schema.cjs.map +1 -0
  150. package/dist/graph/zod/schema.d.cts +38 -0
  151. package/dist/graph/zod/schema.d.cts.map +1 -0
  152. package/dist/graph/zod/schema.d.ts +12 -6
  153. package/dist/graph/zod/schema.d.ts.map +1 -0
  154. package/dist/graph/zod/schema.js +77 -103
  155. package/dist/graph/zod/schema.js.map +1 -1
  156. package/dist/graph/zod/zod-registry.cjs +41 -47
  157. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  158. package/dist/graph/zod/zod-registry.d.cts +51 -0
  159. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  160. package/dist/graph/zod/zod-registry.d.ts +34 -26
  161. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  162. package/dist/graph/zod/zod-registry.js +37 -41
  163. package/dist/graph/zod/zod-registry.js.map +1 -1
  164. package/dist/hash.cjs +205 -267
  165. package/dist/hash.cjs.map +1 -0
  166. package/dist/hash.js +205 -265
  167. package/dist/hash.js.map +1 -1
  168. package/dist/index.cjs +110 -33
  169. package/dist/index.cjs.map +1 -0
  170. package/dist/index.d.cts +25 -0
  171. package/dist/index.d.ts +25 -5
  172. package/dist/index.js +18 -7
  173. package/dist/index.js.map +1 -1
  174. package/dist/interrupt.cjs +79 -85
  175. package/dist/interrupt.cjs.map +1 -0
  176. package/dist/interrupt.d.cts +49 -0
  177. package/dist/interrupt.d.cts.map +1 -0
  178. package/dist/interrupt.d.ts +6 -1
  179. package/dist/interrupt.d.ts.map +1 -0
  180. package/dist/interrupt.js +76 -80
  181. package/dist/interrupt.js.map +1 -1
  182. package/dist/prebuilt/agentName.cjs +139 -172
  183. package/dist/prebuilt/agentName.cjs.map +1 -0
  184. package/dist/prebuilt/agentName.d.cts +42 -0
  185. package/dist/prebuilt/agentName.d.cts.map +1 -0
  186. package/dist/prebuilt/agentName.d.ts +13 -21
  187. package/dist/prebuilt/agentName.d.ts.map +1 -0
  188. package/dist/prebuilt/agentName.js +139 -168
  189. package/dist/prebuilt/agentName.js.map +1 -1
  190. package/dist/prebuilt/agent_executor.cjs +42 -80
  191. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  192. package/dist/prebuilt/agent_executor.d.cts +57 -0
  193. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  194. package/dist/prebuilt/agent_executor.d.ts +46 -37
  195. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  196. package/dist/prebuilt/agent_executor.js +40 -75
  197. package/dist/prebuilt/agent_executor.js.map +1 -1
  198. package/dist/prebuilt/chat_agent_executor.cjs +66 -128
  199. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  200. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  201. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  202. package/dist/prebuilt/chat_agent_executor.d.ts +18 -10
  203. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  204. package/dist/prebuilt/chat_agent_executor.js +63 -123
  205. package/dist/prebuilt/chat_agent_executor.js.map +1 -1
  206. package/dist/prebuilt/index.cjs +15 -18
  207. package/dist/prebuilt/index.d.cts +8 -0
  208. package/dist/prebuilt/index.d.ts +8 -8
  209. package/dist/prebuilt/index.js +8 -7
  210. package/dist/prebuilt/interrupt.d.cts +73 -0
  211. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  212. package/dist/prebuilt/interrupt.d.ts +32 -15
  213. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  214. package/dist/prebuilt/react_agent_executor.cjs +317 -473
  215. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  216. package/dist/prebuilt/react_agent_executor.d.cts +229 -0
  217. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  218. package/dist/prebuilt/react_agent_executor.d.ts +171 -143
  219. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  220. package/dist/prebuilt/react_agent_executor.js +315 -465
  221. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  222. package/dist/prebuilt/tool_executor.cjs +45 -67
  223. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  224. package/dist/prebuilt/tool_executor.d.cts +42 -0
  225. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  226. package/dist/prebuilt/tool_executor.d.ts +30 -24
  227. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  228. package/dist/prebuilt/tool_executor.js +44 -63
  229. package/dist/prebuilt/tool_executor.js.map +1 -1
  230. package/dist/prebuilt/tool_node.cjs +213 -275
  231. package/dist/prebuilt/tool_node.cjs.map +1 -0
  232. package/dist/prebuilt/tool_node.d.cts +151 -0
  233. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  234. package/dist/prebuilt/tool_node.d.ts +30 -17
  235. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  236. package/dist/prebuilt/tool_node.js +209 -268
  237. package/dist/prebuilt/tool_node.js.map +1 -1
  238. package/dist/pregel/algo.cjs +521 -692
  239. package/dist/pregel/algo.cjs.map +1 -0
  240. package/dist/pregel/algo.d.cts +13 -0
  241. package/dist/pregel/algo.d.cts.map +1 -0
  242. package/dist/pregel/algo.d.ts +8 -38
  243. package/dist/pregel/algo.d.ts.map +1 -0
  244. package/dist/pregel/algo.js +516 -683
  245. package/dist/pregel/algo.js.map +1 -1
  246. package/dist/pregel/call.cjs +46 -42
  247. package/dist/pregel/call.cjs.map +1 -0
  248. package/dist/pregel/call.js +43 -37
  249. package/dist/pregel/call.js.map +1 -1
  250. package/dist/pregel/debug.cjs +153 -223
  251. package/dist/pregel/debug.cjs.map +1 -0
  252. package/dist/pregel/debug.js +152 -215
  253. package/dist/pregel/debug.js.map +1 -1
  254. package/dist/pregel/index.cjs +1134 -1604
  255. package/dist/pregel/index.cjs.map +1 -0
  256. package/dist/pregel/index.d.cts +534 -0
  257. package/dist/pregel/index.d.cts.map +1 -0
  258. package/dist/pregel/index.d.ts +458 -422
  259. package/dist/pregel/index.d.ts.map +1 -0
  260. package/dist/pregel/index.js +1125 -1592
  261. package/dist/pregel/index.js.map +1 -1
  262. package/dist/pregel/io.cjs +127 -234
  263. package/dist/pregel/io.cjs.map +1 -0
  264. package/dist/pregel/io.js +122 -225
  265. package/dist/pregel/io.js.map +1 -1
  266. package/dist/pregel/loop.cjs +539 -954
  267. package/dist/pregel/loop.cjs.map +1 -0
  268. package/dist/pregel/loop.js +536 -948
  269. package/dist/pregel/loop.js.map +1 -1
  270. package/dist/pregel/messages.cjs +104 -196
  271. package/dist/pregel/messages.cjs.map +1 -0
  272. package/dist/pregel/messages.js +102 -191
  273. package/dist/pregel/messages.js.map +1 -1
  274. package/dist/pregel/read.cjs +150 -280
  275. package/dist/pregel/read.cjs.map +1 -0
  276. package/dist/pregel/read.d.cts +51 -0
  277. package/dist/pregel/read.d.cts.map +1 -0
  278. package/dist/pregel/read.d.ts +48 -46
  279. package/dist/pregel/read.d.ts.map +1 -0
  280. package/dist/pregel/read.js +147 -274
  281. package/dist/pregel/read.js.map +1 -1
  282. package/dist/pregel/remote.cjs +339 -458
  283. package/dist/pregel/remote.cjs.map +1 -0
  284. package/dist/pregel/remote.d.cts +121 -0
  285. package/dist/pregel/remote.d.cts.map +1 -0
  286. package/dist/pregel/remote.d.ts +79 -69
  287. package/dist/pregel/remote.d.ts.map +1 -0
  288. package/dist/pregel/remote.js +337 -453
  289. package/dist/pregel/remote.js.map +1 -1
  290. package/dist/pregel/retry.cjs +87 -138
  291. package/dist/pregel/retry.cjs.map +1 -0
  292. package/dist/pregel/retry.js +83 -130
  293. package/dist/pregel/retry.js.map +1 -1
  294. package/dist/pregel/runnable_types.d.cts +25 -0
  295. package/dist/pregel/runnable_types.d.cts.map +1 -0
  296. package/dist/pregel/runnable_types.d.ts +22 -16
  297. package/dist/pregel/runnable_types.d.ts.map +1 -0
  298. package/dist/pregel/runner.cjs +222 -315
  299. package/dist/pregel/runner.cjs.map +1 -0
  300. package/dist/pregel/runner.js +219 -308
  301. package/dist/pregel/runner.js.map +1 -1
  302. package/dist/pregel/stream.cjs +89 -130
  303. package/dist/pregel/stream.cjs.map +1 -0
  304. package/dist/pregel/stream.js +87 -125
  305. package/dist/pregel/stream.js.map +1 -1
  306. package/dist/pregel/types.cjs +25 -62
  307. package/dist/pregel/types.cjs.map +1 -0
  308. package/dist/pregel/types.d.cts +437 -0
  309. package/dist/pregel/types.d.cts.map +1 -0
  310. package/dist/pregel/types.d.ts +377 -431
  311. package/dist/pregel/types.d.ts.map +1 -0
  312. package/dist/pregel/types.js +23 -57
  313. package/dist/pregel/types.js.map +1 -1
  314. package/dist/pregel/utils/config.cjs +100 -147
  315. package/dist/pregel/utils/config.cjs.map +1 -0
  316. package/dist/pregel/utils/config.d.cts +36 -0
  317. package/dist/pregel/utils/config.d.cts.map +1 -0
  318. package/dist/pregel/utils/config.d.ts +12 -9
  319. package/dist/pregel/utils/config.d.ts.map +1 -0
  320. package/dist/pregel/utils/config.js +98 -143
  321. package/dist/pregel/utils/config.js.map +1 -1
  322. package/dist/pregel/utils/index.cjs +87 -125
  323. package/dist/pregel/utils/index.cjs.map +1 -0
  324. package/dist/pregel/utils/index.d.cts +51 -0
  325. package/dist/pregel/utils/index.d.cts.map +1 -0
  326. package/dist/pregel/utils/index.d.ts +45 -61
  327. package/dist/pregel/utils/index.d.ts.map +1 -0
  328. package/dist/pregel/utils/index.js +86 -120
  329. package/dist/pregel/utils/index.js.map +1 -1
  330. package/dist/pregel/utils/subgraph.cjs +15 -26
  331. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  332. package/dist/pregel/utils/subgraph.js +12 -21
  333. package/dist/pregel/utils/subgraph.js.map +1 -1
  334. package/dist/pregel/validate.cjs +42 -92
  335. package/dist/pregel/validate.cjs.map +1 -0
  336. package/dist/pregel/validate.js +39 -84
  337. package/dist/pregel/validate.js.map +1 -1
  338. package/dist/pregel/write.cjs +87 -137
  339. package/dist/pregel/write.cjs.map +1 -0
  340. package/dist/pregel/write.d.cts +35 -0
  341. package/dist/pregel/write.d.cts.map +1 -0
  342. package/dist/pregel/write.d.ts +27 -23
  343. package/dist/pregel/write.d.ts.map +1 -0
  344. package/dist/pregel/write.js +83 -131
  345. package/dist/pregel/write.js.map +1 -1
  346. package/dist/remote.cjs +3 -6
  347. package/dist/remote.d.cts +2 -0
  348. package/dist/remote.d.ts +2 -1
  349. package/dist/remote.js +3 -2
  350. package/dist/setup/async_local_storage.cjs +10 -7
  351. package/dist/setup/async_local_storage.cjs.map +1 -0
  352. package/dist/setup/async_local_storage.js +7 -2
  353. package/dist/setup/async_local_storage.js.map +1 -1
  354. package/dist/ui/index.cjs +4 -0
  355. package/dist/ui/index.d.cts +5 -0
  356. package/dist/ui/index.d.ts +5 -0
  357. package/dist/ui/index.js +3 -0
  358. package/dist/ui/stream.cjs +145 -0
  359. package/dist/ui/stream.cjs.map +1 -0
  360. package/dist/ui/stream.d.cts +25 -0
  361. package/dist/ui/stream.d.cts.map +1 -0
  362. package/dist/ui/stream.d.ts +25 -0
  363. package/dist/ui/stream.d.ts.map +1 -0
  364. package/dist/ui/stream.js +143 -0
  365. package/dist/ui/stream.js.map +1 -0
  366. package/dist/ui/types.infer.d.cts +53 -0
  367. package/dist/ui/types.infer.d.cts.map +1 -0
  368. package/dist/ui/types.infer.d.ts +53 -0
  369. package/dist/ui/types.infer.d.ts.map +1 -0
  370. package/dist/ui/types.message.d.cts +95 -0
  371. package/dist/ui/types.message.d.cts.map +1 -0
  372. package/dist/ui/types.message.d.ts +95 -0
  373. package/dist/ui/types.message.d.ts.map +1 -0
  374. package/dist/ui/types.schema.d.cts +228 -0
  375. package/dist/ui/types.schema.d.cts.map +1 -0
  376. package/dist/ui/types.schema.d.ts +228 -0
  377. package/dist/ui/types.schema.d.ts.map +1 -0
  378. package/dist/utils.cjs +77 -147
  379. package/dist/utils.cjs.map +1 -0
  380. package/dist/utils.d.cts +32 -0
  381. package/dist/utils.d.cts.map +1 -0
  382. package/dist/utils.d.ts +29 -25
  383. package/dist/utils.d.ts.map +1 -0
  384. package/dist/utils.js +73 -140
  385. package/dist/utils.js.map +1 -1
  386. package/dist/web.cjs +97 -55
  387. package/dist/web.d.cts +23 -0
  388. package/dist/web.d.ts +23 -14
  389. package/dist/web.js +15 -8
  390. package/package.json +83 -86
  391. package/dist/channels/any_value.cjs +0 -65
  392. package/dist/channels/any_value.js +0 -61
  393. package/dist/channels/any_value.js.map +0 -1
  394. package/dist/channels/dynamic_barrier_value.cjs +0 -212
  395. package/dist/channels/dynamic_barrier_value.js +0 -207
  396. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  397. package/dist/channels/index.d.ts +0 -7
  398. package/dist/channels/index.js.map +0 -1
  399. package/dist/func/types.cjs +0 -15
  400. package/dist/func/types.js +0 -12
  401. package/dist/func/types.js.map +0 -1
  402. package/dist/graph/index.d.ts +0 -4
  403. package/dist/graph/index.js.map +0 -1
  404. package/dist/graph/message.test.cjs +0 -196
  405. package/dist/graph/message.test.d.ts +0 -1
  406. package/dist/graph/message.test.js +0 -194
  407. package/dist/graph/message.test.js.map +0 -1
  408. package/dist/graph/zod/index.js.map +0 -1
  409. package/dist/graph/zod/plugin.d.ts +0 -28
  410. package/dist/hash.d.ts +0 -2
  411. package/dist/prebuilt/index.js.map +0 -1
  412. package/dist/prebuilt/interrupt.cjs +0 -3
  413. package/dist/prebuilt/interrupt.js +0 -2
  414. package/dist/prebuilt/interrupt.js.map +0 -1
  415. package/dist/pregel/call.d.ts +0 -16
  416. package/dist/pregel/debug.d.ts +0 -41
  417. package/dist/pregel/debug.test.cjs +0 -258
  418. package/dist/pregel/debug.test.d.ts +0 -1
  419. package/dist/pregel/debug.test.js +0 -256
  420. package/dist/pregel/debug.test.js.map +0 -1
  421. package/dist/pregel/io.d.ts +0 -30
  422. package/dist/pregel/io.mapCommand.test.cjs +0 -150
  423. package/dist/pregel/io.mapCommand.test.d.ts +0 -1
  424. package/dist/pregel/io.mapCommand.test.js +0 -148
  425. package/dist/pregel/io.mapCommand.test.js.map +0 -1
  426. package/dist/pregel/loop.d.ts +0 -147
  427. package/dist/pregel/messages.d.ts +0 -30
  428. package/dist/pregel/messages.test.cjs +0 -369
  429. package/dist/pregel/messages.test.d.ts +0 -1
  430. package/dist/pregel/messages.test.js +0 -367
  431. package/dist/pregel/messages.test.js.map +0 -1
  432. package/dist/pregel/read.test.cjs +0 -194
  433. package/dist/pregel/read.test.d.ts +0 -1
  434. package/dist/pregel/read.test.js +0 -192
  435. package/dist/pregel/read.test.js.map +0 -1
  436. package/dist/pregel/retry.d.ts +0 -17
  437. package/dist/pregel/runnable_types.cjs +0 -3
  438. package/dist/pregel/runnable_types.js +0 -2
  439. package/dist/pregel/runnable_types.js.map +0 -1
  440. package/dist/pregel/runner.d.ts +0 -79
  441. package/dist/pregel/runner.test.cjs +0 -66
  442. package/dist/pregel/runner.test.d.ts +0 -1
  443. package/dist/pregel/runner.test.js +0 -64
  444. package/dist/pregel/runner.test.js.map +0 -1
  445. package/dist/pregel/stream.d.ts +0 -40
  446. package/dist/pregel/utils/config.test.cjs +0 -214
  447. package/dist/pregel/utils/config.test.d.ts +0 -1
  448. package/dist/pregel/utils/config.test.js +0 -212
  449. package/dist/pregel/utils/config.test.js.map +0 -1
  450. package/dist/pregel/utils/subgraph.d.ts +0 -4
  451. package/dist/pregel/utils/subgraph.test.cjs +0 -83
  452. package/dist/pregel/utils/subgraph.test.d.ts +0 -1
  453. package/dist/pregel/utils/subgraph.test.js +0 -81
  454. package/dist/pregel/utils/subgraph.test.js.map +0 -1
  455. package/dist/pregel/validate.d.ts +0 -16
  456. package/dist/pregel/validate.test.cjs +0 -220
  457. package/dist/pregel/validate.test.d.ts +0 -1
  458. package/dist/pregel/validate.test.js +0 -218
  459. package/dist/pregel/validate.test.js.map +0 -1
  460. package/dist/pregel/write.test.cjs +0 -181
  461. package/dist/pregel/write.test.d.ts +0 -1
  462. package/dist/pregel/write.test.js +0 -179
  463. package/dist/pregel/write.test.js.map +0 -1
  464. package/dist/remote.js.map +0 -1
  465. package/dist/setup/async_local_storage.d.ts +0 -1
  466. package/dist/web.js.map +0 -1
  467. package/index.cjs +0 -1
  468. package/index.d.cts +0 -1
  469. package/index.d.ts +0 -1
  470. package/index.js +0 -1
  471. package/prebuilt.cjs +0 -1
  472. package/prebuilt.d.cts +0 -1
  473. package/prebuilt.d.ts +0 -1
  474. package/prebuilt.js +0 -1
  475. package/pregel.cjs +0 -1
  476. package/pregel.d.cts +0 -1
  477. package/pregel.d.ts +0 -1
  478. package/pregel.js +0 -1
  479. package/remote.cjs +0 -1
  480. package/remote.d.cts +0 -1
  481. package/remote.d.ts +0 -1
  482. package/remote.js +0 -1
  483. package/web.cjs +0 -1
  484. package/web.d.cts +0 -1
  485. package/web.d.ts +0 -1
  486. package/web.js +0 -1
  487. package/zod/schema.cjs +0 -1
  488. package/zod/schema.d.cts +0 -1
  489. package/zod/schema.d.ts +0 -1
  490. package/zod/schema.js +0 -1
  491. package/zod.cjs +0 -1
  492. package/zod.d.cts +0 -1
  493. package/zod.d.ts +0 -1
  494. package/zod.js +0 -1
@@ -1,960 +1,545 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PregelLoop = void 0;
4
- const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
5
- const base_js_1 = require("../channels/base.cjs");
6
- const constants_js_1 = require("../constants.cjs");
7
- const algo_js_1 = require("./algo.cjs");
8
- const utils_js_1 = require("../utils.cjs");
9
- const io_js_1 = require("./io.cjs");
10
- const errors_js_1 = require("../errors.cjs");
11
- const index_js_1 = require("./utils/index.cjs");
12
- const debug_js_1 = require("./debug.cjs");
13
- const stream_js_1 = require("./stream.cjs");
14
- const hash_js_1 = require("../hash.cjs");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('../errors.cjs');
3
+ const require_base = require('../channels/base.cjs');
4
+ const require_constants = require('../constants.cjs');
5
+ const require_utils = require('../utils.cjs');
6
+ const require_hash = require('../hash.cjs');
7
+ const require_io = require('./io.cjs');
8
+ const require_index = require('./utils/index.cjs');
9
+ const require_algo = require('./algo.cjs');
10
+ const require_debug = require('./debug.cjs');
11
+ const require_stream = require('./stream.cjs');
12
+ const __langchain_langgraph_checkpoint = require_rolldown_runtime.__toESM(require("@langchain/langgraph-checkpoint"));
13
+
14
+ //#region src/pregel/loop.ts
15
15
  const INPUT_DONE = Symbol.for("INPUT_DONE");
16
16
  const INPUT_RESUMING = Symbol.for("INPUT_RESUMING");
17
17
  const DEFAULT_LOOP_LIMIT = 25;
18
18
  function createDuplexStream(...streams) {
19
- return new stream_js_1.IterableReadableWritableStream({
20
- passthroughFn: (value) => {
21
- for (const stream of streams) {
22
- if (stream.modes.has(value[1])) {
23
- stream.push(value);
24
- }
25
- }
26
- },
27
- modes: new Set(streams.flatMap((s) => Array.from(s.modes))),
28
- });
29
- }
30
- class AsyncBatchedCache extends langgraph_checkpoint_1.BaseCache {
31
- constructor(cache) {
32
- super();
33
- Object.defineProperty(this, "cache", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: void 0
38
- });
39
- Object.defineProperty(this, "queue", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: Promise.resolve()
44
- });
45
- this.cache = cache;
46
- }
47
- async get(keys) {
48
- return this.enqueueOperation("get", keys);
49
- }
50
- async set(pairs) {
51
- return this.enqueueOperation("set", pairs);
52
- }
53
- async clear(namespaces) {
54
- return this.enqueueOperation("clear", namespaces);
55
- }
56
- async stop() {
57
- await this.queue;
58
- }
59
- enqueueOperation(type, ...args) {
60
- const newPromise = this.queue.then(() => {
61
- // @ts-expect-error Tuple type warning
62
- return this.cache[type](...args);
63
- });
64
- this.queue = newPromise.then(() => void 0, () => void 0);
65
- return newPromise;
66
- }
67
- }
68
- class PregelLoop {
69
- get isResuming() {
70
- let hasChannelVersions = false;
71
- if (constants_js_1.START in this.checkpoint.channel_versions) {
72
- // For common channels, we can short-circuit the check
73
- hasChannelVersions = true;
74
- }
75
- else {
76
- for (const chan in this.checkpoint.channel_versions) {
77
- if (Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions, chan)) {
78
- hasChannelVersions = true;
79
- break;
80
- }
81
- }
82
- }
83
- const configHasResumingFlag = this.config.configurable?.[constants_js_1.CONFIG_KEY_RESUMING] !== undefined;
84
- const configIsResuming = configHasResumingFlag && this.config.configurable?.[constants_js_1.CONFIG_KEY_RESUMING];
85
- const inputIsNullOrUndefined = this.input === null || this.input === undefined;
86
- const inputIsCommandResuming = (0, constants_js_1.isCommand)(this.input) && this.input.resume != null;
87
- const inputIsResuming = this.input === INPUT_RESUMING;
88
- const runIdMatchesPrevious = !this.isNested &&
89
- this.config.metadata?.run_id !== undefined &&
90
- this.checkpointMetadata?.run_id !== undefined &&
91
- this.config.metadata.run_id ===
92
- this.checkpointMetadata?.run_id;
93
- return (hasChannelVersions &&
94
- (configIsResuming ||
95
- inputIsNullOrUndefined ||
96
- inputIsCommandResuming ||
97
- inputIsResuming ||
98
- runIdMatchesPrevious));
99
- }
100
- constructor(params) {
101
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
- Object.defineProperty(this, "input", {
103
- enumerable: true,
104
- configurable: true,
105
- writable: true,
106
- value: void 0
107
- });
108
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
- Object.defineProperty(this, "output", {
110
- enumerable: true,
111
- configurable: true,
112
- writable: true,
113
- value: void 0
114
- });
115
- Object.defineProperty(this, "config", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: void 0
120
- });
121
- Object.defineProperty(this, "checkpointer", {
122
- enumerable: true,
123
- configurable: true,
124
- writable: true,
125
- value: void 0
126
- });
127
- Object.defineProperty(this, "checkpointerGetNextVersion", {
128
- enumerable: true,
129
- configurable: true,
130
- writable: true,
131
- value: void 0
132
- });
133
- Object.defineProperty(this, "channels", {
134
- enumerable: true,
135
- configurable: true,
136
- writable: true,
137
- value: void 0
138
- });
139
- Object.defineProperty(this, "checkpoint", {
140
- enumerable: true,
141
- configurable: true,
142
- writable: true,
143
- value: void 0
144
- });
145
- Object.defineProperty(this, "checkpointIdSaved", {
146
- enumerable: true,
147
- configurable: true,
148
- writable: true,
149
- value: void 0
150
- });
151
- Object.defineProperty(this, "checkpointConfig", {
152
- enumerable: true,
153
- configurable: true,
154
- writable: true,
155
- value: void 0
156
- });
157
- Object.defineProperty(this, "checkpointMetadata", {
158
- enumerable: true,
159
- configurable: true,
160
- writable: true,
161
- value: void 0
162
- });
163
- Object.defineProperty(this, "checkpointNamespace", {
164
- enumerable: true,
165
- configurable: true,
166
- writable: true,
167
- value: void 0
168
- });
169
- Object.defineProperty(this, "checkpointPendingWrites", {
170
- enumerable: true,
171
- configurable: true,
172
- writable: true,
173
- value: []
174
- });
175
- Object.defineProperty(this, "checkpointPreviousVersions", {
176
- enumerable: true,
177
- configurable: true,
178
- writable: true,
179
- value: void 0
180
- });
181
- Object.defineProperty(this, "step", {
182
- enumerable: true,
183
- configurable: true,
184
- writable: true,
185
- value: void 0
186
- });
187
- Object.defineProperty(this, "stop", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: void 0
192
- });
193
- Object.defineProperty(this, "durability", {
194
- enumerable: true,
195
- configurable: true,
196
- writable: true,
197
- value: void 0
198
- });
199
- Object.defineProperty(this, "outputKeys", {
200
- enumerable: true,
201
- configurable: true,
202
- writable: true,
203
- value: void 0
204
- });
205
- Object.defineProperty(this, "streamKeys", {
206
- enumerable: true,
207
- configurable: true,
208
- writable: true,
209
- value: void 0
210
- });
211
- Object.defineProperty(this, "nodes", {
212
- enumerable: true,
213
- configurable: true,
214
- writable: true,
215
- value: void 0
216
- });
217
- Object.defineProperty(this, "skipDoneTasks", {
218
- enumerable: true,
219
- configurable: true,
220
- writable: true,
221
- value: void 0
222
- });
223
- Object.defineProperty(this, "prevCheckpointConfig", {
224
- enumerable: true,
225
- configurable: true,
226
- writable: true,
227
- value: void 0
228
- });
229
- Object.defineProperty(this, "status", {
230
- enumerable: true,
231
- configurable: true,
232
- writable: true,
233
- value: "pending"
234
- });
235
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
- Object.defineProperty(this, "tasks", {
237
- enumerable: true,
238
- configurable: true,
239
- writable: true,
240
- value: {}
241
- });
242
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
- Object.defineProperty(this, "stream", {
244
- enumerable: true,
245
- configurable: true,
246
- writable: true,
247
- value: void 0
248
- });
249
- Object.defineProperty(this, "checkpointerPromises", {
250
- enumerable: true,
251
- configurable: true,
252
- writable: true,
253
- value: []
254
- });
255
- Object.defineProperty(this, "isNested", {
256
- enumerable: true,
257
- configurable: true,
258
- writable: true,
259
- value: void 0
260
- });
261
- Object.defineProperty(this, "_checkpointerChainedPromise", {
262
- enumerable: true,
263
- configurable: true,
264
- writable: true,
265
- value: Promise.resolve()
266
- });
267
- Object.defineProperty(this, "store", {
268
- enumerable: true,
269
- configurable: true,
270
- writable: true,
271
- value: void 0
272
- });
273
- Object.defineProperty(this, "cache", {
274
- enumerable: true,
275
- configurable: true,
276
- writable: true,
277
- value: void 0
278
- });
279
- Object.defineProperty(this, "manager", {
280
- enumerable: true,
281
- configurable: true,
282
- writable: true,
283
- value: void 0
284
- });
285
- Object.defineProperty(this, "interruptAfter", {
286
- enumerable: true,
287
- configurable: true,
288
- writable: true,
289
- value: void 0
290
- });
291
- Object.defineProperty(this, "interruptBefore", {
292
- enumerable: true,
293
- configurable: true,
294
- writable: true,
295
- value: void 0
296
- });
297
- Object.defineProperty(this, "toInterrupt", {
298
- enumerable: true,
299
- configurable: true,
300
- writable: true,
301
- value: []
302
- });
303
- Object.defineProperty(this, "debug", {
304
- enumerable: true,
305
- configurable: true,
306
- writable: true,
307
- value: false
308
- });
309
- Object.defineProperty(this, "triggerToNodes", {
310
- enumerable: true,
311
- configurable: true,
312
- writable: true,
313
- value: void 0
314
- });
315
- this.input = params.input;
316
- this.checkpointer = params.checkpointer;
317
- // TODO: if managed values no longer needs graph we can replace with
318
- // managed_specs, channel_specs
319
- if (this.checkpointer !== undefined) {
320
- this.checkpointerGetNextVersion = this.checkpointer.getNextVersion.bind(this.checkpointer);
321
- }
322
- else {
323
- this.checkpointerGetNextVersion = algo_js_1.increment;
324
- }
325
- this.checkpoint = params.checkpoint;
326
- this.checkpointMetadata = params.checkpointMetadata;
327
- this.checkpointPreviousVersions = params.checkpointPreviousVersions;
328
- this.channels = params.channels;
329
- this.checkpointPendingWrites = params.checkpointPendingWrites;
330
- this.step = params.step;
331
- this.stop = params.stop;
332
- this.config = params.config;
333
- this.checkpointConfig = params.checkpointConfig;
334
- this.isNested = params.isNested;
335
- this.manager = params.manager;
336
- this.outputKeys = params.outputKeys;
337
- this.streamKeys = params.streamKeys;
338
- this.nodes = params.nodes;
339
- this.skipDoneTasks = params.skipDoneTasks;
340
- this.store = params.store;
341
- this.cache = params.cache ? new AsyncBatchedCache(params.cache) : undefined;
342
- this.stream = params.stream;
343
- this.checkpointNamespace = params.checkpointNamespace;
344
- this.prevCheckpointConfig = params.prevCheckpointConfig;
345
- this.interruptAfter = params.interruptAfter;
346
- this.interruptBefore = params.interruptBefore;
347
- this.durability = params.durability;
348
- this.debug = params.debug;
349
- this.triggerToNodes = params.triggerToNodes;
350
- }
351
- static async initialize(params) {
352
- let { config, stream } = params;
353
- if (stream !== undefined &&
354
- config.configurable?.[constants_js_1.CONFIG_KEY_STREAM] !== undefined) {
355
- stream = createDuplexStream(stream, config.configurable[constants_js_1.CONFIG_KEY_STREAM]);
356
- }
357
- const skipDoneTasks = config.configurable
358
- ? !("checkpoint_id" in config.configurable)
359
- : true;
360
- const scratchpad = config.configurable?.[constants_js_1.CONFIG_KEY_SCRATCHPAD];
361
- if (config.configurable && scratchpad) {
362
- if (scratchpad.subgraphCounter > 0) {
363
- config = (0, index_js_1.patchConfigurable)(config, {
364
- [constants_js_1.CONFIG_KEY_CHECKPOINT_NS]: [
365
- config.configurable[constants_js_1.CONFIG_KEY_CHECKPOINT_NS],
366
- scratchpad.subgraphCounter.toString(),
367
- ].join(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR),
368
- });
369
- }
370
- scratchpad.subgraphCounter += 1;
371
- }
372
- const isNested = constants_js_1.CONFIG_KEY_READ in (config.configurable ?? {});
373
- if (!isNested &&
374
- config.configurable?.checkpoint_ns !== undefined &&
375
- config.configurable?.checkpoint_ns !== "") {
376
- config = (0, index_js_1.patchConfigurable)(config, {
377
- checkpoint_ns: "",
378
- checkpoint_id: undefined,
379
- });
380
- }
381
- let checkpointConfig = config;
382
- if (config.configurable?.[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP] !== undefined &&
383
- config.configurable?.[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP]?.[config.configurable?.checkpoint_ns]) {
384
- checkpointConfig = (0, index_js_1.patchConfigurable)(config, {
385
- checkpoint_id: config.configurable[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP][config.configurable?.checkpoint_ns],
386
- });
387
- }
388
- const checkpointNamespace = config.configurable?.checkpoint_ns?.split(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR) ?? [];
389
- const saved = (await params.checkpointer?.getTuple(checkpointConfig)) ?? {
390
- config,
391
- checkpoint: (0, langgraph_checkpoint_1.emptyCheckpoint)(),
392
- metadata: { source: "input", step: -2, parents: {} },
393
- pendingWrites: [],
394
- };
395
- checkpointConfig = {
396
- ...config,
397
- ...saved.config,
398
- configurable: {
399
- checkpoint_ns: "",
400
- ...config.configurable,
401
- ...saved.config.configurable,
402
- },
403
- };
404
- const prevCheckpointConfig = saved.parentConfig;
405
- const checkpoint = (0, langgraph_checkpoint_1.copyCheckpoint)(saved.checkpoint);
406
- const checkpointMetadata = { ...saved.metadata };
407
- const checkpointPendingWrites = saved.pendingWrites ?? [];
408
- const channels = (0, base_js_1.emptyChannels)(params.channelSpecs, checkpoint);
409
- const step = (checkpointMetadata.step ?? 0) + 1;
410
- const stop = step + (config.recursionLimit ?? DEFAULT_LOOP_LIMIT) + 1;
411
- const checkpointPreviousVersions = { ...checkpoint.channel_versions };
412
- const store = params.store
413
- ? new langgraph_checkpoint_1.AsyncBatchedStore(params.store)
414
- : undefined;
415
- if (store) {
416
- // Start the store. This is a batch store, so it will run continuously
417
- await store.start();
418
- }
419
- return new PregelLoop({
420
- input: params.input,
421
- config,
422
- checkpointer: params.checkpointer,
423
- checkpoint,
424
- checkpointMetadata,
425
- checkpointConfig,
426
- prevCheckpointConfig,
427
- checkpointNamespace,
428
- channels,
429
- isNested,
430
- manager: params.manager,
431
- skipDoneTasks,
432
- step,
433
- stop,
434
- checkpointPreviousVersions,
435
- checkpointPendingWrites,
436
- outputKeys: params.outputKeys ?? [],
437
- streamKeys: params.streamKeys ?? [],
438
- nodes: params.nodes,
439
- stream,
440
- store,
441
- cache: params.cache,
442
- interruptAfter: params.interruptAfter,
443
- interruptBefore: params.interruptBefore,
444
- durability: params.durability,
445
- debug: params.debug,
446
- triggerToNodes: params.triggerToNodes,
447
- });
448
- }
449
- _checkpointerPutAfterPrevious(input) {
450
- this._checkpointerChainedPromise = this._checkpointerChainedPromise.then(() => {
451
- return this.checkpointer?.put(input.config, input.checkpoint, input.metadata, input.newVersions);
452
- });
453
- this.checkpointerPromises.push(this._checkpointerChainedPromise);
454
- }
455
- /**
456
- * Put writes for a task, to be read by the next tick.
457
- * @param taskId
458
- * @param writes
459
- */
460
- putWrites(taskId, writes) {
461
- let writesCopy = writes;
462
- if (writesCopy.length === 0)
463
- return;
464
- // deduplicate writes to special channels, last write wins
465
- if (writesCopy.every(([key]) => key in langgraph_checkpoint_1.WRITES_IDX_MAP)) {
466
- writesCopy = Array.from(new Map(writesCopy.map((w) => [w[0], w])).values());
467
- }
468
- // remove existing writes for this task
469
- this.checkpointPendingWrites = this.checkpointPendingWrites.filter((w) => w[0] !== taskId);
470
- // save writes
471
- for (const [c, v] of writesCopy) {
472
- this.checkpointPendingWrites.push([taskId, c, v]);
473
- }
474
- const config = (0, index_js_1.patchConfigurable)(this.checkpointConfig, {
475
- [constants_js_1.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
476
- [constants_js_1.CONFIG_KEY_CHECKPOINT_ID]: this.checkpoint.id,
477
- });
478
- if (this.durability !== "exit" && this.checkpointer != null) {
479
- this.checkpointerPromises.push(this.checkpointer.putWrites(config, writesCopy, taskId));
480
- }
481
- if (this.tasks) {
482
- this._outputWrites(taskId, writesCopy);
483
- }
484
- if (!writes.length || !this.cache || !this.tasks) {
485
- return;
486
- }
487
- // only cache tasks with a cache key
488
- const task = this.tasks[taskId];
489
- if (task == null || task.cache_key == null) {
490
- return;
491
- }
492
- // only cache successful tasks
493
- if (writes[0][0] === constants_js_1.ERROR || writes[0][0] === constants_js_1.INTERRUPT) {
494
- return;
495
- }
496
- void this.cache.set([
497
- {
498
- key: [task.cache_key.ns, task.cache_key.key],
499
- value: task.writes,
500
- ttl: task.cache_key.ttl,
501
- },
502
- ]);
503
- }
504
- _outputWrites(taskId, writes, cached = false) {
505
- const task = this.tasks[taskId];
506
- if (task !== undefined) {
507
- if (task.config !== undefined &&
508
- (task.config.tags ?? []).includes(constants_js_1.TAG_HIDDEN)) {
509
- return;
510
- }
511
- if (writes.length > 0) {
512
- if (writes[0][0] === constants_js_1.INTERRUPT) {
513
- // in `algo.ts` we append a bool to the task path to indicate
514
- // whether or not a call was present. If so, we don't emit the
515
- // the interrupt as it'll be emitted by the parent.
516
- if (task.path?.[0] === constants_js_1.PUSH && task.path?.at(-1) === true)
517
- return;
518
- const interruptWrites = writes
519
- .filter((w) => w[0] === constants_js_1.INTERRUPT)
520
- .flatMap((w) => w[1]);
521
- this._emit([
522
- ["updates", { [constants_js_1.INTERRUPT]: interruptWrites }],
523
- ["values", { [constants_js_1.INTERRUPT]: interruptWrites }],
524
- ]);
525
- }
526
- else if (writes[0][0] !== constants_js_1.ERROR) {
527
- this._emit((0, utils_js_1.gatherIteratorSync)((0, utils_js_1.prefixGenerator)((0, io_js_1.mapOutputUpdates)(this.outputKeys, [[task, writes]], cached), "updates")));
528
- }
529
- }
530
- if (!cached) {
531
- this._emit((0, utils_js_1.gatherIteratorSync)((0, utils_js_1.prefixGenerator)((0, debug_js_1.mapDebugTaskResults)([[task, writes]], this.streamKeys), "tasks")));
532
- }
533
- }
534
- }
535
- async _matchCachedWrites() {
536
- if (!this.cache)
537
- return [];
538
- const matched = [];
539
- const serializeKey = ([ns, key]) => {
540
- return `ns:${ns.join(",")}|key:${key}`;
541
- };
542
- const keys = [];
543
- const keyMap = {};
544
- for (const task of Object.values(this.tasks)) {
545
- if (task.cache_key != null && !task.writes.length) {
546
- keys.push([task.cache_key.ns, task.cache_key.key]);
547
- keyMap[serializeKey([task.cache_key.ns, task.cache_key.key])] = task;
548
- }
549
- }
550
- if (keys.length === 0)
551
- return [];
552
- const cache = await this.cache.get(keys);
553
- for (const { key, value } of cache) {
554
- const task = keyMap[serializeKey(key)];
555
- if (task != null) {
556
- // update the task with the cached writes
557
- task.writes.push(...value);
558
- matched.push({ task, result: value });
559
- }
560
- }
561
- return matched;
562
- }
563
- /**
564
- * Execute a single iteration of the Pregel loop.
565
- * Returns true if more iterations are needed.
566
- * @param params
567
- */
568
- async tick(params) {
569
- if (this.store && !this.store.isRunning) {
570
- await this.store?.start();
571
- }
572
- const { inputKeys = [] } = params;
573
- if (this.status !== "pending") {
574
- throw new Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);
575
- }
576
- if (![INPUT_DONE, INPUT_RESUMING].includes(this.input)) {
577
- await this._first(inputKeys);
578
- }
579
- else if (this.toInterrupt.length > 0) {
580
- this.status = "interrupt_before";
581
- throw new errors_js_1.GraphInterrupt();
582
- }
583
- else if (Object.values(this.tasks).every((task) => task.writes.length > 0)) {
584
- // finish superstep
585
- const writes = Object.values(this.tasks).flatMap((t) => t.writes);
586
- // All tasks have finished
587
- (0, algo_js_1._applyWrites)(this.checkpoint, this.channels, Object.values(this.tasks), this.checkpointerGetNextVersion, this.triggerToNodes);
588
- // produce values output
589
- const valuesOutput = await (0, utils_js_1.gatherIterator)((0, utils_js_1.prefixGenerator)((0, io_js_1.mapOutputValues)(this.outputKeys, writes, this.channels), "values"));
590
- this._emit(valuesOutput);
591
- // clear pending writes
592
- this.checkpointPendingWrites = [];
593
- await this._putCheckpoint({ source: "loop" });
594
- // after execution, check if we should interrupt
595
- if ((0, algo_js_1.shouldInterrupt)(this.checkpoint, this.interruptAfter, Object.values(this.tasks))) {
596
- this.status = "interrupt_after";
597
- throw new errors_js_1.GraphInterrupt();
598
- }
599
- // unset resuming flag
600
- if (this.config.configurable?.[constants_js_1.CONFIG_KEY_RESUMING] !== undefined) {
601
- delete this.config.configurable?.[constants_js_1.CONFIG_KEY_RESUMING];
602
- }
603
- }
604
- else {
605
- return false;
606
- }
607
- if (this.step > this.stop) {
608
- this.status = "out_of_steps";
609
- return false;
610
- }
611
- const nextTasks = (0, algo_js_1._prepareNextTasks)(this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, this.config, true, {
612
- step: this.step,
613
- checkpointer: this.checkpointer,
614
- isResuming: this.isResuming,
615
- manager: this.manager,
616
- store: this.store,
617
- stream: this.stream,
618
- });
619
- this.tasks = nextTasks;
620
- // Produce debug output
621
- if (this.checkpointer) {
622
- this._emit(await (0, utils_js_1.gatherIterator)((0, utils_js_1.prefixGenerator)((0, debug_js_1.mapDebugCheckpoint)(this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites, this.prevCheckpointConfig, this.outputKeys), "checkpoints")));
623
- }
624
- if (Object.values(this.tasks).length === 0) {
625
- this.status = "done";
626
- return false;
627
- }
628
- // if there are pending writes from a previous loop, apply them
629
- if (this.skipDoneTasks && this.checkpointPendingWrites.length > 0) {
630
- for (const [tid, k, v] of this.checkpointPendingWrites) {
631
- if (k === constants_js_1.ERROR || k === constants_js_1.INTERRUPT || k === constants_js_1.RESUME) {
632
- continue;
633
- }
634
- const task = Object.values(this.tasks).find((t) => t.id === tid);
635
- if (task) {
636
- task.writes.push([k, v]);
637
- }
638
- }
639
- for (const task of Object.values(this.tasks)) {
640
- if (task.writes.length > 0) {
641
- this._outputWrites(task.id, task.writes, true);
642
- }
643
- }
644
- }
645
- // if all tasks have finished, re-tick
646
- if (Object.values(this.tasks).every((task) => task.writes.length > 0)) {
647
- return this.tick({ inputKeys });
648
- }
649
- // Before execution, check if we should interrupt
650
- if ((0, algo_js_1.shouldInterrupt)(this.checkpoint, this.interruptBefore, Object.values(this.tasks))) {
651
- this.status = "interrupt_before";
652
- throw new errors_js_1.GraphInterrupt();
653
- }
654
- // Produce debug output
655
- const debugOutput = await (0, utils_js_1.gatherIterator)((0, utils_js_1.prefixGenerator)((0, debug_js_1.mapDebugTasks)(Object.values(this.tasks)), "tasks"));
656
- this._emit(debugOutput);
657
- return true;
658
- }
659
- async finishAndHandleError(error) {
660
- // persist current checkpoint and writes
661
- if (this.durability === "exit" &&
662
- // if it's a top graph
663
- (!this.isNested ||
664
- // or a nested graph with error or interrupt
665
- typeof error !== "undefined" ||
666
- // or a nested graph with checkpointer: true
667
- this.checkpointNamespace.every((part) => !part.includes(constants_js_1.CHECKPOINT_NAMESPACE_END)))) {
668
- this._putCheckpoint(this.checkpointMetadata);
669
- this._flushPendingWrites();
670
- }
671
- const suppress = this._suppressInterrupt(error);
672
- if (suppress || error === undefined) {
673
- this.output = (0, io_js_1.readChannels)(this.channels, this.outputKeys);
674
- }
675
- if (suppress) {
676
- // emit one last "values" event, with pending writes applied
677
- if (this.tasks !== undefined &&
678
- this.checkpointPendingWrites.length > 0 &&
679
- Object.values(this.tasks).some((task) => task.writes.length > 0)) {
680
- (0, algo_js_1._applyWrites)(this.checkpoint, this.channels, Object.values(this.tasks), this.checkpointerGetNextVersion, this.triggerToNodes);
681
- this._emit((0, utils_js_1.gatherIteratorSync)((0, utils_js_1.prefixGenerator)((0, io_js_1.mapOutputValues)(this.outputKeys, Object.values(this.tasks).flatMap((t) => t.writes), this.channels), "values")));
682
- }
683
- // Emit INTERRUPT event
684
- if ((0, errors_js_1.isGraphInterrupt)(error) && !error.interrupts.length) {
685
- this._emit([
686
- ["updates", { [constants_js_1.INTERRUPT]: [] }],
687
- ["values", { [constants_js_1.INTERRUPT]: [] }],
688
- ]);
689
- }
690
- }
691
- return suppress;
692
- }
693
- async acceptPush(task, writeIdx, call) {
694
- if (this.interruptAfter?.length > 0 &&
695
- (0, algo_js_1.shouldInterrupt)(this.checkpoint, this.interruptAfter, [task])) {
696
- this.toInterrupt.push(task);
697
- return;
698
- }
699
- const pushed = (0, algo_js_1._prepareSingleTask)([constants_js_1.PUSH, task.path ?? [], writeIdx, task.id, call], this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, task.config ?? {}, true, {
700
- step: this.step,
701
- checkpointer: this.checkpointer,
702
- manager: this.manager,
703
- store: this.store,
704
- stream: this.stream,
705
- });
706
- if (!pushed)
707
- return;
708
- if (this.interruptBefore?.length > 0 &&
709
- (0, algo_js_1.shouldInterrupt)(this.checkpoint, this.interruptBefore, [pushed])) {
710
- this.toInterrupt.push(pushed);
711
- return;
712
- }
713
- this._emit((0, utils_js_1.gatherIteratorSync)((0, utils_js_1.prefixGenerator)((0, debug_js_1.mapDebugTasks)([pushed]), "tasks")));
714
- if (this.debug)
715
- (0, debug_js_1.printStepTasks)(this.step, [pushed]);
716
- this.tasks[pushed.id] = pushed;
717
- if (this.skipDoneTasks)
718
- this._matchWrites({ [pushed.id]: pushed });
719
- const tasks = await this._matchCachedWrites();
720
- for (const { task } of tasks) {
721
- this._outputWrites(task.id, task.writes, true);
722
- }
723
- return pushed;
724
- }
725
- _suppressInterrupt(e) {
726
- return (0, errors_js_1.isGraphInterrupt)(e) && !this.isNested;
727
- }
728
- async _first(inputKeys) {
729
- /*
730
- * Resuming from previous checkpoint requires
731
- * - finding a previous checkpoint
732
- * - receiving null input (outer graph) or RESUMING flag (subgraph)
733
- */
734
- const { configurable } = this.config;
735
- // take resume value from parent
736
- const scratchpad = configurable?.[constants_js_1.CONFIG_KEY_SCRATCHPAD];
737
- if (scratchpad && scratchpad.nullResume !== undefined) {
738
- this.putWrites(constants_js_1.NULL_TASK_ID, [[constants_js_1.RESUME, scratchpad.nullResume]]);
739
- }
740
- // map command to writes
741
- if ((0, constants_js_1.isCommand)(this.input)) {
742
- const hasResume = this.input.resume != null;
743
- if (this.input.resume != null &&
744
- typeof this.input.resume === "object" &&
745
- Object.keys(this.input.resume).every(hash_js_1.isXXH3)) {
746
- this.config.configurable ??= {};
747
- this.config.configurable[constants_js_1.CONFIG_KEY_RESUME_MAP] = this.input.resume;
748
- }
749
- if (hasResume && this.checkpointer == null) {
750
- throw new Error("Cannot use Command(resume=...) without checkpointer");
751
- }
752
- const writes = {};
753
- // group writes by task id
754
- for (const [tid, key, value] of (0, io_js_1.mapCommand)(this.input, this.checkpointPendingWrites)) {
755
- writes[tid] ??= [];
756
- writes[tid].push([key, value]);
757
- }
758
- if (Object.keys(writes).length === 0) {
759
- throw new errors_js_1.EmptyInputError("Received empty Command input");
760
- }
761
- // save writes
762
- for (const [tid, ws] of Object.entries(writes)) {
763
- this.putWrites(tid, ws);
764
- }
765
- }
766
- // apply null writes
767
- const nullWrites = (this.checkpointPendingWrites ?? [])
768
- .filter((w) => w[0] === constants_js_1.NULL_TASK_ID)
769
- .map((w) => w.slice(1));
770
- if (nullWrites.length > 0) {
771
- (0, algo_js_1._applyWrites)(this.checkpoint, this.channels, [
772
- {
773
- name: constants_js_1.INPUT,
774
- writes: nullWrites,
775
- triggers: [],
776
- },
777
- ], this.checkpointerGetNextVersion, this.triggerToNodes);
778
- }
779
- const isCommandUpdateOrGoto = (0, constants_js_1.isCommand)(this.input) && nullWrites.length > 0;
780
- if (this.isResuming || isCommandUpdateOrGoto) {
781
- for (const channelName in this.channels) {
782
- if (!Object.prototype.hasOwnProperty.call(this.channels, channelName))
783
- continue;
784
- if (this.checkpoint.channel_versions[channelName] !== undefined) {
785
- const version = this.checkpoint.channel_versions[channelName];
786
- this.checkpoint.versions_seen[constants_js_1.INTERRUPT] = {
787
- ...this.checkpoint.versions_seen[constants_js_1.INTERRUPT],
788
- [channelName]: version,
789
- };
790
- }
791
- }
792
- // produce values output
793
- const valuesOutput = await (0, utils_js_1.gatherIterator)((0, utils_js_1.prefixGenerator)((0, io_js_1.mapOutputValues)(this.outputKeys, true, this.channels), "values"));
794
- this._emit(valuesOutput);
795
- }
796
- if (this.isResuming) {
797
- this.input = INPUT_RESUMING;
798
- }
799
- else if (isCommandUpdateOrGoto) {
800
- // we need to create a new checkpoint for Command(update=...) or Command(goto=...)
801
- // in case the result of Command(goto=...) is an interrupt.
802
- // If not done, the checkpoint containing the interrupt will be lost.
803
- await this._putCheckpoint({ source: "input" });
804
- this.input = INPUT_DONE;
805
- }
806
- else {
807
- // map inputs to channel updates
808
- const inputWrites = await (0, utils_js_1.gatherIterator)((0, io_js_1.mapInput)(inputKeys, this.input));
809
- if (inputWrites.length > 0) {
810
- const discardTasks = (0, algo_js_1._prepareNextTasks)(this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, this.config, true, { step: this.step });
811
- (0, algo_js_1._applyWrites)(this.checkpoint, this.channels, Object.values(discardTasks).concat([
812
- {
813
- name: constants_js_1.INPUT,
814
- writes: inputWrites,
815
- triggers: [],
816
- },
817
- ]), this.checkpointerGetNextVersion, this.triggerToNodes);
818
- // save input checkpoint
819
- await this._putCheckpoint({ source: "input" });
820
- this.input = INPUT_DONE;
821
- }
822
- else if (!(constants_js_1.CONFIG_KEY_RESUMING in (this.config.configurable ?? {}))) {
823
- throw new errors_js_1.EmptyInputError(`Received no input writes for ${JSON.stringify(inputKeys, null, 2)}`);
824
- }
825
- else {
826
- // done with input
827
- this.input = INPUT_DONE;
828
- }
829
- }
830
- if (!this.isNested) {
831
- this.config = (0, index_js_1.patchConfigurable)(this.config, {
832
- [constants_js_1.CONFIG_KEY_RESUMING]: this.isResuming,
833
- });
834
- }
835
- }
836
- _emit(values) {
837
- for (const [mode, payload] of values) {
838
- if (this.stream.modes.has(mode)) {
839
- this.stream.push([this.checkpointNamespace, mode, payload]);
840
- }
841
- // debug mode is a "checkpoints" or "tasks" wrapped in an object
842
- // TODO: consider deprecating this in 1.x
843
- if ((mode === "checkpoints" || mode === "tasks") &&
844
- this.stream.modes.has("debug")) {
845
- const step = mode === "checkpoints" ? this.step - 1 : this.step;
846
- const timestamp = new Date().toISOString();
847
- const type = (() => {
848
- if (mode === "checkpoints") {
849
- return "checkpoint";
850
- }
851
- else if (typeof payload === "object" &&
852
- payload != null &&
853
- "result" in payload) {
854
- return "task_result";
855
- }
856
- else {
857
- return "task";
858
- }
859
- })();
860
- this.stream.push([
861
- this.checkpointNamespace,
862
- "debug",
863
- { step, type, timestamp, payload },
864
- ]);
865
- }
866
- }
867
- }
868
- _putCheckpoint(inputMetadata) {
869
- const exiting = this.checkpointMetadata === inputMetadata;
870
- const doCheckpoint = this.checkpointer != null && (this.durability !== "exit" || exiting);
871
- const storeCheckpoint = (checkpoint) => {
872
- // store the previous checkpoint config for debug events
873
- this.prevCheckpointConfig = this.checkpointConfig?.configurable
874
- ?.checkpoint_id
875
- ? this.checkpointConfig
876
- : undefined;
877
- // child graphs keep at most one checkpoint per parent checkpoint
878
- // this is achieved by writing child checkpoints as progress is made
879
- // (so that error recovery / resuming from interrupt don't lose work)
880
- // but doing so always with an id equal to that of the parent checkpoint
881
- this.checkpointConfig = (0, index_js_1.patchConfigurable)(this.checkpointConfig, {
882
- [constants_js_1.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
883
- });
884
- const channelVersions = { ...this.checkpoint.channel_versions };
885
- const newVersions = (0, index_js_1.getNewChannelVersions)(this.checkpointPreviousVersions, channelVersions);
886
- this.checkpointPreviousVersions = channelVersions;
887
- // save it, without blocking
888
- // if there's a previous checkpoint save in progress, wait for it
889
- // ensuring checkpointers receive checkpoints in order
890
- void this._checkpointerPutAfterPrevious({
891
- config: { ...this.checkpointConfig },
892
- checkpoint: (0, langgraph_checkpoint_1.copyCheckpoint)(checkpoint),
893
- metadata: { ...this.checkpointMetadata },
894
- newVersions,
895
- });
896
- this.checkpointConfig = {
897
- ...this.checkpointConfig,
898
- configurable: {
899
- ...this.checkpointConfig.configurable,
900
- checkpoint_id: this.checkpoint.id,
901
- },
902
- };
903
- };
904
- if (!exiting) {
905
- this.checkpointMetadata = {
906
- ...inputMetadata,
907
- step: this.step,
908
- parents: this.config.configurable?.[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP] ?? {},
909
- };
910
- }
911
- // create new checkpoint
912
- this.checkpoint = (0, base_js_1.createCheckpoint)(this.checkpoint, doCheckpoint ? this.channels : undefined, this.step, exiting ? { id: this.checkpoint.id } : undefined);
913
- // Bail if no checkpointer
914
- if (doCheckpoint)
915
- storeCheckpoint(this.checkpoint);
916
- if (!exiting) {
917
- // increment step
918
- this.step += 1;
919
- }
920
- }
921
- _flushPendingWrites() {
922
- if (this.checkpointer == null)
923
- return;
924
- if (this.checkpointPendingWrites.length === 0)
925
- return;
926
- // patch config
927
- const config = (0, index_js_1.patchConfigurable)(this.checkpointConfig, {
928
- [constants_js_1.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
929
- [constants_js_1.CONFIG_KEY_CHECKPOINT_ID]: this.checkpoint.id,
930
- });
931
- // group writes by task id
932
- const byTask = {};
933
- for (const [tid, key, value] of this.checkpointPendingWrites) {
934
- byTask[tid] ??= [];
935
- byTask[tid].push([key, value]);
936
- }
937
- // submit writes to checkpointer
938
- for (const [tid, ws] of Object.entries(byTask)) {
939
- this.checkpointerPromises.push(this.checkpointer.putWrites(config, ws, tid));
940
- }
941
- }
942
- _matchWrites(tasks) {
943
- for (const [tid, k, v] of this.checkpointPendingWrites) {
944
- if (k === constants_js_1.ERROR || k === constants_js_1.INTERRUPT || k === constants_js_1.RESUME) {
945
- continue;
946
- }
947
- const task = Object.values(tasks).find((t) => t.id === tid);
948
- if (task) {
949
- task.writes.push([k, v]);
950
- }
951
- }
952
- for (const task of Object.values(tasks)) {
953
- if (task.writes.length > 0) {
954
- this._outputWrites(task.id, task.writes, true);
955
- }
956
- }
957
- }
19
+ return new require_stream.IterableReadableWritableStream({
20
+ passthroughFn: (value) => {
21
+ for (const stream of streams) if (stream.modes.has(value[1])) stream.push(value);
22
+ },
23
+ modes: new Set(streams.flatMap((s) => Array.from(s.modes)))
24
+ });
958
25
  }
26
+ var AsyncBatchedCache = class extends __langchain_langgraph_checkpoint.BaseCache {
27
+ cache;
28
+ queue = Promise.resolve();
29
+ constructor(cache) {
30
+ super();
31
+ this.cache = cache;
32
+ }
33
+ async get(keys) {
34
+ return this.enqueueOperation("get", keys);
35
+ }
36
+ async set(pairs) {
37
+ return this.enqueueOperation("set", pairs);
38
+ }
39
+ async clear(namespaces) {
40
+ return this.enqueueOperation("clear", namespaces);
41
+ }
42
+ async stop() {
43
+ await this.queue;
44
+ }
45
+ enqueueOperation(type, ...args) {
46
+ const newPromise = this.queue.then(() => {
47
+ return this.cache[type](...args);
48
+ });
49
+ this.queue = newPromise.then(() => void 0, () => void 0);
50
+ return newPromise;
51
+ }
52
+ };
53
+ var PregelLoop = class PregelLoop {
54
+ input;
55
+ output;
56
+ config;
57
+ checkpointer;
58
+ checkpointerGetNextVersion;
59
+ channels;
60
+ checkpoint;
61
+ checkpointIdSaved;
62
+ checkpointConfig;
63
+ checkpointMetadata;
64
+ checkpointNamespace;
65
+ checkpointPendingWrites = [];
66
+ checkpointPreviousVersions;
67
+ step;
68
+ stop;
69
+ durability;
70
+ outputKeys;
71
+ streamKeys;
72
+ nodes;
73
+ skipDoneTasks;
74
+ prevCheckpointConfig;
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 configHasResumingFlag = this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING] !== void 0;
97
+ const configIsResuming = configHasResumingFlag && this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING];
98
+ const inputIsNullOrUndefined = this.input === null || this.input === void 0;
99
+ const inputIsCommandResuming = require_constants.isCommand(this.input) && this.input.resume != null;
100
+ const inputIsResuming = this.input === INPUT_RESUMING;
101
+ 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;
102
+ return hasChannelVersions && (configIsResuming || inputIsNullOrUndefined || inputIsCommandResuming || inputIsResuming || runIdMatchesPrevious);
103
+ }
104
+ constructor(params) {
105
+ this.input = params.input;
106
+ this.checkpointer = params.checkpointer;
107
+ if (this.checkpointer !== void 0) this.checkpointerGetNextVersion = this.checkpointer.getNextVersion.bind(this.checkpointer);
108
+ else this.checkpointerGetNextVersion = require_algo.increment;
109
+ this.checkpoint = params.checkpoint;
110
+ this.checkpointMetadata = params.checkpointMetadata;
111
+ this.checkpointPreviousVersions = params.checkpointPreviousVersions;
112
+ this.channels = params.channels;
113
+ this.checkpointPendingWrites = params.checkpointPendingWrites;
114
+ this.step = params.step;
115
+ this.stop = params.stop;
116
+ this.config = params.config;
117
+ this.checkpointConfig = params.checkpointConfig;
118
+ this.isNested = params.isNested;
119
+ this.manager = params.manager;
120
+ this.outputKeys = params.outputKeys;
121
+ this.streamKeys = params.streamKeys;
122
+ this.nodes = params.nodes;
123
+ this.skipDoneTasks = params.skipDoneTasks;
124
+ this.store = params.store;
125
+ this.cache = params.cache ? new AsyncBatchedCache(params.cache) : void 0;
126
+ this.stream = params.stream;
127
+ this.checkpointNamespace = params.checkpointNamespace;
128
+ this.prevCheckpointConfig = params.prevCheckpointConfig;
129
+ this.interruptAfter = params.interruptAfter;
130
+ this.interruptBefore = params.interruptBefore;
131
+ this.durability = params.durability;
132
+ this.debug = params.debug;
133
+ this.triggerToNodes = params.triggerToNodes;
134
+ }
135
+ static async initialize(params) {
136
+ let { config, stream } = params;
137
+ if (stream !== void 0 && config.configurable?.[require_constants.CONFIG_KEY_STREAM] !== void 0) stream = createDuplexStream(stream, config.configurable[require_constants.CONFIG_KEY_STREAM]);
138
+ const skipDoneTasks = config.configurable ? !("checkpoint_id" in config.configurable) : true;
139
+ const scratchpad = config.configurable?.[require_constants.CONFIG_KEY_SCRATCHPAD];
140
+ if (config.configurable && scratchpad) {
141
+ 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) });
142
+ scratchpad.subgraphCounter += 1;
143
+ }
144
+ const isNested = require_constants.CONFIG_KEY_READ in (config.configurable ?? {});
145
+ if (!isNested && config.configurable?.checkpoint_ns !== void 0 && config.configurable?.checkpoint_ns !== "") config = require_index.patchConfigurable(config, {
146
+ checkpoint_ns: "",
147
+ checkpoint_id: void 0
148
+ });
149
+ let checkpointConfig = config;
150
+ 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] });
151
+ const checkpointNamespace = config.configurable?.checkpoint_ns?.split(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR) ?? [];
152
+ const saved = await params.checkpointer?.getTuple(checkpointConfig) ?? {
153
+ config,
154
+ checkpoint: (0, __langchain_langgraph_checkpoint.emptyCheckpoint)(),
155
+ metadata: {
156
+ source: "input",
157
+ step: -2,
158
+ parents: {}
159
+ },
160
+ pendingWrites: []
161
+ };
162
+ checkpointConfig = {
163
+ ...config,
164
+ ...saved.config,
165
+ configurable: {
166
+ checkpoint_ns: "",
167
+ ...config.configurable,
168
+ ...saved.config.configurable
169
+ }
170
+ };
171
+ const prevCheckpointConfig = saved.parentConfig;
172
+ const checkpoint = (0, __langchain_langgraph_checkpoint.copyCheckpoint)(saved.checkpoint);
173
+ const checkpointMetadata = { ...saved.metadata };
174
+ const checkpointPendingWrites = saved.pendingWrites ?? [];
175
+ const channels = require_base.emptyChannels(params.channelSpecs, checkpoint);
176
+ const step = (checkpointMetadata.step ?? 0) + 1;
177
+ const stop = step + (config.recursionLimit ?? DEFAULT_LOOP_LIMIT) + 1;
178
+ const checkpointPreviousVersions = { ...checkpoint.channel_versions };
179
+ const store = params.store ? new __langchain_langgraph_checkpoint.AsyncBatchedStore(params.store) : void 0;
180
+ if (store) await store.start();
181
+ return new PregelLoop({
182
+ input: params.input,
183
+ config,
184
+ checkpointer: params.checkpointer,
185
+ checkpoint,
186
+ checkpointMetadata,
187
+ checkpointConfig,
188
+ prevCheckpointConfig,
189
+ checkpointNamespace,
190
+ channels,
191
+ isNested,
192
+ manager: params.manager,
193
+ skipDoneTasks,
194
+ step,
195
+ stop,
196
+ checkpointPreviousVersions,
197
+ checkpointPendingWrites,
198
+ outputKeys: params.outputKeys ?? [],
199
+ streamKeys: params.streamKeys ?? [],
200
+ nodes: params.nodes,
201
+ stream,
202
+ store,
203
+ cache: params.cache,
204
+ interruptAfter: params.interruptAfter,
205
+ interruptBefore: params.interruptBefore,
206
+ durability: params.durability,
207
+ debug: params.debug,
208
+ triggerToNodes: params.triggerToNodes
209
+ });
210
+ }
211
+ _checkpointerPutAfterPrevious(input) {
212
+ this._checkpointerChainedPromise = this._checkpointerChainedPromise.then(() => {
213
+ return this.checkpointer?.put(input.config, input.checkpoint, input.metadata, input.newVersions);
214
+ });
215
+ this.checkpointerPromises.push(this._checkpointerChainedPromise);
216
+ }
217
+ /**
218
+ * Put writes for a task, to be read by the next tick.
219
+ * @param taskId
220
+ * @param writes
221
+ */
222
+ putWrites(taskId, writes) {
223
+ let writesCopy = writes;
224
+ if (writesCopy.length === 0) return;
225
+ if (writesCopy.every(([key]) => key in __langchain_langgraph_checkpoint.WRITES_IDX_MAP)) writesCopy = Array.from(new Map(writesCopy.map((w) => [w[0], w])).values());
226
+ this.checkpointPendingWrites = this.checkpointPendingWrites.filter((w) => w[0] !== taskId);
227
+ for (const [c, v] of writesCopy) this.checkpointPendingWrites.push([
228
+ taskId,
229
+ c,
230
+ v
231
+ ]);
232
+ const config = require_index.patchConfigurable(this.checkpointConfig, {
233
+ [require_constants.CONFIG_KEY_CHECKPOINT_NS]: this.config.configurable?.checkpoint_ns ?? "",
234
+ [require_constants.CONFIG_KEY_CHECKPOINT_ID]: this.checkpoint.id
235
+ });
236
+ if (this.durability !== "exit" && this.checkpointer != null) this.checkpointerPromises.push(this.checkpointer.putWrites(config, writesCopy, taskId));
237
+ if (this.tasks) this._outputWrites(taskId, writesCopy);
238
+ if (!writes.length || !this.cache || !this.tasks) return;
239
+ const task = this.tasks[taskId];
240
+ if (task == null || task.cache_key == null) return;
241
+ if (writes[0][0] === require_constants.ERROR || writes[0][0] === require_constants.INTERRUPT) return;
242
+ this.cache.set([{
243
+ key: [task.cache_key.ns, task.cache_key.key],
244
+ value: task.writes,
245
+ ttl: task.cache_key.ttl
246
+ }]);
247
+ }
248
+ _outputWrites(taskId, writes, cached = false) {
249
+ const task = this.tasks[taskId];
250
+ if (task !== void 0) {
251
+ if (task.config !== void 0 && (task.config.tags ?? []).includes(require_constants.TAG_HIDDEN)) return;
252
+ if (writes.length > 0) {
253
+ if (writes[0][0] === require_constants.INTERRUPT) {
254
+ if (task.path?.[0] === require_constants.PUSH && task.path?.at(-1) === true) return;
255
+ const interruptWrites = writes.filter((w) => w[0] === require_constants.INTERRUPT).flatMap((w) => w[1]);
256
+ this._emit([["updates", { [require_constants.INTERRUPT]: interruptWrites }], ["values", { [require_constants.INTERRUPT]: interruptWrites }]]);
257
+ } 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")));
258
+ }
259
+ if (!cached) this._emit(require_utils.gatherIteratorSync(require_utils.prefixGenerator(require_debug.mapDebugTaskResults([[task, writes]], this.streamKeys), "tasks")));
260
+ }
261
+ }
262
+ async _matchCachedWrites() {
263
+ if (!this.cache) return [];
264
+ const matched = [];
265
+ const serializeKey = ([ns, key]) => {
266
+ return `ns:${ns.join(",")}|key:${key}`;
267
+ };
268
+ const keys = [];
269
+ const keyMap = {};
270
+ for (const task of Object.values(this.tasks)) if (task.cache_key != null && !task.writes.length) {
271
+ keys.push([task.cache_key.ns, task.cache_key.key]);
272
+ keyMap[serializeKey([task.cache_key.ns, task.cache_key.key])] = task;
273
+ }
274
+ if (keys.length === 0) return [];
275
+ const cache = await this.cache.get(keys);
276
+ for (const { key, value } of cache) {
277
+ const task = keyMap[serializeKey(key)];
278
+ if (task != null) {
279
+ task.writes.push(...value);
280
+ matched.push({
281
+ task,
282
+ result: value
283
+ });
284
+ }
285
+ }
286
+ return matched;
287
+ }
288
+ /**
289
+ * Execute a single iteration of the Pregel loop.
290
+ * Returns true if more iterations are needed.
291
+ * @param params
292
+ */
293
+ async tick(params) {
294
+ if (this.store && !this.store.isRunning) await this.store?.start();
295
+ const { inputKeys = [] } = params;
296
+ if (this.status !== "pending") throw new Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);
297
+ if (![INPUT_DONE, INPUT_RESUMING].includes(this.input)) await this._first(inputKeys);
298
+ else if (this.toInterrupt.length > 0) {
299
+ this.status = "interrupt_before";
300
+ throw new require_errors.GraphInterrupt();
301
+ } else if (Object.values(this.tasks).every((task) => task.writes.length > 0)) {
302
+ const writes = Object.values(this.tasks).flatMap((t) => t.writes);
303
+ require_algo._applyWrites(this.checkpoint, this.channels, Object.values(this.tasks), this.checkpointerGetNextVersion, this.triggerToNodes);
304
+ const valuesOutput = await require_utils.gatherIterator(require_utils.prefixGenerator(require_io.mapOutputValues(this.outputKeys, writes, this.channels), "values"));
305
+ this._emit(valuesOutput);
306
+ this.checkpointPendingWrites = [];
307
+ await this._putCheckpoint({ source: "loop" });
308
+ if (require_algo.shouldInterrupt(this.checkpoint, this.interruptAfter, Object.values(this.tasks))) {
309
+ this.status = "interrupt_after";
310
+ throw new require_errors.GraphInterrupt();
311
+ }
312
+ if (this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING] !== void 0) delete this.config.configurable?.[require_constants.CONFIG_KEY_RESUMING];
313
+ } else return false;
314
+ if (this.step > this.stop) {
315
+ this.status = "out_of_steps";
316
+ return false;
317
+ }
318
+ const nextTasks = require_algo._prepareNextTasks(this.checkpoint, this.checkpointPendingWrites, this.nodes, this.channels, this.config, true, {
319
+ step: this.step,
320
+ checkpointer: this.checkpointer,
321
+ isResuming: this.isResuming,
322
+ manager: this.manager,
323
+ store: this.store,
324
+ stream: this.stream
325
+ });
326
+ this.tasks = nextTasks;
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
+ 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
+ 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
959
544
  exports.PregelLoop = PregelLoop;
960
- //# sourceMappingURL=loop.js.map
545
+ //# sourceMappingURL=loop.cjs.map