billion-context 0.1.75-pr.490.310 → 0.1.75-pr.493.315
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 +23 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48479,11 +48479,14 @@ ${summary}` }]
|
|
|
48479
48479
|
}
|
|
48480
48480
|
return { items, replaced, dropped };
|
|
48481
48481
|
}
|
|
48482
|
-
function
|
|
48483
|
-
if (
|
|
48482
|
+
function codexCompactGatePre(session, effectiveLimit) {
|
|
48483
|
+
if (effectiveLimit <= 0) return false;
|
|
48484
48484
|
if (session.stats.lastInputTokens >= effectiveLimit * 0.9) return false;
|
|
48485
48485
|
return session.state.blocks.some((b2) => b2.active);
|
|
48486
48486
|
}
|
|
48487
|
+
function codexCompactGate(session, effectiveLimit, transformOk) {
|
|
48488
|
+
return transformOk && codexCompactGatePre(session, effectiveLimit);
|
|
48489
|
+
}
|
|
48487
48490
|
function buildTriggerForgeBody(summaryText, usage, stream2) {
|
|
48488
48491
|
const compactionItem = {
|
|
48489
48492
|
type: "compaction",
|
|
@@ -51914,6 +51917,7 @@ var CONTEXT_OVERFLOW_PATTERNS = [
|
|
|
51914
51917
|
/maximum context length/i,
|
|
51915
51918
|
/max context length/i,
|
|
51916
51919
|
/maximum context size/i,
|
|
51920
|
+
/longer than the model'?s context length/i,
|
|
51917
51921
|
/exceeds the context window/i,
|
|
51918
51922
|
/out of room in the model/i,
|
|
51919
51923
|
/exceeded model token limit/i,
|
|
@@ -51930,7 +51934,7 @@ function toTokenNumber(s3) {
|
|
|
51930
51934
|
function parseOverflowWindow(text) {
|
|
51931
51935
|
let m2 = text.match(/>\s*(\d[\d,]*)\s*maximum/i);
|
|
51932
51936
|
if (m2) return toTokenNumber(m2[1]);
|
|
51933
|
-
m2 = text.match(/maximum context length is (\d[\d,]*)/i) ?? text.match(/maximum context length of (\d[\d,]*)/i) ?? text.match(/maximum context size (?:is|of) (\d[\d,]*)/i) ?? text.match(/(?:maximum|max)\s+(?:context\s+)?length\s+(?:is\s+)?(\d[\d,]*)/i) ?? text.match(/limit of (\d[\d,]*)\s*token/i) ?? text.match(/(\d[\d,]*)\s*maximum\b/i);
|
|
51937
|
+
m2 = text.match(/maximum context length is (\d[\d,]*)/i) ?? text.match(/maximum context length of (\d[\d,]*)/i) ?? text.match(/maximum context size (?:is|of) (\d[\d,]*)/i) ?? text.match(/(?:maximum|max)\s+(?:context\s+)?length\s+(?:is\s+)?(\d[\d,]*)/i) ?? text.match(/context length\s*\((\d[\d,]*)\s*token/i) ?? text.match(/limit of (\d[\d,]*)\s*token/i) ?? text.match(/(\d[\d,]*)\s*maximum\b/i);
|
|
51934
51938
|
if (m2) return toTokenNumber(m2[1]);
|
|
51935
51939
|
return void 0;
|
|
51936
51940
|
}
|
|
@@ -57074,6 +57078,21 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
57074
57078
|
try {
|
|
57075
57079
|
await withSessionLock(session, async () => {
|
|
57076
57080
|
const runPrepare = () => countTokens ? prepareCountTokens(parsed, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode) : protocol === "openai" ? prepareOpenai(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode, nativeWindow) : responsesCompact ? prepareResponsesCompact(bodyBuffer, parsed, session, req, core, reqConfig, log2) : prepareResponses(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, responsesIdentity, pluginMode, upstreamOrigin, nativeWindow);
|
|
57081
|
+
const isCodexCompactTrigger = protocol === "responses" && !responsesCompact && isCodexClient(req.headers) && hasCompactionTrigger(parsed.input);
|
|
57082
|
+
if (isCodexCompactTrigger) {
|
|
57083
|
+
const mode = codexCompactMode();
|
|
57084
|
+
const gatePre = codexCompactGatePre(session, reqConfig.modelContextLimit);
|
|
57085
|
+
if (mode === "intercept" && gatePre) prepared = runPrepare();
|
|
57086
|
+
if (prepared?.codexForge) {
|
|
57087
|
+
await forward(req, res, opts, prepared.body, prepared, core, reqConfig, log2, route, instanceId, affinity);
|
|
57088
|
+
rememberPluginMessages(sessionId, prepared.processedMessages, prepared.originalMessages, prepared.nudge);
|
|
57089
|
+
return;
|
|
57090
|
+
}
|
|
57091
|
+
const why = mode !== "intercept" ? "BILI_CODEX_COMPACT=pass" : !gatePre ? "gate preconditions not met" : "transform/forge failed";
|
|
57092
|
+
log2("info", `[${session.id}] codex compaction_trigger request not intercepted (${why}) \u2014 forwarding verbatim (no preflight, no rebuild, no window clamp)`);
|
|
57093
|
+
await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route, instanceId, affinity);
|
|
57094
|
+
return;
|
|
57095
|
+
}
|
|
57077
57096
|
prepared = runPrepare();
|
|
57078
57097
|
if (!countTokens && !responsesCompact) {
|
|
57079
57098
|
const outcome = await preflightCompressIfNeeded(
|
|
@@ -57519,7 +57538,7 @@ function prepareResponsesCompact(body, parsed, session, req, core, config, log2)
|
|
|
57519
57538
|
compressInjected: false,
|
|
57520
57539
|
resetAfterSuccess: true
|
|
57521
57540
|
};
|
|
57522
|
-
if (codexCompactMode() !== "intercept" || !isCodexClient(req.headers) || !Array.isArray(parsed.input)) {
|
|
57541
|
+
if (codexCompactMode() !== "intercept" || !isCodexClient(req.headers) || !Array.isArray(parsed.input) || !codexCompactGatePre(session, config.modelContextLimit)) {
|
|
57523
57542
|
return base;
|
|
57524
57543
|
}
|
|
57525
57544
|
const prevState = session.state;
|