/**
 * Model management module
 *
 * Handles model selection, switching, and automatic fallback
 * when a provider fails.
 */
import { Agent, type AgentMessage } from '@earendil-works/pi-agent-core';
import type { Model, Api } from '@earendil-works/pi-ai';
import { type Config } from '../../config/schema.js';
import { type ModelCandidate } from '../fallback/index.js';
export interface ModelManagerConfig {
    defaultModel?: string;
    config?: Config;
}
export interface RunResult {
    content: string | null;
    usage?: {
        prompt_tokens: number;
        completion_tokens: number;
        total_tokens: number;
    };
}
export declare class ModelManager {
    private defaultModel;
    private config?;
    private currentModelName;
    private currentProvider;
    private sessionModels;
    /** Baseline model from `agents.list` / defaults merge when the session agent is created. */
    private sessionProfileDefaults;
    private channelManager?;
    constructor(config?: ModelManagerConfig);
    /**
     * Set channel manager reference for accessing session-specific settings
     */
    setChannelManager(channelManager: any): void;
    /**
     * Apply updated config so default model and failover metadata match disk/runtime config.
     */
    updateFromConfig(config: Config): void;
    /**
     * Set the config-derived default model for a session (from effective agent profile).
     * Cleared by {@link updateFromConfig} or {@link clearSessionProfileDefault}.
     */
    setSessionProfileDefault(sessionKey: string, modelRef: string): void;
    clearSessionProfileDefault(sessionKey: string): void;
    /**
     * Get current model name
     */
    getCurrentModel(): string;
    /**
     * Get current provider
     */
    getCurrentProvider(): string;
    /**
     * Switch model for a specific session
     */
    switchModelForSession(sessionKey: string, modelId: string): Promise<boolean>;
    /** Drop in-memory session override so the global default is used again. */
    clearSessionModelOverride(sessionKey: string): void;
    /**
     * Resolved pi-ai model for session (for transcript policy, tools, etc.)
     */
    getResolvedModelForSession(sessionKey: string): Model<Api>;
    /**
     * Get model for session, checking session override first
     */
    getModelForSession(sessionKey: string): string;
    /**
     * Apply model to agent if different from current
     */
    applyModelForSession(agent: Agent, sessionKey: string): Promise<void>;
    /**
     * Ordered model candidates for the session (primary + `agents.defaults.model.fallbacks`).
     */
    getFallbackCandidatesForSession(sessionKey: string): ModelCandidate[];
    /**
     * Apply a resolved pi-ai model and sync {@link currentModelName} / {@link currentProvider}.
     */
    applyResolvedModel(agent: Agent, model: Model<Api>, modelRef: string): void;
    /**
     * Run the agent with automatic model fallback on failure.
     */
    runWithFallback(agent: Agent, sessionKey: string, userMessage: AgentMessage, provider: string, model: string): Promise<RunResult>;
    /**
     * Find model by reference (provider/modelId)
     */
    findByRef(ref: string): Model<Api> | undefined;
    /**
     * Find model by provider and ID
     */
    find(provider: string, modelId: string): Model<Api> | undefined;
    /**
     * Get all available models
     */
    getAllModels(): readonly Model<Api>[];
    /**
     * Get models grouped by provider
     */
    getModelsByProvider(): Map<string, Model<Api>[]>;
}
