Merge pull request #37 from Askhz/fix/model-use

fix: 修复对话时模型不一致问题
This commit is contained in:
geroge 2026-04-22 18:03:19 +08:00 committed by GitHub
commit 3d86840c4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 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 {
// 初始化失败不阻断启动

View File

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