@langchain/langgraph
Version:
1 lines • 56.5 kB
Source Map (JSON)
{"version":3,"file":"graph.cjs","names":["Runnable","ChannelWrite","RunnableCallable","NodeInterrupt","_isSend","InvalidUpdateError","isPregelLike","START","END","EphemeralValue","UnreachableNodeError","Pregel","PregelNode","PASSTHROUGH","TAG_HIDDEN","Channel","DrawableGraph","z","gatherIterator","gatherIteratorSync"],"sources":["../../src/graph/graph.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport {\n _coerceToRunnable,\n Runnable,\n RunnableConfig,\n RunnableInterface,\n RunnableIOSchema,\n type RunnableLike as LangChainRunnableLike,\n} from \"@langchain/core/runnables\";\nimport {\n Node as DrawableGraphNode,\n Graph as DrawableGraph,\n} from \"@langchain/core/runnables/graph\";\nimport { All, BaseCheckpointSaver } from \"@langchain/langgraph-checkpoint\";\nimport { z } from \"zod/v4\";\nimport { validate as isUuid } from \"@langchain/core/utils/uuid\";\nimport type {\n RunnableLike,\n LangGraphRunnableConfig,\n} from \"../pregel/runnable_types.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { Channel, Pregel } from \"../pregel/index.js\";\nimport type { PregelOptions, PregelParams } from \"../pregel/types.js\";\nimport { BaseChannel } from \"../channels/base.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { ChannelWrite, PASSTHROUGH } from \"../pregel/write.js\";\nimport {\n _isSend,\n CHECKPOINT_NAMESPACE_END,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n END,\n Send,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport {\n gatherIterator,\n gatherIteratorSync,\n RunnableCallable,\n} from \"../utils.js\";\nimport {\n InvalidUpdateError,\n NodeError,\n NodeInterrupt,\n UnreachableNodeError,\n} from \"../errors.js\";\nimport { StateDefinition, StateType } from \"./annotation.js\";\nimport { isPregelLike } from \"../pregel/utils/subgraph.js\";\nimport type { StreamTransformer } from \"../stream/types.js\";\nimport type { GraphNodeReturnValue } from \"./types.js\";\n\nexport interface BranchOptions<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig,\n> {\n source: N;\n path: RunnableLike<IO, BranchPathReturnValue, CallOptions>;\n pathMap?: Record<string, N | typeof END> | (N | typeof END)[];\n}\n\nexport type BranchPathReturnValue =\n | string\n | Send\n | (string | Send)[]\n | Promise<string | Send | (string | Send)[]>;\n\ntype CompiledGraphTypeNode<Spec> = Spec extends { node: infer N extends string }\n ? N\n : any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\ntype CompiledGraphTypeContext<Spec> = Spec extends {\n context: infer Context extends Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n ? Context\n : Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n\ntype CompiledGraphTypeStreamTransformers<Spec> = Spec extends {\n streamTransformers: infer Transformers;\n}\n ? Transformers extends ReadonlyArray<\n () => StreamTransformer<any> // eslint-disable-line @typescript-eslint/no-explicit-any\n >\n ? Transformers\n : Transformers extends ReadonlyArray<\n StreamTransformer<any> // eslint-disable-line @typescript-eslint/no-explicit-any\n >\n ? { readonly [K in keyof Transformers]: () => Transformers[K] }\n : Transformers extends StreamTransformer<any> // eslint-disable-line @typescript-eslint/no-explicit-any\n ? readonly [() => Transformers]\n : []\n : [];\n\n/**\n * Convenience type for referencing a compiled graph by named type slots.\n *\n * @example\n * ```ts\n * type MyCompiledGraph = CompiledGraphType<{\n * state: State;\n * update: Update;\n * streamTransformers: [\n * StreamTransformer<Extensions>,\n * StreamTransformer<MoreExtensions>,\n * ];\n * }>;\n * ```\n */\nexport type CompiledGraphType<Spec extends object = object> = CompiledGraph<\n CompiledGraphTypeNode<Spec>,\n Spec extends { state: infer State } ? State : any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Spec extends { update: infer Update } ? Update : any, // eslint-disable-line @typescript-eslint/no-explicit-any\n CompiledGraphTypeContext<Spec>,\n Spec extends { input: infer Input } ? Input : any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Spec extends { output: infer Output } ? Output : any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Spec extends { nodeReturn: infer NodeReturn } ? NodeReturn : unknown,\n Spec extends { command: infer Command } ? Command : unknown,\n Spec extends { streamCustom: infer StreamCustom } ? StreamCustom : any, // eslint-disable-line @typescript-eslint/no-explicit-any\n CompiledGraphTypeStreamTransformers<Spec>\n>;\n\ntype NodeAction<S, U, C extends StateDefinition> = RunnableLike<\n S,\n U extends object ? U & Record<string, any> : U, // eslint-disable-line @typescript-eslint/no-explicit-any\n LangGraphRunnableConfig<StateType<C>>\n>;\n\nexport class Branch<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig,\n> {\n path: Runnable<IO, BranchPathReturnValue>;\n\n ends?: Record<string, N | typeof END>;\n\n constructor(options: Omit<BranchOptions<IO, N, CallOptions>, \"source\">) {\n if (Runnable.isRunnable(options.path)) {\n this.path = options.path as Runnable<IO, BranchPathReturnValue>;\n } else {\n this.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<IO, BranchPathReturnValue>\n );\n }\n this.ends = Array.isArray(options.pathMap)\n ? options.pathMap.reduce(\n (acc, n) => {\n acc[n] = n;\n return acc;\n },\n {} as Record<string, N | typeof END>\n )\n : options.pathMap;\n }\n\n run(\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n ) {\n return ChannelWrite.registerWriter(\n new RunnableCallable({\n name: \"<branch_run>\",\n trace: false,\n func: async (input: IO, config: CallOptions) => {\n try {\n return await this._route(input, config, writer, reader);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n // Detect & warn if NodeInterrupt is thrown in a conditional edge\n if (e.name === NodeInterrupt.unminifiable_name) {\n console.warn(\n \"[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.\\n\" +\n \"NodeInterrupt should only be thrown inside a node, not in edge conditions.\"\n );\n }\n throw e;\n }\n },\n })\n );\n }\n\n async _route(\n input: IO,\n config: CallOptions,\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<Runnable | any> {\n let result = await this.path.invoke(\n reader ? reader(config) : input,\n config\n );\n if (!Array.isArray(result)) {\n result = [result];\n }\n\n let destinations: (string | Send)[];\n if (this.ends) {\n destinations = result.map((r) => (_isSend(r) ? r : this.ends![r]));\n } else {\n destinations = result;\n }\n if (destinations.some((dest) => !dest)) {\n throw new Error(\"Branch condition returned unknown or null destination\");\n }\n if (destinations.filter(_isSend).some((packet) => packet.node === END)) {\n throw new InvalidUpdateError(\"Cannot send a packet to the END node\");\n }\n const writeResult = await writer(destinations, config);\n return writeResult ?? input;\n }\n}\n\nexport type NodeSpec<RunInput, RunOutput> = {\n runnable: Runnable<RunInput, RunOutput>;\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: string[];\n defer?: boolean;\n /** Whether this node is an auto-generated node-level error handler. */\n isErrorHandler?: boolean;\n /** Name of the auto-generated error handler node to run on failure. */\n errorHandlerNode?: string;\n};\n\n/**\n * Return value type for node-level error handlers.\n *\n * Handlers may return a partial state update, a `Command`, or a Promise of either.\n *\n * @template Update - The update type (what fields can be returned)\n * @template Nodes - Union of valid node names for Command.goto\n */\nexport type NodeErrorHandlerReturnValue<\n Update,\n Nodes extends string = string,\n> = GraphNodeReturnValue<Update, Nodes>;\n\n/**\n * A node-level error handler callable.\n *\n * Invoked with the node input state, a {@link NodeError} describing the failed\n * node and thrown error, and the runnable config. The handler runs ONLY after\n * the failing node's {@link RetryPolicy} is exhausted. It may return a state\n * update or a `Command` (to route via `goto`).\n */\nexport type NodeErrorHandler<\n TState = unknown,\n TUpdate = Partial<TState>,\n Nodes extends string = string,\n> = (\n state: TState,\n error: NodeError,\n config?: LangGraphRunnableConfig\n) => NodeErrorHandlerReturnValue<TUpdate, Nodes>;\n\nexport type AddNodeOptions<Nodes extends string = string> = {\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: Nodes[];\n defer?: boolean;\n};\n\nexport class Graph<\n N extends string = typeof START | typeof END,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<\n RunInput,\n RunOutput\n >,\n C extends StateDefinition = StateDefinition,\n> {\n nodes: Record<N, NodeSpecType>;\n\n edges: Set<[N | typeof START, N | typeof END]>;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n branches: Record<string, Record<string, Branch<RunInput, N, any>>>;\n\n entryPoint?: string;\n\n compiled = false;\n\n constructor() {\n this.nodes = {} as Record<N, NodeSpecType>;\n this.edges = new Set();\n this.branches = {};\n }\n\n protected warnIfCompiled(message: string): void {\n if (this.compiled) {\n console.warn(message);\n }\n }\n\n get allEdges(): Set<[string, string]> {\n return this.edges;\n }\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions,\n ][]\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n ...args:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions,\n ]\n | [\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions,\n ][],\n ]\n ): Graph<N | K, RunInput, RunOutput> {\n function isMutlipleNodes(\n args: unknown[]\n ): args is [\n nodes:\n | Record<K, NodeAction<NodeInput, RunOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, RunOutput, C>,\n options?: AddNodeOptions,\n ][],\n options?: AddNodeOptions,\n ] {\n return args.length >= 1 && typeof args[0] !== \"string\";\n }\n\n const nodes = (\n isMutlipleNodes(args) // eslint-disable-line no-nested-ternary\n ? Array.isArray(args[0])\n ? args[0]\n : Object.entries(args[0])\n : [[args[0], args[1], args[2]]]\n ) as [K, NodeAction<NodeInput, RunOutput, C>, AddNodeOptions][];\n\n if (nodes.length === 0) {\n throw new Error(\"No nodes provided in `addNode`\");\n }\n\n for (const [key, action, options] of nodes) {\n for (const reservedChar of [\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CHECKPOINT_NAMESPACE_END,\n ]) {\n if (key.includes(reservedChar)) {\n throw new Error(\n `\"${reservedChar}\" is a reserved character and is not allowed in node names.`\n );\n }\n }\n this.warnIfCompiled(\n `Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (key in this.nodes) {\n throw new Error(`Node \\`${key}\\` already present.`);\n }\n if (key === END) {\n throw new Error(`Node \\`${key}\\` is reserved.`);\n }\n\n const runnable = _coerceToRunnable<RunInput, RunOutput>(\n // Account for arbitrary state due to Send API\n action as RunnableLike<RunInput, RunOutput>\n );\n\n this.nodes[key as unknown as N] = {\n runnable,\n metadata: options?.metadata,\n subgraphs: isPregelLike(runnable) ? [runnable] : options?.subgraphs,\n ends: options?.ends,\n } as NodeSpecType;\n }\n\n return this as Graph<N | K, RunInput, RunOutput, NodeSpecType>;\n }\n\n addEdge(startKey: N | typeof START, endKey: N | typeof END): this {\n this.warnIfCompiled(\n `Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (startKey === END) {\n throw new Error(\"END cannot be a start node\");\n }\n if (endKey === START) {\n throw new Error(\"START cannot be an end node\");\n }\n if (\n Array.from(this.edges).some(([start]) => start === startKey) &&\n !(\"channels\" in this)\n ) {\n throw new Error(\n `Already found path for ${startKey}. For multiple edges, use StateGraph.`\n );\n }\n\n this.edges.add([startKey, endKey]);\n\n return this;\n }\n\n addConditionalEdges(\n source: BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>\n ): this;\n\n addConditionalEdges(\n source: N,\n path: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this;\n\n addConditionalEdges(\n source:\n | N\n | BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>,\n path?: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this {\n const options: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n > = typeof source === \"object\" ? source : { source, path: path!, pathMap };\n\n this.warnIfCompiled(\n \"Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n if (!Runnable.isRunnable(options.path)) {\n options.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<RunInput, BranchPathReturnValue>\n );\n }\n // find a name for condition\n const name =\n options.path.getName() === \"RunnableLambda\"\n ? \"condition\"\n : options.path.getName();\n // validate condition\n if (this.branches[options.source] && this.branches[options.source][name]) {\n throw new Error(\n `Condition \\`${name}\\` already present for node \\`${source}\\``\n );\n }\n // save it\n this.branches[options.source] ??= {};\n this.branches[options.source][name] = new Branch(options);\n return this;\n }\n\n /**\n * @deprecated use `addEdge(START, key)` instead\n */\n setEntryPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(START, key);\n }\n\n /**\n * @deprecated use `addEdge(key, END)` instead\n */\n setFinishPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(key, END);\n }\n\n compile<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const TTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n [],\n >({\n checkpointer,\n interruptBefore,\n interruptAfter,\n name,\n transformers,\n }: {\n checkpointer?: BaseCheckpointSaver | false;\n interruptBefore?: N[] | All;\n interruptAfter?: N[] | All;\n name?: string;\n /**\n * Stream transformer factories baked into the compiled graph. These run\n * automatically for every `streamEvents(..., { version: \"v3\" })` call,\n * before any call-site transformers.\n */\n transformers?: TTransformers;\n } = {}): CompiledGraph<\n N,\n RunInput,\n RunOutput,\n Record<string, any>,\n any,\n any,\n unknown,\n unknown,\n any,\n TTransformers\n > {\n // eslint-disable-line @typescript-eslint/no-explicit-any\n // validate the graph\n this.validate([\n ...(Array.isArray(interruptBefore) ? interruptBefore : []),\n ...(Array.isArray(interruptAfter) ? interruptAfter : []),\n ]);\n\n // create empty compiled graph\n const compiled = new CompiledGraph({\n builder: this,\n checkpointer,\n interruptAfter,\n interruptBefore,\n autoValidate: false,\n nodes: {} as Record<N | typeof START, PregelNode<RunInput, RunOutput>>,\n channels: {\n [START]: new EphemeralValue(),\n [END]: new EphemeralValue(),\n } as Record<N | typeof START | typeof END | string, BaseChannel>,\n inputChannels: START,\n outputChannels: END,\n streamChannels: [] as N[],\n streamMode: \"values\",\n name,\n streamTransformers: transformers,\n });\n\n // attach nodes, edges and branches\n for (const [key, node] of Object.entries<NodeSpec<RunInput, RunOutput>>(\n this.nodes\n )) {\n compiled.attachNode(key as N, node);\n }\n for (const [start, end] of this.edges) {\n compiled.attachEdge(start, end);\n }\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const [name, branch] of Object.entries(branches)) {\n compiled.attachBranch(start as N, name, branch);\n }\n }\n\n return compiled.validate();\n }\n\n validate(interrupt?: string[]): void {\n // assemble sources\n const allSources = new Set([...this.allEdges].map(([src, _]) => src));\n for (const [start] of Object.entries(this.branches)) {\n allSources.add(start);\n }\n\n // validate sources\n for (const source of allSources) {\n if (source !== START && !(source in this.nodes)) {\n throw new Error(`Found edge starting at unknown node \\`${source}\\``);\n }\n }\n\n // assemble targets\n const allTargets = new Set([...this.allEdges].map(([_, target]) => target));\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const branch of Object.values(branches)) {\n if (branch.ends != null) {\n for (const end of Object.values(branch.ends)) {\n allTargets.add(end);\n }\n } else {\n allTargets.add(END);\n for (const node of Object.keys(this.nodes)) {\n if (node !== start) {\n allTargets.add(node);\n }\n }\n }\n }\n }\n for (const node of Object.values<NodeSpecType>(this.nodes)) {\n for (const target of node.ends ?? []) {\n allTargets.add(target);\n }\n }\n // Node-level error handlers can route to any node via `Command({ goto })`\n // (saga / compensation flows), so treat them like an open-ended branch:\n // any node may be a recovery target reachable from a handler.\n const hasErrorHandler = Object.values<NodeSpecType>(this.nodes).some(\n (node) => node.isErrorHandler\n );\n if (hasErrorHandler) {\n for (const node of Object.keys(this.nodes)) {\n allTargets.add(node);\n }\n }\n // validate targets\n for (const node of Object.keys(this.nodes)) {\n // auto-generated error handler nodes are reachable only on failure of\n // their source node, so they are exempt from the reachability check.\n if (this.nodes[node as N].isErrorHandler) {\n continue;\n }\n if (!allTargets.has(node)) {\n throw new UnreachableNodeError(\n [\n `Node \\`${node}\\` is not reachable.`,\n \"\",\n \"If you are returning Command objects from your node,\",\n 'make sure you are passing names of potential destination nodes as an \"ends\" array',\n 'into \".addNode(..., { ends: [\"node1\", \"node2\"] })\".',\n ].join(\"\\n\"),\n {\n lc_error_code: \"UNREACHABLE_NODE\",\n }\n );\n }\n }\n for (const target of allTargets) {\n if (target !== END && !(target in this.nodes)) {\n throw new Error(`Found edge ending at unknown node \\`${target}\\``);\n }\n }\n\n // validate interrupts\n if (interrupt) {\n for (const node of interrupt) {\n if (!(node in this.nodes)) {\n throw new Error(`Interrupt node \\`${node}\\` is not present`);\n }\n }\n }\n\n this.compiled = true;\n }\n}\n\nexport class CompiledGraph<\n N extends string,\n State = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Update = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n InputType = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n OutputType = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n NodeReturnType = unknown,\n CommandType = unknown,\n StreamCustomType = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n TStreamTransformers extends ReadonlyArray<() => StreamTransformer<any>> = [], // eslint-disable-line @typescript-eslint/no-explicit-any\n> extends Pregel<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>,\n ContextType & Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n InputType,\n OutputType,\n InputType,\n OutputType,\n NodeReturnType,\n CommandType,\n StreamCustomType,\n TStreamTransformers\n> {\n declare \"~NodeType\": N;\n\n declare \"~NodeReturnType\": NodeReturnType;\n\n declare \"~RunInput\": Update;\n\n declare \"~RunOutput\": State;\n\n builder: Graph<N, State, Update>;\n\n constructor({\n builder,\n ...rest\n }: { builder: Graph<N, State, Update> } & PregelParams<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>,\n TStreamTransformers\n >) {\n super(rest);\n this.builder = builder;\n }\n\n override withConfig<\n const TTransformers extends ReadonlyArray<() => StreamTransformer<any>> =\n [],\n >(\n config: Omit<LangGraphRunnableConfig, \"store\" | \"writer\" | \"interrupt\"> & {\n streamTransformers: TTransformers;\n }\n ): CompiledGraph<\n N,\n State,\n Update,\n ContextType,\n InputType,\n OutputType,\n NodeReturnType,\n CommandType,\n StreamCustomType,\n readonly [...TStreamTransformers, ...TTransformers]\n >;\n\n override withConfig(\n config: PregelOptions<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>,\n ContextType & Record<string, any>\n >\n ): this;\n\n override withConfig(\n config: Omit<LangGraphRunnableConfig, \"store\" | \"writer\" | \"interrupt\"> & {\n streamTransformers?: ReadonlyArray<() => StreamTransformer<any>>;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): any {\n return (super.withConfig as any)(config) as unknown as CompiledGraph<\n N,\n State,\n Update,\n ContextType,\n InputType,\n OutputType,\n NodeReturnType,\n CommandType,\n StreamCustomType,\n ReadonlyArray<() => StreamTransformer<any>>\n >;\n }\n\n attachNode(key: N, node: NodeSpec<State, Update>): void {\n this.channels[key] = new EphemeralValue();\n this.nodes[key] = new PregelNode({\n channels: [],\n triggers: [],\n metadata: node.metadata,\n subgraphs: node.subgraphs,\n ends: node.ends,\n })\n .pipe(node.runnable)\n .pipe(\n new ChannelWrite([{ channel: key, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n (this.streamChannels as N[]).push(key);\n }\n\n attachEdge(start: N | typeof START, end: N | typeof END): void {\n if (end === END) {\n if (start === START) {\n throw new Error(\"Cannot have an edge from START to END\");\n }\n this.nodes[start].writers.push(\n new ChannelWrite([{ channel: END, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n } else {\n this.nodes[end].triggers.push(start);\n (this.nodes[end].channels as string[]).push(start);\n }\n }\n\n attachBranch(\n start: N | typeof START,\n name: string,\n branch: Branch<State, N>\n ) {\n // add hidden start node\n if (start === START && !this.nodes[START]) {\n this.nodes[START] = Channel.subscribeTo(START, { tags: [TAG_HIDDEN] });\n }\n\n // attach branch writer\n this.nodes[start].pipe(\n branch.run((dests) => {\n const writes = dests.map((dest) => {\n if (_isSend(dest)) {\n return dest;\n }\n return {\n channel: dest === END ? END : `branch:${start}:${name}:${dest}`,\n value: PASSTHROUGH,\n };\n });\n return new ChannelWrite(writes, [TAG_HIDDEN]);\n })\n );\n\n // attach branch readers\n const ends = branch.ends\n ? Object.values(branch.ends)\n : (Object.keys(this.nodes) as N[]);\n for (const end of ends) {\n if (end !== END) {\n const channelName = `branch:${start}:${name}:${end}`;\n (this.channels as Record<string, BaseChannel>)[channelName] =\n new EphemeralValue();\n this.nodes[end].triggers.push(channelName);\n (this.nodes[end].channels as string[]).push(channelName);\n }\n }\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n */\n override async getGraphAsync(\n config?: RunnableConfig & { xray?: boolean | number }\n ): Promise<DrawableGraph> {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode({ schema: z.any() }, START),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n (await gatherIterator(this.getSubgraphsAsync())).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n const discoveredEdges: DiscoveredGraphEdge[] = [];\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n if (startNodes[start] === undefined) {\n return;\n }\n if (endNodes[end] === undefined) {\n throw new Error(`End node ${end} not found!`);\n }\n discoveredEdges.push({ src: start, dest: end, conditional });\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>,\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? await subgraphs[key].getGraphAsync({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n for (const [key, node] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>,\n ][]) {\n if (node.ends !== undefined) {\n for (const end of node.ends) {\n addEdge(\n _escapeMermaidKeywords(key),\n _escapeMermaidKeywords(end),\n undefined,\n true\n );\n }\n }\n }\n addImplicitTerminalEndEdges(this.builder.nodes, discoveredEdges, addEdge);\n return graph;\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n *\n * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.\n */\n override getGraph(\n config?: RunnableConfig & { xray?: boolean | number }\n ): DrawableGraph {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode(\n {\n schema: z.any(),\n },\n START\n ),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n gatherIteratorSync(this.getSubgraphs()).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n const discoveredEdges: DiscoveredGraphEdge[] = [];\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n if (startNodes[start] === undefined) {\n return;\n }\n if (endNodes[end] === undefined) {\n throw new Error(`End node ${end} not found!`);\n }\n discoveredEdges.push({ src: start, dest: end, conditional });\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>,\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? subgraphs[key].getGraph({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n for (const [key, node] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>,\n ][]) {\n if (node.ends !== undefined) {\n for (const end of node.ends) {\n addEdge(\n _escapeMermaidKeywords(key),\n _escapeMermaidKeywords(end),\n undefined,\n true\n );\n }\n }\n }\n addImplicitTerminalEndEdges(this.builder.nodes, discoveredEdges, addEdge);\n return graph;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isCompiledGraph(x: unknown): x is CompiledGraph<any> {\n return (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachNode === \"function\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachEdge === \"function\"\n );\n}\n\nfunction _escapeMermaidKeywords(key: string) {\n if (key === \"subgraph\") {\n return `\"${key}\"`;\n }\n return key;\n}\n\n/**\n * An edge collected while building a {@link DrawableGraph} from a compiled\n * {@link StateGraph}.\n *\n * Used by {@link addImplicitTerminalEndEdges} to detect nodes that should\n * receive an implicit edge to {@link END} (terminal nodes with no outgoing\n * edges in the drawable view).\n *\n * @internal\n */\ntype DiscoveredGraphEdge = {\n /** Display name of the source node (Mermaid-escaped). */\n src: string;\n /** Display name of the target node (Mermaid-escaped), or {@link END}. */\n dest: string;\n /**\n * Whether the edge comes from a conditional branch or `node.ends` declaration.\n * Non-conditional edges alone determine implicit terminal `→ END` links.\n */\n conditional: boolean;\n};\n\n/**\n * Add implicit edges to END for terminal nodes (targets with no outgoing edges).\n *\n * Only nodes reached by a non-conditional edge are considered, so\n * conditional-branch targets are not treated as implicit sinks.\n */\nfunction addImplicitTerminalEndEdges<N extends string>(\n nodes: Record<N, NodeSpec<unknown, unknown>>,\n discovered: DiscoveredGraphEdge[],\n addEdge: (\n start: string,\n end: string,\n label?: string,\n conditional?: boolean\n ) => void\n): void {\n const sources = new Set(discovered.map((e) => e.src));\n const nonConditionalDestinations = [\n ...new Set(\n discovered\n .filter((e) => !e.conditional && e.dest !== END)\n .map((e) => e.dest)\n ),\n ].sort();\n\n for (const displayDest of nonConditionalDestinations) {\n if (sources.has(displayDest)) continue;\n const rawKey = (Object.keys(nodes) as N[]).find(\n (k) => _escapeMermaidKeywords(k) === displayDest\n );\n if (rawKey !== undefined && nodes[rawKey]?.isErrorHandler) continue;\n addEdge(displayDest, END);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA+HA,IAAa,SAAb,MAIE;CACA;CAEA;CAEA,YAAY,SAA4D;AACtE,MAAIA,0BAAAA,SAAS,WAAW,QAAQ,KAAK,CACnC,MAAK,OAAO,QAAQ;MAEpB,MAAK,QAAA,GAAA,0BAAA,mBACH,QAAQ,KACT;AAEH,OAAK,OAAO,MAAM,QAAQ,QAAQ,QAAQ,GACtC,QAAQ,QAAQ,QACb,KAAK,MAAM;AACV,OAAI,KAAK;AACT,UAAO;KAET,EAAE,CACH,GACD,QAAQ;;CAGd,IACE,QAIA,QACA;AACA,SAAOC,cAAAA,aAAa,eAClB,IAAIC,cAAAA,iBAAiB;GACnB,MAAM;GACN,OAAO;GACP,MAAM,OAAO,OAAW,WAAwB;AAC9C,QAAI;AACF,YAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,QAAQ,OAAO;aAEhD,GAAQ;AAEf,SAAI,EAAE,SAASC,eAAAA,cAAc,kBAC3B,SAAQ,KACN,qLAED;AAEH,WAAM;;;GAGX,CAAC,CACH;;CAGH,MAAM,OACJ,OACA,QACA,QAIA,QAEyB;EACzB,IAAI,SAAS,MAAM,KAAK,KAAK,OAC3B,SAAS,OAAO,OAAO,GAAG,OAC1B,OACD;AACD,MAAI,CAAC,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