@langchain/langgraph 1.0.7 → 1.0.12

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 (383) hide show
  1. package/package.json +7 -7
  2. package/CHANGELOG.md +0 -286
  3. package/dist/_virtual/rolldown_runtime.cjs +0 -25
  4. package/dist/channels/any_value.cjs +0 -46
  5. package/dist/channels/any_value.cjs.map +0 -1
  6. package/dist/channels/any_value.d.cts +0 -24
  7. package/dist/channels/any_value.d.cts.map +0 -1
  8. package/dist/channels/any_value.d.ts +0 -24
  9. package/dist/channels/any_value.d.ts.map +0 -1
  10. package/dist/channels/any_value.js +0 -46
  11. package/dist/channels/any_value.js.map +0 -1
  12. package/dist/channels/base.cjs +0 -102
  13. package/dist/channels/base.cjs.map +0 -1
  14. package/dist/channels/base.d.cts +0 -79
  15. package/dist/channels/base.d.cts.map +0 -1
  16. package/dist/channels/base.d.ts +0 -79
  17. package/dist/channels/base.d.ts.map +0 -1
  18. package/dist/channels/base.js +0 -97
  19. package/dist/channels/base.js.map +0 -1
  20. package/dist/channels/binop.cjs +0 -49
  21. package/dist/channels/binop.cjs.map +0 -1
  22. package/dist/channels/binop.d.cts +0 -22
  23. package/dist/channels/binop.d.cts.map +0 -1
  24. package/dist/channels/binop.d.ts +0 -22
  25. package/dist/channels/binop.d.ts.map +0 -1
  26. package/dist/channels/binop.js +0 -49
  27. package/dist/channels/binop.js.map +0 -1
  28. package/dist/channels/dynamic_barrier_value.cjs +0 -76
  29. package/dist/channels/dynamic_barrier_value.cjs.map +0 -1
  30. package/dist/channels/dynamic_barrier_value.d.cts +0 -42
  31. package/dist/channels/dynamic_barrier_value.d.cts.map +0 -1
  32. package/dist/channels/dynamic_barrier_value.d.ts +0 -42
  33. package/dist/channels/dynamic_barrier_value.d.ts.map +0 -1
  34. package/dist/channels/dynamic_barrier_value.js +0 -76
  35. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  36. package/dist/channels/ephemeral_value.cjs +0 -46
  37. package/dist/channels/ephemeral_value.cjs.map +0 -1
  38. package/dist/channels/ephemeral_value.d.cts +0 -22
  39. package/dist/channels/ephemeral_value.d.cts.map +0 -1
  40. package/dist/channels/ephemeral_value.d.ts +0 -22
  41. package/dist/channels/ephemeral_value.d.ts.map +0 -1
  42. package/dist/channels/ephemeral_value.js +0 -46
  43. package/dist/channels/ephemeral_value.js.map +0 -1
  44. package/dist/channels/index.cjs +0 -21
  45. package/dist/channels/index.d.cts +0 -9
  46. package/dist/channels/index.d.ts +0 -9
  47. package/dist/channels/index.js +0 -10
  48. package/dist/channels/last_value.cjs +0 -98
  49. package/dist/channels/last_value.cjs.map +0 -1
  50. package/dist/channels/last_value.d.cts +0 -44
  51. package/dist/channels/last_value.d.cts.map +0 -1
  52. package/dist/channels/last_value.d.ts +0 -44
  53. package/dist/channels/last_value.d.ts.map +0 -1
  54. package/dist/channels/last_value.js +0 -97
  55. package/dist/channels/last_value.js.map +0 -1
  56. package/dist/channels/named_barrier_value.cjs +0 -118
  57. package/dist/channels/named_barrier_value.cjs.map +0 -1
  58. package/dist/channels/named_barrier_value.d.cts +0 -46
  59. package/dist/channels/named_barrier_value.d.cts.map +0 -1
  60. package/dist/channels/named_barrier_value.d.ts +0 -46
  61. package/dist/channels/named_barrier_value.d.ts.map +0 -1
  62. package/dist/channels/named_barrier_value.js +0 -116
  63. package/dist/channels/named_barrier_value.js.map +0 -1
  64. package/dist/channels/topic.cjs +0 -65
  65. package/dist/channels/topic.cjs.map +0 -1
  66. package/dist/channels/topic.d.cts +0 -32
  67. package/dist/channels/topic.d.cts.map +0 -1
  68. package/dist/channels/topic.d.ts +0 -32
  69. package/dist/channels/topic.d.ts.map +0 -1
  70. package/dist/channels/topic.js +0 -65
  71. package/dist/channels/topic.js.map +0 -1
  72. package/dist/constants.cjs +0 -406
  73. package/dist/constants.cjs.map +0 -1
  74. package/dist/constants.d.cts +0 -285
  75. package/dist/constants.d.cts.map +0 -1
  76. package/dist/constants.d.ts +0 -285
  77. package/dist/constants.d.ts.map +0 -1
  78. package/dist/constants.js +0 -362
  79. package/dist/constants.js.map +0 -1
  80. package/dist/errors.cjs +0 -163
  81. package/dist/errors.cjs.map +0 -1
  82. package/dist/errors.d.cts +0 -81
  83. package/dist/errors.d.cts.map +0 -1
  84. package/dist/errors.d.ts +0 -81
  85. package/dist/errors.d.ts.map +0 -1
  86. package/dist/errors.js +0 -146
  87. package/dist/errors.js.map +0 -1
  88. package/dist/func/index.cjs +0 -301
  89. package/dist/func/index.cjs.map +0 -1
  90. package/dist/func/index.d.cts +0 -293
  91. package/dist/func/index.d.cts.map +0 -1
  92. package/dist/func/index.d.ts +0 -293
  93. package/dist/func/index.d.ts.map +0 -1
  94. package/dist/func/index.js +0 -298
  95. package/dist/func/index.js.map +0 -1
  96. package/dist/func/types.d.cts +0 -64
  97. package/dist/func/types.d.cts.map +0 -1
  98. package/dist/func/types.d.ts +0 -64
  99. package/dist/func/types.d.ts.map +0 -1
  100. package/dist/graph/annotation.cjs +0 -101
  101. package/dist/graph/annotation.cjs.map +0 -1
  102. package/dist/graph/annotation.d.cts +0 -116
  103. package/dist/graph/annotation.d.cts.map +0 -1
  104. package/dist/graph/annotation.d.ts +0 -116
  105. package/dist/graph/annotation.d.ts.map +0 -1
  106. package/dist/graph/annotation.js +0 -99
  107. package/dist/graph/annotation.js.map +0 -1
  108. package/dist/graph/graph.cjs +0 -423
  109. package/dist/graph/graph.cjs.map +0 -1
  110. package/dist/graph/graph.d.cts +0 -132
  111. package/dist/graph/graph.d.cts.map +0 -1
  112. package/dist/graph/graph.d.ts +0 -132
  113. package/dist/graph/graph.d.ts.map +0 -1
  114. package/dist/graph/graph.js +0 -420
  115. package/dist/graph/graph.js.map +0 -1
  116. package/dist/graph/index.cjs +0 -5
  117. package/dist/graph/index.js +0 -7
  118. package/dist/graph/message.cjs +0 -99
  119. package/dist/graph/message.cjs.map +0 -1
  120. package/dist/graph/message.d.cts +0 -40
  121. package/dist/graph/message.d.cts.map +0 -1
  122. package/dist/graph/message.d.ts +0 -40
  123. package/dist/graph/message.d.ts.map +0 -1
  124. package/dist/graph/message.js +0 -95
  125. package/dist/graph/message.js.map +0 -1
  126. package/dist/graph/messages_annotation.cjs +0 -110
  127. package/dist/graph/messages_annotation.cjs.map +0 -1
  128. package/dist/graph/messages_annotation.d.cts +0 -112
  129. package/dist/graph/messages_annotation.d.cts.map +0 -1
  130. package/dist/graph/messages_annotation.d.ts +0 -112
  131. package/dist/graph/messages_annotation.d.ts.map +0 -1
  132. package/dist/graph/messages_annotation.js +0 -107
  133. package/dist/graph/messages_annotation.js.map +0 -1
  134. package/dist/graph/state.cjs +0 -501
  135. package/dist/graph/state.cjs.map +0 -1
  136. package/dist/graph/state.d.cts +0 -236
  137. package/dist/graph/state.d.cts.map +0 -1
  138. package/dist/graph/state.d.ts +0 -236
  139. package/dist/graph/state.d.ts.map +0 -1
  140. package/dist/graph/state.js +0 -499
  141. package/dist/graph/state.js.map +0 -1
  142. package/dist/graph/zod/index.cjs +0 -10
  143. package/dist/graph/zod/index.d.cts +0 -3
  144. package/dist/graph/zod/index.d.ts +0 -3
  145. package/dist/graph/zod/index.js +0 -5
  146. package/dist/graph/zod/meta.cjs +0 -145
  147. package/dist/graph/zod/meta.cjs.map +0 -1
  148. package/dist/graph/zod/meta.d.cts +0 -116
  149. package/dist/graph/zod/meta.d.cts.map +0 -1
  150. package/dist/graph/zod/meta.d.ts +0 -116
  151. package/dist/graph/zod/meta.d.ts.map +0 -1
  152. package/dist/graph/zod/meta.js +0 -141
  153. package/dist/graph/zod/meta.js.map +0 -1
  154. package/dist/graph/zod/plugin.cjs +0 -41
  155. package/dist/graph/zod/plugin.cjs.map +0 -1
  156. package/dist/graph/zod/plugin.js +0 -41
  157. package/dist/graph/zod/plugin.js.map +0 -1
  158. package/dist/graph/zod/schema.cjs +0 -99
  159. package/dist/graph/zod/schema.cjs.map +0 -1
  160. package/dist/graph/zod/schema.d.cts +0 -38
  161. package/dist/graph/zod/schema.d.cts.map +0 -1
  162. package/dist/graph/zod/schema.d.ts +0 -38
  163. package/dist/graph/zod/schema.d.ts.map +0 -1
  164. package/dist/graph/zod/schema.js +0 -94
  165. package/dist/graph/zod/schema.js.map +0 -1
  166. package/dist/graph/zod/zod-registry.cjs +0 -43
  167. package/dist/graph/zod/zod-registry.cjs.map +0 -1
  168. package/dist/graph/zod/zod-registry.d.cts +0 -51
  169. package/dist/graph/zod/zod-registry.d.cts.map +0 -1
  170. package/dist/graph/zod/zod-registry.d.ts +0 -51
  171. package/dist/graph/zod/zod-registry.d.ts.map +0 -1
  172. package/dist/graph/zod/zod-registry.js +0 -41
  173. package/dist/graph/zod/zod-registry.js.map +0 -1
  174. package/dist/hash.cjs +0 -271
  175. package/dist/hash.cjs.map +0 -1
  176. package/dist/hash.js +0 -269
  177. package/dist/hash.js.map +0 -1
  178. package/dist/index.cjs +0 -112
  179. package/dist/index.cjs.map +0 -1
  180. package/dist/index.d.cts +0 -26
  181. package/dist/index.d.ts +0 -26
  182. package/dist/index.js +0 -22
  183. package/dist/index.js.map +0 -1
  184. package/dist/interrupt.cjs +0 -82
  185. package/dist/interrupt.cjs.map +0 -1
  186. package/dist/interrupt.d.cts +0 -58
  187. package/dist/interrupt.d.cts.map +0 -1
  188. package/dist/interrupt.d.ts +0 -58
  189. package/dist/interrupt.d.ts.map +0 -1
  190. package/dist/interrupt.js +0 -81
  191. package/dist/interrupt.js.map +0 -1
  192. package/dist/prebuilt/agentName.cjs +0 -153
  193. package/dist/prebuilt/agentName.cjs.map +0 -1
  194. package/dist/prebuilt/agentName.d.cts +0 -42
  195. package/dist/prebuilt/agentName.d.cts.map +0 -1
  196. package/dist/prebuilt/agentName.d.ts +0 -42
  197. package/dist/prebuilt/agentName.d.ts.map +0 -1
  198. package/dist/prebuilt/agentName.js +0 -152
  199. package/dist/prebuilt/agentName.js.map +0 -1
  200. package/dist/prebuilt/agent_executor.cjs +0 -44
  201. package/dist/prebuilt/agent_executor.cjs.map +0 -1
  202. package/dist/prebuilt/agent_executor.d.cts +0 -58
  203. package/dist/prebuilt/agent_executor.d.cts.map +0 -1
  204. package/dist/prebuilt/agent_executor.d.ts +0 -58
  205. package/dist/prebuilt/agent_executor.d.ts.map +0 -1
  206. package/dist/prebuilt/agent_executor.js +0 -44
  207. package/dist/prebuilt/agent_executor.js.map +0 -1
  208. package/dist/prebuilt/chat_agent_executor.cjs +0 -68
  209. package/dist/prebuilt/chat_agent_executor.cjs.map +0 -1
  210. package/dist/prebuilt/chat_agent_executor.d.cts +0 -23
  211. package/dist/prebuilt/chat_agent_executor.d.cts.map +0 -1
  212. package/dist/prebuilt/chat_agent_executor.d.ts +0 -23
  213. package/dist/prebuilt/chat_agent_executor.d.ts.map +0 -1
  214. package/dist/prebuilt/chat_agent_executor.js +0 -67
  215. package/dist/prebuilt/chat_agent_executor.js.map +0 -1
  216. package/dist/prebuilt/index.cjs +0 -15
  217. package/dist/prebuilt/index.d.cts +0 -8
  218. package/dist/prebuilt/index.d.ts +0 -8
  219. package/dist/prebuilt/index.js +0 -8
  220. package/dist/prebuilt/interrupt.d.cts +0 -61
  221. package/dist/prebuilt/interrupt.d.cts.map +0 -1
  222. package/dist/prebuilt/interrupt.d.ts +0 -61
  223. package/dist/prebuilt/interrupt.d.ts.map +0 -1
  224. package/dist/prebuilt/react_agent_executor.cjs +0 -344
  225. package/dist/prebuilt/react_agent_executor.cjs.map +0 -1
  226. package/dist/prebuilt/react_agent_executor.d.cts +0 -230
  227. package/dist/prebuilt/react_agent_executor.d.cts.map +0 -1
  228. package/dist/prebuilt/react_agent_executor.d.ts +0 -230
  229. package/dist/prebuilt/react_agent_executor.d.ts.map +0 -1
  230. package/dist/prebuilt/react_agent_executor.js +0 -342
  231. package/dist/prebuilt/react_agent_executor.js.map +0 -1
  232. package/dist/prebuilt/tool_executor.cjs +0 -48
  233. package/dist/prebuilt/tool_executor.cjs.map +0 -1
  234. package/dist/prebuilt/tool_executor.d.cts +0 -42
  235. package/dist/prebuilt/tool_executor.d.cts.map +0 -1
  236. package/dist/prebuilt/tool_executor.d.ts +0 -42
  237. package/dist/prebuilt/tool_executor.d.ts.map +0 -1
  238. package/dist/prebuilt/tool_executor.js +0 -47
  239. package/dist/prebuilt/tool_executor.js.map +0 -1
  240. package/dist/prebuilt/tool_node.cjs +0 -248
  241. package/dist/prebuilt/tool_node.cjs.map +0 -1
  242. package/dist/prebuilt/tool_node.d.cts +0 -182
  243. package/dist/prebuilt/tool_node.d.cts.map +0 -1
  244. package/dist/prebuilt/tool_node.d.ts +0 -182
  245. package/dist/prebuilt/tool_node.d.ts.map +0 -1
  246. package/dist/prebuilt/tool_node.js +0 -246
  247. package/dist/prebuilt/tool_node.js.map +0 -1
  248. package/dist/pregel/algo.cjs +0 -573
  249. package/dist/pregel/algo.cjs.map +0 -1
  250. package/dist/pregel/algo.d.cts +0 -13
  251. package/dist/pregel/algo.d.cts.map +0 -1
  252. package/dist/pregel/algo.d.ts +0 -13
  253. package/dist/pregel/algo.d.ts.map +0 -1
  254. package/dist/pregel/algo.js +0 -567
  255. package/dist/pregel/algo.js.map +0 -1
  256. package/dist/pregel/call.cjs +0 -53
  257. package/dist/pregel/call.cjs.map +0 -1
  258. package/dist/pregel/call.js +0 -50
  259. package/dist/pregel/call.js.map +0 -1
  260. package/dist/pregel/debug.cjs +0 -175
  261. package/dist/pregel/debug.cjs.map +0 -1
  262. package/dist/pregel/debug.js +0 -169
  263. package/dist/pregel/debug.js.map +0 -1
  264. package/dist/pregel/index.cjs +0 -1170
  265. package/dist/pregel/index.cjs.map +0 -1
  266. package/dist/pregel/index.d.cts +0 -546
  267. package/dist/pregel/index.d.cts.map +0 -1
  268. package/dist/pregel/index.d.ts +0 -546
  269. package/dist/pregel/index.d.ts.map +0 -1
  270. package/dist/pregel/index.js +0 -1168
  271. package/dist/pregel/index.js.map +0 -1
  272. package/dist/pregel/io.cjs +0 -140
  273. package/dist/pregel/io.cjs.map +0 -1
  274. package/dist/pregel/io.js +0 -135
  275. package/dist/pregel/io.js.map +0 -1
  276. package/dist/pregel/loop.cjs +0 -548
  277. package/dist/pregel/loop.cjs.map +0 -1
  278. package/dist/pregel/loop.js +0 -547
  279. package/dist/pregel/loop.js.map +0 -1
  280. package/dist/pregel/messages.cjs +0 -108
  281. package/dist/pregel/messages.cjs.map +0 -1
  282. package/dist/pregel/messages.js +0 -107
  283. package/dist/pregel/messages.js.map +0 -1
  284. package/dist/pregel/read.cjs +0 -152
  285. package/dist/pregel/read.cjs.map +0 -1
  286. package/dist/pregel/read.d.cts +0 -51
  287. package/dist/pregel/read.d.cts.map +0 -1
  288. package/dist/pregel/read.d.ts +0 -51
  289. package/dist/pregel/read.d.ts.map +0 -1
  290. package/dist/pregel/read.js +0 -150
  291. package/dist/pregel/read.js.map +0 -1
  292. package/dist/pregel/remote.cjs +0 -349
  293. package/dist/pregel/remote.cjs.map +0 -1
  294. package/dist/pregel/remote.d.cts +0 -123
  295. package/dist/pregel/remote.d.cts.map +0 -1
  296. package/dist/pregel/remote.d.ts +0 -123
  297. package/dist/pregel/remote.d.ts.map +0 -1
  298. package/dist/pregel/remote.js +0 -348
  299. package/dist/pregel/remote.js.map +0 -1
  300. package/dist/pregel/retry.cjs +0 -92
  301. package/dist/pregel/retry.cjs.map +0 -1
  302. package/dist/pregel/retry.js +0 -92
  303. package/dist/pregel/retry.js.map +0 -1
  304. package/dist/pregel/runnable_types.d.cts +0 -49
  305. package/dist/pregel/runnable_types.d.cts.map +0 -1
  306. package/dist/pregel/runnable_types.d.ts +0 -49
  307. package/dist/pregel/runnable_types.d.ts.map +0 -1
  308. package/dist/pregel/runner.cjs +0 -228
  309. package/dist/pregel/runner.cjs.map +0 -1
  310. package/dist/pregel/runner.js +0 -228
  311. package/dist/pregel/runner.js.map +0 -1
  312. package/dist/pregel/stream.cjs +0 -199
  313. package/dist/pregel/stream.cjs.map +0 -1
  314. package/dist/pregel/stream.js +0 -196
  315. package/dist/pregel/stream.js.map +0 -1
  316. package/dist/pregel/types.cjs +0 -27
  317. package/dist/pregel/types.cjs.map +0 -1
  318. package/dist/pregel/types.d.cts +0 -453
  319. package/dist/pregel/types.d.cts.map +0 -1
  320. package/dist/pregel/types.d.ts +0 -453
  321. package/dist/pregel/types.d.ts.map +0 -1
  322. package/dist/pregel/types.js +0 -25
  323. package/dist/pregel/types.js.map +0 -1
  324. package/dist/pregel/utils/config.cjs +0 -122
  325. package/dist/pregel/utils/config.cjs.map +0 -1
  326. package/dist/pregel/utils/config.d.cts +0 -36
  327. package/dist/pregel/utils/config.d.cts.map +0 -1
  328. package/dist/pregel/utils/config.d.ts +0 -36
  329. package/dist/pregel/utils/config.d.ts.map +0 -1
  330. package/dist/pregel/utils/config.js +0 -115
  331. package/dist/pregel/utils/config.js.map +0 -1
  332. package/dist/pregel/utils/index.cjs +0 -103
  333. package/dist/pregel/utils/index.cjs.map +0 -1
  334. package/dist/pregel/utils/index.d.cts +0 -51
  335. package/dist/pregel/utils/index.d.cts.map +0 -1
  336. package/dist/pregel/utils/index.d.ts +0 -51
  337. package/dist/pregel/utils/index.d.ts.map +0 -1
  338. package/dist/pregel/utils/index.js +0 -97
  339. package/dist/pregel/utils/index.js.map +0 -1
  340. package/dist/pregel/utils/subgraph.cjs +0 -19
  341. package/dist/pregel/utils/subgraph.cjs.map +0 -1
  342. package/dist/pregel/utils/subgraph.js +0 -17
  343. package/dist/pregel/utils/subgraph.js.map +0 -1
  344. package/dist/pregel/validate.cjs +0 -45
  345. package/dist/pregel/validate.cjs.map +0 -1
  346. package/dist/pregel/validate.js +0 -44
  347. package/dist/pregel/validate.js.map +0 -1
  348. package/dist/pregel/write.cjs +0 -97
  349. package/dist/pregel/write.cjs.map +0 -1
  350. package/dist/pregel/write.d.cts +0 -35
  351. package/dist/pregel/write.d.cts.map +0 -1
  352. package/dist/pregel/write.d.ts +0 -35
  353. package/dist/pregel/write.d.ts.map +0 -1
  354. package/dist/pregel/write.js +0 -95
  355. package/dist/pregel/write.js.map +0 -1
  356. package/dist/remote.cjs +0 -3
  357. package/dist/remote.d.cts +0 -2
  358. package/dist/remote.d.ts +0 -2
  359. package/dist/remote.js +0 -3
  360. package/dist/setup/async_local_storage.cjs +0 -12
  361. package/dist/setup/async_local_storage.cjs.map +0 -1
  362. package/dist/setup/async_local_storage.js +0 -11
  363. package/dist/setup/async_local_storage.js.map +0 -1
  364. package/dist/utils.cjs +0 -88
  365. package/dist/utils.cjs.map +0 -1
  366. package/dist/utils.d.cts +0 -32
  367. package/dist/utils.d.cts.map +0 -1
  368. package/dist/utils.d.ts +0 -32
  369. package/dist/utils.d.ts.map +0 -1
  370. package/dist/utils.js +0 -81
  371. package/dist/utils.js.map +0 -1
  372. package/dist/web.cjs +0 -96
  373. package/dist/web.d.cts +0 -23
  374. package/dist/web.d.ts +0 -23
  375. package/dist/web.js +0 -15
  376. package/dist/writer.cjs +0 -15
  377. package/dist/writer.cjs.map +0 -1
  378. package/dist/writer.d.cts +0 -7
  379. package/dist/writer.d.cts.map +0 -1
  380. package/dist/writer.d.ts +0 -7
  381. package/dist/writer.d.ts.map +0 -1
  382. package/dist/writer.js +0 -14
  383. package/dist/writer.js.map +0 -1
@@ -1,1170 +0,0 @@
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_config = require('./utils/config.cjs');
6
- const require_utils = require('../utils.cjs');
7
- const require_write = require('./write.cjs');
8
- const require_read = require('./read.cjs');
9
- const require_io = require('./io.cjs');
10
- const require_index = require('./utils/index.cjs');
11
- const require_algo = require('./algo.cjs');
12
- const require_subgraph = require('./utils/subgraph.cjs');
13
- const require_debug = require('./debug.cjs');
14
- const require_stream = require('./stream.cjs');
15
- const require_loop = require('./loop.cjs');
16
- const require_messages = require('./messages.cjs');
17
- const require_runner = require('./runner.cjs');
18
- const require_validate = require('./validate.cjs');
19
- const require_topic = require('../channels/topic.cjs');
20
- const require_interrupt = require('../interrupt.cjs');
21
- const __langchain_langgraph_checkpoint = require_rolldown_runtime.__toESM(require("@langchain/langgraph-checkpoint"));
22
- const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
23
-
24
- //#region src/pregel/index.ts
25
- /**
26
- * Utility class for working with channels in the Pregel system.
27
- * Provides static methods for subscribing to channels and writing to them.
28
- *
29
- * Channels are the communication pathways between nodes in a Pregel graph.
30
- * They enable message passing and state updates between different parts of the graph.
31
- */
32
- var Channel = class {
33
- static subscribeTo(channels, options) {
34
- const { key, tags } = {
35
- key: void 0,
36
- tags: void 0,
37
- ...options ?? {}
38
- };
39
- if (Array.isArray(channels) && key !== void 0) throw new Error("Can't specify a key when subscribing to multiple channels");
40
- let channelMappingOrArray;
41
- if (typeof channels === "string") if (key) channelMappingOrArray = { [key]: channels };
42
- else channelMappingOrArray = [channels];
43
- else channelMappingOrArray = Object.fromEntries(channels.map((chan) => [chan, chan]));
44
- const triggers = Array.isArray(channels) ? channels : [channels];
45
- return new require_read.PregelNode({
46
- channels: channelMappingOrArray,
47
- triggers,
48
- tags
49
- });
50
- }
51
- /**
52
- * Creates a ChannelWrite that specifies how to write values to channels.
53
- * This is used to define how nodes send output to channels.
54
- *
55
- * @example
56
- * ```typescript
57
- * // Write to multiple channels
58
- * const write = Channel.writeTo(["output", "state"]);
59
- *
60
- * // Write with specific values
61
- * const write = Channel.writeTo(["output"], {
62
- * state: "completed",
63
- * result: calculateResult()
64
- * });
65
- *
66
- * // Write with a transformation function
67
- * const write = Channel.writeTo(["output"], {
68
- * result: (x) => processResult(x)
69
- * });
70
- * ```
71
- *
72
- * @param channels - Array of channel names to write to
73
- * @param writes - Optional map of channel names to values or transformations
74
- * @returns A ChannelWrite object that can be used to write to the specified channels
75
- */
76
- static writeTo(channels, writes) {
77
- const channelWriteEntries = [];
78
- for (const channel of channels) channelWriteEntries.push({
79
- channel,
80
- value: require_write.PASSTHROUGH,
81
- skipNone: false
82
- });
83
- for (const [key, value] of Object.entries(writes ?? {})) if (__langchain_core_runnables.Runnable.isRunnable(value) || typeof value === "function") channelWriteEntries.push({
84
- channel: key,
85
- value: require_write.PASSTHROUGH,
86
- skipNone: true,
87
- mapper: (0, __langchain_core_runnables._coerceToRunnable)(value)
88
- });
89
- else channelWriteEntries.push({
90
- channel: key,
91
- value,
92
- skipNone: false
93
- });
94
- return new require_write.ChannelWrite(channelWriteEntries);
95
- }
96
- };
97
- var PartialRunnable = class extends __langchain_core_runnables.Runnable {
98
- lc_namespace = ["langgraph", "pregel"];
99
- invoke(_input, _options) {
100
- throw new Error("Not implemented");
101
- }
102
- withConfig(_config) {
103
- return super.withConfig(_config);
104
- }
105
- stream(input, options) {
106
- return super.stream(input, options);
107
- }
108
- };
109
- /**
110
- * The Pregel class is the core runtime engine of LangGraph, implementing a message-passing graph computation model
111
- * inspired by [Google's Pregel system](https://research.google/pubs/pregel-a-system-for-large-scale-graph-processing/).
112
- * It provides the foundation for building reliable, controllable agent workflows that can evolve state over time.
113
- *
114
- * Key features:
115
- * - Message passing between nodes in discrete "supersteps"
116
- * - Built-in persistence layer through checkpointers
117
- * - First-class streaming support for values, updates, and events
118
- * - Human-in-the-loop capabilities via interrupts
119
- * - Support for parallel node execution within supersteps
120
- *
121
- * The Pregel class is not intended to be instantiated directly by consumers. Instead, use the following higher-level APIs:
122
- * - {@link StateGraph}: The main graph class for building agent workflows
123
- * - Compiling a {@link StateGraph} will return a {@link CompiledGraph} instance, which extends `Pregel`
124
- * - Functional API: A declarative approach using tasks and entrypoints
125
- * - A `Pregel` instance is returned by the {@link entrypoint} function
126
- *
127
- * @example
128
- * ```typescript
129
- * // Using StateGraph API
130
- * const graph = new StateGraph(annotation)
131
- * .addNode("nodeA", myNodeFunction)
132
- * .addEdge("nodeA", "nodeB")
133
- * .compile();
134
- *
135
- * // The compiled graph is a Pregel instance
136
- * const result = await graph.invoke(input);
137
- * ```
138
- *
139
- * @example
140
- * ```typescript
141
- * // Using Functional API
142
- * import { task, entrypoint } from "@langchain/langgraph";
143
- * import { MemorySaver } from "@langchain/langgraph-checkpoint";
144
- *
145
- * // Define tasks that can be composed
146
- * const addOne = task("add", async (x: number) => x + 1);
147
- *
148
- * // Create a workflow using the entrypoint function
149
- * const workflow = entrypoint({
150
- * name: "workflow",
151
- * checkpointer: new MemorySaver()
152
- * }, async (numbers: number[]) => {
153
- * // Tasks can be run in parallel
154
- * const results = await Promise.all(numbers.map(n => addOne(n)));
155
- * return results;
156
- * });
157
- *
158
- * // The workflow is a Pregel instance
159
- * const result = await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]
160
- * ```
161
- *
162
- * @typeParam Nodes - Mapping of node names to their {@link PregelNode} implementations
163
- * @typeParam Channels - Mapping of channel names to their {@link BaseChannel} or {@link ManagedValueSpec} implementations
164
- * @typeParam ContextType - Type of context that can be passed to the graph
165
- * @typeParam InputType - Type of input values accepted by the graph
166
- * @typeParam OutputType - Type of output values produced by the graph
167
- */
168
- var Pregel = class extends PartialRunnable {
169
- /**
170
- * Name of the class when serialized
171
- * @internal
172
- */
173
- static lc_name() {
174
- return "LangGraph";
175
- }
176
- /** @internal LangChain namespace for serialization necessary because Pregel extends Runnable */
177
- lc_namespace = ["langgraph", "pregel"];
178
- /** @internal Flag indicating this is a Pregel instance - necessary for serialization */
179
- lg_is_pregel = true;
180
- /** The nodes in the graph, mapping node names to their PregelNode instances */
181
- nodes;
182
- /** The channels in the graph, mapping channel names to their BaseChannel or ManagedValueSpec instances */
183
- channels;
184
- /**
185
- * The input channels for the graph. These channels receive the initial input when the graph is invoked.
186
- * Can be a single channel key or an array of channel keys.
187
- */
188
- inputChannels;
189
- /**
190
- * The output channels for the graph. These channels contain the final output when the graph completes.
191
- * Can be a single channel key or an array of channel keys.
192
- */
193
- outputChannels;
194
- /** Whether to automatically validate the graph structure when it is compiled. Defaults to true. */
195
- autoValidate = true;
196
- /**
197
- * The streaming modes enabled for this graph. Defaults to ["values"].
198
- * Supported modes:
199
- * - "values": Streams the full state after each step
200
- * - "updates": Streams state updates after each step
201
- * - "messages": Streams messages from within nodes
202
- * - "custom": Streams custom events from within nodes
203
- * - "debug": Streams events related to the execution of the graph - useful for tracing & debugging graph execution
204
- */
205
- streamMode = ["values"];
206
- /**
207
- * Optional channels to stream. If not specified, all channels will be streamed.
208
- * Can be a single channel key or an array of channel keys.
209
- */
210
- streamChannels;
211
- /**
212
- * Optional array of node names or "all" to interrupt after executing these nodes.
213
- * Used for implementing human-in-the-loop workflows.
214
- */
215
- interruptAfter;
216
- /**
217
- * Optional array of node names or "all" to interrupt before executing these nodes.
218
- * Used for implementing human-in-the-loop workflows.
219
- */
220
- interruptBefore;
221
- /** Optional timeout in milliseconds for the execution of each superstep */
222
- stepTimeout;
223
- /** Whether to enable debug logging. Defaults to false. */
224
- debug = false;
225
- /**
226
- * Optional checkpointer for persisting graph state.
227
- * When provided, saves a checkpoint of the graph state at every superstep.
228
- * When false or undefined, checkpointing is disabled, and the graph will not be able to save or restore state.
229
- */
230
- checkpointer;
231
- /** Optional retry policy for handling failures in node execution */
232
- retryPolicy;
233
- /** The default configuration for graph execution, can be overridden on a per-invocation basis */
234
- config;
235
- /**
236
- * Optional long-term memory store for the graph, allows for persistence & retrieval of data across threads
237
- */
238
- store;
239
- /**
240
- * Optional cache for the graph, useful for caching tasks.
241
- */
242
- cache;
243
- /**
244
- * Optional interrupt helper function.
245
- * @internal
246
- */
247
- userInterrupt;
248
- /**
249
- * The trigger to node mapping for the graph run.
250
- * @internal
251
- */
252
- triggerToNodes = {};
253
- /**
254
- * Constructor for Pregel - meant for internal use only.
255
- *
256
- * @internal
257
- */
258
- constructor(fields) {
259
- super(fields);
260
- let { streamMode } = fields;
261
- if (streamMode != null && !Array.isArray(streamMode)) streamMode = [streamMode];
262
- this.nodes = fields.nodes;
263
- this.channels = fields.channels;
264
- if (require_constants.TASKS in this.channels && "lc_graph_name" in this.channels[require_constants.TASKS] && this.channels[require_constants.TASKS].lc_graph_name !== "Topic") throw new Error(`Channel '${require_constants.TASKS}' is reserved and cannot be used in the graph.`);
265
- else this.channels[require_constants.TASKS] = new require_topic.Topic({ accumulate: false });
266
- this.autoValidate = fields.autoValidate ?? this.autoValidate;
267
- this.streamMode = streamMode ?? this.streamMode;
268
- this.inputChannels = fields.inputChannels;
269
- this.outputChannels = fields.outputChannels;
270
- this.streamChannels = fields.streamChannels ?? this.streamChannels;
271
- this.interruptAfter = fields.interruptAfter;
272
- this.interruptBefore = fields.interruptBefore;
273
- this.stepTimeout = fields.stepTimeout ?? this.stepTimeout;
274
- this.debug = fields.debug ?? this.debug;
275
- this.checkpointer = fields.checkpointer;
276
- this.retryPolicy = fields.retryPolicy;
277
- this.config = fields.config;
278
- this.store = fields.store;
279
- this.cache = fields.cache;
280
- this.name = fields.name;
281
- this.triggerToNodes = fields.triggerToNodes ?? this.triggerToNodes;
282
- this.userInterrupt = fields.userInterrupt;
283
- if (this.autoValidate) this.validate();
284
- }
285
- /**
286
- * Creates a new instance of the Pregel graph with updated configuration.
287
- * This method follows the immutable pattern - instead of modifying the current instance,
288
- * it returns a new instance with the merged configuration.
289
- *
290
- * @example
291
- * ```typescript
292
- * // Create a new instance with debug enabled
293
- * const debugGraph = graph.withConfig({ debug: true });
294
- *
295
- * // Create a new instance with a specific thread ID
296
- * const threadGraph = graph.withConfig({
297
- * configurable: { thread_id: "123" }
298
- * });
299
- * ```
300
- *
301
- * @param config - The configuration to merge with the current configuration
302
- * @returns A new Pregel instance with the merged configuration
303
- */
304
- withConfig(config) {
305
- const mergedConfig = (0, __langchain_core_runnables.mergeConfigs)(this.config, config);
306
- return new this.constructor({
307
- ...this,
308
- config: mergedConfig
309
- });
310
- }
311
- /**
312
- * Validates the graph structure to ensure it is well-formed.
313
- * Checks for:
314
- * - No orphaned nodes
315
- * - Valid input/output channel configurations
316
- * - Valid interrupt configurations
317
- *
318
- * @returns this - The Pregel instance for method chaining
319
- * @throws {GraphValidationError} If the graph structure is invalid
320
- */
321
- validate() {
322
- require_validate.validateGraph({
323
- nodes: this.nodes,
324
- channels: this.channels,
325
- outputChannels: this.outputChannels,
326
- inputChannels: this.inputChannels,
327
- streamChannels: this.streamChannels,
328
- interruptAfterNodes: this.interruptAfter,
329
- interruptBeforeNodes: this.interruptBefore
330
- });
331
- for (const [name, node] of Object.entries(this.nodes)) for (const trigger of node.triggers) {
332
- this.triggerToNodes[trigger] ??= [];
333
- this.triggerToNodes[trigger].push(name);
334
- }
335
- return this;
336
- }
337
- /**
338
- * Gets a list of all channels that should be streamed.
339
- * If streamChannels is specified, returns those channels.
340
- * Otherwise, returns all channels in the graph.
341
- *
342
- * @returns Array of channel keys to stream
343
- */
344
- get streamChannelsList() {
345
- if (Array.isArray(this.streamChannels)) return this.streamChannels;
346
- else if (this.streamChannels) return [this.streamChannels];
347
- else return Object.keys(this.channels);
348
- }
349
- /**
350
- * Gets the channels to stream in their original format.
351
- * If streamChannels is specified, returns it as-is (either single key or array).
352
- * Otherwise, returns all channels in the graph as an array.
353
- *
354
- * @returns Channel keys to stream, either as a single key or array
355
- */
356
- get streamChannelsAsIs() {
357
- if (this.streamChannels) return this.streamChannels;
358
- else return Object.keys(this.channels);
359
- }
360
- /**
361
- * Gets a drawable representation of the graph structure.
362
- * This is an async version of getGraph() and is the preferred method to use.
363
- *
364
- * @param config - Configuration for generating the graph visualization
365
- * @returns A representation of the graph that can be visualized
366
- */
367
- async getGraphAsync(config) {
368
- return this.getGraph(config);
369
- }
370
- /**
371
- * Gets all subgraphs within this graph.
372
- * A subgraph is a Pregel instance that is nested within a node of this graph.
373
- *
374
- * @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release.
375
- * @param namespace - Optional namespace to filter subgraphs
376
- * @param recurse - Whether to recursively get subgraphs of subgraphs
377
- * @returns Generator yielding tuples of [name, subgraph]
378
- */
379
- *getSubgraphs(namespace, recurse) {
380
- for (const [name, node] of Object.entries(this.nodes)) {
381
- if (namespace !== void 0) {
382
- if (!namespace.startsWith(name)) continue;
383
- }
384
- const candidates = node.subgraphs?.length ? node.subgraphs : [node.bound];
385
- for (const candidate of candidates) {
386
- const graph = require_subgraph.findSubgraphPregel(candidate);
387
- if (graph !== void 0) {
388
- if (name === namespace) {
389
- yield [name, graph];
390
- return;
391
- }
392
- if (namespace === void 0) yield [name, graph];
393
- if (recurse) {
394
- let newNamespace = namespace;
395
- if (namespace !== void 0) newNamespace = namespace.slice(name.length + 1);
396
- for (const [subgraphName, subgraph] of graph.getSubgraphs(newNamespace, recurse)) yield [`${name}${require_constants.CHECKPOINT_NAMESPACE_SEPARATOR}${subgraphName}`, subgraph];
397
- }
398
- }
399
- }
400
- }
401
- }
402
- /**
403
- * Gets all subgraphs within this graph asynchronously.
404
- * A subgraph is a Pregel instance that is nested within a node of this graph.
405
- *
406
- * @param namespace - Optional namespace to filter subgraphs
407
- * @param recurse - Whether to recursively get subgraphs of subgraphs
408
- * @returns AsyncGenerator yielding tuples of [name, subgraph]
409
- */
410
- async *getSubgraphsAsync(namespace, recurse) {
411
- yield* this.getSubgraphs(namespace, recurse);
412
- }
413
- /**
414
- * Prepares a state snapshot from saved checkpoint data.
415
- * This is an internal method used by getState and getStateHistory.
416
- *
417
- * @param config - Configuration for preparing the snapshot
418
- * @param saved - Optional saved checkpoint data
419
- * @param subgraphCheckpointer - Optional checkpointer for subgraphs
420
- * @param applyPendingWrites - Whether to apply pending writes to tasks and then to channels
421
- * @returns A snapshot of the graph state
422
- * @internal
423
- */
424
- async _prepareStateSnapshot({ config, saved, subgraphCheckpointer, applyPendingWrites = false }) {
425
- if (saved === void 0) return {
426
- values: {},
427
- next: [],
428
- config,
429
- tasks: []
430
- };
431
- const channels = require_base.emptyChannels(this.channels, saved.checkpoint);
432
- if (saved.pendingWrites?.length) {
433
- const nullWrites = saved.pendingWrites.filter(([taskId, _]) => taskId === require_constants.NULL_TASK_ID).map(([_, channel, value]) => [String(channel), value]);
434
- if (nullWrites.length > 0) require_algo._applyWrites(saved.checkpoint, channels, [{
435
- name: require_constants.INPUT,
436
- writes: nullWrites,
437
- triggers: []
438
- }], void 0, this.triggerToNodes);
439
- }
440
- const nextTasks = Object.values(require_algo._prepareNextTasks(saved.checkpoint, saved.pendingWrites, this.nodes, channels, saved.config, true, {
441
- step: (saved.metadata?.step ?? -1) + 1,
442
- store: this.store
443
- }));
444
- const subgraphs = await require_utils.gatherIterator(this.getSubgraphsAsync());
445
- const parentNamespace = saved.config.configurable?.checkpoint_ns ?? "";
446
- const taskStates = {};
447
- for (const task of nextTasks) {
448
- const matchingSubgraph = subgraphs.find(([name]) => name === task.name);
449
- if (!matchingSubgraph) continue;
450
- let taskNs = `${String(task.name)}${require_constants.CHECKPOINT_NAMESPACE_END}${task.id}`;
451
- if (parentNamespace) taskNs = `${parentNamespace}${require_constants.CHECKPOINT_NAMESPACE_SEPARATOR}${taskNs}`;
452
- if (subgraphCheckpointer === void 0) {
453
- const config$1 = { configurable: {
454
- thread_id: saved.config.configurable?.thread_id,
455
- checkpoint_ns: taskNs
456
- } };
457
- taskStates[task.id] = config$1;
458
- } else {
459
- const subgraphConfig = { configurable: {
460
- [require_constants.CONFIG_KEY_CHECKPOINTER]: subgraphCheckpointer,
461
- thread_id: saved.config.configurable?.thread_id,
462
- checkpoint_ns: taskNs
463
- } };
464
- const pregel = matchingSubgraph[1];
465
- taskStates[task.id] = await pregel.getState(subgraphConfig, { subgraphs: true });
466
- }
467
- }
468
- if (applyPendingWrites && saved.pendingWrites?.length) {
469
- const nextTaskById = Object.fromEntries(nextTasks.map((task) => [task.id, task]));
470
- for (const [taskId, channel, value] of saved.pendingWrites) {
471
- if ([
472
- require_constants.ERROR,
473
- require_constants.INTERRUPT,
474
- __langchain_langgraph_checkpoint.SCHEDULED
475
- ].includes(channel)) continue;
476
- if (!(taskId in nextTaskById)) continue;
477
- nextTaskById[taskId].writes.push([String(channel), value]);
478
- }
479
- const tasksWithWrites$1 = nextTasks.filter((task) => task.writes.length > 0);
480
- if (tasksWithWrites$1.length > 0) require_algo._applyWrites(saved.checkpoint, channels, tasksWithWrites$1, void 0, this.triggerToNodes);
481
- }
482
- let metadata = saved?.metadata;
483
- if (metadata && saved?.config?.configurable?.thread_id) metadata = {
484
- ...metadata,
485
- thread_id: saved.config.configurable.thread_id
486
- };
487
- const nextList = nextTasks.filter((task) => task.writes.length === 0).map((task) => task.name);
488
- return {
489
- values: require_io.readChannels(channels, this.streamChannelsAsIs),
490
- next: nextList,
491
- tasks: require_debug.tasksWithWrites(nextTasks, saved?.pendingWrites ?? [], taskStates, this.streamChannelsAsIs),
492
- metadata,
493
- config: require_index.patchCheckpointMap(saved.config, saved.metadata),
494
- createdAt: saved.checkpoint.ts,
495
- parentConfig: saved.parentConfig
496
- };
497
- }
498
- /**
499
- * Gets the current state of the graph.
500
- * Requires a checkpointer to be configured.
501
- *
502
- * @param config - Configuration for retrieving the state
503
- * @param options - Additional options
504
- * @returns A snapshot of the current graph state
505
- * @throws {GraphValueError} If no checkpointer is configured
506
- */
507
- async getState(config, options) {
508
- const checkpointer = config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] ?? this.checkpointer;
509
- if (!checkpointer) throw new require_errors.GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
510
- const checkpointNamespace = config.configurable?.checkpoint_ns ?? "";
511
- if (checkpointNamespace !== "" && config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] === void 0) {
512
- const recastNamespace = require_config.recastCheckpointNamespace(checkpointNamespace);
513
- for await (const [name, subgraph] of this.getSubgraphsAsync(recastNamespace, true)) if (name === recastNamespace) return await subgraph.getState(require_utils.patchConfigurable(config, { [require_constants.CONFIG_KEY_CHECKPOINTER]: checkpointer }), { subgraphs: options?.subgraphs });
514
- throw new Error(`Subgraph with namespace "${recastNamespace}" not found.`);
515
- }
516
- const mergedConfig = (0, __langchain_core_runnables.mergeConfigs)(this.config, config);
517
- const saved = await checkpointer.getTuple(config);
518
- const snapshot = await this._prepareStateSnapshot({
519
- config: mergedConfig,
520
- saved,
521
- subgraphCheckpointer: options?.subgraphs ? checkpointer : void 0,
522
- applyPendingWrites: !config.configurable?.checkpoint_id
523
- });
524
- return snapshot;
525
- }
526
- /**
527
- * Gets the history of graph states.
528
- * Requires a checkpointer to be configured.
529
- * Useful for:
530
- * - Debugging execution history
531
- * - Implementing time travel
532
- * - Analyzing graph behavior
533
- *
534
- * @param config - Configuration for retrieving the history
535
- * @param options - Options for filtering the history
536
- * @returns An async iterator of state snapshots
537
- * @throws {Error} If no checkpointer is configured
538
- */
539
- async *getStateHistory(config, options) {
540
- const checkpointer = config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] ?? this.checkpointer;
541
- if (!checkpointer) throw new require_errors.GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
542
- const checkpointNamespace = config.configurable?.checkpoint_ns ?? "";
543
- if (checkpointNamespace !== "" && config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] === void 0) {
544
- const recastNamespace = require_config.recastCheckpointNamespace(checkpointNamespace);
545
- for await (const [name, pregel] of this.getSubgraphsAsync(recastNamespace, true)) if (name === recastNamespace) {
546
- yield* pregel.getStateHistory(require_utils.patchConfigurable(config, { [require_constants.CONFIG_KEY_CHECKPOINTER]: checkpointer }), options);
547
- return;
548
- }
549
- throw new Error(`Subgraph with namespace "${recastNamespace}" not found.`);
550
- }
551
- const mergedConfig = (0, __langchain_core_runnables.mergeConfigs)(this.config, config, { configurable: { checkpoint_ns: checkpointNamespace } });
552
- for await (const checkpointTuple of checkpointer.list(mergedConfig, options)) yield this._prepareStateSnapshot({
553
- config: checkpointTuple.config,
554
- saved: checkpointTuple
555
- });
556
- }
557
- /**
558
- * Apply updates to the graph state in bulk.
559
- * Requires a checkpointer to be configured.
560
- *
561
- * This method is useful for recreating a thread
562
- * from a list of updates, especially if a checkpoint
563
- * is created as a result of multiple tasks.
564
- *
565
- * @internal The API might change in the future.
566
- *
567
- * @param startConfig - Configuration for the update
568
- * @param updates - The list of updates to apply to graph state
569
- * @returns Updated configuration
570
- * @throws {GraphValueError} If no checkpointer is configured
571
- * @throws {InvalidUpdateError} If the update cannot be attributed to a node or an update can be only applied in sequence.
572
- */
573
- async bulkUpdateState(startConfig, supersteps) {
574
- const checkpointer = startConfig.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] ?? this.checkpointer;
575
- if (!checkpointer) throw new require_errors.GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
576
- if (supersteps.length === 0) throw new Error("No supersteps provided");
577
- if (supersteps.some((s) => s.updates.length === 0)) throw new Error("No updates provided");
578
- const checkpointNamespace = startConfig.configurable?.checkpoint_ns ?? "";
579
- if (checkpointNamespace !== "" && startConfig.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] === void 0) {
580
- const recastNamespace = require_config.recastCheckpointNamespace(checkpointNamespace);
581
- for await (const [, pregel] of this.getSubgraphsAsync(recastNamespace, true)) return await pregel.bulkUpdateState(require_utils.patchConfigurable(startConfig, { [require_constants.CONFIG_KEY_CHECKPOINTER]: checkpointer }), supersteps);
582
- throw new Error(`Subgraph "${recastNamespace}" not found`);
583
- }
584
- const updateSuperStep = async (inputConfig, updates) => {
585
- const config = this.config ? (0, __langchain_core_runnables.mergeConfigs)(this.config, inputConfig) : inputConfig;
586
- const saved = await checkpointer.getTuple(config);
587
- const checkpoint = saved !== void 0 ? (0, __langchain_langgraph_checkpoint.copyCheckpoint)(saved.checkpoint) : (0, __langchain_langgraph_checkpoint.emptyCheckpoint)();
588
- const checkpointPreviousVersions = { ...saved?.checkpoint.channel_versions };
589
- const step = saved?.metadata?.step ?? -1;
590
- let checkpointConfig = require_utils.patchConfigurable(config, { checkpoint_ns: config.configurable?.checkpoint_ns ?? "" });
591
- let checkpointMetadata = config.metadata ?? {};
592
- if (saved?.config.configurable) {
593
- checkpointConfig = require_utils.patchConfigurable(config, saved.config.configurable);
594
- checkpointMetadata = {
595
- ...saved.metadata,
596
- ...checkpointMetadata
597
- };
598
- }
599
- const { values, asNode } = updates[0];
600
- if (values == null && asNode === void 0) {
601
- if (updates.length > 1) throw new require_errors.InvalidUpdateError(`Cannot create empty checkpoint with multiple updates`);
602
- const nextConfig$1 = await checkpointer.put(checkpointConfig, require_base.createCheckpoint(checkpoint, void 0, step), {
603
- source: "update",
604
- step: step + 1,
605
- parents: saved?.metadata?.parents ?? {}
606
- }, {});
607
- return require_index.patchCheckpointMap(nextConfig$1, saved ? saved.metadata : void 0);
608
- }
609
- const channels = require_base.emptyChannels(this.channels, checkpoint);
610
- if (values === null && asNode === require_constants.END) {
611
- if (updates.length > 1) throw new require_errors.InvalidUpdateError(`Cannot apply multiple updates when clearing state`);
612
- if (saved) {
613
- const nextTasks = require_algo._prepareNextTasks(checkpoint, saved.pendingWrites || [], this.nodes, channels, saved.config, true, {
614
- step: (saved.metadata?.step ?? -1) + 1,
615
- checkpointer,
616
- store: this.store
617
- });
618
- const nullWrites = (saved.pendingWrites || []).filter((w) => w[0] === require_constants.NULL_TASK_ID).map((w) => w.slice(1));
619
- if (nullWrites.length > 0) require_algo._applyWrites(checkpoint, channels, [{
620
- name: require_constants.INPUT,
621
- writes: nullWrites,
622
- triggers: []
623
- }], checkpointer.getNextVersion.bind(checkpointer), this.triggerToNodes);
624
- for (const [taskId, k, v] of saved.pendingWrites || []) {
625
- if ([
626
- require_constants.ERROR,
627
- require_constants.INTERRUPT,
628
- __langchain_langgraph_checkpoint.SCHEDULED
629
- ].includes(k)) continue;
630
- if (!(taskId in nextTasks)) continue;
631
- nextTasks[taskId].writes.push([k, v]);
632
- }
633
- require_algo._applyWrites(checkpoint, channels, Object.values(nextTasks), checkpointer.getNextVersion.bind(checkpointer), this.triggerToNodes);
634
- }
635
- const nextConfig$1 = await checkpointer.put(checkpointConfig, require_base.createCheckpoint(checkpoint, channels, step), {
636
- ...checkpointMetadata,
637
- source: "update",
638
- step: step + 1,
639
- parents: saved?.metadata?.parents ?? {}
640
- }, require_index.getNewChannelVersions(checkpointPreviousVersions, checkpoint.channel_versions));
641
- return require_index.patchCheckpointMap(nextConfig$1, saved ? saved.metadata : void 0);
642
- }
643
- if (asNode === require_constants.COPY) {
644
- if (updates.length > 1) throw new require_errors.InvalidUpdateError(`Cannot copy checkpoint with multiple updates`);
645
- if (saved == null) throw new require_errors.InvalidUpdateError(`Cannot copy a non-existent checkpoint`);
646
- const isCopyWithUpdates = (values$1) => {
647
- if (!Array.isArray(values$1)) return false;
648
- if (values$1.length === 0) return false;
649
- return values$1.every((v) => Array.isArray(v) && v.length === 2);
650
- };
651
- const nextCheckpoint = require_base.createCheckpoint(checkpoint, void 0, step);
652
- const nextConfig$1 = await checkpointer.put(saved.parentConfig ?? require_utils.patchConfigurable(saved.config, { checkpoint_id: void 0 }), nextCheckpoint, {
653
- source: "fork",
654
- step: step + 1,
655
- parents: saved.metadata?.parents ?? {}
656
- }, {});
657
- if (isCopyWithUpdates(values)) {
658
- const nextTasks = require_algo._prepareNextTasks(nextCheckpoint, saved.pendingWrites, this.nodes, channels, nextConfig$1, false, { step: step + 2 });
659
- const tasksGroupBy = Object.values(nextTasks).reduce((acc, { name, id }) => {
660
- acc[name] ??= [];
661
- acc[name].push({ id });
662
- return acc;
663
- }, {});
664
- const userGroupBy = values.reduce((acc, item) => {
665
- const [values$1, asNode$1] = item;
666
- acc[asNode$1] ??= [];
667
- const targetIdx = acc[asNode$1].length;
668
- const taskId = tasksGroupBy[asNode$1]?.[targetIdx]?.id;
669
- acc[asNode$1].push({
670
- values: values$1,
671
- asNode: asNode$1,
672
- taskId
673
- });
674
- return acc;
675
- }, {});
676
- return updateSuperStep(require_index.patchCheckpointMap(nextConfig$1, saved.metadata), Object.values(userGroupBy).flat());
677
- }
678
- return require_index.patchCheckpointMap(nextConfig$1, saved.metadata);
679
- }
680
- if (asNode === require_constants.INPUT) {
681
- if (updates.length > 1) throw new require_errors.InvalidUpdateError(`Cannot apply multiple updates when updating as input`);
682
- const inputWrites = await require_utils.gatherIterator(require_io.mapInput(this.inputChannels, values));
683
- if (inputWrites.length === 0) throw new require_errors.InvalidUpdateError(`Received no input writes for ${JSON.stringify(this.inputChannels, null, 2)}`);
684
- require_algo._applyWrites(checkpoint, channels, [{
685
- name: require_constants.INPUT,
686
- writes: inputWrites,
687
- triggers: []
688
- }], checkpointer.getNextVersion.bind(this.checkpointer), this.triggerToNodes);
689
- const nextStep = saved?.metadata?.step != null ? saved.metadata.step + 1 : -1;
690
- const nextConfig$1 = await checkpointer.put(checkpointConfig, require_base.createCheckpoint(checkpoint, channels, nextStep), {
691
- source: "input",
692
- step: nextStep,
693
- parents: saved?.metadata?.parents ?? {}
694
- }, require_index.getNewChannelVersions(checkpointPreviousVersions, checkpoint.channel_versions));
695
- await checkpointer.putWrites(nextConfig$1, inputWrites, (0, __langchain_langgraph_checkpoint.uuid5)(require_constants.INPUT, checkpoint.id));
696
- return require_index.patchCheckpointMap(nextConfig$1, saved ? saved.metadata : void 0);
697
- }
698
- if (config.configurable?.checkpoint_id === void 0 && saved?.pendingWrites !== void 0 && saved.pendingWrites.length > 0) {
699
- const nextTasks = require_algo._prepareNextTasks(checkpoint, saved.pendingWrites, this.nodes, channels, saved.config, true, {
700
- store: this.store,
701
- checkpointer: this.checkpointer,
702
- step: (saved.metadata?.step ?? -1) + 1
703
- });
704
- const nullWrites = (saved.pendingWrites ?? []).filter((w) => w[0] === require_constants.NULL_TASK_ID).map((w) => w.slice(1));
705
- if (nullWrites.length > 0) require_algo._applyWrites(saved.checkpoint, channels, [{
706
- name: require_constants.INPUT,
707
- writes: nullWrites,
708
- triggers: []
709
- }], void 0, this.triggerToNodes);
710
- for (const [tid, k, v] of saved.pendingWrites) {
711
- if ([
712
- require_constants.ERROR,
713
- require_constants.INTERRUPT,
714
- __langchain_langgraph_checkpoint.SCHEDULED
715
- ].includes(k) || nextTasks[tid] === void 0) continue;
716
- nextTasks[tid].writes.push([k, v]);
717
- }
718
- const tasks$1 = Object.values(nextTasks).filter((task) => {
719
- return task.writes.length > 0;
720
- });
721
- if (tasks$1.length > 0) require_algo._applyWrites(checkpoint, channels, tasks$1, void 0, this.triggerToNodes);
722
- }
723
- const nonNullVersion = Object.values(checkpoint.versions_seen).map((seenVersions) => {
724
- return Object.values(seenVersions);
725
- }).flat().find((v) => !!v);
726
- const validUpdates = [];
727
- if (updates.length === 1) {
728
- let { values: values$1, asNode: asNode$1, taskId } = updates[0];
729
- if (asNode$1 === void 0 && Object.keys(this.nodes).length === 1) [asNode$1] = Object.keys(this.nodes);
730
- else if (asNode$1 === void 0 && nonNullVersion === void 0) {
731
- if (typeof this.inputChannels === "string" && this.nodes[this.inputChannels] !== void 0) asNode$1 = this.inputChannels;
732
- } else if (asNode$1 === void 0) {
733
- const lastSeenByNode = Object.entries(checkpoint.versions_seen).map(([n, seen]) => {
734
- return Object.values(seen).map((v) => {
735
- return [v, n];
736
- });
737
- }).flat().filter(([_, v]) => v !== require_constants.INTERRUPT).sort(([aNumber], [bNumber]) => (0, __langchain_langgraph_checkpoint.compareChannelVersions)(aNumber, bNumber));
738
- if (lastSeenByNode) {
739
- if (lastSeenByNode.length === 1) asNode$1 = lastSeenByNode[0][1];
740
- else if (lastSeenByNode[lastSeenByNode.length - 1][0] !== lastSeenByNode[lastSeenByNode.length - 2][0]) asNode$1 = lastSeenByNode[lastSeenByNode.length - 1][1];
741
- }
742
- }
743
- if (asNode$1 === void 0) throw new require_errors.InvalidUpdateError(`Ambiguous update, specify "asNode"`);
744
- validUpdates.push({
745
- values: values$1,
746
- asNode: asNode$1,
747
- taskId
748
- });
749
- } else for (const { asNode: asNode$1, values: values$1, taskId } of updates) {
750
- if (asNode$1 == null) throw new require_errors.InvalidUpdateError(`"asNode" is required when applying multiple updates`);
751
- validUpdates.push({
752
- values: values$1,
753
- asNode: asNode$1,
754
- taskId
755
- });
756
- }
757
- const tasks = [];
758
- for (const { asNode: asNode$1, values: values$1, taskId } of validUpdates) {
759
- if (this.nodes[asNode$1] === void 0) throw new require_errors.InvalidUpdateError(`Node "${asNode$1.toString()}" does not exist`);
760
- const writers = this.nodes[asNode$1].getWriters();
761
- if (!writers.length) throw new require_errors.InvalidUpdateError(`No writers found for node "${asNode$1.toString()}"`);
762
- tasks.push({
763
- name: asNode$1,
764
- input: values$1,
765
- proc: writers.length > 1 ? __langchain_core_runnables.RunnableSequence.from(writers, { omitSequenceTags: true }) : writers[0],
766
- writes: [],
767
- triggers: [require_constants.INTERRUPT],
768
- id: taskId ?? (0, __langchain_langgraph_checkpoint.uuid5)(require_constants.INTERRUPT, checkpoint.id),
769
- writers: []
770
- });
771
- }
772
- for (const task of tasks) await task.proc.invoke(task.input, (0, __langchain_core_runnables.patchConfig)({
773
- ...config,
774
- store: config?.store ?? this.store
775
- }, {
776
- runName: config.runName ?? `${this.getName()}UpdateState`,
777
- configurable: {
778
- [require_constants.CONFIG_KEY_SEND]: (items) => task.writes.push(...items),
779
- [require_constants.CONFIG_KEY_READ]: (select_, fresh_ = false) => require_algo._localRead(checkpoint, channels, task, select_, fresh_)
780
- }
781
- }));
782
- for (const task of tasks) {
783
- const channelWrites = task.writes.filter((w) => w[0] !== require_constants.PUSH);
784
- if (saved !== void 0 && channelWrites.length > 0) await checkpointer.putWrites(checkpointConfig, channelWrites, task.id);
785
- }
786
- require_algo._applyWrites(checkpoint, channels, tasks, checkpointer.getNextVersion.bind(this.checkpointer), this.triggerToNodes);
787
- const newVersions = require_index.getNewChannelVersions(checkpointPreviousVersions, checkpoint.channel_versions);
788
- const nextConfig = await checkpointer.put(checkpointConfig, require_base.createCheckpoint(checkpoint, channels, step + 1), {
789
- source: "update",
790
- step: step + 1,
791
- parents: saved?.metadata?.parents ?? {}
792
- }, newVersions);
793
- for (const task of tasks) {
794
- const pushWrites = task.writes.filter((w) => w[0] === require_constants.PUSH);
795
- if (pushWrites.length > 0) await checkpointer.putWrites(nextConfig, pushWrites, task.id);
796
- }
797
- return require_index.patchCheckpointMap(nextConfig, saved ? saved.metadata : void 0);
798
- };
799
- let currentConfig = startConfig;
800
- for (const { updates } of supersteps) currentConfig = await updateSuperStep(currentConfig, updates);
801
- return currentConfig;
802
- }
803
- /**
804
- * Updates the state of the graph with new values.
805
- * Requires a checkpointer to be configured.
806
- *
807
- * This method can be used for:
808
- * - Implementing human-in-the-loop workflows
809
- * - Modifying graph state during breakpoints
810
- * - Integrating external inputs into the graph
811
- *
812
- * @param inputConfig - Configuration for the update
813
- * @param values - The values to update the state with
814
- * @param asNode - Optional node name to attribute the update to
815
- * @returns Updated configuration
816
- * @throws {GraphValueError} If no checkpointer is configured
817
- * @throws {InvalidUpdateError} If the update cannot be attributed to a node
818
- */
819
- async updateState(inputConfig, values, asNode) {
820
- return this.bulkUpdateState(inputConfig, [{ updates: [{
821
- values,
822
- asNode
823
- }] }]);
824
- }
825
- /**
826
- * Gets the default values for various graph configuration options.
827
- * This is an internal method used to process and normalize configuration options.
828
- *
829
- * @param config - The input configuration options
830
- * @returns A tuple containing normalized values for:
831
- * - debug mode
832
- * - stream modes
833
- * - input keys
834
- * - output keys
835
- * - remaining config
836
- * - interrupt before nodes
837
- * - interrupt after nodes
838
- * - checkpointer
839
- * - store
840
- * - whether stream mode is single
841
- * - node cache
842
- * - whether checkpoint during is enabled
843
- * @internal
844
- */
845
- _defaults(config) {
846
- const { debug, streamMode, inputKeys, outputKeys, interruptAfter, interruptBefore,...rest } = config;
847
- let streamModeSingle = true;
848
- const defaultDebug = debug !== void 0 ? debug : this.debug;
849
- let defaultOutputKeys = outputKeys;
850
- if (defaultOutputKeys === void 0) defaultOutputKeys = this.streamChannelsAsIs;
851
- else require_validate.validateKeys(defaultOutputKeys, this.channels);
852
- let defaultInputKeys = inputKeys;
853
- if (defaultInputKeys === void 0) defaultInputKeys = this.inputChannels;
854
- else require_validate.validateKeys(defaultInputKeys, this.channels);
855
- const defaultInterruptBefore = interruptBefore ?? this.interruptBefore ?? [];
856
- const defaultInterruptAfter = interruptAfter ?? this.interruptAfter ?? [];
857
- let defaultStreamMode;
858
- if (streamMode !== void 0) {
859
- defaultStreamMode = Array.isArray(streamMode) ? streamMode : [streamMode];
860
- streamModeSingle = typeof streamMode === "string";
861
- } else {
862
- if (config.configurable?.[require_constants.CONFIG_KEY_TASK_ID] !== void 0) defaultStreamMode = ["values"];
863
- else defaultStreamMode = this.streamMode;
864
- streamModeSingle = true;
865
- }
866
- let defaultCheckpointer;
867
- if (this.checkpointer === false) defaultCheckpointer = void 0;
868
- else if (config !== void 0 && config.configurable?.[require_constants.CONFIG_KEY_CHECKPOINTER] !== void 0) defaultCheckpointer = config.configurable[require_constants.CONFIG_KEY_CHECKPOINTER];
869
- else if (this.checkpointer === true) throw new Error("checkpointer: true cannot be used for root graphs.");
870
- else defaultCheckpointer = this.checkpointer;
871
- const defaultStore = config.store ?? this.store;
872
- const defaultCache = config.cache ?? this.cache;
873
- if (config.durability != null && config.checkpointDuring != null) throw new Error("Cannot use both `durability` and `checkpointDuring` at the same time.");
874
- const checkpointDuringDurability = (() => {
875
- if (config.checkpointDuring == null) return void 0;
876
- if (config.checkpointDuring === false) return "exit";
877
- return "async";
878
- })();
879
- const defaultDurability = config.durability ?? checkpointDuringDurability ?? config?.configurable?.[require_constants.CONFIG_KEY_DURABILITY] ?? "async";
880
- return [
881
- defaultDebug,
882
- defaultStreamMode,
883
- defaultInputKeys,
884
- defaultOutputKeys,
885
- rest,
886
- defaultInterruptBefore,
887
- defaultInterruptAfter,
888
- defaultCheckpointer,
889
- defaultStore,
890
- streamModeSingle,
891
- defaultCache,
892
- defaultDurability
893
- ];
894
- }
895
- /**
896
- * Streams the execution of the graph, emitting state updates as they occur.
897
- * This is the primary method for observing graph execution in real-time.
898
- *
899
- * Stream modes:
900
- * - "values": Emits complete state after each step
901
- * - "updates": Emits only state changes after each step
902
- * - "debug": Emits detailed debug information
903
- * - "messages": Emits messages from within nodes
904
- * - "custom": Emits custom events from within nodes
905
- * - "checkpoints": Emits checkpoints from within nodes
906
- * - "tasks": Emits tasks from within nodes
907
- *
908
- * @param input - The input to start graph execution with
909
- * @param options - Configuration options for streaming
910
- * @returns An async iterable stream of graph state updates
911
- */
912
- async stream(input, options) {
913
- const abortController = new AbortController();
914
- const config = {
915
- recursionLimit: this.config?.recursionLimit,
916
- ...options,
917
- signal: require_index.combineAbortSignals(options?.signal, abortController.signal).signal
918
- };
919
- const stream = await super.stream(input, config);
920
- return new require_stream.IterableReadableStreamWithAbortSignal(options?.encoding === "text/event-stream" ? require_stream.toEventStream(stream) : stream, abortController);
921
- }
922
- streamEvents(input, options, streamOptions) {
923
- const abortController = new AbortController();
924
- const config = {
925
- recursionLimit: this.config?.recursionLimit,
926
- ...options,
927
- callbacks: require_index.combineCallbacks(this.config?.callbacks, options?.callbacks),
928
- signal: require_index.combineAbortSignals(options?.signal, abortController.signal).signal
929
- };
930
- return new require_stream.IterableReadableStreamWithAbortSignal(super.streamEvents(input, config, streamOptions), abortController);
931
- }
932
- /**
933
- * Validates the input for the graph.
934
- * @param input - The input to validate
935
- * @returns The validated input
936
- * @internal
937
- */
938
- async _validateInput(input) {
939
- return input;
940
- }
941
- /**
942
- * Validates the context options for the graph.
943
- * @param context - The context options to validate
944
- * @returns The validated context options
945
- * @internal
946
- */
947
- async _validateContext(context) {
948
- return context;
949
- }
950
- /**
951
- * Internal iterator used by stream() to generate state updates.
952
- * This method handles the core logic of graph execution and streaming.
953
- *
954
- * @param input - The input to start graph execution with
955
- * @param options - Configuration options for streaming
956
- * @returns AsyncGenerator yielding state updates
957
- * @internal
958
- */
959
- async *_streamIterator(input, options) {
960
- const streamEncoding = "version" in (options ?? {}) ? void 0 : options?.encoding ?? void 0;
961
- const streamSubgraphs = options?.subgraphs;
962
- const inputConfig = require_config.ensureLangGraphConfig(this.config, options);
963
- if (inputConfig.recursionLimit === void 0 || inputConfig.recursionLimit < 1) throw new Error(`Passed "recursionLimit" must be at least 1.`);
964
- if (this.checkpointer !== void 0 && this.checkpointer !== false && inputConfig.configurable === void 0) throw new Error(`Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"`);
965
- const validInput = await this._validateInput(input);
966
- const { runId,...restConfig } = inputConfig;
967
- const [debug, streamMode, , outputKeys, config, interruptBefore, interruptAfter, checkpointer, store, streamModeSingle, cache, durability] = this._defaults(restConfig);
968
- if (typeof config.context !== "undefined") config.context = await this._validateContext(config.context);
969
- else config.configurable = await this._validateContext(config.configurable);
970
- const stream = new require_stream.IterableReadableWritableStream({ modes: new Set(streamMode) });
971
- if (this.checkpointer === true) {
972
- config.configurable ??= {};
973
- const ns = config.configurable[require_constants.CONFIG_KEY_CHECKPOINT_NS] ?? "";
974
- config.configurable[require_constants.CONFIG_KEY_CHECKPOINT_NS] = ns.split(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR).map((part) => part.split(require_constants.CHECKPOINT_NAMESPACE_END)[0]).join(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR);
975
- }
976
- if (streamMode.includes("messages")) {
977
- const messageStreamer = new require_messages.StreamMessagesHandler((chunk) => stream.push(chunk));
978
- const { callbacks } = config;
979
- if (callbacks === void 0) config.callbacks = [messageStreamer];
980
- else if (Array.isArray(callbacks)) config.callbacks = callbacks.concat(messageStreamer);
981
- else {
982
- const copiedCallbacks = callbacks.copy();
983
- copiedCallbacks.addHandler(messageStreamer, true);
984
- config.callbacks = copiedCallbacks;
985
- }
986
- }
987
- config.writer ??= (chunk) => {
988
- if (!streamMode.includes("custom")) return;
989
- const ns = (require_config.getConfig()?.configurable?.[require_constants.CONFIG_KEY_CHECKPOINT_NS])?.split(require_constants.CHECKPOINT_NAMESPACE_SEPARATOR).slice(0, -1);
990
- stream.push([
991
- ns ?? [],
992
- "custom",
993
- chunk
994
- ]);
995
- };
996
- config.interrupt ??= this.userInterrupt ?? require_interrupt.interrupt;
997
- const callbackManager = await (0, __langchain_core_runnables.getCallbackManagerForConfig)(config);
998
- const runManager = await callbackManager?.handleChainStart(this.toJSON(), require_index._coerceToDict(input, "input"), runId, void 0, void 0, void 0, config?.runName ?? this.getName());
999
- const channelSpecs = require_base.getOnlyChannels(this.channels);
1000
- let loop;
1001
- let loopError;
1002
- /**
1003
- * The PregelLoop will yield events from concurrent tasks as soon as they are
1004
- * generated. Each task can push multiple events onto the stream in any order.
1005
- *
1006
- * We use a separate background method and stream here in order to yield events
1007
- * from the loop to the main stream and therefore back to the user as soon as
1008
- * they are available.
1009
- */
1010
- const createAndRunLoop = async () => {
1011
- try {
1012
- loop = await require_loop.PregelLoop.initialize({
1013
- input: validInput,
1014
- config,
1015
- checkpointer,
1016
- nodes: this.nodes,
1017
- channelSpecs,
1018
- outputKeys,
1019
- streamKeys: this.streamChannelsAsIs,
1020
- store,
1021
- cache,
1022
- stream,
1023
- interruptAfter,
1024
- interruptBefore,
1025
- manager: runManager,
1026
- debug: this.debug,
1027
- triggerToNodes: this.triggerToNodes,
1028
- durability
1029
- });
1030
- const runner = new require_runner.PregelRunner({
1031
- loop,
1032
- nodeFinished: config.configurable?.[require_constants.CONFIG_KEY_NODE_FINISHED]
1033
- });
1034
- if (options?.subgraphs) loop.config.configurable = {
1035
- ...loop.config.configurable,
1036
- [require_constants.CONFIG_KEY_STREAM]: loop.stream
1037
- };
1038
- await this._runLoop({
1039
- loop,
1040
- runner,
1041
- debug,
1042
- config
1043
- });
1044
- if (durability === "sync") await Promise.all(loop?.checkpointerPromises ?? []);
1045
- } catch (e) {
1046
- loopError = e;
1047
- } finally {
1048
- try {
1049
- if (loop) {
1050
- await loop.store?.stop();
1051
- await loop.cache?.stop();
1052
- }
1053
- await Promise.all(loop?.checkpointerPromises ?? []);
1054
- } catch (e) {
1055
- loopError = loopError ?? e;
1056
- }
1057
- if (loopError) stream.error(loopError);
1058
- else stream.close();
1059
- }
1060
- };
1061
- const runLoopPromise = createAndRunLoop();
1062
- try {
1063
- for await (const chunk of stream) {
1064
- if (chunk === void 0) throw new Error("Data structure error.");
1065
- const [namespace, mode, payload] = chunk;
1066
- if (streamMode.includes(mode)) {
1067
- if (streamEncoding === "text/event-stream") {
1068
- if (streamSubgraphs) yield [
1069
- namespace,
1070
- mode,
1071
- payload
1072
- ];
1073
- else yield [
1074
- null,
1075
- mode,
1076
- payload
1077
- ];
1078
- continue;
1079
- }
1080
- if (streamSubgraphs && !streamModeSingle) yield [
1081
- namespace,
1082
- mode,
1083
- payload
1084
- ];
1085
- else if (!streamModeSingle) yield [mode, payload];
1086
- else if (streamSubgraphs) yield [namespace, payload];
1087
- else yield payload;
1088
- }
1089
- }
1090
- } catch (e) {
1091
- await runManager?.handleChainError(loopError);
1092
- throw e;
1093
- } finally {
1094
- await runLoopPromise;
1095
- }
1096
- await runManager?.handleChainEnd(loop?.output ?? {}, runId, void 0, void 0, void 0);
1097
- }
1098
- /**
1099
- * Run the graph with a single input and config.
1100
- * @param input The input to the graph.
1101
- * @param options The configuration to use for the run.
1102
- */
1103
- async invoke(input, options) {
1104
- const streamMode = options?.streamMode ?? "values";
1105
- const config = {
1106
- ...options,
1107
- outputKeys: options?.outputKeys ?? this.outputChannels,
1108
- streamMode,
1109
- encoding: void 0
1110
- };
1111
- const chunks = [];
1112
- const stream = await this.stream(input, config);
1113
- const interruptChunks = [];
1114
- let latest;
1115
- for await (const chunk of stream) if (streamMode === "values") if (require_constants.isInterrupted(chunk)) interruptChunks.push(chunk[require_constants.INTERRUPT]);
1116
- else latest = chunk;
1117
- else chunks.push(chunk);
1118
- if (streamMode === "values") {
1119
- if (interruptChunks.length > 0) {
1120
- const interrupts = interruptChunks.flat(1);
1121
- if (latest == null) return { [require_constants.INTERRUPT]: interrupts };
1122
- if (typeof latest === "object") return {
1123
- ...latest,
1124
- [require_constants.INTERRUPT]: interrupts
1125
- };
1126
- }
1127
- return latest;
1128
- }
1129
- return chunks;
1130
- }
1131
- async _runLoop(params) {
1132
- const { loop, runner, debug, config } = params;
1133
- let tickError;
1134
- try {
1135
- while (await loop.tick({ inputKeys: this.inputChannels })) {
1136
- for (const { task } of await loop._matchCachedWrites()) loop._outputWrites(task.id, task.writes, true);
1137
- if (debug) require_debug.printStepCheckpoint(loop.checkpointMetadata.step, loop.channels, this.streamChannelsList);
1138
- if (debug) require_debug.printStepTasks(loop.step, Object.values(loop.tasks));
1139
- await runner.tick({
1140
- timeout: this.stepTimeout,
1141
- retryPolicy: this.retryPolicy,
1142
- onStepWrite: (step, writes) => {
1143
- if (debug) require_debug.printStepWrites(step, writes, this.streamChannelsList);
1144
- },
1145
- maxConcurrency: config.maxConcurrency,
1146
- signal: config.signal
1147
- });
1148
- }
1149
- if (loop.status === "out_of_steps") throw new require_errors.GraphRecursionError([
1150
- `Recursion limit of ${config.recursionLimit} reached`,
1151
- "without hitting a stop condition. You can increase the",
1152
- `limit by setting the "recursionLimit" config key.`
1153
- ].join(" "), { lc_error_code: "GRAPH_RECURSION_LIMIT" });
1154
- } catch (e) {
1155
- tickError = e;
1156
- const suppress = await loop.finishAndHandleError(tickError);
1157
- if (!suppress) throw e;
1158
- } finally {
1159
- if (tickError === void 0) await loop.finishAndHandleError();
1160
- }
1161
- }
1162
- async clearCache() {
1163
- await this.cache?.clear([]);
1164
- }
1165
- };
1166
-
1167
- //#endregion
1168
- exports.Channel = Channel;
1169
- exports.Pregel = Pregel;
1170
- //# sourceMappingURL=index.cjs.map