@langchain/langgraph 0.4.8 → 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 +7 -2
  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 +83 -86
  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,461 +1,345 @@
1
- import { Client, } from "@langchain/langgraph-sdk";
2
- import { Graph as DrawableGraph, } from "@langchain/core/runnables/graph";
3
- import { mergeConfigs, Runnable, } from "@langchain/core/runnables";
1
+ import { GraphInterrupt, RemoteException } from "../errors.js";
2
+ import { CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_STREAM, INTERRUPT, isCommand } from "../constants.js";
3
+ import "../web.js";
4
+ import { Runnable, mergeConfigs } from "@langchain/core/runnables";
5
+ import { Graph } from "@langchain/core/runnables/graph";
4
6
  import { isBaseMessage } from "@langchain/core/messages";
5
- import { GraphInterrupt, RemoteException, } from "../web.js";
6
- import { CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_STREAM, INTERRUPT, isCommand, } from "../constants.js";
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ import { Client } from "@langchain/langgraph-sdk";
8
+
9
+ //#region src/pregel/remote.ts
8
10
  const _serializeInputs = (obj) => {
9
- if (obj === null || typeof obj !== "object") {
10
- return obj;
11
- }
12
- if (Array.isArray(obj)) {
13
- return obj.map(_serializeInputs);
14
- }
15
- // Handle BaseMessage instances by converting them to a serializable format
16
- if (isBaseMessage(obj)) {
17
- const dict = obj.toDict();
18
- return {
19
- ...dict.data,
20
- role: obj.getType(),
21
- };
22
- }
23
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, _serializeInputs(value)]));
11
+ if (obj === null || typeof obj !== "object") return obj;
12
+ if (Array.isArray(obj)) return obj.map(_serializeInputs);
13
+ if (isBaseMessage(obj)) {
14
+ const dict = obj.toDict();
15
+ return {
16
+ ...dict.data,
17
+ role: obj.getType()
18
+ };
19
+ }
20
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, _serializeInputs(value)]));
24
21
  };
25
22
  /**
26
- * Return a tuple of the final list of stream modes sent to the
27
- * remote graph and a boolean flag indicating if only one stream mode was
28
- * originally requested and whether stream mode 'updates'
29
- * was present in the original list of stream modes.
30
- *
31
- * 'updates' mode is always added to the list of stream modes so that interrupts
32
- * can be detected in the remote graph.
33
- */
23
+ * Return a tuple of the final list of stream modes sent to the
24
+ * remote graph and a boolean flag indicating if only one stream mode was
25
+ * originally requested and whether stream mode 'updates'
26
+ * was present in the original list of stream modes.
27
+ *
28
+ * 'updates' mode is always added to the list of stream modes so that interrupts
29
+ * can be detected in the remote graph.
30
+ */
34
31
  const getStreamModes = (streamMode, defaultStreamMode = "updates") => {
35
- const updatedStreamModes = [];
36
- let reqUpdates = false;
37
- let reqSingle = true;
38
- if (streamMode !== undefined &&
39
- (typeof streamMode === "string" ||
40
- (Array.isArray(streamMode) && streamMode.length > 0))) {
41
- reqSingle = typeof streamMode === "string";
42
- const mapped = Array.isArray(streamMode) ? streamMode : [streamMode];
43
- updatedStreamModes.push(...mapped);
44
- }
45
- else {
46
- updatedStreamModes.push(defaultStreamMode);
47
- }
48
- if (updatedStreamModes.includes("updates")) {
49
- reqUpdates = true;
50
- }
51
- else {
52
- updatedStreamModes.push("updates");
53
- }
54
- return {
55
- updatedStreamModes,
56
- reqUpdates,
57
- reqSingle,
58
- };
32
+ const updatedStreamModes = [];
33
+ let reqUpdates = false;
34
+ let reqSingle = true;
35
+ if (streamMode !== void 0 && (typeof streamMode === "string" || Array.isArray(streamMode) && streamMode.length > 0)) {
36
+ reqSingle = typeof streamMode === "string";
37
+ const mapped = Array.isArray(streamMode) ? streamMode : [streamMode];
38
+ updatedStreamModes.push(...mapped);
39
+ } else updatedStreamModes.push(defaultStreamMode);
40
+ if (updatedStreamModes.includes("updates")) reqUpdates = true;
41
+ else updatedStreamModes.push("updates");
42
+ return {
43
+ updatedStreamModes,
44
+ reqUpdates,
45
+ reqSingle
46
+ };
59
47
  };
60
48
  /**
61
- * The `RemoteGraph` class is a client implementation for calling remote
62
- * APIs that implement the LangGraph Server API specification.
63
- *
64
- * For example, the `RemoteGraph` class can be used to call APIs from deployments
65
- * on LangGraph Cloud.
66
- *
67
- * `RemoteGraph` behaves the same way as a `StateGraph` and can be used directly as
68
- * a node in another `StateGraph`.
69
- *
70
- * @example
71
- * ```ts
72
- * import { RemoteGraph } from "@langchain/langgraph/remote";
73
- *
74
- * // Can also pass a LangGraph SDK client instance directly
75
- * const remoteGraph = new RemoteGraph({
76
- * graphId: process.env.LANGGRAPH_REMOTE_GRAPH_ID!,
77
- * apiKey: process.env.LANGGRAPH_REMOTE_GRAPH_API_KEY,
78
- * url: process.env.LANGGRAPH_REMOTE_GRAPH_API_URL,
79
- * });
80
- *
81
- * const input = {
82
- * messages: [
83
- * {
84
- * role: "human",
85
- * content: "Hello world!",
86
- * },
87
- * ],
88
- * };
89
- *
90
- * const config = {
91
- * configurable: { thread_id: "threadId1" },
92
- * };
93
- *
94
- * await remoteGraph.invoke(input, config);
95
- * ```
96
- */
97
- export class RemoteGraph extends Runnable {
98
- static lc_name() {
99
- return "RemoteGraph";
100
- }
101
- constructor(params) {
102
- super(params);
103
- Object.defineProperty(this, "lc_namespace", {
104
- enumerable: true,
105
- configurable: true,
106
- writable: true,
107
- value: ["langgraph", "pregel"]
108
- });
109
- Object.defineProperty(this, "lg_is_pregel", {
110
- enumerable: true,
111
- configurable: true,
112
- writable: true,
113
- value: true
114
- });
115
- Object.defineProperty(this, "config", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: void 0
120
- });
121
- Object.defineProperty(this, "graphId", {
122
- enumerable: true,
123
- configurable: true,
124
- writable: true,
125
- value: void 0
126
- });
127
- Object.defineProperty(this, "client", {
128
- enumerable: true,
129
- configurable: true,
130
- writable: true,
131
- value: void 0
132
- });
133
- Object.defineProperty(this, "interruptBefore", {
134
- enumerable: true,
135
- configurable: true,
136
- writable: true,
137
- value: void 0
138
- });
139
- Object.defineProperty(this, "interruptAfter", {
140
- enumerable: true,
141
- configurable: true,
142
- writable: true,
143
- value: void 0
144
- });
145
- this.graphId = params.graphId;
146
- this.client =
147
- params.client ??
148
- new Client({
149
- apiUrl: params.url,
150
- apiKey: params.apiKey,
151
- defaultHeaders: params.headers,
152
- });
153
- this.config = params.config;
154
- this.interruptBefore = params.interruptBefore;
155
- this.interruptAfter = params.interruptAfter;
156
- }
157
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
158
- // @ts-ignore Remove ignore when we remove support for 0.2 versions of core
159
- withConfig(config) {
160
- const mergedConfig = mergeConfigs(this.config, config);
161
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- return new this.constructor({ ...this, config: mergedConfig });
163
- }
164
- _sanitizeConfig(config) {
165
- const reservedConfigurableKeys = new Set([
166
- "callbacks",
167
- "checkpoint_map",
168
- "checkpoint_id",
169
- "checkpoint_ns",
170
- ]);
171
- const sanitizeObj = (obj) => {
172
- try {
173
- // This will only throw if we're trying to serialize a circular reference
174
- // or trying to serialize a BigInt...
175
- JSON.stringify(obj);
176
- return obj;
177
- }
178
- catch {
179
- const seen = new WeakSet();
180
- return JSON.parse(JSON.stringify(obj, (_, value) => {
181
- if (typeof value === "object" && value != null) {
182
- if (seen.has(value))
183
- return "[Circular]";
184
- seen.add(value);
185
- }
186
- if (typeof value === "bigint")
187
- return value.toString();
188
- return value;
189
- }));
190
- }
191
- };
192
- // Remove non-JSON serializable fields from the config
193
- const sanitizedConfig = sanitizeObj(config);
194
- // Only include configurable keys that are not reserved and
195
- // not starting with "__pregel_" prefix
196
- const newConfigurable = Object.fromEntries(Object.entries(sanitizedConfig.configurable ?? {}).filter(([k]) => !reservedConfigurableKeys.has(k) && !k.startsWith("__pregel_")));
197
- return {
198
- tags: sanitizedConfig.tags ?? [],
199
- metadata: sanitizedConfig.metadata ?? {},
200
- configurable: newConfigurable,
201
- recursion_limit: sanitizedConfig.recursionLimit,
202
- };
203
- }
204
- _getConfig(checkpoint) {
205
- return {
206
- configurable: {
207
- thread_id: checkpoint.thread_id,
208
- checkpoint_ns: checkpoint.checkpoint_ns,
209
- checkpoint_id: checkpoint.checkpoint_id,
210
- checkpoint_map: checkpoint.checkpoint_map ?? {},
211
- },
212
- };
213
- }
214
- _getCheckpoint(config) {
215
- if (config?.configurable === undefined) {
216
- return undefined;
217
- }
218
- const checkpointKeys = [
219
- "thread_id",
220
- "checkpoint_ns",
221
- "checkpoint_id",
222
- "checkpoint_map",
223
- ];
224
- const checkpoint = Object.fromEntries(checkpointKeys
225
- .map((key) => [key, config.configurable[key]])
226
- .filter(([_, value]) => value !== undefined));
227
- return Object.keys(checkpoint).length > 0 ? checkpoint : undefined;
228
- }
229
- _createStateSnapshot(state) {
230
- const tasks = state.tasks.map((task) => {
231
- return {
232
- id: task.id,
233
- name: task.name,
234
- error: task.error ? { message: task.error } : undefined,
235
- // TODO: remove in LangGraph.js 0.4
236
- interrupts: task.interrupts.map(({ id, ...rest }) => ({
237
- interrupt_id: id,
238
- ...rest,
239
- })),
240
- // eslint-disable-next-line no-nested-ternary
241
- state: task.state
242
- ? this._createStateSnapshot(task.state)
243
- : task.checkpoint
244
- ? { configurable: task.checkpoint }
245
- : undefined,
246
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
- result: task.result,
248
- };
249
- });
250
- return {
251
- values: state.values,
252
- next: state.next ? [...state.next] : [],
253
- config: {
254
- configurable: {
255
- thread_id: state.checkpoint.thread_id,
256
- checkpoint_ns: state.checkpoint.checkpoint_ns,
257
- checkpoint_id: state.checkpoint.checkpoint_id,
258
- checkpoint_map: state.checkpoint.checkpoint_map ?? {},
259
- },
260
- },
261
- metadata: state.metadata
262
- ? state.metadata
263
- : undefined,
264
- createdAt: state.created_at ?? undefined,
265
- parentConfig: state.parent_checkpoint
266
- ? {
267
- configurable: {
268
- thread_id: state.parent_checkpoint.thread_id,
269
- checkpoint_ns: state.parent_checkpoint.checkpoint_ns,
270
- checkpoint_id: state.parent_checkpoint.checkpoint_id,
271
- checkpoint_map: state.parent_checkpoint.checkpoint_map ?? {},
272
- },
273
- }
274
- : undefined,
275
- tasks,
276
- };
277
- }
278
- async invoke(input, options) {
279
- let lastValue;
280
- const stream = await this.stream(input, {
281
- ...options,
282
- streamMode: "values",
283
- });
284
- for await (const chunk of stream) {
285
- lastValue = chunk;
286
- }
287
- return lastValue;
288
- }
289
- streamEvents(_input, _options) {
290
- throw new Error("Not implemented.");
291
- }
292
- async *_streamIterator(input, options) {
293
- const mergedConfig = mergeConfigs(this.config, options);
294
- const sanitizedConfig = this._sanitizeConfig(mergedConfig);
295
- const streamProtocolInstance = options?.configurable?.[CONFIG_KEY_STREAM];
296
- const streamSubgraphs = options?.subgraphs ?? streamProtocolInstance !== undefined;
297
- const interruptBefore = options?.interruptBefore ?? this.interruptBefore;
298
- const interruptAfter = options?.interruptAfter ?? this.interruptAfter;
299
- const { updatedStreamModes, reqSingle, reqUpdates } = getStreamModes(options?.streamMode);
300
- const extendedStreamModes = [
301
- ...new Set([
302
- ...updatedStreamModes,
303
- ...(streamProtocolInstance?.modes ?? new Set()),
304
- ]),
305
- ].map((mode) => {
306
- if (mode === "messages")
307
- return "messages-tuple";
308
- return mode;
309
- });
310
- let command;
311
- let serializedInput;
312
- if (isCommand(input)) {
313
- // TODO: Remove cast when SDK type fix gets merged
314
- command = input.toJSON();
315
- serializedInput = undefined;
316
- }
317
- else {
318
- serializedInput = _serializeInputs(input);
319
- }
320
- for await (const chunk of this.client.runs.stream(sanitizedConfig.configurable.thread_id, this.graphId, {
321
- command,
322
- input: serializedInput,
323
- config: sanitizedConfig,
324
- streamMode: extendedStreamModes,
325
- interruptBefore: interruptBefore,
326
- interruptAfter: interruptAfter,
327
- streamSubgraphs,
328
- ifNotExists: "create",
329
- signal: mergedConfig.signal,
330
- })) {
331
- let mode;
332
- let namespace;
333
- if (chunk.event.includes(CHECKPOINT_NAMESPACE_SEPARATOR)) {
334
- const eventComponents = chunk.event.split(CHECKPOINT_NAMESPACE_SEPARATOR);
335
- // eslint-disable-next-line prefer-destructuring
336
- mode = eventComponents[0];
337
- namespace = eventComponents.slice(1);
338
- }
339
- else {
340
- mode = chunk.event;
341
- namespace = [];
342
- }
343
- const callerNamespace = options?.configurable?.checkpoint_ns;
344
- if (typeof callerNamespace === "string") {
345
- namespace = callerNamespace
346
- .split(CHECKPOINT_NAMESPACE_SEPARATOR)
347
- .concat(namespace);
348
- }
349
- if (streamProtocolInstance !== undefined &&
350
- streamProtocolInstance.modes?.has(chunk.event)) {
351
- streamProtocolInstance.push([namespace, mode, chunk.data]);
352
- }
353
- if (chunk.event.startsWith("updates")) {
354
- if (typeof chunk.data === "object" &&
355
- chunk.data?.[INTERRUPT] !== undefined) {
356
- throw new GraphInterrupt(chunk.data[INTERRUPT]);
357
- }
358
- if (!reqUpdates) {
359
- continue;
360
- }
361
- }
362
- else if (chunk.event?.startsWith("error")) {
363
- throw new RemoteException(typeof chunk.data === "string"
364
- ? chunk.data
365
- : JSON.stringify(chunk.data));
366
- }
367
- if (!updatedStreamModes.includes(chunk.event.split(CHECKPOINT_NAMESPACE_SEPARATOR)[0])) {
368
- continue;
369
- }
370
- if (options?.subgraphs) {
371
- if (reqSingle) {
372
- yield [namespace, chunk.data];
373
- }
374
- else {
375
- yield [namespace, mode, chunk.data];
376
- }
377
- }
378
- else if (reqSingle) {
379
- yield chunk.data;
380
- }
381
- else {
382
- yield [mode, chunk.data];
383
- }
384
- }
385
- }
386
- async updateState(inputConfig, values, asNode) {
387
- const mergedConfig = mergeConfigs(this.config, inputConfig);
388
- const response = await this.client.threads.updateState(mergedConfig.configurable?.thread_id, { values, asNode, checkpoint: this._getCheckpoint(mergedConfig) });
389
- // TODO: Fix SDK typing
390
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
391
- return this._getConfig(response.checkpoint);
392
- }
393
- async *getStateHistory(config, options) {
394
- const mergedConfig = mergeConfigs(this.config, config);
395
- const states = await this.client.threads.getHistory(mergedConfig.configurable?.thread_id, {
396
- limit: options?.limit ?? 10,
397
- // TODO: Fix type
398
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
399
- before: this._getCheckpoint(options?.before),
400
- metadata: options?.filter,
401
- checkpoint: this._getCheckpoint(mergedConfig),
402
- });
403
- for (const state of states) {
404
- yield this._createStateSnapshot(state);
405
- }
406
- }
407
- _getDrawableNodes(nodes) {
408
- const nodesMap = {};
409
- for (const node of nodes) {
410
- const nodeId = node.id;
411
- nodesMap[nodeId] = {
412
- id: nodeId.toString(),
413
- name: typeof node.data === "string" ? node.data : node.data?.name ?? "",
414
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
415
- data: node.data ?? {},
416
- metadata: typeof node.data !== "string" ? node.data?.metadata ?? {} : {},
417
- };
418
- }
419
- return nodesMap;
420
- }
421
- async getState(config, options) {
422
- const mergedConfig = mergeConfigs(this.config, config);
423
- const state = await this.client.threads.getState(mergedConfig.configurable?.thread_id, this._getCheckpoint(mergedConfig), options);
424
- return this._createStateSnapshot(state);
425
- }
426
- /** @deprecated Use getGraphAsync instead. The async method will become the default in the next minor release. */
427
- getGraph(_) {
428
- throw new Error(`The synchronous "getGraph" is not supported for this graph. Call "getGraphAsync" instead.`);
429
- }
430
- /**
431
- * Returns a drawable representation of the computation graph.
432
- */
433
- async getGraphAsync(config) {
434
- const graph = await this.client.assistants.getGraph(this.graphId, {
435
- xray: config?.xray,
436
- });
437
- return new DrawableGraph({
438
- nodes: this._getDrawableNodes(graph.nodes),
439
- edges: graph.edges,
440
- });
441
- }
442
- /** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */
443
- getSubgraphs() {
444
- throw new Error(`The synchronous "getSubgraphs" method is not supported for this graph. Call "getSubgraphsAsync" instead.`);
445
- }
446
- async *getSubgraphsAsync(namespace, recurse = false) {
447
- const subgraphs = await this.client.assistants.getSubgraphs(this.graphId, {
448
- namespace,
449
- recurse,
450
- });
451
- for (const [ns, graphSchema] of Object.entries(subgraphs)) {
452
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
453
- const remoteSubgraph = new this.constructor({
454
- ...this,
455
- graphId: graphSchema.graph_id,
456
- });
457
- yield [ns, remoteSubgraph];
458
- }
459
- }
460
- }
49
+ * The `RemoteGraph` class is a client implementation for calling remote
50
+ * APIs that implement the LangGraph Server API specification.
51
+ *
52
+ * For example, the `RemoteGraph` class can be used to call APIs from deployments
53
+ * on LangGraph Cloud.
54
+ *
55
+ * `RemoteGraph` behaves the same way as a `StateGraph` and can be used directly as
56
+ * a node in another `StateGraph`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { RemoteGraph } from "@langchain/langgraph/remote";
61
+ *
62
+ * // Can also pass a LangGraph SDK client instance directly
63
+ * const remoteGraph = new RemoteGraph({
64
+ * graphId: process.env.LANGGRAPH_REMOTE_GRAPH_ID!,
65
+ * apiKey: process.env.LANGGRAPH_REMOTE_GRAPH_API_KEY,
66
+ * url: process.env.LANGGRAPH_REMOTE_GRAPH_API_URL,
67
+ * });
68
+ *
69
+ * const input = {
70
+ * messages: [
71
+ * {
72
+ * role: "human",
73
+ * content: "Hello world!",
74
+ * },
75
+ * ],
76
+ * };
77
+ *
78
+ * const config = {
79
+ * configurable: { thread_id: "threadId1" },
80
+ * };
81
+ *
82
+ * await remoteGraph.invoke(input, config);
83
+ * ```
84
+ */
85
+ var RemoteGraph = class extends Runnable {
86
+ static lc_name() {
87
+ return "RemoteGraph";
88
+ }
89
+ lc_namespace = ["langgraph", "pregel"];
90
+ lg_is_pregel = true;
91
+ config;
92
+ graphId;
93
+ client;
94
+ interruptBefore;
95
+ interruptAfter;
96
+ constructor(params) {
97
+ super(params);
98
+ this.graphId = params.graphId;
99
+ this.client = params.client ?? new Client({
100
+ apiUrl: params.url,
101
+ apiKey: params.apiKey,
102
+ defaultHeaders: params.headers
103
+ });
104
+ this.config = params.config;
105
+ this.interruptBefore = params.interruptBefore;
106
+ this.interruptAfter = params.interruptAfter;
107
+ }
108
+ withConfig(config) {
109
+ const mergedConfig = mergeConfigs(this.config, config);
110
+ return new this.constructor({
111
+ ...this,
112
+ config: mergedConfig
113
+ });
114
+ }
115
+ _sanitizeConfig(config) {
116
+ const reservedConfigurableKeys = new Set([
117
+ "callbacks",
118
+ "checkpoint_map",
119
+ "checkpoint_id",
120
+ "checkpoint_ns"
121
+ ]);
122
+ const sanitizeObj = (obj) => {
123
+ try {
124
+ JSON.stringify(obj);
125
+ return obj;
126
+ } catch {
127
+ const seen = /* @__PURE__ */ new WeakSet();
128
+ return JSON.parse(JSON.stringify(obj, (_, value) => {
129
+ if (typeof value === "object" && value != null) {
130
+ if (seen.has(value)) return "[Circular]";
131
+ seen.add(value);
132
+ }
133
+ if (typeof value === "bigint") return value.toString();
134
+ return value;
135
+ }));
136
+ }
137
+ };
138
+ const sanitizedConfig = sanitizeObj(config);
139
+ const newConfigurable = Object.fromEntries(Object.entries(sanitizedConfig.configurable ?? {}).filter(([k]) => !reservedConfigurableKeys.has(k) && !k.startsWith("__pregel_")));
140
+ return {
141
+ tags: sanitizedConfig.tags ?? [],
142
+ metadata: sanitizedConfig.metadata ?? {},
143
+ configurable: newConfigurable,
144
+ recursion_limit: sanitizedConfig.recursionLimit
145
+ };
146
+ }
147
+ _getConfig(checkpoint) {
148
+ return { configurable: {
149
+ thread_id: checkpoint.thread_id,
150
+ checkpoint_ns: checkpoint.checkpoint_ns,
151
+ checkpoint_id: checkpoint.checkpoint_id,
152
+ checkpoint_map: checkpoint.checkpoint_map ?? {}
153
+ } };
154
+ }
155
+ _getCheckpoint(config) {
156
+ if (config?.configurable === void 0) return void 0;
157
+ const checkpointKeys = [
158
+ "thread_id",
159
+ "checkpoint_ns",
160
+ "checkpoint_id",
161
+ "checkpoint_map"
162
+ ];
163
+ const checkpoint = Object.fromEntries(checkpointKeys.map((key) => [key, config.configurable[key]]).filter(([_, value]) => value !== void 0));
164
+ return Object.keys(checkpoint).length > 0 ? checkpoint : void 0;
165
+ }
166
+ _createStateSnapshot(state) {
167
+ const tasks = state.tasks.map((task) => {
168
+ return {
169
+ id: task.id,
170
+ name: task.name,
171
+ error: task.error ? { message: task.error } : void 0,
172
+ interrupts: task.interrupts.map(({ id,...rest }) => ({
173
+ interrupt_id: id,
174
+ ...rest
175
+ })),
176
+ state: task.state ? this._createStateSnapshot(task.state) : task.checkpoint ? { configurable: task.checkpoint } : void 0,
177
+ result: task.result
178
+ };
179
+ });
180
+ return {
181
+ values: state.values,
182
+ next: state.next ? [...state.next] : [],
183
+ config: { configurable: {
184
+ thread_id: state.checkpoint.thread_id,
185
+ checkpoint_ns: state.checkpoint.checkpoint_ns,
186
+ checkpoint_id: state.checkpoint.checkpoint_id,
187
+ checkpoint_map: state.checkpoint.checkpoint_map ?? {}
188
+ } },
189
+ metadata: state.metadata ? state.metadata : void 0,
190
+ createdAt: state.created_at ?? void 0,
191
+ parentConfig: state.parent_checkpoint ? { configurable: {
192
+ thread_id: state.parent_checkpoint.thread_id,
193
+ checkpoint_ns: state.parent_checkpoint.checkpoint_ns,
194
+ checkpoint_id: state.parent_checkpoint.checkpoint_id,
195
+ checkpoint_map: state.parent_checkpoint.checkpoint_map ?? {}
196
+ } } : void 0,
197
+ tasks
198
+ };
199
+ }
200
+ async invoke(input, options) {
201
+ let lastValue;
202
+ const stream = await this.stream(input, {
203
+ ...options,
204
+ streamMode: "values"
205
+ });
206
+ for await (const chunk of stream) lastValue = chunk;
207
+ return lastValue;
208
+ }
209
+ streamEvents(_input, _options) {
210
+ throw new Error("Not implemented.");
211
+ }
212
+ async *_streamIterator(input, options) {
213
+ const mergedConfig = mergeConfigs(this.config, options);
214
+ const sanitizedConfig = this._sanitizeConfig(mergedConfig);
215
+ const streamProtocolInstance = options?.configurable?.[CONFIG_KEY_STREAM];
216
+ const streamSubgraphs = options?.subgraphs ?? streamProtocolInstance !== void 0;
217
+ const interruptBefore = options?.interruptBefore ?? this.interruptBefore;
218
+ const interruptAfter = options?.interruptAfter ?? this.interruptAfter;
219
+ const { updatedStreamModes, reqSingle, reqUpdates } = getStreamModes(options?.streamMode);
220
+ const extendedStreamModes = [...new Set([...updatedStreamModes, ...streamProtocolInstance?.modes ?? /* @__PURE__ */ new Set()])].map((mode) => {
221
+ if (mode === "messages") return "messages-tuple";
222
+ return mode;
223
+ });
224
+ let command;
225
+ let serializedInput;
226
+ if (isCommand(input)) {
227
+ command = input.toJSON();
228
+ serializedInput = void 0;
229
+ } else serializedInput = _serializeInputs(input);
230
+ for await (const chunk of this.client.runs.stream(sanitizedConfig.configurable.thread_id, this.graphId, {
231
+ command,
232
+ input: serializedInput,
233
+ config: sanitizedConfig,
234
+ streamMode: extendedStreamModes,
235
+ interruptBefore,
236
+ interruptAfter,
237
+ streamSubgraphs,
238
+ ifNotExists: "create",
239
+ signal: mergedConfig.signal
240
+ })) {
241
+ let mode;
242
+ let namespace;
243
+ if (chunk.event.includes(CHECKPOINT_NAMESPACE_SEPARATOR)) {
244
+ const eventComponents = chunk.event.split(CHECKPOINT_NAMESPACE_SEPARATOR);
245
+ mode = eventComponents[0];
246
+ namespace = eventComponents.slice(1);
247
+ } else {
248
+ mode = chunk.event;
249
+ namespace = [];
250
+ }
251
+ const callerNamespace = options?.configurable?.checkpoint_ns;
252
+ if (typeof callerNamespace === "string") namespace = callerNamespace.split(CHECKPOINT_NAMESPACE_SEPARATOR).concat(namespace);
253
+ if (streamProtocolInstance !== void 0 && streamProtocolInstance.modes?.has(chunk.event)) streamProtocolInstance.push([
254
+ namespace,
255
+ mode,
256
+ chunk.data
257
+ ]);
258
+ if (chunk.event.startsWith("updates")) {
259
+ if (typeof chunk.data === "object" && chunk.data?.[INTERRUPT] !== void 0) throw new GraphInterrupt(chunk.data[INTERRUPT]);
260
+ if (!reqUpdates) continue;
261
+ } else if (chunk.event?.startsWith("error")) throw new RemoteException(typeof chunk.data === "string" ? chunk.data : JSON.stringify(chunk.data));
262
+ if (!updatedStreamModes.includes(chunk.event.split(CHECKPOINT_NAMESPACE_SEPARATOR)[0])) continue;
263
+ if (options?.subgraphs) if (reqSingle) yield [namespace, chunk.data];
264
+ else yield [
265
+ namespace,
266
+ mode,
267
+ chunk.data
268
+ ];
269
+ else if (reqSingle) yield chunk.data;
270
+ else yield [mode, chunk.data];
271
+ }
272
+ }
273
+ async updateState(inputConfig, values, asNode) {
274
+ const mergedConfig = mergeConfigs(this.config, inputConfig);
275
+ const response = await this.client.threads.updateState(mergedConfig.configurable?.thread_id, {
276
+ values,
277
+ asNode,
278
+ checkpoint: this._getCheckpoint(mergedConfig)
279
+ });
280
+ return this._getConfig(response.checkpoint);
281
+ }
282
+ async *getStateHistory(config, options) {
283
+ const mergedConfig = mergeConfigs(this.config, config);
284
+ const states = await this.client.threads.getHistory(mergedConfig.configurable?.thread_id, {
285
+ limit: options?.limit ?? 10,
286
+ before: this._getCheckpoint(options?.before),
287
+ metadata: options?.filter,
288
+ checkpoint: this._getCheckpoint(mergedConfig)
289
+ });
290
+ for (const state of states) yield this._createStateSnapshot(state);
291
+ }
292
+ _getDrawableNodes(nodes) {
293
+ const nodesMap = {};
294
+ for (const node of nodes) {
295
+ const nodeId = node.id;
296
+ nodesMap[nodeId] = {
297
+ id: nodeId.toString(),
298
+ name: typeof node.data === "string" ? node.data : node.data?.name ?? "",
299
+ data: node.data ?? {},
300
+ metadata: typeof node.data !== "string" ? node.data?.metadata ?? {} : {}
301
+ };
302
+ }
303
+ return nodesMap;
304
+ }
305
+ async getState(config, options) {
306
+ const mergedConfig = mergeConfigs(this.config, config);
307
+ const state = await this.client.threads.getState(mergedConfig.configurable?.thread_id, this._getCheckpoint(mergedConfig), options);
308
+ return this._createStateSnapshot(state);
309
+ }
310
+ /** @deprecated Use getGraphAsync instead. The async method will become the default in the next minor release. */
311
+ getGraph(_) {
312
+ throw new Error(`The synchronous "getGraph" is not supported for this graph. Call "getGraphAsync" instead.`);
313
+ }
314
+ /**
315
+ * Returns a drawable representation of the computation graph.
316
+ */
317
+ async getGraphAsync(config) {
318
+ const graph = await this.client.assistants.getGraph(this.graphId, { xray: config?.xray });
319
+ return new Graph({
320
+ nodes: this._getDrawableNodes(graph.nodes),
321
+ edges: graph.edges
322
+ });
323
+ }
324
+ /** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */
325
+ getSubgraphs() {
326
+ throw new Error(`The synchronous "getSubgraphs" method is not supported for this graph. Call "getSubgraphsAsync" instead.`);
327
+ }
328
+ async *getSubgraphsAsync(namespace, recurse = false) {
329
+ const subgraphs = await this.client.assistants.getSubgraphs(this.graphId, {
330
+ namespace,
331
+ recurse
332
+ });
333
+ for (const [ns, graphSchema] of Object.entries(subgraphs)) {
334
+ const remoteSubgraph = new this.constructor({
335
+ ...this,
336
+ graphId: graphSchema.graph_id
337
+ });
338
+ yield [ns, remoteSubgraph];
339
+ }
340
+ }
341
+ };
342
+
343
+ //#endregion
344
+ export { RemoteGraph };
461
345
  //# sourceMappingURL=remote.js.map