/** * Context Manager for MCP * * Manages conversation contexts across agent-LLM interactions with compression and sharing */ import { EventEmitter } from 'events'; import { ConversationContext, ConversationMessage, ContextMetadata, ContextPriority } from '../types'; import { MemoryStorageProvider } from '../../storage/providers/memory-storage-provider'; /** * Context compression result */ export interface CompressionResult { originalTokens: number; compressedTokens: number; compressionRatio: number; summary: string; droppedMessages: number; } /** * Context sharing configuration */ export interface ContextSharingConfig { allowSharing: boolean; requireConsent: boolean; maxShareDepth: number; shareableFields: string[]; } /** * Context search options */ export interface ContextSearchOptions { agentDID?: string; sessionId?: string; conversationId?: string; priority?: ContextPriority; domain?: string; includeArchived?: boolean; limit?: number; } /** * Context statistics */ export interface ContextStatistics { totalContexts: number; activeContexts: number; archivedContexts: number; totalTokens: number; averageTokensPerContext: number; compressionsSaved: number; contextsByPriority: Record; contextsByDomain: Record; } /** * Context Manager */ export declare class ContextManager extends EventEmitter { private config; private contexts; private sessionIndex; private agentIndex; private domainIndex; private archivedContexts; private compressionTimer?; private retentionTimer?; private storageProvider; constructor(config?: { maxTokensPerContext: number; compressionThreshold: number; compressionStrategy: 'summary' | 'sliding-window' | 'importance'; retentionCheckInterval: number; sharing: ContextSharingConfig; archiveAfterDays: number; }, storageProvider?: MemoryStorageProvider); /** * Create or update context */ createContext(agentDID: string, sessionId: string, metadata: ContextMetadata): Promise; /** * Get context */ getContext(conversationId: string): ConversationContext | null; /** * Get contexts for agent */ getAgentContexts(agentDID: string, includeArchived?: boolean): ConversationContext[]; /** * Add message to context */ addMessage(conversationId: string, message: Omit): Promise; /** * Compress context */ compressContext(context: ConversationContext): Promise; /** * Summarize context */ private summarizeContext; /** * Apply sliding window compression */ private applySlidingWindow; /** * Compress by importance */ private compressByImportance; /** * Calculate message importance */ private calculateMessageImportance; /** * Share context with another agent */ shareContext(conversationId: string, targetAgentDID: string, options?: { shareHistory?: boolean; shareSummary?: boolean; shareMetadata?: boolean; }): Promise; /** * Search contexts */ searchContexts(options: ContextSearchOptions): Promise; /** * Archive old contexts */ private archiveOldContexts; /** * Apply retention policies */ private applyRetentionPolicies; /** * Group messages by topic */ private groupMessagesByTopic; /** * Estimate token count */ private estimateTokens; /** * Update indices */ private updateIndices; /** * Remove from indices */ private removeFromIndices; /** * Load contexts from storage */ private loadContexts; /** * Save contexts to storage */ private saveContexts; /** * Start maintenance tasks */ private startMaintenanceTasks; /** * Check if compression needed */ private checkCompressionNeeded; /** * Get statistics */ getStatistics(): ContextStatistics; /** * Clear context */ clearContext(conversationId: string): Promise; /** * Delete context */ deleteContext(conversationId: string): Promise; /** * Shutdown */ shutdown(): void; } export default ContextManager; //# sourceMappingURL=context-manager.d.ts.map