import { BaseChannel } from "../channels/base.cjs"; import { END, START, Send } from "../constants.cjs"; import { LangGraphRunnableConfig, RunnableLike as RunnableLike$1 } from "../pregel/runnable_types.cjs"; import { StateDefinition, StateType } from "./annotation.cjs"; import { RunnableCallable } from "../utils.cjs"; import { PregelNode } from "../pregel/read.cjs"; import { StreamTransformer } from "../stream/types.cjs"; import { PregelOptions, PregelParams } from "../pregel/types.cjs"; import { Pregel } from "../pregel/index.cjs"; import { NodeError } from "../errors.cjs"; import { GraphNodeReturnValue } from "./types.cjs"; import { All, BaseCheckpointSaver } from "@langchain/langgraph-checkpoint"; import { Runnable, RunnableConfig } from "@langchain/core/runnables"; import { Graph } from "@langchain/core/runnables/graph"; //#region src/graph/graph.d.ts interface BranchOptions { source: N; path: RunnableLike$1; pathMap?: Record | (N | typeof END)[]; } type BranchPathReturnValue = string | Send | (string | Send)[] | Promise; type CompiledGraphTypeNode = Spec extends { node: infer N extends string; } ? N : any; type CompiledGraphTypeContext = Spec extends { context: infer Context extends Record; } ? Context : Record; type CompiledGraphTypeStreamTransformers = Spec extends { streamTransformers: infer Transformers; } ? Transformers extends ReadonlyArray<() => StreamTransformer> ? Transformers : Transformers extends ReadonlyArray> ? { readonly [K in keyof Transformers]: () => Transformers[K] } : Transformers extends StreamTransformer ? readonly [() => Transformers] : [] : []; /** * Convenience type for referencing a compiled graph by named type slots. * * @example * ```ts * type MyCompiledGraph = CompiledGraphType<{ * state: State; * update: Update; * streamTransformers: [ * StreamTransformer, * StreamTransformer, * ]; * }>; * ``` */ type CompiledGraphType = CompiledGraph, Spec extends { state: infer State; } ? State : any, Spec extends { update: infer Update; } ? Update : any, CompiledGraphTypeContext, Spec extends { input: infer Input; } ? Input : any, Spec extends { output: infer Output; } ? Output : any, Spec extends { nodeReturn: infer NodeReturn; } ? NodeReturn : unknown, Spec extends { command: infer Command; } ? Command : unknown, Spec extends { streamCustom: infer StreamCustom; } ? StreamCustom : any, CompiledGraphTypeStreamTransformers>; type NodeAction = RunnableLike$1 : U, LangGraphRunnableConfig>>; declare class Branch { path: Runnable; ends?: Record; constructor(options: Omit, "source">); run(writer: (dests: (string | Send)[], config: LangGraphRunnableConfig) => Runnable | void | Promise, reader?: (config: CallOptions) => IO): RunnableCallable; _route(input: IO, config: CallOptions, writer: (dests: (string | Send)[], config: LangGraphRunnableConfig) => Runnable | void | Promise, reader?: (config: CallOptions) => IO): Promise; } type NodeSpec = { runnable: Runnable; metadata?: Record; subgraphs?: Pregel[]; ends?: string[]; defer?: boolean; /** Whether this node is an auto-generated node-level error handler. */ isErrorHandler?: boolean; /** Name of the auto-generated error handler node to run on failure. */ errorHandlerNode?: string; }; /** * Return value type for node-level error handlers. * * Handlers may return a partial state update, a `Command`, or a Promise of either. * * @template Update - The update type (what fields can be returned) * @template Nodes - Union of valid node names for Command.goto */ type NodeErrorHandlerReturnValue = GraphNodeReturnValue; /** * A node-level error handler callable. * * Invoked with the node input state, a {@link NodeError} describing the failed * node and thrown error, and the runnable config. The handler runs ONLY after * the failing node's {@link RetryPolicy} is exhausted. It may return a state * update or a `Command` (to route via `goto`). */ type NodeErrorHandler, Nodes extends string = string> = (state: TState, error: NodeError, config?: LangGraphRunnableConfig) => NodeErrorHandlerReturnValue; type AddNodeOptions = { metadata?: Record; subgraphs?: Pregel[]; ends?: Nodes[]; defer?: boolean; }; declare class Graph$1 = NodeSpec, C extends StateDefinition = StateDefinition> { nodes: Record; edges: Set<[N | typeof START, N | typeof END]>; branches: Record>>; entryPoint?: string; compiled: boolean; constructor(); protected warnIfCompiled(message: string): void; get allEdges(): Set<[string, string]>; addNode(nodes: Record> | [key: K, action: NodeAction, options?: AddNodeOptions][]): Graph$1; addNode(key: K, action: NodeAction, options?: AddNodeOptions): Graph$1; addEdge(startKey: N | typeof START, endKey: N | typeof END): this; addConditionalEdges(source: BranchOptions>>): this; addConditionalEdges(source: N, path: RunnableLike$1>>, pathMap?: BranchOptions>>["pathMap"]): this; /** * @deprecated use `addEdge(START, key)` instead */ setEntryPoint(key: N): this; /** * @deprecated use `addEdge(key, END)` instead */ setFinishPoint(key: N): this; compile StreamTransformer> = []>({ checkpointer, interruptBefore, interruptAfter, name, transformers }?: { checkpointer?: BaseCheckpointSaver | false; interruptBefore?: N[] | All; interruptAfter?: N[] | All; name?: string; /** * Stream transformer factories baked into the compiled graph. These run * automatically for every `streamEvents(..., { version: "v3" })` call, * before any call-site transformers. */ transformers?: TTransformers; }): CompiledGraph, any, any, unknown, unknown, any, TTransformers>; validate(interrupt?: string[]): void; } declare class CompiledGraph = Record, InputType = any, OutputType = any, NodeReturnType = unknown, CommandType = unknown, StreamCustomType = any, TStreamTransformers extends ReadonlyArray<() => StreamTransformer> = []> extends Pregel>, Record, ContextType & Record, InputType, OutputType, InputType, OutputType, NodeReturnType, CommandType, StreamCustomType, TStreamTransformers> { "~NodeType": N; "~NodeReturnType": NodeReturnType; "~RunInput": Update; "~RunOutput": State; builder: Graph$1; constructor({ builder, ...rest }: { builder: Graph$1; } & PregelParams>, Record, TStreamTransformers>); withConfig StreamTransformer> = []>(config: Omit & { streamTransformers: TTransformers; }): CompiledGraph; withConfig(config: PregelOptions>, Record, ContextType & Record>): this; attachNode(key: N, node: NodeSpec): void; attachEdge(start: N | typeof START, end: N | typeof END): void; attachBranch(start: N | typeof START, name: string, branch: Branch): void; /** * Returns a drawable representation of the computation graph. */ getGraphAsync(config?: RunnableConfig & { xray?: boolean | number; }): Promise; /** * Returns a drawable representation of the computation graph. * * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release. */ getGraph(config?: RunnableConfig & { xray?: boolean | number; }): Graph; } //#endregion export { AddNodeOptions, Branch, CompiledGraph, CompiledGraphType, Graph$1 as Graph, NodeErrorHandler, NodeSpec }; //# sourceMappingURL=graph.d.cts.map