fix: preserve OpenAI-like provider settings when switching modes

- Save current provider configuration when switching to a mode without saved config
- Re-activate custom OpenAI provider profiles to ensure settings persist
- Fixes issue where Jan.ai and other OpenAI-compatible provider settings were lost

Fixes #8583
This commit is contained in:
Roo Code 2025-10-09 19:30:40 +00:00
parent 507a600ee9
commit 0e3fe0e8f8

View file

@ -1211,14 +1211,20 @@ export class ClineProvider
await this.activateProviderProfile({ name: profile.name })
}
} else {
// If no saved config for this mode, save current config as default.
// If no saved config exists for this mode, handle the current configuration
const currentApiConfigName = this.getGlobalState("currentApiConfigName")
const currentConfig = listApiConfig.find(({ name }) => name === currentApiConfigName)
if (currentApiConfigName) {
const config = listApiConfig.find((c) => c.name === currentApiConfigName)
if (currentApiConfigName && currentConfig?.id) {
// Always save the current config as the default for the new mode
// This ensures that custom OpenAI providers (and all other providers) persist across mode switches
await this.providerSettingsManager.setModeConfig(newMode, currentConfig.id)
if (config?.id) {
await this.providerSettingsManager.setModeConfig(newMode, config.id)
// For custom OpenAI providers, we need to ensure the configuration is properly loaded
// The "openai" provider is the customizable one that users configure for OpenAI-compatible endpoints
if (currentConfig.apiProvider === "openai") {
// Re-activate the profile to ensure all settings are properly loaded
await this.activateProviderProfile({ name: currentConfig.name })
}
}
}