Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

if (currentApiConfigName) {
const config = listApiConfig.find((c) => c.name === currentApiConfigName)

if (config?.id) {
await this.providerSettingsManager.setModeConfig(newMode, config.id)
const currentConfig = listApiConfig.find(({ name }) => 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)

// 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") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The comment mentions "custom OpenAI providers" but the check is for apiProvider === "openai". Consider clarifying that this applies to all OpenAI-compatible providers configured through the "openai" provider type, not just custom ones. This would make the intent clearer for future maintainers.

// Re-activate the profile to ensure all settings are properly loaded
await this.activateProviderProfile({ name: currentConfig.name })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Consider adding error handling around the activateProviderProfile call. If activation fails, the mode switch will still complete but the provider settings might not be fully loaded.

Suggested change
await this.activateProviderProfile({ name: currentConfig.name })
try {
await this.activateProviderProfile({ name: currentConfig.name })
} catch (error) {
this.log(`Failed to re-activate OpenAI provider profile during mode switch: ${error instanceof Error ? error.message : String(error)}`)
}

}
}
}
Expand Down