import { type ConditionInput, type ConditionModel, type ConditionOptions } from "./Condition"; import type { Destination } from "./Destination"; import type { ConverseOptions, EndOptions, NodeUpdate, ToolOptions, ToolRef, TransferOptions, WorkflowGraph } from "./WorkflowGraph"; export interface WhenOptions { /** Condition for coming back along this edge, from the new node to this one. */ back?: ConditionInput; } /** The branches of a tool node, for `onResult()`. Each callback gets the branch `onSuccess()` or `onFailure()` opens. */ export interface ResultBranches { /** Followed when every tool in the node succeeded. */ success?: (branch: WorkflowBranch) => unknown; /** Followed when any tool in the node failed. */ failure?: (branch: WorkflowBranch) => unknown; } export interface GoToOptions { /** Condition for coming back along this edge, from the target to this node. */ back?: ConditionInput; } /** @internal Where the next edge starts and which conditions it carries. */ export interface EdgeOrigin { source: string; forwardCondition: ConditionModel; backwardCondition?: ConditionModel; } /** * The verbs that add a node and connect it to the current point in the workflow. Each returns the new node, so * linear flows chain: `wf.converse(...).when("...").tool(...)`. */ export declare abstract class WorkflowChain { /** @internal */ protected readonly _graph: WorkflowGraph; protected constructor(graph: WorkflowGraph); /** @internal */ protected abstract _origin(): EdgeOrigin; /** * The agent holds a conversation with `prompt` added to its instructions, until an outgoing condition holds. * A subagent node in the API and the UI. */ converse(id: string, prompt: string, options?: ConverseOptions): WorkflowNode; /** * Runs the tools in parallel. Branch on the result with `onSuccess()` and `onFailure()`. Each tool is an id, or a * `Tool` object whose id is filled in when the workflow is built with `toolIds`, as `agents.push()` does. */ tool(id: string, toolIds: ToolRef[], options?: ToolOptions): WorkflowNode; /** Transfers the conversation to a phone number, SIP URI or another agent. */ transfer(id: string, destination: Destination, options?: TransferOptions): WorkflowNode; /** Ends the conversation. Every `end()` without an id shares one end node, `"end"`. */ end(options?: EndOptions): WorkflowNode; /** * Moves the conversation to a node that already exists (or will by the time you call `build()`), for merges * and loops. */ goTo(target: WorkflowNode | string, options?: GoToOptions): WorkflowNode; private _connect; } /** A pending edge out of a node, opened by `when()`, `onSuccess()` or `onFailure()`. */ export declare class WorkflowBranch extends WorkflowChain { private readonly _from; /** @internal */ constructor(graph: WorkflowGraph, origin: EdgeOrigin); /** @internal */ protected _origin(): EdgeOrigin; } /** A handle to one node in a workflow. Handles are cheap: all state lives in the `Workflow`. */ export declare class WorkflowNode extends WorkflowChain { readonly id: string; private readonly _parentId; /** @internal */ constructor(graph: WorkflowGraph, id: string, parentId?: string); /** The API node type, e.g. `"override_agent"` or `"tool"`. */ get type(): string | undefined; /** Opens a branch that is followed when `condition` holds. A string is an LLM condition. */ when(condition: ConditionInput, options?: WhenOptions): WorkflowBranch; /** Opens the branch followed when every tool in this tool node succeeded. */ onSuccess(options?: ConditionOptions): WorkflowBranch; /** Opens the branch followed when any tool in this tool node failed. */ onFailure(options?: ConditionOptions): WorkflowBranch; /** * Routes both outcomes of this tool node in one place. Same as calling `onSuccess()` and then `onFailure()`, so * the success edge always comes first. Returns this node. */ onResult(branches: ResultBranches): this; /** * The node this handle was chained from, so a whole workflow can be written as one chain. For a handle from * `node()`, the source of the first edge into the node. The start node if there is neither. * * @example * wf.converse("triage", "Find out what the caller needs") * .when("Caller wants a human").transfer("human", Destination.phone("+15551234567")).up() * .when("Caller is done").end(); */ up(): WorkflowNode; /** Changes this node's options. Only fields that apply to the node's kind may be set. */ update(options: NodeUpdate): this; /** @internal */ protected _origin(): EdgeOrigin; } /** @internal */ export declare function branch(graph: WorkflowGraph, source: string, condition: ConditionInput, options?: WhenOptions): WorkflowBranch;