@langchain/langgraph 0.4.9 → 1.0.0-alpha.1

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 (505) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -2
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/channels/any_value.cjs +44 -63
  5. package/dist/channels/any_value.cjs.map +1 -0
  6. package/dist/channels/any_value.d.cts +24 -0
  7. package/dist/channels/any_value.d.cts.map +1 -0
  8. package/dist/channels/any_value.d.ts +16 -11
  9. package/dist/channels/any_value.d.ts.map +1 -0
  10. package/dist/channels/any_value.js +42 -57
  11. package/dist/channels/any_value.js.map +1 -1
  12. package/dist/channels/base.cjs +93 -133
  13. package/dist/channels/base.cjs.map +1 -0
  14. package/dist/channels/base.d.cts +79 -0
  15. package/dist/channels/base.d.cts.map +1 -0
  16. package/dist/channels/base.d.ts +77 -73
  17. package/dist/channels/base.d.ts.map +1 -0
  18. package/dist/channels/base.js +90 -127
  19. package/dist/channels/base.js.map +1 -1
  20. package/dist/channels/binop.cjs +47 -77
  21. package/dist/channels/binop.cjs.map +1 -0
  22. package/dist/channels/binop.d.cts +22 -0
  23. package/dist/channels/binop.d.cts.map +1 -0
  24. package/dist/channels/binop.d.ts +17 -12
  25. package/dist/channels/binop.d.ts.map +1 -0
  26. package/dist/channels/binop.js +45 -71
  27. package/dist/channels/binop.js.map +1 -1
  28. package/dist/channels/dynamic_barrier_value.cjs +72 -208
  29. package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
  30. package/dist/channels/dynamic_barrier_value.d.cts +42 -0
  31. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  32. package/dist/channels/dynamic_barrier_value.d.ts +20 -35
  33. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  34. package/dist/channels/dynamic_barrier_value.js +69 -200
  35. package/dist/channels/dynamic_barrier_value.js.map +1 -1
  36. package/dist/channels/ephemeral_value.cjs +44 -70
  37. package/dist/channels/ephemeral_value.cjs.map +1 -0
  38. package/dist/channels/ephemeral_value.d.cts +22 -0
  39. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  40. package/dist/channels/ephemeral_value.d.ts +18 -12
  41. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  42. package/dist/channels/ephemeral_value.js +43 -65
  43. package/dist/channels/ephemeral_value.js.map +1 -1
  44. package/dist/channels/index.cjs +21 -10
  45. package/dist/channels/index.d.cts +9 -0
  46. package/dist/channels/index.d.ts +9 -7
  47. package/dist/channels/index.js +10 -3
  48. package/dist/channels/last_value.cjs +90 -140
  49. package/dist/channels/last_value.cjs.map +1 -0
  50. package/dist/channels/last_value.d.cts +42 -0
  51. package/dist/channels/last_value.d.cts.map +1 -0
  52. package/dist/channels/last_value.d.ts +27 -23
  53. package/dist/channels/last_value.d.ts.map +1 -0
  54. package/dist/channels/last_value.js +87 -133
  55. package/dist/channels/last_value.js.map +1 -1
  56. package/dist/channels/named_barrier_value.cjs +114 -170
  57. package/dist/channels/named_barrier_value.cjs.map +1 -0
  58. package/dist/channels/named_barrier_value.d.cts +46 -0
  59. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  60. package/dist/channels/named_barrier_value.d.ts +32 -29
  61. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  62. package/dist/channels/named_barrier_value.js +111 -163
  63. package/dist/channels/named_barrier_value.js.map +1 -1
  64. package/dist/channels/topic.cjs +63 -96
  65. package/dist/channels/topic.cjs.map +1 -0
  66. package/dist/channels/topic.d.cts +32 -0
  67. package/dist/channels/topic.d.cts.map +1 -0
  68. package/dist/channels/topic.d.ts +28 -19
  69. package/dist/channels/topic.d.ts.map +1 -0
  70. package/dist/channels/topic.js +61 -90
  71. package/dist/channels/topic.js.map +1 -1
  72. package/dist/constants.cjs +376 -452
  73. package/dist/constants.cjs.map +1 -0
  74. package/dist/constants.d.cts +285 -0
  75. package/dist/constants.d.cts.map +1 -0
  76. package/dist/constants.d.ts +113 -148
  77. package/dist/constants.d.ts.map +1 -0
  78. package/dist/constants.js +336 -444
  79. package/dist/constants.js.map +1 -1
  80. package/dist/errors.cjs +151 -179
  81. package/dist/errors.cjs.map +1 -0
  82. package/dist/errors.d.cts +81 -0
  83. package/dist/errors.d.cts.map +1 -0
  84. package/dist/errors.d.ts +56 -46
  85. package/dist/errors.d.ts.map +1 -0
  86. package/dist/errors.js +140 -165
  87. package/dist/errors.js.map +1 -1
  88. package/dist/func/index.cjs +292 -290
  89. package/dist/func/index.cjs.map +1 -0
  90. package/dist/func/index.d.cts +293 -0
  91. package/dist/func/index.d.cts.map +1 -0
  92. package/dist/func/index.d.ts +86 -72
  93. package/dist/func/index.d.ts.map +1 -0
  94. package/dist/func/index.js +288 -284
  95. package/dist/func/index.js.map +1 -1
  96. package/dist/func/types.d.cts +64 -0
  97. package/dist/func/types.d.cts.map +1 -0
  98. package/dist/func/types.d.ts +24 -19
  99. package/dist/func/types.d.ts.map +1 -0
  100. package/dist/graph/annotation.cjs +96 -120
  101. package/dist/graph/annotation.cjs.map +1 -0
  102. package/dist/graph/annotation.d.cts +116 -0
  103. package/dist/graph/annotation.d.cts.map +1 -0
  104. package/dist/graph/annotation.d.ts +33 -34
  105. package/dist/graph/annotation.d.ts.map +1 -0
  106. package/dist/graph/annotation.js +91 -112
  107. package/dist/graph/annotation.js.map +1 -1
  108. package/dist/graph/graph.cjs +419 -723
  109. package/dist/graph/graph.cjs.map +1 -0
  110. package/dist/graph/graph.d.cts +133 -0
  111. package/dist/graph/graph.d.cts.map +1 -0
  112. package/dist/graph/graph.d.ts +124 -91
  113. package/dist/graph/graph.d.ts.map +1 -0
  114. package/dist/graph/graph.js +412 -713
  115. package/dist/graph/graph.js.map +1 -1
  116. package/dist/graph/index.cjs +4 -17
  117. package/dist/graph/index.js +6 -5
  118. package/dist/graph/message.cjs +59 -104
  119. package/dist/graph/message.cjs.map +1 -0
  120. package/dist/graph/message.d.cts +19 -0
  121. package/dist/graph/message.d.cts.map +1 -0
  122. package/dist/graph/message.d.ts +11 -10
  123. package/dist/graph/message.d.ts.map +1 -0
  124. package/dist/graph/message.js +56 -98
  125. package/dist/graph/message.js.map +1 -1
  126. package/dist/graph/messages_annotation.cjs +106 -106
  127. package/dist/graph/messages_annotation.cjs.map +1 -0
  128. package/dist/graph/messages_annotation.d.cts +111 -0
  129. package/dist/graph/messages_annotation.d.cts.map +1 -0
  130. package/dist/graph/messages_annotation.d.ts +18 -9
  131. package/dist/graph/messages_annotation.d.ts.map +1 -0
  132. package/dist/graph/messages_annotation.js +100 -100
  133. package/dist/graph/messages_annotation.js.map +1 -1
  134. package/dist/graph/state.cjs +475 -779
  135. package/dist/graph/state.cjs.map +1 -0
  136. package/dist/graph/state.d.cts +231 -0
  137. package/dist/graph/state.d.cts.map +1 -0
  138. package/dist/graph/state.d.ts +148 -138
  139. package/dist/graph/state.d.ts.map +1 -0
  140. package/dist/graph/state.js +469 -769
  141. package/dist/graph/state.js.map +1 -1
  142. package/dist/graph/zod/index.cjs +10 -21
  143. package/dist/graph/zod/index.d.cts +3 -0
  144. package/dist/graph/zod/index.d.ts +3 -3
  145. package/dist/graph/zod/index.js +4 -4
  146. package/dist/graph/zod/meta.cjs +142 -177
  147. package/dist/graph/zod/meta.cjs.map +1 -0
  148. package/dist/graph/zod/meta.d.cts +116 -0
  149. package/dist/graph/zod/meta.d.cts.map +1 -0
  150. package/dist/graph/zod/meta.d.ts +99 -97
  151. package/dist/graph/zod/meta.d.ts.map +1 -0
  152. package/dist/graph/zod/meta.js +136 -170
  153. package/dist/graph/zod/meta.js.map +1 -1
  154. package/dist/graph/zod/plugin.cjs +36 -39
  155. package/dist/graph/zod/plugin.cjs.map +1 -0
  156. package/dist/graph/zod/plugin.js +34 -35
  157. package/dist/graph/zod/plugin.js.map +1 -1
  158. package/dist/graph/zod/schema.cjs +82 -110
  159. package/dist/graph/zod/schema.cjs.map +1 -0
  160. package/dist/graph/zod/schema.d.cts +38 -0
  161. package/dist/graph/zod/schema.d.cts.map +1 -0
  162. package/dist/graph/zod/schema.d.ts +12 -6
  163. package/dist/graph/zod/schema.d.ts.map +1 -0
  164. package/dist/graph/zod/schema.js +77 -103
  165. package/dist/graph/zod/schema.js.map +1 -1
  166. package/dist/graph/zod/zod-registry.cjs +41 -47
  167. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  168. package/dist/graph/zod/zod-registry.d.cts +51 -0
  169. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  170. package/dist/graph/zod/zod-registry.d.ts +34 -26
  171. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  172. package/dist/graph/zod/zod-registry.js +37 -41
  173. package/dist/graph/zod/zod-registry.js.map +1 -1
  174. package/dist/hash.cjs +205 -267
  175. package/dist/hash.cjs.map +1 -0
  176. package/dist/hash.js +205 -265
  177. package/dist/hash.js.map +1 -1
  178. package/dist/index.cjs +111 -33
  179. package/dist/index.cjs.map +1 -0
  180. package/dist/index.d.cts +26 -0
  181. package/dist/index.d.ts +26 -5
  182. package/dist/index.js +19 -7
  183. package/dist/index.js.map +1 -1
  184. package/dist/interrupt.cjs +79 -85
  185. package/dist/interrupt.cjs.map +1 -0
  186. package/dist/interrupt.d.cts +49 -0
  187. package/dist/interrupt.d.cts.map +1 -0
  188. package/dist/interrupt.d.ts +6 -1
  189. package/dist/interrupt.d.ts.map +1 -0
  190. package/dist/interrupt.js +76 -80
  191. package/dist/interrupt.js.map +1 -1
  192. package/dist/prebuilt/agentName.cjs +139 -172
  193. package/dist/prebuilt/agentName.cjs.map +1 -0
  194. package/dist/prebuilt/agentName.d.cts +42 -0
  195. package/dist/prebuilt/agentName.d.cts.map +1 -0
  196. package/dist/prebuilt/agentName.d.ts +13 -21
  197. package/dist/prebuilt/agentName.d.ts.map +1 -0
  198. package/dist/prebuilt/agentName.js +139 -168
  199. package/dist/prebuilt/agentName.js.map +1 -1
  200. package/dist/prebuilt/agent_executor.cjs +42 -80
  201. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  202. package/dist/prebuilt/agent_executor.d.cts +57 -0
  203. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  204. package/dist/prebuilt/agent_executor.d.ts +47 -38
  205. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  206. package/dist/prebuilt/agent_executor.js +40 -75
  207. package/dist/prebuilt/agent_executor.js.map +1 -1
  208. package/dist/prebuilt/chat_agent_executor.cjs +66 -128
  209. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  210. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  211. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  212. package/dist/prebuilt/chat_agent_executor.d.ts +18 -10
  213. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  214. package/dist/prebuilt/chat_agent_executor.js +63 -123
  215. package/dist/prebuilt/chat_agent_executor.js.map +1 -1
  216. package/dist/prebuilt/index.cjs +15 -18
  217. package/dist/prebuilt/index.d.cts +8 -0
  218. package/dist/prebuilt/index.d.ts +8 -8
  219. package/dist/prebuilt/index.js +8 -7
  220. package/dist/prebuilt/interrupt.d.cts +73 -0
  221. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  222. package/dist/prebuilt/interrupt.d.ts +32 -15
  223. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  224. package/dist/prebuilt/react_agent_executor.cjs +317 -473
  225. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  226. package/dist/prebuilt/react_agent_executor.d.cts +229 -0
  227. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  228. package/dist/prebuilt/react_agent_executor.d.ts +171 -143
  229. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  230. package/dist/prebuilt/react_agent_executor.js +315 -465
  231. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  232. package/dist/prebuilt/tool_executor.cjs +45 -67
  233. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  234. package/dist/prebuilt/tool_executor.d.cts +42 -0
  235. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  236. package/dist/prebuilt/tool_executor.d.ts +30 -24
  237. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  238. package/dist/prebuilt/tool_executor.js +44 -63
  239. package/dist/prebuilt/tool_executor.js.map +1 -1
  240. package/dist/prebuilt/tool_node.cjs +213 -275
  241. package/dist/prebuilt/tool_node.cjs.map +1 -0
  242. package/dist/prebuilt/tool_node.d.cts +151 -0
  243. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  244. package/dist/prebuilt/tool_node.d.ts +30 -17
  245. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  246. package/dist/prebuilt/tool_node.js +209 -268
  247. package/dist/prebuilt/tool_node.js.map +1 -1
  248. package/dist/pregel/algo.cjs +551 -692
  249. package/dist/pregel/algo.cjs.map +1 -0
  250. package/dist/pregel/algo.d.cts +13 -0
  251. package/dist/pregel/algo.d.cts.map +1 -0
  252. package/dist/pregel/algo.d.ts +8 -38
  253. package/dist/pregel/algo.d.ts.map +1 -0
  254. package/dist/pregel/algo.js +546 -683
  255. package/dist/pregel/algo.js.map +1 -1
  256. package/dist/pregel/call.cjs +46 -42
  257. package/dist/pregel/call.cjs.map +1 -0
  258. package/dist/pregel/call.js +43 -37
  259. package/dist/pregel/call.js.map +1 -1
  260. package/dist/pregel/debug.cjs +153 -223
  261. package/dist/pregel/debug.cjs.map +1 -0
  262. package/dist/pregel/debug.js +152 -215
  263. package/dist/pregel/debug.js.map +1 -1
  264. package/dist/pregel/index.cjs +1138 -1604
  265. package/dist/pregel/index.cjs.map +1 -0
  266. package/dist/pregel/index.d.cts +536 -0
  267. package/dist/pregel/index.d.cts.map +1 -0
  268. package/dist/pregel/index.d.ts +460 -422
  269. package/dist/pregel/index.d.ts.map +1 -0
  270. package/dist/pregel/index.js +1129 -1592
  271. package/dist/pregel/index.js.map +1 -1
  272. package/dist/pregel/io.cjs +127 -234
  273. package/dist/pregel/io.cjs.map +1 -0
  274. package/dist/pregel/io.js +122 -225
  275. package/dist/pregel/io.js.map +1 -1
  276. package/dist/pregel/loop.cjs +542 -954
  277. package/dist/pregel/loop.cjs.map +1 -0
  278. package/dist/pregel/loop.js +539 -948
  279. package/dist/pregel/loop.js.map +1 -1
  280. package/dist/pregel/messages.cjs +104 -196
  281. package/dist/pregel/messages.cjs.map +1 -0
  282. package/dist/pregel/messages.js +102 -191
  283. package/dist/pregel/messages.js.map +1 -1
  284. package/dist/pregel/read.cjs +150 -280
  285. package/dist/pregel/read.cjs.map +1 -0
  286. package/dist/pregel/read.d.cts +51 -0
  287. package/dist/pregel/read.d.cts.map +1 -0
  288. package/dist/pregel/read.d.ts +48 -46
  289. package/dist/pregel/read.d.ts.map +1 -0
  290. package/dist/pregel/read.js +147 -274
  291. package/dist/pregel/read.js.map +1 -1
  292. package/dist/pregel/remote.cjs +339 -458
  293. package/dist/pregel/remote.cjs.map +1 -0
  294. package/dist/pregel/remote.d.cts +121 -0
  295. package/dist/pregel/remote.d.cts.map +1 -0
  296. package/dist/pregel/remote.d.ts +79 -69
  297. package/dist/pregel/remote.d.ts.map +1 -0
  298. package/dist/pregel/remote.js +337 -453
  299. package/dist/pregel/remote.js.map +1 -1
  300. package/dist/pregel/retry.cjs +87 -138
  301. package/dist/pregel/retry.cjs.map +1 -0
  302. package/dist/pregel/retry.js +83 -130
  303. package/dist/pregel/retry.js.map +1 -1
  304. package/dist/pregel/runnable_types.d.cts +49 -0
  305. package/dist/pregel/runnable_types.d.cts.map +1 -0
  306. package/dist/pregel/runnable_types.d.ts +47 -17
  307. package/dist/pregel/runnable_types.d.ts.map +1 -0
  308. package/dist/pregel/runner.cjs +222 -315
  309. package/dist/pregel/runner.cjs.map +1 -0
  310. package/dist/pregel/runner.js +219 -308
  311. package/dist/pregel/runner.js.map +1 -1
  312. package/dist/pregel/stream.cjs +89 -130
  313. package/dist/pregel/stream.cjs.map +1 -0
  314. package/dist/pregel/stream.js +87 -125
  315. package/dist/pregel/stream.js.map +1 -1
  316. package/dist/pregel/types.cjs +25 -62
  317. package/dist/pregel/types.cjs.map +1 -0
  318. package/dist/pregel/types.d.cts +440 -0
  319. package/dist/pregel/types.d.cts.map +1 -0
  320. package/dist/pregel/types.d.ts +381 -432
  321. package/dist/pregel/types.d.ts.map +1 -0
  322. package/dist/pregel/types.js +23 -57
  323. package/dist/pregel/types.js.map +1 -1
  324. package/dist/pregel/utils/config.cjs +101 -147
  325. package/dist/pregel/utils/config.cjs.map +1 -0
  326. package/dist/pregel/utils/config.d.cts +36 -0
  327. package/dist/pregel/utils/config.d.cts.map +1 -0
  328. package/dist/pregel/utils/config.d.ts +12 -9
  329. package/dist/pregel/utils/config.d.ts.map +1 -0
  330. package/dist/pregel/utils/config.js +99 -143
  331. package/dist/pregel/utils/config.js.map +1 -1
  332. package/dist/pregel/utils/index.cjs +87 -125
  333. package/dist/pregel/utils/index.cjs.map +1 -0
  334. package/dist/pregel/utils/index.d.cts +51 -0
  335. package/dist/pregel/utils/index.d.cts.map +1 -0
  336. package/dist/pregel/utils/index.d.ts +45 -61
  337. package/dist/pregel/utils/index.d.ts.map +1 -0
  338. package/dist/pregel/utils/index.js +86 -120
  339. package/dist/pregel/utils/index.js.map +1 -1
  340. package/dist/pregel/utils/subgraph.cjs +15 -26
  341. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  342. package/dist/pregel/utils/subgraph.js +12 -21
  343. package/dist/pregel/utils/subgraph.js.map +1 -1
  344. package/dist/pregel/validate.cjs +42 -92
  345. package/dist/pregel/validate.cjs.map +1 -0
  346. package/dist/pregel/validate.js +39 -84
  347. package/dist/pregel/validate.js.map +1 -1
  348. package/dist/pregel/write.cjs +87 -137
  349. package/dist/pregel/write.cjs.map +1 -0
  350. package/dist/pregel/write.d.cts +35 -0
  351. package/dist/pregel/write.d.cts.map +1 -0
  352. package/dist/pregel/write.d.ts +27 -23
  353. package/dist/pregel/write.d.ts.map +1 -0
  354. package/dist/pregel/write.js +83 -131
  355. package/dist/pregel/write.js.map +1 -1
  356. package/dist/remote.cjs +3 -6
  357. package/dist/remote.d.cts +2 -0
  358. package/dist/remote.d.ts +2 -1
  359. package/dist/remote.js +3 -2
  360. package/dist/setup/async_local_storage.cjs +10 -7
  361. package/dist/setup/async_local_storage.cjs.map +1 -0
  362. package/dist/setup/async_local_storage.js +7 -2
  363. package/dist/setup/async_local_storage.js.map +1 -1
  364. package/dist/ui/index.cjs +4 -0
  365. package/dist/ui/index.d.cts +5 -0
  366. package/dist/ui/index.d.ts +5 -0
  367. package/dist/ui/index.js +3 -0
  368. package/dist/ui/stream.cjs +145 -0
  369. package/dist/ui/stream.cjs.map +1 -0
  370. package/dist/ui/stream.d.cts +25 -0
  371. package/dist/ui/stream.d.cts.map +1 -0
  372. package/dist/ui/stream.d.ts +25 -0
  373. package/dist/ui/stream.d.ts.map +1 -0
  374. package/dist/ui/stream.js +143 -0
  375. package/dist/ui/stream.js.map +1 -0
  376. package/dist/ui/types.infer.d.cts +53 -0
  377. package/dist/ui/types.infer.d.cts.map +1 -0
  378. package/dist/ui/types.infer.d.ts +53 -0
  379. package/dist/ui/types.infer.d.ts.map +1 -0
  380. package/dist/ui/types.message.d.cts +95 -0
  381. package/dist/ui/types.message.d.cts.map +1 -0
  382. package/dist/ui/types.message.d.ts +95 -0
  383. package/dist/ui/types.message.d.ts.map +1 -0
  384. package/dist/ui/types.schema.d.cts +228 -0
  385. package/dist/ui/types.schema.d.cts.map +1 -0
  386. package/dist/ui/types.schema.d.ts +228 -0
  387. package/dist/ui/types.schema.d.ts.map +1 -0
  388. package/dist/utils.cjs +77 -147
  389. package/dist/utils.cjs.map +1 -0
  390. package/dist/utils.d.cts +32 -0
  391. package/dist/utils.d.cts.map +1 -0
  392. package/dist/utils.d.ts +29 -25
  393. package/dist/utils.d.ts.map +1 -0
  394. package/dist/utils.js +73 -140
  395. package/dist/utils.js.map +1 -1
  396. package/dist/web.cjs +96 -55
  397. package/dist/web.d.cts +23 -0
  398. package/dist/web.d.ts +23 -14
  399. package/dist/web.js +15 -8
  400. package/dist/writer.cjs +15 -0
  401. package/dist/writer.cjs.map +1 -0
  402. package/dist/writer.d.cts +5 -0
  403. package/dist/writer.d.cts.map +1 -0
  404. package/dist/writer.d.ts +5 -0
  405. package/dist/writer.d.ts.map +1 -0
  406. package/dist/writer.js +14 -0
  407. package/dist/writer.js.map +1 -0
  408. package/package.json +90 -83
  409. package/dist/channels/index.js.map +0 -1
  410. package/dist/func/types.cjs +0 -15
  411. package/dist/func/types.js +0 -12
  412. package/dist/func/types.js.map +0 -1
  413. package/dist/graph/index.d.ts +0 -4
  414. package/dist/graph/index.js.map +0 -1
  415. package/dist/graph/message.test.cjs +0 -196
  416. package/dist/graph/message.test.d.ts +0 -1
  417. package/dist/graph/message.test.js +0 -194
  418. package/dist/graph/message.test.js.map +0 -1
  419. package/dist/graph/zod/index.js.map +0 -1
  420. package/dist/graph/zod/plugin.d.ts +0 -28
  421. package/dist/hash.d.ts +0 -2
  422. package/dist/prebuilt/index.js.map +0 -1
  423. package/dist/prebuilt/interrupt.cjs +0 -3
  424. package/dist/prebuilt/interrupt.js +0 -2
  425. package/dist/prebuilt/interrupt.js.map +0 -1
  426. package/dist/pregel/call.d.ts +0 -16
  427. package/dist/pregel/debug.d.ts +0 -41
  428. package/dist/pregel/debug.test.cjs +0 -258
  429. package/dist/pregel/debug.test.d.ts +0 -1
  430. package/dist/pregel/debug.test.js +0 -256
  431. package/dist/pregel/debug.test.js.map +0 -1
  432. package/dist/pregel/io.d.ts +0 -30
  433. package/dist/pregel/io.mapCommand.test.cjs +0 -150
  434. package/dist/pregel/io.mapCommand.test.d.ts +0 -1
  435. package/dist/pregel/io.mapCommand.test.js +0 -148
  436. package/dist/pregel/io.mapCommand.test.js.map +0 -1
  437. package/dist/pregel/loop.d.ts +0 -147
  438. package/dist/pregel/messages.d.ts +0 -30
  439. package/dist/pregel/messages.test.cjs +0 -369
  440. package/dist/pregel/messages.test.d.ts +0 -1
  441. package/dist/pregel/messages.test.js +0 -367
  442. package/dist/pregel/messages.test.js.map +0 -1
  443. package/dist/pregel/read.test.cjs +0 -194
  444. package/dist/pregel/read.test.d.ts +0 -1
  445. package/dist/pregel/read.test.js +0 -192
  446. package/dist/pregel/read.test.js.map +0 -1
  447. package/dist/pregel/retry.d.ts +0 -17
  448. package/dist/pregel/runnable_types.cjs +0 -3
  449. package/dist/pregel/runnable_types.js +0 -2
  450. package/dist/pregel/runnable_types.js.map +0 -1
  451. package/dist/pregel/runner.d.ts +0 -79
  452. package/dist/pregel/runner.test.cjs +0 -66
  453. package/dist/pregel/runner.test.d.ts +0 -1
  454. package/dist/pregel/runner.test.js +0 -64
  455. package/dist/pregel/runner.test.js.map +0 -1
  456. package/dist/pregel/stream.d.ts +0 -40
  457. package/dist/pregel/utils/config.test.cjs +0 -214
  458. package/dist/pregel/utils/config.test.d.ts +0 -1
  459. package/dist/pregel/utils/config.test.js +0 -212
  460. package/dist/pregel/utils/config.test.js.map +0 -1
  461. package/dist/pregel/utils/subgraph.d.ts +0 -4
  462. package/dist/pregel/utils/subgraph.test.cjs +0 -83
  463. package/dist/pregel/utils/subgraph.test.d.ts +0 -1
  464. package/dist/pregel/utils/subgraph.test.js +0 -81
  465. package/dist/pregel/utils/subgraph.test.js.map +0 -1
  466. package/dist/pregel/validate.d.ts +0 -16
  467. package/dist/pregel/validate.test.cjs +0 -220
  468. package/dist/pregel/validate.test.d.ts +0 -1
  469. package/dist/pregel/validate.test.js +0 -218
  470. package/dist/pregel/validate.test.js.map +0 -1
  471. package/dist/pregel/write.test.cjs +0 -181
  472. package/dist/pregel/write.test.d.ts +0 -1
  473. package/dist/pregel/write.test.js +0 -179
  474. package/dist/pregel/write.test.js.map +0 -1
  475. package/dist/remote.js.map +0 -1
  476. package/dist/setup/async_local_storage.d.ts +0 -1
  477. package/dist/web.js.map +0 -1
  478. package/index.cjs +0 -1
  479. package/index.d.cts +0 -1
  480. package/index.d.ts +0 -1
  481. package/index.js +0 -1
  482. package/prebuilt.cjs +0 -1
  483. package/prebuilt.d.cts +0 -1
  484. package/prebuilt.d.ts +0 -1
  485. package/prebuilt.js +0 -1
  486. package/pregel.cjs +0 -1
  487. package/pregel.d.cts +0 -1
  488. package/pregel.d.ts +0 -1
  489. package/pregel.js +0 -1
  490. package/remote.cjs +0 -1
  491. package/remote.d.cts +0 -1
  492. package/remote.d.ts +0 -1
  493. package/remote.js +0 -1
  494. package/web.cjs +0 -1
  495. package/web.d.cts +0 -1
  496. package/web.d.ts +0 -1
  497. package/web.js +0 -1
  498. package/zod/schema.cjs +0 -1
  499. package/zod/schema.d.cts +0 -1
  500. package/zod/schema.d.ts +0 -1
  501. package/zod/schema.js +0 -1
  502. package/zod.cjs +0 -1
  503. package/zod.d.cts +0 -1
  504. package/zod.d.ts +0 -1
  505. package/zod.js +0 -1
@@ -1,801 +1,497 @@
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
+ /** @internal */
110
+ _interrupt;
111
+ /** @internal */
112
+ _writer;
113
+ constructor(fields, contextSchema) {
114
+ super();
115
+ if (isZodStateGraphArgsWithStateSchema(fields)) {
116
+ const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);
117
+ const inputDef = fields.input != null ? this._metaRegistry.getChannelsForSchema(fields.input) : stateDef;
118
+ const outputDef = fields.output != null ? this._metaRegistry.getChannelsForSchema(fields.output) : stateDef;
119
+ this._schemaDefinition = stateDef;
120
+ this._schemaRuntimeDefinition = fields.state;
121
+ this._inputDefinition = inputDef;
122
+ this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;
123
+ this._outputDefinition = outputDef;
124
+ this._outputRuntimeDefinition = fields.output ?? fields.state;
125
+ } else if ((0, __langchain_core_utils_types.isInteropZodObject)(fields)) {
126
+ const stateDef = this._metaRegistry.getChannelsForSchema(fields);
127
+ this._schemaDefinition = stateDef;
128
+ this._schemaRuntimeDefinition = fields;
129
+ this._inputDefinition = stateDef;
130
+ this._inputRuntimeDefinition = PartialStateSchema;
131
+ this._outputDefinition = stateDef;
132
+ this._outputRuntimeDefinition = fields;
133
+ } else if (isStateGraphArgsWithInputOutputSchemas(fields)) {
134
+ this._schemaDefinition = fields.input.spec;
135
+ this._inputDefinition = fields.input.spec;
136
+ this._outputDefinition = fields.output.spec;
137
+ } else if (isStateGraphArgsWithStateSchema(fields)) {
138
+ this._schemaDefinition = fields.stateSchema.spec;
139
+ this._inputDefinition = fields.input?.spec ?? this._schemaDefinition;
140
+ this._outputDefinition = fields.output?.spec ?? this._schemaDefinition;
141
+ } else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {
142
+ const spec = isAnnotationRoot(fields) ? fields.spec : fields;
143
+ this._schemaDefinition = spec;
144
+ } else if (isStateGraphArgs(fields)) {
145
+ const spec = _getChannels(fields.channels);
146
+ this._schemaDefinition = spec;
147
+ } else throw new Error("Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.");
148
+ this._inputDefinition ??= this._schemaDefinition;
149
+ this._outputDefinition ??= this._schemaDefinition;
150
+ this._addSchema(this._schemaDefinition);
151
+ this._addSchema(this._inputDefinition);
152
+ this._addSchema(this._outputDefinition);
153
+ function isOptions(options) {
154
+ return typeof options === "object" && options != null && !("spec" in options) && !(0, __langchain_core_utils_types.isInteropZodObject)(options);
155
+ }
156
+ if (isOptions(contextSchema)) {
157
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(contextSchema.context)) this._configRuntimeSchema = contextSchema.context;
158
+ } else if ((0, __langchain_core_utils_types.isInteropZodObject)(contextSchema)) this._configRuntimeSchema = contextSchema;
159
+ }
160
+ get allEdges() {
161
+ return new Set([...this.edges, ...Array.from(this.waitingEdges).flatMap(([starts, end]) => starts.map((start) => [start, end]))]);
162
+ }
163
+ _addSchema(stateDefinition) {
164
+ if (this._schemaDefinitions.has(stateDefinition)) return;
165
+ this._schemaDefinitions.set(stateDefinition, stateDefinition);
166
+ for (const [key, val] of Object.entries(stateDefinition)) {
167
+ let channel;
168
+ if (typeof val === "function") channel = val();
169
+ else channel = val;
170
+ if (this.channels[key] !== void 0) {
171
+ if (this.channels[key] !== channel) {
172
+ if (channel.lc_graph_name !== "LastValue") throw new Error(`Channel "${key}" already exists with a different type.`);
173
+ }
174
+ } else this.channels[key] = channel;
175
+ }
176
+ }
177
+ addNode(...args) {
178
+ function isMultipleNodes(args$1) {
179
+ return args$1.length >= 1 && typeof args$1[0] !== "string";
180
+ }
181
+ const nodes = isMultipleNodes(args) ? Array.isArray(args[0]) ? args[0] : Object.entries(args[0]).map(([key, action]) => [key, action]) : [[
182
+ args[0],
183
+ args[1],
184
+ args[2]
185
+ ]];
186
+ if (nodes.length === 0) throw new Error("No nodes provided in `addNode`");
187
+ for (const [key, action, options] of nodes) {
188
+ 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.`);
189
+ 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.`);
190
+ this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
191
+ if (key in this.nodes) throw new Error(`Node \`${key}\` already present.`);
192
+ if (key === require_constants.END || key === require_constants.START) throw new Error(`Node \`${key}\` is reserved.`);
193
+ let inputSpec = this._schemaDefinition;
194
+ if (options?.input !== void 0) {
195
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(options.input)) inputSpec = this._metaRegistry.getChannelsForSchema(options.input);
196
+ else if (options.input.spec !== void 0) inputSpec = options.input.spec;
197
+ }
198
+ if (inputSpec !== void 0) this._addSchema(inputSpec);
199
+ let runnable;
200
+ if (__langchain_core_runnables.Runnable.isRunnable(action)) runnable = action;
201
+ else if (typeof action === "function") runnable = new require_utils.RunnableCallable({
202
+ func: action,
203
+ name: key,
204
+ trace: false
205
+ });
206
+ else runnable = (0, __langchain_core_runnables._coerceToRunnable)(action);
207
+ let cachePolicy = options?.cachePolicy;
208
+ if (typeof cachePolicy === "boolean") cachePolicy = cachePolicy ? {} : void 0;
209
+ const nodeSpec = {
210
+ runnable,
211
+ retryPolicy: options?.retryPolicy,
212
+ cachePolicy,
213
+ metadata: options?.metadata,
214
+ input: inputSpec ?? this._schemaDefinition,
215
+ subgraphs: require_subgraph.isPregelLike(runnable) ? [runnable] : options?.subgraphs,
216
+ ends: options?.ends,
217
+ defer: options?.defer
218
+ };
219
+ this.nodes[key] = nodeSpec;
220
+ }
221
+ return this;
222
+ }
223
+ addEdge(startKey, endKey) {
224
+ if (typeof startKey === "string") return super.addEdge(startKey, endKey);
225
+ 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.");
226
+ for (const start of startKey) {
227
+ if (start === require_constants.END) throw new Error("END cannot be a start node");
228
+ if (!Object.keys(this.nodes).some((node) => node === start)) throw new Error(`Need to add a node named "${start}" first`);
229
+ }
230
+ if (endKey === require_constants.END) throw new Error("END cannot be an end node");
231
+ if (!Object.keys(this.nodes).some((node) => node === endKey)) throw new Error(`Need to add a node named "${endKey}" first`);
232
+ this.waitingEdges.add([startKey, endKey]);
233
+ return this;
234
+ }
235
+ addSequence(nodes) {
236
+ const parsedNodes = Array.isArray(nodes) ? nodes : Object.entries(nodes);
237
+ if (parsedNodes.length === 0) throw new Error("Sequence requires at least one node.");
238
+ let previousNode;
239
+ for (const [key, action, options] of parsedNodes) {
240
+ if (key in this.nodes) throw new Error(`Node names must be unique: node with the name "${key}" already exists.`);
241
+ const validKey = key;
242
+ this.addNode(validKey, action, options);
243
+ if (previousNode != null) this.addEdge(previousNode, validKey);
244
+ previousNode = validKey;
245
+ }
246
+ return this;
247
+ }
248
+ compile({ checkpointer, store, cache, interruptBefore, interruptAfter, name, description } = {}) {
249
+ this.validate([...Array.isArray(interruptBefore) ? interruptBefore : [], ...Array.isArray(interruptAfter) ? interruptAfter : []]);
250
+ const outputKeys = Object.keys(this._schemaDefinitions.get(this._outputDefinition));
251
+ const outputChannels = outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;
252
+ const streamKeys = Object.keys(this.channels);
253
+ const streamChannels = streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;
254
+ const compiled = new CompiledStateGraph({
255
+ builder: this,
256
+ checkpointer,
257
+ interruptAfter,
258
+ interruptBefore,
259
+ autoValidate: false,
260
+ nodes: {},
261
+ channels: {
262
+ ...this.channels,
263
+ [require_constants.START]: new require_ephemeral_value.EphemeralValue()
264
+ },
265
+ inputChannels: require_constants.START,
266
+ outputChannels,
267
+ streamChannels,
268
+ streamMode: "updates",
269
+ store,
270
+ cache,
271
+ name,
272
+ description
273
+ });
274
+ compiled.attachNode(require_constants.START);
275
+ for (const [key, node] of Object.entries(this.nodes)) compiled.attachNode(key, node);
276
+ compiled.attachBranch(require_constants.START, require_constants.SELF, _getControlBranch(), { withReader: false });
277
+ for (const [key] of Object.entries(this.nodes)) compiled.attachBranch(key, require_constants.SELF, _getControlBranch(), { withReader: false });
278
+ for (const [start, end] of this.edges) compiled.attachEdge(start, end);
279
+ for (const [starts, end] of this.waitingEdges) compiled.attachEdge(starts, end);
280
+ for (const [start, branches] of Object.entries(this.branches)) for (const [name$1, branch] of Object.entries(branches)) compiled.attachBranch(start, name$1, branch);
281
+ return compiled.validate();
282
+ }
283
+ };
456
284
  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;
285
+ const channels = {};
286
+ for (const [name, val] of Object.entries(schema)) if (name === ROOT) channels[name] = require_annotation.getChannel(val);
287
+ else channels[name] = require_annotation.getChannel(val);
288
+ return channels;
468
289
  }
469
290
  /**
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;
291
+ * Final result from building and compiling a {@link StateGraph}.
292
+ * Should not be instantiated directly, only using the StateGraph `.compile()`
293
+ * instance method.
294
+ */
295
+ var CompiledStateGraph = class extends require_graph.CompiledGraph {
296
+ /**
297
+ * The description of the compiled graph.
298
+ * This is used by the supervisor agent to describe the handoff to the agent.
299
+ */
300
+ description;
301
+ /** @internal */
302
+ _metaRegistry = require_meta.schemaMetaRegistry;
303
+ constructor({ description,...rest }) {
304
+ super(rest);
305
+ this.description = description;
306
+ }
307
+ attachNode(key, node) {
308
+ let outputKeys;
309
+ if (key === require_constants.START) outputKeys = Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([k]) => k);
310
+ else outputKeys = Object.keys(this.builder.channels);
311
+ function _getRoot(input) {
312
+ if (require_constants.isCommand(input)) {
313
+ if (input.graph === require_constants.Command.PARENT) return null;
314
+ return input._updateAsTuples();
315
+ } else if (Array.isArray(input) && input.length > 0 && input.some((i) => require_constants.isCommand(i))) {
316
+ const updates = [];
317
+ for (const i of input) if (require_constants.isCommand(i)) {
318
+ if (i.graph === require_constants.Command.PARENT) continue;
319
+ updates.push(...i._updateAsTuples());
320
+ } else updates.push([ROOT, i]);
321
+ return updates;
322
+ } else if (input != null) return [[ROOT, input]];
323
+ return null;
324
+ }
325
+ const nodeKey = key;
326
+ function _getUpdates(input) {
327
+ if (!input) return null;
328
+ else if (require_constants.isCommand(input)) {
329
+ if (input.graph === require_constants.Command.PARENT) return null;
330
+ return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));
331
+ } else if (Array.isArray(input) && input.length > 0 && input.some(require_constants.isCommand)) {
332
+ const updates = [];
333
+ for (const item of input) if (require_constants.isCommand(item)) {
334
+ if (item.graph === require_constants.Command.PARENT) continue;
335
+ updates.push(...item._updateAsTuples().filter(([k]) => outputKeys.includes(k)));
336
+ } else {
337
+ const itemUpdates = _getUpdates(item);
338
+ if (itemUpdates) updates.push(...itemUpdates ?? []);
339
+ }
340
+ return updates;
341
+ } else if (typeof input === "object" && !Array.isArray(input)) return Object.entries(input).filter(([k]) => outputKeys.includes(k));
342
+ else {
343
+ const typeofInput = Array.isArray(input) ? "array" : typeof input;
344
+ 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" });
345
+ }
346
+ }
347
+ const stateWriteEntries = [{
348
+ value: require_write.PASSTHROUGH,
349
+ mapper: new require_utils.RunnableCallable({
350
+ func: outputKeys.length && outputKeys[0] === ROOT ? _getRoot : _getUpdates,
351
+ trace: false,
352
+ recurse: false
353
+ })
354
+ }];
355
+ if (key === require_constants.START) this.nodes[key] = new require_read.PregelNode({
356
+ tags: [require_constants.TAG_HIDDEN],
357
+ triggers: [require_constants.START],
358
+ channels: [require_constants.START],
359
+ writers: [new require_write.ChannelWrite(stateWriteEntries, [require_constants.TAG_HIDDEN])]
360
+ });
361
+ else {
362
+ const inputDefinition = node?.input ?? this.builder._schemaDefinition;
363
+ const inputValues = Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map((k) => [k, k]));
364
+ const isSingleInput = Object.keys(inputValues).length === 1 && ROOT in inputValues;
365
+ const branchChannel = `branch:to:${key}`;
366
+ this.channels[branchChannel] = node?.defer ? new require_last_value.LastValueAfterFinish() : new require_ephemeral_value.EphemeralValue(false);
367
+ this.nodes[key] = new require_read.PregelNode({
368
+ triggers: [branchChannel],
369
+ channels: isSingleInput ? Object.keys(inputValues) : inputValues,
370
+ writers: [new require_write.ChannelWrite(stateWriteEntries, [require_constants.TAG_HIDDEN])],
371
+ mapper: isSingleInput ? void 0 : (input) => {
372
+ return Object.fromEntries(Object.entries(input).filter(([k]) => k in inputValues));
373
+ },
374
+ bound: node?.runnable,
375
+ metadata: node?.metadata,
376
+ retryPolicy: node?.retryPolicy,
377
+ cachePolicy: node?.cachePolicy,
378
+ subgraphs: node?.subgraphs,
379
+ ends: node?.ends
380
+ });
381
+ }
382
+ }
383
+ attachEdge(starts, end) {
384
+ if (end === require_constants.END) return;
385
+ if (typeof starts === "string") this.nodes[starts].writers.push(new require_write.ChannelWrite([{
386
+ channel: `branch:to:${end}`,
387
+ value: null
388
+ }], [require_constants.TAG_HIDDEN]));
389
+ else if (Array.isArray(starts)) {
390
+ const channelName = `join:${starts.join("+")}:${end}`;
391
+ 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));
392
+ this.nodes[end].triggers.push(channelName);
393
+ for (const start of starts) this.nodes[start].writers.push(new require_write.ChannelWrite([{
394
+ channel: channelName,
395
+ value: start
396
+ }], [require_constants.TAG_HIDDEN]));
397
+ }
398
+ }
399
+ attachBranch(start, _, branch, options = { withReader: true }) {
400
+ const branchWriter = async (packets, config) => {
401
+ const filteredPackets = packets.filter((p) => p !== require_constants.END);
402
+ if (!filteredPackets.length) return;
403
+ const writes = filteredPackets.map((p) => {
404
+ if (require_constants._isSend(p)) return p;
405
+ return {
406
+ channel: p === require_constants.END ? p : `branch:to:${p}`,
407
+ value: start
408
+ };
409
+ });
410
+ await require_write.ChannelWrite.doWrite({
411
+ ...config,
412
+ tags: (config.tags ?? []).concat([require_constants.TAG_HIDDEN])
413
+ }, writes);
414
+ };
415
+ this.nodes[start].writers.push(branch.run(branchWriter, options.withReader ? (config) => require_read.ChannelRead.doRead(config, this.streamChannels ?? this.outputChannels, true) : void 0));
416
+ }
417
+ async _validateInput(input) {
418
+ if (input == null) return input;
419
+ const schema = (() => {
420
+ const input$1 = this.builder._inputRuntimeDefinition;
421
+ const schema$1 = this.builder._schemaRuntimeDefinition;
422
+ const apply = (schema$2) => {
423
+ if (schema$2 == null) return void 0;
424
+ return this._metaRegistry.getExtendedChannelSchemas(schema$2, { withReducerSchema: true });
425
+ };
426
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(input$1)) return apply(input$1);
427
+ if (input$1 === PartialStateSchema) return (0, __langchain_core_utils_types.interopZodObjectPartial)(apply(schema$1));
428
+ return void 0;
429
+ })();
430
+ if (require_constants.isCommand(input)) {
431
+ const parsedInput = input;
432
+ if (input.update && schema != null) parsedInput.update = (0, __langchain_core_utils_types.interopParse)(schema, input.update);
433
+ return parsedInput;
434
+ }
435
+ if (schema != null) return (0, __langchain_core_utils_types.interopParse)(schema, input);
436
+ return input;
437
+ }
438
+ isInterrupted(input) {
439
+ return require_constants.isInterrupted(input);
440
+ }
441
+ async _validateContext(config) {
442
+ const configSchema = this.builder._configRuntimeSchema;
443
+ if ((0, __langchain_core_utils_types.isInteropZodObject)(configSchema)) (0, __langchain_core_utils_types.interopParse)(configSchema, config);
444
+ return config;
445
+ }
446
+ };
705
447
  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)));
448
+ 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
449
  }
712
450
  function isAnnotationRoot(obj) {
713
- return (typeof obj === "object" &&
714
- obj !== null &&
715
- "lc_graph_name" in obj &&
716
- obj.lc_graph_name === "AnnotationRoot");
451
+ return typeof obj === "object" && obj !== null && "lc_graph_name" in obj && obj.lc_graph_name === "AnnotationRoot";
717
452
  }
718
453
  function isStateGraphArgs(obj) {
719
- return (typeof obj === "object" &&
720
- obj !== null &&
721
- obj.channels !== undefined);
454
+ return typeof obj === "object" && obj !== null && obj.channels !== void 0;
722
455
  }
723
456
  function isStateGraphArgsWithStateSchema(obj) {
724
- return (typeof obj === "object" &&
725
- obj !== null &&
726
- obj.stateSchema !== undefined);
457
+ return typeof obj === "object" && obj !== null && obj.stateSchema !== void 0;
727
458
  }
728
459
  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);
460
+ return typeof obj === "object" && obj !== null && obj.stateSchema === void 0 && obj.input !== void 0 && obj.output !== void 0;
735
461
  }
736
462
  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;
463
+ if (typeof value !== "object" || value == null) return false;
464
+ if (!("state" in value) || !(0, __langchain_core_utils_types.isInteropZodObject)(value.state)) return false;
465
+ if ("input" in value && !(0, __langchain_core_utils_types.isInteropZodObject)(value.input)) return false;
466
+ if ("output" in value && !(0, __langchain_core_utils_types.isInteropZodObject)(value.output)) return false;
467
+ return true;
750
468
  }
751
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
752
469
  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;
470
+ if (require_constants._isSend(value)) return [value];
471
+ const commands = [];
472
+ if (require_constants.isCommand(value)) commands.push(value);
473
+ else if (Array.isArray(value)) commands.push(...value.filter(require_constants.isCommand));
474
+ const destinations = [];
475
+ for (const command of commands) {
476
+ if (command.graph === require_constants.Command.PARENT) throw new require_errors.ParentCommand(command);
477
+ if (require_constants._isSend(command.goto)) destinations.push(command.goto);
478
+ else if (typeof command.goto === "string") destinations.push(command.goto);
479
+ else if (Array.isArray(command.goto)) destinations.push(...command.goto);
480
+ }
481
+ return destinations;
781
482
  }
782
483
  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
- });
484
+ const CONTROL_BRANCH_PATH = new require_utils.RunnableCallable({
485
+ func: _controlBranch,
486
+ tags: [require_constants.TAG_HIDDEN],
487
+ trace: false,
488
+ recurse: false,
489
+ name: "<control_branch>"
490
+ });
491
+ return new require_graph.Branch({ path: CONTROL_BRANCH_PATH });
794
492
  }
795
- function typedNode(_state, _options) {
796
- return (func, options) => {
797
- Object.assign(func, { [Symbol.for("langgraph.state.node")]: options });
798
- return func;
799
- };
800
- }
801
- //# sourceMappingURL=state.js.map
493
+
494
+ //#endregion
495
+ exports.CompiledStateGraph = CompiledStateGraph;
496
+ exports.StateGraph = StateGraph;
497
+ //# sourceMappingURL=state.cjs.map