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 <noreply@anthropic.com>
This commit is contained in:
Askhz 2026-04-22 15:48:15 +08:00
parent 3e8a82d01c
commit 98c9f219f7
2 changed files with 7 additions and 15 deletions

View File

@ -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
}

View File

@ -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 {
// 初始化失败不阻断启动