agent-bridge-aun 1.0.21 → 1.0.22
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
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
`agent-bridge-aun` 为 mu-agent-bridge 提供 AUN 消息通道,支持使用已有 AID 或通过管理 API 注册 AID,并将收到的文本交给指定 Agent 插件处理。
|
|
4
4
|
|
|
5
|
-
安装后在 ABWeb 的插件管理中启动 AUN 通道。配置 `aid` 和可选的 `agent_plugin`;默认 Agent 插件为 `qwenwork
|
|
5
|
+
安装后在 ABWeb 的插件管理中启动 AUN 通道。配置 `aid` 和可选的 `agent_plugin`;默认 Agent 插件为 `qwenwork`。配置字段 `owner_aid` 是可选字符串,用作默认 Owner。AID 创建接口为 `POST /api/plugins/aun/aid`,请求内容为 `{"aid":"新AID.agentid.cn","owner_aid":"所有者AID.agentid.cn"}`。
|
|
6
6
|
|
|
7
7
|
创建使用 SDK 的兼容注册流程;Owner AID 只保存为本地归属配置,不代表 AUN 协议 Owner 关系已签名或激活。Gateway 信任根使用随插件提供并校验指纹的 AUN 根证书,不从 Gateway 下载未经验证的 CA 链。
|
|
8
8
|
|
|
9
|
-
核心支持插件命令后,可运行 `mab aun status`、`mab aun list`、`mab aun agents`、`mab aun create <aid> --owner <owner-aid> [--agent <plugin-id>]`、`mab aun bind <aid> <plugin-id>` 和 `mab aun unbind <plugin-id
|
|
9
|
+
核心支持插件命令后,可运行 `mab aun status`、`mab aun list`、`mab aun agents`、`mab aun default-owner`、`mab aun default-owner set <owner-aid>`、`mab aun create <aid> [--owner <owner-aid>] [--agent <plugin-id>]`、`mab aun bind <aid> <plugin-id>` 和 `mab aun unbind <plugin-id>`。`default-owner` 不带参数显示当前配置,`default-owner set <owner-aid>` 校验格式并持久化新的默认值。`create` 明确传入 `--owner` 时优先使用该值;省略时回退到同一配置中的 `owner_aid`,两者都没有时返回错误,不会创建 AID。创建新身份时,实际使用的 Owner 会保存为下次默认值。ABWeb 从同一插件配置读取 `owner_aid` 并预填创建表单,因此 CLI 和 ABWeb 共用默认 Owner。Agent 从当前已就绪的插件动态发现。创建后连接或关联失败时,响应会标明 AID 已创建;先用 `mab aun list` 检查,不要重试创建。运行日志不记录原始参数或 Owner AID;默认 Owner 查询会在终端显示当前值。
|
|
10
10
|
|
|
11
11
|
该插件依赖 `@agentunion/fastaun`,要求 Node.js 22.16 或更高版本。
|
|
12
12
|
|
|
13
|
-
ABWeb 的 AUN 设置只展示已连接 AID
|
|
13
|
+
ABWeb 的 AUN 设置只展示已连接 AID,并按来源分组。成功注册并记录在插件 `created_aids` 中的 AID 属于本工程;共享密钥库中其余 AID 属于 EvolCore。旧版 `created-aids.json` 记录继续兼容。来源只用于展示,连接和关联由 AUN 插件直接管理。列表先显示已关联 Agent 的身份,各组按最近成功关联的时间倒序排列,时间相同或旧记录没有时间时按 AID 名称排序。关联时间保存在插件配置的 `binding_times` 中,刷新或重启后保留;旧记录不补造时间,再次关联成功后开始记录。
|
|
14
14
|
|
|
15
15
|
AUN 独立包支持核心后台每五分钟检测更新;可信提供者在自动安装策略下会下载新副本并重载通道。
|
package/config.schema.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"type": "object",
|
|
3
3
|
"properties": {
|
|
4
4
|
"identities": { "type": "array", "items": { "type": "string" } },
|
|
5
|
+
"created_aids": { "type": "array", "items": { "type": "string" } },
|
|
5
6
|
"bindings": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
6
7
|
"binding_times": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
7
8
|
"aid": { "type": "string", "minLength": 1 },
|
|
@@ -10,12 +10,13 @@ const node_os_1 = require("node:os");
|
|
|
10
10
|
const node_url_1 = require("node:url");
|
|
11
11
|
const messages_1 = require("./messages");
|
|
12
12
|
const manifest = {
|
|
13
|
-
id: "aun", version: "1.0.
|
|
13
|
+
id: "aun", version: "1.0.22", 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", "cli"],
|
|
16
16
|
configSchema: "config.schema.json",
|
|
17
17
|
managementPage: "/abweb/channels/aun",
|
|
18
18
|
};
|
|
19
|
+
const newSessionCommand = /^\/new(?:[ \t]+[^\r\n]+)?$/;
|
|
19
20
|
async function loadSdk() {
|
|
20
21
|
const resolver = (0, node_module_1.createRequire)(__filename);
|
|
21
22
|
const dynamicImport = new Function("url", "return import(url)");
|
|
@@ -36,7 +37,8 @@ const cliCommands = [
|
|
|
36
37
|
{ name: "status", summary: "查看 AUN 通道状态", usage: "mab aun status" },
|
|
37
38
|
{ name: "list", summary: "查看已连接 AID 和 Agent 关联", usage: "mab aun list" },
|
|
38
39
|
{ name: "agents", summary: "列出当前已就绪的 Agent 插件", usage: "mab aun agents" },
|
|
39
|
-
{ name: "
|
|
40
|
+
{ name: "default-owner", summary: "查询或设置默认 Owner AID", usage: "mab aun default-owner [set <owner-aid>]", examples: ["mab aun default-owner", "mab aun default-owner set owner.agentid.cn"] },
|
|
41
|
+
{ name: "create", summary: "创建并连接 AID,可选关联 Agent", usage: "mab aun create <aid> [--owner <owner-aid>] [--agent <plugin-id>]", examples: ["mab aun create new.agentid.cn --owner owner.agentid.cn --agent qwenwork"] },
|
|
40
42
|
{ name: "bind", summary: "将 AID 关联到 Agent", usage: "mab aun bind <aid> <plugin-id>", examples: ["mab aun bind new.agentid.cn qwenwork"] },
|
|
41
43
|
{ name: "unbind", summary: "解除 Agent 与 AID 的关联", usage: "mab aun unbind <plugin-id>", examples: ["mab aun unbind qwenwork"] },
|
|
42
44
|
];
|
|
@@ -58,6 +60,7 @@ class AunPlugin {
|
|
|
58
60
|
clients = new Map();
|
|
59
61
|
identities = new Set();
|
|
60
62
|
legacyCreatedAids = new Set();
|
|
63
|
+
createdAids = new Set();
|
|
61
64
|
bindings = {};
|
|
62
65
|
bindingTimes = {};
|
|
63
66
|
creating = false;
|
|
@@ -75,10 +78,11 @@ class AunPlugin {
|
|
|
75
78
|
}
|
|
76
79
|
identity = {
|
|
77
80
|
list: async () => {
|
|
81
|
+
const own = new Set([...this.createdAids, ...this.legacyCreatedAids]);
|
|
78
82
|
return {
|
|
79
|
-
evolcore: [],
|
|
80
|
-
muAgentBridge: [...this.clients.keys()].sort(),
|
|
81
|
-
localMuAgentBridge: [...
|
|
83
|
+
evolcore: [...this.clients.keys()].filter((aid) => !own.has(aid)).sort(),
|
|
84
|
+
muAgentBridge: [...this.clients.keys()].filter((aid) => own.has(aid)).sort(),
|
|
85
|
+
localMuAgentBridge: [...own].filter((aid) => !this.clients.has(aid)).sort(),
|
|
82
86
|
};
|
|
83
87
|
},
|
|
84
88
|
create: async (aid, owner) => {
|
|
@@ -95,6 +99,8 @@ class AunPlugin {
|
|
|
95
99
|
const result = await this.store.register(aid);
|
|
96
100
|
if (!result.ok)
|
|
97
101
|
throw new Error(redact(result.error?.message ?? result.error?.code ?? "AID 注册失败"));
|
|
102
|
+
this.createdAids.add(aid);
|
|
103
|
+
await this.persist();
|
|
98
104
|
}
|
|
99
105
|
const loaded = this.store.load(aid);
|
|
100
106
|
if (!loaded.ok || !loaded.data)
|
|
@@ -180,6 +186,7 @@ class AunPlugin {
|
|
|
180
186
|
};
|
|
181
187
|
async persist() {
|
|
182
188
|
this.config.identities = [...this.identities].sort();
|
|
189
|
+
this.config.created_aids = [...new Set([...this.createdAids, ...this.legacyCreatedAids])].sort();
|
|
183
190
|
this.config.bindings = this.bindings;
|
|
184
191
|
this.config.binding_times = this.bindingTimes;
|
|
185
192
|
await (0, promises_1.writeFile)((0, node_path_1.join)(this.context.dataDir, "config.json"), `${JSON.stringify(this.config, null, 2)}\n`, { mode: 0o600 });
|
|
@@ -188,6 +195,7 @@ class AunPlugin {
|
|
|
188
195
|
this.context = context;
|
|
189
196
|
this.config = { ...context.config };
|
|
190
197
|
this.legacyCreatedAids.clear();
|
|
198
|
+
this.createdAids.clear();
|
|
191
199
|
try {
|
|
192
200
|
const created = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(context.dataDir, "..", "created-aids.json"), "utf8"));
|
|
193
201
|
if (Array.isArray(created))
|
|
@@ -199,6 +207,10 @@ class AunPlugin {
|
|
|
199
207
|
if (error.code !== "ENOENT")
|
|
200
208
|
context.logger.warn("读取旧版身份创建记录失败", { error: safeError(error) });
|
|
201
209
|
}
|
|
210
|
+
for (const aid of Array.isArray(this.config.created_aids) ? this.config.created_aids : []) {
|
|
211
|
+
if (typeof aid === "string" && aidPattern.test(aid))
|
|
212
|
+
this.createdAids.add(aid);
|
|
213
|
+
}
|
|
202
214
|
for (const key of ["aid", "owner_aid", "aun_path", "encryption_seed", "root_ca_path", "allow_from", "agent_plugin"]) {
|
|
203
215
|
if (this.config[key] !== undefined && typeof this.config[key] !== "string")
|
|
204
216
|
throw new Error(`${key} 必须是字符串`);
|
|
@@ -487,6 +499,8 @@ class AunPlugin {
|
|
|
487
499
|
const agents = await this.agents();
|
|
488
500
|
return { message: agents.length ? `当前已就绪的 Agent 插件:\n${agents.map((agent) => `${agent.id}(${agent.displayName})`).join("\n")}` : "暂无已就绪的 Agent 插件", data: agents };
|
|
489
501
|
}
|
|
502
|
+
if (command === "default-owner")
|
|
503
|
+
return this.defaultOwnerCommand(args);
|
|
490
504
|
if (command === "create")
|
|
491
505
|
return this.createCommand(args);
|
|
492
506
|
if (command === "bind" && args.length === 2) {
|
|
@@ -522,10 +536,29 @@ class AunPlugin {
|
|
|
522
536
|
}
|
|
523
537
|
return { message: `已解除 ${pluginId} 的 AID 关联`, data: { agent: pluginId, unboundAids } };
|
|
524
538
|
}
|
|
525
|
-
if (!["status", "list", "agents", "create", "bind", "unbind"].includes(command ?? ""))
|
|
539
|
+
if (!["status", "list", "agents", "default-owner", "create", "bind", "unbind"].includes(command ?? ""))
|
|
526
540
|
throw new AunCommandError(`未知 AUN 命令:${command ?? ""}`);
|
|
527
541
|
throw new AunCommandError(`AUN 命令参数无效:${command}`);
|
|
528
542
|
}
|
|
543
|
+
async defaultOwnerCommand(args) {
|
|
544
|
+
const owner = typeof this.config.owner_aid === "string" ? this.config.owner_aid.trim() : "";
|
|
545
|
+
if (!args.length)
|
|
546
|
+
return { message: owner ? `默认 Owner:${owner}` : "未配置默认 Owner", data: { owner_aid: owner || undefined } };
|
|
547
|
+
if (args.length !== 2 || args[0] !== "set")
|
|
548
|
+
throw new AunCommandError("AUN 默认 Owner 命令参数无效");
|
|
549
|
+
const nextOwner = args[1].trim();
|
|
550
|
+
if (!aidPattern.test(nextOwner))
|
|
551
|
+
throw new AunCommandError("Owner AID 格式无效");
|
|
552
|
+
this.config.owner_aid = nextOwner;
|
|
553
|
+
try {
|
|
554
|
+
await this.persist();
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
this.config.owner_aid = owner;
|
|
558
|
+
throw error;
|
|
559
|
+
}
|
|
560
|
+
return { message: "默认 Owner 已保存", data: { configured: true } };
|
|
561
|
+
}
|
|
529
562
|
async createCommand(args) {
|
|
530
563
|
const aid = args[0] ?? "";
|
|
531
564
|
if (!aidPattern.test(aid))
|
|
@@ -544,8 +577,10 @@ class AunPlugin {
|
|
|
544
577
|
else
|
|
545
578
|
throw new AunCommandError(`不支持的创建参数:${option}`);
|
|
546
579
|
}
|
|
580
|
+
if (!owner)
|
|
581
|
+
owner = typeof this.config.owner_aid === "string" ? this.config.owner_aid.trim() : "";
|
|
547
582
|
if (!owner || !aidPattern.test(owner))
|
|
548
|
-
throw new AunCommandError("需要有效的 --owner AID");
|
|
583
|
+
throw new AunCommandError("需要有效的 --owner AID,或先设置默认 Owner");
|
|
549
584
|
if (agent) {
|
|
550
585
|
this.validatePluginId(agent);
|
|
551
586
|
await this.requireAgent(agent);
|
|
@@ -703,12 +738,14 @@ class AunPlugin {
|
|
|
703
738
|
const message = (0, messages_1.normalizeAunMessage)(payload, aid, typeof this.config.allow_from === "string" ? this.config.allow_from : undefined);
|
|
704
739
|
if (!message || !this.seen.add(message.messageId ? `${aid}:${message.messageId}` : ""))
|
|
705
740
|
return;
|
|
741
|
+
let replyAttempted = false;
|
|
706
742
|
const channelMessage = {
|
|
707
743
|
channel: "aun", recipientId: aid, peerId: message.peerId, messageId: message.messageId, text: message.text, threadId: message.threadId,
|
|
708
744
|
agentPlugin: this.bindings[aid] || (typeof this.config.agent_plugin === "string" && this.config.agent_plugin.trim() ? this.config.agent_plugin.trim() : "qwenwork"),
|
|
709
745
|
reply: async (text) => {
|
|
710
746
|
if (!text.trim())
|
|
711
747
|
return;
|
|
748
|
+
replyAttempted = true;
|
|
712
749
|
const payload = { type: "text", text };
|
|
713
750
|
if (message.threadId)
|
|
714
751
|
payload.thread_id = message.threadId;
|
|
@@ -728,6 +765,14 @@ class AunPlugin {
|
|
|
728
765
|
}
|
|
729
766
|
catch (error) {
|
|
730
767
|
this.context?.logger.warn("AUN 消息处理失败", { error: safeError(error) });
|
|
768
|
+
if (!replyAttempted && newSessionCommand.test(message.text.trim())) {
|
|
769
|
+
try {
|
|
770
|
+
await channelMessage.reply(`新建会话失败:${safeError(error)}`);
|
|
771
|
+
}
|
|
772
|
+
catch (replyError) {
|
|
773
|
+
this.context?.logger.warn("AUN 错误回复失败", { error: safeError(replyError) });
|
|
774
|
+
}
|
|
775
|
+
}
|
|
731
776
|
}
|
|
732
777
|
}
|
|
733
778
|
isE2eeError(error) {
|
|
@@ -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"
|
|
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" placeholder="例如:owner.agentid.cn"><small class="hint">留空时使用已配置的默认 Owner;未配置时需填写。Owner 保存为本地归属配置;不代表 AUN 协议中的 Owner 关系已激活。</small></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