From 98c9f219f7530d21c80e1095c537f61888706168 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Wed, 22 Apr 2026 15:48:15 +0800 Subject: [PATCH] fix: pass through user-configured model name instead of overriding with first API model CoStrict provider now directly passes the user's configured model name to the API, instead of replacing it with the first model from the /ai-gateway/api/v1/models list. Co-Authored-By: Claude Opus 4.6 --- src/costrict/provider/modelMapping.ts | 17 +++++------------ src/setup.ts | 5 ++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/costrict/provider/modelMapping.ts b/src/costrict/provider/modelMapping.ts index 73a415f3d..ac8ecae7c 100644 --- a/src/costrict/provider/modelMapping.ts +++ b/src/costrict/provider/modelMapping.ts @@ -17,10 +17,9 @@ function getModelFamily(model: string): 'haiku' | 'sonnet' | 'opus' | null { * * 优先级: * 1. 传入的 model 本身就是已知的 CoStrict 模型 ID(用户通过 /model 明确选择) - * 2. COSTRICT_MODEL 环境变量(管理员全局覆盖 / 登录默认值) - * 3. COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量(按模型族) - * 4. 已缓存的 CoStrict 模型列表中的第一个 - * 5. 直接透传原始模型名(最后兜底) + * 2. COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量(按模型族) + * 3. 直接透传原始模型名(用户手动配置的模型名) + * 4. COSTRICT_MODEL 环境变量(仅作为最终兜底) */ export function resolveCoStrictModel(anthropicModel: string): string { const cleanModel = anthropicModel.replace(/\[1m\]$/, '') @@ -29,10 +28,7 @@ export function resolveCoStrictModel(anthropicModel: string): string { const cached = getCachedCoStrictModels() if (cached.some(m => m.id === cleanModel)) return cleanModel - // 优先级 2: COSTRICT_MODEL 环境变量 - if (process.env.COSTRICT_MODEL) return process.env.COSTRICT_MODEL - - // 优先级 3: COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量 + // 优先级 2: COSTRICT_DEFAULT_{FAMILY}_MODEL 环境变量 const family = getModelFamily(cleanModel) if (family) { const envVar = `COSTRICT_DEFAULT_${family.toUpperCase()}_MODEL` @@ -40,9 +36,6 @@ export function resolveCoStrictModel(anthropicModel: string): string { if (override) return override } - // 优先级 4: 缓存中的第一个模型 - if (cached.length > 0) return cached[0].id - - // 优先级 5: 透传原始模型名 + // 优先级 3: 直接透传原始模型名(用户手动配置的模型名优先于环境变量) return cleanModel } diff --git a/src/setup.ts b/src/setup.ts index d2bb9451d..eca42d030 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -433,9 +433,8 @@ export async function setup( // 预取模型列表,填充同步缓存 const baseUrl = getCoStrictBaseURL(activeCreds.base_url) const models = await fetchCoStrictModels(baseUrl, activeCreds.access_token) - if (models.length > 0 && !process.env.COSTRICT_MODEL) { - process.env.COSTRICT_MODEL = models[0].id - } + // 模型列表已预取并缓存,不再自动设置 COSTRICT_MODEL 环境变量 + // resolveCoStrictModel() 会直接透传用户配置的模型名 process.env.CLAUDE_CODE_USE_COSTRICT = '1' } catch { // 初始化失败不阻断启动