Files
freewriting-prompts/types.ts
T
AlexKucera 902d2b1b9a Refines Anthropic model type and list definitions
Updates model type to use ModelId type for stronger type safety

Improves hardcoded model list with TODO for keeping it current
Removes outdated comments and simplifies model list annotations

Prepares for more dynamic model handling with explicit update guidance
2025-10-24 16:53:06 +02:00

179 lines
6.3 KiB
TypeScript

// ABOUTME: Type definitions for the Freewriting Prompts plugin
// ABOUTME: Defines interfaces for settings, API responses, and plugin configuration
/**
* Type alias representing a Claude model identifier.
* Used to document the intent that a string should be a valid Claude model ID.
*/
export type ModelId = string;
/**
* Plugin configuration settings that control prompt generation behavior.
* These settings are persisted to disk and can be modified through the settings UI.
*/
export interface FreewritingPromptsSettings {
/** Anthropic API key for authenticating with Claude API */
apiKey: string;
/** Claude model ID to use for prompt generation (e.g., 'claude-3-5-haiku-latest') */
model: ModelId; // Changed from AnthropicModel to string to support dynamic models
/** Number of prompts to generate for timed notifications (1-50) */
timedCount: number;
/** Delay in seconds between each timed prompt notification (1-300) */
delaySeconds: number;
/** Number of prompts to append to a note (1-20) */
noteCount: number;
/** System-level instructions that guide the AI's prompt generation behavior */
systemPrompt: string;
/** Example prompt that demonstrates the desired style for timed prompts */
timedExamplePrompt: string;
/** Example prompt that demonstrates the desired style for note-inserted prompts */
freewritingExamplePrompt: string;
}
/**
* Extended settings data that includes both user configuration and cached model information.
* This is the structure saved to and loaded from disk to persist state across sessions.
*/
export interface FreewritingPromptsData extends FreewritingPromptsSettings {
/** Optional cached model list with 24-hour TTL to reduce API calls */
modelCache?: ModelCache;
}
/**
* Represents a single message in the conversation with Claude.
* Used to construct the messages array sent to the Anthropic API.
*/
export interface AnthropicMessage {
/** Role identifier indicating who sent the message */
role: 'user' | 'assistant' | 'system';
/** The actual content/text of the message */
content: string;
}
/**
* Request payload structure for the Anthropic Messages API.
* Defines all parameters needed to generate a completion from Claude.
*/
export interface AnthropicRequest {
/** Model identifier (e.g., 'claude-3-5-haiku-latest') */
model: ModelId;
/** Maximum number of tokens to generate in the response */
max_tokens: number;
/** Array of conversation messages between user and assistant */
messages: AnthropicMessage[];
/** Optional system prompt that provides context and instructions */
system?: string;
}
/**
* Response structure returned by the Anthropic Messages API.
* Contains the generated text, metadata, and token usage information.
*/
export interface AnthropicResponse {
/** Array of content blocks containing the generated text */
content: Array<{
/** The actual generated text */
text: string;
/** Content type identifier */
type: 'text';
}>;
/** Unique identifier for this API response */
id: string;
/** Model that generated the response */
model: string;
/** Role of the responder (always 'assistant' for API responses) */
role: 'assistant';
/** Reason the generation stopped (e.g., 'end_turn', 'max_tokens') */
stop_reason: string;
/** Custom stop sequence that triggered completion, if any */
stop_sequence: null;
/** Response type identifier */
type: 'message';
/** Token usage statistics for billing and monitoring */
usage: {
/** Number of tokens in the input prompt */
input_tokens: number;
/** Number of tokens generated in the response */
output_tokens: number;
};
}
/**
* Represents a generated writing prompt with its creation timestamp.
* Used for caching prompts to avoid unnecessary API calls within the cache TTL.
*/
export interface GeneratedPrompt {
/** The actual prompt text generated by Claude */
text: string;
/** When this prompt was generated (used for cache expiry) */
timestamp: Date;
}
/**
* Information about a single Claude model returned from the Models API.
* Used to populate the model selection dropdown with current available models.
*/
export interface ModelInfo {
/** Unique model identifier (e.g., 'claude-3-5-haiku-latest') */
id: string;
/** Human-readable model name for display purposes */
display_name?: string;
/** ISO timestamp of when the model was created */
created_at: string;
/** Model type classification */
type: string;
}
/**
* Response structure from the Anthropic Models List API.
* Provides paginated list of available Claude models.
*/
export interface ModelsListResponse {
/** Array of available model information */
data: ModelInfo[];
/** ID of the first model in the list (for pagination) */
first_id: string;
/** Whether more models are available on subsequent pages */
has_more: boolean;
/** ID of the last model in the list (for pagination) */
last_id: string;
}
/**
* Cached model list with timestamp for TTL-based expiry.
* Models are cached for 24 hours to reduce API calls while staying reasonably current.
*/
export interface ModelCache {
/** Array of cached model information */
models: ModelInfo[];
/** Unix timestamp (milliseconds) when this cache was created */
fetchedAt: number;
}
/**
* Hardcoded fallback list of known Claude models.
* Used when the Models API is unavailable or the API key is not configured.
*
* TODO: Keep this list updated with current models from:
* https://docs.anthropic.com/en/docs/about-claude/models
*
* Prefer "-latest" aliases where available for automatic updates.
*/
export const ANTHROPIC_MODELS = [
// Current generation models (use -latest aliases where available)
'claude-sonnet-4-5-20250929',
'claude-haiku-4-5-20251001',
'claude-opus-4-1-20250805',
// Legacy models
'claude-sonnet-4-20250514',
'claude-3-7-sonnet-latest',
'claude-opus-4-20250514',
'claude-3-5-haiku-latest',
'claude-3-haiku-20240307'
] as const;
/**
* Type representing one of the hardcoded fallback model identifiers.
* This is a union type of all strings in the ANTHROPIC_MODELS array.
*/
export type AnthropicModel = typeof ANTHROPIC_MODELS[number];