MemoryTools.js•2.88 kB
import { z } from 'zod';
import { MemoryOperations } from './modules/MemoryOperations.js';
import { MemoryQueryHandler } from './modules/MemoryQueryHandler.js';
import { MemoryStreamingTools } from './modules/MemoryStreamingTools.js';
import { MemoryManagement } from './modules/MemoryManagement.js';
export class MemoryTools {
constructor(factStore, processor, qualityScorer) {
this.factStore = factStore;
this.processor = processor;
this.qualityScorer = qualityScorer;
// Initialize modular components
this.operations = new MemoryOperations(factStore, qualityScorer);
this.queryHandler = new MemoryQueryHandler(factStore, processor);
this.streamingTools = new MemoryStreamingTools(factStore);
this.management = new MemoryManagement(factStore);
// Maintain backward compatibility
this.streamingManager = this.streamingTools.getStreamingManager();
}
async registerTools(server) {
// Register tools from modular components
this.operations.registerTools(server);
this.queryHandler.registerTools(server);
this.streamingTools.registerTools(server);
this.management.registerTools(server);
}
// Delegate methods to modular components for backward compatibility
async handleStoreInsight(args) {
return await this.operations.handleStoreInsight(args);
}
async handleQuery(args) {
return await this.queryHandler.handleQuery(args);
}
async handleUpdateFact(args) {
return await this.operations.handleUpdateFact(args);
}
async handleDeleteFact(args) {
return await this.operations.handleDeleteFact(args);
}
async handleGetStats(args) {
return await this.operations.handleGetStats(args);
}
async handleGetRelated(args) {
return await this.operations.handleGetRelated(args);
}
async handleBulkProcess(args) {
return await this.queryHandler.handleBulkProcess(args);
}
async handleCleanup(args) {
return await this.management.handleCleanup(args);
}
// Backward compatibility methods
// Direct method for storing insights (used by slash commands)
async storeInsight(insight) {
return await this.operations.storeInsight(insight);
}
// Additional convenience methods that delegate to modules
async searchSimilarFacts(factId, options = {}) {
return await this.queryHandler.searchSimilarFacts(factId, options);
}
async getFactKeywords(factId, topN = 10) {
return await this.queryHandler.getFactKeywords(factId, topN);
}
async getSemanticStats() {
return await this.queryHandler.getSemanticStats();
}
async createBatchStream(query, options = {}) {
return await this.streamingTools.createBatchStream(query, options);
}
async getStreamStats() {
return await this.streamingTools.getStreamStats();
}
async getMaintenanceStats() {
return await this.management.getMaintenanceStats();
}
}