File size: 7,210 Bytes
01aa854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6684dc3
01aa854
 
 
 
6684dc3
01aa854
6684dc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

// Global metrics object for dashboard data
const metrics = {
    activeModules: 6,
    conversations: {
        today: 42,
        week: 142,
        change: 12
    },
    memory: {
        total: 1.2,
        episodic: 0.65,
        semantic: 0.55,
        change: 5
    },
    health: {
        uptime: 98.7,
        latency: {
            avg: 320,
            p95: 540
        },
        errorRate: 0.4
    },
    cost: {
        current: 0.042,
        target: 0.05
    }
};

// Simulate data updates
function simulateData() {
    // Randomly adjust metrics within reasonable ranges
    metrics.conversations.today = Math.max(30, metrics.conversations.today + Math.floor(Math.random() * 3) - 1);
    metrics.conversations.week = metrics.conversations.today + Math.floor(Math.random() * 100);
    metrics.conversations.change = Math.floor(Math.random() * 5) + 8;
    
    metrics.memory.total = 1.1 + Math.random() * 0.3;
    metrics.memory.episodic = metrics.memory.total * (0.5 + Math.random() * 0.1);
    metrics.memory.semantic = metrics.memory.total - metrics.memory.episodic;
    metrics.memory.change = Math.floor(Math.random() * 4) + 3;
    
    metrics.health.uptime = 98 + Math.random() * 1.5;
    metrics.health.latency.avg = 300 + Math.random() * 100;
    metrics.health.latency.p95 = metrics.health.latency.avg * (1.5 + Math.random() * 0.3);
    metrics.health.errorRate = Math.random() * 0.5;
    
    metrics.cost.current = 0.04 + Math.random() * 0.005;
    
    updateMetrics();
}

// Update dashboard metrics display
function updateMetrics() {
    document.querySelectorAll('[data-metric="active-modules"]').forEach(el => {
        el.textContent = metrics.activeModules;
    });
    
    document.querySelectorAll('[data-metric="conversations-today"]').forEach(el => {
        el.textContent = metrics.conversations.today;
    });
    
    document.querySelectorAll('[data-metric="conversations-week"]').forEach(el => {
        el.textContent = metrics.conversations.week;
    });
    
    document.querySelectorAll('[data-metric="conversations-change"]').forEach(el => {
        el.textContent = metrics.conversations.change;
    });
    
    document.querySelectorAll('[data-metric="memory-total"]').forEach(el => {
        el.textContent = metrics.memory.total.toFixed(1);
    });
    
    document.querySelectorAll('[data-metric="memory-episodic"]').forEach(el => {
        el.textContent = metrics.memory.episodic.toFixed(2) + 'GB';
    });
    
    document.querySelectorAll('[data-metric="memory-semantic"]').forEach(el => {
        el.textContent = metrics.memory.semantic.toFixed(2) + 'GB';
    });
    
    document.querySelectorAll('[data-metric="memory-change"]').forEach(el => {
        el.textContent = metrics.memory.change;
    });
    
    document.querySelectorAll('[data-metric="health-uptime"]').forEach(el => {
        el.textContent = metrics.health.uptime.toFixed(1);
    });
    
    document.querySelectorAll('[data-metric="health-avg-latency"]').forEach(el => {
        el.textContent = metrics.health.latency.avg.toFixed(0);
    });
    
    document.querySelectorAll('[data-metric="health-p95-latency"]').forEach(el => {
        el.textContent = metrics.health.latency.p95.toFixed(0);
    });
    
    document.querySelectorAll('[data-metric="health-error-rate"]').forEach(el => {
        el.textContent = metrics.health.errorRate.toFixed(1);
    });
    
    document.querySelectorAll('[data-metric="cost-current"]').forEach(el => {
        el.textContent = 'const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
    
    tooltipTriggers.forEach(trigger => {
        const tooltip = document.createElement('div');
        tooltip.className = 'absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip';
        tooltip.textContent = trigger.getAttribute('data-tooltip');
        trigger.appendChild(tooltip);
        
        trigger.addEventListener('mouseenter', () => {
            tooltip.classList.remove('invisible', 'opacity-0');
            tooltip.classList.add('visible', 'opacity-100');
        });
        
        trigger.addEventListener('mouseleave', () => {
            tooltip.classList.remove('visible', 'opacity-100');
            tooltip.classList.add('invisible', 'opacity-0');
        });
    });

    // Dark mode toggle
    const darkModeToggle = document.getElementById('dark-mode-toggle');
    if (darkModeToggle) {
        darkModeToggle.addEventListener('click', () => {
            document.documentElement.classList.toggle('dark');
            localStorage.setItem('darkMode', document.documentElement.classList.contains('dark'));
        });
    }

    // Check for saved dark mode preference
    if (localStorage.getItem('darkMode') === 'true') {
        document.documentElement.classList.add('dark');
    }

    // Initialize charts (placeholder for actual chart implementation)
    const initCharts = () => {
        // This would be replaced with actual Chart + metrics.cost.current.toFixed(3);
    });
    
    // Update memory usage bar
    const memoryPercent = (metrics.memory.total / 2) * 100;
    document.querySelector('.memory-usage-bar').style.width = `${Math.min(100, memoryPercent)}%`;
    
    // Update cost performance bar
    const costPercent = (metrics.cost.current / metrics.cost.target) * 100;
    document.querySelector('.cost-performance-bar').style.width = `${Math.min(100, costPercent)}%`;
}

document.addEventListener('DOMContentLoaded', function() {
    // Initialize metrics and start simulation
    updateMetrics();
    setInterval(simulateData, 10000);
    
    // Initialize tooltips
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
    
    tooltipTriggers.forEach(trigger => {
        const tooltip = document.createElement('div');
        tooltip.className = 'absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip';
        tooltip.textContent = trigger.getAttribute('data-tooltip');
        trigger.appendChild(tooltip);
        
        trigger.addEventListener('mouseenter', () => {
            tooltip.classList.remove('invisible', 'opacity-0');
            tooltip.classList.add('visible', 'opacity-100');
        });
        
        trigger.addEventListener('mouseleave', () => {
            tooltip.classList.remove('visible', 'opacity-100');
            tooltip.classList.add('invisible', 'opacity-0');
        });
    });

    // Dark mode toggle
    const darkModeToggle = document.getElementById('dark-mode-toggle');
    if (darkModeToggle) {
        darkModeToggle.addEventListener('click', () => {
            document.documentElement.classList.toggle('dark');
            localStorage.setItem('darkMode', document.documentElement.classList.contains('dark'));
        });
    }

    // Check for saved dark mode preference
    if (localStorage.getItem('darkMode') === 'true') {
        document.documentElement.classList.add('dark');
    }

    // Initialize charts (placeholder for actual chart implementation)
    const initCharts = () => {
        // This would be replaced with actual Chart