@sleep2agi/commhub-server 0.5.0-preview.34 → 0.5.0-preview.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.5.0-preview.34",
3
+ "version": "0.5.0-preview.36",
4
4
  "description": "CommHub Server \u2014 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/auth.ts CHANGED
@@ -85,22 +85,15 @@ export function login(username: string, password: string): AuthResult {
85
85
  if (!user) return { ok: false, error: "invalid username or password" };
86
86
  if (user.password_hash !== hashPassword(password)) return { ok: false, error: "invalid username or password" };
87
87
 
88
- // Generate/rotate user token (utok_, not bound to network)
89
- let userTokenRow = db.get<any>(
90
- "SELECT token_id FROM api_tokens WHERE user_id = ?1 AND scope = 'user' ORDER BY created_at DESC LIMIT 1",
91
- user.user_id);
92
-
88
+ // Issue a NEW user token do NOT rotate/invalidate existing ones. Each
89
+ // login (cli, dashboard, second machine) gets its own row so they don't
90
+ // kick each other out of session. Tokens can be revoked via /api/auth/tokens.
93
91
  const userToken = generateUserToken();
94
- if (userTokenRow) {
95
- db.run("UPDATE api_tokens SET token_hash = ?1, last_used_at = datetime('now') WHERE token_id = ?2",
96
- [hashToken(userToken), userTokenRow.token_id]);
97
- } else {
98
- const tokenId = generateId("tok");
99
- db.run(
100
- "INSERT INTO api_tokens (token_id, token_hash, user_id, network_id, name, scope) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
101
- [tokenId, hashToken(userToken), user.user_id, null, "user-login", "user"]
102
- );
103
- }
92
+ const tokenId = generateId("tok");
93
+ db.run(
94
+ "INSERT INTO api_tokens (token_id, token_hash, user_id, network_id, name, scope) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
95
+ [tokenId, hashToken(userToken), user.user_id, null, "user-login", "user"]
96
+ );
104
97
 
105
98
  // Find default network
106
99
  const defaultNet = db.get<any>(
package/src/index.ts CHANGED
@@ -10,6 +10,14 @@ const PORT = Number(process.env.PORT) || 9200;
10
10
  const HOST = process.env.HOST || "0.0.0.0";
11
11
  const AUTH_TOKEN = process.env.COMMHUB_AUTH_TOKEN;
12
12
 
13
+ // Read version from package.json so banners and /health stay in sync.
14
+ const SERVER_VERSION = (() => {
15
+ try {
16
+ const url = new URL("../package.json", import.meta.url);
17
+ return JSON.parse(require("fs").readFileSync(url, "utf8")).version || "?";
18
+ } catch { return "?"; }
19
+ })();
20
+
13
21
  // ── Rate limiter (in-memory, per IP) ──
14
22
  const rateLimits = new Map<string, { count: number; resetAt: number }>();
15
23
  function checkRateLimit(ip: string, maxPerMinute = 60): boolean {
@@ -594,7 +602,7 @@ Bun.serve({
594
602
  const license = db.get<any>("SELECT type, expires_at FROM licenses LIMIT 1");
595
603
  return withCors(req, Response.json({
596
604
  ok: true,
597
- version: "0.5.0-preview.33",
605
+ version: SERVER_VERSION,
598
606
  api_version: "v3",
599
607
  transport: "streamable-http",
600
608
  sessions_count: count?.cnt ?? 0,
@@ -913,7 +921,7 @@ Bun.serve({
913
921
  }
914
922
 
915
923
  return withCors(req, new Response(
916
- `CommHub MCP Server v0.5.0-preview.33 (Streamable HTTP + SSE Push)
924
+ `CommHub MCP Server v${SERVER_VERSION} (Streamable HTTP + SSE Push)
917
925
 
918
926
  Endpoints:
919
927
  POST /mcp - MCP Streamable HTTP (for Claude Code / Codex)
@@ -1025,7 +1033,7 @@ process.on("SIGINT", shutdown);
1025
1033
 
1026
1034
  console.log(`
1027
1035
  ╔══════════════════════════════════════════════════╗
1028
- ║ CommHub MCP Server v0.5.0-preview.33
1036
+ ║ CommHub MCP Server v${SERVER_VERSION}
1029
1037
  ║ Transport: Streamable HTTP (Bun native) ║
1030
1038
  ║ Auth: ${AUTH_TOKEN ? "ENABLED (Bearer token)" : "DISABLED (set COMMHUB_AUTH_TOKEN)"}${"".padEnd(AUTH_TOKEN ? 5 : 0)}║
1031
1039
  ║ ║