agent-bridge-aun 1.0.16 → 1.0.18

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
@@ -7,5 +7,3 @@
7
7
  该插件依赖 `@agentunion/fastaun`,要求 Node.js 22.16 或更高版本。
8
8
 
9
9
  ABWeb 的 AUN 设置只展示已连接 AID,并按来源分组。插件通过 SDK 密钥库枚举 AID,再逐个建立连接;只有连接成功的身份才会显示。EvolCore 来源身份只用于连接状态检测,不订阅消息,避免重复收信;本工程创建的身份负责消息收发。连接状态检测不调用 `ec agent list/show`。将 EvolCore 身份关联到 Agent 时仍使用既有 `ec agent set/reload` 路由配置,该配置不参与连接状态检测。列表先显示已关联 Agent 的身份,各组按最近成功关联的时间倒序排列,时间相同或旧记录没有时间时按 AID 名称排序。关联时间保存在插件配置的 `binding_times` 中,刷新或重启后保留;旧记录不补造时间,再次关联成功后开始记录。
10
-
11
- AUN 独立包支持核心后台每五分钟检测更新;可信提供者在自动安装策略下会下载新副本并重载通道。
@@ -10,7 +10,7 @@ const node_url_1 = require("node:url");
10
10
  const messages_1 = require("./messages");
11
11
  const evolcore_1 = require("./evolcore");
12
12
  const manifest = {
13
- id: "aun", version: "1.0.16", type: "channel", displayName: "AUN 通道",
13
+ id: "aun", version: "1.0.18", type: "channel", displayName: "AUN 通道",
14
14
  entry: "dist/src-ts/plugins/aun/index.js", apiVersion: "1", process: "in-process",
15
15
  capabilities: ["channel", "channel.identity.create", "channel.receive", "channel.send", "health"],
16
16
  configSchema: "config.schema.json",
@@ -72,11 +72,11 @@ class AunPlugin {
72
72
  this.creating = true;
73
73
  try {
74
74
  if (!this.identities.has(aid)) {
75
- // 创建身份沿用 EvolCore 的 legacy 注册流程。Owner AID 是本地归属配置,
76
- // 只有明确执行 Owner 关系绑定时才进入 aid_register_* 双签流程。
75
+ // Owner AID 是本地归属配置;身份签发沿用 EvolCore 的兼容注册流程。
77
76
  const result = await this.store.register(aid);
78
77
  if (!result.ok)
79
78
  throw new Error(redact(result.error?.message ?? result.error?.code ?? "AID 注册失败"));
79
+ await this.prepareTrustRoots(aid);
80
80
  const loaded = this.store.load(aid);
81
81
  if (!loaded.ok || !loaded.data)
82
82
  throw new Error(loaded.error?.message ?? "注册后未能加载本地身份");
@@ -222,6 +222,7 @@ class AunPlugin {
222
222
  }
223
223
  async connectAid(aid) {
224
224
  try {
225
+ await this.prepareTrustRoots(aid);
225
226
  const loaded = this.store.load(aid);
226
227
  if (!loaded.ok || !loaded.data)
227
228
  throw new Error(loaded.error?.message ?? "本地密钥库中不存在该 AID");
@@ -272,9 +273,47 @@ class AunPlugin {
272
273
  return (0, node_path_1.resolve)(process.env.AUN_HOME ?? process.env.EVOLCORE_HOME ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".evolcore"));
273
274
  }
274
275
  newStore() {
275
- const rootCaPath = typeof this.config.root_ca_path === "string" && this.config.root_ca_path ? this.config.root_ca_path : (0, node_path_1.join)(this.path(), "CA", "root", "root.crt");
276
+ const rootCaPath = this.rootCaPath();
276
277
  return new this.sdk.AIDStore({ aunPath: this.path(), encryptionSeed: typeof this.config.encryption_seed === "string" && this.config.encryption_seed ? this.config.encryption_seed : "evol", verifySsl: typeof this.config.verify_ssl === "boolean" ? this.config.verify_ssl : true, rootCaPath: (0, node_fs_1.existsSync)(rootCaPath) ? rootCaPath : undefined });
277
278
  }
279
+ rootCaPath() {
280
+ return typeof this.config.root_ca_path === "string" && this.config.root_ca_path
281
+ ? this.config.root_ca_path
282
+ : (0, node_path_1.join)(this.path(), "CA", "root", "root.crt");
283
+ }
284
+ async prepareTrustRoots(aid) {
285
+ const rootCaPath = this.rootCaPath();
286
+ if ((0, node_fs_1.existsSync)(rootCaPath))
287
+ return;
288
+ try {
289
+ if (!this.sdk?.GatewayDiscovery)
290
+ throw new Error("AUN SDK 未提供 GatewayDiscovery");
291
+ const discovery = new this.sdk.GatewayDiscovery({ verifySsl: typeof this.config.verify_ssl === "boolean" ? this.config.verify_ssl : true });
292
+ const gatewayUrl = await discovery.discover(`https://${aid}/.well-known/aun-gateway`);
293
+ const gatewayHttpUrl = gatewayUrl.replace(/^wss?:/i, "https:").replace(/\/aun\/?$/i, "");
294
+ const response = await fetch(`${gatewayHttpUrl}/pki/chain`, { redirect: "follow" });
295
+ if (!response.ok)
296
+ throw new Error(`下载 Gateway CA 链失败:HTTP ${response.status}`);
297
+ const chain = await response.text();
298
+ if (!chain.includes("-----BEGIN CERTIFICATE-----"))
299
+ throw new Error("Gateway CA 链响应中没有证书");
300
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(rootCaPath), { recursive: true });
301
+ await (0, promises_1.writeFile)(rootCaPath, chain, { mode: 0o600 });
302
+ const oldStore = this.store;
303
+ const newStore = this.newStore();
304
+ this.store = newStore;
305
+ try {
306
+ await oldStore?.close();
307
+ }
308
+ catch (error) {
309
+ this.context?.logger.warn("关闭旧 AUN Store 失败", { error: safeError(error) });
310
+ }
311
+ this.context?.logger.info("AUN Gateway 信任根证书已下载", { aid });
312
+ }
313
+ catch (error) {
314
+ this.context?.logger.warn("AUN Gateway 信任根证书初始化失败", { aid, error: safeError(error) });
315
+ }
316
+ }
278
317
  createAid = async (request, response) => {
279
318
  let input;
280
319
  try {
@@ -31,8 +31,15 @@
31
31
  configForm.elements.encryption_seed.value = "";
32
32
  }
33
33
  list.replaceChildren();
34
- const entries = [["本工程 · 已连接", identities.groups.muAgentBridge || []], ["EvolCore · 已连接", identities.groups.evolcore || []]]
35
- .flatMap(([label, values], group) => values.map((aid) => ({ aid, label, group, bound: identities.bindings?.[aid] || agents.find((agent) => agent.id && agent.configAid === aid)?.id || "", time: Date.parse(identities.bindingTimes?.[aid] || "") || 0 })));
34
+ const entries = [];
35
+ const seen = new Set();
36
+ for (const [group, label, values] of [[0, "本工程 · 已连接", identities.groups.muAgentBridge || []], [1, "EvolCore · 已连接", identities.groups.evolcore || []]]) {
37
+ for (const aid of values) {
38
+ if (seen.has(aid)) continue;
39
+ seen.add(aid);
40
+ entries.push({ aid, label, group, bound: identities.bindings?.[aid] || agents.find((agent) => agent.id && agent.configAid === aid)?.id || "", time: Date.parse(identities.bindingTimes?.[aid] || "") || 0 });
41
+ }
42
+ }
36
43
  entries.sort((a, b) => Number(Boolean(b.bound)) - Number(Boolean(a.bound)) || a.group - b.group || b.time - a.time || a.aid.localeCompare(b.aid));
37
44
  for (const { aid, label, bound } of entries) {
38
45
  const row = document.createElement("tr");
@@ -43,7 +50,7 @@
43
50
  cell.append(select); row.append(cell); list.append(row);
44
51
  }
45
52
  if (!list.children.length) { const row = document.createElement("tr"); const cell = document.createElement("td"); cell.colSpan = 4; cell.textContent = "暂无已连接 AID"; row.append(cell); list.append(row); }
46
- show(`${(identities.groups.evolcore || []).length + (identities.groups.muAgentBridge || []).length} 个已连接 AID`);
53
+ show(`${entries.length} 个已连接 AID`);
47
54
  } catch (error) { show(String(error), true); }
48
55
  finally { loading = false; }
49
56
  }
@@ -6,7 +6,7 @@
6
6
  <header><h1>AUN 身份</h1><button id="refresh" type="button">刷新</button></header>
7
7
  <p id="status" role="status"></p>
8
8
  <div class="table-scroll"><table><thead><tr><th>AID</th><th>来源</th><th>已关联 Agent</th><th>操作</th></tr></thead><tbody id="identities"></tbody></table></div>
9
- <form id="create-form"><h2>创建 AID</h2><div class="fields"><label>新 AID<input name="aid" required placeholder="例如:example.agentid.cn"></label><label>Owner AID<input name="ownerAid" required placeholder="例如:owner.agentid.cn(本地归属配置)"><small class="hint">Owner AID 用于本地归属和 Agent 关联;创建身份本身沿用 AUN 的普通注册流程</small></label></div><button type="submit">创建</button></form>
9
+ <form id="create-form"><h2>创建 AID</h2><div class="fields"><label>新 AID<input name="aid" required placeholder="new.agentid.cn"></label><label>Owner AID<input name="ownerAid" required></label></div><button type="submit">创建</button></form>
10
10
  <form id="config-form"><h2>通道配置</h2><div class="fields"><label>默认 Agent<select name="agent_plugin"></select></label><label>允许的来源<input name="allow_from"></label><label>AUN 存储路径<input name="aun_path"></label><label>加密种子<input name="encryption_seed" type="password" autocomplete="new-password" placeholder="留空则不修改"></label></div><button type="submit">保存配置</button></form>
11
11
  </main>
12
12
  <script src="/abweb/channels/aun/app.js"></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-aun",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "mu-agent-bridge 的 AUN 通道插件。",
5
5
  "keywords": [
6
6
  "mu-agent-bridge-plugin",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "aun",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "channel",
5
5
  "displayName": "AUN 通道",
6
6
  "entry": "dist/src-ts/plugins/aun/index.js",