agent-bridge-aun 1.0.30 → 1.0.31
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,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
`agent-bridge-aun` 为 mu-agent-bridge 提供 AUN 消息通道,支持使用已有 AID 或通过管理 API 注册 AID,并将收到的文本交给指定 Agent 插件处理。
|
|
4
4
|
|
|
5
|
-
安装后在 ABWeb 的插件管理中启动 AUN
|
|
5
|
+
安装后在 ABWeb 的插件管理中启动 AUN 通道。收到的 AID 消息仅投递给用户在 AUN 身份页中明确关联的 Agent;未关联的 AID 消息会被忽略。旧配置中的 `agent_plugin` 字段不再作为默认路由。配置字段 `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 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 <
|
|
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 <aid>`。关联或解绑只修改指定 AID,不会影响同一 Agent 下的其它 AID,也不会写入 Agent 全局 AID 配置。`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
|
|
package/config.schema.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"binding_times": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
8
8
|
"aid": { "type": "string", "minLength": 1 },
|
|
9
9
|
"owner_aid": { "type": "string", "minLength": 1 },
|
|
10
|
-
"agent_plugin": { "type": "string", "
|
|
10
|
+
"agent_plugin": { "type": "string", "description": "兼容旧配置;消息只按 AID 的显式关联路由。" },
|
|
11
11
|
"aun_path": { "type": "string", "minLength": 1 },
|
|
12
12
|
"encryption_seed": { "type": "string" },
|
|
13
13
|
"verify_ssl": { "type": "boolean", "default": true },
|
|
@@ -11,7 +11,7 @@ const node_url_1 = require("node:url");
|
|
|
11
11
|
const messages_1 = require("./messages");
|
|
12
12
|
const attachments_1 = require("./attachments");
|
|
13
13
|
const manifest = {
|
|
14
|
-
id: "aun", version: "1.0.
|
|
14
|
+
id: "aun", version: "1.0.31", type: "channel", displayName: "AUN 通道",
|
|
15
15
|
entry: "dist/src-ts/plugins/aun/index.js", apiVersion: "1", process: "in-process",
|
|
16
16
|
capabilities: ["channel", "channel.identity.create", "channel.receive", "channel.send", "health", "cli"],
|
|
17
17
|
configSchema: "config.schema.json",
|
|
@@ -41,7 +41,7 @@ const cliCommands = [
|
|
|
41
41
|
{ 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"] },
|
|
42
42
|
{ 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"] },
|
|
43
43
|
{ name: "bind", summary: "将 AID 关联到 Agent", usage: "mab aun bind <aid> <plugin-id>", examples: ["mab aun bind new.agentid.cn qwenwork"] },
|
|
44
|
-
{ name: "unbind", summary: "
|
|
44
|
+
{ name: "unbind", summary: "解除指定 AID 与 Agent 的关联", usage: "mab aun unbind <aid>", examples: ["mab aun unbind old.agentid.cn"] },
|
|
45
45
|
];
|
|
46
46
|
class AunCommandError extends Error {
|
|
47
47
|
statusCode;
|
|
@@ -140,11 +140,6 @@ class AunPlugin {
|
|
|
140
140
|
await this.connectAid(aid);
|
|
141
141
|
if (!this.clients.has(aid))
|
|
142
142
|
throw new Error("AID 当前未连接");
|
|
143
|
-
for (const [identity, target] of Object.entries(this.bindings))
|
|
144
|
-
if (target === pluginId) {
|
|
145
|
-
delete this.bindings[identity];
|
|
146
|
-
delete this.bindingTimes[identity];
|
|
147
|
-
}
|
|
148
143
|
this.bindings[aid] = pluginId;
|
|
149
144
|
}
|
|
150
145
|
else {
|
|
@@ -157,21 +152,11 @@ class AunPlugin {
|
|
|
157
152
|
await this.connectAid(aid);
|
|
158
153
|
if (!this.clients.has(aid))
|
|
159
154
|
throw new Error("AID 当前未连接");
|
|
160
|
-
for (const [identity, target] of Object.entries(this.bindings))
|
|
161
|
-
if (target === pluginId) {
|
|
162
|
-
delete this.bindings[identity];
|
|
163
|
-
delete this.bindingTimes[identity];
|
|
164
|
-
}
|
|
165
155
|
this.bindings[aid] = pluginId;
|
|
166
156
|
}
|
|
167
157
|
}
|
|
168
|
-
else
|
|
169
|
-
|
|
170
|
-
if (target === pluginId) {
|
|
171
|
-
delete this.bindings[identity];
|
|
172
|
-
delete this.bindingTimes[identity];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
158
|
+
else
|
|
159
|
+
throw new Error("必须指定要关联的 AID");
|
|
175
160
|
if (aid)
|
|
176
161
|
this.bindingTimes[aid] = new Date().toISOString();
|
|
177
162
|
await this.persist();
|
|
@@ -186,6 +171,29 @@ class AunPlugin {
|
|
|
186
171
|
}
|
|
187
172
|
this.context?.logger.info("AUN 身份关联已更新", { aid, pluginId });
|
|
188
173
|
},
|
|
174
|
+
unbind: async (pluginId, aid) => {
|
|
175
|
+
if (!aidPattern.test(aid))
|
|
176
|
+
throw new Error("AID 格式无效");
|
|
177
|
+
if (this.bindings[aid] !== pluginId)
|
|
178
|
+
throw new Error("指定 AID 当前未关联到该 Agent");
|
|
179
|
+
const previous = this.bindings;
|
|
180
|
+
const previousTimes = this.bindingTimes;
|
|
181
|
+
this.bindings = { ...previous };
|
|
182
|
+
this.bindingTimes = { ...previousTimes };
|
|
183
|
+
delete this.bindings[aid];
|
|
184
|
+
delete this.bindingTimes[aid];
|
|
185
|
+
try {
|
|
186
|
+
await this.persist();
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
this.bindings = previous;
|
|
190
|
+
this.bindingTimes = previousTimes;
|
|
191
|
+
this.config.bindings = previous;
|
|
192
|
+
this.config.binding_times = previousTimes;
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
this.context?.logger.info("AUN 单个身份关联已解除", { aid, pluginId });
|
|
196
|
+
},
|
|
189
197
|
};
|
|
190
198
|
async persist() {
|
|
191
199
|
this.config.identities = [...this.identities].sort();
|
|
@@ -214,7 +222,7 @@ class AunPlugin {
|
|
|
214
222
|
if (typeof aid === "string" && aidPattern.test(aid))
|
|
215
223
|
this.createdAids.add(aid);
|
|
216
224
|
}
|
|
217
|
-
for (const key of ["aid", "owner_aid", "aun_path", "encryption_seed", "root_ca_path", "allow_from"
|
|
225
|
+
for (const key of ["aid", "owner_aid", "aun_path", "encryption_seed", "root_ca_path", "allow_from"]) {
|
|
218
226
|
if (this.config[key] !== undefined && typeof this.config[key] !== "string")
|
|
219
227
|
throw new Error(`${key} 必须是字符串`);
|
|
220
228
|
}
|
|
@@ -236,6 +244,7 @@ class AunPlugin {
|
|
|
236
244
|
["POST", "/api/plugins/aun/aid", this.createAid],
|
|
237
245
|
["GET", "/api/plugins/aun/identities", this.listIdentities],
|
|
238
246
|
["POST", "/api/plugins/aun/bind", this.bindAgent],
|
|
247
|
+
["POST", "/api/plugins/aun/unbind", this.unbindAgent],
|
|
239
248
|
["POST", "/api/plugins/aun/settings", this.saveSettings],
|
|
240
249
|
["GET", "/api/plugins/aun/commands", this.listCommands],
|
|
241
250
|
["POST", "/api/plugins/aun/commands", this.runCommand],
|
|
@@ -419,12 +428,12 @@ class AunPlugin {
|
|
|
419
428
|
throw new Error("请求内容过大");
|
|
420
429
|
}
|
|
421
430
|
const body = JSON.parse(raw || "{}");
|
|
422
|
-
for (const key of ["
|
|
431
|
+
for (const key of ["allow_from", "aun_path"])
|
|
423
432
|
if (typeof body[key] !== "string")
|
|
424
433
|
return this.json(response, 400, { error: `${key} 必须是字符串` });
|
|
425
434
|
if (body.encryption_seed !== undefined && typeof body.encryption_seed !== "string")
|
|
426
435
|
return this.json(response, 400, { error: "encryption_seed 必须是字符串" });
|
|
427
|
-
this.config = { ...this.config,
|
|
436
|
+
this.config = { ...this.config, allow_from: body.allow_from, aun_path: body.aun_path, ...(body.encryption_seed ? { encryption_seed: body.encryption_seed } : {}) };
|
|
428
437
|
await this.persist();
|
|
429
438
|
this.context?.logger.info("AUN 通道配置已保存");
|
|
430
439
|
this.json(response, 200, { ok: true });
|
|
@@ -455,6 +464,28 @@ class AunPlugin {
|
|
|
455
464
|
this.json(response, 400, { error: safeError(error) });
|
|
456
465
|
}
|
|
457
466
|
};
|
|
467
|
+
unbindAgent = async (request, response) => {
|
|
468
|
+
try {
|
|
469
|
+
let raw = "";
|
|
470
|
+
for await (const chunk of request) {
|
|
471
|
+
raw += chunk;
|
|
472
|
+
if (raw.length > 65536)
|
|
473
|
+
throw new Error("请求内容过大");
|
|
474
|
+
}
|
|
475
|
+
const body = JSON.parse(raw || "{}");
|
|
476
|
+
const aid = typeof body.aid === "string" ? body.aid.trim() : "";
|
|
477
|
+
if (!aidPattern.test(aid))
|
|
478
|
+
return this.json(response, 400, { error: "AID 格式无效" });
|
|
479
|
+
const pluginId = this.bindings[aid];
|
|
480
|
+
if (!pluginId)
|
|
481
|
+
return this.json(response, 404, { error: "指定 AID 当前未关联 Agent" });
|
|
482
|
+
await this.identity.unbind(pluginId, aid, Number(this.context?.runtime?.ports?.aun ?? 0));
|
|
483
|
+
this.json(response, 200, { ok: true, aid, pluginId });
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
this.json(response, 400, { error: safeError(error) });
|
|
487
|
+
}
|
|
488
|
+
};
|
|
458
489
|
listCommands = async (_request, response) => {
|
|
459
490
|
response.setHeader("cache-control", "no-store");
|
|
460
491
|
this.json(response, 200, { protocolVersion: 1, plugin: "aun", version: manifest.version, commands: cliCommands });
|
|
@@ -515,7 +546,6 @@ class AunPlugin {
|
|
|
515
546
|
throw new AunCommandError("AID 格式无效");
|
|
516
547
|
this.validatePluginId(pluginId);
|
|
517
548
|
await this.requireAgent(pluginId);
|
|
518
|
-
const replacedAids = (await this.agentBindings(pluginId)).filter((previousAid) => previousAid !== aid);
|
|
519
549
|
try {
|
|
520
550
|
await this.patchAgentAid(pluginId, aid);
|
|
521
551
|
}
|
|
@@ -524,23 +554,25 @@ class AunPlugin {
|
|
|
524
554
|
throw new AunCommandError(`AID 关联请求失败,已回读当前状态:${safeError(error)}`, error instanceof AunCommandError ? error.statusCode : 502, { aid, agent: pluginId, ...(bindingState ? { bindingState } : { bindingState: "unknown" }) });
|
|
525
555
|
}
|
|
526
556
|
return {
|
|
527
|
-
message:
|
|
528
|
-
data: { aid, agent: pluginId
|
|
557
|
+
message: `AID ${aid} 已关联到 ${pluginId}`,
|
|
558
|
+
data: { aid, agent: pluginId },
|
|
529
559
|
};
|
|
530
560
|
}
|
|
531
561
|
if (command === "unbind" && args.length === 1) {
|
|
532
|
-
const [
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const
|
|
562
|
+
const [aid] = args;
|
|
563
|
+
if (!aidPattern.test(aid))
|
|
564
|
+
throw new AunCommandError("AID 格式无效");
|
|
565
|
+
const pluginId = this.bindings[aid];
|
|
566
|
+
if (!pluginId)
|
|
567
|
+
throw new AunCommandError("指定 AID 当前未关联 Agent");
|
|
536
568
|
try {
|
|
537
|
-
await this.
|
|
569
|
+
await this.identity.unbind(pluginId, aid, 0);
|
|
538
570
|
}
|
|
539
571
|
catch (error) {
|
|
540
572
|
const bindingState = await this.bindingState(pluginId).catch(() => undefined);
|
|
541
|
-
throw new AunCommandError(`解除关联请求失败,已回读当前状态:${safeError(error)}`, error instanceof AunCommandError ? error.statusCode : 502, { agent: pluginId, ...(bindingState ? { bindingState } : { bindingState: "unknown" }) });
|
|
573
|
+
throw new AunCommandError(`解除关联请求失败,已回读当前状态:${safeError(error)}`, error instanceof AunCommandError ? error.statusCode : 502, { aid, agent: pluginId, ...(bindingState ? { bindingState } : { bindingState: "unknown" }) });
|
|
542
574
|
}
|
|
543
|
-
return { message: `已解除 ${
|
|
575
|
+
return { message: `已解除 AID ${aid} 与 ${pluginId} 的关联`, data: { aid, agent: pluginId } };
|
|
544
576
|
}
|
|
545
577
|
if (!["status", "list", "agents", "default-owner", "create", "bind", "unbind"].includes(command ?? ""))
|
|
546
578
|
throw new AunCommandError(`未知 AUN 命令:${command ?? ""}`);
|
|
@@ -604,10 +636,8 @@ class AunPlugin {
|
|
|
604
636
|
const data = { created: true, aid, connection: created.connection ?? "ready" };
|
|
605
637
|
if (created.connection !== "ready")
|
|
606
638
|
throw new AunCommandError("AID 已创建,但连接失败;请先执行 mab aun list 确认,不要重试创建", 502, { ...data, connectionError: created.connectionError });
|
|
607
|
-
let replacedAids = [];
|
|
608
639
|
if (agent) {
|
|
609
640
|
try {
|
|
610
|
-
replacedAids = (await this.agentBindings(agent)).filter((previousAid) => previousAid !== aid);
|
|
611
641
|
await this.patchAgentAid(agent, aid);
|
|
612
642
|
}
|
|
613
643
|
catch (error) {
|
|
@@ -616,8 +646,8 @@ class AunPlugin {
|
|
|
616
646
|
}
|
|
617
647
|
}
|
|
618
648
|
return {
|
|
619
|
-
message: agent ?
|
|
620
|
-
data: { ...data, ...(agent ? { agent
|
|
649
|
+
message: agent ? `AID 已创建并关联到 ${agent}` : "AID 已创建并连接",
|
|
650
|
+
data: { ...data, ...(agent ? { agent } : {}) },
|
|
621
651
|
};
|
|
622
652
|
}
|
|
623
653
|
async agents(readyOnly = true) {
|
|
@@ -671,7 +701,7 @@ class AunPlugin {
|
|
|
671
701
|
method,
|
|
672
702
|
headers: { accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
|
|
673
703
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
674
|
-
signal: AbortSignal.timeout(5000),
|
|
704
|
+
signal: AbortSignal.timeout(method === "PATCH" ? 120_000 : 5000),
|
|
675
705
|
redirect: "error",
|
|
676
706
|
});
|
|
677
707
|
}
|
|
@@ -741,7 +771,8 @@ class AunPlugin {
|
|
|
741
771
|
}
|
|
742
772
|
};
|
|
743
773
|
async onMessage(payload, aid) {
|
|
744
|
-
|
|
774
|
+
const agentPlugin = this.bindings[aid];
|
|
775
|
+
if (!this.acceptingMessages || !agentPlugin)
|
|
745
776
|
return;
|
|
746
777
|
const message = (0, messages_1.normalizeAunMessage)(payload, aid, typeof this.config.allow_from === "string" ? this.config.allow_from : undefined);
|
|
747
778
|
if (!message || !this.seen.add(message.messageId ? `${aid}:${message.messageId}` : ""))
|
|
@@ -757,7 +788,7 @@ class AunPlugin {
|
|
|
757
788
|
}
|
|
758
789
|
return;
|
|
759
790
|
}
|
|
760
|
-
const current = (pending ?? Promise.resolve()).catch(() => undefined).then(() => this.processMessage(message, aid));
|
|
791
|
+
const current = (pending ?? Promise.resolve()).catch(() => undefined).then(() => this.processMessage(message, aid, agentPlugin));
|
|
761
792
|
this.pendingMessages.set(sourceKey, current);
|
|
762
793
|
try {
|
|
763
794
|
await current;
|
|
@@ -767,12 +798,22 @@ class AunPlugin {
|
|
|
767
798
|
this.pendingMessages.delete(sourceKey);
|
|
768
799
|
}
|
|
769
800
|
}
|
|
770
|
-
async processMessage(message, aid) {
|
|
801
|
+
async processMessage(message, aid, agentPlugin) {
|
|
771
802
|
let replyAttempted = false;
|
|
772
803
|
const client = this.clients.get(aid)?.client;
|
|
773
804
|
let attachments = [];
|
|
774
805
|
let uploadedItems;
|
|
775
806
|
let uploadedRefs;
|
|
807
|
+
if (this.context?.pluginStatus(agentPlugin) !== "ready") {
|
|
808
|
+
this.context?.logger.warn("AUN 关联 Agent 尚未就绪,消息未转发", { aid, agentPlugin, status: this.context?.pluginStatus(agentPlugin) });
|
|
809
|
+
try {
|
|
810
|
+
await this.sendText(aid, message.peerId, `绑定的 Agent 插件 ${agentPlugin} 尚未就绪,消息未转发;AID 关联保持不变。`, message.threadId);
|
|
811
|
+
}
|
|
812
|
+
catch (error) {
|
|
813
|
+
this.context?.logger.warn("AUN Agent 未就绪提示发送失败", { aid, agentPlugin, error: safeError(error) });
|
|
814
|
+
}
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
776
817
|
try {
|
|
777
818
|
if (message.attachmentError)
|
|
778
819
|
throw new Error(message.attachmentError);
|
|
@@ -793,7 +834,7 @@ class AunPlugin {
|
|
|
793
834
|
const channelMessage = {
|
|
794
835
|
channel: "aun", recipientId: aid, peerId: message.peerId, messageId: message.messageId, text: message.text, threadId: message.threadId,
|
|
795
836
|
...(attachments.length ? { attachments } : {}),
|
|
796
|
-
agentPlugin
|
|
837
|
+
agentPlugin,
|
|
797
838
|
reply: async (text) => {
|
|
798
839
|
if (!text.trim())
|
|
799
840
|
return;
|
|
@@ -28,11 +28,7 @@
|
|
|
28
28
|
const [identities, plugins, config] = await Promise.all([request("/api/plugins/aun/identities"), request("/api/plugins"), request("/api/plugins/aun/config")]);
|
|
29
29
|
agents = (plugins.plugins || []).filter((plugin) => plugin.type === "agent");
|
|
30
30
|
if (refreshForm) createForm.elements.ownerAid.value = config.owner_aid || "";
|
|
31
|
-
await Promise.all(agents.map(async (agent) => { agent.configAid = (await request(`/api/plugins/${encodeURIComponent(agent.id)}/config`)).aid || ""; }));
|
|
32
|
-
const target = configForm.elements.agent_plugin;
|
|
33
31
|
if (refreshForm) {
|
|
34
|
-
target.replaceChildren(new Option("默认 Agent", ""), ...agents.map((agent) => new Option(agent.displayName || agent.id, agent.id)));
|
|
35
|
-
target.value = config.agent_plugin || "";
|
|
36
32
|
for (const key of ["allow_from", "aun_path"]) configForm.elements[key].value = config[key] || "";
|
|
37
33
|
configForm.elements.encryption_seed.value = "";
|
|
38
34
|
}
|
|
@@ -43,7 +39,7 @@
|
|
|
43
39
|
for (const aid of values) {
|
|
44
40
|
if (seen.has(aid)) continue;
|
|
45
41
|
seen.add(aid);
|
|
46
|
-
entries.push({ aid, label, group, bound: identities.bindings?.[aid] ||
|
|
42
|
+
entries.push({ aid, label, group, bound: identities.bindings?.[aid] || "", time: Date.parse(identities.bindingTimes?.[aid] || "") || 0 });
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
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));
|
|
@@ -52,7 +48,7 @@
|
|
|
52
48
|
for (const value of [aid, label, bound || "未关联"]) { const cell = document.createElement("td"); cell.textContent = value; row.append(cell); }
|
|
53
49
|
const cell = document.createElement("td"); const select = document.createElement("select"); select.setAttribute("aria-label", `${aid} 关联 Agent`);
|
|
54
50
|
select.append(new Option("选择 Agent", ""), ...agents.map((agent) => new Option(agent.displayName || agent.id, agent.id)));
|
|
55
|
-
select.value = bound; select.onchange = () => { if (select.value) void bind(aid, select.value); };
|
|
51
|
+
select.value = bound; select.onchange = () => { if (select.value) void bind(aid, select.value); else if (bound) void unbind(aid); };
|
|
56
52
|
cell.append(select); row.append(cell); list.append(row);
|
|
57
53
|
}
|
|
58
54
|
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); }
|
|
@@ -66,6 +62,12 @@
|
|
|
66
62
|
await load(); notify("关联成功", `${aid} 已关联 ${pluginId}`);
|
|
67
63
|
} catch (error) { notify("关联失败", errorMessage(error), true); }
|
|
68
64
|
}
|
|
65
|
+
async function unbind(aid) {
|
|
66
|
+
try {
|
|
67
|
+
await request("/api/plugins/aun/unbind", "POST", { aid });
|
|
68
|
+
await load(); notify("解除关联成功", `${aid} 已解除关联`);
|
|
69
|
+
} catch (error) { notify("解除关联失败", errorMessage(error), true); }
|
|
70
|
+
}
|
|
69
71
|
createForm.onsubmit = (event) => { event.preventDefault(); const aid = createForm.elements.aid.value.trim(); const owner = createForm.elements.ownerAid.value.trim();
|
|
70
72
|
show("正在创建 AID 并连接,请稍候……");
|
|
71
73
|
void request("/api/plugins/aun/aid", "POST", { aid, ownerAid: owner }).then((result) => {
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
return load();
|
|
77
79
|
}).catch((error) => notify("创建 AID 失败", errorMessage(error), true));
|
|
78
80
|
};
|
|
79
|
-
configForm.onsubmit = (event) => { event.preventDefault(); const changes = {
|
|
81
|
+
configForm.onsubmit = (event) => { event.preventDefault(); const changes = { allow_from: configForm.elements.allow_from.value, aun_path: configForm.elements.aun_path.value };
|
|
80
82
|
if (configForm.elements.encryption_seed.value) changes.encryption_seed = configForm.elements.encryption_seed.value;
|
|
81
83
|
void request("/api/plugins/aun/settings", "POST", changes).then(() => request("/api/plugins/aun/reload", "POST")).then(() => load()).then(() => notify("保存成功", "配置已保存")).catch((error) => notify("保存配置失败", errorMessage(error), true));
|
|
82
84
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
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
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
|
-
<form id="config-form"><h2>通道配置</h2><div class="fields"><label
|
|
10
|
+
<form id="config-form"><h2>通道配置</h2><div class="fields"><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>
|
|
13
13
|
</body>
|
package/package.json
CHANGED