@codai/memorai-core
Version:
Simplified advanced memory engine - no tiers, just powerful semantic search with persistence
177 lines • 4.7 kB
TypeScript
/**
* Conversation Context Reconstruction Engine
* Advanced system for reconstructing and maintaining conversation context across sessions
*/
import { MemoryMetadata } from '../types/index.js';
import { MemoryPattern } from './PatternRecognition.js';
import { AIMemoryRelationship } from './RelationshipExtractor.js';
export interface ConversationThread {
id: string;
agentId: string;
userId?: string;
startTime: Date;
endTime: Date;
isActive: boolean;
context: ConversationContext;
memories: MemoryMetadata[];
relationships: AIMemoryRelationship[];
patterns: MemoryPattern[];
metadata: {
topic?: string;
sentiment?: 'positive' | 'negative' | 'neutral';
complexity: number;
continuity: number;
tags: string[];
};
}
export interface ConversationContext {
currentTopic: string;
topicHistory: Array<{
topic: string;
timestamp: Date;
confidence: number;
}>;
entities: Array<{
name: string;
type: string;
mentions: number;
lastMention: Date;
importance: number;
}>;
intentions: Array<{
intent: string;
confidence: number;
fulfilled: boolean;
timestamp: Date;
}>;
emotionalContext: {
currentMood: string;
moodHistory: Array<{
mood: string;
timestamp: Date;
intensity: number;
}>;
};
preferences: Record<string, any>;
previousSessions: string[];
}
export interface ContextReconstructionConfig {
maxThreadAge: number;
maxMemoriesPerThread: number;
similarityThreshold: number;
continuityThreshold: number;
enableCrossSessionContext: boolean;
enableEmotionalContext: boolean;
enableIntentTracking: boolean;
}
export declare class ConversationContextReconstructor {
private config;
private relationshipExtractor;
private patternEngine;
private activeThreads;
private threadHistory;
constructor(config?: Partial<ContextReconstructionConfig>);
/**
* Reconstruct conversation context from memory fragments
*/
reconstructContext(agentId: string, memories: MemoryMetadata[], userId?: string): Promise<ConversationThread[]>;
/**
* Group memories into logical conversation threads
*/
private groupMemoriesIntoThreads;
/**
* Determine if a new thread should start
*/
private shouldStartNewThread;
/**
* Calculate topic similarity between thread and new memory
*/
private calculateTopicSimilarity;
/**
* Build conversation context for a thread
*/
private buildConversationContext;
/**
* Extract dominant topic from memories
*/
private extractDominantTopic;
/**
* Build topic history with confidence scores
*/
private buildTopicHistory;
/**
* Group memories by time windows
*/
private groupMemoriesByTimeWindows;
/**
* Calculate confidence score for a topic
*/
private calculateTopicConfidence;
/**
* Extract entities from memories
*/
private extractEntities;
/**
* Classify entity type (simplified)
*/
private classifyEntityType;
/**
* Extract intentions from memories
*/
private extractIntentions;
/**
* Determine if an intent was fulfilled
*/
private isIntentFulfilled;
/**
* Build emotional context
*/
private buildEmotionalContext;
/**
* Detect mood from memory content
*/
private detectMoodFromMemory;
/**
* Extract preferences from memories
*/
private extractPreferences;
/**
* Link threads across sessions
*/
private linkCrossSessionThreads;
/**
* Find related threads based on similarity
*/
private findRelatedThreads;
/**
* Calculate similarity between threads
*/
private calculateThreadSimilarity;
/**
* Create empty conversation context
*/
private createEmptyContext;
/**
* Update active threads cache
*/
private updateActiveThreads;
/**
* Get active conversation threads
*/
getActiveThreads(): ConversationThread[];
/**
* Get conversation thread by ID
*/
getThread(threadId: string): ConversationThread | null;
/**
* Get conversation summary for a thread
*/
getConversationSummary(threadId: string): Promise<{
summary: string;
keyTopics: string[];
duration: number;
memoryCount: number;
continuityScore: number;
} | null>;
}
//# sourceMappingURL=ConversationContextReconstructor.d.ts.map