"use strict";
/**
 * Extended Context Configuration
 *
 * Handles the [1m] suffix for models supporting 1M token context window.
 * Claude Code recognizes this suffix to enable extended context.
 *
 * Behavior:
 * - Gemini family (gemini-*): Auto-enabled by default
 * - Claude (Anthropic): Opt-in via --1m flag
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyExtendedContextConfig = exports.shouldApplyExtendedContext = exports.applyExtendedContextSuffix = void 0;
const model_catalog_1 = require("../model-catalog");
const ui_1 = require("../../utils/ui");
const extended_context_utils_1 = require("../../shared/extended-context-utils");
// Backward-compatible export retained for tests/importers that reference this module.
function applyExtendedContextSuffix(modelId) {
    return (0, extended_context_utils_1.applyExtendedContextSuffix)(modelId);
}
exports.applyExtendedContextSuffix = applyExtendedContextSuffix;
/**
 * Determine if extended context should be applied to a model.
 *
 * @param provider - CLIProxy provider
 * @param modelId - Base model ID (without suffixes)
 * @param extendedContextOverride - CLI override (true = force on, false = force off, undefined = auto)
 * @returns Whether to apply extended context suffix
 */
function shouldApplyExtendedContext(provider, modelId, extendedContextOverride) {
    // Explicit override takes priority
    if (extendedContextOverride === true) {
        // User explicitly requested --1m
        const supported = (0, model_catalog_1.supportsExtendedContext)(provider, modelId);
        if (!supported) {
            console.error((0, ui_1.warn)(`Model "${modelId}" does not support 1M extended context. Flag ignored.`));
        }
        return supported;
    }
    if (extendedContextOverride === false) {
        // User explicitly disabled with --no-1m
        return false;
    }
    // Auto behavior: enable for native Gemini models only
    if ((0, extended_context_utils_1.isNativeGeminiModel)(modelId)) {
        return (0, model_catalog_1.supportsExtendedContext)(provider, modelId);
    }
    // For other models (Claude, etc.), default to off - require explicit --1m
    return false;
}
exports.shouldApplyExtendedContext = shouldApplyExtendedContext;
/**
 * Apply extended context configuration to env vars.
 * Modifies ANTHROPIC_MODEL and tier models with [1m] suffix.
 *
 * @param envVars - Environment variables to modify (mutated in place)
 * @param provider - CLIProxy provider
 * @param extendedContextOverride - CLI override (true = force on, false = force off, undefined = auto)
 */
function applyExtendedContextConfig(envVars, provider, extendedContextOverride) {
    if (extendedContextOverride === false) {
        Object.assign(envVars, (0, extended_context_utils_1.applyExtendedContextPreferenceToAnthropicModels)(envVars, false));
        return;
    }
    Object.assign(envVars, (0, extended_context_utils_1.applyExtendedContextPreferenceToAnthropicModels)(envVars, true, {
        supportsExtendedContext: (modelId) => shouldApplyExtendedContext(provider, (0, extended_context_utils_1.stripModelConfigurationSuffixes)(modelId), extendedContextOverride),
    }));
}
exports.applyExtendedContextConfig = applyExtendedContextConfig;
//# sourceMappingURL=extended-context-config.js.map