"use strict";
/**
 * Max completion/output tokens by model or Azure deployment name fragment.
 * Shared by Azure OpenAI and OpenAI chat providers.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_MAX_COMPLETION_TOKENS_FALLBACK = void 0;
exports.getMaxCompletionTokensForDeployment = getMaxCompletionTokensForDeployment;
exports.clampMaxCompletionTokens = clampMaxCompletionTokens;
exports.passthroughWithoutTokenLimits = passthroughWithoutTokenLimits;
exports.DEFAULT_MAX_COMPLETION_TOKENS_FALLBACK = 16384;
const DEPLOYMENT_MAX_COMPLETION_TOKENS = [
    { includes: 'gpt-4.1', max: 32768 },
    { includes: 'gpt-audio-mini', max: 16384 },
    { includes: 'gpt-audio', max: 16384 },
    { includes: 'gpt-4o-mini', max: 16384 },
    { includes: 'gpt-4o', max: 16384 },
    { includes: 'gpt-4', max: 8192 },
    { includes: 'gpt-35-turbo', max: 4096 },
    { includes: 'gpt-3.5-turbo', max: 4096 },
];
function getMaxCompletionTokensForDeployment(deploymentName) {
    const lower = String(deploymentName ?? '').toLowerCase();
    for (const { includes, max } of DEPLOYMENT_MAX_COMPLETION_TOKENS) {
        if (lower.includes(includes)) {
            return max;
        }
    }
    return exports.DEFAULT_MAX_COMPLETION_TOKENS_FALLBACK;
}
/** Clamp requested max output tokens to the deployment/model supported limit. */
function clampMaxCompletionTokens(deploymentName, requested, fallback) {
    const raw = requested ?? fallback;
    const cap = getMaxCompletionTokensForDeployment(deploymentName);
    return Math.min(Math.max(1, raw), cap);
}
/** Remove token limits from passthrough so they cannot bypass clamping. */
function passthroughWithoutTokenLimits(passthrough) {
    if (!passthrough || typeof passthrough !== 'object') {
        return {};
    }
    const { max_tokens: _mt, max_completion_tokens: _mct, ...rest } = passthrough;
    return rest;
}
//# sourceMappingURL=maxOutputTokens.js.map