/**
 * Request Interceptors and Retry Logic
 *
 * Provides middleware interceptors for the NeuroLink client SDK including
 * authentication, logging, retry logic, rate limiting, and request/response transformation.
 *
 * @module @neurolink/client/interceptors
 */
import type { Middleware, MiddlewareRequest, MiddlewareResponse, ClientMiddlewareContext as MiddlewareContext, ClientRetryConfig as RetryConfig, ApiError } from "../types/clientTypes.js";
/**
 * API Key authentication interceptor
 *
 * Adds X-API-Key header to all requests.
 *
 * @example
 * ```typescript
 * client.use(createApiKeyAuthInterceptor('your-api-key'));
 * ```
 */
export declare function createApiKeyAuthInterceptor(apiKey: string): Middleware;
/**
 * Bearer token authentication interceptor
 *
 * Adds Authorization header with Bearer token.
 *
 * @example
 * ```typescript
 * client.use(createBearerAuthInterceptor('your-token'));
 * ```
 */
export declare function createBearerAuthInterceptor(token: string): Middleware;
/**
 * Dynamic authentication interceptor
 *
 * Retrieves authentication token dynamically for each request.
 * Useful for token refresh scenarios.
 *
 * @example
 * ```typescript
 * client.use(createDynamicAuthInterceptor(async () => {
 *   const token = await getAccessToken();
 *   return { type: 'bearer', token };
 * }));
 * ```
 */
export declare function createDynamicAuthInterceptor(getAuth: () => Promise<{
    type: "apiKey";
    key: string;
} | {
    type: "bearer";
    token: string;
} | null>): Middleware;
/**
 * Logging interceptor options
 */
export type LoggingInterceptorOptions = {
    /** Log request details */
    logRequest?: boolean;
    /** Log response details */
    logResponse?: boolean;
    /** Log request body */
    logBody?: boolean;
    /** Log response body */
    logResponseBody?: boolean;
    /** Custom logger function */
    logger?: (message: string, data?: unknown) => void;
    /** Redact sensitive fields */
    redactFields?: string[];
};
/**
 * Logging interceptor
 *
 * Logs request and response details for debugging.
 *
 * @example
 * ```typescript
 * client.use(createLoggingInterceptor({
 *   logRequest: true,
 *   logResponse: true,
 *   redactFields: ['apiKey', 'password'],
 * }));
 * ```
 */
export declare function createLoggingInterceptor(options?: LoggingInterceptorOptions): Middleware;
/**
 * Retry interceptor options
 */
export type RetryInterceptorOptions = RetryConfig & {
    /** Callback when a retry is attempted */
    onRetry?: (attempt: number, error: Error | ApiError, request: MiddlewareRequest) => void;
    /** Custom retry condition */
    shouldRetry?: (response: MiddlewareResponse, attempt: number) => boolean;
};
/**
 * Retry interceptor with exponential backoff
 *
 * Automatically retries failed requests with configurable backoff.
 *
 * @example
 * ```typescript
 * client.use(createRetryInterceptor({
 *   maxAttempts: 3,
 *   initialDelayMs: 1000,
 *   maxDelayMs: 10000,
 *   backoffMultiplier: 2,
 *   retryableStatusCodes: [429, 500, 502, 503, 504],
 *   onRetry: (attempt, error) => console.log(`Retry ${attempt}:`, error),
 * }));
 * ```
 */
export declare function createRetryInterceptor(options: RetryInterceptorOptions): Middleware;
/**
 * Rate limiter options
 */
export type RateLimiterOptions = {
    /** Maximum requests per window */
    maxRequests: number;
    /** Window size in milliseconds */
    windowMs: number;
    /** Strategy when limit is reached: 'queue' or 'throw' */
    strategy?: "queue" | "throw";
    /** Callback when rate limited */
    onRateLimited?: (waitTime: number) => void;
};
/**
 * Rate limiting interceptor
 *
 * Limits the rate of requests to prevent overwhelming the API.
 *
 * @example
 * ```typescript
 * client.use(createRateLimitInterceptor({
 *   maxRequests: 100,
 *   windowMs: 60000, // 100 requests per minute
 *   strategy: 'queue',
 *   onRateLimited: (waitTime) => console.log(`Rate limited, waiting ${waitTime}ms`),
 * }));
 * ```
 */
export declare function createRateLimitInterceptor(options: RateLimiterOptions): Middleware;
/**
 * Request transformation interceptor
 *
 * Transform request before sending.
 *
 * @example
 * ```typescript
 * client.use(createRequestTransformInterceptor((request) => {
 *   // Add custom header based on request body
 *   if (request.body?.priority === 'high') {
 *     request.headers['X-Priority'] = 'high';
 *   }
 *   return request;
 * }));
 * ```
 */
export declare function createRequestTransformInterceptor(transform: (request: MiddlewareRequest) => MiddlewareRequest | Promise<MiddlewareRequest>): Middleware;
/**
 * Response transformation interceptor
 *
 * Transform response before returning.
 *
 * @example
 * ```typescript
 * client.use(createResponseTransformInterceptor((response) => {
 *   // Add metadata to response
 *   response.context.processedAt = Date.now();
 *   return response;
 * }));
 * ```
 */
export declare function createResponseTransformInterceptor(transform: (response: MiddlewareResponse) => MiddlewareResponse | Promise<MiddlewareResponse>): Middleware;
/**
 * Cache options
 */
export type CacheInterceptorOptions = {
    /** Cache TTL in milliseconds */
    ttl: number;
    /** Maximum cache size */
    maxSize?: number;
    /** Cache key generator */
    keyGenerator?: (request: MiddlewareRequest) => string;
    /** Methods to cache (default: ['GET']) */
    methods?: string[];
    /** Paths to cache (regex patterns) */
    includePaths?: RegExp[];
    /** Paths to exclude from cache */
    excludePaths?: RegExp[];
};
/**
 * Caching interceptor
 *
 * Caches responses to reduce API calls.
 *
 * @example
 * ```typescript
 * client.use(createCacheInterceptor({
 *   ttl: 60000, // 1 minute
 *   methods: ['GET'],
 *   includePaths: [/\/api\/tools/, /\/api\/providers/],
 * }));
 * ```
 */
export declare function createCacheInterceptor(options: CacheInterceptorOptions): Middleware;
/**
 * Timeout interceptor options
 */
export type TimeoutInterceptorOptions = {
    /** Timeout in milliseconds */
    timeout: number;
    /** Callback when timeout occurs */
    onTimeout?: (request: MiddlewareRequest) => void;
};
/**
 * Timeout interceptor
 *
 * Adds a timeout to requests.
 *
 * @example
 * ```typescript
 * client.use(createTimeoutInterceptor({
 *   timeout: 30000, // 30 seconds
 *   onTimeout: (request) => console.log('Request timed out:', request.url),
 * }));
 * ```
 */
export declare function createTimeoutInterceptor(options: TimeoutInterceptorOptions): Middleware;
/**
 * Error handling interceptor options
 */
export type ErrorHandlerOptions = {
    /** Custom error handler */
    onError?: (error: Error, request: MiddlewareRequest) => Error | void;
    /** Transform error response */
    transformError?: (error: unknown) => ApiError;
    /** Report errors to external service */
    reportError?: (error: Error, context: MiddlewareContext) => void | Promise<void>;
};
/**
 * Error handling interceptor
 *
 * Provides centralized error handling and transformation.
 *
 * @example
 * ```typescript
 * client.use(createErrorHandlerInterceptor({
 *   onError: (error, request) => {
 *     console.error('Request failed:', error.message);
 *   },
 *   reportError: async (error, context) => {
 *     await errorReportingService.report(error, context);
 *   },
 * }));
 * ```
 */
export declare function createErrorHandlerInterceptor(options?: ErrorHandlerOptions): Middleware;
/**
 * Compose multiple middleware into one
 *
 * @example
 * ```typescript
 * const combinedMiddleware = composeMiddleware(
 *   createLoggingInterceptor(),
 *   createRetryInterceptor({ maxAttempts: 3 }),
 *   createRateLimitInterceptor({ maxRequests: 100, windowMs: 60000 }),
 * );
 *
 * client.use(combinedMiddleware);
 * ```
 */
export declare function composeMiddleware(...middlewares: Middleware[]): Middleware;
/**
 * Conditionally apply middleware
 *
 * @example
 * ```typescript
 * client.use(conditionalMiddleware(
 *   (request) => request.url.includes('/api/agents'),
 *   createLoggingInterceptor(),
 * ));
 * ```
 */
export declare function conditionalMiddleware(condition: (request: MiddlewareRequest) => boolean, middleware: Middleware): Middleware;
