@sleep2agi/commhub-server 0.9.0-preview.181 → 0.9.0-preview.183
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/agent-teams-http.test.ts +8 -1
- package/src/departments-agent-count.test.ts +129 -0
- package/src/departments.ts +41 -2
- package/src/scheduled-failures.ts +9 -2
- package/src/scheduled-offline-backoff-probe.test.ts +7 -1
- package/src/server.ts +3 -1
- package/src/tools.ts +4 -8
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.183",
|
|
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",
|
|
@@ -316,7 +316,14 @@ describe("#764 network deletion removes team rows", () => {
|
|
|
316
316
|
describe("#764 existing endpoints unchanged", () => {
|
|
317
317
|
test("departments / humans / node config byte-identical after all team operations", async () => {
|
|
318
318
|
const after = await snapshot();
|
|
319
|
-
|
|
319
|
+
// #2822 —— `/departments` 新增了 `agents_unassigned`(轴2:没有显式部门的 Agent 数)。
|
|
320
|
+
// 它是**活跃的节点普查**,而本文件在 #764 用例里故意 `DELETE /api/nodes/<n2>` 删了一个节点,
|
|
321
|
+
// 所以这一格必然从 3 变 2。部门/成员结构仍然要求逐字节相同;节点普查单独钉住差额,
|
|
322
|
+
// 不把「删节点」当成「团队操作改了部门」。
|
|
323
|
+
const dept = (t: string) => { const o = JSON.parse(t); const n = o.agents_unassigned; delete o.agents_unassigned; return { body: JSON.stringify(o), n }; };
|
|
324
|
+
const a = dept(after.departments), b = dept(before.departments);
|
|
325
|
+
expect(a.body).toBe(b.body);
|
|
326
|
+
expect(a.n).toBe((b.n as number) - 1);
|
|
320
327
|
expect(after.humans).toBe(before.humans);
|
|
321
328
|
expect(after.node).toBe(before.node);
|
|
322
329
|
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// #2822 —— 部门 → Agent 计数(轴2)必须是接口直接给出的,而且要和客户端同一口径。
|
|
2
|
+
//
|
|
3
|
+
// 背景:admin 看到 Dashboard 部门盘「未分组 105 / TMAI 1 / 其余 0」,客户端同一棵树却是
|
|
4
|
+
// 「TMWork 15 / TM智能体空间 2」。根因是**两个轴**被混成了一个:
|
|
5
|
+
// 轴1 人 network_members.department_id
|
|
6
|
+
// 轴2 Agent nodes.department_id ← 权威
|
|
7
|
+
// 本测试钉住:HTTP `GET …/departments` 与 MCP `departments list` 都直接用 nodes.department_id,
|
|
8
|
+
// 并且按 #2596 的口径去重(同 alias 只算一个,保留 updated_at 最新的那一行)。
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
11
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
import { tmpdir } from "os";
|
|
14
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
16
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
17
|
+
import { register } from "./auth.js";
|
|
18
|
+
import { db } from "./db.js";
|
|
19
|
+
import { registerTools } from "./tools.js";
|
|
20
|
+
|
|
21
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-dept-agent-count-"));
|
|
22
|
+
let BASE = "";
|
|
23
|
+
let hub: any = null;
|
|
24
|
+
const PW = "DeptAgentCountPassw0rd!";
|
|
25
|
+
let NET = "";
|
|
26
|
+
let TOKEN = "";
|
|
27
|
+
const UID: string[] = [];
|
|
28
|
+
|
|
29
|
+
async function send(token: string, method: string, path: string, body?: unknown) {
|
|
30
|
+
const res = await fetch(`${BASE}${path}`, { method, headers: { ...(token ? { Authorization: `Bearer ${token}` } : {}), "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
31
|
+
const text = await res.text();
|
|
32
|
+
let json: any = null;
|
|
33
|
+
try { json = JSON.parse(text); } catch {}
|
|
34
|
+
return { status: res.status, body: json };
|
|
35
|
+
}
|
|
36
|
+
const D = () => `/api/networks/${NET}/departments`;
|
|
37
|
+
|
|
38
|
+
function mkDept(name: string): string {
|
|
39
|
+
const id = `dept_${name.toLowerCase().replace(/[^a-z0-9]/g, "")}_${Math.random().toString(36).slice(2, 8)}`;
|
|
40
|
+
db.run("INSERT INTO network_departments (network_id, department_id, name) VALUES (?1, ?2, ?3)", [NET, id, name]);
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
let seq = 0;
|
|
44
|
+
function mkNode(alias: string | null, departmentId: string | null, updatedAt: string) {
|
|
45
|
+
const nodeId = `n_c_${Date.now()}_${seq++}`;
|
|
46
|
+
db.run(
|
|
47
|
+
"INSERT INTO nodes (node_id, node_name, alias, runtime, network_id, department_id, updated_at) VALUES (?1, ?2, ?3, 'codex', ?4, ?5, ?6)",
|
|
48
|
+
[nodeId, alias || nodeId, alias, NET, departmentId, updatedAt],
|
|
49
|
+
);
|
|
50
|
+
return nodeId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
beforeAll(async () => {
|
|
54
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
55
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
56
|
+
process.env.HOST = "127.0.0.1";
|
|
57
|
+
const a = register(`dca_owner_${Date.now()}`, PW, undefined, "Owner");
|
|
58
|
+
expect(a.ok).toBe(true);
|
|
59
|
+
TOKEN = a.token!;
|
|
60
|
+
UID.push(a.user!.user_id);
|
|
61
|
+
NET = a.network_id!;
|
|
62
|
+
db.run("UPDATE users SET role = 'admin' WHERE user_id = ?1", [a.user!.user_id]);
|
|
63
|
+
const mod: any = await import("./server.js");
|
|
64
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
65
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
66
|
+
}, 30_000);
|
|
67
|
+
|
|
68
|
+
afterAll(() => {
|
|
69
|
+
try { hub?.stop?.(true); } catch {}
|
|
70
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("#2822 部门 → Agent 计数走 nodes.department_id(轴2)", () => {
|
|
74
|
+
test("agent_count 只数显式归属的 Agent;agents_unassigned 单独给;人的部门不参与", async () => {
|
|
75
|
+
const work = mkDept("TMWork");
|
|
76
|
+
const space = mkDept("TM智能体空间");
|
|
77
|
+
const infra = mkDept("TM基建");
|
|
78
|
+
|
|
79
|
+
// 轴2:TMWork 3 个(其中两个同 alias,旧的应被去重掉)→ 期望 2
|
|
80
|
+
mkNode("alice", work, "2026-10-01 00:00:00");
|
|
81
|
+
mkNode("alice", work, "2026-10-20 00:00:00"); // 更新 ⇒ 保留这一行
|
|
82
|
+
mkNode("bob", work, "2026-10-20 00:00:00");
|
|
83
|
+
// TM智能体空间 1 个
|
|
84
|
+
mkNode("carol", space, "2026-10-20 00:00:00");
|
|
85
|
+
// TM基建:同 alias 但更新的一行被移到了别的部门 ⇒ 计数要跟着最新那一行走
|
|
86
|
+
mkNode("dave", infra, "2026-10-01 00:00:00");
|
|
87
|
+
mkNode("dave", space, "2026-10-25 00:00:00");
|
|
88
|
+
// 未归属 2 个
|
|
89
|
+
mkNode("eve", null, "2026-10-20 00:00:00");
|
|
90
|
+
mkNode("frank", "", "2026-10-20 00:00:00");
|
|
91
|
+
// 把负责人放进 TM基建(轴1)—— 轴1 有任何值都不能影响轴2 的计数
|
|
92
|
+
db.run("UPDATE network_members SET department_id = ?2 WHERE network_id = ?1 AND user_id = ?3", [NET, infra, UID[0]]);
|
|
93
|
+
|
|
94
|
+
const r = await send(TOKEN, "GET", D());
|
|
95
|
+
expect(r.status).toBe(200);
|
|
96
|
+
const byName = new Map<string, any>((r.body.departments as any[]).map((d) => [d.name, d]));
|
|
97
|
+
|
|
98
|
+
expect(byName.get("TMWork").agent_count).toBe(2); // alice 去重后 + bob
|
|
99
|
+
expect(byName.get("TM智能体空间").agent_count).toBe(2); // carol + dave(最新那一行在这里)
|
|
100
|
+
expect(byName.get("TM基建").agent_count).toBe(0); // dave 已被移走;人的部门不算
|
|
101
|
+
expect(r.body.agents_unassigned).toBe(2); // eve + frank(domain: department_id 空)
|
|
102
|
+
|
|
103
|
+
// 轴1 仍然是直属人数,不受影响
|
|
104
|
+
expect(byName.get("TM基建").member_count).toBe(1);
|
|
105
|
+
expect(byName.get("TMWork").member_count).toBe(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("MCP departments list 与 HTTP 同一口径(不再各自算一遍)", async () => {
|
|
109
|
+
// 真的走 in-process MCP transport(不是直调函数):要验的正是「工具返回的就是同一份口径」。
|
|
110
|
+
const server = new McpServer({ name: "dept-agent-count", version: "1" });
|
|
111
|
+
registerTools(server, undefined, NET, UID[0], "owner-agent", true, null);
|
|
112
|
+
const client = new Client({ name: "dept-agent-count-client", version: "1" });
|
|
113
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
114
|
+
await server.connect(st);
|
|
115
|
+
await client.connect(ct);
|
|
116
|
+
try {
|
|
117
|
+
const raw: any = await client.callTool({ name: "departments", arguments: { action: "list" } });
|
|
118
|
+
const mcp = JSON.parse(String(raw.content?.[0]?.text ?? "{}"));
|
|
119
|
+
const http = (await send(TOKEN, "GET", D())).body;
|
|
120
|
+
const httpByName = new Map<string, any>((http.departments as any[]).map((d) => [d.name, d]));
|
|
121
|
+
expect(mcp.departments.length).toBeGreaterThan(0);
|
|
122
|
+
for (const d of mcp.departments as any[]) expect(d.agent_count).toBe(httpByName.get(d.name).agent_count);
|
|
123
|
+
expect(mcp.unassigned_agents).toBe(http.agents_unassigned);
|
|
124
|
+
} finally {
|
|
125
|
+
await client.close();
|
|
126
|
+
await server.close();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
package/src/departments.ts
CHANGED
|
@@ -40,7 +40,17 @@ const NAME_MAX = 40;
|
|
|
40
40
|
const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
41
41
|
|
|
42
42
|
type DeptRow = { network_id: string; department_id: string; name: string; parent_id: string | null; leader_user_id: string | null; sort: number; created_at: string; updated_at: string };
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* 部门(轴1 = 人)。
|
|
45
|
+
*
|
|
46
|
+
* `member_count` 是**直属人数**(不含子树)。
|
|
47
|
+
* `agent_count` 是**轴2**:Agent 显式归属 `nodes.department_id` 指向本部门的数量,
|
|
48
|
+
* 与「成员的 Agent」无关(RFC-040 / #1976:Agent 部门只由显式设置决定,不再按负责人推断)。
|
|
49
|
+
* 没有这一格时,任何客户端想画「部门 → Agent 数」都得自己拉全量
|
|
50
|
+
* `people/directory` 再去重,各端口径必然分叉(#2822:Dashboard 105/TMAI 1
|
|
51
|
+
* vs 客户端 TMWork 15/TM智能体空间 2)。
|
|
52
|
+
*/
|
|
53
|
+
export type Department = { id: string; name: string; parent_id: string | null; leader_user_id: string | null; sort: number; member_count: number; agent_count: number; created_at: string; updated_at: string };
|
|
44
54
|
|
|
45
55
|
type Fail = { ok: false; status: number; error: string };
|
|
46
56
|
type Ok<T> = { ok: true } & T;
|
|
@@ -64,7 +74,12 @@ function isMember(networkId: string, userId: string): boolean {
|
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
/** 读:部门(带直属人数)+ 每个成员在哪个部门。负责人不在本网络了 → null。 */
|
|
67
|
-
export function listDepartments(networkId: string): {
|
|
77
|
+
export function listDepartments(networkId: string): {
|
|
78
|
+
departments: Department[];
|
|
79
|
+
members: Array<{ user_id: string; department_id: string | null }>;
|
|
80
|
+
/// 轴2 里没有显式归属的 Agent 数(Dashboard 的「未分组」不该拿人的未分配去填)。
|
|
81
|
+
agents_unassigned: number;
|
|
82
|
+
} {
|
|
68
83
|
const members = db.all<{ user_id: string; department_id: string | null }>(
|
|
69
84
|
"SELECT user_id, department_id FROM network_members WHERE network_id = ?1 ORDER BY joined_at, user_id",
|
|
70
85
|
networkId,
|
|
@@ -76,6 +91,28 @@ export function listDepartments(networkId: string): { departments: Department[];
|
|
|
76
91
|
const placed = members.map((m) => ({ user_id: m.user_id, department_id: m.department_id && ids.has(m.department_id) ? m.department_id : null }));
|
|
77
92
|
const counts = new Map<string, number>();
|
|
78
93
|
for (const m of placed) if (m.department_id) counts.set(m.department_id, (counts.get(m.department_id) ?? 0) + 1);
|
|
94
|
+
// ── 轴2:Agent 的显式部门(nodes.department_id)────────────────────────────
|
|
95
|
+
// 去重口径与 #2596 一致:同一个 alias 只算一个 Agent,保留 updated_at 最新的那一行,
|
|
96
|
+
// 它落在哪个部门就计入哪个部门(没有 alias 的用 node_id 当键)。
|
|
97
|
+
// 不在这里做「近 7 天」过滤:那是展示策略,接口只给事实。
|
|
98
|
+
const agentRows = db.all<{ department_id: string; alias: string | null; node_id: string; updated_at: string | null }>(
|
|
99
|
+
"SELECT department_id, alias, node_id, updated_at FROM nodes WHERE network_id = ?1 AND department_id IS NOT NULL AND department_id != ''",
|
|
100
|
+
networkId,
|
|
101
|
+
);
|
|
102
|
+
const newestByKey = new Map<string, { department_id: string; updated_at: string | null }>();
|
|
103
|
+
for (const n of agentRows) {
|
|
104
|
+
const key = n.alias || n.node_id;
|
|
105
|
+
const prev = newestByKey.get(key);
|
|
106
|
+
if (!prev || (n.updated_at ?? "") > (prev.updated_at ?? "")) {
|
|
107
|
+
newestByKey.set(key, { department_id: n.department_id, updated_at: n.updated_at });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const agentCounts = new Map<string, number>();
|
|
111
|
+
for (const v of newestByKey.values()) agentCounts.set(v.department_id, (agentCounts.get(v.department_id) ?? 0) + 1);
|
|
112
|
+
const unassigned = db.get<{ n: number }>(
|
|
113
|
+
"SELECT COUNT(*) AS n FROM nodes WHERE network_id = ?1 AND (department_id IS NULL OR department_id = '')",
|
|
114
|
+
networkId,
|
|
115
|
+
)?.n ?? 0;
|
|
79
116
|
return {
|
|
80
117
|
departments: all.map((d) => ({
|
|
81
118
|
id: d.department_id,
|
|
@@ -84,10 +121,12 @@ export function listDepartments(networkId: string): { departments: Department[];
|
|
|
84
121
|
leader_user_id: d.leader_user_id && memberIds.has(d.leader_user_id) ? d.leader_user_id : null,
|
|
85
122
|
sort: d.sort,
|
|
86
123
|
member_count: counts.get(d.department_id) ?? 0,
|
|
124
|
+
agent_count: agentCounts.get(d.department_id) ?? 0,
|
|
87
125
|
created_at: d.created_at,
|
|
88
126
|
updated_at: d.updated_at,
|
|
89
127
|
})),
|
|
90
128
|
members: placed,
|
|
129
|
+
agents_unassigned: unassigned,
|
|
91
130
|
};
|
|
92
131
|
}
|
|
93
132
|
|
|
@@ -324,11 +324,18 @@ export function applyNoProgressBackoff(scheduleId: string, now = new Date()): {
|
|
|
324
324
|
const effective = Math.min(cap, base * 2 ** Math.min(streak - from + 1, 5));
|
|
325
325
|
const previous = row.backoff_effective_seconds ?? base;
|
|
326
326
|
let next = row.next_run_at;
|
|
327
|
-
|
|
327
|
+
// 🔴 生产实测(2026-10-28,`.181` 的两行日志):
|
|
328
|
+
// offline-backoff effective=5760s next_before=+180s ← 退避值没推进去
|
|
329
|
+
// offline-backoff-final next_after=+360s ← 二次 advance 又加了一个 base
|
|
330
|
+
// 根因就在这里:原来用 `effective !== previous` 做守卫,退避一旦进入**稳态**(例如已是 5760),
|
|
331
|
+
// 这个条件恒为 false ⇒ 不再推 next_run_at;而调用方在此之前刚 `advance()` 把 next 重置成 +base。
|
|
332
|
+
// 于是「退避值写着 5760,实际每 360s 跳一次」,且永远不会自愈。
|
|
333
|
+
// 正确语义:只要这一步是「同因跳过」,next_run_at 至少要 ≥ now + effective(只能往后推,不往前拉)。
|
|
334
|
+
if (next) {
|
|
328
335
|
const candidate = now.getTime() + effective * 1000;
|
|
329
336
|
const existing = parseHubTimestamp(next);
|
|
330
337
|
if (existing !== null) {
|
|
331
|
-
next = new Date(
|
|
338
|
+
next = new Date(Math.max(existing, candidate)).toISOString();
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
db.run(
|
|
@@ -31,10 +31,12 @@ beforeAll(() => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('target_offline backoff 是否真的推后 next_run_at', () => {
|
|
34
|
+
// 稳态回归(2026-10-28 生产实测):退避值已经等于 effective 时,原来 `effective !== previous`
|
|
35
|
+
// 的守卫恒假 ⇒ 不再推 next_run_at ⇒ 实际每 360s 跳一次。这里连打 6 次(eff 已进稳态)验证仍推。
|
|
34
36
|
test('连续 4 次离线跳过后,next_run_at 应 ≈ now + effective(而不是 base 的倍数)', () => {
|
|
35
37
|
const s = seed();
|
|
36
38
|
const rows: any[] = [];
|
|
37
|
-
for (let i = 0; i <
|
|
39
|
+
for (let i = 0; i < 9; i++) { // 9 次 ⇒ streak 到 10 ⇒ eff 进入稳态 5760,覆盖「第二次起不推」的坑
|
|
38
40
|
const at = new Date(Date.now() + i * 10).toISOString();
|
|
39
41
|
const r = dispatchScheduledOccurrence(getScheduleRow(s.schedule_id)!, at, true, new Date());
|
|
40
42
|
const after = db.get<any>("SELECT backoff_effective_seconds, backoff_streak, next_run_at FROM scheduled_tasks WHERE schedule_id = ?1", s.schedule_id);
|
|
@@ -46,5 +48,9 @@ describe('target_offline backoff 是否真的推后 next_run_at', () => {
|
|
|
46
48
|
// 断言:最后一次的 next_run_at 与 effective 同量级(允许 ±2 个 base 的容差)
|
|
47
49
|
if (!last.eff) throw new Error('backoff_effective_seconds 始终为空:退避没有生效');
|
|
48
50
|
if (last.gap_s < last.eff) throw new Error(`next_run_at 只推后 ${last.gap_s}s,但 effective=${last.eff}s`);
|
|
51
|
+
// 稳态:所有 fire 的 gap 都必须 ≥ 当次的 effective(没有「第二次起就不推」)
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
if (row.eff && row.gap_s < row.eff) throw new Error(`第 ${row.i} 次:gap=${row.gap_s}s < effective=${row.eff}s(稳态没推)`);
|
|
54
|
+
}
|
|
49
55
|
});
|
|
50
56
|
});
|
package/src/server.ts
CHANGED
|
@@ -2237,7 +2237,9 @@ return Bun.serve({
|
|
|
2237
2237
|
// viewer_can:manage = 能改名 / 移动 / 删除 / 换负责人;create_child = 能在它下面建子部门。
|
|
2238
2238
|
// project_grants(部门项目授权)只给 owner / admin:项目 id 不对只看相关任务的成员公开。
|
|
2239
2239
|
const departments = listed.departments.map((d) => ({ ...d, viewer_can: { manage: canManage || head.strict.has(d.id), create_child: canManage || head.managed.has(d.id) } }));
|
|
2240
|
-
|
|
2240
|
+
// agents_unassigned = 轴2 里没有显式归属的 Agent 数。Dashboard 的「未分组」必须用它,
|
|
2241
|
+
// 不能用「人的未分配」去填(#2822:那是另一个轴,混了就会出现「105 个 Agent 在未分组」)。
|
|
2242
|
+
return withCors(req, Response.json({ ok: true, network_id: netId, departments, members: listed.members, agents_unassigned: listed.agents_unassigned, ...(canManage ? { project_grants: listDepartmentProjectGrants(netId) } : {}) }));
|
|
2241
2243
|
}
|
|
2242
2244
|
if (deptSubMatch) {
|
|
2243
2245
|
const deptId = decodeURIComponent(deptSubMatch[2]);
|
package/src/tools.ts
CHANGED
|
@@ -464,15 +464,11 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
464
464
|
const agents = db.all<{ node_id: string; alias: string; department_id: string | null }>(
|
|
465
465
|
"SELECT node_id, alias, department_id FROM nodes WHERE network_id = ?1 ORDER BY alias", netId,
|
|
466
466
|
);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
for (const a of agents) {
|
|
470
|
-
if (a.department_id) counts.set(a.department_id, (counts.get(a.department_id) ?? 0) + 1);
|
|
471
|
-
else unassigned += 1;
|
|
472
|
-
}
|
|
467
|
+
// agent_count / agents_unassigned 一律取 listDepartments 的口径(含 #2596 的 alias 去重),
|
|
468
|
+
// 不在这里再算一遍 —— 否则 MCP 和 HTTP 会给出两个数(#2822 的教训)。
|
|
473
469
|
return deptReply({
|
|
474
|
-
ok: true, network_id: netId, unassigned_agents:
|
|
475
|
-
departments: listed.departments
|
|
470
|
+
ok: true, network_id: netId, unassigned_agents: listed.agents_unassigned, agents,
|
|
471
|
+
departments: listed.departments,
|
|
476
472
|
});
|
|
477
473
|
}
|
|
478
474
|
if (!canManageDepartments(netId)) return writeDeniedReply(netId, "write") as any;
|