Skip to content

fix: SDK 模型列表应合并而非替换默认列表#369

Open
yike-gunshi wants to merge 1 commit intoop7418:mainfrom
yike-gunshi:fix/env-models-merge-not-replace
Open

fix: SDK 模型列表应合并而非替换默认列表#369
yike-gunshi wants to merge 1 commit intoop7418:mainfrom
yike-gunshi:fix/env-models-merge-not-replace

Conversation

@yike-gunshi
Copy link

关联 Issue

Fixes #367

问题

/api/providers/models 的 env provider 处理逻辑中,getCachedModels('env') 返回的 SDK 模型列表会完全替换 DEFAULT_MODELS

如果 supportedModels() 只返回了部分模型(比如只有 Sonnet),其他模型(Opus、Haiku)就从选择器里消失了。重启后缓存为空,又会显示完整的默认列表,所以表现为"用着用着模型就少了,重启又好了"。

修复

把替换改为合并:SDK 返回的模型优先(带有 supportsEffort 等更丰富的元数据),但 SDK 没返回的默认模型保留在列表末尾。

// 之前:直接替换
groups[0].models = sdkEntries;

// 之后:合并,保留 SDK 没覆盖到的默认模型
const sdkIds = new Set(sdkEntries.map(m => m.value));
const missing = groups[0].models.filter(m => !sdkIds.has(m.value));
groups[0].models = [...sdkEntries, ...missing];

改动很小,只动了 route.ts 一个文件,+9 -2 行。

When getCachedModels('env') returns a partial list (e.g. only Sonnet),
the env provider group loses models like Opus because the SDK result
completely replaces DEFAULT_MODELS.

Change the logic to merge: SDK models take precedence (richer metadata),
but any default models missing from the SDK response are preserved.

Fixes op7418#367
@vercel
Copy link

vercel bot commented Mar 23, 2026

Someone is attempting to deploy a commit to the op7418's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

OAuth模式下Opus 4.6用着用着就从模型列表消失了

1 participant