billion-context 0.1.93 → 0.1.94-pr.632.453
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 +146 -77
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -46740,6 +46740,74 @@ 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
|
+
}
|
|
46743
46811
|
function parseCompressArgs(input, opts) {
|
|
46744
46812
|
const callId = opts?.callId;
|
|
46745
46813
|
const diag = { ok: false, kind: "ok", invalidItems: 0 };
|
|
@@ -48293,6 +48361,7 @@ function loadOptions(env = process.env) {
|
|
|
48293
48361
|
passthrough: passthrough.enabled,
|
|
48294
48362
|
passthroughSource: passthrough.source,
|
|
48295
48363
|
autoUpdate: (env.ACP_AUTO_UPDATE ?? (fileConfig.autoUpdate === false ? "0" : "1")) !== "0",
|
|
48364
|
+
updateTag: (env.ACP_UPDATE_TAG ?? fileConfig.updateTag ?? "latest").trim() || "latest",
|
|
48296
48365
|
logFile: env.ACP_LOG_FILE !== void 0 ? env.ACP_LOG_FILE || void 0 : fileConfig.logFile,
|
|
48297
48366
|
mitm: {
|
|
48298
48367
|
enabled: (env.BILI_MITM ?? (fileConfig.mitm?.enabled === false ? "0" : "1")) !== "0",
|
|
@@ -63656,6 +63725,12 @@ var To = (s3) => {
|
|
|
63656
63725
|
import path12 from "path";
|
|
63657
63726
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
63658
63727
|
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
|
+
}
|
|
63659
63734
|
var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
|
|
63660
63735
|
var THROTTLE_FILE = path12.join(cacheDir(), ".update-check");
|
|
63661
63736
|
var LOCK_FILE = path12.join(cacheDir(), ".update-lock");
|
|
@@ -63666,22 +63741,42 @@ function shouldStealLock(holderAlive, ageMs) {
|
|
|
63666
63741
|
var timer2;
|
|
63667
63742
|
var inFlight = false;
|
|
63668
63743
|
var firstCheckDone = false;
|
|
63669
|
-
function
|
|
63670
|
-
|
|
63671
|
-
|
|
63672
|
-
|
|
63673
|
-
const l = parseVersion(latest);
|
|
63674
|
-
const c = parseVersion(current);
|
|
63744
|
+
function isVersionNewer(latest, current) {
|
|
63745
|
+
const next = parseSemVer(latest);
|
|
63746
|
+
const prev = parseSemVer(current);
|
|
63747
|
+
if (!next || !prev) return false;
|
|
63675
63748
|
for (let i = 0; i < 3; i++) {
|
|
63676
|
-
const
|
|
63677
|
-
const
|
|
63678
|
-
if (
|
|
63679
|
-
|
|
63749
|
+
const a = next.parts[i] ?? 0;
|
|
63750
|
+
const b2 = prev.parts[i] ?? 0;
|
|
63751
|
+
if (a !== b2) return a > b2;
|
|
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;
|
|
63680
63767
|
}
|
|
63681
63768
|
return false;
|
|
63682
63769
|
}
|
|
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
|
+
}
|
|
63683
63778
|
function staleInstallStatus(diskVersion, runningVersion) {
|
|
63684
|
-
return diskVersion !== void 0 &&
|
|
63779
|
+
return diskVersion !== void 0 && isVersionNewer(diskVersion, runningVersion) ? "restart" : "current";
|
|
63685
63780
|
}
|
|
63686
63781
|
async function readLastCheck() {
|
|
63687
63782
|
try {
|
|
@@ -63887,7 +63982,8 @@ async function checkForUpdate(opts, force = false) {
|
|
|
63887
63982
|
return;
|
|
63888
63983
|
}
|
|
63889
63984
|
log("info", `[update] checking npm registry for ${opts.packageName}${sinceLastSec < 0 ? " (startup check)" : sinceLastSec === 0 ? "" : ` (last check ${sinceLastSec}s ago)`}\u2026`);
|
|
63890
|
-
const
|
|
63985
|
+
const tag = normalizeUpdateTag(opts.updateTag);
|
|
63986
|
+
const url = registryUrlFor(opts.packageName, tag);
|
|
63891
63987
|
const registryDispatcher = egressDispatcher(opts, url);
|
|
63892
63988
|
const res = await fetchWithEgress(url, {
|
|
63893
63989
|
signal: AbortSignal.timeout(5e3),
|
|
@@ -63906,11 +64002,11 @@ async function checkForUpdate(opts, force = false) {
|
|
|
63906
64002
|
}
|
|
63907
64003
|
const diskVersion = installDir ? await readDiskVersion(installDir) : void 0;
|
|
63908
64004
|
const currentVersion = diskVersion ?? opts.currentVersion;
|
|
63909
|
-
if (!
|
|
64005
|
+
if (!isVersionNewer(latest, currentVersion)) {
|
|
63910
64006
|
if (staleInstallStatus(diskVersion, opts.currentVersion) === "restart") {
|
|
63911
64007
|
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)`);
|
|
63912
64008
|
} else {
|
|
63913
|
-
log("info", `[update] current=${currentVersion} latest=${latest} (up to date)`);
|
|
64009
|
+
log("info", `[update] current=${currentVersion} latest=${latest} tag=${tag} (up to date)`);
|
|
63914
64010
|
}
|
|
63915
64011
|
return;
|
|
63916
64012
|
}
|
|
@@ -65975,7 +66071,33 @@ function latestBlockTime(s3) {
|
|
|
65975
66071
|
for (const b2 of s3.state.blocks) if (b2.createdAt > latest) latest = b2.createdAt;
|
|
65976
66072
|
return latest;
|
|
65977
66073
|
}
|
|
65978
|
-
function
|
|
66074
|
+
function renderHandoff2(s3, full) {
|
|
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
|
+
}
|
|
65979
66101
|
const lines = [];
|
|
65980
66102
|
lines.push(`# billion-context session handoff`);
|
|
65981
66103
|
lines.push("");
|
|
@@ -65988,38 +66110,6 @@ function renderHandoff(s3, full) {
|
|
|
65988
66110
|
if (s3.stats.contextTokens) lines.push(`- last context tokens: ~${s3.stats.contextTokens}`);
|
|
65989
66111
|
lines.push(`- compression blocks: ${s3.state.blocks.length} (active ${s3.state.blocks.filter((b2) => b2.active).length})`);
|
|
65990
66112
|
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
|
-
}
|
|
66023
66113
|
const active = s3.state.blocks.filter((b2) => b2.active);
|
|
66024
66114
|
if (active.length === 0) {
|
|
66025
66115
|
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.");
|
|
@@ -66048,32 +66138,8 @@ function renderHandoff(s3, full) {
|
|
|
66048
66138
|
}
|
|
66049
66139
|
return lines.join("\n");
|
|
66050
66140
|
}
|
|
66051
|
-
function
|
|
66052
|
-
|
|
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;
|
|
66141
|
+
function matchSession2(sessions2, selector) {
|
|
66142
|
+
return matchSession(sessions2, selector, (s3) => s3.meta.label);
|
|
66077
66143
|
}
|
|
66078
66144
|
async function exportSession(selector, opts = {}) {
|
|
66079
66145
|
const store = new SessionStore({ dir: opts.dir, enabled: true });
|
|
@@ -66088,7 +66154,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
66088
66154
|
);
|
|
66089
66155
|
return ["Persisted sessions:", "", ...rows.map((r) => ` ${r}`), "", "Usage: bili export <session-id|label> [--output handoff.md] [--full]"].join("\n");
|
|
66090
66156
|
}
|
|
66091
|
-
const matches =
|
|
66157
|
+
const matches = matchSession2(all, selector);
|
|
66092
66158
|
if (matches.length === 0) {
|
|
66093
66159
|
throw new Error(`no session matches "${selector}" (run "bili export" to list sessions)`);
|
|
66094
66160
|
}
|
|
@@ -66096,7 +66162,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
66096
66162
|
const ids = matches.map((s3) => s3.id).join(", ");
|
|
66097
66163
|
throw new Error(`selector "${selector}" matches ${matches.length} sessions (${ids}); use the full session id`);
|
|
66098
66164
|
}
|
|
66099
|
-
const markdown =
|
|
66165
|
+
const markdown = renderHandoff2(matches[0], opts.full ?? false);
|
|
66100
66166
|
if (opts.output) {
|
|
66101
66167
|
mkdirSync6(path16.dirname(path16.resolve(opts.output)), { recursive: true });
|
|
66102
66168
|
writeFileSync5(opts.output, markdown, "utf8");
|
|
@@ -66421,14 +66487,16 @@ async function main() {
|
|
|
66421
66487
|
if (v2 !== void 0) process.env[k2] = v2;
|
|
66422
66488
|
}
|
|
66423
66489
|
let updaterResolveProxy;
|
|
66490
|
+
let updateTag;
|
|
66424
66491
|
try {
|
|
66425
66492
|
const o = loadOptions();
|
|
66426
66493
|
updaterResolveProxy = (url) => resolveProxy(o.routes, o.proxy, url, o.proxyFallback);
|
|
66494
|
+
updateTag = o.updateTag;
|
|
66427
66495
|
} catch (e) {
|
|
66428
66496
|
console.error(`bili update: config load failed (${String(e)}); updater egress goes direct`);
|
|
66429
66497
|
}
|
|
66430
66498
|
await checkForUpdate(
|
|
66431
|
-
{ packageName: PACKAGE_NAME, currentVersion: VERSION3, autoUpdate: true, resolveProxy: updaterResolveProxy },
|
|
66499
|
+
{ packageName: PACKAGE_NAME, currentVersion: VERSION3, autoUpdate: true, resolveProxy: updaterResolveProxy, updateTag },
|
|
66432
66500
|
true
|
|
66433
66501
|
);
|
|
66434
66502
|
return;
|
|
@@ -66456,7 +66524,8 @@ async function main() {
|
|
|
66456
66524
|
packageName: PACKAGE_NAME,
|
|
66457
66525
|
currentVersion: VERSION3,
|
|
66458
66526
|
autoUpdate: true,
|
|
66459
|
-
resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback)
|
|
66527
|
+
resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback),
|
|
66528
|
+
updateTag: opts.updateTag
|
|
66460
66529
|
});
|
|
66461
66530
|
}
|
|
66462
66531
|
}
|