@langchain/langgraph 0.4.7 → 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 +11 -0
  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 +77 -80
  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,704 +1,537 @@
1
- /* eslint-disable no-param-reassign */
2
- import { mergeConfigs, patchConfig, } from "@langchain/core/runnables";
3
- import { copyCheckpoint, uuid5, maxChannelVersion, } from "@langchain/langgraph-checkpoint";
4
- import { createCheckpoint, emptyChannels, getOnlyChannels, } from "../channels/base.js";
5
- import { readChannel, readChannels } from "./io.js";
6
- import { _isSend, _isSendInterface, CONFIG_KEY_CHECKPOINT_MAP, CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ, CONFIG_KEY_TASK_ID, CONFIG_KEY_SEND, INTERRUPT, RESERVED, Send, TAG_HIDDEN, TASKS, CHECKPOINT_NAMESPACE_END, PUSH, PULL, RESUME, NULL_TASK_ID, CONFIG_KEY_SCRATCHPAD, RETURN, ERROR, NO_WRITES, CONFIG_KEY_PREVIOUS_STATE, PREVIOUS, CACHE_NS_WRITES, CONFIG_KEY_RESUME_MAP, } from "../constants.js";
7
- import { isCall, } from "./types.js";
8
1
  import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
2
+ import { createCheckpoint, emptyChannels, getOnlyChannels } from "../channels/base.js";
3
+ import { CACHE_NS_WRITES, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_CHECKPOINT_MAP, CONFIG_KEY_PREVIOUS_STATE, CONFIG_KEY_READ, CONFIG_KEY_RESUME_MAP, CONFIG_KEY_SCRATCHPAD, CONFIG_KEY_SEND, CONFIG_KEY_TASK_ID, ERROR, INTERRUPT, NO_WRITES, NULL_TASK_ID, PREVIOUS, PULL, PUSH, RESERVED, RESUME, RETURN, Send, TAG_HIDDEN, TASKS, _isSend, _isSendInterface } from "../constants.js";
4
+ import { XXH3 } from "../hash.js";
5
+ import { readChannel, readChannels } from "./io.js";
6
+ import { isCall } from "./types.js";
9
7
  import { getNullChannelVersion } from "./utils/index.js";
10
8
  import { getRunnableForFunc } from "./call.js";
11
- import { XXH3 } from "../hash.js";
12
- export const increment = (current) => {
13
- return current !== undefined ? current + 1 : 1;
9
+ import { copyCheckpoint, maxChannelVersion, uuid5 } from "@langchain/langgraph-checkpoint";
10
+ import { mergeConfigs, patchConfig } from "@langchain/core/runnables";
11
+
12
+ //#region src/pregel/algo.ts
13
+ const increment = (current) => {
14
+ return current !== void 0 ? current + 1 : 1;
14
15
  };
15
- // Avoids unnecessary double iteration
16
16
  function maxChannelMapVersion(channelVersions) {
17
- let maxVersion;
18
- for (const chan in channelVersions) {
19
- if (!Object.prototype.hasOwnProperty.call(channelVersions, chan))
20
- continue;
21
- if (maxVersion == null) {
22
- maxVersion = channelVersions[chan];
23
- }
24
- else {
25
- maxVersion = maxChannelVersion(maxVersion, channelVersions[chan]);
26
- }
27
- }
28
- return maxVersion;
17
+ let maxVersion;
18
+ for (const chan in channelVersions) {
19
+ if (!Object.prototype.hasOwnProperty.call(channelVersions, chan)) continue;
20
+ if (maxVersion == null) maxVersion = channelVersions[chan];
21
+ else maxVersion = maxChannelVersion(maxVersion, channelVersions[chan]);
22
+ }
23
+ return maxVersion;
29
24
  }
30
- export function shouldInterrupt(checkpoint, interruptNodes, tasks) {
31
- const nullVersion = getNullChannelVersion(checkpoint.channel_versions);
32
- const seen = checkpoint.versions_seen[INTERRUPT] ?? {};
33
- let anyChannelUpdated = false;
34
- for (const chan in checkpoint.channel_versions) {
35
- if (!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan))
36
- continue;
37
- if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
38
- anyChannelUpdated = true;
39
- break;
40
- }
41
- }
42
- const anyTriggeredNodeInInterruptNodes = tasks.some((task) => interruptNodes === "*"
43
- ? !task.config?.tags?.includes(TAG_HIDDEN)
44
- : interruptNodes.includes(task.name));
45
- return anyChannelUpdated && anyTriggeredNodeInInterruptNodes;
25
+ function shouldInterrupt(checkpoint, interruptNodes, tasks) {
26
+ const nullVersion = getNullChannelVersion(checkpoint.channel_versions);
27
+ const seen = checkpoint.versions_seen[INTERRUPT] ?? {};
28
+ let anyChannelUpdated = false;
29
+ for (const chan in checkpoint.channel_versions) {
30
+ if (!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan)) continue;
31
+ if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
32
+ anyChannelUpdated = true;
33
+ break;
34
+ }
35
+ }
36
+ const anyTriggeredNodeInInterruptNodes = tasks.some((task) => interruptNodes === "*" ? !task.config?.tags?.includes(TAG_HIDDEN) : interruptNodes.includes(task.name));
37
+ return anyChannelUpdated && anyTriggeredNodeInInterruptNodes;
46
38
  }
47
- export function _localRead(checkpoint, channels, task, select, fresh = false) {
48
- let updated = new Set();
49
- if (!Array.isArray(select)) {
50
- for (const [c] of task.writes) {
51
- if (c === select) {
52
- updated = new Set([c]);
53
- break;
54
- }
55
- }
56
- updated = updated || new Set();
57
- }
58
- else {
59
- updated = new Set(select.filter((c) => task.writes.some(([key, _]) => key === c)));
60
- }
61
- let values;
62
- if (fresh && updated.size > 0) {
63
- const localChannels = Object.fromEntries(Object.entries(channels).filter(([k, _]) => updated.has(k)));
64
- const newCheckpoint = createCheckpoint(checkpoint, localChannels, -1);
65
- const newChannels = emptyChannels(localChannels, newCheckpoint);
66
- _applyWrites(copyCheckpoint(newCheckpoint), newChannels, [task], undefined, undefined);
67
- values = readChannels({ ...channels, ...newChannels }, select);
68
- }
69
- else {
70
- values = readChannels(channels, select);
71
- }
72
- return values;
39
+ function _localRead(checkpoint, channels, task, select, fresh = false) {
40
+ let updated = /* @__PURE__ */ new Set();
41
+ if (!Array.isArray(select)) {
42
+ for (const [c] of task.writes) if (c === select) {
43
+ updated = new Set([c]);
44
+ break;
45
+ }
46
+ updated = updated || /* @__PURE__ */ new Set();
47
+ } else updated = new Set(select.filter((c) => task.writes.some(([key, _]) => key === c)));
48
+ let values;
49
+ if (fresh && updated.size > 0) {
50
+ const localChannels = Object.fromEntries(Object.entries(channels).filter(([k, _]) => updated.has(k)));
51
+ const newCheckpoint = createCheckpoint(checkpoint, localChannels, -1);
52
+ const newChannels = emptyChannels(localChannels, newCheckpoint);
53
+ _applyWrites(copyCheckpoint(newCheckpoint), newChannels, [task], void 0, void 0);
54
+ values = readChannels({
55
+ ...channels,
56
+ ...newChannels
57
+ }, select);
58
+ } else values = readChannels(channels, select);
59
+ return values;
73
60
  }
74
- export function _localWrite(
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- commit, processes,
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- writes) {
79
- for (const [chan, value] of writes) {
80
- if ([PUSH, TASKS].includes(chan) && value != null) {
81
- if (!_isSend(value)) {
82
- throw new InvalidUpdateError(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(value)}`);
83
- }
84
- if (!(value.node in processes)) {
85
- throw new InvalidUpdateError(`Invalid node name "${value.node}" in Send packet`);
86
- }
87
- }
88
- }
89
- commit(writes);
61
+ function _localWrite(commit, processes, writes) {
62
+ for (const [chan, value] of writes) if ([PUSH, TASKS].includes(chan) && value != null) {
63
+ if (!_isSend(value)) throw new InvalidUpdateError(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(value)}`);
64
+ if (!(value.node in processes)) throw new InvalidUpdateError(`Invalid node name "${value.node}" in Send packet`);
65
+ }
66
+ commit(writes);
90
67
  }
91
68
  const IGNORE = new Set([
92
- NO_WRITES,
93
- PUSH,
94
- RESUME,
95
- INTERRUPT,
96
- RETURN,
97
- ERROR,
69
+ NO_WRITES,
70
+ PUSH,
71
+ RESUME,
72
+ INTERRUPT,
73
+ RETURN,
74
+ ERROR
98
75
  ]);
99
- export function _applyWrites(checkpoint, channels, tasks,
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- getNextVersion, triggerToNodes) {
102
- // Sort tasks by first 3 path elements for deterministic order
103
- // Later path parts (like task IDs) are ignored for sorting
104
- tasks.sort((a, b) => {
105
- const aPath = a.path?.slice(0, 3) || [];
106
- const bPath = b.path?.slice(0, 3) || [];
107
- // Compare each path element
108
- for (let i = 0; i < Math.min(aPath.length, bPath.length); i += 1) {
109
- if (aPath[i] < bPath[i])
110
- return -1;
111
- if (aPath[i] > bPath[i])
112
- return 1;
113
- }
114
- // If one path is shorter, it comes first
115
- return aPath.length - bPath.length;
116
- });
117
- // if no task has triggers this is applying writes from the null task only
118
- // so we don't do anything other than update the channels written to
119
- const bumpStep = tasks.some((task) => task.triggers.length > 0);
120
- // Filter out non instances of BaseChannel
121
- const onlyChannels = getOnlyChannels(channels);
122
- // Update seen versions
123
- for (const task of tasks) {
124
- checkpoint.versions_seen[task.name] ??= {};
125
- for (const chan of task.triggers) {
126
- if (chan in checkpoint.channel_versions) {
127
- checkpoint.versions_seen[task.name][chan] =
128
- checkpoint.channel_versions[chan];
129
- }
130
- }
131
- }
132
- // Find the highest version of all channels
133
- let maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
134
- // Consume all channels that were read
135
- const channelsToConsume = new Set(tasks
136
- .flatMap((task) => task.triggers)
137
- .filter((chan) => !RESERVED.includes(chan)));
138
- for (const chan of channelsToConsume) {
139
- if (chan in onlyChannels && onlyChannels[chan].consume()) {
140
- if (getNextVersion !== undefined) {
141
- checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
142
- }
143
- }
144
- }
145
- // Group writes by channel
146
- const pendingWritesByChannel = {};
147
- for (const task of tasks) {
148
- for (const [chan, val] of task.writes) {
149
- if (IGNORE.has(chan)) {
150
- // do nothing
151
- }
152
- else if (chan in onlyChannels) {
153
- pendingWritesByChannel[chan] ??= [];
154
- pendingWritesByChannel[chan].push(val);
155
- }
156
- }
157
- }
158
- // Find the highest version of all channels
159
- maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
160
- const updatedChannels = new Set();
161
- // Apply writes to channels
162
- for (const [chan, vals] of Object.entries(pendingWritesByChannel)) {
163
- if (chan in onlyChannels) {
164
- const channel = onlyChannels[chan];
165
- let updated;
166
- try {
167
- updated = channel.update(vals);
168
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
- }
170
- catch (e) {
171
- if (e.name === InvalidUpdateError.unminifiable_name) {
172
- const wrappedError = new InvalidUpdateError(`Invalid update for channel "${chan}" with values ${JSON.stringify(vals)}: ${e.message}`);
173
- wrappedError.lc_error_code = e.lc_error_code;
174
- throw wrappedError;
175
- }
176
- else {
177
- throw e;
178
- }
179
- }
180
- if (updated && getNextVersion !== undefined) {
181
- checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
182
- // unavailable channels can't trigger tasks, so don't add them
183
- if (channel.isAvailable())
184
- updatedChannels.add(chan);
185
- }
186
- }
187
- }
188
- // Channels that weren't updated in this step are notified of a new step
189
- if (bumpStep) {
190
- for (const chan in onlyChannels) {
191
- if (!Object.prototype.hasOwnProperty.call(onlyChannels, chan))
192
- continue;
193
- const channel = onlyChannels[chan];
194
- if (channel.isAvailable() && !updatedChannels.has(chan)) {
195
- const updated = channel.update([]);
196
- if (updated && getNextVersion !== undefined) {
197
- checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
198
- // unavailable channels can't trigger tasks, so don't add them
199
- if (channel.isAvailable())
200
- updatedChannels.add(chan);
201
- }
202
- }
203
- }
204
- }
205
- // If this is (tentatively) the last superstep, notify all channels of finish
206
- if (bumpStep &&
207
- !Object.keys(triggerToNodes ?? {}).some((channel) => updatedChannels.has(channel))) {
208
- for (const chan in onlyChannels) {
209
- if (!Object.prototype.hasOwnProperty.call(onlyChannels, chan))
210
- continue;
211
- const channel = onlyChannels[chan];
212
- if (channel.finish() && getNextVersion !== undefined) {
213
- checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
214
- // unavailable channels can't trigger tasks, so don't add them
215
- if (channel.isAvailable())
216
- updatedChannels.add(chan);
217
- }
218
- }
219
- }
76
+ function _applyWrites(checkpoint, channels, tasks, getNextVersion, triggerToNodes) {
77
+ tasks.sort((a, b) => {
78
+ const aPath = a.path?.slice(0, 3) || [];
79
+ const bPath = b.path?.slice(0, 3) || [];
80
+ for (let i = 0; i < Math.min(aPath.length, bPath.length); i += 1) {
81
+ if (aPath[i] < bPath[i]) return -1;
82
+ if (aPath[i] > bPath[i]) return 1;
83
+ }
84
+ return aPath.length - bPath.length;
85
+ });
86
+ const bumpStep = tasks.some((task) => task.triggers.length > 0);
87
+ const onlyChannels = getOnlyChannels(channels);
88
+ for (const task of tasks) {
89
+ checkpoint.versions_seen[task.name] ??= {};
90
+ for (const chan of task.triggers) if (chan in checkpoint.channel_versions) checkpoint.versions_seen[task.name][chan] = checkpoint.channel_versions[chan];
91
+ }
92
+ let maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
93
+ const channelsToConsume = new Set(tasks.flatMap((task) => task.triggers).filter((chan) => !RESERVED.includes(chan)));
94
+ for (const chan of channelsToConsume) if (chan in onlyChannels && onlyChannels[chan].consume()) {
95
+ if (getNextVersion !== void 0) checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
96
+ }
97
+ const pendingWritesByChannel = {};
98
+ for (const task of tasks) for (const [chan, val] of task.writes) if (IGNORE.has(chan)) {} else if (chan in onlyChannels) {
99
+ pendingWritesByChannel[chan] ??= [];
100
+ pendingWritesByChannel[chan].push(val);
101
+ }
102
+ maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
103
+ const updatedChannels = /* @__PURE__ */ new Set();
104
+ for (const [chan, vals] of Object.entries(pendingWritesByChannel)) if (chan in onlyChannels) {
105
+ const channel = onlyChannels[chan];
106
+ let updated;
107
+ try {
108
+ updated = channel.update(vals);
109
+ } catch (e) {
110
+ if (e.name === InvalidUpdateError.unminifiable_name) {
111
+ const wrappedError = new InvalidUpdateError(`Invalid update for channel "${chan}" with values ${JSON.stringify(vals)}: ${e.message}`);
112
+ wrappedError.lc_error_code = e.lc_error_code;
113
+ throw wrappedError;
114
+ } else throw e;
115
+ }
116
+ if (updated && getNextVersion !== void 0) {
117
+ checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
118
+ if (channel.isAvailable()) updatedChannels.add(chan);
119
+ }
120
+ }
121
+ if (bumpStep) for (const chan in onlyChannels) {
122
+ if (!Object.prototype.hasOwnProperty.call(onlyChannels, chan)) continue;
123
+ const channel = onlyChannels[chan];
124
+ if (channel.isAvailable() && !updatedChannels.has(chan)) {
125
+ const updated = channel.update([]);
126
+ if (updated && getNextVersion !== void 0) {
127
+ checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
128
+ if (channel.isAvailable()) updatedChannels.add(chan);
129
+ }
130
+ }
131
+ }
132
+ if (bumpStep && !Object.keys(triggerToNodes ?? {}).some((channel) => updatedChannels.has(channel))) for (const chan in onlyChannels) {
133
+ if (!Object.prototype.hasOwnProperty.call(onlyChannels, chan)) continue;
134
+ const channel = onlyChannels[chan];
135
+ if (channel.finish() && getNextVersion !== void 0) {
136
+ checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
137
+ if (channel.isAvailable()) updatedChannels.add(chan);
138
+ }
139
+ }
220
140
  }
221
141
  /**
222
- * Prepare the set of tasks that will make up the next Pregel step.
223
- * This is the union of all PUSH tasks (Sends) and PULL tasks (nodes triggered
224
- * by edges).
225
- */
226
- export function _prepareNextTasks(checkpoint, pendingWrites, processes, channels, config, forExecution, extra) {
227
- const tasks = {};
228
- // Consume pending tasks
229
- const tasksChannel = channels[TASKS];
230
- if (tasksChannel?.isAvailable()) {
231
- const len = tasksChannel.get().length;
232
- for (let i = 0; i < len; i += 1) {
233
- const task = _prepareSingleTask([PUSH, i], checkpoint, pendingWrites, processes, channels, config, forExecution, extra);
234
- if (task !== undefined) {
235
- tasks[task.id] = task;
236
- }
237
- }
238
- }
239
- // Check if any processes should be run in next step
240
- // If so, prepare the values to be passed to them
241
- for (const name in processes) {
242
- if (!Object.prototype.hasOwnProperty.call(processes, name))
243
- continue;
244
- const task = _prepareSingleTask([PULL, name], checkpoint, pendingWrites, processes, channels, config, forExecution, extra);
245
- if (task !== undefined) {
246
- tasks[task.id] = task;
247
- }
248
- }
249
- return tasks;
142
+ * Prepare the set of tasks that will make up the next Pregel step.
143
+ * This is the union of all PUSH tasks (Sends) and PULL tasks (nodes triggered
144
+ * by edges).
145
+ */
146
+ function _prepareNextTasks(checkpoint, pendingWrites, processes, channels, config, forExecution, extra) {
147
+ const tasks = {};
148
+ const tasksChannel = channels[TASKS];
149
+ if (tasksChannel?.isAvailable()) {
150
+ const len = tasksChannel.get().length;
151
+ for (let i = 0; i < len; i += 1) {
152
+ const task = _prepareSingleTask([PUSH, i], checkpoint, pendingWrites, processes, channels, config, forExecution, extra);
153
+ if (task !== void 0) tasks[task.id] = task;
154
+ }
155
+ }
156
+ for (const name in processes) {
157
+ if (!Object.prototype.hasOwnProperty.call(processes, name)) continue;
158
+ const task = _prepareSingleTask([PULL, name], checkpoint, pendingWrites, processes, channels, config, forExecution, extra);
159
+ if (task !== void 0) tasks[task.id] = task;
160
+ }
161
+ return tasks;
250
162
  }
251
163
  /**
252
- * Prepares a single task for the next Pregel step, given a task path, which
253
- * uniquely identifies a PUSH or PULL task within the graph.
254
- */
255
- export function _prepareSingleTask(taskPath, checkpoint, pendingWrites, processes, channels, config, forExecution, extra) {
256
- const { step, checkpointer, manager } = extra;
257
- const configurable = config.configurable ?? {};
258
- const parentNamespace = configurable.checkpoint_ns ?? "";
259
- if (taskPath[0] === PUSH && isCall(taskPath[taskPath.length - 1])) {
260
- const call = taskPath[taskPath.length - 1];
261
- const proc = getRunnableForFunc(call.name, call.func);
262
- const triggers = [PUSH];
263
- const checkpointNamespace = parentNamespace === ""
264
- ? call.name
265
- : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${call.name}`;
266
- const id = uuid5(JSON.stringify([
267
- checkpointNamespace,
268
- step.toString(),
269
- call.name,
270
- PUSH,
271
- taskPath[1],
272
- taskPath[2],
273
- ]), checkpoint.id);
274
- const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${id}`;
275
- // we append `true` to the task path to indicate that a call is being made
276
- // so we should not return interrupts from this task (responsibility lies with the parent)
277
- const outputTaskPath = [...taskPath.slice(0, 3), true];
278
- const metadata = {
279
- langgraph_step: step,
280
- langgraph_node: call.name,
281
- langgraph_triggers: triggers,
282
- langgraph_path: outputTaskPath,
283
- langgraph_checkpoint_ns: taskCheckpointNamespace,
284
- };
285
- if (forExecution) {
286
- const writes = [];
287
- const task = {
288
- name: call.name,
289
- input: call.input,
290
- proc,
291
- writes,
292
- config: patchConfig(mergeConfigs(config, {
293
- metadata,
294
- store: extra.store ?? config.store,
295
- }), {
296
- runName: call.name,
297
- callbacks: manager?.getChild(`graph:step:${step}`),
298
- configurable: {
299
- [CONFIG_KEY_TASK_ID]: id,
300
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
301
- [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => writes.push(...items), processes, writes_),
302
- [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
303
- name: call.name,
304
- writes: writes,
305
- triggers,
306
- path: outputTaskPath,
307
- }, select_, fresh_),
308
- [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
309
- [CONFIG_KEY_CHECKPOINT_MAP]: {
310
- ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
311
- [parentNamespace]: checkpoint.id,
312
- },
313
- [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
314
- pendingWrites: pendingWrites ?? [],
315
- taskId: id,
316
- currentTaskInput: call.input,
317
- resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
318
- namespaceHash: XXH3(taskCheckpointNamespace),
319
- }),
320
- [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
321
- checkpoint_id: undefined,
322
- checkpoint_ns: taskCheckpointNamespace,
323
- },
324
- }),
325
- triggers,
326
- retry_policy: call.retry,
327
- cache_key: call.cache
328
- ? {
329
- key: XXH3((call.cache.keyFunc ?? JSON.stringify)([call.input])),
330
- ns: [CACHE_NS_WRITES, call.name ?? "__dynamic__"],
331
- ttl: call.cache.ttl,
332
- }
333
- : undefined,
334
- id,
335
- path: outputTaskPath,
336
- writers: [],
337
- };
338
- return task;
339
- }
340
- else {
341
- return {
342
- id,
343
- name: call.name,
344
- interrupts: [],
345
- path: outputTaskPath,
346
- };
347
- }
348
- }
349
- else if (taskPath[0] === PUSH) {
350
- const index = typeof taskPath[1] === "number"
351
- ? taskPath[1]
352
- : parseInt(taskPath[1], 10);
353
- if (!channels[TASKS]?.isAvailable()) {
354
- return undefined;
355
- }
356
- const sends = channels[TASKS].get();
357
- if (index < 0 || index >= sends.length) {
358
- return undefined;
359
- }
360
- const packet = _isSendInterface(sends[index]) && !_isSend(sends[index])
361
- ? new Send(sends[index].node, sends[index].args)
362
- : sends[index];
363
- if (!_isSendInterface(packet)) {
364
- console.warn(`Ignoring invalid packet ${JSON.stringify(packet)} in pending sends.`);
365
- return undefined;
366
- }
367
- if (!(packet.node in processes)) {
368
- console.warn(`Ignoring unknown node name ${packet.node} in pending sends.`);
369
- return undefined;
370
- }
371
- const triggers = [PUSH];
372
- const checkpointNamespace = parentNamespace === ""
373
- ? packet.node
374
- : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${packet.node}`;
375
- const taskId = uuid5(JSON.stringify([
376
- checkpointNamespace,
377
- step.toString(),
378
- packet.node,
379
- PUSH,
380
- index.toString(),
381
- ]), checkpoint.id);
382
- const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
383
- let metadata = {
384
- langgraph_step: step,
385
- langgraph_node: packet.node,
386
- langgraph_triggers: triggers,
387
- langgraph_path: taskPath.slice(0, 3),
388
- langgraph_checkpoint_ns: taskCheckpointNamespace,
389
- };
390
- if (forExecution) {
391
- const proc = processes[packet.node];
392
- const node = proc.getNode();
393
- if (node !== undefined) {
394
- if (proc.metadata !== undefined) {
395
- metadata = { ...metadata, ...proc.metadata };
396
- }
397
- const writes = [];
398
- return {
399
- name: packet.node,
400
- input: packet.args,
401
- proc: node,
402
- subgraphs: proc.subgraphs,
403
- writes,
404
- config: patchConfig(mergeConfigs(config, {
405
- metadata,
406
- tags: proc.tags,
407
- store: extra.store ?? config.store,
408
- }), {
409
- runName: packet.node,
410
- callbacks: manager?.getChild(`graph:step:${step}`),
411
- configurable: {
412
- [CONFIG_KEY_TASK_ID]: taskId,
413
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
414
- [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => writes.push(...items), processes, writes_),
415
- [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
416
- name: packet.node,
417
- writes: writes,
418
- triggers,
419
- path: taskPath,
420
- }, select_, fresh_),
421
- [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
422
- [CONFIG_KEY_CHECKPOINT_MAP]: {
423
- ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
424
- [parentNamespace]: checkpoint.id,
425
- },
426
- [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
427
- pendingWrites: pendingWrites ?? [],
428
- taskId,
429
- currentTaskInput: packet.args,
430
- resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
431
- namespaceHash: XXH3(taskCheckpointNamespace),
432
- }),
433
- [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
434
- checkpoint_id: undefined,
435
- checkpoint_ns: taskCheckpointNamespace,
436
- },
437
- }),
438
- triggers,
439
- retry_policy: proc.retryPolicy,
440
- cache_key: proc.cachePolicy
441
- ? {
442
- key: XXH3((proc.cachePolicy.keyFunc ?? JSON.stringify)([packet.args])),
443
- ns: [CACHE_NS_WRITES, proc.name ?? "__dynamic__", packet.node],
444
- ttl: proc.cachePolicy.ttl,
445
- }
446
- : undefined,
447
- id: taskId,
448
- path: taskPath,
449
- writers: proc.getWriters(),
450
- };
451
- }
452
- }
453
- else {
454
- return {
455
- id: taskId,
456
- name: packet.node,
457
- interrupts: [],
458
- path: taskPath,
459
- };
460
- }
461
- }
462
- else if (taskPath[0] === PULL) {
463
- const name = taskPath[1].toString();
464
- const proc = processes[name];
465
- if (proc === undefined) {
466
- return undefined;
467
- }
468
- // Check if this task already has successful writes in the pending writes
469
- if (pendingWrites?.length) {
470
- // Find the task ID for this node/path
471
- const checkpointNamespace = parentNamespace === ""
472
- ? name
473
- : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
474
- const taskId = uuid5(JSON.stringify([
475
- checkpointNamespace,
476
- step.toString(),
477
- name,
478
- PULL,
479
- name,
480
- ]), checkpoint.id);
481
- // Check if there are successful writes (not ERROR) for this task ID
482
- const hasSuccessfulWrites = pendingWrites.some((w) => w[0] === taskId && w[1] !== ERROR);
483
- // If task completed successfully, don't include it in next tasks
484
- if (hasSuccessfulWrites) {
485
- return undefined;
486
- }
487
- }
488
- const nullVersion = getNullChannelVersion(checkpoint.channel_versions);
489
- if (nullVersion === undefined) {
490
- return undefined;
491
- }
492
- const seen = checkpoint.versions_seen[name] ?? {};
493
- // Find the first trigger that is available and has a new version
494
- const trigger = proc.triggers.find((chan) => {
495
- if (!channels[chan].isAvailable())
496
- return false;
497
- return ((checkpoint.channel_versions[chan] ?? nullVersion) >
498
- (seen[chan] ?? nullVersion));
499
- });
500
- // If any of the channels read by this process were updated
501
- if (trigger !== undefined) {
502
- const val = _procInput(proc, channels, forExecution);
503
- if (val === undefined) {
504
- return undefined;
505
- }
506
- const checkpointNamespace = parentNamespace === ""
507
- ? name
508
- : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
509
- const taskId = uuid5(JSON.stringify([
510
- checkpointNamespace,
511
- step.toString(),
512
- name,
513
- PULL,
514
- [trigger],
515
- ]), checkpoint.id);
516
- const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
517
- let metadata = {
518
- langgraph_step: step,
519
- langgraph_node: name,
520
- langgraph_triggers: [trigger],
521
- langgraph_path: taskPath,
522
- langgraph_checkpoint_ns: taskCheckpointNamespace,
523
- };
524
- if (forExecution) {
525
- const node = proc.getNode();
526
- if (node !== undefined) {
527
- if (proc.metadata !== undefined) {
528
- metadata = { ...metadata, ...proc.metadata };
529
- }
530
- const writes = [];
531
- return {
532
- name,
533
- input: val,
534
- proc: node,
535
- subgraphs: proc.subgraphs,
536
- writes,
537
- config: patchConfig(mergeConfigs(config, {
538
- metadata,
539
- tags: proc.tags,
540
- store: extra.store ?? config.store,
541
- }), {
542
- runName: name,
543
- callbacks: manager?.getChild(`graph:step:${step}`),
544
- configurable: {
545
- [CONFIG_KEY_TASK_ID]: taskId,
546
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
547
- [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => {
548
- writes.push(...items);
549
- }, processes, writes_),
550
- [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
551
- name,
552
- writes: writes,
553
- triggers: [trigger],
554
- path: taskPath,
555
- }, select_, fresh_),
556
- [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
557
- [CONFIG_KEY_CHECKPOINT_MAP]: {
558
- ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
559
- [parentNamespace]: checkpoint.id,
560
- },
561
- [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
562
- pendingWrites: pendingWrites ?? [],
563
- taskId,
564
- currentTaskInput: val,
565
- resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
566
- namespaceHash: XXH3(taskCheckpointNamespace),
567
- }),
568
- [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
569
- checkpoint_id: undefined,
570
- checkpoint_ns: taskCheckpointNamespace,
571
- },
572
- }),
573
- triggers: [trigger],
574
- retry_policy: proc.retryPolicy,
575
- cache_key: proc.cachePolicy
576
- ? {
577
- key: XXH3((proc.cachePolicy.keyFunc ?? JSON.stringify)([val])),
578
- ns: [CACHE_NS_WRITES, proc.name ?? "__dynamic__", name],
579
- ttl: proc.cachePolicy.ttl,
580
- }
581
- : undefined,
582
- id: taskId,
583
- path: taskPath,
584
- writers: proc.getWriters(),
585
- };
586
- }
587
- }
588
- else {
589
- return {
590
- id: taskId,
591
- name,
592
- interrupts: [],
593
- path: taskPath,
594
- };
595
- }
596
- }
597
- }
598
- return undefined;
164
+ * Prepares a single task for the next Pregel step, given a task path, which
165
+ * uniquely identifies a PUSH or PULL task within the graph.
166
+ */
167
+ function _prepareSingleTask(taskPath, checkpoint, pendingWrites, processes, channels, config, forExecution, extra) {
168
+ const { step, checkpointer, manager } = extra;
169
+ const configurable = config.configurable ?? {};
170
+ const parentNamespace = configurable.checkpoint_ns ?? "";
171
+ if (taskPath[0] === PUSH && isCall(taskPath[taskPath.length - 1])) {
172
+ const call = taskPath[taskPath.length - 1];
173
+ const proc = getRunnableForFunc(call.name, call.func);
174
+ const triggers = [PUSH];
175
+ const checkpointNamespace = parentNamespace === "" ? call.name : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${call.name}`;
176
+ const id = uuid5(JSON.stringify([
177
+ checkpointNamespace,
178
+ step.toString(),
179
+ call.name,
180
+ PUSH,
181
+ taskPath[1],
182
+ taskPath[2]
183
+ ]), checkpoint.id);
184
+ const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${id}`;
185
+ const outputTaskPath = [...taskPath.slice(0, 3), true];
186
+ const metadata = {
187
+ langgraph_step: step,
188
+ langgraph_node: call.name,
189
+ langgraph_triggers: triggers,
190
+ langgraph_path: outputTaskPath,
191
+ langgraph_checkpoint_ns: taskCheckpointNamespace
192
+ };
193
+ if (forExecution) {
194
+ const writes = [];
195
+ const task = {
196
+ name: call.name,
197
+ input: call.input,
198
+ proc,
199
+ writes,
200
+ config: patchConfig(mergeConfigs(config, {
201
+ metadata,
202
+ store: extra.store ?? config.store
203
+ }), {
204
+ runName: call.name,
205
+ callbacks: manager?.getChild(`graph:step:${step}`),
206
+ configurable: {
207
+ [CONFIG_KEY_TASK_ID]: id,
208
+ [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => writes.push(...items), processes, writes_),
209
+ [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
210
+ name: call.name,
211
+ writes,
212
+ triggers,
213
+ path: outputTaskPath
214
+ }, select_, fresh_),
215
+ [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
216
+ [CONFIG_KEY_CHECKPOINT_MAP]: {
217
+ ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
218
+ [parentNamespace]: checkpoint.id
219
+ },
220
+ [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
221
+ pendingWrites: pendingWrites ?? [],
222
+ taskId: id,
223
+ currentTaskInput: call.input,
224
+ resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
225
+ namespaceHash: XXH3(taskCheckpointNamespace)
226
+ }),
227
+ [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
228
+ checkpoint_id: void 0,
229
+ checkpoint_ns: taskCheckpointNamespace
230
+ }
231
+ }),
232
+ triggers,
233
+ retry_policy: call.retry,
234
+ cache_key: call.cache ? {
235
+ key: XXH3((call.cache.keyFunc ?? JSON.stringify)([call.input])),
236
+ ns: [CACHE_NS_WRITES, call.name ?? "__dynamic__"],
237
+ ttl: call.cache.ttl
238
+ } : void 0,
239
+ id,
240
+ path: outputTaskPath,
241
+ writers: []
242
+ };
243
+ return task;
244
+ } else return {
245
+ id,
246
+ name: call.name,
247
+ interrupts: [],
248
+ path: outputTaskPath
249
+ };
250
+ } else if (taskPath[0] === PUSH) {
251
+ const index = typeof taskPath[1] === "number" ? taskPath[1] : parseInt(taskPath[1], 10);
252
+ if (!channels[TASKS]?.isAvailable()) return void 0;
253
+ const sends = channels[TASKS].get();
254
+ if (index < 0 || index >= sends.length) return void 0;
255
+ const packet = _isSendInterface(sends[index]) && !_isSend(sends[index]) ? new Send(sends[index].node, sends[index].args) : sends[index];
256
+ if (!_isSendInterface(packet)) {
257
+ console.warn(`Ignoring invalid packet ${JSON.stringify(packet)} in pending sends.`);
258
+ return void 0;
259
+ }
260
+ if (!(packet.node in processes)) {
261
+ console.warn(`Ignoring unknown node name ${packet.node} in pending sends.`);
262
+ return void 0;
263
+ }
264
+ const triggers = [PUSH];
265
+ const checkpointNamespace = parentNamespace === "" ? packet.node : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${packet.node}`;
266
+ const taskId = uuid5(JSON.stringify([
267
+ checkpointNamespace,
268
+ step.toString(),
269
+ packet.node,
270
+ PUSH,
271
+ index.toString()
272
+ ]), checkpoint.id);
273
+ const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
274
+ let metadata = {
275
+ langgraph_step: step,
276
+ langgraph_node: packet.node,
277
+ langgraph_triggers: triggers,
278
+ langgraph_path: taskPath.slice(0, 3),
279
+ langgraph_checkpoint_ns: taskCheckpointNamespace
280
+ };
281
+ if (forExecution) {
282
+ const proc = processes[packet.node];
283
+ const node = proc.getNode();
284
+ if (node !== void 0) {
285
+ if (proc.metadata !== void 0) metadata = {
286
+ ...metadata,
287
+ ...proc.metadata
288
+ };
289
+ const writes = [];
290
+ return {
291
+ name: packet.node,
292
+ input: packet.args,
293
+ proc: node,
294
+ subgraphs: proc.subgraphs,
295
+ writes,
296
+ config: patchConfig(mergeConfigs(config, {
297
+ metadata,
298
+ tags: proc.tags,
299
+ store: extra.store ?? config.store
300
+ }), {
301
+ runName: packet.node,
302
+ callbacks: manager?.getChild(`graph:step:${step}`),
303
+ configurable: {
304
+ [CONFIG_KEY_TASK_ID]: taskId,
305
+ [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => writes.push(...items), processes, writes_),
306
+ [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
307
+ name: packet.node,
308
+ writes,
309
+ triggers,
310
+ path: taskPath
311
+ }, select_, fresh_),
312
+ [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
313
+ [CONFIG_KEY_CHECKPOINT_MAP]: {
314
+ ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
315
+ [parentNamespace]: checkpoint.id
316
+ },
317
+ [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
318
+ pendingWrites: pendingWrites ?? [],
319
+ taskId,
320
+ currentTaskInput: packet.args,
321
+ resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
322
+ namespaceHash: XXH3(taskCheckpointNamespace)
323
+ }),
324
+ [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
325
+ checkpoint_id: void 0,
326
+ checkpoint_ns: taskCheckpointNamespace
327
+ }
328
+ }),
329
+ triggers,
330
+ retry_policy: proc.retryPolicy,
331
+ cache_key: proc.cachePolicy ? {
332
+ key: XXH3((proc.cachePolicy.keyFunc ?? JSON.stringify)([packet.args])),
333
+ ns: [
334
+ CACHE_NS_WRITES,
335
+ proc.name ?? "__dynamic__",
336
+ packet.node
337
+ ],
338
+ ttl: proc.cachePolicy.ttl
339
+ } : void 0,
340
+ id: taskId,
341
+ path: taskPath,
342
+ writers: proc.getWriters()
343
+ };
344
+ }
345
+ } else return {
346
+ id: taskId,
347
+ name: packet.node,
348
+ interrupts: [],
349
+ path: taskPath
350
+ };
351
+ } else if (taskPath[0] === PULL) {
352
+ const name = taskPath[1].toString();
353
+ const proc = processes[name];
354
+ if (proc === void 0) return void 0;
355
+ if (pendingWrites?.length) {
356
+ const checkpointNamespace = parentNamespace === "" ? name : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
357
+ const taskId = uuid5(JSON.stringify([
358
+ checkpointNamespace,
359
+ step.toString(),
360
+ name,
361
+ PULL,
362
+ name
363
+ ]), checkpoint.id);
364
+ const hasSuccessfulWrites = pendingWrites.some((w) => w[0] === taskId && w[1] !== ERROR);
365
+ if (hasSuccessfulWrites) return void 0;
366
+ }
367
+ const nullVersion = getNullChannelVersion(checkpoint.channel_versions);
368
+ if (nullVersion === void 0) return void 0;
369
+ const seen = checkpoint.versions_seen[name] ?? {};
370
+ const trigger = proc.triggers.find((chan) => {
371
+ if (!channels[chan].isAvailable()) return false;
372
+ return (checkpoint.channel_versions[chan] ?? nullVersion) > (seen[chan] ?? nullVersion);
373
+ });
374
+ if (trigger !== void 0) {
375
+ const val = _procInput(proc, channels, forExecution);
376
+ if (val === void 0) return void 0;
377
+ const checkpointNamespace = parentNamespace === "" ? name : `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
378
+ const taskId = uuid5(JSON.stringify([
379
+ checkpointNamespace,
380
+ step.toString(),
381
+ name,
382
+ PULL,
383
+ [trigger]
384
+ ]), checkpoint.id);
385
+ const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
386
+ let metadata = {
387
+ langgraph_step: step,
388
+ langgraph_node: name,
389
+ langgraph_triggers: [trigger],
390
+ langgraph_path: taskPath,
391
+ langgraph_checkpoint_ns: taskCheckpointNamespace
392
+ };
393
+ if (forExecution) {
394
+ const node = proc.getNode();
395
+ if (node !== void 0) {
396
+ if (proc.metadata !== void 0) metadata = {
397
+ ...metadata,
398
+ ...proc.metadata
399
+ };
400
+ const writes = [];
401
+ return {
402
+ name,
403
+ input: val,
404
+ proc: node,
405
+ subgraphs: proc.subgraphs,
406
+ writes,
407
+ config: patchConfig(mergeConfigs(config, {
408
+ metadata,
409
+ tags: proc.tags,
410
+ store: extra.store ?? config.store
411
+ }), {
412
+ runName: name,
413
+ callbacks: manager?.getChild(`graph:step:${step}`),
414
+ configurable: {
415
+ [CONFIG_KEY_TASK_ID]: taskId,
416
+ [CONFIG_KEY_SEND]: (writes_) => _localWrite((items) => {
417
+ writes.push(...items);
418
+ }, processes, writes_),
419
+ [CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(checkpoint, channels, {
420
+ name,
421
+ writes,
422
+ triggers: [trigger],
423
+ path: taskPath
424
+ }, select_, fresh_),
425
+ [CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
426
+ [CONFIG_KEY_CHECKPOINT_MAP]: {
427
+ ...configurable[CONFIG_KEY_CHECKPOINT_MAP],
428
+ [parentNamespace]: checkpoint.id
429
+ },
430
+ [CONFIG_KEY_SCRATCHPAD]: _scratchpad({
431
+ pendingWrites: pendingWrites ?? [],
432
+ taskId,
433
+ currentTaskInput: val,
434
+ resumeMap: config.configurable?.[CONFIG_KEY_RESUME_MAP],
435
+ namespaceHash: XXH3(taskCheckpointNamespace)
436
+ }),
437
+ [CONFIG_KEY_PREVIOUS_STATE]: checkpoint.channel_values[PREVIOUS],
438
+ checkpoint_id: void 0,
439
+ checkpoint_ns: taskCheckpointNamespace
440
+ }
441
+ }),
442
+ triggers: [trigger],
443
+ retry_policy: proc.retryPolicy,
444
+ cache_key: proc.cachePolicy ? {
445
+ key: XXH3((proc.cachePolicy.keyFunc ?? JSON.stringify)([val])),
446
+ ns: [
447
+ CACHE_NS_WRITES,
448
+ proc.name ?? "__dynamic__",
449
+ name
450
+ ],
451
+ ttl: proc.cachePolicy.ttl
452
+ } : void 0,
453
+ id: taskId,
454
+ path: taskPath,
455
+ writers: proc.getWriters()
456
+ };
457
+ }
458
+ } else return {
459
+ id: taskId,
460
+ name,
461
+ interrupts: [],
462
+ path: taskPath
463
+ };
464
+ }
465
+ }
466
+ return void 0;
599
467
  }
600
468
  /**
601
- * Function injected under CONFIG_KEY_READ in task config, to read current state.
602
- * Used by conditional edges to read a copy of the state with reflecting the writes
603
- * from that node only.
604
- *
605
- * @internal
606
- */
469
+ * Function injected under CONFIG_KEY_READ in task config, to read current state.
470
+ * Used by conditional edges to read a copy of the state with reflecting the writes
471
+ * from that node only.
472
+ *
473
+ * @internal
474
+ */
607
475
  function _procInput(proc, channels, forExecution) {
608
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
609
- let val;
610
- if (typeof proc.channels === "object" && !Array.isArray(proc.channels)) {
611
- val = {};
612
- for (const [k, chan] of Object.entries(proc.channels)) {
613
- if (proc.triggers.includes(chan)) {
614
- try {
615
- val[k] = readChannel(channels, chan, false);
616
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
617
- }
618
- catch (e) {
619
- if (e.name === EmptyChannelError.unminifiable_name) {
620
- return undefined;
621
- }
622
- else {
623
- throw e;
624
- }
625
- }
626
- }
627
- else if (chan in channels) {
628
- try {
629
- val[k] = readChannel(channels, chan, false);
630
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
631
- }
632
- catch (e) {
633
- if (e.name === EmptyChannelError.unminifiable_name) {
634
- continue;
635
- }
636
- else {
637
- throw e;
638
- }
639
- }
640
- }
641
- }
642
- }
643
- else if (Array.isArray(proc.channels)) {
644
- let successfulRead = false;
645
- for (const chan of proc.channels) {
646
- try {
647
- val = readChannel(channels, chan, false);
648
- successfulRead = true;
649
- break;
650
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
651
- }
652
- catch (e) {
653
- if (e.name === EmptyChannelError.unminifiable_name) {
654
- continue;
655
- }
656
- else {
657
- throw e;
658
- }
659
- }
660
- }
661
- if (!successfulRead) {
662
- return undefined;
663
- }
664
- }
665
- else {
666
- throw new Error(`Invalid channels type, expected list or dict, got ${proc.channels}`);
667
- }
668
- // If the process has a mapper, apply it to the value
669
- if (forExecution && proc.mapper !== undefined) {
670
- val = proc.mapper(val);
671
- }
672
- return val;
476
+ let val;
477
+ if (typeof proc.channels === "object" && !Array.isArray(proc.channels)) {
478
+ val = {};
479
+ for (const [k, chan] of Object.entries(proc.channels)) if (proc.triggers.includes(chan)) try {
480
+ val[k] = readChannel(channels, chan, false);
481
+ } catch (e) {
482
+ if (e.name === EmptyChannelError.unminifiable_name) return void 0;
483
+ else throw e;
484
+ }
485
+ else if (chan in channels) try {
486
+ val[k] = readChannel(channels, chan, false);
487
+ } catch (e) {
488
+ if (e.name === EmptyChannelError.unminifiable_name) continue;
489
+ else throw e;
490
+ }
491
+ } else if (Array.isArray(proc.channels)) {
492
+ let successfulRead = false;
493
+ for (const chan of proc.channels) try {
494
+ val = readChannel(channels, chan, false);
495
+ successfulRead = true;
496
+ break;
497
+ } catch (e) {
498
+ if (e.name === EmptyChannelError.unminifiable_name) continue;
499
+ else throw e;
500
+ }
501
+ if (!successfulRead) return void 0;
502
+ } else throw new Error(`Invalid channels type, expected list or dict, got ${proc.channels}`);
503
+ if (forExecution && proc.mapper !== void 0) val = proc.mapper(val);
504
+ return val;
673
505
  }
674
- function _scratchpad({ pendingWrites, taskId, currentTaskInput, resumeMap, namespaceHash, }) {
675
- const nullResume = pendingWrites.find(([writeTaskId, chan]) => writeTaskId === NULL_TASK_ID && chan === RESUME)?.[2];
676
- const resume = (() => {
677
- const result = pendingWrites
678
- .filter(([writeTaskId, chan]) => writeTaskId === taskId && chan === RESUME)
679
- .flatMap(([_writeTaskId, _chan, resume]) => resume);
680
- if (resumeMap != null && namespaceHash in resumeMap) {
681
- const mappedResume = resumeMap[namespaceHash];
682
- result.push(mappedResume);
683
- }
684
- return result;
685
- })();
686
- const scratchpad = {
687
- callCounter: 0,
688
- interruptCounter: -1,
689
- resume,
690
- nullResume,
691
- subgraphCounter: 0,
692
- currentTaskInput,
693
- consumeNullResume: () => {
694
- if (scratchpad.nullResume) {
695
- delete scratchpad.nullResume;
696
- pendingWrites.splice(pendingWrites.findIndex(([writeTaskId, chan]) => writeTaskId === NULL_TASK_ID && chan === RESUME), 1);
697
- return nullResume;
698
- }
699
- return undefined;
700
- },
701
- };
702
- return scratchpad;
506
+ function _scratchpad({ pendingWrites, taskId, currentTaskInput, resumeMap, namespaceHash }) {
507
+ const nullResume = pendingWrites.find(([writeTaskId, chan]) => writeTaskId === NULL_TASK_ID && chan === RESUME)?.[2];
508
+ const resume = (() => {
509
+ const result = pendingWrites.filter(([writeTaskId, chan]) => writeTaskId === taskId && chan === RESUME).flatMap(([_writeTaskId, _chan, resume$1]) => resume$1);
510
+ if (resumeMap != null && namespaceHash in resumeMap) {
511
+ const mappedResume = resumeMap[namespaceHash];
512
+ result.push(mappedResume);
513
+ }
514
+ return result;
515
+ })();
516
+ const scratchpad = {
517
+ callCounter: 0,
518
+ interruptCounter: -1,
519
+ resume,
520
+ nullResume,
521
+ subgraphCounter: 0,
522
+ currentTaskInput,
523
+ consumeNullResume: () => {
524
+ if (scratchpad.nullResume) {
525
+ delete scratchpad.nullResume;
526
+ pendingWrites.splice(pendingWrites.findIndex(([writeTaskId, chan]) => writeTaskId === NULL_TASK_ID && chan === RESUME), 1);
527
+ return nullResume;
528
+ }
529
+ return void 0;
530
+ }
531
+ };
532
+ return scratchpad;
703
533
  }
534
+
535
+ //#endregion
536
+ export { _applyWrites, _localRead, _prepareNextTasks, _prepareSingleTask, increment, shouldInterrupt };
704
537
  //# sourceMappingURL=algo.js.map