Adds dynamic Claude model fetching and management #1

Merged
AlexKucera merged 60 commits from dynamic-models into master 2025-10-31 13:42:04 +01:00
Showing only changes of commit 1c1cba6ce5 - Show all commits
+20 -3
View File
1
@@ -176,9 +176,9 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab {
if (this.availableModels.length > 0) { if (this.availableModels.length > 0) {
dropdown.setValue(this.plugin.settings.model); dropdown.setValue(this.plugin.settings.model);
} }
dropdown.onChange(async (value) => { dropdown.onChange((value) => {
this.plugin.settings.model = value; this.plugin.settings.model = value;
await this.plugin.saveSettings(); this.debounceSaveSettings();
}); });
}); });
@@ -292,6 +292,18 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab {
const notice = new Notice('Cache cleared'); const notice = new Notice('Cache cleared');
setTimeout(() => notice.hide(), 2000); setTimeout(() => notice.hide(), 2000);
})); }));
new Setting(containerEl)
.setName('Clear Model List Cache')
.setDesc('Clear cached Claude model list to force a fresh fetch from the API')
.addButton(button => button
.setButtonText('Clear Models Cache')
.onClick(() => {
this.plugin.modelService.clearCache();
// Show a temporary notice
const notice = new Notice('Model list cache cleared');
setTimeout(() => notice.hide(), 2000);
}));
} }
// MARK: - Model Loading // MARK: - Model Loading
@@ -338,7 +350,12 @@ export class FreewritingPromptsSettingTab extends PluginSettingTab {
} else { } else {
// Fall back to first available model if current one is gone // Fall back to first available model if current one is gone
const fallbackModel = this.availableModels[0]; const fallbackModel = this.availableModels[0];
if (fallbackModel && this.plugin.settings.model !== fallbackModel.id) { if (!fallbackModel) {
// Edge case: both API and fallback returned empty
this.modelDropdown.setDisabled(true);
this.modelDropdown.selectEl.empty();
this.modelDropdown.addOption('', 'No models available');
} else if (this.plugin.settings.model !== fallbackModel.id) {
this.modelDropdown.setValue(fallbackModel.id); this.modelDropdown.setValue(fallbackModel.id);
this.plugin.settings.model = fallbackModel.id; this.plugin.settings.model = fallbackModel.id;
await this.plugin.saveSettings(); await this.plugin.saveSettings();