/** * Middleware Adapters - Pattern to Middleware Conversion * * This file contains adapters that wrap existing patterns as middleware * for use with the compose() function. */ import type { Middleware, TimeoutMiddlewareOptions, FallbackMiddlewareOptions, CacheMiddlewareOptions } from "../types/composition"; import type { RetryOptions } from "../types/retry"; import type { CircuitBreakerOptions } from "../types/circuit-breaker"; import type { RateLimiterOptions } from "../types/rate-limiter"; import type { BulkheadOptions } from "../types/bulkhead"; import type { DebounceOptions } from "../types/debounce"; import type { ThrottleOptions } from "../types/throttle"; import type { IdempotencyOptions } from "../types/idempotency"; import type { CostTrackingConfig } from "../types/cost-tracking"; import type { PromptVersioningConfig, PromptVersion } from "../types/prompt-versioning"; import type { ValidateResponseConfig, ResponseValidator } from "../types/response-validation"; import type { SmartContextWindowConfig, Message, ContextStrategy } from "../types/context-window"; export type { TimeoutMiddlewareOptions, FallbackMiddlewareOptions, CacheMiddlewareOptions, }; /** * Retry middleware - wraps the retry pattern */ export declare function retryMiddleware(options?: Omit, "execute">): Middleware; /** * Timeout middleware - wraps the timeout pattern */ export declare function timeoutMiddleware(options: TimeoutMiddlewareOptions): Middleware; /** * Fallback middleware - wraps the fallback pattern */ export declare function fallbackMiddleware(options: FallbackMiddlewareOptions): Middleware; /** * Circuit breaker middleware - wraps the CircuitBreaker class * * Note: Maintains state across calls. Create once and reuse. */ export declare function circuitBreakerMiddleware(options: Omit, "execute">): Middleware; /** * Rate limiter middleware - wraps the RateLimiter class * * Note: Maintains GLOBAL state across all calls. This rate limiter counts * all requests regardless of which function is being executed, making it * ideal for enforcing API rate limits across different operations. * * @example * ```typescript * // This rate limiter will count ALL requests together * const robustApi = compose([withRateLimiter({ maxRequests: 5, windowMs: 10000 })]); * * // These all share the same rate limit counter * await robustApi(fetchUsers, undefined); // Count: 1/5 * await robustApi(fetchProducts, undefined); // Count: 2/5 * await robustApi(fetchOrders, undefined); // Count: 3/5 * ``` */ export declare function rateLimiterMiddleware(options: Omit, "execute">): Middleware; /** * Cache middleware - wraps the memoize pattern */ export declare function cacheMiddleware(options?: CacheMiddlewareOptions): Middleware; /** * Bulkhead middleware - wraps the bulkhead pattern * Note: Creates a new bulkhead instance for each input */ export declare function bulkheadMiddleware(options: Omit, "execute">): Middleware; /** * Debounce middleware - wraps the debounce pattern */ export declare function debounceMiddleware(options: Omit, "execute">): Middleware; /** * Throttle middleware - wraps the throttle pattern */ export declare function throttleMiddleware(options: Omit, "execute">): Middleware; /** * Idempotency middleware - wraps the idempotency pattern */ export declare function idempotencyMiddleware(options: Omit, "execute" | "key"> & { keyFn: (input: TInput) => string; }): Middleware; /** * Cost tracking middleware - wraps the cost tracking pattern */ export declare function costTrackingMiddleware(options: Omit, "execute">): Middleware; /** * Prompt versioning middleware - wraps the versionedPrompt pattern */ export declare function promptVersioningMiddleware(options: { promptId: string; versions: Record; getPromptForInput?: (input: TInput) => string; } & Omit, "execute" | "promptId" | "versions">): Middleware; /** * Response validation middleware - wraps the validateResponse pattern */ export declare function responseValidationMiddleware(options: { validators: ResponseValidator[]; } & Omit, "execute" | "validators">): Middleware; /** * Context window middleware - wraps the smartContextWindow pattern * Useful for managing message history in chat applications */ export declare function contextWindowMiddleware(options: { getMessages: (input: TInput) => Message[]; maxTokens: number; strategy?: ContextStrategy; } & Omit, "execute" | "messages" | "maxTokens" | "strategy">): Middleware; export declare const withRetry: typeof retryMiddleware; export declare const withTimeout: typeof timeoutMiddleware; export declare const withFallback: typeof fallbackMiddleware; export declare const withCircuitBreaker: typeof circuitBreakerMiddleware; export declare const withRateLimiter: typeof rateLimiterMiddleware; export declare const withCache: typeof cacheMiddleware; export declare const withBulkhead: typeof bulkheadMiddleware; export declare const withDebounce: typeof debounceMiddleware; export declare const withThrottle: typeof throttleMiddleware; export declare const withIdempotency: typeof idempotencyMiddleware; export declare const withCostTracking: typeof costTrackingMiddleware; export declare const withPromptVersioning: typeof promptVersioningMiddleware; export declare const withResponseValidation: typeof responseValidationMiddleware; export declare const withContextWindow: typeof contextWindowMiddleware; //# sourceMappingURL=middleware.d.ts.map