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 13645af300 - Show all commits
+17 -3
View File
@@ -2,7 +2,7 @@
// ABOUTME: Coordinates between services, commands, and Obsidian's plugin lifecycle
import { Editor, MarkdownView, Notice, Plugin } from 'obsidian';
import { FreewritingPromptsSettings, FreewritingPromptsData } from './types';
import { FreewritingPromptsSettings, FreewritingPromptsData, ModelCache } from './types';
import { DEFAULT_SETTINGS, FreewritingPromptsSettingTab } from './settings';
import { PromptGeneratorService } from './services/promptGenerator';
import { ModelService } from './services/modelService';
@@ -50,11 +50,25 @@ export default class FreewritingPromptsPlugin extends Plugin {
*/
async onload() {
// Load data once and use it for both settings and model cache
// Guard against corrupted persisted data to prevent plugin load failure
let modelCache: ModelCache | undefined;
try {
const data = await this.loadData() as FreewritingPromptsData | null;
if (data) {
// Destructure to prevent modelCache from being merged into settings (type drift)
const { modelCache, ...savedSettings } = data ?? {};
const { modelCache: cache, ...savedSettings } = data;
modelCache = cache;
this.settings = Object.assign({}, DEFAULT_SETTINGS, savedSettings);
} else {
// No data loaded, use defaults
this.settings = { ...DEFAULT_SETTINGS };
modelCache = undefined;
}
} catch (error) {
console.error('Failed to load settings; using defaults.', error);
this.settings = { ...DEFAULT_SETTINGS };
modelCache = undefined;
}
// Track initial API key to detect changes on save
this.lastApiKey = this.settings.apiKey;