/**
 * Smart Model Router
 *
 * OpenClaw-inspired unified routing layer that integrates:
 * - Model tier selection (complexity-based)
 * - Provider fallback (health-based circuit breaker)
 * - Cost optimization (budget tracking)
 * - Auto-promotion and recovery
 *
 * Usage:
 * ```typescript
 * const router = getSmartRouter();
 *
 * // Configure providers and models
 * router.configureChain({
 *   providers: ['grok', 'openai', 'anthropic'],
 *   models: {
 *     grok: ['grok-3-mini', 'grok-3', 'grok-3-reasoning'],
 *     openai: ['gpt-4o-mini', 'gpt-4o'],
 *     anthropic: ['claude-3-haiku', 'claude-3-sonnet']
 *   }
 * });
 *
 * // Route a request
 * const route = await router.route({
 *   task: 'complex reasoning task',
 *   requiresVision: false,
 *   preferredProvider: 'grok'
 * });
 * ```
 */
import { EventEmitter } from 'events';
import { FallbackConfig, ProviderHealth } from './fallback-chain.js';
import type { ProviderType } from './types.js';
import { TaskClassification, ModelTier } from '../optimization/model-routing.js';
export interface ProviderModels {
    [provider: string]: string[];
}
export interface SmartRouterConfig {
    /** Providers in priority order (first = primary) */
    providers: ProviderType[];
    /** Models per provider (in tier order: mini → standard → reasoning) */
    models: ProviderModels;
    /** Fallback chain configuration */
    fallbackConfig?: Partial<FallbackConfig>;
    /** Cost budget per session in dollars */
    sessionBudget?: number;
    /** Whether to auto-downgrade on cost pressure */
    autoDowngrade?: boolean;
    /** Minimum confidence for tier selection */
    minTierConfidence?: number;
}
export interface RouteRequest {
    /** Task description or message */
    task: string;
    /** Whether task requires vision capabilities */
    requiresVision?: boolean;
    /** Explicitly request reasoning model */
    requiresReasoning?: boolean;
    /** Preferred provider (will try first if healthy) */
    preferredProvider?: ProviderType;
    /** Force specific model (bypasses routing) */
    forceModel?: string;
    /** Force specific tier */
    forceTier?: ModelTier;
    /** Estimated input tokens */
    estimatedTokens?: number;
}
export interface RouteResult {
    /** Selected provider */
    provider: ProviderType;
    /** Selected model */
    model: string;
    /** Model tier */
    tier: ModelTier;
    /** Why this route was chosen */
    reason: string;
    /** Provider health at selection time */
    providerHealth: ProviderHealth;
    /** Task classification used */
    classification?: TaskClassification;
    /** Cost estimate for this route */
    estimatedCost?: number;
    /** Whether this is a fallback route */
    isFallback: boolean;
    /** Alternatives if this fails */
    alternatives: Array<{
        provider: ProviderType;
        model: string;
    }>;
}
export interface SmartRouterEvents {
    /** Emitted when route is selected */
    'route:selected': (result: RouteResult) => void;
    /** Emitted when falling back to alternative */
    'route:fallback': (from: RouteResult, to: RouteResult, reason: string) => void;
    /** Emitted when budget threshold reached */
    'budget:warning': (current: number, limit: number) => void;
    /** Emitted when budget exceeded */
    'budget:exceeded': (current: number, limit: number) => void;
    /** Emitted when auto-downgrading tier */
    'tier:downgraded': (from: ModelTier, to: ModelTier, reason: string) => void;
}
export declare class SmartModelRouter extends EventEmitter {
    private config;
    private fallbackChain;
    private modelRouter;
    private currentCost;
    private routeHistory;
    constructor(config?: Partial<SmartRouterConfig>);
    /**
     * Configure the routing chain
     */
    configureChain(config: Partial<SmartRouterConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): SmartRouterConfig;
    /**
     * Route a request to the best provider/model combination
     */
    route(request: RouteRequest): Promise<RouteResult>;
    /**
     * Route to a forced model
     */
    private routeToForced;
    /**
     * Get fallback route if current route fails
     */
    getFallbackRoute(failedResult: RouteResult, error: string): Promise<RouteResult | null>;
    /**
     * Record successful route execution
     */
    recordSuccess(result: RouteResult, responseTimeMs: number, actualCost?: number): void;
    /**
     * Record failed route execution
     */
    recordFailure(result: RouteResult, error: string): void;
    /**
     * Check if provider is healthy
     */
    isProviderHealthy(provider: ProviderType): boolean;
    /**
     * Get health status for all providers
     */
    getAllHealth(): ProviderHealth[];
    /**
     * Add to current session cost
     */
    addCost(cost: number): void;
    /**
     * Get current session cost
     */
    getCurrentCost(): number;
    /**
     * Reset session cost
     */
    resetCost(): void;
    /**
     * Check if we should downgrade tier due to budget
     */
    private shouldDowngrade;
    /**
     * Get tier for task classification
     */
    private getTierForClassification;
    /**
     * Get lower tier for downgrading
     */
    private getLowerTier;
    /**
     * Select model for provider and tier
     */
    private selectModelForTier;
    /**
     * Find provider that has the given model
     */
    private findProviderForModel;
    /**
     * Get tier for a specific model
     */
    private getTierForModel;
    /**
     * Build alternatives list
     */
    private buildAlternatives;
    /**
     * Build reason string
     */
    private buildReason;
    /**
     * Estimate cost for model and tokens
     */
    private estimateCost;
    /**
     * Get routing statistics
     */
    getStats(): {
        totalRoutes: number;
        fallbackRoutes: number;
        costToDate: number;
        routesByProvider: Record<string, number>;
        routesByTier: Record<string, number>;
        healthByProvider: ProviderHealth[];
    };
    /**
     * Format statistics as string
     */
    formatStats(): string;
    /**
     * Reset router state
     */
    reset(): void;
    /**
     * Dispose router
     */
    dispose(): void;
}
/**
 * Get singleton SmartModelRouter instance
 */
export declare function getSmartRouter(config?: Partial<SmartRouterConfig>): SmartModelRouter;
/**
 * Reset singleton instance
 */
export declare function resetSmartRouter(): void;
export default SmartModelRouter;
