dist / outputBudget.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.automaticOutputReduction = automaticOutputReduction;
// Borrow only a small part of an automatic output reservation. Never reduce the
// configured context safety margin or an explicit thinking/output budget.
function automaticOutputReduction(estimated, inputBudget, outputLimit, explicitMaxTokens, thinkingBudget) {
    if (explicitMaxTokens || estimated <= inputBudget)
        return 0;
    const floor = Math.max(Math.min(outputLimit, 8192), thinkingBudget ? thinkingBudget + 2048 : 0);
    // Leave room for the archive protocol notice added after the first successful fit.
    const reduction = Math.ceil((estimated - inputBudget + 1024) / 256) * 256;
    if (reduction > Math.min(4096, outputLimit * .25) || outputLimit - reduction < floor)
        return 0;
    return reduction;
}