billion-context 0.1.106-pr.724.561 → 0.1.106
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 +17 -63
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43467,7 +43467,7 @@ var require_lib = __commonJS({
|
|
|
43467
43467
|
}
|
|
43468
43468
|
});
|
|
43469
43469
|
|
|
43470
|
-
// node_modules/acp-kernel/dist/chunk-
|
|
43470
|
+
// node_modules/acp-kernel/dist/chunk-6TAK7DSI.js
|
|
43471
43471
|
import { createRequire } from "module";
|
|
43472
43472
|
var require2 = createRequire(import.meta.url);
|
|
43473
43473
|
function defaultCountTokens(text) {
|
|
@@ -43652,22 +43652,11 @@ function formatTierTargetBlocks(blocks) {
|
|
|
43652
43652
|
return `Target ${blocks[0].tier === 1 ? "tier-1" : "tier-2"} blocks to distill (${blocks.length}):
|
|
43653
43653
|
${lines.join("\n")}`;
|
|
43654
43654
|
}
|
|
43655
|
-
var BLOCK_MAP_MAX_SHOWN = 8;
|
|
43656
|
-
function formatBlockMap(spans) {
|
|
43657
|
-
if (spans.length === 0) return "";
|
|
43658
|
-
const hidden = Math.max(0, spans.length - BLOCK_MAP_MAX_SHOWN);
|
|
43659
|
-
const shown = hidden > 0 ? spans.slice(-BLOCK_MAP_MAX_SHOWN) : spans;
|
|
43660
|
-
const items = shown.map(
|
|
43661
|
-
(s3) => `${s3.blockId}=${s3.startRef}\u2013${s3.endRef}${s3.tier > 1 ? ` t${s3.tier}` : ""}`
|
|
43662
|
-
);
|
|
43663
|
-
const prefix = hidden > 0 ? `\u2026+${hidden} older \xB7 ` : "";
|
|
43664
|
-
return `Active blocks (${spans.length}): ${prefix}${items.join(" \xB7 ")}`;
|
|
43665
|
-
}
|
|
43666
43655
|
function formatRanges(compressible, protectedRanges) {
|
|
43667
43656
|
if (compressible.length === 0 && protectedRanges.length === 0) {
|
|
43668
43657
|
return "[No specific ranges detected \u2014 compress any consumed content.]";
|
|
43669
43658
|
}
|
|
43670
|
-
const
|
|
43659
|
+
const refNum3 = (ref) => {
|
|
43671
43660
|
const m2 = ref.match(/\d+/);
|
|
43672
43661
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
43673
43662
|
};
|
|
@@ -43676,11 +43665,10 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43676
43665
|
entries.push({
|
|
43677
43666
|
startRef: r.startRef,
|
|
43678
43667
|
endRef: r.endRef,
|
|
43679
|
-
startNum:
|
|
43680
|
-
endNum:
|
|
43668
|
+
startNum: refNum3(r.startRef),
|
|
43669
|
+
endNum: refNum3(r.endRef),
|
|
43681
43670
|
count: r.count,
|
|
43682
43671
|
tokens: r.tokens,
|
|
43683
|
-
userMsgs: r.userMsgs ?? 0,
|
|
43684
43672
|
toolPct: r.toolPct,
|
|
43685
43673
|
textPct: r.textPct,
|
|
43686
43674
|
compressibleTokens: r.tokens,
|
|
@@ -43695,11 +43683,10 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43695
43683
|
entries.push({
|
|
43696
43684
|
startRef: r.startRef,
|
|
43697
43685
|
endRef: r.endRef,
|
|
43698
|
-
startNum:
|
|
43699
|
-
endNum:
|
|
43686
|
+
startNum: refNum3(r.startRef),
|
|
43687
|
+
endNum: refNum3(r.endRef),
|
|
43700
43688
|
count: r.count,
|
|
43701
43689
|
tokens: r.tokens,
|
|
43702
|
-
userMsgs: 0,
|
|
43703
43690
|
toolPct: 0,
|
|
43704
43691
|
textPct: 0,
|
|
43705
43692
|
compressibleTokens: 0,
|
|
@@ -43719,7 +43706,6 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43719
43706
|
last.endNum = Math.max(last.endNum, e.endNum);
|
|
43720
43707
|
last.count += e.count;
|
|
43721
43708
|
last.tokens += e.tokens;
|
|
43722
|
-
last.userMsgs += e.userMsgs;
|
|
43723
43709
|
last.compressibleTokens += e.compressibleTokens;
|
|
43724
43710
|
last.compressibleCount += e.compressibleCount;
|
|
43725
43711
|
last.protectedTokens += e.protectedTokens;
|
|
@@ -43732,16 +43718,15 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43732
43718
|
merged.push({ ...e });
|
|
43733
43719
|
}
|
|
43734
43720
|
}
|
|
43735
|
-
const userNote = (n) => n > 0 ? ` \xB7 ${n} user msg${n > 1 ? "s" : ""}` : "";
|
|
43736
43721
|
const lines = merged.map((e) => {
|
|
43737
43722
|
const suffix = e.dangerous && e.compressibleTokens > 0 ? " \u26A0\uFE0F NOT recommended unless you are certain." : "";
|
|
43738
43723
|
if (e.protectedTokens > 0 && e.compressibleTokens === 0) {
|
|
43739
43724
|
return ` ${e.startRef}\u2013${e.endRef} ${e.count} msgs ${formatK(e.tokens)} [PROTECTED: ${e.protectedTools.join(", ")} \u2014 not compressible]${suffix}`;
|
|
43740
43725
|
}
|
|
43741
43726
|
if (e.protectedTokens > 0 && e.compressibleTokens > 0) {
|
|
43742
|
-
return ` ${e.startRef}\u2013${e.endRef} ${e.count} msgs ${formatK(e.tokens)} [${formatK(e.compressibleTokens)} compressible | ${formatK(e.protectedTokens)} protected: ${e.protectedTools.join(", ")}]${
|
|
43727
|
+
return ` ${e.startRef}\u2013${e.endRef} ${e.count} msgs ${formatK(e.tokens)} [${formatK(e.compressibleTokens)} compressible | ${formatK(e.protectedTokens)} protected: ${e.protectedTools.join(", ")}]${suffix}`;
|
|
43743
43728
|
}
|
|
43744
|
-
return ` ${e.startRef}\u2013${e.endRef} ${e.count} msgs ${formatK(e.tokens)} [tool ${e.toolPct}% | text ${e.textPct}%]${
|
|
43729
|
+
return ` ${e.startRef}\u2013${e.endRef} ${e.count} msgs ${formatK(e.tokens)} [tool ${e.toolPct}% | text ${e.textPct}%]${suffix}`;
|
|
43745
43730
|
});
|
|
43746
43731
|
return `Compressible ranges (${merged.length}, oldest first):
|
|
43747
43732
|
${lines.join("\n")}`;
|
|
@@ -43749,7 +43734,6 @@ ${lines.join("\n")}`;
|
|
|
43749
43734
|
function renderNudgeText(decision, prompts = defaultPrompts) {
|
|
43750
43735
|
const breakdownStr = formatBreakdown(decision.contextBreakdown);
|
|
43751
43736
|
const rangesStr = formatRanges(decision.compressibleRanges, decision.protectedRanges ?? []);
|
|
43752
|
-
const blockMapStr = formatBlockMap(decision.activeBlockSpans ?? []);
|
|
43753
43737
|
const isEmergency = !!decision.breakdown?.emergencyOverride || !!decision.breakdown?.overLimit;
|
|
43754
43738
|
if (decision.tier !== null && decision.tier >= 2) {
|
|
43755
43739
|
const isT2 = decision.tier === 2;
|
|
@@ -43790,8 +43774,7 @@ function renderNudgeText(decision, prompts = defaultPrompts) {
|
|
|
43790
43774
|
`{ "topic": "...", "content": [{ "startId": "<ID>", "endId": "<ID>", "summary": "..." }] }`,
|
|
43791
43775
|
"Only use IDs from visible messages above. Compress older work first.",
|
|
43792
43776
|
"",
|
|
43793
|
-
rangesStr
|
|
43794
|
-
...blockMapStr ? ["", blockMapStr] : []
|
|
43777
|
+
rangesStr
|
|
43795
43778
|
].join("\n")
|
|
43796
43779
|
};
|
|
43797
43780
|
}
|
|
@@ -43805,7 +43788,6 @@ function renderNudgeText(decision, prompts = defaultPrompts) {
|
|
|
43805
43788
|
prompts.howToCompressRules,
|
|
43806
43789
|
"",
|
|
43807
43790
|
rangesStr,
|
|
43808
|
-
...blockMapStr ? ["", blockMapStr] : [],
|
|
43809
43791
|
"",
|
|
43810
43792
|
`\u{1F4A1} Compress all ranges in one call (pass multiple content entries: \`content: [{...}, {...}]\`).`
|
|
43811
43793
|
].join("\n")
|
|
@@ -45275,30 +45257,6 @@ function applyMessageFilters(messages, config) {
|
|
|
45275
45257
|
}
|
|
45276
45258
|
return { messages: working, ...tally };
|
|
45277
45259
|
}
|
|
45278
|
-
function refNum(ref) {
|
|
45279
|
-
const m2 = ref.match(/\d+/);
|
|
45280
|
-
return m2 ? parseInt(m2[0], 10) : 0;
|
|
45281
|
-
}
|
|
45282
|
-
var M_REF = /^m\d+$/;
|
|
45283
|
-
function resolveBlockSpan(block, byRaw) {
|
|
45284
|
-
if (block.startRef && block.endRef && M_REF.test(block.startRef) && M_REF.test(block.endRef)) {
|
|
45285
|
-
return { startRef: block.startRef, endRef: block.endRef };
|
|
45286
|
-
}
|
|
45287
|
-
const refs = block.effectiveMessageIds.map((id) => byRaw[id]).filter((r) => typeof r === "string" && r !== "BLOCKED");
|
|
45288
|
-
if (refs.length === 0) return null;
|
|
45289
|
-
const sorted = [...refs].sort((a, b2) => refNum(a) - refNum(b2));
|
|
45290
|
-
return { startRef: sorted[0], endRef: sorted[sorted.length - 1] };
|
|
45291
|
-
}
|
|
45292
|
-
function activeBlockSpans(state) {
|
|
45293
|
-
const spans = [];
|
|
45294
|
-
for (const block of state.blocks) {
|
|
45295
|
-
if (!block.active) continue;
|
|
45296
|
-
const span = resolveBlockSpan(block, state.messageRefs.byRaw);
|
|
45297
|
-
if (!span) continue;
|
|
45298
|
-
spans.push({ blockId: block.blockId, tier: block.tier, ...span });
|
|
45299
|
-
}
|
|
45300
|
-
return spans;
|
|
45301
|
-
}
|
|
45302
45260
|
function formatTokens(tokens) {
|
|
45303
45261
|
if (tokens < 1e3) return String(tokens);
|
|
45304
45262
|
if (tokens < 1e4) return (tokens / 1e3).toFixed(1) + "K";
|
|
@@ -45594,15 +45552,13 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45594
45552
|
tokens: info.tokens,
|
|
45595
45553
|
chars: info.chars,
|
|
45596
45554
|
toolPct: info.isTool ? 100 : 0,
|
|
45597
|
-
textPct: info.isTool ? 0 : 100
|
|
45598
|
-
userMsgs: info.isUser ? 1 : 0
|
|
45555
|
+
textPct: info.isTool ? 0 : 100
|
|
45599
45556
|
};
|
|
45600
45557
|
} else {
|
|
45601
45558
|
cur.endRef = info.ref;
|
|
45602
45559
|
cur.count++;
|
|
45603
45560
|
cur.tokens += info.tokens;
|
|
45604
45561
|
cur.chars = (cur.chars ?? 0) + info.chars;
|
|
45605
|
-
if (info.isUser) cur.userMsgs = (cur.userMsgs ?? 0) + 1;
|
|
45606
45562
|
if (info.isTool) {
|
|
45607
45563
|
cur.toolPct = Math.round((cur.toolPct * (cur.count - 1) + 100) / cur.count);
|
|
45608
45564
|
} else {
|
|
@@ -45658,8 +45614,7 @@ function mergeBatch(batch) {
|
|
|
45658
45614
|
tokens,
|
|
45659
45615
|
chars,
|
|
45660
45616
|
toolPct,
|
|
45661
|
-
textPct: 100 - toolPct
|
|
45662
|
-
userMsgs: batch.reduce((s3, r) => s3 + (r.userMsgs ?? 0), 0)
|
|
45617
|
+
textPct: 100 - toolPct
|
|
45663
45618
|
};
|
|
45664
45619
|
if (batch.some((r) => r.dangerous === true)) {
|
|
45665
45620
|
merged.dangerous = true;
|
|
@@ -46561,7 +46516,6 @@ function decideNudge(input) {
|
|
|
46561
46516
|
reason,
|
|
46562
46517
|
compressibleRanges: rec?.recommendedRanges ?? [],
|
|
46563
46518
|
protectedRanges: rec?.contextRanges.protected ?? [],
|
|
46564
|
-
activeBlockSpans: activeBlockSpans(state),
|
|
46565
46519
|
tierTargetBlocks: injectedTier ? tiers[injectedTier].targetBlocks : [],
|
|
46566
46520
|
contextUsage: usage,
|
|
46567
46521
|
tier: injectedTier,
|
|
@@ -46858,7 +46812,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46858
46812
|
lines.push(" (no uncompressed messages)");
|
|
46859
46813
|
return lines.join("\n");
|
|
46860
46814
|
}
|
|
46861
|
-
const
|
|
46815
|
+
const refNum3 = (ref) => {
|
|
46862
46816
|
const m2 = ref.match(/\d+/);
|
|
46863
46817
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
46864
46818
|
};
|
|
@@ -46875,7 +46829,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46875
46829
|
};
|
|
46876
46830
|
const merged = [];
|
|
46877
46831
|
for (const m2 of visible) {
|
|
46878
|
-
const num3 =
|
|
46832
|
+
const num3 = refNum3(m2.ref);
|
|
46879
46833
|
const last = merged[merged.length - 1];
|
|
46880
46834
|
if (last && num3 === last.startNum + last.count) {
|
|
46881
46835
|
last.endRef = m2.ref;
|
|
@@ -51945,7 +51899,7 @@ ${lines.join("\n\n")}`;
|
|
|
51945
51899
|
}
|
|
51946
51900
|
return `[Unknown proxy tool: ${toolName}]`;
|
|
51947
51901
|
}
|
|
51948
|
-
function
|
|
51902
|
+
function refNum(ref) {
|
|
51949
51903
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
51950
51904
|
}
|
|
51951
51905
|
function applyRanges(parsed, ctx) {
|
|
@@ -51994,7 +51948,7 @@ ${reasons.map((r) => `- ${r}`).join("\n")}` : "";
|
|
|
51994
51948
|
}
|
|
51995
51949
|
const preContext = ctx.session.stats.lastInputTokens;
|
|
51996
51950
|
const shrinkRatio = preContext > 0 ? r.tokensCompressed / preContext : 0;
|
|
51997
|
-
const foldPoint = [...ranges].sort((a, b2) =>
|
|
51951
|
+
const foldPoint = [...ranges].sort((a, b2) => refNum(a.startRef) - refNum(b2.startRef))[0]?.startRef ?? "unknown";
|
|
51998
51952
|
ctx.session.lastCompress = { at: Date.now(), shrinkRatio, foldPoint, blocks: r.blocksCreated, tokensCompressed: r.tokensCompressed };
|
|
51999
51953
|
ctx.session.stats.pendingFoldUsage = true;
|
|
52000
51954
|
const anchorTok = res.state.blocks.reduce((n, b2) => n + (b2.active ? Math.ceil(b2.summary.length / 4) : 0), 0);
|
|
@@ -52065,7 +52019,7 @@ function refMaps(messages, state) {
|
|
|
52065
52019
|
});
|
|
52066
52020
|
return { refToIdx, idxToRef };
|
|
52067
52021
|
}
|
|
52068
|
-
function
|
|
52022
|
+
function refNum2(ref) {
|
|
52069
52023
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
52070
52024
|
}
|
|
52071
52025
|
function estimateCoreMessages(messages) {
|
|
@@ -52354,7 +52308,7 @@ async function preflightCompress(deps, messages) {
|
|
|
52354
52308
|
failure = { kind: "exhausted", detail: relaxed ? relaxedExhaustedDetail : "no compressible ranges remain in the conversation" };
|
|
52355
52309
|
break;
|
|
52356
52310
|
}
|
|
52357
|
-
const ordered = [...ranges].sort((a, b2) =>
|
|
52311
|
+
const ordered = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef));
|
|
52358
52312
|
let appliedThisRound = 0;
|
|
52359
52313
|
for (const range of ordered) {
|
|
52360
52314
|
if (currentTokens < limit) break;
|