/** * Model management module * * Handles model selection, switching, and automatic fallback * when a provider fails. */ import { Agent } 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/candidates.js'; export interface ModelManagerConfig { defaultModel?: string; config?: Config; } 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 sessionProfileFallbacks; constructor(config?: ModelManagerConfig); /** * 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, fallbacks?: string[]): void; /** * Register the profile model and return the model that should initialize the * session agent. An existing per-session override always wins. */ resolveInitialModelForSession(sessionKey: string, profileModelRef: string, fallbacks?: string[]): string; 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; /** 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; /** * 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; /** * Ordered model candidates for the session. */ getFallbackCandidatesForSession(sessionKey: string): ModelCandidate[]; /** * Apply a resolved pi-ai model and sync {@link currentModelName} / {@link currentProvider}. */ applyResolvedModel(agent: Agent, model: Model, modelRef: string): void; /** * Find model by reference (provider/modelId) */ findByRef(ref: string): Model | undefined; /** * Find model by provider and ID */ find(provider: string, modelId: string): Model | undefined; /** * Get all available models */ getAllModels(): readonly Model[]; /** * Get models grouped by provider */ getModelsByProvider(): Map[]>; }