"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDirectGlmBaseUrl = exports.buildGlmtCompatibilityWarnings = exports.normalizeDeprecatedGlmtEnv = exports.isLegacyGlmtBaseUrl = exports.isDeprecatedGlmtProfileName = void 0;
const LEGACY_GLMT_PROFILE = 'glmt';
const LEGACY_GLMT_BASE_URL = 'https://api.z.ai/api/coding/paas/v4/chat/completions';
const DIRECT_GLM_BASE_URL = 'https://api.z.ai/api/anthropic';
const GLMT_PROXY_ONLY_ENV_KEYS = [
    'API_TIMEOUT_MS',
    'ANTHROPIC_SAFE_MODE',
    'ENABLE_STREAMING',
    'MAX_THINKING_TOKENS',
];
function isDeprecatedGlmtProfileName(profileName) {
    return (profileName || '').trim().toLowerCase() === LEGACY_GLMT_PROFILE;
}
exports.isDeprecatedGlmtProfileName = isDeprecatedGlmtProfileName;
function isLegacyGlmtBaseUrl(baseUrl) {
    const normalized = (baseUrl || '').trim().toLowerCase().replace(/\/+$/, '');
    if (!normalized) {
        return false;
    }
    return (normalized === LEGACY_GLMT_BASE_URL ||
        normalized.includes('/api/coding/paas/v4') ||
        normalized.endsWith('/chat/completions'));
}
exports.isLegacyGlmtBaseUrl = isLegacyGlmtBaseUrl;
function normalizeDeprecatedGlmtEnv(env) {
    const normalizedEnv = { ...env };
    let migrated = false;
    if (!normalizedEnv['ANTHROPIC_BASE_URL'] ||
        isLegacyGlmtBaseUrl(normalizedEnv['ANTHROPIC_BASE_URL'])) {
        normalizedEnv['ANTHROPIC_BASE_URL'] = DIRECT_GLM_BASE_URL;
        migrated = true;
    }
    for (const key of GLMT_PROXY_ONLY_ENV_KEYS) {
        if (key in normalizedEnv) {
            delete normalizedEnv[key];
            migrated = true;
        }
    }
    return {
        env: normalizedEnv,
        warnings: buildGlmtCompatibilityWarnings(migrated),
        migrated,
    };
}
exports.normalizeDeprecatedGlmtEnv = normalizeDeprecatedGlmtEnv;
function buildGlmtCompatibilityWarnings(migrated) {
    const warnings = [
        'GLMT is deprecated and kept only as a compatibility path.',
        'Use ccs glm for Z.AI API profiles.',
        'Use ccs km for reasoning-first Kimi API profiles.',
    ];
    if (migrated) {
        warnings.splice(1, 0, 'CCS normalized legacy GLMT proxy settings to the direct GLM endpoint for this run.');
    }
    return warnings;
}
exports.buildGlmtCompatibilityWarnings = buildGlmtCompatibilityWarnings;
function getDirectGlmBaseUrl() {
    return DIRECT_GLM_BASE_URL;
}
exports.getDirectGlmBaseUrl = getDirectGlmBaseUrl;
//# sourceMappingURL=glmt-deprecation.js.map