Skip to content

feat: named provider entries bind onto their URL lanes - #1466

Closed
ranxianglei wants to merge 2 commits into
2026-09-26_non-http-providers-opt-infrom
2026-09-26_named-provider-routes
Closed

ranxianglei wants to merge 2 commits into
2026-09-26_non-http-providers-opt-infrom
2026-09-26_named-provider-routes

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1465. Stacked on #1437 (the providers-table compactionOptIn shape).

What

providers keys may be provider names (any non-URL string). Under bili <client> launches the launcher hands the spawned proxy a name→URL map (BILI_LAUNCHER_NAME_ROUTES, discovered from the client's own config — the same pairs BILI_PROVIDER_REWRITES is built from), and loadRoutes flattens each name-keyed entry onto its URL lane:

"providers": {
  "https://api.openai.com": { "compress": { "modelContextLimit": 111000 } },
  "main": { "compress": { "absorb": { "enabled": true } } }  // = same upstream
}
  • Explicit URL entry wins every conflict; the named entry fills gaps (deep merge; per-model too).
  • Origin-form key normalization identical to hand-written URL keys; non-http(s) targets and unmapped names stay inert.
  • Zero wire changes — three-level compress resolves through the existing machinery.

Where

  • src/config.ts: NAME_ROUTES_ENV / parseLauncherNameRoutes / flattenNamedRoutes / deepMergeRoute; loadRoutes applies flattening.
  • src/launcher.ts: collectNameRoutes(discovered) (http+https rewrite lanes → origin pairs), nameRoutes spawn opt → child env, wired at both ensureProxyRunning call sites.
  • tests/named-provider-routes.test.ts: 7 tests (parse/flatten precedence/gap-fill/per-model/inert cases/loadRoutes e2e through resolveCompress/collector).
  • CONFIGURATION.md + zh: named-alias paragraph + example.

Gates: typecheck ✓ · targeted suites 238+7+36+7 pass, 0 fail · build ✓.

Non-goal (documented in #1465): URL-less providers (claude-bridge) need a manifest settings channel for three-level support — deferred.

providers keys can now be provider NAMES, not just URL prefixes. Under
bili <client> launches the launcher already discovers each client's own
name→upstream-URL pairs (the same sources BILI_PROVIDER_REWRITES is built
from); it now hands them to the spawned proxy via BILI_LAUNCHER_NAME_ROUTES
and loadRoutes flattens each name-keyed entry onto its URL lane:

  providers: {
    "https://api.openai.com": { compress: { ... } },
    "main": { compress: { absorb: { enabled: true } } }   // = same upstream
  }

- Explicit URL-keyed entry wins every conflict; the named entry fills gaps
  (deep merge over compress / models / scalar fields).
- Per-model entries merge per model, URL side winning.
- Targets normalized to origin form (protocol//host) like hand-written URL
  keys; non-http(s) targets and unmapped names stay inert — without a
  launcher mapping (plain bili start) a named entry carries only
  agent-side fields such as compactionOptIn (#1392).
- Zero wire changes: three-level compress (global → provider → model)
  resolves through the existing machinery once the lane exists.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 开始 review PR #1466(named provider entries bind onto their URL lanes,stacked on #1437)。流程:先审原 issue #1465 方向 → 拉分支核对代码/回归面 → 本地跑 typecheck/定向测试/build → 出结论。稍后给完整结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:可以合并(需先合 #1437,stacked base)。中文摘要:实现了 providers 表按 provider 名字绑定 URL 车道(#1465 owner 拍板方案),零 wire 变更,回归面逐项核对无破坏,本地 typecheck/全量测试/build 全绿,CI 五个真实客户端 e2e lane 全绿。

① 原 issue 方向(#1465)

Owner directive 明确要求「名字映射为 agents 里面的配置, 最终还是 url」,PR 精确实现:name-keyed entry 经 launcher 发现的 name→URL 映射(BILI_LAUNCHER_NAME_ROUTES)flatten 到 URL 车道,三级压缩走既有 resolveCompress 机制。Non-goal(URL-less providers / claude-bridge)已文档化并 defer。方向无误。另注:#1465 正文写的「PR: #1463」是笔误,#1463 是 ccr fix,实际 PR 是本条 #1466,建议修正交叉引用。

② 回归审查(既有行为清单)

  • loadRoutes 无 env 时行为不变:parseLauncherNameRoutes 对缺失/坏 JSON/非对象 env 一律返回 {} → flattenNamedRoutes 退化为浅拷贝,内容逐键相同。裸 bili start、launcher 自身进程、web 进程均不受影响。✓
  • name key 此前即存于 routes map 且路由惰性:findRoute(src/config.ts:505)是最长前缀匹配,name 字符串不可能是 http(s):// URL 的前缀,故旧行为 = inert;本 PR 只在「launcher 启动 + name 命中客户端发现的名字」时才生效 —— 即 feature 本身,见下方行为披露。✓
  • [investigation] Non-http baseUrl providers (pi-claude-bridge etc.): an opt-in path to ride bili — beyond the #1383 stopgap veto #1392 compactionOptIn 路径不受影响:resolveNonHttpProviders(src/config.ts:993)直接读原始 config file 而非 loadRoutes,flatten 碰不到它;且 parseRouteEntry(src/config.ts:1262)白名单不含 compactionOptIn,deepMergeRoute 注释的声明属实(已核实)。✓
  • runTestPi 改动等价:discoverDomains(client, config) 的定义就是 discoverRoutes(client, config).httpsDomains(src/launcher.ts:822-824),换成复用同一次 discovery 结果,行为逐字节相同。✓
  • wire 零变更:diff 仅触 config.ts / launcher.ts / tests / docs,server、loop、adapters、stream 一行未动;「zero wire changes」声明成立。两种压缩模式(plugin/proxy)均不涉及注入路径。✓
  • hot reload 一致:/__bili/config/reload(src/server.ts:5608)在 proxy 进程内重跑 loadRoutes(),env 存在则同样 flatten,重启前配置视图一致。✓
  • web UI:GET /config 的 providers 视图在 launcher 派生 proxy 下会显示 flatten 后的有效车道(readProviders = loadRoutes)——与既有 ACP_PROVIDERS 外部文件条目出现在同一视图的模式一致;PUT 只写请求体、不与视图合并回盘,无 config clobber 风险。✓

行为变更披露(Deliverables #4):旧行为 = name-keyed providers 条目对路由完全惰性(仅承载 compactionOptIn);新行为 = 在 bili <client> 下,若名字命中客户端配置里发现的同名 provider,其字段(compress/models/proxy 等白名单字段)开始作用于该上游的 URL 车道,显式 URL 键冲突胜出、命名条目只补空缺。这是 feature 的预期语义,CONFIGURATION.md(+zh)已同步文档化。裸 bili start 不变。

③ 代码审查

解析防御到位(坏 JSON/空串/数组/非 string value 全丢弃,不抛错);deepMergeRoute 递归正确(plain object 递归、base 冲突胜、base undefined 才补);origin-form 归一化与手写键共用 normalizeUrlKey,findRoute 最长前缀保证更具体的手写 path 键仍胜过 flatten 出的 origin 键。两个非阻塞 nit(不建议为此加 commit):

  1. 两个不同 name 映射到同一上游时,合并顺序随 env JSON 的 Object.entries 序,先者胜 —— 确定性但任意,未测;
  2. 无既有 URL 车道时命名条目以引用放入(out[name] 与 out[urlKey] 共享对象),当前所有消费方只读 routes,无实际危害。

④ 测试有效性

7 个测试断言有牙(精确值 deepEqual/equal),含一个真 e2e:临时 config file(BILI_CONFIG_FILE)→ loadRoutes(env) → resolveCompress 三级解析,能抓住「不再绑定」「优先级反转」「gap-fill 失效」任一回退;collector 测试覆盖双 rewrite lane + 坏 URL + 空 key。缺口(可接受):dual-name-same-target 顺序用例缺失;ensureProxyRunning spawn-env 接线行未被单测直接钉住(CI e2e lane 间接覆盖)。

⑤ diff 整洁度

单 commit,5 文件,+227/-7,全部与本 PR 目的相关;无空白重排、无 lockfile/version 变动、无生成物。干净。

门

本地(PR head 57def46):typecheck ✓ · build ✓ · 全量测试 2893 tests / 2881 pass / 0 fail / 12 skipped ✓
CI(head commit):real opencode / pi / codex / dsh e2e lane + hermetic registry e2e 共 5 job 全 success;mergeable: clean。

注意:base 是 2026-09-26_non-http-providers-opt-in(#1437,仍 open),须待 #1437 先行合并;该 base 已包含当前 master(b371bd0),无 stale-base 风险。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Closed without merging per owner decision: land this in one shot, not staged — the full design (bind aliasing + inertness guard + launcher wiring + acceptance criteria) is preserved in #1469, including everything explored on this branch (head 3fab012). Nothing here is lost; the branch remains available for reference/salvage when implementing #1469.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant