/** * Context Manager Types * * Type definitions for the Context Manager module which tracks * context window usage across different providers and models. */ /** * Configuration for the Context Manager. */ export interface ContextManagerConfig { /** Default context limit if not specified per model (default: 128000) */ defaultContextLimit: number; /** Threshold to trigger auto-compact (0-1, default 0.9) */ autoCompactThreshold: number; /** Threshold to block new messages (0-1, default 0.98) */ blockingThreshold: number; /** Maximum tokens per tool result (default: 4096) */ maxToolResultTokens: number; /** Maximum tokens per message (default: 16384) */ maxMessageTokens: number; /** Per-model context limits */ modelLimits: Record; } /** * Current context state for a provider/model combination. */ export interface ContextState { /** Provider name */ provider: string; /** Model name */ model: string; /** Tokens currently used */ usedTokens: number; /** Maximum tokens available */ maxTokens: number; /** Percentage of context used (0-100) */ usedPercentage: number; /** Percentage of context remaining (0-100) */ remainingPercentage: number; /** Tokens remaining */ remainingTokens: number; /** Whether context usage is near the auto-compact threshold */ isNearLimit: boolean; /** Whether context is blocked (too full for new messages) */ isBlocked: boolean; } /** * Detailed breakdown of context usage by category. */ export interface ContextBreakdown { /** Tokens used by system prompts */ systemPrompt: number; /** Tokens used by conversation messages */ messages: number; /** Tokens used by tool results */ toolResults: number; /** Tokens used by image content (estimated) */ images: number; /** Total tokens across all categories */ total: number; } /** * Message structure for context analysis. * Compatible with the main Message type but allows string or array content. */ export interface ContextMessage { /** Message role */ role: 'user' | 'assistant' | 'system'; /** Message content (string or content blocks) */ content: string | ContextContentBlock[]; /** Optional metadata for categorization */ metadata?: { /** Whether this is a system prompt */ isSystemPrompt?: boolean; /** Whether this contains tool results */ isToolResult?: boolean; }; } /** * Content block within a context message. */ export interface ContextContentBlock { /** Type of content */ type: 'text' | 'tool_use' | 'tool_result' | 'image'; /** Text content */ text?: string; /** Tool name (for tool_use blocks) */ name?: string; /** Tool use ID (for tool_use blocks) */ id?: string; /** Tool result content */ content?: string; /** Tool input (for tool_use blocks) */ input?: Record; /** Reference to tool_use ID (for tool_result blocks) */ tool_use_id?: string; /** Image source (for image blocks) */ source?: { type: 'base64' | 'url'; media_type?: string; data?: string; url?: string; }; } /** * Result of a context compaction operation. */ export interface CompactionResult { /** Original token count */ originalTokens: number; /** Token count after compaction */ compactedTokens: number; /** Tokens saved */ tokensSaved: number; /** Percentage reduction */ reductionPercentage: number; /** Number of messages before compaction */ originalMessageCount: number; /** Number of messages after compaction */ compactedMessageCount: number; /** Strategy used for compaction */ strategy: CompactionStrategy; } /** * Strategy used for compaction. */ export type CompactionStrategy = 'summarize' | 'truncate' | 'drop_old' | 'hybrid'; /** * Events emitted by the Context Manager. */ export type ContextEvent = { type: 'compact_triggered'; state: ContextState; threshold: number; } | { type: 'compact_completed'; result: CompactionResult; } | { type: 'context_blocked'; state: ContextState; } | { type: 'context_warning'; state: ContextState; message: string; } | { type: 'truncation_applied'; originalTokens: number; truncatedTokens: number; }; /** * Listener for context events. */ export type ContextEventListener = (event: ContextEvent) => void; /** * Options for content truncation. */ export interface TruncationOptions { /** Maximum tokens allowed */ maxTokens: number; /** Where to truncate: start, end, or middle */ position?: 'start' | 'end' | 'middle'; /** Suffix to add when truncating (e.g., "...") */ suffix?: string; /** Prefix to add when truncating (e.g., "[truncated] ") */ prefix?: string; /** Whether to preserve code blocks if possible */ preserveCodeBlocks?: boolean; } /** * Result of a truncation operation. */ export interface TruncationResult { /** Truncated content */ content: string; /** Original token count */ originalTokens: number; /** Truncated token count */ truncatedTokens: number; /** Whether truncation was applied */ wasTruncated: boolean; } //# sourceMappingURL=context-types.d.ts.map