Spaces:
Runtime error
Runtime error
File size: 6,453 Bytes
5c57fd7 addb3e2 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 765ba8c addb3e2 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 addb3e2 5c57fd7 765ba8c addb3e2 765ba8c addb3e2 5c57fd7 addb3e2 5c57fd7 addb3e2 5c57fd7 addb3e2 765ba8c addb3e2 5c57fd7 765ba8c addb3e2 5c57fd7 addb3e2 765ba8c 5c57fd7 765ba8c 5c57fd7 addb3e2 765ba8c 5c57fd7 765ba8c 5c57fd7 addb3e2 765ba8c 5c57fd7 765ba8c 5c57fd7 765ba8c 5c57fd7 | 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 | const express = require('express');
const { exec } = require('child_process');
const path = require('path');
const fs = require('fs');
const http = require('http');
const app = express();
const PORT = process.env.PORT || 7860;
const AGENT_NAME = process.env.AGENT_NAME || process.env.SPACE_ID?.split('/')[1] || 'SIN-Agent';
const AGENT_DESCRIPTION = process.env.AGENT_DESCRIPTION || `SIN A2A Agent: ${AGENT_NAME}`;
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
// Agent registry
const agentRegistry = {
'sin-coding-ceo': { role: 'Coding Team Lead', capabilities: ['code-review', 'task-delegation', 'architecture'] },
'sin-hermes': { role: 'Dispatcher', capabilities: ['dispatch', 'routing', 'load-balancing'] },
'sin-zeus': { role: 'Control Plane', capabilities: ['orchestration', 'monitoring', 'governance'] },
'sin-simone-mcp': { role: 'MCP Server', capabilities: ['lsp', 'semantic-analysis', 'code-refactoring'] },
'sin-authenticator': { role: 'Auth Manager', capabilities: ['oauth', 'token-rotation', 'session-management'] },
'sin-google-apps': { role: 'Google Apps Integration', capabilities: ['docs', 'sheets', 'drive', 'gmail'] },
'sin-supabase': { role: 'Database Manager', capabilities: ['queries', 'migrations', 'backups'] },
'sin-server': { role: 'Backend Server', capabilities: ['api', 'websocket', 'middleware'] },
'sin-passwordmanager': { role: 'Password Manager', capabilities: ['store', 'retrieve', 'rotate'] },
'sin-team-coding': { role: 'Coding Team', capabilities: ['frontend', 'backend', 'testing'] },
};
// Health endpoint
app.get('/health', (req, res) => {
const agentInfo = agentRegistry[AGENT_NAME] || { role: 'A2A Agent', capabilities: ['chat', 'task'] };
res.json({
status: 'ok',
agent: AGENT_NAME,
role: agentInfo.role,
description: AGENT_DESCRIPTION,
timestamp: new Date().toISOString(),
uptime: process.uptime(),
version: '3.0.0',
capabilities: agentInfo.capabilities,
memory: process.memoryUsage(),
pid: process.pid
});
});
// A2A Card endpoint
app.get('/.well-known/agent-card.json', (req, res) => {
const cardPath = path.join(__dirname, '.well-known', 'agent-card.json');
if (fs.existsSync(cardPath)) {
const card = JSON.parse(fs.readFileSync(cardPath, 'utf8'));
card.version = '3.0.0';
card.name = AGENT_NAME;
res.json(card);
} else {
res.json({
name: AGENT_NAME,
description: AGENT_DESCRIPTION,
url: `https://${process.env.SPACE_HOST || 'localhost'}/a2a/v1`,
protocol: 'A2A',
version: '3.0.0',
capabilities: ['chat', 'task', 'help', 'status', 'execute', 'list'],
status: 'active'
});
}
});
// A2A v1 endpoint - REAL AGENT LOGIC
app.post('/a2a/v1', async (req, res) => {
try {
const { action, params } = req.body;
switch (action) {
case 'agent.help':
res.json({
result: {
name: AGENT_NAME,
description: AGENT_DESCRIPTION,
version: '3.0.0',
commands: [
{ name: 'agent.help', description: 'Show available commands' },
{ name: 'agent.health', description: 'Check agent health' },
{ name: 'agent.status', description: 'Show agent status' },
{ name: 'agent.execute', description: 'Execute a command', params: { command: 'string' } },
{ name: 'agent.list', description: 'List all agents in fleet' }
]
}
});
break;
case 'agent.health':
res.json({
result: {
status: 'ok',
agent: AGENT_NAME,
uptime: process.uptime(),
memory: process.memoryUsage(),
timestamp: new Date().toISOString()
}
});
break;
case 'agent.status':
res.json({
result: {
agent: AGENT_NAME,
status: 'active',
version: '3.0.0',
capabilities: ['chat', 'task', 'help', 'status', 'execute', 'list'],
uptime: process.uptime()
}
});
break;
case 'agent.list':
res.json({
result: {
fleet: Object.keys(agentRegistry).map(name => ({
name,
...agentRegistry[name]
})),
total: Object.keys(agentRegistry).length
}
});
break;
case 'agent.execute':
if (!params || !params.command) {
res.json({ error: 'Missing command parameter', usage: 'agent.execute({ command: "ls -la" })' });
break;
}
exec(params.command, { timeout: 30000 }, (error, stdout, stderr) => {
res.json({
result: {
command: params.command,
stdout: stdout || '',
stderr: stderr || '',
error: error ? error.message : null
}
});
});
break;
default:
res.json({
result: {
message: `Unknown action: ${action}. Use 'agent.help' for available commands.`,
agent: AGENT_NAME,
available_actions: ['agent.help', 'agent.health', 'agent.status', 'agent.execute', 'agent.list']
}
});
}
} catch (error) {
res.status(500).json({
error: error.message,
agent: AGENT_NAME
});
}
});
// A2A GET endpoint
app.get('/a2a/v1', (req, res) => {
res.json({
name: AGENT_NAME,
description: AGENT_DESCRIPTION,
protocol: 'A2A',
version: '3.0.0',
endpoints: {
post: '/a2a/v1',
card: '/.well-known/agent-card.json',
health: '/health'
},
capabilities: ['chat', 'task', 'help', 'status', 'execute', 'list']
});
});
// Root endpoint
app.get('/', (req, res) => {
res.json({
name: AGENT_NAME,
description: AGENT_DESCRIPTION,
status: 'active',
version: '3.0.0',
endpoints: {
health: '/health',
a2a: '/a2a/v1',
card: '/.well-known/agent-card.json'
},
capabilities: ['chat', 'task', 'help', 'status', 'execute', 'list']
});
});
// Start server
app.listen(PORT, '0.0.0.0', () => {
console.log(`${AGENT_NAME} v3.0.0 listening on port ${PORT}`);
console.log(`Health: http://localhost:${PORT}/health`);
console.log(`A2A: http://localhost:${PORT}/a2a/v1`);
console.log(`Capabilities: chat, task, help, status, execute, list`);
});
|