"use strict";
/**
 * Model Catalog - Available models for CLI Proxy providers
 *
 * Ships with CCS to provide users with interactive model selection.
 * Models are mapped to their internal names used by the proxy backend.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNativeGeminiModel = exports.supportsNativeImageInput = exports.supportsExtendedContext = exports.supportsThinking = exports.getModelMaxLevel = exports.getModelThinkingSupport = exports.getModelDeprecationReason = exports.isModelDeprecated = exports.getModelIssueUrl = exports.isModelBroken = exports.findModel = exports.getSuggestedReplacementModel = exports.getProviderCatalog = exports.supportsModelConfig = exports.MODEL_CATALOG = void 0;
const model_id_normalizer_1 = require("./ai-providers/model-id-normalizer");
const agy_gemini_pro_compatibility_1 = require("../shared/agy-gemini-pro-compatibility");
const extended_context_utils_1 = require("../shared/extended-context-utils");
const gemini_minor_version_compatibility_1 = require("../shared/gemini-minor-version-compatibility");
/**
 * Model catalog for providers that support interactive configuration
 *
 * Models listed in order of recommendation (top = best)
 */
exports.MODEL_CATALOG = {
    agy: {
        provider: 'agy',
        displayName: 'Antigravity',
        defaultModel: 'claude-opus-4-6-thinking',
        models: [
            {
                id: 'claude-opus-4-6-thinking',
                name: 'Claude Opus 4.6 Thinking',
                description: 'Latest flagship, extended thinking',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: true,
                    dynamicAllowed: true,
                },
                // TODO: Re-enable when Antigravity backend supports 1M context (currently 256k)
                // extendedContext: true,
                extendedContext: false,
            },
            {
                id: 'claude-sonnet-4-6',
                name: 'Claude Sonnet 4.6',
                description: 'Latest Sonnet with thinking budget support',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 64000,
                    zeroAllowed: true,
                    dynamicAllowed: true,
                },
            },
            {
                id: agy_gemini_pro_compatibility_1.AGY_GEMINI_PRO_HIGH_ID,
                name: 'Gemini 3.1 Pro High',
                description: 'Current Antigravity Gemini Pro route with higher reasoning budget',
                nativeImageInput: true,
                thinking: { type: 'none' },
                extendedContext: true,
            },
            {
                id: agy_gemini_pro_compatibility_1.AGY_GEMINI_PRO_LOW_ID,
                name: 'Gemini 3.1 Pro Low',
                description: 'Current Antigravity Gemini Pro route with the lighter quota tier',
                nativeImageInput: true,
                thinking: { type: 'none' },
                extendedContext: true,
            },
            {
                id: 'gemini-3-1-flash-preview',
                name: 'Gemini Flash',
                description: 'Latest Gemini Flash model via Antigravity',
                nativeImageInput: true,
                thinking: { type: 'levels', levels: ['low', 'high'], dynamicAllowed: true },
                extendedContext: true,
            },
        ],
    },
    gemini: {
        provider: 'gemini',
        displayName: 'Gemini',
        defaultModel: 'gemini-2.5-pro',
        models: [
            {
                id: 'gemini-3.1-pro-preview',
                name: 'Gemini 3.1 Pro',
                tier: 'pro',
                description: 'Latest Gemini Pro model, requires paid Google account',
                nativeImageInput: true,
                thinking: { type: 'levels', levels: ['low', 'high'], dynamicAllowed: true },
                extendedContext: true,
            },
            {
                id: 'gemini-3-flash-preview',
                name: 'Gemini Flash',
                tier: 'pro',
                description: 'Latest Gemini Flash model, requires paid Google account',
                nativeImageInput: true,
                thinking: { type: 'levels', levels: ['low', 'high'], dynamicAllowed: true },
                extendedContext: true,
            },
            {
                id: 'gemini-2.5-pro',
                name: 'Gemini 2.5 Pro',
                description: 'Stable, works with free Google account',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 128,
                    max: 32768,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
        ],
    },
    codex: {
        provider: 'codex',
        displayName: 'Copilot Codex',
        defaultModel: 'gpt-5.4',
        models: [
            {
                id: 'gpt-5.5',
                name: 'GPT-5.5',
                tier: 'pro',
                description: 'Newest Codex-released GPT-5 family model; falls back to GPT-5.4 on free plans',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh'],
                    maxLevel: 'xhigh',
                    dynamicAllowed: false,
                },
                codexServiceTiers: ['fast'],
            },
            {
                id: 'gpt-5.4',
                name: 'GPT-5.4',
                description: 'Recommended Codex default for most coding and agentic tasks',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh'],
                    maxLevel: 'xhigh',
                    dynamicAllowed: false,
                },
                codexServiceTiers: ['fast'],
            },
            {
                id: 'gpt-5.4-mini',
                name: 'GPT-5.4 Mini',
                description: 'Fast, lower-cost Codex option for lighter tasks and haiku-tier routing',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high'],
                    maxLevel: 'high',
                    dynamicAllowed: false,
                },
            },
            {
                id: 'gpt-5.3-codex',
                name: 'GPT-5.3 Codex',
                tier: 'pro',
                description: 'Previous flagship coding model whose capabilities now power GPT-5.4',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh'],
                    maxLevel: 'xhigh',
                    dynamicAllowed: false,
                },
            },
            {
                id: 'gpt-5.3-codex-spark',
                name: 'GPT-5.3 Codex Spark',
                tier: 'pro',
                description: 'Research preview model for ChatGPT Pro subscribers, optimized for near-instant coding iteration',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh'],
                    maxLevel: 'xhigh',
                    dynamicAllowed: false,
                },
            },
            {
                id: 'gpt-5.2',
                name: 'GPT-5.2',
                description: 'Previous general-purpose Codex model',
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh'],
                    maxLevel: 'xhigh',
                    dynamicAllowed: false,
                },
            },
        ],
    },
    kimi: {
        provider: 'kimi',
        displayName: 'Kimi (Moonshot)',
        defaultModel: 'kimi-k2.5',
        models: [
            {
                id: 'kimi-k2.5',
                name: 'Kimi K2.5',
                description: 'Latest multimodal model (262K context)',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 32000,
                    zeroAllowed: true,
                    dynamicAllowed: true,
                },
            },
            {
                id: 'kimi-k2-thinking',
                name: 'Kimi K2 Thinking',
                description: 'Extended reasoning model',
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 32000,
                    zeroAllowed: true,
                    dynamicAllowed: true,
                },
            },
            {
                id: 'kimi-k2',
                name: 'Kimi K2',
                description: 'Flagship coding model',
            },
        ],
    },
    claude: {
        provider: 'claude',
        displayName: 'Claude (Anthropic)',
        defaultModel: 'claude-sonnet-4-6',
        models: [
            {
                id: 'claude-opus-4-7',
                name: 'Claude Opus 4.7',
                description: 'Latest flagship model',
                nativeImageInput: true,
                // Opus 4.7 only supports adaptive thinking on the Anthropic API; manual
                // thinking.type: "enabled" with budget_tokens is rejected with 400.
                // Expose effort levels; the proxy translates these into adaptive effort.
                // `max` is a distinct adaptive effort above `xhigh` exposed by Anthropic.
                thinking: {
                    type: 'levels',
                    levels: ['low', 'medium', 'high', 'xhigh', 'max'],
                    maxLevel: 'max',
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-opus-4-6',
                name: 'Claude Opus 4.6',
                description: 'Previous flagship model',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-sonnet-4-6',
                name: 'Claude Sonnet 4.6',
                description: 'Balanced performance and speed',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-opus-4-5-20251101',
                name: 'Claude Opus 4.5',
                description: 'Most capable Claude model',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-sonnet-4-5-20250929',
                name: 'Claude Sonnet 4.5',
                description: 'Balanced performance and speed',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-sonnet-4-20250514',
                name: 'Claude Sonnet 4',
                description: 'Previous generation Sonnet',
                nativeImageInput: true,
                thinking: {
                    type: 'budget',
                    min: 1024,
                    max: 128000,
                    zeroAllowed: false,
                    dynamicAllowed: true,
                },
                extendedContext: true,
            },
            {
                id: 'claude-haiku-4-5-20251001',
                name: 'Claude Haiku 4.5',
                description: 'Fast and efficient',
                nativeImageInput: true,
                thinking: { type: 'none' },
            },
        ],
    },
};
/**
 * Check if provider supports interactive model configuration
 */
function supportsModelConfig(provider) {
    return provider in exports.MODEL_CATALOG;
}
exports.supportsModelConfig = supportsModelConfig;
/**
 * Get catalog for provider
 */
function getProviderCatalog(provider) {
    return exports.MODEL_CATALOG[provider];
}
exports.getProviderCatalog = getProviderCatalog;
/**
 * Suggest a supported replacement model from the provider catalog.
 * Prefers the provider default unless it matches the excluded model or is itself broken.
 */
function getSuggestedReplacementModel(provider, excludedModelId) {
    const catalog = exports.MODEL_CATALOG[provider];
    if (!catalog)
        return undefined;
    const excludedId = excludedModelId ? findModel(provider, excludedModelId)?.id : undefined;
    const defaultModel = findModel(provider, catalog.defaultModel);
    if (defaultModel && !defaultModel.broken && defaultModel.id !== excludedId) {
        return defaultModel.id;
    }
    return catalog.models.find((model) => !model.broken && model.id !== excludedId)?.id;
}
exports.getSuggestedReplacementModel = getSuggestedReplacementModel;
/**
 * Find model entry by ID
 * Note: Model IDs are normalized to lowercase for case-insensitive comparison
 */
function findModel(provider, modelId) {
    const catalog = exports.MODEL_CATALOG[provider];
    if (!catalog || !modelId)
        return undefined;
    const normalizedId = (0, extended_context_utils_1.stripModelConfigurationSuffixes)(modelId).trim().toLowerCase();
    const providerNormalizedId = (0, model_id_normalizer_1.normalizeModelIdForProvider)(normalizedId, provider)
        .trim()
        .toLowerCase();
    const lookupCandidates = new Set([normalizedId, providerNormalizedId]);
    if ((0, model_id_normalizer_1.isAntigravityProvider)(provider)) {
        const migratedRaw = (0, model_id_normalizer_1.migrateDeniedAntigravityModelAliases)(normalizedId).trim().toLowerCase();
        const migratedProvider = (0, model_id_normalizer_1.migrateDeniedAntigravityModelAliases)(providerNormalizedId)
            .trim()
            .toLowerCase();
        lookupCandidates.add(migratedRaw);
        lookupCandidates.add(migratedProvider);
    }
    for (const candidate of [...lookupCandidates]) {
        const compatibilityId = gemini_minor_version_compatibility_1.GEMINI_MINOR_VERSION_COMPATIBILITY_IDS[candidate];
        if (compatibilityId) {
            lookupCandidates.add(compatibilityId);
        }
        if ((0, model_id_normalizer_1.isAntigravityProvider)(provider)) {
            const agyCompatibilityId = agy_gemini_pro_compatibility_1.AGY_GEMINI_PRO_COMPATIBILITY_IDS[candidate];
            if (agyCompatibilityId) {
                lookupCandidates.add(agyCompatibilityId);
            }
        }
    }
    return catalog.models.find((m) => lookupCandidates.has(m.id.toLowerCase()));
}
exports.findModel = findModel;
/**
 * Check if model has known issues
 */
function isModelBroken(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.broken === true;
}
exports.isModelBroken = isModelBroken;
/**
 * Get issue URL for broken model
 */
function getModelIssueUrl(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.issueUrl;
}
exports.getModelIssueUrl = getModelIssueUrl;
/**
 * Check if model is deprecated
 */
function isModelDeprecated(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.deprecated === true;
}
exports.isModelDeprecated = isModelDeprecated;
/**
 * Get deprecation reason for deprecated model
 */
function getModelDeprecationReason(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.deprecationReason;
}
exports.getModelDeprecationReason = getModelDeprecationReason;
/**
 * Get thinking support configuration for a model
 */
function getModelThinkingSupport(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.thinking;
}
exports.getModelThinkingSupport = getModelThinkingSupport;
/**
 * Get the maximum reasoning effort level for a model.
 * Returns undefined if model has no cap or is not in catalog.
 */
function getModelMaxLevel(provider, modelId) {
    const thinking = getModelThinkingSupport(provider, modelId);
    return thinking?.maxLevel;
}
exports.getModelMaxLevel = getModelMaxLevel;
/**
 * Check if model supports thinking/reasoning
 */
function supportsThinking(provider, modelId) {
    const thinking = getModelThinkingSupport(provider, modelId);
    return thinking !== undefined && thinking.type !== 'none';
}
exports.supportsThinking = supportsThinking;
/**
 * Check if model supports extended context (1M tokens).
 * Returns true if model has extendedContext: true in catalog.
 */
function supportsExtendedContext(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.extendedContext === true;
}
exports.supportsExtendedContext = supportsExtendedContext;
/**
 * Check if a model can read image inputs natively.
 */
function supportsNativeImageInput(provider, modelId) {
    const model = findModel(provider, modelId);
    return model?.nativeImageInput === true;
}
exports.supportsNativeImageInput = supportsNativeImageInput;
/**
 * Check if model is a native Gemini model (not Claude via Antigravity).
 * Native Gemini models get extended context auto-enabled.
 */
function isNativeGeminiModel(modelId) {
    const lower = modelId.toLowerCase();
    return lower.startsWith('gemini-');
}
exports.isNativeGeminiModel = isNativeGeminiModel;
//# sourceMappingURL=model-catalog.js.map