acp-kernel 0.0.58-pr.212.72 → 0.0.58
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 +20 -114
- package/dist/index.js.map +1 -1
- package/dist/parse-compress-input.d.ts +0 -2
- package/dist/parse-compress-input.d.ts.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/wire/anthropic.d.ts.map +1 -1
- package/dist/wire/index.js +5 -27
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/openai.d.ts.map +1 -1
- package/dist/wire/responses.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1652,6 +1652,10 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
1652
1652
|
}
|
|
1653
1653
|
|
|
1654
1654
|
// src/recommend.ts
|
|
1655
|
+
function refNum(ref) {
|
|
1656
|
+
const n = parseInt(ref.slice(1), 10);
|
|
1657
|
+
return Number.isNaN(n) ? -1 : n;
|
|
1658
|
+
}
|
|
1655
1659
|
function estimateTextTokens(text) {
|
|
1656
1660
|
return Math.ceil(text.length / 4);
|
|
1657
1661
|
}
|
|
@@ -1704,50 +1708,42 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1704
1708
|
const compressibleMsgs = [];
|
|
1705
1709
|
const protectedMsgs = [];
|
|
1706
1710
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
1707
|
-
let skipSinceCompressible = false;
|
|
1708
|
-
let skipSinceProtected = false;
|
|
1709
1711
|
for (const msg of messages) {
|
|
1712
|
+
if (isSyntheticOrPruned(msg, state)) continue;
|
|
1710
1713
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
1711
1714
|
if (!ref || ref === "BLOCKED") continue;
|
|
1712
|
-
|
|
1713
|
-
skipSinceCompressible = true;
|
|
1714
|
-
skipSinceProtected = true;
|
|
1715
|
-
continue;
|
|
1716
|
-
}
|
|
1715
|
+
const rn = refNum(ref);
|
|
1717
1716
|
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
|
|
1718
1717
|
protectedMsgs.push({
|
|
1719
1718
|
ref,
|
|
1720
|
-
|
|
1719
|
+
refNum: rn,
|
|
1721
1720
|
tokens: countTokens(msg.text ?? ""),
|
|
1722
1721
|
tools: msg.toolName ? [msg.toolName] : []
|
|
1723
1722
|
});
|
|
1724
|
-
skipSinceProtected = false;
|
|
1725
|
-
skipSinceCompressible = true;
|
|
1726
1723
|
continue;
|
|
1727
1724
|
}
|
|
1728
1725
|
if (protectedZoneRefs?.has(ref)) {
|
|
1729
|
-
skipSinceCompressible = true;
|
|
1730
|
-
skipSinceProtected = true;
|
|
1731
1726
|
continue;
|
|
1732
1727
|
}
|
|
1733
1728
|
compressibleMsgs.push({
|
|
1734
1729
|
ref,
|
|
1735
|
-
|
|
1730
|
+
refNum: rn,
|
|
1736
1731
|
tokens: countTokens(msg.text ?? ""),
|
|
1737
1732
|
chars: (msg.text ?? "").length,
|
|
1738
1733
|
isTool: isToolMessage(msg),
|
|
1739
1734
|
isUser: msg.role === "user"
|
|
1740
1735
|
});
|
|
1741
|
-
skipSinceCompressible = false;
|
|
1742
|
-
skipSinceProtected = true;
|
|
1743
1736
|
}
|
|
1744
1737
|
const compressible = [];
|
|
1745
1738
|
let cur = null;
|
|
1739
|
+
let prevRefNum = -2;
|
|
1746
1740
|
for (const info of compressibleMsgs) {
|
|
1747
|
-
|
|
1741
|
+
const hasGap = info.refNum > prevRefNum + 1;
|
|
1742
|
+
if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
|
|
1748
1743
|
compressible.push(cur);
|
|
1749
1744
|
cur = null;
|
|
1750
1745
|
}
|
|
1746
|
+
prevRefNum = info.refNum;
|
|
1751
1747
|
if (!cur) {
|
|
1752
1748
|
cur = {
|
|
1753
1749
|
startRef: info.ref,
|
|
@@ -1774,11 +1770,14 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1774
1770
|
if (cur) compressible.push(cur);
|
|
1775
1771
|
const protectedRanges = [];
|
|
1776
1772
|
let pcur = null;
|
|
1773
|
+
let pPrevRefNum = -2;
|
|
1777
1774
|
for (const info of protectedMsgs) {
|
|
1778
|
-
|
|
1775
|
+
const hasGap = info.refNum > pPrevRefNum + 1;
|
|
1776
|
+
if (pcur && hasGap) {
|
|
1779
1777
|
protectedRanges.push(pcur);
|
|
1780
1778
|
pcur = null;
|
|
1781
1779
|
}
|
|
1780
|
+
pPrevRefNum = info.refNum;
|
|
1782
1781
|
if (!pcur) {
|
|
1783
1782
|
pcur = {
|
|
1784
1783
|
startRef: info.ref,
|
|
@@ -3048,7 +3047,7 @@ function renderUncompressedRanges(visible) {
|
|
|
3048
3047
|
lines.push(" (no uncompressed messages)");
|
|
3049
3048
|
return lines.join("\n");
|
|
3050
3049
|
}
|
|
3051
|
-
const
|
|
3050
|
+
const refNum2 = (ref) => {
|
|
3052
3051
|
const m = ref.match(/\d+/);
|
|
3053
3052
|
return m ? parseInt(m[0], 10) : 0;
|
|
3054
3053
|
};
|
|
@@ -3065,7 +3064,7 @@ function renderUncompressedRanges(visible) {
|
|
|
3065
3064
|
};
|
|
3066
3065
|
const merged = [];
|
|
3067
3066
|
for (const m of visible) {
|
|
3068
|
-
const num =
|
|
3067
|
+
const num = refNum2(m.ref);
|
|
3069
3068
|
const last = merged[merged.length - 1];
|
|
3070
3069
|
if (last && num === last.startNum + last.count) {
|
|
3071
3070
|
last.endRef = m.ref;
|
|
@@ -3263,23 +3262,6 @@ function parseStringInput(raw, callId, diag) {
|
|
|
3263
3262
|
diag.rawPrefix = raw.slice(0, 800);
|
|
3264
3263
|
diag.length = raw.length;
|
|
3265
3264
|
const cleaned = stripFence(raw.trim());
|
|
3266
|
-
const first = parseStringCore(cleaned, callId, diag);
|
|
3267
|
-
if (first.ranges.length === 0 || first.diagnostics.invalidItems > 0) {
|
|
3268
|
-
const normalized = normalizeSingleQuotes(cleaned);
|
|
3269
|
-
if (normalized !== void 0) {
|
|
3270
|
-
const retryDiag = { ok: false, kind: "ok", invalidItems: 0 };
|
|
3271
|
-
retryDiag.rawPrefix = diag.rawPrefix;
|
|
3272
|
-
retryDiag.length = diag.length;
|
|
3273
|
-
const retry = parseStringCore(normalized, callId, retryDiag);
|
|
3274
|
-
if (retry.ranges.length > first.ranges.length) {
|
|
3275
|
-
retryDiag.quoteSalvage = true;
|
|
3276
|
-
return retry;
|
|
3277
|
-
}
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
return first;
|
|
3281
|
-
}
|
|
3282
|
-
function parseStringCore(cleaned, callId, diag) {
|
|
3283
3265
|
if (cleaned === "") {
|
|
3284
3266
|
diag.kind = "empty-input";
|
|
3285
3267
|
return finish([], diag);
|
|
@@ -3323,7 +3305,6 @@ function parseObjectValue(value, callId, diag) {
|
|
|
3323
3305
|
}
|
|
3324
3306
|
entries = parsed.entries;
|
|
3325
3307
|
salvaged = parsed.salvaged;
|
|
3326
|
-
if (parsed.quoteRepaired) diag.quoteSalvage = true;
|
|
3327
3308
|
} else {
|
|
3328
3309
|
diag.kind = "content-not-array";
|
|
3329
3310
|
return finish([], diag);
|
|
@@ -3345,17 +3326,7 @@ function parseObjectValue(value, callId, diag) {
|
|
|
3345
3326
|
}
|
|
3346
3327
|
function parseContentArray(s) {
|
|
3347
3328
|
const cleaned = stripFence(s.trim());
|
|
3348
|
-
|
|
3349
|
-
if (direct !== null && direct.entries.length > 0) return direct;
|
|
3350
|
-
const normalized = normalizeSingleQuotes(cleaned);
|
|
3351
|
-
if (normalized !== void 0) {
|
|
3352
|
-
const retry = parseContentArrayCore(normalized);
|
|
3353
|
-
if (retry !== null && retry.entries.length > 0) return { ...retry, quoteRepaired: true };
|
|
3354
|
-
}
|
|
3355
|
-
return direct;
|
|
3356
|
-
}
|
|
3357
|
-
function parseContentArrayCore(s) {
|
|
3358
|
-
let value = s === "" ? void 0 : tryParseLenient(s);
|
|
3329
|
+
let value = cleaned === "" ? void 0 : tryParseLenient(cleaned);
|
|
3359
3330
|
if (typeof value === "string") {
|
|
3360
3331
|
value = tryParseLenient(stripFence(value));
|
|
3361
3332
|
}
|
|
@@ -3363,7 +3334,7 @@ function parseContentArrayCore(s) {
|
|
|
3363
3334
|
return { entries: value, salvaged: false };
|
|
3364
3335
|
}
|
|
3365
3336
|
if (value === void 0) {
|
|
3366
|
-
const entries = salvageContentEntries('{"content": ' +
|
|
3337
|
+
const entries = salvageContentEntries('{"content": ' + cleaned);
|
|
3367
3338
|
return { entries, salvaged: entries.length > 0 };
|
|
3368
3339
|
}
|
|
3369
3340
|
return null;
|
|
@@ -3436,71 +3407,6 @@ function tryParseLenient(s) {
|
|
|
3436
3407
|
}
|
|
3437
3408
|
return void 0;
|
|
3438
3409
|
}
|
|
3439
|
-
function normalizeSingleQuotes(raw) {
|
|
3440
|
-
if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
|
|
3441
|
-
let out = "";
|
|
3442
|
-
let changed = false;
|
|
3443
|
-
let inDouble = false;
|
|
3444
|
-
let inSingle = false;
|
|
3445
|
-
for (let i = 0; i < raw.length; i++) {
|
|
3446
|
-
const ch = raw.charAt(i);
|
|
3447
|
-
if (inDouble) {
|
|
3448
|
-
out += ch;
|
|
3449
|
-
if (ch === "\\" && i + 1 < raw.length) {
|
|
3450
|
-
out += raw.charAt(i + 1);
|
|
3451
|
-
i++;
|
|
3452
|
-
} else if (ch === '"') {
|
|
3453
|
-
inDouble = false;
|
|
3454
|
-
}
|
|
3455
|
-
continue;
|
|
3456
|
-
}
|
|
3457
|
-
if (inSingle) {
|
|
3458
|
-
if (ch === "\\" && i + 1 < raw.length) {
|
|
3459
|
-
const next = raw.charAt(i + 1);
|
|
3460
|
-
out += next === "'" ? "'" : "\\" + next;
|
|
3461
|
-
i++;
|
|
3462
|
-
continue;
|
|
3463
|
-
}
|
|
3464
|
-
if (ch === "'") {
|
|
3465
|
-
out += '"';
|
|
3466
|
-
inSingle = false;
|
|
3467
|
-
changed = true;
|
|
3468
|
-
continue;
|
|
3469
|
-
}
|
|
3470
|
-
if (ch === '"') {
|
|
3471
|
-
out += '\\"';
|
|
3472
|
-
continue;
|
|
3473
|
-
}
|
|
3474
|
-
if (ch === "\n") {
|
|
3475
|
-
out += "\\n";
|
|
3476
|
-
continue;
|
|
3477
|
-
}
|
|
3478
|
-
if (ch === "\r") {
|
|
3479
|
-
out += "\\r";
|
|
3480
|
-
continue;
|
|
3481
|
-
}
|
|
3482
|
-
if (ch === " ") {
|
|
3483
|
-
out += "\\t";
|
|
3484
|
-
continue;
|
|
3485
|
-
}
|
|
3486
|
-
out += ch;
|
|
3487
|
-
continue;
|
|
3488
|
-
}
|
|
3489
|
-
if (ch === '"') {
|
|
3490
|
-
inDouble = true;
|
|
3491
|
-
out += ch;
|
|
3492
|
-
continue;
|
|
3493
|
-
}
|
|
3494
|
-
if (ch === "'") {
|
|
3495
|
-
inSingle = true;
|
|
3496
|
-
out += '"';
|
|
3497
|
-
changed = true;
|
|
3498
|
-
continue;
|
|
3499
|
-
}
|
|
3500
|
-
out += ch;
|
|
3501
|
-
}
|
|
3502
|
-
return changed ? out : void 0;
|
|
3503
|
-
}
|
|
3504
3410
|
function stripFence(s) {
|
|
3505
3411
|
if (!s.startsWith("```")) return s;
|
|
3506
3412
|
const firstNewline = s.indexOf("\n");
|