@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,727 +1,423 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompiledGraph = exports.Graph = exports.Branch = void 0;
4
- /* eslint-disable @typescript-eslint/no-use-before-define */
5
- const runnables_1 = require("@langchain/core/runnables");
6
- const graph_1 = require("@langchain/core/runnables/graph");
7
- const zod_1 = require("zod");
8
- const uuid_1 = require("uuid");
9
- const read_js_1 = require("../pregel/read.cjs");
10
- const index_js_1 = require("../pregel/index.cjs");
11
- const ephemeral_value_js_1 = require("../channels/ephemeral_value.cjs");
12
- const write_js_1 = require("../pregel/write.cjs");
13
- const constants_js_1 = require("../constants.cjs");
14
- const utils_js_1 = require("../utils.cjs");
15
- const errors_js_1 = require("../errors.cjs");
16
- const subgraph_js_1 = require("../pregel/utils/subgraph.cjs");
17
- class Branch {
18
- constructor(options) {
19
- Object.defineProperty(this, "path", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "ends", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- if (runnables_1.Runnable.isRunnable(options.path)) {
32
- this.path = options.path;
33
- }
34
- else {
35
- this.path = (0, runnables_1._coerceToRunnable)(options.path).withConfig({ runName: `Branch` });
36
- }
37
- this.ends = Array.isArray(options.pathMap)
38
- ? options.pathMap.reduce((acc, n) => {
39
- acc[n] = n;
40
- return acc;
41
- }, {})
42
- : options.pathMap;
43
- }
44
- run(writer, reader) {
45
- return write_js_1.ChannelWrite.registerWriter(new utils_js_1.RunnableCallable({
46
- name: "<branch_run>",
47
- trace: false,
48
- func: async (input, config) => {
49
- try {
50
- return await this._route(input, config, writer, reader);
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- }
53
- catch (e) {
54
- // Detect & warn if NodeInterrupt is thrown in a conditional edge
55
- if (e.name === errors_js_1.NodeInterrupt.unminifiable_name) {
56
- console.warn("[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.\n" +
57
- "NodeInterrupt should only be thrown inside a node, not in edge conditions.");
58
- }
59
- throw e;
60
- }
61
- },
62
- }));
63
- }
64
- async _route(input, config, writer, reader
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- ) {
67
- let result = await this.path.invoke(reader ? reader(config) : input, config);
68
- if (!Array.isArray(result)) {
69
- result = [result];
70
- }
71
- let destinations;
72
- if (this.ends) {
73
- destinations = result.map((r) => ((0, constants_js_1._isSend)(r) ? r : this.ends[r]));
74
- }
75
- else {
76
- destinations = result;
77
- }
78
- if (destinations.some((dest) => !dest)) {
79
- throw new Error("Branch condition returned unknown or null destination");
80
- }
81
- if (destinations.filter(constants_js_1._isSend).some((packet) => packet.node === constants_js_1.END)) {
82
- throw new errors_js_1.InvalidUpdateError("Cannot send a packet to the END node");
83
- }
84
- const writeResult = await writer(destinations, config);
85
- return writeResult ?? input;
86
- }
87
- }
88
- exports.Branch = Branch;
89
- class Graph {
90
- constructor() {
91
- Object.defineProperty(this, "nodes", {
92
- enumerable: true,
93
- configurable: true,
94
- writable: true,
95
- value: void 0
96
- });
97
- Object.defineProperty(this, "edges", {
98
- enumerable: true,
99
- configurable: true,
100
- writable: true,
101
- value: void 0
102
- });
103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
- Object.defineProperty(this, "branches", {
105
- enumerable: true,
106
- configurable: true,
107
- writable: true,
108
- value: void 0
109
- });
110
- Object.defineProperty(this, "entryPoint", {
111
- enumerable: true,
112
- configurable: true,
113
- writable: true,
114
- value: void 0
115
- });
116
- Object.defineProperty(this, "compiled", {
117
- enumerable: true,
118
- configurable: true,
119
- writable: true,
120
- value: false
121
- });
122
- this.nodes = {};
123
- this.edges = new Set();
124
- this.branches = {};
125
- }
126
- warnIfCompiled(message) {
127
- if (this.compiled) {
128
- console.warn(message);
129
- }
130
- }
131
- get allEdges() {
132
- return this.edges;
133
- }
134
- addNode(...args) {
135
- function isMutlipleNodes(args) {
136
- return args.length >= 1 && typeof args[0] !== "string";
137
- }
138
- const nodes = (isMutlipleNodes(args) // eslint-disable-line no-nested-ternary
139
- ? Array.isArray(args[0])
140
- ? args[0]
141
- : Object.entries(args[0])
142
- : [[args[0], args[1], args[2]]]);
143
- if (nodes.length === 0) {
144
- throw new Error("No nodes provided in `addNode`");
145
- }
146
- for (const [key, action, options] of nodes) {
147
- for (const reservedChar of [
148
- constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
149
- constants_js_1.CHECKPOINT_NAMESPACE_END,
150
- ]) {
151
- if (key.includes(reservedChar)) {
152
- throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
153
- }
154
- }
155
- this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
156
- if (key in this.nodes) {
157
- throw new Error(`Node \`${key}\` already present.`);
158
- }
159
- if (key === constants_js_1.END) {
160
- throw new Error(`Node \`${key}\` is reserved.`);
161
- }
162
- const runnable = (0, runnables_1._coerceToRunnable)(
163
- // Account for arbitrary state due to Send API
164
- action);
165
- this.nodes[key] = {
166
- runnable,
167
- metadata: options?.metadata,
168
- subgraphs: (0, subgraph_js_1.isPregelLike)(runnable) ? [runnable] : options?.subgraphs,
169
- ends: options?.ends,
170
- };
171
- }
172
- return this;
173
- }
174
- addEdge(startKey, endKey) {
175
- this.warnIfCompiled(`Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
176
- if (startKey === constants_js_1.END) {
177
- throw new Error("END cannot be a start node");
178
- }
179
- if (endKey === constants_js_1.START) {
180
- throw new Error("START cannot be an end node");
181
- }
182
- if (Array.from(this.edges).some(([start]) => start === startKey) &&
183
- !("channels" in this)) {
184
- throw new Error(`Already found path for ${startKey}. For multiple edges, use StateGraph.`);
185
- }
186
- this.edges.add([startKey, endKey]);
187
- return this;
188
- }
189
- addConditionalEdges(source, path, pathMap) {
190
- const options = typeof source === "object" ? source : { source, path: path, pathMap };
191
- this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
192
- if (!runnables_1.Runnable.isRunnable(options.path)) {
193
- const pathDisplayValues = Array.isArray(options.pathMap)
194
- ? options.pathMap.join(",")
195
- : Object.keys(options.pathMap ?? {}).join(",");
196
- options.path = (0, runnables_1._coerceToRunnable)(options.path).withConfig({
197
- runName: `Branch<${options.source}${pathDisplayValues !== "" ? `,${pathDisplayValues}` : ""}>`.slice(0, 63),
198
- });
199
- }
200
- // find a name for condition
201
- const name = options.path.getName() === "RunnableLambda"
202
- ? "condition"
203
- : options.path.getName();
204
- // validate condition
205
- if (this.branches[options.source] && this.branches[options.source][name]) {
206
- throw new Error(`Condition \`${name}\` already present for node \`${source}\``);
207
- }
208
- // save it
209
- this.branches[options.source] ??= {};
210
- this.branches[options.source][name] = new Branch(options);
211
- return this;
212
- }
213
- /**
214
- * @deprecated use `addEdge(START, key)` instead
215
- */
216
- setEntryPoint(key) {
217
- this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
218
- return this.addEdge(constants_js_1.START, key);
219
- }
220
- /**
221
- * @deprecated use `addEdge(key, END)` instead
222
- */
223
- setFinishPoint(key) {
224
- this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
225
- return this.addEdge(key, constants_js_1.END);
226
- }
227
- compile({ checkpointer, interruptBefore, interruptAfter, name, } = {}) {
228
- // validate the graph
229
- this.validate([
230
- ...(Array.isArray(interruptBefore) ? interruptBefore : []),
231
- ...(Array.isArray(interruptAfter) ? interruptAfter : []),
232
- ]);
233
- // create empty compiled graph
234
- const compiled = new CompiledGraph({
235
- builder: this,
236
- checkpointer,
237
- interruptAfter,
238
- interruptBefore,
239
- autoValidate: false,
240
- nodes: {},
241
- channels: {
242
- [constants_js_1.START]: new ephemeral_value_js_1.EphemeralValue(),
243
- [constants_js_1.END]: new ephemeral_value_js_1.EphemeralValue(),
244
- },
245
- inputChannels: constants_js_1.START,
246
- outputChannels: constants_js_1.END,
247
- streamChannels: [],
248
- streamMode: "values",
249
- name,
250
- });
251
- // attach nodes, edges and branches
252
- for (const [key, node] of Object.entries(this.nodes)) {
253
- compiled.attachNode(key, node);
254
- }
255
- for (const [start, end] of this.edges) {
256
- compiled.attachEdge(start, end);
257
- }
258
- for (const [start, branches] of Object.entries(this.branches)) {
259
- for (const [name, branch] of Object.entries(branches)) {
260
- compiled.attachBranch(start, name, branch);
261
- }
262
- }
263
- return compiled.validate();
264
- }
265
- validate(interrupt) {
266
- // assemble sources
267
- const allSources = new Set([...this.allEdges].map(([src, _]) => src));
268
- for (const [start] of Object.entries(this.branches)) {
269
- allSources.add(start);
270
- }
271
- // validate sources
272
- for (const source of allSources) {
273
- if (source !== constants_js_1.START && !(source in this.nodes)) {
274
- throw new Error(`Found edge starting at unknown node \`${source}\``);
275
- }
276
- }
277
- // assemble targets
278
- const allTargets = new Set([...this.allEdges].map(([_, target]) => target));
279
- for (const [start, branches] of Object.entries(this.branches)) {
280
- for (const branch of Object.values(branches)) {
281
- if (branch.ends != null) {
282
- for (const end of Object.values(branch.ends)) {
283
- allTargets.add(end);
284
- }
285
- }
286
- else {
287
- allTargets.add(constants_js_1.END);
288
- for (const node of Object.keys(this.nodes)) {
289
- if (node !== start) {
290
- allTargets.add(node);
291
- }
292
- }
293
- }
294
- }
295
- }
296
- for (const node of Object.values(this.nodes)) {
297
- for (const target of node.ends ?? []) {
298
- allTargets.add(target);
299
- }
300
- }
301
- // validate targets
302
- for (const node of Object.keys(this.nodes)) {
303
- if (!allTargets.has(node)) {
304
- throw new errors_js_1.UnreachableNodeError([
305
- `Node \`${node}\` is not reachable.`,
306
- "",
307
- "If you are returning Command objects from your node,",
308
- 'make sure you are passing names of potential destination nodes as an "ends" array',
309
- 'into ".addNode(..., { ends: ["node1", "node2"] })".',
310
- ].join("\n"), {
311
- lc_error_code: "UNREACHABLE_NODE",
312
- });
313
- }
314
- }
315
- for (const target of allTargets) {
316
- if (target !== constants_js_1.END && !(target in this.nodes)) {
317
- throw new Error(`Found edge ending at unknown node \`${target}\``);
318
- }
319
- }
320
- // validate interrupts
321
- if (interrupt) {
322
- for (const node of interrupt) {
323
- if (!(node in this.nodes)) {
324
- throw new Error(`Interrupt node \`${node}\` is not present`);
325
- }
326
- }
327
- }
328
- this.compiled = true;
329
- }
330
- }
331
- exports.Graph = Graph;
332
- class CompiledGraph extends index_js_1.Pregel {
333
- constructor({ builder, ...rest }) {
334
- super(rest);
335
- Object.defineProperty(this, "builder", {
336
- enumerable: true,
337
- configurable: true,
338
- writable: true,
339
- value: void 0
340
- });
341
- this.builder = builder;
342
- }
343
- attachNode(key, node) {
344
- this.channels[key] = new ephemeral_value_js_1.EphemeralValue();
345
- this.nodes[key] = new read_js_1.PregelNode({
346
- channels: [],
347
- triggers: [],
348
- metadata: node.metadata,
349
- subgraphs: node.subgraphs,
350
- ends: node.ends,
351
- })
352
- .pipe(node.runnable)
353
- .pipe(new write_js_1.ChannelWrite([{ channel: key, value: write_js_1.PASSTHROUGH }], [constants_js_1.TAG_HIDDEN]));
354
- this.streamChannels.push(key);
355
- }
356
- attachEdge(start, end) {
357
- if (end === constants_js_1.END) {
358
- if (start === constants_js_1.START) {
359
- throw new Error("Cannot have an edge from START to END");
360
- }
361
- this.nodes[start].writers.push(new write_js_1.ChannelWrite([{ channel: constants_js_1.END, value: write_js_1.PASSTHROUGH }], [constants_js_1.TAG_HIDDEN]));
362
- }
363
- else {
364
- this.nodes[end].triggers.push(start);
365
- this.nodes[end].channels.push(start);
366
- }
367
- }
368
- attachBranch(start, name, branch) {
369
- // add hidden start node
370
- if (start === constants_js_1.START && !this.nodes[constants_js_1.START]) {
371
- this.nodes[constants_js_1.START] = index_js_1.Channel.subscribeTo(constants_js_1.START, { tags: [constants_js_1.TAG_HIDDEN] });
372
- }
373
- // attach branch writer
374
- this.nodes[start].pipe(branch.run((dests) => {
375
- const writes = dests.map((dest) => {
376
- if ((0, constants_js_1._isSend)(dest)) {
377
- return dest;
378
- }
379
- return {
380
- channel: dest === constants_js_1.END ? constants_js_1.END : `branch:${start}:${name}:${dest}`,
381
- value: write_js_1.PASSTHROUGH,
382
- };
383
- });
384
- return new write_js_1.ChannelWrite(writes, [constants_js_1.TAG_HIDDEN]);
385
- }));
386
- // attach branch readers
387
- const ends = branch.ends
388
- ? Object.values(branch.ends)
389
- : Object.keys(this.nodes);
390
- for (const end of ends) {
391
- if (end !== constants_js_1.END) {
392
- const channelName = `branch:${start}:${name}:${end}`;
393
- this.channels[channelName] =
394
- new ephemeral_value_js_1.EphemeralValue();
395
- this.nodes[end].triggers.push(channelName);
396
- this.nodes[end].channels.push(channelName);
397
- }
398
- }
399
- }
400
- /**
401
- * Returns a drawable representation of the computation graph.
402
- */
403
- async getGraphAsync(config) {
404
- const xray = config?.xray;
405
- const graph = new graph_1.Graph();
406
- const startNodes = {
407
- [constants_js_1.START]: graph.addNode({
408
- schema: zod_1.z.any(),
409
- }, constants_js_1.START),
410
- };
411
- const endNodes = {};
412
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
413
- let subgraphs = {};
414
- if (xray) {
415
- subgraphs = Object.fromEntries((await (0, utils_js_1.gatherIterator)(this.getSubgraphsAsync())).filter(
416
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
417
- (x) => isCompiledGraph(x[1])));
418
- }
419
- function addEdge(start, end, label, conditional = false) {
420
- if (end === constants_js_1.END && endNodes[constants_js_1.END] === undefined) {
421
- endNodes[constants_js_1.END] = graph.addNode({ schema: zod_1.z.any() }, constants_js_1.END);
422
- }
423
- if (startNodes[start] === undefined) {
424
- return;
425
- }
426
- if (endNodes[end] === undefined) {
427
- throw new Error(`End node ${end} not found!`);
428
- }
429
- return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : undefined, conditional);
430
- }
431
- for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
432
- const displayKey = _escapeMermaidKeywords(key);
433
- const node = nodeSpec.runnable;
434
- const metadata = nodeSpec.metadata ?? {};
435
- if (this.interruptBefore?.includes(key) &&
436
- this.interruptAfter?.includes(key)) {
437
- metadata.__interrupt = "before,after";
438
- }
439
- else if (this.interruptBefore?.includes(key)) {
440
- metadata.__interrupt = "before";
441
- }
442
- else if (this.interruptAfter?.includes(key)) {
443
- metadata.__interrupt = "after";
444
- }
445
- if (xray) {
446
- const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
447
- const drawableSubgraph = subgraphs[key] !== undefined
448
- ? await subgraphs[key].getGraphAsync({
449
- ...config,
450
- xray: newXrayValue,
451
- })
452
- : node.getGraph(config);
453
- drawableSubgraph.trimFirstNode();
454
- drawableSubgraph.trimLastNode();
455
- if (Object.keys(drawableSubgraph.nodes).length > 1) {
456
- const [e, s] = graph.extend(drawableSubgraph, displayKey);
457
- if (e === undefined) {
458
- throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
459
- }
460
- // TODO: Remove default name once we stop supporting core 0.2.0
461
- // eslint-disable-next-line no-inner-declarations
462
- function _isRunnableInterface(
463
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
464
- thing) {
465
- return thing ? thing.lc_runnable : false;
466
- }
467
- // eslint-disable-next-line no-inner-declarations
468
- function _nodeDataStr(id, data) {
469
- if (id !== undefined && !(0, uuid_1.validate)(id)) {
470
- return id;
471
- }
472
- else if (_isRunnableInterface(data)) {
473
- try {
474
- let dataStr = data.getName();
475
- dataStr = dataStr.startsWith("Runnable")
476
- ? dataStr.slice("Runnable".length)
477
- : dataStr;
478
- return dataStr;
479
- }
480
- catch (error) {
481
- return data.getName();
482
- }
483
- }
484
- else {
485
- return data.name ?? "UnknownSchema";
486
- }
487
- }
488
- // TODO: Remove casts when we stop supporting core 0.2.0
489
- if (s !== undefined) {
490
- startNodes[displayKey] = {
491
- name: _nodeDataStr(s.id, s.data),
492
- ...s,
493
- };
494
- }
495
- endNodes[displayKey] = {
496
- name: _nodeDataStr(e.id, e.data),
497
- ...e,
498
- };
499
- }
500
- else {
501
- // TODO: Remove when we stop supporting core 0.2.0
502
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
503
- // @ts-ignore
504
- const newNode = graph.addNode(node, displayKey, metadata);
505
- startNodes[displayKey] = newNode;
506
- endNodes[displayKey] = newNode;
507
- }
508
- }
509
- else {
510
- // TODO: Remove when we stop supporting core 0.2.0
511
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
512
- // @ts-ignore
513
- const newNode = graph.addNode(node, displayKey, metadata);
514
- startNodes[displayKey] = newNode;
515
- endNodes[displayKey] = newNode;
516
- }
517
- }
518
- const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
519
- if (a < b) {
520
- return -1;
521
- }
522
- else if (b > a) {
523
- return 1;
524
- }
525
- else {
526
- return 0;
527
- }
528
- });
529
- for (const [start, end] of sortedEdges) {
530
- addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
531
- }
532
- for (const [start, branches] of Object.entries(this.builder.branches)) {
533
- const defaultEnds = {
534
- ...Object.fromEntries(Object.keys(this.builder.nodes)
535
- .filter((k) => k !== start)
536
- .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
537
- [constants_js_1.END]: constants_js_1.END,
538
- };
539
- for (const branch of Object.values(branches)) {
540
- let ends;
541
- if (branch.ends !== undefined) {
542
- ends = branch.ends;
543
- }
544
- else {
545
- ends = defaultEnds;
546
- }
547
- for (const [label, end] of Object.entries(ends)) {
548
- addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
549
- }
550
- }
551
- }
552
- for (const [key, node] of Object.entries(this.builder.nodes)) {
553
- if (node.ends !== undefined) {
554
- for (const end of node.ends) {
555
- addEdge(_escapeMermaidKeywords(key), _escapeMermaidKeywords(end), undefined, true);
556
- }
557
- }
558
- }
559
- return graph;
560
- }
561
- /**
562
- * Returns a drawable representation of the computation graph.
563
- *
564
- * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.
565
- */
566
- getGraph(config) {
567
- const xray = config?.xray;
568
- const graph = new graph_1.Graph();
569
- const startNodes = {
570
- [constants_js_1.START]: graph.addNode({
571
- schema: zod_1.z.any(),
572
- }, constants_js_1.START),
573
- };
574
- const endNodes = {};
575
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
576
- let subgraphs = {};
577
- if (xray) {
578
- subgraphs = Object.fromEntries((0, utils_js_1.gatherIteratorSync)(this.getSubgraphs()).filter(
579
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
580
- (x) => isCompiledGraph(x[1])));
581
- }
582
- function addEdge(start, end, label, conditional = false) {
583
- if (end === constants_js_1.END && endNodes[constants_js_1.END] === undefined) {
584
- endNodes[constants_js_1.END] = graph.addNode({ schema: zod_1.z.any() }, constants_js_1.END);
585
- }
586
- return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : undefined, conditional);
587
- }
588
- for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
589
- const displayKey = _escapeMermaidKeywords(key);
590
- const node = nodeSpec.runnable;
591
- const metadata = nodeSpec.metadata ?? {};
592
- if (this.interruptBefore?.includes(key) &&
593
- this.interruptAfter?.includes(key)) {
594
- metadata.__interrupt = "before,after";
595
- }
596
- else if (this.interruptBefore?.includes(key)) {
597
- metadata.__interrupt = "before";
598
- }
599
- else if (this.interruptAfter?.includes(key)) {
600
- metadata.__interrupt = "after";
601
- }
602
- if (xray) {
603
- const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
604
- const drawableSubgraph = subgraphs[key] !== undefined
605
- ? subgraphs[key].getGraph({
606
- ...config,
607
- xray: newXrayValue,
608
- })
609
- : node.getGraph(config);
610
- drawableSubgraph.trimFirstNode();
611
- drawableSubgraph.trimLastNode();
612
- if (Object.keys(drawableSubgraph.nodes).length > 1) {
613
- const [e, s] = graph.extend(drawableSubgraph, displayKey);
614
- if (e === undefined) {
615
- throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
616
- }
617
- // TODO: Remove default name once we stop supporting core 0.2.0
618
- // eslint-disable-next-line no-inner-declarations
619
- function _isRunnableInterface(
620
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
621
- thing) {
622
- return thing ? thing.lc_runnable : false;
623
- }
624
- // eslint-disable-next-line no-inner-declarations
625
- function _nodeDataStr(id, data) {
626
- if (id !== undefined && !(0, uuid_1.validate)(id)) {
627
- return id;
628
- }
629
- else if (_isRunnableInterface(data)) {
630
- try {
631
- let dataStr = data.getName();
632
- dataStr = dataStr.startsWith("Runnable")
633
- ? dataStr.slice("Runnable".length)
634
- : dataStr;
635
- return dataStr;
636
- }
637
- catch (error) {
638
- return data.getName();
639
- }
640
- }
641
- else {
642
- return data.name ?? "UnknownSchema";
643
- }
644
- }
645
- // TODO: Remove casts when we stop supporting core 0.2.0
646
- if (s !== undefined) {
647
- startNodes[displayKey] = {
648
- name: _nodeDataStr(s.id, s.data),
649
- ...s,
650
- };
651
- }
652
- endNodes[displayKey] = {
653
- name: _nodeDataStr(e.id, e.data),
654
- ...e,
655
- };
656
- }
657
- else {
658
- // TODO: Remove when we stop supporting core 0.2.0
659
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
660
- // @ts-ignore
661
- const newNode = graph.addNode(node, displayKey, metadata);
662
- startNodes[displayKey] = newNode;
663
- endNodes[displayKey] = newNode;
664
- }
665
- }
666
- else {
667
- // TODO: Remove when we stop supporting core 0.2.0
668
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
669
- // @ts-ignore
670
- const newNode = graph.addNode(node, displayKey, metadata);
671
- startNodes[displayKey] = newNode;
672
- endNodes[displayKey] = newNode;
673
- }
674
- }
675
- const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
676
- if (a < b) {
677
- return -1;
678
- }
679
- else if (b > a) {
680
- return 1;
681
- }
682
- else {
683
- return 0;
684
- }
685
- });
686
- for (const [start, end] of sortedEdges) {
687
- addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
688
- }
689
- for (const [start, branches] of Object.entries(this.builder.branches)) {
690
- const defaultEnds = {
691
- ...Object.fromEntries(Object.keys(this.builder.nodes)
692
- .filter((k) => k !== start)
693
- .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
694
- [constants_js_1.END]: constants_js_1.END,
695
- };
696
- for (const branch of Object.values(branches)) {
697
- let ends;
698
- if (branch.ends !== undefined) {
699
- ends = branch.ends;
700
- }
701
- else {
702
- ends = defaultEnds;
703
- }
704
- for (const [label, end] of Object.entries(ends)) {
705
- addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
706
- }
707
- }
708
- }
709
- return graph;
710
- }
711
- }
712
- exports.CompiledGraph = CompiledGraph;
713
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('../errors.cjs');
3
+ const require_constants = require('../constants.cjs');
4
+ const require_utils = require('../utils.cjs');
5
+ const require_write = require('../pregel/write.cjs');
6
+ const require_read = require('../pregel/read.cjs');
7
+ const require_subgraph = require('../pregel/utils/subgraph.cjs');
8
+ const require_pregel_index = require('../pregel/index.cjs');
9
+ const require_ephemeral_value = require('../channels/ephemeral_value.cjs');
10
+ const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
11
+ const __langchain_core_runnables_graph = require_rolldown_runtime.__toESM(require("@langchain/core/runnables/graph"));
12
+ const zod = require_rolldown_runtime.__toESM(require("zod"));
13
+ const uuid = require_rolldown_runtime.__toESM(require("uuid"));
14
+
15
+ //#region src/graph/graph.ts
16
+ var Branch = class {
17
+ path;
18
+ ends;
19
+ constructor(options) {
20
+ if (__langchain_core_runnables.Runnable.isRunnable(options.path)) this.path = options.path;
21
+ else this.path = (0, __langchain_core_runnables._coerceToRunnable)(options.path).withConfig({ runName: `Branch` });
22
+ this.ends = Array.isArray(options.pathMap) ? options.pathMap.reduce((acc, n) => {
23
+ acc[n] = n;
24
+ return acc;
25
+ }, {}) : options.pathMap;
26
+ }
27
+ run(writer, reader) {
28
+ return require_write.ChannelWrite.registerWriter(new require_utils.RunnableCallable({
29
+ name: "<branch_run>",
30
+ trace: false,
31
+ func: async (input, config) => {
32
+ try {
33
+ return await this._route(input, config, writer, reader);
34
+ } catch (e) {
35
+ if (e.name === require_errors.NodeInterrupt.unminifiable_name) console.warn("[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.\nNodeInterrupt should only be thrown inside a node, not in edge conditions.");
36
+ throw e;
37
+ }
38
+ }
39
+ }));
40
+ }
41
+ async _route(input, config, writer, reader) {
42
+ let result = await this.path.invoke(reader ? reader(config) : input, config);
43
+ if (!Array.isArray(result)) result = [result];
44
+ let destinations;
45
+ if (this.ends) destinations = result.map((r) => require_constants._isSend(r) ? r : this.ends[r]);
46
+ else destinations = result;
47
+ if (destinations.some((dest) => !dest)) throw new Error("Branch condition returned unknown or null destination");
48
+ if (destinations.filter(require_constants._isSend).some((packet) => packet.node === require_constants.END)) throw new require_errors.InvalidUpdateError("Cannot send a packet to the END node");
49
+ const writeResult = await writer(destinations, config);
50
+ return writeResult ?? input;
51
+ }
52
+ };
53
+ var Graph = class {
54
+ nodes;
55
+ edges;
56
+ branches;
57
+ entryPoint;
58
+ compiled = false;
59
+ constructor() {
60
+ this.nodes = {};
61
+ this.edges = /* @__PURE__ */ new Set();
62
+ this.branches = {};
63
+ }
64
+ warnIfCompiled(message) {
65
+ if (this.compiled) console.warn(message);
66
+ }
67
+ get allEdges() {
68
+ return this.edges;
69
+ }
70
+ addNode(...args) {
71
+ function isMutlipleNodes(args$1) {
72
+ return args$1.length >= 1 && typeof args$1[0] !== "string";
73
+ }
74
+ const nodes = isMutlipleNodes(args) ? Array.isArray(args[0]) ? args[0] : Object.entries(args[0]) : [[
75
+ args[0],
76
+ args[1],
77
+ args[2]
78
+ ]];
79
+ if (nodes.length === 0) throw new Error("No nodes provided in `addNode`");
80
+ for (const [key, action, options] of nodes) {
81
+ 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.`);
82
+ this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
83
+ if (key in this.nodes) throw new Error(`Node \`${key}\` already present.`);
84
+ if (key === require_constants.END) throw new Error(`Node \`${key}\` is reserved.`);
85
+ const runnable = (0, __langchain_core_runnables._coerceToRunnable)(action);
86
+ this.nodes[key] = {
87
+ runnable,
88
+ metadata: options?.metadata,
89
+ subgraphs: require_subgraph.isPregelLike(runnable) ? [runnable] : options?.subgraphs,
90
+ ends: options?.ends
91
+ };
92
+ }
93
+ return this;
94
+ }
95
+ addEdge(startKey, endKey) {
96
+ this.warnIfCompiled(`Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
97
+ if (startKey === require_constants.END) throw new Error("END cannot be a start node");
98
+ if (endKey === require_constants.START) throw new Error("START cannot be an end node");
99
+ if (Array.from(this.edges).some(([start]) => start === startKey) && !("channels" in this)) throw new Error(`Already found path for ${startKey}. For multiple edges, use StateGraph.`);
100
+ this.edges.add([startKey, endKey]);
101
+ return this;
102
+ }
103
+ addConditionalEdges(source, path, pathMap) {
104
+ const options = typeof source === "object" ? source : {
105
+ source,
106
+ path,
107
+ pathMap
108
+ };
109
+ this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
110
+ if (!__langchain_core_runnables.Runnable.isRunnable(options.path)) {
111
+ const pathDisplayValues = Array.isArray(options.pathMap) ? options.pathMap.join(",") : Object.keys(options.pathMap ?? {}).join(",");
112
+ options.path = (0, __langchain_core_runnables._coerceToRunnable)(options.path).withConfig({ runName: `Branch<${options.source}${pathDisplayValues !== "" ? `,${pathDisplayValues}` : ""}>`.slice(0, 63) });
113
+ }
114
+ const name = options.path.getName() === "RunnableLambda" ? "condition" : options.path.getName();
115
+ if (this.branches[options.source] && this.branches[options.source][name]) throw new Error(`Condition \`${name}\` already present for node \`${source}\``);
116
+ this.branches[options.source] ??= {};
117
+ this.branches[options.source][name] = new Branch(options);
118
+ return this;
119
+ }
120
+ /**
121
+ * @deprecated use `addEdge(START, key)` instead
122
+ */
123
+ setEntryPoint(key) {
124
+ this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
125
+ return this.addEdge(require_constants.START, key);
126
+ }
127
+ /**
128
+ * @deprecated use `addEdge(key, END)` instead
129
+ */
130
+ setFinishPoint(key) {
131
+ this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
132
+ return this.addEdge(key, require_constants.END);
133
+ }
134
+ compile({ checkpointer, interruptBefore, interruptAfter, name } = {}) {
135
+ this.validate([...Array.isArray(interruptBefore) ? interruptBefore : [], ...Array.isArray(interruptAfter) ? interruptAfter : []]);
136
+ const compiled = new CompiledGraph({
137
+ builder: this,
138
+ checkpointer,
139
+ interruptAfter,
140
+ interruptBefore,
141
+ autoValidate: false,
142
+ nodes: {},
143
+ channels: {
144
+ [require_constants.START]: new require_ephemeral_value.EphemeralValue(),
145
+ [require_constants.END]: new require_ephemeral_value.EphemeralValue()
146
+ },
147
+ inputChannels: require_constants.START,
148
+ outputChannels: require_constants.END,
149
+ streamChannels: [],
150
+ streamMode: "values",
151
+ name
152
+ });
153
+ for (const [key, node] of Object.entries(this.nodes)) compiled.attachNode(key, node);
154
+ for (const [start, end] of this.edges) compiled.attachEdge(start, end);
155
+ for (const [start, branches] of Object.entries(this.branches)) for (const [name$1, branch] of Object.entries(branches)) compiled.attachBranch(start, name$1, branch);
156
+ return compiled.validate();
157
+ }
158
+ validate(interrupt) {
159
+ const allSources = new Set([...this.allEdges].map(([src, _]) => src));
160
+ for (const [start] of Object.entries(this.branches)) allSources.add(start);
161
+ for (const source of allSources) if (source !== require_constants.START && !(source in this.nodes)) throw new Error(`Found edge starting at unknown node \`${source}\``);
162
+ const allTargets = new Set([...this.allEdges].map(([_, target]) => target));
163
+ for (const [start, branches] of Object.entries(this.branches)) for (const branch of Object.values(branches)) if (branch.ends != null) for (const end of Object.values(branch.ends)) allTargets.add(end);
164
+ else {
165
+ allTargets.add(require_constants.END);
166
+ for (const node of Object.keys(this.nodes)) if (node !== start) allTargets.add(node);
167
+ }
168
+ for (const node of Object.values(this.nodes)) for (const target of node.ends ?? []) allTargets.add(target);
169
+ for (const node of Object.keys(this.nodes)) if (!allTargets.has(node)) throw new require_errors.UnreachableNodeError([
170
+ `Node \`${node}\` is not reachable.`,
171
+ "",
172
+ "If you are returning Command objects from your node,",
173
+ "make sure you are passing names of potential destination nodes as an \"ends\" array",
174
+ "into \".addNode(..., { ends: [\"node1\", \"node2\"] })\"."
175
+ ].join("\n"), { lc_error_code: "UNREACHABLE_NODE" });
176
+ for (const target of allTargets) if (target !== require_constants.END && !(target in this.nodes)) throw new Error(`Found edge ending at unknown node \`${target}\``);
177
+ if (interrupt) {
178
+ for (const node of interrupt) if (!(node in this.nodes)) throw new Error(`Interrupt node \`${node}\` is not present`);
179
+ }
180
+ this.compiled = true;
181
+ }
182
+ };
183
+ var CompiledGraph = class extends require_pregel_index.Pregel {
184
+ builder;
185
+ constructor({ builder,...rest }) {
186
+ super(rest);
187
+ this.builder = builder;
188
+ }
189
+ attachNode(key, node) {
190
+ this.channels[key] = new require_ephemeral_value.EphemeralValue();
191
+ this.nodes[key] = new require_read.PregelNode({
192
+ channels: [],
193
+ triggers: [],
194
+ metadata: node.metadata,
195
+ subgraphs: node.subgraphs,
196
+ ends: node.ends
197
+ }).pipe(node.runnable).pipe(new require_write.ChannelWrite([{
198
+ channel: key,
199
+ value: require_write.PASSTHROUGH
200
+ }], [require_constants.TAG_HIDDEN]));
201
+ this.streamChannels.push(key);
202
+ }
203
+ attachEdge(start, end) {
204
+ if (end === require_constants.END) {
205
+ if (start === require_constants.START) throw new Error("Cannot have an edge from START to END");
206
+ this.nodes[start].writers.push(new require_write.ChannelWrite([{
207
+ channel: require_constants.END,
208
+ value: require_write.PASSTHROUGH
209
+ }], [require_constants.TAG_HIDDEN]));
210
+ } else {
211
+ this.nodes[end].triggers.push(start);
212
+ this.nodes[end].channels.push(start);
213
+ }
214
+ }
215
+ attachBranch(start, name, branch) {
216
+ if (start === require_constants.START && !this.nodes[require_constants.START]) this.nodes[require_constants.START] = require_pregel_index.Channel.subscribeTo(require_constants.START, { tags: [require_constants.TAG_HIDDEN] });
217
+ this.nodes[start].pipe(branch.run((dests) => {
218
+ const writes = dests.map((dest) => {
219
+ if (require_constants._isSend(dest)) return dest;
220
+ return {
221
+ channel: dest === require_constants.END ? require_constants.END : `branch:${start}:${name}:${dest}`,
222
+ value: require_write.PASSTHROUGH
223
+ };
224
+ });
225
+ return new require_write.ChannelWrite(writes, [require_constants.TAG_HIDDEN]);
226
+ }));
227
+ const ends = branch.ends ? Object.values(branch.ends) : Object.keys(this.nodes);
228
+ for (const end of ends) if (end !== require_constants.END) {
229
+ const channelName = `branch:${start}:${name}:${end}`;
230
+ this.channels[channelName] = new require_ephemeral_value.EphemeralValue();
231
+ this.nodes[end].triggers.push(channelName);
232
+ this.nodes[end].channels.push(channelName);
233
+ }
234
+ }
235
+ /**
236
+ * Returns a drawable representation of the computation graph.
237
+ */
238
+ async getGraphAsync(config) {
239
+ const xray = config?.xray;
240
+ const graph = new __langchain_core_runnables_graph.Graph();
241
+ const startNodes = { [require_constants.START]: graph.addNode({ schema: zod.z.any() }, require_constants.START) };
242
+ const endNodes = {};
243
+ let subgraphs = {};
244
+ if (xray) subgraphs = Object.fromEntries((await require_utils.gatherIterator(this.getSubgraphsAsync())).filter((x) => isCompiledGraph(x[1])));
245
+ function addEdge(start, end, label, conditional = false) {
246
+ if (end === require_constants.END && endNodes[require_constants.END] === void 0) endNodes[require_constants.END] = graph.addNode({ schema: zod.z.any() }, require_constants.END);
247
+ if (startNodes[start] === void 0) return;
248
+ if (endNodes[end] === void 0) throw new Error(`End node ${end} not found!`);
249
+ return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : void 0, conditional);
250
+ }
251
+ for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
252
+ const displayKey = _escapeMermaidKeywords(key);
253
+ const node = nodeSpec.runnable;
254
+ const metadata = nodeSpec.metadata ?? {};
255
+ if (this.interruptBefore?.includes(key) && this.interruptAfter?.includes(key)) metadata.__interrupt = "before,after";
256
+ else if (this.interruptBefore?.includes(key)) metadata.__interrupt = "before";
257
+ else if (this.interruptAfter?.includes(key)) metadata.__interrupt = "after";
258
+ if (xray) {
259
+ const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
260
+ const drawableSubgraph = subgraphs[key] !== void 0 ? await subgraphs[key].getGraphAsync({
261
+ ...config,
262
+ xray: newXrayValue
263
+ }) : node.getGraph(config);
264
+ drawableSubgraph.trimFirstNode();
265
+ drawableSubgraph.trimLastNode();
266
+ if (Object.keys(drawableSubgraph.nodes).length > 1) {
267
+ const [e, s] = graph.extend(drawableSubgraph, displayKey);
268
+ if (e === void 0) throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
269
+ function _isRunnableInterface(thing) {
270
+ return thing ? thing.lc_runnable : false;
271
+ }
272
+ function _nodeDataStr(id, data) {
273
+ if (id !== void 0 && !(0, uuid.validate)(id)) return id;
274
+ else if (_isRunnableInterface(data)) try {
275
+ let dataStr = data.getName();
276
+ dataStr = dataStr.startsWith("Runnable") ? dataStr.slice(8) : dataStr;
277
+ return dataStr;
278
+ } catch (error) {
279
+ return data.getName();
280
+ }
281
+ else return data.name ?? "UnknownSchema";
282
+ }
283
+ if (s !== void 0) startNodes[displayKey] = {
284
+ name: _nodeDataStr(s.id, s.data),
285
+ ...s
286
+ };
287
+ endNodes[displayKey] = {
288
+ name: _nodeDataStr(e.id, e.data),
289
+ ...e
290
+ };
291
+ } else {
292
+ const newNode = graph.addNode(node, displayKey, metadata);
293
+ startNodes[displayKey] = newNode;
294
+ endNodes[displayKey] = newNode;
295
+ }
296
+ } else {
297
+ const newNode = graph.addNode(node, displayKey, metadata);
298
+ startNodes[displayKey] = newNode;
299
+ endNodes[displayKey] = newNode;
300
+ }
301
+ }
302
+ const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
303
+ if (a < b) return -1;
304
+ else if (b > a) return 1;
305
+ else return 0;
306
+ });
307
+ for (const [start, end] of sortedEdges) addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
308
+ for (const [start, branches] of Object.entries(this.builder.branches)) {
309
+ const defaultEnds = {
310
+ ...Object.fromEntries(Object.keys(this.builder.nodes).filter((k) => k !== start).map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
311
+ [require_constants.END]: require_constants.END
312
+ };
313
+ for (const branch of Object.values(branches)) {
314
+ let ends;
315
+ if (branch.ends !== void 0) ends = branch.ends;
316
+ else ends = defaultEnds;
317
+ for (const [label, end] of Object.entries(ends)) addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
318
+ }
319
+ }
320
+ for (const [key, node] of Object.entries(this.builder.nodes)) if (node.ends !== void 0) for (const end of node.ends) addEdge(_escapeMermaidKeywords(key), _escapeMermaidKeywords(end), void 0, true);
321
+ return graph;
322
+ }
323
+ /**
324
+ * Returns a drawable representation of the computation graph.
325
+ *
326
+ * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.
327
+ */
328
+ getGraph(config) {
329
+ const xray = config?.xray;
330
+ const graph = new __langchain_core_runnables_graph.Graph();
331
+ const startNodes = { [require_constants.START]: graph.addNode({ schema: zod.z.any() }, require_constants.START) };
332
+ const endNodes = {};
333
+ let subgraphs = {};
334
+ if (xray) subgraphs = Object.fromEntries(require_utils.gatherIteratorSync(this.getSubgraphs()).filter((x) => isCompiledGraph(x[1])));
335
+ function addEdge(start, end, label, conditional = false) {
336
+ if (end === require_constants.END && endNodes[require_constants.END] === void 0) endNodes[require_constants.END] = graph.addNode({ schema: zod.z.any() }, require_constants.END);
337
+ return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : void 0, conditional);
338
+ }
339
+ for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
340
+ const displayKey = _escapeMermaidKeywords(key);
341
+ const node = nodeSpec.runnable;
342
+ const metadata = nodeSpec.metadata ?? {};
343
+ if (this.interruptBefore?.includes(key) && this.interruptAfter?.includes(key)) metadata.__interrupt = "before,after";
344
+ else if (this.interruptBefore?.includes(key)) metadata.__interrupt = "before";
345
+ else if (this.interruptAfter?.includes(key)) metadata.__interrupt = "after";
346
+ if (xray) {
347
+ const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
348
+ const drawableSubgraph = subgraphs[key] !== void 0 ? subgraphs[key].getGraph({
349
+ ...config,
350
+ xray: newXrayValue
351
+ }) : node.getGraph(config);
352
+ drawableSubgraph.trimFirstNode();
353
+ drawableSubgraph.trimLastNode();
354
+ if (Object.keys(drawableSubgraph.nodes).length > 1) {
355
+ const [e, s] = graph.extend(drawableSubgraph, displayKey);
356
+ if (e === void 0) throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
357
+ function _isRunnableInterface(thing) {
358
+ return thing ? thing.lc_runnable : false;
359
+ }
360
+ function _nodeDataStr(id, data) {
361
+ if (id !== void 0 && !(0, uuid.validate)(id)) return id;
362
+ else if (_isRunnableInterface(data)) try {
363
+ let dataStr = data.getName();
364
+ dataStr = dataStr.startsWith("Runnable") ? dataStr.slice(8) : dataStr;
365
+ return dataStr;
366
+ } catch (error) {
367
+ return data.getName();
368
+ }
369
+ else return data.name ?? "UnknownSchema";
370
+ }
371
+ if (s !== void 0) startNodes[displayKey] = {
372
+ name: _nodeDataStr(s.id, s.data),
373
+ ...s
374
+ };
375
+ endNodes[displayKey] = {
376
+ name: _nodeDataStr(e.id, e.data),
377
+ ...e
378
+ };
379
+ } else {
380
+ const newNode = graph.addNode(node, displayKey, metadata);
381
+ startNodes[displayKey] = newNode;
382
+ endNodes[displayKey] = newNode;
383
+ }
384
+ } else {
385
+ const newNode = graph.addNode(node, displayKey, metadata);
386
+ startNodes[displayKey] = newNode;
387
+ endNodes[displayKey] = newNode;
388
+ }
389
+ }
390
+ const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
391
+ if (a < b) return -1;
392
+ else if (b > a) return 1;
393
+ else return 0;
394
+ });
395
+ for (const [start, end] of sortedEdges) addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
396
+ for (const [start, branches] of Object.entries(this.builder.branches)) {
397
+ const defaultEnds = {
398
+ ...Object.fromEntries(Object.keys(this.builder.nodes).filter((k) => k !== start).map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
399
+ [require_constants.END]: require_constants.END
400
+ };
401
+ for (const branch of Object.values(branches)) {
402
+ let ends;
403
+ if (branch.ends !== void 0) ends = branch.ends;
404
+ else ends = defaultEnds;
405
+ for (const [label, end] of Object.entries(ends)) addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
406
+ }
407
+ }
408
+ return graph;
409
+ }
410
+ };
714
411
  function isCompiledGraph(x) {
715
- return (
716
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
717
- typeof x.attachNode === "function" &&
718
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
719
- typeof x.attachEdge === "function");
412
+ return typeof x.attachNode === "function" && typeof x.attachEdge === "function";
720
413
  }
721
414
  function _escapeMermaidKeywords(key) {
722
- if (key === "subgraph") {
723
- return `"${key}"`;
724
- }
725
- return key;
415
+ if (key === "subgraph") return `"${key}"`;
416
+ return key;
726
417
  }
727
- //# sourceMappingURL=graph.js.map
418
+
419
+ //#endregion
420
+ exports.Branch = Branch;
421
+ exports.CompiledGraph = CompiledGraph;
422
+ exports.Graph = Graph;
423
+ //# sourceMappingURL=graph.cjs.map