@sleep2agi/commhub-server 0.5.3-preview.0 → 0.6.0

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/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  CommHub: MCP Streamable HTTP + SSE push + REST API for an AI agent network. Single-process Bun server, SQLite-backed, zero config.
4
4
 
5
- **v0.5.0 stable.** The supported path is to install the `anet` CLI (`@sleep2agi/agent-network` 2.0.0) and run `anet hub start`, which wires up port, default account, and config for you.
5
+ **Current preview line.** The supported path is to install the `anet` CLI (`@sleep2agi/agent-network` 2.0.3-preview.4) and run `anet hub start`, which wires up port, the server token, the default account, and local config for you.
6
6
 
7
7
  ## Quick start (verified)
8
8
 
9
9
  ```bash
10
10
  # Recommended — through the anet CLI
11
- npm install -g @sleep2agi/agent-network
11
+ npm install -g @sleep2agi/agent-network@preview
12
12
  anet hub start
13
- # • http://127.0.0.1:9200 (also bound to LAN)
13
+ # • http://127.0.0.1:9200 by default
14
14
  # • SQLite at ~/.commhub/commhub.db
15
15
  # • Default admin account auto-created: admin / anethub
16
16
  # • Reset hint printed in the launch banner
@@ -35,9 +35,9 @@ Once running:
35
35
 
36
36
  | Package | Version |
37
37
  |---|---|
38
- | [`@sleep2agi/agent-network`](https://www.npmjs.com/package/@sleep2agi/agent-network) | 2.0.0 |
39
- | [`@sleep2agi/agent-network-dashboard`](https://www.npmjs.com/package/@sleep2agi/agent-network-dashboard) | 0.1.0 |
40
- | [`@sleep2agi/agent-node`](https://www.npmjs.com/package/@sleep2agi/agent-node) | 2.1.1 |
38
+ | [`@sleep2agi/agent-network`](https://www.npmjs.com/package/@sleep2agi/agent-network) | 2.0.3-preview.4 |
39
+ | [`@sleep2agi/agent-network-dashboard`](https://www.npmjs.com/package/@sleep2agi/agent-network-dashboard) | 0.2.1-preview.1 |
40
+ | [`@sleep2agi/agent-node`](https://www.npmjs.com/package/@sleep2agi/agent-node) | 2.2.0-preview.1 |
41
41
 
42
42
  ## MCP tools (18)
43
43
 
@@ -87,7 +87,7 @@ The server exposes ~33 endpoints across health, auth, networks, and observabilit
87
87
  | GET | `/api/stats` | Aggregate stats |
88
88
  | GET | `/api/audit-log` | Audit trail |
89
89
 
90
- Network-management endpoints (`/api/networks…`) and `/api/license[…]` are present but are **not** part of the v2.0.0 verified flow — see *Not verified* below.
90
+ Network-management endpoints (`/api/networks…`) are present and used by the current CLI. `/api/license[…]` is present but remains a placeholder.
91
91
 
92
92
  Auth: `Authorization: Bearer <token>` header, or `?token=<token>` query.
93
93
 
@@ -123,7 +123,7 @@ delivered/acked/running → reassign → delivered (new agent)
123
123
 
124
124
  ## PostgreSQL (experimental)
125
125
 
126
- Set `DATABASE_URL` to switch to PostgreSQL — the SQL layer auto-translates SQLite-isms (datetime, parameter placeholders) so application code is unchanged. Requires `bun add pg`. **Not in the v2.0.0 verified path.**
126
+ Set `DATABASE_URL` to switch to PostgreSQL — the SQL layer auto-translates SQLite-isms (datetime, parameter placeholders) so application code is unchanged. Requires `bun add pg`. PostgreSQL remains experimental.
127
127
 
128
128
  ```bash
129
129
  DATABASE_URL=postgres://user:pass@host:5432/commhub bunx @sleep2agi/commhub-server
@@ -134,7 +134,7 @@ DATABASE_URL=postgres://user:pass@host:5432/commhub bunx @sleep2agi/commhub-serv
134
134
  | Variable | Default | Notes |
135
135
  |---|---|---|
136
136
  | `PORT` | `9200` | listen port |
137
- | `HOST` | `0.0.0.0` | listen address |
137
+ | `HOST` | `0.0.0.0` in the server package, `127.0.0.1` when launched by `anet hub start` | listen address |
138
138
  | `COMMHUB_AUTH_TOKEN` | (none) | Bearer token gate (legacy) |
139
139
  | `COMMHUB_DB` | `~/.commhub/commhub.db` | SQLite path |
140
140
  | `DATABASE_URL` | (none) | switches to PostgreSQL when set (unverified) |
@@ -148,10 +148,9 @@ DATABASE_URL=postgres://user:pass@host:5432/commhub bunx @sleep2agi/commhub-serv
148
148
 
149
149
  ## Not verified
150
150
 
151
- - `/api/networks*` (multi-network create / invite / member management) — code present, not E2E regressed.
152
151
  - `/api/license*` — placeholder for a future paid tier.
153
152
  - PostgreSQL backend — translation layer exists, no E2E run.
154
- - Telegram / WeChat / Feishu channel endpoints — out of scope for v2.0.0 verification.
153
+ - Telegram / WeChat / Feishu channel endpoints — channel code exists, but only Telegram-oriented agent-node paths are actively exercised.
155
154
 
156
155
  ## License
157
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.5.3-preview.0",
3
+ "version": "0.6.0",
4
4
  "description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and 18 MCP tools.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -699,11 +699,32 @@ Bun.serve({
699
699
  }
700
700
  const id = crypto.randomUUID();
701
701
  const fromSession = body.from || "api";
702
- db.run(
703
- `INSERT INTO inbox (id, session_name, type, priority, content, from_session, network_id)
704
- VALUES (?1, ?2, 'task', ?3, ?4, ?5, ?6)`,
705
- [id, body.alias, body.priority, body.task, fromSession, taskNetId]
706
- );
702
+ const ttlSeconds = (body as any).ttl_seconds || 3600;
703
+ // Mirror send_task MCP: write inbox + tasks rows in a single
704
+ // transaction so the dispatch is visible to dashboard's Tasks page
705
+ // and the parent_task_id lineage chain. Previously this endpoint
706
+ // only wrote inbox, leaving GET /api/tasks empty for any task
707
+ // dispatched via REST (anet demo, dashboard Dispatch button, etc.).
708
+ db.transaction(() => {
709
+ db.run(
710
+ `INSERT INTO inbox (id, session_name, type, priority, content, from_session, requires_response, network_id)
711
+ VALUES (?1, ?2, 'task', ?3, ?4, ?5, 'reply', ?6)`,
712
+ [id, body.alias, body.priority, body.task, fromSession, taskNetId]
713
+ );
714
+ db.run(
715
+ `INSERT INTO tasks (task_id, from_name, to_name, priority, status, content, requires_response, created_at, delivered_at, expires_at, network_id)
716
+ VALUES (?1, ?2, ?3, ?4, 'delivered', ?5, 'reply', datetime('now'), datetime('now'), datetime('now', ?6), ?7)`,
717
+ [id, fromSession, body.alias, body.priority, body.task, `+${ttlSeconds} seconds`, taskNetId]
718
+ );
719
+ // Touch session row so the dashboard reflects "task in flight"
720
+ // immediately, without waiting for the agent's report_status to
721
+ // arrive. Updating both `task` and `updated_at` is enough — we
722
+ // leave `status` to the agent (idle → working → idle).
723
+ const touchParams: any[] = [body.task.slice(0, 200), body.alias];
724
+ let touchSql = "UPDATE sessions SET task = ?1, updated_at = datetime('now') WHERE alias = ?2";
725
+ if (taskNetId) { touchSql += " AND network_id = ?3"; touchParams.push(taskNetId); }
726
+ db.run(touchSql, touchParams);
727
+ });
707
728
  // SSE push: 秒达
708
729
  const pendingParams: any[] = [body.alias];
709
730
  let pendingSql = "SELECT COUNT(*) as cnt FROM inbox WHERE session_name = ?1 AND acked = 0";
package/src/tools.ts CHANGED
@@ -453,7 +453,10 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
453
453
 
454
454
  console.log(`[${ts()}] ${from_session} → send_task → ${alias}: ${task.slice(0, 60)}${priority === "high" ? " [HIGH]" : ""}`);
455
455
  const id = uuidv4();
456
- // 事务:inbox + tasks 双写
456
+ // 事务:inbox + tasks 双写 + 触碰目标 session 的 task/updated_at(让
457
+ // dashboard 在派任务一刻就反映出"任务已下发",不再等 agent 的
458
+ // report_status 心跳;status 字段交给 agent,避免与 working/idle
459
+ // 报告冲突)。
457
460
  db.transaction(() => {
458
461
  db.run(
459
462
  `INSERT INTO inbox (id, session_name, type, priority, content, context, from_session, requires_response, network_id)
@@ -465,6 +468,10 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
465
468
  VALUES (?1, ?2, ?3, ?4, 'delivered', ?5, 'reply', datetime('now'), datetime('now'), datetime('now', ?6), ?7, ?8)`,
466
469
  [id, from_session, alias, priority, task, `+${ttl_seconds || 3600} seconds`, effectiveNetId ?? null, parentTaskId]
467
470
  );
471
+ const touchParams: any[] = [task.slice(0, 200), alias];
472
+ let touchSql = "UPDATE sessions SET task = ?1, updated_at = datetime('now') WHERE alias = ?2";
473
+ touchSql = addScope(touchSql, touchParams, effectiveNetId);
474
+ db.run(touchSql, touchParams);
468
475
  });
469
476
  logTaskEvent(id, null, "delivered", from_session, parentTaskId ? `→ ${alias} (parent=${parentTaskId.slice(0,8)})` : `→ ${alias}`);
470
477