import type { ChannelSchema, CompileOptions, EdgeRouter, GraphCheckpoint, GraphDescription, GraphInput, GraphProgress, GraphResult, GraphRunOptions, GraphStatus, GraphStepEvent, NodeFn, NodeOptions, StateUpdate } from '../types/graph.js'; interface GraphNodeDefinition { fn: NodeFn; options: NodeOptions; } /** Which channels a caller may write and read, as `createGraph()` declared them. */ interface GraphScope { input?: readonly string[]; output?: readonly string[]; } interface Edge { from: string; to?: string; router?: EdgeRouter; /** Maps a router's return value onto node names, so a router can return a domain word. */ mapping?: Record; } /** * Builds a typed state graph. * * Nodes read a frozen state and return an update; channels decide how updates combine. Edges may be * static or conditional, may form cycles, and a compiled graph can be used as a node inside another * graph. */ export declare class StateGraph { private readonly channels; private readonly scope; private readonly nodes; private readonly edges; constructor(channels: S, scope?: GraphScope); /** Adds a node. Returns the graph, for chaining. */ addNode(name: string, fn: NodeFn, options?: NodeOptions): this; /** Adds an edge that always runs `to` after `from`. Returns the graph, for chaining. */ addEdge(from: string, to: string): this; /** * Routes on state after `from` runs. * * Returning an array fans out: every named node runs in the next superstep and their writes are * combined by the channel reducers. */ addConditionalEdges(from: string, router: EdgeRouter, mapping?: Record): this; /** Names the first node. Equivalent to an edge from `START`. */ setEntry(node: string): this; /** Validates the shape and returns something runnable. */ compile(options?: CompileOptions): CompiledGraph; } /** A validated graph, ready to run. */ export declare class CompiledGraph { private readonly channels; private readonly nodes; private readonly edges; private readonly options; private readonly scope; private readonly now; private readonly store; /** Loaded the first time a node that declares `cache` runs, and not before. */ private nodeCache; constructor(channels: S, nodes: Map>, edges: Array>, options: CompileOptions, scope?: GraphScope); /** Runs to completion, to an interrupt, or to the step limit. */ invoke(input?: GraphInput, runOptions?: GraphRunOptions): Promise>; /** Yields one event per superstep, so a caller can render progress as it happens. */ stream(input?: GraphInput, runOptions?: GraphRunOptions): AsyncIterable>; /** * Supplies the value a node asked for and continues. * * The interrupted node runs again from the top; `context.interrupt()` returns `value` this time * instead of throwing. A node that interrupts should therefore keep the work before the interrupt * cheap and free of side effects, because it happens twice. */ resume(threadId: string, value: unknown, runOptions?: GraphRunOptions): AsyncIterable>; /** Like `resume`, but returns the final result rather than the stream. */ resumeWith(threadId: string, value: unknown, runOptions?: GraphRunOptions): Promise>; /** * Answers several of a paused step's questions at once, keyed by interrupt id. * * Parallel tasks can each ask something, so one answer is not always enough. Questions left * unanswered are asked again when the step runs. */ resumeInterrupts(threadId: string, answers: Record, runOptions?: GraphRunOptions): AsyncIterable>; /** Like `resumeInterrupts`, but returns the final result rather than the stream. */ resumeInterruptsWith(threadId: string, answers: Record, runOptions?: GraphRunOptions): Promise>; /** Continues a thread that stopped for any other reason, such as the step limit. */ continue(threadId: string, runOptions?: GraphRunOptions): AsyncIterable>; /** * Rewinds to an earlier superstep and runs forward from there. * * Checkpoints after `step` belong to the timeline being abandoned, so the checkpointer drops them * once the rewound checkpoint is written. */ resumeFrom(threadId: string, step: number, runOptions?: GraphRunOptions): AsyncIterable>; /** Latest checkpoint, or the one at `step`. */ state(threadId: string, step?: number): Promise | undefined>; /** Checkpoints for a thread, newest first. */ history(threadId: string, limit?: number): Promise>>; /** * Wraps this graph as a node in another graph. * * The subgraph runs to completion within one superstep of the parent. Channels the two graphs * share by name are passed in and merged back; anything else stays private to the subgraph. * * When the subgraph interrupts, the parent interrupts with the same question. Resuming the parent * passes the answer into the subgraph, which continues where it stopped rather than starting over. */ asNode

(): NodeFn

; /** * The graph's shape as plain data: nodes, edges, and which routes are chosen at run time. * * What `nexus-ai-pro/graph/visualize` draws, and what a UI or a test can inspect without running * anything. Subgraphs added through `asNode()` are described inside the node that runs them. */ describe(): GraphDescription; /** * Edits a thread's state. * * Without `asNode`, the update is merged into the latest checkpoint in place, through the channel * reducers, and the run continues exactly where it was — including a thread paused for input. * With `asNode`, the update is applied as if that node had just produced it: a new checkpoint is * written and the next step follows that node's edges. That is how an operator corrects a wrong * intermediate result and lets the rest of the graph run on the fix. */ updateState(threadId: string, update: StateUpdate, options?: { asNode?: string; }): Promise>; /** * Copies a thread's history up to `step` into a new thread, and returns the new thread's id. * * Rewinding with `resumeFrom()` replaces the original timeline. A fork keeps it: both threads stay * readable and runnable, so two answers to the same question can be compared side by side. Every * copied checkpoint records `metadata.forkedFrom`. */ fork(threadId: string, options?: { step?: number; threadId?: string; }): Promise; private run; /** Runs one task to a verdict, applying its retry policy and timeout. */ private runTask; private runNode; private loadNodeCache; /** Rejects writes to channels the graph does not accept from a caller. */ private assertInput; /** State as a caller sees it: the output channels, when the graph declared them. */ private visible; /** Combines this superstep's writes into state through each channel's reducer. */ private reduce; /** Follows every edge out of the nodes that ran, producing the next step's tasks. */ private nextTasks; private entryNodes; private seedState; private requireCheckpoint; /** Persists a checkpoint. The store keeps opaque state; the schema stays this class's business. */ private save; private checkpointResult; private checkpointer; private toEvent; private toResult; } /** * Starts a graph definition. * * `input` and `output` restrict which channels a caller may set and which come back, so working * channels stay internal. Both default to every channel. As a subgraph, a graph receives only its * input channels from the parent and merges back only its output channels. Checkpoints, `state()`, * and stream events still carry the whole state, because they describe the thread rather than * answer a caller. */ export declare function createGraph(config: { channels: S; input: readonly []; output: readonly []; }): StateGraph; export declare function createGraph(config: { channels: S; input: readonly []; output?: readonly O[]; }): StateGraph; export declare function createGraph(config: { channels: S; input?: readonly I[]; output: readonly []; }): StateGraph; export declare function createGraph(config: { channels: S; input?: readonly I[]; output?: readonly O[]; }): StateGraph; export type { GraphProgress, GraphStatus };