/** * M — Middleware namespace. * * Composable middleware for cross-cutting concerns. * Compose with .pipe() to stack middleware layers. * * Usage: * agent.middleware(M.retry({ maxAttempts: 3 }).pipe(M.log())) * agent.middleware(M.cost().pipe(M.latency()).pipe(M.trace())) */ import type { CallbackFn, State } from "../core/types.js"; /** Descriptor for a single middleware in the composite. */ export interface MiddlewareSpec { name: string; config: Record; } /** A composable middleware descriptor. */ export declare class MComposite { readonly middlewares: MiddlewareSpec[]; constructor(middlewares: MiddlewareSpec[]); /** Chain: stack another middleware. */ pipe(other: MComposite): MComposite; /** Convert to a flat middleware array for passing to builder. */ toArray(): MiddlewareSpec[]; } /** * M namespace — middleware factories. * * All 28 methods from the Python M namespace. */ export declare class M { /** Retry with exponential backoff. */ static retry(opts?: { maxAttempts?: number; backoff?: number; }): MComposite; /** Structured event logging. */ static log(): MComposite; /** Token usage tracking. */ static cost(): MComposite; /** Per-agent latency tracking. */ static latency(): MComposite; /** Topology event logging (loops, fanout, routes, fallbacks, timeouts). */ static topologyLog(): MComposite; /** Dispatch/join lifecycle logging. */ static dispatchLog(): MComposite; /** Restrict middleware to specific agents. */ static scope(agents: string[], mw: MComposite): MComposite; /** Conditional middleware. */ static when(condition: CallbackFn | ((state: State) => boolean), mw: MComposite): MComposite; /** Pre-agent hook. */ static beforeAgent(fn: CallbackFn): MComposite; /** Post-agent hook. */ static afterAgent(fn: CallbackFn): MComposite; /** Pre-model hook. */ static beforeModel(fn: CallbackFn): MComposite; /** Post-model hook. */ static afterModel(fn: CallbackFn): MComposite; /** Loop iteration hook. */ static onLoop(fn: CallbackFn): MComposite; /** Timeout event hook. */ static onTimeout(fn: CallbackFn): MComposite; /** Routing event hook. */ static onRoute(fn: CallbackFn): MComposite; /** Fallback event hook. */ static onFallback(fn: CallbackFn): MComposite; /** Circuit breaker: trips open after N consecutive errors. */ static circuitBreaker(opts?: { threshold?: number; resetAfter?: number; }): MComposite; /** Per-agent execution timeout. */ static timeout(seconds: number): MComposite; /** Cache LLM responses with TTL. */ static cache(opts?: { ttl?: number; keyFn?: CallbackFn; }): MComposite; /** Auto-downgrade to fallback model on failure. */ static fallbackModel(model: string): MComposite; /** Suppress duplicate model calls within a sliding window. */ static dedup(opts?: { window?: number; }): MComposite; /** Probabilistic middleware: fires inner middleware only N% of the time. */ static sample(rate: number, mw?: MComposite): MComposite; /** OpenTelemetry span export. */ static trace(opts?: { exporter?: unknown; }): MComposite; /** Metrics collection. */ static metrics(opts?: { collector?: unknown; }): MComposite; /** A2A-specific retry for remote agents. */ static a2aRetry(opts?: { maxAttempts?: number; backoff?: number; agents?: string[]; onRetry?: CallbackFn; }): MComposite; /** Circuit breaker for A2A remote agents. */ static a2aCircuitBreaker(opts?: { threshold?: number; resetAfter?: number; agents?: string[]; onOpen?: CallbackFn; onClose?: CallbackFn; }): MComposite; /** Per-delegation timeout for A2A remote agents. */ static a2aTimeout(opts?: { seconds?: number; agents?: string[]; onTimeout?: CallbackFn; }): MComposite; /** Log A2UI surface operations. */ static a2uiLog(opts?: { level?: "info" | "debug" | "trace"; agents?: string[]; }): MComposite; } //# sourceMappingURL=middleware.d.ts.map