@langchain/langgraph 1.0.7 → 1.0.12

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 (383) hide show
  1. package/package.json +7 -7
  2. package/CHANGELOG.md +0 -286
  3. package/dist/_virtual/rolldown_runtime.cjs +0 -25
  4. package/dist/channels/any_value.cjs +0 -46
  5. package/dist/channels/any_value.cjs.map +0 -1
  6. package/dist/channels/any_value.d.cts +0 -24
  7. package/dist/channels/any_value.d.cts.map +0 -1
  8. package/dist/channels/any_value.d.ts +0 -24
  9. package/dist/channels/any_value.d.ts.map +0 -1
  10. package/dist/channels/any_value.js +0 -46
  11. package/dist/channels/any_value.js.map +0 -1
  12. package/dist/channels/base.cjs +0 -102
  13. package/dist/channels/base.cjs.map +0 -1
  14. package/dist/channels/base.d.cts +0 -79
  15. package/dist/channels/base.d.cts.map +0 -1
  16. package/dist/channels/base.d.ts +0 -79
  17. package/dist/channels/base.d.ts.map +0 -1
  18. package/dist/channels/base.js +0 -97
  19. package/dist/channels/base.js.map +0 -1
  20. package/dist/channels/binop.cjs +0 -49
  21. package/dist/channels/binop.cjs.map +0 -1
  22. package/dist/channels/binop.d.cts +0 -22
  23. package/dist/channels/binop.d.cts.map +0 -1
  24. package/dist/channels/binop.d.ts +0 -22
  25. package/dist/channels/binop.d.ts.map +0 -1
  26. package/dist/channels/binop.js +0 -49
  27. package/dist/channels/binop.js.map +0 -1
  28. package/dist/channels/dynamic_barrier_value.cjs +0 -76
  29. package/dist/channels/dynamic_barrier_value.cjs.map +0 -1
  30. package/dist/channels/dynamic_barrier_value.d.cts +0 -42
  31. package/dist/channels/dynamic_barrier_value.d.cts.map +0 -1
  32. package/dist/channels/dynamic_barrier_value.d.ts +0 -42
  33. package/dist/channels/dynamic_barrier_value.d.ts.map +0 -1
  34. package/dist/channels/dynamic_barrier_value.js +0 -76
  35. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  36. package/dist/channels/ephemeral_value.cjs +0 -46
  37. package/dist/channels/ephemeral_value.cjs.map +0 -1
  38. package/dist/channels/ephemeral_value.d.cts +0 -22
  39. package/dist/channels/ephemeral_value.d.cts.map +0 -1
  40. package/dist/channels/ephemeral_value.d.ts +0 -22
  41. package/dist/channels/ephemeral_value.d.ts.map +0 -1
  42. package/dist/channels/ephemeral_value.js +0 -46
  43. package/dist/channels/ephemeral_value.js.map +0 -1
  44. package/dist/channels/index.cjs +0 -21
  45. package/dist/channels/index.d.cts +0 -9
  46. package/dist/channels/index.d.ts +0 -9
  47. package/dist/channels/index.js +0 -10
  48. package/dist/channels/last_value.cjs +0 -98
  49. package/dist/channels/last_value.cjs.map +0 -1
  50. package/dist/channels/last_value.d.cts +0 -44
  51. package/dist/channels/last_value.d.cts.map +0 -1
  52. package/dist/channels/last_value.d.ts +0 -44
  53. package/dist/channels/last_value.d.ts.map +0 -1
  54. package/dist/channels/last_value.js +0 -97
  55. package/dist/channels/last_value.js.map +0 -1
  56. package/dist/channels/named_barrier_value.cjs +0 -118
  57. package/dist/channels/named_barrier_value.cjs.map +0 -1
  58. package/dist/channels/named_barrier_value.d.cts +0 -46
  59. package/dist/channels/named_barrier_value.d.cts.map +0 -1
  60. package/dist/channels/named_barrier_value.d.ts +0 -46
  61. package/dist/channels/named_barrier_value.d.ts.map +0 -1
  62. package/dist/channels/named_barrier_value.js +0 -116
  63. package/dist/channels/named_barrier_value.js.map +0 -1
  64. package/dist/channels/topic.cjs +0 -65
  65. package/dist/channels/topic.cjs.map +0 -1
  66. package/dist/channels/topic.d.cts +0 -32
  67. package/dist/channels/topic.d.cts.map +0 -1
  68. package/dist/channels/topic.d.ts +0 -32
  69. package/dist/channels/topic.d.ts.map +0 -1
  70. package/dist/channels/topic.js +0 -65
  71. package/dist/channels/topic.js.map +0 -1
  72. package/dist/constants.cjs +0 -406
  73. package/dist/constants.cjs.map +0 -1
  74. package/dist/constants.d.cts +0 -285
  75. package/dist/constants.d.cts.map +0 -1
  76. package/dist/constants.d.ts +0 -285
  77. package/dist/constants.d.ts.map +0 -1
  78. package/dist/constants.js +0 -362
  79. package/dist/constants.js.map +0 -1
  80. package/dist/errors.cjs +0 -163
  81. package/dist/errors.cjs.map +0 -1
  82. package/dist/errors.d.cts +0 -81
  83. package/dist/errors.d.cts.map +0 -1
  84. package/dist/errors.d.ts +0 -81
  85. package/dist/errors.d.ts.map +0 -1
  86. package/dist/errors.js +0 -146
  87. package/dist/errors.js.map +0 -1
  88. package/dist/func/index.cjs +0 -301
  89. package/dist/func/index.cjs.map +0 -1
  90. package/dist/func/index.d.cts +0 -293
  91. package/dist/func/index.d.cts.map +0 -1
  92. package/dist/func/index.d.ts +0 -293
  93. package/dist/func/index.d.ts.map +0 -1
  94. package/dist/func/index.js +0 -298
  95. package/dist/func/index.js.map +0 -1
  96. package/dist/func/types.d.cts +0 -64
  97. package/dist/func/types.d.cts.map +0 -1
  98. package/dist/func/types.d.ts +0 -64
  99. package/dist/func/types.d.ts.map +0 -1
  100. package/dist/graph/annotation.cjs +0 -101
  101. package/dist/graph/annotation.cjs.map +0 -1
  102. package/dist/graph/annotation.d.cts +0 -116
  103. package/dist/graph/annotation.d.cts.map +0 -1
  104. package/dist/graph/annotation.d.ts +0 -116
  105. package/dist/graph/annotation.d.ts.map +0 -1
  106. package/dist/graph/annotation.js +0 -99
  107. package/dist/graph/annotation.js.map +0 -1
  108. package/dist/graph/graph.cjs +0 -423
  109. package/dist/graph/graph.cjs.map +0 -1
  110. package/dist/graph/graph.d.cts +0 -132
  111. package/dist/graph/graph.d.cts.map +0 -1
  112. package/dist/graph/graph.d.ts +0 -132
  113. package/dist/graph/graph.d.ts.map +0 -1
  114. package/dist/graph/graph.js +0 -420
  115. package/dist/graph/graph.js.map +0 -1
  116. package/dist/graph/index.cjs +0 -5
  117. package/dist/graph/index.js +0 -7
  118. package/dist/graph/message.cjs +0 -99
  119. package/dist/graph/message.cjs.map +0 -1
  120. package/dist/graph/message.d.cts +0 -40
  121. package/dist/graph/message.d.cts.map +0 -1
  122. package/dist/graph/message.d.ts +0 -40
  123. package/dist/graph/message.d.ts.map +0 -1
  124. package/dist/graph/message.js +0 -95
  125. package/dist/graph/message.js.map +0 -1
  126. package/dist/graph/messages_annotation.cjs +0 -110
  127. package/dist/graph/messages_annotation.cjs.map +0 -1
  128. package/dist/graph/messages_annotation.d.cts +0 -112
  129. package/dist/graph/messages_annotation.d.cts.map +0 -1
  130. package/dist/graph/messages_annotation.d.ts +0 -112
  131. package/dist/graph/messages_annotation.d.ts.map +0 -1
  132. package/dist/graph/messages_annotation.js +0 -107
  133. package/dist/graph/messages_annotation.js.map +0 -1
  134. package/dist/graph/state.cjs +0 -501
  135. package/dist/graph/state.cjs.map +0 -1
  136. package/dist/graph/state.d.cts +0 -236
  137. package/dist/graph/state.d.cts.map +0 -1
  138. package/dist/graph/state.d.ts +0 -236
  139. package/dist/graph/state.d.ts.map +0 -1
  140. package/dist/graph/state.js +0 -499
  141. package/dist/graph/state.js.map +0 -1
  142. package/dist/graph/zod/index.cjs +0 -10
  143. package/dist/graph/zod/index.d.cts +0 -3
  144. package/dist/graph/zod/index.d.ts +0 -3
  145. package/dist/graph/zod/index.js +0 -5
  146. package/dist/graph/zod/meta.cjs +0 -145
  147. package/dist/graph/zod/meta.cjs.map +0 -1
  148. package/dist/graph/zod/meta.d.cts +0 -116
  149. package/dist/graph/zod/meta.d.cts.map +0 -1
  150. package/dist/graph/zod/meta.d.ts +0 -116
  151. package/dist/graph/zod/meta.d.ts.map +0 -1
  152. package/dist/graph/zod/meta.js +0 -141
  153. package/dist/graph/zod/meta.js.map +0 -1
  154. package/dist/graph/zod/plugin.cjs +0 -41
  155. package/dist/graph/zod/plugin.cjs.map +0 -1
  156. package/dist/graph/zod/plugin.js +0 -41
  157. package/dist/graph/zod/plugin.js.map +0 -1
  158. package/dist/graph/zod/schema.cjs +0 -99
  159. package/dist/graph/zod/schema.cjs.map +0 -1
  160. package/dist/graph/zod/schema.d.cts +0 -38
  161. package/dist/graph/zod/schema.d.cts.map +0 -1
  162. package/dist/graph/zod/schema.d.ts +0 -38
  163. package/dist/graph/zod/schema.d.ts.map +0 -1
  164. package/dist/graph/zod/schema.js +0 -94
  165. package/dist/graph/zod/schema.js.map +0 -1
  166. package/dist/graph/zod/zod-registry.cjs +0 -43
  167. package/dist/graph/zod/zod-registry.cjs.map +0 -1
  168. package/dist/graph/zod/zod-registry.d.cts +0 -51
  169. package/dist/graph/zod/zod-registry.d.cts.map +0 -1
  170. package/dist/graph/zod/zod-registry.d.ts +0 -51
  171. package/dist/graph/zod/zod-registry.d.ts.map +0 -1
  172. package/dist/graph/zod/zod-registry.js +0 -41
  173. package/dist/graph/zod/zod-registry.js.map +0 -1
  174. package/dist/hash.cjs +0 -271
  175. package/dist/hash.cjs.map +0 -1
  176. package/dist/hash.js +0 -269
  177. package/dist/hash.js.map +0 -1
  178. package/dist/index.cjs +0 -112
  179. package/dist/index.cjs.map +0 -1
  180. package/dist/index.d.cts +0 -26
  181. package/dist/index.d.ts +0 -26
  182. package/dist/index.js +0 -22
  183. package/dist/index.js.map +0 -1
  184. package/dist/interrupt.cjs +0 -82
  185. package/dist/interrupt.cjs.map +0 -1
  186. package/dist/interrupt.d.cts +0 -58
  187. package/dist/interrupt.d.cts.map +0 -1
  188. package/dist/interrupt.d.ts +0 -58
  189. package/dist/interrupt.d.ts.map +0 -1
  190. package/dist/interrupt.js +0 -81
  191. package/dist/interrupt.js.map +0 -1
  192. package/dist/prebuilt/agentName.cjs +0 -153
  193. package/dist/prebuilt/agentName.cjs.map +0 -1
  194. package/dist/prebuilt/agentName.d.cts +0 -42
  195. package/dist/prebuilt/agentName.d.cts.map +0 -1
  196. package/dist/prebuilt/agentName.d.ts +0 -42
  197. package/dist/prebuilt/agentName.d.ts.map +0 -1
  198. package/dist/prebuilt/agentName.js +0 -152
  199. package/dist/prebuilt/agentName.js.map +0 -1
  200. package/dist/prebuilt/agent_executor.cjs +0 -44
  201. package/dist/prebuilt/agent_executor.cjs.map +0 -1
  202. package/dist/prebuilt/agent_executor.d.cts +0 -58
  203. package/dist/prebuilt/agent_executor.d.cts.map +0 -1
  204. package/dist/prebuilt/agent_executor.d.ts +0 -58
  205. package/dist/prebuilt/agent_executor.d.ts.map +0 -1
  206. package/dist/prebuilt/agent_executor.js +0 -44
  207. package/dist/prebuilt/agent_executor.js.map +0 -1
  208. package/dist/prebuilt/chat_agent_executor.cjs +0 -68
  209. package/dist/prebuilt/chat_agent_executor.cjs.map +0 -1
  210. package/dist/prebuilt/chat_agent_executor.d.cts +0 -23
  211. package/dist/prebuilt/chat_agent_executor.d.cts.map +0 -1
  212. package/dist/prebuilt/chat_agent_executor.d.ts +0 -23
  213. package/dist/prebuilt/chat_agent_executor.d.ts.map +0 -1
  214. package/dist/prebuilt/chat_agent_executor.js +0 -67
  215. package/dist/prebuilt/chat_agent_executor.js.map +0 -1
  216. package/dist/prebuilt/index.cjs +0 -15
  217. package/dist/prebuilt/index.d.cts +0 -8
  218. package/dist/prebuilt/index.d.ts +0 -8
  219. package/dist/prebuilt/index.js +0 -8
  220. package/dist/prebuilt/interrupt.d.cts +0 -61
  221. package/dist/prebuilt/interrupt.d.cts.map +0 -1
  222. package/dist/prebuilt/interrupt.d.ts +0 -61
  223. package/dist/prebuilt/interrupt.d.ts.map +0 -1
  224. package/dist/prebuilt/react_agent_executor.cjs +0 -344
  225. package/dist/prebuilt/react_agent_executor.cjs.map +0 -1
  226. package/dist/prebuilt/react_agent_executor.d.cts +0 -230
  227. package/dist/prebuilt/react_agent_executor.d.cts.map +0 -1
  228. package/dist/prebuilt/react_agent_executor.d.ts +0 -230
  229. package/dist/prebuilt/react_agent_executor.d.ts.map +0 -1
  230. package/dist/prebuilt/react_agent_executor.js +0 -342
  231. package/dist/prebuilt/react_agent_executor.js.map +0 -1
  232. package/dist/prebuilt/tool_executor.cjs +0 -48
  233. package/dist/prebuilt/tool_executor.cjs.map +0 -1
  234. package/dist/prebuilt/tool_executor.d.cts +0 -42
  235. package/dist/prebuilt/tool_executor.d.cts.map +0 -1
  236. package/dist/prebuilt/tool_executor.d.ts +0 -42
  237. package/dist/prebuilt/tool_executor.d.ts.map +0 -1
  238. package/dist/prebuilt/tool_executor.js +0 -47
  239. package/dist/prebuilt/tool_executor.js.map +0 -1
  240. package/dist/prebuilt/tool_node.cjs +0 -248
  241. package/dist/prebuilt/tool_node.cjs.map +0 -1
  242. package/dist/prebuilt/tool_node.d.cts +0 -182
  243. package/dist/prebuilt/tool_node.d.cts.map +0 -1
  244. package/dist/prebuilt/tool_node.d.ts +0 -182
  245. package/dist/prebuilt/tool_node.d.ts.map +0 -1
  246. package/dist/prebuilt/tool_node.js +0 -246
  247. package/dist/prebuilt/tool_node.js.map +0 -1
  248. package/dist/pregel/algo.cjs +0 -573
  249. package/dist/pregel/algo.cjs.map +0 -1
  250. package/dist/pregel/algo.d.cts +0 -13
  251. package/dist/pregel/algo.d.cts.map +0 -1
  252. package/dist/pregel/algo.d.ts +0 -13
  253. package/dist/pregel/algo.d.ts.map +0 -1
  254. package/dist/pregel/algo.js +0 -567
  255. package/dist/pregel/algo.js.map +0 -1
  256. package/dist/pregel/call.cjs +0 -53
  257. package/dist/pregel/call.cjs.map +0 -1
  258. package/dist/pregel/call.js +0 -50
  259. package/dist/pregel/call.js.map +0 -1
  260. package/dist/pregel/debug.cjs +0 -175
  261. package/dist/pregel/debug.cjs.map +0 -1
  262. package/dist/pregel/debug.js +0 -169
  263. package/dist/pregel/debug.js.map +0 -1
  264. package/dist/pregel/index.cjs +0 -1170
  265. package/dist/pregel/index.cjs.map +0 -1
  266. package/dist/pregel/index.d.cts +0 -546
  267. package/dist/pregel/index.d.cts.map +0 -1
  268. package/dist/pregel/index.d.ts +0 -546
  269. package/dist/pregel/index.d.ts.map +0 -1
  270. package/dist/pregel/index.js +0 -1168
  271. package/dist/pregel/index.js.map +0 -1
  272. package/dist/pregel/io.cjs +0 -140
  273. package/dist/pregel/io.cjs.map +0 -1
  274. package/dist/pregel/io.js +0 -135
  275. package/dist/pregel/io.js.map +0 -1
  276. package/dist/pregel/loop.cjs +0 -548
  277. package/dist/pregel/loop.cjs.map +0 -1
  278. package/dist/pregel/loop.js +0 -547
  279. package/dist/pregel/loop.js.map +0 -1
  280. package/dist/pregel/messages.cjs +0 -108
  281. package/dist/pregel/messages.cjs.map +0 -1
  282. package/dist/pregel/messages.js +0 -107
  283. package/dist/pregel/messages.js.map +0 -1
  284. package/dist/pregel/read.cjs +0 -152
  285. package/dist/pregel/read.cjs.map +0 -1
  286. package/dist/pregel/read.d.cts +0 -51
  287. package/dist/pregel/read.d.cts.map +0 -1
  288. package/dist/pregel/read.d.ts +0 -51
  289. package/dist/pregel/read.d.ts.map +0 -1
  290. package/dist/pregel/read.js +0 -150
  291. package/dist/pregel/read.js.map +0 -1
  292. package/dist/pregel/remote.cjs +0 -349
  293. package/dist/pregel/remote.cjs.map +0 -1
  294. package/dist/pregel/remote.d.cts +0 -123
  295. package/dist/pregel/remote.d.cts.map +0 -1
  296. package/dist/pregel/remote.d.ts +0 -123
  297. package/dist/pregel/remote.d.ts.map +0 -1
  298. package/dist/pregel/remote.js +0 -348
  299. package/dist/pregel/remote.js.map +0 -1
  300. package/dist/pregel/retry.cjs +0 -92
  301. package/dist/pregel/retry.cjs.map +0 -1
  302. package/dist/pregel/retry.js +0 -92
  303. package/dist/pregel/retry.js.map +0 -1
  304. package/dist/pregel/runnable_types.d.cts +0 -49
  305. package/dist/pregel/runnable_types.d.cts.map +0 -1
  306. package/dist/pregel/runnable_types.d.ts +0 -49
  307. package/dist/pregel/runnable_types.d.ts.map +0 -1
  308. package/dist/pregel/runner.cjs +0 -228
  309. package/dist/pregel/runner.cjs.map +0 -1
  310. package/dist/pregel/runner.js +0 -228
  311. package/dist/pregel/runner.js.map +0 -1
  312. package/dist/pregel/stream.cjs +0 -199
  313. package/dist/pregel/stream.cjs.map +0 -1
  314. package/dist/pregel/stream.js +0 -196
  315. package/dist/pregel/stream.js.map +0 -1
  316. package/dist/pregel/types.cjs +0 -27
  317. package/dist/pregel/types.cjs.map +0 -1
  318. package/dist/pregel/types.d.cts +0 -453
  319. package/dist/pregel/types.d.cts.map +0 -1
  320. package/dist/pregel/types.d.ts +0 -453
  321. package/dist/pregel/types.d.ts.map +0 -1
  322. package/dist/pregel/types.js +0 -25
  323. package/dist/pregel/types.js.map +0 -1
  324. package/dist/pregel/utils/config.cjs +0 -122
  325. package/dist/pregel/utils/config.cjs.map +0 -1
  326. package/dist/pregel/utils/config.d.cts +0 -36
  327. package/dist/pregel/utils/config.d.cts.map +0 -1
  328. package/dist/pregel/utils/config.d.ts +0 -36
  329. package/dist/pregel/utils/config.d.ts.map +0 -1
  330. package/dist/pregel/utils/config.js +0 -115
  331. package/dist/pregel/utils/config.js.map +0 -1
  332. package/dist/pregel/utils/index.cjs +0 -103
  333. package/dist/pregel/utils/index.cjs.map +0 -1
  334. package/dist/pregel/utils/index.d.cts +0 -51
  335. package/dist/pregel/utils/index.d.cts.map +0 -1
  336. package/dist/pregel/utils/index.d.ts +0 -51
  337. package/dist/pregel/utils/index.d.ts.map +0 -1
  338. package/dist/pregel/utils/index.js +0 -97
  339. package/dist/pregel/utils/index.js.map +0 -1
  340. package/dist/pregel/utils/subgraph.cjs +0 -19
  341. package/dist/pregel/utils/subgraph.cjs.map +0 -1
  342. package/dist/pregel/utils/subgraph.js +0 -17
  343. package/dist/pregel/utils/subgraph.js.map +0 -1
  344. package/dist/pregel/validate.cjs +0 -45
  345. package/dist/pregel/validate.cjs.map +0 -1
  346. package/dist/pregel/validate.js +0 -44
  347. package/dist/pregel/validate.js.map +0 -1
  348. package/dist/pregel/write.cjs +0 -97
  349. package/dist/pregel/write.cjs.map +0 -1
  350. package/dist/pregel/write.d.cts +0 -35
  351. package/dist/pregel/write.d.cts.map +0 -1
  352. package/dist/pregel/write.d.ts +0 -35
  353. package/dist/pregel/write.d.ts.map +0 -1
  354. package/dist/pregel/write.js +0 -95
  355. package/dist/pregel/write.js.map +0 -1
  356. package/dist/remote.cjs +0 -3
  357. package/dist/remote.d.cts +0 -2
  358. package/dist/remote.d.ts +0 -2
  359. package/dist/remote.js +0 -3
  360. package/dist/setup/async_local_storage.cjs +0 -12
  361. package/dist/setup/async_local_storage.cjs.map +0 -1
  362. package/dist/setup/async_local_storage.js +0 -11
  363. package/dist/setup/async_local_storage.js.map +0 -1
  364. package/dist/utils.cjs +0 -88
  365. package/dist/utils.cjs.map +0 -1
  366. package/dist/utils.d.cts +0 -32
  367. package/dist/utils.d.cts.map +0 -1
  368. package/dist/utils.d.ts +0 -32
  369. package/dist/utils.d.ts.map +0 -1
  370. package/dist/utils.js +0 -81
  371. package/dist/utils.js.map +0 -1
  372. package/dist/web.cjs +0 -96
  373. package/dist/web.d.cts +0 -23
  374. package/dist/web.d.ts +0 -23
  375. package/dist/web.js +0 -15
  376. package/dist/writer.cjs +0 -15
  377. package/dist/writer.cjs.map +0 -1
  378. package/dist/writer.d.cts +0 -7
  379. package/dist/writer.d.cts.map +0 -1
  380. package/dist/writer.d.ts +0 -7
  381. package/dist/writer.d.ts.map +0 -1
  382. package/dist/writer.js +0 -14
  383. package/dist/writer.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"remote.js","names":["updatedStreamModes: StreamMode[]","tasks: PregelTaskDescription[]","namespace: string[]","nodesMap: Record<string, DrawableNode>","DrawableGraph"],"sources":["../../src/pregel/remote.ts"],"sourcesContent":["import {\n Client,\n type Checkpoint,\n type ThreadState,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Graph as DrawableGraph,\n Node as DrawableNode,\n} from \"@langchain/core/runnables/graph\";\nimport {\n mergeConfigs,\n Runnable,\n RunnableConfig,\n} from \"@langchain/core/runnables\";\nimport {\n All,\n CheckpointListOptions,\n CheckpointMetadata,\n} from \"@langchain/langgraph-checkpoint\";\nimport { StreamEvent } from \"@langchain/core/tracers/log_stream\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport { isBaseMessage } from \"@langchain/core/messages\";\n\nimport {\n BaseChannel,\n GraphInterrupt,\n LangGraphRunnableConfig,\n RemoteException,\n} from \"../web.js\";\nimport { StrRecord } from \"./algo.js\";\nimport { PregelInputType, PregelOptions, PregelOutputType } from \"./index.js\";\nimport { PregelNode } from \"./read.js\";\nimport {\n PregelParams,\n PregelInterface,\n PregelTaskDescription,\n StateSnapshot,\n StreamMode,\n} from \"./types.js\";\nimport {\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CONFIG_KEY_STREAM,\n INTERRUPT,\n isCommand,\n} from \"../constants.js\";\n\nexport type RemoteGraphParams = Omit<\n PregelParams<StrRecord<string, PregelNode>, StrRecord<string, BaseChannel>>,\n \"channels\" | \"nodes\" | \"inputChannels\" | \"outputChannels\"\n> & {\n graphId: string;\n client?: Client;\n url?: string;\n apiKey?: string;\n headers?: Record<string, string>;\n streamResumable?: boolean;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst _serializeInputs = (obj: any): any => {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(_serializeInputs);\n }\n\n // Handle BaseMessage instances by converting them to a serializable format\n if (isBaseMessage(obj)) {\n const dict = obj.toDict();\n return {\n ...dict.data,\n role: obj.getType(),\n };\n }\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [key, _serializeInputs(value)])\n );\n};\n\n/**\n * Return a tuple of the final list of stream modes sent to the\n * remote graph and a boolean flag indicating if only one stream mode was\n * originally requested and whether stream mode 'updates'\n * was present in the original list of stream modes.\n *\n * 'updates' mode is always added to the list of stream modes so that interrupts\n * can be detected in the remote graph.\n */\nconst getStreamModes = (\n streamMode?: StreamMode | StreamMode[],\n defaultStreamMode: StreamMode = \"updates\"\n) => {\n const updatedStreamModes: StreamMode[] = [];\n let reqUpdates = false;\n let reqSingle = true;\n\n if (\n streamMode !== undefined &&\n (typeof streamMode === \"string\" ||\n (Array.isArray(streamMode) && streamMode.length > 0))\n ) {\n reqSingle = typeof streamMode === \"string\";\n const mapped = Array.isArray(streamMode) ? streamMode : [streamMode];\n updatedStreamModes.push(...mapped);\n } else {\n updatedStreamModes.push(defaultStreamMode);\n }\n if (updatedStreamModes.includes(\"updates\")) {\n reqUpdates = true;\n } else {\n updatedStreamModes.push(\"updates\");\n }\n return {\n updatedStreamModes,\n reqUpdates,\n reqSingle,\n };\n};\n\n/**\n * The `RemoteGraph` class is a client implementation for calling remote\n * APIs that implement the LangGraph Server API specification.\n *\n * For example, the `RemoteGraph` class can be used to call APIs from deployments\n * on LangSmith Deployment.\n *\n * `RemoteGraph` behaves the same way as a `StateGraph` and can be used directly as\n * a node in another `StateGraph`.\n *\n * @example\n * ```ts\n * import { RemoteGraph } from \"@langchain/langgraph/remote\";\n *\n * // Can also pass a LangGraph SDK client instance directly\n * const remoteGraph = new RemoteGraph({\n * graphId: process.env.LANGGRAPH_REMOTE_GRAPH_ID!,\n * apiKey: process.env.LANGGRAPH_REMOTE_GRAPH_API_KEY,\n * url: process.env.LANGGRAPH_REMOTE_GRAPH_API_URL,\n * });\n *\n * const input = {\n * messages: [\n * {\n * role: \"human\",\n * content: \"Hello world!\",\n * },\n * ],\n * };\n *\n * const config = {\n * configurable: { thread_id: \"threadId1\" },\n * };\n *\n * await remoteGraph.invoke(input, config);\n * ```\n */\nexport class RemoteGraph<\n Nn extends StrRecord<string, PregelNode> = StrRecord<string, PregelNode>,\n Cc extends StrRecord<string, BaseChannel> = StrRecord<string, BaseChannel>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = StrRecord<string, any>\n >\n extends Runnable<\n PregelInputType,\n PregelOutputType,\n PregelOptions<Nn, Cc, ContextType>\n >\n implements PregelInterface<Nn, Cc, ContextType>\n{\n static lc_name() {\n return \"RemoteGraph\";\n }\n\n lc_namespace = [\"langgraph\", \"pregel\"];\n\n lg_is_pregel = true;\n\n config?: RunnableConfig;\n\n graphId: string;\n\n protected client: Client;\n\n protected interruptBefore?: Array<keyof Nn> | All;\n\n protected interruptAfter?: Array<keyof Nn> | All;\n\n protected streamResumable?: boolean;\n\n constructor(params: RemoteGraphParams) {\n super(params);\n\n this.graphId = params.graphId;\n this.client =\n params.client ??\n new Client({\n apiUrl: params.url,\n apiKey: params.apiKey,\n defaultHeaders: params.headers,\n });\n this.config = params.config;\n this.interruptBefore = params.interruptBefore;\n this.interruptAfter = params.interruptAfter;\n this.streamResumable = params.streamResumable;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Remove ignore when we remove support for 0.2 versions of core\n override withConfig(config: RunnableConfig): typeof this {\n const mergedConfig = mergeConfigs(this.config, config);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return new (this.constructor as any)({ ...this, config: mergedConfig });\n }\n\n protected _sanitizeConfig(config: RunnableConfig) {\n const reservedConfigurableKeys = new Set([\n \"callbacks\",\n \"checkpoint_map\",\n \"checkpoint_id\",\n \"checkpoint_ns\",\n ]);\n\n const sanitizeObj = <T>(obj: T): T => {\n try {\n // This will only throw if we're trying to serialize a circular reference\n // or trying to serialize a BigInt...\n JSON.stringify(obj);\n return obj;\n } catch {\n const seen = new WeakSet();\n return JSON.parse(\n JSON.stringify(obj, (_, value) => {\n if (typeof value === \"object\" && value != null) {\n if (seen.has(value)) return \"[Circular]\";\n seen.add(value);\n }\n\n if (typeof value === \"bigint\") return value.toString();\n return value;\n })\n );\n }\n };\n\n // Remove non-JSON serializable fields from the config\n const sanitizedConfig = sanitizeObj(config);\n\n // Only include configurable keys that are not reserved and\n // not starting with \"__pregel_\" prefix\n const newConfigurable = Object.fromEntries(\n Object.entries(sanitizedConfig.configurable ?? {}).filter(\n ([k]) => !reservedConfigurableKeys.has(k) && !k.startsWith(\"__pregel_\")\n )\n );\n\n return {\n tags: sanitizedConfig.tags ?? [],\n metadata: sanitizedConfig.metadata ?? {},\n configurable: newConfigurable,\n recursion_limit: sanitizedConfig.recursionLimit,\n };\n }\n\n protected _getConfig(checkpoint: Record<string, unknown>): RunnableConfig {\n return {\n configurable: {\n thread_id: checkpoint.thread_id,\n checkpoint_ns: checkpoint.checkpoint_ns,\n checkpoint_id: checkpoint.checkpoint_id,\n checkpoint_map: checkpoint.checkpoint_map ?? {},\n },\n };\n }\n\n protected _getCheckpoint(config?: RunnableConfig): Checkpoint | undefined {\n if (config?.configurable === undefined) {\n return undefined;\n }\n\n const checkpointKeys = [\n \"thread_id\",\n \"checkpoint_ns\",\n \"checkpoint_id\",\n \"checkpoint_map\",\n ] as const;\n\n const checkpoint = Object.fromEntries(\n checkpointKeys\n .map((key) => [key, config.configurable![key]])\n .filter(([_, value]) => value !== undefined)\n );\n\n return Object.keys(checkpoint).length > 0 ? checkpoint : undefined;\n }\n\n protected _createStateSnapshot(state: ThreadState): StateSnapshot {\n const tasks: PregelTaskDescription[] = state.tasks.map((task) => {\n return {\n id: task.id,\n name: task.name,\n error: task.error ? { message: task.error } : undefined,\n // TODO: remove in LangGraph.js 0.4\n interrupts: task.interrupts.map(({ id, ...rest }) => ({\n interrupt_id: id,\n ...rest,\n })),\n // eslint-disable-next-line no-nested-ternary\n state: task.state\n ? this._createStateSnapshot(task.state)\n : task.checkpoint\n ? { configurable: task.checkpoint }\n : undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result: (task as any).result,\n };\n });\n\n return {\n values: state.values,\n next: state.next ? [...state.next] : [],\n config: {\n configurable: {\n thread_id: state.checkpoint.thread_id,\n checkpoint_ns: state.checkpoint.checkpoint_ns,\n checkpoint_id: state.checkpoint.checkpoint_id,\n checkpoint_map: state.checkpoint.checkpoint_map ?? {},\n },\n },\n metadata: state.metadata\n ? (state.metadata as CheckpointMetadata)\n : undefined,\n createdAt: state.created_at ?? undefined,\n parentConfig: state.parent_checkpoint\n ? {\n configurable: {\n thread_id: state.parent_checkpoint.thread_id,\n checkpoint_ns: state.parent_checkpoint.checkpoint_ns,\n checkpoint_id: state.parent_checkpoint.checkpoint_id,\n checkpoint_map: state.parent_checkpoint.checkpoint_map ?? {},\n },\n }\n : undefined,\n tasks,\n };\n }\n\n override async invoke(\n input: PregelInputType,\n options?: Partial<PregelOptions<Nn, Cc, ContextType>>\n ): Promise<PregelOutputType> {\n let lastValue;\n const stream = await this.stream(input, {\n ...options,\n streamMode: \"values\",\n });\n for await (const chunk of stream) {\n lastValue = chunk;\n }\n return lastValue;\n }\n\n override streamEvents(\n input: PregelInputType,\n options: Partial<PregelOptions<Nn, Cc, ContextType>> & {\n version: \"v1\" | \"v2\";\n }\n ): IterableReadableStream<StreamEvent>;\n\n override streamEvents(\n input: PregelInputType,\n options: Partial<PregelOptions<Nn, Cc, ContextType>> & {\n version: \"v1\" | \"v2\";\n encoding: never;\n }\n ): IterableReadableStream<never>;\n\n override streamEvents(\n _input: PregelInputType,\n _options: Partial<PregelOptions<Nn, Cc, ContextType>> & {\n version: \"v1\" | \"v2\";\n encoding?: never;\n }\n ): IterableReadableStream<StreamEvent> {\n throw new Error(\"Not implemented.\");\n }\n\n override async *_streamIterator(\n input: PregelInputType,\n options?: Partial<PregelOptions<Nn, Cc, ContextType>>\n ): AsyncGenerator<PregelOutputType> {\n const mergedConfig = mergeConfigs(this.config, options);\n const sanitizedConfig = this._sanitizeConfig(mergedConfig);\n\n const streamProtocolInstance = options?.configurable?.[CONFIG_KEY_STREAM];\n\n const streamSubgraphs =\n options?.subgraphs ?? streamProtocolInstance !== undefined;\n\n const interruptBefore = options?.interruptBefore ?? this.interruptBefore;\n const interruptAfter = options?.interruptAfter ?? this.interruptAfter;\n\n const { updatedStreamModes, reqSingle, reqUpdates } = getStreamModes(\n options?.streamMode\n );\n\n const extendedStreamModes = [\n ...new Set([\n ...updatedStreamModes,\n ...(streamProtocolInstance?.modes ?? new Set()),\n ]),\n ].map((mode) => {\n if (mode === \"messages\") return \"messages-tuple\";\n return mode;\n });\n\n let command;\n let serializedInput;\n if (isCommand(input)) {\n // TODO: Remove cast when SDK type fix gets merged\n command = input.toJSON() as Record<string, unknown>;\n serializedInput = undefined;\n } else {\n serializedInput = _serializeInputs(input);\n }\n\n for await (const chunk of this.client.runs.stream(\n sanitizedConfig.configurable.thread_id as string,\n this.graphId,\n {\n command,\n input: serializedInput,\n config: sanitizedConfig,\n streamMode: extendedStreamModes,\n interruptBefore: interruptBefore as string[],\n interruptAfter: interruptAfter as string[],\n streamSubgraphs,\n ifNotExists: \"create\",\n signal: mergedConfig.signal,\n streamResumable: this.streamResumable,\n }\n )) {\n let mode;\n let namespace: string[];\n if (chunk.event.includes(CHECKPOINT_NAMESPACE_SEPARATOR)) {\n const eventComponents = chunk.event.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n // eslint-disable-next-line prefer-destructuring\n mode = eventComponents[0];\n namespace = eventComponents.slice(1);\n } else {\n mode = chunk.event;\n namespace = [];\n }\n const callerNamespace = options?.configurable?.checkpoint_ns;\n if (typeof callerNamespace === \"string\") {\n namespace = callerNamespace\n .split(CHECKPOINT_NAMESPACE_SEPARATOR)\n .concat(namespace);\n }\n if (\n streamProtocolInstance !== undefined &&\n streamProtocolInstance.modes?.has(chunk.event)\n ) {\n streamProtocolInstance.push([namespace, mode, chunk.data]);\n }\n if (chunk.event.startsWith(\"updates\")) {\n if (\n typeof chunk.data === \"object\" &&\n chunk.data?.[INTERRUPT] !== undefined\n ) {\n throw new GraphInterrupt(chunk.data[INTERRUPT]);\n }\n if (!reqUpdates) {\n continue;\n }\n } else if (chunk.event?.startsWith(\"error\")) {\n throw new RemoteException(\n typeof chunk.data === \"string\"\n ? chunk.data\n : JSON.stringify(chunk.data)\n );\n }\n if (\n !updatedStreamModes.includes(\n chunk.event.split(CHECKPOINT_NAMESPACE_SEPARATOR)[0] as StreamMode\n )\n ) {\n continue;\n }\n if (options?.subgraphs) {\n if (reqSingle) {\n yield [namespace, chunk.data];\n } else {\n yield [namespace, mode, chunk.data];\n }\n } else if (reqSingle) {\n yield chunk.data;\n } else {\n yield [mode, chunk.data];\n }\n }\n }\n\n async updateState(\n inputConfig: LangGraphRunnableConfig,\n values: Record<string, unknown>,\n asNode?: string\n ): Promise<RunnableConfig> {\n const mergedConfig = mergeConfigs(this.config, inputConfig);\n const response = await this.client.threads.updateState(\n mergedConfig.configurable?.thread_id,\n { values, asNode, checkpoint: this._getCheckpoint(mergedConfig) }\n );\n // TODO: Fix SDK typing\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return this._getConfig((response as any).checkpoint);\n }\n\n async *getStateHistory(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncIterableIterator<StateSnapshot> {\n const mergedConfig = mergeConfigs(this.config, config);\n const states = await this.client.threads.getHistory(\n mergedConfig.configurable?.thread_id,\n {\n limit: options?.limit ?? 10,\n // TODO: Fix type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n before: this._getCheckpoint(options?.before) as any,\n metadata: options?.filter,\n checkpoint: this._getCheckpoint(mergedConfig),\n }\n );\n for (const state of states) {\n yield this._createStateSnapshot(state);\n }\n }\n\n protected _getDrawableNodes(\n nodes: Array<{\n id: string | number;\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data?: Record<string, any> | string;\n metadata?: unknown;\n }>\n ): Record<string, DrawableNode> {\n const nodesMap: Record<string, DrawableNode> = {};\n for (const node of nodes) {\n const nodeId = node.id;\n nodesMap[nodeId] = {\n id: nodeId.toString(),\n name: typeof node.data === \"string\" ? node.data : node.data?.name ?? \"\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: (node.data as any) ?? {},\n metadata:\n typeof node.data !== \"string\" ? node.data?.metadata ?? {} : {},\n };\n }\n return nodesMap;\n }\n\n async getState(\n config: RunnableConfig,\n options?: { subgraphs?: boolean }\n ): Promise<StateSnapshot> {\n const mergedConfig = mergeConfigs(this.config, config);\n\n const state = await this.client.threads.getState(\n mergedConfig.configurable?.thread_id,\n this._getCheckpoint(mergedConfig),\n options\n );\n return this._createStateSnapshot(state);\n }\n\n /** @deprecated Use getGraphAsync instead. The async method will become the default in the next minor release. */\n override getGraph(\n _?: RunnableConfig & { xray?: boolean | number }\n ): DrawableGraph {\n throw new Error(\n `The synchronous \"getGraph\" is not supported for this graph. Call \"getGraphAsync\" instead.`\n );\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n */\n async getGraphAsync(config?: RunnableConfig & { xray?: boolean | number }) {\n const graph = await this.client.assistants.getGraph(this.graphId, {\n xray: config?.xray,\n });\n return new DrawableGraph({\n nodes: this._getDrawableNodes(graph.nodes),\n edges: graph.edges,\n });\n }\n\n /** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */\n getSubgraphs(): Generator<[string, PregelInterface<Nn, Cc, ContextType>]> {\n throw new Error(\n `The synchronous \"getSubgraphs\" method is not supported for this graph. Call \"getSubgraphsAsync\" instead.`\n );\n }\n\n async *getSubgraphsAsync(\n namespace?: string,\n recurse = false\n ): AsyncGenerator<[string, PregelInterface<Nn, Cc, ContextType>]> {\n const subgraphs = await this.client.assistants.getSubgraphs(this.graphId, {\n namespace,\n recurse,\n });\n\n for (const [ns, graphSchema] of Object.entries(subgraphs)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const remoteSubgraph = new (this.constructor as any)({\n ...this,\n graphId: graphSchema.graph_id,\n });\n yield [ns, remoteSubgraph];\n }\n }\n}\n"],"mappings":";;;;;;;;;AA2DA,MAAM,oBAAoB,QAAkB;AAC1C,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,KAChB,QAAO,IAAI,IAAI;AAIjB,KAAI,cAAc,MAAM;EACtB,MAAM,OAAO,IAAI;AACjB,SAAO;GACL,GAAG,KAAK;GACR,MAAM,IAAI;;;AAId,QAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,iBAAiB;;;;;;;;;;;AAarE,MAAM,kBACJ,YACA,oBAAgC,cAC7B;CACH,MAAMA,qBAAmC;CACzC,IAAI,aAAa;CACjB,IAAI,YAAY;AAEhB,KACE,eAAe,W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zB,QAAQ,KAAK,eAAe,SAAS;GACrC,UAAU,SAAS;GACnB,YAAY,KAAK,eAAe;;AAGpC,OAAK,MAAM,SAAS,OAClB,OAAM,KAAK,qBAAqB;;CAIpC,AAAU,kBACR,OAO8B;EAC9B,MAAMC,WAAyC;AAC/C,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,SAAS,KAAK;AACpB,YAAS,UAAU;IACjB,IAAI,OAAO;IACX,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO,KAAK,MAAM,QAAQ;IAErE,MAAO,KAAK,QAAgB;IAC5B,UACE,OAAO,KAAK,SAAS,WAAW,KAAK,MAAM,YAAY,KAAK;;;AAGlE,SAAO;;CAGT,MAAM,SACJ,QACA,SACwB;EACxB,MAAM,eAAe,aAAa,KAAK,QAAQ;EAE/C,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,SACtC,aAAa,cAAc,WAC3B,KAAK,eAAe,eACpB;AAEF,SAAO,KAAK,qBAAqB;;;CAInC,AAAS,SACP,GACe;AACf,QAAM,IAAI,MACR;;;;;CAOJ,MAAM,cAAc,QAAuD;EACzE,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,SAAS,KAAK,SAAS,EAChE,MAAM,QAAQ;AAEhB,SAAO,IAAIC,MAAc;GACvB,OAAO,KAAK,kBAAkB,MAAM;GACpC,OAAO,MAAM;;;;CAKjB,eAA0E;AACxE,QAAM,IAAI,MACR;;CAIJ,OAAO,kBACL,WACA,UAAU,OACsD;EAChE,MAAM,YAAY,MAAM,KAAK,OAAO,WAAW,aAAa,KAAK,SAAS;GACxE;GACA;;AAGF,OAAK,MAAM,CAAC,IAAI,gBAAgB,OAAO,QAAQ,YAAY;GAEzD,MAAM,iBAAiB,IAAK,KAAK,YAAoB;IACnD,GAAG;IACH,SAAS,YAAY;;AAEvB,SAAM,CAAC,IAAI"}
@@ -1,92 +0,0 @@
1
- const require_errors = require('../errors.cjs');
2
- const require_constants = require('../constants.cjs');
3
- const require_config = require('./utils/config.cjs');
4
- const require_index = require('./utils/index.cjs');
5
-
6
- //#region src/pregel/retry.ts
7
- const DEFAULT_INITIAL_INTERVAL = 500;
8
- const DEFAULT_BACKOFF_FACTOR = 2;
9
- const DEFAULT_MAX_INTERVAL = 128e3;
10
- const DEFAULT_MAX_RETRIES = 3;
11
- const DEFAULT_STATUS_NO_RETRY = [
12
- 400,
13
- 401,
14
- 402,
15
- 403,
16
- 404,
17
- 405,
18
- 406,
19
- 407,
20
- 409
21
- ];
22
- const DEFAULT_RETRY_ON_HANDLER = (error) => {
23
- if (error.message.startsWith("Cancel") || error.message.startsWith("AbortError") || error.name === "AbortError") return false;
24
- if (error.name === "GraphValueError") return false;
25
- if (error?.code === "ECONNABORTED") return false;
26
- const status = error?.response?.status ?? error?.status;
27
- if (status && DEFAULT_STATUS_NO_RETRY.includes(+status)) return false;
28
- if (error?.error?.code === "insufficient_quota") return false;
29
- return true;
30
- };
31
- async function _runWithRetry(pregelTask, retryPolicy, configurable, signal) {
32
- const resolvedRetryPolicy = pregelTask.retry_policy ?? retryPolicy;
33
- let interval = resolvedRetryPolicy !== void 0 ? resolvedRetryPolicy.initialInterval ?? DEFAULT_INITIAL_INTERVAL : 0;
34
- let attempts = 0;
35
- let error;
36
- let result;
37
- let { config } = pregelTask;
38
- if (configurable) config = require_index.patchConfigurable(config, configurable);
39
- config = {
40
- ...config,
41
- signal
42
- };
43
- while (true) {
44
- if (signal?.aborted) break;
45
- pregelTask.writes.splice(0, pregelTask.writes.length);
46
- error = void 0;
47
- try {
48
- result = await pregelTask.proc.invoke(pregelTask.input, config);
49
- break;
50
- } catch (e) {
51
- error = e;
52
- error.pregelTaskId = pregelTask.id;
53
- if (require_errors.isParentCommand(error)) {
54
- const ns = config?.configurable?.checkpoint_ns;
55
- const cmd = error.command;
56
- if (cmd.graph === ns) {
57
- for (const writer of pregelTask.writers) await writer.invoke(cmd, config);
58
- error = void 0;
59
- break;
60
- } else if (cmd.graph === require_constants.Command.PARENT) {
61
- const parentNs = require_config.getParentCheckpointNamespace(ns);
62
- error.command = new require_constants.Command({
63
- ...error.command,
64
- graph: parentNs
65
- });
66
- }
67
- }
68
- if (require_errors.isGraphBubbleUp(error)) break;
69
- if (resolvedRetryPolicy === void 0) break;
70
- attempts += 1;
71
- if (attempts >= (resolvedRetryPolicy.maxAttempts ?? DEFAULT_MAX_RETRIES)) break;
72
- const retryOn = resolvedRetryPolicy.retryOn ?? DEFAULT_RETRY_ON_HANDLER;
73
- if (!retryOn(error)) break;
74
- interval = Math.min(resolvedRetryPolicy.maxInterval ?? DEFAULT_MAX_INTERVAL, interval * (resolvedRetryPolicy.backoffFactor ?? DEFAULT_BACKOFF_FACTOR));
75
- const intervalWithJitter = resolvedRetryPolicy.jitter ? Math.floor(interval + Math.random() * 1e3) : interval;
76
- await new Promise((resolve) => setTimeout(resolve, intervalWithJitter));
77
- const errorName = error.name ?? error.constructor.unminifiable_name ?? error.constructor.name;
78
- if (resolvedRetryPolicy?.logWarning ?? true) console.log(`Retrying task "${String(pregelTask.name)}" after ${interval.toFixed(2)}ms (attempt ${attempts}) after ${errorName}: ${error}`);
79
- config = require_index.patchConfigurable(config, { [require_constants.CONFIG_KEY_RESUMING]: true });
80
- }
81
- }
82
- return {
83
- task: pregelTask,
84
- result,
85
- error,
86
- signalAborted: signal?.aborted
87
- };
88
- }
89
-
90
- //#endregion
91
- exports._runWithRetry = _runWithRetry;
92
- //# sourceMappingURL=retry.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.cjs","names":["patchConfigurable","e: unknown","isParentCommand","ns: string","Command","getParentCheckpointNamespace","isGraphBubbleUp","CONFIG_KEY_RESUMING"],"sources":["../../src/pregel/retry.ts"],"sourcesContent":["import { Command, CONFIG_KEY_RESUMING } from \"../constants.js\";\nimport { isGraphBubbleUp, isParentCommand } from \"../errors.js\";\nimport { PregelExecutableTask } from \"./types.js\";\nimport { getParentCheckpointNamespace } from \"./utils/config.js\";\nimport { patchConfigurable, type RetryPolicy } from \"./utils/index.js\";\n\nexport const DEFAULT_INITIAL_INTERVAL = 500;\nexport const DEFAULT_BACKOFF_FACTOR = 2;\nexport const DEFAULT_MAX_INTERVAL = 128000;\nexport const DEFAULT_MAX_RETRIES = 3;\n\nconst DEFAULT_STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst DEFAULT_RETRY_ON_HANDLER = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n return false;\n }\n\n // Thrown when interrupt is called without a checkpointer\n if (error.name === \"GraphValueError\") {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n return false;\n }\n\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && DEFAULT_STATUS_NO_RETRY.includes(+status)) {\n return false;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n return false;\n }\n return true;\n};\n\nexport type SettledPregelTask = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n task: PregelExecutableTask<any, any>;\n error: Error;\n signalAborted?: boolean;\n};\n\nexport async function _runWithRetry<\n N extends PropertyKey,\n C extends PropertyKey\n>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pregelTask: PregelExecutableTask<N, C>,\n retryPolicy?: RetryPolicy,\n configurable?: Record<string, unknown>,\n signal?: AbortSignal\n): Promise<{\n task: PregelExecutableTask<N, C>;\n result: unknown;\n error: Error | undefined;\n signalAborted?: boolean;\n}> {\n const resolvedRetryPolicy = pregelTask.retry_policy ?? retryPolicy;\n let interval =\n resolvedRetryPolicy !== undefined\n ? resolvedRetryPolicy.initialInterval ?? DEFAULT_INITIAL_INTERVAL\n : 0;\n let attempts = 0;\n let error;\n let result;\n\n let { config } = pregelTask;\n if (configurable) config = patchConfigurable(config, configurable);\n config = { ...config, signal };\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (signal?.aborted) {\n // no need to throw here - we'll throw from the runner, instead.\n // there's just no point in retrying if the user has requested an abort.\n break;\n }\n // Clear any writes from previous attempts\n pregelTask.writes.splice(0, pregelTask.writes.length);\n error = undefined;\n try {\n result = await pregelTask.proc.invoke(pregelTask.input, config);\n break;\n } catch (e: unknown) {\n error = e;\n (error as { pregelTaskId: string }).pregelTaskId = pregelTask.id;\n if (isParentCommand(error)) {\n const ns: string = config?.configurable?.checkpoint_ns;\n const cmd = error.command;\n if (cmd.graph === ns) {\n // this command is for the current graph, handle it\n for (const writer of pregelTask.writers) {\n await writer.invoke(cmd, config);\n }\n error = undefined;\n break;\n } else if (cmd.graph === Command.PARENT) {\n // this command is for the parent graph, assign it to the parent\n const parentNs = getParentCheckpointNamespace(ns);\n error.command = new Command({\n ...error.command,\n graph: parentNs,\n });\n }\n }\n if (isGraphBubbleUp(error)) {\n break;\n }\n if (resolvedRetryPolicy === undefined) {\n break;\n }\n attempts += 1;\n // check if we should give up\n if (\n attempts >= (resolvedRetryPolicy.maxAttempts ?? DEFAULT_MAX_RETRIES)\n ) {\n break;\n }\n const retryOn = resolvedRetryPolicy.retryOn ?? DEFAULT_RETRY_ON_HANDLER;\n if (!retryOn(error)) {\n break;\n }\n interval = Math.min(\n resolvedRetryPolicy.maxInterval ?? DEFAULT_MAX_INTERVAL,\n interval * (resolvedRetryPolicy.backoffFactor ?? DEFAULT_BACKOFF_FACTOR)\n );\n const intervalWithJitter = resolvedRetryPolicy.jitter\n ? Math.floor(interval + Math.random() * 1000)\n : interval;\n // sleep before retrying\n // eslint-disable-next-line no-promise-executor-return\n await new Promise((resolve) => setTimeout(resolve, intervalWithJitter));\n // log the retry\n const errorName =\n (error as Error).name ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((error as Error).constructor as any).unminifiable_name ??\n (error as Error).constructor.name;\n if (resolvedRetryPolicy?.logWarning ?? true) {\n console.log(\n `Retrying task \"${String(pregelTask.name)}\" after ${interval.toFixed(\n 2\n )}ms (attempt ${attempts}) after ${errorName}: ${error}`\n );\n }\n\n // signal subgraphs to resume (if available)\n config = patchConfigurable(config, { [CONFIG_KEY_RESUMING]: true });\n }\n }\n return {\n task: pregelTask,\n result,\n error: error as Error | undefined,\n signalAborted: signal?.aborted,\n };\n}\n"],"mappings":";;;;;;AAMA,MAAa,2BAA2B;AACxC,MAAa,yBAAyB;AACtC,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AAEnC,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAIF,MAAM,4BAA4B,UAAe;AAC/C,KACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,iBACzB,MAAM,SAAS,aAEf,QAAO;AAIT,KAAI,MAAM,SAAS,kBACjB,QAAO;AAIT,KAAK,OAAe,SAAS,eAC3B,QAAO;CAGT,MAAM,SAEH,OAAe,UAAU,UAAW,OAAe;AACtD,KAAI,UAAU,wBAAwB,SAAS,CAAC,QAC9C,QAAO;AAGT,KAAK,OAAe,OAAO,SAAS,qBAClC,QAAO;AAET,QAAO;;AAUT,eAAsB,cAKpB,YACA,aACA,cACA,QAMC;CACD,MAAM,sBAAsB,WAAW,gBAAgB;CACvD,IAAI,WACF,wBAAwB,SACpB,oBAAoB,mBAAmB,2BACvC;CACN,IAAI,WAAW;CACf,IAAI;CACJ,IAAI;CAEJ,IAAI,EAAE,WAAW;AACjB,KAAI,aAAc,UAASA,gCAAkB,QAAQ;AACrD,UAAS;EAAE,GAAG;EAAQ;;AAGtB,QAAO,MAAM;AACX,MAAI,QAAQ,QAGV;AAGF,aAAW,OAAO,OAAO,GAAG,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CheckpointNamespace } from "./utils/config.js";
4
- import { patchConfigurable } from "./utils/index.js";
5
-
6
- //#region src/pregel/retry.ts
7
- const DEFAULT_INITIAL_INTERVAL = 500;
8
- const DEFAULT_BACKOFF_FACTOR = 2;
9
- const DEFAULT_MAX_INTERVAL = 128e3;
10
- const DEFAULT_MAX_RETRIES = 3;
11
- const DEFAULT_STATUS_NO_RETRY = [
12
- 400,
13
- 401,
14
- 402,
15
- 403,
16
- 404,
17
- 405,
18
- 406,
19
- 407,
20
- 409
21
- ];
22
- const DEFAULT_RETRY_ON_HANDLER = (error) => {
23
- if (error.message.startsWith("Cancel") || error.message.startsWith("AbortError") || error.name === "AbortError") return false;
24
- if (error.name === "GraphValueError") return false;
25
- if (error?.code === "ECONNABORTED") return false;
26
- const status = error?.response?.status ?? error?.status;
27
- if (status && DEFAULT_STATUS_NO_RETRY.includes(+status)) return false;
28
- if (error?.error?.code === "insufficient_quota") return false;
29
- return true;
30
- };
31
- async function _runWithRetry(pregelTask, retryPolicy, configurable, signal) {
32
- const resolvedRetryPolicy = pregelTask.retry_policy ?? retryPolicy;
33
- let interval = resolvedRetryPolicy !== void 0 ? resolvedRetryPolicy.initialInterval ?? DEFAULT_INITIAL_INTERVAL : 0;
34
- let attempts = 0;
35
- let error;
36
- let result;
37
- let { config } = pregelTask;
38
- if (configurable) config = patchConfigurable(config, configurable);
39
- config = {
40
- ...config,
41
- signal
42
- };
43
- while (true) {
44
- if (signal?.aborted) break;
45
- pregelTask.writes.splice(0, pregelTask.writes.length);
46
- error = void 0;
47
- try {
48
- result = await pregelTask.proc.invoke(pregelTask.input, config);
49
- break;
50
- } catch (e) {
51
- error = e;
52
- error.pregelTaskId = pregelTask.id;
53
- if (isParentCommand(error)) {
54
- const ns = config?.configurable?.checkpoint_ns;
55
- const cmd = error.command;
56
- if (cmd.graph === ns) {
57
- for (const writer of pregelTask.writers) await writer.invoke(cmd, config);
58
- error = void 0;
59
- break;
60
- } else if (cmd.graph === Command.PARENT) {
61
- const parentNs = getParentCheckpointNamespace(ns);
62
- error.command = new Command({
63
- ...error.command,
64
- graph: parentNs
65
- });
66
- }
67
- }
68
- if (isGraphBubbleUp(error)) break;
69
- if (resolvedRetryPolicy === void 0) break;
70
- attempts += 1;
71
- if (attempts >= (resolvedRetryPolicy.maxAttempts ?? DEFAULT_MAX_RETRIES)) break;
72
- const retryOn = resolvedRetryPolicy.retryOn ?? DEFAULT_RETRY_ON_HANDLER;
73
- if (!retryOn(error)) break;
74
- interval = Math.min(resolvedRetryPolicy.maxInterval ?? DEFAULT_MAX_INTERVAL, interval * (resolvedRetryPolicy.backoffFactor ?? DEFAULT_BACKOFF_FACTOR));
75
- const intervalWithJitter = resolvedRetryPolicy.jitter ? Math.floor(interval + Math.random() * 1e3) : interval;
76
- await new Promise((resolve) => setTimeout(resolve, intervalWithJitter));
77
- const errorName = error.name ?? error.constructor.unminifiable_name ?? error.constructor.name;
78
- if (resolvedRetryPolicy?.logWarning ?? true) console.log(`Retrying task "${String(pregelTask.name)}" after ${interval.toFixed(2)}ms (attempt ${attempts}) after ${errorName}: ${error}`);
79
- config = patchConfigurable(config, { [CONFIG_KEY_RESUMING]: true });
80
- }
81
- }
82
- return {
83
- task: pregelTask,
84
- result,
85
- error,
86
- signalAborted: signal?.aborted
87
- };
88
- }
89
-
90
- //#endregion
91
- export { _runWithRetry };
92
- //# sourceMappingURL=retry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.js","names":["e: unknown","ns: string"],"sources":["../../src/pregel/retry.ts"],"sourcesContent":["import { Command, CONFIG_KEY_RESUMING } from \"../constants.js\";\nimport { isGraphBubbleUp, isParentCommand } from \"../errors.js\";\nimport { PregelExecutableTask } from \"./types.js\";\nimport { getParentCheckpointNamespace } from \"./utils/config.js\";\nimport { patchConfigurable, type RetryPolicy } from \"./utils/index.js\";\n\nexport const DEFAULT_INITIAL_INTERVAL = 500;\nexport const DEFAULT_BACKOFF_FACTOR = 2;\nexport const DEFAULT_MAX_INTERVAL = 128000;\nexport const DEFAULT_MAX_RETRIES = 3;\n\nconst DEFAULT_STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst DEFAULT_RETRY_ON_HANDLER = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n return false;\n }\n\n // Thrown when interrupt is called without a checkpointer\n if (error.name === \"GraphValueError\") {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n return false;\n }\n\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && DEFAULT_STATUS_NO_RETRY.includes(+status)) {\n return false;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n return false;\n }\n return true;\n};\n\nexport type SettledPregelTask = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n task: PregelExecutableTask<any, any>;\n error: Error;\n signalAborted?: boolean;\n};\n\nexport async function _runWithRetry<\n N extends PropertyKey,\n C extends PropertyKey\n>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pregelTask: PregelExecutableTask<N, C>,\n retryPolicy?: RetryPolicy,\n configurable?: Record<string, unknown>,\n signal?: AbortSignal\n): Promise<{\n task: PregelExecutableTask<N, C>;\n result: unknown;\n error: Error | undefined;\n signalAborted?: boolean;\n}> {\n const resolvedRetryPolicy = pregelTask.retry_policy ?? retryPolicy;\n let interval =\n resolvedRetryPolicy !== undefined\n ? resolvedRetryPolicy.initialInterval ?? DEFAULT_INITIAL_INTERVAL\n : 0;\n let attempts = 0;\n let error;\n let result;\n\n let { config } = pregelTask;\n if (configurable) config = patchConfigurable(config, configurable);\n config = { ...config, signal };\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (signal?.aborted) {\n // no need to throw here - we'll throw from the runner, instead.\n // there's just no point in retrying if the user has requested an abort.\n break;\n }\n // Clear any writes from previous attempts\n pregelTask.writes.splice(0, pregelTask.writes.length);\n error = undefined;\n try {\n result = await pregelTask.proc.invoke(pregelTask.input, config);\n break;\n } catch (e: unknown) {\n error = e;\n (error as { pregelTaskId: string }).pregelTaskId = pregelTask.id;\n if (isParentCommand(error)) {\n const ns: string = config?.configurable?.checkpoint_ns;\n const cmd = error.command;\n if (cmd.graph === ns) {\n // this command is for the current graph, handle it\n for (const writer of pregelTask.writers) {\n await writer.invoke(cmd, config);\n }\n error = undefined;\n break;\n } else if (cmd.graph === Command.PARENT) {\n // this command is for the parent graph, assign it to the parent\n const parentNs = getParentCheckpointNamespace(ns);\n error.command = new Command({\n ...error.command,\n graph: parentNs,\n });\n }\n }\n if (isGraphBubbleUp(error)) {\n break;\n }\n if (resolvedRetryPolicy === undefined) {\n break;\n }\n attempts += 1;\n // check if we should give up\n if (\n attempts >= (resolvedRetryPolicy.maxAttempts ?? DEFAULT_MAX_RETRIES)\n ) {\n break;\n }\n const retryOn = resolvedRetryPolicy.retryOn ?? DEFAULT_RETRY_ON_HANDLER;\n if (!retryOn(error)) {\n break;\n }\n interval = Math.min(\n resolvedRetryPolicy.maxInterval ?? DEFAULT_MAX_INTERVAL,\n interval * (resolvedRetryPolicy.backoffFactor ?? DEFAULT_BACKOFF_FACTOR)\n );\n const intervalWithJitter = resolvedRetryPolicy.jitter\n ? Math.floor(interval + Math.random() * 1000)\n : interval;\n // sleep before retrying\n // eslint-disable-next-line no-promise-executor-return\n await new Promise((resolve) => setTimeout(resolve, intervalWithJitter));\n // log the retry\n const errorName =\n (error as Error).name ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((error as Error).constructor as any).unminifiable_name ??\n (error as Error).constructor.name;\n if (resolvedRetryPolicy?.logWarning ?? true) {\n console.log(\n `Retrying task \"${String(pregelTask.name)}\" after ${interval.toFixed(\n 2\n )}ms (attempt ${attempts}) after ${errorName}: ${error}`\n );\n }\n\n // signal subgraphs to resume (if available)\n config = patchConfigurable(config, { [CONFIG_KEY_RESUMING]: true });\n }\n }\n return {\n task: pregelTask,\n result,\n error: error as Error | undefined,\n signalAborted: signal?.aborted,\n };\n}\n"],"mappings":";;;;;;AAMA,MAAa,2BAA2B;AACxC,MAAa,yBAAyB;AACtC,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AAEnC,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAIF,MAAM,4BAA4B,UAAe;AAC/C,KACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,iBACzB,MAAM,SAAS,aAEf,QAAO;AAIT,KAAI,MAAM,SAAS,kBACjB,QAAO;AAIT,KAAK,OAAe,SAAS,eAC3B,QAAO;CAGT,MAAM,SAEH,OAAe,UAAU,UAAW,OAAe;AACtD,KAAI,UAAU,wBAAwB,SAAS,CAAC,QAC9C,QAAO;AAGT,KAAK,OAAe,OAAO,SAAS,qBAClC,QAAO;AAET,QAAO;;AAUT,eAAsB,cAKpB,YACA,aACA,cACA,QAMC;CACD,MAAM,sBAAsB,WAAW,gBAAgB;CACvD,IAAI,WACF,wBAAwB,SACpB,oBAAoB,mBAAmB,2BACvC;CACN,IAAI,WAAW;CACf,IAAI;CACJ,IAAI;CAEJ,IAAI,EAAE,WAAW;AACjB,KAAI,aAAc,UAAS,kBAAkB,QAAQ;AACrD,UAAS;EAAE,GAAG;EAAQ;;AAGtB,QAAO,MAAM;AACX,MAAI,QAAQ,QAGV;AAGF,aAAW,OAAO,OAAO,GAAG,WAAW,OAAO;AAC9C,UAAQ;AACR,MAAI;AACF,YAAS,MAAM,WAAW,KAAK,OAAO,WAAW,OAAO;AACxD;WACOA,GAAY;AACnB,WAAQ;AACR,GAAC,MAAmC,eAAe,WAAW;AAC9D,OAAI,gBAAgB,QAAQ;IAC1B,MAAMC,KAAa,QAAQ,cAAc;IACzC,MAAM,MAAM,MAAM;AAClB,QAAI,IAAI,UAAU,IAAI;AAEpB,UAAK,MAAM,UAAU,WAAW,QAC9B,OAAM,OAAO,OAAO,KAAK;AAE3B,aAAQ;AACR;eACS,IAAI,UAAU,QAAQ,QAAQ;KAEvC,MAAM,WAAW,6BAA6B;AAC9C,WAAM,UAAU,IAAI,QAAQ;MAC1B,GAAG,MAAM;MACT,OAAO;;;;AAIb,OAAI,gBAAgB,OAClB;AAEF,OAAI,wBAAwB,OAC1B;AAEF,eAAY;AAEZ,OACE,aAAa,oBAAoB,eAAe,qBAEhD;GAEF,MAAM,UAAU,oBAAoB,WAAW;AAC/C,OAAI,CAAC,QAAQ,OACX;AAEF,cAAW,KAAK,IACd,oBAAoB,eAAe,sBACnC,YAAY,oBAAoB,iBAAiB;GAEnD,MAAM,qBAAqB,oBAAoB,SAC3C,KAAK,MAAM,WAAW,KAAK,WAAW,OACtC;AAGJ,SAAM,IAAI,SAAS,YAAY,WAAW,SAAS;GAEnD,MAAM,YACH,MAAgB,QAEf,MAAgB,YAAoB,qBACrC,MAAgB,YAAY;AAC/B,OAAI,qBAAqB,cAAc,KACrC,SAAQ,IACN,kBAAkB,OAAO,WAAW,MAAM,UAAU,SAAS,QAC3D,GACA,cAAc,SAAS,UAAU,UAAU,IAAI;AAKrD,YAAS,kBAAkB,QAAQ,GAAG,sBAAsB;;;AAGhE,QAAO;EACL,MAAM;EACN;EACO;EACP,eAAe,QAAQ"}
@@ -1,49 +0,0 @@
1
- import { BaseStore } from "@langchain/langgraph-checkpoint";
2
- import { RunnableConfig, RunnableInterface } from "@langchain/core/runnables";
3
-
4
- //#region src/pregel/runnable_types.d.ts
5
- type RunnableFunc$1<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = (input: RunInput,
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- options: CallOptions) => RunOutput | Promise<RunOutput>;
8
- type RunnableMapLike<RunInput, RunOutput> = { [K in keyof RunOutput]: RunnableLike$1<RunInput, RunOutput[K]> };
9
- type RunnableLike$1<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc$1<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>;
10
- type IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
11
- interface Runtime<ContextType = Record<string, unknown>, InterruptType = unknown, WriterType = unknown> {
12
- configurable?: ContextType;
13
- /** User provided context */
14
- context?: ContextType;
15
- /** Persistent key-value store */
16
- store?: BaseStore;
17
- /** Callback to send custom data chunks via the `custom` stream mode */
18
- writer: IsEqual<WriterType, unknown> extends true ? (chunk: unknown) => void : WriterType;
19
- /**
20
- * Interrupts the execution of a graph node.
21
- *
22
- * This function can be used to pause execution of a node, and return the value of the `resume`
23
- * input when the graph is re-invoked using `Command`.
24
- * Multiple interrupts can be called within a single node, and each will be handled sequentially.
25
- *
26
- * When an interrupt is called:
27
- * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.
28
- * 2. Otherwise, it throws a `GraphInterrupt` with the provided value
29
- * 3. The graph can be resumed by passing a `Command` with a `resume` value
30
- *
31
- * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,
32
- * you should avoid using `try/catch` blocks around the `interrupt` function,
33
- * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.
34
- *
35
- * @param value - The value to include in the interrupt.
36
- * @returns The `resume` value provided when the graph is re-invoked with a Command.
37
- */
38
- interrupt: IsEqual<InterruptType, unknown> extends true ? (value: unknown) => unknown : InterruptType;
39
- /** Abort signal to cancel the run. */
40
- signal: AbortSignal;
41
- }
42
- interface LangGraphRunnableConfig<
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- ContextType extends Record<string, any> = Record<string, any>
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- > extends RunnableConfig<ContextType>, Partial<Runtime<ContextType, unknown, unknown>> {}
47
- //#endregion
48
- export { LangGraphRunnableConfig, RunnableLike$1 as RunnableLike, Runtime };
49
- //# sourceMappingURL=runnable_types.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runnable_types.d.cts","names":["RunnableConfig","RunnableInterface","BaseStore","RunnableFunc","RunInput","CallOptions","RunOutput","Promise","RunnableMapLike","K","RunnableLike","IsEqual","T","U","Runtime","Record","ContextType","WriterType","InterruptType","AbortSignal","LangGraphRunnableConfig","Partial"],"sources":["../../src/pregel/runnable_types.d.ts"],"sourcesContent":["import { RunnableConfig, RunnableInterface } from \"@langchain/core/runnables\";\nimport { BaseStore } from \"@langchain/langgraph-checkpoint\";\ntype RunnableFunc<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = (input: RunInput, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\noptions: CallOptions) => RunOutput | Promise<RunOutput>;\ntype RunnableMapLike<RunInput, RunOutput> = {\n [K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;\n};\nexport type RunnableLike<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>;\ntype IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;\nexport interface Runtime<ContextType = Record<string, unknown>, InterruptType = unknown, WriterType = unknown> {\n configurable?: ContextType;\n /** User provided context */\n context?: ContextType;\n /** Persistent key-value store */\n store?: BaseStore;\n /** Callback to send custom data chunks via the `custom` stream mode */\n writer: IsEqual<WriterType, unknown> extends true ? (chunk: unknown) => void : WriterType;\n /**\n * Interrupts the execution of a graph node.\n *\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt.\n * @returns The `resume` value provided when the graph is re-invoked with a Command.\n */\n interrupt: IsEqual<InterruptType, unknown> extends true ? (value: unknown) => unknown : InterruptType;\n /** Abort signal to cancel the run. */\n signal: AbortSignal;\n}\nexport interface LangGraphRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextType extends Record<string, any> = Record<string, any>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n> extends RunnableConfig<ContextType>, Partial<Runtime<ContextType, unknown, unknown>> {\n}\nexport {};\n"],"mappings":";;;;KAEKG,wDAAsDH,iBAAiBA,0BAA0BI;;AAD1C,OACvDD,EAEIE,WAFJF,EAAY,GAEQG,SAFR,GAEoBC,OAFpB,CAE4BD,SAF5B,CAAA;KAGZE,eAHY,CAAA,QAAA,EAAA,SAAA,CAAA,GAAA,QAA0CR,MAI3CM,SAJ2CN,GAI/BU,cAJ+BV,CAIlBI,QAJkBJ,EAIRM,SAJQN,CAIES,CAJFT,CAAAA,CAAAA;AAA2CI,KAM1FM,cAN0FN,CAAAA,QAAAA,EAAAA,SAAAA,EAAAA,oBAMpCJ,cANoCI,GAMnBJ,cANmBI,CAAAA,GAMDH,iBANCG,CAMiBA,QANjBA,EAM2BE,SAN3BF,EAMsCC,WANtCD,CAAAA,GAMqDD,cANrDC,CAMkEA,QANlEA,EAM4EE,SAN5EF,EAMuFC,WANvFD,CAAAA,GAMsGI,eANtGJ,CAMsHA,QANtHA,EAMgIE,SANhIF,CAAAA;KAOjGO,OALIN,CAAAA,CAAAA,EAAAA,CAAAA,CAAAA,GAAAA,CAKaO,CALbP,CAAAA,SAAAA,CAKyBQ,CALzBR,CAAAA,GAAAA,CAAAA,CAKgCQ,CALhCR,CAAAA,SAAAA,CAK4CO,CAL5CP,CAAAA,GAAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,KAAAA;AAAgBC,UAMRQ,OANQR,CAAAA,cAMcS,MANdT,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,gBAAAA,OAAAA,EAAAA,aAAAA,OAAAA,CAAAA,CAAAA;cAAoBA,CAAAA,EAO1BU,WAP0BV;;YAS/BU;EARTR;EAAe,KAAA,CAAA,EAURN,SAVQ;;QACqBE,EAW7BO,OAX6BP,CAWrBa,UAXqBb,EAAAA,OAAAA,CAAAA,SAAAA,IAAAA,GAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,GAAAA,IAAAA,GAW0Ca,UAX1Cb;;;;;AAEzC;;;;;;;;;;;;;;;aA6BeO,QAAQO,qEAAqEA;EA5BvFP;EAAO,MAAA,EA8BAQ,WA9BA;;AAAsBN,UAgCjBO,uBAhCiBP;;oBAkCdE,MAlCiCH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAkCXG,MAlCWH,CAAAA,MAAAA,EAAAA,GAAAA;;CACrD,SAmCUZ,cAnCc,CAmCCgB,WAnCD,CAAA,EAmCeK,OAnCf,CAmCuBP,OAnCvB,CAmC+BE,WAnC/B,EAAA,OAAA,EAAA,OAAA,CAAA,CAAA,CAAA"}
@@ -1,49 +0,0 @@
1
- import { BaseStore } from "@langchain/langgraph-checkpoint";
2
- import { RunnableConfig, RunnableInterface } from "@langchain/core/runnables";
3
-
4
- //#region src/pregel/runnable_types.d.ts
5
- type RunnableFunc$1<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = (input: RunInput,
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- options: CallOptions) => RunOutput | Promise<RunOutput>;
8
- type RunnableMapLike<RunInput, RunOutput> = { [K in keyof RunOutput]: RunnableLike$1<RunInput, RunOutput[K]> };
9
- type RunnableLike$1<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc$1<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>;
10
- type IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
11
- interface Runtime<ContextType = Record<string, unknown>, InterruptType = unknown, WriterType = unknown> {
12
- configurable?: ContextType;
13
- /** User provided context */
14
- context?: ContextType;
15
- /** Persistent key-value store */
16
- store?: BaseStore;
17
- /** Callback to send custom data chunks via the `custom` stream mode */
18
- writer: IsEqual<WriterType, unknown> extends true ? (chunk: unknown) => void : WriterType;
19
- /**
20
- * Interrupts the execution of a graph node.
21
- *
22
- * This function can be used to pause execution of a node, and return the value of the `resume`
23
- * input when the graph is re-invoked using `Command`.
24
- * Multiple interrupts can be called within a single node, and each will be handled sequentially.
25
- *
26
- * When an interrupt is called:
27
- * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.
28
- * 2. Otherwise, it throws a `GraphInterrupt` with the provided value
29
- * 3. The graph can be resumed by passing a `Command` with a `resume` value
30
- *
31
- * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,
32
- * you should avoid using `try/catch` blocks around the `interrupt` function,
33
- * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.
34
- *
35
- * @param value - The value to include in the interrupt.
36
- * @returns The `resume` value provided when the graph is re-invoked with a Command.
37
- */
38
- interrupt: IsEqual<InterruptType, unknown> extends true ? (value: unknown) => unknown : InterruptType;
39
- /** Abort signal to cancel the run. */
40
- signal: AbortSignal;
41
- }
42
- interface LangGraphRunnableConfig<
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- ContextType extends Record<string, any> = Record<string, any>
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- > extends RunnableConfig<ContextType>, Partial<Runtime<ContextType, unknown, unknown>> {}
47
- //#endregion
48
- export { LangGraphRunnableConfig, RunnableLike$1 as RunnableLike, Runtime };
49
- //# sourceMappingURL=runnable_types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runnable_types.d.ts","names":["RunnableConfig","RunnableInterface","BaseStore","RunnableFunc","RunInput","CallOptions","RunOutput","Promise","RunnableMapLike","K","RunnableLike","IsEqual","T","U","Runtime","Record","ContextType","WriterType","InterruptType","AbortSignal","LangGraphRunnableConfig","Partial"],"sources":["../../src/pregel/runnable_types.d.ts"],"sourcesContent":["import { RunnableConfig, RunnableInterface } from \"@langchain/core/runnables\";\nimport { BaseStore } from \"@langchain/langgraph-checkpoint\";\ntype RunnableFunc<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = (input: RunInput, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\noptions: CallOptions) => RunOutput | Promise<RunOutput>;\ntype RunnableMapLike<RunInput, RunOutput> = {\n [K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;\n};\nexport type RunnableLike<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>;\ntype IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;\nexport interface Runtime<ContextType = Record<string, unknown>, InterruptType = unknown, WriterType = unknown> {\n configurable?: ContextType;\n /** User provided context */\n context?: ContextType;\n /** Persistent key-value store */\n store?: BaseStore;\n /** Callback to send custom data chunks via the `custom` stream mode */\n writer: IsEqual<WriterType, unknown> extends true ? (chunk: unknown) => void : WriterType;\n /**\n * Interrupts the execution of a graph node.\n *\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt.\n * @returns The `resume` value provided when the graph is re-invoked with a Command.\n */\n interrupt: IsEqual<InterruptType, unknown> extends true ? (value: unknown) => unknown : InterruptType;\n /** Abort signal to cancel the run. */\n signal: AbortSignal;\n}\nexport interface LangGraphRunnableConfig<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nContextType extends Record<string, any> = Record<string, any>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n> extends RunnableConfig<ContextType>, Partial<Runtime<ContextType, unknown, unknown>> {\n}\nexport {};\n"],"mappings":";;;;KAEKG,wDAAsDH,iBAAiBA,0BAA0BI;;AAD1C,OACvDD,EAEIE,WAFJF,EAAY,GAEQG,SAFR,GAEoBC,OAFpB,CAE4BD,SAF5B,CAAA;KAGZE,eAHY,CAAA,QAAA,EAAA,SAAA,CAAA,GAAA,QAA0CR,MAI3CM,SAJ2CN,GAI/BU,cAJ+BV,CAIlBI,QAJkBJ,EAIRM,SAJQN,CAIES,CAJFT,CAAAA,CAAAA;AAA2CI,KAM1FM,cAN0FN,CAAAA,QAAAA,EAAAA,SAAAA,EAAAA,oBAMpCJ,cANoCI,GAMnBJ,cANmBI,CAAAA,GAMDH,iBANCG,CAMiBA,QANjBA,EAM2BE,SAN3BF,EAMsCC,WANtCD,CAAAA,GAMqDD,cANrDC,CAMkEA,QANlEA,EAM4EE,SAN5EF,EAMuFC,WANvFD,CAAAA,GAMsGI,eANtGJ,CAMsHA,QANtHA,EAMgIE,SANhIF,CAAAA;KAOjGO,OALIN,CAAAA,CAAAA,EAAAA,CAAAA,CAAAA,GAAAA,CAKaO,CALbP,CAAAA,SAAAA,CAKyBQ,CALzBR,CAAAA,GAAAA,CAAAA,CAKgCQ,CALhCR,CAAAA,SAAAA,CAK4CO,CAL5CP,CAAAA,GAAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,KAAAA;AAAgBC,UAMRQ,OANQR,CAAAA,cAMcS,MANdT,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,gBAAAA,OAAAA,EAAAA,aAAAA,OAAAA,CAAAA,CAAAA;cAAoBA,CAAAA,EAO1BU,WAP0BV;;YAS/BU;EARTR;EAAe,KAAA,CAAA,EAURN,SAVQ;;QACqBE,EAW7BO,OAX6BP,CAWrBa,UAXqBb,EAAAA,OAAAA,CAAAA,SAAAA,IAAAA,GAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,GAAAA,IAAAA,GAW0Ca,UAX1Cb;;;;;AAEzC;;;;;;;;;;;;;;;aA6BeO,QAAQO,qEAAqEA;EA5BvFP;EAAO,MAAA,EA8BAQ,WA9BA;;AAAsBN,UAgCjBO,uBAhCiBP;;oBAkCdE,MAlCiCH,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAkCXG,MAlCWH,CAAAA,MAAAA,EAAAA,GAAAA;;CACrD,SAmCUZ,cAnCc,CAmCCgB,WAnCD,CAAA,EAmCeK,OAnCf,CAmCuBP,OAnCvB,CAmC+BE,WAnC/B,EAAA,OAAA,EAAA,OAAA,CAAA,CAAA,CAAA"}
@@ -1,228 +0,0 @@
1
- const require_errors = require('../errors.cjs');
2
- const require_constants = require('../constants.cjs');
3
- const require_types = require('./types.cjs');
4
- const require_index = require('./utils/index.cjs');
5
- const require_retry = require('./retry.cjs');
6
-
7
- //#region src/pregel/runner.ts
8
- const PROMISE_ADDED_SYMBOL = Symbol.for("promiseAdded");
9
- function createPromiseBarrier() {
10
- const barrier = {
11
- next: () => void 0,
12
- wait: Promise.resolve(PROMISE_ADDED_SYMBOL)
13
- };
14
- function waitHandler(resolve) {
15
- barrier.next = () => {
16
- barrier.wait = new Promise(waitHandler);
17
- resolve(PROMISE_ADDED_SYMBOL);
18
- };
19
- }
20
- barrier.wait = new Promise(waitHandler);
21
- return barrier;
22
- }
23
- /**
24
- * Responsible for handling task execution on each tick of the {@link PregelLoop}.
25
- */
26
- var PregelRunner = class {
27
- nodeFinished;
28
- loop;
29
- /**
30
- * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.
31
- * @param loop - The PregelLoop that produces tasks for this runner to execute.
32
- */
33
- constructor({ loop, nodeFinished }) {
34
- this.loop = loop;
35
- this.nodeFinished = nodeFinished;
36
- }
37
- /**
38
- * Execute tasks from the current step of the PregelLoop.
39
- *
40
- * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.
41
- * @param options - Options for the execution.
42
- */
43
- async tick(options = {}) {
44
- const { timeout, retryPolicy, onStepWrite, maxConcurrency } = options;
45
- const nodeErrors = /* @__PURE__ */ new Set();
46
- let graphBubbleUp;
47
- const exceptionSignalController = new AbortController();
48
- const exceptionSignal = exceptionSignalController.signal;
49
- const stepTimeoutSignal = timeout ? AbortSignal.timeout(timeout) : void 0;
50
- const pendingTasks = Object.values(this.loop.tasks).filter((t) => t.writes.length === 0);
51
- const { signals, disposeCombinedSignal } = this._initializeAbortSignals({
52
- exceptionSignal,
53
- stepTimeoutSignal,
54
- signal: options.signal
55
- });
56
- const taskStream = this._executeTasksWithRetry(pendingTasks, {
57
- signals,
58
- retryPolicy,
59
- maxConcurrency
60
- });
61
- for await (const { task, error, signalAborted } of taskStream) {
62
- this._commit(task, error);
63
- if (require_errors.isGraphInterrupt(error)) graphBubbleUp = error;
64
- else if (require_errors.isGraphBubbleUp(error) && !require_errors.isGraphInterrupt(graphBubbleUp)) graphBubbleUp = error;
65
- else if (error && (nodeErrors.size === 0 || !signalAborted)) {
66
- exceptionSignalController.abort();
67
- nodeErrors.add(error);
68
- }
69
- }
70
- disposeCombinedSignal?.();
71
- onStepWrite?.(this.loop.step, Object.values(this.loop.tasks).map((task) => task.writes).flat());
72
- if (nodeErrors.size === 1) throw Array.from(nodeErrors)[0];
73
- else if (nodeErrors.size > 1) throw new AggregateError(Array.from(nodeErrors), `Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);
74
- if (require_errors.isGraphInterrupt(graphBubbleUp)) throw graphBubbleUp;
75
- if (require_errors.isGraphBubbleUp(graphBubbleUp) && this.loop.isNested) throw graphBubbleUp;
76
- }
77
- /**
78
- * Initializes the current AbortSignals for the PregelRunner, handling the various ways that
79
- * AbortSignals must be chained together so that the PregelLoop can be interrupted if necessary
80
- * while still allowing nodes to gracefully exit.
81
- *
82
- * This method must only be called once per PregelRunner#tick. It has the side effect of updating
83
- * the PregelLoop#config with the new AbortSignals so they may be propagated correctly to future
84
- * ticks and subgraph calls.
85
- *
86
- * @param options - Options for the initialization.
87
- * @returns The current abort signals.
88
- * @internal
89
- */
90
- _initializeAbortSignals({ exceptionSignal, stepTimeoutSignal, signal }) {
91
- const previousSignals = this.loop.config.configurable?.[require_constants.CONFIG_KEY_ABORT_SIGNALS] ?? {};
92
- const externalAbortSignal = previousSignals.externalAbortSignal ?? signal;
93
- const timeoutAbortSignal = stepTimeoutSignal ?? previousSignals.timeoutAbortSignal;
94
- const { signal: composedAbortSignal, dispose: disposeCombinedSignal } = require_index.combineAbortSignals(externalAbortSignal, timeoutAbortSignal, exceptionSignal);
95
- const signals = {
96
- externalAbortSignal,
97
- timeoutAbortSignal,
98
- composedAbortSignal
99
- };
100
- this.loop.config = require_index.patchConfigurable(this.loop.config, { [require_constants.CONFIG_KEY_ABORT_SIGNALS]: signals });
101
- return {
102
- signals,
103
- disposeCombinedSignal
104
- };
105
- }
106
- /**
107
- * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.
108
- * @param tasks - The tasks to execute.
109
- * @param options - Options for the execution.
110
- */
111
- async *_executeTasksWithRetry(tasks, options) {
112
- const { retryPolicy, maxConcurrency, signals } = options ?? {};
113
- const barrier = createPromiseBarrier();
114
- const executingTasksMap = {};
115
- const thisCall = {
116
- executingTasksMap,
117
- barrier,
118
- retryPolicy,
119
- scheduleTask: async (task, writeIdx, call$1) => this.loop.acceptPush(task, writeIdx, call$1)
120
- };
121
- if (signals?.composedAbortSignal?.aborted) throw new Error("Abort");
122
- let startedTasksCount = 0;
123
- let listener;
124
- const timeoutOrCancelSignal = require_index.combineAbortSignals(signals?.externalAbortSignal, signals?.timeoutAbortSignal);
125
- const abortPromise = timeoutOrCancelSignal.signal ? new Promise((_resolve, reject) => {
126
- listener = () => reject(/* @__PURE__ */ new Error("Abort"));
127
- timeoutOrCancelSignal.signal?.addEventListener("abort", listener, { once: true });
128
- }) : void 0;
129
- while ((startedTasksCount === 0 || Object.keys(executingTasksMap).length > 0) && tasks.length) {
130
- for (; Object.values(executingTasksMap).length < (maxConcurrency ?? tasks.length) && startedTasksCount < tasks.length; startedTasksCount += 1) {
131
- const task = tasks[startedTasksCount];
132
- executingTasksMap[task.id] = require_retry._runWithRetry(task, retryPolicy, { [require_constants.CONFIG_KEY_CALL]: call?.bind(thisCall, this, task) }, signals?.composedAbortSignal).catch((error) => {
133
- return {
134
- task,
135
- error,
136
- signalAborted: signals?.composedAbortSignal?.aborted
137
- };
138
- });
139
- }
140
- const settledTask = await Promise.race([
141
- ...Object.values(executingTasksMap),
142
- ...abortPromise ? [abortPromise] : [],
143
- barrier.wait
144
- ]);
145
- if (settledTask === PROMISE_ADDED_SYMBOL) continue;
146
- yield settledTask;
147
- if (listener != null) {
148
- timeoutOrCancelSignal.signal?.removeEventListener("abort", listener);
149
- timeoutOrCancelSignal.dispose?.();
150
- }
151
- delete executingTasksMap[settledTask.task.id];
152
- }
153
- }
154
- /**
155
- * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.
156
- *
157
- * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.
158
- *
159
- * @param task - The task to commit.
160
- * @param error - The error that occurred, if any.
161
- */
162
- _commit(task, error) {
163
- if (error !== void 0) if (require_errors.isGraphInterrupt(error)) {
164
- if (error.interrupts.length) {
165
- const interrupts = error.interrupts.map((interrupt) => [require_constants.INTERRUPT, interrupt]);
166
- const resumes = task.writes.filter((w) => w[0] === require_constants.RESUME);
167
- if (resumes.length) interrupts.push(...resumes);
168
- this.loop.putWrites(task.id, interrupts);
169
- }
170
- } else if (require_errors.isGraphBubbleUp(error) && task.writes.length) this.loop.putWrites(task.id, task.writes);
171
- else this.loop.putWrites(task.id, [[require_constants.ERROR, {
172
- message: error.message,
173
- name: error.name
174
- }]]);
175
- else {
176
- if (this.nodeFinished && (task.config?.tags == null || !task.config.tags.includes(require_constants.TAG_HIDDEN))) this.nodeFinished(String(task.name));
177
- if (task.writes.length === 0) task.writes.push([require_constants.NO_WRITES, null]);
178
- this.loop.putWrites(task.id, task.writes);
179
- }
180
- }
181
- };
182
- async function call(runner, task, func, name, input, options = {}) {
183
- const scratchpad = task.config?.configurable?.[require_constants.CONFIG_KEY_SCRATCHPAD];
184
- if (!scratchpad) throw new Error(`BUG: No scratchpad found on task ${task.name}__${task.id}`);
185
- const cnt = scratchpad.callCounter;
186
- scratchpad.callCounter += 1;
187
- const wcall = new require_types.Call({
188
- func,
189
- name,
190
- input,
191
- cache: options.cache,
192
- retry: options.retry,
193
- callbacks: options.callbacks
194
- });
195
- const nextTask = await this.scheduleTask(task, cnt, wcall);
196
- if (!nextTask) return void 0;
197
- const existingPromise = this.executingTasksMap[nextTask.id];
198
- if (existingPromise !== void 0) return existingPromise;
199
- if (nextTask.writes.length > 0) {
200
- const returns = nextTask.writes.filter(([c]) => c === require_constants.RETURN);
201
- const errors = nextTask.writes.filter(([c]) => c === require_constants.ERROR);
202
- if (returns.length > 0) {
203
- if (returns.length === 1) return Promise.resolve(returns[0][1]);
204
- throw new Error(`BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`);
205
- }
206
- if (errors.length > 0) {
207
- if (errors.length === 1) {
208
- const errorValue = errors[0][1];
209
- const error = errorValue instanceof Error ? errorValue : new Error(String(errorValue));
210
- return Promise.reject(error);
211
- }
212
- throw new Error(`BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`);
213
- }
214
- return void 0;
215
- } else {
216
- const prom = require_retry._runWithRetry(nextTask, options.retry, { [require_constants.CONFIG_KEY_CALL]: call.bind(this, runner, nextTask) });
217
- this.executingTasksMap[nextTask.id] = prom;
218
- this.barrier.next();
219
- return prom.then(({ result, error }) => {
220
- if (error) return Promise.reject(error);
221
- return result;
222
- });
223
- }
224
- }
225
-
226
- //#endregion
227
- exports.PregelRunner = PregelRunner;
228
- //# sourceMappingURL=runner.cjs.map