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 - FreewritingPromptsData 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>
81 lines
1.8 KiB
TypeScript
81 lines
1.8 KiB
TypeScript
// ABOUTME: Type definitions for the Freewriting Prompts plugin
|
|
// ABOUTME: Defines interfaces for settings, API responses, and plugin configuration
|
|
|
|
export interface FreewritingPromptsSettings {
|
|
apiKey: string;
|
|
model: string; // Changed from AnthropicModel to string to support dynamic models
|
|
timedCount: number;
|
|
delaySeconds: number;
|
|
noteCount: number;
|
|
systemPrompt: string;
|
|
timedExamplePrompt: string;
|
|
freewritingExamplePrompt: string;
|
|
}
|
|
|
|
export interface FreewritingPromptsData extends FreewritingPromptsSettings {
|
|
modelCache?: ModelCache;
|
|
}
|
|
|
|
export interface AnthropicMessage {
|
|
role: 'user' | 'assistant' | 'system';
|
|
content: string;
|
|
}
|
|
|
|
export interface AnthropicRequest {
|
|
model: string;
|
|
max_tokens: number;
|
|
messages: AnthropicMessage[];
|
|
system?: string;
|
|
}
|
|
|
|
export interface AnthropicResponse {
|
|
content: Array<{
|
|
text: string;
|
|
type: 'text';
|
|
}>;
|
|
id: string;
|
|
model: string;
|
|
role: 'assistant';
|
|
stop_reason: string;
|
|
stop_sequence: null;
|
|
type: 'message';
|
|
usage: {
|
|
input_tokens: number;
|
|
output_tokens: number;
|
|
};
|
|
}
|
|
|
|
export interface GeneratedPrompt {
|
|
text: string;
|
|
timestamp: Date;
|
|
}
|
|
|
|
export interface ModelInfo {
|
|
id: string;
|
|
display_name?: string;
|
|
created_at: string;
|
|
type: string;
|
|
}
|
|
|
|
export interface ModelsListResponse {
|
|
data: ModelInfo[];
|
|
first_id: string;
|
|
has_more: boolean;
|
|
last_id: string;
|
|
}
|
|
|
|
export interface ModelCache {
|
|
models: ModelInfo[];
|
|
fetchedAt: number;
|
|
}
|
|
|
|
export const ANTHROPIC_MODELS = [
|
|
'claude-opus-4-1-20250805',
|
|
'claude-opus-4-20250514',
|
|
'claude-sonnet-4-20250514',
|
|
'claude-3-7-sonnet-latest',
|
|
'claude-3-5-haiku-latest',
|
|
'claude-3-haiku-20240307'
|
|
] as const;
|
|
|
|
export type AnthropicModel = typeof ANTHROPIC_MODELS[number]; |