Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
245 lines (206 loc) · 7.75 KB
/
Copy pathscript.js
File metadata and controls
245 lines (206 loc) · 7.75 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Agents AI Status Dashboard JavaScript
/**
* Initialize the agents dashboard
*/
document.addEventListener('DOMContentLoaded', () => {
const logContainer = document.querySelector('.log-container');
const restartButtons = document.querySelectorAll('.btn-primary');
const viewLogsButtons = document.querySelectorAll('.btn-secondary');
// Auto-scroll logs
let autoScroll = true;
logContainer.addEventListener('scroll', () => {
const isAtBottom = logContainer.scrollHeight - logContainer.scrollTop === logContainer.clientHeight;
autoScroll = isAtBottom;
});
// Simulate live log updates
startLogSimulation();
// Handle restart button clicks
restartButtons.forEach(button => {
button.addEventListener('click', handleRestart);
});
// Handle view logs button clicks
viewLogsButtons.forEach(button => {
button.addEventListener('click', handleViewLogs);
});
/**
* Simulate live log updates
*/
function startLogSimulation() {
const logMessages = [
{ level: 'info', message: 'Agent heartbeat check completed' },
{ level: 'success', message: 'Task queue processed successfully' },
{ level: 'info', message: 'Performance metrics updated' },
{ level: 'warning', message: 'High memory usage detected' },
{ level: 'success', message: 'Cache cleared successfully' },
{ level: 'info', message: 'Configuration reloaded' }
];
setInterval(() => {
const randomMessage = logMessages[Math.floor(Math.random() * logMessages.length)];
addLogEntry(randomMessage.level, randomMessage.message);
}, 5000); // Add new log every 5 seconds
}
/**
* Add a new log entry
*/
function addLogEntry(level, message) {
const now = new Date();
const timeString = now.toTimeString().split(' ')[0];
const isoString = now.toISOString();
const logEntry = document.createElement('div');
logEntry.className = 'log-entry';
// Create time element
const timeElement = document.createElement('time');
timeElement.setAttribute('datetime', isoString);
timeElement.textContent = timeString;
// Create level element
const levelElement = document.createElement('span');
levelElement.className = `log-level log-${level}`;
levelElement.textContent = level.toUpperCase();
// Create message element
const messageElement = document.createElement('span');
messageElement.className = 'log-message';
messageElement.textContent = message;
logEntry.appendChild(timeElement);
logEntry.appendChild(levelElement);
logEntry.appendChild(messageElement);
logContainer.appendChild(logEntry);
// Keep only last 50 log entries
const entries = logContainer.querySelectorAll('.log-entry');
if (entries.length > 50) {
entries[0].remove();
}
// Auto-scroll if enabled
if (autoScroll) {
logContainer.scrollTop = logContainer.scrollHeight;
}
}
/**
* Handle restart button click
*/
function handleRestart(event) {
const button = event.currentTarget;
const agentCard = button.closest('.agent-card');
const agentName = agentCard.querySelector('h3').textContent;
button.disabled = true;
button.textContent = 'Restarting...';
// Simulate restart process
setTimeout(() => {
addLogEntry('info', `${agentName} restart initiated`);
setTimeout(() => {
addLogEntry('success', `${agentName} restarted successfully`);
button.disabled = false;
button.textContent = 'Restart';
showNotification(`${agentName} has been restarted`, 'success');
}, 2000);
}, 1000);
}
/**
* Handle view logs button click
*/
function handleViewLogs(event) {
const button = event.currentTarget;
const agentCard = button.closest('.agent-card');
const agentName = agentCard.querySelector('h3').textContent;
// Scroll to logs section
const logsSection = document.querySelector('.logs-section');
logsSection.scrollIntoView({ behavior: 'smooth' });
// Filter logs for this agent (simulated)
addLogEntry('info', `Viewing logs for ${agentName}`);
showNotification(`Showing logs for ${agentName}`, 'info');
}
/**
* Update agent metrics periodically
*/
function updateMetrics() {
const agentCards = document.querySelectorAll('.agent-card');
agentCards.forEach(card => {
const requestsElement = card.querySelector('.metric:nth-child(2) .metric-value');
if (requestsElement) {
const currentRequests = parseInt(requestsElement.textContent);
const increment = Math.floor(Math.random() * 3);
if (increment > 0) {
requestsElement.textContent = currentRequests + increment;
}
}
});
}
// Update metrics every 10 seconds
setInterval(updateMetrics, 10000);
/**
* Show notification
*/
function showNotification(message, type = 'info') {
let container = document.getElementById('notification-container');
if (!container) {
container = document.createElement('div');
container.id = 'notification-container';
container.className = 'notification-container';
container.setAttribute('aria-live', 'polite');
container.setAttribute('aria-atomic', 'true');
document.body.appendChild(container);
}
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
notification.setAttribute('role', 'status');
container.appendChild(notification);
setTimeout(() => {
notification.style.opacity = '0';
setTimeout(() => {
container.removeChild(notification);
}, 300);
}, 4000);
}
/**
* Monitor system status
*/
function checkSystemHealth() {
const activeCount = document.querySelectorAll('.status-badge.status-active').length;
const totalAgents = document.querySelectorAll('.agent-card').length;
if (activeCount < totalAgents * 0.5) {
addLogEntry('warning', 'System health degraded - less than 50% agents active');
}
}
// Check system health every 30 seconds
setInterval(checkSystemHealth, 30000);
});
// Add notification styles dynamically
const notificationStyles = document.createElement('style');
notificationStyles.textContent = `
.notification-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 10px;
max-width: 350px;
}
.notification {
padding: 1rem 1.5rem;
border-radius: 8px;
background: white;
border: 2px solid #00bcd4;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
opacity: 1;
transition: opacity 0.3s ease;
font-weight: 500;
}
.notification-success {
border-color: #28a745;
background: #d4edda;
}
.notification-info {
border-color: #17a2b8;
background: #d1ecf1;
}
@media (max-width: 768px) {
.notification-container {
left: 20px;
right: 20px;
max-width: none;
}
}
`;
document.head.appendChild(notificationStyles);