From 9ebae850bdb14ed4c50fc56198ea7ef43149103e Mon Sep 17 00:00:00 2001 From: yike-gunshi Date: Mon, 23 Mar 2026 09:39:25 +0800 Subject: [PATCH] fix: merge SDK models with defaults instead of replacing 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 #367 --- src/app/api/providers/models/route.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/api/providers/models/route.ts b/src/app/api/providers/models/route.ts index 740d97e3..7890c5ca 100644 --- a/src/app/api/providers/models/route.ts +++ b/src/app/api/providers/models/route.ts @@ -64,12 +64,15 @@ export async function GET() { }), }); - // If SDK has discovered models, use them for the env group + // If SDK has discovered models, merge them into the default list. + // SDK models carry richer metadata (supportsEffort, etc.) so they take + // precedence, but default models missing from the SDK response are kept + // to avoid models disappearing when supportedModels() returns a partial list. try { const { getCachedModels } = await import('@/lib/agent-sdk-capabilities'); const sdkModels = getCachedModels('env'); if (sdkModels.length > 0) { - groups[0].models = sdkModels.map(m => { + const sdkEntries = sdkModels.map(m => { const cw = getContextWindow(m.value); return { value: m.value, @@ -81,6 +84,10 @@ export async function GET() { ...(cw != null ? { contextWindow: cw } : {}), }; }); + // Append default models that the SDK didn't return + 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]; } } catch { // SDK capabilities not available, keep defaults