import type { TSchema } from "typebox"; import type { BranchCondition, ForeachSelector, LoopCondition, MapFn, StepDefinition, WorkflowDefinition } from "./types.ts"; /** Default loop guard: a loop that neither satisfies its condition nor errors within this many iterations crashes. */ export declare const DEFAULT_MAX_ITERATIONS = 100; /** Default concurrency ceiling (spec §3.6): the max steps executing at once across the whole run. */ export declare const DEFAULT_MAX_CONCURRENCY = 4; /** Default foreach concurrency (spec §3.4): sequential unless the author opts in. */ export declare const DEFAULT_FOREACH_CONCURRENCY = 1; export interface CreateWorkflowOptions { /** Unique workflow name/id — used by `/workflow list` and the run store (spec §1.5, §8.9). */ name: string; description?: string; /** * Optional top-level input schema (spec §3.9). `/workflow run --input` (spec §6.1) validates its * parsed payload against this before a run starts; `/workflow create` (spec §6.6) supplies its own * initial input directly rather than through the command line, since its input is a fixed shape * (the project root) known at every invocation, not something a caller varies per run. */ input?: TInputSchema; /** Default model (`provider/modelId`) for agent steps that declare none (spec §9.5). */ defaultModel?: string; /** * The concurrency ceiling (spec §3.6): bounds the total steps executing at once across every * construct in the run, including nested workflows (which inherit the ROOT run's ceiling). Default * {@link DEFAULT_MAX_CONCURRENCY}. A per-construct `concurrency` above this is rejected at `.commit()`. */ maxConcurrency?: number; } /** Options for a `.map()` construct. */ export interface MapOptions { /** Override the auto-generated step name (`map-1`, `map-2`, ...) used in the event log / run context. */ name?: string; } /** Options for a `.branch()` construct. */ export interface BranchOptions { /** Override the auto-generated node name (`branch-1`, ...). */ name?: string; } /** Options for a loop construct. */ export interface LoopOptions { /** Override the auto-generated node name (`loop-1`, ...). */ name?: string; /** Max iterations before the loop crashes (default {@link DEFAULT_MAX_ITERATIONS}). */ maxIterations?: number; } /** Options for a `.foreach()` construct. */ export interface ForeachOptions { /** Override the auto-generated node name (`foreach-1`, ...). */ name?: string; /** * How many items run at once (spec §3.4). Default {@link DEFAULT_FOREACH_CONCURRENCY} (sequential). * Rejected at `.commit()` if it exceeds the workflow's `maxConcurrency` ceiling (spec §3.6). */ concurrency?: number; } /** Options for a `.parallel()` construct. */ export interface ParallelOptions { /** Override the auto-generated node name (`parallel-1`, ...). */ name?: string; } /** Options for a `.workflow()` (nested-workflow) construct. */ export interface NestedWorkflowOptions { /** Override the node name (defaults to the sub-workflow's name). */ name?: string; } /** One `.branch()` arm: a pure condition paired with the sub-workflow to run when it holds. */ export type BranchArmSpec = readonly [BranchCondition, WorkflowDefinition]; /** * Builder finalized with `.commit()` (Mastra-inspired, spec §1.2/§3). Nodes: `.then()` / `.map()` * (steps), `.branch()` (multi-match), `.dowhile()` / `.dountil()` (loops), `.foreach()`, * `.parallel()` (structural fan-out). Branch arms and loop/foreach bodies are committed sub-workflows * executed recursively by the same engine. */ export interface WorkflowBuilder { /** Append a step node to run next in sequence (spec §3.1). */ then(step: StepDefinition): WorkflowBuilder; /** * Insert a pure transform whose result becomes the next node's input via the linear hand-off * (spec §3.7). Reads earlier, non-adjacent outputs via `ctx.getStepResult` / `ctx.getInitData`. */ map(transform: MapFn, options?: MapOptions): WorkflowBuilder; /** * Multi-match branch (spec §3.2): every arm whose condition holds runs sequentially; the node's * output is an object keyed by the executed arm names (each arm name is its body's workflow name). */ branch(arms: readonly BranchArmSpec[], options?: BranchOptions): WorkflowBuilder; /** Loop (spec §3.3): run `body`, then repeat while `condition` holds; output is the last body output. */ dowhile(body: WorkflowDefinition, condition: LoopCondition, options?: LoopOptions): WorkflowBuilder; /** Loop (spec §3.3): run `body`, then repeat until `condition` holds; output is the last body output. */ dountil(body: WorkflowDefinition, condition: LoopCondition, options?: LoopOptions): WorkflowBuilder; /** * Foreach (spec §3.4): run `body` once per item selected by `selector` (pure), with the item as the * body's input. `options.concurrency` (default 1) bounds how many items run at once. Output is the * array of per-item outputs, in item order — independent of completion order. * * **Author contract (spec §8.3, "non-overlapping side effects"):** at `concurrency > 1`, items run * genuinely concurrently — the engine does not, and cannot, know what a step or its subagent will * touch, so it enforces nothing here. Give each item's body its own files/branches/external * resources; anything shared across items (two agents editing the same file, say) must be sequenced * — either keep `concurrency` at 1, or restructure so the shared resource is touched outside the * fan-out. */ foreach(body: WorkflowDefinition, selector: ForeachSelector, options?: ForeachOptions): WorkflowBuilder; /** * Parallel (spec §3.5): structural fan-out over independent STEPS — every arm runs concurrently * against the same input, bounded only by the workflow ceiling (spec §3.6). Output is an object * keyed by each arm's own step name, independent of completion order. * * **Author contract (spec §8.3, "non-overlapping side effects"):** every arm runs genuinely * concurrently — the same rule as `.foreach`'s doc above applies per arm here: no two arms may touch * the same file, branch, or external resource, since the engine has no way to detect or prevent two * concurrent agents rewriting the same working-tree state. Sequence anything that shares state with * `.then()` instead of putting it in the same `.parallel([...])`. */ parallel(arms: readonly StepDefinition[], options?: ParallelOptions): WorkflowBuilder; /** * Nested workflow (spec §2.3/§11): run a committed sub-workflow's nodes here, transparently folding * into the parent run/log. Output is the sub-workflow's final output. Every step/node name must be * unique across the flattened tree, so nesting the *same* sub-workflow twice is a `commit()` error. */ workflow(subWorkflow: WorkflowDefinition, options?: NestedWorkflowOptions): WorkflowBuilder; /** Finalize the workflow definition. */ commit(): WorkflowDefinition; } export declare function createWorkflow(options: CreateWorkflowOptions): WorkflowBuilder; //# sourceMappingURL=create-workflow.d.ts.map