@sleep2agi/commhub-server 0.5.0-preview.12 → 0.5.0-preview.14
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/package.json +1 -1
- package/src/index.ts +19 -7
- package/src/tools.ts +11 -5
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -277,7 +277,11 @@ Bun.serve({
|
|
|
277
277
|
if (url.pathname === "/api/status") {
|
|
278
278
|
const cutoff = new Date(Date.now() - 10 * 60 * 1000).toISOString().replace("T", " ").slice(0, 19);
|
|
279
279
|
db.run("UPDATE sessions SET status = 'offline' WHERE updated_at < ?1 AND status != 'offline'", [cutoff]);
|
|
280
|
-
const
|
|
280
|
+
const netFilter = url.searchParams.get("network_id");
|
|
281
|
+
const sql = netFilter
|
|
282
|
+
? "SELECT * FROM sessions WHERE network_id = ?1 ORDER BY updated_at DESC"
|
|
283
|
+
: "SELECT * FROM sessions ORDER BY updated_at DESC";
|
|
284
|
+
const sessions = netFilter ? db.query(sql).all(netFilter) : db.query(sql).all();
|
|
281
285
|
return withCors(req, Response.json({ ok: true, sessions }));
|
|
282
286
|
}
|
|
283
287
|
|
|
@@ -401,15 +405,18 @@ Bun.serve({
|
|
|
401
405
|
|
|
402
406
|
// ── REST: stats summary ──
|
|
403
407
|
if (url.pathname === "/api/stats") {
|
|
404
|
-
const
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
const
|
|
408
|
+
const n = url.searchParams.get("network_id");
|
|
409
|
+
const nw = n ? ` WHERE network_id = '${n}'` : "";
|
|
410
|
+
const taskStats = db.query<any, []>(`SELECT status, COUNT(*) as count FROM tasks${nw} GROUP BY status`).all();
|
|
411
|
+
const sessionStats = db.query<any, []>(`SELECT status, COUNT(*) as count FROM sessions${nw} GROUP BY status`).all();
|
|
412
|
+
const totalTasks = db.query<{ cnt: number }, []>(`SELECT COUNT(*) as cnt FROM tasks${nw}`).get();
|
|
413
|
+
const totalNodes = db.query<{ cnt: number }, []>(`SELECT COUNT(*) as cnt FROM nodes${nw}`).get();
|
|
408
414
|
const recentTasks = db.query<any, []>(
|
|
409
|
-
|
|
415
|
+
`SELECT task_id, from_name, to_name, status, created_at FROM tasks${nw} ORDER BY created_at DESC LIMIT 5`
|
|
410
416
|
).all();
|
|
411
417
|
return withCors(req, Response.json({
|
|
412
418
|
ok: true,
|
|
419
|
+
network_id: n || null,
|
|
413
420
|
tasks: { total: totalTasks?.cnt || 0, by_status: taskStats },
|
|
414
421
|
sessions: { by_status: sessionStats },
|
|
415
422
|
nodes: { total: totalNodes?.cnt || 0 },
|
|
@@ -455,8 +462,10 @@ Bun.serve({
|
|
|
455
462
|
if (url.pathname === "/api/nodes") {
|
|
456
463
|
const nodeId = url.searchParams.get("node_id");
|
|
457
464
|
const alias = url.searchParams.get("alias");
|
|
465
|
+
const netFilter = url.searchParams.get("network_id");
|
|
458
466
|
let sql = "SELECT * FROM nodes WHERE 1=1";
|
|
459
467
|
const params: any[] = [];
|
|
468
|
+
if (netFilter) { sql += ` AND network_id = ?${params.length + 1}`; params.push(netFilter); }
|
|
460
469
|
if (nodeId) { sql += ` AND node_id = ?${params.length + 1}`; params.push(nodeId); }
|
|
461
470
|
if (alias) { sql += ` AND alias = ?${params.length + 1}`; params.push(alias); }
|
|
462
471
|
sql += " ORDER BY updated_at DESC";
|
|
@@ -470,10 +479,12 @@ Bun.serve({
|
|
|
470
479
|
const status = url.searchParams.get("status");
|
|
471
480
|
const toName = url.searchParams.get("to_name");
|
|
472
481
|
const fromName = url.searchParams.get("from_name");
|
|
482
|
+
const netFilter = url.searchParams.get("network_id");
|
|
473
483
|
const limit = Math.min(Number(url.searchParams.get("limit")) || 50, 200);
|
|
474
484
|
|
|
475
485
|
let sql = "SELECT * FROM tasks WHERE 1=1";
|
|
476
486
|
const params: any[] = [];
|
|
487
|
+
if (netFilter) { sql += ` AND network_id = ?${params.length + 1}`; params.push(netFilter); }
|
|
477
488
|
if (taskId) { sql += ` AND task_id = ?${params.length + 1}`; params.push(taskId); }
|
|
478
489
|
if (status) { sql += ` AND status = ?${params.length + 1}`; params.push(status); }
|
|
479
490
|
if (toName) { sql += ` AND to_name = ?${params.length + 1}`; params.push(toName); }
|
|
@@ -482,7 +493,8 @@ Bun.serve({
|
|
|
482
493
|
params.push(limit);
|
|
483
494
|
|
|
484
495
|
const rows = db.query(sql).all(...params);
|
|
485
|
-
const
|
|
496
|
+
const statsFilter = netFilter ? ` WHERE network_id = '${netFilter}'` : "";
|
|
497
|
+
const stats = db.query<any, []>(`SELECT status, COUNT(*) as count FROM tasks${statsFilter} GROUP BY status`).all();
|
|
486
498
|
return withCors(req, Response.json({ ok: true, tasks: rows, count: rows.length, stats }));
|
|
487
499
|
}
|
|
488
500
|
|
package/src/tools.ts
CHANGED
|
@@ -270,9 +270,10 @@ export function registerTools(server: McpServer, clientIP?: string) {
|
|
|
270
270
|
{
|
|
271
271
|
filter_status: z.string().max(50).optional(),
|
|
272
272
|
filter_server: z.string().max(200).optional(),
|
|
273
|
+
network_id: z.string().max(200).optional().describe("Filter by network"),
|
|
273
274
|
},
|
|
274
|
-
async ({ filter_status, filter_server }) => {
|
|
275
|
-
console.log(`[${ts()}] hub → get_all_status${filter_status ? ": filter=" + filter_status : ""}${
|
|
275
|
+
async ({ filter_status, filter_server, network_id: netId }) => {
|
|
276
|
+
console.log(`[${ts()}] hub → get_all_status${filter_status ? ": filter=" + filter_status : ""}${netId ? " net=" + netId.slice(0, 12) : ""}`);
|
|
276
277
|
|
|
277
278
|
const sessions = db.transaction(() => {
|
|
278
279
|
const cutoff = new Date(Date.now() - 10 * 60 * 1000).toISOString().replace("T", " ").slice(0, 19);
|
|
@@ -280,6 +281,7 @@ export function registerTools(server: McpServer, clientIP?: string) {
|
|
|
280
281
|
|
|
281
282
|
let sql = "SELECT * FROM sessions WHERE 1=1";
|
|
282
283
|
const params: any[] = [];
|
|
284
|
+
if (netId) { sql += " AND network_id = ?"; params.push(netId); }
|
|
283
285
|
if (filter_status) { sql += " AND status = ?"; params.push(filter_status); }
|
|
284
286
|
if (filter_server) { sql += " AND server = ?"; params.push(filter_server); }
|
|
285
287
|
sql += " ORDER BY updated_at DESC";
|
|
@@ -576,11 +578,13 @@ export function registerTools(server: McpServer, clientIP?: string) {
|
|
|
576
578
|
alias: z.string().max(200).optional().describe("Filter by to_name (target agent)"),
|
|
577
579
|
status: z.string().max(50).optional().describe("Filter by status"),
|
|
578
580
|
from_name: z.string().max(200).optional().describe("Filter by sender"),
|
|
581
|
+
network_id: z.string().max(200).optional().describe("Filter by network"),
|
|
579
582
|
limit: z.number().min(1).max(100).optional().default(20),
|
|
580
583
|
},
|
|
581
|
-
async ({ alias, status, from_name, limit }) => {
|
|
584
|
+
async ({ alias, status, from_name, network_id: netId, limit }) => {
|
|
582
585
|
let sql = "SELECT task_id, from_name, to_name, priority, status, content, result, created_at, completed_at FROM tasks WHERE 1=1";
|
|
583
586
|
const params: any[] = [];
|
|
587
|
+
if (netId) { sql += ` AND network_id = ?${params.length + 1}`; params.push(netId); }
|
|
584
588
|
if (alias) { sql += ` AND to_name = ?${params.length + 1}`; params.push(alias); }
|
|
585
589
|
if (status) { sql += ` AND status = ?${params.length + 1}`; params.push(status); }
|
|
586
590
|
if (from_name) { sql += ` AND from_name = ?${params.length + 1}`; params.push(from_name); }
|
|
@@ -672,11 +676,13 @@ export function registerTools(server: McpServer, clientIP?: string) {
|
|
|
672
676
|
message: z.string().min(1).max(10000),
|
|
673
677
|
filter_server: z.string().max(200).optional(),
|
|
674
678
|
filter_status: z.string().max(50).optional(),
|
|
679
|
+
network_id: z.string().max(200).optional().describe("Broadcast within a specific network"),
|
|
675
680
|
},
|
|
676
|
-
async ({ message, filter_server, filter_status }) => {
|
|
677
|
-
console.log(`[${ts()}] hub → broadcast: ${message.slice(0, 60)}${
|
|
681
|
+
async ({ message, filter_server, filter_status, network_id: netId }) => {
|
|
682
|
+
console.log(`[${ts()}] hub → broadcast: ${message.slice(0, 60)}${netId ? " [net=" + netId.slice(0, 12) + "]" : ""}`);
|
|
678
683
|
let sql = "SELECT alias FROM sessions WHERE alias IS NOT NULL";
|
|
679
684
|
const params: any[] = [];
|
|
685
|
+
if (netId) { sql += " AND network_id = ?"; params.push(netId); }
|
|
680
686
|
if (filter_server) { sql += " AND server = ?"; params.push(filter_server); }
|
|
681
687
|
if (filter_status) { sql += " AND status = ?"; params.push(filter_status); }
|
|
682
688
|
|