@skvil/piertotum 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/broker.js +11 -1
- package/mcp-server.js +9 -3
- package/package.json +1 -1
package/broker.js
CHANGED
|
@@ -125,6 +125,9 @@ app.post('/agents/register', (req, res) => {
|
|
|
125
125
|
if (typeof agentId !== 'string' || typeof name !== 'string') {
|
|
126
126
|
return res.status(400).json({ error: 'agentId e name devem ser strings' });
|
|
127
127
|
}
|
|
128
|
+
if (agentId.length > 64 || name.length > 128) {
|
|
129
|
+
return res.status(400).json({ error: 'agentId (máx 64) ou name (máx 128) excede o limite' });
|
|
130
|
+
}
|
|
128
131
|
|
|
129
132
|
if (!agents.has(agentId) && agents.size >= MAX_AGENTS) {
|
|
130
133
|
return res.status(429).json({ error: `Limite de ${MAX_AGENTS} agentes atingido` });
|
|
@@ -317,6 +320,12 @@ app.post('/context', (req, res) => {
|
|
|
317
320
|
if (!key || value === undefined || value === null) {
|
|
318
321
|
return res.status(400).json({ error: 'key e value são obrigatórios' });
|
|
319
322
|
}
|
|
323
|
+
if (typeof key !== 'string') {
|
|
324
|
+
return res.status(400).json({ error: 'key deve ser uma string' });
|
|
325
|
+
}
|
|
326
|
+
if (key.length > 256) {
|
|
327
|
+
return res.status(400).json({ error: 'key deve ter no máximo 256 caracteres' });
|
|
328
|
+
}
|
|
320
329
|
|
|
321
330
|
if (Buffer.byteLength(JSON.stringify(value), 'utf8') > MAX_CONTEXT_VALUE_SIZE) {
|
|
322
331
|
return res.status(413).json({ error: `Valor excede o limite de ${MAX_CONTEXT_VALUE_SIZE / 1024}KB` });
|
|
@@ -383,7 +392,8 @@ app.get('/status', (req, res) => {
|
|
|
383
392
|
// ══════════════════════════════════════════════
|
|
384
393
|
|
|
385
394
|
app.use((req, res) => {
|
|
386
|
-
|
|
395
|
+
const safePath = req.path.replace(/[\x00-\x1f\x7f]/g, '');
|
|
396
|
+
res.status(404).json({ error: `Rota não encontrada: ${req.method} ${safePath}` });
|
|
387
397
|
});
|
|
388
398
|
|
|
389
399
|
// Error handler — retorna JSON em vez de HTML (ex: body JSON malformado)
|
package/mcp-server.js
CHANGED
|
@@ -48,7 +48,7 @@ function validateBrokerUrl(raw) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const BROKER_URL = validateBrokerUrl(process.env.BROKER_URL || 'http://localhost:4800').replace(/\/+$/, '');
|
|
51
|
-
const AGENT_ID = process.env.AGENT_ID || os.hostname().toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
51
|
+
const AGENT_ID = (process.env.AGENT_ID || os.hostname()).toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
52
52
|
const AGENT_NAME = process.env.AGENT_NAME || `SP-${AGENT_ID}`;
|
|
53
53
|
const PROJECT_NAME = process.env.PROJECT_NAME || 'unknown';
|
|
54
54
|
|
|
@@ -83,7 +83,7 @@ function formatUptime(seconds) {
|
|
|
83
83
|
function formatLastSeen(lastSeenIso) {
|
|
84
84
|
if (!lastSeenIso) return 'desconhecido';
|
|
85
85
|
const diffMs = Date.now() - new Date(lastSeenIso).getTime();
|
|
86
|
-
const diffS = Math.floor(diffMs / 1000);
|
|
86
|
+
const diffS = Math.max(0, Math.floor(diffMs / 1000));
|
|
87
87
|
if (diffS < 60) return `há ${diffS}s`;
|
|
88
88
|
const diffM = Math.floor(diffS / 60);
|
|
89
89
|
if (diffM < 60) return `há ${diffM}min`;
|
|
@@ -201,6 +201,9 @@ server.tool(
|
|
|
201
201
|
return { content: [{ type: 'text', text: `❌ ${result.error}` }] };
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
if (!result.agents) {
|
|
205
|
+
return { content: [{ type: 'text', text: '⚠️ Resposta inesperada do broker' }] };
|
|
206
|
+
}
|
|
204
207
|
if (result.agents.length === 0) {
|
|
205
208
|
return { content: [{ type: 'text', text: '📭 Nenhum agente registrado.' }] };
|
|
206
209
|
}
|
|
@@ -402,6 +405,9 @@ server.tool(
|
|
|
402
405
|
return { content: [{ type: 'text', text: `❌ ${result.error}` }] };
|
|
403
406
|
}
|
|
404
407
|
|
|
408
|
+
if (!result.contexts) {
|
|
409
|
+
return { content: [{ type: 'text', text: '⚠️ Resposta inesperada do broker' }] };
|
|
410
|
+
}
|
|
405
411
|
if (result.contexts.length === 0) {
|
|
406
412
|
return { content: [{ type: 'text', text: '📭 Nenhum contexto compartilhado.' }] };
|
|
407
413
|
}
|
|
@@ -455,7 +461,7 @@ server.tool(
|
|
|
455
461
|
return { content: [{ type: 'text', text: `❌ ${result.error}` }] };
|
|
456
462
|
}
|
|
457
463
|
|
|
458
|
-
const agentLines = result.agents.map(a =>
|
|
464
|
+
const agentLines = (result.agents || []).map(a =>
|
|
459
465
|
` • ${a.name} (${a.agentId}) — ${a.project} — ${a.unreadMessages} msgs não lidas`
|
|
460
466
|
);
|
|
461
467
|
|