/** * @fileoverview Core pipeline executor * * Provides the `executePipeline()` function — the transport-agnostic * implementation of pipeline execution with variable resolution, * conditional steps, and metadata aggregation. * * Separated from `pipeline.ts` to keep both modules within the * repository file-size convention. */ import type { PipelineRequest, PipelineResult } from './pipeline.js'; import type { CommandResult } from './result.js'; /** * Function signature for executing a single command. * * The core pipeline executor is decoupled from command registration. * The server (or any host) provides this callback so the core module * stays agnostic of how commands are resolved and invoked. */ export type CommandExecutor = (commandName: string, input: unknown, context: Record) => Promise; /** * Execute a pipeline of chained commands with variable resolution. * * This is the core implementation used by both the MCP server and * any other host that needs pipeline semantics. It supports: * - Sequential step execution with `$prev`, `$first`, `$steps`, `$input` variable resolution * (see `spec/pipeline-variables.md`) * - Conditional steps via `when` clauses * - `continueOnFailure` and `timeoutMs` options * - Full metadata aggregation (confidence, reasoning, warnings, sources, alternatives) * * The request is validated before any step runs: a malformed envelope fails with * `INVALID_PIPELINE_REQUEST`, and step inputs or a request `input` nested deeper than 64 levels * fail with `VALIDATION_ERROR`. Options the envelope accepts but the executor does not * implement, `options.parallel` and a step's `stream: true`, fail that step (step 0 for * `parallel`) with `UNSUPPORTED_OPTION` and skip every other step, so no command runs. * Each step's data is copied (`structuredClone`) as it enters the * pipeline context and again when a reference resolves it, so a handler that mutates its input * cannot change another step's data. * * **Behavior change:** `$input` resolves to `request.input`. It used to resolve to `context`, * which exposed the host's trace IDs, auth and other execution values to pipeline references. * * @param request - The pipeline request describing steps, options and `input` * @param execute - Callback to execute a single command * @param context - Optional context passed to every command invocation; never visible to * `$input` or any other reference * @returns The aggregated pipeline result * * @example * ```typescript * import { executePipeline, type PipelineRequest } from '@lushly-dev/afd-core'; * * const result = await executePipeline( * { steps: [{ command: 'user-get', input: { id: 1 } }] }, * (name, input, ctx) => server.execute(name, input, ctx), * ); * ``` */ export declare function executePipeline(request: PipelineRequest, execute: CommandExecutor, context?: Record): Promise; //# sourceMappingURL=pipeline-executor.d.ts.map