billion-context 0.1.93-pr.631.452 → 0.1.93
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 +77 -146
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -46740,74 +46740,6 @@ function renderCompressedDrilldown(blocks, state, sort, limit, countTokens) {
|
|
|
46740
46740
|
}
|
|
46741
46741
|
return lines.join("\n");
|
|
46742
46742
|
}
|
|
46743
|
-
function renderMessage2(m2) {
|
|
46744
|
-
const parts = [];
|
|
46745
|
-
switch (m2.contentType) {
|
|
46746
|
-
case "text":
|
|
46747
|
-
parts.push(m2.text ?? "");
|
|
46748
|
-
break;
|
|
46749
|
-
case "tool-call":
|
|
46750
|
-
parts.push(`\`${m2.toolName ?? "?"}(${m2.toolCallId ?? ""})\` args: ${m2.text ?? ""}`);
|
|
46751
|
-
break;
|
|
46752
|
-
case "tool-result":
|
|
46753
|
-
parts.push(`\`${m2.toolName ?? "?"}(${m2.toolCallId ?? ""})\` \u2192 ${m2.text ?? ""}`);
|
|
46754
|
-
break;
|
|
46755
|
-
case "reasoning":
|
|
46756
|
-
parts.push(`_reasoning_: ${m2.text ?? ""}`);
|
|
46757
|
-
break;
|
|
46758
|
-
}
|
|
46759
|
-
const body = parts.join("\n").trim();
|
|
46760
|
-
return body === "" ? "_(empty)_" : body + "\n";
|
|
46761
|
-
}
|
|
46762
|
-
function renderHandoff(input) {
|
|
46763
|
-
const { coreMessages, state, full, meta } = input;
|
|
46764
|
-
const lines = [];
|
|
46765
|
-
lines.push("# billion-context session handoff");
|
|
46766
|
-
lines.push("");
|
|
46767
|
-
lines.push(`- title: ${meta.title ?? "(untitled)"}`);
|
|
46768
|
-
if (meta.label) lines.push(`- label: ${meta.label}`);
|
|
46769
|
-
lines.push(`- session id: ${meta.sessionId}`);
|
|
46770
|
-
for (const bullet of meta.extraBullets ?? []) lines.push(bullet);
|
|
46771
|
-
if (meta.contextTokens) lines.push(`- last context tokens: ~${meta.contextTokens}`);
|
|
46772
|
-
lines.push(`- compression blocks: ${state.blocks.length} (active ${state.blocks.filter((b2) => b2.active).length})`);
|
|
46773
|
-
lines.push("");
|
|
46774
|
-
const folded = input.folded === true;
|
|
46775
|
-
const view = full || folded ? coreMessages : prune(coreMessages, state);
|
|
46776
|
-
lines.push(full && !folded ? `## Full conversation (${coreMessages.length} messages)` : folded ? `## Conversation (persisted folded snapshot, ${coreMessages.length} messages)` : `## Conversation (folded view as the model saw it, ${coreMessages.length} client messages)`);
|
|
46777
|
-
lines.push("");
|
|
46778
|
-
if (view.length === 0) {
|
|
46779
|
-
lines.push("No conversation messages to export.");
|
|
46780
|
-
lines.push("");
|
|
46781
|
-
}
|
|
46782
|
-
let lastRole = "";
|
|
46783
|
-
for (const m2 of view) {
|
|
46784
|
-
if (m2.role !== lastRole) {
|
|
46785
|
-
lines.push(`### ${m2.role}`);
|
|
46786
|
-
lines.push("");
|
|
46787
|
-
lastRole = m2.role;
|
|
46788
|
-
}
|
|
46789
|
-
lines.push(renderMessage2(m2));
|
|
46790
|
-
}
|
|
46791
|
-
lines.push("");
|
|
46792
|
-
if (full && folded) {
|
|
46793
|
-
for (const b2 of input.blocksFull ?? []) {
|
|
46794
|
-
lines.push(`## Block ${b2.blockId}${b2.topic ? ` \u2014 ${b2.topic}` : ""}`);
|
|
46795
|
-
lines.push("");
|
|
46796
|
-
lines.push(`### Original messages (${b2.count})`);
|
|
46797
|
-
lines.push("");
|
|
46798
|
-
lines.push(b2.fullText.trim());
|
|
46799
|
-
lines.push("");
|
|
46800
|
-
}
|
|
46801
|
-
}
|
|
46802
|
-
return lines.join("\n");
|
|
46803
|
-
}
|
|
46804
|
-
function matchSession(sessions2, selector, labelOf) {
|
|
46805
|
-
const exact = sessions2.filter((s3) => s3.id === selector);
|
|
46806
|
-
if (exact.length > 0) return exact;
|
|
46807
|
-
const byLabel = sessions2.filter((s3) => labelOf(s3) === selector);
|
|
46808
|
-
if (byLabel.length > 0) return byLabel;
|
|
46809
|
-
return sessions2.filter((s3) => s3.id.startsWith(selector) || (labelOf(s3) ?? "").startsWith(selector));
|
|
46810
|
-
}
|
|
46811
46743
|
function parseCompressArgs(input, opts) {
|
|
46812
46744
|
const callId = opts?.callId;
|
|
46813
46745
|
const diag = { ok: false, kind: "ok", invalidItems: 0 };
|
|
@@ -48361,7 +48293,6 @@ function loadOptions(env = process.env) {
|
|
|
48361
48293
|
passthrough: passthrough.enabled,
|
|
48362
48294
|
passthroughSource: passthrough.source,
|
|
48363
48295
|
autoUpdate: (env.ACP_AUTO_UPDATE ?? (fileConfig.autoUpdate === false ? "0" : "1")) !== "0",
|
|
48364
|
-
updateTag: (env.ACP_UPDATE_TAG ?? fileConfig.updateTag ?? "latest").trim() || "latest",
|
|
48365
48296
|
logFile: env.ACP_LOG_FILE !== void 0 ? env.ACP_LOG_FILE || void 0 : fileConfig.logFile,
|
|
48366
48297
|
mitm: {
|
|
48367
48298
|
enabled: (env.BILI_MITM ?? (fileConfig.mitm?.enabled === false ? "0" : "1")) !== "0",
|
|
@@ -63725,12 +63656,6 @@ var To = (s3) => {
|
|
|
63725
63656
|
import path12 from "path";
|
|
63726
63657
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
63727
63658
|
var REGISTRY_BASE = "https://registry.npmjs.org";
|
|
63728
|
-
function normalizeUpdateTag(tag) {
|
|
63729
|
-
return (tag ?? "latest").trim() || "latest";
|
|
63730
|
-
}
|
|
63731
|
-
function registryUrlFor(packageName, tag) {
|
|
63732
|
-
return `${REGISTRY_BASE}/${packageName}/${encodeURIComponent(tag)}`;
|
|
63733
|
-
}
|
|
63734
63659
|
var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
|
|
63735
63660
|
var THROTTLE_FILE = path12.join(cacheDir(), ".update-check");
|
|
63736
63661
|
var LOCK_FILE = path12.join(cacheDir(), ".update-lock");
|
|
@@ -63741,42 +63666,22 @@ function shouldStealLock(holderAlive, ageMs) {
|
|
|
63741
63666
|
var timer2;
|
|
63742
63667
|
var inFlight = false;
|
|
63743
63668
|
var firstCheckDone = false;
|
|
63744
|
-
function
|
|
63745
|
-
|
|
63746
|
-
|
|
63747
|
-
|
|
63669
|
+
function parseVersion(v2) {
|
|
63670
|
+
return v2.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
|
|
63671
|
+
}
|
|
63672
|
+
function isNewer(latest, current) {
|
|
63673
|
+
const l = parseVersion(latest);
|
|
63674
|
+
const c = parseVersion(current);
|
|
63748
63675
|
for (let i = 0; i < 3; i++) {
|
|
63749
|
-
const
|
|
63750
|
-
const
|
|
63751
|
-
if (
|
|
63752
|
-
|
|
63753
|
-
if (!next.pre.length && prev.pre.length) return true;
|
|
63754
|
-
if (next.pre.length && !prev.pre.length) return false;
|
|
63755
|
-
for (let i = 0; i < Math.max(next.pre.length, prev.pre.length); i++) {
|
|
63756
|
-
const a = next.pre[i];
|
|
63757
|
-
const b2 = prev.pre[i];
|
|
63758
|
-
if (a === void 0) return false;
|
|
63759
|
-
if (b2 === void 0) return true;
|
|
63760
|
-
if (a === b2) continue;
|
|
63761
|
-
const aNumber = /^\d+$/.test(a) ? Number(a) : void 0;
|
|
63762
|
-
const bNumber = /^\d+$/.test(b2) ? Number(b2) : void 0;
|
|
63763
|
-
if (aNumber !== void 0 && bNumber !== void 0) return aNumber > bNumber;
|
|
63764
|
-
if (aNumber !== void 0) return false;
|
|
63765
|
-
if (bNumber !== void 0) return true;
|
|
63766
|
-
return a > b2;
|
|
63676
|
+
const lv = l[i] ?? 0;
|
|
63677
|
+
const cv = c[i] ?? 0;
|
|
63678
|
+
if (lv > cv) return true;
|
|
63679
|
+
if (lv < cv) return false;
|
|
63767
63680
|
}
|
|
63768
63681
|
return false;
|
|
63769
63682
|
}
|
|
63770
|
-
function parseSemVer(version2) {
|
|
63771
|
-
const match = version2.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.+)?$/);
|
|
63772
|
-
if (!match) return void 0;
|
|
63773
|
-
return {
|
|
63774
|
-
parts: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
63775
|
-
pre: match[4]?.split(".") ?? []
|
|
63776
|
-
};
|
|
63777
|
-
}
|
|
63778
63683
|
function staleInstallStatus(diskVersion, runningVersion) {
|
|
63779
|
-
return diskVersion !== void 0 &&
|
|
63684
|
+
return diskVersion !== void 0 && isNewer(diskVersion, runningVersion) ? "restart" : "current";
|
|
63780
63685
|
}
|
|
63781
63686
|
async function readLastCheck() {
|
|
63782
63687
|
try {
|
|
@@ -63982,8 +63887,7 @@ async function checkForUpdate(opts, force = false) {
|
|
|
63982
63887
|
return;
|
|
63983
63888
|
}
|
|
63984
63889
|
log("info", `[update] checking npm registry for ${opts.packageName}${sinceLastSec < 0 ? " (startup check)" : sinceLastSec === 0 ? "" : ` (last check ${sinceLastSec}s ago)`}\u2026`);
|
|
63985
|
-
const
|
|
63986
|
-
const url = registryUrlFor(opts.packageName, tag);
|
|
63890
|
+
const url = `${REGISTRY_BASE}/${opts.packageName}/latest`;
|
|
63987
63891
|
const registryDispatcher = egressDispatcher(opts, url);
|
|
63988
63892
|
const res = await fetchWithEgress(url, {
|
|
63989
63893
|
signal: AbortSignal.timeout(5e3),
|
|
@@ -64002,11 +63906,11 @@ async function checkForUpdate(opts, force = false) {
|
|
|
64002
63906
|
}
|
|
64003
63907
|
const diskVersion = installDir ? await readDiskVersion(installDir) : void 0;
|
|
64004
63908
|
const currentVersion = diskVersion ?? opts.currentVersion;
|
|
64005
|
-
if (!
|
|
63909
|
+
if (!isNewer(latest, currentVersion)) {
|
|
64006
63910
|
if (staleInstallStatus(diskVersion, opts.currentVersion) === "restart") {
|
|
64007
63911
|
log("warn", `[update] running v${opts.currentVersion} but v${diskVersion} is installed \u2014 restart bili to activate (auto-update replaced the on-disk install; this process is still on the old code)`);
|
|
64008
63912
|
} else {
|
|
64009
|
-
log("info", `[update] current=${currentVersion} latest=${latest}
|
|
63913
|
+
log("info", `[update] current=${currentVersion} latest=${latest} (up to date)`);
|
|
64010
63914
|
}
|
|
64011
63915
|
return;
|
|
64012
63916
|
}
|
|
@@ -66071,33 +65975,7 @@ function latestBlockTime(s3) {
|
|
|
66071
65975
|
for (const b2 of s3.state.blocks) if (b2.createdAt > latest) latest = b2.createdAt;
|
|
66072
65976
|
return latest;
|
|
66073
65977
|
}
|
|
66074
|
-
function
|
|
66075
|
-
const messages = s3.lastMessages;
|
|
66076
|
-
if (messages && messages.length > 0) {
|
|
66077
|
-
const folded = s3.lastMessagesFolded === true;
|
|
66078
|
-
const blocksFull = full && folded ? s3.state.blocks.filter((b2) => b2.active).map((b2) => {
|
|
66079
|
-
const content = s3.blockContents.get(b2.blockId);
|
|
66080
|
-
return content ? { blockId: b2.blockId, topic: b2.topic, count: content.full.count, fullText: content.full.text } : void 0;
|
|
66081
|
-
}).filter((x) => x !== void 0) : void 0;
|
|
66082
|
-
return renderHandoff({
|
|
66083
|
-
coreMessages: messages,
|
|
66084
|
-
state: s3.state,
|
|
66085
|
-
full,
|
|
66086
|
-
folded,
|
|
66087
|
-
blocksFull,
|
|
66088
|
-
meta: {
|
|
66089
|
-
title: s3.meta.title,
|
|
66090
|
-
label: s3.meta.label,
|
|
66091
|
-
sessionId: s3.id,
|
|
66092
|
-
contextTokens: s3.stats.contextTokens,
|
|
66093
|
-
extraBullets: [
|
|
66094
|
-
...s3.meta.protocol ? [`- protocol: ${s3.meta.protocol}`] : [],
|
|
66095
|
-
...s3.meta.upstreamOrigin ? [`- upstream: ${s3.meta.upstreamOrigin}`] : [],
|
|
66096
|
-
`- requests: ${s3.stats.requests}`
|
|
66097
|
-
]
|
|
66098
|
-
}
|
|
66099
|
-
});
|
|
66100
|
-
}
|
|
65978
|
+
function renderHandoff(s3, full) {
|
|
66101
65979
|
const lines = [];
|
|
66102
65980
|
lines.push(`# billion-context session handoff`);
|
|
66103
65981
|
lines.push("");
|
|
@@ -66110,6 +65988,38 @@ function renderHandoff2(s3, full) {
|
|
|
66110
65988
|
if (s3.stats.contextTokens) lines.push(`- last context tokens: ~${s3.stats.contextTokens}`);
|
|
66111
65989
|
lines.push(`- compression blocks: ${s3.state.blocks.length} (active ${s3.state.blocks.filter((b2) => b2.active).length})`);
|
|
66112
65990
|
lines.push("");
|
|
65991
|
+
const messages = s3.lastMessages;
|
|
65992
|
+
if (messages && messages.length > 0) {
|
|
65993
|
+
const folded = s3.lastMessagesFolded === true;
|
|
65994
|
+
const view = full || folded ? messages : prune(messages, s3.state);
|
|
65995
|
+
lines.push(
|
|
65996
|
+
full && !folded ? `## Full conversation (${messages.length} messages)` : folded ? `## Conversation (persisted folded snapshot, ${messages.length} messages)` : `## Conversation (folded view as the model saw it, ${messages.length} client messages)`
|
|
65997
|
+
);
|
|
65998
|
+
lines.push("");
|
|
65999
|
+
let lastRole = "";
|
|
66000
|
+
for (const m2 of view) {
|
|
66001
|
+
if (m2.role !== lastRole) {
|
|
66002
|
+
lines.push(`### ${m2.role}`);
|
|
66003
|
+
lines.push("");
|
|
66004
|
+
lastRole = m2.role;
|
|
66005
|
+
}
|
|
66006
|
+
lines.push(renderMessage2(m2));
|
|
66007
|
+
}
|
|
66008
|
+
lines.push("");
|
|
66009
|
+
if (full && folded) {
|
|
66010
|
+
for (const b2 of s3.state.blocks.filter((x) => x.active)) {
|
|
66011
|
+
const content = s3.blockContents.get(b2.blockId);
|
|
66012
|
+
if (!content) continue;
|
|
66013
|
+
lines.push(`## Block ${b2.blockId}${b2.topic ? ` \u2014 ${b2.topic}` : ""}`);
|
|
66014
|
+
lines.push("");
|
|
66015
|
+
lines.push(`### Original messages (${content.full.count})`);
|
|
66016
|
+
lines.push("");
|
|
66017
|
+
lines.push(content.full.text.trim());
|
|
66018
|
+
lines.push("");
|
|
66019
|
+
}
|
|
66020
|
+
}
|
|
66021
|
+
return lines.join("\n");
|
|
66022
|
+
}
|
|
66113
66023
|
const active = s3.state.blocks.filter((b2) => b2.active);
|
|
66114
66024
|
if (active.length === 0) {
|
|
66115
66025
|
lines.push("No active compression blocks and no persisted conversation snapshot (v2 session file). Original messages are only persisted when they are compressed into a block, so this session's conversation content is not available for export.");
|
|
@@ -66138,8 +66048,32 @@ function renderHandoff2(s3, full) {
|
|
|
66138
66048
|
}
|
|
66139
66049
|
return lines.join("\n");
|
|
66140
66050
|
}
|
|
66141
|
-
function
|
|
66142
|
-
|
|
66051
|
+
function renderMessage2(m2) {
|
|
66052
|
+
const parts = [];
|
|
66053
|
+
switch (m2.contentType) {
|
|
66054
|
+
case "text":
|
|
66055
|
+
parts.push(m2.text ?? "");
|
|
66056
|
+
break;
|
|
66057
|
+
case "tool-call":
|
|
66058
|
+
parts.push(`\`${m2.toolName ?? "?"}(${m2.toolCallId ?? ""})\` args: ${m2.text ?? ""}`);
|
|
66059
|
+
break;
|
|
66060
|
+
case "tool-result":
|
|
66061
|
+
parts.push(`\`${m2.toolName ?? "?"}(${m2.toolCallId ?? ""})\` \u2192 ${m2.text ?? ""}`);
|
|
66062
|
+
break;
|
|
66063
|
+
case "reasoning":
|
|
66064
|
+
parts.push(`_reasoning_: ${m2.text ?? ""}`);
|
|
66065
|
+
break;
|
|
66066
|
+
}
|
|
66067
|
+
const body = parts.join("\n").trim();
|
|
66068
|
+
return body === "" ? "_(empty)_" : body + "\n";
|
|
66069
|
+
}
|
|
66070
|
+
function matchSession(sessions2, selector) {
|
|
66071
|
+
const exact = sessions2.filter((s3) => s3.id === selector);
|
|
66072
|
+
if (exact.length > 0) return exact;
|
|
66073
|
+
const byLabel = sessions2.filter((s3) => s3.meta.label === selector);
|
|
66074
|
+
if (byLabel.length > 0) return byLabel;
|
|
66075
|
+
const byPrefix = sessions2.filter((s3) => s3.id.startsWith(selector) || (s3.meta.label ?? "").startsWith(selector));
|
|
66076
|
+
return byPrefix;
|
|
66143
66077
|
}
|
|
66144
66078
|
async function exportSession(selector, opts = {}) {
|
|
66145
66079
|
const store = new SessionStore({ dir: opts.dir, enabled: true });
|
|
@@ -66154,7 +66088,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
66154
66088
|
);
|
|
66155
66089
|
return ["Persisted sessions:", "", ...rows.map((r) => ` ${r}`), "", "Usage: bili export <session-id|label> [--output handoff.md] [--full]"].join("\n");
|
|
66156
66090
|
}
|
|
66157
|
-
const matches =
|
|
66091
|
+
const matches = matchSession(all, selector);
|
|
66158
66092
|
if (matches.length === 0) {
|
|
66159
66093
|
throw new Error(`no session matches "${selector}" (run "bili export" to list sessions)`);
|
|
66160
66094
|
}
|
|
@@ -66162,7 +66096,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
66162
66096
|
const ids = matches.map((s3) => s3.id).join(", ");
|
|
66163
66097
|
throw new Error(`selector "${selector}" matches ${matches.length} sessions (${ids}); use the full session id`);
|
|
66164
66098
|
}
|
|
66165
|
-
const markdown =
|
|
66099
|
+
const markdown = renderHandoff(matches[0], opts.full ?? false);
|
|
66166
66100
|
if (opts.output) {
|
|
66167
66101
|
mkdirSync6(path16.dirname(path16.resolve(opts.output)), { recursive: true });
|
|
66168
66102
|
writeFileSync5(opts.output, markdown, "utf8");
|
|
@@ -66487,16 +66421,14 @@ async function main() {
|
|
|
66487
66421
|
if (v2 !== void 0) process.env[k2] = v2;
|
|
66488
66422
|
}
|
|
66489
66423
|
let updaterResolveProxy;
|
|
66490
|
-
let updateTag;
|
|
66491
66424
|
try {
|
|
66492
66425
|
const o = loadOptions();
|
|
66493
66426
|
updaterResolveProxy = (url) => resolveProxy(o.routes, o.proxy, url, o.proxyFallback);
|
|
66494
|
-
updateTag = o.updateTag;
|
|
66495
66427
|
} catch (e) {
|
|
66496
66428
|
console.error(`bili update: config load failed (${String(e)}); updater egress goes direct`);
|
|
66497
66429
|
}
|
|
66498
66430
|
await checkForUpdate(
|
|
66499
|
-
{ packageName: PACKAGE_NAME, currentVersion: VERSION3, autoUpdate: true, resolveProxy: updaterResolveProxy
|
|
66431
|
+
{ packageName: PACKAGE_NAME, currentVersion: VERSION3, autoUpdate: true, resolveProxy: updaterResolveProxy },
|
|
66500
66432
|
true
|
|
66501
66433
|
);
|
|
66502
66434
|
return;
|
|
@@ -66524,8 +66456,7 @@ async function main() {
|
|
|
66524
66456
|
packageName: PACKAGE_NAME,
|
|
66525
66457
|
currentVersion: VERSION3,
|
|
66526
66458
|
autoUpdate: true,
|
|
66527
|
-
resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback)
|
|
66528
|
-
updateTag: opts.updateTag
|
|
66459
|
+
resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback)
|
|
66529
66460
|
});
|
|
66530
66461
|
}
|
|
66531
66462
|
}
|