Skip to content

Interface: FlowBuilder<TIn, THandle, TStepIds, TReceipt, TCustomMetrics, TStepOutputs> ​

Defined in: builders/flow-builder.ts:34

Fluent builder for a declarative multi-step workflow (P.flow(id)).

Threads THandle, TReceipt, TCustomMetrics, TStepIds, and TStepOutputs across sequential .step() and conditional .branch() declarations while enforcing scope capability tiers at .toAST() compilation time.

Extends ​

Type Parameters ​

Type ParameterDefault typeDescription
TInunknownValidated flow input payload type.
THandleunknownRuntime handle type of the flow's isolation scope.
TStepIds extends stringneverUnion of literal step and branch identifiers registered in nodes.
TReceiptunknownInspected scope receipt type inferred from .scope(scope).
TCustomMetrics extends Record<string, unknown>Record<string, unknown>Custom step telemetry metrics type inferred from .telemetry(collector).
TStepOutputs extends Record<string, unknown>Record<string, never>Typed map of completed step and branch outputs indexed by literal step ID.

Methods ​

branch() ​

ts
branch<TBranchId, TBranchOut>(id, configure): FlowBuilder<TIn, THandle, TStepIds | TBranchId, TReceipt, TCustomMetrics, TStepOutputs & { readonly [K in string]: TBranchOut }>;

Defined in: builders/flow-builder.ts:132

Appends a conditional multi-way branch to the flow and records its unified output type under TStepOutputs[TBranchId].

Adds TBranchId to TStepIds and validates that the branch has an output schema, at least one when, and an otherwise.

Type Parameters ​

Type ParameterDescription
TBranchId extends stringLiteral branch identifier string.
TBranchOutUnified branch output payload type.

Parameters ​

ParameterTypeDescription
idTBranchIdUnique branch identifier.
configure($b) => FlowBranchBuilder<TIn, TBranchOut, THandle, TBranchId, TReceipt, TCustomMetrics, TStepOutputs>Branch configurator callback.

Returns ​

FlowBuilder<TIn, THandle, TStepIds | TBranchId, TReceipt, TCustomMetrics, TStepOutputs & { readonly [K in string]: TBranchOut }>

New immutable flow builder.


exit() ​

ts
exit(exitState): FlowBuilder<TIn, THandle, TStepIds, TReceipt, TCustomMetrics, TStepOutputs>;

Defined in: builders/flow-builder.ts:155

Sets the terminal exit state label recorded when the flow completes its final node.

Required before .toAST() can compile a valid FlowNode.

Parameters ​

ParameterTypeDescription
exitStatestringTerminal exit state label (e.g. 'done').

Returns ​

FlowBuilder<TIn, THandle, TStepIds, TReceipt, TCustomMetrics, TStepOutputs>

New immutable flow builder.


input() ​

ts
input<TNewIn>(schema): FlowBuilder<TNewIn, THandle, TStepIds, TReceipt, TCustomMetrics, TStepOutputs>;

Defined in: builders/flow-builder.ts:56

Binds the Zod validation schema for the work item input entering the flow.

Narrows TIn to TNewIn for all subsequent step input mappers and branch predicates.

Type Parameters ​

Type ParameterDescription
TNewInValidated flow input payload type.

Parameters ​

ParameterTypeDescription
schemaZodType<TNewIn>Zod schema validating flow input.

Returns ​

FlowBuilder<TNewIn, THandle, TStepIds, TReceipt, TCustomMetrics, TStepOutputs>

New immutable flow builder.


scope() ​

ts
scope<TScope>(scope): FlowBuilder<TIn, ExtractScopeHandle<TScope>, TStepIds, ExtractScopeReceipt<TScope>, TCustomMetrics, TStepOutputs>;

Defined in: builders/flow-builder.ts:71

Binds the capability-tiered IsolationScopeASTNode governing workspace lifecycle, checkpoints, and branching.

Infers both ExtractScopeHandle<TScope> and ExtractScopeReceipt<TScope> from scope.

Type Parameters ​

Type ParameterDescription
TScope extends IsolationScopeASTNodeIsolation scope AST node type.

Parameters ​

ParameterTypeDescription
scopeMaybeBuilder<TScope>Isolation scope AST node or builder.

Returns ​

FlowBuilder<TIn, ExtractScopeHandle<TScope>, TStepIds, ExtractScopeReceipt<TScope>, TCustomMetrics, TStepOutputs>

New immutable flow builder.


step() ​

ts
step<TStepId, TStep>(
   id, 
   step, 
   configure?
): FlowBuilder<TIn, THandle, TStepIds | TStepId, TReceipt, TCustomMetrics, TStepOutputs & { readonly [K in string]: ExtractStepOutput<TStep> }>;

Defined in: builders/flow-builder.ts:104

Appends a sequential step to the flow and records its output type under TStepOutputs[TStepId].

Adds TStepId to TStepIds so lane.onSignal(...).rewindTo(stepId) is type-checked against known step IDs.

Type Parameters ​

Type ParameterDescription
TStepId extends stringLiteral step identifier string.
TStep extends StepASTNodeStep AST node type.

Parameters ​

ParameterTypeDescription
idTStepIdUnique step identifier.
stepMaybeBuilder<TStep>Step AST node or builder.
configure?($s) => FlowStepConfigBuilder<TIn, ExtractStepInput<TStep>, THandle, TReceipt, TCustomMetrics, TStepOutputs, TStepId>Optional step input and interrupt configurator.

Returns ​

FlowBuilder<TIn, THandle, TStepIds | TStepId, TReceipt, TCustomMetrics, TStepOutputs & { readonly [K in string]: ExtractStepOutput<TStep> }>

New immutable flow builder.


telemetry() ​

ts
telemetry<TCollector>(collector): FlowBuilder<TIn, THandle, TStepIds, TReceipt, ExtractTelemetryMetrics<TCollector>, TStepOutputs>;

Defined in: builders/flow-builder.ts:86

Binds an optional TelemetryCollectorASTNode folding observed ToolEffect lists into custom metrics.

Infers ExtractTelemetryMetrics<TCollector> for downstream .replaceWith(...) telemetry callbacks.

Type Parameters ​

Type ParameterDescription
TCollector extends FsTelemetryCollectorNodeTelemetry collector AST node type.

Parameters ​

ParameterTypeDescription
collectorMaybeBuilder<TCollector>Telemetry collector AST node or builder.

Returns ​

FlowBuilder<TIn, THandle, TStepIds, TReceipt, ExtractTelemetryMetrics<TCollector>, TStepOutputs>

New immutable flow builder.


toAST() ​

ts
toAST(): FlowNode;

Defined in: ast/ast-builder.ts:20

Compiles the current builder configuration into a deeply frozen passive AST node.

Validates required builder invariants at compilation time and returns an immutable plain-object AST representation containing zero execution methods.

Returns ​

FlowNode

Deeply frozen passive AST node.

Inherited from ​

AstBuilder.toAST

Properties ​

PropertyModifierTypeDescriptionDefined in
idreadonlystringUnique identifier of the flow.builders/flow-builder.ts:43

Released under the MIT License.