@langchain/langgraph 1.0.12 → 1.0.14

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 (381) hide show
  1. package/dist/channels/any_value.cjs +46 -0
  2. package/dist/channels/any_value.cjs.map +1 -0
  3. package/dist/channels/any_value.d.cts +23 -0
  4. package/dist/channels/any_value.d.cts.map +1 -0
  5. package/dist/channels/any_value.d.ts +23 -0
  6. package/dist/channels/any_value.d.ts.map +1 -0
  7. package/dist/channels/any_value.js +46 -0
  8. package/dist/channels/any_value.js.map +1 -0
  9. package/dist/channels/base.cjs +101 -0
  10. package/dist/channels/base.cjs.map +1 -0
  11. package/dist/channels/base.d.cts +79 -0
  12. package/dist/channels/base.d.cts.map +1 -0
  13. package/dist/channels/base.d.ts +79 -0
  14. package/dist/channels/base.d.ts.map +1 -0
  15. package/dist/channels/base.js +97 -0
  16. package/dist/channels/base.js.map +1 -0
  17. package/dist/channels/binop.cjs +49 -0
  18. package/dist/channels/binop.cjs.map +1 -0
  19. package/dist/channels/binop.d.cts +22 -0
  20. package/dist/channels/binop.d.cts.map +1 -0
  21. package/dist/channels/binop.d.ts +22 -0
  22. package/dist/channels/binop.d.ts.map +1 -0
  23. package/dist/channels/binop.js +49 -0
  24. package/dist/channels/binop.js.map +1 -0
  25. package/dist/channels/dynamic_barrier_value.cjs +75 -0
  26. package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
  27. package/dist/channels/dynamic_barrier_value.d.cts +40 -0
  28. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  29. package/dist/channels/dynamic_barrier_value.d.ts +40 -0
  30. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  31. package/dist/channels/dynamic_barrier_value.js +75 -0
  32. package/dist/channels/dynamic_barrier_value.js.map +1 -0
  33. package/dist/channels/ephemeral_value.cjs +46 -0
  34. package/dist/channels/ephemeral_value.cjs.map +1 -0
  35. package/dist/channels/ephemeral_value.d.cts +21 -0
  36. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  37. package/dist/channels/ephemeral_value.d.ts +21 -0
  38. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  39. package/dist/channels/ephemeral_value.js +46 -0
  40. package/dist/channels/ephemeral_value.js.map +1 -0
  41. package/dist/channels/index.cjs +21 -0
  42. package/dist/channels/index.d.cts +9 -0
  43. package/dist/channels/index.d.ts +9 -0
  44. package/dist/channels/index.js +10 -0
  45. package/dist/channels/last_value.cjs +98 -0
  46. package/dist/channels/last_value.cjs.map +1 -0
  47. package/dist/channels/last_value.d.cts +42 -0
  48. package/dist/channels/last_value.d.cts.map +1 -0
  49. package/dist/channels/last_value.d.ts +42 -0
  50. package/dist/channels/last_value.d.ts.map +1 -0
  51. package/dist/channels/last_value.js +97 -0
  52. package/dist/channels/last_value.js.map +1 -0
  53. package/dist/channels/named_barrier_value.cjs +116 -0
  54. package/dist/channels/named_barrier_value.cjs.map +1 -0
  55. package/dist/channels/named_barrier_value.d.cts +44 -0
  56. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  57. package/dist/channels/named_barrier_value.d.ts +44 -0
  58. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  59. package/dist/channels/named_barrier_value.js +114 -0
  60. package/dist/channels/named_barrier_value.js.map +1 -0
  61. package/dist/channels/topic.cjs +65 -0
  62. package/dist/channels/topic.cjs.map +1 -0
  63. package/dist/channels/topic.d.cts +32 -0
  64. package/dist/channels/topic.d.cts.map +1 -0
  65. package/dist/channels/topic.d.ts +32 -0
  66. package/dist/channels/topic.d.ts.map +1 -0
  67. package/dist/channels/topic.js +65 -0
  68. package/dist/channels/topic.js.map +1 -0
  69. package/dist/constants.cjs +406 -0
  70. package/dist/constants.cjs.map +1 -0
  71. package/dist/constants.d.cts +281 -0
  72. package/dist/constants.d.cts.map +1 -0
  73. package/dist/constants.d.ts +281 -0
  74. package/dist/constants.d.ts.map +1 -0
  75. package/dist/constants.js +362 -0
  76. package/dist/constants.js.map +1 -0
  77. package/dist/errors.cjs +163 -0
  78. package/dist/errors.cjs.map +1 -0
  79. package/dist/errors.d.cts +77 -0
  80. package/dist/errors.d.cts.map +1 -0
  81. package/dist/errors.d.ts +77 -0
  82. package/dist/errors.d.ts.map +1 -0
  83. package/dist/errors.js +146 -0
  84. package/dist/errors.js.map +1 -0
  85. package/dist/func/index.cjs +299 -0
  86. package/dist/func/index.cjs.map +1 -0
  87. package/dist/func/index.d.cts +288 -0
  88. package/dist/func/index.d.cts.map +1 -0
  89. package/dist/func/index.d.ts +288 -0
  90. package/dist/func/index.d.ts.map +1 -0
  91. package/dist/func/index.js +297 -0
  92. package/dist/func/index.js.map +1 -0
  93. package/dist/func/types.d.cts +62 -0
  94. package/dist/func/types.d.cts.map +1 -0
  95. package/dist/func/types.d.ts +62 -0
  96. package/dist/func/types.d.ts.map +1 -0
  97. package/dist/graph/annotation.cjs +101 -0
  98. package/dist/graph/annotation.cjs.map +1 -0
  99. package/dist/graph/annotation.d.cts +116 -0
  100. package/dist/graph/annotation.d.cts.map +1 -0
  101. package/dist/graph/annotation.d.ts +116 -0
  102. package/dist/graph/annotation.d.ts.map +1 -0
  103. package/dist/graph/annotation.js +99 -0
  104. package/dist/graph/annotation.js.map +1 -0
  105. package/dist/graph/graph.cjs +420 -0
  106. package/dist/graph/graph.cjs.map +1 -0
  107. package/dist/graph/graph.d.cts +108 -0
  108. package/dist/graph/graph.d.cts.map +1 -0
  109. package/dist/graph/graph.d.ts +108 -0
  110. package/dist/graph/graph.d.ts.map +1 -0
  111. package/dist/graph/graph.js +418 -0
  112. package/dist/graph/graph.js.map +1 -0
  113. package/dist/graph/index.cjs +5 -0
  114. package/dist/graph/index.js +7 -0
  115. package/dist/graph/message.cjs +97 -0
  116. package/dist/graph/message.cjs.map +1 -0
  117. package/dist/graph/message.d.cts +40 -0
  118. package/dist/graph/message.d.cts.map +1 -0
  119. package/dist/graph/message.d.ts +40 -0
  120. package/dist/graph/message.d.ts.map +1 -0
  121. package/dist/graph/message.js +94 -0
  122. package/dist/graph/message.js.map +1 -0
  123. package/dist/graph/messages_annotation.cjs +109 -0
  124. package/dist/graph/messages_annotation.cjs.map +1 -0
  125. package/dist/graph/messages_annotation.d.cts +112 -0
  126. package/dist/graph/messages_annotation.d.cts.map +1 -0
  127. package/dist/graph/messages_annotation.d.ts +112 -0
  128. package/dist/graph/messages_annotation.d.ts.map +1 -0
  129. package/dist/graph/messages_annotation.js +107 -0
  130. package/dist/graph/messages_annotation.js.map +1 -0
  131. package/dist/graph/state.cjs +494 -0
  132. package/dist/graph/state.cjs.map +1 -0
  133. package/dist/graph/state.d.cts +229 -0
  134. package/dist/graph/state.d.cts.map +1 -0
  135. package/dist/graph/state.d.ts +229 -0
  136. package/dist/graph/state.d.ts.map +1 -0
  137. package/dist/graph/state.js +493 -0
  138. package/dist/graph/state.js.map +1 -0
  139. package/dist/graph/zod/index.cjs +10 -0
  140. package/dist/graph/zod/index.d.cts +3 -0
  141. package/dist/graph/zod/index.d.ts +3 -0
  142. package/dist/graph/zod/index.js +5 -0
  143. package/dist/graph/zod/meta.cjs +144 -0
  144. package/dist/graph/zod/meta.cjs.map +1 -0
  145. package/dist/graph/zod/meta.d.cts +115 -0
  146. package/dist/graph/zod/meta.d.cts.map +1 -0
  147. package/dist/graph/zod/meta.d.ts +115 -0
  148. package/dist/graph/zod/meta.d.ts.map +1 -0
  149. package/dist/graph/zod/meta.js +141 -0
  150. package/dist/graph/zod/meta.js.map +1 -0
  151. package/dist/graph/zod/plugin.cjs +39 -0
  152. package/dist/graph/zod/plugin.cjs.map +1 -0
  153. package/dist/graph/zod/plugin.js +40 -0
  154. package/dist/graph/zod/plugin.js.map +1 -0
  155. package/dist/graph/zod/schema.cjs +98 -0
  156. package/dist/graph/zod/schema.cjs.map +1 -0
  157. package/dist/graph/zod/schema.d.cts +38 -0
  158. package/dist/graph/zod/schema.d.cts.map +1 -0
  159. package/dist/graph/zod/schema.d.ts +38 -0
  160. package/dist/graph/zod/schema.d.ts.map +1 -0
  161. package/dist/graph/zod/schema.js +94 -0
  162. package/dist/graph/zod/schema.js.map +1 -0
  163. package/dist/graph/zod/zod-registry.cjs +42 -0
  164. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  165. package/dist/graph/zod/zod-registry.d.cts +49 -0
  166. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  167. package/dist/graph/zod/zod-registry.d.ts +49 -0
  168. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  169. package/dist/graph/zod/zod-registry.js +41 -0
  170. package/dist/graph/zod/zod-registry.js.map +1 -0
  171. package/dist/hash.cjs +265 -0
  172. package/dist/hash.cjs.map +1 -0
  173. package/dist/hash.js +263 -0
  174. package/dist/hash.js.map +1 -0
  175. package/dist/index.cjs +111 -0
  176. package/dist/index.cjs.map +1 -0
  177. package/dist/index.d.cts +26 -0
  178. package/dist/index.d.ts +26 -0
  179. package/dist/index.js +22 -0
  180. package/dist/index.js.map +1 -0
  181. package/dist/interrupt.cjs +79 -0
  182. package/dist/interrupt.cjs.map +1 -0
  183. package/dist/interrupt.d.cts +55 -0
  184. package/dist/interrupt.d.cts.map +1 -0
  185. package/dist/interrupt.d.ts +55 -0
  186. package/dist/interrupt.d.ts.map +1 -0
  187. package/dist/interrupt.js +79 -0
  188. package/dist/interrupt.js.map +1 -0
  189. package/dist/prebuilt/agentName.cjs +148 -0
  190. package/dist/prebuilt/agentName.cjs.map +1 -0
  191. package/dist/prebuilt/agentName.d.cts +42 -0
  192. package/dist/prebuilt/agentName.d.cts.map +1 -0
  193. package/dist/prebuilt/agentName.d.ts +42 -0
  194. package/dist/prebuilt/agentName.d.ts.map +1 -0
  195. package/dist/prebuilt/agentName.js +148 -0
  196. package/dist/prebuilt/agentName.js.map +1 -0
  197. package/dist/prebuilt/agent_executor.cjs +41 -0
  198. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  199. package/dist/prebuilt/agent_executor.d.cts +58 -0
  200. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  201. package/dist/prebuilt/agent_executor.d.ts +58 -0
  202. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  203. package/dist/prebuilt/agent_executor.js +41 -0
  204. package/dist/prebuilt/agent_executor.js.map +1 -0
  205. package/dist/prebuilt/chat_agent_executor.cjs +62 -0
  206. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  207. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  208. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  209. package/dist/prebuilt/chat_agent_executor.d.ts +23 -0
  210. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  211. package/dist/prebuilt/chat_agent_executor.js +62 -0
  212. package/dist/prebuilt/chat_agent_executor.js.map +1 -0
  213. package/dist/prebuilt/index.cjs +15 -0
  214. package/dist/prebuilt/index.d.cts +8 -0
  215. package/dist/prebuilt/index.d.ts +8 -0
  216. package/dist/prebuilt/index.js +8 -0
  217. package/dist/prebuilt/interrupt.d.cts +60 -0
  218. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  219. package/dist/prebuilt/interrupt.d.ts +60 -0
  220. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  221. package/dist/prebuilt/react_agent_executor.cjs +339 -0
  222. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  223. package/dist/prebuilt/react_agent_executor.d.cts +211 -0
  224. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  225. package/dist/prebuilt/react_agent_executor.d.ts +211 -0
  226. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  227. package/dist/prebuilt/react_agent_executor.js +338 -0
  228. package/dist/prebuilt/react_agent_executor.js.map +1 -0
  229. package/dist/prebuilt/tool_executor.cjs +43 -0
  230. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  231. package/dist/prebuilt/tool_executor.d.cts +40 -0
  232. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  233. package/dist/prebuilt/tool_executor.d.ts +40 -0
  234. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  235. package/dist/prebuilt/tool_executor.js +43 -0
  236. package/dist/prebuilt/tool_executor.js.map +1 -0
  237. package/dist/prebuilt/tool_node.cjs +247 -0
  238. package/dist/prebuilt/tool_node.cjs.map +1 -0
  239. package/dist/prebuilt/tool_node.d.cts +180 -0
  240. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  241. package/dist/prebuilt/tool_node.d.ts +180 -0
  242. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  243. package/dist/prebuilt/tool_node.js +246 -0
  244. package/dist/prebuilt/tool_node.js.map +1 -0
  245. package/dist/pregel/algo.cjs +565 -0
  246. package/dist/pregel/algo.cjs.map +1 -0
  247. package/dist/pregel/algo.d.cts +13 -0
  248. package/dist/pregel/algo.d.cts.map +1 -0
  249. package/dist/pregel/algo.d.ts +13 -0
  250. package/dist/pregel/algo.d.ts.map +1 -0
  251. package/dist/pregel/algo.js +560 -0
  252. package/dist/pregel/algo.js.map +1 -0
  253. package/dist/pregel/call.cjs +50 -0
  254. package/dist/pregel/call.cjs.map +1 -0
  255. package/dist/pregel/call.js +48 -0
  256. package/dist/pregel/call.js.map +1 -0
  257. package/dist/pregel/debug.cjs +172 -0
  258. package/dist/pregel/debug.cjs.map +1 -0
  259. package/dist/pregel/debug.js +166 -0
  260. package/dist/pregel/debug.js.map +1 -0
  261. package/dist/pregel/index.cjs +1163 -0
  262. package/dist/pregel/index.cjs.map +1 -0
  263. package/dist/pregel/index.d.cts +498 -0
  264. package/dist/pregel/index.d.cts.map +1 -0
  265. package/dist/pregel/index.d.ts +498 -0
  266. package/dist/pregel/index.d.ts.map +1 -0
  267. package/dist/pregel/index.js +1162 -0
  268. package/dist/pregel/index.js.map +1 -0
  269. package/dist/pregel/io.cjs +140 -0
  270. package/dist/pregel/io.cjs.map +1 -0
  271. package/dist/pregel/io.js +135 -0
  272. package/dist/pregel/io.js.map +1 -0
  273. package/dist/pregel/loop.cjs +545 -0
  274. package/dist/pregel/loop.cjs.map +1 -0
  275. package/dist/pregel/loop.js +545 -0
  276. package/dist/pregel/loop.js.map +1 -0
  277. package/dist/pregel/messages.cjs +107 -0
  278. package/dist/pregel/messages.cjs.map +1 -0
  279. package/dist/pregel/messages.js +107 -0
  280. package/dist/pregel/messages.js.map +1 -0
  281. package/dist/pregel/read.cjs +151 -0
  282. package/dist/pregel/read.cjs.map +1 -0
  283. package/dist/pregel/read.d.cts +45 -0
  284. package/dist/pregel/read.d.cts.map +1 -0
  285. package/dist/pregel/read.d.ts +45 -0
  286. package/dist/pregel/read.d.ts.map +1 -0
  287. package/dist/pregel/read.js +150 -0
  288. package/dist/pregel/read.js.map +1 -0
  289. package/dist/pregel/remote.cjs +341 -0
  290. package/dist/pregel/remote.cjs.map +1 -0
  291. package/dist/pregel/remote.d.cts +118 -0
  292. package/dist/pregel/remote.d.cts.map +1 -0
  293. package/dist/pregel/remote.d.ts +118 -0
  294. package/dist/pregel/remote.d.ts.map +1 -0
  295. package/dist/pregel/remote.js +341 -0
  296. package/dist/pregel/remote.js.map +1 -0
  297. package/dist/pregel/retry.cjs +91 -0
  298. package/dist/pregel/retry.cjs.map +1 -0
  299. package/dist/pregel/retry.js +91 -0
  300. package/dist/pregel/retry.js.map +1 -0
  301. package/dist/pregel/runnable_types.d.cts +43 -0
  302. package/dist/pregel/runnable_types.d.cts.map +1 -0
  303. package/dist/pregel/runnable_types.d.ts +43 -0
  304. package/dist/pregel/runnable_types.d.ts.map +1 -0
  305. package/dist/pregel/runner.cjs +228 -0
  306. package/dist/pregel/runner.cjs.map +1 -0
  307. package/dist/pregel/runner.js +228 -0
  308. package/dist/pregel/runner.js.map +1 -0
  309. package/dist/pregel/stream.cjs +197 -0
  310. package/dist/pregel/stream.cjs.map +1 -0
  311. package/dist/pregel/stream.js +195 -0
  312. package/dist/pregel/stream.js.map +1 -0
  313. package/dist/pregel/types.cjs +27 -0
  314. package/dist/pregel/types.cjs.map +1 -0
  315. package/dist/pregel/types.d.cts +440 -0
  316. package/dist/pregel/types.d.cts.map +1 -0
  317. package/dist/pregel/types.d.ts +440 -0
  318. package/dist/pregel/types.d.ts.map +1 -0
  319. package/dist/pregel/types.js +25 -0
  320. package/dist/pregel/types.js.map +1 -0
  321. package/dist/pregel/utils/config.cjs +121 -0
  322. package/dist/pregel/utils/config.cjs.map +1 -0
  323. package/dist/pregel/utils/config.d.cts +36 -0
  324. package/dist/pregel/utils/config.d.cts.map +1 -0
  325. package/dist/pregel/utils/config.d.ts +36 -0
  326. package/dist/pregel/utils/config.d.ts.map +1 -0
  327. package/dist/pregel/utils/config.js +115 -0
  328. package/dist/pregel/utils/config.js.map +1 -0
  329. package/dist/pregel/utils/index.cjs +102 -0
  330. package/dist/pregel/utils/index.cjs.map +1 -0
  331. package/dist/pregel/utils/index.d.cts +51 -0
  332. package/dist/pregel/utils/index.d.cts.map +1 -0
  333. package/dist/pregel/utils/index.d.ts +51 -0
  334. package/dist/pregel/utils/index.d.ts.map +1 -0
  335. package/dist/pregel/utils/index.js +96 -0
  336. package/dist/pregel/utils/index.js.map +1 -0
  337. package/dist/pregel/utils/subgraph.cjs +18 -0
  338. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  339. package/dist/pregel/utils/subgraph.js +16 -0
  340. package/dist/pregel/utils/subgraph.js.map +1 -0
  341. package/dist/pregel/validate.cjs +45 -0
  342. package/dist/pregel/validate.cjs.map +1 -0
  343. package/dist/pregel/validate.js +44 -0
  344. package/dist/pregel/validate.js.map +1 -0
  345. package/dist/pregel/write.cjs +96 -0
  346. package/dist/pregel/write.cjs.map +1 -0
  347. package/dist/pregel/write.d.cts +31 -0
  348. package/dist/pregel/write.d.cts.map +1 -0
  349. package/dist/pregel/write.d.ts +31 -0
  350. package/dist/pregel/write.d.ts.map +1 -0
  351. package/dist/pregel/write.js +95 -0
  352. package/dist/pregel/write.js.map +1 -0
  353. package/dist/remote.cjs +3 -0
  354. package/dist/remote.d.cts +2 -0
  355. package/dist/remote.d.ts +2 -0
  356. package/dist/remote.js +3 -0
  357. package/dist/setup/async_local_storage.cjs +11 -0
  358. package/dist/setup/async_local_storage.cjs.map +1 -0
  359. package/dist/setup/async_local_storage.js +11 -0
  360. package/dist/setup/async_local_storage.js.map +1 -0
  361. package/dist/utils.cjs +86 -0
  362. package/dist/utils.cjs.map +1 -0
  363. package/dist/utils.d.cts +25 -0
  364. package/dist/utils.d.cts.map +1 -0
  365. package/dist/utils.d.ts +25 -0
  366. package/dist/utils.d.ts.map +1 -0
  367. package/dist/utils.js +80 -0
  368. package/dist/utils.js.map +1 -0
  369. package/dist/web.cjs +95 -0
  370. package/dist/web.d.cts +23 -0
  371. package/dist/web.d.ts +23 -0
  372. package/dist/web.js +15 -0
  373. package/dist/writer.cjs +14 -0
  374. package/dist/writer.cjs.map +1 -0
  375. package/dist/writer.d.cts +6 -0
  376. package/dist/writer.d.cts.map +1 -0
  377. package/dist/writer.d.ts +6 -0
  378. package/dist/writer.d.ts.map +1 -0
  379. package/dist/writer.js +14 -0
  380. package/dist/writer.js.map +1 -0
  381. package/package.json +25 -27
@@ -0,0 +1,96 @@
1
+ import { CONFIG_KEY_CHECKPOINT_MAP, START } from "../../constants.js";
2
+
3
+ //#region src/pregel/utils/index.ts
4
+ function getNullChannelVersion(currentVersions) {
5
+ const startVersion = typeof currentVersions[START];
6
+ if (startVersion === "number") return 0;
7
+ if (startVersion === "string") return "";
8
+ for (const key in currentVersions) {
9
+ if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;
10
+ const versionType = typeof currentVersions[key];
11
+ if (versionType === "number") return 0;
12
+ if (versionType === "string") return "";
13
+ break;
14
+ }
15
+ }
16
+ function getNewChannelVersions(previousVersions, currentVersions) {
17
+ if (Object.keys(previousVersions).length > 0) {
18
+ const nullVersion = getNullChannelVersion(currentVersions);
19
+ return Object.fromEntries(Object.entries(currentVersions).filter(([k, v]) => v > (previousVersions[k] ?? nullVersion)));
20
+ } else return currentVersions;
21
+ }
22
+ function _coerceToDict(value, defaultKey) {
23
+ return value && !Array.isArray(value) && !(value instanceof Date) && typeof value === "object" ? value : { [defaultKey]: value };
24
+ }
25
+ function patchConfigurable(config, patch) {
26
+ if (config === null) return { configurable: patch };
27
+ else if (config?.configurable === void 0) return {
28
+ ...config,
29
+ configurable: patch
30
+ };
31
+ else return {
32
+ ...config,
33
+ configurable: {
34
+ ...config.configurable,
35
+ ...patch
36
+ }
37
+ };
38
+ }
39
+ function patchCheckpointMap(config, metadata) {
40
+ const parents = metadata?.parents ?? {};
41
+ if (Object.keys(parents).length > 0) return patchConfigurable(config, { [CONFIG_KEY_CHECKPOINT_MAP]: {
42
+ ...parents,
43
+ [config.configurable?.checkpoint_ns ?? ""]: config.configurable?.checkpoint_id
44
+ } });
45
+ else return config;
46
+ }
47
+ /**
48
+ * Combine multiple abort signals into a single abort signal.
49
+ * @param signals - The abort signals to combine.
50
+ * @returns A combined abort signal and a dispose function to remove the abort listener if unused.
51
+ */
52
+ function combineAbortSignals(...x) {
53
+ const signals = [...new Set(x.filter(Boolean))];
54
+ if (signals.length === 0) return {
55
+ signal: void 0,
56
+ dispose: void 0
57
+ };
58
+ if (signals.length === 1) return {
59
+ signal: signals[0],
60
+ dispose: void 0
61
+ };
62
+ const combinedController = new AbortController();
63
+ const listener = () => {
64
+ const reason = signals.find((s) => s.aborted)?.reason;
65
+ combinedController.abort(reason);
66
+ signals.forEach((s) => s.removeEventListener("abort", listener));
67
+ };
68
+ signals.forEach((s) => s.addEventListener("abort", listener, { once: true }));
69
+ const hasAlreadyAbortedSignal = signals.find((s) => s.aborted);
70
+ if (hasAlreadyAbortedSignal) combinedController.abort(hasAlreadyAbortedSignal.reason);
71
+ return {
72
+ signal: combinedController.signal,
73
+ dispose: () => {
74
+ signals.forEach((s) => s.removeEventListener("abort", listener));
75
+ }
76
+ };
77
+ }
78
+ /**
79
+ * Combine multiple callbacks into a single callback.
80
+ * @param callback1 - The first callback to combine.
81
+ * @param callback2 - The second callback to combine.
82
+ * @returns A single callback that is a combination of the input callbacks.
83
+ */
84
+ const combineCallbacks = (callback1, callback2) => {
85
+ if (!callback1 && !callback2) return;
86
+ if (!callback1) return callback2;
87
+ if (!callback2) return callback1;
88
+ if (Array.isArray(callback1) && Array.isArray(callback2)) return [...callback1, ...callback2];
89
+ if (Array.isArray(callback1)) return [...callback1, callback2];
90
+ if (Array.isArray(callback2)) return [callback1, ...callback2];
91
+ return [callback1, callback2];
92
+ };
93
+
94
+ //#endregion
95
+ export { _coerceToDict, combineAbortSignals, combineCallbacks, getNewChannelVersions, getNullChannelVersion, patchCheckpointMap, patchConfigurable };
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/pregel/utils/index.ts"],"sourcesContent":["import { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n ChannelVersions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { CONFIG_KEY_CHECKPOINT_MAP, START } from \"../../constants.js\";\n\nexport function getNullChannelVersion(currentVersions: ChannelVersions) {\n // Short circuit for commonly used channels such as __start__\n // (used by StateGraph)\n const startVersion = typeof currentVersions[START];\n if (startVersion === \"number\") return 0;\n if (startVersion === \"string\") return \"\";\n\n // Defer back to obtaining a first key from channel versions\n for (const key in currentVersions) {\n if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;\n const versionType = typeof currentVersions[key];\n if (versionType === \"number\") return 0;\n if (versionType === \"string\") return \"\";\n break;\n }\n\n return undefined;\n}\n\nexport function getNewChannelVersions(\n previousVersions: ChannelVersions,\n currentVersions: ChannelVersions\n): ChannelVersions {\n // Get new channel versions\n if (Object.keys(previousVersions).length > 0) {\n const nullVersion = getNullChannelVersion(currentVersions);\n return Object.fromEntries(\n Object.entries(currentVersions).filter(\n ([k, v]) => v > (previousVersions[k] ?? nullVersion)\n )\n );\n } else {\n return currentVersions;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function _coerceToDict(value: any, defaultKey: string) {\n return value &&\n !Array.isArray(value) &&\n // eslint-disable-next-line no-instanceof/no-instanceof\n !(value instanceof Date) &&\n typeof value === \"object\"\n ? value\n : { [defaultKey]: value };\n}\n\nexport type RetryPolicy = {\n /**\n * Amount of time that must elapse before the first retry occurs in milliseconds.\n * @default 500\n */\n initialInterval?: number;\n\n /**\n * Multiplier by which the interval increases after each retry.\n * @default 2\n */\n backoffFactor?: number;\n\n /**\n * Maximum amount of time that may elapse between retries in milliseconds.\n * @default 128000\n */\n maxInterval?: number;\n\n /**\n * Maximum amount of time that may elapse between retries.\n * @default 3\n */\n maxAttempts?: number;\n\n /** Whether to add random jitter to the interval between retries. */\n jitter?: boolean;\n\n /** A function that returns True for exceptions that should trigger a retry. */\n retryOn?: (e: any) => boolean; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /** Whether to log a warning when a retry is attempted. Defaults to true. */\n logWarning?: boolean;\n};\n\n/**\n * Configuration for caching nodes.\n */\nexport type CachePolicy = {\n /**\n * A function used to generate a cache key from node's input.\n * @returns A key for the cache.\n */\n keyFunc?: (args: unknown[]) => string;\n\n /**\n * The time to live for the cache in seconds.\n * If not defined, the entry will never expire.\n */\n ttl?: number;\n};\n\nexport function patchConfigurable(\n config: RunnableConfig | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n patch: Record<string, any>\n): RunnableConfig {\n if (config === null) {\n return { configurable: patch };\n } else if (config?.configurable === undefined) {\n return { ...config, configurable: patch };\n } else {\n return {\n ...config,\n configurable: { ...config.configurable, ...patch },\n };\n }\n}\n\nexport function patchCheckpointMap(\n config: RunnableConfig,\n metadata?: CheckpointMetadata\n): RunnableConfig {\n const parents = metadata?.parents ?? {};\n\n if (Object.keys(parents).length > 0) {\n return patchConfigurable(config, {\n [CONFIG_KEY_CHECKPOINT_MAP]: {\n ...parents,\n [config.configurable?.checkpoint_ns ?? \"\"]:\n config.configurable?.checkpoint_id,\n },\n });\n } else {\n return config;\n }\n}\n\n/**\n * Combine multiple abort signals into a single abort signal.\n * @param signals - The abort signals to combine.\n * @returns A combined abort signal and a dispose function to remove the abort listener if unused.\n */\nexport function combineAbortSignals(...x: (AbortSignal | undefined)[]): {\n signal: AbortSignal | undefined;\n dispose?: () => void;\n} {\n const signals = [...new Set(x.filter(Boolean))] as AbortSignal[];\n\n if (signals.length === 0) {\n return { signal: undefined, dispose: undefined };\n }\n\n if (signals.length === 1) {\n return { signal: signals[0], dispose: undefined };\n }\n\n const combinedController = new AbortController();\n const listener = () => {\n const reason = signals.find((s) => s.aborted)?.reason;\n combinedController.abort(reason);\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n };\n\n signals.forEach((s) => s.addEventListener(\"abort\", listener, { once: true }));\n\n const hasAlreadyAbortedSignal = signals.find((s) => s.aborted);\n if (hasAlreadyAbortedSignal) {\n combinedController.abort(hasAlreadyAbortedSignal.reason);\n }\n\n return {\n signal: combinedController.signal,\n dispose: () => {\n signals.forEach((s) => s.removeEventListener(\"abort\", listener));\n },\n };\n}\n\n/**\n * Combine multiple callbacks into a single callback.\n * @param callback1 - The first callback to combine.\n * @param callback2 - The second callback to combine.\n * @returns A single callback that is a combination of the input callbacks.\n */\nexport const combineCallbacks = (\n callback1?: Callbacks,\n callback2?: Callbacks\n): Callbacks | undefined => {\n if (!callback1 && !callback2) {\n return undefined;\n }\n\n if (!callback1) {\n return callback2;\n }\n\n if (!callback2) {\n return callback1;\n }\n if (Array.isArray(callback1) && Array.isArray(callback2)) {\n return [...callback1, ...callback2];\n }\n if (Array.isArray(callback1)) {\n return [...callback1, callback2] as Callbacks;\n }\n if (Array.isArray(callback2)) {\n return [callback1, ...callback2];\n }\n return [callback1, callback2] as Callbacks;\n};\n"],"mappings":";;;AAQA,SAAgB,sBAAsB,iBAAkC;CAGtE,MAAM,eAAe,OAAO,gBAAgB;AAC5C,KAAI,iBAAiB,SAAU,QAAO;AACtC,KAAI,iBAAiB,SAAU,QAAO;AAGtC,MAAK,MAAM,OAAO,iBAAiB;AACjC,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,iBAAiB,IAAI,CAAE;EACjE,MAAM,cAAc,OAAO,gBAAgB;AAC3C,MAAI,gBAAgB,SAAU,QAAO;AACrC,MAAI,gBAAgB,SAAU,QAAO;AACrC;;;AAMJ,SAAgB,sBACd,kBACA,iBACiB;AAEjB,KAAI,OAAO,KAAK,iBAAiB,CAAC,SAAS,GAAG;EAC5C,MAAM,cAAc,sBAAsB,gBAAgB;AAC1D,SAAO,OAAO,YACZ,OAAO,QAAQ,gBAAgB,CAAC,QAC7B,CAAC,GAAG,OAAO,KAAK,iBAAiB,MAAM,aACzC,CACF;OAED,QAAO;;AAKX,SAAgB,cAAc,OAAY,YAAoB;AAC5D,QAAO,SACL,CAAC,MAAM,QAAQ,MAAM,IAErB,EAAE,iBAAiB,SACnB,OAAO,UAAU,WACf,QACA,GAAG,aAAa,OAAO;;AAuD7B,SAAgB,kBACd,QAEA,OACgB;AAChB,KAAI,WAAW,KACb,QAAO,EAAE,cAAc,OAAO;UACrB,QAAQ,iBAAiB,OAClC,QAAO;EAAE,GAAG;EAAQ,cAAc;EAAO;KAEzC,QAAO;EACL,GAAG;EACH,cAAc;GAAE,GAAG,OAAO;GAAc,GAAG;GAAO;EACnD;;AAIL,SAAgB,mBACd,QACA,UACgB;CAChB,MAAM,UAAU,UAAU,WAAW,EAAE;AAEvC,KAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAChC,QAAO,kBAAkB,QAAQ,GAC9B,4BAA4B;EAC3B,GAAG;GACF,OAAO,cAAc,iBAAiB,KACrC,OAAO,cAAc;EACxB,EACF,CAAC;KAEF,QAAO;;;;;;;AASX,SAAgB,oBAAoB,GAAG,GAGrC;CACA,MAAM,UAAU,CAAC,GAAG,IAAI,IAAI,EAAE,OAAO,QAAQ,CAAC,CAAC;AAE/C,KAAI,QAAQ,WAAW,EACrB,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAW;AAGlD,KAAI,QAAQ,WAAW,EACrB,QAAO;EAAE,QAAQ,QAAQ;EAAI,SAAS;EAAW;CAGnD,MAAM,qBAAqB,IAAI,iBAAiB;CAChD,MAAM,iBAAiB;EACrB,MAAM,SAAS,QAAQ,MAAM,MAAM,EAAE,QAAQ,EAAE;AAC/C,qBAAmB,MAAM,OAAO;AAChC,UAAQ,SAAS,MAAM,EAAE,oBAAoB,SAAS,SAAS,CAAC;;AAGlE,SAAQ,SAAS,MAAM,EAAE,iBAAiB,SAAS,UAAU,EAAE,MAAM,MAAM,CAAC,CAAC;CAE7E,MAAM,0BAA0B,QAAQ,MAAM,MAAM,EAAE,QAAQ;AAC9D,KAAI,wBACF,oBAAmB,MAAM,wBAAwB,OAAO;AAG1D,QAAO;EACL,QAAQ,mBAAmB;EAC3B,eAAe;AACb,WAAQ,SAAS,MAAM,EAAE,oBAAoB,SAAS,SAAS,CAAC;;EAEnE;;;;;;;;AASH,MAAa,oBACX,WACA,cAC0B;AAC1B,KAAI,CAAC,aAAa,CAAC,UACjB;AAGF,KAAI,CAAC,UACH,QAAO;AAGT,KAAI,CAAC,UACH,QAAO;AAET,KAAI,MAAM,QAAQ,UAAU,IAAI,MAAM,QAAQ,UAAU,CACtD,QAAO,CAAC,GAAG,WAAW,GAAG,UAAU;AAErC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,GAAG,WAAW,UAAU;AAElC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAO,CAAC,WAAW,GAAG,UAAU;AAElC,QAAO,CAAC,WAAW,UAAU"}
@@ -0,0 +1,18 @@
1
+
2
+ //#region src/pregel/utils/subgraph.ts
3
+ function isRunnableSequence(x) {
4
+ return "steps" in x && Array.isArray(x.steps);
5
+ }
6
+ function isPregelLike(x) {
7
+ return "lg_is_pregel" in x && x.lg_is_pregel === true;
8
+ }
9
+ function findSubgraphPregel(candidate) {
10
+ const candidates = [candidate];
11
+ for (const candidate$1 of candidates) if (isPregelLike(candidate$1)) return candidate$1;
12
+ else if (isRunnableSequence(candidate$1)) candidates.push(...candidate$1.steps);
13
+ }
14
+
15
+ //#endregion
16
+ exports.findSubgraphPregel = findSubgraphPregel;
17
+ exports.isPregelLike = isPregelLike;
18
+ //# sourceMappingURL=subgraph.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.cjs","names":["candidate"],"sources":["../../../src/pregel/utils/subgraph.ts"],"sourcesContent":["import {\n RunnableSequence,\n Runnable,\n RunnableLike,\n} from \"@langchain/core/runnables\";\nimport type { PregelInterface } from \"../types.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isRunnableSequence(\n x: RunnableSequence | Runnable\n): x is RunnableSequence {\n return \"steps\" in x && Array.isArray(x.steps);\n}\n\nexport function isPregelLike(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n x: PregelInterface<any, any> | RunnableLike<any, any, any>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): x is PregelInterface<any, any> {\n return \"lg_is_pregel\" in x && x.lg_is_pregel === true;\n}\n\nexport function findSubgraphPregel(\n candidate: Runnable\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): PregelInterface<any, any> | undefined {\n const candidates = [candidate];\n for (const candidate of candidates) {\n if (isPregelLike(candidate)) {\n return candidate;\n } else if (isRunnableSequence(candidate)) {\n candidates.push(...candidate.steps);\n }\n }\n return undefined;\n}\n"],"mappings":";;AAQA,SAAS,mBACP,GACuB;AACvB,QAAO,WAAW,KAAK,MAAM,QAAQ,EAAE,MAAM;;AAG/C,SAAgB,aAEd,GAEgC;AAChC,QAAO,kBAAkB,KAAK,EAAE,iBAAiB;;AAGnD,SAAgB,mBACd,WAEuC;CACvC,MAAM,aAAa,CAAC,UAAU;AAC9B,MAAK,MAAMA,eAAa,WACtB,KAAI,aAAaA,YAAU,CACzB,QAAOA;UACE,mBAAmBA,YAAU,CACtC,YAAW,KAAK,GAAGA,YAAU,MAAM"}
@@ -0,0 +1,16 @@
1
+ //#region src/pregel/utils/subgraph.ts
2
+ function isRunnableSequence(x) {
3
+ return "steps" in x && Array.isArray(x.steps);
4
+ }
5
+ function isPregelLike(x) {
6
+ return "lg_is_pregel" in x && x.lg_is_pregel === true;
7
+ }
8
+ function findSubgraphPregel(candidate) {
9
+ const candidates = [candidate];
10
+ for (const candidate$1 of candidates) if (isPregelLike(candidate$1)) return candidate$1;
11
+ else if (isRunnableSequence(candidate$1)) candidates.push(...candidate$1.steps);
12
+ }
13
+
14
+ //#endregion
15
+ export { findSubgraphPregel, isPregelLike };
16
+ //# sourceMappingURL=subgraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.js","names":["candidate"],"sources":["../../../src/pregel/utils/subgraph.ts"],"sourcesContent":["import {\n RunnableSequence,\n Runnable,\n RunnableLike,\n} from \"@langchain/core/runnables\";\nimport type { PregelInterface } from \"../types.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isRunnableSequence(\n x: RunnableSequence | Runnable\n): x is RunnableSequence {\n return \"steps\" in x && Array.isArray(x.steps);\n}\n\nexport function isPregelLike(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n x: PregelInterface<any, any> | RunnableLike<any, any, any>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): x is PregelInterface<any, any> {\n return \"lg_is_pregel\" in x && x.lg_is_pregel === true;\n}\n\nexport function findSubgraphPregel(\n candidate: Runnable\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): PregelInterface<any, any> | undefined {\n const candidates = [candidate];\n for (const candidate of candidates) {\n if (isPregelLike(candidate)) {\n return candidate;\n } else if (isRunnableSequence(candidate)) {\n candidates.push(...candidate.steps);\n }\n }\n return undefined;\n}\n"],"mappings":";AAQA,SAAS,mBACP,GACuB;AACvB,QAAO,WAAW,KAAK,MAAM,QAAQ,EAAE,MAAM;;AAG/C,SAAgB,aAEd,GAEgC;AAChC,QAAO,kBAAkB,KAAK,EAAE,iBAAiB;;AAGnD,SAAgB,mBACd,WAEuC;CACvC,MAAM,aAAa,CAAC,UAAU;AAC9B,MAAK,MAAMA,eAAa,WACtB,KAAI,aAAaA,YAAU,CACzB,QAAOA;UACE,mBAAmBA,YAAU,CACtC,YAAW,KAAK,GAAGA,YAAU,MAAM"}
@@ -0,0 +1,45 @@
1
+ const require_constants = require('../constants.cjs');
2
+ const require_read = require('./read.cjs');
3
+
4
+ //#region src/pregel/validate.ts
5
+ var GraphValidationError = class extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "GraphValidationError";
9
+ }
10
+ };
11
+ function validateGraph({ nodes, channels, inputChannels, outputChannels, streamChannels, interruptAfterNodes, interruptBeforeNodes }) {
12
+ if (!channels) throw new GraphValidationError("Channels not provided");
13
+ const subscribedChannels = /* @__PURE__ */ new Set();
14
+ const allOutputChannels = /* @__PURE__ */ new Set();
15
+ for (const [name, node] of Object.entries(nodes)) {
16
+ if (name === require_constants.INTERRUPT) throw new GraphValidationError(`"Node name ${require_constants.INTERRUPT} is reserved"`);
17
+ if (node.constructor === require_read.PregelNode) node.triggers.forEach((trigger) => subscribedChannels.add(trigger));
18
+ else throw new GraphValidationError(`Invalid node type ${typeof node}, expected PregelNode`);
19
+ }
20
+ for (const chan of subscribedChannels) if (!(chan in channels)) throw new GraphValidationError(`Subscribed channel '${String(chan)}' not in channels`);
21
+ if (!Array.isArray(inputChannels)) {
22
+ if (!subscribedChannels.has(inputChannels)) throw new GraphValidationError(`Input channel ${String(inputChannels)} is not subscribed to by any node`);
23
+ } else if (inputChannels.every((channel) => !subscribedChannels.has(channel))) throw new GraphValidationError(`None of the input channels ${inputChannels} are subscribed to by any node`);
24
+ if (!Array.isArray(outputChannels)) allOutputChannels.add(outputChannels);
25
+ else outputChannels.forEach((chan) => allOutputChannels.add(chan));
26
+ if (streamChannels && !Array.isArray(streamChannels)) allOutputChannels.add(streamChannels);
27
+ else if (Array.isArray(streamChannels)) streamChannels.forEach((chan) => allOutputChannels.add(chan));
28
+ for (const chan of allOutputChannels) if (!(chan in channels)) throw new GraphValidationError(`Output channel '${String(chan)}' not in channels`);
29
+ if (interruptAfterNodes && interruptAfterNodes !== "*") {
30
+ for (const node of interruptAfterNodes) if (!(node in nodes)) throw new GraphValidationError(`Node ${String(node)} not in nodes`);
31
+ }
32
+ if (interruptBeforeNodes && interruptBeforeNodes !== "*") {
33
+ for (const node of interruptBeforeNodes) if (!(node in nodes)) throw new GraphValidationError(`Node ${String(node)} not in nodes`);
34
+ }
35
+ }
36
+ function validateKeys(keys, channels) {
37
+ if (Array.isArray(keys)) {
38
+ for (const key of keys) if (!(key in channels)) throw new Error(`Key ${String(key)} not found in channels`);
39
+ } else if (!(keys in channels)) throw new Error(`Key ${String(keys)} not found in channels`);
40
+ }
41
+
42
+ //#endregion
43
+ exports.validateGraph = validateGraph;
44
+ exports.validateKeys = validateKeys;
45
+ //# sourceMappingURL=validate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.cjs","names":["INTERRUPT","PregelNode"],"sources":["../../src/pregel/validate.ts"],"sourcesContent":["import { All } from \"@langchain/langgraph-checkpoint\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport { INTERRUPT } from \"../constants.js\";\nimport { PregelNode } from \"./read.js\";\n\nexport class GraphValidationError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"GraphValidationError\";\n }\n}\n\nexport function validateGraph<\n Nn extends Record<string, PregelNode>,\n Cc extends Record<string, BaseChannel>\n>({\n nodes,\n channels,\n inputChannels,\n outputChannels,\n streamChannels,\n interruptAfterNodes,\n interruptBeforeNodes,\n}: {\n nodes: Nn;\n channels: Cc;\n inputChannels: keyof Cc | Array<keyof Cc>;\n outputChannels: keyof Cc | Array<keyof Cc>;\n streamChannels?: keyof Cc | Array<keyof Cc>;\n interruptAfterNodes?: Array<keyof Nn> | All;\n interruptBeforeNodes?: Array<keyof Nn> | All;\n}): void {\n if (!channels) {\n throw new GraphValidationError(\"Channels not provided\");\n }\n\n const subscribedChannels = new Set<keyof Cc>();\n const allOutputChannels = new Set<keyof Cc>();\n\n for (const [name, node] of Object.entries(nodes)) {\n if (name === INTERRUPT) {\n throw new GraphValidationError(`\"Node name ${INTERRUPT} is reserved\"`);\n }\n if (node.constructor === PregelNode) {\n node.triggers.forEach((trigger) => subscribedChannels.add(trigger));\n } else {\n throw new GraphValidationError(\n `Invalid node type ${typeof node}, expected PregelNode`\n );\n }\n }\n\n // side effect: update channels\n for (const chan of subscribedChannels) {\n if (!(chan in channels)) {\n throw new GraphValidationError(\n `Subscribed channel '${String(chan)}' not in channels`\n );\n }\n }\n\n if (!Array.isArray(inputChannels)) {\n if (!subscribedChannels.has(inputChannels)) {\n throw new GraphValidationError(\n `Input channel ${String(\n inputChannels\n )} is not subscribed to by any node`\n );\n }\n } else {\n if (inputChannels.every((channel) => !subscribedChannels.has(channel))) {\n throw new GraphValidationError(\n `None of the input channels ${inputChannels} are subscribed to by any node`\n );\n }\n }\n\n if (!Array.isArray(outputChannels)) {\n allOutputChannels.add(outputChannels);\n } else {\n outputChannels.forEach((chan) => allOutputChannels.add(chan));\n }\n\n if (streamChannels && !Array.isArray(streamChannels)) {\n allOutputChannels.add(streamChannels);\n } else if (Array.isArray(streamChannels)) {\n streamChannels.forEach((chan) => allOutputChannels.add(chan));\n }\n\n for (const chan of allOutputChannels) {\n if (!(chan in channels)) {\n throw new GraphValidationError(\n `Output channel '${String(chan)}' not in channels`\n );\n }\n }\n\n // validate interrupt before/after\n if (interruptAfterNodes && interruptAfterNodes !== \"*\") {\n for (const node of interruptAfterNodes) {\n if (!(node in nodes)) {\n throw new GraphValidationError(`Node ${String(node)} not in nodes`);\n }\n }\n }\n\n if (interruptBeforeNodes && interruptBeforeNodes !== \"*\") {\n for (const node of interruptBeforeNodes) {\n if (!(node in nodes)) {\n throw new GraphValidationError(`Node ${String(node)} not in nodes`);\n }\n }\n }\n}\n\nexport function validateKeys<Cc extends Record<string, BaseChannel>>(\n keys: keyof Cc | Array<keyof Cc>,\n channels: Cc\n): void {\n if (Array.isArray(keys)) {\n for (const key of keys) {\n if (!(key in channels)) {\n throw new Error(`Key ${String(key)} not found in channels`);\n }\n }\n } else {\n if (!(keys in channels)) {\n throw new Error(`Key ${String(keys)} not found in channels`);\n }\n }\n}\n"],"mappings":";;;;AAKA,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAY,SAAkB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAIhB,SAAgB,cAGd,EACA,OACA,UACA,eACA,gBACA,gBACA,qBACA,wBASO;AACP,KAAI,CAAC,SACH,OAAM,IAAI,qBAAqB,wBAAwB;CAGzD,MAAM,qCAAqB,IAAI,KAAe;CAC9C,MAAM,oCAAoB,IAAI,KAAe;AAE7C,MAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,MAAM,EAAE;AAChD,MAAI,SAASA,4BACX,OAAM,IAAI,qBAAqB,cAAcA,4BAAU,eAAe;AAExE,MAAI,KAAK,gBAAgBC,wBACvB,MAAK,SAAS,SAAS,YAAY,mBAAmB,IAAI,QAAQ,CAAC;MAEnE,OAAM,IAAI,qBACR,qBAAqB,OAAO,KAAK,uBAClC;;AAKL,MAAK,MAAM,QAAQ,mBACjB,KAAI,EAAE,QAAQ,UACZ,OAAM,IAAI,qBACR,uBAAuB,OAAO,KAAK,CAAC,mBACrC;AAIL,KAAI,CAAC,MAAM,QAAQ,cAAc,EAC/B;MAAI,CAAC,mBAAmB,IAAI,cAAc,CACxC,OAAM,IAAI,qBACR,iBAAiB,OACf,cACD,CAAC,mCACH;YAGC,cAAc,OAAO,YAAY,CAAC,mBAAmB,IAAI,QAAQ,CAAC,CACpE,OAAM,IAAI,qBACR,8BAA8B,cAAc,gCAC7C;AAIL,KAAI,CAAC,MAAM,QAAQ,eAAe,CAChC,mBAAkB,IAAI,eAAe;KAErC,gBAAe,SAAS,SAAS,kBAAkB,IAAI,KAAK,CAAC;AAG/D,KAAI,kBAAkB,CAAC,MAAM,QAAQ,eAAe,CAClD,mBAAkB,IAAI,eAAe;UAC5B,MAAM,QAAQ,eAAe,CACtC,gBAAe,SAAS,SAAS,kBAAkB,IAAI,KAAK,CAAC;AAG/D,MAAK,MAAM,QAAQ,kBACjB,KAAI,EAAE,QAAQ,UACZ,OAAM,IAAI,qBACR,mBAAmB,OAAO,KAAK,CAAC,mBACjC;AAKL,KAAI,uBAAuB,wBAAwB,KACjD;OAAK,MAAM,QAAQ,oBACjB,KAAI,EAAE,QAAQ,OACZ,OAAM,IAAI,qBAAqB,QAAQ,OAAO,KAAK,CAAC,eAAe;;AAKzE,KAAI,wBAAwB,yBAAyB,KACnD;OAAK,MAAM,QAAQ,qBACjB,KAAI,EAAE,QAAQ,OACZ,OAAM,IAAI,qBAAqB,QAAQ,OAAO,KAAK,CAAC,eAAe;;;AAM3E,SAAgB,aACd,MACA,UACM;AACN,KAAI,MAAM,QAAQ,KAAK,EACrB;OAAK,MAAM,OAAO,KAChB,KAAI,EAAE,OAAO,UACX,OAAM,IAAI,MAAM,OAAO,OAAO,IAAI,CAAC,wBAAwB;YAI3D,EAAE,QAAQ,UACZ,OAAM,IAAI,MAAM,OAAO,OAAO,KAAK,CAAC,wBAAwB"}
@@ -0,0 +1,44 @@
1
+ import { INTERRUPT } from "../constants.js";
2
+ import { PregelNode } from "./read.js";
3
+
4
+ //#region src/pregel/validate.ts
5
+ var GraphValidationError = class extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "GraphValidationError";
9
+ }
10
+ };
11
+ function validateGraph({ nodes, channels, inputChannels, outputChannels, streamChannels, interruptAfterNodes, interruptBeforeNodes }) {
12
+ if (!channels) throw new GraphValidationError("Channels not provided");
13
+ const subscribedChannels = /* @__PURE__ */ new Set();
14
+ const allOutputChannels = /* @__PURE__ */ new Set();
15
+ for (const [name, node] of Object.entries(nodes)) {
16
+ if (name === INTERRUPT) throw new GraphValidationError(`"Node name ${INTERRUPT} is reserved"`);
17
+ if (node.constructor === PregelNode) node.triggers.forEach((trigger) => subscribedChannels.add(trigger));
18
+ else throw new GraphValidationError(`Invalid node type ${typeof node}, expected PregelNode`);
19
+ }
20
+ for (const chan of subscribedChannels) if (!(chan in channels)) throw new GraphValidationError(`Subscribed channel '${String(chan)}' not in channels`);
21
+ if (!Array.isArray(inputChannels)) {
22
+ if (!subscribedChannels.has(inputChannels)) throw new GraphValidationError(`Input channel ${String(inputChannels)} is not subscribed to by any node`);
23
+ } else if (inputChannels.every((channel) => !subscribedChannels.has(channel))) throw new GraphValidationError(`None of the input channels ${inputChannels} are subscribed to by any node`);
24
+ if (!Array.isArray(outputChannels)) allOutputChannels.add(outputChannels);
25
+ else outputChannels.forEach((chan) => allOutputChannels.add(chan));
26
+ if (streamChannels && !Array.isArray(streamChannels)) allOutputChannels.add(streamChannels);
27
+ else if (Array.isArray(streamChannels)) streamChannels.forEach((chan) => allOutputChannels.add(chan));
28
+ for (const chan of allOutputChannels) if (!(chan in channels)) throw new GraphValidationError(`Output channel '${String(chan)}' not in channels`);
29
+ if (interruptAfterNodes && interruptAfterNodes !== "*") {
30
+ for (const node of interruptAfterNodes) if (!(node in nodes)) throw new GraphValidationError(`Node ${String(node)} not in nodes`);
31
+ }
32
+ if (interruptBeforeNodes && interruptBeforeNodes !== "*") {
33
+ for (const node of interruptBeforeNodes) if (!(node in nodes)) throw new GraphValidationError(`Node ${String(node)} not in nodes`);
34
+ }
35
+ }
36
+ function validateKeys(keys, channels) {
37
+ if (Array.isArray(keys)) {
38
+ for (const key of keys) if (!(key in channels)) throw new Error(`Key ${String(key)} not found in channels`);
39
+ } else if (!(keys in channels)) throw new Error(`Key ${String(keys)} not found in channels`);
40
+ }
41
+
42
+ //#endregion
43
+ export { validateGraph, validateKeys };
44
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","names":[],"sources":["../../src/pregel/validate.ts"],"sourcesContent":["import { All } from \"@langchain/langgraph-checkpoint\";\nimport { BaseChannel } from \"../channels/index.js\";\nimport { INTERRUPT } from \"../constants.js\";\nimport { PregelNode } from \"./read.js\";\n\nexport class GraphValidationError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"GraphValidationError\";\n }\n}\n\nexport function validateGraph<\n Nn extends Record<string, PregelNode>,\n Cc extends Record<string, BaseChannel>\n>({\n nodes,\n channels,\n inputChannels,\n outputChannels,\n streamChannels,\n interruptAfterNodes,\n interruptBeforeNodes,\n}: {\n nodes: Nn;\n channels: Cc;\n inputChannels: keyof Cc | Array<keyof Cc>;\n outputChannels: keyof Cc | Array<keyof Cc>;\n streamChannels?: keyof Cc | Array<keyof Cc>;\n interruptAfterNodes?: Array<keyof Nn> | All;\n interruptBeforeNodes?: Array<keyof Nn> | All;\n}): void {\n if (!channels) {\n throw new GraphValidationError(\"Channels not provided\");\n }\n\n const subscribedChannels = new Set<keyof Cc>();\n const allOutputChannels = new Set<keyof Cc>();\n\n for (const [name, node] of Object.entries(nodes)) {\n if (name === INTERRUPT) {\n throw new GraphValidationError(`\"Node name ${INTERRUPT} is reserved\"`);\n }\n if (node.constructor === PregelNode) {\n node.triggers.forEach((trigger) => subscribedChannels.add(trigger));\n } else {\n throw new GraphValidationError(\n `Invalid node type ${typeof node}, expected PregelNode`\n );\n }\n }\n\n // side effect: update channels\n for (const chan of subscribedChannels) {\n if (!(chan in channels)) {\n throw new GraphValidationError(\n `Subscribed channel '${String(chan)}' not in channels`\n );\n }\n }\n\n if (!Array.isArray(inputChannels)) {\n if (!subscribedChannels.has(inputChannels)) {\n throw new GraphValidationError(\n `Input channel ${String(\n inputChannels\n )} is not subscribed to by any node`\n );\n }\n } else {\n if (inputChannels.every((channel) => !subscribedChannels.has(channel))) {\n throw new GraphValidationError(\n `None of the input channels ${inputChannels} are subscribed to by any node`\n );\n }\n }\n\n if (!Array.isArray(outputChannels)) {\n allOutputChannels.add(outputChannels);\n } else {\n outputChannels.forEach((chan) => allOutputChannels.add(chan));\n }\n\n if (streamChannels && !Array.isArray(streamChannels)) {\n allOutputChannels.add(streamChannels);\n } else if (Array.isArray(streamChannels)) {\n streamChannels.forEach((chan) => allOutputChannels.add(chan));\n }\n\n for (const chan of allOutputChannels) {\n if (!(chan in channels)) {\n throw new GraphValidationError(\n `Output channel '${String(chan)}' not in channels`\n );\n }\n }\n\n // validate interrupt before/after\n if (interruptAfterNodes && interruptAfterNodes !== \"*\") {\n for (const node of interruptAfterNodes) {\n if (!(node in nodes)) {\n throw new GraphValidationError(`Node ${String(node)} not in nodes`);\n }\n }\n }\n\n if (interruptBeforeNodes && interruptBeforeNodes !== \"*\") {\n for (const node of interruptBeforeNodes) {\n if (!(node in nodes)) {\n throw new GraphValidationError(`Node ${String(node)} not in nodes`);\n }\n }\n }\n}\n\nexport function validateKeys<Cc extends Record<string, BaseChannel>>(\n keys: keyof Cc | Array<keyof Cc>,\n channels: Cc\n): void {\n if (Array.isArray(keys)) {\n for (const key of keys) {\n if (!(key in channels)) {\n throw new Error(`Key ${String(key)} not found in channels`);\n }\n }\n } else {\n if (!(keys in channels)) {\n throw new Error(`Key ${String(keys)} not found in channels`);\n }\n }\n}\n"],"mappings":";;;;AAKA,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAY,SAAkB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAIhB,SAAgB,cAGd,EACA,OACA,UACA,eACA,gBACA,gBACA,qBACA,wBASO;AACP,KAAI,CAAC,SACH,OAAM,IAAI,qBAAqB,wBAAwB;CAGzD,MAAM,qCAAqB,IAAI,KAAe;CAC9C,MAAM,oCAAoB,IAAI,KAAe;AAE7C,MAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,MAAM,EAAE;AAChD,MAAI,SAAS,UACX,OAAM,IAAI,qBAAqB,cAAc,UAAU,eAAe;AAExE,MAAI,KAAK,gBAAgB,WACvB,MAAK,SAAS,SAAS,YAAY,mBAAmB,IAAI,QAAQ,CAAC;MAEnE,OAAM,IAAI,qBACR,qBAAqB,OAAO,KAAK,uBAClC;;AAKL,MAAK,MAAM,QAAQ,mBACjB,KAAI,EAAE,QAAQ,UACZ,OAAM,IAAI,qBACR,uBAAuB,OAAO,KAAK,CAAC,mBACrC;AAIL,KAAI,CAAC,MAAM,QAAQ,cAAc,EAC/B;MAAI,CAAC,mBAAmB,IAAI,cAAc,CACxC,OAAM,IAAI,qBACR,iBAAiB,OACf,cACD,CAAC,mCACH;YAGC,cAAc,OAAO,YAAY,CAAC,mBAAmB,IAAI,QAAQ,CAAC,CACpE,OAAM,IAAI,qBACR,8BAA8B,cAAc,gCAC7C;AAIL,KAAI,CAAC,MAAM,QAAQ,eAAe,CAChC,mBAAkB,IAAI,eAAe;KAErC,gBAAe,SAAS,SAAS,kBAAkB,IAAI,KAAK,CAAC;AAG/D,KAAI,kBAAkB,CAAC,MAAM,QAAQ,eAAe,CAClD,mBAAkB,IAAI,eAAe;UAC5B,MAAM,QAAQ,eAAe,CACtC,gBAAe,SAAS,SAAS,kBAAkB,IAAI,KAAK,CAAC;AAG/D,MAAK,MAAM,QAAQ,kBACjB,KAAI,EAAE,QAAQ,UACZ,OAAM,IAAI,qBACR,mBAAmB,OAAO,KAAK,CAAC,mBACjC;AAKL,KAAI,uBAAuB,wBAAwB,KACjD;OAAK,MAAM,QAAQ,oBACjB,KAAI,EAAE,QAAQ,OACZ,OAAM,IAAI,qBAAqB,QAAQ,OAAO,KAAK,CAAC,eAAe;;AAKzE,KAAI,wBAAwB,yBAAyB,KACnD;OAAK,MAAM,QAAQ,qBACjB,KAAI,EAAE,QAAQ,OACZ,OAAM,IAAI,qBAAqB,QAAQ,OAAO,KAAK,CAAC,eAAe;;;AAM3E,SAAgB,aACd,MACA,UACM;AACN,KAAI,MAAM,QAAQ,KAAK,EACrB;OAAK,MAAM,OAAO,KAChB,KAAI,EAAE,OAAO,UACX,OAAM,IAAI,MAAM,OAAO,OAAO,IAAI,CAAC,wBAAwB;YAI3D,EAAE,QAAQ,UACZ,OAAM,IAAI,MAAM,OAAO,OAAO,KAAK,CAAC,wBAAwB"}
@@ -0,0 +1,96 @@
1
+ const require_errors = require('../errors.cjs');
2
+ const require_constants = require('../constants.cjs');
3
+ const require_utils = require('../utils.cjs');
4
+ let _langchain_core_runnables = require("@langchain/core/runnables");
5
+
6
+ //#region src/pregel/write.ts
7
+ const SKIP_WRITE = { [Symbol.for("LG_SKIP_WRITE")]: true };
8
+ function _isSkipWrite(x) {
9
+ return typeof x === "object" && x?.[Symbol.for("LG_SKIP_WRITE")] !== void 0;
10
+ }
11
+ const PASSTHROUGH = { [Symbol.for("LG_PASSTHROUGH")]: true };
12
+ function _isPassthrough(x) {
13
+ return typeof x === "object" && x?.[Symbol.for("LG_PASSTHROUGH")] !== void 0;
14
+ }
15
+ const IS_WRITER = Symbol("IS_WRITER");
16
+ /**
17
+ * Mapping of write channels to Runnables that return the value to be written,
18
+ * or None to skip writing.
19
+ */
20
+ var ChannelWrite = class ChannelWrite extends require_utils.RunnableCallable {
21
+ writes;
22
+ constructor(writes, tags) {
23
+ const name = `ChannelWrite<${writes.map((packet) => {
24
+ if (require_constants._isSend(packet)) return packet.node;
25
+ else if ("channel" in packet) return packet.channel;
26
+ return "...";
27
+ }).join(",")}>`;
28
+ super({
29
+ writes,
30
+ name,
31
+ tags,
32
+ func: async (input, config) => {
33
+ return this._write(input, config ?? {});
34
+ }
35
+ });
36
+ this.writes = writes;
37
+ }
38
+ async _write(input, config) {
39
+ const writes = this.writes.map((write) => {
40
+ if (_isChannelWriteTupleEntry(write) && _isPassthrough(write.value)) return {
41
+ mapper: write.mapper,
42
+ value: input
43
+ };
44
+ else if (_isChannelWriteEntry(write) && _isPassthrough(write.value)) return {
45
+ channel: write.channel,
46
+ value: input,
47
+ skipNone: write.skipNone,
48
+ mapper: write.mapper
49
+ };
50
+ else return write;
51
+ });
52
+ await ChannelWrite.doWrite(config, writes);
53
+ return input;
54
+ }
55
+ static async doWrite(config, writes) {
56
+ for (const w of writes) {
57
+ if (_isChannelWriteEntry(w)) {
58
+ if (w.channel === require_constants.TASKS) throw new require_errors.InvalidUpdateError("Cannot write to the reserved channel TASKS");
59
+ if (_isPassthrough(w.value)) throw new require_errors.InvalidUpdateError("PASSTHROUGH value must be replaced");
60
+ }
61
+ if (_isChannelWriteTupleEntry(w)) {
62
+ if (_isPassthrough(w.value)) throw new require_errors.InvalidUpdateError("PASSTHROUGH value must be replaced");
63
+ }
64
+ }
65
+ const writeEntries = [];
66
+ for (const w of writes) if (require_constants._isSend(w)) writeEntries.push([require_constants.TASKS, w]);
67
+ else if (_isChannelWriteTupleEntry(w)) {
68
+ const mappedResult = await w.mapper.invoke(w.value, config);
69
+ if (mappedResult != null && mappedResult.length > 0) writeEntries.push(...mappedResult);
70
+ } else if (_isChannelWriteEntry(w)) {
71
+ const mappedValue = w.mapper !== void 0 ? await w.mapper.invoke(w.value, config) : w.value;
72
+ if (_isSkipWrite(mappedValue)) continue;
73
+ if (w.skipNone && mappedValue === void 0) continue;
74
+ writeEntries.push([w.channel, mappedValue]);
75
+ } else throw new Error(`Invalid write entry: ${JSON.stringify(w)}`);
76
+ const write = config.configurable?.[require_constants.CONFIG_KEY_SEND];
77
+ write(writeEntries);
78
+ }
79
+ static isWriter(runnable) {
80
+ return runnable instanceof ChannelWrite || IS_WRITER in runnable && !!runnable[IS_WRITER];
81
+ }
82
+ static registerWriter(runnable) {
83
+ return Object.defineProperty(runnable, IS_WRITER, { value: true });
84
+ }
85
+ };
86
+ function _isChannelWriteEntry(x) {
87
+ return x !== void 0 && typeof x.channel === "string";
88
+ }
89
+ function _isChannelWriteTupleEntry(x) {
90
+ return x !== void 0 && !_isChannelWriteEntry(x) && _langchain_core_runnables.Runnable.isRunnable(x.mapper);
91
+ }
92
+
93
+ //#endregion
94
+ exports.ChannelWrite = ChannelWrite;
95
+ exports.PASSTHROUGH = PASSTHROUGH;
96
+ //# sourceMappingURL=write.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.cjs","names":["RunnableCallable","_isSend","TASKS","InvalidUpdateError","CONFIG_KEY_SEND","Runnable"],"sources":["../../src/pregel/write.ts"],"sourcesContent":["import {\n Runnable,\n RunnableConfig,\n RunnableLike,\n} from \"@langchain/core/runnables\";\nimport { _isSend, CONFIG_KEY_SEND, Send, TASKS } from \"../constants.js\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { InvalidUpdateError } from \"../errors.js\";\n\ntype TYPE_SEND = (values: Array<[string, unknown]>) => void;\n\nexport const SKIP_WRITE = {\n [Symbol.for(\"LG_SKIP_WRITE\")]: true,\n};\n\nfunction _isSkipWrite(x: unknown) {\n return (\n typeof x === \"object\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x as any)?.[Symbol.for(\"LG_SKIP_WRITE\")] !== undefined\n );\n}\n\nexport const PASSTHROUGH = {\n [Symbol.for(\"LG_PASSTHROUGH\")]: true,\n};\n\nfunction _isPassthrough(x: unknown) {\n return (\n typeof x === \"object\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x as any)?.[Symbol.for(\"LG_PASSTHROUGH\")] !== undefined\n );\n}\n\nconst IS_WRITER = Symbol(\"IS_WRITER\");\n\n/**\n * Mapping of write channels to Runnables that return the value to be written,\n * or None to skip writing.\n */\nexport class ChannelWrite<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput = any\n> extends RunnableCallable<RunInput, RunInput> {\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;\n\n constructor(\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>,\n tags?: string[]\n ) {\n const name = `ChannelWrite<${writes\n .map((packet) => {\n if (_isSend(packet)) {\n return packet.node;\n } else if (\"channel\" in packet) {\n return packet.channel;\n }\n return \"...\";\n })\n .join(\",\")}>`;\n super({\n ...{ writes, name, tags },\n func: async (input: RunInput, config?: RunnableConfig) => {\n return this._write(input, config ?? {});\n },\n });\n\n this.writes = writes;\n }\n\n async _write(input: unknown, config: RunnableConfig): Promise<unknown> {\n const writes = this.writes.map((write) => {\n if (_isChannelWriteTupleEntry(write) && _isPassthrough(write.value)) {\n return {\n mapper: write.mapper,\n value: input,\n };\n } else if (_isChannelWriteEntry(write) && _isPassthrough(write.value)) {\n return {\n channel: write.channel,\n value: input,\n skipNone: write.skipNone,\n mapper: write.mapper,\n };\n } else {\n return write;\n }\n });\n await ChannelWrite.doWrite(config, writes);\n return input;\n }\n\n // TODO: Support requireAtLeastOneOf\n static async doWrite(\n config: RunnableConfig,\n writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]\n ): Promise<void> {\n // validate\n for (const w of writes) {\n if (_isChannelWriteEntry(w)) {\n if (w.channel === TASKS) {\n throw new InvalidUpdateError(\n \"Cannot write to the reserved channel TASKS\"\n );\n }\n if (_isPassthrough(w.value)) {\n throw new InvalidUpdateError(\"PASSTHROUGH value must be replaced\");\n }\n }\n if (_isChannelWriteTupleEntry(w)) {\n if (_isPassthrough(w.value)) {\n throw new InvalidUpdateError(\"PASSTHROUGH value must be replaced\");\n }\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const writeEntries: [string, any][] = [];\n for (const w of writes) {\n if (_isSend(w)) {\n writeEntries.push([TASKS, w]);\n } else if (_isChannelWriteTupleEntry(w)) {\n const mappedResult = await w.mapper.invoke(w.value, config);\n if (mappedResult != null && mappedResult.length > 0) {\n writeEntries.push(...mappedResult);\n }\n } else if (_isChannelWriteEntry(w)) {\n const mappedValue =\n w.mapper !== undefined\n ? await w.mapper.invoke(w.value, config)\n : w.value;\n if (_isSkipWrite(mappedValue)) {\n continue;\n }\n if (w.skipNone && mappedValue === undefined) {\n continue;\n }\n writeEntries.push([w.channel, mappedValue]);\n } else {\n throw new Error(`Invalid write entry: ${JSON.stringify(w)}`);\n }\n }\n const write: TYPE_SEND = config.configurable?.[CONFIG_KEY_SEND];\n write(writeEntries);\n }\n\n static isWriter(runnable: RunnableLike): runnable is ChannelWrite {\n return (\n // eslint-disable-next-line no-instanceof/no-instanceof\n runnable instanceof ChannelWrite ||\n (IS_WRITER in runnable && !!runnable[IS_WRITER])\n );\n }\n\n static registerWriter<T extends Runnable>(runnable: T): T {\n return Object.defineProperty(runnable, IS_WRITER, { value: true });\n }\n}\n\nexport interface ChannelWriteEntry {\n channel: string;\n value: unknown;\n skipNone?: boolean;\n mapper?: Runnable;\n}\n\nfunction _isChannelWriteEntry(x: unknown): x is ChannelWriteEntry {\n return (\n x !== undefined && typeof (x as ChannelWriteEntry).channel === \"string\"\n );\n}\n\nexport interface ChannelWriteTupleEntry {\n value: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n mapper: Runnable<any, [string, any][]>;\n}\n\nfunction _isChannelWriteTupleEntry(x: unknown): x is ChannelWriteTupleEntry {\n return (\n x !== undefined &&\n !_isChannelWriteEntry(x) &&\n Runnable.isRunnable((x as ChannelWriteTupleEntry).mapper)\n );\n}\n"],"mappings":"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"}
@@ -0,0 +1,31 @@
1
+ import { RunnableCallable } from "../utils.cjs";
2
+ import { Send } from "../constants.cjs";
3
+ import { Runnable, RunnableConfig, RunnableLike } from "@langchain/core/runnables";
4
+
5
+ //#region src/pregel/write.d.ts
6
+
7
+ /**
8
+ * Mapping of write channels to Runnables that return the value to be written,
9
+ * or None to skip writing.
10
+ */
11
+ declare class ChannelWrite<RunInput = any> extends RunnableCallable<RunInput, RunInput> {
12
+ writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;
13
+ constructor(writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>, tags?: string[]);
14
+ _write(input: unknown, config: RunnableConfig): Promise<unknown>;
15
+ static doWrite(config: RunnableConfig, writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]): Promise<void>;
16
+ static isWriter(runnable: RunnableLike): runnable is ChannelWrite;
17
+ static registerWriter<T extends Runnable>(runnable: T): T;
18
+ }
19
+ interface ChannelWriteEntry {
20
+ channel: string;
21
+ value: unknown;
22
+ skipNone?: boolean;
23
+ mapper?: Runnable;
24
+ }
25
+ interface ChannelWriteTupleEntry {
26
+ value: unknown;
27
+ mapper: Runnable<any, [string, any][]>;
28
+ }
29
+ //#endregion
30
+ export { ChannelWrite };
31
+ //# sourceMappingURL=write.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.cts","names":["Runnable","RunnableConfig","RunnableLike","Send","RunnableCallable","SKIP_WRITE","PASSTHROUGH","ChannelWrite","RunInput","ChannelWriteEntry","ChannelWriteTupleEntry","Array","Promise","T"],"sources":["../../src/pregel/write.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig, RunnableLike } from \"@langchain/core/runnables\";\nimport { Send } from \"../constants.js\";\nimport { RunnableCallable } from \"../utils.js\";\nexport declare const SKIP_WRITE: {\n [x: symbol]: boolean;\n};\nexport declare const PASSTHROUGH: {\n [x: symbol]: boolean;\n};\n/**\n * Mapping of write channels to Runnables that return the value to be written,\n * or None to skip writing.\n */\nexport declare class ChannelWrite<RunInput = any> extends RunnableCallable<RunInput, RunInput> {\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;\n constructor(writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>, tags?: string[]);\n _write(input: unknown, config: RunnableConfig): Promise<unknown>;\n static doWrite(config: RunnableConfig, writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]): Promise<void>;\n static isWriter(runnable: RunnableLike): runnable is ChannelWrite;\n static registerWriter<T extends Runnable>(runnable: T): T;\n}\nexport interface ChannelWriteEntry {\n channel: string;\n value: unknown;\n skipNone?: boolean;\n mapper?: Runnable;\n}\nexport interface ChannelWriteTupleEntry {\n value: unknown;\n mapper: Runnable<any, [string, any][]>;\n}\n"],"mappings":";;;;;;;;;;AAe8BS,cAFTF,YAESE,CAAAA,WAAAA,GAAAA,CAAAA,SAF4BL,gBAE5BK,CAF6CD,QAE7CC,EAFuDD,QAEvDC,CAAAA,CAAAA;QAAoBC,EADtCC,KACsCD,CADhCD,iBACgCC,GADZA,sBACYA,GADaP,IACbO,CAAAA;aAAyBP,CAAAA,MAAAA,EAAnDQ,KAAmDR,CAA7CM,iBAA6CN,GAAzBO,sBAAyBP,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA,CAAAA,EAAAA,MAAAA,EAAAA;QAAnDQ,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,MAAAA,EACWV,cADXU,CAAAA,EAC4BC,OAD5BD,CAAAA,OAAAA,CAAAA;SACWV,OAAAA,CAAAA,MAAAA,EACRA,cADQA,EAAAA,MAAAA,EAAAA,CACiBQ,iBADjBR,GACqCS,sBADrCT,GAC8DE,IAD9DF,CAAAA,EAAAA,CAAAA,EACwEW,OADxEX,CAAAA,IAAAA,CAAAA;SAAiBW,QAAAA,CAAAA,QAAAA,EAEtBV,YAFsBU,CAAAA,EAAAA,QAAAA,IAEKL,YAFLK;SACzBX,cAAAA,CAAAA,UAESD,QAFTC,CAAAA,CAAAA,QAAAA,EAE6BY,CAF7BZ,CAAAA,EAEiCY,CAFjCZ;;AAA6CS,UAIvDD,iBAAAA,CAJuDC;SAAyBP,EAAAA,MAAAA;OAAUS,EAAAA,OAAAA;UAC7EV,CAAAA,EAAAA,OAAAA;QAA2BK,CAAAA,EAO5CP,QAP4CO;;AACDM,UAQvCH,sBAAAA,CARuCG;OAAIA,EAAAA,OAAAA;QANFT,EAgB9CJ,QAhB8CI,CAAAA,GAAAA,EAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,EAAAA,CAAAA"}
@@ -0,0 +1,31 @@
1
+ import { RunnableCallable } from "../utils.js";
2
+ import { Send } from "../constants.js";
3
+ import { Runnable, RunnableConfig, RunnableLike } from "@langchain/core/runnables";
4
+
5
+ //#region src/pregel/write.d.ts
6
+
7
+ /**
8
+ * Mapping of write channels to Runnables that return the value to be written,
9
+ * or None to skip writing.
10
+ */
11
+ declare class ChannelWrite<RunInput = any> extends RunnableCallable<RunInput, RunInput> {
12
+ writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;
13
+ constructor(writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>, tags?: string[]);
14
+ _write(input: unknown, config: RunnableConfig): Promise<unknown>;
15
+ static doWrite(config: RunnableConfig, writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]): Promise<void>;
16
+ static isWriter(runnable: RunnableLike): runnable is ChannelWrite;
17
+ static registerWriter<T extends Runnable>(runnable: T): T;
18
+ }
19
+ interface ChannelWriteEntry {
20
+ channel: string;
21
+ value: unknown;
22
+ skipNone?: boolean;
23
+ mapper?: Runnable;
24
+ }
25
+ interface ChannelWriteTupleEntry {
26
+ value: unknown;
27
+ mapper: Runnable<any, [string, any][]>;
28
+ }
29
+ //#endregion
30
+ export { ChannelWrite };
31
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","names":["Runnable","RunnableConfig","RunnableLike","Send","RunnableCallable","SKIP_WRITE","PASSTHROUGH","ChannelWrite","RunInput","ChannelWriteEntry","ChannelWriteTupleEntry","Array","Promise","T"],"sources":["../../src/pregel/write.d.ts"],"sourcesContent":["import { Runnable, RunnableConfig, RunnableLike } from \"@langchain/core/runnables\";\nimport { Send } from \"../constants.js\";\nimport { RunnableCallable } from \"../utils.js\";\nexport declare const SKIP_WRITE: {\n [x: symbol]: boolean;\n};\nexport declare const PASSTHROUGH: {\n [x: symbol]: boolean;\n};\n/**\n * Mapping of write channels to Runnables that return the value to be written,\n * or None to skip writing.\n */\nexport declare class ChannelWrite<RunInput = any> extends RunnableCallable<RunInput, RunInput> {\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;\n constructor(writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>, tags?: string[]);\n _write(input: unknown, config: RunnableConfig): Promise<unknown>;\n static doWrite(config: RunnableConfig, writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]): Promise<void>;\n static isWriter(runnable: RunnableLike): runnable is ChannelWrite;\n static registerWriter<T extends Runnable>(runnable: T): T;\n}\nexport interface ChannelWriteEntry {\n channel: string;\n value: unknown;\n skipNone?: boolean;\n mapper?: Runnable;\n}\nexport interface ChannelWriteTupleEntry {\n value: unknown;\n mapper: Runnable<any, [string, any][]>;\n}\n"],"mappings":";;;;;;;;;;AAe8BS,cAFTF,YAESE,CAAAA,WAAAA,GAAAA,CAAAA,SAF4BL,gBAE5BK,CAF6CD,QAE7CC,EAFuDD,QAEvDC,CAAAA,CAAAA;QAAoBC,EADtCC,KACsCD,CADhCD,iBACgCC,GADZA,sBACYA,GADaP,IACbO,CAAAA;aAAyBP,CAAAA,MAAAA,EAAnDQ,KAAmDR,CAA7CM,iBAA6CN,GAAzBO,sBAAyBP,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA,CAAAA,EAAAA,MAAAA,EAAAA;QAAnDQ,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,MAAAA,EACWV,cADXU,CAAAA,EAC4BC,OAD5BD,CAAAA,OAAAA,CAAAA;SACWV,OAAAA,CAAAA,MAAAA,EACRA,cADQA,EAAAA,MAAAA,EAAAA,CACiBQ,iBADjBR,GACqCS,sBADrCT,GAC8DE,IAD9DF,CAAAA,EAAAA,CAAAA,EACwEW,OADxEX,CAAAA,IAAAA,CAAAA;SAAiBW,QAAAA,CAAAA,QAAAA,EAEtBV,YAFsBU,CAAAA,EAAAA,QAAAA,IAEKL,YAFLK;SACzBX,cAAAA,CAAAA,UAESD,QAFTC,CAAAA,CAAAA,QAAAA,EAE6BY,CAF7BZ,CAAAA,EAEiCY,CAFjCZ;;AAA6CS,UAIvDD,iBAAAA,CAJuDC;SAAyBP,EAAAA,MAAAA;OAAUS,EAAAA,OAAAA;UAC7EV,CAAAA,EAAAA,OAAAA;QAA2BK,CAAAA,EAO5CP,QAP4CO;;AACDM,UAQvCH,sBAAAA,CARuCG;OAAIA,EAAAA,OAAAA;QANFT,EAgB9CJ,QAhB8CI,CAAAA,GAAAA,EAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,EAAAA,CAAAA"}
@@ -0,0 +1,95 @@
1
+ import { InvalidUpdateError } from "../errors.js";
2
+ import { CONFIG_KEY_SEND, TASKS, _isSend } from "../constants.js";
3
+ import { RunnableCallable } from "../utils.js";
4
+ import { Runnable } from "@langchain/core/runnables";
5
+
6
+ //#region src/pregel/write.ts
7
+ const SKIP_WRITE = { [Symbol.for("LG_SKIP_WRITE")]: true };
8
+ function _isSkipWrite(x) {
9
+ return typeof x === "object" && x?.[Symbol.for("LG_SKIP_WRITE")] !== void 0;
10
+ }
11
+ const PASSTHROUGH = { [Symbol.for("LG_PASSTHROUGH")]: true };
12
+ function _isPassthrough(x) {
13
+ return typeof x === "object" && x?.[Symbol.for("LG_PASSTHROUGH")] !== void 0;
14
+ }
15
+ const IS_WRITER = Symbol("IS_WRITER");
16
+ /**
17
+ * Mapping of write channels to Runnables that return the value to be written,
18
+ * or None to skip writing.
19
+ */
20
+ var ChannelWrite = class ChannelWrite extends RunnableCallable {
21
+ writes;
22
+ constructor(writes, tags) {
23
+ const name = `ChannelWrite<${writes.map((packet) => {
24
+ if (_isSend(packet)) return packet.node;
25
+ else if ("channel" in packet) return packet.channel;
26
+ return "...";
27
+ }).join(",")}>`;
28
+ super({
29
+ writes,
30
+ name,
31
+ tags,
32
+ func: async (input, config) => {
33
+ return this._write(input, config ?? {});
34
+ }
35
+ });
36
+ this.writes = writes;
37
+ }
38
+ async _write(input, config) {
39
+ const writes = this.writes.map((write) => {
40
+ if (_isChannelWriteTupleEntry(write) && _isPassthrough(write.value)) return {
41
+ mapper: write.mapper,
42
+ value: input
43
+ };
44
+ else if (_isChannelWriteEntry(write) && _isPassthrough(write.value)) return {
45
+ channel: write.channel,
46
+ value: input,
47
+ skipNone: write.skipNone,
48
+ mapper: write.mapper
49
+ };
50
+ else return write;
51
+ });
52
+ await ChannelWrite.doWrite(config, writes);
53
+ return input;
54
+ }
55
+ static async doWrite(config, writes) {
56
+ for (const w of writes) {
57
+ if (_isChannelWriteEntry(w)) {
58
+ if (w.channel === TASKS) throw new InvalidUpdateError("Cannot write to the reserved channel TASKS");
59
+ if (_isPassthrough(w.value)) throw new InvalidUpdateError("PASSTHROUGH value must be replaced");
60
+ }
61
+ if (_isChannelWriteTupleEntry(w)) {
62
+ if (_isPassthrough(w.value)) throw new InvalidUpdateError("PASSTHROUGH value must be replaced");
63
+ }
64
+ }
65
+ const writeEntries = [];
66
+ for (const w of writes) if (_isSend(w)) writeEntries.push([TASKS, w]);
67
+ else if (_isChannelWriteTupleEntry(w)) {
68
+ const mappedResult = await w.mapper.invoke(w.value, config);
69
+ if (mappedResult != null && mappedResult.length > 0) writeEntries.push(...mappedResult);
70
+ } else if (_isChannelWriteEntry(w)) {
71
+ const mappedValue = w.mapper !== void 0 ? await w.mapper.invoke(w.value, config) : w.value;
72
+ if (_isSkipWrite(mappedValue)) continue;
73
+ if (w.skipNone && mappedValue === void 0) continue;
74
+ writeEntries.push([w.channel, mappedValue]);
75
+ } else throw new Error(`Invalid write entry: ${JSON.stringify(w)}`);
76
+ const write = config.configurable?.[CONFIG_KEY_SEND];
77
+ write(writeEntries);
78
+ }
79
+ static isWriter(runnable) {
80
+ return runnable instanceof ChannelWrite || IS_WRITER in runnable && !!runnable[IS_WRITER];
81
+ }
82
+ static registerWriter(runnable) {
83
+ return Object.defineProperty(runnable, IS_WRITER, { value: true });
84
+ }
85
+ };
86
+ function _isChannelWriteEntry(x) {
87
+ return x !== void 0 && typeof x.channel === "string";
88
+ }
89
+ function _isChannelWriteTupleEntry(x) {
90
+ return x !== void 0 && !_isChannelWriteEntry(x) && Runnable.isRunnable(x.mapper);
91
+ }
92
+
93
+ //#endregion
94
+ export { ChannelWrite, PASSTHROUGH };
95
+ //# sourceMappingURL=write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.js","names":[],"sources":["../../src/pregel/write.ts"],"sourcesContent":["import {\n Runnable,\n RunnableConfig,\n RunnableLike,\n} from \"@langchain/core/runnables\";\nimport { _isSend, CONFIG_KEY_SEND, Send, TASKS } from \"../constants.js\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { InvalidUpdateError } from \"../errors.js\";\n\ntype TYPE_SEND = (values: Array<[string, unknown]>) => void;\n\nexport const SKIP_WRITE = {\n [Symbol.for(\"LG_SKIP_WRITE\")]: true,\n};\n\nfunction _isSkipWrite(x: unknown) {\n return (\n typeof x === \"object\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x as any)?.[Symbol.for(\"LG_SKIP_WRITE\")] !== undefined\n );\n}\n\nexport const PASSTHROUGH = {\n [Symbol.for(\"LG_PASSTHROUGH\")]: true,\n};\n\nfunction _isPassthrough(x: unknown) {\n return (\n typeof x === \"object\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x as any)?.[Symbol.for(\"LG_PASSTHROUGH\")] !== undefined\n );\n}\n\nconst IS_WRITER = Symbol(\"IS_WRITER\");\n\n/**\n * Mapping of write channels to Runnables that return the value to be written,\n * or None to skip writing.\n */\nexport class ChannelWrite<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput = any\n> extends RunnableCallable<RunInput, RunInput> {\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>;\n\n constructor(\n writes: Array<ChannelWriteEntry | ChannelWriteTupleEntry | Send>,\n tags?: string[]\n ) {\n const name = `ChannelWrite<${writes\n .map((packet) => {\n if (_isSend(packet)) {\n return packet.node;\n } else if (\"channel\" in packet) {\n return packet.channel;\n }\n return \"...\";\n })\n .join(\",\")}>`;\n super({\n ...{ writes, name, tags },\n func: async (input: RunInput, config?: RunnableConfig) => {\n return this._write(input, config ?? {});\n },\n });\n\n this.writes = writes;\n }\n\n async _write(input: unknown, config: RunnableConfig): Promise<unknown> {\n const writes = this.writes.map((write) => {\n if (_isChannelWriteTupleEntry(write) && _isPassthrough(write.value)) {\n return {\n mapper: write.mapper,\n value: input,\n };\n } else if (_isChannelWriteEntry(write) && _isPassthrough(write.value)) {\n return {\n channel: write.channel,\n value: input,\n skipNone: write.skipNone,\n mapper: write.mapper,\n };\n } else {\n return write;\n }\n });\n await ChannelWrite.doWrite(config, writes);\n return input;\n }\n\n // TODO: Support requireAtLeastOneOf\n static async doWrite(\n config: RunnableConfig,\n writes: (ChannelWriteEntry | ChannelWriteTupleEntry | Send)[]\n ): Promise<void> {\n // validate\n for (const w of writes) {\n if (_isChannelWriteEntry(w)) {\n if (w.channel === TASKS) {\n throw new InvalidUpdateError(\n \"Cannot write to the reserved channel TASKS\"\n );\n }\n if (_isPassthrough(w.value)) {\n throw new InvalidUpdateError(\"PASSTHROUGH value must be replaced\");\n }\n }\n if (_isChannelWriteTupleEntry(w)) {\n if (_isPassthrough(w.value)) {\n throw new InvalidUpdateError(\"PASSTHROUGH value must be replaced\");\n }\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const writeEntries: [string, any][] = [];\n for (const w of writes) {\n if (_isSend(w)) {\n writeEntries.push([TASKS, w]);\n } else if (_isChannelWriteTupleEntry(w)) {\n const mappedResult = await w.mapper.invoke(w.value, config);\n if (mappedResult != null && mappedResult.length > 0) {\n writeEntries.push(...mappedResult);\n }\n } else if (_isChannelWriteEntry(w)) {\n const mappedValue =\n w.mapper !== undefined\n ? await w.mapper.invoke(w.value, config)\n : w.value;\n if (_isSkipWrite(mappedValue)) {\n continue;\n }\n if (w.skipNone && mappedValue === undefined) {\n continue;\n }\n writeEntries.push([w.channel, mappedValue]);\n } else {\n throw new Error(`Invalid write entry: ${JSON.stringify(w)}`);\n }\n }\n const write: TYPE_SEND = config.configurable?.[CONFIG_KEY_SEND];\n write(writeEntries);\n }\n\n static isWriter(runnable: RunnableLike): runnable is ChannelWrite {\n return (\n // eslint-disable-next-line no-instanceof/no-instanceof\n runnable instanceof ChannelWrite ||\n (IS_WRITER in runnable && !!runnable[IS_WRITER])\n );\n }\n\n static registerWriter<T extends Runnable>(runnable: T): T {\n return Object.defineProperty(runnable, IS_WRITER, { value: true });\n }\n}\n\nexport interface ChannelWriteEntry {\n channel: string;\n value: unknown;\n skipNone?: boolean;\n mapper?: Runnable;\n}\n\nfunction _isChannelWriteEntry(x: unknown): x is ChannelWriteEntry {\n return (\n x !== undefined && typeof (x as ChannelWriteEntry).channel === \"string\"\n );\n}\n\nexport interface ChannelWriteTupleEntry {\n value: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n mapper: Runnable<any, [string, any][]>;\n}\n\nfunction _isChannelWriteTupleEntry(x: unknown): x is ChannelWriteTupleEntry {\n return (\n x !== undefined &&\n !_isChannelWriteEntry(x) &&\n Runnable.isRunnable((x as ChannelWriteTupleEntry).mapper)\n );\n}\n"],"mappings":";;;;;;AAWA,MAAa,aAAa,GACvB,OAAO,IAAI,gBAAgB,GAAG,MAChC;AAED,SAAS,aAAa,GAAY;AAChC,QACE,OAAO,MAAM,YAEZ,IAAY,OAAO,IAAI,gBAAgB,MAAM;;AAIlD,MAAa,cAAc,GACxB,OAAO,IAAI,iBAAiB,GAAG,MACjC;AAED,SAAS,eAAe,GAAY;AAClC,QACE,OAAO,MAAM,YAEZ,IAAY,OAAO,IAAI,iBAAiB,MAAM;;AAInD,MAAM,YAAY,OAAO,YAAY;;;;;AAMrC,IAAa,eAAb,MAAa,qBAGH,iBAAqC;CAC7C;CAEA,YACE,QACA,MACA;EACA,MAAM,OAAO,gBAAgB,OAC1B,KAAK,WAAW;AACf,OAAI,QAAQ,OAAO,CACjB,QAAO,OAAO;YACL,aAAa,OACtB,QAAO,OAAO;AAEhB,UAAO;IACP,CACD,KAAK,IAAI,CAAC;AACb,QAAM;GACC;GAAQ;GAAM;GACnB,MAAM,OAAO,OAAiB,WAA4B;AACxD,WAAO,KAAK,OAAO,OAAO,UAAU,EAAE,CAAC;;GAE1C,CAAC;AAEF,OAAK,SAAS;;CAGhB,MAAM,OAAO,OAAgB,QAA0C;EACrE,MAAM,SAAS,KAAK,OAAO,KAAK,UAAU;AACxC,OAAI,0BAA0B,MAAM,IAAI,eAAe,MAAM,MAAM,CACjE,QAAO;IACL,QAAQ,MAAM;IACd,OAAO;IACR;YACQ,qBAAqB,MAAM,IAAI,eAAe,MAAM,MAAM,CACnE,QAAO;IACL,SAAS,MAAM;IACf,OAAO;IACP,UAAU,MAAM;IAChB,QAAQ,MAAM;IACf;OAED,QAAO;IAET;AACF,QAAM,aAAa,QAAQ,QAAQ,OAAO;AAC1C,SAAO;;CAIT,aAAa,QACX,QACA,QACe;AAEf,OAAK,MAAM,KAAK,QAAQ;AACtB,OAAI,qBAAqB,EAAE,EAAE;AAC3B,QAAI,EAAE,YAAY,MAChB,OAAM,IAAI,mBACR,6CACD;AAEH,QAAI,eAAe,EAAE,MAAM,CACzB,OAAM,IAAI,mBAAmB,qCAAqC;;AAGtE,OAAI,0BAA0B,EAAE,EAC9B;QAAI,eAAe,EAAE,MAAM,CACzB,OAAM,IAAI,mBAAmB,qCAAqC;;;EAKxE,MAAM,eAAgC,EAAE;AACxC,OAAK,MAAM,KAAK,OACd,KAAI,QAAQ,EAAE,CACZ,cAAa,KAAK,CAAC,OAAO,EAAE,CAAC;WACpB,0BAA0B,EAAE,EAAE;GACvC,MAAM,eAAe,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,OAAO;AAC3D,OAAI,gBAAgB,QAAQ,aAAa,SAAS,EAChD,cAAa,KAAK,GAAG,aAAa;aAE3B,qBAAqB,EAAE,EAAE;GAClC,MAAM,cACJ,EAAE,WAAW,SACT,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,OAAO,GACtC,EAAE;AACR,OAAI,aAAa,YAAY,CAC3B;AAEF,OAAI,EAAE,YAAY,gBAAgB,OAChC;AAEF,gBAAa,KAAK,CAAC,EAAE,SAAS,YAAY,CAAC;QAE3C,OAAM,IAAI,MAAM,wBAAwB,KAAK,UAAU,EAAE,GAAG;EAGhE,MAAM,QAAmB,OAAO,eAAe;AAC/C,QAAM,aAAa;;CAGrB,OAAO,SAAS,UAAkD;AAChE,SAEE,oBAAoB,gBACnB,aAAa,YAAY,CAAC,CAAC,SAAS;;CAIzC,OAAO,eAAmC,UAAgB;AACxD,SAAO,OAAO,eAAe,UAAU,WAAW,EAAE,OAAO,MAAM,CAAC;;;AAWtE,SAAS,qBAAqB,GAAoC;AAChE,QACE,MAAM,UAAa,OAAQ,EAAwB,YAAY;;AAUnE,SAAS,0BAA0B,GAAyC;AAC1E,QACE,MAAM,UACN,CAAC,qBAAqB,EAAE,IACxB,SAAS,WAAY,EAA6B,OAAO"}
@@ -0,0 +1,3 @@
1
+ const require_remote = require('./pregel/remote.cjs');
2
+
3
+ exports.RemoteGraph = require_remote.RemoteGraph;
@@ -0,0 +1,2 @@
1
+ import { RemoteGraph, RemoteGraphParams } from "./pregel/remote.cjs";
2
+ export { RemoteGraph, type RemoteGraphParams };
@@ -0,0 +1,2 @@
1
+ import { RemoteGraph, RemoteGraphParams } from "./pregel/remote.js";
2
+ export { RemoteGraph, type RemoteGraphParams };
package/dist/remote.js ADDED
@@ -0,0 +1,3 @@
1
+ import { RemoteGraph } from "./pregel/remote.js";
2
+
3
+ export { RemoteGraph };
@@ -0,0 +1,11 @@
1
+ let _langchain_core_singletons = require("@langchain/core/singletons");
2
+ let node_async_hooks = require("node:async_hooks");
3
+
4
+ //#region src/setup/async_local_storage.ts
5
+ function initializeAsyncLocalStorageSingleton() {
6
+ _langchain_core_singletons.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new node_async_hooks.AsyncLocalStorage());
7
+ }
8
+
9
+ //#endregion
10
+ exports.initializeAsyncLocalStorageSingleton = initializeAsyncLocalStorageSingleton;
11
+ //# sourceMappingURL=async_local_storage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async_local_storage.cjs","names":["AsyncLocalStorage"],"sources":["../../src/setup/async_local_storage.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport function initializeAsyncLocalStorageSingleton() {\n AsyncLocalStorageProviderSingleton.initializeGlobalInstance(\n new AsyncLocalStorage()\n );\n}\n"],"mappings":";;;;AAGA,SAAgB,uCAAuC;AACrD,+DAAmC,yBACjC,IAAIA,oCAAmB,CACxB"}