billion-context 0.1.94-pr.633.454 → 0.1.94
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 +123 -156
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43650,7 +43650,7 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43650
43650
|
if (compressible.length === 0 && protectedRanges.length === 0) {
|
|
43651
43651
|
return "[No specific ranges detected \u2014 compress any consumed content.]";
|
|
43652
43652
|
}
|
|
43653
|
-
const
|
|
43653
|
+
const refNum4 = (ref) => {
|
|
43654
43654
|
const m2 = ref.match(/\d+/);
|
|
43655
43655
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
43656
43656
|
};
|
|
@@ -43659,8 +43659,8 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43659
43659
|
entries.push({
|
|
43660
43660
|
startRef: r.startRef,
|
|
43661
43661
|
endRef: r.endRef,
|
|
43662
|
-
startNum:
|
|
43663
|
-
endNum:
|
|
43662
|
+
startNum: refNum4(r.startRef),
|
|
43663
|
+
endNum: refNum4(r.endRef),
|
|
43664
43664
|
count: r.count,
|
|
43665
43665
|
tokens: r.tokens,
|
|
43666
43666
|
toolPct: r.toolPct,
|
|
@@ -43677,8 +43677,8 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
43677
43677
|
entries.push({
|
|
43678
43678
|
startRef: r.startRef,
|
|
43679
43679
|
endRef: r.endRef,
|
|
43680
|
-
startNum:
|
|
43681
|
-
endNum:
|
|
43680
|
+
startNum: refNum4(r.startRef),
|
|
43681
|
+
endNum: refNum4(r.endRef),
|
|
43682
43682
|
count: r.count,
|
|
43683
43683
|
tokens: r.tokens,
|
|
43684
43684
|
toolPct: 0,
|
|
@@ -45328,6 +45328,10 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
45328
45328
|
}
|
|
45329
45329
|
return { startIndex: newStartIndex, endIndex: newEndIndex };
|
|
45330
45330
|
}
|
|
45331
|
+
function refNum(ref) {
|
|
45332
|
+
const n = parseInt(ref.slice(1), 10);
|
|
45333
|
+
return Number.isNaN(n) ? -1 : n;
|
|
45334
|
+
}
|
|
45331
45335
|
function estimateTextTokens(text) {
|
|
45332
45336
|
return Math.ceil(text.length / 4);
|
|
45333
45337
|
}
|
|
@@ -45380,50 +45384,42 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45380
45384
|
const compressibleMsgs = [];
|
|
45381
45385
|
const protectedMsgs = [];
|
|
45382
45386
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
45383
|
-
let skipSinceCompressible = false;
|
|
45384
|
-
let skipSinceProtected = false;
|
|
45385
45387
|
for (const msg of messages) {
|
|
45388
|
+
if (isSyntheticOrPruned(msg, state)) continue;
|
|
45386
45389
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
45387
45390
|
if (!ref || ref === "BLOCKED") continue;
|
|
45388
|
-
|
|
45389
|
-
skipSinceCompressible = true;
|
|
45390
|
-
skipSinceProtected = true;
|
|
45391
|
-
continue;
|
|
45392
|
-
}
|
|
45391
|
+
const rn2 = refNum(ref);
|
|
45393
45392
|
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
|
|
45394
45393
|
protectedMsgs.push({
|
|
45395
45394
|
ref,
|
|
45396
|
-
|
|
45395
|
+
refNum: rn2,
|
|
45397
45396
|
tokens: countTokens(msg.text ?? ""),
|
|
45398
45397
|
tools: msg.toolName ? [msg.toolName] : []
|
|
45399
45398
|
});
|
|
45400
|
-
skipSinceProtected = false;
|
|
45401
|
-
skipSinceCompressible = true;
|
|
45402
45399
|
continue;
|
|
45403
45400
|
}
|
|
45404
45401
|
if (protectedZoneRefs?.has(ref)) {
|
|
45405
|
-
skipSinceCompressible = true;
|
|
45406
|
-
skipSinceProtected = true;
|
|
45407
45402
|
continue;
|
|
45408
45403
|
}
|
|
45409
45404
|
compressibleMsgs.push({
|
|
45410
45405
|
ref,
|
|
45411
|
-
|
|
45406
|
+
refNum: rn2,
|
|
45412
45407
|
tokens: countTokens(msg.text ?? ""),
|
|
45413
45408
|
chars: (msg.text ?? "").length,
|
|
45414
45409
|
isTool: isToolMessage(msg),
|
|
45415
45410
|
isUser: msg.role === "user"
|
|
45416
45411
|
});
|
|
45417
|
-
skipSinceCompressible = false;
|
|
45418
|
-
skipSinceProtected = true;
|
|
45419
45412
|
}
|
|
45420
45413
|
const compressible = [];
|
|
45421
45414
|
let cur = null;
|
|
45415
|
+
let prevRefNum = -2;
|
|
45422
45416
|
for (const info of compressibleMsgs) {
|
|
45423
|
-
|
|
45417
|
+
const hasGap = info.refNum > prevRefNum + 1;
|
|
45418
|
+
if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
|
|
45424
45419
|
compressible.push(cur);
|
|
45425
45420
|
cur = null;
|
|
45426
45421
|
}
|
|
45422
|
+
prevRefNum = info.refNum;
|
|
45427
45423
|
if (!cur) {
|
|
45428
45424
|
cur = {
|
|
45429
45425
|
startRef: info.ref,
|
|
@@ -45450,11 +45446,14 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45450
45446
|
if (cur) compressible.push(cur);
|
|
45451
45447
|
const protectedRanges = [];
|
|
45452
45448
|
let pcur = null;
|
|
45449
|
+
let pPrevRefNum = -2;
|
|
45453
45450
|
for (const info of protectedMsgs) {
|
|
45454
|
-
|
|
45451
|
+
const hasGap = info.refNum > pPrevRefNum + 1;
|
|
45452
|
+
if (pcur && hasGap) {
|
|
45455
45453
|
protectedRanges.push(pcur);
|
|
45456
45454
|
pcur = null;
|
|
45457
45455
|
}
|
|
45456
|
+
pPrevRefNum = info.refNum;
|
|
45458
45457
|
if (!pcur) {
|
|
45459
45458
|
pcur = {
|
|
45460
45459
|
startRef: info.ref,
|
|
@@ -46648,7 +46647,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46648
46647
|
lines.push(" (no uncompressed messages)");
|
|
46649
46648
|
return lines.join("\n");
|
|
46650
46649
|
}
|
|
46651
|
-
const
|
|
46650
|
+
const refNum22 = (ref) => {
|
|
46652
46651
|
const m2 = ref.match(/\d+/);
|
|
46653
46652
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
46654
46653
|
};
|
|
@@ -46665,7 +46664,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46665
46664
|
};
|
|
46666
46665
|
const merged = [];
|
|
46667
46666
|
for (const m2 of visible) {
|
|
46668
|
-
const num3 =
|
|
46667
|
+
const num3 = refNum22(m2.ref);
|
|
46669
46668
|
const last = merged[merged.length - 1];
|
|
46670
46669
|
if (last && num3 === last.startNum + last.count) {
|
|
46671
46670
|
last.endRef = m2.ref;
|
|
@@ -46829,23 +46828,6 @@ function parseStringInput(raw, callId, diag) {
|
|
|
46829
46828
|
diag.rawPrefix = raw.slice(0, 800);
|
|
46830
46829
|
diag.length = raw.length;
|
|
46831
46830
|
const cleaned = stripFence(raw.trim());
|
|
46832
|
-
const first = parseStringCore(cleaned, callId, diag);
|
|
46833
|
-
if (first.ranges.length === 0 || first.diagnostics.invalidItems > 0) {
|
|
46834
|
-
const normalized = normalizeSingleQuotes(cleaned);
|
|
46835
|
-
if (normalized !== void 0) {
|
|
46836
|
-
const retryDiag = { ok: false, kind: "ok", invalidItems: 0 };
|
|
46837
|
-
retryDiag.rawPrefix = diag.rawPrefix;
|
|
46838
|
-
retryDiag.length = diag.length;
|
|
46839
|
-
const retry = parseStringCore(normalized, callId, retryDiag);
|
|
46840
|
-
if (retry.ranges.length > first.ranges.length) {
|
|
46841
|
-
retryDiag.quoteSalvage = true;
|
|
46842
|
-
return retry;
|
|
46843
|
-
}
|
|
46844
|
-
}
|
|
46845
|
-
}
|
|
46846
|
-
return first;
|
|
46847
|
-
}
|
|
46848
|
-
function parseStringCore(cleaned, callId, diag) {
|
|
46849
46831
|
if (cleaned === "") {
|
|
46850
46832
|
diag.kind = "empty-input";
|
|
46851
46833
|
return finish([], diag);
|
|
@@ -46889,7 +46871,6 @@ function parseObjectValue(value, callId, diag) {
|
|
|
46889
46871
|
}
|
|
46890
46872
|
entries = parsed.entries;
|
|
46891
46873
|
salvaged = parsed.salvaged;
|
|
46892
|
-
if (parsed.quoteRepaired) diag.quoteSalvage = true;
|
|
46893
46874
|
} else {
|
|
46894
46875
|
diag.kind = "content-not-array";
|
|
46895
46876
|
return finish([], diag);
|
|
@@ -46911,17 +46892,7 @@ function parseObjectValue(value, callId, diag) {
|
|
|
46911
46892
|
}
|
|
46912
46893
|
function parseContentArray(s3) {
|
|
46913
46894
|
const cleaned = stripFence(s3.trim());
|
|
46914
|
-
|
|
46915
|
-
if (direct !== null && direct.entries.length > 0) return direct;
|
|
46916
|
-
const normalized = normalizeSingleQuotes(cleaned);
|
|
46917
|
-
if (normalized !== void 0) {
|
|
46918
|
-
const retry = parseContentArrayCore(normalized);
|
|
46919
|
-
if (retry !== null && retry.entries.length > 0) return { ...retry, quoteRepaired: true };
|
|
46920
|
-
}
|
|
46921
|
-
return direct;
|
|
46922
|
-
}
|
|
46923
|
-
function parseContentArrayCore(s3) {
|
|
46924
|
-
let value = s3 === "" ? void 0 : tryParseLenient(s3);
|
|
46895
|
+
let value = cleaned === "" ? void 0 : tryParseLenient(cleaned);
|
|
46925
46896
|
if (typeof value === "string") {
|
|
46926
46897
|
value = tryParseLenient(stripFence(value));
|
|
46927
46898
|
}
|
|
@@ -46929,7 +46900,7 @@ function parseContentArrayCore(s3) {
|
|
|
46929
46900
|
return { entries: value, salvaged: false };
|
|
46930
46901
|
}
|
|
46931
46902
|
if (value === void 0) {
|
|
46932
|
-
const entries = salvageContentEntries('{"content": ' +
|
|
46903
|
+
const entries = salvageContentEntries('{"content": ' + cleaned);
|
|
46933
46904
|
return { entries, salvaged: entries.length > 0 };
|
|
46934
46905
|
}
|
|
46935
46906
|
return null;
|
|
@@ -47002,71 +46973,6 @@ function tryParseLenient(s3) {
|
|
|
47002
46973
|
}
|
|
47003
46974
|
return void 0;
|
|
47004
46975
|
}
|
|
47005
|
-
function normalizeSingleQuotes(raw) {
|
|
47006
|
-
if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
|
|
47007
|
-
let out = "";
|
|
47008
|
-
let changed = false;
|
|
47009
|
-
let inDouble = false;
|
|
47010
|
-
let inSingle = false;
|
|
47011
|
-
for (let i = 0; i < raw.length; i++) {
|
|
47012
|
-
const ch = raw.charAt(i);
|
|
47013
|
-
if (inDouble) {
|
|
47014
|
-
out += ch;
|
|
47015
|
-
if (ch === "\\" && i + 1 < raw.length) {
|
|
47016
|
-
out += raw.charAt(i + 1);
|
|
47017
|
-
i++;
|
|
47018
|
-
} else if (ch === '"') {
|
|
47019
|
-
inDouble = false;
|
|
47020
|
-
}
|
|
47021
|
-
continue;
|
|
47022
|
-
}
|
|
47023
|
-
if (inSingle) {
|
|
47024
|
-
if (ch === "\\" && i + 1 < raw.length) {
|
|
47025
|
-
const next = raw.charAt(i + 1);
|
|
47026
|
-
out += next === "'" ? "'" : "\\" + next;
|
|
47027
|
-
i++;
|
|
47028
|
-
continue;
|
|
47029
|
-
}
|
|
47030
|
-
if (ch === "'") {
|
|
47031
|
-
out += '"';
|
|
47032
|
-
inSingle = false;
|
|
47033
|
-
changed = true;
|
|
47034
|
-
continue;
|
|
47035
|
-
}
|
|
47036
|
-
if (ch === '"') {
|
|
47037
|
-
out += '\\"';
|
|
47038
|
-
continue;
|
|
47039
|
-
}
|
|
47040
|
-
if (ch === "\n") {
|
|
47041
|
-
out += "\\n";
|
|
47042
|
-
continue;
|
|
47043
|
-
}
|
|
47044
|
-
if (ch === "\r") {
|
|
47045
|
-
out += "\\r";
|
|
47046
|
-
continue;
|
|
47047
|
-
}
|
|
47048
|
-
if (ch === " ") {
|
|
47049
|
-
out += "\\t";
|
|
47050
|
-
continue;
|
|
47051
|
-
}
|
|
47052
|
-
out += ch;
|
|
47053
|
-
continue;
|
|
47054
|
-
}
|
|
47055
|
-
if (ch === '"') {
|
|
47056
|
-
inDouble = true;
|
|
47057
|
-
out += ch;
|
|
47058
|
-
continue;
|
|
47059
|
-
}
|
|
47060
|
-
if (ch === "'") {
|
|
47061
|
-
inSingle = true;
|
|
47062
|
-
out += '"';
|
|
47063
|
-
changed = true;
|
|
47064
|
-
continue;
|
|
47065
|
-
}
|
|
47066
|
-
out += ch;
|
|
47067
|
-
}
|
|
47068
|
-
return changed ? out : void 0;
|
|
47069
|
-
}
|
|
47070
46976
|
function stripFence(s3) {
|
|
47071
46977
|
if (!s3.startsWith("```")) return s3;
|
|
47072
46978
|
const firstNewline = s3.indexOf("\n");
|
|
@@ -49304,7 +49210,6 @@ function anthropicToCore(body) {
|
|
|
49304
49210
|
const msgs = [];
|
|
49305
49211
|
const cacheControls = /* @__PURE__ */ new Map();
|
|
49306
49212
|
const clusters = new ClusterCounter();
|
|
49307
|
-
const toolNames = /* @__PURE__ */ new Map();
|
|
49308
49213
|
for (const m2 of body.messages) {
|
|
49309
49214
|
const blocks = typeof m2.content === "string" ? [{ type: "text", text: m2.content }] : m2.content;
|
|
49310
49215
|
for (const b2 of blocks) {
|
|
@@ -49330,7 +49235,6 @@ function anthropicToCore(body) {
|
|
|
49330
49235
|
toolCallId: b2.id,
|
|
49331
49236
|
text: safeStringify(b2.input)
|
|
49332
49237
|
});
|
|
49333
|
-
toolNames.set(b2.id, b2.name);
|
|
49334
49238
|
if (b2.cache_control) cacheControls.set(id, b2.cache_control);
|
|
49335
49239
|
break;
|
|
49336
49240
|
}
|
|
@@ -49338,14 +49242,12 @@ function anthropicToCore(body) {
|
|
|
49338
49242
|
const text = typeof b2.content === "string" ? b2.content : b2.content.map((c) => c.text).join("\n");
|
|
49339
49243
|
const base = deriveMessageId("tool", "tool-result", text, { toolCallId: b2.tool_use_id });
|
|
49340
49244
|
const id = clusters.next(base);
|
|
49341
|
-
const name = toolNames.get(b2.tool_use_id);
|
|
49342
49245
|
msgs.push({
|
|
49343
49246
|
id,
|
|
49344
49247
|
role: "tool",
|
|
49345
49248
|
contentType: "tool-result",
|
|
49346
49249
|
toolCallId: b2.tool_use_id,
|
|
49347
49250
|
text,
|
|
49348
|
-
...name ? { toolName: name } : {},
|
|
49349
49251
|
...b2.is_error === true ? { toolIsError: true } : {}
|
|
49350
49252
|
});
|
|
49351
49253
|
if (b2.cache_control) cacheControls.set(id, b2.cache_control);
|
|
@@ -49493,7 +49395,6 @@ function openaiToCore(body) {
|
|
|
49493
49395
|
const msgs = [];
|
|
49494
49396
|
const systemParts = [];
|
|
49495
49397
|
const clusters = new ClusterCounter();
|
|
49496
|
-
const toolNames = /* @__PURE__ */ new Map();
|
|
49497
49398
|
for (const m2 of body.messages) {
|
|
49498
49399
|
switch (m2.role) {
|
|
49499
49400
|
case "system":
|
|
@@ -49561,7 +49462,6 @@ function openaiToCore(body) {
|
|
|
49561
49462
|
toolCallId: tc.id,
|
|
49562
49463
|
text: tc.function.arguments ?? ""
|
|
49563
49464
|
});
|
|
49564
|
-
toolNames.set(tc.id, tc.function.name);
|
|
49565
49465
|
}
|
|
49566
49466
|
}
|
|
49567
49467
|
break;
|
|
@@ -49570,14 +49470,12 @@ function openaiToCore(body) {
|
|
|
49570
49470
|
const base = deriveMessageId("tool", "tool-result", stringContent(m2.content), {
|
|
49571
49471
|
toolCallId: m2.tool_call_id ?? ""
|
|
49572
49472
|
});
|
|
49573
|
-
const name = m2.name || toolNames.get(m2.tool_call_id ?? "");
|
|
49574
49473
|
msgs.push({
|
|
49575
49474
|
id: clusters.next(base),
|
|
49576
49475
|
role: "tool",
|
|
49577
49476
|
contentType: "tool-result",
|
|
49578
49477
|
toolCallId: m2.tool_call_id ?? "",
|
|
49579
|
-
text: stringContent(m2.content)
|
|
49580
|
-
...name ? { toolName: name } : {}
|
|
49478
|
+
text: stringContent(m2.content)
|
|
49581
49479
|
});
|
|
49582
49480
|
break;
|
|
49583
49481
|
}
|
|
@@ -49682,7 +49580,7 @@ function allImageParts(content) {
|
|
|
49682
49580
|
if (typeof p2 !== "object" || p2 === null) continue;
|
|
49683
49581
|
if (!("type" in p2) || p2.type !== "image_url" || !("image_url" in p2)) continue;
|
|
49684
49582
|
const imagePart = p2;
|
|
49685
|
-
const url = imagePart.image_url
|
|
49583
|
+
const url = imagePart.image_url.url;
|
|
49686
49584
|
if (typeof url === "string" && parseDataUrl(url)) out.push(p2);
|
|
49687
49585
|
}
|
|
49688
49586
|
return out;
|
|
@@ -49694,14 +49592,6 @@ var OPAQUE_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
|
49694
49592
|
function isOpaqueItem(item) {
|
|
49695
49593
|
return OPAQUE_ITEM_TYPES.has(item.type);
|
|
49696
49594
|
}
|
|
49697
|
-
var EASY_INPUT_ROLES = /* @__PURE__ */ new Set(["user", "assistant", "system", "developer"]);
|
|
49698
|
-
function normalizeEasyInputItem(item) {
|
|
49699
|
-
if (typeof item.type === "string") return item;
|
|
49700
|
-
if (EASY_INPUT_ROLES.has(String(item.role))) {
|
|
49701
|
-
return { ...item, type: "message" };
|
|
49702
|
-
}
|
|
49703
|
-
return item;
|
|
49704
|
-
}
|
|
49705
49595
|
function shouldDropAllReasoning() {
|
|
49706
49596
|
return (process.env.ACP_REASONING_KEEP ?? "").trim().toLowerCase() === "none";
|
|
49707
49597
|
}
|
|
@@ -49738,7 +49628,6 @@ function responsesToCore(body) {
|
|
|
49738
49628
|
const layout = [];
|
|
49739
49629
|
let droppedReasoning = 0;
|
|
49740
49630
|
const clusters = new ClusterCounter();
|
|
49741
|
-
const toolNames = /* @__PURE__ */ new Map();
|
|
49742
49631
|
let idx = 0;
|
|
49743
49632
|
if (typeof body.instructions === "string" && body.instructions.trim()) systemParts.push(body.instructions);
|
|
49744
49633
|
if (typeof body.input === "string") {
|
|
@@ -49746,8 +49635,7 @@ function responsesToCore(body) {
|
|
|
49746
49635
|
msgs.push({ id, role: "user", contentType: "text", text: body.input });
|
|
49747
49636
|
return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning, stringInput: { original: body.input, coreId: id } };
|
|
49748
49637
|
}
|
|
49749
|
-
for (const
|
|
49750
|
-
const item = normalizeEasyInputItem(raw);
|
|
49638
|
+
for (const item of body.input) {
|
|
49751
49639
|
let coreId;
|
|
49752
49640
|
if (isOpaqueItem(item)) preamble.push(item);
|
|
49753
49641
|
switch (item.type) {
|
|
@@ -49822,15 +49710,13 @@ function responsesToCore(body) {
|
|
|
49822
49710
|
text: call.arguments ?? "",
|
|
49823
49711
|
rawResponsesItem: item
|
|
49824
49712
|
});
|
|
49825
|
-
toolNames.set(call.call_id, call.name);
|
|
49826
49713
|
break;
|
|
49827
49714
|
}
|
|
49828
49715
|
case "function_call_output": {
|
|
49829
49716
|
const output = item;
|
|
49830
49717
|
const text = typeof output.output === "string" ? output.output : JSON.stringify(output.output);
|
|
49831
49718
|
coreId = clusters.next(deriveMessageId("tool", "tool-result", text, { toolCallId: output.call_id }));
|
|
49832
|
-
|
|
49833
|
-
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: output.call_id, text, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
49719
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: output.call_id, text, rawResponsesItem: item });
|
|
49834
49720
|
break;
|
|
49835
49721
|
}
|
|
49836
49722
|
case "computer_call":
|
|
@@ -49852,7 +49738,6 @@ function responsesToCore(body) {
|
|
|
49852
49738
|
const argText = ctc.input ?? ctc.arguments ?? "";
|
|
49853
49739
|
coreId = clusters.next(deriveMessageId("assistant", "tool-call", argText, { toolCallId: callId, toolName: ctc.name ?? "custom" }));
|
|
49854
49740
|
msgs.push({ id: coreId, role: "assistant", contentType: "tool-call", toolName: ctc.name ?? "custom", toolCallId: callId, text: argText, rawResponsesItem: item });
|
|
49855
|
-
toolNames.set(callId, ctc.name ?? "custom");
|
|
49856
49741
|
break;
|
|
49857
49742
|
}
|
|
49858
49743
|
case "custom_tool_call_output": {
|
|
@@ -49861,8 +49746,7 @@ function responsesToCore(body) {
|
|
|
49861
49746
|
customToolCallIds.add(callId);
|
|
49862
49747
|
const outText = typeof ctco.output === "string" ? ctco.output : JSON.stringify(ctco.output ?? "");
|
|
49863
49748
|
coreId = clusters.next(deriveMessageId("tool", "tool-result", outText, { toolCallId: callId }));
|
|
49864
|
-
|
|
49865
|
-
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: callId, text: outText, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
49749
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: callId, text: outText, rawResponsesItem: item });
|
|
49866
49750
|
break;
|
|
49867
49751
|
}
|
|
49868
49752
|
default:
|
|
@@ -51183,14 +51067,97 @@ var ABSORB_TOOL_RESPONSES = {
|
|
|
51183
51067
|
parameters: ABSORB_TOOL_OPENAI.function.parameters
|
|
51184
51068
|
};
|
|
51185
51069
|
function parseCompressInput(input, callId) {
|
|
51186
|
-
const
|
|
51187
|
-
if (
|
|
51188
|
-
|
|
51070
|
+
const first = parseCompressArgs(input, { callId });
|
|
51071
|
+
if (first.ranges.length === 0 || first.diagnostics.invalidItems > 0) {
|
|
51072
|
+
const normalized = normalizeQuoteShape(input);
|
|
51073
|
+
if (normalized !== void 0) {
|
|
51074
|
+
const retry = parseCompressArgs(normalized, { callId });
|
|
51075
|
+
if (retry.ranges.length > first.ranges.length) {
|
|
51076
|
+
log("warn", `[acp-compress-input] quote-salvage: recovered ${retry.ranges.length} range(s) after single->double quote normalization (was ${first.ranges.length}, kind=${first.diagnostics.kind})`);
|
|
51077
|
+
return { ranges: retry.ranges, diagnostics: retry.diagnostics };
|
|
51078
|
+
}
|
|
51079
|
+
}
|
|
51080
|
+
}
|
|
51081
|
+
if (!first.diagnostics.ok && first.diagnostics.kind !== "ok") {
|
|
51082
|
+
log("warn", `[acp-compress-input] rejected: kind=${first.diagnostics.kind} invalidItems=${first.diagnostics.invalidItems}${first.diagnostics.keys ? ` keys=[${first.diagnostics.keys.join(",")}]` : ""}${first.diagnostics.length !== void 0 ? ` len=${first.diagnostics.length}` : ""}${first.diagnostics.invalidReasons && first.diagnostics.invalidReasons.length > 0 ? ` reasons=[${first.diagnostics.invalidReasons.join(" | ")}]` : ""}`);
|
|
51189
51083
|
}
|
|
51190
|
-
|
|
51191
|
-
|
|
51084
|
+
return { ranges: first.ranges, diagnostics: first.diagnostics };
|
|
51085
|
+
}
|
|
51086
|
+
function normalizeQuoteShape(input) {
|
|
51087
|
+
if (typeof input === "string") return normalizeSingleQuotes(input);
|
|
51088
|
+
if (input !== null && typeof input === "object" && !Array.isArray(input)) {
|
|
51089
|
+
const obj = input;
|
|
51090
|
+
if (typeof obj["content"] === "string") {
|
|
51091
|
+
const fixed = normalizeSingleQuotes(obj["content"]);
|
|
51092
|
+
if (fixed !== void 0) return { ...obj, content: fixed };
|
|
51093
|
+
}
|
|
51192
51094
|
}
|
|
51193
|
-
return
|
|
51095
|
+
return void 0;
|
|
51096
|
+
}
|
|
51097
|
+
function normalizeSingleQuotes(raw) {
|
|
51098
|
+
if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
|
|
51099
|
+
let out = "";
|
|
51100
|
+
let changed = false;
|
|
51101
|
+
let inDouble = false;
|
|
51102
|
+
let inSingle = false;
|
|
51103
|
+
for (let i = 0; i < raw.length; i++) {
|
|
51104
|
+
const ch = raw.charAt(i);
|
|
51105
|
+
if (inDouble) {
|
|
51106
|
+
out += ch;
|
|
51107
|
+
if (ch === "\\" && i + 1 < raw.length) {
|
|
51108
|
+
out += raw.charAt(i + 1);
|
|
51109
|
+
i++;
|
|
51110
|
+
} else if (ch === '"') {
|
|
51111
|
+
inDouble = false;
|
|
51112
|
+
}
|
|
51113
|
+
continue;
|
|
51114
|
+
}
|
|
51115
|
+
if (inSingle) {
|
|
51116
|
+
if (ch === "\\" && i + 1 < raw.length) {
|
|
51117
|
+
const next = raw.charAt(i + 1);
|
|
51118
|
+
out += next === "'" ? "'" : "\\" + next;
|
|
51119
|
+
i++;
|
|
51120
|
+
continue;
|
|
51121
|
+
}
|
|
51122
|
+
if (ch === "'") {
|
|
51123
|
+
out += '"';
|
|
51124
|
+
inSingle = false;
|
|
51125
|
+
changed = true;
|
|
51126
|
+
continue;
|
|
51127
|
+
}
|
|
51128
|
+
if (ch === '"') {
|
|
51129
|
+
out += '\\"';
|
|
51130
|
+
continue;
|
|
51131
|
+
}
|
|
51132
|
+
if (ch === "\n") {
|
|
51133
|
+
out += "\\n";
|
|
51134
|
+
continue;
|
|
51135
|
+
}
|
|
51136
|
+
if (ch === "\r") {
|
|
51137
|
+
out += "\\r";
|
|
51138
|
+
continue;
|
|
51139
|
+
}
|
|
51140
|
+
if (ch === " ") {
|
|
51141
|
+
out += "\\t";
|
|
51142
|
+
continue;
|
|
51143
|
+
}
|
|
51144
|
+
out += ch;
|
|
51145
|
+
continue;
|
|
51146
|
+
}
|
|
51147
|
+
if (ch === '"') {
|
|
51148
|
+
inDouble = true;
|
|
51149
|
+
out += ch;
|
|
51150
|
+
continue;
|
|
51151
|
+
}
|
|
51152
|
+
if (ch === "'") {
|
|
51153
|
+
inSingle = true;
|
|
51154
|
+
out += '"';
|
|
51155
|
+
changed = true;
|
|
51156
|
+
continue;
|
|
51157
|
+
}
|
|
51158
|
+
out += ch;
|
|
51159
|
+
}
|
|
51160
|
+
return changed ? out : void 0;
|
|
51194
51161
|
}
|
|
51195
51162
|
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.]";
|
|
51196
51163
|
function withStagedCompressGuidance(text) {
|
|
@@ -51637,7 +51604,7 @@ ${lines.join("\n\n")}`;
|
|
|
51637
51604
|
}
|
|
51638
51605
|
return `[Unknown proxy tool: ${toolName}]`;
|
|
51639
51606
|
}
|
|
51640
|
-
function
|
|
51607
|
+
function refNum2(ref) {
|
|
51641
51608
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
51642
51609
|
}
|
|
51643
51610
|
function applyRanges(parsed, ctx) {
|
|
@@ -51686,7 +51653,7 @@ ${reasons.map((r) => `- ${r}`).join("\n")}` : "";
|
|
|
51686
51653
|
}
|
|
51687
51654
|
const preContext = ctx.session.stats.lastInputTokens;
|
|
51688
51655
|
const shrinkRatio = preContext > 0 ? r.tokensCompressed / preContext : 0;
|
|
51689
|
-
const foldPoint = [...ranges].sort((a, b2) =>
|
|
51656
|
+
const foldPoint = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef))[0]?.startRef ?? "unknown";
|
|
51690
51657
|
ctx.session.lastCompress = { at: Date.now(), shrinkRatio, foldPoint, blocks: r.blocksCreated, tokensCompressed: r.tokensCompressed };
|
|
51691
51658
|
ctx.log(`[acp-compress-obs] shrink ${Math.round(shrinkRatio * 100)}% (~${r.tokensCompressed}/${preContext} tok) foldPoint=${foldPoint} blocks=${r.blocksCreated}`);
|
|
51692
51659
|
const warn = r.warnings.length > 0 ? ` ${r.warnings.join("; ")}` : "";
|
|
@@ -51753,7 +51720,7 @@ function refMaps(messages, state) {
|
|
|
51753
51720
|
});
|
|
51754
51721
|
return { refToIdx, idxToRef };
|
|
51755
51722
|
}
|
|
51756
|
-
function
|
|
51723
|
+
function refNum3(ref) {
|
|
51757
51724
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
51758
51725
|
}
|
|
51759
51726
|
function estimateCoreMessages(messages) {
|
|
@@ -52003,7 +51970,7 @@ async function preflightCompress(deps, messages) {
|
|
|
52003
51970
|
failure = { kind: "exhausted", detail: relaxed ? relaxedExhaustedDetail : "no compressible ranges remain in the conversation" };
|
|
52004
51971
|
break;
|
|
52005
51972
|
}
|
|
52006
|
-
const ordered = [...ranges].sort((a, b2) =>
|
|
51973
|
+
const ordered = [...ranges].sort((a, b2) => refNum3(a.startRef) - refNum3(b2.startRef));
|
|
52007
51974
|
let appliedThisRound = 0;
|
|
52008
51975
|
for (const range of ordered) {
|
|
52009
51976
|
if (currentTokens < limit) break;
|