Jeremy commited on
Commit
46f37af
·
1 Parent(s): 1a19a5c

feat: upgrade to A2A Server v2.0 with real agent logic

Browse files
Files changed (1) hide show
  1. server.js +56 -20
server.js CHANGED
@@ -1,15 +1,13 @@
1
  const express = require('express');
 
2
  const path = require('path');
3
  const fs = require('fs');
4
 
5
  const app = express();
6
  const PORT = process.env.PORT || 7860;
7
-
8
- // Agent name from env or default
9
  const AGENT_NAME = process.env.AGENT_NAME || 'SIN-Agent';
10
  const AGENT_DESCRIPTION = process.env.AGENT_DESCRIPTION || 'SIN A2A Agent';
11
 
12
- // Middleware
13
  app.use(express.json());
14
  app.use(express.static(path.join(__dirname, 'public')));
15
 
@@ -18,9 +16,11 @@ app.get('/health', (req, res) => {
18
  res.json({
19
  status: 'ok',
20
  agent: AGENT_NAME,
 
21
  timestamp: new Date().toISOString(),
22
  uptime: process.uptime(),
23
- version: '1.0.0'
 
24
  });
25
  });
26
 
@@ -35,14 +35,20 @@ app.get('/.well-known/agent-card.json', (req, res) => {
35
  description: AGENT_DESCRIPTION,
36
  url: `https://${process.env.SPACE_HOST || 'localhost'}/a2a/v1`,
37
  protocol: 'A2A',
38
- version: '1.0.0',
39
- capabilities: ['chat', 'task'],
 
 
 
 
 
 
40
  status: 'active'
41
  });
42
  }
43
  });
44
 
45
- // A2A v1 endpoint
46
  app.post('/a2a/v1', async (req, res) => {
47
  try {
48
  const { action, params } = req.body;
@@ -53,8 +59,13 @@ app.post('/a2a/v1', async (req, res) => {
53
  result: {
54
  name: AGENT_NAME,
55
  description: AGENT_DESCRIPTION,
56
- commands: ['help', 'health', 'status'],
57
- version: '1.0.0'
 
 
 
 
 
58
  }
59
  });
60
  break;
@@ -64,27 +75,48 @@ app.post('/a2a/v1', async (req, res) => {
64
  result: {
65
  status: 'ok',
66
  agent: AGENT_NAME,
67
- uptime: process.uptime()
 
 
68
  }
69
  });
70
  break;
71
 
72
- case 'agent.card':
73
  res.json({
74
  result: {
75
- name: AGENT_NAME,
76
- description: AGENT_DESCRIPTION,
77
- protocol: 'A2A',
78
- version: '1.0.0'
 
79
  }
80
  });
81
  break;
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  default:
84
  res.json({
85
  result: {
86
  message: `Unknown action: ${action}. Use 'agent.help' for available commands.`,
87
- agent: AGENT_NAME
 
88
  }
89
  });
90
  }
@@ -102,12 +134,13 @@ app.get('/a2a/v1', (req, res) => {
102
  name: AGENT_NAME,
103
  description: AGENT_DESCRIPTION,
104
  protocol: 'A2A',
105
- version: '1.0.0',
106
  endpoints: {
107
  post: '/a2a/v1',
108
  card: '/.well-known/agent-card.json',
109
  health: '/health'
110
- }
 
111
  });
112
  });
113
 
@@ -117,17 +150,20 @@ app.get('/', (req, res) => {
117
  name: AGENT_NAME,
118
  description: AGENT_DESCRIPTION,
119
  status: 'active',
 
120
  endpoints: {
121
  health: '/health',
122
  a2a: '/a2a/v1',
123
  card: '/.well-known/agent-card.json'
124
- }
 
125
  });
126
  });
127
 
128
  // Start server
129
  app.listen(PORT, '0.0.0.0', () => {
130
- console.log(`${AGENT_NAME} listening on port ${PORT}`);
131
  console.log(`Health: http://localhost:${PORT}/health`);
132
  console.log(`A2A: http://localhost:${PORT}/a2a/v1`);
 
133
  });
 
1
  const express = require('express');
2
+ const { exec } = require('child_process');
3
  const path = require('path');
4
  const fs = require('fs');
5
 
6
  const app = express();
7
  const PORT = process.env.PORT || 7860;
 
 
8
  const AGENT_NAME = process.env.AGENT_NAME || 'SIN-Agent';
9
  const AGENT_DESCRIPTION = process.env.AGENT_DESCRIPTION || 'SIN A2A Agent';
10
 
 
11
  app.use(express.json());
12
  app.use(express.static(path.join(__dirname, 'public')));
13
 
 
16
  res.json({
17
  status: 'ok',
18
  agent: AGENT_NAME,
19
+ description: AGENT_DESCRIPTION,
20
  timestamp: new Date().toISOString(),
21
  uptime: process.uptime(),
22
+ version: '2.0.0',
23
+ capabilities: ['chat', 'task', 'help', 'status', 'execute']
24
  });
25
  });
26
 
 
35
  description: AGENT_DESCRIPTION,
36
  url: `https://${process.env.SPACE_HOST || 'localhost'}/a2a/v1`,
37
  protocol: 'A2A',
38
+ version: '2.0.0',
39
+ capabilities: ['chat', 'task', 'help', 'status', 'execute'],
40
+ commands: [
41
+ { name: 'agent.help', description: 'Show available commands' },
42
+ { name: 'agent.health', description: 'Check agent health' },
43
+ { name: 'agent.status', description: 'Show agent status' },
44
+ { name: 'agent.execute', description: 'Execute a command' }
45
+ ],
46
  status: 'active'
47
  });
48
  }
49
  });
50
 
51
+ // A2A v1 endpoint - REAL AGENT LOGIC
52
  app.post('/a2a/v1', async (req, res) => {
53
  try {
54
  const { action, params } = req.body;
 
59
  result: {
60
  name: AGENT_NAME,
61
  description: AGENT_DESCRIPTION,
62
+ version: '2.0.0',
63
+ commands: [
64
+ { name: 'agent.help', description: 'Show available commands' },
65
+ { name: 'agent.health', description: 'Check agent health' },
66
+ { name: 'agent.status', description: 'Show agent status' },
67
+ { name: 'agent.execute', description: 'Execute a command', params: { command: 'string' } }
68
+ ]
69
  }
70
  });
71
  break;
 
75
  result: {
76
  status: 'ok',
77
  agent: AGENT_NAME,
78
+ uptime: process.uptime(),
79
+ memory: process.memoryUsage(),
80
+ timestamp: new Date().toISOString()
81
  }
82
  });
83
  break;
84
 
85
+ case 'agent.status':
86
  res.json({
87
  result: {
88
+ agent: AGENT_NAME,
89
+ status: 'active',
90
+ version: '2.0.0',
91
+ capabilities: ['chat', 'task', 'help', 'status', 'execute'],
92
+ uptime: process.uptime()
93
  }
94
  });
95
  break;
96
 
97
+ case 'agent.execute':
98
+ if (!params || !params.command) {
99
+ res.json({ error: 'Missing command parameter', usage: 'agent.execute({ command: "ls -la" })' });
100
+ break;
101
+ }
102
+ exec(params.command, { timeout: 30000 }, (error, stdout, stderr) => {
103
+ res.json({
104
+ result: {
105
+ command: params.command,
106
+ stdout: stdout || '',
107
+ stderr: stderr || '',
108
+ error: error ? error.message : null
109
+ }
110
+ });
111
+ });
112
+ break;
113
+
114
  default:
115
  res.json({
116
  result: {
117
  message: `Unknown action: ${action}. Use 'agent.help' for available commands.`,
118
+ agent: AGENT_NAME,
119
+ available_actions: ['agent.help', 'agent.health', 'agent.status', 'agent.execute']
120
  }
121
  });
122
  }
 
134
  name: AGENT_NAME,
135
  description: AGENT_DESCRIPTION,
136
  protocol: 'A2A',
137
+ version: '2.0.0',
138
  endpoints: {
139
  post: '/a2a/v1',
140
  card: '/.well-known/agent-card.json',
141
  health: '/health'
142
+ },
143
+ capabilities: ['chat', 'task', 'help', 'status', 'execute']
144
  });
145
  });
146
 
 
150
  name: AGENT_NAME,
151
  description: AGENT_DESCRIPTION,
152
  status: 'active',
153
+ version: '2.0.0',
154
  endpoints: {
155
  health: '/health',
156
  a2a: '/a2a/v1',
157
  card: '/.well-known/agent-card.json'
158
+ },
159
+ capabilities: ['chat', 'task', 'help', 'status', 'execute']
160
  });
161
  });
162
 
163
  // Start server
164
  app.listen(PORT, '0.0.0.0', () => {
165
+ console.log(`${AGENT_NAME} v2.0.0 listening on port ${PORT}`);
166
  console.log(`Health: http://localhost:${PORT}/health`);
167
  console.log(`A2A: http://localhost:${PORT}/a2a/v1`);
168
+ console.log(`Capabilities: chat, task, help, status, execute`);
169
  });