File size: 31,066 Bytes
27290c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ae5c82
 
 
 
 
 
 
 
 
 
 
 
 
27290c2
1ae5c82
 
 
27290c2
1ae5c82
 
 
 
 
 
 
27290c2
 
1ae5c82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27290c2
 
 
1ae5c82
27290c2
1ae5c82
 
 
 
 
 
 
 
 
 
 
 
27290c2
1ae5c82
 
27290c2
1ae5c82
 
27290c2
1ae5c82
 
 
 
 
 
 
 
27290c2
 
1ae5c82
27290c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f22db89
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nexus AI Framework - Advanced Multi-Agent System</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script>
    <script>
        tailwind.config = {
            darkMode: 'class',
            theme: {
                extend: {
                    colors: {
                        violet: {
                            50: '#f5f3ff',
                            100: '#ede9fe',
                            200: '#ddd6fe',
                            300: '#c4b5fd',
                            400: '#a78bfa',
                            500: '#8b5cf6',
                            600: '#7c3aed',
                            700: '#6d28d9',
                            800: '#5b21b6',
                            900: '#4c1d95',
                        }
                    },
                    animation: {
                        'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
                        'float': 'float 6s ease-in-out infinite',
                        'glow': 'glow 2s ease-in-out infinite alternate',
                    },
                    keyframes: {
                        float: {
                            '0%, 100%': { transform: 'translateY(0)' },
                            '50%': { transform: 'translateY(-10px)' },
                        },
                        glow: {
                            '0%': { boxShadow: '0 0 20px rgba(139, 92, 246, 0.5)' },
                            '100%': { boxShadow: '0 0 30px rgba(139, 92, 246, 0.8)' },
                        }
                    }
                }
            }
        }
    </script>
    <style>
        .glass-morphism {
            background: rgba(17, 24, 39, 0.7);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(139, 92, 246, 0.2);
        }
        .neon-border {
            box-shadow: 0 0 20px rgba(139, 92, 246, 0.3), inset 0 0 20px rgba(139, 92, 246, 0.1);
        }
        .agent-card {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .agent-card:hover {
            transform: translateY(-5px) scale(1.02);
        }
        .message-bubble {
            animation: slideIn 0.3s ease-out;
        }
        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateX(-20px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }
        .neural-network {
            background: radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.1) 0%, transparent 70%);
        }
        .code-block {
            background: linear-gradient(135deg, #1e1b4b 0%, #0f0f23 100%);
        }
        .pulse-ring {
            animation: pulseRing 2s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
        }
        @keyframes pulseRing {
            0% {
                transform: scale(0.95);
                opacity: 1;
            }
            100% {
                transform: scale(1.4);
                opacity: 0;
            }
        }
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #1f2937;
        }
        ::-webkit-scrollbar-thumb {
            background: #8b5cf6;
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #7c3aed;
        }
    </style>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen overflow-x-hidden">
    <!-- Vanta.js Background -->
    <div id="vanta-bg" class="fixed inset-0 z-0"></div>
    
    <!-- Main Content -->
    <div class="relative z-10">
        <!-- Navigation Header -->
        <nav class="glass-morphism sticky top-0 z-50 px-6 py-4 border-b border-violet-500/20">
            <div class="max-w-7xl mx-auto flex items-center justify-between">
                <div class="flex items-center space-x-4">
                    <div class="relative">
                        <div class="w-10 h-10 bg-violet-600 rounded-lg flex items-center justify-center">
                            <i data-feather="cpu" class="w-6 h-6"></i>
                        </div>
                        <div class="absolute -inset-1 bg-violet-600 rounded-lg pulse-ring"></div>
                    </div>
                    <h1 class="text-2xl font-bold bg-gradient-to-r from-violet-400 to-violet-600 bg-clip-text text-transparent">
                        Nexus AI Framework
                    </h1>
                </div>
                <div class="flex items-center space-x-6">
                    <button class="flex items-center space-x-2 px-4 py-2 rounded-lg bg-violet-600 hover:bg-violet-700 transition-colors">
                        <i data-feather="play" class="w-4 h-4"></i>
                        <span>Start Simulation</span>
                    </button>
                    <button class="p-2 rounded-lg hover:bg-gray-800 transition-colors">
                        <i data-feather="settings" class="w-5 h-5"></i>
                    </button>
                </div>
            </div>
        </nav>
        <!-- Main Interface -->
        <div class="max-w-7xl mx-auto p-6 space-y-6">
            <!-- LLM Configuration -->
            <div class="glass-morphism rounded-xl p-6 neon-border">
                <h2 class="text-xl font-semibold mb-6 flex items-center space-x-2">
                <i data-feather="settings" class="w-5 h-5 text-violet-400"></i>
                <span>LLM Configuration</span>
            </h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-300 mb-2">LM Studio Server</label>
                        <input type="text" id="lm-studio-url" value="http://localhost:1234" class="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:outline-none focus:border-violet-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-300 mb-2">Model Name</label>
                        <input type="text" id="model-name" placeholder="Enter model name" class="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:outline-none focus:border-violet-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-300 mb-2">Temperature</label>
                        <input type="range" id="temperature" min="0" max="1" step="0.1" value="0.7" class="w-full">
                        <div class="flex justify-between text-xs text-gray-400">
                            <span>0</span>
                            <span>0.5</span>
                            <span>1.0</span>
                    </div>
                </div>
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-300 mb-2">Max Tokens</label>
                        <input type="number" id="max-tokens" value="512" class="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:outline-none focus:border-violet-500">
                    </div>
                    <div class="flex items-center space-x-4">
                        <button onclick="testConnection()" class="px-4 py-2 bg-violet-600 rounded-lg hover:bg-violet-700 transition-colors">
                            Test Connection
                        </button>
                        <button onclick="loadModels()" class="px-4 py-2 bg-violet-600 rounded-lg hover:bg-violet-700 transition-colors">
                            Load Models
                        </button>
                    </div>
                    <div id="connection-status" class="text-sm">
                        <!-- Connection status will be shown here -->
                    </div>
                </div>
            </div>
        </div>

        <!-- Chat Interface -->
        <div class="glass-morphism rounded-xl p-6 neon-border">
            <h2 class="text-xl font-semibold mb-6 flex items-center space-x-2">
                <i data-feather="message-square" class="w-5 h-5 text-violet-400"></i>
                <span>LLM Chat Interface</span>
            </h2>
            <div class="space-y-4">
                <div class="flex space-x-4">
                    <input type="text" id="user-input" placeholder="Enter your message..." class="flex-1 px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:outline-none focus:border-violet-500">
                    <button onclick="sendMessage()" class="px-6 py-2 bg-violet-600 rounded-lg hover:bg-violet-700 transition-colors">
                        <i data-feather="send" class="w-4 h-4"></i>
                    </button>
                </div>
                <div id="chat-messages" class="space-y-4 max-h-96 overflow-y-auto">
                        <!-- Chat messages will be displayed here -->
                </div>
            </div>
        </div>

        <!-- System Logs -->
        <div class="glass-morphism rounded-xl p-6 neon-border">
            <h2 class="text-xl font-semibold mb-6 flex items-center space-x-2">
                <i data-feather="terminal" class="w-5 h-5 text-violet-400"></i>
                <span>System Logs</span>
            </h2>
            <div id="system-logs" class="space-y-2 max-h-64 overflow-y-auto font-mono text-sm">
                <!-- System logs will be displayed here -->
            </div>
        </div>
</div>

    <script>
        // Initialize Vanta.js background
        VANTA.NET({
            el: "#vanta-bg",
            mouseControls: true,
            touchControls: true,
            gyroControls: false,
            minHeight: 200.00,
            minWidth: 200.00,
            scale: 1.00,
            scaleMobile: 1.00,
            color: 0x8b5cf6,
            backgroundColor: 0x111827,
            points: 10.00,
            maxDistance: 20.00,
            spacing: 15.00
        });

        // Agent System Core
        class AgentSystem {
            constructor() {
                this.agents = new Map();
                this.messages = [];
                this.tasks = [];
                this.performanceData = {
                    labels: [],
                    datasets: [{
                        label: 'CPU Usage',
                        data: [],
                        borderColor: 'rgb(139, 92, 246)',
                        backgroundColor: 'rgba(139, 92, 246, 0.1)',
                        tension: 0.4
                    }]
                };
                this.initializeAgents();
                this.startSimulation();
            }

            initializeAgents() {
                const agentTypes = [
                    { name: 'Analyzer', type: 'analytical', specialization: 'data-analysis', status: 'active' },
                    { name: 'Creator', type: 'creative', specialization: 'content-generation', status: 'active' },
                    { name: 'Decider', type: 'decision', specialization: 'strategic-planning', status: 'idle' },
                    { name: 'Coordinator', type: 'coordination', specialization: 'task-orchestration', status: 'active' }
                ];

                agentTypes.forEach((config, index) => {
                    this.createAgent(config);
                });
            }

            createAgent(config) {
                const agent = {
                    id: `agent-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
                    ...config,
                    thoughts: [],
                    goals: [],
                    memory: {
                        short: [],
                        long: [],
                        working: []
                    },
                    tools: this.assignTools(config.specialization),
                    metrics: {
                        tasksCompleted: 0,
                        messagesProcessed: 0,
                        accuracy: Math.random() * 20 + 80,
                        efficiency: Math.random() * 30 + 70
                    }
                };
                this.agents.set(agent.id, agent);
                this.renderAgent(agent);
                return agent;
            }

            assignTools(specialization) {
                const toolsets = {
                    'data-analysis': ['python', 'sql', 'pandas', 'numpy'],
                    'content-generation': ['nlp', 'gpt', 'image-gen', 'text-to-speech'],
                    'strategic-planning': ['frameworks', 'models', 'simulator', 'optimizer'],
                    'task-orchestration': ['scheduler', 'queue', 'monitor', 'balancer']
                };
                return toolsets[specialization] || ['basic-tools'];
            }

            renderAgent(agent) {
                const container = document.getElementById('agents-container');
                const agentCard = document.createElement('div');
                agentCard.className = 'agent-card glass-morphism rounded-lg p-4 border border-violet-500/20 hover:border-violet-500/40';
                agentCard.id = `card-${agent.id}`;
                agentCard.innerHTML = `
                    <div class="flex items-start justify-between mb-3">
                        <div class="flex items-center space-x-3">
                            <div class="w-10 h-10 bg-violet-600 rounded-lg flex items-center justify-center">
                                <i data-feather="${this.getAgentIcon(agent.type)}" class="w-5 h-5"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold">${agent.name}</h4>
                                <span class="text-xs px-2 py-1 rounded-full ${
                                    agent.status === 'active' ? 'bg-green-500/20 text-green-400' : 'bg-gray-500/20 text-gray-400'
                                }">${agent.status}</span>
                            </div>
                        </div>
                        <button onclick="agentSystem.removeAgent('${agent.id}')" class="p-1 hover:bg-red-500/20 rounded transition-colors">
                            <i data-feather="x" class="w-4 h-4"></i>
                        </button>
                    </div>
                    <div class="space-y-2 text-sm">
                        <div class="flex justify-between">
                            <span class="text-gray-400">Specialization:</span>
                            <span class="text-violet-400">${agent.specialization}</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-400">Accuracy:</span>
                            <span>${agent.metrics.accuracy.toFixed(1)}%</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-400">Efficiency:</span>
                            <span>${agent.metrics.efficiency.toFixed(1)}%</span>
                        </div>
                    </div>
                    <div class="mt-3 pt-3 border-t border-gray-700">
                        <div class="text-xs text-gray-400">
                            <div>Tasks: ${agent.metrics.tasksCompleted}</div>
                            <div>Messages: ${agent.metrics.messagesProcessed}</div>
                        </div>
                    </div>
                `;
                container.appendChild(agentCard);
                feather.replace();
            }

            getAgentIcon(type) {
                const icons = {
                    'analytical': 'bar-chart-2',
                    'creative': 'pen-tool',
                    'decision': 'git-branch',
                    'coordination': 'git-pull-request'
                };
                return icons[type] || 'cpu';
            }

            removeAgent(agentId) {
                this.agents.delete(agentId);
                const card = document.getElementById(`card-${agentId}`);
                if (card) {
                    anime({
                        targets: card,
                        opacity: 0,
                        scale: 0.8,
                        duration: 300,
                        easing: 'easeInOutQuad',
                        complete: () => card.remove()
                    });
                }
            }

            startSimulation() {
                setInterval(() => this.simulateAgentActivity(), 2000);
                setInterval(() => this.updatePerformanceMetrics(), 1000);
                setInterval(() => this.simulateMemoryUsage(), 3000);
                this.initializeChart();
            }

            simulateAgentActivity() {
                const agents = Array.from(this.agents.values());
                if (agents.length < 2) return;

                const sender = agents[Math.floor(Math.random() * agents.length)];
                const receiver = agents[Math.floor(Math.random() * agents.length)];
                
                if (sender.id !== receiver.id) {
                    this.sendMessage(sender, receiver);
                    this.processTask(sender);
                }
            }

            sendMessage(sender, receiver) {
                const intents = ['ask', 'respond', 'delegate', 'alert', 'inform'];
                const intent = intents[Math.floor(Math.random() * intents.length)];
                
                const message = {
                    id: `msg-${Date.now()}`,
                    from: sender.id,
                    to: receiver.id,
                    intent: intent,
                    content: this.generateMessageContent(intent, sender.specialization),
                    timestamp: new Date(),
                    priority: Math.random() > 0.7 ? 'high' : 'normal'
                };

                this.messages.push(message);
                this.renderMessage(message);
                sender.metrics.messagesProcessed++;
                this.updateAgentCard(sender);
            }

            generateMessageContent(intent, specialization) {
                const templates = {
                    'ask': [
                        `Requesting analysis on ${specialization} data`,
                        `Need input on current ${specialization} strategy`,
                        `Query regarding ${specialization} optimization`
                    ],
                    'respond': [
                        `Analysis complete for ${specialization} module`,
                        `Response to ${specialization} query received`,
                        `Updated ${specialization} parameters`
                    ],
                    'delegate': [
                        `Delegating ${specialization} task to your queue`,
                        `Please handle this ${specialization} request`,
                        `${specialization} processing required`
                    ],
                    'alert': [
                        `Alert: ${specialization} threshold exceeded`,
                        `Warning: ${specialization} anomaly detected`,
                        `Critical: ${specialization} system stress`
                    ],
                    'inform': [
                        `Update: ${specialization} status changed`,
                        `Info: ${specialization} module updated`,
                        `Notification: ${specialization} complete`
                    ]
                };
                
                const messages = templates[intent] || templates['inform'];
                return messages[Math.floor(Math.random() * messages.length)];
            }

            renderMessage(message) {
                const container = document.getElementById('message-flow');
                const messageEl = document.createElement('div');
                messageEl.className = 'message-bubble flex items-start space-x-3 p-3 rounded-lg bg-gray-800/50 border-l-4 border-violet-500';
                
                const sender = this.agents.get(message.from);
                const receiver = this.agents.get(message.to);
                
                messageEl.innerHTML = `
                    <div class="flex-1">
                        <div class="flex items-center justify-between mb-1">
                            <span class="text-sm font-semibold">${sender.name}${receiver.name}</span>
                            <span class="text-xs text-gray-400">${message.timestamp.toLocaleTimeString()}</span>
                        </div>
                        <p class="text-sm text-gray-300">${message.content}</p>
                        <div class="flex items-center space-x-2 mt-2">
                            <span class="text-xs px-2 py-1 rounded bg-violet-500/20 text-violet-400">${message.intent}</span>
                            ${message.priority === 'high' ? '<span class="text-xs px-2 py-1 rounded bg-red-500/20 text-red-400">HIGH</span>' : ''}
                        </div>
                    </div>
                `;
                
                container.insertBefore(messageEl, container.firstChild);
                if (container.children.length > 10) {
                    container.removeChild(container.lastChild);
                }
            }

            processTask(agent) {
                const taskTypes = ['analysis', 'generation', 'optimization', 'coordination'];
                const task = {
                    id: `task-${Date.now()}`,
                    type: taskTypes[Math.floor(Math.random() * taskTypes.length)],
                    assignedTo: agent.id,
                    status: 'processing',
                    progress: 0,
                    createdAt: new Date()
                };
                
                this.tasks.push(task);
                this.renderTask(task);
                
                // Simulate task progress
                const progressInterval = setInterval(() => {
                    task.progress += Math.random() * 30;
                    if (task.progress >= 100) {
                        task.progress = 100;
                        task.status = 'completed';
                        agent.metrics.tasksCompleted++;
                        this.updateAgentCard(agent);
                        clearInterval(progressInterval);
                        setTimeout(() => this.removeTask(task.id), 2000);
                    }
                    this.updateTaskProgress(task);
                }, 1000);
            }

            renderTask(task) {
                const container = document.getElementById('task-queue');
                const taskEl = document.createElement('div');
                taskEl.className = 'p-3 rounded-lg bg-gray-800/50 border border-gray-700';
                taskEl.id = `task-${task.id}`;
                
                const agent = this.agents.get(task.assignedTo);
                
                taskEl.innerHTML = `
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-sm font-medium">${task.type}</span>
                        <span class="text-xs px-2 py-1 rounded ${
                            task.status === 'completed' ? 'bg-green-500/20 text-green-400' : 'bg-yellow-500/20 text-yellow-400'
                        }">${task.status}</span>
                    </div>
                    <div class="text-xs text-gray-400 mb-2">Assigned to: ${agent.name}</div>
                    <div class="w-full bg-gray-700 rounded-full h-1.5">
                        <div class="bg-violet-500 h-1.5 rounded-full transition-all duration-500" style="width: ${task.progress}%"></div>
                    </div>
                `;
                
                container.insertBefore(taskEl, container.firstChild);
                if (container.children.length > 5) {
                    container.removeChild(container.lastChild);
                }
            }

            updateTaskProgress(task) {
                const taskEl = document.getElementById(`task-${task.id}`);
                if (taskEl) {
                    const progressBar = taskEl.querySelector('.bg-violet-500');
                    const statusBadge = taskEl.querySelector('.rounded');
                    progressBar.style.width = `${task.progress}%`;
                    
                    if (task.status === 'completed') {
                        statusBadge.className = 'text-xs px-2 py-1 rounded bg-green-500/20 text-green-400';
                        statusBadge.textContent = 'completed';
                    }
                }
            }

            removeTask(taskId) {
                const taskEl = document.getElementById(`task-${taskId}`);
                if (taskEl) {
                    anime({
                        targets: taskEl,
                        opacity: 0,
                        translateX: -20,
                        duration: 300,
                        easing: 'easeInOutQuad',
                        complete: () => taskEl.remove()
                    });
                }
            }

            updateAgentCard(agent) {
                const card = document.getElementById(`card-${agent.id}`);
                if (card) {
                    const metricsDiv = card.querySelector('.text-xs.text-gray-400');
                    metricsDiv.innerHTML = `
                        <div>Tasks: ${agent.metrics.tasksCompleted}</div>
                        <div>Messages: ${agent.metrics.messagesProcessed}</div>
                    `;
                }
            }

            updatePerformanceMetrics() {
                const cpuUsage = Math.random() * 30 + 40;
                const time = new Date().toLocaleTimeString();
                
                this.performanceData.labels.push(time);
                this.performanceData.datasets[0].data.push(cpuUsage);
                
                if (this.performanceData.labels.length > 10) {
                    this.performanceData.labels.shift();
                    this.performanceData.datasets[0].data.shift();
                }
                
                if (window.performanceChart) {
                    window.performanceChart.update('none');
                }
            }

            simulateMemoryUsage() {
                const shortTerm = Math.random() * 30 + 40;
                const longTerm = Math.random() * 20 + 60;
                const working = Math.random() * 40 + 20;
                
                document.getElementById('short-term-memory').textContent = `${shortTerm.toFixed(0)}%`;
                document.getElementById('long-term-memory').textContent = `${longTerm.toFixed(0)}%`;
                document.getElementById('working-memory').textContent = `${working.toFixed(0)}%`;
                
                document.getElementById('short-term-bar').style.width = `${shortTerm}%`;
                document.getElementById('long-term-bar').style.width = `${longTerm}%`;
                document.getElementById('working-bar').style.width = `${working}%`;
            }

            initializeChart() {
                const ctx = document.getElementById('performance-chart').getContext('2d');
                window.performanceChart = new Chart(ctx, {
                    type: 'line',
                    data: this.performanceData,
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                display: false
                            }
                        },
                        scales: {
                            x: {
                                display: false
                            },
                            y: {
                                beginAtZero: true,
                                max: 100,
                                ticks: {
                                    color: '#9ca3af',
                                    callback: function(value) {
                                        return value + '%';
                                    }
                                },
                                grid: {
                                    color: 'rgba(75, 85, 99, 0.3)'
                                }
                            }
                        }
                    }
                });
            }
        }

        // Initialize the system
        let agentSystem;
        document.addEventListener('DOMContentLoaded', () => {
            feather.replace();
            agentSystem = new AgentSystem();
            
            // Add animations
            anime({
                targets: '.agent-card',
                opacity: [0, 1],
                translateY: [20, 0],
                delay: anime.stagger(100),
                duration: 800,
                easing: 'easeOutQuad'
            });
        });

        // Global functions
        function createAgent() {
            const types = ['analytical', 'creative', 'decision', 'coordination'];
            const specializations = ['data-analysis', 'content-generation', 'strategic-planning', 'task-orchestration'];
            const names = ['Quantum', 'Nova', 'Phoenix', 'Titan', 'Oracle', 'Matrix', 'Nexus', 'Vertex'];
            
            const config = {
                name: names[Math.floor(Math.random() * names.length)] + '-' + Math.floor(Math.random() * 100),
                type: types[Math.floor(Math.random() * types.length)],
                specialization: specializations[Math.floor(Math.random() * specializations.length)],
                status: Math.random() > 0.3 ? 'active' : 'idle'
            };
            
            agentSystem.createAgent(config);
            
            // Animate new agent card
            setTimeout(() => {
                const newCard = document.querySelectorAll('.agent-card')[document.querySelectorAll('.agent-card').length - 1];
                anime({
                    targets: newCard,
                    scale: [0.8, 1],
                    opacity: [0, 1],
                    duration: 500,
                    easing: 'easeOutBack'
                });
            }, 100);
        }
    </script>
</body>
</html>