Skip to content

fix(models): resolve catalog limits for models configured under a foreign provider#258

Merged
su-fen merged 1 commit into
mainfrom
features
Jul 24, 2026
Merged

fix(models): resolve catalog limits for models configured under a foreign provider#258
su-fen merged 1 commit into
mainfrom
features

Conversation

@su-fen

@su-fen su-fen commented Jul 24, 2026

Copy link
Copy Markdown
Member

问题

各供应商原生目录下的模型限额显示正确,但把 A 家模型配置到 B 家供应商类型下(中转聚合的常见用法)时元数据错误。最典型的例子:grok-4.5 在 xai 供应商下显示正确的 500K/32K,配到 Anthropic 兼容供应商下却显示 claude_code 兜底值 200K/32K。

根因:目录查找 getProviderModelDefaults 只在本供应商类型对应的目录分区里检索,跨供应商配置必然 miss 并落到本供应商兜底限额。

修复

lib/models/modelCatalog.ts(镜像文件,两端字节一致)

  • 新增 findCatalogModelAcrossProviders / resolveModelLimitsAcrossProviders:按模型 id 跨全部目录分区回查,装饰 id 候选链(大小写、@版本[1m]、日期后缀)同样生效;目录 id 全局唯一已由不变量测试锁死,回查无歧义。
  • 新增 repairStaleCrossProviderLimits:修复本 fix 之前已落库的坏默认值——存量恰等于本供应商兜底对、且模型只在别家目录分区可命中时替换为真实限额;任一值偏离兜底对即视为用户显式配置,原样保留。

两端 lib/settings/index.ts(GUI 与 WebUI 手动同步)

  • getProviderModelDefaults 查找顺序:本供应商目录命中 → claude_code 的 [1m]/adaptive 启发式 → 跨供应商回查(新增) → 供应商兜底。启发式优先于回查是刻意的:[1m] 后缀是用户对部署窗口的显式声明;Anthropic 的 1M/adaptive 窗口策略只约束目录内的 Anthropic 模型,跨供应商命中直接透传目录值。
  • normalizeProviderModelConfig 读侧接入存量修复:已存在的错误配置打开设置即自动修正,无需删除重加。

行为确认

  • grok-4.5 配在 anthropic 下:200K/32K → 500K/32K,与 xai 原生下一致;claude 模型配在 codex/xai 下、gemini 模型配在别家下同理。
  • 原生供应商下的模型、全目录未收录的自定义模型、anthropic [1m]/adaptive 启发式与窗口钳制:行为全部不变(anthropic-long-context 测试零改动通过)。
  • 已知副作用(接受):grok-4.5 挂 anthropic 中转后窗口默认 500K > 200K,请求会携带 context-1m beta 头——与用户手动配置 500K 的既有行为一致。

测试

  • 新增用例:目录 id 全局唯一不变量、跨供应商回查(含装饰 id 与 miss 路径)、repairStaleCrossProviderLimits 四种边界、getProviderModelDefaults 三个方向的跨供应商解析与优先级、读侧存量修复。
  • GUI test:frontend 1222 通过、Web npm test 413 通过、两端 tsc --noEmit 与 biome 干净、scripts/check-mirror.mjs 104 个文件全部一致。

🤖 Generated with Claude Code

…eign provider

Relay/aggregator setups often attach one vendor's model to another
vendor's provider type (e.g. grok-4.5 on an Anthropic-compatible relay).
The catalog lookup was scoped to the provider's own section, so such
models missed and fell back to the provider fallback limits (grok-4.5
under claude_code showed 200K/32K instead of its real 500K/32K).

- modelCatalog.ts (mirrored): add findCatalogModelAcrossProviders /
  resolveModelLimitsAcrossProviders (id is globally unique across the
  catalog, locked by the invariants test) and
  repairStaleCrossProviderLimits for limits persisted before this fix.
- getProviderModelDefaults (both frontends): scoped hit -> claude_code
  [1m]/adaptive heuristics -> cross-provider lookup -> provider
  fallback. The heuristic stays ahead of the lookup because a [1m]
  suffix is the user's explicit deployment-window declaration; the
  Anthropic window policy only governs catalog Anthropic models, so
  cross-provider hits pass catalog values through untouched.
- normalizeProviderModelConfig (both frontends): repair stored limits
  that exactly equal the provider fallback pair when the model only
  resolves in a foreign catalog section, so existing configs fix
  themselves on read without re-adding the model.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@su-fen
su-fen merged commit 30a5be1 into main Jul 24, 2026
7 checks passed
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