From de98d4a52d88665d4043f1007a6df4cfbd8f7a06 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 24 Oct 2025 11:05:45 +0200 Subject: [PATCH] Handles model changes when current model unavailable Improves model selection logic to automatically switch to the first available model when the current model is no longer valid Adds fallback mechanism to prevent potential configuration errors Logs model switching for debugging and transparency --- settings.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/settings.ts b/settings.ts index 253ad7a..d26090d 100644 --- a/settings.ts +++ b/settings.ts @@ -261,15 +261,22 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab { if (this.modelDropdown) { this.populateModelDropdown(this.modelDropdown); - // Restore selected model if it still exists + // Restore selected model if it still exists, otherwise use first available const currentModel = this.plugin.settings.model; const modelExists = this.availableModels.some(m => m.id === currentModel); + if (modelExists) { this.modelDropdown.setValue(currentModel); + } else if (this.availableModels.length > 0) { + // Model no longer available - update to first available model + const newModel = this.availableModels[0].id; + this.plugin.settings.model = newModel; + this.modelDropdown.setValue(newModel); + console.log(`Model '${currentModel}' no longer available, switched to '${newModel}'`); } } - // Save updated cache + // Save updated cache and any model changes await this.plugin.saveSettings(); } catch (error) { console.error('Error refreshing models:', error);