import type { ChannelSchema, CompileOptions, EdgeRouter, GraphCheckpoint, GraphDescription, GraphEvent, GraphEventsOptions, GraphInput, GraphProgress, GraphResult, GraphRunOptions, GraphStatus, GraphStepEvent, NodeFn, NodeOptions, StateUpdate } from '../types/graph.js'; import { GraphEventStream } from './event-stream.js'; interface GraphNodeDefinition { fn: NodeFn; options: NodeOptions; } /** * The function that hands a nested run's events to the run of the node whose context this is, under * the node's namespace, or `undefined` when that run did not ask for subgraph events. For a node that * starts runs of its own, such as an agent's tools starting a helper. */ export declare function forwardedEvents(context: object): ((event: GraphEvent) => void) | undefined; /** 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; /** The checkpoint writers of runs in progress, so `flush()` can wait for them. */ private readonly writers; constructor(channels: S, nodes: Map>, edges: Array>, options: CompileOptions, scope?: GraphScope); /** * Waits until every checkpoint written by runs in progress is in the store. Only `async` and * `exit` durability leave any outstanding; a run always waits for its own before it returns. */ flush(): Promise; /** 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>; /** * Runs the graph as one stream of typed events: the state after each superstep, each task's write, * model output as nodes stream it, tool calls, task progress, checkpoints, and custom events. * * Iterate it for everything included, or read one projection with `messages()`, `tools()`, * `values()`, or `updates()`. Each reader has its own bounded buffer, and the run waits for the * slowest at the end of every superstep, so a slow reader slows the graph rather than filling * memory. `result` resolves with the run's result. */ events(input?: GraphInput, options?: GraphEventsOptions): GraphEventStream; /** Like `events()`, answering the question a paused thread is waiting on. */ resumeEvents(threadId: string, value: unknown, options?: GraphEventsOptions): GraphEventStream; /** Like `events()`, carrying a thread on from a breakpoint, a drain, or a failure. */ continueEvents(threadId: string, options?: GraphEventsOptions): GraphEventStream; private eventStream; /** * 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>; /** * Like `continue`, but returns the final result rather than the stream: what a replica calls to * finish a run whose process stopped, from the last checkpoint it wrote. */ continueWith(threadId: string, runOptions?: GraphRunOptions): Promise>; /** * 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`. With a `tenantId`, a thread another tenant owns reads * as absent. */ state(threadId: string, step?: number, options?: { tenantId?: string; }): Promise | undefined>; /** Checkpoints for a thread, newest first. With a `tenantId`, another tenant's thread has none. */ history(threadId: string, limit?: number, options?: { tenantId?: string; }): 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; tenantId?: 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`, and keeps the tenant of the thread it came from. * With a `tenantId`, another tenant's thread is not found. */ fork(threadId: string, options?: { step?: number; threadId?: string; tenantId?: string; }): Promise; /** * Runs the supersteps, as one operation of the compiled lifecycle when there is one. The run is * admitted before its first superstep and finishes with its last, however it ends. */ private run; /** * Runs the step loop with a checkpoint writer for the run's durability mode. However the run ends, * every checkpoint it handed over is in the store before this returns or throws. */ private runSteps; private steps; /** Runs one task to a verdict, applying its retry policy and timeout. */ private runTask; /** * Hands a failure to the node's `onError`, and turns what it decides into the task's result. With * no handler, or for a mistake in the graph itself, the task fails as it always did. */ private recover; /** The node's retry policy over the graph's defaults. */ private retryPolicy; /** The node's run and idle limits over the graph's defaults. `timeout.runMs` wins over `timeoutMs`. */ private timeoutOf; private errorHandler; 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; /** * Completes a checkpoint in the current schema and persists it. 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 };