-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo-swarm.js
More file actions
executable file
·139 lines (116 loc) · 5.72 KB
/
demo-swarm.js
File metadata and controls
executable file
·139 lines (116 loc) · 5.72 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
#!/usr/bin/env node
/**
* AI Agent Swarm - Demo Funcional
* Demonstração do ecossistema completo funcionando
*/
import { SimpleSwarmServiceManager } from './skills/service-manager-esm.js';
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
console.log('🚀 AI Agent Swarm - Demo Funcional');
console.log('=====================================');
async function demo() {
try {
// 1. Inicializar Service Manager
console.log('\n📦 1. Inicializando Service Manager...');
const serviceManager = new SimpleSwarmServiceManager();
// 2. Verificar status atual
console.log('\n📊 2. Verificando status dos serviços...');
const status = await serviceManager.execute({ action: 'status' });
if (status.success) {
console.log('✅ Status obtido com sucesso:');
console.log(` WebMap: ${status.status.webmap}`);
console.log(` SwarmClient: ${status.status.swarmclient}`);
console.log(` Platform: ${status.status.platform}`);
console.log(` Endpoint: ${status.status.endpoint}`);
} else {
console.log('❌ Falha ao obter status:', status.error);
}
// 3. Testar endpoint WebMap
console.log('\n🌐 3. Testando endpoint WebMap...');
try {
const response = await execAsync('curl -s http://localhost:3456/api/comms/messages');
if (response.stdout) {
console.log('✅ WebMap respondendo');
console.log(` Response length: ${response.stdout.length} chars`);
} else {
console.log('⚠️ WebMap não retornou dados (mas está rodando)');
}
} catch (error) {
console.log('⚠️ WebMap acessível mas sem resposta completa');
}
// 4. Verificar processos
console.log('\n🔍 4. Verificando processos ativos...');
try {
const { stdout } = await execAsync('ps aux | grep -E "(WebMap|SwarmClient)" | grep -v grep');
const processes = stdout.trim().split('\n');
console.log(`✅ ${processes.length} processos Swarm ativos:`);
processes.forEach(proc => {
const parts = proc.trim().split(/\s+/);
console.log(` PID: ${parts[1]} - ${parts[10]}`);
});
} catch (error) {
console.log('❌ Erro ao verificar processos:', error.message);
}
// 5. Verificar logs
console.log('\n📋 5. Verificando logs recentes...');
try {
const { stdout: webmapLog } = await execAsync('tail -3 .ai-workspace/logs/webmap.log');
const { stdout: swarmLog } = await execAsync('tail -3 .ai-workspace/logs/swarmclient.log');
console.log('📄 WebMap Log (últimas 3 linhas):');
console.log(' ' + webmapLog.trim().replace(/\n/g, '\n '));
console.log('📄 SwarmClient Log (últimas 3 linhas):');
console.log(' ' + swarmLog.trim().replace(/\n/g, '\n '));
} catch (error) {
console.log('⚠️ Logs não disponíveis ainda');
}
// 6. Testar funcionalidade básica
console.log('\n🧪 6. Testando funcionalidade básica...');
// Testar restart
console.log(' Testando restart dos serviços...');
const restartResult = await serviceManager.execute({ action: 'restart' });
if (restartResult.success) {
console.log('✅ Restart executado com sucesso');
} else {
console.log('⚠️ Restart com problemas:', restartResult.error);
}
// Verificar status pós-restart
await new Promise(resolve => setTimeout(resolve, 3000));
const postRestartStatus = await serviceManager.execute({ action: 'status' });
if (postRestartStatus.success) {
console.log('✅ Status pós-restart:');
console.log(` WebMap: ${postRestartStatus.status.webmap}`);
console.log(` SwarmClient: ${postRestartStatus.status.swarmclient}`);
}
// 7. Resumo do Demo
console.log('\n🎉 7. Resumo do Demo');
console.log('==================');
const servicesRunning = status.success &&
status.status.webmap === 'running' &&
status.status.swarmclient === 'running';
if (servicesRunning) {
console.log('✅ SUCESSO: Ecossistema Swarm fully operacional!');
console.log(' 🟢 WebMap: Rodando e respondendo');
console.log(' 🟢 SwarmClient: Rodando e conectado');
console.log(' 🟢 Scripts: Funcionando corretamente');
console.log(' 🟢 Skills: Prontas para uso');
} else {
console.log('⚠️ PARCIAL: Ecossistema funcionando com limitações');
console.log(' 📊 Verificar logs para detalhes');
}
console.log('\n📋 Próximos passos:');
console.log(' 1. Implementar Mesh Network');
console.log(' 2. Criar Intelligent Sync Engine');
console.log(' 3. Adicionar Security avançada');
console.log(' 4. Publicar skills no Nanobot Registry');
console.log('\n🌐 Endpoints disponíveis:');
console.log(' 📡 WebMap: http://localhost:3456');
console.log(' 📡 API: http://localhost:3456/api/comms');
console.log(' 📊 Health: ./scripts/health-monitor.sh check');
} catch (error) {
console.error('❌ Erro no demo:', error.message);
process.exit(1);
}
}
// Executar demo
demo().catch(console.error);