billion-context 0.1.102-pr.693.522 → 0.1.102
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 -4
- package/README.zh-CN.md +1 -4
- package/dist/index.js +9 -308
- package/dist/index.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,9 +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 codebuddy # Tencent CodeBuddy Code CLI: CODEBUDDY_BASE_URL /bili/ rewrite (OpenAI chat completions wire), budget aligned via CODEBUDDY_AUTO_COMPACT_WINDOW; real ~/.codebuddy untouched
|
|
181
|
-
bili qoder # qoder: model endpoint is hardcoded https (no /bili/ rewrite possible) — cert-MITM via HTTPS_PROXY + NODE_EXTRA_CA_CERTS, default model hosts whitelisted (#653)
|
|
182
|
-
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)
|
|
183
180
|
bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
|
|
184
181
|
```
|
|
185
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,9 +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 codebuddy # Tencent CodeBuddy Code CLI:CODEBUDDY_BASE_URL /bili/ 重写(OpenAI chat completions wire),预算对齐走 CODEBUDDY_AUTO_COMPACT_WINDOW;真实 ~/.codebuddy 不动
|
|
100
|
-
bili qoder # qoder:模型端点硬编码 https(无法 /bili/ 改写)—— 证书 MITM(HTTPS_PROXY + NODE_EXTRA_CA_CERTS),默认模型主机已加白名单(#653)
|
|
101
|
-
bili trae # Trae CLI(字节跳动,闭源 Go 二进制,无 base-URL 覆盖)—— 证书 MITM(HTTPS_PROXY + SSL_CERT_FILE),模型主机取 TRAE_CLI_API_HOST 或默认企业网关(#655)
|
|
102
99
|
bili pi --mitm-domain api.foo.com # 向 MITM 白名单追加域名
|
|
103
100
|
```
|
|
104
101
|
|
package/dist/index.js
CHANGED
|
@@ -57282,55 +57282,6 @@ import path10 from "path";
|
|
|
57282
57282
|
function toModelWindow(id, contextWindow) {
|
|
57283
57283
|
return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
|
|
57284
57284
|
}
|
|
57285
|
-
var QODER_DEFAULT_MODEL_HOSTS = [
|
|
57286
|
-
"api2-v2.qoder.sh",
|
|
57287
|
-
"api1.qoder.sh",
|
|
57288
|
-
"api2.qoder.sh",
|
|
57289
|
-
"api3.qoder.sh",
|
|
57290
|
-
"gateway.qoder.com.cn"
|
|
57291
|
-
];
|
|
57292
|
-
function qoderIsCnSite(env = process.env) {
|
|
57293
|
-
const site = env.QODERCLI_SITE?.trim().toLowerCase();
|
|
57294
|
-
if (site === "cn") return true;
|
|
57295
|
-
if (nonEmpty2(env.QODERCN_CONFIG_DIR) || nonEmpty2(env.QODERCN_CLI_HOME)) return true;
|
|
57296
|
-
const h = os.homedir();
|
|
57297
|
-
const cnDir = path10.join(h, ".qoder-cn");
|
|
57298
|
-
const intlDir = path10.join(h, ".qoder");
|
|
57299
|
-
try {
|
|
57300
|
-
if (fs6.existsSync(cnDir) && !fs6.existsSync(intlDir)) return true;
|
|
57301
|
-
} catch {
|
|
57302
|
-
}
|
|
57303
|
-
return false;
|
|
57304
|
-
}
|
|
57305
|
-
function resolveQoderHome(env = process.env) {
|
|
57306
|
-
const h = os.homedir();
|
|
57307
|
-
const cn2 = qoderIsCnSite(env);
|
|
57308
|
-
const configDir2 = cn2 ? env.QODERCN_CONFIG_DIR : env.QODER_CONFIG_DIR;
|
|
57309
|
-
if (nonEmpty2(configDir2)) return configDir2;
|
|
57310
|
-
const cliHomeEnv = cn2 ? env.QODERCN_CLI_HOME : env.QODER_CLI_HOME;
|
|
57311
|
-
const cliHome = nonEmpty2(cliHomeEnv) ? cliHomeEnv : h;
|
|
57312
|
-
const dirNameEnv = cn2 ? env.QODERCN_CONFIG_DIR_NAME : env.QODER_CONFIG_DIR_NAME;
|
|
57313
|
-
const dirName = nonEmpty2(dirNameEnv) ? dirNameEnv : cn2 ? ".qoder-cn" : ".qoder";
|
|
57314
|
-
return path10.join(cliHome, dirName);
|
|
57315
|
-
}
|
|
57316
|
-
function readQoderConfig(qoderHome, env = process.env) {
|
|
57317
|
-
const result = {};
|
|
57318
|
-
const obj = readJsonObject(path10.join(qoderHome, "settings.json"));
|
|
57319
|
-
const model = obj?.model;
|
|
57320
|
-
if (typeof model === "string" && model.trim().length > 0) {
|
|
57321
|
-
result.model = model.trim();
|
|
57322
|
-
} else if (model && typeof model === "object" && !Array.isArray(model)) {
|
|
57323
|
-
const name = model.name;
|
|
57324
|
-
if (nonEmpty2(name)) result.model = name.trim();
|
|
57325
|
-
}
|
|
57326
|
-
const cn2 = qoderIsCnSite(env);
|
|
57327
|
-
const host = nonEmpty2(cn2 ? env.QODERCN_MODEL_SERVER_HOST : env.QODER_MODEL_SERVER_HOST) ? cn2 ? env.QODERCN_MODEL_SERVER_HOST : env.QODER_MODEL_SERVER_HOST : void 0;
|
|
57328
|
-
if (host) {
|
|
57329
|
-
const bare = host.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "");
|
|
57330
|
-
if (bare.length > 0) result.modelServerHost = bare;
|
|
57331
|
-
}
|
|
57332
|
-
return result;
|
|
57333
|
-
}
|
|
57334
57285
|
function nonEmpty2(s3) {
|
|
57335
57286
|
return typeof s3 === "string" && s3.trim().length > 0;
|
|
57336
57287
|
}
|
|
@@ -57363,98 +57314,6 @@ function resolveCodexHome(env) {
|
|
|
57363
57314
|
const h = os.homedir();
|
|
57364
57315
|
return nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(h, ".codex");
|
|
57365
57316
|
}
|
|
57366
|
-
function resolveCodebuddyHome(env) {
|
|
57367
|
-
const h = os.homedir();
|
|
57368
|
-
return nonEmpty2(env.CODEBUDDY_CONFIG_DIR) ? env.CODEBUDDY_CONFIG_DIR : path10.join(h, ".codebuddy");
|
|
57369
|
-
}
|
|
57370
|
-
function parseCodebuddyModelsJson(obj) {
|
|
57371
|
-
const out = { models: [], urls: [] };
|
|
57372
|
-
const seenUrl = /* @__PURE__ */ new Set();
|
|
57373
|
-
const collect = (id, entry) => {
|
|
57374
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return;
|
|
57375
|
-
const e = entry;
|
|
57376
|
-
const url = e.url;
|
|
57377
|
-
if (typeof url === "string" && url.length > 0 && !seenUrl.has(url)) {
|
|
57378
|
-
seenUrl.add(url);
|
|
57379
|
-
out.urls.push(url);
|
|
57380
|
-
}
|
|
57381
|
-
const win = toModelWindow(id, e.maxInputTokens);
|
|
57382
|
-
if (win) out.models.push(win);
|
|
57383
|
-
};
|
|
57384
|
-
if (!obj) return out;
|
|
57385
|
-
if (Array.isArray(obj)) {
|
|
57386
|
-
for (const item of obj) {
|
|
57387
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
57388
|
-
const it2 = item;
|
|
57389
|
-
collect(it2.id ?? it2.name, it2);
|
|
57390
|
-
}
|
|
57391
|
-
return out;
|
|
57392
|
-
}
|
|
57393
|
-
if (typeof obj !== "object") return out;
|
|
57394
|
-
const root = obj;
|
|
57395
|
-
const modelsField = root.models;
|
|
57396
|
-
if (Array.isArray(modelsField)) {
|
|
57397
|
-
for (const item of modelsField) {
|
|
57398
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
57399
|
-
const it2 = item;
|
|
57400
|
-
collect(it2.id ?? it2.name, it2);
|
|
57401
|
-
}
|
|
57402
|
-
return out;
|
|
57403
|
-
}
|
|
57404
|
-
if (modelsField && typeof modelsField === "object") {
|
|
57405
|
-
for (const [id, val] of Object.entries(modelsField)) collect(id, val);
|
|
57406
|
-
return out;
|
|
57407
|
-
}
|
|
57408
|
-
for (const [id, val] of Object.entries(root)) collect(id, val);
|
|
57409
|
-
return out;
|
|
57410
|
-
}
|
|
57411
|
-
function readJsonFile(filePath) {
|
|
57412
|
-
try {
|
|
57413
|
-
return JSON.parse(fs6.readFileSync(filePath, "utf8"));
|
|
57414
|
-
} catch {
|
|
57415
|
-
return null;
|
|
57416
|
-
}
|
|
57417
|
-
}
|
|
57418
|
-
function readCodebuddyConfig(codebuddyHome, cwd, env = process.env) {
|
|
57419
|
-
let codebuddyBaseUrl;
|
|
57420
|
-
let model;
|
|
57421
|
-
let autoCompactWindow;
|
|
57422
|
-
const settings = readJsonObject(path10.join(codebuddyHome, "settings.json"));
|
|
57423
|
-
const settingsEnv = settings?.env;
|
|
57424
|
-
if (settingsEnv && typeof settingsEnv === "object" && !Array.isArray(settingsEnv)) {
|
|
57425
|
-
const e = settingsEnv;
|
|
57426
|
-
const v2 = e.CODEBUDDY_BASE_URL;
|
|
57427
|
-
if (nonEmpty2(v2)) codebuddyBaseUrl = v2;
|
|
57428
|
-
}
|
|
57429
|
-
const tm = settings?.model;
|
|
57430
|
-
if (nonEmpty2(tm)) model = String(tm);
|
|
57431
|
-
const tacw = Number(settings?.autoCompactWindow);
|
|
57432
|
-
if (Number.isFinite(tacw) && tacw > 0) autoCompactWindow = tacw;
|
|
57433
|
-
if (!codebuddyBaseUrl && nonEmpty2(env.CODEBUDDY_BASE_URL)) codebuddyBaseUrl = env.CODEBUDDY_BASE_URL;
|
|
57434
|
-
const windowByModel = /* @__PURE__ */ new Map();
|
|
57435
|
-
const urls = [];
|
|
57436
|
-
const seenUrl = /* @__PURE__ */ new Set();
|
|
57437
|
-
for (const f2 of [
|
|
57438
|
-
path10.join(codebuddyHome, "models.json"),
|
|
57439
|
-
path10.join(cwd, ".codebuddy", "models.json")
|
|
57440
|
-
]) {
|
|
57441
|
-
const parsed = parseCodebuddyModelsJson(readJsonFile(f2));
|
|
57442
|
-
for (const w2 of parsed.models) windowByModel.set(w2.id, w2.contextWindow);
|
|
57443
|
-
for (const u2 of parsed.urls) {
|
|
57444
|
-
if (!seenUrl.has(u2)) {
|
|
57445
|
-
seenUrl.add(u2);
|
|
57446
|
-
urls.push(u2);
|
|
57447
|
-
}
|
|
57448
|
-
}
|
|
57449
|
-
}
|
|
57450
|
-
return {
|
|
57451
|
-
...codebuddyBaseUrl ? { codebuddyBaseUrl } : {},
|
|
57452
|
-
...model ? { model } : {},
|
|
57453
|
-
...autoCompactWindow ? { autoCompactWindow } : {},
|
|
57454
|
-
...windowByModel.size > 0 ? { models: [...windowByModel.entries()].map(([id, contextWindow]) => ({ id, contextWindow })) } : {},
|
|
57455
|
-
...urls.length > 0 ? { modelUrls: urls } : {}
|
|
57456
|
-
};
|
|
57457
|
-
}
|
|
57458
57317
|
function parseDshSettingsYaml(text) {
|
|
57459
57318
|
const out = [];
|
|
57460
57319
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -57478,20 +57337,6 @@ function readDshConfig(dshHome) {
|
|
|
57478
57337
|
}
|
|
57479
57338
|
return { baseUrls: parseDshSettingsYaml(text) };
|
|
57480
57339
|
}
|
|
57481
|
-
var TRAE_DEFAULT_MODEL_HOSTS = [
|
|
57482
|
-
"console.enterprise.trae.cn",
|
|
57483
|
-
"www.trae.cn"
|
|
57484
|
-
];
|
|
57485
|
-
function resolveTraeHome(env) {
|
|
57486
|
-
const h = os.homedir();
|
|
57487
|
-
return nonEmpty2(env.TRAE_CONFIG_DIR) ? env.TRAE_CONFIG_DIR : path10.join(h, ".trae");
|
|
57488
|
-
}
|
|
57489
|
-
function readTraeConfig(env) {
|
|
57490
|
-
const result = {};
|
|
57491
|
-
const host = nonEmpty2(env.TRAE_CLI_API_HOST) ? env.TRAE_CLI_API_HOST.replace(/^https?:\/\//i, "").replace(/\/+$/, "") : void 0;
|
|
57492
|
-
if (host) result.modelApiHost = host;
|
|
57493
|
-
return result;
|
|
57494
|
-
}
|
|
57495
57340
|
function readClaudeSettings(homeDir, cwd, env = process.env) {
|
|
57496
57341
|
const files = [
|
|
57497
57342
|
path10.join(homeDir, ".claude", "settings.json"),
|
|
@@ -57842,9 +57687,6 @@ function loadClientConfig(env, cwd) {
|
|
|
57842
57687
|
config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
|
|
57843
57688
|
config.hermes = readHermesConfig(resolveHermesHome(env));
|
|
57844
57689
|
config.dsh = readDshConfig(resolveDshHome(env));
|
|
57845
|
-
config.codebuddy = readCodebuddyConfig(resolveCodebuddyHome(env), cwd, env);
|
|
57846
|
-
config.qoder = readQoderConfig(resolveQoderHome(env), env);
|
|
57847
|
-
config.trae = readTraeConfig(env);
|
|
57848
57690
|
return config;
|
|
57849
57691
|
}
|
|
57850
57692
|
function collectModelWindows(config, scope) {
|
|
@@ -57859,14 +57701,12 @@ function collectModelWindows(config, scope) {
|
|
|
57859
57701
|
else if (scope === "pi") for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
|
|
57860
57702
|
else if (scope === "omp") for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
|
|
57861
57703
|
else if (scope === "opencode") for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
|
|
57862
|
-
else if (scope === "codebuddy") add(config.codebuddy?.models);
|
|
57863
57704
|
return out;
|
|
57864
57705
|
}
|
|
57865
57706
|
for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
|
|
57866
57707
|
for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
|
|
57867
57708
|
for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
|
|
57868
57709
|
add(config.codex?.modelWindows);
|
|
57869
|
-
add(config.codebuddy?.models);
|
|
57870
57710
|
return out;
|
|
57871
57711
|
}
|
|
57872
57712
|
|
|
@@ -57904,36 +57744,18 @@ function extractHttpsHosts(config) {
|
|
|
57904
57744
|
if (config.zcode) {
|
|
57905
57745
|
for (const prov of Object.values(config.zcode.providers)) push(prov.baseURL);
|
|
57906
57746
|
}
|
|
57907
|
-
if (config.codebuddy) {
|
|
57908
|
-
push(config.codebuddy.codebuddyBaseUrl);
|
|
57909
|
-
for (const u2 of config.codebuddy.modelUrls ?? []) push(u2);
|
|
57910
|
-
}
|
|
57911
|
-
if (config.qoder) {
|
|
57912
|
-
const hosts = nonEmpty2(config.qoder.modelServerHost) ? [config.qoder.modelServerHost] : QODER_DEFAULT_MODEL_HOSTS;
|
|
57913
|
-
for (const h of hosts) push(`https://${h}`);
|
|
57914
|
-
}
|
|
57915
|
-
if (config.trae) {
|
|
57916
|
-
const hosts = nonEmpty2(config.trae.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
|
|
57917
|
-
for (const h of hosts) push(`https://${h}`);
|
|
57918
|
-
}
|
|
57919
57747
|
return out;
|
|
57920
57748
|
}
|
|
57921
57749
|
function configFilePaths(env) {
|
|
57922
57750
|
const home = os2.homedir();
|
|
57923
57751
|
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path11.join(home, ".codex");
|
|
57924
57752
|
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path11.join(home, ".zcode");
|
|
57925
|
-
const codebuddyHome = resolveCodebuddyHome(env);
|
|
57926
57753
|
return [
|
|
57927
57754
|
path11.join(home, ".claude", "settings.json"),
|
|
57928
57755
|
path11.join(process.cwd(), ".claude", "settings.json"),
|
|
57929
57756
|
path11.join(codexHome, "config.toml"),
|
|
57930
57757
|
path11.join(resolvePiHome(env), "models.json"),
|
|
57931
|
-
path11.join(zcodeHome, "v2", "config.json")
|
|
57932
|
-
path11.join(codebuddyHome, "settings.json"),
|
|
57933
|
-
path11.join(codebuddyHome, "models.json"),
|
|
57934
|
-
path11.join(process.cwd(), ".codebuddy", "models.json"),
|
|
57935
|
-
path11.join(resolveQoderHome(env), "settings.json"),
|
|
57936
|
-
path11.join(resolveTraeHome(env), "traecli.yaml")
|
|
57758
|
+
path11.join(zcodeHome, "v2", "config.json")
|
|
57937
57759
|
];
|
|
57938
57760
|
}
|
|
57939
57761
|
function readMtimes(paths) {
|
|
@@ -58979,7 +58801,7 @@ function logUnrecognizedPath(log2, url) {
|
|
|
58979
58801
|
const n = (unrecognizedPathCounts.get(key) ?? 0) + 1;
|
|
58980
58802
|
unrecognizedPathCounts.set(key, n);
|
|
58981
58803
|
if (n <= 3) {
|
|
58982
|
-
log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /
|
|
58804
|
+
log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
|
|
58983
58805
|
} else if (n === 4) {
|
|
58984
58806
|
log2("info", `unrecognized path ${key}: forwarding unchanged; further occurrences suppressed`);
|
|
58985
58807
|
}
|
|
@@ -59532,7 +59354,7 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
|
|
|
59532
59354
|
}
|
|
59533
59355
|
}
|
|
59534
59356
|
upstreamOrigin = route ? route.upstream : /^https?:\/\//i.test(url) ? new URL(url).origin : opts.upstream;
|
|
59535
|
-
protocol = route?.explicitProtocol ?? (req.method === "POST" && bodyBuffer.length > 0 ? urlPath.endsWith("/chat/completions")
|
|
59357
|
+
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);
|
|
59536
59358
|
if (protocol !== null && bodyBuffer.length > 0) {
|
|
59537
59359
|
try {
|
|
59538
59360
|
const decoded = await decodeRequestBody(headerValue2(req, "content-encoding"), bodyBuffer, MAX_REQUEST_BYTES);
|
|
@@ -60614,7 +60436,7 @@ function logUpstreamProxyDecision(opts, upstreamUrl, decision) {
|
|
|
60614
60436
|
}
|
|
60615
60437
|
function inferWireProtocol(path18) {
|
|
60616
60438
|
const p2 = path18.split("?", 2)[0];
|
|
60617
|
-
if (p2.endsWith("/chat/completions")
|
|
60439
|
+
if (p2.endsWith("/chat/completions")) return "openai";
|
|
60618
60440
|
if (p2.endsWith("/responses") || p2.endsWith("/responses/compact")) return "responses";
|
|
60619
60441
|
return null;
|
|
60620
60442
|
}
|
|
@@ -65561,7 +65383,7 @@ function selfDistFile(name) {
|
|
|
65561
65383
|
return path15.join(selfPackageRoot(), "dist", name);
|
|
65562
65384
|
}
|
|
65563
65385
|
var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
|
|
65564
|
-
var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "
|
|
65386
|
+
var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "pi-test"];
|
|
65565
65387
|
var HEALTH_PATH = "/__bili/health";
|
|
65566
65388
|
var HEALTH_POLL_INTERVAL_MS = 200;
|
|
65567
65389
|
var SPAWN_WAIT_MS = 2e4;
|
|
@@ -65649,29 +65471,6 @@ function discoverRoutes(client, config) {
|
|
|
65649
65471
|
}
|
|
65650
65472
|
} catch {
|
|
65651
65473
|
}
|
|
65652
|
-
} else if (client === "codebuddy") {
|
|
65653
|
-
const raw = nonEmpty2(config.codebuddy?.codebuddyBaseUrl) ? config.codebuddy.codebuddyBaseUrl : "https://tencent.sso.codebuddy.cn/v2";
|
|
65654
|
-
const real = unwrapUpstream2(raw);
|
|
65655
|
-
try {
|
|
65656
|
-
const url = new URL(real);
|
|
65657
|
-
if ((url.protocol === "https:" || url.protocol === "http:") && !rewriteKeys.has("CODEBUDDY_BASE_URL")) {
|
|
65658
|
-
rewriteKeys.add("CODEBUDDY_BASE_URL");
|
|
65659
|
-
httpRewrites.push({ key: "CODEBUDDY_BASE_URL", realUpstream: real });
|
|
65660
|
-
}
|
|
65661
|
-
} catch {
|
|
65662
|
-
}
|
|
65663
|
-
for (const rawModelUrl of config.codebuddy?.modelUrls ?? []) {
|
|
65664
|
-
try {
|
|
65665
|
-
const url = new URL(unwrapUpstream2(rawModelUrl));
|
|
65666
|
-
if (url.protocol !== "https:") continue;
|
|
65667
|
-
const host = url.hostname;
|
|
65668
|
-
if (host && !httpsSeen.has(host.toLowerCase())) {
|
|
65669
|
-
httpsSeen.add(host.toLowerCase());
|
|
65670
|
-
httpsDomains.push(host);
|
|
65671
|
-
}
|
|
65672
|
-
} catch {
|
|
65673
|
-
}
|
|
65674
|
-
}
|
|
65675
65474
|
} else if (client === "pi") {
|
|
65676
65475
|
for (const [name, prov] of Object.entries(config.pi?.providers ?? {})) {
|
|
65677
65476
|
classify(prov.baseUrl, name);
|
|
@@ -65733,24 +65532,6 @@ function discoverRoutes(client, config) {
|
|
|
65733
65532
|
} catch {
|
|
65734
65533
|
}
|
|
65735
65534
|
}
|
|
65736
|
-
} else if (client === "qoder") {
|
|
65737
|
-
const hosts = nonEmpty2(config.qoder?.modelServerHost) ? [config.qoder.modelServerHost] : QODER_DEFAULT_MODEL_HOSTS;
|
|
65738
|
-
for (const host of hosts) {
|
|
65739
|
-
const h = host.toLowerCase();
|
|
65740
|
-
if (h && !httpsSeen.has(h)) {
|
|
65741
|
-
httpsSeen.add(h);
|
|
65742
|
-
httpsDomains.push(h);
|
|
65743
|
-
}
|
|
65744
|
-
}
|
|
65745
|
-
} else if (client === "trae") {
|
|
65746
|
-
const hosts = nonEmpty2(config.trae?.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
|
|
65747
|
-
for (const h of hosts) {
|
|
65748
|
-
const host = h.split(":", 2)[0].toLowerCase();
|
|
65749
|
-
if (host && !httpsSeen.has(host)) {
|
|
65750
|
-
httpsSeen.add(host);
|
|
65751
|
-
httpsDomains.push(host);
|
|
65752
|
-
}
|
|
65753
|
-
}
|
|
65754
65535
|
} else {
|
|
65755
65536
|
for (const [name, prov] of Object.entries(config.codex?.providers ?? {})) {
|
|
65756
65537
|
classify(prov.baseUrl, `model_providers.${name}.base_url`);
|
|
@@ -65783,9 +65564,6 @@ function buildPiEnv(origin, caPath, baseEnv, httpRewrites = [], httpsRewrites =
|
|
|
65783
65564
|
function buildCodexEnv(origin, caPath, baseEnv) {
|
|
65784
65565
|
return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65785
65566
|
}
|
|
65786
|
-
function buildTraeEnv(origin, caPath, baseEnv) {
|
|
65787
|
-
return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65788
|
-
}
|
|
65789
65567
|
function buildCodexArgs(origin, httpRewrites, httpsRewrites, extra) {
|
|
65790
65568
|
const args = [];
|
|
65791
65569
|
for (const r of httpRewrites) {
|
|
@@ -65836,31 +65614,6 @@ function buildClaudeEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
|
|
|
65836
65614
|
if (hr2) env.ANTHROPIC_BASE_URL = hr2.realUpstream;
|
|
65837
65615
|
return env;
|
|
65838
65616
|
}
|
|
65839
|
-
async function resolveCodebuddyBudgetEnv(opts) {
|
|
65840
|
-
const { model, userAutoCompactWindow, shellAutoCompactWindow, routes, upstreamUrl } = opts;
|
|
65841
|
-
if (!model || userAutoCompactWindow !== void 0 || nonEmpty2(shellAutoCompactWindow)) return {};
|
|
65842
|
-
const window2 = await resolveLauncherWindow(model, routes, upstreamUrl);
|
|
65843
|
-
if (!window2) return {};
|
|
65844
|
-
return { CODEBUDDY_AUTO_COMPACT_WINDOW: String(window2) };
|
|
65845
|
-
}
|
|
65846
|
-
function buildCodebuddyEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
|
|
65847
|
-
const env = { ...baseEnv, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65848
|
-
const r = httpRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
|
|
65849
|
-
if (r) env.CODEBUDDY_BASE_URL = wrapUpstream(origin, r.realUpstream);
|
|
65850
|
-
const hr2 = httpsRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
|
|
65851
|
-
if (hr2) env.CODEBUDDY_BASE_URL = hr2.realUpstream;
|
|
65852
|
-
return env;
|
|
65853
|
-
}
|
|
65854
|
-
function buildQoderEnv(origin, caPath, baseEnv) {
|
|
65855
|
-
return { ...baseEnv, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: caPath, BILLION_CONTEXT_PROXY: origin };
|
|
65856
|
-
}
|
|
65857
|
-
async function resolveQoderBudgetEnv(opts) {
|
|
65858
|
-
const { model, userAutoCompactWindow, windowKey, routes, upstreamUrl } = opts;
|
|
65859
|
-
if (!model || nonEmpty2(userAutoCompactWindow)) return {};
|
|
65860
|
-
const window2 = await resolveLauncherWindow(model, routes, upstreamUrl);
|
|
65861
|
-
if (!window2) return {};
|
|
65862
|
-
return { [windowKey]: String(window2) };
|
|
65863
|
-
}
|
|
65864
65617
|
function launcherDirectUrl(env) {
|
|
65865
65618
|
return env.BILI_LAUNCHER_DIRECT === "1";
|
|
65866
65619
|
}
|
|
@@ -65901,7 +65654,7 @@ function isPrivateIPv4(host) {
|
|
|
65901
65654
|
return false;
|
|
65902
65655
|
}
|
|
65903
65656
|
function launcherInjectMcp(env, base, codexUpstream) {
|
|
65904
|
-
if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh"
|
|
65657
|
+
if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh") return false;
|
|
65905
65658
|
if (env.BILI_LAUNCHER_PLUGIN === "0") return false;
|
|
65906
65659
|
if (base === "codex" && env.BILI_LAUNCHER_PLUGIN === void 0 && codexUpstream !== void 0 && isPrivateUpstreamHost(codexUpstream)) {
|
|
65907
65660
|
return false;
|
|
@@ -66724,18 +66477,6 @@ function resolveClientCommand(client, env) {
|
|
|
66724
66477
|
);
|
|
66725
66478
|
return { command: process.execPath, prefixArgs: [cli] };
|
|
66726
66479
|
}
|
|
66727
|
-
if (client === "codebuddy") {
|
|
66728
|
-
const resolved2 = resolveOnPath("codebuddy", env) ?? resolveOnPath("cbc", env);
|
|
66729
|
-
return { command: resolved2 ?? "codebuddy", prefixArgs: [] };
|
|
66730
|
-
}
|
|
66731
|
-
if (client === "qoder") {
|
|
66732
|
-
const resolved2 = resolveOnPath("qoder", env) ?? resolveOnPath("qodercli", env);
|
|
66733
|
-
return { command: resolved2 ?? "qoder", prefixArgs: [] };
|
|
66734
|
-
}
|
|
66735
|
-
if (client === "trae") {
|
|
66736
|
-
const traeBin = resolveOnPath("traecli", env) ?? resolveOnPath("trae-cli", env) ?? resolveOnPath("trae", env);
|
|
66737
|
-
return { command: traeBin ?? "traecli", prefixArgs: [] };
|
|
66738
|
-
}
|
|
66739
66480
|
const resolved = resolveOnPath(client, env);
|
|
66740
66481
|
return { command: resolved ?? client, prefixArgs: [] };
|
|
66741
66482
|
}
|
|
@@ -66802,10 +66543,6 @@ async function runLaunch(params, deps = {}) {
|
|
|
66802
66543
|
console.error(
|
|
66803
66544
|
"bili: direct-URL mode \u2014 claude's ANTHROPIC_BASE_URL is overridden to the proxy; a pre-configured relay is bypassed unless BILI_CLAUDE_UPSTREAM=<relay> is set. OAuth-subscription traffic requires the default MITM mode."
|
|
66804
66545
|
);
|
|
66805
|
-
} else if (base === "qoder") {
|
|
66806
|
-
console.error(
|
|
66807
|
-
"bili: BILI_LAUNCHER_DIRECT has no effect for qoder \u2014 its model endpoint scheme is hardcoded https with no base-URL override env, so qoder always runs in cert-MITM mode."
|
|
66808
|
-
);
|
|
66809
66546
|
}
|
|
66810
66547
|
}
|
|
66811
66548
|
const codexUpstream = base === "codex" ? codexUpstreamUrl(config.codex) : void 0;
|
|
@@ -66875,23 +66612,6 @@ async function runLaunch(params, deps = {}) {
|
|
|
66875
66612
|
}
|
|
66876
66613
|
const dshAcpPatch = writeDshAcpPatch(dshHomeDir);
|
|
66877
66614
|
if (dshAcpPatch) clientArgs = dshArgsWithPatch(clientArgs, dshAcpPatch);
|
|
66878
|
-
} else if (base === "qoder") {
|
|
66879
|
-
env = buildQoderEnv(origin, ca, stripInheritedProxy(process.env));
|
|
66880
|
-
const qoderPrefix = qoderIsCnSite(process.env) ? "QODERCN" : "QODER";
|
|
66881
|
-
env[`${qoderPrefix}_MODEL_TRANSPORT`] = "http";
|
|
66882
|
-
const qoderBudget = await resolveQoderBudgetEnv({
|
|
66883
|
-
model: nonEmpty2(process.env[`${qoderPrefix}_MODEL`]) ? process.env[`${qoderPrefix}_MODEL`] : config.qoder?.model,
|
|
66884
|
-
userAutoCompactWindow: process.env[`${qoderPrefix}_AUTOCOMPACT_WINDOW`],
|
|
66885
|
-
windowKey: `${qoderPrefix}_AUTOCOMPACT_WINDOW`,
|
|
66886
|
-
routes: biliRoutes,
|
|
66887
|
-
upstreamUrl: `https://${config.qoder?.modelServerHost ?? QODER_DEFAULT_MODEL_HOSTS[0]}`
|
|
66888
|
-
});
|
|
66889
|
-
Object.assign(env, qoderBudget);
|
|
66890
|
-
if (qoderBudget[`${qoderPrefix}_AUTOCOMPACT_WINDOW`] !== void 0) {
|
|
66891
|
-
console.error(`bili: qoder budget aligned \u2014 ${qoderPrefix}_AUTOCOMPACT_WINDOW=${qoderBudget[`${qoderPrefix}_AUTOCOMPACT_WINDOW`]}`);
|
|
66892
|
-
}
|
|
66893
|
-
} else if (base === "trae") {
|
|
66894
|
-
env = buildTraeEnv(origin, resolveCombinedCaPath(process.env), stripInheritedProxy(process.env));
|
|
66895
66615
|
} else if (base === "codex") {
|
|
66896
66616
|
const codexConversationId = injectMcp ? randomUUID5() : void 0;
|
|
66897
66617
|
if (directUrl) {
|
|
@@ -66922,19 +66642,6 @@ async function runLaunch(params, deps = {}) {
|
|
|
66922
66642
|
Object.assign(env, inj.envPatch);
|
|
66923
66643
|
if (inj.warning) console.error(`bili: ${inj.warning}`);
|
|
66924
66644
|
}
|
|
66925
|
-
} else if (base === "codebuddy") {
|
|
66926
|
-
env = buildCodebuddyEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
|
|
66927
|
-
const codebuddyBudget = await resolveCodebuddyBudgetEnv({
|
|
66928
|
-
model: config.codebuddy?.model,
|
|
66929
|
-
userAutoCompactWindow: config.codebuddy?.autoCompactWindow,
|
|
66930
|
-
shellAutoCompactWindow: process.env.CODEBUDDY_AUTO_COMPACT_WINDOW,
|
|
66931
|
-
routes: biliRoutes,
|
|
66932
|
-
upstreamUrl: config.codebuddy?.codebuddyBaseUrl ?? "https://tencent.sso.codebuddy.cn/v2"
|
|
66933
|
-
});
|
|
66934
|
-
Object.assign(env, codebuddyBudget);
|
|
66935
|
-
if (codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW !== void 0) {
|
|
66936
|
-
console.error(`bili: codebuddy budget aligned \u2014 CODEBUDDY_AUTO_COMPACT_WINDOW=${codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW}`);
|
|
66937
|
-
}
|
|
66938
66645
|
} else {
|
|
66939
66646
|
env = directUrl ? buildClaudePluginEnv(origin, true, process.env) : buildClaudeEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
|
|
66940
66647
|
if (directUrl) env.BILLION_CONTEXT_PROXY = origin;
|
|
@@ -67189,9 +66896,6 @@ Usage:
|
|
|
67189
66896
|
bili opencode [opts --] [args] start a proxy + launch opencode against it (cert-MITM)
|
|
67190
66897
|
bili hermes [opts --] [args] start a proxy + launch hermes-agent against it (/bili/ rewrite)
|
|
67191
66898
|
bili dsh [opts --] [args] start a proxy + launch deepseek-harness against it (/bili/ rewrite)
|
|
67192
|
-
bili codebuddy [opts --] [args] start a proxy + launch codebuddy against it (/bili/ rewrite)
|
|
67193
|
-
bili qoder [opts --] [args] start a proxy + launch qoder against it (cert-MITM)
|
|
67194
|
-
bili trae [opts --] [args] start a proxy + launch Trae CLI against it (cert-MITM)
|
|
67195
66899
|
bili test pi non-polluting pi smoke test through the proxy
|
|
67196
66900
|
bili export [session] [--full] list sessions / export one as a Markdown handoff
|
|
67197
66901
|
(--full includes original messages; --output FILE)
|
|
@@ -67206,12 +66910,12 @@ Usage:
|
|
|
67206
66910
|
bili --version print version
|
|
67207
66911
|
bili --help show this help
|
|
67208
66912
|
|
|
67209
|
-
Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh
|
|
66913
|
+
Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh):
|
|
67210
66914
|
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
|
|
67211
66915
|
MITM CA \u2014 no config-file edits. Discovered HTTPS upstream domains are
|
|
67212
66916
|
auto-whitelisted for MITM so the proxy TLS-terminates exactly the hosts the
|
|
67213
|
-
client uses; HTTP / localhost providers go direct. pi/claude
|
|
67214
|
-
via NODE_EXTRA_CA_CERTS, codex
|
|
66917
|
+
client uses; HTTP / localhost providers go direct. pi/claude trust the CA
|
|
66918
|
+
via NODE_EXTRA_CA_CERTS, codex via SSL_CERT_FILE. Proxy killed on client exit.
|
|
67215
66919
|
bili flags (-F, --mitm-domain, --port, ...) must precede the client name;
|
|
67216
66920
|
everything after the client name is passed through to the client.
|
|
67217
66921
|
bili pi # launch pi through the proxy
|
|
@@ -67222,9 +66926,6 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h
|
|
|
67222
66926
|
bili omp # launch omp through the proxy (pi-based; /bili/ rewrite)
|
|
67223
66927
|
bili hermes # launch hermes-agent through the proxy (/bili/ rewrite of ~/.hermes/config.yaml)
|
|
67224
66928
|
bili dsh --profile web "task" # launch deepseek-harness through the proxy (/bili/ rewrite of ~/.dsh/settings.yaml)
|
|
67225
|
-
bili codebuddy # launch codebuddy through the proxy (CODEBUDDY_BASE_URL /bili/ rewrite)
|
|
67226
|
-
bili qoder # launch qoder through the proxy (cert-MITM; model endpoint is hardcoded https, so no /bili/ rewrite)
|
|
67227
|
-
bili trae # launch Trae CLI through the proxy (cert-MITM; model host via TRAE_CLI_API_HOST or --mitm-domain)
|
|
67228
66929
|
bili test pi # quick end-to-end check of the pi path
|
|
67229
66930
|
bili --mitm-domain api.foo.com pi # add a domain to the MITM whitelist (flags precede the client)
|
|
67230
66931
|
bili -F http://127.0.0.1:7897 codex # route bili's upstream through a proxy (gost-style -F)
|