billion-context 0.1.94 → 0.1.95-pr.634.455
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 +156 -123
- 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 refNum3 = (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: refNum3(r.startRef),
|
|
43663
|
+
endNum: refNum3(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: refNum3(r.startRef),
|
|
43681
|
+
endNum: refNum3(r.endRef),
|
|
43682
43682
|
count: r.count,
|
|
43683
43683
|
tokens: r.tokens,
|
|
43684
43684
|
toolPct: 0,
|
|
@@ -45328,10 +45328,6 @@ 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
|
-
}
|
|
45335
45331
|
function estimateTextTokens(text) {
|
|
45336
45332
|
return Math.ceil(text.length / 4);
|
|
45337
45333
|
}
|
|
@@ -45384,42 +45380,50 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45384
45380
|
const compressibleMsgs = [];
|
|
45385
45381
|
const protectedMsgs = [];
|
|
45386
45382
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
45383
|
+
let skipSinceCompressible = false;
|
|
45384
|
+
let skipSinceProtected = false;
|
|
45387
45385
|
for (const msg of messages) {
|
|
45388
|
-
if (isSyntheticOrPruned(msg, state)) continue;
|
|
45389
45386
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
45390
45387
|
if (!ref || ref === "BLOCKED") continue;
|
|
45391
|
-
|
|
45388
|
+
if (isSyntheticOrPruned(msg, state)) {
|
|
45389
|
+
skipSinceCompressible = true;
|
|
45390
|
+
skipSinceProtected = true;
|
|
45391
|
+
continue;
|
|
45392
|
+
}
|
|
45392
45393
|
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
|
|
45393
45394
|
protectedMsgs.push({
|
|
45394
45395
|
ref,
|
|
45395
|
-
|
|
45396
|
+
gapBefore: skipSinceProtected,
|
|
45396
45397
|
tokens: countTokens(msg.text ?? ""),
|
|
45397
45398
|
tools: msg.toolName ? [msg.toolName] : []
|
|
45398
45399
|
});
|
|
45400
|
+
skipSinceProtected = false;
|
|
45401
|
+
skipSinceCompressible = true;
|
|
45399
45402
|
continue;
|
|
45400
45403
|
}
|
|
45401
45404
|
if (protectedZoneRefs?.has(ref)) {
|
|
45405
|
+
skipSinceCompressible = true;
|
|
45406
|
+
skipSinceProtected = true;
|
|
45402
45407
|
continue;
|
|
45403
45408
|
}
|
|
45404
45409
|
compressibleMsgs.push({
|
|
45405
45410
|
ref,
|
|
45406
|
-
|
|
45411
|
+
gapBefore: skipSinceCompressible,
|
|
45407
45412
|
tokens: countTokens(msg.text ?? ""),
|
|
45408
45413
|
chars: (msg.text ?? "").length,
|
|
45409
45414
|
isTool: isToolMessage(msg),
|
|
45410
45415
|
isUser: msg.role === "user"
|
|
45411
45416
|
});
|
|
45417
|
+
skipSinceCompressible = false;
|
|
45418
|
+
skipSinceProtected = true;
|
|
45412
45419
|
}
|
|
45413
45420
|
const compressible = [];
|
|
45414
45421
|
let cur = null;
|
|
45415
|
-
let prevRefNum = -2;
|
|
45416
45422
|
for (const info of compressibleMsgs) {
|
|
45417
|
-
|
|
45418
|
-
if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
|
|
45423
|
+
if (cur && (info.isUser && cur.count >= 3 || info.gapBefore)) {
|
|
45419
45424
|
compressible.push(cur);
|
|
45420
45425
|
cur = null;
|
|
45421
45426
|
}
|
|
45422
|
-
prevRefNum = info.refNum;
|
|
45423
45427
|
if (!cur) {
|
|
45424
45428
|
cur = {
|
|
45425
45429
|
startRef: info.ref,
|
|
@@ -45446,14 +45450,11 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45446
45450
|
if (cur) compressible.push(cur);
|
|
45447
45451
|
const protectedRanges = [];
|
|
45448
45452
|
let pcur = null;
|
|
45449
|
-
let pPrevRefNum = -2;
|
|
45450
45453
|
for (const info of protectedMsgs) {
|
|
45451
|
-
|
|
45452
|
-
if (pcur && hasGap) {
|
|
45454
|
+
if (pcur && info.gapBefore) {
|
|
45453
45455
|
protectedRanges.push(pcur);
|
|
45454
45456
|
pcur = null;
|
|
45455
45457
|
}
|
|
45456
|
-
pPrevRefNum = info.refNum;
|
|
45457
45458
|
if (!pcur) {
|
|
45458
45459
|
pcur = {
|
|
45459
45460
|
startRef: info.ref,
|
|
@@ -46647,7 +46648,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46647
46648
|
lines.push(" (no uncompressed messages)");
|
|
46648
46649
|
return lines.join("\n");
|
|
46649
46650
|
}
|
|
46650
|
-
const
|
|
46651
|
+
const refNum3 = (ref) => {
|
|
46651
46652
|
const m2 = ref.match(/\d+/);
|
|
46652
46653
|
return m2 ? parseInt(m2[0], 10) : 0;
|
|
46653
46654
|
};
|
|
@@ -46664,7 +46665,7 @@ function renderUncompressedRanges(visible) {
|
|
|
46664
46665
|
};
|
|
46665
46666
|
const merged = [];
|
|
46666
46667
|
for (const m2 of visible) {
|
|
46667
|
-
const num3 =
|
|
46668
|
+
const num3 = refNum3(m2.ref);
|
|
46668
46669
|
const last = merged[merged.length - 1];
|
|
46669
46670
|
if (last && num3 === last.startNum + last.count) {
|
|
46670
46671
|
last.endRef = m2.ref;
|
|
@@ -46828,6 +46829,23 @@ function parseStringInput(raw, callId, diag) {
|
|
|
46828
46829
|
diag.rawPrefix = raw.slice(0, 800);
|
|
46829
46830
|
diag.length = raw.length;
|
|
46830
46831
|
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) {
|
|
46831
46849
|
if (cleaned === "") {
|
|
46832
46850
|
diag.kind = "empty-input";
|
|
46833
46851
|
return finish([], diag);
|
|
@@ -46871,6 +46889,7 @@ function parseObjectValue(value, callId, diag) {
|
|
|
46871
46889
|
}
|
|
46872
46890
|
entries = parsed.entries;
|
|
46873
46891
|
salvaged = parsed.salvaged;
|
|
46892
|
+
if (parsed.quoteRepaired) diag.quoteSalvage = true;
|
|
46874
46893
|
} else {
|
|
46875
46894
|
diag.kind = "content-not-array";
|
|
46876
46895
|
return finish([], diag);
|
|
@@ -46892,7 +46911,17 @@ function parseObjectValue(value, callId, diag) {
|
|
|
46892
46911
|
}
|
|
46893
46912
|
function parseContentArray(s3) {
|
|
46894
46913
|
const cleaned = stripFence(s3.trim());
|
|
46895
|
-
|
|
46914
|
+
const direct = parseContentArrayCore(cleaned);
|
|
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);
|
|
46896
46925
|
if (typeof value === "string") {
|
|
46897
46926
|
value = tryParseLenient(stripFence(value));
|
|
46898
46927
|
}
|
|
@@ -46900,7 +46929,7 @@ function parseContentArray(s3) {
|
|
|
46900
46929
|
return { entries: value, salvaged: false };
|
|
46901
46930
|
}
|
|
46902
46931
|
if (value === void 0) {
|
|
46903
|
-
const entries = salvageContentEntries('{"content": ' +
|
|
46932
|
+
const entries = salvageContentEntries('{"content": ' + s3);
|
|
46904
46933
|
return { entries, salvaged: entries.length > 0 };
|
|
46905
46934
|
}
|
|
46906
46935
|
return null;
|
|
@@ -46973,6 +47002,71 @@ function tryParseLenient(s3) {
|
|
|
46973
47002
|
}
|
|
46974
47003
|
return void 0;
|
|
46975
47004
|
}
|
|
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
|
+
}
|
|
46976
47070
|
function stripFence(s3) {
|
|
46977
47071
|
if (!s3.startsWith("```")) return s3;
|
|
46978
47072
|
const firstNewline = s3.indexOf("\n");
|
|
@@ -49210,6 +49304,7 @@ function anthropicToCore(body) {
|
|
|
49210
49304
|
const msgs = [];
|
|
49211
49305
|
const cacheControls = /* @__PURE__ */ new Map();
|
|
49212
49306
|
const clusters = new ClusterCounter();
|
|
49307
|
+
const toolNames = /* @__PURE__ */ new Map();
|
|
49213
49308
|
for (const m2 of body.messages) {
|
|
49214
49309
|
const blocks = typeof m2.content === "string" ? [{ type: "text", text: m2.content }] : m2.content;
|
|
49215
49310
|
for (const b2 of blocks) {
|
|
@@ -49235,6 +49330,7 @@ function anthropicToCore(body) {
|
|
|
49235
49330
|
toolCallId: b2.id,
|
|
49236
49331
|
text: safeStringify(b2.input)
|
|
49237
49332
|
});
|
|
49333
|
+
toolNames.set(b2.id, b2.name);
|
|
49238
49334
|
if (b2.cache_control) cacheControls.set(id, b2.cache_control);
|
|
49239
49335
|
break;
|
|
49240
49336
|
}
|
|
@@ -49242,12 +49338,14 @@ function anthropicToCore(body) {
|
|
|
49242
49338
|
const text = typeof b2.content === "string" ? b2.content : b2.content.map((c) => c.text).join("\n");
|
|
49243
49339
|
const base = deriveMessageId("tool", "tool-result", text, { toolCallId: b2.tool_use_id });
|
|
49244
49340
|
const id = clusters.next(base);
|
|
49341
|
+
const name = toolNames.get(b2.tool_use_id);
|
|
49245
49342
|
msgs.push({
|
|
49246
49343
|
id,
|
|
49247
49344
|
role: "tool",
|
|
49248
49345
|
contentType: "tool-result",
|
|
49249
49346
|
toolCallId: b2.tool_use_id,
|
|
49250
49347
|
text,
|
|
49348
|
+
...name ? { toolName: name } : {},
|
|
49251
49349
|
...b2.is_error === true ? { toolIsError: true } : {}
|
|
49252
49350
|
});
|
|
49253
49351
|
if (b2.cache_control) cacheControls.set(id, b2.cache_control);
|
|
@@ -49395,6 +49493,7 @@ function openaiToCore(body) {
|
|
|
49395
49493
|
const msgs = [];
|
|
49396
49494
|
const systemParts = [];
|
|
49397
49495
|
const clusters = new ClusterCounter();
|
|
49496
|
+
const toolNames = /* @__PURE__ */ new Map();
|
|
49398
49497
|
for (const m2 of body.messages) {
|
|
49399
49498
|
switch (m2.role) {
|
|
49400
49499
|
case "system":
|
|
@@ -49462,6 +49561,7 @@ function openaiToCore(body) {
|
|
|
49462
49561
|
toolCallId: tc.id,
|
|
49463
49562
|
text: tc.function.arguments ?? ""
|
|
49464
49563
|
});
|
|
49564
|
+
toolNames.set(tc.id, tc.function.name);
|
|
49465
49565
|
}
|
|
49466
49566
|
}
|
|
49467
49567
|
break;
|
|
@@ -49470,12 +49570,14 @@ function openaiToCore(body) {
|
|
|
49470
49570
|
const base = deriveMessageId("tool", "tool-result", stringContent(m2.content), {
|
|
49471
49571
|
toolCallId: m2.tool_call_id ?? ""
|
|
49472
49572
|
});
|
|
49573
|
+
const name = m2.name || toolNames.get(m2.tool_call_id ?? "");
|
|
49473
49574
|
msgs.push({
|
|
49474
49575
|
id: clusters.next(base),
|
|
49475
49576
|
role: "tool",
|
|
49476
49577
|
contentType: "tool-result",
|
|
49477
49578
|
toolCallId: m2.tool_call_id ?? "",
|
|
49478
|
-
text: stringContent(m2.content)
|
|
49579
|
+
text: stringContent(m2.content),
|
|
49580
|
+
...name ? { toolName: name } : {}
|
|
49479
49581
|
});
|
|
49480
49582
|
break;
|
|
49481
49583
|
}
|
|
@@ -49580,7 +49682,7 @@ function allImageParts(content) {
|
|
|
49580
49682
|
if (typeof p2 !== "object" || p2 === null) continue;
|
|
49581
49683
|
if (!("type" in p2) || p2.type !== "image_url" || !("image_url" in p2)) continue;
|
|
49582
49684
|
const imagePart = p2;
|
|
49583
|
-
const url = imagePart.image_url
|
|
49685
|
+
const url = imagePart.image_url?.url;
|
|
49584
49686
|
if (typeof url === "string" && parseDataUrl(url)) out.push(p2);
|
|
49585
49687
|
}
|
|
49586
49688
|
return out;
|
|
@@ -49592,6 +49694,14 @@ var OPAQUE_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
|
49592
49694
|
function isOpaqueItem(item) {
|
|
49593
49695
|
return OPAQUE_ITEM_TYPES.has(item.type);
|
|
49594
49696
|
}
|
|
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
|
+
}
|
|
49595
49705
|
function shouldDropAllReasoning() {
|
|
49596
49706
|
return (process.env.ACP_REASONING_KEEP ?? "").trim().toLowerCase() === "none";
|
|
49597
49707
|
}
|
|
@@ -49628,6 +49738,7 @@ function responsesToCore(body) {
|
|
|
49628
49738
|
const layout = [];
|
|
49629
49739
|
let droppedReasoning = 0;
|
|
49630
49740
|
const clusters = new ClusterCounter();
|
|
49741
|
+
const toolNames = /* @__PURE__ */ new Map();
|
|
49631
49742
|
let idx = 0;
|
|
49632
49743
|
if (typeof body.instructions === "string" && body.instructions.trim()) systemParts.push(body.instructions);
|
|
49633
49744
|
if (typeof body.input === "string") {
|
|
@@ -49635,7 +49746,8 @@ function responsesToCore(body) {
|
|
|
49635
49746
|
msgs.push({ id, role: "user", contentType: "text", text: body.input });
|
|
49636
49747
|
return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning, stringInput: { original: body.input, coreId: id } };
|
|
49637
49748
|
}
|
|
49638
|
-
for (const
|
|
49749
|
+
for (const raw of body.input) {
|
|
49750
|
+
const item = normalizeEasyInputItem(raw);
|
|
49639
49751
|
let coreId;
|
|
49640
49752
|
if (isOpaqueItem(item)) preamble.push(item);
|
|
49641
49753
|
switch (item.type) {
|
|
@@ -49710,13 +49822,15 @@ function responsesToCore(body) {
|
|
|
49710
49822
|
text: call.arguments ?? "",
|
|
49711
49823
|
rawResponsesItem: item
|
|
49712
49824
|
});
|
|
49825
|
+
toolNames.set(call.call_id, call.name);
|
|
49713
49826
|
break;
|
|
49714
49827
|
}
|
|
49715
49828
|
case "function_call_output": {
|
|
49716
49829
|
const output = item;
|
|
49717
49830
|
const text = typeof output.output === "string" ? output.output : JSON.stringify(output.output);
|
|
49718
49831
|
coreId = clusters.next(deriveMessageId("tool", "tool-result", text, { toolCallId: output.call_id }));
|
|
49719
|
-
|
|
49832
|
+
const name = toolNames.get(output.call_id);
|
|
49833
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: output.call_id, text, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
49720
49834
|
break;
|
|
49721
49835
|
}
|
|
49722
49836
|
case "computer_call":
|
|
@@ -49738,6 +49852,7 @@ function responsesToCore(body) {
|
|
|
49738
49852
|
const argText = ctc.input ?? ctc.arguments ?? "";
|
|
49739
49853
|
coreId = clusters.next(deriveMessageId("assistant", "tool-call", argText, { toolCallId: callId, toolName: ctc.name ?? "custom" }));
|
|
49740
49854
|
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");
|
|
49741
49856
|
break;
|
|
49742
49857
|
}
|
|
49743
49858
|
case "custom_tool_call_output": {
|
|
@@ -49746,7 +49861,8 @@ function responsesToCore(body) {
|
|
|
49746
49861
|
customToolCallIds.add(callId);
|
|
49747
49862
|
const outText = typeof ctco.output === "string" ? ctco.output : JSON.stringify(ctco.output ?? "");
|
|
49748
49863
|
coreId = clusters.next(deriveMessageId("tool", "tool-result", outText, { toolCallId: callId }));
|
|
49749
|
-
|
|
49864
|
+
const name = toolNames.get(callId);
|
|
49865
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: callId, text: outText, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
49750
49866
|
break;
|
|
49751
49867
|
}
|
|
49752
49868
|
default:
|
|
@@ -51067,97 +51183,14 @@ var ABSORB_TOOL_RESPONSES = {
|
|
|
51067
51183
|
parameters: ABSORB_TOOL_OPENAI.function.parameters
|
|
51068
51184
|
};
|
|
51069
51185
|
function parseCompressInput(input, callId) {
|
|
51070
|
-
const
|
|
51071
|
-
if (
|
|
51072
|
-
|
|
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(" | ")}]` : ""}`);
|
|
51186
|
+
const parsed = parseCompressArgs(input, { callId });
|
|
51187
|
+
if (parsed.diagnostics.quoteSalvage === true) {
|
|
51188
|
+
log("warn", `[acp-compress-input] quote-salvage: recovered ${parsed.ranges.length} range(s) after single->double quote normalization (kind=${parsed.diagnostics.kind})`);
|
|
51083
51189
|
}
|
|
51084
|
-
|
|
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
|
-
}
|
|
51190
|
+
if (!parsed.diagnostics.ok && parsed.diagnostics.kind !== "ok") {
|
|
51191
|
+
log("warn", `[acp-compress-input] rejected: kind=${parsed.diagnostics.kind} invalidItems=${parsed.diagnostics.invalidItems}${parsed.diagnostics.keys ? ` keys=[${parsed.diagnostics.keys.join(",")}]` : ""}${parsed.diagnostics.length !== void 0 ? ` len=${parsed.diagnostics.length}` : ""}${parsed.diagnostics.invalidReasons && parsed.diagnostics.invalidReasons.length > 0 ? ` reasons=[${parsed.diagnostics.invalidReasons.join(" | ")}]` : ""}`);
|
|
51094
51192
|
}
|
|
51095
|
-
return
|
|
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;
|
|
51193
|
+
return { ranges: parsed.ranges, diagnostics: parsed.diagnostics };
|
|
51161
51194
|
}
|
|
51162
51195
|
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.]";
|
|
51163
51196
|
function withStagedCompressGuidance(text) {
|
|
@@ -51604,7 +51637,7 @@ ${lines.join("\n\n")}`;
|
|
|
51604
51637
|
}
|
|
51605
51638
|
return `[Unknown proxy tool: ${toolName}]`;
|
|
51606
51639
|
}
|
|
51607
|
-
function
|
|
51640
|
+
function refNum(ref) {
|
|
51608
51641
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
51609
51642
|
}
|
|
51610
51643
|
function applyRanges(parsed, ctx) {
|
|
@@ -51653,7 +51686,7 @@ ${reasons.map((r) => `- ${r}`).join("\n")}` : "";
|
|
|
51653
51686
|
}
|
|
51654
51687
|
const preContext = ctx.session.stats.lastInputTokens;
|
|
51655
51688
|
const shrinkRatio = preContext > 0 ? r.tokensCompressed / preContext : 0;
|
|
51656
|
-
const foldPoint = [...ranges].sort((a, b2) =>
|
|
51689
|
+
const foldPoint = [...ranges].sort((a, b2) => refNum(a.startRef) - refNum(b2.startRef))[0]?.startRef ?? "unknown";
|
|
51657
51690
|
ctx.session.lastCompress = { at: Date.now(), shrinkRatio, foldPoint, blocks: r.blocksCreated, tokensCompressed: r.tokensCompressed };
|
|
51658
51691
|
ctx.log(`[acp-compress-obs] shrink ${Math.round(shrinkRatio * 100)}% (~${r.tokensCompressed}/${preContext} tok) foldPoint=${foldPoint} blocks=${r.blocksCreated}`);
|
|
51659
51692
|
const warn = r.warnings.length > 0 ? ` ${r.warnings.join("; ")}` : "";
|
|
@@ -51720,7 +51753,7 @@ function refMaps(messages, state) {
|
|
|
51720
51753
|
});
|
|
51721
51754
|
return { refToIdx, idxToRef };
|
|
51722
51755
|
}
|
|
51723
|
-
function
|
|
51756
|
+
function refNum2(ref) {
|
|
51724
51757
|
return Number(ref.replace(/\D/g, "")) || 0;
|
|
51725
51758
|
}
|
|
51726
51759
|
function estimateCoreMessages(messages) {
|
|
@@ -51970,7 +52003,7 @@ async function preflightCompress(deps, messages) {
|
|
|
51970
52003
|
failure = { kind: "exhausted", detail: relaxed ? relaxedExhaustedDetail : "no compressible ranges remain in the conversation" };
|
|
51971
52004
|
break;
|
|
51972
52005
|
}
|
|
51973
|
-
const ordered = [...ranges].sort((a, b2) =>
|
|
52006
|
+
const ordered = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef));
|
|
51974
52007
|
let appliedThisRound = 0;
|
|
51975
52008
|
for (const range of ordered) {
|
|
51976
52009
|
if (currentTokens < limit) break;
|