/** * Step-based workflow context — progressive disclosure API. * * Bridges plain async functions with the generator protocol used internally * by the engine. Users write `await ctx.step(name, fn)` and the compiler * produces a generator that yields one operation at a time. * * @module core/step-context */ import type { StepWorkflowContext, WorkflowFunction } from './types.ts'; interface QueuedOperation { /** Explicit, user-supplied step name. Used as the durable activity label. */ name: string; /** The zero-argument step body. Executed by the engine as an inline activity. */ fn: () => unknown; resolve: (value: unknown) => void; reject: (reason: unknown) => void; } /** * Internal implementation of {@link StepWorkflowContext} for step-based * ("progressive disclosure") workflows. Each `step()` call is a thin async * enqueue; the compiled generator (see {@link compileStepWorkflow}) drains the * queue and runs each step through the engine's durable activity machinery, so * a completed step is replayed from the checkpoint rather than re-executed * after a crash. Build via {@link compileStepWorkflow} rather than constructing * directly. * * @example * ```ts * import { StepContext } from '@lostgradient/weft'; * * const controller = new AbortController(); * const ctx = new StepContext('wf-demo', controller.signal); * ctx.step('fetch', async () => ({ name: 'Alice' })).then(console.log); * void ctx; * ``` */ export declare class StepContext implements StepWorkflowContext { #private; readonly workflowId: string; readonly signal: AbortSignal; constructor(workflowId: string, signal: AbortSignal); step(name: string, fn: () => Promise | T): Promise; /** Called by the generator loop to wait for the next operation. */ dequeue(): Promise; /** Unblocks dequeue() when the user function completes. */ signalDone(): void; } /** * Wraps a {@link StepWorkflowFunction} (a plain `async function` using * `ctx.step`) into a durable {@link WorkflowFunction} generator that the * engine can register and persist. This bridges the "progressive disclosure" * API with the underlying generator protocol. * * @example * ```ts * import { workflow, Engine, compileStepWorkflow, type StepWorkflowContext } from '@lostgradient/weft'; * * async function process(ctx: StepWorkflowContext, input: unknown) { * const upper = await ctx.step('uppercase', () => * (input as string).toUpperCase(), * ); * return upper; * } * * const engine = new Engine(); * engine.register(workflow({ name: 'process' }).execute(compileStepWorkflow(process))); * const result = await (await engine.start('process', 'hello')).result(); * console.log(result); // 'HELLO' * ``` */ export declare function compileStepWorkflow(stepFunction: (context: StepWorkflowContext, input: TInput) => Promise): WorkflowFunction; /** Returns `true` if `fn` is a sync generator function (`function*`). */ export declare function isGeneratorFunction(fn: Function): boolean; /** * Returns `true` if `fn` is an async generator function (`async function*`). * * @example * ```ts * import { isAsyncGeneratorFunction } from '@lostgradient/weft'; * * async function* myWorkflow() { yield 1; } * function* syncGen() { yield 1; } * async function asyncFn() { return 1; } * * console.log(isAsyncGeneratorFunction(myWorkflow)); // true * console.log(isAsyncGeneratorFunction(syncGen)); // false * console.log(isAsyncGeneratorFunction(asyncFn)); // false * ``` */ export declare function isAsyncGeneratorFunction(fn: Function): boolean; /** * Check if a value is a Generator or AsyncGenerator object (not just any iterable). * Arrays, Maps, Sets, etc. are NOT matched — only actual generator instances. * * The prototype chain for a generator instance is: * gen -> genFn.prototype -> Generator.prototype * We compare the shared parent prototype so lookalike iterators do not match. */ export declare function isGeneratorResult(value: unknown): boolean; export {};