@sleep2agi/commhub-server 0.5.0-preview.7 → 0.5.0-preview.8
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 +20 -1
- package/src/tools.ts +34 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -286,6 +286,24 @@ Bun.serve({
|
|
|
286
286
|
return withCors(req, Response.json({ ok: true, messages: rows }));
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
// ── REST: stats summary ──
|
|
290
|
+
if (url.pathname === "/api/stats") {
|
|
291
|
+
const taskStats = db.query<any, []>("SELECT status, COUNT(*) as count FROM tasks GROUP BY status").all();
|
|
292
|
+
const sessionStats = db.query<any, []>("SELECT status, COUNT(*) as count FROM sessions GROUP BY status").all();
|
|
293
|
+
const totalTasks = db.query<{ cnt: number }, []>("SELECT COUNT(*) as cnt FROM tasks").get();
|
|
294
|
+
const totalNodes = db.query<{ cnt: number }, []>("SELECT COUNT(*) as cnt FROM nodes").get();
|
|
295
|
+
const recentTasks = db.query<any, []>(
|
|
296
|
+
"SELECT task_id, from_name, to_name, status, created_at FROM tasks ORDER BY created_at DESC LIMIT 5"
|
|
297
|
+
).all();
|
|
298
|
+
return withCors(req, Response.json({
|
|
299
|
+
ok: true,
|
|
300
|
+
tasks: { total: totalTasks?.cnt || 0, by_status: taskStats },
|
|
301
|
+
sessions: { by_status: sessionStats },
|
|
302
|
+
nodes: { total: totalNodes?.cnt || 0 },
|
|
303
|
+
recent_tasks: recentTasks,
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
306
|
+
|
|
289
307
|
// ── REST: task events (V2 Sprint 2) ──
|
|
290
308
|
if (url.pathname === "/api/task_events") {
|
|
291
309
|
const taskId = url.searchParams.get("task_id");
|
|
@@ -330,7 +348,8 @@ Bun.serve({
|
|
|
330
348
|
params.push(limit);
|
|
331
349
|
|
|
332
350
|
const rows = db.query(sql).all(...params);
|
|
333
|
-
|
|
351
|
+
const stats = db.query<any, []>("SELECT status, COUNT(*) as count FROM tasks GROUP BY status").all();
|
|
352
|
+
return withCors(req, Response.json({ ok: true, tasks: rows, count: rows.length, stats }));
|
|
334
353
|
}
|
|
335
354
|
|
|
336
355
|
// ── REST: recent completions ──
|
package/src/tools.ts
CHANGED
|
@@ -565,6 +565,40 @@ export function registerTools(server: McpServer, clientIP?: string) {
|
|
|
565
565
|
}
|
|
566
566
|
);
|
|
567
567
|
|
|
568
|
+
// ── V2: list_tasks (查询任务列表) ──
|
|
569
|
+
server.tool(
|
|
570
|
+
"list_tasks",
|
|
571
|
+
"List tasks with filters. Agents can query their own pending/running tasks.",
|
|
572
|
+
{
|
|
573
|
+
alias: z.string().max(200).optional().describe("Filter by to_name (target agent)"),
|
|
574
|
+
status: z.string().max(50).optional().describe("Filter by status"),
|
|
575
|
+
from_name: z.string().max(200).optional().describe("Filter by sender"),
|
|
576
|
+
limit: z.number().min(1).max(100).optional().default(20),
|
|
577
|
+
},
|
|
578
|
+
async ({ alias, status, from_name, limit }) => {
|
|
579
|
+
let sql = "SELECT task_id, from_name, to_name, priority, status, content, result, created_at, completed_at FROM tasks WHERE 1=1";
|
|
580
|
+
const params: any[] = [];
|
|
581
|
+
if (alias) { sql += ` AND to_name = ?${params.length + 1}`; params.push(alias); }
|
|
582
|
+
if (status) { sql += ` AND status = ?${params.length + 1}`; params.push(status); }
|
|
583
|
+
if (from_name) { sql += ` AND from_name = ?${params.length + 1}`; params.push(from_name); }
|
|
584
|
+
sql += ` ORDER BY created_at DESC LIMIT ?${params.length + 1}`;
|
|
585
|
+
params.push(limit);
|
|
586
|
+
const tasks = db.query(sql).all(...params);
|
|
587
|
+
|
|
588
|
+
// Stats
|
|
589
|
+
const stats = db.query<any, []>(
|
|
590
|
+
"SELECT status, COUNT(*) as count FROM tasks GROUP BY status"
|
|
591
|
+
).all();
|
|
592
|
+
|
|
593
|
+
return {
|
|
594
|
+
content: [{
|
|
595
|
+
type: "text" as const,
|
|
596
|
+
text: JSON.stringify({ ok: true, tasks, count: tasks.length, stats }),
|
|
597
|
+
}],
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
);
|
|
601
|
+
|
|
568
602
|
// ── V2: cancel_task (取消任务) ──
|
|
569
603
|
server.tool(
|
|
570
604
|
"cancel_task",
|