/** * ExecutionPipeline — Orchestrates MCP Tool Execution Steps * * Breaks the monolithic execute() flow into discrete, testable steps * using the Result monad for railway-oriented error handling. * * Each step either succeeds (passes data to the next step) or fails * (short-circuits with an error response). * * Pipeline: ensureBuilt → parseDiscriminator → resolveAction → validateArgs → runChain */ import { type ZodObject, type ZodRawShape } from 'zod'; import { type ToolResponse } from '../response.js'; import { type Result } from '../result.js'; import { type InternalAction } from '../types.js'; import { type CompiledChain } from './MiddlewareCompiler.js'; import { type ProgressSink } from './ProgressHelper.js'; import { type PostProcessTelemetry } from '../../presenter/PostProcessor.js'; /** Pre-built runtime context needed for execution */ export interface ExecutionContext { readonly actionMap: Map>; readonly compiledChain: CompiledChain; readonly validationSchemaCache: Map | null>; readonly actionKeysString: string; readonly discriminator: string; readonly toolName: string; } /** Resolved action with its discriminator value */ interface ResolvedAction { readonly action: InternalAction; readonly discriminatorValue: string; } /** Step 1: Parse discriminator value from raw args */ export declare function parseDiscriminator(execCtx: ExecutionContext, args: Record): Result; /** Step 2: Resolve the action by discriminator value — O(1) lookup */ export declare function resolveAction(execCtx: ExecutionContext, discriminatorValue: string): Result>; /** Step 3: Validate and strip args using pre-cached Zod schema */ export declare function validateArgs(execCtx: ExecutionContext, resolved: ResolvedAction, args: Record): Result<{ validated: Record; selectFields: string[] | undefined; }>; /** * Step 4: Run pre-compiled middleware chain → handler. * * @param rethrow - When `true`, handler exceptions propagate to the caller * instead of being caught and converted to error responses. Used by the * traced execution path so that `_executeTraced` can classify system errors * (`SpanStatusCode.ERROR` + `recordException`). Default: `false`. * @param signal - Optional AbortSignal for cooperative cancellation. * Checked before handler execution. If already aborted, returns an * immediate error response without invoking the handler chain. * @param selectFields - Optional `_select` field names extracted from the * AI's input. Forwarded to `postProcessResult()` → `Presenter.make()` * for Late Guillotine filtering. */ export declare function runChain(execCtx: ExecutionContext, resolved: ResolvedAction, ctx: TContext, args: Record, progressSink?: ProgressSink, rethrow?: boolean, signal?: AbortSignal, selectFields?: string[], telemetry?: PostProcessTelemetry): Promise; /** * An envelope that wraps an async generator from a handler. * The middleware compiler detects generator handlers and wraps * their return value in this envelope so the pipeline can drain them. */ export interface GeneratorResultEnvelope { readonly __brand: 'GeneratorResultEnvelope'; readonly generator: AsyncGenerator; } export {}; //# sourceMappingURL=ExecutionPipeline.d.ts.map