UNPKG

ai-debug-local-mcp

Version:

đŸŽ¯ ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

370 lines â€ĸ 15.2 kB
/** * AI Feedback Real-Time Dashboard * * Provides live analytics and monitoring for AI feedback data with * real-time trend detection and alert generation. */ import { AIFeedbackAnalyticsEngine } from './ai-feedback-analytics-engine.js'; /** * Real-Time Analytics Dashboard for AI Feedback Intelligence */ export class AIFeedbackRealtimeDashboard { analyticsEngine; configuration; metricsHistory = []; alertHistory = []; isMonitoring = false; monitoringInterval; constructor(configuration) { this.analyticsEngine = new AIFeedbackAnalyticsEngine(); this.configuration = { refreshInterval: 5 * 60 * 1000, // 5 minutes alertThresholds: { satisfactionDrop: 0.5, // 0.5 point drop errorRateSpike: 0.1, // 10% error rate usageDrop: 0.3 // 30% usage drop }, retentionPeriod: 24 * 60 * 60 * 1000, // 24 hours enableRealTimeAlerts: true, ...configuration }; } /** * Start real-time monitoring and dashboard updates */ async startMonitoring(feedbackDataSource) { if (this.isMonitoring) return; this.isMonitoring = true; console.log('[Dashboard] 📊 Starting real-time monitoring...'); // Initial metrics calculation await this.updateMetrics(feedbackDataSource); // Set up periodic updates this.monitoringInterval = setInterval(async () => { try { await this.updateMetrics(feedbackDataSource); this.cleanupOldData(); } catch (error) { console.error('[Dashboard] ❌ Error updating metrics:', error); this.addAlert('warning', 'Failed to update dashboard metrics', 'system'); } }, this.configuration.refreshInterval); console.log(`[Dashboard] ✅ Real-time monitoring started (${this.configuration.refreshInterval / 1000}s intervals)`); } /** * Stop real-time monitoring */ stopMonitoring() { if (!this.isMonitoring) return; this.isMonitoring = false; if (this.monitoringInterval) { clearInterval(this.monitoringInterval); this.monitoringInterval = undefined; } console.log('[Dashboard] 🛑 Real-time monitoring stopped'); } /** * Get current dashboard state */ getCurrentDashboard() { return { isMonitoring: this.isMonitoring, latestMetrics: this.metricsHistory[this.metricsHistory.length - 1] || null, configuration: this.configuration, metricsHistory: this.metricsHistory.slice(-20), // Last 20 data points recentAlerts: this.alertHistory.slice(-10) // Last 10 alerts }; } /** * Generate dashboard summary for quick overview */ generateDashboardSummary() { const latest = this.metricsHistory[this.metricsHistory.length - 1]; if (!latest) { return { status: 'warning', summary: 'No recent metrics available', keyMetrics: {}, criticalAlerts: 0, recommendations: ['Start monitoring to collect metrics'] }; } const criticalAlerts = latest.alerts.filter(a => a.level === 'critical').length; const warningAlerts = latest.alerts.filter(a => a.level === 'warning').length; let status = 'healthy'; if (criticalAlerts > 0) status = 'critical'; else if (warningAlerts > 2) status = 'warning'; const keyMetrics = { satisfaction: Math.round(latest.realTimeMetrics.avgSatisfaction * 10) / 10, feedbackRate: Math.round(latest.realTimeMetrics.feedbackRate * 10) / 10, activeUsers: latest.realTimeMetrics.activeUsers, errorRate: Math.round(latest.realTimeMetrics.errorRate * 1000) / 10 // as percentage }; const recommendations = this.generateRecommendations(latest, status); return { status, summary: this.generateStatusSummary(status, latest), keyMetrics, criticalAlerts, recommendations }; } /** * Update dashboard metrics with latest data */ async updateMetrics(feedbackDataSource) { const now = Date.now(); const feedbackData = await feedbackDataSource(); // Calculate real-time metrics const recentFeedback = feedbackData.filter(f => f.timestamp > (now - 60 * 60 * 1000)); // Last hour const realTimeMetrics = this.calculateRealTimeMetrics(recentFeedback, now); // Calculate trend indicators const trendIndicators = this.calculateTrendIndicators(feedbackData); // Generate alerts based on current data and thresholds const alerts = this.generateAlerts(realTimeMetrics, trendIndicators, feedbackData); // Get top insights from analytics engine const topInsights = await this.generateTopInsights(feedbackData); const metrics = { timestamp: now, realTimeMetrics, trendIndicators, alerts, topInsights }; // Store metrics and trigger alerts this.metricsHistory.push(metrics); this.processAlerts(alerts); console.log(`[Dashboard] 📊 Metrics updated: ${realTimeMetrics.feedbackRate} feedback/hr, satisfaction: ${realTimeMetrics.avgSatisfaction.toFixed(1)}`); } /** * Calculate real-time performance metrics */ calculateRealTimeMetrics(recentFeedback, currentTime) { const hourMs = 60 * 60 * 1000; const feedbackRate = recentFeedback.length; // feedback per hour const satisfactionValues = recentFeedback .map(f => f.userExperience?.satisfaction) .filter(s => typeof s === 'number'); const avgSatisfaction = satisfactionValues.length > 0 ? satisfactionValues.reduce((sum, s) => sum + s, 0) / satisfactionValues.length : 0; // Unique users (sessions) in the last hour const activeUsers = new Set(recentFeedback.map(f => f.sessionId)).size; // Error rate calculation (feedback with errors or low satisfaction) const errorFeedback = recentFeedback.filter(f => (f.userExperience?.satisfaction || 0) < 5 || (f.technicalMetrics?.errorsEncountered?.length || 0) > 0); const errorRate = recentFeedback.length > 0 ? errorFeedback.length / recentFeedback.length : 0; return { feedbackRate, avgSatisfaction, activeUsers, errorRate }; } /** * Calculate trend indicators from historical data */ calculateTrendIndicators(feedbackData) { const now = Date.now(); const dayMs = 24 * 60 * 60 * 1000; // Compare last 24 hours to previous 24 hours const recent = feedbackData.filter(f => f.timestamp > (now - dayMs)); const previous = feedbackData.filter(f => f.timestamp > (now - 2 * dayMs) && f.timestamp <= (now - dayMs)); const calculateTrend = (recentValue, previousValue) => { const threshold = 0.05; // 5% change threshold const change = previousValue > 0 ? (recentValue - previousValue) / previousValue : 0; if (change > threshold) return 'up'; if (change < -threshold) return 'down'; return 'stable'; }; // Satisfaction trend const recentSatisfaction = this.calculateAverageSatisfaction(recent); const previousSatisfaction = this.calculateAverageSatisfaction(previous); const satisfactionTrend = calculateTrend(recentSatisfaction, previousSatisfaction); // Usage trend (feedback volume) const usageTrend = calculateTrend(recent.length, previous.length); // Quality trend (error rate) const recentErrorRate = this.calculateErrorRate(recent); const previousErrorRate = this.calculateErrorRate(previous); // Lower error rate is better, so invert the trend const qualityTrend = calculateTrend(previousErrorRate, recentErrorRate); return { satisfactionTrend, usageTrend, qualityTrend }; } /** * Generate alerts based on thresholds and current metrics */ generateAlerts(realTimeMetrics, trendIndicators, feedbackData) { const alerts = []; const now = Date.now(); // Satisfaction alerts if (realTimeMetrics.avgSatisfaction < 6) { alerts.push({ level: realTimeMetrics.avgSatisfaction < 4 ? 'critical' : 'warning', message: `Low satisfaction detected: ${realTimeMetrics.avgSatisfaction.toFixed(1)}/10`, timestamp: now, category: 'satisfaction' }); } // Error rate alerts if (realTimeMetrics.errorRate > this.configuration.alertThresholds.errorRateSpike) { alerts.push({ level: realTimeMetrics.errorRate > 0.2 ? 'critical' : 'warning', message: `High error rate: ${Math.round(realTimeMetrics.errorRate * 100)}%`, timestamp: now, category: 'errors' }); } // Trend alerts if (trendIndicators.satisfactionTrend === 'down') { alerts.push({ level: 'warning', message: 'Satisfaction trend declining over last 24 hours', timestamp: now, category: 'trends' }); } if (trendIndicators.usageTrend === 'down') { alerts.push({ level: 'info', message: 'Usage declining - fewer feedback submissions', timestamp: now, category: 'usage' }); } // No feedback alert if (realTimeMetrics.feedbackRate === 0) { alerts.push({ level: 'warning', message: 'No feedback received in the last hour', timestamp: now, category: 'data' }); } return alerts; } /** * Generate top insights using analytics engine */ async generateTopInsights(feedbackData) { if (feedbackData.length === 0) { return ['No feedback data available for insights']; } try { const intelligenceReport = await this.analyticsEngine.generateIntelligenceReport(feedbackData); return intelligenceReport.actionableInsights .slice(0, 3) // Top 3 insights .map(insight => `${insight.category}: ${insight.insight}`); } catch (error) { console.error('[Dashboard] Failed to generate insights:', error); return ['Error generating insights - see logs']; } } /** * Process alerts and trigger notifications if enabled */ processAlerts(alerts) { alerts.forEach(alert => { this.alertHistory.push({ level: alert.level, message: alert.message, timestamp: alert.timestamp }); if (this.configuration.enableRealTimeAlerts) { if (alert.level === 'critical') { console.error(`[Dashboard] 🚨 CRITICAL ALERT: ${alert.message}`); } else if (alert.level === 'warning') { console.warn(`[Dashboard] âš ī¸ WARNING: ${alert.message}`); } else { console.info(`[Dashboard] â„šī¸ INFO: ${alert.message}`); } } }); } /** * Add custom alert to the system */ addAlert(level, message, category) { const alert = { level, message, timestamp: Date.now(), category }; // Add to latest metrics if available const latest = this.metricsHistory[this.metricsHistory.length - 1]; if (latest) { latest.alerts.push(alert); } this.processAlerts([alert]); } /** * Clean up old data based on retention policy */ cleanupOldData() { const cutoff = Date.now() - this.configuration.retentionPeriod; // Clean metrics history this.metricsHistory = this.metricsHistory.filter(m => m.timestamp > cutoff); // Clean alert history this.alertHistory = this.alertHistory.filter(a => a.timestamp > cutoff); } // Helper methods calculateAverageSatisfaction(data) { const values = data.map(d => d.userExperience?.satisfaction).filter(s => typeof s === 'number'); return values.length > 0 ? values.reduce((sum, s) => sum + s, 0) / values.length : 0; } calculateErrorRate(data) { if (data.length === 0) return 0; const errors = data.filter(d => (d.userExperience?.satisfaction || 0) < 5 || (d.technicalMetrics?.errorsEncountered?.length || 0) > 0); return errors.length / data.length; } generateStatusSummary(status, metrics) { switch (status) { case 'healthy': return `System performing well. Satisfaction: ${metrics.realTimeMetrics.avgSatisfaction.toFixed(1)}/10, ${metrics.realTimeMetrics.feedbackRate} feedback/hr`; case 'warning': return `System needs attention. ${metrics.alerts.filter(a => a.level === 'warning').length} warnings detected`; case 'critical': return `Critical issues detected. Immediate action required for ${metrics.alerts.filter(a => a.level === 'critical').length} critical alerts`; } } generateRecommendations(metrics, status) { const recommendations = []; if (status === 'critical') { recommendations.push('Address critical alerts immediately'); recommendations.push('Review system logs for error patterns'); } if (metrics.realTimeMetrics.avgSatisfaction < 7) { recommendations.push('Investigate satisfaction issues'); recommendations.push('Review recent user feedback for patterns'); } if (metrics.realTimeMetrics.errorRate > 0.05) { recommendations.push('Debug high error rate causes'); recommendations.push('Check tool configurations and performance'); } if (metrics.trendIndicators.usageTrend === 'down') { recommendations.push('Investigate usage decline'); recommendations.push('Consider user engagement improvements'); } if (recommendations.length === 0) { recommendations.push('System operating normally'); recommendations.push('Continue monitoring for trends'); } return recommendations; } } //# sourceMappingURL=ai-feedback-realtime-dashboard.js.map