billion-context 0.1.75-pr.489.309 → 0.1.75-pr.490.310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -98
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47856,7 +47856,7 @@ function parseCompressSettings(v2) {
|
|
|
47856
47856
|
}
|
|
47857
47857
|
out[key] = typeof obj[key] === "string" ? obj[key].trim() : obj[key];
|
|
47858
47858
|
}
|
|
47859
|
-
for (const key of ["nudgeGrowthTokens", "preserveRecentMessages", "preserveRecentTokens", "minCompressRange"]) {
|
|
47859
|
+
for (const key of ["nudgeGrowthTokens", "preserveRecentMessages", "preserveRecentTokens", "minCompressRange", "minCompressRangeChars"]) {
|
|
47860
47860
|
takeNumber(key);
|
|
47861
47861
|
}
|
|
47862
47862
|
if ("tiers" in obj) {
|
|
@@ -47922,6 +47922,7 @@ function resolveContextLimitValue(raw, nativeLimit) {
|
|
|
47922
47922
|
function mergeCompress(global2, provider, model) {
|
|
47923
47923
|
const pick = (k2) => model?.[k2] ?? provider?.[k2] ?? global2?.[k2];
|
|
47924
47924
|
const promptLevels = [global2?.prompts, provider?.prompts, model?.prompts].filter(Boolean);
|
|
47925
|
+
const rangeOf = (s3) => s3?.minCompressRangeChars ?? s3?.minCompressRange;
|
|
47925
47926
|
return {
|
|
47926
47927
|
modelContextLimit: pick("modelContextLimit"),
|
|
47927
47928
|
maxContextLimit: pick("maxContextLimit"),
|
|
@@ -47929,7 +47930,7 @@ function mergeCompress(global2, provider, model) {
|
|
|
47929
47930
|
nudgeGrowthTokens: pick("nudgeGrowthTokens"),
|
|
47930
47931
|
preserveRecentMessages: pick("preserveRecentMessages"),
|
|
47931
47932
|
preserveRecentTokens: pick("preserveRecentTokens"),
|
|
47932
|
-
|
|
47933
|
+
minCompressRangeChars: rangeOf(model) ?? rangeOf(provider) ?? rangeOf(global2),
|
|
47933
47934
|
tiers: pick("tiers"),
|
|
47934
47935
|
prompts: promptLevels.length > 0 ? Object.assign({}, ...promptLevels) : void 0,
|
|
47935
47936
|
acknowledgePromptsRisk: pick("acknowledgePromptsRisk")
|
|
@@ -47983,7 +47984,7 @@ function applyCompressSettings(base, limit, s3) {
|
|
|
47983
47984
|
preserveRecentTokens: s3.preserveRecentTokens ?? base.preserveRecentTokens,
|
|
47984
47985
|
compress: {
|
|
47985
47986
|
...base.compress,
|
|
47986
|
-
minCompressRange: s3.minCompressRange ?? base.compress.minCompressRange
|
|
47987
|
+
minCompressRange: s3.minCompressRangeChars ?? s3.minCompressRange ?? base.compress.minCompressRange
|
|
47987
47988
|
}
|
|
47988
47989
|
};
|
|
47989
47990
|
}
|
|
@@ -48165,6 +48166,7 @@ var CACHE_FILE = path3.join(cacheDir(), "models-dev.json");
|
|
|
48165
48166
|
var TTL_MS = 24 * 60 * 60 * 1e3;
|
|
48166
48167
|
var cache2 = null;
|
|
48167
48168
|
var loading = null;
|
|
48169
|
+
var warnedConflicts = /* @__PURE__ */ new Set();
|
|
48168
48170
|
var snapshotReg = null;
|
|
48169
48171
|
var snapshotMs = 0;
|
|
48170
48172
|
function bundledSnapshotRegistry() {
|
|
@@ -48337,15 +48339,22 @@ function registryLookup(reg, model, host) {
|
|
|
48337
48339
|
}
|
|
48338
48340
|
if (provider === void 0) {
|
|
48339
48341
|
const suffix = `/${model}`;
|
|
48340
|
-
let
|
|
48342
|
+
let max;
|
|
48343
|
+
const distinct = /* @__PURE__ */ new Set();
|
|
48344
|
+
const parts = [];
|
|
48341
48345
|
for (const key of Object.keys(reg)) {
|
|
48342
48346
|
if (!key.endsWith(suffix)) continue;
|
|
48343
48347
|
const ctx = reg[key].limit?.context;
|
|
48344
48348
|
if (typeof ctx !== "number" || ctx <= 0) continue;
|
|
48345
|
-
if (
|
|
48346
|
-
|
|
48349
|
+
if (max === void 0 || ctx > max) max = ctx;
|
|
48350
|
+
distinct.add(ctx);
|
|
48351
|
+
parts.push(`${key}=${ctx}`);
|
|
48352
|
+
}
|
|
48353
|
+
if (max !== void 0 && distinct.size > 1 && !warnedConflicts.has(model)) {
|
|
48354
|
+
warnedConflicts.add(model);
|
|
48355
|
+
log("warn", `[acp-registry] conflicting context windows for "${model}" (${parts.join(", ")}) \u2014 using max ${max}`);
|
|
48347
48356
|
}
|
|
48348
|
-
return
|
|
48357
|
+
return max;
|
|
48349
48358
|
}
|
|
48350
48359
|
return void 0;
|
|
48351
48360
|
}
|
|
@@ -50705,7 +50714,7 @@ function summaryPayload(protocol, model, system, content) {
|
|
|
50705
50714
|
if (protocol === "openai") {
|
|
50706
50715
|
return { model, max_tokens: MAX_SUMMARY_OUTPUT_TOKENS, messages: [{ role: "system", content: system }, { role: "user", content }], stream: false };
|
|
50707
50716
|
}
|
|
50708
|
-
return { model, max_output_tokens: MAX_SUMMARY_OUTPUT_TOKENS, instructions: system, input: [{ role: "user", content }], stream: false
|
|
50717
|
+
return { model, max_output_tokens: MAX_SUMMARY_OUTPUT_TOKENS, instructions: system, input: [{ role: "user", content }], stream: false };
|
|
50709
50718
|
}
|
|
50710
50719
|
function extractSummaryText(protocol, json) {
|
|
50711
50720
|
if (protocol === "anthropic") {
|
|
@@ -50771,7 +50780,7 @@ TASK: The conversation segment below (messages ${startRef}\u2013${endRef}) must
|
|
|
50771
50780
|
var ABORTED_FAILURE = { kind: "aborted", detail: "the client disconnected during preflight compression" };
|
|
50772
50781
|
async function preflightCompress(deps, messages) {
|
|
50773
50782
|
const limit = deps.config.modelContextLimit;
|
|
50774
|
-
const result = { compressedRanges: 0, savedTokens: 0, payloadEstimate: estimateCoreMessages(messages)
|
|
50783
|
+
const result = { compressedRanges: 0, savedTokens: 0, payloadEstimate: estimateCoreMessages(messages) };
|
|
50775
50784
|
if (limit <= 0) return result;
|
|
50776
50785
|
const budget = Math.max(MIN_CHUNK_TOKENS, Math.floor(limit * CHUNK_FRACTION));
|
|
50777
50786
|
const minChars = deps.config.compress.minCompressRange;
|
|
@@ -50791,8 +50800,8 @@ async function preflightCompress(deps, messages) {
|
|
|
50791
50800
|
renderTags: "text-only"
|
|
50792
50801
|
});
|
|
50793
50802
|
deps.session.state = turn.state;
|
|
50794
|
-
currentTokens = Math.max(deps.session.stats.lastInputTokens, estimateCoreMessages(turn.messages)
|
|
50795
|
-
result.payloadEstimate = estimateCoreMessages(turn.messages)
|
|
50803
|
+
currentTokens = Math.max(deps.session.stats.lastInputTokens, estimateCoreMessages(turn.messages));
|
|
50804
|
+
result.payloadEstimate = estimateCoreMessages(turn.messages);
|
|
50796
50805
|
if (startTokens < 0) startTokens = currentTokens;
|
|
50797
50806
|
if (currentTokens < limit) break;
|
|
50798
50807
|
const ranges = viableRanges(turn.nudge?.compressibleRanges ?? []);
|
|
@@ -50878,78 +50887,6 @@ async function preflightCompress(deps, messages) {
|
|
|
50878
50887
|
return result;
|
|
50879
50888
|
}
|
|
50880
50889
|
|
|
50881
|
-
// src/image-tokens.ts
|
|
50882
|
-
var REMOTE_IMAGE_TOKENS = 4096;
|
|
50883
|
-
function imageTokenCap() {
|
|
50884
|
-
const v2 = Number(process.env.BILI_IMAGE_TOKEN_CAP ?? "");
|
|
50885
|
-
return Number.isInteger(v2) && v2 > 0 ? v2 : 0;
|
|
50886
|
-
}
|
|
50887
|
-
function applyCap(cost) {
|
|
50888
|
-
const cap = imageTokenCap();
|
|
50889
|
-
return cap > 0 ? Math.min(cost, cap) : cost;
|
|
50890
|
-
}
|
|
50891
|
-
function costForUrl(url) {
|
|
50892
|
-
if (url.startsWith("data:")) {
|
|
50893
|
-
const i = url.indexOf("base64,");
|
|
50894
|
-
if (i >= 0) return applyCap(Math.ceil((url.length - i - "base64,".length) / 4));
|
|
50895
|
-
}
|
|
50896
|
-
return applyCap(REMOTE_IMAGE_TOKENS);
|
|
50897
|
-
}
|
|
50898
|
-
function isObj(v2) {
|
|
50899
|
-
return typeof v2 === "object" && v2 !== null;
|
|
50900
|
-
}
|
|
50901
|
-
function urlOf(v2) {
|
|
50902
|
-
if (typeof v2 === "string") return v2;
|
|
50903
|
-
if (isObj(v2) && typeof v2.url === "string") return v2.url;
|
|
50904
|
-
return void 0;
|
|
50905
|
-
}
|
|
50906
|
-
function imageTokensInParsedBody(protocol, body) {
|
|
50907
|
-
if (!isObj(body)) return 0;
|
|
50908
|
-
let total = 0;
|
|
50909
|
-
if (protocol === "responses") {
|
|
50910
|
-
const input = body.input;
|
|
50911
|
-
if (!Array.isArray(input)) return 0;
|
|
50912
|
-
for (const item of input) {
|
|
50913
|
-
if (!isObj(item) || !Array.isArray(item.content)) continue;
|
|
50914
|
-
for (const part of item.content) {
|
|
50915
|
-
if (!isObj(part) || part.type !== "input_image") continue;
|
|
50916
|
-
const url = urlOf(part.image_url);
|
|
50917
|
-
if (url) total += costForUrl(url);
|
|
50918
|
-
}
|
|
50919
|
-
}
|
|
50920
|
-
return total;
|
|
50921
|
-
}
|
|
50922
|
-
const messages = body.messages;
|
|
50923
|
-
if (!Array.isArray(messages)) return 0;
|
|
50924
|
-
for (const m2 of messages) {
|
|
50925
|
-
if (!isObj(m2) || !Array.isArray(m2.content)) continue;
|
|
50926
|
-
for (const part of m2.content) {
|
|
50927
|
-
if (!isObj(part)) continue;
|
|
50928
|
-
if (protocol === "openai") {
|
|
50929
|
-
if (part.type !== "image_url") continue;
|
|
50930
|
-
const url = urlOf(part.image_url);
|
|
50931
|
-
if (url) total += costForUrl(url);
|
|
50932
|
-
} else {
|
|
50933
|
-
if (part.type !== "image") continue;
|
|
50934
|
-
const src = part.source;
|
|
50935
|
-
if (isObj(src) && src.type === "base64" && typeof src.data === "string") total += applyCap(Math.ceil(src.data.length / 4));
|
|
50936
|
-
else if (isObj(src) && src.type === "url" && typeof src.url === "string") total += costForUrl(src.url);
|
|
50937
|
-
}
|
|
50938
|
-
}
|
|
50939
|
-
}
|
|
50940
|
-
return total;
|
|
50941
|
-
}
|
|
50942
|
-
function imageTokensInRawBody(protocol, raw) {
|
|
50943
|
-
const s3 = typeof raw === "string" ? raw : raw.toString("utf8");
|
|
50944
|
-
const probe = protocol === "responses" ? s3.includes("input_image") : protocol === "openai" ? s3.includes("image_url") : s3.includes('"type":"image"') || s3.includes('"type": "image"');
|
|
50945
|
-
if (!probe) return 0;
|
|
50946
|
-
try {
|
|
50947
|
-
return imageTokensInParsedBody(protocol, JSON.parse(s3));
|
|
50948
|
-
} catch {
|
|
50949
|
-
return 0;
|
|
50950
|
-
}
|
|
50951
|
-
}
|
|
50952
|
-
|
|
50953
50890
|
// src/web/index.ts
|
|
50954
50891
|
import { readFileSync as readFileSync3 } from "fs";
|
|
50955
50892
|
import { dirname as dirname4, join as join3 } from "path";
|
|
@@ -51158,7 +51095,7 @@ function renderPage(origin, version2) {
|
|
|
51158
51095
|
<div class="card"><div class="card-head"><h2>ZCode\uFF08\u7F16\u7A0B\u5957\u9910\uFF09</h2><span class="badge">MITM</span><button class="btn small copy-btn" data-copy="${caPathEsc}">\u590D\u5236 CA \u8DEF\u5F84</button></div><dl class="kv"><dt>\u65B9\u5F0F</dt><dd>MITM \u900F\u660E\u4EE3\u7406</dd><dt>\u8BBE\u7F6E</dt><dd>Settings \u2192 Network \u2192 HTTP Proxy = <span class="mono">${origin}</span></dd><dt>CA \u8BC1\u4E66</dt><dd class="mono">${caPathEsc}${caReady ? "" : "\uFF08\u5C1A\u672A\u751F\u6210\uFF0C\u542F\u52A8\u4EE3\u7406\u540E\u81EA\u52A8\u521B\u5EFA\uFF09"}</dd></dl><p class="hint">CA \u8DEF\u5F84\u662F\u672C\u673A bili \u5B9E\u9645\u751F\u6210\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u70B9"\u590D\u5236 CA \u8DEF\u5F84"\u540E\u76F4\u63A5\u7C98\u8D34\u8FDB ZCode\u3002\u26A0\uFE0F Windows \u4E0A ZCode \u4E0D\u4F1A\u5C55\u5F00 <span class="mono">~</span>\uFF0C\u8BF7\u52FF\u624B\u586B <span class="mono">~/\u2026</span> \u5F62\u5F0F\u7684\u8DEF\u5F84\u3002</p></div></section>
|
|
51159
51096
|
<section id="page-upstream" class="page"><h1>\u4E0A\u6E38\u7F51\u7EDC</h1><p class="lead">\u63A7\u5236 bili \u5982\u4F55\u8BBF\u95EE\u771F\u5B9E Provider\uFF0C\u4E0D\u4F1A\u6539\u53D8\u5BA2\u6237\u7AEF\u7684\u672C\u5730\u8DEF\u7531\u5730\u5740\u3002</p><div class="card"><div class="card-head"><h2>\u5168\u5C40\u4EE3\u7406</h2></div><div class="modes"><label><input type="radio" name="proxy-mode" value="direct" checked>\u76F4\u8FDE\uFF08\u9ED8\u8BA4\uFF09</label><label><input type="radio" name="proxy-mode" value="manual">\u624B\u52A8\u4EE3\u7406</label><label><input type="radio" name="proxy-mode" value="auto">\u81EA\u52A8\uFF08\u8DDF\u968F\u7CFB\u7EDF\uFF09</label></div><div class="field"><label>HTTP / HTTPS Proxy</label><input id="proxy-url" class="mono" placeholder="http://127.0.0.1:7897"></div><dl class="kv"><dt>\u5F53\u524D\u6765\u6E90</dt><dd id="upstream-source">\u76F4\u8FDE</dd><dt>\u6709\u6548\u4EE3\u7406</dt><dd id="upstream-effective" class="mono">direct</dd><dt>\u7CFB\u7EDF PAC</dt><dd id="upstream-pac" class="mono">\u2014</dd><dt>\u72B6\u6001</dt><dd id="upstream-state" class="status">\u5C1A\u672A\u6D4B\u8BD5</dd></dl><div class="actions"><button id="save-upstream" class="btn primary">\u4FDD\u5B58\u5E76\u70ED\u66F4\u65B0</button><button id="test-upstream" class="btn">\u6D4B\u8BD5\u8FDE\u63A5</button></div></div><div class="card"><div class="card-head"><h2>\u6309 URL \u8986\u76D6</h2></div><p class="status">\u4E3A\u7279\u5B9A Provider \u5355\u72EC\u8BBE\u7F6E\u4E0A\u6E38\u4EE3\u7406\uFF0C\u8986\u76D6\u5168\u5C40\u8BBE\u7F6E\u3002\u7559\u7A7A = \u7EE7\u627F\u5168\u5C40\u3002</p><div id="upstream-overrides" class="status">\u52A0\u8F7D\u4E2D</div><div class="actions"><button id="save-overrides" class="btn primary">\u4FDD\u5B58\u8986\u76D6\u5E76\u70ED\u66F4\u65B0</button></div></div></section>
|
|
51160
51097
|
<section id="page-sessions" class="page"><div class="card-head"><div><h1>\u4F1A\u8BDD</h1><p class="lead">ACP \u538B\u7F29\u72B6\u6001\u4E0E\u4E0A\u6E38\u7528\u91CF\u3002</p></div><button id="refresh-sessions" class="btn">\u5237\u65B0</button></div><div class="card"><table><thead><tr><th>\u6807\u9898</th><th>\u534F\u8BAE</th><th>\u6807\u8BC6</th><th>\u8BF7\u6C42</th><th>\u4E0A\u4E0B\u6587</th><th>\u6700\u540E\u6D3B\u52A8</th></tr></thead><tbody id="sessions-body"></tbody></table></div></section>
|
|
51161
|
-
<section id="page-settings" class="page"><h1>\u9AD8\u7EA7\u8BBE\u7F6E</h1><p class="lead">\u76F4\u63A5\u7F16\u8F91 providers JSON\uFF08\u6DFB\u52A0\u65B0 Provider\u3001\u914D\u7F6E\u6A21\u578B\u4E0A\u4E0B\u6587\u7A97\u53E3\u3001\u6309 URL \u4EE3\u7406\u7B49\uFF09\uFF1B\u4FDD\u5B58\u540E\u7ACB\u5373\u70ED\u66F4\u65B0\u3002</p><div class="card"><div class="field"><label>providers JSON</label><textarea id="providers-json">{}</textarea></div><div class="actions"><button id="save-providers" class="btn primary">\u4FDD\u5B58\u5E76\u5E94\u7528</button></div></div><div class="card"><div class="card-head"><h2>\u538B\u7F29\u53C2\u6570\uFF08\u5168\u5C40\uFF09</h2></div><p class="status">\u5168\u5C40 compress \u914D\u7F6E\uFF08modelContextLimit / maxContextLimit / emergencyThresholdPercent / nudgeGrowthTokens / preserveRecentMessages / preserveRecentTokens / minCompressRange / tiers / injectTool / injectNudge\uFF09\u3002\u4FDD\u5B58\u540E\u70ED\u66F4\u65B0\uFF0C\u65E0\u9700\u91CD\u542F\u3002\u7F6E\u7A7A = \u6062\u590D\u9ED8\u8BA4\u3002</p><div class="field"><label>compress JSON</label><textarea id="compress-json" placeholder='{"modelContextLimit": 200000}'></textarea></div><div class="actions"><button id="save-compress" class="btn primary">\u4FDD\u5B58\u5E76\u70ED\u66F4\u65B0</button></div></div></section></main></div><div id="toast" class="toast"></div><script>${WEB_CLIENT}</script></body></html>`;
|
|
51098
|
+
<section id="page-settings" class="page"><h1>\u9AD8\u7EA7\u8BBE\u7F6E</h1><p class="lead">\u76F4\u63A5\u7F16\u8F91 providers JSON\uFF08\u6DFB\u52A0\u65B0 Provider\u3001\u914D\u7F6E\u6A21\u578B\u4E0A\u4E0B\u6587\u7A97\u53E3\u3001\u6309 URL \u4EE3\u7406\u7B49\uFF09\uFF1B\u4FDD\u5B58\u540E\u7ACB\u5373\u70ED\u66F4\u65B0\u3002</p><div class="card"><div class="field"><label>providers JSON</label><textarea id="providers-json">{}</textarea></div><div class="actions"><button id="save-providers" class="btn primary">\u4FDD\u5B58\u5E76\u5E94\u7528</button></div></div><div class="card"><div class="card-head"><h2>\u538B\u7F29\u53C2\u6570\uFF08\u5168\u5C40\uFF09</h2></div><p class="status">\u5168\u5C40 compress \u914D\u7F6E\uFF08modelContextLimit / maxContextLimit / emergencyThresholdPercent / nudgeGrowthTokens / preserveRecentMessages / preserveRecentTokens / minCompressRangeChars\uFF08\u5355\u4F4D\uFF1A\u5B57\u7B26\uFF0C\u65E7\u540D minCompressRange \u517C\u5BB9\uFF09 / tiers / injectTool / injectNudge\uFF09\u3002\u4FDD\u5B58\u540E\u70ED\u66F4\u65B0\uFF0C\u65E0\u9700\u91CD\u542F\u3002\u7F6E\u7A7A = \u6062\u590D\u9ED8\u8BA4\u3002</p><div class="field"><label>compress JSON</label><textarea id="compress-json" placeholder='{"modelContextLimit": 200000}'></textarea></div><div class="actions"><button id="save-compress" class="btn primary">\u4FDD\u5B58\u5E76\u70ED\u66F4\u65B0</button></div></div></section></main></div><div id="toast" class="toast"></div><script>${WEB_CLIENT}</script></body></html>`;
|
|
51162
51099
|
}
|
|
51163
51100
|
|
|
51164
51101
|
// src/web/api.ts
|
|
@@ -57307,7 +57244,7 @@ function emergencyNudge(nudge, escalationPct = EMERGENCY_NUDGE_ESCALATION_PCT) {
|
|
|
57307
57244
|
function clampOutgoingOutput(rebuilt, field, ctx, sessionId, log2) {
|
|
57308
57245
|
const raw = rebuilt[field];
|
|
57309
57246
|
if (typeof raw !== "number") return;
|
|
57310
|
-
const inputEstimate = estimateInputTokens(ctx.processedMessages, ctx.systemText, ctx.tools, ctx.lastInputTokens)
|
|
57247
|
+
const inputEstimate = estimateInputTokens(ctx.processedMessages, ctx.systemText, ctx.tools, ctx.lastInputTokens);
|
|
57311
57248
|
const capped = clampOutputBudget(raw, inputEstimate, ctx.nativeWindow);
|
|
57312
57249
|
if (capped !== void 0) {
|
|
57313
57250
|
rebuilt[field] = capped;
|
|
@@ -57372,7 +57309,7 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
57372
57309
|
processedMessages = [];
|
|
57373
57310
|
}
|
|
57374
57311
|
const rebuilt = { ...parsed, messages: rebuiltMessages, tools: toolsOut };
|
|
57375
|
-
clampOutgoingOutput(rebuilt, typeof parsed.max_completion_tokens === "number" ? "max_completion_tokens" : "max_tokens", { systemText: openaiSystemText, tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow
|
|
57312
|
+
clampOutgoingOutput(rebuilt, typeof parsed.max_completion_tokens === "number" ? "max_completion_tokens" : "max_tokens", { systemText: openaiSystemText, tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow }, sessionId, log2);
|
|
57376
57313
|
delete rebuilt.prompt_cache_retention;
|
|
57377
57314
|
if (stream2 && rebuilt.stream_options === void 0) {
|
|
57378
57315
|
rebuilt.stream_options = { include_usage: true };
|
|
@@ -57490,7 +57427,7 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
57490
57427
|
}
|
|
57491
57428
|
const rebuilt = { ...parsed, input: rebuiltInput, tools: toolsOut };
|
|
57492
57429
|
if (!isCompactionTrigger) {
|
|
57493
|
-
clampOutgoingOutput(rebuilt, "max_output_tokens", { systemText: (responsesProjection?.systemParts ?? []).join("\n"), tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow
|
|
57430
|
+
clampOutgoingOutput(rebuilt, "max_output_tokens", { systemText: (responsesProjection?.systemParts ?? []).join("\n"), tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow }, sessionId, log2);
|
|
57494
57431
|
}
|
|
57495
57432
|
const promptCacheKey = resolvePromptCacheKey(
|
|
57496
57433
|
rebuilt.prompt_cache_key,
|
|
@@ -57715,13 +57652,11 @@ function isPreflightFailFast(outcome) {
|
|
|
57715
57652
|
async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, core, config, model, route, affinity, log2, instanceId) {
|
|
57716
57653
|
const session = prepared.session;
|
|
57717
57654
|
const limit = config.modelContextLimit;
|
|
57718
|
-
const
|
|
57719
|
-
const payloadEstimate = estimateCoreMessages(prepared.processedMessages) + imageTokens;
|
|
57655
|
+
const payloadEstimate = estimateCoreMessages(prepared.processedMessages);
|
|
57720
57656
|
const tokenCount = Math.max(session.stats.lastInputTokens, payloadEstimate);
|
|
57721
57657
|
if (limit <= 0 || !model || tokenCount < limit) return prepared;
|
|
57722
57658
|
const failFast = (status2, detail, retryable) => {
|
|
57723
|
-
const
|
|
57724
|
-
const message = `context ~${tokenCount} tokens exceeds the model window ${limit} (model=${model}) and preflight compression could not bring it under: ${detail}.` + imageNote + ` The over-window payload was NOT forwarded.`;
|
|
57659
|
+
const message = `context ~${tokenCount} tokens exceeds the model window ${limit} (model=${model}) and preflight compression could not bring it under: ${detail}. The over-window payload was NOT forwarded.`;
|
|
57725
57660
|
log2("error", `[${session.id}] preflight fail-fast ${status2} (retryable=${retryable}): ${message}`);
|
|
57726
57661
|
return { failFast: true, status: status2, message, retryable, respond: !res.writableEnded };
|
|
57727
57662
|
};
|
|
@@ -57751,8 +57686,7 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
57751
57686
|
model,
|
|
57752
57687
|
proxyUrl,
|
|
57753
57688
|
signal: clientAbort.signal,
|
|
57754
|
-
log: log2
|
|
57755
|
-
imageFloor: imageTokens
|
|
57689
|
+
log: log2
|
|
57756
57690
|
},
|
|
57757
57691
|
prepared.originalMessages
|
|
57758
57692
|
);
|
|
@@ -57921,12 +57855,9 @@ ${hdrText}
|
|
|
57921
57855
|
const info = inspectContextOverflow(upstream.status, errBody.toString("utf8"));
|
|
57922
57856
|
if (info.isOverflow) {
|
|
57923
57857
|
let reqModel;
|
|
57924
|
-
let rejectedImageTokens = 0;
|
|
57925
57858
|
try {
|
|
57926
57859
|
const rawBody = typeof prepared.body === "string" ? prepared.body : prepared.body.toString("utf8");
|
|
57927
|
-
|
|
57928
|
-
reqModel = typeof parsedBody.model === "string" ? parsedBody.model : void 0;
|
|
57929
|
-
rejectedImageTokens = imageTokensInParsedBody(prepared.protocol, parsedBody);
|
|
57860
|
+
reqModel = JSON.parse(rawBody).model;
|
|
57930
57861
|
} catch {
|
|
57931
57862
|
reqModel = void 0;
|
|
57932
57863
|
}
|
|
@@ -57938,7 +57869,7 @@ ${hdrText}
|
|
|
57938
57869
|
s3.metadata.learnedContextLimits = learnedMap;
|
|
57939
57870
|
log2("warn", `[${s3.id}] upstream context overflow \u2014 learned real window ${info.window} for ${reqModel ?? "(unknown model)"} (was ${prev ?? "unset"}); arming emergency shrink`);
|
|
57940
57871
|
} else {
|
|
57941
|
-
const payloadEstimate = estimateCoreMessages(prepared.processedMessages)
|
|
57872
|
+
const payloadEstimate = estimateCoreMessages(prepared.processedMessages);
|
|
57942
57873
|
const prev = (reqModel ? learnedMap[reqModel] : void 0) ?? s3.metadata.learnedContextLimit;
|
|
57943
57874
|
if (payloadEstimate >= 1e3 && (prev === void 0 || payloadEstimate < prev)) {
|
|
57944
57875
|
if (reqModel) learnedMap[reqModel] = payloadEstimate;
|