/**
* LangGraph-inspired typed workflow graph with conditional edges.
*
* Phase-3 sibling of the reference engine's workflow primitive. A `Workflow`
* is a state machine: **nodes** transform a typed state value and **edges** —
* static or **conditional** — determine the next node to execute. The runner
* starts at the entry node, applies each node then follows its outgoing edge,
* until it reaches the `END` sentinel (or a node with no outgoing edge), then
* returns the final state.
*
* Nodes may be sync or async; the runner awaits their results. A `maxSteps` cap
* bounds execution so an intentional or accidental cycle can't loop forever.
*
* Standalone module — it does not touch the agent loop. The point is the seam: a
* multi-step orchestration (parse → guardrails → retrieve → compose → …) drops in
* as a graph of named nodes with the routing made explicit.
*/
/** Sentinel a conditional router can return to signal termination. */
export declare const END: "__end__";
/** A node transforms state into a new state; may be sync or async. */
export type NodeFn = (state: S) => S | Promise;
/** A conditional router inspects state and returns the next node name (or `END`). */
export type Router = (state: S) => string;
/** Thrown when a workflow is misconfigured or exceeds its step limit. */
export declare class WorkflowError extends Error {
constructor(message: string);
}
/**
* A typed workflow graph: named nodes connected by static/conditional edges.
*
* Build with `addNode`, `addEdge` / `addConditionalEdge`, `setEntry`, and
* `setEnd`; the builder methods return `this` so they chain. `run` executes the
* graph from the entry node.
*/
export declare class Workflow {
private readonly maxSteps;
private readonly nodes;
private readonly edges;
private entry;
constructor(maxSteps?: number);
/** Register a node `func` under `name` (used to reference it in edges). */
addNode(name: string, func: NodeFn): this;
/** Add a static edge `from` → `to`. */
addEdge(from: string, to: string): this;
/**
* Add a conditional edge whose `router` picks the next node at runtime. The
* router returns the target node name, or `END` to terminate the workflow.
*/
addConditionalEdge(from: string, router: Router): this;
/** Set the entry node (first node to execute). */
setEntry(name: string): this;
/** Mark `from` as terminal — reaching it ends the workflow. */
setEnd(from: string): this;
/**
* Execute the workflow from the entry node, returning the final state.
*
* Throws {@link WorkflowError} if no entry node was set, a referenced node
* does not exist, or the `maxSteps` cap is exceeded (e.g. an unbroken cycle).
*/
run(initialState: S): Promise;
}
/**
* Wrap a child {@link Workflow} as a single node of a parent workflow.
*
* The child runs **to completion** — every node, its conditional edges and the
* `END` sentinel included — inside one parent step. That is the contrast with a
* conversational driver that advances the top-level graph one node per user
* turn: a sub-workflow node executes its whole sub-graph within that one turn,
* and the top level stays turn-gated.
*
* The result is an ordinary {@link NodeFn}: `addEdge` and `addConditionalEdge`
* treat it exactly like a plain node, as an edge source and as an edge target
* alike. Plain nodes and sub-workflows are therefore interchangeable vertices of
* one composite graph, and they nest arbitrarily — a sub-workflow may itself
* contain sub-workflows.
*
* `mapIn` projects parent state into the child's state type; `mapOut` folds the
* child's final state back into the parent's. An error from any child node
* propagates out of the parent's `run`.
*/
export declare function subWorkflowNode
(child: Workflow ;
//# sourceMappingURL=workflow.d.ts.map