fix: model switch reset, custom provider resolution and base_url_env cleanup (#212)
* fix: reset entire config.model on model switch Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: resolve custom provider from CLI config and clean base_url_env on delete - When config.model.provider is "custom" (set by hermes CLI), match base_url + model against custom_providers to resolve custom:name - Clear base_url_env from .env when deleting a builtin provider Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,18 @@ export async function getAvailable(ctx: any) {
|
||||
if (typeof modelSection === 'object' && modelSection !== null) {
|
||||
currentDefault = String(modelSection.default || '').trim()
|
||||
currentDefaultProvider = String(modelSection.provider || '').trim()
|
||||
// When hermes CLI sets provider: custom, resolve to custom:name
|
||||
// by matching base_url + model against custom_providers
|
||||
if (currentDefaultProvider === 'custom' && currentDefault) {
|
||||
const cps = Array.isArray(config.custom_providers) ? config.custom_providers as any[] : []
|
||||
const match = cps.find(
|
||||
(cp: any) => cp.base_url?.replace(/\/+$/, '') === String(modelSection.base_url || '').replace(/\/+$/, '')
|
||||
&& cp.model === currentDefault,
|
||||
)
|
||||
if (match) {
|
||||
currentDefaultProvider = `custom:${match.name.trim().toLowerCase().replace(/ /g, '-')}`
|
||||
}
|
||||
}
|
||||
} else if (typeof modelSection === 'string') {
|
||||
currentDefault = modelSection.trim()
|
||||
}
|
||||
@@ -137,10 +149,8 @@ export async function setConfigModel(ctx: any) {
|
||||
}
|
||||
try {
|
||||
const config = await readConfigYaml()
|
||||
if (typeof config.model !== 'object' || config.model === null) { config.model = {} }
|
||||
config.model = {}
|
||||
config.model.default = defaultModel
|
||||
delete config.model.base_url
|
||||
delete config.model.api_key
|
||||
if (reqProvider) { config.model.provider = reqProvider }
|
||||
await writeConfigYaml(config)
|
||||
ctx.body = { success: true }
|
||||
|
||||
@@ -143,6 +143,7 @@ export async function remove(ctx: any) {
|
||||
const envMapping = PROVIDER_ENV_MAP[poolKey]
|
||||
if (envMapping?.api_key_env) {
|
||||
await saveEnvValue(envMapping.api_key_env, '')
|
||||
if (envMapping.base_url_env) { await saveEnvValue(envMapping.base_url_env, '') }
|
||||
} else if (!envMapping?.api_key_env) {
|
||||
try {
|
||||
const authPath = getActiveAuthPath()
|
||||
|
||||
Reference in New Issue
Block a user