billion-context 0.1.59-pr.308.158 → 0.1.59
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 +32 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43649,7 +43649,7 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43649
43649
|
if (compressible.length === 0 && protectedRanges.length === 0) {
|
|
43650
43650
|
return "[No specific ranges detected \u2014 compress any consumed content.]";
|
|
43651
43651
|
}
|
|
43652
|
-
const
|
|
43652
|
+
const refNum3 = (ref) => {
|
|
43653
43653
|
const m2 = ref.match(/\d+/);
|
|
43654
43654
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
43655
43655
|
};
|
|
@@ -43658,8 +43658,8 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43658
43658
|
entries.push({
|
|
43659
43659
|
startRef: r.startRef,
|
|
43660
43660
|
endRef: r.endRef,
|
|
43661
|
-
startNum:
|
|
43662
|
-
endNum:
|
|
43661
|
+
startNum: refNum3(r.startRef),
|
|
43662
|
+
endNum: refNum3(r.endRef),
|
|
43663
43663
|
count: r.count,
|
|
43664
43664
|
tokens: r.tokens,
|
|
43665
43665
|
toolPct: r.toolPct,
|
|
@@ -43676,8 +43676,8 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43676
43676
|
entries.push({
|
|
43677
43677
|
startRef: r.startRef,
|
|
43678
43678
|
endRef: r.endRef,
|
|
43679
|
-
startNum:
|
|
43680
|
-
endNum:
|
|
43679
|
+
startNum: refNum3(r.startRef),
|
|
43680
|
+
endNum: refNum3(r.endRef),
|
|
43681
43681
|
count: r.count,
|
|
43682
43682
|
tokens: r.tokens,
|
|
43683
43683
|
toolPct: 0,
|
|
@@ -48016,10 +48016,6 @@ function replayBaseDelayMs() {
|
|
|
48016
48016
|
const raw = Number(process.env.BILI_REPLAY_RETRY_BASE_MS);
|
|
48017
48017
|
return Number.isFinite(raw) && raw >= 0 ? raw : 1500;
|
|
48018
48018
|
}
|
|
48019
|
-
function maxShrinkPerCompress() {
|
|
48020
|
-
const raw = Number(process.env.BILI_MAX_SHRINK_PER_COMPRESS);
|
|
48021
|
-
return Number.isFinite(raw) && raw > 0 && raw <= 1 ? raw : void 0;
|
|
48022
|
-
}
|
|
48023
48019
|
function replayBackoffMs(attempt) {
|
|
48024
48020
|
return replayBaseDelayMs() * 2 ** (attempt - 1);
|
|
48025
48021
|
}
|
|
@@ -49595,10 +49591,6 @@ function getStore() {
|
|
|
49595
49591
|
}
|
|
49596
49592
|
|
|
49597
49593
|
// src/session.ts
|
|
49598
|
-
function lastCompressSuffix(info) {
|
|
49599
|
-
if (!info) return "";
|
|
49600
|
-
return ` [after compress: shrink ${Math.round(info.shrinkRatio * 100)}% foldPoint=${info.foldPoint} blocks=${info.blocks} ~${info.tokensCompressed}tok]`;
|
|
49601
|
-
}
|
|
49602
49594
|
var sessions = /* @__PURE__ */ new Map();
|
|
49603
49595
|
var MAX_SESSIONS = Math.max(1, Number.parseInt(process.env.BILI_MAX_SESSIONS ?? "256", 10) || 256);
|
|
49604
49596
|
var initialized = false;
|
|
@@ -49752,11 +49744,6 @@ function parseCompressInput(input, callId) {
|
|
|
49752
49744
|
}
|
|
49753
49745
|
return ranges;
|
|
49754
49746
|
}
|
|
49755
|
-
var STAGED_COMPRESS_GUIDANCE = "\n\n[Smooth-transition guidance: when you compress, prefer a SMALLER, TAIL-biased range \u2014 compress the most recent large content and keep the stable prefix (the earliest messages) intact. A large single rewrite changes the request shape sharply and can trip provider risk-control; smaller tail-biased folds keep the prefix cache alive and the transition gentle.]";
|
|
49756
|
-
function withStagedCompressGuidance(text) {
|
|
49757
|
-
if (maxShrinkPerCompress() === void 0) return text;
|
|
49758
|
-
return text + STAGED_COMPRESS_GUIDANCE;
|
|
49759
|
-
}
|
|
49760
49747
|
|
|
49761
49748
|
// src/decompress-shared.ts
|
|
49762
49749
|
import { mkdirSync as mkdirSync3, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
|
|
@@ -49843,17 +49830,15 @@ function normalizeSseLineEndings(buf) {
|
|
|
49843
49830
|
}
|
|
49844
49831
|
|
|
49845
49832
|
// src/loop/tag-echo-filter.ts
|
|
49846
|
-
var PAIRED = /\x3cacp\s[^<>]
|
|
49847
|
-
var
|
|
49848
|
-
var LONE_CLOSE = /<\/acp(?=[\s>])[^<>]{0,32}>/;
|
|
49833
|
+
var PAIRED = /\x3cacp\s[^<>]*>([^<>]{0,64})<\/acp>/;
|
|
49834
|
+
var LONE = /<\/?acp(?=[\s>])[^<>]*>/;
|
|
49849
49835
|
var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|<\/?a?c?p?)$/;
|
|
49850
|
-
var
|
|
49836
|
+
var TRUNCATED_TAG = /\x3cacp\s[^<>]*tokens\s*=\s*"[^<>"]*"[^<>]*$/;
|
|
49851
49837
|
var CLOSE_TAG = "</acp";
|
|
49852
49838
|
var HOLD_LIMIT = 128;
|
|
49853
|
-
var TAG_OPEN_CAP = 4096;
|
|
49854
49839
|
var SWALLOW_CAP = 80;
|
|
49855
49840
|
function stripAcpTags(text) {
|
|
49856
|
-
return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(
|
|
49841
|
+
return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(LONE.source, "g"), "").replace(new RegExp(TRUNCATED_TAG.source), "");
|
|
49857
49842
|
}
|
|
49858
49843
|
function containsRenderTagText(s3) {
|
|
49859
49844
|
return /\x3c\/?acp(?=[\s>])/.test(s3) || /\\u003c\/?acp(?=[\s>\\])/.test(s3);
|
|
@@ -49896,26 +49881,15 @@ function createTagEchoFilter(onDrop) {
|
|
|
49896
49881
|
return out;
|
|
49897
49882
|
}
|
|
49898
49883
|
const p2 = PAIRED.exec(buf);
|
|
49899
|
-
const
|
|
49900
|
-
|
|
49901
|
-
|
|
49902
|
-
|
|
49903
|
-
if (cand && (m2 === null || cand.index < m2.index)) m2 = cand;
|
|
49904
|
-
}
|
|
49884
|
+
const l = LONE.exec(buf);
|
|
49885
|
+
let m2;
|
|
49886
|
+
if (p2 && l) m2 = p2.index <= l.index ? p2 : l;
|
|
49887
|
+
else m2 = p2 ?? l;
|
|
49905
49888
|
if (!m2) {
|
|
49906
49889
|
const t = PARTIAL_TAIL.exec(buf);
|
|
49907
|
-
if (t) {
|
|
49908
|
-
|
|
49909
|
-
|
|
49910
|
-
if (t[0].length <= cap) {
|
|
49911
|
-
held = t[0];
|
|
49912
|
-
out += buf.slice(0, buf.length - t[0].length);
|
|
49913
|
-
} else if (definite) {
|
|
49914
|
-
drop(t[0]);
|
|
49915
|
-
out += buf.slice(0, buf.length - t[0].length);
|
|
49916
|
-
} else {
|
|
49917
|
-
out += buf;
|
|
49918
|
-
}
|
|
49890
|
+
if (t && t[0].length <= HOLD_LIMIT) {
|
|
49891
|
+
held = t[0];
|
|
49892
|
+
out += buf.slice(0, buf.length - t[0].length);
|
|
49919
49893
|
} else {
|
|
49920
49894
|
out += buf;
|
|
49921
49895
|
}
|
|
@@ -49924,7 +49898,8 @@ function createTagEchoFilter(onDrop) {
|
|
|
49924
49898
|
drop(m2[0]);
|
|
49925
49899
|
out += buf.slice(0, m2.index);
|
|
49926
49900
|
buf = buf.slice(m2.index + m2[0].length);
|
|
49927
|
-
|
|
49901
|
+
const wasPaired = m2 === p2;
|
|
49902
|
+
if (!wasPaired && /^\x3cacp\s/.test(m2[0])) {
|
|
49928
49903
|
swallowUntilClose = true;
|
|
49929
49904
|
swallowed = "";
|
|
49930
49905
|
}
|
|
@@ -49938,19 +49913,14 @@ function createTagEchoFilter(onDrop) {
|
|
|
49938
49913
|
return process2(chunk);
|
|
49939
49914
|
},
|
|
49940
49915
|
flush() {
|
|
49941
|
-
|
|
49942
|
-
const wasSwallowing = swallowUntilClose;
|
|
49916
|
+
let rest = swallowed + held;
|
|
49943
49917
|
swallowed = "";
|
|
49944
49918
|
held = "";
|
|
49945
49919
|
swallowUntilClose = false;
|
|
49946
|
-
|
|
49947
|
-
if (rest.length > 0) drop(rest);
|
|
49948
|
-
return "";
|
|
49949
|
-
}
|
|
49950
|
-
const t = new RegExp(TRUNC_OPEN.source).exec(rest);
|
|
49920
|
+
const t = new RegExp(TRUNCATED_TAG.source).exec(rest);
|
|
49951
49921
|
if (t) {
|
|
49952
49922
|
drop(t[0]);
|
|
49953
|
-
|
|
49923
|
+
rest = rest.slice(0, t.index);
|
|
49954
49924
|
}
|
|
49955
49925
|
return rest;
|
|
49956
49926
|
},
|
|
@@ -50031,9 +50001,6 @@ ${lines.join("\n\n")}`;
|
|
|
50031
50001
|
}
|
|
50032
50002
|
return `[Unknown proxy tool: ${toolName}]`;
|
|
50033
50003
|
}
|
|
50034
|
-
function refNum2(ref) {
|
|
50035
|
-
return Number(ref.replace(/\D/g, "")) || 0;
|
|
50036
|
-
}
|
|
50037
50004
|
function applyRanges(ranges, ctx) {
|
|
50038
50005
|
if (ranges.length === 0) {
|
|
50039
50006
|
ctx.log("[acp-proxy: compress call had no valid ranges; nothing compressed.]");
|
|
@@ -50072,17 +50039,8 @@ function applyRanges(ranges, ctx) {
|
|
|
50072
50039
|
ctx.log(`[acp-proxy: compress FAILED ${detail} \u2192 0 blocks. ${errs}]`);
|
|
50073
50040
|
return `[Compression FAILED: ${errs}]`;
|
|
50074
50041
|
}
|
|
50075
|
-
const preContext = ctx.session.stats.lastInputTokens;
|
|
50076
|
-
const shrinkRatio = preContext > 0 ? r.tokensCompressed / preContext : 0;
|
|
50077
|
-
const foldPoint = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef))[0]?.startRef ?? "unknown";
|
|
50078
|
-
ctx.session.lastCompress = { at: Date.now(), shrinkRatio, foldPoint, blocks: r.blocksCreated, tokensCompressed: r.tokensCompressed };
|
|
50079
|
-
ctx.log(`[acp-compress-obs] shrink ${Math.round(shrinkRatio * 100)}% (~${r.tokensCompressed}/${preContext} tok) foldPoint=${foldPoint} blocks=${r.blocksCreated}`);
|
|
50080
50042
|
const warn = r.warnings.length > 0 ? ` ${r.warnings.join("; ")}` : "";
|
|
50081
|
-
|
|
50082
|
-
const maxShrink = maxShrinkPerCompress();
|
|
50083
|
-
if (maxShrink !== void 0 && shrinkRatio > maxShrink) {
|
|
50084
|
-
msg += ` [Staged-compress: this rewrite shrank context ${Math.round(shrinkRatio * 100)}%, above your ${Math.round(maxShrink * 100)}% per-compress target \u2014 the shape that trips provider risk-control (3007). Next time compress a SMALLER, TAIL-biased range (the most recent large content) and keep the stable prefix intact.]`;
|
|
50085
|
-
}
|
|
50043
|
+
const msg = `[Compressed ${detail} \u2192 ${r.blocksCreated} block(s), ~${r.tokensCompressed} tokens saved.${warn}]`;
|
|
50086
50044
|
ctx.log(`[acp-proxy: ${msg}]`);
|
|
50087
50045
|
ctx.session.stats.compressCreditTokens = (ctx.session.stats.compressCreditTokens ?? 0) + r.tokensCompressed;
|
|
50088
50046
|
ctx.session.stats.lastInputTokens = Math.max(0, ctx.session.stats.lastInputTokens - r.tokensCompressed);
|
|
@@ -50140,7 +50098,7 @@ function refMaps(messages, state) {
|
|
|
50140
50098
|
});
|
|
50141
50099
|
return { refToIdx, idxToRef };
|
|
50142
50100
|
}
|
|
50143
|
-
function
|
|
50101
|
+
function refNum2(ref) {
|
|
50144
50102
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
50145
50103
|
}
|
|
50146
50104
|
function estimateCoreMessages(messages) {
|
|
@@ -50230,9 +50188,7 @@ TASK: The conversation segment below (messages ${startRef}\u2013${endRef}) must
|
|
|
50230
50188
|
},
|
|
50231
50189
|
void 0,
|
|
50232
50190
|
deps.signal,
|
|
50233
|
-
(info) => {
|
|
50234
|
-
deps.log("warn", `[preflight] summary attempt ${info.attempt} got HTTP ${info.status}; retrying in ${info.delayMs}ms${lastCompressSuffix(deps.session.lastCompress)}`);
|
|
50235
|
-
}
|
|
50191
|
+
(info) => deps.log("warn", `[preflight] summary attempt ${info.attempt} got HTTP ${info.status}; retrying in ${info.delayMs}ms`)
|
|
50236
50192
|
);
|
|
50237
50193
|
try {
|
|
50238
50194
|
const text = await response.text();
|
|
@@ -50277,7 +50233,7 @@ async function preflightCompress(deps, messages) {
|
|
|
50277
50233
|
if (currentTokens < limit) break;
|
|
50278
50234
|
const ranges = viableRanges(turn.nudge?.compressibleRanges ?? []);
|
|
50279
50235
|
if (ranges.length === 0) break;
|
|
50280
|
-
const range = [...ranges].sort((a, b2) =>
|
|
50236
|
+
const range = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef))[0];
|
|
50281
50237
|
const { refToIdx } = refMaps(messages, deps.session.state);
|
|
50282
50238
|
const startIdx = refToIdx.get(range.startRef);
|
|
50283
50239
|
const endIdx = refToIdx.get(range.endRef);
|
|
@@ -50907,9 +50863,8 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
50907
50863
|
void 0,
|
|
50908
50864
|
signal,
|
|
50909
50865
|
(info) => {
|
|
50910
|
-
|
|
50911
|
-
|
|
50912
|
-
log("warn", `[acp-loop] upstream rejected replay (HTTP ${info.status}); retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})${lc}`);
|
|
50866
|
+
ctx.log(`[acp-proxy: upstream rejected replay (HTTP ${info.status}: ${info.detail.slice(0, 120)}); likely provider risk-control \u2014 retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})]`);
|
|
50867
|
+
log("warn", `[acp-loop] upstream rejected replay (HTTP ${info.status}); retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})`);
|
|
50913
50868
|
}
|
|
50914
50869
|
);
|
|
50915
50870
|
let newBody = adapter.buildRequest(coreMessages, systemPrompt, requestBody);
|
|
@@ -52419,9 +52374,8 @@ async function compressLoopResponsesJson(initialResponse, ctx, requestBody, requ
|
|
|
52419
52374
|
body: JSON.stringify(requestBody),
|
|
52420
52375
|
...ctx.proxyUrl ? { dispatcher: proxyDispatcher(ctx.proxyUrl) } : {}
|
|
52421
52376
|
}, void 0, void 0, (info) => {
|
|
52422
|
-
|
|
52423
|
-
|
|
52424
|
-
log("warn", `[acp-compress-responses] upstream rejected replay (HTTP ${info.status}); retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})${lc}`);
|
|
52377
|
+
ctx.log(`[acp-proxy: responses upstream rejected replay (HTTP ${info.status}: ${info.detail.slice(0, 120)}); likely provider risk-control \u2014 retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})]`);
|
|
52378
|
+
log("warn", `[acp-compress-responses] upstream rejected replay (HTTP ${info.status}); retrying in ${info.delayMs}ms (attempt ${info.attempt}/${info.maxAttempts})`);
|
|
52425
52379
|
}).catch((e) => {
|
|
52426
52380
|
if (e instanceof UpstreamHttpError) {
|
|
52427
52381
|
const suffix = e.attempts > 1 ? ` after ${e.attempts} attempt(s)` : "";
|
|
@@ -55414,7 +55368,7 @@ function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
55414
55368
|
try {
|
|
55415
55369
|
const rendered = renderNudgeText(turn.nudge, prompts);
|
|
55416
55370
|
if (rendered.text) {
|
|
55417
|
-
rebuiltMessages = [...rebuiltMessages, { role: "user", content:
|
|
55371
|
+
rebuiltMessages = [...rebuiltMessages, { role: "user", content: rendered.text }];
|
|
55418
55372
|
}
|
|
55419
55373
|
} catch {
|
|
55420
55374
|
}
|
|
@@ -55473,7 +55427,7 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
55473
55427
|
try {
|
|
55474
55428
|
const rendered = renderNudgeText(turn.nudge, prompts);
|
|
55475
55429
|
if (rendered.text) {
|
|
55476
|
-
rebuiltMessages = [...rebuiltMessages, { role: "user", content:
|
|
55430
|
+
rebuiltMessages = [...rebuiltMessages, { role: "user", content: rendered.text }];
|
|
55477
55431
|
}
|
|
55478
55432
|
} catch {
|
|
55479
55433
|
}
|
|
@@ -55556,7 +55510,7 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
55556
55510
|
const rendered = renderNudgeText(turn.nudge, prompts);
|
|
55557
55511
|
if (rendered.text) {
|
|
55558
55512
|
const inputItems = typeof rebuiltInput === "string" ? [{ type: "message", role: "user", content: rebuiltInput }] : rebuiltInput;
|
|
55559
|
-
inputItems.push({ type: "message", role: "user", content:
|
|
55513
|
+
inputItems.push({ type: "message", role: "user", content: rendered.text });
|
|
55560
55514
|
rebuiltInput = inputItems;
|
|
55561
55515
|
}
|
|
55562
55516
|
} catch {
|