@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,801 +1,500 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompiledStateGraph = exports.StateGraph = void 0;
4
- exports.typedNode = typedNode;
5
- /* eslint-disable @typescript-eslint/no-use-before-define */
6
- const runnables_1 = require("@langchain/core/runnables");
7
- const types_1 = require("@langchain/core/utils/types");
8
- const base_js_1 = require("../channels/base.cjs");
9
- const graph_js_1 = require("./graph.cjs");
10
- const write_js_1 = require("../pregel/write.cjs");
11
- const read_js_1 = require("../pregel/read.cjs");
12
- const named_barrier_value_js_1 = require("../channels/named_barrier_value.cjs");
13
- const ephemeral_value_js_1 = require("../channels/ephemeral_value.cjs");
14
- const utils_js_1 = require("../utils.cjs");
15
- const constants_js_1 = require("../constants.cjs");
16
- const errors_js_1 = require("../errors.cjs");
17
- const annotation_js_1 = require("./annotation.cjs");
18
- const subgraph_js_1 = require("../pregel/utils/subgraph.cjs");
19
- const last_value_js_1 = require("../channels/last_value.cjs");
20
- const meta_js_1 = require("./zod/meta.cjs");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('../errors.cjs');
3
+ const require_base = require('../channels/base.cjs');
4
+ const require_last_value = require('../channels/last_value.cjs');
5
+ const require_annotation = require('./annotation.cjs');
6
+ const require_constants = require('../constants.cjs');
7
+ const require_utils = require('../utils.cjs');
8
+ const require_write = require('../pregel/write.cjs');
9
+ const require_read = require('../pregel/read.cjs');
10
+ const require_subgraph = require('../pregel/utils/subgraph.cjs');
11
+ const require_ephemeral_value = require('../channels/ephemeral_value.cjs');
12
+ const require_graph = require('./graph.cjs');
13
+ const require_named_barrier_value = require('../channels/named_barrier_value.cjs');
14
+ const require_meta = require('./zod/meta.cjs');
15
+ const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
16
+ const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
17
+
18
+ //#region src/graph/state.ts
21
19
  const ROOT = "__root__";
22
20
  const PartialStateSchema = Symbol.for("langgraph.state.partial");
23
21
  /**
24
- * A graph whose nodes communicate by reading and writing to a shared state.
25
- * Each node takes a defined `State` as input and returns a `Partial<State>`.
26
- *
27
- * Each state key can optionally be annotated with a reducer function that
28
- * will be used to aggregate the values of that key received from multiple nodes.
29
- * The signature of a reducer function is (left: Value, right: UpdateValue) => Value.
30
- *
31
- * See {@link Annotation} for more on defining state.
32
- *
33
- * After adding nodes and edges to your graph, you must call `.compile()` on it before
34
- * you can use it.
35
- *
36
- * @example
37
- * ```ts
38
- * import {
39
- * type BaseMessage,
40
- * AIMessage,
41
- * HumanMessage,
42
- * } from "@langchain/core/messages";
43
- * import { StateGraph, Annotation } from "@langchain/langgraph";
44
- *
45
- * // Define a state with a single key named "messages" that will
46
- * // combine a returned BaseMessage or arrays of BaseMessages
47
- * const StateAnnotation = Annotation.Root({
48
- * sentiment: Annotation<string>,
49
- * messages: Annotation<BaseMessage[]>({
50
- * reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {
51
- * if (Array.isArray(right)) {
52
- * return left.concat(right);
53
- * }
54
- * return left.concat([right]);
55
- * },
56
- * default: () => [],
57
- * }),
58
- * });
59
- *
60
- * const graphBuilder = new StateGraph(StateAnnotation);
61
- *
62
- * // A node in the graph that returns an object with a "messages" key
63
- * // will update the state by combining the existing value with the returned one.
64
- * const myNode = (state: typeof StateAnnotation.State) => {
65
- * return {
66
- * messages: [new AIMessage("Some new response")],
67
- * sentiment: "positive",
68
- * };
69
- * };
70
- *
71
- * const graph = graphBuilder
72
- * .addNode("myNode", myNode)
73
- * .addEdge("__start__", "myNode")
74
- * .addEdge("myNode", "__end__")
75
- * .compile();
76
- *
77
- * await graph.invoke({ messages: [new HumanMessage("how are you?")] });
78
- *
79
- * // {
80
- * // messages: [HumanMessage("how are you?"), AIMessage("Some new response")],
81
- * // sentiment: "positive",
82
- * // }
83
- * ```
84
- */
85
- class StateGraph extends graph_js_1.Graph {
86
- constructor(fields, contextSchema) {
87
- super();
88
- Object.defineProperty(this, "channels", {
89
- enumerable: true,
90
- configurable: true,
91
- writable: true,
92
- value: {}
93
- });
94
- // TODO: this doesn't dedupe edges as in py, so worth fixing at some point
95
- Object.defineProperty(this, "waitingEdges", {
96
- enumerable: true,
97
- configurable: true,
98
- writable: true,
99
- value: new Set()
100
- });
101
- /** @internal */
102
- Object.defineProperty(this, "_schemaDefinition", {
103
- enumerable: true,
104
- configurable: true,
105
- writable: true,
106
- value: void 0
107
- });
108
- /** @internal */
109
- Object.defineProperty(this, "_schemaRuntimeDefinition", {
110
- enumerable: true,
111
- configurable: true,
112
- writable: true,
113
- value: void 0
114
- });
115
- /** @internal */
116
- Object.defineProperty(this, "_inputDefinition", {
117
- enumerable: true,
118
- configurable: true,
119
- writable: true,
120
- value: void 0
121
- });
122
- /** @internal */
123
- Object.defineProperty(this, "_inputRuntimeDefinition", {
124
- enumerable: true,
125
- configurable: true,
126
- writable: true,
127
- value: void 0
128
- });
129
- /** @internal */
130
- Object.defineProperty(this, "_outputDefinition", {
131
- enumerable: true,
132
- configurable: true,
133
- writable: true,
134
- value: void 0
135
- });
136
- /** @internal */
137
- Object.defineProperty(this, "_outputRuntimeDefinition", {
138
- enumerable: true,
139
- configurable: true,
140
- writable: true,
141
- value: void 0
142
- });
143
- /**
144
- * Map schemas to managed values
145
- * @internal
146
- */
147
- Object.defineProperty(this, "_schemaDefinitions", {
148
- enumerable: true,
149
- configurable: true,
150
- writable: true,
151
- value: new Map()
152
- });
153
- /** @internal */
154
- Object.defineProperty(this, "_metaRegistry", {
155
- enumerable: true,
156
- configurable: true,
157
- writable: true,
158
- value: meta_js_1.schemaMetaRegistry
159
- });
160
- /** @internal Used only for typing. */
161
- Object.defineProperty(this, "_configSchema", {
162
- enumerable: true,
163
- configurable: true,
164
- writable: true,
165
- value: void 0
166
- });
167
- /** @internal */
168
- Object.defineProperty(this, "_configRuntimeSchema", {
169
- enumerable: true,
170
- configurable: true,
171
- writable: true,
172
- value: void 0
173
- });
174
- if (isZodStateGraphArgsWithStateSchema(fields)) {
175
- const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);
176
- const inputDef = fields.input != null
177
- ? this._metaRegistry.getChannelsForSchema(fields.input)
178
- : stateDef;
179
- const outputDef = fields.output != null
180
- ? this._metaRegistry.getChannelsForSchema(fields.output)
181
- : stateDef;
182
- this._schemaDefinition = stateDef;
183
- this._schemaRuntimeDefinition = fields.state;
184
- this._inputDefinition = inputDef;
185
- this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;
186
- this._outputDefinition = outputDef;
187
- this._outputRuntimeDefinition = fields.output ?? fields.state;
188
- }
189
- else if ((0, types_1.isInteropZodObject)(fields)) {
190
- const stateDef = this._metaRegistry.getChannelsForSchema(fields);
191
- this._schemaDefinition = stateDef;
192
- this._schemaRuntimeDefinition = fields;
193
- this._inputDefinition = stateDef;
194
- this._inputRuntimeDefinition = PartialStateSchema;
195
- this._outputDefinition = stateDef;
196
- this._outputRuntimeDefinition = fields;
197
- }
198
- else if (isStateGraphArgsWithInputOutputSchemas(fields)) {
199
- this._schemaDefinition = fields.input.spec;
200
- this._inputDefinition = fields.input.spec;
201
- this._outputDefinition = fields.output.spec;
202
- }
203
- else if (isStateGraphArgsWithStateSchema(fields)) {
204
- this._schemaDefinition = fields.stateSchema.spec;
205
- this._inputDefinition = (fields.input?.spec ??
206
- this._schemaDefinition);
207
- this._outputDefinition = (fields.output?.spec ??
208
- this._schemaDefinition);
209
- }
210
- else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {
211
- const spec = isAnnotationRoot(fields) ? fields.spec : fields;
212
- this._schemaDefinition = spec;
213
- }
214
- else if (isStateGraphArgs(fields)) {
215
- const spec = _getChannels(fields.channels);
216
- this._schemaDefinition = spec;
217
- }
218
- else {
219
- throw new Error("Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.");
220
- }
221
- this._inputDefinition ??= this._schemaDefinition;
222
- this._outputDefinition ??= this._schemaDefinition;
223
- this._addSchema(this._schemaDefinition);
224
- this._addSchema(this._inputDefinition);
225
- this._addSchema(this._outputDefinition);
226
- if ((0, types_1.isInteropZodObject)(contextSchema)) {
227
- this._configRuntimeSchema = contextSchema;
228
- }
229
- }
230
- get allEdges() {
231
- return new Set([
232
- ...this.edges,
233
- ...Array.from(this.waitingEdges).flatMap(([starts, end]) => starts.map((start) => [start, end])),
234
- ]);
235
- }
236
- _addSchema(stateDefinition) {
237
- if (this._schemaDefinitions.has(stateDefinition)) {
238
- return;
239
- }
240
- // TODO: Support managed values
241
- this._schemaDefinitions.set(stateDefinition, stateDefinition);
242
- for (const [key, val] of Object.entries(stateDefinition)) {
243
- let channel;
244
- if (typeof val === "function") {
245
- channel = val();
246
- }
247
- else {
248
- channel = val;
249
- }
250
- if (this.channels[key] !== undefined) {
251
- if (this.channels[key] !== channel) {
252
- if (channel.lc_graph_name !== "LastValue") {
253
- throw new Error(`Channel "${key}" already exists with a different type.`);
254
- }
255
- }
256
- }
257
- else {
258
- this.channels[key] = channel;
259
- }
260
- }
261
- }
262
- addNode(...args) {
263
- function isMultipleNodes(args) {
264
- return args.length >= 1 && typeof args[0] !== "string";
265
- }
266
- const nodes = (isMultipleNodes(args) // eslint-disable-line no-nested-ternary
267
- ? Array.isArray(args[0])
268
- ? args[0]
269
- : Object.entries(args[0]).map(([key, action]) => [
270
- key,
271
- action,
272
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
- action[Symbol.for("langgraph.state.node")] ?? undefined,
274
- ])
275
- : [[args[0], args[1], args[2]]]);
276
- if (nodes.length === 0) {
277
- throw new Error("No nodes provided in `addNode`");
278
- }
279
- for (const [key, action, options] of nodes) {
280
- if (key in this.channels) {
281
- throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
282
- }
283
- for (const reservedChar of [
284
- constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
285
- constants_js_1.CHECKPOINT_NAMESPACE_END,
286
- ]) {
287
- if (key.includes(reservedChar)) {
288
- throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
289
- }
290
- }
291
- this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
292
- if (key in this.nodes) {
293
- throw new Error(`Node \`${key}\` already present.`);
294
- }
295
- if (key === constants_js_1.END || key === constants_js_1.START) {
296
- throw new Error(`Node \`${key}\` is reserved.`);
297
- }
298
- let inputSpec = this._schemaDefinition;
299
- if (options?.input !== undefined) {
300
- if ((0, types_1.isInteropZodObject)(options.input)) {
301
- inputSpec = this._metaRegistry.getChannelsForSchema(options.input);
302
- }
303
- else if (options.input.spec !== undefined) {
304
- inputSpec = options.input.spec;
305
- }
306
- }
307
- if (inputSpec !== undefined) {
308
- this._addSchema(inputSpec);
309
- }
310
- let runnable;
311
- if (runnables_1.Runnable.isRunnable(action)) {
312
- runnable = action;
313
- }
314
- else if (typeof action === "function") {
315
- runnable = new utils_js_1.RunnableCallable({
316
- func: action,
317
- name: key,
318
- trace: false,
319
- });
320
- }
321
- else {
322
- runnable = (0, runnables_1._coerceToRunnable)(action);
323
- }
324
- let cachePolicy = options?.cachePolicy;
325
- if (typeof cachePolicy === "boolean") {
326
- cachePolicy = cachePolicy ? {} : undefined;
327
- }
328
- const nodeSpec = {
329
- runnable: runnable,
330
- retryPolicy: options?.retryPolicy,
331
- cachePolicy,
332
- metadata: options?.metadata,
333
- input: inputSpec ?? this._schemaDefinition,
334
- subgraphs: (0, subgraph_js_1.isPregelLike)(runnable)
335
- ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
336
- [runnable]
337
- : options?.subgraphs,
338
- ends: options?.ends,
339
- defer: options?.defer,
340
- };
341
- this.nodes[key] = nodeSpec;
342
- }
343
- return this;
344
- }
345
- addEdge(startKey, endKey) {
346
- if (typeof startKey === "string") {
347
- return super.addEdge(startKey, endKey);
348
- }
349
- if (this.compiled) {
350
- console.warn("Adding an edge to a graph that has already been compiled. This will " +
351
- "not be reflected in the compiled graph.");
352
- }
353
- for (const start of startKey) {
354
- if (start === constants_js_1.END) {
355
- throw new Error("END cannot be a start node");
356
- }
357
- if (!Object.keys(this.nodes).some((node) => node === start)) {
358
- throw new Error(`Need to add a node named "${start}" first`);
359
- }
360
- }
361
- if (endKey === constants_js_1.END) {
362
- throw new Error("END cannot be an end node");
363
- }
364
- if (!Object.keys(this.nodes).some((node) => node === endKey)) {
365
- throw new Error(`Need to add a node named "${endKey}" first`);
366
- }
367
- this.waitingEdges.add([startKey, endKey]);
368
- return this;
369
- }
370
- addSequence(nodes) {
371
- const parsedNodes = Array.isArray(nodes)
372
- ? nodes
373
- : Object.entries(nodes).map(([key, action]) => [
374
- key,
375
- action,
376
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
377
- action[Symbol.for("langgraph.state.node")] ?? undefined,
378
- ]);
379
- if (parsedNodes.length === 0) {
380
- throw new Error("Sequence requires at least one node.");
381
- }
382
- let previousNode;
383
- for (const [key, action, options] of parsedNodes) {
384
- if (key in this.nodes) {
385
- throw new Error(`Node names must be unique: node with the name "${key}" already exists.`);
386
- }
387
- const validKey = key;
388
- this.addNode(validKey, action, options);
389
- if (previousNode != null) {
390
- this.addEdge(previousNode, validKey);
391
- }
392
- previousNode = validKey;
393
- }
394
- return this;
395
- }
396
- compile({ checkpointer, store, cache, interruptBefore, interruptAfter, name, description, } = {}) {
397
- // validate the graph
398
- this.validate([
399
- ...(Array.isArray(interruptBefore) ? interruptBefore : []),
400
- ...(Array.isArray(interruptAfter) ? interruptAfter : []),
401
- ]);
402
- // prepare output channels
403
- const outputKeys = Object.keys(this._schemaDefinitions.get(this._outputDefinition));
404
- const outputChannels = outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;
405
- const streamKeys = Object.keys(this.channels);
406
- const streamChannels = streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;
407
- // create empty compiled graph
408
- const compiled = new CompiledStateGraph({
409
- builder: this,
410
- checkpointer,
411
- interruptAfter,
412
- interruptBefore,
413
- autoValidate: false,
414
- nodes: {},
415
- channels: {
416
- ...this.channels,
417
- [constants_js_1.START]: new ephemeral_value_js_1.EphemeralValue(),
418
- },
419
- inputChannels: constants_js_1.START,
420
- outputChannels,
421
- streamChannels,
422
- streamMode: "updates",
423
- store,
424
- cache,
425
- name,
426
- description,
427
- });
428
- // attach nodes, edges and branches
429
- compiled.attachNode(constants_js_1.START);
430
- for (const [key, node] of Object.entries(this.nodes)) {
431
- compiled.attachNode(key, node);
432
- }
433
- compiled.attachBranch(constants_js_1.START, constants_js_1.SELF, _getControlBranch(), {
434
- withReader: false,
435
- });
436
- for (const [key] of Object.entries(this.nodes)) {
437
- compiled.attachBranch(key, constants_js_1.SELF, _getControlBranch(), {
438
- withReader: false,
439
- });
440
- }
441
- for (const [start, end] of this.edges) {
442
- compiled.attachEdge(start, end);
443
- }
444
- for (const [starts, end] of this.waitingEdges) {
445
- compiled.attachEdge(starts, end);
446
- }
447
- for (const [start, branches] of Object.entries(this.branches)) {
448
- for (const [name, branch] of Object.entries(branches)) {
449
- compiled.attachBranch(start, name, branch);
450
- }
451
- }
452
- return compiled.validate();
453
- }
454
- }
455
- exports.StateGraph = StateGraph;
22
+ * A graph whose nodes communicate by reading and writing to a shared state.
23
+ * Each node takes a defined `State` as input and returns a `Partial<State>`.
24
+ *
25
+ * Each state key can optionally be annotated with a reducer function that
26
+ * will be used to aggregate the values of that key received from multiple nodes.
27
+ * The signature of a reducer function is (left: Value, right: UpdateValue) => Value.
28
+ *
29
+ * See {@link Annotation} for more on defining state.
30
+ *
31
+ * After adding nodes and edges to your graph, you must call `.compile()` on it before
32
+ * you can use it.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import {
37
+ * type BaseMessage,
38
+ * AIMessage,
39
+ * HumanMessage,
40
+ * } from "@langchain/core/messages";
41
+ * import { StateGraph, Annotation } from "@langchain/langgraph";
42
+ *
43
+ * // Define a state with a single key named "messages" that will
44
+ * // combine a returned BaseMessage or arrays of BaseMessages
45
+ * const StateAnnotation = Annotation.Root({
46
+ * sentiment: Annotation<string>,
47
+ * messages: Annotation<BaseMessage[]>({
48
+ * reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {
49
+ * if (Array.isArray(right)) {
50
+ * return left.concat(right);
51
+ * }
52
+ * return left.concat([right]);
53
+ * },
54
+ * default: () => [],
55
+ * }),
56
+ * });
57
+ *
58
+ * const graphBuilder = new StateGraph(StateAnnotation);
59
+ *
60
+ * // A node in the graph that returns an object with a "messages" key
61
+ * // will update the state by combining the existing value with the returned one.
62
+ * const myNode = (state: typeof StateAnnotation.State) => {
63
+ * return {
64
+ * messages: [new AIMessage("Some new response")],
65
+ * sentiment: "positive",
66
+ * };
67
+ * };
68
+ *
69
+ * const graph = graphBuilder
70
+ * .addNode("myNode", myNode)
71
+ * .addEdge("__start__", "myNode")
72
+ * .addEdge("myNode", "__end__")
73
+ * .compile();
74
+ *
75
+ * await graph.invoke({ messages: [new HumanMessage("how are you?")] });
76
+ *
77
+ * // {
78
+ * // messages: [HumanMessage("how are you?"), AIMessage("Some new response")],
79
+ * // sentiment: "positive",
80
+ * // }
81
+ * ```
82
+ */
83
+ var StateGraph = class extends require_graph.Graph {
84
+ channels = {};
85
+ waitingEdges = /* @__PURE__ */ new Set();
86
+ /** @internal */
87
+ _schemaDefinition;
88
+ /** @internal */
89
+ _schemaRuntimeDefinition;
90
+ /** @internal */
91
+ _inputDefinition;
92
+ /** @internal */
93
+ _inputRuntimeDefinition;
94
+ /** @internal */
95
+ _outputDefinition;
96
+ /** @internal */
97
+ _outputRuntimeDefinition;
98
+ /**
99
+ * Map schemas to managed values
100
+ * @internal
101
+ */
102
+ _schemaDefinitions = /* @__PURE__ */ new Map();
103
+ /** @internal */
104
+ _metaRegistry = require_meta.schemaMetaRegistry;
105
+ /** @internal Used only for typing. */
106
+ _configSchema;
107
+ /** @internal */
108
+ _configRuntimeSchema;
109
+ constructor(fields, contextSchema) {
110
+ super();
111
+ if (isZodStateGraphArgsWithStateSchema(fields)) {
112
+ const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);
113
+ const inputDef = fields.input != null ? this._metaRegistry.getChannelsForSchema(fields.input) : stateDef;
114
+ const outputDef = fields.output != null ? this._metaRegistry.getChannelsForSchema(fields.output) : stateDef;
115
+ this._schemaDefinition = stateDef;
116
+ this._schemaRuntimeDefinition = fields.state;
117
+ this._inputDefinition = inputDef;
118
+ this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;
119
+ this._outputDefinition = outputDef;
120
+ this._outputRuntimeDefinition = fields.output ?? fields.state;
121
+ } else if ((0, __langchain_core_utils_types.isInteropZodObject)(fields)) {
122
+ const stateDef = this._metaRegistry.getChannelsForSchema(fields);
123
+ this._schemaDefinition = stateDef;
124
+ this._schemaRuntimeDefinition = fields;
125
+ this._inputDefinition = stateDef;
126
+ this._inputRuntimeDefinition = PartialStateSchema;
127
+ this._outputDefinition = stateDef;
128
+ this._outputRuntimeDefinition = fields;
129
+ } else if (isStateGraphArgsWithInputOutputSchemas(fields)) {
130
+ this._schemaDefinition = fields.input.spec;
131
+ this._inputDefinition = fields.input.spec;
132
+ this._outputDefinition = fields.output.spec;
133
+ } else if (isStateGraphArgsWithStateSchema(fields)) {
134
+ this._schemaDefinition = fields.stateSchema.spec;
135
+ this._inputDefinition = fields.input?.spec ?? this._schemaDefinition;
136
+ this._outputDefinition = fields.output?.spec ?? this._schemaDefinition;
137
+ } else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {
138
+ const spec = isAnnotationRoot(fields) ? fields.spec : fields;
139
+ this._schemaDefinition = spec;
140
+ } else if (isStateGraphArgs(fields)) {
141
+ const spec = _getChannels(fields.channels);
142
+ this._schemaDefinition = spec;
143
+ } else throw new Error("Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.");
144
+ this._inputDefinition ??= this._schemaDefinition;
145
+ this._outputDefinition ??= this._schemaDefinition;
146
+ this._addSchema(this._schemaDefinition);
147
+ this._addSchema(this._inputDefinition);
148
+ this._addSchema(this._outputDefinition);
149
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(contextSchema)) this._configRuntimeSchema = contextSchema;
150
+ }
151
+ get allEdges() {
152
+ return new Set([...this.edges, ...Array.from(this.waitingEdges).flatMap(([starts, end]) => starts.map((start) => [start, end]))]);
153
+ }
154
+ _addSchema(stateDefinition) {
155
+ if (this._schemaDefinitions.has(stateDefinition)) return;
156
+ this._schemaDefinitions.set(stateDefinition, stateDefinition);
157
+ for (const [key, val] of Object.entries(stateDefinition)) {
158
+ let channel;
159
+ if (typeof val === "function") channel = val();
160
+ else channel = val;
161
+ if (this.channels[key] !== void 0) {
162
+ if (this.channels[key] !== channel) {
163
+ if (channel.lc_graph_name !== "LastValue") throw new Error(`Channel "${key}" already exists with a different type.`);
164
+ }
165
+ } else this.channels[key] = channel;
166
+ }
167
+ }
168
+ addNode(...args) {
169
+ function isMultipleNodes(args$1) {
170
+ return args$1.length >= 1 && typeof args$1[0] !== "string";
171
+ }
172
+ const nodes = isMultipleNodes(args) ? Array.isArray(args[0]) ? args[0] : Object.entries(args[0]).map(([key, action]) => [
173
+ key,
174
+ action,
175
+ action[Symbol.for("langgraph.state.node")] ?? void 0
176
+ ]) : [[
177
+ args[0],
178
+ args[1],
179
+ args[2]
180
+ ]];
181
+ if (nodes.length === 0) throw new Error("No nodes provided in `addNode`");
182
+ for (const [key, action, options] of nodes) {
183
+ if (key in this.channels) throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
184
+ for (const reservedChar of [require_constants.CHECKPOINT_NAMESPACE_SEPARATOR, require_constants.CHECKPOINT_NAMESPACE_END]) if (key.includes(reservedChar)) throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
185
+ this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
186
+ if (key in this.nodes) throw new Error(`Node \`${key}\` already present.`);
187
+ if (key === require_constants.END || key === require_constants.START) throw new Error(`Node \`${key}\` is reserved.`);
188
+ let inputSpec = this._schemaDefinition;
189
+ if (options?.input !== void 0) {
190
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(options.input)) inputSpec = this._metaRegistry.getChannelsForSchema(options.input);
191
+ else if (options.input.spec !== void 0) inputSpec = options.input.spec;
192
+ }
193
+ if (inputSpec !== void 0) this._addSchema(inputSpec);
194
+ let runnable;
195
+ if (__langchain_core_runnables.Runnable.isRunnable(action)) runnable = action;
196
+ else if (typeof action === "function") runnable = new require_utils.RunnableCallable({
197
+ func: action,
198
+ name: key,
199
+ trace: false
200
+ });
201
+ else runnable = (0, __langchain_core_runnables._coerceToRunnable)(action);
202
+ let cachePolicy = options?.cachePolicy;
203
+ if (typeof cachePolicy === "boolean") cachePolicy = cachePolicy ? {} : void 0;
204
+ const nodeSpec = {
205
+ runnable,
206
+ retryPolicy: options?.retryPolicy,
207
+ cachePolicy,
208
+ metadata: options?.metadata,
209
+ input: inputSpec ?? this._schemaDefinition,
210
+ subgraphs: require_subgraph.isPregelLike(runnable) ? [runnable] : options?.subgraphs,
211
+ ends: options?.ends,
212
+ defer: options?.defer
213
+ };
214
+ this.nodes[key] = nodeSpec;
215
+ }
216
+ return this;
217
+ }
218
+ addEdge(startKey, endKey) {
219
+ if (typeof startKey === "string") return super.addEdge(startKey, endKey);
220
+ if (this.compiled) console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
221
+ for (const start of startKey) {
222
+ if (start === require_constants.END) throw new Error("END cannot be a start node");
223
+ if (!Object.keys(this.nodes).some((node) => node === start)) throw new Error(`Need to add a node named "${start}" first`);
224
+ }
225
+ if (endKey === require_constants.END) throw new Error("END cannot be an end node");
226
+ if (!Object.keys(this.nodes).some((node) => node === endKey)) throw new Error(`Need to add a node named "${endKey}" first`);
227
+ this.waitingEdges.add([startKey, endKey]);
228
+ return this;
229
+ }
230
+ addSequence(nodes) {
231
+ const parsedNodes = Array.isArray(nodes) ? nodes : Object.entries(nodes).map(([key, action]) => [
232
+ key,
233
+ action,
234
+ action[Symbol.for("langgraph.state.node")] ?? void 0
235
+ ]);
236
+ if (parsedNodes.length === 0) throw new Error("Sequence requires at least one node.");
237
+ let previousNode;
238
+ for (const [key, action, options] of parsedNodes) {
239
+ if (key in this.nodes) throw new Error(`Node names must be unique: node with the name "${key}" already exists.`);
240
+ const validKey = key;
241
+ this.addNode(validKey, action, options);
242
+ if (previousNode != null) this.addEdge(previousNode, validKey);
243
+ previousNode = validKey;
244
+ }
245
+ return this;
246
+ }
247
+ compile({ checkpointer, store, cache, interruptBefore, interruptAfter, name, description } = {}) {
248
+ this.validate([...Array.isArray(interruptBefore) ? interruptBefore : [], ...Array.isArray(interruptAfter) ? interruptAfter : []]);
249
+ const outputKeys = Object.keys(this._schemaDefinitions.get(this._outputDefinition));
250
+ const outputChannels = outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;
251
+ const streamKeys = Object.keys(this.channels);
252
+ const streamChannels = streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;
253
+ const compiled = new CompiledStateGraph({
254
+ builder: this,
255
+ checkpointer,
256
+ interruptAfter,
257
+ interruptBefore,
258
+ autoValidate: false,
259
+ nodes: {},
260
+ channels: {
261
+ ...this.channels,
262
+ [require_constants.START]: new require_ephemeral_value.EphemeralValue()
263
+ },
264
+ inputChannels: require_constants.START,
265
+ outputChannels,
266
+ streamChannels,
267
+ streamMode: "updates",
268
+ store,
269
+ cache,
270
+ name,
271
+ description
272
+ });
273
+ compiled.attachNode(require_constants.START);
274
+ for (const [key, node] of Object.entries(this.nodes)) compiled.attachNode(key, node);
275
+ compiled.attachBranch(require_constants.START, require_constants.SELF, _getControlBranch(), { withReader: false });
276
+ for (const [key] of Object.entries(this.nodes)) compiled.attachBranch(key, require_constants.SELF, _getControlBranch(), { withReader: false });
277
+ for (const [start, end] of this.edges) compiled.attachEdge(start, end);
278
+ for (const [starts, end] of this.waitingEdges) compiled.attachEdge(starts, end);
279
+ for (const [start, branches] of Object.entries(this.branches)) for (const [name$1, branch] of Object.entries(branches)) compiled.attachBranch(start, name$1, branch);
280
+ return compiled.validate();
281
+ }
282
+ };
456
283
  function _getChannels(schema) {
457
- const channels = {};
458
- for (const [name, val] of Object.entries(schema)) {
459
- if (name === ROOT) {
460
- channels[name] = (0, annotation_js_1.getChannel)(val);
461
- }
462
- else {
463
- const key = name;
464
- channels[name] = (0, annotation_js_1.getChannel)(val);
465
- }
466
- }
467
- return channels;
284
+ const channels = {};
285
+ for (const [name, val] of Object.entries(schema)) if (name === ROOT) channels[name] = require_annotation.getChannel(val);
286
+ else channels[name] = require_annotation.getChannel(val);
287
+ return channels;
468
288
  }
469
289
  /**
470
- * Final result from building and compiling a {@link StateGraph}.
471
- * Should not be instantiated directly, only using the StateGraph `.compile()`
472
- * instance method.
473
- */
474
- class CompiledStateGraph extends graph_js_1.CompiledGraph {
475
- constructor({ description, ...rest }) {
476
- super(rest);
477
- /**
478
- * The description of the compiled graph.
479
- * This is used by the supervisor agent to describe the handoff to the agent.
480
- */
481
- Object.defineProperty(this, "description", {
482
- enumerable: true,
483
- configurable: true,
484
- writable: true,
485
- value: void 0
486
- });
487
- /** @internal */
488
- Object.defineProperty(this, "_metaRegistry", {
489
- enumerable: true,
490
- configurable: true,
491
- writable: true,
492
- value: meta_js_1.schemaMetaRegistry
493
- });
494
- this.description = description;
495
- }
496
- attachNode(key, node) {
497
- let outputKeys;
498
- if (key === constants_js_1.START) {
499
- // Get input schema keys excluding managed values
500
- outputKeys = Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([k]) => k);
501
- }
502
- else {
503
- outputKeys = Object.keys(this.builder.channels);
504
- }
505
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
506
- function _getRoot(input) {
507
- if ((0, constants_js_1.isCommand)(input)) {
508
- if (input.graph === constants_js_1.Command.PARENT) {
509
- return null;
510
- }
511
- return input._updateAsTuples();
512
- }
513
- else if (Array.isArray(input) &&
514
- input.length > 0 &&
515
- input.some((i) => (0, constants_js_1.isCommand)(i))) {
516
- const updates = [];
517
- for (const i of input) {
518
- if ((0, constants_js_1.isCommand)(i)) {
519
- if (i.graph === constants_js_1.Command.PARENT) {
520
- continue;
521
- }
522
- updates.push(...i._updateAsTuples());
523
- }
524
- else {
525
- updates.push([ROOT, i]);
526
- }
527
- }
528
- return updates;
529
- }
530
- else if (input != null) {
531
- return [[ROOT, input]];
532
- }
533
- return null;
534
- }
535
- // to avoid name collision below
536
- const nodeKey = key;
537
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
538
- function _getUpdates(input) {
539
- if (!input) {
540
- return null;
541
- }
542
- else if ((0, constants_js_1.isCommand)(input)) {
543
- if (input.graph === constants_js_1.Command.PARENT) {
544
- return null;
545
- }
546
- return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));
547
- }
548
- else if (Array.isArray(input) &&
549
- input.length > 0 &&
550
- input.some(constants_js_1.isCommand)) {
551
- const updates = [];
552
- for (const item of input) {
553
- if ((0, constants_js_1.isCommand)(item)) {
554
- if (item.graph === constants_js_1.Command.PARENT) {
555
- continue;
556
- }
557
- updates.push(...item._updateAsTuples().filter(([k]) => outputKeys.includes(k)));
558
- }
559
- else {
560
- const itemUpdates = _getUpdates(item);
561
- if (itemUpdates) {
562
- updates.push(...(itemUpdates ?? []));
563
- }
564
- }
565
- }
566
- return updates;
567
- }
568
- else if (typeof input === "object" && !Array.isArray(input)) {
569
- return Object.entries(input).filter(([k]) => outputKeys.includes(k));
570
- }
571
- else {
572
- const typeofInput = Array.isArray(input) ? "array" : typeof input;
573
- throw new errors_js_1.InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object or an array containing at least one Command object, received ${typeofInput}`, {
574
- lc_error_code: "INVALID_GRAPH_NODE_RETURN_VALUE",
575
- });
576
- }
577
- }
578
- const stateWriteEntries = [
579
- {
580
- value: write_js_1.PASSTHROUGH,
581
- mapper: new utils_js_1.RunnableCallable({
582
- func: outputKeys.length && outputKeys[0] === ROOT
583
- ? _getRoot
584
- : _getUpdates,
585
- trace: false,
586
- recurse: false,
587
- }),
588
- },
589
- ];
590
- // add node and output channel
591
- if (key === constants_js_1.START) {
592
- this.nodes[key] = new read_js_1.PregelNode({
593
- tags: [constants_js_1.TAG_HIDDEN],
594
- triggers: [constants_js_1.START],
595
- channels: [constants_js_1.START],
596
- writers: [new write_js_1.ChannelWrite(stateWriteEntries, [constants_js_1.TAG_HIDDEN])],
597
- });
598
- }
599
- else {
600
- const inputDefinition = node?.input ?? this.builder._schemaDefinition;
601
- const inputValues = Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map((k) => [k, k]));
602
- const isSingleInput = Object.keys(inputValues).length === 1 && ROOT in inputValues;
603
- const branchChannel = `branch:to:${key}`;
604
- this.channels[branchChannel] = node?.defer
605
- ? new last_value_js_1.LastValueAfterFinish()
606
- : new ephemeral_value_js_1.EphemeralValue(false);
607
- this.nodes[key] = new read_js_1.PregelNode({
608
- triggers: [branchChannel],
609
- // read state keys
610
- channels: isSingleInput ? Object.keys(inputValues) : inputValues,
611
- // publish to state keys
612
- writers: [new write_js_1.ChannelWrite(stateWriteEntries, [constants_js_1.TAG_HIDDEN])],
613
- mapper: isSingleInput
614
- ? undefined
615
- : // eslint-disable-next-line @typescript-eslint/no-explicit-any
616
- (input) => {
617
- return Object.fromEntries(Object.entries(input).filter(([k]) => k in inputValues));
618
- },
619
- bound: node?.runnable,
620
- metadata: node?.metadata,
621
- retryPolicy: node?.retryPolicy,
622
- cachePolicy: node?.cachePolicy,
623
- subgraphs: node?.subgraphs,
624
- ends: node?.ends,
625
- });
626
- }
627
- }
628
- attachEdge(starts, end) {
629
- if (end === constants_js_1.END)
630
- return;
631
- if (typeof starts === "string") {
632
- this.nodes[starts].writers.push(new write_js_1.ChannelWrite([{ channel: `branch:to:${end}`, value: null }], [constants_js_1.TAG_HIDDEN]));
633
- }
634
- else if (Array.isArray(starts)) {
635
- const channelName = `join:${starts.join("+")}:${end}`;
636
- // register channel
637
- this.channels[channelName] = this.builder.nodes[end].defer
638
- ? new named_barrier_value_js_1.NamedBarrierValueAfterFinish(new Set(starts))
639
- : new named_barrier_value_js_1.NamedBarrierValue(new Set(starts));
640
- // subscribe to channel
641
- this.nodes[end].triggers.push(channelName);
642
- // publish to channel
643
- for (const start of starts) {
644
- this.nodes[start].writers.push(new write_js_1.ChannelWrite([{ channel: channelName, value: start }], [constants_js_1.TAG_HIDDEN]));
645
- }
646
- }
647
- }
648
- attachBranch(start, _, branch, options = { withReader: true }) {
649
- const branchWriter = async (packets, config) => {
650
- const filteredPackets = packets.filter((p) => p !== constants_js_1.END);
651
- if (!filteredPackets.length)
652
- return;
653
- const writes = filteredPackets.map((p) => {
654
- if ((0, constants_js_1._isSend)(p))
655
- return p;
656
- return { channel: p === constants_js_1.END ? p : `branch:to:${p}`, value: start };
657
- });
658
- await write_js_1.ChannelWrite.doWrite({ ...config, tags: (config.tags ?? []).concat([constants_js_1.TAG_HIDDEN]) }, writes);
659
- };
660
- // attach branch publisher
661
- this.nodes[start].writers.push(branch.run(branchWriter,
662
- // reader
663
- options.withReader
664
- ? (config) => read_js_1.ChannelRead.doRead(config, this.streamChannels ?? this.outputChannels, true)
665
- : undefined));
666
- }
667
- async _validateInput(input) {
668
- if (input == null)
669
- return input;
670
- const schema = (() => {
671
- const input = this.builder._inputRuntimeDefinition;
672
- const schema = this.builder._schemaRuntimeDefinition;
673
- const apply = (schema) => {
674
- if (schema == null)
675
- return undefined;
676
- return this._metaRegistry.getExtendedChannelSchemas(schema, {
677
- withReducerSchema: true,
678
- });
679
- };
680
- if ((0, types_1.isInteropZodObject)(input))
681
- return apply(input);
682
- if (input === PartialStateSchema) {
683
- return (0, types_1.interopZodObjectPartial)(apply(schema));
684
- }
685
- return undefined;
686
- })();
687
- if ((0, constants_js_1.isCommand)(input)) {
688
- const parsedInput = input;
689
- if (input.update && schema != null)
690
- parsedInput.update = (0, types_1.interopParse)(schema, input.update);
691
- return parsedInput;
692
- }
693
- if (schema != null)
694
- return (0, types_1.interopParse)(schema, input);
695
- return input;
696
- }
697
- async _validateContext(config) {
698
- const configSchema = this.builder._configRuntimeSchema;
699
- if ((0, types_1.isInteropZodObject)(configSchema))
700
- (0, types_1.interopParse)(configSchema, config);
701
- return config;
702
- }
703
- }
704
- exports.CompiledStateGraph = CompiledStateGraph;
290
+ * Final result from building and compiling a {@link StateGraph}.
291
+ * Should not be instantiated directly, only using the StateGraph `.compile()`
292
+ * instance method.
293
+ */
294
+ var CompiledStateGraph = class extends require_graph.CompiledGraph {
295
+ /**
296
+ * The description of the compiled graph.
297
+ * This is used by the supervisor agent to describe the handoff to the agent.
298
+ */
299
+ description;
300
+ /** @internal */
301
+ _metaRegistry = require_meta.schemaMetaRegistry;
302
+ constructor({ description,...rest }) {
303
+ super(rest);
304
+ this.description = description;
305
+ }
306
+ attachNode(key, node) {
307
+ let outputKeys;
308
+ if (key === require_constants.START) outputKeys = Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([k]) => k);
309
+ else outputKeys = Object.keys(this.builder.channels);
310
+ function _getRoot(input) {
311
+ if (require_constants.isCommand(input)) {
312
+ if (input.graph === require_constants.Command.PARENT) return null;
313
+ return input._updateAsTuples();
314
+ } else if (Array.isArray(input) && input.length > 0 && input.some((i) => require_constants.isCommand(i))) {
315
+ const updates = [];
316
+ for (const i of input) if (require_constants.isCommand(i)) {
317
+ if (i.graph === require_constants.Command.PARENT) continue;
318
+ updates.push(...i._updateAsTuples());
319
+ } else updates.push([ROOT, i]);
320
+ return updates;
321
+ } else if (input != null) return [[ROOT, input]];
322
+ return null;
323
+ }
324
+ const nodeKey = key;
325
+ function _getUpdates(input) {
326
+ if (!input) return null;
327
+ else if (require_constants.isCommand(input)) {
328
+ if (input.graph === require_constants.Command.PARENT) return null;
329
+ return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));
330
+ } else if (Array.isArray(input) && input.length > 0 && input.some(require_constants.isCommand)) {
331
+ const updates = [];
332
+ for (const item of input) if (require_constants.isCommand(item)) {
333
+ if (item.graph === require_constants.Command.PARENT) continue;
334
+ updates.push(...item._updateAsTuples().filter(([k]) => outputKeys.includes(k)));
335
+ } else {
336
+ const itemUpdates = _getUpdates(item);
337
+ if (itemUpdates) updates.push(...itemUpdates ?? []);
338
+ }
339
+ return updates;
340
+ } else if (typeof input === "object" && !Array.isArray(input)) return Object.entries(input).filter(([k]) => outputKeys.includes(k));
341
+ else {
342
+ const typeofInput = Array.isArray(input) ? "array" : typeof input;
343
+ throw new require_errors.InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object or an array containing at least one Command object, received ${typeofInput}`, { lc_error_code: "INVALID_GRAPH_NODE_RETURN_VALUE" });
344
+ }
345
+ }
346
+ const stateWriteEntries = [{
347
+ value: require_write.PASSTHROUGH,
348
+ mapper: new require_utils.RunnableCallable({
349
+ func: outputKeys.length && outputKeys[0] === ROOT ? _getRoot : _getUpdates,
350
+ trace: false,
351
+ recurse: false
352
+ })
353
+ }];
354
+ if (key === require_constants.START) this.nodes[key] = new require_read.PregelNode({
355
+ tags: [require_constants.TAG_HIDDEN],
356
+ triggers: [require_constants.START],
357
+ channels: [require_constants.START],
358
+ writers: [new require_write.ChannelWrite(stateWriteEntries, [require_constants.TAG_HIDDEN])]
359
+ });
360
+ else {
361
+ const inputDefinition = node?.input ?? this.builder._schemaDefinition;
362
+ const inputValues = Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map((k) => [k, k]));
363
+ const isSingleInput = Object.keys(inputValues).length === 1 && ROOT in inputValues;
364
+ const branchChannel = `branch:to:${key}`;
365
+ this.channels[branchChannel] = node?.defer ? new require_last_value.LastValueAfterFinish() : new require_ephemeral_value.EphemeralValue(false);
366
+ this.nodes[key] = new require_read.PregelNode({
367
+ triggers: [branchChannel],
368
+ channels: isSingleInput ? Object.keys(inputValues) : inputValues,
369
+ writers: [new require_write.ChannelWrite(stateWriteEntries, [require_constants.TAG_HIDDEN])],
370
+ mapper: isSingleInput ? void 0 : (input) => {
371
+ return Object.fromEntries(Object.entries(input).filter(([k]) => k in inputValues));
372
+ },
373
+ bound: node?.runnable,
374
+ metadata: node?.metadata,
375
+ retryPolicy: node?.retryPolicy,
376
+ cachePolicy: node?.cachePolicy,
377
+ subgraphs: node?.subgraphs,
378
+ ends: node?.ends
379
+ });
380
+ }
381
+ }
382
+ attachEdge(starts, end) {
383
+ if (end === require_constants.END) return;
384
+ if (typeof starts === "string") this.nodes[starts].writers.push(new require_write.ChannelWrite([{
385
+ channel: `branch:to:${end}`,
386
+ value: null
387
+ }], [require_constants.TAG_HIDDEN]));
388
+ else if (Array.isArray(starts)) {
389
+ const channelName = `join:${starts.join("+")}:${end}`;
390
+ this.channels[channelName] = this.builder.nodes[end].defer ? new require_named_barrier_value.NamedBarrierValueAfterFinish(new Set(starts)) : new require_named_barrier_value.NamedBarrierValue(new Set(starts));
391
+ this.nodes[end].triggers.push(channelName);
392
+ for (const start of starts) this.nodes[start].writers.push(new require_write.ChannelWrite([{
393
+ channel: channelName,
394
+ value: start
395
+ }], [require_constants.TAG_HIDDEN]));
396
+ }
397
+ }
398
+ attachBranch(start, _, branch, options = { withReader: true }) {
399
+ const branchWriter = async (packets, config) => {
400
+ const filteredPackets = packets.filter((p) => p !== require_constants.END);
401
+ if (!filteredPackets.length) return;
402
+ const writes = filteredPackets.map((p) => {
403
+ if (require_constants._isSend(p)) return p;
404
+ return {
405
+ channel: p === require_constants.END ? p : `branch:to:${p}`,
406
+ value: start
407
+ };
408
+ });
409
+ await require_write.ChannelWrite.doWrite({
410
+ ...config,
411
+ tags: (config.tags ?? []).concat([require_constants.TAG_HIDDEN])
412
+ }, writes);
413
+ };
414
+ this.nodes[start].writers.push(branch.run(branchWriter, options.withReader ? (config) => require_read.ChannelRead.doRead(config, this.streamChannels ?? this.outputChannels, true) : void 0));
415
+ }
416
+ async _validateInput(input) {
417
+ if (input == null) return input;
418
+ const schema = (() => {
419
+ const input$1 = this.builder._inputRuntimeDefinition;
420
+ const schema$1 = this.builder._schemaRuntimeDefinition;
421
+ const apply = (schema$2) => {
422
+ if (schema$2 == null) return void 0;
423
+ return this._metaRegistry.getExtendedChannelSchemas(schema$2, { withReducerSchema: true });
424
+ };
425
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(input$1)) return apply(input$1);
426
+ if (input$1 === PartialStateSchema) return (0, __langchain_core_utils_types.interopZodObjectPartial)(apply(schema$1));
427
+ return void 0;
428
+ })();
429
+ if (require_constants.isCommand(input)) {
430
+ const parsedInput = input;
431
+ if (input.update && schema != null) parsedInput.update = (0, __langchain_core_utils_types.interopParse)(schema, input.update);
432
+ return parsedInput;
433
+ }
434
+ if (schema != null) return (0, __langchain_core_utils_types.interopParse)(schema, input);
435
+ return input;
436
+ }
437
+ async _validateContext(config) {
438
+ const configSchema = this.builder._configRuntimeSchema;
439
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(configSchema)) (0, __langchain_core_utils_types.interopParse)(configSchema, config);
440
+ return config;
441
+ }
442
+ };
705
443
  function isStateDefinition(obj) {
706
- return (typeof obj === "object" &&
707
- obj !== null &&
708
- !Array.isArray(obj) &&
709
- Object.keys(obj).length > 0 &&
710
- Object.values(obj).every((v) => typeof v === "function" || (0, base_js_1.isBaseChannel)(v)));
444
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj) && Object.keys(obj).length > 0 && Object.values(obj).every((v) => typeof v === "function" || require_base.isBaseChannel(v));
711
445
  }
712
446
  function isAnnotationRoot(obj) {
713
- return (typeof obj === "object" &&
714
- obj !== null &&
715
- "lc_graph_name" in obj &&
716
- obj.lc_graph_name === "AnnotationRoot");
447
+ return typeof obj === "object" && obj !== null && "lc_graph_name" in obj && obj.lc_graph_name === "AnnotationRoot";
717
448
  }
718
449
  function isStateGraphArgs(obj) {
719
- return (typeof obj === "object" &&
720
- obj !== null &&
721
- obj.channels !== undefined);
450
+ return typeof obj === "object" && obj !== null && obj.channels !== void 0;
722
451
  }
723
452
  function isStateGraphArgsWithStateSchema(obj) {
724
- return (typeof obj === "object" &&
725
- obj !== null &&
726
- obj.stateSchema !== undefined);
453
+ return typeof obj === "object" && obj !== null && obj.stateSchema !== void 0;
727
454
  }
728
455
  function isStateGraphArgsWithInputOutputSchemas(obj) {
729
- return (typeof obj === "object" &&
730
- obj !== null &&
731
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
732
- obj.stateSchema === undefined &&
733
- obj.input !== undefined &&
734
- obj.output !== undefined);
456
+ return typeof obj === "object" && obj !== null && obj.stateSchema === void 0 && obj.input !== void 0 && obj.output !== void 0;
735
457
  }
736
458
  function isZodStateGraphArgsWithStateSchema(value) {
737
- if (typeof value !== "object" || value == null) {
738
- return false;
739
- }
740
- if (!("state" in value) || !(0, types_1.isInteropZodObject)(value.state)) {
741
- return false;
742
- }
743
- if ("input" in value && !(0, types_1.isInteropZodObject)(value.input)) {
744
- return false;
745
- }
746
- if ("output" in value && !(0, types_1.isInteropZodObject)(value.output)) {
747
- return false;
748
- }
749
- return true;
459
+ if (typeof value !== "object" || value == null) return false;
460
+ if (!("state" in value) || !(0, __langchain_core_utils_types.isInteropZodObject)(value.state)) return false;
461
+ if ("input" in value && !(0, __langchain_core_utils_types.isInteropZodObject)(value.input)) return false;
462
+ if ("output" in value && !(0, __langchain_core_utils_types.isInteropZodObject)(value.output)) return false;
463
+ return true;
750
464
  }
751
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
752
465
  function _controlBranch(value) {
753
- if ((0, constants_js_1._isSend)(value)) {
754
- return [value];
755
- }
756
- const commands = [];
757
- if ((0, constants_js_1.isCommand)(value)) {
758
- commands.push(value);
759
- }
760
- else if (Array.isArray(value)) {
761
- commands.push(...value.filter(constants_js_1.isCommand));
762
- }
763
- const destinations = [];
764
- for (const command of commands) {
765
- if (command.graph === constants_js_1.Command.PARENT) {
766
- throw new errors_js_1.ParentCommand(command);
767
- }
768
- if ((0, constants_js_1._isSend)(command.goto)) {
769
- destinations.push(command.goto);
770
- }
771
- else if (typeof command.goto === "string") {
772
- destinations.push(command.goto);
773
- }
774
- else {
775
- if (Array.isArray(command.goto)) {
776
- destinations.push(...command.goto);
777
- }
778
- }
779
- }
780
- return destinations;
466
+ if (require_constants._isSend(value)) return [value];
467
+ const commands = [];
468
+ if (require_constants.isCommand(value)) commands.push(value);
469
+ else if (Array.isArray(value)) commands.push(...value.filter(require_constants.isCommand));
470
+ const destinations = [];
471
+ for (const command of commands) {
472
+ if (command.graph === require_constants.Command.PARENT) throw new require_errors.ParentCommand(command);
473
+ if (require_constants._isSend(command.goto)) destinations.push(command.goto);
474
+ else if (typeof command.goto === "string") destinations.push(command.goto);
475
+ else if (Array.isArray(command.goto)) destinations.push(...command.goto);
476
+ }
477
+ return destinations;
781
478
  }
782
479
  function _getControlBranch() {
783
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
784
- const CONTROL_BRANCH_PATH = new utils_js_1.RunnableCallable({
785
- func: _controlBranch,
786
- tags: [constants_js_1.TAG_HIDDEN],
787
- trace: false,
788
- recurse: false,
789
- name: "<control_branch>",
790
- });
791
- return new graph_js_1.Branch({
792
- path: CONTROL_BRANCH_PATH,
793
- });
480
+ const CONTROL_BRANCH_PATH = new require_utils.RunnableCallable({
481
+ func: _controlBranch,
482
+ tags: [require_constants.TAG_HIDDEN],
483
+ trace: false,
484
+ recurse: false,
485
+ name: "<control_branch>"
486
+ });
487
+ return new require_graph.Branch({ path: CONTROL_BRANCH_PATH });
794
488
  }
795
489
  function typedNode(_state, _options) {
796
- return (func, options) => {
797
- Object.assign(func, { [Symbol.for("langgraph.state.node")]: options });
798
- return func;
799
- };
490
+ return (func, options) => {
491
+ Object.assign(func, { [Symbol.for("langgraph.state.node")]: options });
492
+ return func;
493
+ };
800
494
  }
801
- //# sourceMappingURL=state.js.map
495
+
496
+ //#endregion
497
+ exports.CompiledStateGraph = CompiledStateGraph;
498
+ exports.StateGraph = StateGraph;
499
+ exports.typedNode = typedNode;
500
+ //# sourceMappingURL=state.cjs.map