billion-context 0.1.113 → 0.1.114
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/README.md +1 -1
- package/dist/agent/opencode.js.map +1 -1
- package/dist/index.js +1005 -63
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -26858,15 +26858,15 @@ var require_util7 = __commonJS({
|
|
|
26858
26858
|
}
|
|
26859
26859
|
return true;
|
|
26860
26860
|
};
|
|
26861
|
-
util.format = function(
|
|
26861
|
+
util.format = function(format2) {
|
|
26862
26862
|
var re2 = /%./g;
|
|
26863
26863
|
var match;
|
|
26864
26864
|
var part;
|
|
26865
26865
|
var argi = 0;
|
|
26866
26866
|
var parts = [];
|
|
26867
26867
|
var last = 0;
|
|
26868
|
-
while (match = re2.exec(
|
|
26869
|
-
part =
|
|
26868
|
+
while (match = re2.exec(format2)) {
|
|
26869
|
+
part = format2.substring(last, re2.lastIndex - 2);
|
|
26870
26870
|
if (part.length > 0) {
|
|
26871
26871
|
parts.push(part);
|
|
26872
26872
|
}
|
|
@@ -26891,7 +26891,7 @@ var require_util7 = __commonJS({
|
|
|
26891
26891
|
parts.push("<%" + code + "?>");
|
|
26892
26892
|
}
|
|
26893
26893
|
}
|
|
26894
|
-
parts.push(
|
|
26894
|
+
parts.push(format2.substring(last));
|
|
26895
26895
|
return parts.join("");
|
|
26896
26896
|
};
|
|
26897
26897
|
util.formatNumber = function(number, decimals, dec_point, thousands_sep) {
|
|
@@ -28794,18 +28794,18 @@ var require_asn1 = __commonJS({
|
|
|
28794
28794
|
return date;
|
|
28795
28795
|
}
|
|
28796
28796
|
var rval = "";
|
|
28797
|
-
var
|
|
28798
|
-
|
|
28799
|
-
|
|
28800
|
-
|
|
28801
|
-
|
|
28802
|
-
|
|
28803
|
-
|
|
28804
|
-
for (var i = 0; i <
|
|
28805
|
-
if (
|
|
28797
|
+
var format2 = [];
|
|
28798
|
+
format2.push(("" + date.getUTCFullYear()).substr(2));
|
|
28799
|
+
format2.push("" + (date.getUTCMonth() + 1));
|
|
28800
|
+
format2.push("" + date.getUTCDate());
|
|
28801
|
+
format2.push("" + date.getUTCHours());
|
|
28802
|
+
format2.push("" + date.getUTCMinutes());
|
|
28803
|
+
format2.push("" + date.getUTCSeconds());
|
|
28804
|
+
for (var i = 0; i < format2.length; ++i) {
|
|
28805
|
+
if (format2[i].length < 2) {
|
|
28806
28806
|
rval += "0";
|
|
28807
28807
|
}
|
|
28808
|
-
rval +=
|
|
28808
|
+
rval += format2[i];
|
|
28809
28809
|
}
|
|
28810
28810
|
rval += "Z";
|
|
28811
28811
|
return rval;
|
|
@@ -28815,18 +28815,18 @@ var require_asn1 = __commonJS({
|
|
|
28815
28815
|
return date;
|
|
28816
28816
|
}
|
|
28817
28817
|
var rval = "";
|
|
28818
|
-
var
|
|
28819
|
-
|
|
28820
|
-
|
|
28821
|
-
|
|
28822
|
-
|
|
28823
|
-
|
|
28824
|
-
|
|
28825
|
-
for (var i = 0; i <
|
|
28826
|
-
if (
|
|
28818
|
+
var format2 = [];
|
|
28819
|
+
format2.push("" + date.getUTCFullYear());
|
|
28820
|
+
format2.push("" + (date.getUTCMonth() + 1));
|
|
28821
|
+
format2.push("" + date.getUTCDate());
|
|
28822
|
+
format2.push("" + date.getUTCHours());
|
|
28823
|
+
format2.push("" + date.getUTCMinutes());
|
|
28824
|
+
format2.push("" + date.getUTCSeconds());
|
|
28825
|
+
for (var i = 0; i < format2.length; ++i) {
|
|
28826
|
+
if (format2[i].length < 2) {
|
|
28827
28827
|
rval += "0";
|
|
28828
28828
|
}
|
|
28829
|
-
rval +=
|
|
28829
|
+
rval += format2[i];
|
|
28830
28830
|
}
|
|
28831
28831
|
rval += "Z";
|
|
28832
28832
|
return rval;
|
|
@@ -44022,9 +44022,43 @@ function collectSummaryAnchors(state, indexById, summaryIndexById) {
|
|
|
44022
44022
|
anchors.sort((left, right) => left.insertAt - right.insertAt);
|
|
44023
44023
|
return anchors;
|
|
44024
44024
|
}
|
|
44025
|
+
function pairSafeAnchorIndex(messages, index) {
|
|
44026
|
+
let safe = index;
|
|
44027
|
+
while (safe > 0 && safe < messages.length && messages[safe - 1].role === "assistant" && messages[safe].role === "assistant") {
|
|
44028
|
+
safe--;
|
|
44029
|
+
}
|
|
44030
|
+
const resultIndexByCallId = /* @__PURE__ */ new Map();
|
|
44031
|
+
messages.forEach((message, at2) => {
|
|
44032
|
+
if (message.contentType !== "tool-result") return;
|
|
44033
|
+
if (typeof message.toolCallId !== "string") return;
|
|
44034
|
+
if (!resultIndexByCallId.has(message.toolCallId)) {
|
|
44035
|
+
resultIndexByCallId.set(message.toolCallId, at2);
|
|
44036
|
+
}
|
|
44037
|
+
});
|
|
44038
|
+
for (let guard = 0; guard < messages.length; guard++) {
|
|
44039
|
+
let moved = safe;
|
|
44040
|
+
for (let at2 = 0; at2 < safe && at2 < messages.length; at2++) {
|
|
44041
|
+
const message = messages[at2];
|
|
44042
|
+
if (message.role !== "assistant") continue;
|
|
44043
|
+
if (message.contentType !== "tool-call") continue;
|
|
44044
|
+
if (typeof message.toolCallId !== "string") continue;
|
|
44045
|
+
const resultIndex = resultIndexByCallId.get(message.toolCallId);
|
|
44046
|
+
if (resultIndex !== void 0 && resultIndex >= safe && resultIndex + 1 > moved) {
|
|
44047
|
+
moved = resultIndex + 1;
|
|
44048
|
+
}
|
|
44049
|
+
}
|
|
44050
|
+
if (moved === safe) break;
|
|
44051
|
+
safe = moved;
|
|
44052
|
+
}
|
|
44053
|
+
return safe;
|
|
44054
|
+
}
|
|
44025
44055
|
function rebuildMessages(messages, covered, firstUserIndex, anchors) {
|
|
44056
|
+
const safeAnchors = anchors.map((anchor) => ({
|
|
44057
|
+
...anchor,
|
|
44058
|
+
insertAt: pairSafeAnchorIndex(messages, anchor.insertAt)
|
|
44059
|
+
})).sort((left, right) => left.insertAt - right.insertAt);
|
|
44026
44060
|
const result = [];
|
|
44027
|
-
const pending = [...
|
|
44061
|
+
const pending = [...safeAnchors];
|
|
44028
44062
|
const anchoredSummaryIds = new Set(
|
|
44029
44063
|
anchors.map((anchor) => summaryMessageId(anchor.blockId))
|
|
44030
44064
|
);
|
|
@@ -46362,17 +46396,42 @@ function applySingleRange(input) {
|
|
|
46362
46396
|
splitTurnCount++;
|
|
46363
46397
|
for (const id of group) withdrawIds.add(id);
|
|
46364
46398
|
}
|
|
46399
|
+
const resultIdByCallId = /* @__PURE__ */ new Map();
|
|
46400
|
+
for (const m2 of input.messages) {
|
|
46401
|
+
if (!m2.id || m2.contentType !== "tool-result") continue;
|
|
46402
|
+
if (typeof m2.toolCallId !== "string") continue;
|
|
46403
|
+
if (!resultIdByCallId.has(m2.toolCallId)) {
|
|
46404
|
+
resultIdByCallId.set(m2.toolCallId, m2.id);
|
|
46405
|
+
}
|
|
46406
|
+
}
|
|
46407
|
+
let splitPairCount = 0;
|
|
46408
|
+
for (const m2 of input.messages) {
|
|
46409
|
+
if (!m2.id || m2.contentType !== "tool-call") continue;
|
|
46410
|
+
if (typeof m2.toolCallId !== "string") continue;
|
|
46411
|
+
const resultId = resultIdByCallId.get(m2.toolCallId);
|
|
46412
|
+
if (resultId === void 0) continue;
|
|
46413
|
+
if (effectiveMessageIds.has(m2.id) === effectiveMessageIds.has(resultId)) {
|
|
46414
|
+
continue;
|
|
46415
|
+
}
|
|
46416
|
+
withdrawIds.add(m2.id);
|
|
46417
|
+
withdrawIds.add(resultId);
|
|
46418
|
+
splitPairCount++;
|
|
46419
|
+
}
|
|
46365
46420
|
if (withdrawIds.size > 0) {
|
|
46366
46421
|
for (const id of withdrawIds) effectiveMessageIds.delete(id);
|
|
46367
46422
|
const beforeWithdraw = filteredIds.length;
|
|
46368
46423
|
filteredIds = filteredIds.filter((id) => !withdrawIds.has(id));
|
|
46424
|
+
const splitDesc = [
|
|
46425
|
+
splitTurnCount > 0 ? `${splitTurnCount} turn(s)` : null,
|
|
46426
|
+
splitPairCount > 0 ? `${splitPairCount} tool call/result pair(s)` : null
|
|
46427
|
+
].filter((part) => part !== null).join(" and ");
|
|
46369
46428
|
if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
|
|
46370
46429
|
throw new Error(
|
|
46371
|
-
`Range would split ${
|
|
46430
|
+
`Range would split ${splitDesc} at the protected-zone boundary: a visible tool-call must keep its reasoning run and its results (strict providers reject a rebuilt request that lost either). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
|
|
46372
46431
|
);
|
|
46373
46432
|
}
|
|
46374
46433
|
warnings.push(
|
|
46375
|
-
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${
|
|
46434
|
+
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitDesc} intact (visible tool-call would lose its reasoning run or its results).`
|
|
46376
46435
|
);
|
|
46377
46436
|
}
|
|
46378
46437
|
}
|
|
@@ -50040,9 +50099,10 @@ ${summary}` }]
|
|
|
50040
50099
|
}
|
|
50041
50100
|
return { items, replaced, dropped };
|
|
50042
50101
|
}
|
|
50102
|
+
var CODEX_COMPACT_HEALTH_RATIO = 0.9;
|
|
50043
50103
|
function codexCompactGatePre(session, effectiveLimit) {
|
|
50044
50104
|
if (effectiveLimit <= 0) return false;
|
|
50045
|
-
if (session.stats.lastInputTokens >= effectiveLimit *
|
|
50105
|
+
if (session.stats.lastInputTokens >= effectiveLimit * CODEX_COMPACT_HEALTH_RATIO) return false;
|
|
50046
50106
|
return session.state.blocks.some((b2) => b2.active);
|
|
50047
50107
|
}
|
|
50048
50108
|
function codexCompactGate(session, effectiveLimit, transformOk) {
|
|
@@ -53083,8 +53143,8 @@ var HEADER_SCAN_CHARS = 64;
|
|
|
53083
53143
|
var JPEG_SCAN_CHARS = 35e4;
|
|
53084
53144
|
function decodeImageDims(b64) {
|
|
53085
53145
|
const head = Buffer.from(b64.slice(0, HEADER_SCAN_CHARS), "base64");
|
|
53086
|
-
for (const
|
|
53087
|
-
const d =
|
|
53146
|
+
for (const parse4 of [pngDims, gifDims, bmpDims, webpDims]) {
|
|
53147
|
+
const d = parse4(head);
|
|
53088
53148
|
if (d) return d;
|
|
53089
53149
|
}
|
|
53090
53150
|
if (head.length >= 2 && head[0] === 255 && head[1] === 216) {
|
|
@@ -53616,6 +53676,7 @@ function noEmergencyTruncate(config) {
|
|
|
53616
53676
|
}
|
|
53617
53677
|
async function preflightCompress(deps, messages) {
|
|
53618
53678
|
const limit = deps.config.modelContextLimit;
|
|
53679
|
+
let target = Math.min(limit, deps.compressionTarget ?? limit);
|
|
53619
53680
|
const result = { compressedRanges: 0, savedTokens: 0, payloadEstimate: estimateCoreMessages(messages) + (deps.imageFloor ?? 0) + (deps.wireOverhead ?? 0), fitsWindow: true };
|
|
53620
53681
|
if (limit <= 0) return result;
|
|
53621
53682
|
const budget = Math.max(MIN_CHUNK_TOKENS, Math.floor(limit * CHUNK_FRACTION));
|
|
@@ -53655,12 +53716,13 @@ async function preflightCompress(deps, messages) {
|
|
|
53655
53716
|
}
|
|
53656
53717
|
result.payloadEstimate = estimateCoreMessages(turn.messages) + (deps.imageFloor ?? 0) + (deps.wireOverhead ?? 0);
|
|
53657
53718
|
if (startTokens < 0) startTokens = currentTokens;
|
|
53658
|
-
if (currentTokens <
|
|
53719
|
+
if (currentTokens < target) break;
|
|
53659
53720
|
const ranges = viableRanges(turn.nudge?.compressibleRanges ?? []);
|
|
53660
53721
|
if (ranges.length === 0) {
|
|
53661
53722
|
if (!relaxed && result.payloadEstimate >= limit) {
|
|
53662
53723
|
activeConfig = relaxedConfig(deps.config);
|
|
53663
53724
|
relaxed = true;
|
|
53725
|
+
target = limit;
|
|
53664
53726
|
summaryCalls = 0;
|
|
53665
53727
|
budgetHit = false;
|
|
53666
53728
|
deps.log("warn", "[preflight] no compressible ranges outside the protected recent zone; relaxing soft protection (preserveRecentMessages/Tokens -> 0) and retrying");
|
|
@@ -53672,7 +53734,7 @@ async function preflightCompress(deps, messages) {
|
|
|
53672
53734
|
const ordered = [...ranges].sort((a, b2) => refNum3(a.startRef) - refNum3(b2.startRef));
|
|
53673
53735
|
let appliedThisRound = 0;
|
|
53674
53736
|
for (const range of ordered) {
|
|
53675
|
-
if (currentTokens <
|
|
53737
|
+
if (currentTokens < target) break;
|
|
53676
53738
|
if (deps.signal?.aborted) {
|
|
53677
53739
|
failure = ABORTED_FAILURE;
|
|
53678
53740
|
break;
|
|
@@ -53690,7 +53752,7 @@ async function preflightCompress(deps, messages) {
|
|
|
53690
53752
|
rangesTried += 1;
|
|
53691
53753
|
const spans = splitChunks(messages, startIdx, endIdx, budget, baselineKnown ? 0 : minChars, countText).slice().reverse();
|
|
53692
53754
|
while (spans.length > 0) {
|
|
53693
|
-
if (currentTokens <
|
|
53755
|
+
if (currentTokens < target) break;
|
|
53694
53756
|
if (deps.signal?.aborted) {
|
|
53695
53757
|
failure = ABORTED_FAILURE;
|
|
53696
53758
|
break;
|
|
@@ -59333,6 +59395,867 @@ import path14 from "path";
|
|
|
59333
59395
|
import fs7 from "fs";
|
|
59334
59396
|
import os from "os";
|
|
59335
59397
|
import path13 from "path";
|
|
59398
|
+
|
|
59399
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
59400
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
59401
|
+
const len = text.length;
|
|
59402
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
59403
|
+
function scanHexDigits(count, exact) {
|
|
59404
|
+
let digits = 0;
|
|
59405
|
+
let value2 = 0;
|
|
59406
|
+
while (digits < count || !exact) {
|
|
59407
|
+
let ch = text.charCodeAt(pos);
|
|
59408
|
+
if (ch >= 48 && ch <= 57) {
|
|
59409
|
+
value2 = value2 * 16 + ch - 48;
|
|
59410
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
59411
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
59412
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
59413
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
59414
|
+
} else {
|
|
59415
|
+
break;
|
|
59416
|
+
}
|
|
59417
|
+
pos++;
|
|
59418
|
+
digits++;
|
|
59419
|
+
}
|
|
59420
|
+
if (digits < count) {
|
|
59421
|
+
value2 = -1;
|
|
59422
|
+
}
|
|
59423
|
+
return value2;
|
|
59424
|
+
}
|
|
59425
|
+
function setPosition(newPosition) {
|
|
59426
|
+
pos = newPosition;
|
|
59427
|
+
value = "";
|
|
59428
|
+
tokenOffset = 0;
|
|
59429
|
+
token = 16;
|
|
59430
|
+
scanError = 0;
|
|
59431
|
+
}
|
|
59432
|
+
function scanNumber() {
|
|
59433
|
+
let start = pos;
|
|
59434
|
+
if (text.charCodeAt(pos) === 48) {
|
|
59435
|
+
pos++;
|
|
59436
|
+
} else {
|
|
59437
|
+
pos++;
|
|
59438
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
59439
|
+
pos++;
|
|
59440
|
+
}
|
|
59441
|
+
}
|
|
59442
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
59443
|
+
pos++;
|
|
59444
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
59445
|
+
pos++;
|
|
59446
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
59447
|
+
pos++;
|
|
59448
|
+
}
|
|
59449
|
+
} else {
|
|
59450
|
+
scanError = 3;
|
|
59451
|
+
return text.substring(start, pos);
|
|
59452
|
+
}
|
|
59453
|
+
}
|
|
59454
|
+
let end = pos;
|
|
59455
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
59456
|
+
pos++;
|
|
59457
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
59458
|
+
pos++;
|
|
59459
|
+
}
|
|
59460
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
59461
|
+
pos++;
|
|
59462
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
59463
|
+
pos++;
|
|
59464
|
+
}
|
|
59465
|
+
end = pos;
|
|
59466
|
+
} else {
|
|
59467
|
+
scanError = 3;
|
|
59468
|
+
}
|
|
59469
|
+
}
|
|
59470
|
+
return text.substring(start, end);
|
|
59471
|
+
}
|
|
59472
|
+
function scanString() {
|
|
59473
|
+
let result = "", start = pos;
|
|
59474
|
+
while (true) {
|
|
59475
|
+
if (pos >= len) {
|
|
59476
|
+
result += text.substring(start, pos);
|
|
59477
|
+
scanError = 2;
|
|
59478
|
+
break;
|
|
59479
|
+
}
|
|
59480
|
+
const ch = text.charCodeAt(pos);
|
|
59481
|
+
if (ch === 34) {
|
|
59482
|
+
result += text.substring(start, pos);
|
|
59483
|
+
pos++;
|
|
59484
|
+
break;
|
|
59485
|
+
}
|
|
59486
|
+
if (ch === 92) {
|
|
59487
|
+
result += text.substring(start, pos);
|
|
59488
|
+
pos++;
|
|
59489
|
+
if (pos >= len) {
|
|
59490
|
+
scanError = 2;
|
|
59491
|
+
break;
|
|
59492
|
+
}
|
|
59493
|
+
const ch2 = text.charCodeAt(pos++);
|
|
59494
|
+
switch (ch2) {
|
|
59495
|
+
case 34:
|
|
59496
|
+
result += '"';
|
|
59497
|
+
break;
|
|
59498
|
+
case 92:
|
|
59499
|
+
result += "\\";
|
|
59500
|
+
break;
|
|
59501
|
+
case 47:
|
|
59502
|
+
result += "/";
|
|
59503
|
+
break;
|
|
59504
|
+
case 98:
|
|
59505
|
+
result += "\b";
|
|
59506
|
+
break;
|
|
59507
|
+
case 102:
|
|
59508
|
+
result += "\f";
|
|
59509
|
+
break;
|
|
59510
|
+
case 110:
|
|
59511
|
+
result += "\n";
|
|
59512
|
+
break;
|
|
59513
|
+
case 114:
|
|
59514
|
+
result += "\r";
|
|
59515
|
+
break;
|
|
59516
|
+
case 116:
|
|
59517
|
+
result += " ";
|
|
59518
|
+
break;
|
|
59519
|
+
case 117:
|
|
59520
|
+
const ch3 = scanHexDigits(4, true);
|
|
59521
|
+
if (ch3 >= 0) {
|
|
59522
|
+
result += String.fromCharCode(ch3);
|
|
59523
|
+
} else {
|
|
59524
|
+
scanError = 4;
|
|
59525
|
+
}
|
|
59526
|
+
break;
|
|
59527
|
+
default:
|
|
59528
|
+
scanError = 5;
|
|
59529
|
+
}
|
|
59530
|
+
start = pos;
|
|
59531
|
+
continue;
|
|
59532
|
+
}
|
|
59533
|
+
if (ch >= 0 && ch <= 31) {
|
|
59534
|
+
if (isLineBreak(ch)) {
|
|
59535
|
+
result += text.substring(start, pos);
|
|
59536
|
+
scanError = 2;
|
|
59537
|
+
break;
|
|
59538
|
+
} else {
|
|
59539
|
+
scanError = 6;
|
|
59540
|
+
}
|
|
59541
|
+
}
|
|
59542
|
+
pos++;
|
|
59543
|
+
}
|
|
59544
|
+
return result;
|
|
59545
|
+
}
|
|
59546
|
+
function scanNext() {
|
|
59547
|
+
value = "";
|
|
59548
|
+
scanError = 0;
|
|
59549
|
+
tokenOffset = pos;
|
|
59550
|
+
lineStartOffset = lineNumber;
|
|
59551
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
59552
|
+
if (pos >= len) {
|
|
59553
|
+
tokenOffset = len;
|
|
59554
|
+
return token = 17;
|
|
59555
|
+
}
|
|
59556
|
+
let code = text.charCodeAt(pos);
|
|
59557
|
+
if (isWhiteSpace(code)) {
|
|
59558
|
+
do {
|
|
59559
|
+
pos++;
|
|
59560
|
+
value += String.fromCharCode(code);
|
|
59561
|
+
code = text.charCodeAt(pos);
|
|
59562
|
+
} while (isWhiteSpace(code));
|
|
59563
|
+
return token = 15;
|
|
59564
|
+
}
|
|
59565
|
+
if (isLineBreak(code)) {
|
|
59566
|
+
pos++;
|
|
59567
|
+
value += String.fromCharCode(code);
|
|
59568
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
59569
|
+
pos++;
|
|
59570
|
+
value += "\n";
|
|
59571
|
+
}
|
|
59572
|
+
lineNumber++;
|
|
59573
|
+
tokenLineStartOffset = pos;
|
|
59574
|
+
return token = 14;
|
|
59575
|
+
}
|
|
59576
|
+
switch (code) {
|
|
59577
|
+
// tokens: []{}:,
|
|
59578
|
+
case 123:
|
|
59579
|
+
pos++;
|
|
59580
|
+
return token = 1;
|
|
59581
|
+
case 125:
|
|
59582
|
+
pos++;
|
|
59583
|
+
return token = 2;
|
|
59584
|
+
case 91:
|
|
59585
|
+
pos++;
|
|
59586
|
+
return token = 3;
|
|
59587
|
+
case 93:
|
|
59588
|
+
pos++;
|
|
59589
|
+
return token = 4;
|
|
59590
|
+
case 58:
|
|
59591
|
+
pos++;
|
|
59592
|
+
return token = 6;
|
|
59593
|
+
case 44:
|
|
59594
|
+
pos++;
|
|
59595
|
+
return token = 5;
|
|
59596
|
+
// strings
|
|
59597
|
+
case 34:
|
|
59598
|
+
pos++;
|
|
59599
|
+
value = scanString();
|
|
59600
|
+
return token = 10;
|
|
59601
|
+
// comments
|
|
59602
|
+
case 47:
|
|
59603
|
+
const start = pos - 1;
|
|
59604
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
59605
|
+
pos += 2;
|
|
59606
|
+
while (pos < len) {
|
|
59607
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
59608
|
+
break;
|
|
59609
|
+
}
|
|
59610
|
+
pos++;
|
|
59611
|
+
}
|
|
59612
|
+
value = text.substring(start, pos);
|
|
59613
|
+
return token = 12;
|
|
59614
|
+
}
|
|
59615
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
59616
|
+
pos += 2;
|
|
59617
|
+
const safeLength = len - 1;
|
|
59618
|
+
let commentClosed = false;
|
|
59619
|
+
while (pos < safeLength) {
|
|
59620
|
+
const ch = text.charCodeAt(pos);
|
|
59621
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
59622
|
+
pos += 2;
|
|
59623
|
+
commentClosed = true;
|
|
59624
|
+
break;
|
|
59625
|
+
}
|
|
59626
|
+
pos++;
|
|
59627
|
+
if (isLineBreak(ch)) {
|
|
59628
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
59629
|
+
pos++;
|
|
59630
|
+
}
|
|
59631
|
+
lineNumber++;
|
|
59632
|
+
tokenLineStartOffset = pos;
|
|
59633
|
+
}
|
|
59634
|
+
}
|
|
59635
|
+
if (!commentClosed) {
|
|
59636
|
+
pos++;
|
|
59637
|
+
scanError = 1;
|
|
59638
|
+
}
|
|
59639
|
+
value = text.substring(start, pos);
|
|
59640
|
+
return token = 13;
|
|
59641
|
+
}
|
|
59642
|
+
value += String.fromCharCode(code);
|
|
59643
|
+
pos++;
|
|
59644
|
+
return token = 16;
|
|
59645
|
+
// numbers
|
|
59646
|
+
case 45:
|
|
59647
|
+
value += String.fromCharCode(code);
|
|
59648
|
+
pos++;
|
|
59649
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
59650
|
+
return token = 16;
|
|
59651
|
+
}
|
|
59652
|
+
// found a minus, followed by a number so
|
|
59653
|
+
// we fall through to proceed with scanning
|
|
59654
|
+
// numbers
|
|
59655
|
+
case 48:
|
|
59656
|
+
case 49:
|
|
59657
|
+
case 50:
|
|
59658
|
+
case 51:
|
|
59659
|
+
case 52:
|
|
59660
|
+
case 53:
|
|
59661
|
+
case 54:
|
|
59662
|
+
case 55:
|
|
59663
|
+
case 56:
|
|
59664
|
+
case 57:
|
|
59665
|
+
value += scanNumber();
|
|
59666
|
+
return token = 11;
|
|
59667
|
+
// literals and unknown symbols
|
|
59668
|
+
default:
|
|
59669
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
59670
|
+
pos++;
|
|
59671
|
+
code = text.charCodeAt(pos);
|
|
59672
|
+
}
|
|
59673
|
+
if (tokenOffset !== pos) {
|
|
59674
|
+
value = text.substring(tokenOffset, pos);
|
|
59675
|
+
switch (value) {
|
|
59676
|
+
case "true":
|
|
59677
|
+
return token = 8;
|
|
59678
|
+
case "false":
|
|
59679
|
+
return token = 9;
|
|
59680
|
+
case "null":
|
|
59681
|
+
return token = 7;
|
|
59682
|
+
}
|
|
59683
|
+
return token = 16;
|
|
59684
|
+
}
|
|
59685
|
+
value += String.fromCharCode(code);
|
|
59686
|
+
pos++;
|
|
59687
|
+
return token = 16;
|
|
59688
|
+
}
|
|
59689
|
+
}
|
|
59690
|
+
function isUnknownContentCharacter(code) {
|
|
59691
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
59692
|
+
return false;
|
|
59693
|
+
}
|
|
59694
|
+
switch (code) {
|
|
59695
|
+
case 125:
|
|
59696
|
+
case 93:
|
|
59697
|
+
case 123:
|
|
59698
|
+
case 91:
|
|
59699
|
+
case 34:
|
|
59700
|
+
case 58:
|
|
59701
|
+
case 44:
|
|
59702
|
+
case 47:
|
|
59703
|
+
return false;
|
|
59704
|
+
}
|
|
59705
|
+
return true;
|
|
59706
|
+
}
|
|
59707
|
+
function scanNextNonTrivia() {
|
|
59708
|
+
let result;
|
|
59709
|
+
do {
|
|
59710
|
+
result = scanNext();
|
|
59711
|
+
} while (result >= 12 && result <= 15);
|
|
59712
|
+
return result;
|
|
59713
|
+
}
|
|
59714
|
+
return {
|
|
59715
|
+
setPosition,
|
|
59716
|
+
getPosition: () => pos,
|
|
59717
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
59718
|
+
getToken: () => token,
|
|
59719
|
+
getTokenValue: () => value,
|
|
59720
|
+
getTokenOffset: () => tokenOffset,
|
|
59721
|
+
getTokenLength: () => pos - tokenOffset,
|
|
59722
|
+
getTokenStartLine: () => lineStartOffset,
|
|
59723
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
59724
|
+
getTokenError: () => scanError
|
|
59725
|
+
};
|
|
59726
|
+
}
|
|
59727
|
+
function isWhiteSpace(ch) {
|
|
59728
|
+
return ch === 32 || ch === 9;
|
|
59729
|
+
}
|
|
59730
|
+
function isLineBreak(ch) {
|
|
59731
|
+
return ch === 10 || ch === 13;
|
|
59732
|
+
}
|
|
59733
|
+
function isDigit(ch) {
|
|
59734
|
+
return ch >= 48 && ch <= 57;
|
|
59735
|
+
}
|
|
59736
|
+
var CharacterCodes;
|
|
59737
|
+
(function(CharacterCodes2) {
|
|
59738
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
59739
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
59740
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
59741
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
59742
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
59743
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
59744
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
59745
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
59746
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
59747
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
59748
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
59749
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
59750
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
59751
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
59752
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
59753
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
59754
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
59755
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
59756
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
59757
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
59758
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
59759
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
59760
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
59761
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
59762
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
59763
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
59764
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
59765
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
59766
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
59767
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
59768
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
59769
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
59770
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
59771
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
59772
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
59773
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
59774
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
59775
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
59776
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
59777
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
59778
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
59779
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
59780
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
59781
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
59782
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
59783
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
59784
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
59785
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
59786
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
59787
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
59788
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
59789
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
59790
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
59791
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
59792
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
59793
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
59794
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
59795
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
59796
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
59797
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
59798
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
59799
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
59800
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
59801
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
59802
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
59803
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
59804
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
59805
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
59806
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
59807
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
59808
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
59809
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
59810
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
59811
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
59812
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
59813
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
59814
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
59815
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
59816
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
59817
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
59818
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
59819
|
+
|
|
59820
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
59821
|
+
var cachedSpaces = new Array(20).fill(0).map((_2, index) => {
|
|
59822
|
+
return " ".repeat(index);
|
|
59823
|
+
});
|
|
59824
|
+
var maxCachedValues = 200;
|
|
59825
|
+
var cachedBreakLinesWithSpaces = {
|
|
59826
|
+
" ": {
|
|
59827
|
+
"\n": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59828
|
+
return "\n" + " ".repeat(index);
|
|
59829
|
+
}),
|
|
59830
|
+
"\r": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59831
|
+
return "\r" + " ".repeat(index);
|
|
59832
|
+
}),
|
|
59833
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59834
|
+
return "\r\n" + " ".repeat(index);
|
|
59835
|
+
})
|
|
59836
|
+
},
|
|
59837
|
+
" ": {
|
|
59838
|
+
"\n": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59839
|
+
return "\n" + " ".repeat(index);
|
|
59840
|
+
}),
|
|
59841
|
+
"\r": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59842
|
+
return "\r" + " ".repeat(index);
|
|
59843
|
+
}),
|
|
59844
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_2, index) => {
|
|
59845
|
+
return "\r\n" + " ".repeat(index);
|
|
59846
|
+
})
|
|
59847
|
+
}
|
|
59848
|
+
};
|
|
59849
|
+
|
|
59850
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
59851
|
+
var ParseOptions;
|
|
59852
|
+
(function(ParseOptions2) {
|
|
59853
|
+
ParseOptions2.DEFAULT = {
|
|
59854
|
+
allowTrailingComma: false
|
|
59855
|
+
};
|
|
59856
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
59857
|
+
function parse2(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
59858
|
+
let currentProperty = null;
|
|
59859
|
+
let currentParent = [];
|
|
59860
|
+
const previousParents = [];
|
|
59861
|
+
function onValue(value) {
|
|
59862
|
+
if (Array.isArray(currentParent)) {
|
|
59863
|
+
currentParent.push(value);
|
|
59864
|
+
} else if (currentProperty !== null) {
|
|
59865
|
+
currentParent[currentProperty] = value;
|
|
59866
|
+
}
|
|
59867
|
+
}
|
|
59868
|
+
const visitor = {
|
|
59869
|
+
onObjectBegin: () => {
|
|
59870
|
+
const object = {};
|
|
59871
|
+
onValue(object);
|
|
59872
|
+
previousParents.push(currentParent);
|
|
59873
|
+
currentParent = object;
|
|
59874
|
+
currentProperty = null;
|
|
59875
|
+
},
|
|
59876
|
+
onObjectProperty: (name) => {
|
|
59877
|
+
currentProperty = name;
|
|
59878
|
+
},
|
|
59879
|
+
onObjectEnd: () => {
|
|
59880
|
+
currentParent = previousParents.pop();
|
|
59881
|
+
},
|
|
59882
|
+
onArrayBegin: () => {
|
|
59883
|
+
const array = [];
|
|
59884
|
+
onValue(array);
|
|
59885
|
+
previousParents.push(currentParent);
|
|
59886
|
+
currentParent = array;
|
|
59887
|
+
currentProperty = null;
|
|
59888
|
+
},
|
|
59889
|
+
onArrayEnd: () => {
|
|
59890
|
+
currentParent = previousParents.pop();
|
|
59891
|
+
},
|
|
59892
|
+
onLiteralValue: onValue,
|
|
59893
|
+
onError: (error, offset, length) => {
|
|
59894
|
+
errors.push({ error, offset, length });
|
|
59895
|
+
}
|
|
59896
|
+
};
|
|
59897
|
+
visit(text, visitor, options);
|
|
59898
|
+
return currentParent[0];
|
|
59899
|
+
}
|
|
59900
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
59901
|
+
const _scanner = createScanner(text, false);
|
|
59902
|
+
const _jsonPath = [];
|
|
59903
|
+
let suppressedCallbacks = 0;
|
|
59904
|
+
function toNoArgVisit(visitFunction) {
|
|
59905
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
59906
|
+
}
|
|
59907
|
+
function toOneArgVisit(visitFunction) {
|
|
59908
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
59909
|
+
}
|
|
59910
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
59911
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
59912
|
+
}
|
|
59913
|
+
function toBeginVisit(visitFunction) {
|
|
59914
|
+
return visitFunction ? () => {
|
|
59915
|
+
if (suppressedCallbacks > 0) {
|
|
59916
|
+
suppressedCallbacks++;
|
|
59917
|
+
} else {
|
|
59918
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
59919
|
+
if (cbReturn === false) {
|
|
59920
|
+
suppressedCallbacks = 1;
|
|
59921
|
+
}
|
|
59922
|
+
}
|
|
59923
|
+
} : () => true;
|
|
59924
|
+
}
|
|
59925
|
+
function toEndVisit(visitFunction) {
|
|
59926
|
+
return visitFunction ? () => {
|
|
59927
|
+
if (suppressedCallbacks > 0) {
|
|
59928
|
+
suppressedCallbacks--;
|
|
59929
|
+
}
|
|
59930
|
+
if (suppressedCallbacks === 0) {
|
|
59931
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
59932
|
+
}
|
|
59933
|
+
} : () => true;
|
|
59934
|
+
}
|
|
59935
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
59936
|
+
const disallowComments = options && options.disallowComments;
|
|
59937
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
59938
|
+
function scanNext() {
|
|
59939
|
+
while (true) {
|
|
59940
|
+
const token = _scanner.scan();
|
|
59941
|
+
switch (_scanner.getTokenError()) {
|
|
59942
|
+
case 4:
|
|
59943
|
+
handleError(
|
|
59944
|
+
14
|
|
59945
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
59946
|
+
);
|
|
59947
|
+
break;
|
|
59948
|
+
case 5:
|
|
59949
|
+
handleError(
|
|
59950
|
+
15
|
|
59951
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
59952
|
+
);
|
|
59953
|
+
break;
|
|
59954
|
+
case 3:
|
|
59955
|
+
handleError(
|
|
59956
|
+
13
|
|
59957
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
59958
|
+
);
|
|
59959
|
+
break;
|
|
59960
|
+
case 1:
|
|
59961
|
+
if (!disallowComments) {
|
|
59962
|
+
handleError(
|
|
59963
|
+
11
|
|
59964
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
59965
|
+
);
|
|
59966
|
+
}
|
|
59967
|
+
break;
|
|
59968
|
+
case 2:
|
|
59969
|
+
handleError(
|
|
59970
|
+
12
|
|
59971
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
59972
|
+
);
|
|
59973
|
+
break;
|
|
59974
|
+
case 6:
|
|
59975
|
+
handleError(
|
|
59976
|
+
16
|
|
59977
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
59978
|
+
);
|
|
59979
|
+
break;
|
|
59980
|
+
}
|
|
59981
|
+
switch (token) {
|
|
59982
|
+
case 12:
|
|
59983
|
+
case 13:
|
|
59984
|
+
if (disallowComments) {
|
|
59985
|
+
handleError(
|
|
59986
|
+
10
|
|
59987
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
59988
|
+
);
|
|
59989
|
+
} else {
|
|
59990
|
+
onComment();
|
|
59991
|
+
}
|
|
59992
|
+
break;
|
|
59993
|
+
case 16:
|
|
59994
|
+
handleError(
|
|
59995
|
+
1
|
|
59996
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
59997
|
+
);
|
|
59998
|
+
break;
|
|
59999
|
+
case 15:
|
|
60000
|
+
case 14:
|
|
60001
|
+
break;
|
|
60002
|
+
default:
|
|
60003
|
+
return token;
|
|
60004
|
+
}
|
|
60005
|
+
}
|
|
60006
|
+
}
|
|
60007
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
60008
|
+
onError(error);
|
|
60009
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
60010
|
+
let token = _scanner.getToken();
|
|
60011
|
+
while (token !== 17) {
|
|
60012
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
60013
|
+
scanNext();
|
|
60014
|
+
break;
|
|
60015
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
60016
|
+
break;
|
|
60017
|
+
}
|
|
60018
|
+
token = scanNext();
|
|
60019
|
+
}
|
|
60020
|
+
}
|
|
60021
|
+
}
|
|
60022
|
+
function parseString(isValue) {
|
|
60023
|
+
const value = _scanner.getTokenValue();
|
|
60024
|
+
if (isValue) {
|
|
60025
|
+
onLiteralValue(value);
|
|
60026
|
+
} else {
|
|
60027
|
+
onObjectProperty(value);
|
|
60028
|
+
_jsonPath.push(value);
|
|
60029
|
+
}
|
|
60030
|
+
scanNext();
|
|
60031
|
+
return true;
|
|
60032
|
+
}
|
|
60033
|
+
function parseLiteral() {
|
|
60034
|
+
switch (_scanner.getToken()) {
|
|
60035
|
+
case 11:
|
|
60036
|
+
const tokenValue = _scanner.getTokenValue();
|
|
60037
|
+
let value = Number(tokenValue);
|
|
60038
|
+
if (isNaN(value)) {
|
|
60039
|
+
handleError(
|
|
60040
|
+
2
|
|
60041
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
60042
|
+
);
|
|
60043
|
+
value = 0;
|
|
60044
|
+
}
|
|
60045
|
+
onLiteralValue(value);
|
|
60046
|
+
break;
|
|
60047
|
+
case 7:
|
|
60048
|
+
onLiteralValue(null);
|
|
60049
|
+
break;
|
|
60050
|
+
case 8:
|
|
60051
|
+
onLiteralValue(true);
|
|
60052
|
+
break;
|
|
60053
|
+
case 9:
|
|
60054
|
+
onLiteralValue(false);
|
|
60055
|
+
break;
|
|
60056
|
+
default:
|
|
60057
|
+
return false;
|
|
60058
|
+
}
|
|
60059
|
+
scanNext();
|
|
60060
|
+
return true;
|
|
60061
|
+
}
|
|
60062
|
+
function parseProperty() {
|
|
60063
|
+
if (_scanner.getToken() !== 10) {
|
|
60064
|
+
handleError(3, [], [
|
|
60065
|
+
2,
|
|
60066
|
+
5
|
|
60067
|
+
/* SyntaxKind.CommaToken */
|
|
60068
|
+
]);
|
|
60069
|
+
return false;
|
|
60070
|
+
}
|
|
60071
|
+
parseString(false);
|
|
60072
|
+
if (_scanner.getToken() === 6) {
|
|
60073
|
+
onSeparator(":");
|
|
60074
|
+
scanNext();
|
|
60075
|
+
if (!parseValue()) {
|
|
60076
|
+
handleError(4, [], [
|
|
60077
|
+
2,
|
|
60078
|
+
5
|
|
60079
|
+
/* SyntaxKind.CommaToken */
|
|
60080
|
+
]);
|
|
60081
|
+
}
|
|
60082
|
+
} else {
|
|
60083
|
+
handleError(5, [], [
|
|
60084
|
+
2,
|
|
60085
|
+
5
|
|
60086
|
+
/* SyntaxKind.CommaToken */
|
|
60087
|
+
]);
|
|
60088
|
+
}
|
|
60089
|
+
_jsonPath.pop();
|
|
60090
|
+
return true;
|
|
60091
|
+
}
|
|
60092
|
+
function parseObject() {
|
|
60093
|
+
onObjectBegin();
|
|
60094
|
+
scanNext();
|
|
60095
|
+
let needsComma = false;
|
|
60096
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
60097
|
+
if (_scanner.getToken() === 5) {
|
|
60098
|
+
if (!needsComma) {
|
|
60099
|
+
handleError(4, [], []);
|
|
60100
|
+
}
|
|
60101
|
+
onSeparator(",");
|
|
60102
|
+
scanNext();
|
|
60103
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
60104
|
+
break;
|
|
60105
|
+
}
|
|
60106
|
+
} else if (needsComma) {
|
|
60107
|
+
handleError(6, [], []);
|
|
60108
|
+
}
|
|
60109
|
+
if (!parseProperty()) {
|
|
60110
|
+
handleError(4, [], [
|
|
60111
|
+
2,
|
|
60112
|
+
5
|
|
60113
|
+
/* SyntaxKind.CommaToken */
|
|
60114
|
+
]);
|
|
60115
|
+
}
|
|
60116
|
+
needsComma = true;
|
|
60117
|
+
}
|
|
60118
|
+
onObjectEnd();
|
|
60119
|
+
if (_scanner.getToken() !== 2) {
|
|
60120
|
+
handleError(7, [
|
|
60121
|
+
2
|
|
60122
|
+
/* SyntaxKind.CloseBraceToken */
|
|
60123
|
+
], []);
|
|
60124
|
+
} else {
|
|
60125
|
+
scanNext();
|
|
60126
|
+
}
|
|
60127
|
+
return true;
|
|
60128
|
+
}
|
|
60129
|
+
function parseArray() {
|
|
60130
|
+
onArrayBegin();
|
|
60131
|
+
scanNext();
|
|
60132
|
+
let isFirstElement = true;
|
|
60133
|
+
let needsComma = false;
|
|
60134
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
60135
|
+
if (_scanner.getToken() === 5) {
|
|
60136
|
+
if (!needsComma) {
|
|
60137
|
+
handleError(4, [], []);
|
|
60138
|
+
}
|
|
60139
|
+
onSeparator(",");
|
|
60140
|
+
scanNext();
|
|
60141
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
60142
|
+
break;
|
|
60143
|
+
}
|
|
60144
|
+
} else if (needsComma) {
|
|
60145
|
+
handleError(6, [], []);
|
|
60146
|
+
}
|
|
60147
|
+
if (isFirstElement) {
|
|
60148
|
+
_jsonPath.push(0);
|
|
60149
|
+
isFirstElement = false;
|
|
60150
|
+
} else {
|
|
60151
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
60152
|
+
}
|
|
60153
|
+
if (!parseValue()) {
|
|
60154
|
+
handleError(4, [], [
|
|
60155
|
+
4,
|
|
60156
|
+
5
|
|
60157
|
+
/* SyntaxKind.CommaToken */
|
|
60158
|
+
]);
|
|
60159
|
+
}
|
|
60160
|
+
needsComma = true;
|
|
60161
|
+
}
|
|
60162
|
+
onArrayEnd();
|
|
60163
|
+
if (!isFirstElement) {
|
|
60164
|
+
_jsonPath.pop();
|
|
60165
|
+
}
|
|
60166
|
+
if (_scanner.getToken() !== 4) {
|
|
60167
|
+
handleError(8, [
|
|
60168
|
+
4
|
|
60169
|
+
/* SyntaxKind.CloseBracketToken */
|
|
60170
|
+
], []);
|
|
60171
|
+
} else {
|
|
60172
|
+
scanNext();
|
|
60173
|
+
}
|
|
60174
|
+
return true;
|
|
60175
|
+
}
|
|
60176
|
+
function parseValue() {
|
|
60177
|
+
switch (_scanner.getToken()) {
|
|
60178
|
+
case 3:
|
|
60179
|
+
return parseArray();
|
|
60180
|
+
case 1:
|
|
60181
|
+
return parseObject();
|
|
60182
|
+
case 10:
|
|
60183
|
+
return parseString(true);
|
|
60184
|
+
default:
|
|
60185
|
+
return parseLiteral();
|
|
60186
|
+
}
|
|
60187
|
+
}
|
|
60188
|
+
scanNext();
|
|
60189
|
+
if (_scanner.getToken() === 17) {
|
|
60190
|
+
if (options.allowEmptyContent) {
|
|
60191
|
+
return true;
|
|
60192
|
+
}
|
|
60193
|
+
handleError(4, [], []);
|
|
60194
|
+
return false;
|
|
60195
|
+
}
|
|
60196
|
+
if (!parseValue()) {
|
|
60197
|
+
handleError(4, [], []);
|
|
60198
|
+
return false;
|
|
60199
|
+
}
|
|
60200
|
+
if (_scanner.getToken() !== 17) {
|
|
60201
|
+
handleError(9, [], []);
|
|
60202
|
+
}
|
|
60203
|
+
return true;
|
|
60204
|
+
}
|
|
60205
|
+
|
|
60206
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
60207
|
+
var ScanError;
|
|
60208
|
+
(function(ScanError2) {
|
|
60209
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
60210
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
60211
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
60212
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
60213
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
60214
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
60215
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
60216
|
+
})(ScanError || (ScanError = {}));
|
|
60217
|
+
var SyntaxKind;
|
|
60218
|
+
(function(SyntaxKind2) {
|
|
60219
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
60220
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
60221
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
60222
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
60223
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
60224
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
60225
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
60226
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
60227
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
60228
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
60229
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
60230
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
60231
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
60232
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
60233
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
60234
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
60235
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
60236
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
60237
|
+
var parse3 = parse2;
|
|
60238
|
+
var ParseErrorCode;
|
|
60239
|
+
(function(ParseErrorCode2) {
|
|
60240
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
60241
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
60242
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
60243
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
60244
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
60245
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
60246
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
60247
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
60248
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
60249
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
60250
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
60251
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
60252
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
60253
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
60254
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
60255
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
60256
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
60257
|
+
|
|
60258
|
+
// src/client-config.ts
|
|
59336
60259
|
function toModelWindow(id, contextWindow) {
|
|
59337
60260
|
return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
|
|
59338
60261
|
}
|
|
@@ -59900,26 +60823,49 @@ function readHermesConfig(hermesHome) {
|
|
|
59900
60823
|
}
|
|
59901
60824
|
return parseHermesYaml(text);
|
|
59902
60825
|
}
|
|
59903
|
-
function
|
|
59904
|
-
|
|
59905
|
-
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path13.join(os.homedir(), ".config");
|
|
59906
|
-
return path13.join(xdg2, "opencode", "opencode.json");
|
|
59907
|
-
}
|
|
59908
|
-
function readOpencodeConfig(file) {
|
|
59909
|
-
let text;
|
|
60826
|
+
function parseConfigText(text) {
|
|
60827
|
+
let parsed;
|
|
59910
60828
|
try {
|
|
59911
|
-
|
|
60829
|
+
parsed = JSON.parse(text);
|
|
59912
60830
|
} catch {
|
|
59913
|
-
|
|
60831
|
+
const errors = [];
|
|
60832
|
+
parsed = parse3(text, errors, { allowTrailingComma: true });
|
|
59914
60833
|
}
|
|
59915
|
-
|
|
60834
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
60835
|
+
return void 0;
|
|
60836
|
+
}
|
|
60837
|
+
function readConfigFileRoot(file) {
|
|
59916
60838
|
try {
|
|
59917
|
-
|
|
60839
|
+
return parseConfigText(fs7.readFileSync(file, "utf8"));
|
|
59918
60840
|
} catch {
|
|
59919
|
-
return
|
|
60841
|
+
return void 0;
|
|
59920
60842
|
}
|
|
60843
|
+
}
|
|
60844
|
+
function mergeConfigDeep(target, source) {
|
|
60845
|
+
const out = { ...target };
|
|
60846
|
+
for (const [key, value] of Object.entries(source)) {
|
|
60847
|
+
const existing = out[key];
|
|
60848
|
+
out[key] = value !== null && typeof value === "object" && !Array.isArray(value) && existing !== null && typeof existing === "object" && !Array.isArray(existing) ? mergeConfigDeep(existing, value) : value;
|
|
60849
|
+
}
|
|
60850
|
+
return out;
|
|
60851
|
+
}
|
|
60852
|
+
function readOpencodeConfigRoot(env) {
|
|
60853
|
+
let root;
|
|
60854
|
+
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path13.join(os.homedir(), ".config");
|
|
60855
|
+
const dir = path13.join(xdg2, "opencode");
|
|
60856
|
+
for (const file of ["config.json", "opencode.json", "opencode.jsonc"]) {
|
|
60857
|
+
const next = readConfigFileRoot(path13.join(dir, file));
|
|
60858
|
+
if (next !== void 0) root = root === void 0 ? next : mergeConfigDeep(root, next);
|
|
60859
|
+
}
|
|
60860
|
+
if (nonEmpty2(env.OPENCODE_CONFIG)) {
|
|
60861
|
+
const next = readConfigFileRoot(env.OPENCODE_CONFIG);
|
|
60862
|
+
if (next !== void 0) root = root === void 0 ? next : mergeConfigDeep(root, next);
|
|
60863
|
+
}
|
|
60864
|
+
return root;
|
|
60865
|
+
}
|
|
60866
|
+
function parseOpencodeProviders(parsed) {
|
|
59921
60867
|
const providers = {};
|
|
59922
|
-
if (parsed
|
|
60868
|
+
if (parsed !== void 0) {
|
|
59923
60869
|
const root = parsed;
|
|
59924
60870
|
const provRoot = root.provider;
|
|
59925
60871
|
if (provRoot && typeof provRoot === "object" && !Array.isArray(provRoot)) {
|
|
@@ -59990,7 +60936,7 @@ function loadClientConfig(env, cwd) {
|
|
|
59990
60936
|
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path13.join(home, ".zcode");
|
|
59991
60937
|
config.zcode = readZcodeConfig(zcodeHome);
|
|
59992
60938
|
config.omp = readOmpConfig(resolveOmpHome(env));
|
|
59993
|
-
config.opencode =
|
|
60939
|
+
config.opencode = parseOpencodeProviders(readOpencodeConfigRoot(env));
|
|
59994
60940
|
config.hermes = readHermesConfig(resolveHermesHome(env));
|
|
59995
60941
|
config.dsh = readDshConfig(resolveDshHome(env));
|
|
59996
60942
|
config.codebuddy = readCodebuddyConfig(resolveCodebuddyHome(env), cwd, env);
|
|
@@ -62931,6 +63877,7 @@ function beginPreflightHold(res, prepared, log2) {
|
|
|
62931
63877
|
async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, core, config, model, route, affinity, anonymous, log2, instanceId) {
|
|
62932
63878
|
const session = prepared.session;
|
|
62933
63879
|
const limit = config.modelContextLimit;
|
|
63880
|
+
const compressionTarget = prepared.protocol === "responses" && isCodexClient(req.headers) && codexCompactMode() === "intercept" ? limit * CODEX_COMPACT_HEALTH_RATIO : limit;
|
|
62934
63881
|
const preflightReqUrl = req.url ?? "";
|
|
62935
63882
|
const billingUpstream = route?.rewrittenUrl ?? (/^https?:\/\//i.test(preflightReqUrl) ? preflightReqUrl : opts.upstream);
|
|
62936
63883
|
const imageTokens = imageTokensInRawBody(prepared.protocol, prepared.body, imageBillingFor(opts, billingUpstream));
|
|
@@ -62939,10 +63886,11 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
62939
63886
|
const payloadEstimate = textEstimate + overheadEstimate + imageTokens;
|
|
62940
63887
|
const unknownBaseline = anonymous && session.stats.lastInputTokens <= 0;
|
|
62941
63888
|
const tokenCount = unknownBaseline ? estimateCoreMessagesUpper(prepared.processedMessages) + overheadEstimate + imageTokens : Math.max(session.stats.lastInputTokens, payloadEstimate);
|
|
62942
|
-
if (limit <= 0 || !model || tokenCount <
|
|
63889
|
+
if (limit <= 0 || !model || tokenCount < compressionTarget) return prepared;
|
|
63890
|
+
const payloadFitsWindow = (unknownBaseline ? tokenCount : payloadEstimate) < limit;
|
|
62943
63891
|
const learnedLimit = resolveLearnedLimit(session, model);
|
|
62944
63892
|
const noOverflowEvidence = session.stats.lastInputTokens < limit && learnedLimit === void 0;
|
|
62945
|
-
if (imageTokens > 0 && textEstimate < limit && noOverflowEvidence) {
|
|
63893
|
+
if (imageTokens > 0 && payloadEstimate >= limit && textEstimate < limit && noOverflowEvidence) {
|
|
62946
63894
|
log2("warn", `[${session.id}] image-dominated payload (~${textEstimate} text + ~${imageTokens} image tokens) exceeds window ${limit} by estimate only, no upstream overflow evidence \u2014 forwarding once so the upstream arbitrates billing (#496)`);
|
|
62947
63895
|
return prepared;
|
|
62948
63896
|
}
|
|
@@ -62953,8 +63901,8 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
62953
63901
|
return { failFast: true, status: status2, message, retryable, respond: !res.writableEnded };
|
|
62954
63902
|
};
|
|
62955
63903
|
if ((prepared.nudge?.compressibleRanges ?? []).length === 0) {
|
|
62956
|
-
if (
|
|
62957
|
-
log2("warn", `[${session.id}] preflight
|
|
63904
|
+
if (payloadFitsWindow) {
|
|
63905
|
+
log2("warn", `[${session.id}] preflight target reached (~${tokenCount}) but the payload fits with no compressible ranges (~${payloadEstimate}/${limit}); forwarding as-is`);
|
|
62958
63906
|
return prepared;
|
|
62959
63907
|
}
|
|
62960
63908
|
if (unknownBaseline) {
|
|
@@ -62965,11 +63913,12 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
62965
63913
|
if (deadEnd && typeof deadEnd === "object") {
|
|
62966
63914
|
const de2 = deadEnd;
|
|
62967
63915
|
if (typeof de2.key === "string" && de2.key === `${model}\0${limit}` && typeof de2.until === "number" && de2.until > Date.now() && typeof de2.message === "string") {
|
|
63916
|
+
if (payloadFitsWindow) return prepared;
|
|
62968
63917
|
log2("warn", `[${session.id}] preflight dead-end cooldown active (${Math.ceil((de2.until - Date.now()) / 1e3)}s left); failing fast without upstream calls (#726)`);
|
|
62969
63918
|
return { failFast: true, status: typeof de2.status === "number" ? de2.status : 502, message: de2.message, retryable: de2.retryable === true, respond: !res.writableEnded };
|
|
62970
63919
|
}
|
|
62971
63920
|
}
|
|
62972
|
-
log2("warn", `[${session.id}] context ${tokenCount} tokens
|
|
63921
|
+
log2("warn", `[${session.id}] context ${tokenCount} tokens reached preflight target ${compressionTarget} (model window ${limit}, model=${model}); preflight compressing before forward`);
|
|
62973
63922
|
const { upstreamUrl, headers, proxyUrl } = buildForwardTarget(req, opts, route, affinity, instanceId);
|
|
62974
63923
|
const clientAbort = new AbortController();
|
|
62975
63924
|
res.on("close", () => {
|
|
@@ -62988,6 +63937,7 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
62988
63937
|
core,
|
|
62989
63938
|
session,
|
|
62990
63939
|
config,
|
|
63940
|
+
compressionTarget,
|
|
62991
63941
|
prompts: prepared.prompts ?? defaultPrompts,
|
|
62992
63942
|
surface: prepared.surface,
|
|
62993
63943
|
protocol: prepared.protocol,
|
|
@@ -68754,17 +69704,9 @@ function opencodeMajorVersion(command) {
|
|
|
68754
69704
|
ocMajorCache.set(command, major);
|
|
68755
69705
|
return major;
|
|
68756
69706
|
}
|
|
68757
|
-
function prepareOpencodeHttpRewrite(
|
|
69707
|
+
function prepareOpencodeHttpRewrite(userRoot, origin, httpRewrites, httpsRewrites, pluginPath, pluginDirMode) {
|
|
68758
69708
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0 && !pluginPath) return void 0;
|
|
68759
|
-
|
|
68760
|
-
try {
|
|
68761
|
-
const txt = fs13.readFileSync(configFile2, "utf8");
|
|
68762
|
-
const parsed = JSON.parse(txt);
|
|
68763
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
68764
|
-
root = { ...parsed };
|
|
68765
|
-
}
|
|
68766
|
-
} catch {
|
|
68767
|
-
}
|
|
69709
|
+
const root = structuredClone(userRoot ?? {});
|
|
68768
69710
|
const provRoot = root.provider;
|
|
68769
69711
|
if (provRoot && typeof provRoot === "object" && !Array.isArray(provRoot)) {
|
|
68770
69712
|
const providers = provRoot;
|
|
@@ -69225,7 +70167,7 @@ async function runLaunch(params, deps = {}) {
|
|
|
69225
70167
|
const opencodePlugin = selfDistFile("agent/opencode.js");
|
|
69226
70168
|
const opencodePluginPath = opencodePlugin && fs13.existsSync(opencodePlugin) ? opencodePlugin : void 0;
|
|
69227
70169
|
const ocDirMode = opencodePluginPath !== void 0 && opencodeMajorVersion(resolveClientCommand("opencode", process.env).command) >= 2;
|
|
69228
|
-
opencodeTmpFile = prepareOpencodeHttpRewrite(
|
|
70170
|
+
opencodeTmpFile = prepareOpencodeHttpRewrite(readOpencodeConfigRoot(process.env), origin, routes.httpRewrites, routes.httpsRewrites, opencodePluginPath, ocDirMode);
|
|
69229
70171
|
if (opencodeTmpFile) env.OPENCODE_CONFIG = opencodeTmpFile;
|
|
69230
70172
|
} else if (base === "hermes") {
|
|
69231
70173
|
env = stripInheritedProxy(process.env);
|