feat: cleanup CLAUDE_CODE_USE_COSTRICT env var after provider switch
- Remove env var in provider.ts unset/anthropic/openai/gemini/grok handlers - Remove env var after OAuth login and model save success in ConsoleOAuthFlow - Fix modelOptions.ts to only show CoStrict models when provider IS costrict - Remove unused hasCoStrictCredentialsSync import and getCoStrictLoginOption
This commit is contained in:
parent
d7bcf65968
commit
425ca6bb19
|
|
@ -53,6 +53,7 @@ const call: LocalCommandCall = async (args, context) => {
|
||||||
delete process.env.CLAUDE_CODE_USE_OPENAI
|
delete process.env.CLAUDE_CODE_USE_OPENAI
|
||||||
delete process.env.CLAUDE_CODE_USE_GEMINI
|
delete process.env.CLAUDE_CODE_USE_GEMINI
|
||||||
delete process.env.CLAUDE_CODE_USE_GROK
|
delete process.env.CLAUDE_CODE_USE_GROK
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
return {
|
return {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
value: 'API provider cleared (will use environment variables).',
|
value: 'API provider cleared (will use environment variables).',
|
||||||
|
|
@ -131,6 +132,7 @@ const call: LocalCommandCall = async (args, context) => {
|
||||||
delete process.env.CLAUDE_CODE_USE_OPENAI
|
delete process.env.CLAUDE_CODE_USE_OPENAI
|
||||||
delete process.env.CLAUDE_CODE_USE_GEMINI
|
delete process.env.CLAUDE_CODE_USE_GEMINI
|
||||||
delete process.env.CLAUDE_CODE_USE_GROK
|
delete process.env.CLAUDE_CODE_USE_GROK
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
// Update settings.json
|
// Update settings.json
|
||||||
updateSettingsForSource('userSettings', { modelType: arg })
|
updateSettingsForSource('userSettings', { modelType: arg })
|
||||||
// Ensure settings.env gets applied to process.env
|
// Ensure settings.env gets applied to process.env
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,8 @@ export function ConsoleOAuthFlow({
|
||||||
}
|
}
|
||||||
// Reset modelType to anthropic when using OAuth login
|
// Reset modelType to anthropic when using OAuth login
|
||||||
updateSettingsForSource('userSettings', { modelType: 'anthropic' } as any)
|
updateSettingsForSource('userSettings', { modelType: 'anthropic' } as any)
|
||||||
|
// Clear costrict env var to prevent conflicts
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
|
|
||||||
setOAuthStatus({ state: 'success' })
|
setOAuthStatus({ state: 'success' })
|
||||||
void sendNotification(
|
void sendNotification(
|
||||||
|
|
@ -725,6 +727,8 @@ function OAuthStatusMessage({
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
||||||
|
// Clear costrict env var to prevent conflicts when using custom platform
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
setOAuthStatus({ state: 'success' })
|
setOAuthStatus({ state: 'success' })
|
||||||
void onDone()
|
void onDone()
|
||||||
}
|
}
|
||||||
|
|
@ -945,6 +949,8 @@ function OAuthStatusMessage({
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
||||||
|
// Clear costrict env var to prevent conflicts when using OpenAI
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
setOAuthStatus({ state: 'success' })
|
setOAuthStatus({ state: 'success' })
|
||||||
void onDone()
|
void onDone()
|
||||||
}
|
}
|
||||||
|
|
@ -1178,6 +1184,8 @@ function OAuthStatusMessage({
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
for (const [k, v] of Object.entries(env)) process.env[k] = v
|
||||||
|
// Clear costrict env var to prevent conflicts when using Gemini
|
||||||
|
delete process.env.CLAUDE_CODE_USE_COSTRICT
|
||||||
setOAuthStatus({ state: 'success' })
|
setOAuthStatus({ state: 'success' })
|
||||||
void onDone()
|
void onDone()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ import {
|
||||||
} from './model.js'
|
} from './model.js'
|
||||||
import { has1mContext } from '../context.js'
|
import { has1mContext } from '../context.js'
|
||||||
import { getGlobalConfig } from '../config.js'
|
import { getGlobalConfig } from '../config.js'
|
||||||
import { hasCoStrictCredentialsSync } from '../../costrict/provider/credentials.js'
|
|
||||||
|
|
||||||
// @[MODEL LAUNCH]: Update all the available and default model option strings below.
|
// @[MODEL LAUNCH]: Update all the available and default model option strings below.
|
||||||
|
|
||||||
|
|
@ -380,10 +379,8 @@ function getModelOptionsBase(fastMode = false): ModelOption[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoStrict provider: 从缓存中动态展示 CoStrict 可用模型
|
// CoStrict provider: 从缓存中动态展示 CoStrict 可用模型
|
||||||
// 也覆盖其他 provider 但用户已有 CoStrict 凭证的场景(modelType 丢失/竞态)
|
|
||||||
const isCoStrictProvider = getAPIProvider() === 'costrict'
|
const isCoStrictProvider = getAPIProvider() === 'costrict'
|
||||||
const hasCoStrictCreds = hasCoStrictCredentialsSync()
|
if (isCoStrictProvider) {
|
||||||
if (isCoStrictProvider || hasCoStrictCreds) {
|
|
||||||
// 延迟 require 避免循环依赖,且该模块只在 costrict provider 下加载
|
// 延迟 require 避免循环依赖,且该模块只在 costrict provider 下加载
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
const { getCachedCoStrictModels } =
|
const { getCachedCoStrictModels } =
|
||||||
|
|
@ -414,21 +411,27 @@ function getModelOptionsBase(fastMode = false): ModelOption[] {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户没有 CoStrict 凭证,显示推荐登录选项
|
// PAYG 用户:展示标准模型选项(Sonnet, Opus, Haiku 等)
|
||||||
return [getCoStrictLoginOption()]
|
const paygOptions = [getDefaultOptionForUser(fastMode)]
|
||||||
}
|
const customSonnet = getCustomSonnetOption()
|
||||||
|
if (customSonnet) {
|
||||||
/**
|
paygOptions.push(customSonnet)
|
||||||
* CoStrict 登录推荐选项
|
} else {
|
||||||
* 当用户未登录 CoStrict 时显示,提示用户可以登录以使用 CoStrict 模型
|
paygOptions.push(getSonnet46Option())
|
||||||
*/
|
|
||||||
function getCoStrictLoginOption(): ModelOption {
|
|
||||||
return {
|
|
||||||
value: 'costrict-login',
|
|
||||||
label: 'CoStrict (Recommended)',
|
|
||||||
description:
|
|
||||||
'Sign in to CoStrict for more models and better pricing · Run /login and select CoStrict',
|
|
||||||
}
|
}
|
||||||
|
const customOpus = getCustomOpusOption()
|
||||||
|
if (customOpus) {
|
||||||
|
paygOptions.push(customOpus)
|
||||||
|
} else {
|
||||||
|
paygOptions.push(getOpus46Option(fastMode))
|
||||||
|
}
|
||||||
|
const customHaiku = getCustomHaikuOption()
|
||||||
|
if (customHaiku) {
|
||||||
|
paygOptions.push(customHaiku)
|
||||||
|
} else {
|
||||||
|
paygOptions.push(getHaikuOption())
|
||||||
|
}
|
||||||
|
return paygOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// @[MODEL LAUNCH]: Add the new model ID to the appropriate family pattern below
|
// @[MODEL LAUNCH]: Add the new model ID to the appropriate family pattern below
|
||||||
|
|
@ -549,11 +552,6 @@ export function getModelOptions(fastMode = false): ModelOption[] {
|
||||||
} else if (initialMainLoopModel !== null) {
|
} else if (initialMainLoopModel !== null) {
|
||||||
customModel = initialMainLoopModel
|
customModel = initialMainLoopModel
|
||||||
}
|
}
|
||||||
// 忽略 costrict-login 伪模型值(用户点击了推荐登录选项但未完成登录)
|
|
||||||
if (customModel === 'costrict-login') {
|
|
||||||
return filterModelOptionsByAllowlist(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customModel === null || options.some(opt => opt.value === customModel)) {
|
if (customModel === null || options.some(opt => opt.value === customModel)) {
|
||||||
return filterModelOptionsByAllowlist(options)
|
return filterModelOptionsByAllowlist(options)
|
||||||
} else if (customModel === 'opusplan') {
|
} else if (customModel === 'opusplan') {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user