@sleep2agi/commhub-server 0.9.0-preview.235 → 0.9.0-preview.236

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.9.0-preview.235",
3
+ "version": "0.9.0-preview.236",
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",
@@ -136,6 +136,27 @@ describe("GET /api/skills", () => {
136
136
  const owner = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
137
137
  expect(owner.body.state).toBe("configured");
138
138
  expect("hint" in owner.body).toBe(false);
139
+
140
+ // 2026-10-31 —— **闭集不许有死成员**:客户端 union 里写着 all_disabled,
141
+ // 而这个端点原来只产出前两个 ⇒ 那一格永远不会出现、界面分支永远跑不到。
142
+ // 本地 hub 实测:建了 enabled:true 的行 ⇒ configured;把 enabled 改成 false ⇒ **仍是 configured**
143
+ // ⇒ 读的人会把「全都关了」看成「配置好了」。现在三态都必须可产出。
144
+ db.run(`UPDATE hub_provider_configs SET config_json = json_set(config_json, '$.enabled', json('false'))
145
+ WHERE network_id = ?1`, [ownerNet]);
146
+ const disabled = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
147
+ expect(disabled.body.state).toBe("all_disabled");
148
+ expect(disabled.body.counts.providers_enabled).toBe(0);
149
+ expect(disabled.body.counts.providers_disabled).toBeGreaterThan(0);
150
+ expect(disabled.body.counts.models_enabled).toBe(0);
151
+ expect(disabled.body.hint).toContain("全部被禁用");
152
+ expect(disabled.body.hint).toContain("不是「还没配置」");
153
+
154
+ // 还原:否则后面的用例会看到一个全禁用的网络
155
+ db.run(`UPDATE hub_provider_configs SET config_json = json_set(config_json, '$.enabled', json('true'))
156
+ WHERE network_id = ?1`, [ownerNet]);
157
+ const back = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
158
+ expect(back.body.state).toBe("configured");
159
+ expect(back.body.counts.models_enabled).toBeGreaterThan(0);
139
160
  });
140
161
 
141
162
  test("a member of another network is refused", async () => {
@@ -95,12 +95,33 @@ export function readHubProviders(h: Human, exposeRefs = false) {
95
95
  const otherSource = db.get<{ cnt: number }>(
96
96
  'SELECT COUNT(*) AS cnt FROM providers WHERE network_id=?1 AND enabled=1', h.networkId!);
97
97
  const otherCount = otherSource?.cnt ?? 0;
98
- const state = rows.length > 0 ? 'configured' as const : 'unconfigured' as const;
98
+ // 2026-10-31 —— **闭集不许有死成员**:客户端 union 里写着
99
+ // "configured" | "unconfigured" | "all_disabled",而这个端点原来只产出前两个
100
+ // ⇒ all_disabled 是一格永远不会出现的状态,界面里那条分支也就永远跑不到
101
+ // (实测:本地 hub 建了一行 enabled:true 的 provider 之后,state 仍是 configured/空表是 unconfigured,
102
+ // 把 enabled 改成 false 依旧是 configured ⇒ 读的人会把「全都关了」看成「配置好了」)。
103
+ // 现在三态都可产出,并把「哪些算可用」用计数说清(客户端不必自己再数一遍)。
104
+ const parsed = rows.map(r => JSON.parse(r.config_json) as { enabled?: boolean; models?: string[] });
105
+ const enabledRows = parsed.filter(c => c.enabled === true);
106
+ const state = rows.length === 0 ? 'unconfigured' as const
107
+ : enabledRows.length === 0 ? 'all_disabled' as const
108
+ : 'configured' as const;
99
109
  return { ok: true as const, network_id: h.networkId!, source: 'hub' as const,
100
110
  // 读的是哪张表 —— 名字直接写出来,避免下一个人拿这个结果去解释另一个接口
101
111
  source_table: 'hub_provider_configs' as const,
102
112
  state,
103
- counts: { providers: rows.length, providers_in_cli_registry: otherCount },
113
+ counts: {
114
+ providers: rows.length,
115
+ providers_enabled: enabledRows.length,
116
+ providers_disabled: rows.length - enabledRows.length,
117
+ models_enabled: enabledRows.reduce((n, c) => n + (Array.isArray(c.models) ? c.models.length : 0), 0),
118
+ providers_without_models: enabledRows.filter(c => !Array.isArray(c.models) || c.models.length === 0).length,
119
+ providers_in_cli_registry: otherCount,
120
+ },
121
+ ...(state === 'all_disabled' ? {
122
+ hint: '这个网络里配置了 ' + rows.length + ' 个 provider,但**全部被禁用** ⇒ 客户端仍然没有可选模型。'
123
+ + '这不是「还没配置」,要做的是启用其中一个(或在确认无用后删除)。',
124
+ } : {}),
104
125
  ...(state === 'unconfigured' ? {
105
126
  hint: otherCount > 0
106
127
  ? '本端点读 hub_provider_configs(网络自有 provider 配置),此处为空;但要给客户端选模型,还需要这里至少一行 —— CLI 注册表里的 ' + otherCount + ' 条不会自动出现在本端点。'