billion-context 0.1.97-pr.669.488 → 0.1.97
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 -2
- package/README.zh-CN.md +1 -2
- package/dist/index.js +34 -179
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +13 -38
- package/dist/mcp.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -158,7 +158,7 @@ rewrite until dsh gains a settings-path env or an upstream loopback opt-out.
|
|
|
158
158
|
Overlay dirs created by older versions are left in place and never merged back
|
|
159
159
|
into the real home.
|
|
160
160
|
|
|
161
|
-
### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`
|
|
161
|
+
### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)
|
|
162
162
|
|
|
163
163
|
The launcher wraps a client in one command: it starts a proxy on an
|
|
164
164
|
independent port (a fresh instance is always spawned — a port is never
|
|
@@ -177,7 +177,6 @@ bili omp # pi-style, file-free (#535): env + extens
|
|
|
177
177
|
bili opencode # MITM for HTTPS + temp opencode.json (/bili/ for HTTP) + thin /acp plugin
|
|
178
178
|
bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + HERMES_CA_BUNDLE) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched
|
|
179
179
|
bili dsh # deepseek-harness: non-loopback upstreams ride proxy envs (https MITM, http absolute-form), loopback keeps the overlay DSH_HOME (~/.dsh-bili) rewrite (#535), built-in deepseek route via DEEPSEEK_BASE_URL, native /acp command injected via --patch
|
|
180
|
-
bili trae # Trae CLI (ByteDance, closed Go binary, no base-URL override) — cert-MITM via HTTPS_PROXY + SSL_CERT_FILE, model host from TRAE_CLI_API_HOST or the default enterprise gateway (#655)
|
|
181
180
|
bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
|
|
182
181
|
```
|
|
183
182
|
|
package/README.zh-CN.md
CHANGED
|
@@ -84,7 +84,7 @@ npm install -g billion-context
|
|
|
84
84
|
|
|
85
85
|
bili 永不拥有用户数据:每个被启动的客户端都跑在**真实 home** 上,运行期写入落在用户预期的位置。把客户端指向代理时,启动器按优先级选择——**优先 env 变量**(hermes/dsh/codex 的代理/CA env;pi/omp 的 `BILI_PROVIDER_REWRITES` URL 清单,由扩展加载时经 `registerProvider` 消费),其次 **CLI 参数或扩展 API**(codex `-c key=value`、opencode 插件),最后才是**生成文件**——目前仅剩 opencode 的临时 `opencode.json`(退出即删)和 dsh 的回环例外:dsh 的 fetch 栈对回环目标无条件绕过代理 env,所以本地上游保留持久 `~/.dsh-bili` overlay 改写,直到 dsh 提供 settings-path env 或上游支持回环 opt-out。旧版本创建的 overlay 目录原地保留,绝不合并回真实 home。
|
|
86
86
|
|
|
87
|
-
### 方式 1 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`
|
|
87
|
+
### 方式 1 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)
|
|
88
88
|
|
|
89
89
|
启动器把客户端包进一条命令:在独立端口拉起一个代理(总是全新实例,绝不复用端口),再按客户端支持的机制把它指向代理 —— 能吃代理/CA 环境变量的走**证书 MITM**,不吃的走隔离的**`/bili/` 配置重写**。真实配置文件从不被修改;客户端自己的配置只被**读取**,用来发现它实际连接的 HTTPS 上游主机,把这些主机加入 MITM 白名单 —— 代理只 TLS 终结它们,其余流量盲透传。
|
|
90
90
|
|
|
@@ -96,7 +96,6 @@ bili omp # pi 同款,file-free(#535):环境变量 +
|
|
|
96
96
|
bili opencode # HTTPS 走 MITM + 临时 opencode.json(HTTP 走 /bili/)+ 轻量 /acp 插件
|
|
97
97
|
bili hermes # file-free(#535):hermes 代理环境变量(HTTPS_PROXY + HERMES_CA_BUNDLE)—— https 走 CONNECT MITM,http 走绝对形式转发;真实 ~/.hermes 不动
|
|
98
98
|
bili dsh # deepseek-harness:非回环上游走代理 env(https MITM、http absolute-form),回环上游保留 overlay DSH_HOME(~/.dsh-bili)改写(#535),内置 deepseek 路由走 DEEPSEEK_BASE_URL,经 --patch 注入原生 /acp 命令
|
|
99
|
-
bili trae # Trae CLI(字节跳动,闭源 Go 二进制,无 base-URL 覆盖)—— 证书 MITM(HTTPS_PROXY + SSL_CERT_FILE),模型主机取 TRAE_CLI_API_HOST 或默认企业网关(#655)
|
|
100
99
|
bili pi --mitm-domain api.foo.com # 向 MITM 白名单追加域名
|
|
101
100
|
```
|
|
102
101
|
|
package/dist/index.js
CHANGED
|
@@ -48726,7 +48726,6 @@ function mergeCompress(global2, provider, model) {
|
|
|
48726
48726
|
const promptLevels = [global2?.prompts, provider?.prompts, model?.prompts].filter(Boolean);
|
|
48727
48727
|
const rangeOf = (s3) => s3?.minCompressRangeChars ?? s3?.minCompressRange;
|
|
48728
48728
|
const absorbLevels = [global2?.absorb, provider?.absorb, model?.absorb].filter(Boolean);
|
|
48729
|
-
const reasoningLevels = [global2?.reasoning, provider?.reasoning, model?.reasoning].filter(Boolean);
|
|
48730
48729
|
return {
|
|
48731
48730
|
modelContextLimit: pick("modelContextLimit"),
|
|
48732
48731
|
maxContextLimit: pick("maxContextLimit"),
|
|
@@ -48740,11 +48739,7 @@ function mergeCompress(global2, provider, model) {
|
|
|
48740
48739
|
acknowledgePromptsRisk: pick("acknowledgePromptsRisk"),
|
|
48741
48740
|
absorb: absorbLevels.length > 0 ? Object.assign({}, ...absorbLevels) : void 0,
|
|
48742
48741
|
stripImages: pick("stripImages"),
|
|
48743
|
-
stripImagesKeepRecent: pick("stripImagesKeepRecent")
|
|
48744
|
-
// `reasoning` is a third nested-object field merged sub-field-wise
|
|
48745
|
-
// exactly like `absorb`/`prompts`: a model-level `threshold` must not
|
|
48746
|
-
// discard a provider-level `drop: false`.
|
|
48747
|
-
reasoning: reasoningLevels.length > 0 ? Object.assign({}, ...reasoningLevels) : void 0
|
|
48742
|
+
stripImagesKeepRecent: pick("stripImagesKeepRecent")
|
|
48748
48743
|
};
|
|
48749
48744
|
}
|
|
48750
48745
|
function resolveCompress(routes, upstreamUrl, model, global2) {
|
|
@@ -48824,53 +48819,6 @@ function resolveRequestConfig(base, routes, embeddedUrl, model, native, globalCo
|
|
|
48824
48819
|
return applyCompressSettings(base, limit, compress);
|
|
48825
48820
|
}
|
|
48826
48821
|
|
|
48827
|
-
// src/reasoning-drop.ts
|
|
48828
|
-
var DEFAULT_COMPRESS_REASONING = { drop: true, threshold: 2048 };
|
|
48829
|
-
function resolveReasoningDrop(cfg) {
|
|
48830
|
-
let threshold = DEFAULT_COMPRESS_REASONING.threshold;
|
|
48831
|
-
if (cfg?.threshold !== void 0) {
|
|
48832
|
-
const t = cfg.threshold;
|
|
48833
|
-
if (typeof t === "number" && Number.isFinite(t) && t >= 0) {
|
|
48834
|
-
threshold = Math.floor(t);
|
|
48835
|
-
}
|
|
48836
|
-
}
|
|
48837
|
-
return { drop: cfg?.drop !== false, threshold };
|
|
48838
|
-
}
|
|
48839
|
-
function dropCompressReasoning(messages, cfg) {
|
|
48840
|
-
const { drop, threshold } = resolveReasoningDrop(cfg);
|
|
48841
|
-
if (!drop || messages.length === 0) return messages;
|
|
48842
|
-
try {
|
|
48843
|
-
const last = messages.length - 1;
|
|
48844
|
-
const resultAt = /* @__PURE__ */ new Map();
|
|
48845
|
-
for (let i = 0; i <= last; i++) {
|
|
48846
|
-
const m2 = messages[i];
|
|
48847
|
-
if (m2.contentType === "tool-result" && typeof m2.toolCallId === "string" && !resultAt.has(m2.toolCallId)) {
|
|
48848
|
-
resultAt.set(m2.toolCallId, i);
|
|
48849
|
-
}
|
|
48850
|
-
}
|
|
48851
|
-
const dropIdx = /* @__PURE__ */ new Set();
|
|
48852
|
-
for (let i = 0; i <= last; i++) {
|
|
48853
|
-
const m2 = messages[i];
|
|
48854
|
-
if (m2.contentType !== "tool-call" || m2.toolName !== "compress") continue;
|
|
48855
|
-
const ri2 = typeof m2.toolCallId === "string" ? resultAt.get(m2.toolCallId) : void 0;
|
|
48856
|
-
if (ri2 === void 0 || ri2 <= i || ri2 >= last) continue;
|
|
48857
|
-
let total = 0;
|
|
48858
|
-
let j2 = i - 1;
|
|
48859
|
-
while (j2 >= 0 && messages[j2].contentType === "reasoning") {
|
|
48860
|
-
total += (messages[j2].text ?? "").length;
|
|
48861
|
-
j2--;
|
|
48862
|
-
}
|
|
48863
|
-
if (total > threshold) {
|
|
48864
|
-
for (let k2 = j2 + 1; k2 < i; k2++) dropIdx.add(k2);
|
|
48865
|
-
}
|
|
48866
|
-
}
|
|
48867
|
-
if (dropIdx.size === 0) return messages;
|
|
48868
|
-
return messages.filter((_2, idx) => !dropIdx.has(idx));
|
|
48869
|
-
} catch {
|
|
48870
|
-
return messages;
|
|
48871
|
-
}
|
|
48872
|
-
}
|
|
48873
|
-
|
|
48874
48822
|
// src/strip-images.ts
|
|
48875
48823
|
var DEFAULT_STRIP_IMAGES_KEEP_RECENT = 5;
|
|
48876
48824
|
var IMAGE_PLACEHOLDER = "[image]";
|
|
@@ -56307,28 +56255,15 @@ function handlePluginManifest(res) {
|
|
|
56307
56255
|
statusEndpoint: "/__bili/plugin/status"
|
|
56308
56256
|
}));
|
|
56309
56257
|
}
|
|
56310
|
-
function conversationIdForSession(sessionId) {
|
|
56311
|
-
let bestId;
|
|
56312
|
-
let bestSeen = -Infinity;
|
|
56313
|
-
for (const [cid, entry] of conversations) {
|
|
56314
|
-
if (entry.sessionId === sessionId && entry.lastSeen > bestSeen) {
|
|
56315
|
-
bestId = cid;
|
|
56316
|
-
bestSeen = entry.lastSeen;
|
|
56317
|
-
}
|
|
56318
|
-
}
|
|
56319
|
-
return bestId;
|
|
56320
|
-
}
|
|
56321
56258
|
function handlePluginStatus(conversationId2, res, deps, fallbackLatest = false) {
|
|
56322
56259
|
let entry = conversations.get(conversationId2);
|
|
56323
56260
|
let session = entry ? peekSession(entry.sessionId) : void 0;
|
|
56324
56261
|
let viaFallback = false;
|
|
56325
|
-
let resolvedConversationId = conversationId2;
|
|
56326
56262
|
if ((!entry || !session) && fallbackLatest) {
|
|
56327
56263
|
const latest = listSessions().filter((s3) => s3.restored !== true).sort((a, b2) => (b2.lastSeen ?? 0) - (a.lastSeen ?? 0))[0];
|
|
56328
56264
|
if (latest) {
|
|
56329
56265
|
session = latest;
|
|
56330
56266
|
viaFallback = true;
|
|
56331
|
-
resolvedConversationId = conversationIdForSession(latest.id) ?? conversationId2;
|
|
56332
56267
|
} else {
|
|
56333
56268
|
res.writeHead(404, { "content-type": "application/json" });
|
|
56334
56269
|
res.end(JSON.stringify({ ok: false, error: "no session with activity since boot \u2014 issue a model request or pass the conversation id" }));
|
|
@@ -56378,7 +56313,7 @@ function handlePluginStatus(conversationId2, res, deps, fallbackLatest = false)
|
|
|
56378
56313
|
res.writeHead(200, { "content-type": "application/json" });
|
|
56379
56314
|
res.end(JSON.stringify({
|
|
56380
56315
|
ok: true,
|
|
56381
|
-
conversationId:
|
|
56316
|
+
conversationId: conversationId2,
|
|
56382
56317
|
fallback: viaFallback || void 0,
|
|
56383
56318
|
label: session.meta.label ?? null,
|
|
56384
56319
|
pluginAgent: session.metadata.pluginAgent ?? null,
|
|
@@ -56413,12 +56348,8 @@ async function handlePluginTool(payload, res, deps) {
|
|
|
56413
56348
|
const entry = conversations.get(conversationId2);
|
|
56414
56349
|
const session = entry ? peekSession(entry.sessionId) : void 0;
|
|
56415
56350
|
if (!entry || !session) {
|
|
56416
|
-
deps.log("warn", `[plugin] tool "${tool}" rejected for conversation ${conversationId2}: ${entry ? "id registered but session not resident in this proxy instance" : "id never registered (stale shim session id after host resume?)"}`);
|
|
56417
56351
|
res.writeHead(404, { "content-type": "application/json" });
|
|
56418
|
-
res.end(JSON.stringify({
|
|
56419
|
-
ok: false,
|
|
56420
|
-
error: !entry ? "unknown plugin conversation (no model request has arrived with this conversation id yet)" : "unknown plugin conversation (id registered but its session is not resident in this proxy instance \u2014 a fresh model request re-binds it)"
|
|
56421
|
-
}));
|
|
56352
|
+
res.end(JSON.stringify({ ok: false, error: "unknown plugin conversation (no model request has arrived with this conversation id yet)" }));
|
|
56422
56353
|
return;
|
|
56423
56354
|
}
|
|
56424
56355
|
if (!isProxyToolFor(tool, session, deps.config)) {
|
|
@@ -56986,20 +56917,6 @@ function readDshConfig(dshHome) {
|
|
|
56986
56917
|
}
|
|
56987
56918
|
return { baseUrls: parseDshSettingsYaml(text) };
|
|
56988
56919
|
}
|
|
56989
|
-
var TRAE_DEFAULT_MODEL_HOSTS = [
|
|
56990
|
-
"console.enterprise.trae.cn",
|
|
56991
|
-
"www.trae.cn"
|
|
56992
|
-
];
|
|
56993
|
-
function resolveTraeHome(env) {
|
|
56994
|
-
const h = os.homedir();
|
|
56995
|
-
return nonEmpty2(env.TRAE_CONFIG_DIR) ? env.TRAE_CONFIG_DIR : path10.join(h, ".trae");
|
|
56996
|
-
}
|
|
56997
|
-
function readTraeConfig(env) {
|
|
56998
|
-
const result = {};
|
|
56999
|
-
const host = nonEmpty2(env.TRAE_CLI_API_HOST) ? env.TRAE_CLI_API_HOST.replace(/^https?:\/\//i, "").replace(/\/+$/, "") : void 0;
|
|
57000
|
-
if (host) result.modelApiHost = host;
|
|
57001
|
-
return result;
|
|
57002
|
-
}
|
|
57003
56920
|
function readClaudeSettings(homeDir, cwd, env = process.env) {
|
|
57004
56921
|
const files = [
|
|
57005
56922
|
path10.join(homeDir, ".claude", "settings.json"),
|
|
@@ -57350,7 +57267,6 @@ function loadClientConfig(env, cwd) {
|
|
|
57350
57267
|
config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
|
|
57351
57268
|
config.hermes = readHermesConfig(resolveHermesHome(env));
|
|
57352
57269
|
config.dsh = readDshConfig(resolveDshHome(env));
|
|
57353
|
-
config.trae = readTraeConfig(env);
|
|
57354
57270
|
return config;
|
|
57355
57271
|
}
|
|
57356
57272
|
function collectModelWindows(config, scope) {
|
|
@@ -57408,10 +57324,6 @@ function extractHttpsHosts(config) {
|
|
|
57408
57324
|
if (config.zcode) {
|
|
57409
57325
|
for (const prov of Object.values(config.zcode.providers)) push(prov.baseURL);
|
|
57410
57326
|
}
|
|
57411
|
-
if (config.trae) {
|
|
57412
|
-
const hosts = nonEmpty2(config.trae.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
|
|
57413
|
-
for (const h of hosts) push(`https://${h}`);
|
|
57414
|
-
}
|
|
57415
57327
|
return out;
|
|
57416
57328
|
}
|
|
57417
57329
|
function configFilePaths(env) {
|
|
@@ -57423,8 +57335,7 @@ function configFilePaths(env) {
|
|
|
57423
57335
|
path11.join(process.cwd(), ".claude", "settings.json"),
|
|
57424
57336
|
path11.join(codexHome, "config.toml"),
|
|
57425
57337
|
path11.join(resolvePiHome(env), "models.json"),
|
|
57426
|
-
path11.join(zcodeHome, "v2", "config.json")
|
|
57427
|
-
path11.join(resolveTraeHome(env), "traecli.yaml")
|
|
57338
|
+
path11.join(zcodeHome, "v2", "config.json")
|
|
57428
57339
|
];
|
|
57429
57340
|
}
|
|
57430
57341
|
function readMtimes(paths) {
|
|
@@ -58470,7 +58381,7 @@ function logUnrecognizedPath(log2, url) {
|
|
|
58470
58381
|
const n = (unrecognizedPathCounts.get(key) ?? 0) + 1;
|
|
58471
58382
|
unrecognizedPathCounts.set(key, n);
|
|
58472
58383
|
if (n <= 3) {
|
|
58473
|
-
log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /
|
|
58384
|
+
log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
|
|
58474
58385
|
} else if (n === 4) {
|
|
58475
58386
|
log2("info", `unrecognized path ${key}: forwarding unchanged; further occurrences suppressed`);
|
|
58476
58387
|
}
|
|
@@ -59022,7 +58933,7 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
|
|
|
59022
58933
|
}
|
|
59023
58934
|
}
|
|
59024
58935
|
upstreamOrigin = route ? route.upstream : /^https?:\/\//i.test(url) ? new URL(url).origin : opts.upstream;
|
|
59025
|
-
protocol = route?.explicitProtocol ?? (req.method === "POST" && bodyBuffer.length > 0 ? urlPath.endsWith("/chat/completions")
|
|
58936
|
+
protocol = route?.explicitProtocol ?? (req.method === "POST" && bodyBuffer.length > 0 ? urlPath.endsWith("/chat/completions") ? "openai" : urlPath.endsWith("/v1/messages") || urlPath.endsWith("/messages") ? "anthropic" : urlPath.endsWith("/responses") || responsesCompact ? "responses" : null : null);
|
|
59026
58937
|
if (protocol !== null && bodyBuffer.length > 0) {
|
|
59027
58938
|
try {
|
|
59028
58939
|
const decoded = await decodeRequestBody(headerValue2(req, "content-encoding"), bodyBuffer, MAX_REQUEST_BYTES);
|
|
@@ -59303,14 +59214,13 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
59303
59214
|
await withSessionLock(session, async () => {
|
|
59304
59215
|
const runPrepare = () => {
|
|
59305
59216
|
const cs2 = resolveCompress(opts.routes, route?.rewrittenUrl, parsed.model, opts.compress);
|
|
59306
|
-
const reasoningCfg = cs2.reasoning;
|
|
59307
59217
|
const keepRecent = cs2.stripImagesKeepRecent ?? DEFAULT_STRIP_IMAGES_KEEP_RECENT;
|
|
59308
59218
|
const stripped = cs2.stripImages ? stripHistoricalImages(parsed, protocol, keepRecent) : { body: parsed, removed: 0 };
|
|
59309
59219
|
if (opts.debug && stripped.removed > 0) {
|
|
59310
59220
|
log2("info", `[debug] strip-images: dropped ${stripped.removed} historical image part(s), kept last ${keepRecent} (session=${session.id})`);
|
|
59311
59221
|
}
|
|
59312
59222
|
const work = stripped.body;
|
|
59313
|
-
return countTokens ? prepareCountTokens(work, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode
|
|
59223
|
+
return countTokens ? prepareCountTokens(work, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode) : protocol === "openai" ? prepareOpenai(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode, nativeWindow) : responsesCompact ? prepareResponsesCompact(stripped.removed > 0 ? Buffer.from(JSON.stringify(work)) : bodyBuffer, work, session, req, core, reqConfig, log2) : prepareResponses(work, req, opts, core, reqConfig, reqPrompts, log2, session, responsesIdentity, pluginMode, upstreamOrigin, nativeWindow);
|
|
59314
59224
|
};
|
|
59315
59225
|
const isCodexCompactTrigger = protocol === "responses" && !responsesCompact && isCodexClient(req.headers) && hasCompactionTrigger(parsed.input);
|
|
59316
59226
|
if (isCodexCompactTrigger) {
|
|
@@ -59398,13 +59308,6 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
59398
59308
|
}
|
|
59399
59309
|
}
|
|
59400
59310
|
var ACP_TAG_MARK = "<acp ";
|
|
59401
|
-
function withReasoningDrop(msgs, reasoning, log2, sessionId) {
|
|
59402
|
-
const out = dropCompressReasoning(msgs, reasoning);
|
|
59403
|
-
if (out.length !== msgs.length) {
|
|
59404
|
-
log2("info", `[${sessionId}] compress-reasoning: dropped ${msgs.length - out.length} reasoning message(s) from closed compress turns (#651)`);
|
|
59405
|
-
}
|
|
59406
|
-
return out;
|
|
59407
|
-
}
|
|
59408
59311
|
function stripKernelSummaries(messages, state) {
|
|
59409
59312
|
const carried = /* @__PURE__ */ new Set();
|
|
59410
59313
|
for (const b2 of state.blocks) {
|
|
@@ -59506,13 +59409,12 @@ function effectiveTokenCount(session, msgs) {
|
|
|
59506
59409
|
if (!session.metadata.anonymousPrefixAffinity) return 0;
|
|
59507
59410
|
return estimateCoreMessagesUpper(msgs);
|
|
59508
59411
|
}
|
|
59509
|
-
function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, session, pluginMode
|
|
59412
|
+
function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, session, pluginMode) {
|
|
59510
59413
|
const sessionId = session.id;
|
|
59511
59414
|
const stream2 = parsed.stream === true;
|
|
59512
59415
|
++session.stats.requests;
|
|
59513
59416
|
session.hostCreditTokens = 0;
|
|
59514
59417
|
const injectTools = opts.compress.injectTool && !pluginMode;
|
|
59515
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
59516
59418
|
if (isAutoModeClassifier(parsed)) {
|
|
59517
59419
|
log2("info", `[${sessionId}] auto-mode classifier passthrough (skipping compress injection)`);
|
|
59518
59420
|
return { body: JSON.stringify(parsed), session, processedMessages: [], originalMessages: [], anthropicSystem: parsed.system, protocol: "anthropic", stream: stream2, compressInjected: false, pluginMode, nudge: void 0, prompts };
|
|
@@ -59550,7 +59452,7 @@ function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
59550
59452
|
log2("info", diagTagSummary(turn.messages, sessionId, "text-only"));
|
|
59551
59453
|
const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && (turn.nudge.shouldInject || emergencyNudge(turn.nudge));
|
|
59552
59454
|
log2("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge));
|
|
59553
|
-
processedMessages =
|
|
59455
|
+
processedMessages = stripKernelSummaries(turn.messages, turn.state);
|
|
59554
59456
|
applyCompactionArchive(session, activeBefore, new Set(msgs.map((m2) => m2.id)), log2);
|
|
59555
59457
|
reapOrphanBlocks(session, msgs, deactivateBlock);
|
|
59556
59458
|
rebuiltMessages = coreToAnthropic(processedMessages, cacheControls);
|
|
@@ -59632,13 +59534,12 @@ function clampOutgoingOutput(rebuilt, field, ctx, sessionId, log2) {
|
|
|
59632
59534
|
log2("info", `[${sessionId}] output budget clamped ${raw} -> ${capped} (input~${inputEstimate}, window=${ctx.nativeWindow}); prevents input+output overflow (#453)`);
|
|
59633
59535
|
}
|
|
59634
59536
|
}
|
|
59635
|
-
function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session, pluginMode, nativeWindow
|
|
59537
|
+
function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session, pluginMode, nativeWindow) {
|
|
59636
59538
|
const sessionId = session.id;
|
|
59637
59539
|
const stream2 = parsed.stream === true;
|
|
59638
59540
|
++session.stats.requests;
|
|
59639
59541
|
session.hostCreditTokens = 0;
|
|
59640
59542
|
let openaiSystemText = "";
|
|
59641
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
59642
59543
|
let openaiOutboundSystem;
|
|
59643
59544
|
let processedMessages = [];
|
|
59644
59545
|
let originalMessages = [];
|
|
@@ -59676,7 +59577,7 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
59676
59577
|
log2("info", diagTagSummary(turn.messages, sessionId, "text-only"));
|
|
59677
59578
|
const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && shouldInject && (turn.nudge.shouldInject || emergencyNudge(turn.nudge));
|
|
59678
59579
|
log2("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge));
|
|
59679
|
-
processedMessages =
|
|
59580
|
+
processedMessages = stripKernelSummaries(turn.messages, turn.state);
|
|
59680
59581
|
applyCompactionArchive(session, activeBefore, new Set(msgs.map((m2) => m2.id)), log2);
|
|
59681
59582
|
reapOrphanBlocks(session, msgs, deactivateBlock);
|
|
59682
59583
|
rebuiltMessages = systemToUser(coreToOpenai(processedMessages));
|
|
@@ -59716,12 +59617,11 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
59716
59617
|
markDirty(session);
|
|
59717
59618
|
return { body: JSON.stringify(rebuilt), session, processedMessages, originalMessages, protocol: "openai", stream: stream2, compressInjected: injectTools, pluginMode, nudge, prompts, openaiSystemText, renderTags: "text-only" };
|
|
59718
59619
|
}
|
|
59719
|
-
function prepareResponses(parsed, req, opts, core, config, prompts, log2, session, identity, pluginMode, upstreamOrigin, nativeWindow
|
|
59620
|
+
function prepareResponses(parsed, req, opts, core, config, prompts, log2, session, identity, pluginMode, upstreamOrigin, nativeWindow) {
|
|
59720
59621
|
const sessionId = session.id;
|
|
59721
59622
|
const stream2 = parsed.stream === true;
|
|
59722
59623
|
++session.stats.requests;
|
|
59723
59624
|
session.hostCreditTokens = 0;
|
|
59724
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
59725
59625
|
if (reconcileNativeCompactionBoundary(session)) {
|
|
59726
59626
|
log2("info", `[${sessionId}] reconciled ACP state after native Responses compact boundary`);
|
|
59727
59627
|
}
|
|
@@ -59786,7 +59686,7 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
59786
59686
|
log2("info", diagTagSummary(turn.messages, sessionId, "text-only"));
|
|
59787
59687
|
const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && shouldInject && !isCompactionTrigger && (turn.nudge.shouldInject || emergencyNudge(turn.nudge));
|
|
59788
59688
|
log2("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge));
|
|
59789
|
-
processedMessages = repairResponsesAssistantOrdering(
|
|
59689
|
+
processedMessages = repairResponsesAssistantOrdering(stripKernelSummaries(turn.messages, turn.state), originalMessages);
|
|
59790
59690
|
reapOrphanBlocks(session, msgs, deactivateBlock);
|
|
59791
59691
|
rebuiltInput = patchResponsesInput(projection, processedMessages);
|
|
59792
59692
|
const forgedSummaries = echoReplaced ? [] : session.metadata.codexForgedSummaries ?? [];
|
|
@@ -60044,7 +59944,7 @@ function logUpstreamProxyDecision(opts, upstreamUrl, decision) {
|
|
|
60044
59944
|
}
|
|
60045
59945
|
function inferWireProtocol(path18) {
|
|
60046
59946
|
const p2 = path18.split("?", 2)[0];
|
|
60047
|
-
if (p2.endsWith("/chat/completions")
|
|
59947
|
+
if (p2.endsWith("/chat/completions")) return "openai";
|
|
60048
59948
|
if (p2.endsWith("/responses") || p2.endsWith("/responses/compact")) return "responses";
|
|
60049
59949
|
return null;
|
|
60050
59950
|
}
|
|
@@ -64421,7 +64321,6 @@ function resolveProxyOrigin() {
|
|
|
64421
64321
|
var TOOL_TIMEOUT_MS = 6e4;
|
|
64422
64322
|
var CONVERSATION_FROM_ENV = process.env.CLAUDE_CODE_SESSION_ID?.trim() || process.env.BILI_CONVERSATION_ID?.trim() || void 0;
|
|
64423
64323
|
var IDENTITY_BINDING = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim());
|
|
64424
|
-
var ORPHAN_ADOPT = IDENTITY_BINDING && process.env.BILI_MCP_NO_ORPHAN_ADOPT !== "1";
|
|
64425
64324
|
var manifestTools = [];
|
|
64426
64325
|
var conversationId = CONVERSATION_FROM_ENV;
|
|
64427
64326
|
var registered = false;
|
|
@@ -64454,45 +64353,21 @@ function ensureManifest() {
|
|
|
64454
64353
|
return manifestPromise;
|
|
64455
64354
|
}
|
|
64456
64355
|
async function forwardTool(tool, args, timeoutMs = TOOL_TIMEOUT_MS) {
|
|
64457
|
-
|
|
64458
|
-
let res;
|
|
64459
|
-
try {
|
|
64460
|
-
res = await fetch(`${resolveProxyOrigin()}/__bili/plugin/tool`, {
|
|
64461
|
-
method: "POST",
|
|
64462
|
-
headers: { "content-type": "application/json" },
|
|
64463
|
-
body: JSON.stringify({ conversationId, tool, args }),
|
|
64464
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
64465
|
-
});
|
|
64466
|
-
} catch (err2) {
|
|
64467
|
-
if (err2 instanceof Error && err2.name === "TimeoutError") throw new Error(`tool forward timed out after ${timeoutMs}ms: ${tool}`);
|
|
64468
|
-
throw err2;
|
|
64469
|
-
}
|
|
64470
|
-
const data = await res.json();
|
|
64471
|
-
if (res.ok && data.ok) return data.result ?? "";
|
|
64472
|
-
if (res.status === 404 && attempt === 0 && ORPHAN_ADOPT && conversationId && typeof data.error === "string" && data.error.includes("no model request has arrived")) {
|
|
64473
|
-
if (await adoptLatestActiveConversation()) continue;
|
|
64474
|
-
}
|
|
64475
|
-
throw new Error(data.error ?? `tool forward failed: ${res.status}`);
|
|
64476
|
-
}
|
|
64477
|
-
}
|
|
64478
|
-
async function adoptLatestActiveConversation() {
|
|
64356
|
+
let res;
|
|
64479
64357
|
try {
|
|
64480
|
-
|
|
64481
|
-
|
|
64482
|
-
{
|
|
64483
|
-
|
|
64484
|
-
|
|
64485
|
-
|
|
64486
|
-
|
|
64487
|
-
|
|
64488
|
-
|
|
64489
|
-
`
|
|
64490
|
-
);
|
|
64491
|
-
conversationId = data.conversationId;
|
|
64492
|
-
return true;
|
|
64493
|
-
} catch {
|
|
64494
|
-
return false;
|
|
64358
|
+
res = await fetch(`${resolveProxyOrigin()}/__bili/plugin/tool`, {
|
|
64359
|
+
method: "POST",
|
|
64360
|
+
headers: { "content-type": "application/json" },
|
|
64361
|
+
body: JSON.stringify({ conversationId, tool, args }),
|
|
64362
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
64363
|
+
});
|
|
64364
|
+
} catch (err2) {
|
|
64365
|
+
if (err2 instanceof Error && err2.name === "TimeoutError") throw new Error(`tool forward timed out after ${timeoutMs}ms: ${tool}`);
|
|
64366
|
+
throw err2;
|
|
64495
64367
|
}
|
|
64368
|
+
const data = await res.json();
|
|
64369
|
+
if (!res.ok || !data.ok) throw new Error(data.error ?? `tool forward failed: ${res.status}`);
|
|
64370
|
+
return data.result ?? "";
|
|
64496
64371
|
}
|
|
64497
64372
|
var ERR_TOOL = -32602;
|
|
64498
64373
|
async function handleMessage(msg) {
|
|
@@ -64986,7 +64861,7 @@ function selfDistFile(name) {
|
|
|
64986
64861
|
return path15.join(selfPackageRoot(), "dist", name);
|
|
64987
64862
|
}
|
|
64988
64863
|
var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
|
|
64989
|
-
var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "
|
|
64864
|
+
var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "pi-test"];
|
|
64990
64865
|
var HEALTH_PATH = "/__bili/health";
|
|
64991
64866
|
var HEALTH_POLL_INTERVAL_MS = 200;
|
|
64992
64867
|
var SPAWN_WAIT_MS = 2e4;
|
|
@@ -65135,15 +65010,6 @@ function discoverRoutes(client, config) {
|
|
|
65135
65010
|
} catch {
|
|
65136
65011
|
}
|
|
65137
65012
|
}
|
|
65138
|
-
} else if (client === "trae") {
|
|
65139
|
-
const hosts = nonEmpty2(config.trae?.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
|
|
65140
|
-
for (const h of hosts) {
|
|
65141
|
-
const host = h.split(":", 2)[0].toLowerCase();
|
|
65142
|
-
if (host && !httpsSeen.has(host)) {
|
|
65143
|
-
httpsSeen.add(host);
|
|
65144
|
-
httpsDomains.push(host);
|
|
65145
|
-
}
|
|
65146
|
-
}
|
|
65147
65013
|
} else {
|
|
65148
65014
|
for (const [name, prov] of Object.entries(config.codex?.providers ?? {})) {
|
|
65149
65015
|
classify(prov.baseUrl, `model_providers.${name}.base_url`);
|
|
@@ -65176,9 +65042,6 @@ function buildPiEnv(origin, caPath, baseEnv, httpRewrites = [], httpsRewrites =
|
|
|
65176
65042
|
function buildCodexEnv(origin, caPath, baseEnv) {
|
|
65177
65043
|
return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65178
65044
|
}
|
|
65179
|
-
function buildTraeEnv(origin, caPath, baseEnv) {
|
|
65180
|
-
return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65181
|
-
}
|
|
65182
65045
|
function buildCodexArgs(origin, httpRewrites, httpsRewrites, extra) {
|
|
65183
65046
|
const args = [];
|
|
65184
65047
|
for (const r of httpRewrites) {
|
|
@@ -65269,7 +65132,7 @@ function isPrivateIPv4(host) {
|
|
|
65269
65132
|
return false;
|
|
65270
65133
|
}
|
|
65271
65134
|
function launcherInjectMcp(env, base, codexUpstream) {
|
|
65272
|
-
if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh"
|
|
65135
|
+
if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh") return false;
|
|
65273
65136
|
if (env.BILI_LAUNCHER_PLUGIN === "0") return false;
|
|
65274
65137
|
if (base === "codex" && env.BILI_LAUNCHER_PLUGIN === void 0 && codexUpstream !== void 0 && isPrivateUpstreamHost(codexUpstream)) {
|
|
65275
65138
|
return false;
|
|
@@ -66024,10 +65887,6 @@ function resolveClientCommand(client, env) {
|
|
|
66024
65887
|
);
|
|
66025
65888
|
return { command: process.execPath, prefixArgs: [cli] };
|
|
66026
65889
|
}
|
|
66027
|
-
if (client === "trae") {
|
|
66028
|
-
const traeBin = resolveOnPath("traecli", env) ?? resolveOnPath("trae-cli", env) ?? resolveOnPath("trae", env);
|
|
66029
|
-
return { command: traeBin ?? "traecli", prefixArgs: [] };
|
|
66030
|
-
}
|
|
66031
65890
|
const resolved = resolveOnPath(client, env);
|
|
66032
65891
|
return { command: resolved ?? client, prefixArgs: [] };
|
|
66033
65892
|
}
|
|
@@ -66163,8 +66022,6 @@ async function runLaunch(params, deps = {}) {
|
|
|
66163
66022
|
}
|
|
66164
66023
|
const dshAcpPatch = writeDshAcpPatch(dshHomeDir);
|
|
66165
66024
|
if (dshAcpPatch) clientArgs = dshArgsWithPatch(clientArgs, dshAcpPatch);
|
|
66166
|
-
} else if (base === "trae") {
|
|
66167
|
-
env = buildTraeEnv(origin, resolveCombinedCaPath(process.env), stripInheritedProxy(process.env));
|
|
66168
66025
|
} else if (base === "codex") {
|
|
66169
66026
|
const codexConversationId = injectMcp ? randomUUID5() : void 0;
|
|
66170
66027
|
if (directUrl) {
|
|
@@ -66440,7 +66297,6 @@ Usage:
|
|
|
66440
66297
|
bili opencode [opts --] [args] start a proxy + launch opencode against it (cert-MITM)
|
|
66441
66298
|
bili hermes [opts --] [args] start a proxy + launch hermes-agent against it (/bili/ rewrite)
|
|
66442
66299
|
bili dsh [opts --] [args] start a proxy + launch deepseek-harness against it (/bili/ rewrite)
|
|
66443
|
-
bili trae [opts --] [args] start a proxy + launch Trae CLI against it (cert-MITM)
|
|
66444
66300
|
bili test pi non-polluting pi smoke test through the proxy
|
|
66445
66301
|
bili export [session] [--full] list sessions / export one as a Markdown handoff
|
|
66446
66302
|
(--full includes original messages; --output FILE)
|
|
@@ -66455,12 +66311,12 @@ Usage:
|
|
|
66455
66311
|
bili --version print version
|
|
66456
66312
|
bili --help show this help
|
|
66457
66313
|
|
|
66458
|
-
Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh
|
|
66314
|
+
Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh):
|
|
66459
66315
|
Brings up a proxy on an independent port (a fresh instance every launch), then runs the client pointed at it via HTTPS_PROXY + the proxy's
|
|
66460
66316
|
MITM CA \u2014 no config-file edits. Discovered HTTPS upstream domains are
|
|
66461
66317
|
auto-whitelisted for MITM so the proxy TLS-terminates exactly the hosts the
|
|
66462
|
-
|
|
66463
|
-
|
|
66318
|
+
client uses; HTTP / localhost providers go direct. pi/claude trust the CA
|
|
66319
|
+
via NODE_EXTRA_CA_CERTS, codex via SSL_CERT_FILE. Proxy killed on client exit.
|
|
66464
66320
|
bili flags (-F, --mitm-domain, --port, ...) must precede the client name;
|
|
66465
66321
|
everything after the client name is passed through to the client.
|
|
66466
66322
|
bili pi # launch pi through the proxy
|
|
@@ -66470,9 +66326,8 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h
|
|
|
66470
66326
|
bili claude # launch claude through the proxy
|
|
66471
66327
|
bili omp # launch omp through the proxy (pi-based; /bili/ rewrite)
|
|
66472
66328
|
bili hermes # launch hermes-agent through the proxy (/bili/ rewrite of ~/.hermes/config.yaml)
|
|
66473
|
-
|
|
66474
|
-
|
|
66475
|
-
bili test pi # quick end-to-end check of the pi path
|
|
66329
|
+
bili dsh --profile web "task" # launch deepseek-harness through the proxy (/bili/ rewrite of ~/.dsh/settings.yaml)
|
|
66330
|
+
bili test pi # quick end-to-end check of the pi path
|
|
66476
66331
|
bili --mitm-domain api.foo.com pi # add a domain to the MITM whitelist (flags precede the client)
|
|
66477
66332
|
bili -F http://127.0.0.1:7897 codex # route bili's upstream through a proxy (gost-style -F)
|
|
66478
66333
|
|