@langchain/langgraph 0.4.7 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (494) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +1 -2
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/channels/any_value.d.cts +26 -0
  5. package/dist/channels/any_value.d.cts.map +1 -0
  6. package/dist/channels/any_value.d.ts +16 -9
  7. package/dist/channels/any_value.d.ts.map +1 -0
  8. package/dist/channels/base.cjs +97 -133
  9. package/dist/channels/base.cjs.map +1 -0
  10. package/dist/channels/base.d.cts +73 -0
  11. package/dist/channels/base.d.cts.map +1 -0
  12. package/dist/channels/base.d.ts +73 -74
  13. package/dist/channels/base.d.ts.map +1 -0
  14. package/dist/channels/base.js +94 -127
  15. package/dist/channels/base.js.map +1 -1
  16. package/dist/channels/binop.cjs +47 -77
  17. package/dist/channels/binop.cjs.map +1 -0
  18. package/dist/channels/binop.d.cts +22 -0
  19. package/dist/channels/binop.d.cts.map +1 -0
  20. package/dist/channels/binop.d.ts +17 -12
  21. package/dist/channels/binop.d.ts.map +1 -0
  22. package/dist/channels/binop.js +45 -71
  23. package/dist/channels/binop.js.map +1 -1
  24. package/dist/channels/dynamic_barrier_value.d.cts +43 -0
  25. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  26. package/dist/channels/dynamic_barrier_value.d.ts +20 -34
  27. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  28. package/dist/channels/ephemeral_value.cjs +46 -70
  29. package/dist/channels/ephemeral_value.cjs.map +1 -0
  30. package/dist/channels/ephemeral_value.d.cts +23 -0
  31. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  32. package/dist/channels/ephemeral_value.d.ts +18 -11
  33. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  34. package/dist/channels/ephemeral_value.js +45 -65
  35. package/dist/channels/ephemeral_value.js.map +1 -1
  36. package/dist/channels/index.cjs +2 -10
  37. package/dist/channels/index.js +4 -3
  38. package/dist/channels/last_value.cjs +91 -140
  39. package/dist/channels/last_value.cjs.map +1 -0
  40. package/dist/channels/last_value.d.cts +30 -0
  41. package/dist/channels/last_value.d.cts.map +1 -0
  42. package/dist/channels/last_value.d.ts +15 -23
  43. package/dist/channels/last_value.d.ts.map +1 -0
  44. package/dist/channels/last_value.js +88 -133
  45. package/dist/channels/last_value.js.map +1 -1
  46. package/dist/channels/named_barrier_value.cjs +114 -170
  47. package/dist/channels/named_barrier_value.cjs.map +1 -0
  48. package/dist/channels/named_barrier_value.d.cts +33 -0
  49. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  50. package/dist/channels/named_barrier_value.d.ts +19 -29
  51. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  52. package/dist/channels/named_barrier_value.js +112 -163
  53. package/dist/channels/named_barrier_value.js.map +1 -1
  54. package/dist/channels/topic.cjs +63 -96
  55. package/dist/channels/topic.cjs.map +1 -0
  56. package/dist/channels/topic.d.cts +26 -0
  57. package/dist/channels/topic.d.cts.map +1 -0
  58. package/dist/channels/topic.d.ts +21 -18
  59. package/dist/channels/topic.d.ts.map +1 -0
  60. package/dist/channels/topic.js +61 -90
  61. package/dist/channels/topic.js.map +1 -1
  62. package/dist/constants.cjs +373 -452
  63. package/dist/constants.cjs.map +1 -0
  64. package/dist/constants.d.cts +284 -0
  65. package/dist/constants.d.cts.map +1 -0
  66. package/dist/constants.d.ts +112 -148
  67. package/dist/constants.d.ts.map +1 -0
  68. package/dist/constants.js +333 -444
  69. package/dist/constants.js.map +1 -1
  70. package/dist/errors.cjs +150 -179
  71. package/dist/errors.cjs.map +1 -0
  72. package/dist/errors.d.cts +80 -0
  73. package/dist/errors.d.cts.map +1 -0
  74. package/dist/errors.d.ts +55 -46
  75. package/dist/errors.d.ts.map +1 -0
  76. package/dist/errors.js +139 -165
  77. package/dist/errors.js.map +1 -1
  78. package/dist/func/index.cjs +289 -290
  79. package/dist/func/index.cjs.map +1 -0
  80. package/dist/func/index.d.cts +289 -0
  81. package/dist/func/index.d.cts.map +1 -0
  82. package/dist/func/index.d.ts +81 -71
  83. package/dist/func/index.d.ts.map +1 -0
  84. package/dist/func/index.js +285 -284
  85. package/dist/func/index.js.map +1 -1
  86. package/dist/func/types.d.cts +64 -0
  87. package/dist/func/types.d.cts.map +1 -0
  88. package/dist/func/types.d.ts +24 -19
  89. package/dist/func/types.d.ts.map +1 -0
  90. package/dist/graph/annotation.cjs +96 -120
  91. package/dist/graph/annotation.cjs.map +1 -0
  92. package/dist/graph/annotation.d.cts +116 -0
  93. package/dist/graph/annotation.d.cts.map +1 -0
  94. package/dist/graph/annotation.d.ts +33 -34
  95. package/dist/graph/annotation.d.ts.map +1 -0
  96. package/dist/graph/annotation.js +91 -112
  97. package/dist/graph/annotation.js.map +1 -1
  98. package/dist/graph/graph.cjs +419 -723
  99. package/dist/graph/graph.cjs.map +1 -0
  100. package/dist/graph/graph.d.cts +131 -0
  101. package/dist/graph/graph.d.cts.map +1 -0
  102. package/dist/graph/graph.d.ts +122 -91
  103. package/dist/graph/graph.d.ts.map +1 -0
  104. package/dist/graph/graph.js +412 -713
  105. package/dist/graph/graph.js.map +1 -1
  106. package/dist/graph/index.cjs +4 -17
  107. package/dist/graph/index.js +6 -5
  108. package/dist/graph/message.cjs +59 -104
  109. package/dist/graph/message.cjs.map +1 -0
  110. package/dist/graph/message.d.cts +19 -0
  111. package/dist/graph/message.d.cts.map +1 -0
  112. package/dist/graph/message.d.ts +11 -10
  113. package/dist/graph/message.d.ts.map +1 -0
  114. package/dist/graph/message.js +56 -98
  115. package/dist/graph/message.js.map +1 -1
  116. package/dist/graph/messages_annotation.cjs +106 -106
  117. package/dist/graph/messages_annotation.cjs.map +1 -0
  118. package/dist/graph/messages_annotation.d.cts +111 -0
  119. package/dist/graph/messages_annotation.d.cts.map +1 -0
  120. package/dist/graph/messages_annotation.d.ts +18 -9
  121. package/dist/graph/messages_annotation.d.ts.map +1 -0
  122. package/dist/graph/messages_annotation.js +100 -100
  123. package/dist/graph/messages_annotation.js.map +1 -1
  124. package/dist/graph/state.cjs +476 -777
  125. package/dist/graph/state.cjs.map +1 -0
  126. package/dist/graph/state.d.cts +216 -0
  127. package/dist/graph/state.d.cts.map +1 -0
  128. package/dist/graph/state.d.ts +129 -134
  129. package/dist/graph/state.d.ts.map +1 -0
  130. package/dist/graph/state.js +470 -768
  131. package/dist/graph/state.js.map +1 -1
  132. package/dist/graph/zod/index.cjs +10 -21
  133. package/dist/graph/zod/index.d.cts +3 -0
  134. package/dist/graph/zod/index.d.ts +3 -3
  135. package/dist/graph/zod/index.js +4 -4
  136. package/dist/graph/zod/meta.cjs +142 -177
  137. package/dist/graph/zod/meta.cjs.map +1 -0
  138. package/dist/graph/zod/meta.d.cts +116 -0
  139. package/dist/graph/zod/meta.d.cts.map +1 -0
  140. package/dist/graph/zod/meta.d.ts +99 -97
  141. package/dist/graph/zod/meta.d.ts.map +1 -0
  142. package/dist/graph/zod/meta.js +136 -170
  143. package/dist/graph/zod/meta.js.map +1 -1
  144. package/dist/graph/zod/plugin.cjs +36 -39
  145. package/dist/graph/zod/plugin.cjs.map +1 -0
  146. package/dist/graph/zod/plugin.js +34 -35
  147. package/dist/graph/zod/plugin.js.map +1 -1
  148. package/dist/graph/zod/schema.cjs +82 -110
  149. package/dist/graph/zod/schema.cjs.map +1 -0
  150. package/dist/graph/zod/schema.d.cts +38 -0
  151. package/dist/graph/zod/schema.d.cts.map +1 -0
  152. package/dist/graph/zod/schema.d.ts +12 -6
  153. package/dist/graph/zod/schema.d.ts.map +1 -0
  154. package/dist/graph/zod/schema.js +77 -103
  155. package/dist/graph/zod/schema.js.map +1 -1
  156. package/dist/graph/zod/zod-registry.cjs +41 -47
  157. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  158. package/dist/graph/zod/zod-registry.d.cts +51 -0
  159. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  160. package/dist/graph/zod/zod-registry.d.ts +34 -26
  161. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  162. package/dist/graph/zod/zod-registry.js +37 -41
  163. package/dist/graph/zod/zod-registry.js.map +1 -1
  164. package/dist/hash.cjs +205 -267
  165. package/dist/hash.cjs.map +1 -0
  166. package/dist/hash.js +205 -265
  167. package/dist/hash.js.map +1 -1
  168. package/dist/index.cjs +110 -33
  169. package/dist/index.cjs.map +1 -0
  170. package/dist/index.d.cts +25 -0
  171. package/dist/index.d.ts +25 -5
  172. package/dist/index.js +18 -7
  173. package/dist/index.js.map +1 -1
  174. package/dist/interrupt.cjs +79 -85
  175. package/dist/interrupt.cjs.map +1 -0
  176. package/dist/interrupt.d.cts +49 -0
  177. package/dist/interrupt.d.cts.map +1 -0
  178. package/dist/interrupt.d.ts +6 -1
  179. package/dist/interrupt.d.ts.map +1 -0
  180. package/dist/interrupt.js +76 -80
  181. package/dist/interrupt.js.map +1 -1
  182. package/dist/prebuilt/agentName.cjs +139 -172
  183. package/dist/prebuilt/agentName.cjs.map +1 -0
  184. package/dist/prebuilt/agentName.d.cts +42 -0
  185. package/dist/prebuilt/agentName.d.cts.map +1 -0
  186. package/dist/prebuilt/agentName.d.ts +13 -21
  187. package/dist/prebuilt/agentName.d.ts.map +1 -0
  188. package/dist/prebuilt/agentName.js +139 -168
  189. package/dist/prebuilt/agentName.js.map +1 -1
  190. package/dist/prebuilt/agent_executor.cjs +42 -80
  191. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  192. package/dist/prebuilt/agent_executor.d.cts +57 -0
  193. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  194. package/dist/prebuilt/agent_executor.d.ts +46 -37
  195. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  196. package/dist/prebuilt/agent_executor.js +40 -75
  197. package/dist/prebuilt/agent_executor.js.map +1 -1
  198. package/dist/prebuilt/chat_agent_executor.cjs +66 -128
  199. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  200. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  201. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  202. package/dist/prebuilt/chat_agent_executor.d.ts +18 -10
  203. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  204. package/dist/prebuilt/chat_agent_executor.js +63 -123
  205. package/dist/prebuilt/chat_agent_executor.js.map +1 -1
  206. package/dist/prebuilt/index.cjs +15 -18
  207. package/dist/prebuilt/index.d.cts +8 -0
  208. package/dist/prebuilt/index.d.ts +8 -8
  209. package/dist/prebuilt/index.js +8 -7
  210. package/dist/prebuilt/interrupt.d.cts +73 -0
  211. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  212. package/dist/prebuilt/interrupt.d.ts +32 -15
  213. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  214. package/dist/prebuilt/react_agent_executor.cjs +317 -473
  215. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  216. package/dist/prebuilt/react_agent_executor.d.cts +229 -0
  217. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  218. package/dist/prebuilt/react_agent_executor.d.ts +171 -143
  219. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  220. package/dist/prebuilt/react_agent_executor.js +315 -465
  221. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  222. package/dist/prebuilt/tool_executor.cjs +45 -67
  223. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  224. package/dist/prebuilt/tool_executor.d.cts +42 -0
  225. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  226. package/dist/prebuilt/tool_executor.d.ts +30 -24
  227. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  228. package/dist/prebuilt/tool_executor.js +44 -63
  229. package/dist/prebuilt/tool_executor.js.map +1 -1
  230. package/dist/prebuilt/tool_node.cjs +213 -275
  231. package/dist/prebuilt/tool_node.cjs.map +1 -0
  232. package/dist/prebuilt/tool_node.d.cts +151 -0
  233. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  234. package/dist/prebuilt/tool_node.d.ts +30 -17
  235. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  236. package/dist/prebuilt/tool_node.js +209 -268
  237. package/dist/prebuilt/tool_node.js.map +1 -1
  238. package/dist/pregel/algo.cjs +521 -692
  239. package/dist/pregel/algo.cjs.map +1 -0
  240. package/dist/pregel/algo.d.cts +13 -0
  241. package/dist/pregel/algo.d.cts.map +1 -0
  242. package/dist/pregel/algo.d.ts +8 -38
  243. package/dist/pregel/algo.d.ts.map +1 -0
  244. package/dist/pregel/algo.js +516 -683
  245. package/dist/pregel/algo.js.map +1 -1
  246. package/dist/pregel/call.cjs +46 -42
  247. package/dist/pregel/call.cjs.map +1 -0
  248. package/dist/pregel/call.js +43 -37
  249. package/dist/pregel/call.js.map +1 -1
  250. package/dist/pregel/debug.cjs +153 -223
  251. package/dist/pregel/debug.cjs.map +1 -0
  252. package/dist/pregel/debug.js +152 -215
  253. package/dist/pregel/debug.js.map +1 -1
  254. package/dist/pregel/index.cjs +1134 -1604
  255. package/dist/pregel/index.cjs.map +1 -0
  256. package/dist/pregel/index.d.cts +534 -0
  257. package/dist/pregel/index.d.cts.map +1 -0
  258. package/dist/pregel/index.d.ts +458 -422
  259. package/dist/pregel/index.d.ts.map +1 -0
  260. package/dist/pregel/index.js +1125 -1592
  261. package/dist/pregel/index.js.map +1 -1
  262. package/dist/pregel/io.cjs +127 -234
  263. package/dist/pregel/io.cjs.map +1 -0
  264. package/dist/pregel/io.js +122 -225
  265. package/dist/pregel/io.js.map +1 -1
  266. package/dist/pregel/loop.cjs +539 -954
  267. package/dist/pregel/loop.cjs.map +1 -0
  268. package/dist/pregel/loop.js +536 -948
  269. package/dist/pregel/loop.js.map +1 -1
  270. package/dist/pregel/messages.cjs +104 -196
  271. package/dist/pregel/messages.cjs.map +1 -0
  272. package/dist/pregel/messages.js +102 -191
  273. package/dist/pregel/messages.js.map +1 -1
  274. package/dist/pregel/read.cjs +150 -280
  275. package/dist/pregel/read.cjs.map +1 -0
  276. package/dist/pregel/read.d.cts +51 -0
  277. package/dist/pregel/read.d.cts.map +1 -0
  278. package/dist/pregel/read.d.ts +48 -46
  279. package/dist/pregel/read.d.ts.map +1 -0
  280. package/dist/pregel/read.js +147 -274
  281. package/dist/pregel/read.js.map +1 -1
  282. package/dist/pregel/remote.cjs +339 -458
  283. package/dist/pregel/remote.cjs.map +1 -0
  284. package/dist/pregel/remote.d.cts +121 -0
  285. package/dist/pregel/remote.d.cts.map +1 -0
  286. package/dist/pregel/remote.d.ts +79 -69
  287. package/dist/pregel/remote.d.ts.map +1 -0
  288. package/dist/pregel/remote.js +337 -453
  289. package/dist/pregel/remote.js.map +1 -1
  290. package/dist/pregel/retry.cjs +87 -138
  291. package/dist/pregel/retry.cjs.map +1 -0
  292. package/dist/pregel/retry.js +83 -130
  293. package/dist/pregel/retry.js.map +1 -1
  294. package/dist/pregel/runnable_types.d.cts +25 -0
  295. package/dist/pregel/runnable_types.d.cts.map +1 -0
  296. package/dist/pregel/runnable_types.d.ts +22 -16
  297. package/dist/pregel/runnable_types.d.ts.map +1 -0
  298. package/dist/pregel/runner.cjs +222 -315
  299. package/dist/pregel/runner.cjs.map +1 -0
  300. package/dist/pregel/runner.js +219 -308
  301. package/dist/pregel/runner.js.map +1 -1
  302. package/dist/pregel/stream.cjs +89 -130
  303. package/dist/pregel/stream.cjs.map +1 -0
  304. package/dist/pregel/stream.js +87 -125
  305. package/dist/pregel/stream.js.map +1 -1
  306. package/dist/pregel/types.cjs +25 -62
  307. package/dist/pregel/types.cjs.map +1 -0
  308. package/dist/pregel/types.d.cts +437 -0
  309. package/dist/pregel/types.d.cts.map +1 -0
  310. package/dist/pregel/types.d.ts +377 -431
  311. package/dist/pregel/types.d.ts.map +1 -0
  312. package/dist/pregel/types.js +23 -57
  313. package/dist/pregel/types.js.map +1 -1
  314. package/dist/pregel/utils/config.cjs +100 -147
  315. package/dist/pregel/utils/config.cjs.map +1 -0
  316. package/dist/pregel/utils/config.d.cts +36 -0
  317. package/dist/pregel/utils/config.d.cts.map +1 -0
  318. package/dist/pregel/utils/config.d.ts +12 -9
  319. package/dist/pregel/utils/config.d.ts.map +1 -0
  320. package/dist/pregel/utils/config.js +98 -143
  321. package/dist/pregel/utils/config.js.map +1 -1
  322. package/dist/pregel/utils/index.cjs +87 -125
  323. package/dist/pregel/utils/index.cjs.map +1 -0
  324. package/dist/pregel/utils/index.d.cts +51 -0
  325. package/dist/pregel/utils/index.d.cts.map +1 -0
  326. package/dist/pregel/utils/index.d.ts +45 -61
  327. package/dist/pregel/utils/index.d.ts.map +1 -0
  328. package/dist/pregel/utils/index.js +86 -120
  329. package/dist/pregel/utils/index.js.map +1 -1
  330. package/dist/pregel/utils/subgraph.cjs +15 -26
  331. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  332. package/dist/pregel/utils/subgraph.js +12 -21
  333. package/dist/pregel/utils/subgraph.js.map +1 -1
  334. package/dist/pregel/validate.cjs +42 -92
  335. package/dist/pregel/validate.cjs.map +1 -0
  336. package/dist/pregel/validate.js +39 -84
  337. package/dist/pregel/validate.js.map +1 -1
  338. package/dist/pregel/write.cjs +87 -137
  339. package/dist/pregel/write.cjs.map +1 -0
  340. package/dist/pregel/write.d.cts +35 -0
  341. package/dist/pregel/write.d.cts.map +1 -0
  342. package/dist/pregel/write.d.ts +27 -23
  343. package/dist/pregel/write.d.ts.map +1 -0
  344. package/dist/pregel/write.js +83 -131
  345. package/dist/pregel/write.js.map +1 -1
  346. package/dist/remote.cjs +3 -6
  347. package/dist/remote.d.cts +2 -0
  348. package/dist/remote.d.ts +2 -1
  349. package/dist/remote.js +3 -2
  350. package/dist/setup/async_local_storage.cjs +10 -7
  351. package/dist/setup/async_local_storage.cjs.map +1 -0
  352. package/dist/setup/async_local_storage.js +7 -2
  353. package/dist/setup/async_local_storage.js.map +1 -1
  354. package/dist/ui/index.cjs +4 -0
  355. package/dist/ui/index.d.cts +5 -0
  356. package/dist/ui/index.d.ts +5 -0
  357. package/dist/ui/index.js +3 -0
  358. package/dist/ui/stream.cjs +145 -0
  359. package/dist/ui/stream.cjs.map +1 -0
  360. package/dist/ui/stream.d.cts +25 -0
  361. package/dist/ui/stream.d.cts.map +1 -0
  362. package/dist/ui/stream.d.ts +25 -0
  363. package/dist/ui/stream.d.ts.map +1 -0
  364. package/dist/ui/stream.js +143 -0
  365. package/dist/ui/stream.js.map +1 -0
  366. package/dist/ui/types.infer.d.cts +53 -0
  367. package/dist/ui/types.infer.d.cts.map +1 -0
  368. package/dist/ui/types.infer.d.ts +53 -0
  369. package/dist/ui/types.infer.d.ts.map +1 -0
  370. package/dist/ui/types.message.d.cts +95 -0
  371. package/dist/ui/types.message.d.cts.map +1 -0
  372. package/dist/ui/types.message.d.ts +95 -0
  373. package/dist/ui/types.message.d.ts.map +1 -0
  374. package/dist/ui/types.schema.d.cts +228 -0
  375. package/dist/ui/types.schema.d.cts.map +1 -0
  376. package/dist/ui/types.schema.d.ts +228 -0
  377. package/dist/ui/types.schema.d.ts.map +1 -0
  378. package/dist/utils.cjs +77 -147
  379. package/dist/utils.cjs.map +1 -0
  380. package/dist/utils.d.cts +32 -0
  381. package/dist/utils.d.cts.map +1 -0
  382. package/dist/utils.d.ts +29 -25
  383. package/dist/utils.d.ts.map +1 -0
  384. package/dist/utils.js +73 -140
  385. package/dist/utils.js.map +1 -1
  386. package/dist/web.cjs +97 -55
  387. package/dist/web.d.cts +23 -0
  388. package/dist/web.d.ts +23 -14
  389. package/dist/web.js +15 -8
  390. package/package.json +77 -80
  391. package/dist/channels/any_value.cjs +0 -65
  392. package/dist/channels/any_value.js +0 -61
  393. package/dist/channels/any_value.js.map +0 -1
  394. package/dist/channels/dynamic_barrier_value.cjs +0 -212
  395. package/dist/channels/dynamic_barrier_value.js +0 -207
  396. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  397. package/dist/channels/index.d.ts +0 -7
  398. package/dist/channels/index.js.map +0 -1
  399. package/dist/func/types.cjs +0 -15
  400. package/dist/func/types.js +0 -12
  401. package/dist/func/types.js.map +0 -1
  402. package/dist/graph/index.d.ts +0 -4
  403. package/dist/graph/index.js.map +0 -1
  404. package/dist/graph/message.test.cjs +0 -196
  405. package/dist/graph/message.test.d.ts +0 -1
  406. package/dist/graph/message.test.js +0 -194
  407. package/dist/graph/message.test.js.map +0 -1
  408. package/dist/graph/zod/index.js.map +0 -1
  409. package/dist/graph/zod/plugin.d.ts +0 -28
  410. package/dist/hash.d.ts +0 -2
  411. package/dist/prebuilt/index.js.map +0 -1
  412. package/dist/prebuilt/interrupt.cjs +0 -3
  413. package/dist/prebuilt/interrupt.js +0 -2
  414. package/dist/prebuilt/interrupt.js.map +0 -1
  415. package/dist/pregel/call.d.ts +0 -16
  416. package/dist/pregel/debug.d.ts +0 -41
  417. package/dist/pregel/debug.test.cjs +0 -258
  418. package/dist/pregel/debug.test.d.ts +0 -1
  419. package/dist/pregel/debug.test.js +0 -256
  420. package/dist/pregel/debug.test.js.map +0 -1
  421. package/dist/pregel/io.d.ts +0 -30
  422. package/dist/pregel/io.mapCommand.test.cjs +0 -150
  423. package/dist/pregel/io.mapCommand.test.d.ts +0 -1
  424. package/dist/pregel/io.mapCommand.test.js +0 -148
  425. package/dist/pregel/io.mapCommand.test.js.map +0 -1
  426. package/dist/pregel/loop.d.ts +0 -147
  427. package/dist/pregel/messages.d.ts +0 -30
  428. package/dist/pregel/messages.test.cjs +0 -369
  429. package/dist/pregel/messages.test.d.ts +0 -1
  430. package/dist/pregel/messages.test.js +0 -367
  431. package/dist/pregel/messages.test.js.map +0 -1
  432. package/dist/pregel/read.test.cjs +0 -194
  433. package/dist/pregel/read.test.d.ts +0 -1
  434. package/dist/pregel/read.test.js +0 -192
  435. package/dist/pregel/read.test.js.map +0 -1
  436. package/dist/pregel/retry.d.ts +0 -17
  437. package/dist/pregel/runnable_types.cjs +0 -3
  438. package/dist/pregel/runnable_types.js +0 -2
  439. package/dist/pregel/runnable_types.js.map +0 -1
  440. package/dist/pregel/runner.d.ts +0 -79
  441. package/dist/pregel/runner.test.cjs +0 -66
  442. package/dist/pregel/runner.test.d.ts +0 -1
  443. package/dist/pregel/runner.test.js +0 -64
  444. package/dist/pregel/runner.test.js.map +0 -1
  445. package/dist/pregel/stream.d.ts +0 -40
  446. package/dist/pregel/utils/config.test.cjs +0 -214
  447. package/dist/pregel/utils/config.test.d.ts +0 -1
  448. package/dist/pregel/utils/config.test.js +0 -212
  449. package/dist/pregel/utils/config.test.js.map +0 -1
  450. package/dist/pregel/utils/subgraph.d.ts +0 -4
  451. package/dist/pregel/utils/subgraph.test.cjs +0 -83
  452. package/dist/pregel/utils/subgraph.test.d.ts +0 -1
  453. package/dist/pregel/utils/subgraph.test.js +0 -81
  454. package/dist/pregel/utils/subgraph.test.js.map +0 -1
  455. package/dist/pregel/validate.d.ts +0 -16
  456. package/dist/pregel/validate.test.cjs +0 -220
  457. package/dist/pregel/validate.test.d.ts +0 -1
  458. package/dist/pregel/validate.test.js +0 -218
  459. package/dist/pregel/validate.test.js.map +0 -1
  460. package/dist/pregel/write.test.cjs +0 -181
  461. package/dist/pregel/write.test.d.ts +0 -1
  462. package/dist/pregel/write.test.js +0 -179
  463. package/dist/pregel/write.test.js.map +0 -1
  464. package/dist/remote.js.map +0 -1
  465. package/dist/setup/async_local_storage.d.ts +0 -1
  466. package/dist/web.js.map +0 -1
  467. package/index.cjs +0 -1
  468. package/index.d.cts +0 -1
  469. package/index.d.ts +0 -1
  470. package/index.js +0 -1
  471. package/prebuilt.cjs +0 -1
  472. package/prebuilt.d.cts +0 -1
  473. package/prebuilt.d.ts +0 -1
  474. package/prebuilt.js +0 -1
  475. package/pregel.cjs +0 -1
  476. package/pregel.d.cts +0 -1
  477. package/pregel.d.ts +0 -1
  478. package/pregel.js +0 -1
  479. package/remote.cjs +0 -1
  480. package/remote.d.cts +0 -1
  481. package/remote.d.ts +0 -1
  482. package/remote.js +0 -1
  483. package/web.cjs +0 -1
  484. package/web.d.cts +0 -1
  485. package/web.d.ts +0 -1
  486. package/web.js +0 -1
  487. package/zod/schema.cjs +0 -1
  488. package/zod/schema.d.cts +0 -1
  489. package/zod/schema.d.ts +0 -1
  490. package/zod/schema.js +0 -1
  491. package/zod.cjs +0 -1
  492. package/zod.d.cts +0 -1
  493. package/zod.d.ts +0 -1
  494. package/zod.js +0 -1
@@ -1,294 +1,295 @@
1
- import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
2
- import { Pregel } from "../pregel/index.js";
3
- import { PregelNode } from "../pregel/read.js";
4
- import { CONFIG_KEY_PREVIOUS_STATE, END, PREVIOUS, START, TAG_HIDDEN, } from "../constants.js";
5
- import { EphemeralValue } from "../channels/ephemeral_value.js";
6
- import { call, getRunnableForEntrypoint } from "../pregel/call.js";
7
1
  import { LastValue } from "../channels/last_value.js";
8
- import { RunnableCallable, isAsyncGeneratorFunction, isGeneratorFunction, } from "../utils.js";
2
+ import { CONFIG_KEY_PREVIOUS_STATE, END, PREVIOUS, START, TAG_HIDDEN } from "../constants.js";
3
+ import { RunnableCallable, isAsyncGeneratorFunction, isGeneratorFunction } from "../utils.js";
9
4
  import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
5
+ import { PregelNode } from "../pregel/read.js";
6
+ import { call, getRunnableForEntrypoint } from "../pregel/call.js";
7
+ import { Pregel } from "../pregel/index.js";
8
+ import { EphemeralValue } from "../channels/ephemeral_value.js";
9
+ import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
10
+
11
+ //#region src/func/index.ts
10
12
  /**
11
- * Define a LangGraph task using the `task` function.
12
- *
13
- * Tasks can only be called from within an {@link entrypoint} or from within a StateGraph.
14
- * A task can be called like a regular function with the following differences:
15
- *
16
- * - When a checkpointer is enabled, the function inputs and outputs must be serializable.
17
- * - The wrapped function can only be called from within an entrypoint or StateGraph.
18
- * - Calling the function produces a promise. This makes it easy to parallelize tasks.
19
- *
20
- * @typeParam ArgsT - The type of arguments the task function accepts
21
- * @typeParam OutputT - The type of value the task function returns
22
- * @param optionsOrName - Either an {@link TaskOptions} object, or a string for the name of the task
23
- * @param func - The function that executes this task
24
- * @returns A proxy function that accepts the same arguments as the original and always returns the result as a Promise
25
- *
26
- * @example basic example
27
- * ```typescript
28
- * const addOne = task("add", async (a: number) => a + 1);
29
- *
30
- * const workflow = entrypoint("example", async (numbers: number[]) => {
31
- * const promises = numbers.map(n => addOne(n));
32
- * const results = await Promise.all(promises);
33
- * return results;
34
- * });
35
- *
36
- * // Call the entrypoint
37
- * await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]
38
- * ```
39
- *
40
- * @example using a retry policy
41
- * ```typescript
42
- * const addOne = task({
43
- * name: "add",
44
- * retry: { maxAttempts: 3 }
45
- * },
46
- * async (a: number) => a + 1
47
- * );
48
- *
49
- * const workflow = entrypoint("example", async (numbers: number[]) => {
50
- * const promises = numbers.map(n => addOne(n));
51
- * const results = await Promise.all(promises);
52
- * return results;
53
- * });
54
- * ```
55
- */
56
- export function task(optionsOrName, func) {
57
- const options = typeof optionsOrName === "string"
58
- ? { name: optionsOrName, retry: undefined, cachePolicy: undefined }
59
- : optionsOrName;
60
- const { name, retry } = options;
61
- if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {
62
- throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");
63
- }
64
- const cachePolicy = options.cachePolicy ??
65
- // `cache` was mistakingly used as an alias for `cachePolicy` in v0.3.x,
66
- // TODO: remove in 1.x
67
- ("cache" in options ? options.cache : undefined);
68
- let cache;
69
- if (typeof cachePolicy === "boolean") {
70
- cache = cachePolicy ? {} : undefined;
71
- }
72
- else {
73
- cache = cachePolicy;
74
- }
75
- return (...args) => {
76
- return call({ func, name, retry, cache }, ...args);
77
- };
13
+ * Define a LangGraph task using the `task` function.
14
+ *
15
+ * Tasks can only be called from within an {@link entrypoint} or from within a StateGraph.
16
+ * A task can be called like a regular function with the following differences:
17
+ *
18
+ * - When a checkpointer is enabled, the function inputs and outputs must be serializable.
19
+ * - The wrapped function can only be called from within an entrypoint or StateGraph.
20
+ * - Calling the function produces a promise. This makes it easy to parallelize tasks.
21
+ *
22
+ * @typeParam ArgsT - The type of arguments the task function accepts
23
+ * @typeParam OutputT - The type of value the task function returns
24
+ * @param optionsOrName - Either an {@link TaskOptions} object, or a string for the name of the task
25
+ * @param func - The function that executes this task
26
+ * @returns A proxy function that accepts the same arguments as the original and always returns the result as a Promise
27
+ *
28
+ * @example basic example
29
+ * ```typescript
30
+ * const addOne = task("add", async (a: number) => a + 1);
31
+ *
32
+ * const workflow = entrypoint("example", async (numbers: number[]) => {
33
+ * const promises = numbers.map(n => addOne(n));
34
+ * const results = await Promise.all(promises);
35
+ * return results;
36
+ * });
37
+ *
38
+ * // Call the entrypoint
39
+ * await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]
40
+ * ```
41
+ *
42
+ * @example using a retry policy
43
+ * ```typescript
44
+ * const addOne = task({
45
+ * name: "add",
46
+ * retry: { maxAttempts: 3 }
47
+ * },
48
+ * async (a: number) => a + 1
49
+ * );
50
+ *
51
+ * const workflow = entrypoint("example", async (numbers: number[]) => {
52
+ * const promises = numbers.map(n => addOne(n));
53
+ * const results = await Promise.all(promises);
54
+ * return results;
55
+ * });
56
+ * ```
57
+ */
58
+ function task(optionsOrName, func) {
59
+ const options = typeof optionsOrName === "string" ? {
60
+ name: optionsOrName,
61
+ retry: void 0,
62
+ cachePolicy: void 0
63
+ } : optionsOrName;
64
+ const { name, retry } = options;
65
+ if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");
66
+ const cachePolicy = options.cachePolicy ?? ("cache" in options ? options.cache : void 0);
67
+ let cache;
68
+ if (typeof cachePolicy === "boolean") cache = cachePolicy ? {} : void 0;
69
+ else cache = cachePolicy;
70
+ return (...args) => {
71
+ return call({
72
+ func,
73
+ name,
74
+ retry,
75
+ cache
76
+ }, ...args);
77
+ };
78
78
  }
79
79
  /**
80
- * Define a LangGraph workflow using the `entrypoint` function.
81
- *
82
- * ### Function signature
83
- *
84
- * The wrapped function must accept at most **two parameters**. The first parameter
85
- * is the input to the function. The second (optional) parameter is a
86
- * {@link LangGraphRunnableConfig} object. If you wish to pass multiple parameters to
87
- * the function, you can pass them as an object.
88
- *
89
- * ### Helper functions
90
- *
91
- * #### Streaming
92
- * To write data to the "custom" stream, use the {@link getWriter} function, or the
93
- * {@link LangGraphRunnableConfig.writer} property.
94
- *
95
- * #### State management
96
- * The {@link getPreviousState} function can be used to access the previous state
97
- * that was returned from the last invocation of the entrypoint on the same thread id.
98
- *
99
- * If you wish to save state other than the return value, you can use the
100
- * {@link entrypoint.final} function.
101
- *
102
- * @typeParam InputT - The type of input the entrypoint accepts
103
- * @typeParam OutputT - The type of output the entrypoint produces
104
- * @param optionsOrName - Either an {@link EntrypointOptions} object, or a string for the name of the entrypoint
105
- * @param func - The function that executes this entrypoint
106
- * @returns A {@link Pregel} instance that can be run to execute the workflow
107
- *
108
- * @example Using entrypoint and tasks
109
- * ```typescript
110
- * import { task, entrypoint } from "@langchain/langgraph";
111
- * import { MemorySaver } from "@langchain/langgraph-checkpoint";
112
- * import { interrupt, Command } from "@langchain/langgraph";
113
- *
114
- * const composeEssay = task("compose", async (topic: string) => {
115
- * await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation
116
- * return `An essay about ${topic}`;
117
- * });
118
- *
119
- * const reviewWorkflow = entrypoint({
120
- * name: "review",
121
- * checkpointer: new MemorySaver()
122
- * }, async (topic: string) => {
123
- * const essay = await composeEssay(topic);
124
- * const humanReview = await interrupt({
125
- * question: "Please provide a review",
126
- * essay
127
- * });
128
- * return {
129
- * essay,
130
- * review: humanReview
131
- * };
132
- * });
133
- *
134
- * // Example configuration for the workflow
135
- * const config = {
136
- * configurable: {
137
- * thread_id: "some_thread"
138
- * }
139
- * };
140
- *
141
- * // Topic for the essay
142
- * const topic = "cats";
143
- *
144
- * // Stream the workflow to generate the essay and await human review
145
- * for await (const result of reviewWorkflow.stream(topic, config)) {
146
- * console.log(result);
147
- * }
148
- *
149
- * // Example human review provided after the interrupt
150
- * const humanReview = "This essay is great.";
151
- *
152
- * // Resume the workflow with the provided human review
153
- * for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {
154
- * console.log(result);
155
- * }
156
- * ```
157
- *
158
- * @example Accessing the previous return value
159
- * ```typescript
160
- * import { entrypoint, getPreviousState } from "@langchain/langgraph";
161
- * import { MemorySaver } from "@langchain/langgraph-checkpoint";
162
- *
163
- * const accumulator = entrypoint({
164
- * name: "accumulator",
165
- * checkpointer: new MemorySaver()
166
- * }, async (input: string) => {
167
- * const previous = getPreviousState<number>();
168
- * return previous !== undefined ? `${previous } ${input}` : input;
169
- * });
170
- *
171
- * const config = {
172
- * configurable: {
173
- * thread_id: "some_thread"
174
- * }
175
- * };
176
- * await accumulator.invoke("hello", config); // returns "hello"
177
- * await accumulator.invoke("world", config); // returns "hello world"
178
- * ```
179
- *
180
- * @example Using entrypoint.final to save a value
181
- * ```typescript
182
- * import { entrypoint, getPreviousState } from "@langchain/langgraph";
183
- * import { MemorySaver } from "@langchain/langgraph-checkpoint";
184
- *
185
- * const myWorkflow = entrypoint({
186
- * name: "accumulator",
187
- * checkpointer: new MemorySaver()
188
- * }, async (num: number) => {
189
- * const previous = getPreviousState<number>();
190
- *
191
- * // This will return the previous value to the caller, saving
192
- * // 2 * num to the checkpoint, which will be used in the next invocation
193
- * // for the `previous` parameter.
194
- * return entrypoint.final({
195
- * value: previous ?? 0,
196
- * save: 2 * num
197
- * });
198
- * });
199
- *
200
- * const config = {
201
- * configurable: {
202
- * thread_id: "some_thread"
203
- * }
204
- * };
205
- *
206
- * await myWorkflow.invoke(3, config); // 0 (previous was undefined)
207
- * await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
208
- * ```
209
- */
210
- export const entrypoint = function entrypoint(optionsOrName, func) {
211
- const { name, checkpointer, store, cache } = typeof optionsOrName === "string"
212
- ? { name: optionsOrName, checkpointer: undefined, store: undefined }
213
- : optionsOrName;
214
- if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {
215
- throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");
216
- }
217
- const streamMode = "updates";
218
- const bound = getRunnableForEntrypoint(name, func);
219
- // Helper to check if a value is an EntrypointFinal
220
- function isEntrypointFinal(value) {
221
- return (typeof value === "object" &&
222
- value !== null &&
223
- "__lg_type" in value &&
224
- value.__lg_type === "__pregel_final");
225
- }
226
- // Helper function to pluck the return value from EntrypointFinal or passthrough
227
- const pluckReturnValue = new RunnableCallable({
228
- name: "pluckReturnValue",
229
- func: (value) => {
230
- return isEntrypointFinal(value) ? value.value : value;
231
- },
232
- });
233
- // Helper function to pluck the save value from EntrypointFinal or passthrough
234
- const pluckSaveValue = new RunnableCallable({
235
- name: "pluckSaveValue",
236
- func: (value) => {
237
- return isEntrypointFinal(value) ? value.save : value;
238
- },
239
- });
240
- const entrypointNode = new PregelNode({
241
- bound,
242
- triggers: [START],
243
- channels: [START],
244
- writers: [
245
- new ChannelWrite([
246
- { channel: END, value: PASSTHROUGH, mapper: pluckReturnValue },
247
- { channel: PREVIOUS, value: PASSTHROUGH, mapper: pluckSaveValue },
248
- ], [TAG_HIDDEN]),
249
- ],
250
- });
251
- return new Pregel({
252
- name,
253
- checkpointer,
254
- nodes: {
255
- [name]: entrypointNode,
256
- },
257
- channels: {
258
- [START]: new EphemeralValue(),
259
- [END]: new LastValue(),
260
- [PREVIOUS]: new LastValue(),
261
- },
262
- inputChannels: START,
263
- outputChannels: END,
264
- streamChannels: END,
265
- streamMode,
266
- store,
267
- cache,
268
- });
80
+ * Define a LangGraph workflow using the `entrypoint` function.
81
+ *
82
+ * ### Function signature
83
+ *
84
+ * The wrapped function must accept at most **two parameters**. The first parameter
85
+ * is the input to the function. The second (optional) parameter is a
86
+ * {@link LangGraphRunnableConfig} object. If you wish to pass multiple parameters to
87
+ * the function, you can pass them as an object.
88
+ *
89
+ * ### Helper functions
90
+ *
91
+ * #### Streaming
92
+ * To write data to the "custom" stream, use the {@link getWriter} function, or the
93
+ * {@link LangGraphRunnableConfig.writer} property.
94
+ *
95
+ * #### State management
96
+ * The {@link getPreviousState} function can be used to access the previous state
97
+ * that was returned from the last invocation of the entrypoint on the same thread id.
98
+ *
99
+ * If you wish to save state other than the return value, you can use the
100
+ * {@link entrypoint.final} function.
101
+ *
102
+ * @typeParam InputT - The type of input the entrypoint accepts
103
+ * @typeParam OutputT - The type of output the entrypoint produces
104
+ * @param optionsOrName - Either an {@link EntrypointOptions} object, or a string for the name of the entrypoint
105
+ * @param func - The function that executes this entrypoint
106
+ * @returns A {@link Pregel} instance that can be run to execute the workflow
107
+ *
108
+ * @example Using entrypoint and tasks
109
+ * ```typescript
110
+ * import { task, entrypoint } from "@langchain/langgraph";
111
+ * import { MemorySaver } from "@langchain/langgraph-checkpoint";
112
+ * import { interrupt, Command } from "@langchain/langgraph";
113
+ *
114
+ * const composeEssay = task("compose", async (topic: string) => {
115
+ * await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation
116
+ * return `An essay about ${topic}`;
117
+ * });
118
+ *
119
+ * const reviewWorkflow = entrypoint({
120
+ * name: "review",
121
+ * checkpointer: new MemorySaver()
122
+ * }, async (topic: string) => {
123
+ * const essay = await composeEssay(topic);
124
+ * const humanReview = await interrupt({
125
+ * question: "Please provide a review",
126
+ * essay
127
+ * });
128
+ * return {
129
+ * essay,
130
+ * review: humanReview
131
+ * };
132
+ * });
133
+ *
134
+ * // Example configuration for the workflow
135
+ * const config = {
136
+ * configurable: {
137
+ * thread_id: "some_thread"
138
+ * }
139
+ * };
140
+ *
141
+ * // Topic for the essay
142
+ * const topic = "cats";
143
+ *
144
+ * // Stream the workflow to generate the essay and await human review
145
+ * for await (const result of reviewWorkflow.stream(topic, config)) {
146
+ * console.log(result);
147
+ * }
148
+ *
149
+ * // Example human review provided after the interrupt
150
+ * const humanReview = "This essay is great.";
151
+ *
152
+ * // Resume the workflow with the provided human review
153
+ * for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {
154
+ * console.log(result);
155
+ * }
156
+ * ```
157
+ *
158
+ * @example Accessing the previous return value
159
+ * ```typescript
160
+ * import { entrypoint, getPreviousState } from "@langchain/langgraph";
161
+ * import { MemorySaver } from "@langchain/langgraph-checkpoint";
162
+ *
163
+ * const accumulator = entrypoint({
164
+ * name: "accumulator",
165
+ * checkpointer: new MemorySaver()
166
+ * }, async (input: string) => {
167
+ * const previous = getPreviousState<number>();
168
+ * return previous !== undefined ? `${previous } ${input}` : input;
169
+ * });
170
+ *
171
+ * const config = {
172
+ * configurable: {
173
+ * thread_id: "some_thread"
174
+ * }
175
+ * };
176
+ * await accumulator.invoke("hello", config); // returns "hello"
177
+ * await accumulator.invoke("world", config); // returns "hello world"
178
+ * ```
179
+ *
180
+ * @example Using entrypoint.final to save a value
181
+ * ```typescript
182
+ * import { entrypoint, getPreviousState } from "@langchain/langgraph";
183
+ * import { MemorySaver } from "@langchain/langgraph-checkpoint";
184
+ *
185
+ * const myWorkflow = entrypoint({
186
+ * name: "accumulator",
187
+ * checkpointer: new MemorySaver()
188
+ * }, async (num: number) => {
189
+ * const previous = getPreviousState<number>();
190
+ *
191
+ * // This will return the previous value to the caller, saving
192
+ * // 2 * num to the checkpoint, which will be used in the next invocation
193
+ * // for the `previous` parameter.
194
+ * return entrypoint.final({
195
+ * value: previous ?? 0,
196
+ * save: 2 * num
197
+ * });
198
+ * });
199
+ *
200
+ * const config = {
201
+ * configurable: {
202
+ * thread_id: "some_thread"
203
+ * }
204
+ * };
205
+ *
206
+ * await myWorkflow.invoke(3, config); // 0 (previous was undefined)
207
+ * await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
208
+ * ```
209
+ */
210
+ const entrypoint = function entrypoint$1(optionsOrName, func) {
211
+ const { name, checkpointer, store, cache } = typeof optionsOrName === "string" ? {
212
+ name: optionsOrName,
213
+ checkpointer: void 0,
214
+ store: void 0
215
+ } : optionsOrName;
216
+ if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");
217
+ const streamMode = "updates";
218
+ const bound = getRunnableForEntrypoint(name, func);
219
+ function isEntrypointFinal(value) {
220
+ return typeof value === "object" && value !== null && "__lg_type" in value && value.__lg_type === "__pregel_final";
221
+ }
222
+ const pluckReturnValue = new RunnableCallable({
223
+ name: "pluckReturnValue",
224
+ func: (value) => {
225
+ return isEntrypointFinal(value) ? value.value : value;
226
+ }
227
+ });
228
+ const pluckSaveValue = new RunnableCallable({
229
+ name: "pluckSaveValue",
230
+ func: (value) => {
231
+ return isEntrypointFinal(value) ? value.save : value;
232
+ }
233
+ });
234
+ const entrypointNode = new PregelNode({
235
+ bound,
236
+ triggers: [START],
237
+ channels: [START],
238
+ writers: [new ChannelWrite([{
239
+ channel: END,
240
+ value: PASSTHROUGH,
241
+ mapper: pluckReturnValue
242
+ }, {
243
+ channel: PREVIOUS,
244
+ value: PASSTHROUGH,
245
+ mapper: pluckSaveValue
246
+ }], [TAG_HIDDEN])]
247
+ });
248
+ return new Pregel({
249
+ name,
250
+ checkpointer,
251
+ nodes: { [name]: entrypointNode },
252
+ channels: {
253
+ [START]: new EphemeralValue(),
254
+ [END]: new LastValue(),
255
+ [PREVIOUS]: new LastValue()
256
+ },
257
+ inputChannels: START,
258
+ outputChannels: END,
259
+ streamChannels: END,
260
+ streamMode,
261
+ store,
262
+ cache
263
+ });
269
264
  };
270
- // documented by the EntrypointFunction interface
271
- entrypoint.final = function final({ value, save, }) {
272
- return { value, save, __lg_type: "__pregel_final" };
265
+ entrypoint.final = function final({ value, save }) {
266
+ return {
267
+ value,
268
+ save,
269
+ __lg_type: "__pregel_final"
270
+ };
273
271
  };
274
272
  /**
275
- * A helper utility function for use with the functional API that returns the previous
276
- * state from the checkpoint from the last invocation of the current thread.
277
- *
278
- * This function allows workflows to access state that was saved in previous runs
279
- * using {@link entrypoint.final}.
280
- *
281
- * @typeParam StateT - The type of the state that was previously saved
282
- * @returns The previous saved state from the last invocation of the current thread
283
- *
284
- * @example
285
- * ```typescript
286
- * const previousState = getPreviousState<{ counter: number }>();
287
- * const newCount = (previousState?.counter ?? 0) + 1;
288
- * ```
289
- */
290
- export function getPreviousState() {
291
- const config = AsyncLocalStorageProviderSingleton.getRunnableConfig();
292
- return config.configurable?.[CONFIG_KEY_PREVIOUS_STATE];
273
+ * A helper utility function for use with the functional API that returns the previous
274
+ * state from the checkpoint from the last invocation of the current thread.
275
+ *
276
+ * This function allows workflows to access state that was saved in previous runs
277
+ * using {@link entrypoint.final}.
278
+ *
279
+ * @typeParam StateT - The type of the state that was previously saved
280
+ * @returns The previous saved state from the last invocation of the current thread
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const previousState = getPreviousState<{ counter: number }>();
285
+ * const newCount = (previousState?.counter ?? 0) + 1;
286
+ * ```
287
+ */
288
+ function getPreviousState() {
289
+ const config = AsyncLocalStorageProviderSingleton.getRunnableConfig();
290
+ return config.configurable?.[CONFIG_KEY_PREVIOUS_STATE];
293
291
  }
292
+
293
+ //#endregion
294
+ export { entrypoint, getPreviousState, task };
294
295
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/func/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kCAAkC,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,yBAAyB,EACzB,GAAG,EACH,QAAQ,EACR,KAAK,EACL,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAStD,OA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AU,gBAAgB;IAC9B,MAAM,MAAM,GACV,kCAAkC,CAAC,iBAAiB,EAAE,CAAC;IACzD,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,yBAAyB,CAAW,CAAC;AACpE,CAAC"}
1
+ {"version":3,"file":"index.js","names":["cache: CachePolicy | undefined","entrypoint","config: LangGraphRunnableConfig"],"sources":["../../src/func/index.ts"],"sourcesContent":["import {\n BaseCache,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport {\n CONFIG_KEY_PREVIOUS_STATE,\n END,\n PREVIOUS,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { call, getRunnableForEntrypoint } from \"../pregel/call.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport {\n EntrypointFinal,\n EntrypointReturnT,\n EntrypointFinalSaveT,\n EntrypointFunc,\n TaskFunc,\n} from \"./types.js\";\nimport { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\nimport {\n RunnableCallable,\n isAsyncGeneratorFunction,\n isGeneratorFunction,\n} from \"../utils.js\";\nimport { ChannelWrite, PASSTHROUGH } from \"../pregel/write.js\";\n\n/**\n * Options for the {@link task} function\n */\nexport interface TaskOptions {\n /**\n * The name of the task, analogous to the node name in {@link StateGraph}.\n */\n name: string;\n /**\n * The retry policy for the task. Configures how many times and under what conditions\n * the task should be retried if it fails.\n */\n retry?: RetryPolicy;\n\n /**\n * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\n}\n\n/**\n * Define a LangGraph task using the `task` function.\n *\n * Tasks can only be called from within an {@link entrypoint} or from within a StateGraph.\n * A task can be called like a regular function with the following differences:\n *\n * - When a checkpointer is enabled, the function inputs and outputs must be serializable.\n * - The wrapped function can only be called from within an entrypoint or StateGraph.\n * - Calling the function produces a promise. This makes it easy to parallelize tasks.\n *\n * @typeParam ArgsT - The type of arguments the task function accepts\n * @typeParam OutputT - The type of value the task function returns\n * @param optionsOrName - Either an {@link TaskOptions} object, or a string for the name of the task\n * @param func - The function that executes this task\n * @returns A proxy function that accepts the same arguments as the original and always returns the result as a Promise\n *\n * @example basic example\n * ```typescript\n * const addOne = task(\"add\", async (a: number) => a + 1);\n *\n * const workflow = entrypoint(\"example\", async (numbers: number[]) => {\n * const promises = numbers.map(n => addOne(n));\n * const results = await Promise.all(promises);\n * return results;\n * });\n *\n * // Call the entrypoint\n * await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]\n * ```\n *\n * @example using a retry policy\n * ```typescript\n * const addOne = task({\n * name: \"add\",\n * retry: { maxAttempts: 3 }\n * },\n * async (a: number) => a + 1\n * );\n *\n * const workflow = entrypoint(\"example\", async (numbers: number[]) => {\n * const promises = numbers.map(n => addOne(n));\n * const results = await Promise.all(promises);\n * return results;\n * });\n * ```\n */\nexport function task<ArgsT extends unknown[], OutputT>(\n optionsOrName: TaskOptions | string,\n func: TaskFunc<ArgsT, OutputT>\n): (...args: ArgsT) => Promise<OutputT> {\n const options =\n typeof optionsOrName === \"string\"\n ? { name: optionsOrName, retry: undefined, cachePolicy: undefined }\n : optionsOrName;\n\n const { name, retry } = options;\n if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {\n throw new Error(\n \"Generators are disallowed as tasks. For streaming responses, use config.write.\"\n );\n }\n\n const cachePolicy =\n options.cachePolicy ??\n // `cache` was mistakingly used as an alias for `cachePolicy` in v0.3.x,\n // TODO: remove in 1.x\n (\"cache\" in options ? (options.cache as CachePolicy) : undefined);\n\n let cache: CachePolicy | undefined;\n if (typeof cachePolicy === \"boolean\") {\n cache = cachePolicy ? {} : undefined;\n } else {\n cache = cachePolicy;\n }\n\n return (...args: ArgsT) => {\n return call({ func, name, retry, cache }, ...args);\n };\n}\n\n/**\n * Options for the {@link entrypoint} function\n */\nexport type EntrypointOptions = {\n /**\n * The name of the {@link entrypoint}, analogous to the node name in {@link StateGraph}.\n * This name is used for logging, debugging, and checkpoint identification.\n */\n name: string;\n /**\n * The checkpointer for the {@link entrypoint}. Used to save and restore state between\n * invocations of the workflow.\n */\n checkpointer?: BaseCheckpointSaver;\n /**\n * The store for the {@link entrypoint}. Used to persist data across workflow runs.\n */\n store?: BaseStore;\n\n /**\n * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n\n/**\n * Type declaration for the entrypoint function with its properties\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(\n optionsOrName: EntrypointOptions | string,\n func: EntrypointFunc<InputT, OutputT>\n ): Pregel<\n Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>,\n {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n },\n Record<string, unknown>,\n InputT,\n EntrypointReturnT<OutputT>,\n // Because the update type is an return type union of tasks + entrypoint,\n // thus we can't type it properly.\n any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Awaited<EntrypointReturnT<OutputT>>\n >;\n\n /**\n * A helper utility for use with the functional API that returns a value to the caller,\n * as well as a separate state value to persist to the checkpoint. This allows workflows\n * to maintain state between runs while returning different values to the caller.\n *\n * @typeParam ValueT - The type of the value to return to the caller\n * @typeParam SaveT - The type of the state to save to the checkpoint\n * @param value - The value to return to the caller\n * @param save - The value to save to the checkpoint\n * @returns An object with the value and save properties\n *\n * @example\n * ```typescript\n * return entrypoint.final({\n * value: \"result for caller\",\n * save: { counter: currentCount + 1 }\n * });\n * ```\n */\n final<ValueT, SaveT>(options: {\n value?: ValueT;\n save?: SaveT;\n }): EntrypointFinal<ValueT, SaveT>;\n}\n\n/**\n * Define a LangGraph workflow using the `entrypoint` function.\n *\n * ### Function signature\n *\n * The wrapped function must accept at most **two parameters**. The first parameter\n * is the input to the function. The second (optional) parameter is a\n * {@link LangGraphRunnableConfig} object. If you wish to pass multiple parameters to\n * the function, you can pass them as an object.\n *\n * ### Helper functions\n *\n * #### Streaming\n * To write data to the \"custom\" stream, use the {@link getWriter} function, or the\n * {@link LangGraphRunnableConfig.writer} property.\n *\n * #### State management\n * The {@link getPreviousState} function can be used to access the previous state\n * that was returned from the last invocation of the entrypoint on the same thread id.\n *\n * If you wish to save state other than the return value, you can use the\n * {@link entrypoint.final} function.\n *\n * @typeParam InputT - The type of input the entrypoint accepts\n * @typeParam OutputT - The type of output the entrypoint produces\n * @param optionsOrName - Either an {@link EntrypointOptions} object, or a string for the name of the entrypoint\n * @param func - The function that executes this entrypoint\n * @returns A {@link Pregel} instance that can be run to execute the workflow\n *\n * @example Using entrypoint and tasks\n * ```typescript\n * import { task, entrypoint } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n * import { interrupt, Command } from \"@langchain/langgraph\";\n *\n * const composeEssay = task(\"compose\", async (topic: string) => {\n * await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation\n * return `An essay about ${topic}`;\n * });\n *\n * const reviewWorkflow = entrypoint({\n * name: \"review\",\n * checkpointer: new MemorySaver()\n * }, async (topic: string) => {\n * const essay = await composeEssay(topic);\n * const humanReview = await interrupt({\n * question: \"Please provide a review\",\n * essay\n * });\n * return {\n * essay,\n * review: humanReview\n * };\n * });\n *\n * // Example configuration for the workflow\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n *\n * // Topic for the essay\n * const topic = \"cats\";\n *\n * // Stream the workflow to generate the essay and await human review\n * for await (const result of reviewWorkflow.stream(topic, config)) {\n * console.log(result);\n * }\n *\n * // Example human review provided after the interrupt\n * const humanReview = \"This essay is great.\";\n *\n * // Resume the workflow with the provided human review\n * for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {\n * console.log(result);\n * }\n * ```\n *\n * @example Accessing the previous return value\n * ```typescript\n * import { entrypoint, getPreviousState } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n *\n * const accumulator = entrypoint({\n * name: \"accumulator\",\n * checkpointer: new MemorySaver()\n * }, async (input: string) => {\n * const previous = getPreviousState<number>();\n * return previous !== undefined ? `${previous } ${input}` : input;\n * });\n *\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n * await accumulator.invoke(\"hello\", config); // returns \"hello\"\n * await accumulator.invoke(\"world\", config); // returns \"hello world\"\n * ```\n *\n * @example Using entrypoint.final to save a value\n * ```typescript\n * import { entrypoint, getPreviousState } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n *\n * const myWorkflow = entrypoint({\n * name: \"accumulator\",\n * checkpointer: new MemorySaver()\n * }, async (num: number) => {\n * const previous = getPreviousState<number>();\n *\n * // This will return the previous value to the caller, saving\n * // 2 * num to the checkpoint, which will be used in the next invocation\n * // for the `previous` parameter.\n * return entrypoint.final({\n * value: previous ?? 0,\n * save: 2 * num\n * });\n * });\n *\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n *\n * await myWorkflow.invoke(3, config); // 0 (previous was undefined)\n * await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)\n * ```\n */\nexport const entrypoint = function entrypoint<InputT, OutputT>(\n optionsOrName: EntrypointOptions | string,\n func: EntrypointFunc<InputT, OutputT>\n) {\n const { name, checkpointer, store, cache } =\n typeof optionsOrName === \"string\"\n ? { name: optionsOrName, checkpointer: undefined, store: undefined }\n : optionsOrName;\n if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {\n throw new Error(\n \"Generators are disallowed as entrypoints. For streaming responses, use config.write.\"\n );\n }\n const streamMode = \"updates\";\n const bound = getRunnableForEntrypoint(name, func);\n\n // Helper to check if a value is an EntrypointFinal\n function isEntrypointFinal(\n value: unknown\n ): value is EntrypointFinal<unknown, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__lg_type\" in value &&\n value.__lg_type === \"__pregel_final\"\n );\n }\n\n // Helper function to pluck the return value from EntrypointFinal or passthrough\n const pluckReturnValue = new RunnableCallable({\n name: \"pluckReturnValue\",\n func: (value: unknown) => {\n return isEntrypointFinal(value) ? value.value : value;\n },\n });\n\n // Helper function to pluck the save value from EntrypointFinal or passthrough\n const pluckSaveValue = new RunnableCallable({\n name: \"pluckSaveValue\",\n func: (value: unknown) => {\n return isEntrypointFinal(value) ? value.save : value;\n },\n });\n\n const entrypointNode = new PregelNode<InputT, EntrypointReturnT<OutputT>>({\n bound,\n triggers: [START],\n channels: [START],\n writers: [\n new ChannelWrite(\n [\n { channel: END, value: PASSTHROUGH, mapper: pluckReturnValue },\n { channel: PREVIOUS, value: PASSTHROUGH, mapper: pluckSaveValue },\n ],\n [TAG_HIDDEN]\n ),\n ],\n });\n\n return new Pregel<\n Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, // node types\n {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, // channel types\n Record<string, unknown>, // configurable types\n InputT, // input type\n EntrypointReturnT<OutputT> // output type\n >({\n name,\n checkpointer,\n nodes: {\n [name]: entrypointNode,\n },\n channels: {\n [START]: new EphemeralValue<InputT>(),\n [END]: new LastValue<EntrypointReturnT<OutputT>>(),\n [PREVIOUS]: new LastValue<EntrypointFinalSaveT<OutputT>>(),\n },\n inputChannels: START,\n outputChannels: END,\n streamChannels: END,\n streamMode,\n store,\n cache,\n });\n} as EntrypointFunction;\n\n// documented by the EntrypointFunction interface\nentrypoint.final = function final<ValueT, SaveT>({\n value,\n save,\n}: {\n value?: ValueT;\n save?: SaveT;\n}): EntrypointFinal<ValueT, SaveT> {\n return { value, save, __lg_type: \"__pregel_final\" };\n};\n\n/**\n * A helper utility function for use with the functional API that returns the previous\n * state from the checkpoint from the last invocation of the current thread.\n *\n * This function allows workflows to access state that was saved in previous runs\n * using {@link entrypoint.final}.\n *\n * @typeParam StateT - The type of the state that was previously saved\n * @returns The previous saved state from the last invocation of the current thread\n *\n * @example\n * ```typescript\n * const previousState = getPreviousState<{ counter: number }>();\n * const newCount = (previousState?.counter ?? 0) + 1;\n * ```\n */\nexport function getPreviousState<StateT>(): StateT {\n const config: LangGraphRunnableConfig =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n return config.configurable?.[CONFIG_KEY_PREVIOUS_STATE] as StateT;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,SAAgB,KACd,eACA,MACsC;CACtC,MAAM,UACJ,OAAO,kBAAkB,WACrB;EAAE,MAAM;EAAe,OAAO;EAAW,aAAa;KACtD;CAEN,MAAM,EAAE,MAAM,UAAU;AACxB,KAAI,yBAAyB,SAAS,oBAAoB,MACxD,OAAM,IAAI,MACR;CAIJ,MAAM,cACJ,QAAQ,gBAGP,WAAW,UAAW,QAAQ,QAAwB;CAEzD,IAAIA;AACJ,KAAI,OAAO,gBAAgB,UACzB,SAAQ,cAAc,KAAK;KAE3B,SAAQ;AAGV,SAAQ,GAAG,SAAgB;AACzB,SAAO,KAAK;GAAE;GAAM;GAAM;GAAO;KAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgNjD,MAAa,aAAa,SAASC,aACjC,eACA,MACA;CACA,MAAM,EAAE,MAAM,cAAc,OAAO,UACjC,OAAO,kBAAkB,WACrB;EAAE,MAAM;EAAe,cAAc;EAAW,OAAO;KACvD;AACN,KAAI,yBAAyB,SAAS,oBAAoB,MACxD,OAAM,IAA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