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 1/2] 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 { // 初始化失败不阻断启动 From 772739c6c9417557bf1588f23fd4dccfbef39a84 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Wed, 22 Apr 2026 16:09:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=9C=A8=20CoStrict=20provider=20?= =?UTF-8?q?=E4=B8=8B=E4=BE=A7=E6=9F=A5=E8=AF=A2=E7=BB=9F=E4=B8=80=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=BB=E5=BE=AA=E7=8E=AF=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- src/utils/model/model.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/model/model.ts b/src/utils/model/model.ts index 61cccbcf9..21a8f7c49 100644 --- a/src/utils/model/model.ts +++ b/src/utils/model/model.ts @@ -36,6 +36,8 @@ export type ModelSetting = ModelName | ModelAlias | null export function getSmallFastModel(): ModelName { const provider = getAPIProvider() + // CoStrict has no haiku alias — use the main loop model to stay on the same provider + if (provider === 'costrict') return getMainLoopModel() // Provider-specific small fast model if (provider === 'openai' && process.env.OPENAI_SMALL_FAST_MODEL) { return process.env.OPENAI_SMALL_FAST_MODEL @@ -149,6 +151,8 @@ export function getDefaultOpusModel(): ModelName { // @[MODEL LAUNCH]: Update the default Sonnet model (3P providers may lag so keep defaults unchanged). export function getDefaultSonnetModel(): ModelName { const provider = getAPIProvider() + // CoStrict has no sonnet alias — use the main loop model to stay on the same provider + if (provider === 'costrict') return getMainLoopModel() // For OpenAI provider, check OPENAI_DEFAULT_SONNET_MODEL first if (provider === 'openai' && process.env.OPENAI_DEFAULT_SONNET_MODEL) { return process.env.OPENAI_DEFAULT_SONNET_MODEL @@ -171,6 +175,8 @@ export function getDefaultSonnetModel(): ModelName { // @[MODEL LAUNCH]: Update the default Haiku model (3P providers may lag so keep defaults unchanged). export function getDefaultHaikuModel(): ModelName { const provider = getAPIProvider() + // CoStrict has no haiku alias — use the main loop model to stay on the same provider + if (provider === 'costrict') return getMainLoopModel() // For OpenAI provider, check OPENAI_DEFAULT_HAIKU_MODEL first if (provider === 'openai' && process.env.OPENAI_DEFAULT_HAIKU_MODEL) { return process.env.OPENAI_DEFAULT_HAIKU_MODEL