UNPKG

ms365-mcp-server

Version:

Microsoft 365 MCP Server for managing Microsoft 365 email through natural language interactions with full OAuth2 authentication support

72 lines (71 loc) 3.41 kB
import { CrossReferenceDetector } from './cross-reference-detector.js'; import { EnhancedFuzzySearch } from './enhanced-fuzzy-search.js'; import { ThreadReconstruction } from './thread-reconstruction.js'; import { logger } from './api.js'; export class IntelligenceEngine { constructor(ms365Operations) { this.ms365Operations = ms365Operations; this.crossRefDetector = new CrossReferenceDetector(ms365Operations); this.fuzzySearch = new EnhancedFuzzySearch(ms365Operations); this.threadReconstruction = new ThreadReconstruction(ms365Operations); } async intelligentSearch(query, emails, options = {}) { const startTime = Date.now(); logger.log(`🧠 Starting intelligent search for: "${query}"`); const result = { originalQuery: query, results: [], crossReferences: new Map(), fuzzyMatches: [], threads: new Map(), insights: { totalEmails: emails.length, highPriorityEmails: 0, threadCount: 0, averageConfidence: 0, processingTime: 0 } }; // 1. Enhanced fuzzy search if (options.enableFuzzySearch !== false) { result.fuzzyMatches = await this.fuzzySearch.naturalLanguageSearch(query, emails); result.results = result.fuzzyMatches.map(match => match.email); } // 2. Cross-reference detection if (options.enableCrossReference !== false && result.results.length > 0) { result.crossReferences = await this.crossRefDetector.findAllCrossReferences(result.results); } // 3. Thread reconstruction if (options.enableThreadReconstruction !== false && result.results.length > 0) { result.threads = await this.threadReconstruction.batchReconstructThreads(result.results); } // 4. Calculate insights result.insights = this.calculateInsights(result, startTime); logger.log(`🧠 Intelligent search completed in ${result.insights.processingTime}ms`); return result; } calculateInsights(result, startTime) { const highPriorityEmails = result.results.filter(email => email.importance === 'high' || this.isGovernmentEmail(email) || this.isUrgentEmail(email)).length; const totalConfidence = result.fuzzyMatches.reduce((sum, match) => sum + match.score, 0); const averageConfidence = result.fuzzyMatches.length > 0 ? totalConfidence / result.fuzzyMatches.length : 0; return { totalEmails: result.results.length, highPriorityEmails, threadCount: result.threads.size, averageConfidence, processingTime: Date.now() - startTime }; } isGovernmentEmail(email) { const govPatterns = ['.gov', 'government', 'federal', 'state', 'municipal', 'irs', 'tax']; const text = `${email.from.address} ${email.subject} ${email.bodyPreview}`.toLowerCase(); return govPatterns.some(pattern => text.includes(pattern)); } isUrgentEmail(email) { const urgentPatterns = ['urgent', 'asap', 'immediately', 'deadline', 'due']; const text = `${email.subject} ${email.bodyPreview}`.toLowerCase(); return urgentPatterns.some(pattern => text.includes(pattern)); } }