import { a as PersistedValue, o as RetryConfig } from "./types-nm947ViN.mjs"; import { StandardSchemaV1 } from "@standard-schema/spec"; //#region src/core/workflow.d.ts /** Context passed to every step handler. */ interface StepContext = Record> { /** The validated workflow input (same for every step in the run). */ input: TInput; /** The return value of the previous step (`undefined` for the first step). */ prev: TPrev; /** Aborted on cancellation, lease loss, or step timeout. */ signal: AbortSignal; /** Complete the workflow early, skipping remaining steps. Optionally persist a value as the final result. */ complete: (value?: PersistedValue) => never; /** Results of all previously completed steps, keyed by step name. */ steps: TStepsSoFar; } /** Internal representation of a step used by the engine. */ interface StepDefinition { name: string; handler: (ctx: StepContext>) => Promise; retry?: RetryConfig; timeoutMs?: number; } /** A single execution unit: either a sequential step or a parallel group. */ type ExecutionUnit = { readonly kind: 'step'; readonly definition: StepDefinition; } | { readonly kind: 'parallel'; readonly branches: readonly StepDefinition[]; }; /** Configuration object form for `.step()` when you need retry or timeout options. */ interface StepConfig = Record> { retry?: RetryConfig; /** Timeout per attempt in milliseconds. Takes precedence over `retry.timeoutMs`. */ timeoutMs?: number; handler: (ctx: StepContext) => Promise; } /** A parallel branch: either a bare handler or a StepConfig with retry/timeout. */ type ParallelBranch = Record> = ((ctx: StepContext) => Promise) | StepConfig; /** Extract the output type from a ParallelBranch. */ type InferBranchOutput = B extends ((ctx: never) => Promise) ? O : B extends { handler: (ctx: never) => Promise; } ? O : never; /** Context passed to the `onFailure` handler when a workflow run fails. */ interface FailureContext { /** The error that caused the failure. */ error: Error; /** The name of the step that failed. */ stepName: string; /** The original validated workflow input. */ input: TInput; } /** * A typed workflow definition. * * @typeParam TName - Literal string name of the workflow (e.g. `'order-fulfillment'`) * @typeParam TInput - The validated input schema type * @typeParam TPrev - The output type of the most recently added step (used for chaining) * @typeParam TSteps - Accumulated map of `{ stepName: outputType }` across `.step()` calls */ interface Workflow = Record> { readonly name: TName; readonly inputSchema: StandardSchemaV1; readonly executionUnits: readonly ExecutionUnit[]; readonly failureHandler?: (ctx: FailureContext) => Promise; step(name: TStepName, handler: (ctx: StepContext) => Promise): Workflow, TSteps & Record>>; step(name: TStepName, config: StepConfig): Workflow, TSteps & Record>>; parallel>>(branches: TBranches): Workflow> }>, TSteps & { [K in keyof TBranches & string]: NormalizeOutput> }>; onFailure(handler: (ctx: FailureContext) => Promise): Workflow; parseInput(input: unknown): TInput; } type AnyWorkflow = Workflow; /** Extract the input type from a Workflow */ type InferInput = W extends Workflow ? I : never; /** Extract the accumulated steps map from a Workflow */ type InferSteps = W extends Workflow ? S : never; /** Map a workflow tuple/array to `{ workflowName: inputType }` */ type WorkflowInputMap = { [W in T[number] as W extends Workflow ? N : never]: InferInput }; /** Map a workflow tuple/array to `{ workflowName: stepsRecord }` */ type WorkflowStepsMap = { [W in T[number] as W extends Workflow ? N : never]: InferSteps }; /** Flatten intersection types for readable IDE tooltips */ type Prettify = { [K in keyof T]: T[K] } & {}; type NormalizeOutput = Exclude | (void extends T ? undefined : never); /** * Create a new workflow definition. * * @example * ```ts * const workflow = createWorkflow({ * name: 'process-content', * input: z.object({ url: z.string() }), * }) * .step('scrape', async ({ input }) => { ... }) * .step('summarize', async ({ prev }) => { ... }) * ``` */ declare function createWorkflow(config: { name: TName; input: StandardSchemaV1; }): Workflow; //#endregion export { InferInput as a, StepConfig as c, Workflow as d, WorkflowInputMap as f, InferBranchOutput as i, StepContext as l, createWorkflow as m, ExecutionUnit as n, InferSteps as o, WorkflowStepsMap as p, FailureContext as r, ParallelBranch as s, AnyWorkflow as t, StepDefinition as u }; //# sourceMappingURL=workflow-Cic2yHNB.d.mts.map