"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MODEL_ALIASES = void 0;
exports.resolveModel = resolveModel;
exports.resolveModelWithMetadata = resolveModelWithMetadata;
exports.getDefaultModel = getDefaultModel;
exports.resolveModelSync = resolveModelSync;
exports.getDefaultModelSync = getDefaultModelSync;
const majk_chat_core_1 = require("@majkapp/majk-chat-core");
// Static fallback aliases for legacy sync API
exports.MODEL_ALIASES = {
    // Anthropic Claude fallbacks
    'claude-3-opus': 'claude-3-opus',
    'claude-3-sonnet': 'claude-3-5-sonnet',
    'claude-3-haiku': 'claude-3-haiku',
    // OpenAI fallbacks
    'gpt4': 'gpt-4',
    'gpt-4': 'gpt-4-turbo',
    'gpt4-turbo': 'gpt-4-turbo',
    'gpt-4-turbo': 'gpt-4-turbo',
    'gpt-3.5': 'gpt-3.5-turbo',
    'gpt3.5': 'gpt-3.5-turbo',
    'gpt5': 'gpt-5.1',
    'gpt-5': 'gpt-5.1',
    'gpt5.1': 'gpt-5.1',
    'gpt5.2': 'gpt-5.2',
    'gpt5-mini': 'gpt-5-mini',
    'gpt5-nano': 'gpt-5-nano',
    'gpt5-pro': 'gpt-5.2-pro',
    // Common shortcuts
    'o1': 'o1-preview',
    'o1-mini': 'o1-mini',
    // Tier shortcuts (use versioned IDs that actually exist in API)
    'opus': 'claude-3-opus-20240229',
    'sonnet': 'claude-3-5-sonnet-20241022',
    'haiku': 'claude-3-5-haiku-20241022',
};
/**
 * Resolve a model name or alias to the full model identifier using ModelResolverService
 *
 * This is the primary model resolution API. It uses the MajkChat instance to access
 * the ModelResolverService, which queries provider APIs for available models and
 * intelligently selects the best match using structured metadata.
 *
 * Handles:
 * - Tier names: "sonnet", "opus", "haiku", "pro", "mini"
 * - Aliases: "gpt4", "gpt5"
 * - Partial IDs: "claude-4", "gpt-5.2"
 * - Full IDs: "claude-sonnet-4-5-20250929"
 *
 * Examples:
 * - resolveModel(chat, 'sonnet') -> 'claude-sonnet-4-5-20250929' (latest sonnet from API)
 * - resolveModel(chat, 'opus') -> 'claude-opus-4-6' (latest opus)
 * - resolveModel(chat, 'gpt5-pro') -> 'gpt-5.2-pro'
 *
 * @param chat - MajkChat instance with access to ModelResolverService
 * @param modelInput - Model name, tier, alias, or ID
 * @param provider - Optional provider hint
 * @param context - Optional request context for API calls
 * @returns Resolved model ID
 */
async function resolveModel(chat, modelInput, provider, context) {
    const resolved = await chat.resolveModel(modelInput, provider, context);
    return resolved.modelId;
}
/**
 * Resolve a model and return full resolution details including metadata
 *
 * Same as resolveModel but returns the full ResolvedModel object with metadata.
 *
 * @param chat - MajkChat instance
 * @param modelInput - Model name, tier, alias, or ID
 * @param provider - Optional provider hint
 * @param context - Optional request context
 * @returns ResolvedModel with ID, provider, and metadata
 */
async function resolveModelWithMetadata(chat, modelInput, provider, context) {
    return chat.resolveModel(modelInput, provider, context);
}
/**
 * Get the appropriate default model for a provider
 *
 * Uses ModelResolverService to find the highest version model for a provider/tier.
 *
 * @param chat - MajkChat instance
 * @param provider - Provider name (anthropic, openai, etc.)
 * @param tierFilter - Optional tier to filter by (sonnet, opus, haiku, pro, mini, etc.)
 * @param context - Optional request context
 * @returns The best model ID for the provider
 *
 * Examples:
 * - getDefaultModel(chat, 'anthropic') -> 'claude-opus-4-6' (highest overall)
 * - getDefaultModel(chat, 'anthropic', 'sonnet') -> 'claude-sonnet-4-5-20250929'
 * - getDefaultModel(chat, 'openai', 'pro') -> 'gpt-5.2-pro'
 */
async function getDefaultModel(chat, provider, tierFilter, context) {
    const resolver = chat.getModelResolver();
    const resolved = await resolver.getBest(provider, tierFilter, context);
    return resolved.modelId;
}
/**
 * Legacy sync model resolution using static fallbacks only
 *
 * This is kept for backwards compatibility but does NOT use dynamic model discovery.
 * New code should use the async resolveModel() instead.
 *
 * @deprecated Use async resolveModel(chat, input, provider, context) instead
 */
function resolveModelSync(modelInput) {
    const lowerInput = modelInput.toLowerCase();
    // Check static fallback aliases
    if (exports.MODEL_ALIASES[lowerInput]) {
        return exports.MODEL_ALIASES[lowerInput];
    }
    // Return as-is if not an alias (might be a full model ID)
    return modelInput;
}
/**
 * Legacy sync default model getter using static fallbacks only
 *
 * This is kept for backwards compatibility but does NOT use dynamic model discovery.
 * New code should use the async getDefaultModel() instead.
 *
 * @deprecated Use async getDefaultModel(chat, provider, tier, context) instead
 */
function getDefaultModelSync(provider, tierFilter) {
    if (tierFilter) {
        const defaults = {
            anthropic: {
                opus: 'claude-3-opus-20240229',
                sonnet: 'claude-3-5-sonnet-20241022',
                haiku: 'claude-3-5-haiku-20241022'
            },
            openai: {
                pro: 'gpt-4o',
                standard: 'gpt-4o',
                mini: 'gpt-4o-mini'
            }
        };
        return defaults[provider]?.[tierFilter.toLowerCase()] || majk_chat_core_1.DEFAULT_MODEL_PREFERENCES[provider] || 'gpt-4';
    }
    // Fallback to built-in static defaults
    return majk_chat_core_1.DEFAULT_MODEL_PREFERENCES[provider] || 'gpt-4';
}
//# sourceMappingURL=models.js.map