@sleep2agi/commhub-server 0.9.0-preview.279 → 0.9.0-preview.280
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/build-info.json +2 -2
- package/package.json +1 -1
- package/src/server.ts +21 -0
- package/src/status-node-secrets-capable-http.test.ts +44 -0
package/build-info.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.280",
|
|
4
4
|
"description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
package/src/server.ts
CHANGED
|
@@ -4904,6 +4904,26 @@ return Bun.serve({
|
|
|
4904
4904
|
return new Map<string, number>();
|
|
4905
4905
|
}
|
|
4906
4906
|
})();
|
|
4907
|
+
// The node 密钥 page gates on node_secrets_capable, which nodes report in
|
|
4908
|
+
// nodes.config_snapshot (not a sessions column). Without projecting it here the
|
|
4909
|
+
// app never saw it and fell back to the runtime version — null for claude-code
|
|
4910
|
+
// nodes — so a capable node (e.g. claude-code-cli on agent-network ≥ .219) was
|
|
4911
|
+
// shown "upgrade required". Only emitted when true: other rows keep their bytes.
|
|
4912
|
+
const nodeSecretsCapable = (() => {
|
|
4913
|
+
const ids = isLight ? [] : [...new Set(rows.map((r: any) => r.node_id).filter((v: unknown): v is string => typeof v === "string" && v.length > 0))];
|
|
4914
|
+
const out = new Set<string>();
|
|
4915
|
+
for (let i = 0; i < ids.length; i += 500) {
|
|
4916
|
+
const chunk = ids.slice(i, i + 500);
|
|
4917
|
+
try {
|
|
4918
|
+
const found = db.all<{ node_id: string; config_snapshot: string | null }>(
|
|
4919
|
+
`SELECT node_id, config_snapshot FROM nodes WHERE node_id IN (${chunk.map((_, j) => `?${j + 1}`).join(",")})`, ...chunk);
|
|
4920
|
+
for (const r of found) {
|
|
4921
|
+
try { if (JSON.parse(r.config_snapshot || "{}")?.node_secrets_capable === true) out.add(r.node_id); } catch { /* malformed snapshot: not capable */ }
|
|
4922
|
+
}
|
|
4923
|
+
} catch { /* projection is best-effort; never fail /api/status */ }
|
|
4924
|
+
}
|
|
4925
|
+
return out;
|
|
4926
|
+
})();
|
|
4907
4927
|
// `model` comes straight from the explicit sessions projection; `runtime` is
|
|
4908
4928
|
// derived from the raw `agent` field. Both default to null for old nodes
|
|
4909
4929
|
// that never reported a model — the dashboard falls back to a placeholder.
|
|
@@ -4960,6 +4980,7 @@ return Bun.serve({
|
|
|
4960
4980
|
skills_capable: s.skills_capable === 1,
|
|
4961
4981
|
files_capable: s.files_capable === 1,
|
|
4962
4982
|
logs_capable: s.logs_capable === 1,
|
|
4983
|
+
...(s.node_id && nodeSecretsCapable.has(s.node_id) ? { node_secrets_capable: true } : {}),
|
|
4963
4984
|
model: s.model ?? null,
|
|
4964
4985
|
runtime: normalizeRuntime(s.agent),
|
|
4965
4986
|
host: {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The node 密钥 page gates on node_secrets_capable. Nodes report it in
|
|
2
|
+
// nodes.config_snapshot; /api/status did not project it, so the app fell back to the
|
|
3
|
+
// runtime version (null for claude-code nodes) and told a capable node to upgrade.
|
|
4
|
+
import { afterAll, beforeAll, expect, test } from "bun:test";
|
|
5
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import { tmpdir } from "os";
|
|
8
|
+
import { register } from "./auth.js";
|
|
9
|
+
import { db } from "./db.js";
|
|
10
|
+
|
|
11
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-status-node-secrets-"));
|
|
12
|
+
let BASE = "", hub: any = null, userToken = "", userId = "", NET = "";
|
|
13
|
+
|
|
14
|
+
function seed(node: string, alias: string, snapshot: Record<string, unknown> | null) {
|
|
15
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, config_snapshot) VALUES (?1, ?2, ?2, ?3, ?4, ?5)`,
|
|
16
|
+
[node, alias, NET, userId, snapshot ? JSON.stringify(snapshot) : null]);
|
|
17
|
+
db.run(`INSERT INTO sessions (resume_id, alias, node_id, status, network_id, agent, updated_at, last_seen_at, registered_at)
|
|
18
|
+
VALUES (?1, ?2, ?3, 'idle', ?4, 'claude-code', datetime('now'), datetime('now'), datetime('now'))`, [`r_${node}`, alias, node, NET]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
23
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
24
|
+
process.env.HOST = "127.0.0.1";
|
|
25
|
+
const a = register(`nsc_owner_${Date.now()}`, "NodeSecretsCapablePassw0rd!");
|
|
26
|
+
userToken = a.token!; userId = a.user!.user_id; NET = a.network_id!;
|
|
27
|
+
seed("node_nsc_yes", "nsc-yes", { node_secrets_capable: true });
|
|
28
|
+
seed("node_nsc_no", "nsc-no", { model: "x" });
|
|
29
|
+
seed("node_nsc_bad", "nsc-bad", null);
|
|
30
|
+
const mod: any = await import("./server.js");
|
|
31
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
32
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
33
|
+
}, 30_000);
|
|
34
|
+
afterAll(() => { try { hub?.stop?.(true); } catch {} try { rmSync(DIR, { recursive: true, force: true }); } catch {} });
|
|
35
|
+
|
|
36
|
+
test("full /api/status carries node_secrets_capable only for nodes that reported it", async () => {
|
|
37
|
+
const res = await fetch(`${BASE}/api/status?network_id=${NET}&full=1`, { headers: { Authorization: `Bearer ${userToken}` } });
|
|
38
|
+
expect(res.status).toBe(200);
|
|
39
|
+
const body: any = await res.json();
|
|
40
|
+
const byAlias = new Map((body.sessions ?? body).map((s: any) => [s.alias, s]));
|
|
41
|
+
expect((byAlias.get("nsc-yes") as any)?.node_secrets_capable).toBe(true);
|
|
42
|
+
expect("node_secrets_capable" in (byAlias.get("nsc-no") as any)).toBe(false);
|
|
43
|
+
expect("node_secrets_capable" in (byAlias.get("nsc-bad") as any)).toBe(false);
|
|
44
|
+
});
|