feat: add dynamic model fetching from Anthropic API #2

Merged
AlexKucera merged 10 commits from dynamic-models into master 2025-10-24 11:14:13 +02:00
10 Commits
Author SHA1 Message Date
AlexKucera f8427e72a0 Enforces display name for model selection
Removes fallback to model ID for display names
Ensures consistent and user-friendly model representation

Improves model dropdown experience by requiring display names from API
2025-10-24 11:06:48 +02:00
AlexKucera de98d4a52d 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
2025-10-24 11:05:45 +02:00
AlexKucera 5c8314a986 Enhances model loading in settings display
Modifies display method to load models asynchronously in the background

Improves user experience by:
- Removing async modifier from display method
- Handling model loading as a background task
- Adding error handling for model loading
- Preparing to update UI dynamically when models are loaded
2025-10-24 11:04:35 +02:00
AlexKucera 3d1227dc45 Improves model fallback and caching strategy
Adds API key validation before fetching models
Ensures consistent fallback model caching on API errors or missing key
Reduces redundant code by centralizing fallback model caching logic

Relates to dynamic-models branch
2025-10-24 11:03:30 +02:00
AlexKucera fcc495aa8f Enhances model service fallback and caching logic
Improves model retrieval strategy for scenarios with invalid/missing API keys

Adds immediate fallback model generation when API key is invalid
Ensures consistent model caching for both API and fallback scenarios
Sorts model options alphabetically for improved user experience

Introduces new getFallbackOptions() method for direct fallback access
Refactors model refresh and error handling to provide more robust model selection
2025-10-24 11:00:42 +02:00
AlexKucera c3d4888c98 Optimizes settings and model cache loading
Refactors loadSettings method to avoid redundant data loading
Reduces duplicate loadData() calls by reusing loaded data
Improves efficiency of plugin initialization process
2025-10-24 10:57:47 +02:00
AlexKucera 4db5639160 Adds token usage tracking for text cleanup requests
Enhances Anthropic API client to return token usage information

Modifies cleanup service to capture and store input and output token counts from API responses
Refactors request and response handling to extract and pass usage metrics
Provides more detailed tracking of API request resource consumption
2025-10-24 10:55:54 +02:00
AlexKucera b63ab214b3 Refactors Anthropic model type and list handling
Removes strict type definition for Anthropic models to enable more dynamic model selection

Allows for flexible model ID fetching from Anthropic API
Provides a fallback list of models when direct API access is limited

Supports more adaptable model configuration in the application
2025-10-24 10:53:54 +02:00
AlexKucera eae48521c5 Refactors confirmation modal with Obsidian integration
Replaces custom modal implementation with Obsidian's Modal class for improved consistency and accessibility

Enhances API key management with dynamic model refreshing and fallback handling
Improves event handling and modal interaction patterns
2025-10-24 10:44:53 +02:00
Jarvis 7b23ed6615 feat: add dynamic model fetching from Anthropic API
Replace hardcoded model list with dynamic API-based model fetching
that queries the Anthropic models endpoint. Implements 24-hour caching
with automatic fallback to hardcoded models if API is unavailable.

Changes:
- Add ModelService to fetch and cache available models from API
- Implement 24-hour TTL cache persisted in plugin data
- Update AnthropicClient with fetchModels() method
- Modify settings UI to load models asynchronously with loading states
- Auto-refresh models when API key is entered or changed
- Display model names using display_name field from API
- Preserve user's selected model across updates and restarts
- Show notice when falling back to hardcoded model list
- Change model type from strict enum to string for dynamic support

Technical details:
- New ModelInfo and ModelsListResponse interfaces for API response
- ModelCache interface with timestamp for TTL validation
- FreewritingCleanupData extends settings to include cache
- Settings dropdown disabled during model fetch/refresh
- Fallback to ANTHROPIC_MODELS constant on API failure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 10:25:22 +02:00