billion-context 0.1.66 → 0.1.67-pr.379.234
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 +197 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48880,21 +48880,6 @@ function coreToOpenai(messages) {
|
|
|
48880
48880
|
flush();
|
|
48881
48881
|
return out;
|
|
48882
48882
|
}
|
|
48883
|
-
function injectOpenaiSystem(messages, parts) {
|
|
48884
|
-
if (parts.length === 0) return messages;
|
|
48885
|
-
const extra = parts.join("\n\n");
|
|
48886
|
-
if (messages.length > 0 && (messages[0]?.role === "system" || messages[0]?.role === "developer")) {
|
|
48887
|
-
const head = messages[0];
|
|
48888
|
-
const base = stringContent(head.content);
|
|
48889
|
-
const merged = base ? `${base}
|
|
48890
|
-
|
|
48891
|
-
---
|
|
48892
|
-
|
|
48893
|
-
${extra}` : extra;
|
|
48894
|
-
return [{ ...head, content: merged }, ...messages.slice(1)];
|
|
48895
|
-
}
|
|
48896
|
-
return [{ role: "system", content: extra }, ...messages];
|
|
48897
|
-
}
|
|
48898
48883
|
function conversationSignalOpenai(body, headerValue3) {
|
|
48899
48884
|
if (headerValue3 && headerValue3.trim()) return headerValue3.trim();
|
|
48900
48885
|
const firstUser = body.messages.find((m2) => m2.role === "user");
|
|
@@ -51591,25 +51576,17 @@ function reserveOutputHeadroom(window2, maxOutput) {
|
|
|
51591
51576
|
}
|
|
51592
51577
|
return window2;
|
|
51593
51578
|
}
|
|
51594
|
-
function
|
|
51595
|
-
|
|
51596
|
-
while (lead < messages.length && (messages[lead].role === "system" || messages[lead].role === "developer")) lead++;
|
|
51597
|
-
if (lead === messages.length) return messages;
|
|
51598
|
-
let midCount = 0;
|
|
51599
|
-
for (let i = lead; i < messages.length; i++) {
|
|
51600
|
-
const r = messages[i].role;
|
|
51601
|
-
if (r === "system" || r === "developer") midCount++;
|
|
51602
|
-
}
|
|
51603
|
-
if (midCount === 0) return messages;
|
|
51604
|
-
const head = messages.slice(0, lead);
|
|
51605
|
-
const mid = [];
|
|
51579
|
+
function mergeSystemMessages(messages, sysParts) {
|
|
51580
|
+
const sys = [];
|
|
51606
51581
|
const rest = [];
|
|
51607
|
-
for (
|
|
51608
|
-
|
|
51609
|
-
|
|
51610
|
-
else rest.push(messages[i]);
|
|
51582
|
+
for (const m2 of messages) {
|
|
51583
|
+
if (m2.role === "system" || m2.role === "developer") sys.push(m2);
|
|
51584
|
+
else rest.push(m2);
|
|
51611
51585
|
}
|
|
51612
|
-
|
|
51586
|
+
const sysContents = sys.map((m2) => typeof m2.content === "string" ? m2.content : m2.content == null ? "" : JSON.stringify(m2.content));
|
|
51587
|
+
const parts = [...sysParts, ...sysContents].filter((s3) => s3.length > 0);
|
|
51588
|
+
if (parts.length === 0) return messages;
|
|
51589
|
+
return [{ role: "system", content: parts.join("\n\n---\n\n") }, ...rest];
|
|
51613
51590
|
}
|
|
51614
51591
|
function shouldReserveOutputHeadroom(protocol) {
|
|
51615
51592
|
return protocol !== "anthropic";
|
|
@@ -52272,8 +52249,8 @@ function createOpenaiAdapter(requestBody, clientSystem) {
|
|
|
52272
52249
|
);
|
|
52273
52250
|
return {
|
|
52274
52251
|
buildRequest(coreMessages, systemPrompt, body) {
|
|
52275
|
-
const messages =
|
|
52276
|
-
const withSys =
|
|
52252
|
+
const messages = coreToOpenai(coreMessages);
|
|
52253
|
+
const withSys = mergeSystemMessages(messages, [clientSystem, systemPrompt].filter((p2) => typeof p2 === "string" && p2.length > 0));
|
|
52277
52254
|
return { ...body, messages: withSys };
|
|
52278
52255
|
},
|
|
52279
52256
|
async *parseStream(upstream, _round) {
|
|
@@ -56338,11 +56315,11 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
56338
56315
|
log2("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model));
|
|
56339
56316
|
processedMessages = stripKernelSummaries(turn.messages, turn.state);
|
|
56340
56317
|
reapOrphanBlocks(session, msgs, deactivateBlock);
|
|
56341
|
-
rebuiltMessages =
|
|
56318
|
+
rebuiltMessages = coreToOpenai(processedMessages);
|
|
56342
56319
|
const sysParts = [];
|
|
56343
56320
|
if (systemText) sysParts.push(systemText);
|
|
56344
56321
|
if (shouldInject) sysParts.push(buildCompressSystemPrompt(prompts));
|
|
56345
|
-
rebuiltMessages =
|
|
56322
|
+
rebuiltMessages = mergeSystemMessages(rebuiltMessages, sysParts);
|
|
56346
56323
|
if (injectTools) {
|
|
56347
56324
|
toolsOut = injectOpenaiTool(parsed.tools);
|
|
56348
56325
|
}
|
|
@@ -61421,6 +61398,120 @@ function livePidHoldsOverlay(overlay) {
|
|
|
61421
61398
|
}
|
|
61422
61399
|
return pid;
|
|
61423
61400
|
}
|
|
61401
|
+
function linkOverlayEntry(realHome, overlay, entry) {
|
|
61402
|
+
const target = path13.join(realHome, entry);
|
|
61403
|
+
const link = path13.join(overlay, entry);
|
|
61404
|
+
try {
|
|
61405
|
+
fs10.symlinkSync(target, link);
|
|
61406
|
+
return true;
|
|
61407
|
+
} catch (err2) {
|
|
61408
|
+
const code = err2.code;
|
|
61409
|
+
if (code !== "EPERM" && code !== "EACCES" && code !== "EINVAL") return false;
|
|
61410
|
+
}
|
|
61411
|
+
let st2;
|
|
61412
|
+
try {
|
|
61413
|
+
st2 = fs10.lstatSync(target);
|
|
61414
|
+
} catch {
|
|
61415
|
+
return false;
|
|
61416
|
+
}
|
|
61417
|
+
if (st2.isDirectory()) {
|
|
61418
|
+
try {
|
|
61419
|
+
fs10.symlinkSync(target, link, "junction");
|
|
61420
|
+
return true;
|
|
61421
|
+
} catch {
|
|
61422
|
+
return false;
|
|
61423
|
+
}
|
|
61424
|
+
}
|
|
61425
|
+
try {
|
|
61426
|
+
fs10.linkSync(target, link);
|
|
61427
|
+
return true;
|
|
61428
|
+
} catch {
|
|
61429
|
+
try {
|
|
61430
|
+
fs10.copyFileSync(target, link);
|
|
61431
|
+
return true;
|
|
61432
|
+
} catch {
|
|
61433
|
+
return false;
|
|
61434
|
+
}
|
|
61435
|
+
}
|
|
61436
|
+
}
|
|
61437
|
+
function isWriteThroughHardlink(overlayPath, realPath, st2) {
|
|
61438
|
+
if (st2.isDirectory() || st2.isSymbolicLink() || st2.nlink <= 1) return false;
|
|
61439
|
+
try {
|
|
61440
|
+
const realSt = fs10.lstatSync(realPath);
|
|
61441
|
+
return st2.dev === realSt.dev && st2.ino === realSt.ino;
|
|
61442
|
+
} catch {
|
|
61443
|
+
return false;
|
|
61444
|
+
}
|
|
61445
|
+
}
|
|
61446
|
+
function sqliteSetMembers(base) {
|
|
61447
|
+
return [base, `${base}-wal`, `${base}-shm`];
|
|
61448
|
+
}
|
|
61449
|
+
function mergeSqliteSet(overlay, realHome, base) {
|
|
61450
|
+
const members = sqliteSetMembers(base).filter((m2) => {
|
|
61451
|
+
try {
|
|
61452
|
+
return fs10.lstatSync(path13.join(overlay, m2)).isFile();
|
|
61453
|
+
} catch {
|
|
61454
|
+
return false;
|
|
61455
|
+
}
|
|
61456
|
+
});
|
|
61457
|
+
if (members.length === 0) return true;
|
|
61458
|
+
const undo = [];
|
|
61459
|
+
const rollback = () => {
|
|
61460
|
+
for (const step of undo.reverse()) {
|
|
61461
|
+
try {
|
|
61462
|
+
step();
|
|
61463
|
+
} catch {
|
|
61464
|
+
}
|
|
61465
|
+
}
|
|
61466
|
+
undo.length = 0;
|
|
61467
|
+
};
|
|
61468
|
+
try {
|
|
61469
|
+
for (const m2 of members) {
|
|
61470
|
+
const src = path13.join(overlay, m2);
|
|
61471
|
+
const dst = path13.join(realHome, m2);
|
|
61472
|
+
let dstStat;
|
|
61473
|
+
try {
|
|
61474
|
+
dstStat = fs10.lstatSync(dst);
|
|
61475
|
+
} catch {
|
|
61476
|
+
}
|
|
61477
|
+
if (dstStat && dstStat.isDirectory()) {
|
|
61478
|
+
rollback();
|
|
61479
|
+
return false;
|
|
61480
|
+
}
|
|
61481
|
+
const srcStat = fs10.lstatSync(src);
|
|
61482
|
+
if (dstStat && dstStat.mtimeMs >= srcStat.mtimeMs) {
|
|
61483
|
+
try {
|
|
61484
|
+
fs10.renameSync(src, `${dst}.bili-conflict`);
|
|
61485
|
+
} catch {
|
|
61486
|
+
rollback();
|
|
61487
|
+
return false;
|
|
61488
|
+
}
|
|
61489
|
+
undo.push(() => fs10.renameSync(`${dst}.bili-conflict`, src));
|
|
61490
|
+
continue;
|
|
61491
|
+
}
|
|
61492
|
+
if (dstStat) {
|
|
61493
|
+
try {
|
|
61494
|
+
fs10.renameSync(dst, `${dst}.bili-conflict`);
|
|
61495
|
+
} catch {
|
|
61496
|
+
rollback();
|
|
61497
|
+
return false;
|
|
61498
|
+
}
|
|
61499
|
+
undo.push(() => fs10.renameSync(`${dst}.bili-conflict`, dst));
|
|
61500
|
+
}
|
|
61501
|
+
try {
|
|
61502
|
+
fs10.renameSync(src, dst);
|
|
61503
|
+
} catch {
|
|
61504
|
+
rollback();
|
|
61505
|
+
return false;
|
|
61506
|
+
}
|
|
61507
|
+
undo.push(() => fs10.renameSync(dst, src));
|
|
61508
|
+
}
|
|
61509
|
+
return true;
|
|
61510
|
+
} catch {
|
|
61511
|
+
rollback();
|
|
61512
|
+
return false;
|
|
61513
|
+
}
|
|
61514
|
+
}
|
|
61424
61515
|
function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
61425
61516
|
try {
|
|
61426
61517
|
fs10.mkdirSync(overlay, { recursive: true });
|
|
@@ -61444,7 +61535,32 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
61444
61535
|
} catch {
|
|
61445
61536
|
}
|
|
61446
61537
|
try {
|
|
61447
|
-
|
|
61538
|
+
let overlayEntries;
|
|
61539
|
+
try {
|
|
61540
|
+
overlayEntries = fs10.readdirSync(overlay);
|
|
61541
|
+
} catch {
|
|
61542
|
+
overlayEntries = [];
|
|
61543
|
+
}
|
|
61544
|
+
const dbSets = [];
|
|
61545
|
+
for (const entry of overlayEntries) {
|
|
61546
|
+
if (!entry.endsWith(".db") || entry === generatedFile) continue;
|
|
61547
|
+
const members = sqliteSetMembers(entry);
|
|
61548
|
+
if (!members.some((m2) => m2 !== entry && overlayEntries.includes(m2))) continue;
|
|
61549
|
+
let mainSt;
|
|
61550
|
+
try {
|
|
61551
|
+
mainSt = fs10.lstatSync(path13.join(overlay, entry));
|
|
61552
|
+
} catch {
|
|
61553
|
+
}
|
|
61554
|
+
const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(path13.join(overlay, entry), path13.join(realHome, entry), mainSt);
|
|
61555
|
+
dbSets.push({ base: entry, keepSidecars });
|
|
61556
|
+
}
|
|
61557
|
+
const skipEntries = /* @__PURE__ */ new Set();
|
|
61558
|
+
for (const { base, keepSidecars } of dbSets) {
|
|
61559
|
+
for (const m2 of sqliteSetMembers(base)) {
|
|
61560
|
+
if (keepSidecars ? m2 !== base : true) skipEntries.add(m2);
|
|
61561
|
+
}
|
|
61562
|
+
}
|
|
61563
|
+
for (const entry of overlayEntries) {
|
|
61448
61564
|
if (entry === generatedFile) continue;
|
|
61449
61565
|
const overlayPath = path13.join(overlay, entry);
|
|
61450
61566
|
if (entry.startsWith(`.${generatedFile}.`) && entry.endsWith(".tmp")) {
|
|
@@ -61454,6 +61570,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
61454
61570
|
}
|
|
61455
61571
|
continue;
|
|
61456
61572
|
}
|
|
61573
|
+
if (skipEntries.has(entry)) continue;
|
|
61457
61574
|
let st2;
|
|
61458
61575
|
try {
|
|
61459
61576
|
st2 = fs10.lstatSync(overlayPath);
|
|
@@ -61474,7 +61591,13 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
61474
61591
|
}
|
|
61475
61592
|
}
|
|
61476
61593
|
} else if (realEntries.has(entry)) {
|
|
61477
|
-
|
|
61594
|
+
const realPath = path13.join(realHome, entry);
|
|
61595
|
+
if (isWriteThroughHardlink(overlayPath, realPath, st2)) {
|
|
61596
|
+
try {
|
|
61597
|
+
fs10.unlinkSync(overlayPath);
|
|
61598
|
+
} catch {
|
|
61599
|
+
}
|
|
61600
|
+
} else if (mergeOverlayEntry(overlayPath, realPath)) {
|
|
61478
61601
|
try {
|
|
61479
61602
|
fs10.rmSync(overlayPath, { recursive: true, force: true });
|
|
61480
61603
|
} catch {
|
|
@@ -61484,12 +61607,47 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
61484
61607
|
}
|
|
61485
61608
|
}
|
|
61486
61609
|
}
|
|
61610
|
+
for (const { base, keepSidecars } of dbSets) {
|
|
61611
|
+
if (keepSidecars) continue;
|
|
61612
|
+
if (!mergeSqliteSet(overlay, realHome, base)) {
|
|
61613
|
+
console.error(
|
|
61614
|
+
`bili: could not merge the SQLite set ${base} / ${base}-wal / ${base}-shm into ${realHome} (the real db is likely open/locked) \u2014 kept in the overlay, retry on the next launch.`
|
|
61615
|
+
);
|
|
61616
|
+
}
|
|
61617
|
+
}
|
|
61618
|
+
let accessible = 0;
|
|
61619
|
+
let total = 0;
|
|
61620
|
+
const linkFailures = [];
|
|
61487
61621
|
for (const entry of realEntries) {
|
|
61488
61622
|
if (entry === generatedFile) continue;
|
|
61623
|
+
total += 1;
|
|
61624
|
+
const overlayPath = path13.join(overlay, entry);
|
|
61625
|
+
let present = false;
|
|
61489
61626
|
try {
|
|
61490
|
-
fs10.
|
|
61627
|
+
fs10.lstatSync(overlayPath);
|
|
61628
|
+
present = true;
|
|
61491
61629
|
} catch {
|
|
61492
61630
|
}
|
|
61631
|
+
if (present) {
|
|
61632
|
+
accessible += 1;
|
|
61633
|
+
continue;
|
|
61634
|
+
}
|
|
61635
|
+
if (linkOverlayEntry(realHome, overlay, entry)) {
|
|
61636
|
+
accessible += 1;
|
|
61637
|
+
} else {
|
|
61638
|
+
linkFailures.push(entry);
|
|
61639
|
+
}
|
|
61640
|
+
}
|
|
61641
|
+
if (total > 0 && accessible === 0) {
|
|
61642
|
+
console.error(
|
|
61643
|
+
`bili: overlay ${overlay} is HOLLOW \u2014 none of ${total} real-home entries is reachable (on Windows, symlink creation is denied without Developer Mode and the junction/hardlink/copy fallbacks also failed). The client will start from its real home without the bili config rewrite.`
|
|
61644
|
+
);
|
|
61645
|
+
return false;
|
|
61646
|
+
}
|
|
61647
|
+
if (linkFailures.length > 0) {
|
|
61648
|
+
console.error(
|
|
61649
|
+
`bili: overlay ${overlay} \u2014 could not link ${linkFailures.length} entr${linkFailures.length === 1 ? "y" : "ies"}: ${linkFailures.join(", ")}. The client may miss those (on Windows, enable Developer Mode for full symlink support).`
|
|
61650
|
+
);
|
|
61493
61651
|
}
|
|
61494
61652
|
} catch {
|
|
61495
61653
|
}
|