@langchain/langgraph 1.4.15 → 1.4.17

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 (60) hide show
  1. package/dist/callbacks.cjs +29 -0
  2. package/dist/callbacks.cjs.map +1 -0
  3. package/dist/callbacks.d.cts +46 -0
  4. package/dist/callbacks.d.cts.map +1 -0
  5. package/dist/callbacks.d.ts +46 -0
  6. package/dist/callbacks.d.ts.map +1 -0
  7. package/dist/callbacks.js +29 -0
  8. package/dist/callbacks.js.map +1 -0
  9. package/dist/constants.cjs.map +1 -1
  10. package/dist/constants.d.cts +6 -0
  11. package/dist/constants.d.cts.map +1 -1
  12. package/dist/constants.d.ts +6 -0
  13. package/dist/constants.d.ts.map +1 -1
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.cjs +2 -0
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +3 -2
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +2 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/interrupt.cjs +19 -7
  22. package/dist/interrupt.cjs.map +1 -1
  23. package/dist/interrupt.d.cts +20 -3
  24. package/dist/interrupt.d.cts.map +1 -1
  25. package/dist/interrupt.d.ts +20 -3
  26. package/dist/interrupt.d.ts.map +1 -1
  27. package/dist/interrupt.js +19 -7
  28. package/dist/interrupt.js.map +1 -1
  29. package/dist/pregel/callbacks.cjs +25 -0
  30. package/dist/pregel/callbacks.cjs.map +1 -0
  31. package/dist/pregel/callbacks.js +25 -0
  32. package/dist/pregel/callbacks.js.map +1 -0
  33. package/dist/pregel/index.cjs +8 -2
  34. package/dist/pregel/index.cjs.map +1 -1
  35. package/dist/pregel/index.d.cts.map +1 -1
  36. package/dist/pregel/index.d.ts.map +1 -1
  37. package/dist/pregel/index.js +8 -2
  38. package/dist/pregel/index.js.map +1 -1
  39. package/dist/pregel/loop.cjs +18 -1
  40. package/dist/pregel/loop.cjs.map +1 -1
  41. package/dist/pregel/loop.js +18 -1
  42. package/dist/pregel/loop.js.map +1 -1
  43. package/dist/pregel/messages-v2.cjs +1 -1
  44. package/dist/pregel/messages-v2.js +1 -1
  45. package/dist/pregel/messages.cjs +1 -1
  46. package/dist/pregel/messages.js +1 -1
  47. package/dist/pregel/runner.cjs +1 -1
  48. package/dist/pregel/runner.cjs.map +1 -1
  49. package/dist/pregel/runner.js +2 -2
  50. package/dist/pregel/runner.js.map +1 -1
  51. package/dist/pregel/stream.cjs +1 -1
  52. package/dist/pregel/stream.d.cts +1 -0
  53. package/dist/pregel/stream.d.cts.map +1 -1
  54. package/dist/pregel/stream.d.ts +1 -1
  55. package/dist/pregel/stream.js +1 -1
  56. package/dist/web.cjs +2 -0
  57. package/dist/web.d.cts +3 -2
  58. package/dist/web.d.ts +3 -2
  59. package/dist/web.js +2 -1
  60. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"runner.cjs","names":["isGraphInterrupt","isGraphBubbleUp","isGraphDrained","combineAbortSignals","patchConfigurable","CONFIG_KEY_ABORT_SIGNALS","_runWithRetry","CONFIG_KEY_CALL","INTERRUPT","RESUME","ERROR","ERROR_SOURCE_NODE","NO_WRITES","CONFIG_KEY_SCRATCHPAD","Call","RETURN"],"sources":["../../src/pregel/runner.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n Call,\n PregelAbortSignals,\n PregelExecutableTask,\n PregelScratchpad,\n} from \"./types.js\";\nimport {\n CachePolicy,\n combineAbortSignals,\n patchConfigurable,\n RetryPolicy,\n TimeoutPolicy,\n} from \"./utils/index.js\";\nimport {\n CONFIG_KEY_SCRATCHPAD,\n ERROR,\n ERROR_SOURCE_NODE,\n INTERRUPT,\n RESUME,\n NO_WRITES,\n TAG_HIDDEN,\n RETURN,\n CONFIG_KEY_CALL,\n CONFIG_KEY_ABORT_SIGNALS,\n} from \"../constants.js\";\nimport {\n GraphBubbleUp,\n isGraphBubbleUp,\n isGraphDrained,\n isGraphInterrupt,\n} from \"../errors.js\";\nimport { _runWithRetry, SettledPregelTask } from \"./retry.js\";\nimport { PregelLoop } from \"./loop.js\";\n\nconst PROMISE_ADDED_SYMBOL = Symbol.for(\"promiseAdded\");\n\nfunction createPromiseBarrier() {\n const barrier: {\n next: () => void;\n wait: Promise<unknown>;\n } = {\n next: () => void 0,\n wait: Promise.resolve(PROMISE_ADDED_SYMBOL),\n };\n\n function waitHandler(resolve: (value: typeof PROMISE_ADDED_SYMBOL) => void) {\n barrier.next = () => {\n barrier.wait = new Promise(waitHandler);\n resolve(PROMISE_ADDED_SYMBOL);\n };\n }\n barrier.wait = new Promise(waitHandler);\n return barrier;\n}\n\n/**\n * Options for the {@link PregelRunner#tick} method.\n */\nexport type TickOptions = {\n /**\n * The deadline before which all tasks must be completed.\n */\n timeout?: number;\n\n /**\n * An optional {@link AbortSignal} to cancel processing of tasks.\n */\n signal?: AbortSignal;\n\n /**\n * The {@link RetryPolicy} to use for the tick.\n */\n retryPolicy?: RetryPolicy;\n\n /**\n * An optional callback to be called after all task writes are completed.\n */\n onStepWrite?: (step: number, writes: PendingWrite[]) => void;\n\n /**\n * The maximum number of tasks to execute concurrently.\n */\n maxConcurrency?: number;\n};\n\n/**\n * Responsible for handling task execution on each tick of the {@link PregelLoop}.\n */\nexport class PregelRunner {\n private nodeFinished?: (id: string) => void;\n\n private loop: PregelLoop;\n\n /**\n * Exceptions already routed to a node-level error handler. Consulted when\n * deciding whether a failed task should abort the run.\n */\n private handledExceptions = new WeakSet<Error>();\n\n /**\n * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.\n * @param loop - The PregelLoop that produces tasks for this runner to execute.\n */\n constructor({\n loop,\n nodeFinished,\n }: {\n loop: PregelLoop;\n nodeFinished?: (id: string) => void;\n }) {\n this.loop = loop;\n this.nodeFinished = nodeFinished;\n }\n\n /**\n * Execute tasks from the current step of the PregelLoop.\n *\n * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.\n * @param options - Options for the execution.\n */\n async tick(options: TickOptions = {}) {\n const { timeout, retryPolicy, onStepWrite, maxConcurrency } = options;\n\n const nodeErrors: Set<Error> = new Set();\n let graphBubbleUp: GraphBubbleUp | undefined;\n\n const exceptionSignalController = new AbortController();\n const exceptionSignal = exceptionSignalController.signal;\n const stepTimeoutSignal = timeout\n ? AbortSignal.timeout(timeout)\n : undefined;\n\n const allTasks = Object.values(this.loop.tasks);\n const pendingTasks = allTasks.filter((t) => t.writes.length === 0);\n\n const { signals, disposeCombinedSignal } = this._initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal: options.signal,\n });\n\n const taskStream = this._executeTasksWithRetry(pendingTasks, {\n signals,\n retryPolicy,\n maxConcurrency,\n });\n\n for await (const { task, error, signalAborted } of taskStream) {\n this._commit(task, error);\n if (error !== undefined && this.handledExceptions.has(error)) {\n // Routed to a node-level error handler in this tick; provenance is\n // checkpointed and the error must not abort the run.\n continue;\n }\n if (isGraphInterrupt(error)) {\n graphBubbleUp = error;\n } else if (isGraphBubbleUp(error) && !isGraphInterrupt(graphBubbleUp)) {\n graphBubbleUp = error;\n } else if (error && (nodeErrors.size === 0 || !signalAborted)) {\n /*\n * The goal here is to capture the exception that causes the graph to terminate early. In\n * theory it's possible for multiple nodes to throw, so this also handles the edge case of\n * capturing concurrent exceptions thrown before the node saw an abort. This is checked via\n * the signalAborted flag, which records the state of the abort signal at the time the node\n * execution finished.\n *\n * There is a case however where one node throws some error causing us to trigger an abort,\n * which then causes other concurrently executing nodes to throw their own AbortErrors. In\n * this case we don't care about reporting the abort errors thrown by the other nodes,\n * because they don't tell the user anything about what caused the graph execution to\n * terminate early, so we ignore them (and any other errors that occur after the node sees\n * an abort signal).\n */\n exceptionSignalController.abort();\n nodeErrors.add(error);\n }\n }\n\n disposeCombinedSignal?.();\n\n onStepWrite?.(this.loop.step, allTasks.map((task) => task.writes).flat());\n\n if (nodeErrors.size === 1) {\n throw Array.from(nodeErrors)[0];\n } else if (nodeErrors.size > 1) {\n throw new AggregateError(\n Array.from(nodeErrors),\n `Multiple errors occurred during superstep ${this.loop.step}. See the \"errors\" field of this exception for more details.`\n );\n }\n\n if (isGraphInterrupt(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n // A cooperative drain raised by a subgraph bubbles up through the parent\n // loop (even when the parent is the top graph) so the parent stops at this\n // boundary and its checkpoint can be resumed later.\n if (isGraphDrained(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n if (isGraphBubbleUp(graphBubbleUp) && this.loop.isNested) {\n throw graphBubbleUp;\n }\n }\n\n /**\n * Initializes the current AbortSignals for the PregelRunner, handling the various ways that\n * AbortSignals must be chained together so that the PregelLoop can be interrupted if necessary\n * while still allowing nodes to gracefully exit.\n *\n * This method must only be called once per PregelRunner#tick. It has the side effect of updating\n * the PregelLoop#config with the new AbortSignals so they may be propagated correctly to future\n * ticks and subgraph calls.\n *\n * @param options - Options for the initialization.\n * @returns The current abort signals.\n * @internal\n */\n private _initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal,\n }: {\n exceptionSignal: AbortSignal;\n stepTimeoutSignal?: AbortSignal;\n signal?: AbortSignal;\n }): { signals: PregelAbortSignals; disposeCombinedSignal?: () => void } {\n const previousSignals = (this.loop.config.configurable?.[\n CONFIG_KEY_ABORT_SIGNALS\n ] ?? {}) as PregelAbortSignals;\n\n // We always inherit the external abort signal from AsyncLocalStorage,\n // since that's the only way the signal is inherited by the subgraph calls.\n const externalAbortSignal = previousSignals.externalAbortSignal ?? signal;\n\n // inherit the step timeout signal from parent graph\n const timeoutAbortSignal =\n stepTimeoutSignal ?? previousSignals.timeoutAbortSignal;\n\n const { signal: composedAbortSignal, dispose: disposeCombinedSignal } =\n combineAbortSignals(\n externalAbortSignal,\n timeoutAbortSignal,\n exceptionSignal\n );\n\n const signals: PregelAbortSignals = {\n externalAbortSignal,\n timeoutAbortSignal,\n composedAbortSignal,\n };\n\n this.loop.config = patchConfigurable(this.loop.config, {\n [CONFIG_KEY_ABORT_SIGNALS]: signals,\n });\n\n return { signals, disposeCombinedSignal };\n }\n\n /**\n * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.\n * @param tasks - The tasks to execute.\n * @param options - Options for the execution.\n */\n private async *_executeTasksWithRetry(\n tasks: PregelExecutableTask<string, string>[],\n options?: {\n signals?: PregelAbortSignals;\n retryPolicy?: RetryPolicy;\n maxConcurrency?: number;\n }\n ): AsyncGenerator<SettledPregelTask> {\n const { retryPolicy, maxConcurrency, signals } = options ?? {};\n\n const barrier = createPromiseBarrier();\n const executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n > = {};\n\n const thisCall = {\n executingTasksMap,\n barrier,\n retryPolicy,\n scheduleTask: async (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => this.loop.acceptPush(task, writeIdx, call),\n };\n\n if (signals?.composedAbortSignal?.aborted) {\n // note: don't use throwIfAborted here because it throws a DOMException,\n // which isn't consistent with how we throw on abort below.\n throw new Error(\"Abort\");\n }\n\n let startedTasksCount = 0;\n\n let listener: (() => void) | undefined;\n const timeoutOrCancelSignal = combineAbortSignals(\n signals?.externalAbortSignal,\n signals?.timeoutAbortSignal\n );\n\n const abortPromise = timeoutOrCancelSignal.signal\n ? new Promise<never>((_resolve, reject) => {\n listener = () => reject(new Error(\"Abort\"));\n timeoutOrCancelSignal.signal?.addEventListener(\"abort\", listener, {\n once: true,\n });\n })\n : undefined;\n\n while (\n (startedTasksCount === 0 || Object.keys(executingTasksMap).length > 0) &&\n tasks.length\n ) {\n for (\n ;\n Object.values(executingTasksMap).length <\n (maxConcurrency ?? tasks.length) && startedTasksCount < tasks.length;\n startedTasksCount += 1\n ) {\n const task = tasks[startedTasksCount];\n\n executingTasksMap[task.id] = _runWithRetry(\n task,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, task) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n }\n\n const settledTask = await Promise.race([\n ...Object.values(executingTasksMap),\n ...(abortPromise ? [abortPromise] : []),\n barrier.wait,\n ]);\n\n if (settledTask === PROMISE_ADDED_SYMBOL) {\n continue;\n }\n\n const settled = settledTask as SettledPregelTask;\n const { task: settledPregelTask, error: settledError } = settled;\n\n // If the task failed (after exhausting its retry policy) and the node has\n // a registered error handler, schedule that handler to run within this\n // same tick instead of aborting the run. GraphBubbleUp errors (e.g.\n // interrupts / parent commands) are never routed to error handlers.\n if (\n settledError !== undefined &&\n !isGraphBubbleUp(settledError) &&\n !this.loop.isErrorHandlerNode(String(settledPregelTask.name)) &&\n this.loop.getErrorHandlerNode(String(settledPregelTask.name)) !==\n undefined\n ) {\n const handlerTask = this.loop.scheduleErrorHandler(\n settledPregelTask,\n settledError\n );\n if (handlerTask !== undefined) {\n executingTasksMap[handlerTask.id] = _runWithRetry(\n handlerTask,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, handlerTask) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task: handlerTask,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n barrier.next();\n }\n }\n\n yield settled;\n\n if (listener != null) {\n timeoutOrCancelSignal.signal?.removeEventListener(\"abort\", listener);\n timeoutOrCancelSignal.dispose?.();\n }\n\n delete executingTasksMap[(settledTask as SettledPregelTask).task.id];\n }\n }\n\n /**\n * Whether a failed task should record {@link ERROR_SOURCE_NODE} provenance.\n */\n private _shouldRouteToErrorHandler(\n task: PregelExecutableTask<string, string>\n ): boolean {\n const name = String(task.name);\n if (this.loop.isErrorHandlerNode(name)) {\n return false;\n }\n return this.loop.getErrorHandlerNode(name) !== undefined;\n }\n\n /**\n * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.\n *\n * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.\n *\n * @param task - The task to commit.\n * @param error - The error that occurred, if any.\n */\n private _commit(task: PregelExecutableTask<string, string>, error?: Error) {\n if (error !== undefined) {\n if (isGraphInterrupt(error)) {\n if (error.interrupts.length) {\n const interrupts: PendingWrite<string>[] = error.interrupts.map(\n (interrupt) => [INTERRUPT, interrupt]\n );\n const resumes = task.writes.filter((w) => w[0] === RESUME);\n if (resumes.length) {\n interrupts.push(...resumes);\n }\n this.loop.putWrites(task.id, interrupts);\n }\n } else if (isGraphDrained(error)) {\n // Cooperative drain bubbled up from a subgraph. Leave the task\n // uncommitted (unless it already produced writes) so it is\n // re-executed when the parent run resumes.\n if (task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n }\n } else if (isGraphBubbleUp(error) && task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n } else {\n task.writes.push([ERROR, { message: error.message, name: error.name }]);\n if (this._shouldRouteToErrorHandler(task)) {\n task.writes.push([ERROR_SOURCE_NODE, String(task.name)]);\n this.handledExceptions.add(error);\n }\n this.loop.putWrites(task.id, task.writes);\n }\n } else {\n if (\n this.nodeFinished &&\n (task.config?.tags == null || !task.config.tags.includes(TAG_HIDDEN))\n ) {\n this.nodeFinished(String(task.name));\n }\n\n if (task.writes.length === 0) {\n // Add no writes marker\n task.writes.push([NO_WRITES, null]);\n }\n\n // Save task writes to checkpointer\n this.loop.putWrites(task.id, task.writes);\n }\n }\n}\n\nasync function call(\n this: {\n executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n >;\n\n barrier: {\n next: () => void;\n wait: Promise<unknown>;\n };\n\n retryPolicy?: RetryPolicy;\n\n scheduleTask: (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => Promise<PregelExecutableTask<string, string> | void>;\n },\n runner: PregelRunner,\n task: PregelExecutableTask<string, string>,\n func: (...args: unknown[]) => unknown | Promise<unknown>,\n name: string,\n input: unknown,\n options: {\n retry?: RetryPolicy;\n cache?: CachePolicy;\n timeout?: TimeoutPolicy;\n callbacks?: unknown;\n } = {}\n): Promise<unknown> {\n // Schedule PUSH tasks, collect promises\n const scratchpad = task.config?.configurable?.[CONFIG_KEY_SCRATCHPAD] as\n | PregelScratchpad<unknown>\n | undefined;\n\n if (!scratchpad) {\n throw new Error(\n `BUG: No scratchpad found on task ${task.name}__${task.id}`\n );\n }\n\n const cnt = scratchpad.callCounter;\n scratchpad.callCounter += 1;\n\n // schedule the next task, if the callback returns one\n const wcall = new Call({\n func,\n name,\n input,\n cache: options.cache,\n retry: options.retry,\n timeout: options.timeout,\n callbacks: options.callbacks,\n });\n const nextTask = await this.scheduleTask(task, cnt, wcall);\n if (!nextTask) return undefined;\n\n // Check if this task is already running\n const existingPromise = this.executingTasksMap[nextTask.id];\n\n if (existingPromise !== undefined) {\n // If the parent task was retried, the next task might already be running\n return existingPromise;\n }\n\n if (nextTask.writes.length > 0) {\n // If it already ran, return the result\n const returns = nextTask.writes.filter(([c]) => c === RETURN);\n const errors = nextTask.writes.filter(([c]) => c === ERROR);\n\n if (returns.length > 0) {\n // Task completed successfully\n if (returns.length === 1) return Promise.resolve(returns[0][1]);\n\n // should be unreachable\n throw new Error(\n `BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n if (errors.length > 0) {\n // Task failed\n if (errors.length === 1) {\n const errorValue = errors[0][1];\n const error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n errorValue instanceof Error\n ? errorValue\n : new Error(String(errorValue));\n\n return Promise.reject(error);\n }\n\n // the only way this should happen is if the task executes multiple times and writes aren't cleared\n throw new Error(\n `BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n return undefined;\n } else {\n // Schedule the next task with retry\n const prom = _runWithRetry<string, string>(nextTask, options.retry, {\n [CONFIG_KEY_CALL]: call.bind(this, runner, nextTask),\n });\n\n this.executingTasksMap[nextTask.id] = prom;\n this.barrier.next();\n\n return prom.then(({ result, error }) => {\n if (error) return Promise.re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,OAAI,QAAQ,WAAW,EAAG,QAAO,QAAQ,QAAQ,QAAQ,GAAG,GAAG;AAG/D,SAAM,IAAI,MACR,wCAAwC,SAAS,KAAK,IAAI,SAAS,KACpE;;AAGH,MAAI,OAAO,SAAS,GAAG;AAErB,OAAI,OAAO,WAAW,GAAG;IACvB,MAAM,aAAa,OAAO,GAAG;IAC7B,MAAM,QAEJ,sBAAsB,QAClB,aACA,IAAI,MAAM,OAAO,WAAW,CAAC;AAEnC,WAAO,QAAQ,OAAO,MAAM;;AAI9B,SAAM,IAAI,MACR,uCAAuC,SAAS,KAAK,IAAI,SAAS,KACnE;;AAGH;QACK;EAEL,MAAM,OAAOJ,cAAAA,cAA8B,UAAU,QAAQ,OAAO,GACjEC,kBAAAA,kBAAkB,KAAK,KAAK,MAAM,QAAQ,SAAS,EACrD,CAAC;AAEF,OAAK,kBAAkB,SAAS,MAAM;AACtC,OAAK,QAAQ,MAAM;AAEnB,SAAO,KAAK,MAAM,EAAE,QAAQ,YAAY;AACtC,OAAI,MAAO,QAAO,QAAQ,OAAO,MAAM;AACvC,UAAO;IACP"}
1
+ {"version":3,"file":"runner.cjs","names":["isGraphInterrupt","GraphInterrupt","isGraphBubbleUp","isGraphDrained","combineAbortSignals","patchConfigurable","CONFIG_KEY_ABORT_SIGNALS","_runWithRetry","CONFIG_KEY_CALL","INTERRUPT","RESUME","ERROR","ERROR_SOURCE_NODE","NO_WRITES","CONFIG_KEY_SCRATCHPAD","Call","RETURN"],"sources":["../../src/pregel/runner.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n Call,\n PregelAbortSignals,\n PregelExecutableTask,\n PregelScratchpad,\n} from \"./types.js\";\nimport {\n CachePolicy,\n combineAbortSignals,\n patchConfigurable,\n RetryPolicy,\n TimeoutPolicy,\n} from \"./utils/index.js\";\nimport {\n CONFIG_KEY_SCRATCHPAD,\n ERROR,\n ERROR_SOURCE_NODE,\n INTERRUPT,\n RESUME,\n NO_WRITES,\n TAG_HIDDEN,\n RETURN,\n CONFIG_KEY_CALL,\n CONFIG_KEY_ABORT_SIGNALS,\n} from \"../constants.js\";\nimport {\n GraphBubbleUp,\n GraphInterrupt,\n isGraphBubbleUp,\n isGraphDrained,\n isGraphInterrupt,\n} from \"../errors.js\";\nimport { _runWithRetry, SettledPregelTask } from \"./retry.js\";\nimport { PregelLoop } from \"./loop.js\";\n\nconst PROMISE_ADDED_SYMBOL = Symbol.for(\"promiseAdded\");\n\nfunction createPromiseBarrier() {\n const barrier: {\n next: () => void;\n wait: Promise<unknown>;\n } = {\n next: () => void 0,\n wait: Promise.resolve(PROMISE_ADDED_SYMBOL),\n };\n\n function waitHandler(resolve: (value: typeof PROMISE_ADDED_SYMBOL) => void) {\n barrier.next = () => {\n barrier.wait = new Promise(waitHandler);\n resolve(PROMISE_ADDED_SYMBOL);\n };\n }\n barrier.wait = new Promise(waitHandler);\n return barrier;\n}\n\n/**\n * Options for the {@link PregelRunner#tick} method.\n */\nexport type TickOptions = {\n /**\n * The deadline before which all tasks must be completed.\n */\n timeout?: number;\n\n /**\n * An optional {@link AbortSignal} to cancel processing of tasks.\n */\n signal?: AbortSignal;\n\n /**\n * The {@link RetryPolicy} to use for the tick.\n */\n retryPolicy?: RetryPolicy;\n\n /**\n * An optional callback to be called after all task writes are completed.\n */\n onStepWrite?: (step: number, writes: PendingWrite[]) => void;\n\n /**\n * The maximum number of tasks to execute concurrently.\n */\n maxConcurrency?: number;\n};\n\n/**\n * Responsible for handling task execution on each tick of the {@link PregelLoop}.\n */\nexport class PregelRunner {\n private nodeFinished?: (id: string) => void;\n\n private loop: PregelLoop;\n\n /**\n * Exceptions already routed to a node-level error handler. Consulted when\n * deciding whether a failed task should abort the run.\n */\n private handledExceptions = new WeakSet<Error>();\n\n /**\n * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.\n * @param loop - The PregelLoop that produces tasks for this runner to execute.\n */\n constructor({\n loop,\n nodeFinished,\n }: {\n loop: PregelLoop;\n nodeFinished?: (id: string) => void;\n }) {\n this.loop = loop;\n this.nodeFinished = nodeFinished;\n }\n\n /**\n * Execute tasks from the current step of the PregelLoop.\n *\n * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.\n * @param options - Options for the execution.\n */\n async tick(options: TickOptions = {}) {\n const { timeout, retryPolicy, onStepWrite, maxConcurrency } = options;\n\n const nodeErrors: Set<Error> = new Set();\n let graphBubbleUp: GraphBubbleUp | undefined;\n\n const exceptionSignalController = new AbortController();\n const exceptionSignal = exceptionSignalController.signal;\n const stepTimeoutSignal = timeout\n ? AbortSignal.timeout(timeout)\n : undefined;\n\n const allTasks = Object.values(this.loop.tasks);\n const pendingTasks = allTasks.filter((t) => t.writes.length === 0);\n\n const { signals, disposeCombinedSignal } = this._initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal: options.signal,\n });\n\n const taskStream = this._executeTasksWithRetry(pendingTasks, {\n signals,\n retryPolicy,\n maxConcurrency,\n });\n\n for await (const { task, error, signalAborted } of taskStream) {\n this._commit(task, error);\n if (error !== undefined && this.handledExceptions.has(error)) {\n // Routed to a node-level error handler in this tick; provenance is\n // checkpointed and the error must not abort the run.\n continue;\n }\n if (isGraphInterrupt(error)) {\n graphBubbleUp = isGraphInterrupt(graphBubbleUp)\n ? new GraphInterrupt([\n ...graphBubbleUp.interrupts,\n ...error.interrupts,\n ])\n : error;\n } else if (isGraphBubbleUp(error) && !isGraphInterrupt(graphBubbleUp)) {\n graphBubbleUp = error;\n } else if (error && (nodeErrors.size === 0 || !signalAborted)) {\n /*\n * The goal here is to capture the exception that causes the graph to terminate early. In\n * theory it's possible for multiple nodes to throw, so this also handles the edge case of\n * capturing concurrent exceptions thrown before the node saw an abort. This is checked via\n * the signalAborted flag, which records the state of the abort signal at the time the node\n * execution finished.\n *\n * There is a case however where one node throws some error causing us to trigger an abort,\n * which then causes other concurrently executing nodes to throw their own AbortErrors. In\n * this case we don't care about reporting the abort errors thrown by the other nodes,\n * because they don't tell the user anything about what caused the graph execution to\n * terminate early, so we ignore them (and any other errors that occur after the node sees\n * an abort signal).\n */\n exceptionSignalController.abort();\n nodeErrors.add(error);\n }\n }\n\n disposeCombinedSignal?.();\n\n onStepWrite?.(this.loop.step, allTasks.map((task) => task.writes).flat());\n\n if (nodeErrors.size === 1) {\n throw Array.from(nodeErrors)[0];\n } else if (nodeErrors.size > 1) {\n throw new AggregateError(\n Array.from(nodeErrors),\n `Multiple errors occurred during superstep ${this.loop.step}. See the \"errors\" field of this exception for more details.`\n );\n }\n\n if (isGraphInterrupt(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n // A cooperative drain raised by a subgraph bubbles up through the parent\n // loop (even when the parent is the top graph) so the parent stops at this\n // boundary and its checkpoint can be resumed later.\n if (isGraphDrained(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n if (isGraphBubbleUp(graphBubbleUp) && this.loop.isNested) {\n throw graphBubbleUp;\n }\n }\n\n /**\n * Initializes the current AbortSignals for the PregelRunner, handling the various ways that\n * AbortSignals must be chained together so that the PregelLoop can be interrupted if necessary\n * while still allowing nodes to gracefully exit.\n *\n * This method must only be called once per PregelRunner#tick. It has the side effect of updating\n * the PregelLoop#config with the new AbortSignals so they may be propagated correctly to future\n * ticks and subgraph calls.\n *\n * @param options - Options for the initialization.\n * @returns The current abort signals.\n * @internal\n */\n private _initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal,\n }: {\n exceptionSignal: AbortSignal;\n stepTimeoutSignal?: AbortSignal;\n signal?: AbortSignal;\n }): { signals: PregelAbortSignals; disposeCombinedSignal?: () => void } {\n const previousSignals = (this.loop.config.configurable?.[\n CONFIG_KEY_ABORT_SIGNALS\n ] ?? {}) as PregelAbortSignals;\n\n // We always inherit the external abort signal from AsyncLocalStorage,\n // since that's the only way the signal is inherited by the subgraph calls.\n const externalAbortSignal = previousSignals.externalAbortSignal ?? signal;\n\n // inherit the step timeout signal from parent graph\n const timeoutAbortSignal =\n stepTimeoutSignal ?? previousSignals.timeoutAbortSignal;\n\n const { signal: composedAbortSignal, dispose: disposeCombinedSignal } =\n combineAbortSignals(\n externalAbortSignal,\n timeoutAbortSignal,\n exceptionSignal\n );\n\n const signals: PregelAbortSignals = {\n externalAbortSignal,\n timeoutAbortSignal,\n composedAbortSignal,\n };\n\n this.loop.config = patchConfigurable(this.loop.config, {\n [CONFIG_KEY_ABORT_SIGNALS]: signals,\n });\n\n return { signals, disposeCombinedSignal };\n }\n\n /**\n * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.\n * @param tasks - The tasks to execute.\n * @param options - Options for the execution.\n */\n private async *_executeTasksWithRetry(\n tasks: PregelExecutableTask<string, string>[],\n options?: {\n signals?: PregelAbortSignals;\n retryPolicy?: RetryPolicy;\n maxConcurrency?: number;\n }\n ): AsyncGenerator<SettledPregelTask> {\n const { retryPolicy, maxConcurrency, signals } = options ?? {};\n\n const barrier = createPromiseBarrier();\n const executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n > = {};\n\n const thisCall = {\n executingTasksMap,\n barrier,\n retryPolicy,\n scheduleTask: async (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => this.loop.acceptPush(task, writeIdx, call),\n };\n\n if (signals?.composedAbortSignal?.aborted) {\n // note: don't use throwIfAborted here because it throws a DOMException,\n // which isn't consistent with how we throw on abort below.\n throw new Error(\"Abort\");\n }\n\n let startedTasksCount = 0;\n\n let listener: (() => void) | undefined;\n const timeoutOrCancelSignal = combineAbortSignals(\n signals?.externalAbortSignal,\n signals?.timeoutAbortSignal\n );\n\n const abortPromise = timeoutOrCancelSignal.signal\n ? new Promise<never>((_resolve, reject) => {\n listener = () => reject(new Error(\"Abort\"));\n timeoutOrCancelSignal.signal?.addEventListener(\"abort\", listener, {\n once: true,\n });\n })\n : undefined;\n\n while (\n (startedTasksCount === 0 || Object.keys(executingTasksMap).length > 0) &&\n tasks.length\n ) {\n for (\n ;\n Object.values(executingTasksMap).length <\n (maxConcurrency ?? tasks.length) && startedTasksCount < tasks.length;\n startedTasksCount += 1\n ) {\n const task = tasks[startedTasksCount];\n\n executingTasksMap[task.id] = _runWithRetry(\n task,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, task) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n }\n\n const settledTask = await Promise.race([\n ...Object.values(executingTasksMap),\n ...(abortPromise ? [abortPromise] : []),\n barrier.wait,\n ]);\n\n if (settledTask === PROMISE_ADDED_SYMBOL) {\n continue;\n }\n\n const settled = settledTask as SettledPregelTask;\n const { task: settledPregelTask, error: settledError } = settled;\n\n // If the task failed (after exhausting its retry policy) and the node has\n // a registered error handler, schedule that handler to run within this\n // same tick instead of aborting the run. GraphBubbleUp errors (e.g.\n // interrupts / parent commands) are never routed to error handlers.\n if (\n settledError !== undefined &&\n !isGraphBubbleUp(settledError) &&\n !this.loop.isErrorHandlerNode(String(settledPregelTask.name)) &&\n this.loop.getErrorHandlerNode(String(settledPregelTask.name)) !==\n undefined\n ) {\n const handlerTask = this.loop.scheduleErrorHandler(\n settledPregelTask,\n settledError\n );\n if (handlerTask !== undefined) {\n executingTasksMap[handlerTask.id] = _runWithRetry(\n handlerTask,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, handlerTask) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task: handlerTask,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n barrier.next();\n }\n }\n\n yield settled;\n\n if (listener != null) {\n timeoutOrCancelSignal.signal?.removeEventListener(\"abort\", listener);\n timeoutOrCancelSignal.dispose?.();\n }\n\n delete executingTasksMap[(settledTask as SettledPregelTask).task.id];\n }\n }\n\n /**\n * Whether a failed task should record {@link ERROR_SOURCE_NODE} provenance.\n */\n private _shouldRouteToErrorHandler(\n task: PregelExecutableTask<string, string>\n ): boolean {\n const name = String(task.name);\n if (this.loop.isErrorHandlerNode(name)) {\n return false;\n }\n return this.loop.getErrorHandlerNode(name) !== undefined;\n }\n\n /**\n * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.\n *\n * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.\n *\n * @param task - The task to commit.\n * @param error - The error that occurred, if any.\n */\n private _commit(task: PregelExecutableTask<string, string>, error?: Error) {\n if (error !== undefined) {\n if (isGraphInterrupt(error)) {\n if (error.interrupts.length) {\n const interrupts: PendingWrite<string>[] = error.interrupts.map(\n (interrupt) => [INTERRUPT, interrupt]\n );\n const resumes = task.writes.filter((w) => w[0] === RESUME);\n if (resumes.length) {\n interrupts.push(...resumes);\n }\n this.loop.putWrites(task.id, interrupts);\n }\n } else if (isGraphDrained(error)) {\n // Cooperative drain bubbled up from a subgraph. Leave the task\n // uncommitted (unless it already produced writes) so it is\n // re-executed when the parent run resumes.\n if (task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n }\n } else if (isGraphBubbleUp(error) && task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n } else {\n task.writes.push([ERROR, { message: error.message, name: error.name }]);\n if (this._shouldRouteToErrorHandler(task)) {\n task.writes.push([ERROR_SOURCE_NODE, String(task.name)]);\n this.handledExceptions.add(error);\n }\n this.loop.putWrites(task.id, task.writes);\n }\n } else {\n if (\n this.nodeFinished &&\n (task.config?.tags == null || !task.config.tags.includes(TAG_HIDDEN))\n ) {\n this.nodeFinished(String(task.name));\n }\n\n if (task.writes.length === 0) {\n // Add no writes marker\n task.writes.push([NO_WRITES, null]);\n }\n\n // Save task writes to checkpointer\n this.loop.putWrites(task.id, task.writes);\n }\n }\n}\n\nasync function call(\n this: {\n executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n >;\n\n barrier: {\n next: () => void;\n wait: Promise<unknown>;\n };\n\n retryPolicy?: RetryPolicy;\n\n scheduleTask: (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => Promise<PregelExecutableTask<string, string> | void>;\n },\n runner: PregelRunner,\n task: PregelExecutableTask<string, string>,\n func: (...args: unknown[]) => unknown | Promise<unknown>,\n name: string,\n input: unknown,\n options: {\n retry?: RetryPolicy;\n cache?: CachePolicy;\n timeout?: TimeoutPolicy;\n callbacks?: unknown;\n } = {}\n): Promise<unknown> {\n // Schedule PUSH tasks, collect promises\n const scratchpad = task.config?.configurable?.[CONFIG_KEY_SCRATCHPAD] as\n | PregelScratchpad<unknown>\n | undefined;\n\n if (!scratchpad) {\n throw new Error(\n `BUG: No scratchpad found on task ${task.name}__${task.id}`\n );\n }\n\n const cnt = scratchpad.callCounter;\n scratchpad.callCounter += 1;\n\n // schedule the next task, if the callback returns one\n const wcall = new Call({\n func,\n name,\n input,\n cache: options.cache,\n retry: options.retry,\n timeout: options.timeout,\n callbacks: options.callbacks,\n });\n const nextTask = await this.scheduleTask(task, cnt, wcall);\n if (!nextTask) return undefined;\n\n // Check if this task is already running\n const existingPromise = this.executingTasksMap[nextTask.id];\n\n if (existingPromise !== undefined) {\n // If the parent task was retried, the next task might already be running\n return existingPromise;\n }\n\n if (nextTask.writes.length > 0) {\n // If it already ran, return the result\n const returns = nextTask.writes.filter(([c]) => c === RETURN);\n const errors = nextTask.writes.filter(([c]) => c === ERROR);\n\n if (returns.length > 0) {\n // Task completed successfully\n if (returns.length === 1) return Promise.resolve(returns[0][1]);\n\n // should be unreachable\n throw new Error(\n `BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n if (errors.length > 0) {\n // Task failed\n if (errors.length === 1) {\n const errorValue = errors[0][1];\n const error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n errorValue instanceof Error\n ? errorValue\n : new Error(String(errorValue));\n\n return Promise.reject(error);\n }\n\n // the only way this should happen is if the task executes multiple times and writes aren't cleared\n throw new Error(\n `BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n return undefined;\n } else {\n // Schedule the next task with retry\n const prom = _runWithRetry<string, string>(nextTask, options.retry, {\n [CONFIG_KEY_CALL]: call.bind(this, runner, nextTask),\n });\n\n this.executingTasksMap[nextTask.id] = prom;\n this.barrier.next();\n\n return prom.then(({ result, error }) => {\n if (error) return Promise.reject(error);\n return result;\n });\n }\n}\n"],"mappings":";;;;;;AAoCA,MAAM,uBAAuB,OAAO,IAAI,eAAe;AAEvD,SAAS,uBAAuB;CAC9B,MAAM,UAGF;EACF,YAAY,KAAK;EACjB,MAAM,QAAQ,QAAQ,qBAAqB;EAC5C;CAED,SAAS,YAAY,SAAuD;AAC1E,UAAQ,aAAa;AACnB,WAAQ,OAAO,IAAI,QAAQ,YAAY;AACvC,WAAQ,qBAAqB;;;AAGjC,SAAQ,OAAO,IAAI,QAAQ,YAAY;AACvC,QAAO;;;;;AAoCT,IAAa,eAAb,MAA0B;CACxB;CAEA;;;;;CAMA,oCAA4B,IAAI,SAAgB;;;;;CAMhD,YAAY,EACV,MACA,gBAIC;AACD,OAAK,OAAO;AACZ,OAAK,eAAe;;;;;;;;CAStB,MAAM,KAAK,UAAuB,EAAE,EAAE;EACpC,MAAM,EAAE,SAAS,aAAa,aAAa,mBAAmB;EAE9D,MAAM,6BAAyB,IAAI,KAAK;EACxC,IAAI;EAEJ,MAAM,4BAA4B,IAAI,iBAAiB;EACvD,MAAM,kBAAkB,0BAA0B;EAClD,MAAM,oBAAoB,UACtB,YAAY,QAAQ,QAAQ,GAC5B,KAAA;EAEJ,MAAM,WAAW,OAAO,OAAO,KAAK,KAAK,MAAM;EAC/C,MAAM,eAAe,SAAS,QAAQ,MAAM,EAAE,OAAO,WAAW,EAAE;EAElE,MAAM,EAAE,SAAS,0BAA0B,KAAK,wBAAwB;GACtE;GACA;GACA,QAAQ,QAAQ;GACjB,CAAC;EAEF,MAAM,aAAa,KAAK,uBAAuB,cAAc;GAC3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"../errors.js";
2
+ import { GraphInterrupt, isGraphBubbleUp, isGraphDrained, isGraphInterrupt } from "../errors.js";
3
3
  import { Call } from "./types.js";
4
4
  import { combineAbortSignals, patchConfigurable } from "./utils/index.js";
5
5
  import { _runWithRetry } from "./retry.js";
@@ -66,7 +66,7 @@ var PregelRunner = class {
66
66
  for await (const { task, error, signalAborted } of taskStream) {
67
67
  this._commit(task, error);
68
68
  if (error !== void 0 && this.handledExceptions.has(error)) continue;
69
- if (isGraphInterrupt(error)) graphBubbleUp = error;
69
+ if (isGraphInterrupt(error)) graphBubbleUp = isGraphInterrupt(graphBubbleUp) ? new GraphInterrupt([...graphBubbleUp.interrupts, ...error.interrupts]) : error;
70
70
  else if (isGraphBubbleUp(error) && !isGraphInterrupt(graphBubbleUp)) graphBubbleUp = error;
71
71
  else if (error && (nodeErrors.size === 0 || !signalAborted)) {
72
72
  exceptionSignalController.abort();
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","names":[],"sources":["../../src/pregel/runner.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n Call,\n PregelAbortSignals,\n PregelExecutableTask,\n PregelScratchpad,\n} from \"./types.js\";\nimport {\n CachePolicy,\n combineAbortSignals,\n patchConfigurable,\n RetryPolicy,\n TimeoutPolicy,\n} from \"./utils/index.js\";\nimport {\n CONFIG_KEY_SCRATCHPAD,\n ERROR,\n ERROR_SOURCE_NODE,\n INTERRUPT,\n RESUME,\n NO_WRITES,\n TAG_HIDDEN,\n RETURN,\n CONFIG_KEY_CALL,\n CONFIG_KEY_ABORT_SIGNALS,\n} from \"../constants.js\";\nimport {\n GraphBubbleUp,\n isGraphBubbleUp,\n isGraphDrained,\n isGraphInterrupt,\n} from \"../errors.js\";\nimport { _runWithRetry, SettledPregelTask } from \"./retry.js\";\nimport { PregelLoop } from \"./loop.js\";\n\nconst PROMISE_ADDED_SYMBOL = Symbol.for(\"promiseAdded\");\n\nfunction createPromiseBarrier() {\n const barrier: {\n next: () => void;\n wait: Promise<unknown>;\n } = {\n next: () => void 0,\n wait: Promise.resolve(PROMISE_ADDED_SYMBOL),\n };\n\n function waitHandler(resolve: (value: typeof PROMISE_ADDED_SYMBOL) => void) {\n barrier.next = () => {\n barrier.wait = new Promise(waitHandler);\n resolve(PROMISE_ADDED_SYMBOL);\n };\n }\n barrier.wait = new Promise(waitHandler);\n return barrier;\n}\n\n/**\n * Options for the {@link PregelRunner#tick} method.\n */\nexport type TickOptions = {\n /**\n * The deadline before which all tasks must be completed.\n */\n timeout?: number;\n\n /**\n * An optional {@link AbortSignal} to cancel processing of tasks.\n */\n signal?: AbortSignal;\n\n /**\n * The {@link RetryPolicy} to use for the tick.\n */\n retryPolicy?: RetryPolicy;\n\n /**\n * An optional callback to be called after all task writes are completed.\n */\n onStepWrite?: (step: number, writes: PendingWrite[]) => void;\n\n /**\n * The maximum number of tasks to execute concurrently.\n */\n maxConcurrency?: number;\n};\n\n/**\n * Responsible for handling task execution on each tick of the {@link PregelLoop}.\n */\nexport class PregelRunner {\n private nodeFinished?: (id: string) => void;\n\n private loop: PregelLoop;\n\n /**\n * Exceptions already routed to a node-level error handler. Consulted when\n * deciding whether a failed task should abort the run.\n */\n private handledExceptions = new WeakSet<Error>();\n\n /**\n * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.\n * @param loop - The PregelLoop that produces tasks for this runner to execute.\n */\n constructor({\n loop,\n nodeFinished,\n }: {\n loop: PregelLoop;\n nodeFinished?: (id: string) => void;\n }) {\n this.loop = loop;\n this.nodeFinished = nodeFinished;\n }\n\n /**\n * Execute tasks from the current step of the PregelLoop.\n *\n * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.\n * @param options - Options for the execution.\n */\n async tick(options: TickOptions = {}) {\n const { timeout, retryPolicy, onStepWrite, maxConcurrency } = options;\n\n const nodeErrors: Set<Error> = new Set();\n let graphBubbleUp: GraphBubbleUp | undefined;\n\n const exceptionSignalController = new AbortController();\n const exceptionSignal = exceptionSignalController.signal;\n const stepTimeoutSignal = timeout\n ? AbortSignal.timeout(timeout)\n : undefined;\n\n const allTasks = Object.values(this.loop.tasks);\n const pendingTasks = allTasks.filter((t) => t.writes.length === 0);\n\n const { signals, disposeCombinedSignal } = this._initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal: options.signal,\n });\n\n const taskStream = this._executeTasksWithRetry(pendingTasks, {\n signals,\n retryPolicy,\n maxConcurrency,\n });\n\n for await (const { task, error, signalAborted } of taskStream) {\n this._commit(task, error);\n if (error !== undefined && this.handledExceptions.has(error)) {\n // Routed to a node-level error handler in this tick; provenance is\n // checkpointed and the error must not abort the run.\n continue;\n }\n if (isGraphInterrupt(error)) {\n graphBubbleUp = error;\n } else if (isGraphBubbleUp(error) && !isGraphInterrupt(graphBubbleUp)) {\n graphBubbleUp = error;\n } else if (error && (nodeErrors.size === 0 || !signalAborted)) {\n /*\n * The goal here is to capture the exception that causes the graph to terminate early. In\n * theory it's possible for multiple nodes to throw, so this also handles the edge case of\n * capturing concurrent exceptions thrown before the node saw an abort. This is checked via\n * the signalAborted flag, which records the state of the abort signal at the time the node\n * execution finished.\n *\n * There is a case however where one node throws some error causing us to trigger an abort,\n * which then causes other concurrently executing nodes to throw their own AbortErrors. In\n * this case we don't care about reporting the abort errors thrown by the other nodes,\n * because they don't tell the user anything about what caused the graph execution to\n * terminate early, so we ignore them (and any other errors that occur after the node sees\n * an abort signal).\n */\n exceptionSignalController.abort();\n nodeErrors.add(error);\n }\n }\n\n disposeCombinedSignal?.();\n\n onStepWrite?.(this.loop.step, allTasks.map((task) => task.writes).flat());\n\n if (nodeErrors.size === 1) {\n throw Array.from(nodeErrors)[0];\n } else if (nodeErrors.size > 1) {\n throw new AggregateError(\n Array.from(nodeErrors),\n `Multiple errors occurred during superstep ${this.loop.step}. See the \"errors\" field of this exception for more details.`\n );\n }\n\n if (isGraphInterrupt(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n // A cooperative drain raised by a subgraph bubbles up through the parent\n // loop (even when the parent is the top graph) so the parent stops at this\n // boundary and its checkpoint can be resumed later.\n if (isGraphDrained(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n if (isGraphBubbleUp(graphBubbleUp) && this.loop.isNested) {\n throw graphBubbleUp;\n }\n }\n\n /**\n * Initializes the current AbortSignals for the PregelRunner, handling the various ways that\n * AbortSignals must be chained together so that the PregelLoop can be interrupted if necessary\n * while still allowing nodes to gracefully exit.\n *\n * This method must only be called once per PregelRunner#tick. It has the side effect of updating\n * the PregelLoop#config with the new AbortSignals so they may be propagated correctly to future\n * ticks and subgraph calls.\n *\n * @param options - Options for the initialization.\n * @returns The current abort signals.\n * @internal\n */\n private _initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal,\n }: {\n exceptionSignal: AbortSignal;\n stepTimeoutSignal?: AbortSignal;\n signal?: AbortSignal;\n }): { signals: PregelAbortSignals; disposeCombinedSignal?: () => void } {\n const previousSignals = (this.loop.config.configurable?.[\n CONFIG_KEY_ABORT_SIGNALS\n ] ?? {}) as PregelAbortSignals;\n\n // We always inherit the external abort signal from AsyncLocalStorage,\n // since that's the only way the signal is inherited by the subgraph calls.\n const externalAbortSignal = previousSignals.externalAbortSignal ?? signal;\n\n // inherit the step timeout signal from parent graph\n const timeoutAbortSignal =\n stepTimeoutSignal ?? previousSignals.timeoutAbortSignal;\n\n const { signal: composedAbortSignal, dispose: disposeCombinedSignal } =\n combineAbortSignals(\n externalAbortSignal,\n timeoutAbortSignal,\n exceptionSignal\n );\n\n const signals: PregelAbortSignals = {\n externalAbortSignal,\n timeoutAbortSignal,\n composedAbortSignal,\n };\n\n this.loop.config = patchConfigurable(this.loop.config, {\n [CONFIG_KEY_ABORT_SIGNALS]: signals,\n });\n\n return { signals, disposeCombinedSignal };\n }\n\n /**\n * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.\n * @param tasks - The tasks to execute.\n * @param options - Options for the execution.\n */\n private async *_executeTasksWithRetry(\n tasks: PregelExecutableTask<string, string>[],\n options?: {\n signals?: PregelAbortSignals;\n retryPolicy?: RetryPolicy;\n maxConcurrency?: number;\n }\n ): AsyncGenerator<SettledPregelTask> {\n const { retryPolicy, maxConcurrency, signals } = options ?? {};\n\n const barrier = createPromiseBarrier();\n const executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n > = {};\n\n const thisCall = {\n executingTasksMap,\n barrier,\n retryPolicy,\n scheduleTask: async (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => this.loop.acceptPush(task, writeIdx, call),\n };\n\n if (signals?.composedAbortSignal?.aborted) {\n // note: don't use throwIfAborted here because it throws a DOMException,\n // which isn't consistent with how we throw on abort below.\n throw new Error(\"Abort\");\n }\n\n let startedTasksCount = 0;\n\n let listener: (() => void) | undefined;\n const timeoutOrCancelSignal = combineAbortSignals(\n signals?.externalAbortSignal,\n signals?.timeoutAbortSignal\n );\n\n const abortPromise = timeoutOrCancelSignal.signal\n ? new Promise<never>((_resolve, reject) => {\n listener = () => reject(new Error(\"Abort\"));\n timeoutOrCancelSignal.signal?.addEventListener(\"abort\", listener, {\n once: true,\n });\n })\n : undefined;\n\n while (\n (startedTasksCount === 0 || Object.keys(executingTasksMap).length > 0) &&\n tasks.length\n ) {\n for (\n ;\n Object.values(executingTasksMap).length <\n (maxConcurrency ?? tasks.length) && startedTasksCount < tasks.length;\n startedTasksCount += 1\n ) {\n const task = tasks[startedTasksCount];\n\n executingTasksMap[task.id] = _runWithRetry(\n task,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, task) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n }\n\n const settledTask = await Promise.race([\n ...Object.values(executingTasksMap),\n ...(abortPromise ? [abortPromise] : []),\n barrier.wait,\n ]);\n\n if (settledTask === PROMISE_ADDED_SYMBOL) {\n continue;\n }\n\n const settled = settledTask as SettledPregelTask;\n const { task: settledPregelTask, error: settledError } = settled;\n\n // If the task failed (after exhausting its retry policy) and the node has\n // a registered error handler, schedule that handler to run within this\n // same tick instead of aborting the run. GraphBubbleUp errors (e.g.\n // interrupts / parent commands) are never routed to error handlers.\n if (\n settledError !== undefined &&\n !isGraphBubbleUp(settledError) &&\n !this.loop.isErrorHandlerNode(String(settledPregelTask.name)) &&\n this.loop.getErrorHandlerNode(String(settledPregelTask.name)) !==\n undefined\n ) {\n const handlerTask = this.loop.scheduleErrorHandler(\n settledPregelTask,\n settledError\n );\n if (handlerTask !== undefined) {\n executingTasksMap[handlerTask.id] = _runWithRetry(\n handlerTask,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, handlerTask) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task: handlerTask,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n barrier.next();\n }\n }\n\n yield settled;\n\n if (listener != null) {\n timeoutOrCancelSignal.signal?.removeEventListener(\"abort\", listener);\n timeoutOrCancelSignal.dispose?.();\n }\n\n delete executingTasksMap[(settledTask as SettledPregelTask).task.id];\n }\n }\n\n /**\n * Whether a failed task should record {@link ERROR_SOURCE_NODE} provenance.\n */\n private _shouldRouteToErrorHandler(\n task: PregelExecutableTask<string, string>\n ): boolean {\n const name = String(task.name);\n if (this.loop.isErrorHandlerNode(name)) {\n return false;\n }\n return this.loop.getErrorHandlerNode(name) !== undefined;\n }\n\n /**\n * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.\n *\n * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.\n *\n * @param task - The task to commit.\n * @param error - The error that occurred, if any.\n */\n private _commit(task: PregelExecutableTask<string, string>, error?: Error) {\n if (error !== undefined) {\n if (isGraphInterrupt(error)) {\n if (error.interrupts.length) {\n const interrupts: PendingWrite<string>[] = error.interrupts.map(\n (interrupt) => [INTERRUPT, interrupt]\n );\n const resumes = task.writes.filter((w) => w[0] === RESUME);\n if (resumes.length) {\n interrupts.push(...resumes);\n }\n this.loop.putWrites(task.id, interrupts);\n }\n } else if (isGraphDrained(error)) {\n // Cooperative drain bubbled up from a subgraph. Leave the task\n // uncommitted (unless it already produced writes) so it is\n // re-executed when the parent run resumes.\n if (task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n }\n } else if (isGraphBubbleUp(error) && task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n } else {\n task.writes.push([ERROR, { message: error.message, name: error.name }]);\n if (this._shouldRouteToErrorHandler(task)) {\n task.writes.push([ERROR_SOURCE_NODE, String(task.name)]);\n this.handledExceptions.add(error);\n }\n this.loop.putWrites(task.id, task.writes);\n }\n } else {\n if (\n this.nodeFinished &&\n (task.config?.tags == null || !task.config.tags.includes(TAG_HIDDEN))\n ) {\n this.nodeFinished(String(task.name));\n }\n\n if (task.writes.length === 0) {\n // Add no writes marker\n task.writes.push([NO_WRITES, null]);\n }\n\n // Save task writes to checkpointer\n this.loop.putWrites(task.id, task.writes);\n }\n }\n}\n\nasync function call(\n this: {\n executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n >;\n\n barrier: {\n next: () => void;\n wait: Promise<unknown>;\n };\n\n retryPolicy?: RetryPolicy;\n\n scheduleTask: (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => Promise<PregelExecutableTask<string, string> | void>;\n },\n runner: PregelRunner,\n task: PregelExecutableTask<string, string>,\n func: (...args: unknown[]) => unknown | Promise<unknown>,\n name: string,\n input: unknown,\n options: {\n retry?: RetryPolicy;\n cache?: CachePolicy;\n timeout?: TimeoutPolicy;\n callbacks?: unknown;\n } = {}\n): Promise<unknown> {\n // Schedule PUSH tasks, collect promises\n const scratchpad = task.config?.configurable?.[CONFIG_KEY_SCRATCHPAD] as\n | PregelScratchpad<unknown>\n | undefined;\n\n if (!scratchpad) {\n throw new Error(\n `BUG: No scratchpad found on task ${task.name}__${task.id}`\n );\n }\n\n const cnt = scratchpad.callCounter;\n scratchpad.callCounter += 1;\n\n // schedule the next task, if the callback returns one\n const wcall = new Call({\n func,\n name,\n input,\n cache: options.cache,\n retry: options.retry,\n timeout: options.timeout,\n callbacks: options.callbacks,\n });\n const nextTask = await this.scheduleTask(task, cnt, wcall);\n if (!nextTask) return undefined;\n\n // Check if this task is already running\n const existingPromise = this.executingTasksMap[nextTask.id];\n\n if (existingPromise !== undefined) {\n // If the parent task was retried, the next task might already be running\n return existingPromise;\n }\n\n if (nextTask.writes.length > 0) {\n // If it already ran, return the result\n const returns = nextTask.writes.filter(([c]) => c === RETURN);\n const errors = nextTask.writes.filter(([c]) => c === ERROR);\n\n if (returns.length > 0) {\n // Task completed successfully\n if (returns.length === 1) return Promise.resolve(returns[0][1]);\n\n // should be unreachable\n throw new Error(\n `BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n if (errors.length > 0) {\n // Task failed\n if (errors.length === 1) {\n const errorValue = errors[0][1];\n const error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n errorValue instanceof Error\n ? errorValue\n : new Error(String(errorValue));\n\n return Promise.reject(error);\n }\n\n // the only way this should happen is if the task executes multiple times and writes aren't cleared\n throw new Error(\n `BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n return undefined;\n } else {\n // Schedule the next task with retry\n const prom = _runWithRetry<string, string>(nextTask, options.retry, {\n [CONFIG_KEY_CALL]: call.bind(this, runner, nextTask),\n });\n\n this.executingTasksMap[nextTask.id] = prom;\n this.barrier.next();\n\n return prom.then(({ result, error }) => {\n if (error) return Promise.reject(error);\n return result;\n });\n }\n}\n"],"mappings":";;;;;;AAmCA,MAAM,uBAAuB,OAAO,IAAI,eAAe;AAEvD,SAAS,uBAAuB;CAC9B,MAAM,UAGF;EACF,YAAY,KAAK;EACjB,MAAM,QAAQ,QAAQ,qBAA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AEL,MAAM,OAAO,cAA8B,UAAU,QAAQ,OAAO,GACjE,kBAAkB,KAAK,KAAK,MAAM,QAAQ,SAAS,EACrD,CAAC;AAEF,OAAK,kBAAkB,SAAS,MAAM;AACtC,OAAK,QAAQ,MAAM;AAEnB,SAAO,KAAK,MAAM,EAAE,QAAQ,YAAY;AACtC,OAAI,MAAO,QAAO,QAAQ,OAAO,MAAM;AACvC,UAAO;IACP"}
1
+ {"version":3,"file":"runner.js","names":[],"sources":["../../src/pregel/runner.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n Call,\n PregelAbortSignals,\n PregelExecutableTask,\n PregelScratchpad,\n} from \"./types.js\";\nimport {\n CachePolicy,\n combineAbortSignals,\n patchConfigurable,\n RetryPolicy,\n TimeoutPolicy,\n} from \"./utils/index.js\";\nimport {\n CONFIG_KEY_SCRATCHPAD,\n ERROR,\n ERROR_SOURCE_NODE,\n INTERRUPT,\n RESUME,\n NO_WRITES,\n TAG_HIDDEN,\n RETURN,\n CONFIG_KEY_CALL,\n CONFIG_KEY_ABORT_SIGNALS,\n} from \"../constants.js\";\nimport {\n GraphBubbleUp,\n GraphInterrupt,\n isGraphBubbleUp,\n isGraphDrained,\n isGraphInterrupt,\n} from \"../errors.js\";\nimport { _runWithRetry, SettledPregelTask } from \"./retry.js\";\nimport { PregelLoop } from \"./loop.js\";\n\nconst PROMISE_ADDED_SYMBOL = Symbol.for(\"promiseAdded\");\n\nfunction createPromiseBarrier() {\n const barrier: {\n next: () => void;\n wait: Promise<unknown>;\n } = {\n next: () => void 0,\n wait: Promise.resolve(PROMISE_ADDED_SYMBOL),\n };\n\n function waitHandler(resolve: (value: typeof PROMISE_ADDED_SYMBOL) => void) {\n barrier.next = () => {\n barrier.wait = new Promise(waitHandler);\n resolve(PROMISE_ADDED_SYMBOL);\n };\n }\n barrier.wait = new Promise(waitHandler);\n return barrier;\n}\n\n/**\n * Options for the {@link PregelRunner#tick} method.\n */\nexport type TickOptions = {\n /**\n * The deadline before which all tasks must be completed.\n */\n timeout?: number;\n\n /**\n * An optional {@link AbortSignal} to cancel processing of tasks.\n */\n signal?: AbortSignal;\n\n /**\n * The {@link RetryPolicy} to use for the tick.\n */\n retryPolicy?: RetryPolicy;\n\n /**\n * An optional callback to be called after all task writes are completed.\n */\n onStepWrite?: (step: number, writes: PendingWrite[]) => void;\n\n /**\n * The maximum number of tasks to execute concurrently.\n */\n maxConcurrency?: number;\n};\n\n/**\n * Responsible for handling task execution on each tick of the {@link PregelLoop}.\n */\nexport class PregelRunner {\n private nodeFinished?: (id: string) => void;\n\n private loop: PregelLoop;\n\n /**\n * Exceptions already routed to a node-level error handler. Consulted when\n * deciding whether a failed task should abort the run.\n */\n private handledExceptions = new WeakSet<Error>();\n\n /**\n * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.\n * @param loop - The PregelLoop that produces tasks for this runner to execute.\n */\n constructor({\n loop,\n nodeFinished,\n }: {\n loop: PregelLoop;\n nodeFinished?: (id: string) => void;\n }) {\n this.loop = loop;\n this.nodeFinished = nodeFinished;\n }\n\n /**\n * Execute tasks from the current step of the PregelLoop.\n *\n * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.\n * @param options - Options for the execution.\n */\n async tick(options: TickOptions = {}) {\n const { timeout, retryPolicy, onStepWrite, maxConcurrency } = options;\n\n const nodeErrors: Set<Error> = new Set();\n let graphBubbleUp: GraphBubbleUp | undefined;\n\n const exceptionSignalController = new AbortController();\n const exceptionSignal = exceptionSignalController.signal;\n const stepTimeoutSignal = timeout\n ? AbortSignal.timeout(timeout)\n : undefined;\n\n const allTasks = Object.values(this.loop.tasks);\n const pendingTasks = allTasks.filter((t) => t.writes.length === 0);\n\n const { signals, disposeCombinedSignal } = this._initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal: options.signal,\n });\n\n const taskStream = this._executeTasksWithRetry(pendingTasks, {\n signals,\n retryPolicy,\n maxConcurrency,\n });\n\n for await (const { task, error, signalAborted } of taskStream) {\n this._commit(task, error);\n if (error !== undefined && this.handledExceptions.has(error)) {\n // Routed to a node-level error handler in this tick; provenance is\n // checkpointed and the error must not abort the run.\n continue;\n }\n if (isGraphInterrupt(error)) {\n graphBubbleUp = isGraphInterrupt(graphBubbleUp)\n ? new GraphInterrupt([\n ...graphBubbleUp.interrupts,\n ...error.interrupts,\n ])\n : error;\n } else if (isGraphBubbleUp(error) && !isGraphInterrupt(graphBubbleUp)) {\n graphBubbleUp = error;\n } else if (error && (nodeErrors.size === 0 || !signalAborted)) {\n /*\n * The goal here is to capture the exception that causes the graph to terminate early. In\n * theory it's possible for multiple nodes to throw, so this also handles the edge case of\n * capturing concurrent exceptions thrown before the node saw an abort. This is checked via\n * the signalAborted flag, which records the state of the abort signal at the time the node\n * execution finished.\n *\n * There is a case however where one node throws some error causing us to trigger an abort,\n * which then causes other concurrently executing nodes to throw their own AbortErrors. In\n * this case we don't care about reporting the abort errors thrown by the other nodes,\n * because they don't tell the user anything about what caused the graph execution to\n * terminate early, so we ignore them (and any other errors that occur after the node sees\n * an abort signal).\n */\n exceptionSignalController.abort();\n nodeErrors.add(error);\n }\n }\n\n disposeCombinedSignal?.();\n\n onStepWrite?.(this.loop.step, allTasks.map((task) => task.writes).flat());\n\n if (nodeErrors.size === 1) {\n throw Array.from(nodeErrors)[0];\n } else if (nodeErrors.size > 1) {\n throw new AggregateError(\n Array.from(nodeErrors),\n `Multiple errors occurred during superstep ${this.loop.step}. See the \"errors\" field of this exception for more details.`\n );\n }\n\n if (isGraphInterrupt(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n // A cooperative drain raised by a subgraph bubbles up through the parent\n // loop (even when the parent is the top graph) so the parent stops at this\n // boundary and its checkpoint can be resumed later.\n if (isGraphDrained(graphBubbleUp)) {\n throw graphBubbleUp;\n }\n\n if (isGraphBubbleUp(graphBubbleUp) && this.loop.isNested) {\n throw graphBubbleUp;\n }\n }\n\n /**\n * Initializes the current AbortSignals for the PregelRunner, handling the various ways that\n * AbortSignals must be chained together so that the PregelLoop can be interrupted if necessary\n * while still allowing nodes to gracefully exit.\n *\n * This method must only be called once per PregelRunner#tick. It has the side effect of updating\n * the PregelLoop#config with the new AbortSignals so they may be propagated correctly to future\n * ticks and subgraph calls.\n *\n * @param options - Options for the initialization.\n * @returns The current abort signals.\n * @internal\n */\n private _initializeAbortSignals({\n exceptionSignal,\n stepTimeoutSignal,\n signal,\n }: {\n exceptionSignal: AbortSignal;\n stepTimeoutSignal?: AbortSignal;\n signal?: AbortSignal;\n }): { signals: PregelAbortSignals; disposeCombinedSignal?: () => void } {\n const previousSignals = (this.loop.config.configurable?.[\n CONFIG_KEY_ABORT_SIGNALS\n ] ?? {}) as PregelAbortSignals;\n\n // We always inherit the external abort signal from AsyncLocalStorage,\n // since that's the only way the signal is inherited by the subgraph calls.\n const externalAbortSignal = previousSignals.externalAbortSignal ?? signal;\n\n // inherit the step timeout signal from parent graph\n const timeoutAbortSignal =\n stepTimeoutSignal ?? previousSignals.timeoutAbortSignal;\n\n const { signal: composedAbortSignal, dispose: disposeCombinedSignal } =\n combineAbortSignals(\n externalAbortSignal,\n timeoutAbortSignal,\n exceptionSignal\n );\n\n const signals: PregelAbortSignals = {\n externalAbortSignal,\n timeoutAbortSignal,\n composedAbortSignal,\n };\n\n this.loop.config = patchConfigurable(this.loop.config, {\n [CONFIG_KEY_ABORT_SIGNALS]: signals,\n });\n\n return { signals, disposeCombinedSignal };\n }\n\n /**\n * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.\n * @param tasks - The tasks to execute.\n * @param options - Options for the execution.\n */\n private async *_executeTasksWithRetry(\n tasks: PregelExecutableTask<string, string>[],\n options?: {\n signals?: PregelAbortSignals;\n retryPolicy?: RetryPolicy;\n maxConcurrency?: number;\n }\n ): AsyncGenerator<SettledPregelTask> {\n const { retryPolicy, maxConcurrency, signals } = options ?? {};\n\n const barrier = createPromiseBarrier();\n const executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n > = {};\n\n const thisCall = {\n executingTasksMap,\n barrier,\n retryPolicy,\n scheduleTask: async (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => this.loop.acceptPush(task, writeIdx, call),\n };\n\n if (signals?.composedAbortSignal?.aborted) {\n // note: don't use throwIfAborted here because it throws a DOMException,\n // which isn't consistent with how we throw on abort below.\n throw new Error(\"Abort\");\n }\n\n let startedTasksCount = 0;\n\n let listener: (() => void) | undefined;\n const timeoutOrCancelSignal = combineAbortSignals(\n signals?.externalAbortSignal,\n signals?.timeoutAbortSignal\n );\n\n const abortPromise = timeoutOrCancelSignal.signal\n ? new Promise<never>((_resolve, reject) => {\n listener = () => reject(new Error(\"Abort\"));\n timeoutOrCancelSignal.signal?.addEventListener(\"abort\", listener, {\n once: true,\n });\n })\n : undefined;\n\n while (\n (startedTasksCount === 0 || Object.keys(executingTasksMap).length > 0) &&\n tasks.length\n ) {\n for (\n ;\n Object.values(executingTasksMap).length <\n (maxConcurrency ?? tasks.length) && startedTasksCount < tasks.length;\n startedTasksCount += 1\n ) {\n const task = tasks[startedTasksCount];\n\n executingTasksMap[task.id] = _runWithRetry(\n task,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, task) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n }\n\n const settledTask = await Promise.race([\n ...Object.values(executingTasksMap),\n ...(abortPromise ? [abortPromise] : []),\n barrier.wait,\n ]);\n\n if (settledTask === PROMISE_ADDED_SYMBOL) {\n continue;\n }\n\n const settled = settledTask as SettledPregelTask;\n const { task: settledPregelTask, error: settledError } = settled;\n\n // If the task failed (after exhausting its retry policy) and the node has\n // a registered error handler, schedule that handler to run within this\n // same tick instead of aborting the run. GraphBubbleUp errors (e.g.\n // interrupts / parent commands) are never routed to error handlers.\n if (\n settledError !== undefined &&\n !isGraphBubbleUp(settledError) &&\n !this.loop.isErrorHandlerNode(String(settledPregelTask.name)) &&\n this.loop.getErrorHandlerNode(String(settledPregelTask.name)) !==\n undefined\n ) {\n const handlerTask = this.loop.scheduleErrorHandler(\n settledPregelTask,\n settledError\n );\n if (handlerTask !== undefined) {\n executingTasksMap[handlerTask.id] = _runWithRetry(\n handlerTask,\n retryPolicy,\n { [CONFIG_KEY_CALL]: call?.bind(thisCall, this, handlerTask) },\n signals?.composedAbortSignal\n ).catch((error) => {\n return {\n task: handlerTask,\n error,\n signalAborted: signals?.composedAbortSignal?.aborted,\n };\n });\n barrier.next();\n }\n }\n\n yield settled;\n\n if (listener != null) {\n timeoutOrCancelSignal.signal?.removeEventListener(\"abort\", listener);\n timeoutOrCancelSignal.dispose?.();\n }\n\n delete executingTasksMap[(settledTask as SettledPregelTask).task.id];\n }\n }\n\n /**\n * Whether a failed task should record {@link ERROR_SOURCE_NODE} provenance.\n */\n private _shouldRouteToErrorHandler(\n task: PregelExecutableTask<string, string>\n ): boolean {\n const name = String(task.name);\n if (this.loop.isErrorHandlerNode(name)) {\n return false;\n }\n return this.loop.getErrorHandlerNode(name) !== undefined;\n }\n\n /**\n * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.\n *\n * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.\n *\n * @param task - The task to commit.\n * @param error - The error that occurred, if any.\n */\n private _commit(task: PregelExecutableTask<string, string>, error?: Error) {\n if (error !== undefined) {\n if (isGraphInterrupt(error)) {\n if (error.interrupts.length) {\n const interrupts: PendingWrite<string>[] = error.interrupts.map(\n (interrupt) => [INTERRUPT, interrupt]\n );\n const resumes = task.writes.filter((w) => w[0] === RESUME);\n if (resumes.length) {\n interrupts.push(...resumes);\n }\n this.loop.putWrites(task.id, interrupts);\n }\n } else if (isGraphDrained(error)) {\n // Cooperative drain bubbled up from a subgraph. Leave the task\n // uncommitted (unless it already produced writes) so it is\n // re-executed when the parent run resumes.\n if (task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n }\n } else if (isGraphBubbleUp(error) && task.writes.length) {\n this.loop.putWrites(task.id, task.writes);\n } else {\n task.writes.push([ERROR, { message: error.message, name: error.name }]);\n if (this._shouldRouteToErrorHandler(task)) {\n task.writes.push([ERROR_SOURCE_NODE, String(task.name)]);\n this.handledExceptions.add(error);\n }\n this.loop.putWrites(task.id, task.writes);\n }\n } else {\n if (\n this.nodeFinished &&\n (task.config?.tags == null || !task.config.tags.includes(TAG_HIDDEN))\n ) {\n this.nodeFinished(String(task.name));\n }\n\n if (task.writes.length === 0) {\n // Add no writes marker\n task.writes.push([NO_WRITES, null]);\n }\n\n // Save task writes to checkpointer\n this.loop.putWrites(task.id, task.writes);\n }\n }\n}\n\nasync function call(\n this: {\n executingTasksMap: Record<\n string,\n Promise<{\n task: PregelExecutableTask<string, string>;\n result?: unknown;\n error?: Error;\n }>\n >;\n\n barrier: {\n next: () => void;\n wait: Promise<unknown>;\n };\n\n retryPolicy?: RetryPolicy;\n\n scheduleTask: (\n task: PregelExecutableTask<string, string>,\n writeIdx: number,\n call?: Call\n ) => Promise<PregelExecutableTask<string, string> | void>;\n },\n runner: PregelRunner,\n task: PregelExecutableTask<string, string>,\n func: (...args: unknown[]) => unknown | Promise<unknown>,\n name: string,\n input: unknown,\n options: {\n retry?: RetryPolicy;\n cache?: CachePolicy;\n timeout?: TimeoutPolicy;\n callbacks?: unknown;\n } = {}\n): Promise<unknown> {\n // Schedule PUSH tasks, collect promises\n const scratchpad = task.config?.configurable?.[CONFIG_KEY_SCRATCHPAD] as\n | PregelScratchpad<unknown>\n | undefined;\n\n if (!scratchpad) {\n throw new Error(\n `BUG: No scratchpad found on task ${task.name}__${task.id}`\n );\n }\n\n const cnt = scratchpad.callCounter;\n scratchpad.callCounter += 1;\n\n // schedule the next task, if the callback returns one\n const wcall = new Call({\n func,\n name,\n input,\n cache: options.cache,\n retry: options.retry,\n timeout: options.timeout,\n callbacks: options.callbacks,\n });\n const nextTask = await this.scheduleTask(task, cnt, wcall);\n if (!nextTask) return undefined;\n\n // Check if this task is already running\n const existingPromise = this.executingTasksMap[nextTask.id];\n\n if (existingPromise !== undefined) {\n // If the parent task was retried, the next task might already be running\n return existingPromise;\n }\n\n if (nextTask.writes.length > 0) {\n // If it already ran, return the result\n const returns = nextTask.writes.filter(([c]) => c === RETURN);\n const errors = nextTask.writes.filter(([c]) => c === ERROR);\n\n if (returns.length > 0) {\n // Task completed successfully\n if (returns.length === 1) return Promise.resolve(returns[0][1]);\n\n // should be unreachable\n throw new Error(\n `BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n if (errors.length > 0) {\n // Task failed\n if (errors.length === 1) {\n const errorValue = errors[0][1];\n const error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n errorValue instanceof Error\n ? errorValue\n : new Error(String(errorValue));\n\n return Promise.reject(error);\n }\n\n // the only way this should happen is if the task executes multiple times and writes aren't cleared\n throw new Error(\n `BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`\n );\n }\n\n return undefined;\n } else {\n // Schedule the next task with retry\n const prom = _runWithRetry<string, string>(nextTask, options.retry, {\n [CONFIG_KEY_CALL]: call.bind(this, runner, nextTask),\n });\n\n this.executingTasksMap[nextTask.id] = prom;\n this.barrier.next();\n\n return prom.then(({ result, error }) => {\n if (error) return Promise.reject(error);\n return result;\n });\n }\n}\n"],"mappings":";;;;;;AAoCA,MAAM,uBAAuB,OAAO,IAAI,eAAe;AAEvD,SAAS,uBAAuB;CAC9B,MAAM,UAGF;EACF,YAAY,KAAK;EACjB,MAAM,QAAQ,QAAQ,qBAAqB;EAC5C;CAED,SAAS,YAAY,SAAuD;AAC1E,UAAQ,aAAa;AACnB,WAAQ,OAAO,IAAI,QAAQ,YAAY;AACvC,WAAQ,qBAAqB;;;AAGjC,SAAQ,OAAO,IAAI,QAAQ,YAAY;AACvC,QAAO;;;;;AAoCT,IAAa,eAAb,MAA0B;CACxB;CAEA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,MAAM;AACtC,OAAK,QAAQ,MAAM;AAEnB,SAAO,KAAK,MAAM,EAAE,QAAQ,YAAY;AACtC,OAAI,MAAO,QAAO,QAAQ,OAAO,MAAM;AACvC,UAAO;IACP"}
@@ -1,7 +1,7 @@
1
1
  require("../constants.cjs");
2
2
  const require_convert = require("../stream/convert.cjs");
3
- let _langchain_core_utils_stream = require("@langchain/core/utils/stream");
4
3
  let _langchain_core_callbacks_base = require("@langchain/core/callbacks/base");
4
+ let _langchain_core_utils_stream = require("@langchain/core/utils/stream");
5
5
  //#region src/pregel/stream.ts
6
6
  /**
7
7
  * A wrapper around an IterableReadableStream that allows for aborting the stream when
@@ -1,5 +1,6 @@
1
1
  import { StreamMode } from "./types.cjs";
2
2
  import { IterableReadableStream } from "@langchain/core/utils/stream";
3
+ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
3
4
 
4
5
  //#region src/pregel/stream.d.ts
5
6
  type StreamChunk = [string[], StreamMode, unknown];
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.cts","names":[],"sources":["../../src/pregel/stream.ts"],"mappings":";;;;KA8BY,WAAA,cAAyB,UAAA"}
1
+ {"version":3,"file":"stream.d.cts","names":[],"sources":["../../src/pregel/stream.ts"],"mappings":";;;;;KA8BY,WAAA,cAAyB,UAAA"}
@@ -1,6 +1,6 @@
1
1
  import { StreamMode } from "./types.js";
2
- import { IterableReadableStream } from "@langchain/core/utils/stream";
3
2
  import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
3
+ import { IterableReadableStream } from "@langchain/core/utils/stream";
4
4
 
5
5
  //#region src/pregel/stream.d.ts
6
6
  type StreamChunk = [string[], StreamMode, unknown];
@@ -1,7 +1,7 @@
1
1
  import "../constants.js";
2
2
  import { isCheckpointEnvelope } from "../stream/convert.js";
3
- import { IterableReadableStream } from "@langchain/core/utils/stream";
4
3
  import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
4
+ import { IterableReadableStream } from "@langchain/core/utils/stream";
5
5
  //#region src/pregel/stream.ts
6
6
  /**
7
7
  * A wrapper around an IterableReadableStream that allows for aborting the stream when
package/dist/web.cjs CHANGED
@@ -5,6 +5,7 @@ const require_base = require("./channels/base.cjs");
5
5
  const require_binop = require("./channels/binop.cjs");
6
6
  const require_annotation = require("./graph/annotation.cjs");
7
7
  const require_config = require("./pregel/utils/config.cjs");
8
+ const require_callbacks = require("./callbacks.cjs");
8
9
  const require_runtime = require("./pregel/runtime.cjs");
9
10
  const require_convert = require("./stream/convert.cjs");
10
11
  const require_stream_channel = require("./stream/stream-channel.cjs");
@@ -77,6 +78,7 @@ exports.EmptyInputError = require_errors.EmptyInputError;
77
78
  exports.EventLog = require_stream_channel.StreamChannel;
78
79
  exports.Graph = require_graph.Graph;
79
80
  exports.GraphBubbleUp = require_errors.GraphBubbleUp;
81
+ exports.GraphCallbackHandler = require_callbacks.GraphCallbackHandler;
80
82
  exports.GraphDrained = require_errors.GraphDrained;
81
83
  exports.GraphInterrupt = require_errors.GraphInterrupt;
82
84
  exports.GraphRecursionError = require_errors.GraphRecursionError;
package/dist/web.d.cts CHANGED
@@ -35,7 +35,7 @@ import { DeltaValue, DeltaValueInit } from "./state/values/delta.cjs";
35
35
  import { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition } from "./state/schema.cjs";
36
36
  import { ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ExtractStateType, ExtractUpdateType, GraphNode, GraphNodeReturnValue, GraphNodeTypes, StateDefinitionInit, StateGraphInit, StateGraphOptions, ToStateDefinition } from "./graph/types.cjs";
37
37
  import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.cjs";
38
- import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.cjs";
38
+ import { InferInterruptInputType, InferInterruptResumeType, InterruptOptions, interrupt } from "./interrupt.cjs";
39
39
  import { InferWriterType, writer } from "./writer.cjs";
40
40
  import { CompiledStateGraph, NodePolicyOptions, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.cjs";
41
41
  import { Messages, REMOVE_ALL_MESSAGES, messagesDeltaReducer, messagesStateReducer } from "./graph/messages_reducer.cjs";
@@ -45,5 +45,6 @@ import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/m
45
45
  import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./state/adapter.cjs";
46
46
  import { MessagesDeltaValue, MessagesValue } from "./state/prebuilt/messages.cjs";
47
47
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.cjs";
48
+ import { GraphCallbackHandler, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphResumeEvent } from "./callbacks.cjs";
48
49
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "@langchain/langgraph-checkpoint";
49
- export { type AddNodeOptions, type AgentStatus, Annotation, type AnnotationRoot, AnyStateSchema, type AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, type BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, type CachePolicy, type ChatModelStream, ChatModelStreamImpl, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, Command, CommandInstance, type CommandParams, type CompiledGraph, type CompiledGraphType, CompiledStateGraph, type ConditionalEdgeRouter, type ConditionalEdgeRouterTypes, type ContextSchemaInit, type ConvertToProtocolEventOptions, type CreateGraphRunStreamOptions, DeltaChannel, type DeltaReducer, DeltaValue, DeltaValueInit, type DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, type EntrypointOptions, type EphemeralValue, StreamChannel as EventLog, type ExecutionInfo, type ExtractStateType, type ExtractUpdateType, type GetOperation, type GetStateOptions, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, type GraphNode, type GraphNodeReturnValue, type GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, type InferExtensions, type InferInterruptInputType, type InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, type InferWriterType, type Interrupt, type InterruptPayload, InvalidUpdateError, type Item, type LangGraphRunnableConfig, type LastValue, type LifecycleCause, type LifecycleData, type LifecycleEntry, type LifecycleProjection, type LifecycleTransformerOptions, type ListNamespacesOperation, type MatchCondition, MemorySaver, MessageGraph, type Messages, MessagesAnnotation, MessagesDeltaValue, type MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, type MultipleChannelSubscriptionOptions, MultipleSubgraphsError, type NameSpacePath, type NamedBarrierValue, type Namespace, type NamespaceMatchType, type NativeStreamTransformer, NodeError, NodeInterrupt, type NodePolicyOptions, type NodeSpec, NodeTimeoutError, type NodeType, type Operation, type OperationResults, Overwrite, type OverwriteValue, ParentCommand, type Pregel, type PregelNode, type PregelOptions, type PregelParams, type ProtocolEvent, type PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, type RetryPolicy, RunControl, type Runtime, START, STREAM_EVENTS_V3_MODES, type SearchOperation, Send, type SendOptions, type ServerInfo, type SingleChannelSubscriptionOptions, type SingleReducer, type StateDefinition, type StateDefinitionInit, StateGraph, type StateGraphAddNodeOptions, type StateGraphArgs, type StateGraphArgsWithInputOutputSchemas, type StateGraphArgsWithStateSchema, type StateGraphInit, StateGraphInputError, type StateGraphNodeSpec, type StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, type StateSnapshot, type StateType, StreamChannel, type StreamEmitter, type StreamMode, type StreamOutputMap, type StreamTransformer, type SubgraphDiscoveryProjection, type SubgraphDiscoveryTransformerOptions, SubgraphRunStream, type TaskOptions, type TimeoutPolicy, type ToStateDefinition, type ToolCallStatus, type ToolCallStream, type ToolsEventData, type Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, type UpdateType, type UpdatesEventData, type UsageInfo, type WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
50
+ export { type AddNodeOptions, type AgentStatus, Annotation, type AnnotationRoot, AnyStateSchema, type AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, type BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, type CachePolicy, type ChatModelStream, ChatModelStreamImpl, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, Command, CommandInstance, type CommandParams, type CompiledGraph, type CompiledGraphType, CompiledStateGraph, type ConditionalEdgeRouter, type ConditionalEdgeRouterTypes, type ContextSchemaInit, type ConvertToProtocolEventOptions, type CreateGraphRunStreamOptions, DeltaChannel, type DeltaReducer, DeltaValue, DeltaValueInit, type DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, type EntrypointOptions, type EphemeralValue, StreamChannel as EventLog, type ExecutionInfo, type ExtractStateType, type ExtractUpdateType, type GetOperation, type GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, type GraphInterruptEvent, type GraphLifecycleEvent, type GraphLifecycleStatus, type GraphNode, type GraphNodeReturnValue, type GraphNodeTypes, GraphRecursionError, type GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, type InferExtensions, type InferInterruptInputType, type InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, type InferWriterType, type Interrupt, type InterruptOptions, type InterruptPayload, InvalidUpdateError, type Item, type LangGraphRunnableConfig, type LastValue, type LifecycleCause, type LifecycleData, type LifecycleEntry, type LifecycleProjection, type LifecycleTransformerOptions, type ListNamespacesOperation, type MatchCondition, MemorySaver, MessageGraph, type Messages, MessagesAnnotation, MessagesDeltaValue, type MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, type MultipleChannelSubscriptionOptions, MultipleSubgraphsError, type NameSpacePath, type NamedBarrierValue, type Namespace, type NamespaceMatchType, type NativeStreamTransformer, NodeError, NodeInterrupt, type NodePolicyOptions, type NodeSpec, NodeTimeoutError, type NodeType, type Operation, type OperationResults, Overwrite, type OverwriteValue, ParentCommand, type Pregel, type PregelNode, type PregelOptions, type PregelParams, type ProtocolEvent, type PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, type RetryPolicy, RunControl, type Runtime, START, STREAM_EVENTS_V3_MODES, type SearchOperation, Send, type SendOptions, type ServerInfo, type SingleChannelSubscriptionOptions, type SingleReducer, type StateDefinition, type StateDefinitionInit, StateGraph, type StateGraphAddNodeOptions, type StateGraphArgs, type StateGraphArgsWithInputOutputSchemas, type StateGraphArgsWithStateSchema, type StateGraphInit, StateGraphInputError, type StateGraphNodeSpec, type StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, type StateSnapshot, type StateType, StreamChannel, type StreamEmitter, type StreamMode, type StreamOutputMap, type StreamTransformer, type SubgraphDiscoveryProjection, type SubgraphDiscoveryTransformerOptions, SubgraphRunStream, type TaskOptions, type TimeoutPolicy, type ToStateDefinition, type ToolCallStatus, type ToolCallStream, type ToolsEventData, type Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, type UpdateType, type UpdatesEventData, type UsageInfo, type WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/dist/web.d.ts CHANGED
@@ -35,7 +35,7 @@ import { DeltaValue, DeltaValueInit } from "./state/values/delta.js";
35
35
  import { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition } from "./state/schema.js";
36
36
  import { ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ExtractStateType, ExtractUpdateType, GraphNode, GraphNodeReturnValue, GraphNodeTypes, StateDefinitionInit, StateGraphInit, StateGraphOptions, ToStateDefinition } from "./graph/types.js";
37
37
  import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.js";
38
- import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.js";
38
+ import { InferInterruptInputType, InferInterruptResumeType, InterruptOptions, interrupt } from "./interrupt.js";
39
39
  import { InferWriterType, writer } from "./writer.js";
40
40
  import { CompiledStateGraph, NodePolicyOptions, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.js";
41
41
  import { Messages, REMOVE_ALL_MESSAGES, messagesDeltaReducer, messagesStateReducer } from "./graph/messages_reducer.js";
@@ -45,5 +45,6 @@ import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/m
45
45
  import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./state/adapter.js";
46
46
  import { MessagesDeltaValue, MessagesValue } from "./state/prebuilt/messages.js";
47
47
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
48
+ import { GraphCallbackHandler, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphResumeEvent } from "./callbacks.js";
48
49
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "@langchain/langgraph-checkpoint";
49
- export { type AddNodeOptions, type AgentStatus, Annotation, type AnnotationRoot, AnyStateSchema, type AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, type BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, type CachePolicy, type ChatModelStream, ChatModelStreamImpl, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, Command, CommandInstance, type CommandParams, type CompiledGraph, type CompiledGraphType, CompiledStateGraph, type ConditionalEdgeRouter, type ConditionalEdgeRouterTypes, type ContextSchemaInit, type ConvertToProtocolEventOptions, type CreateGraphRunStreamOptions, DeltaChannel, type DeltaReducer, DeltaValue, DeltaValueInit, type DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, type EntrypointOptions, type EphemeralValue, StreamChannel as EventLog, type ExecutionInfo, type ExtractStateType, type ExtractUpdateType, type GetOperation, type GetStateOptions, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, type GraphNode, type GraphNodeReturnValue, type GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, type InferExtensions, type InferInterruptInputType, type InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, type InferWriterType, type Interrupt, type InterruptPayload, InvalidUpdateError, type Item, type LangGraphRunnableConfig, type LastValue, type LifecycleCause, type LifecycleData, type LifecycleEntry, type LifecycleProjection, type LifecycleTransformerOptions, type ListNamespacesOperation, type MatchCondition, MemorySaver, MessageGraph, type Messages, MessagesAnnotation, MessagesDeltaValue, type MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, type MultipleChannelSubscriptionOptions, MultipleSubgraphsError, type NameSpacePath, type NamedBarrierValue, type Namespace, type NamespaceMatchType, type NativeStreamTransformer, NodeError, NodeInterrupt, type NodePolicyOptions, type NodeSpec, NodeTimeoutError, type NodeType, type Operation, type OperationResults, Overwrite, type OverwriteValue, ParentCommand, type Pregel, type PregelNode, type PregelOptions, type PregelParams, type ProtocolEvent, type PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, type RetryPolicy, RunControl, type Runtime, START, STREAM_EVENTS_V3_MODES, type SearchOperation, Send, type SendOptions, type ServerInfo, type SingleChannelSubscriptionOptions, type SingleReducer, type StateDefinition, type StateDefinitionInit, StateGraph, type StateGraphAddNodeOptions, type StateGraphArgs, type StateGraphArgsWithInputOutputSchemas, type StateGraphArgsWithStateSchema, type StateGraphInit, StateGraphInputError, type StateGraphNodeSpec, type StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, type StateSnapshot, type StateType, StreamChannel, type StreamEmitter, type StreamMode, type StreamOutputMap, type StreamTransformer, type SubgraphDiscoveryProjection, type SubgraphDiscoveryTransformerOptions, SubgraphRunStream, type TaskOptions, type TimeoutPolicy, type ToStateDefinition, type ToolCallStatus, type ToolCallStream, type ToolsEventData, type Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, type UpdateType, type UpdatesEventData, type UsageInfo, type WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
50
+ export { type AddNodeOptions, type AgentStatus, Annotation, type AnnotationRoot, AnyStateSchema, type AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, type BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, type CachePolicy, type ChatModelStream, ChatModelStreamImpl, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, Command, CommandInstance, type CommandParams, type CompiledGraph, type CompiledGraphType, CompiledStateGraph, type ConditionalEdgeRouter, type ConditionalEdgeRouterTypes, type ContextSchemaInit, type ConvertToProtocolEventOptions, type CreateGraphRunStreamOptions, DeltaChannel, type DeltaReducer, DeltaValue, DeltaValueInit, type DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, type EntrypointOptions, type EphemeralValue, StreamChannel as EventLog, type ExecutionInfo, type ExtractStateType, type ExtractUpdateType, type GetOperation, type GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, type GraphInterruptEvent, type GraphLifecycleEvent, type GraphLifecycleStatus, type GraphNode, type GraphNodeReturnValue, type GraphNodeTypes, GraphRecursionError, type GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, type InferExtensions, type InferInterruptInputType, type InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, type InferWriterType, type Interrupt, type InterruptOptions, type InterruptPayload, InvalidUpdateError, type Item, type LangGraphRunnableConfig, type LastValue, type LifecycleCause, type LifecycleData, type LifecycleEntry, type LifecycleProjection, type LifecycleTransformerOptions, type ListNamespacesOperation, type MatchCondition, MemorySaver, MessageGraph, type Messages, MessagesAnnotation, MessagesDeltaValue, type MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, type MultipleChannelSubscriptionOptions, MultipleSubgraphsError, type NameSpacePath, type NamedBarrierValue, type Namespace, type NamespaceMatchType, type NativeStreamTransformer, NodeError, NodeInterrupt, type NodePolicyOptions, type NodeSpec, NodeTimeoutError, type NodeType, type Operation, type OperationResults, Overwrite, type OverwriteValue, ParentCommand, type Pregel, type PregelNode, type PregelOptions, type PregelParams, type ProtocolEvent, type PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, type RetryPolicy, RunControl, type Runtime, START, STREAM_EVENTS_V3_MODES, type SearchOperation, Send, type SendOptions, type ServerInfo, type SingleChannelSubscriptionOptions, type SingleReducer, type StateDefinition, type StateDefinitionInit, StateGraph, type StateGraphAddNodeOptions, type StateGraphArgs, type StateGraphArgsWithInputOutputSchemas, type StateGraphArgsWithStateSchema, type StateGraphInit, StateGraphInputError, type StateGraphNodeSpec, type StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, type StateSnapshot, type StateType, StreamChannel, type StreamEmitter, type StreamMode, type StreamOutputMap, type StreamTransformer, type SubgraphDiscoveryProjection, type SubgraphDiscoveryTransformerOptions, SubgraphRunStream, type TaskOptions, type TimeoutPolicy, type ToStateDefinition, type ToolCallStatus, type ToolCallStream, type ToolsEventData, type Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, type UpdateType, type UpdatesEventData, type UsageInfo, type WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/dist/web.js CHANGED
@@ -4,6 +4,7 @@ import { BaseChannel } from "./channels/base.js";
4
4
  import { BinaryOperatorAggregate } from "./channels/binop.js";
5
5
  import { Annotation } from "./graph/annotation.js";
6
6
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
7
+ import { GraphCallbackHandler } from "./callbacks.js";
7
8
  import { RunControl } from "./pregel/runtime.js";
8
9
  import { STREAM_EVENTS_V3_MODES, convertToProtocolEvent, isCheckpointEnvelope } from "./stream/convert.js";
9
10
  import { StreamChannel } from "./stream/stream-channel.js";
@@ -35,4 +36,4 @@ import { entrypoint, getPreviousState, task } from "./func/index.js";
35
36
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.js";
36
37
  import { writer } from "./writer.js";
37
38
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, InMemoryStore, MemorySaver, copyCheckpoint, emptyCheckpoint } from "@langchain/langgraph-checkpoint";
38
- export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, COMMAND_SYMBOL, ChatModelStreamImpl, Command, CommandInstance, CompiledStateGraph, DeltaChannel, DeltaValue, END, EmptyChannelError, EmptyInputError, StreamChannel as EventLog, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesDeltaValue, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, Overwrite, ParentCommand, REMOVE_ALL_MESSAGES, ReducedValue, RemoteException, RunControl, START, STREAM_EVENTS_V3_MODES, Send, StateGraph, StateGraphInputError, StateSchema, StreamChannel, SubgraphRunStream, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
39
+ export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, COMMAND_SYMBOL, ChatModelStreamImpl, Command, CommandInstance, CompiledStateGraph, DeltaChannel, DeltaValue, END, EmptyChannelError, EmptyInputError, StreamChannel as EventLog, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesDeltaValue, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, Overwrite, ParentCommand, REMOVE_ALL_MESSAGES, ReducedValue, RemoteException, RunControl, START, STREAM_EVENTS_V3_MODES, Send, StateGraph, StateGraphInputError, StateSchema, StreamChannel, SubgraphRunStream, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {
@@ -19,7 +19,7 @@
19
19
  "@langchain/protocol": "^0.0.19",
20
20
  "@standard-schema/spec": "1.1.0",
21
21
  "@langchain/langgraph-checkpoint": "^1.1.5",
22
- "@langchain/langgraph-sdk": "~1.11.0"
22
+ "@langchain/langgraph-sdk": "~1.11.2"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@langchain/core": "^1.1.48",