import type { MiddlewareStage, MiddlewareHandler, MiddlewareNext, MiddlewareInputPhase, MiddlewareOutputPhase, MiddlewareInputHandler, MiddlewareOutputHandler } from './types.js'; /** * Registry that stores middleware handlers keyed by stage tokens * and composes them into execution chains with phase ordering. */ export declare class MiddlewareRegistry { private readonly _handlers; constructor(); /** * Register a middleware handler for a given stage (Wrap phase). * Handlers are stored in registration order within their phase. * * @param stage - The stage token to register the handler for * @param handler - The middleware handler function */ add(stage: MiddlewareStage, handler: MiddlewareHandler): void; /** * Register an Input phase handler. Transforms context before the Wrap chain runs. * Multiple Input handlers compose in registration order (each sees the previous handler's output). * Returns the adapted handler for cleanup purposes. */ addInput(phase: MiddlewareInputPhase, handler: MiddlewareInputHandler): MiddlewareHandler; /** * Register an Output phase handler. Transforms result after the Wrap chain completes. * Multiple Output handlers compose in registration order (each sees the previous handler's output). * Returns the adapted handler for cleanup purposes. */ addOutput(phase: MiddlewareOutputPhase, handler: MiddlewareOutputHandler): MiddlewareHandler; /** * Remove a previously registered middleware handler for a given stage. * Removes the first occurrence of the handler (by reference equality on the adapted handler). * * @param stage - The stage token to remove the handler from * @param handler - The middleware handler function to remove */ remove(stage: MiddlewareStage, handler: MiddlewareHandler): void; /** * Compose all registered handlers for a stage into a single middleware chain. * Handlers are ordered by phase (input → output → wrap), then by registration order within phase. * First in the composed chain = outermost. * * @param stage - The stage token to compose handlers for * @param terminal - The innermost function that performs actual stage execution * @returns A single function representing the full middleware chain */ compose(stage: MiddlewareStage, terminal: MiddlewareNext): MiddlewareNext; /** * Compose and invoke the middleware chain for a stage in one call. * Equivalent to `compose(stage, terminal)(context)` but reads more clearly at call sites. * * @param stage - The stage token to invoke * @param context - The context to pass into the chain * @param terminal - The innermost function that performs actual stage execution * @returns An async generator yielding events and returning the stage result */ invoke(stage: MiddlewareStage, context: TContext, terminal: MiddlewareNext): AsyncGenerator; } //# sourceMappingURL=registry.d.ts.map