mu-agent-bridge 1.0.15 → 1.0.16
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 +15 -7
- package/dist/src-ts/cli.js +47 -1
- package/dist/src-ts/control-server.js +12 -5
- package/dist/src-ts/local-aids.js +2 -2
- package/dist/src-ts/plugin-manifest.js +4 -1
- package/dist/src-ts/plugins/abweb/public/app.js +10 -0
- package/dist/src-ts/plugins/aun/evolcore.js +43 -0
- package/dist/src-ts/plugins/aun/index.js +41 -23
- package/dist/src-ts/plugins/aun/public/app.js +3 -3
- package/dist/src-ts/plugins/qwenwork/cdp-client.js +8 -1
- package/dist/tests-ts/aun-plugin.test.js +60 -16
- package/dist/tests-ts/bundled-package.test.js +24 -0
- package/dist/tests-ts/control-server.test.js +27 -0
- package/dist/tests-ts/plugin-manager.test.js +39 -0
- package/dist/tests-ts/qwenwork-plugin.test.js +38 -0
- package/package.json +6 -6
- package/plugins/abweb/dist/src-ts/agent.js +10 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/control-client.js +91 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/index.js +132 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/public/app.js +366 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/public/app.ts +227 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/public/index.html +25 -0
- package/plugins/abweb/dist/src-ts/plugins/abweb/public/style.css +55 -0
- package/plugins/abweb/plugin.json +7 -3
- package/plugins/aun/config.schema.json +18 -0
- package/plugins/aun/dist/src-ts/agent.js +10 -0
- package/plugins/aun/dist/src-ts/plugins/aun/evolcore.js +43 -0
- package/plugins/aun/dist/src-ts/plugins/aun/index.js +434 -0
- package/plugins/aun/dist/src-ts/plugins/aun/messages.js +45 -0
- package/plugins/aun/dist/src-ts/plugins/aun/public/app.js +66 -0
- package/plugins/aun/dist/src-ts/plugins/aun/public/index.html +14 -0
- package/plugins/aun/dist/src-ts/plugins/aun/public/style.css +21 -0
- package/plugins/aun/plugin.json +18 -0
- package/plugins/doubao/config.schema.json +13 -0
- package/plugins/doubao/dist/src-ts/agent.js +10 -0
- package/plugins/doubao/dist/src-ts/plugins/doubao/cdp-client.js +94 -0
- package/plugins/doubao/dist/src-ts/plugins/doubao/index.js +84 -0
- package/plugins/doubao/plugin.json +15 -0
- package/plugins/dsh/config.schema.json +8 -0
- package/plugins/dsh/dist/src-ts/agent.js +10 -0
- package/plugins/dsh/dist/src-ts/dsh-agent.js +70 -0
- package/plugins/dsh/dist/src-ts/dsh-paths.js +15 -0
- package/plugins/dsh/dist/src-ts/headless-account.patch.yml +5 -0
- package/plugins/dsh/dist/src-ts/plugins/dsh/index.js +61 -0
- package/plugins/dsh/dist/src-ts/plugins/qwenwork/openai-adapter.js +146 -0
- package/plugins/dsh/plugin.json +14 -0
- package/plugins/feishu/config.schema.json +68 -0
- package/plugins/feishu/dist/src-ts/agent.js +10 -0
- package/plugins/feishu/dist/src-ts/channel.js +2 -0
- package/plugins/feishu/dist/src-ts/plugins/feishu/client.js +133 -0
- package/plugins/feishu/dist/src-ts/plugins/feishu/index.js +257 -0
- package/plugins/feishu/dist/src-ts/plugins/feishu/public/app.js +147 -0
- package/plugins/feishu/dist/src-ts/plugins/feishu/public/index.html +17 -0
- package/plugins/feishu/dist/src-ts/plugins/feishu/public/style.css +30 -0
- package/plugins/feishu/plugin.json +18 -0
- package/plugins/qwenwork/dist/src-ts/agent.js +10 -0
- package/plugins/qwenwork/dist/src-ts/plugins/qwenwork/cdp-client.js +172 -0
- package/plugins/qwenwork/dist/src-ts/plugins/qwenwork/index.js +148 -0
- package/plugins/qwenwork/dist/src-ts/plugins/qwenwork/openai-adapter.js +146 -0
- package/plugins/qwenwork/plugin.json +8 -4
- package/plugins/workbuddy/config.schema.json +15 -0
- package/plugins/workbuddy/dist/src-ts/agent.js +10 -0
- package/plugins/workbuddy/dist/src-ts/plugins/workbuddy/cdp-client.js +118 -0
- package/plugins/workbuddy/dist/src-ts/plugins/workbuddy/cli-client.js +39 -0
- package/plugins/workbuddy/dist/src-ts/plugins/workbuddy/index.js +139 -0
- package/plugins/workbuddy/plugin.json +15 -0
package/README.md
CHANGED
|
@@ -20,12 +20,10 @@ OpenAI 兼容 API 为 `/v1/models` 和 `/v1/chat/completions`。管理页面位
|
|
|
20
20
|
安装后使用 `mab start` 启动。旧桥仍可使用 `17893`,不会与管理页面冲突。局域网访问时设置
|
|
21
21
|
`AGENT_BRIDGE_HOST=0.0.0.0` 和 `AGENT_BRIDGE_TOKEN`,然后访问
|
|
22
22
|
`http://<Windows 主机 IP>:26107/abweb/`。页面使用一次性配置码配对后管理插件;请只在可信网络使用。
|
|
23
|
-
已有 AID 的连接状态由 AUN
|
|
24
|
-
|
|
23
|
+
已有 AID 的连接状态由 AUN 插件自己建立和查询,只有当前已连接的身份才能关联 Agent。
|
|
24
|
+
AUN 插件通过 SDK 枚举 EvolCore 的本地 AID,并逐个建立连接;ABWeb 只展示已连接 AID,并按 EvolCore 与 mu-agent-bridge 分组,未连接身份不显示。状态检测不调用 `ec agent list/show`。
|
|
25
25
|
创建新 AID 必须填写 Owner AID,并安装、启动 AUN 插件;创建与通信由该插件完成。
|
|
26
|
-
|
|
27
|
-
关联 AID 到 DSH 或千问办公等 Agent 时,由 AUN 插件直接保持该身份连接并把来信转给
|
|
28
|
-
对应 Agent,回复经 AUN 发送;关联不再执行 `ec agent set/reload` 配置 EvolCore 路由。
|
|
26
|
+
本工程创建的身份由 AUN 插件保持连接并收发消息;EvolCore 来源身份只用于连接状态检测,不订阅消息,避免重复收信。将 EvolCore 身份关联到 Agent 时,AUN 插件仍执行既有 `ec agent set/reload` 路由配置;该命令不用于检测连接状态。
|
|
29
27
|
其他 Agent 插件可关联 AUN 插件自己创建的身份,由通道直接转发来信和回复。
|
|
30
28
|
Windows 可运行 `start-mab.ps1` 注册并启动登录时自动运行的计划任务;令牌保存在
|
|
31
29
|
`%USERPROFILE%\.mab\token.txt`,页面输入该令牌即可使用管理 API。
|
|
@@ -42,7 +40,14 @@ abweb 的“配置码”栏;配对码 10 分钟有效,只能使用一次,
|
|
|
42
40
|
|
|
43
41
|
## npm 插件
|
|
44
42
|
|
|
45
|
-
默认包 `mu-agent-bridge`
|
|
43
|
+
默认包 `mu-agent-bridge` 已内置 abweb、AUN、千问办公、DSH、豆包、飞书和 WorkBuddy 七个插件,直接安装即可使用:
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
npm install -g mu-agent-bridge@latest
|
|
47
|
+
mab start
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
七个插件会从核心包的 `plugins/` 目录自动发现。插件仍分别发布为独立 npm 包,可用于单独测试、升级或替换版本。安装与发布说明见
|
|
46
51
|
[`docs/npm-publishing.md`](docs/npm-publishing.md)。
|
|
47
52
|
|
|
48
53
|
`mab start` 启动时会查询核心包和托管插件的 npm 最新版本,检查状态保存于 mab 状态目录的
|
|
@@ -50,6 +55,9 @@ abweb 的“配置码”栏;配对码 10 分钟有效,只能使用一次,
|
|
|
50
55
|
升级失败会恢复旧插件并继续启动。Windows 的 `start-mab.ps1` 登录计划任务会在启动 daemon 前
|
|
51
56
|
更新全局核心包,健康检查失败时恢复备份。全局单独安装的插件及 Linux 核心自动升级暂不受管理。
|
|
52
57
|
|
|
58
|
+
可用 `mab status` 查看后台、插件以及 AUN 已连接 AID 和关联 Agent 的状态。AUN 插件自己加载本地
|
|
59
|
+
`~/.evolcore/AIDs` 并建立连接,不要求先启动 `ec start`,也不调用 `ec agent list/show`。
|
|
60
|
+
|
|
53
61
|
插件更新策略可在 ABWeb 的“版本管理”中选择:默认“自动下载并安装”;“自动下载,手动安装”会把新版本缓存到状态目录并等待页面操作;“手动下载和安装”只检查版本。策略保存在 `state/update-policy.json`,插件下载缓存位于 `state/downloads`。
|
|
54
62
|
|
|
55
63
|
运行时会发现核心包依赖和 `AGENT_BRIDGE_PLUGIN_PACKAGES` 中声明的 npm 包。插件包在自己的
|
|
@@ -64,7 +72,7 @@ abweb 插件目录从 npm 搜索带 `mu-agent-bridge-plugin` 关键词的包,
|
|
|
64
72
|
插件仍在 daemon 的同一个 Node.js 进程内运行。修改插件入口依赖后应重启 daemon,避免模块缓存
|
|
65
73
|
影响新代码。
|
|
66
74
|
|
|
67
|
-
npm
|
|
75
|
+
npm 尚未发布时,核心包内置的七个默认插件仍会出现在插件列表。abweb 的“安装本地插件”
|
|
68
76
|
可填写 **Windows 主机上**包含 `plugin.json` 的目录路径,例如编译后的
|
|
69
77
|
`C:\path\to\agent_bridge\packages\dsh`;安装后可在下拉框中启动。已内置的千问办公无需再次安装。
|
|
70
78
|
“安装 npm 插件”只适用于包已经公开发布的情况。npm 发布令牌仅供发布脚本向 npm 官网认证,
|
package/dist/src-ts/cli.js
CHANGED
|
@@ -109,6 +109,50 @@ async function update() {
|
|
|
109
109
|
console.log("核心已更新,已请求 mab 计划任务重新启动");
|
|
110
110
|
return 0;
|
|
111
111
|
}
|
|
112
|
+
async function status() {
|
|
113
|
+
const port = Number(process.env.AGENT_BRIDGE_PORT ?? "26107");
|
|
114
|
+
const get = (path) => new Promise((resolve, reject) => {
|
|
115
|
+
const req = (0, node_http_1.request)({ host: "127.0.0.1", port, path, method: "GET" }, (res) => {
|
|
116
|
+
let body = "";
|
|
117
|
+
res.setEncoding("utf8");
|
|
118
|
+
res.on("data", (chunk) => body += chunk);
|
|
119
|
+
res.on("end", () => {
|
|
120
|
+
try {
|
|
121
|
+
const value = JSON.parse(body);
|
|
122
|
+
if ((res.statusCode ?? 500) >= 400)
|
|
123
|
+
reject(new Error(value.error ?? `HTTP ${res.statusCode}`));
|
|
124
|
+
else
|
|
125
|
+
resolve(value);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
reject(new Error("后台响应格式错误"));
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
req.setTimeout(5000, () => req.destroy(new Error("连接后台超时")));
|
|
133
|
+
req.on("error", reject);
|
|
134
|
+
req.end();
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
const [plugins, health, aids] = await Promise.all([get("/api/plugins"), get("/api/health"), get("/api/plugins/aun/identities")]);
|
|
138
|
+
console.log(`后台:运行中(端口 ${port})`);
|
|
139
|
+
console.log(`插件:${health.plugins ?? plugins.plugins?.length ?? 0} 个`);
|
|
140
|
+
for (const plugin of plugins.plugins ?? [])
|
|
141
|
+
console.log(` ${plugin.id} ${plugin.version}:${plugin.status}`);
|
|
142
|
+
const groups = aids.groups ?? { muAgentBridge: [], evolcore: [] };
|
|
143
|
+
const all = aids.aids ?? [...(groups.muAgentBridge ?? []), ...(groups.evolcore ?? [])];
|
|
144
|
+
console.log(`AUN 已连接 AID:${all.length} 个`);
|
|
145
|
+
for (const aid of groups.muAgentBridge ?? [])
|
|
146
|
+
console.log(` ${aid}:本工程${aids.bindings?.[aid] ? ` → ${aids.bindings[aid]}` : ""}`);
|
|
147
|
+
for (const aid of groups.evolcore ?? [])
|
|
148
|
+
console.log(` ${aid}:EvolCore${aids.bindings?.[aid] ? ` → ${aids.bindings[aid]}` : ""}`);
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error(`后台未运行或无法访问:${error instanceof Error ? error.message : String(error)}`);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
112
156
|
async function serve() {
|
|
113
157
|
const manager = new plugin_manager_1.PluginManager({
|
|
114
158
|
pluginsDir: (0, node_path_1.resolve)(process.env.AGENT_BRIDGE_PLUGINS_DIR ?? (0, node_path_1.resolve)(__dirname, "..", "..", "plugins")),
|
|
@@ -201,6 +245,8 @@ async function main() {
|
|
|
201
245
|
const args = process.argv.slice(2);
|
|
202
246
|
if (args.includes("pair"))
|
|
203
247
|
return pair();
|
|
248
|
+
if (args[0] === "status")
|
|
249
|
+
return status();
|
|
204
250
|
if (args[0] === "update")
|
|
205
251
|
return update();
|
|
206
252
|
const selfTestIndex = args.indexOf("--self-test");
|
|
@@ -208,7 +254,7 @@ async function main() {
|
|
|
208
254
|
return selfTest(args[selfTestIndex + 1] ?? "hi");
|
|
209
255
|
if (args.includes("--serve") || args.includes("start"))
|
|
210
256
|
return serve();
|
|
211
|
-
console.error("用法:mab start | mab --self-test <任务>");
|
|
257
|
+
console.error("用法:mab start | mab status | mab --self-test <任务>");
|
|
212
258
|
return 2;
|
|
213
259
|
}
|
|
214
260
|
main().then((code) => { process.exitCode = code; }).catch((error) => {
|
|
@@ -4,9 +4,10 @@ exports.ControlServer = exports.listExistingAids = void 0;
|
|
|
4
4
|
const node_http_1 = require("node:http");
|
|
5
5
|
const node_child_process_1 = require("node:child_process");
|
|
6
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const local_aids_1 = require("./local-aids");
|
|
7
8
|
const openai_adapter_1 = require("./plugins/qwenwork/openai-adapter");
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "listExistingAids", { enumerable: true, get: function () { return
|
|
9
|
+
var local_aids_2 = require("./local-aids");
|
|
10
|
+
Object.defineProperty(exports, "listExistingAids", { enumerable: true, get: function () { return local_aids_2.listExistingAids; } });
|
|
10
11
|
const AID_PATTERN = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$/;
|
|
11
12
|
class ControlServer {
|
|
12
13
|
options;
|
|
@@ -102,9 +103,8 @@ class ControlServer {
|
|
|
102
103
|
if (method === "GET" && url.pathname === "/api/aids") {
|
|
103
104
|
const identity = this.identity();
|
|
104
105
|
const groups = identity ? await identity.list() : { evolcore: [], muAgentBridge: [] };
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return this.json(res, 200, { aids, groups, localAids: [], canCreate: Boolean(identity), message: identity ? "" : "请先安装并启动 AUN 插件,才能创建或关联 AID" });
|
|
106
|
+
const aids = [...new Set([...groups.evolcore, ...groups.muAgentBridge])];
|
|
107
|
+
return this.json(res, 200, { aids, groups, localAids: (await (0, local_aids_1.listExistingAids)()).filter((aid) => !aids.includes(aid)), canCreate: Boolean(identity), message: identity ? "" : "请先安装并启动 AUN 插件,才能创建或关联 AID" });
|
|
108
108
|
}
|
|
109
109
|
if (method === "POST" && url.pathname === "/api/aids") {
|
|
110
110
|
const body = await this.body(req);
|
|
@@ -189,6 +189,13 @@ class ControlServer {
|
|
|
189
189
|
}
|
|
190
190
|
if (await this.options.manager.dispatchHttp(req, res))
|
|
191
191
|
return;
|
|
192
|
+
// 根路径直接进入 abweb 管理页面,避免用户手敲 /abweb/
|
|
193
|
+
if (method === "GET" && (url.pathname === "/" || url.pathname === "")) {
|
|
194
|
+
res.statusCode = 302;
|
|
195
|
+
res.setHeader("location", "/abweb/");
|
|
196
|
+
res.end();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
192
199
|
return this.json(res, 404, { error: "not found" });
|
|
193
200
|
}
|
|
194
201
|
catch (error) {
|
|
@@ -4,8 +4,8 @@ exports.listExistingAids = listExistingAids;
|
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const node_os_1 = require("node:os");
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
-
async function listExistingAids() {
|
|
8
|
-
const root = (0, node_path_1.resolve)(process.env.EVOLCORE_HOME ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".evolcore"), "AIDs");
|
|
7
|
+
async function listExistingAids(aunRoot) {
|
|
8
|
+
const root = (0, node_path_1.resolve)(aunRoot ?? process.env.EVOLCORE_HOME ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".evolcore"), "AIDs");
|
|
9
9
|
let names;
|
|
10
10
|
try {
|
|
11
11
|
names = await (0, promises_1.readdir)(root);
|
|
@@ -4,6 +4,7 @@ exports.validateManifest = validateManifest;
|
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const agent_1 = require("./agent");
|
|
6
6
|
const semver = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
7
|
+
const httpUrl = /^https?:\/\/.+$/;
|
|
7
8
|
function validateManifest(value, baseDir) {
|
|
8
9
|
if (!value || typeof value !== "object")
|
|
9
10
|
throw new agent_1.AgentError("invalid plugin manifest");
|
|
@@ -27,6 +28,8 @@ function validateManifest(value, baseDir) {
|
|
|
27
28
|
throw new agent_1.AgentError("invalid plugin process");
|
|
28
29
|
if (m.managementPage !== undefined && ((m.type ?? inferredType) !== "channel" || m.managementPage !== `/abweb/channels/${m.id}`))
|
|
29
30
|
throw new agent_1.AgentError("插件管理页面路径无效");
|
|
31
|
+
if (m.clientDownloadUrl !== undefined && (typeof m.clientDownloadUrl !== "string" || !httpUrl.test(m.clientDownloadUrl)))
|
|
32
|
+
throw new agent_1.AgentError("客户端下载地址必须是 http(s) URL");
|
|
30
33
|
if (m.dependencies && (!m.dependencies || typeof m.dependencies !== "object" || Array.isArray(m.dependencies) || Object.entries(m.dependencies).some(([id, range]) => !/^[a-z][a-z0-9-]{1,63}$/.test(id) || typeof range !== "string" || !range.trim())))
|
|
31
34
|
throw new agent_1.AgentError("插件依赖声明无效");
|
|
32
35
|
if (baseDir) {
|
|
@@ -36,5 +39,5 @@ function validateManifest(value, baseDir) {
|
|
|
36
39
|
if ((0, node_path_1.isAbsolute)(m.entry) || rel.startsWith(`..${node_path_1.sep}`) || rel === "..")
|
|
37
40
|
throw new agent_1.AgentError("plugin entry path escapes plugin directory");
|
|
38
41
|
}
|
|
39
|
-
return { id: m.id, version: m.version, displayName: m.displayName ?? m.id, type: m.type ?? inferredType, entry: m.entry, apiVersion: m.apiVersion, process: m.process ?? "in-process", capabilities: [...m.capabilities], configSchema: m.configSchema, routes: m.routes, ...(m.dependencies ? { dependencies: { ...m.dependencies } } : {}), ...(m.managementPage ? { managementPage: m.managementPage } : {}) };
|
|
42
|
+
return { id: m.id, version: m.version, displayName: m.displayName ?? m.id, type: m.type ?? inferredType, entry: m.entry, apiVersion: m.apiVersion, process: m.process ?? "in-process", capabilities: [...m.capabilities], configSchema: m.configSchema, routes: m.routes, ...(m.dependencies ? { dependencies: { ...m.dependencies } } : {}), ...(m.managementPage ? { managementPage: m.managementPage } : {}), ...(m.clientDownloadUrl ? { clientDownloadUrl: m.clientDownloadUrl } : {}) };
|
|
40
43
|
}
|
|
@@ -239,6 +239,16 @@
|
|
|
239
239
|
detail.textContent = `依赖:${plugin.dependencyStatus.join(";")}`;
|
|
240
240
|
state.append(detail);
|
|
241
241
|
}
|
|
242
|
+
// 插件未就绪且声明了客户端下载地址时,给出获取桌面客户端的入口
|
|
243
|
+
if (plugin.manifest?.clientDownloadUrl && plugin.status !== "ready") {
|
|
244
|
+
const link = document.createElement("a");
|
|
245
|
+
link.className = "plugin-id";
|
|
246
|
+
link.href = plugin.manifest.clientDownloadUrl;
|
|
247
|
+
link.target = "_blank";
|
|
248
|
+
link.rel = "noreferrer noopener";
|
|
249
|
+
link.textContent = "下载客户端";
|
|
250
|
+
state.append(link);
|
|
251
|
+
}
|
|
242
252
|
const controls = document.createElement("td");
|
|
243
253
|
controls.className = "controls";
|
|
244
254
|
if (pluginVersions[plugin.id]?.state === "update-available" && plugin.path.includes("node_modules")) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runEc = runEc;
|
|
4
|
+
exports.configureAidForPlugin = configureAidForPlugin;
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
|
+
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
8
|
+
async function runEc(args) {
|
|
9
|
+
try {
|
|
10
|
+
const { stdout } = await execFileAsync("ec", args, { shell: process.platform === "win32", timeout: 15_000, maxBuffer: 1024 * 1024 });
|
|
11
|
+
return JSON.parse(stdout);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const stdout = error.stdout;
|
|
15
|
+
if (stdout) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(stdout);
|
|
18
|
+
}
|
|
19
|
+
catch { /* 保留原始命令错误 */ }
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function configureAidForPlugin(pluginId, aid, port, run = runEc) {
|
|
25
|
+
if (!aid)
|
|
26
|
+
return;
|
|
27
|
+
if (!/^[a-z0-9_-]+$/.test(pluginId))
|
|
28
|
+
throw new Error("插件 ID 格式无效");
|
|
29
|
+
const path = pluginId === "dsh" ? "/dsh/v1" : pluginId === "qwenwork" ? "/v1" : `/api/agents/${pluginId}/v1`;
|
|
30
|
+
for (const [key, value] of [
|
|
31
|
+
["baseagents.ecagent.baseUrl", `http://127.0.0.1:${port}${path}`],
|
|
32
|
+
["baseagents.ecagent.apiKey", "mab-local"],
|
|
33
|
+
["baseagents.ecagent.model", pluginId],
|
|
34
|
+
["active_baseagent", "ecagent"],
|
|
35
|
+
]) {
|
|
36
|
+
const result = await run(["agent", "set", aid, key, value, "--format", "json"]);
|
|
37
|
+
if (!result?.ok)
|
|
38
|
+
throw new Error(`配置 AID ${aid} 失败:${key};${result?.code ?? ""} ${result?.error ?? "未知错误"}`);
|
|
39
|
+
}
|
|
40
|
+
const result = await run(["agent", "reload", aid, "--format", "json"]);
|
|
41
|
+
if (!result?.ok)
|
|
42
|
+
throw new Error(`重载 AID ${aid} 失败:${result?.code ?? ""} ${result?.error ?? "未知错误"}`);
|
|
43
|
+
}
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AunPlugin = void 0;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
5
6
|
const node_module_1 = require("node:module");
|
|
6
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
7
9
|
const node_url_1 = require("node:url");
|
|
8
10
|
const messages_1 = require("./messages");
|
|
11
|
+
const evolcore_1 = require("./evolcore");
|
|
9
12
|
const manifest = {
|
|
10
|
-
id: "aun", version: "1.0.
|
|
13
|
+
id: "aun", version: "1.0.10", type: "channel", displayName: "AUN 通道",
|
|
11
14
|
entry: "dist/src-ts/plugins/aun/index.js", apiVersion: "1", process: "in-process",
|
|
12
15
|
capabilities: ["channel", "channel.identity.create", "channel.receive", "channel.send", "health"],
|
|
13
16
|
configSchema: "config.schema.json",
|
|
@@ -36,6 +39,7 @@ class AunPlugin {
|
|
|
36
39
|
store;
|
|
37
40
|
clients = new Map();
|
|
38
41
|
identities = new Set();
|
|
42
|
+
legacyCreatedAids = new Set();
|
|
39
43
|
bindings = {};
|
|
40
44
|
bindingTimes = {};
|
|
41
45
|
creating = false;
|
|
@@ -53,13 +57,11 @@ class AunPlugin {
|
|
|
53
57
|
}
|
|
54
58
|
identity = {
|
|
55
59
|
list: async () => {
|
|
56
|
-
|
|
57
|
-
const local = this.listStoreAids();
|
|
60
|
+
const connected = [...this.clients.keys()];
|
|
58
61
|
return {
|
|
59
|
-
evolcore:
|
|
60
|
-
muAgentBridge:
|
|
62
|
+
evolcore: connected.filter((aid) => !this.identities.has(aid) && !this.legacyCreatedAids.has(aid)).sort(),
|
|
63
|
+
muAgentBridge: connected.filter((aid) => this.identities.has(aid) || this.legacyCreatedAids.has(aid)).sort(),
|
|
61
64
|
localMuAgentBridge: [...this.identities].filter((aid) => !this.clients.has(aid)).sort(),
|
|
62
|
-
local,
|
|
63
65
|
};
|
|
64
66
|
},
|
|
65
67
|
create: async (aid, owner) => {
|
|
@@ -94,7 +96,7 @@ class AunPlugin {
|
|
|
94
96
|
this.creating = false;
|
|
95
97
|
}
|
|
96
98
|
},
|
|
97
|
-
bind: async (pluginId, aid,
|
|
99
|
+
bind: async (pluginId, aid, port) => {
|
|
98
100
|
if (pluginId === "aun" || pluginId === "abweb")
|
|
99
101
|
throw new Error("只能关联 Agent 插件");
|
|
100
102
|
const previous = this.bindings;
|
|
@@ -107,7 +109,7 @@ class AunPlugin {
|
|
|
107
109
|
throw new Error("AID 格式无效");
|
|
108
110
|
if (this.context?.pluginStatus(pluginId) !== "ready")
|
|
109
111
|
throw new Error("目标 Agent 插件未启动");
|
|
110
|
-
if (this.identities.has(aid)) {
|
|
112
|
+
if (this.identities.has(aid) || this.legacyCreatedAids.has(aid)) {
|
|
111
113
|
if (!this.clients.has(aid))
|
|
112
114
|
await this.connectAid(aid);
|
|
113
115
|
if (!this.clients.has(aid))
|
|
@@ -120,20 +122,15 @@ class AunPlugin {
|
|
|
120
122
|
this.bindings[aid] = pluginId;
|
|
121
123
|
}
|
|
122
124
|
else {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (!loaded.ok || !loaded.data)
|
|
126
|
-
throw new Error("AID 不在本地密钥库中,无法关联");
|
|
127
|
-
await this.connectAid(aid);
|
|
128
|
-
if (!this.clients.has(aid))
|
|
125
|
+
const connected = await this.identity.list();
|
|
126
|
+
if (![...connected.evolcore, ...connected.muAgentBridge].includes(aid))
|
|
129
127
|
throw new Error("AID 当前未连接");
|
|
128
|
+
await (0, evolcore_1.configureAidForPlugin)(pluginId, aid, port);
|
|
130
129
|
for (const [identity, target] of Object.entries(this.bindings))
|
|
131
130
|
if (target === pluginId) {
|
|
132
131
|
delete this.bindings[identity];
|
|
133
132
|
delete this.bindingTimes[identity];
|
|
134
133
|
}
|
|
135
|
-
this.bindings[aid] = pluginId;
|
|
136
|
-
this.identities.add(aid);
|
|
137
134
|
}
|
|
138
135
|
}
|
|
139
136
|
else {
|
|
@@ -167,6 +164,18 @@ class AunPlugin {
|
|
|
167
164
|
async activate(context) {
|
|
168
165
|
this.context = context;
|
|
169
166
|
this.config = { ...context.config };
|
|
167
|
+
this.legacyCreatedAids.clear();
|
|
168
|
+
try {
|
|
169
|
+
const created = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(context.dataDir, "..", "created-aids.json"), "utf8"));
|
|
170
|
+
if (Array.isArray(created))
|
|
171
|
+
for (const aid of created)
|
|
172
|
+
if (typeof aid === "string" && aidPattern.test(aid))
|
|
173
|
+
this.legacyCreatedAids.add(aid);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (error.code !== "ENOENT")
|
|
177
|
+
context.logger.warn("读取旧版身份创建记录失败", { error: safeError(error) });
|
|
178
|
+
}
|
|
170
179
|
for (const key of ["aid", "owner_aid", "aun_path", "encryption_seed", "root_ca_path", "allow_from", "agent_plugin"]) {
|
|
171
180
|
if (this.config[key] !== undefined && typeof this.config[key] !== "string")
|
|
172
181
|
throw new Error(`${key} 必须是字符串`);
|
|
@@ -207,6 +216,10 @@ class AunPlugin {
|
|
|
207
216
|
this.identities.add(this.aid);
|
|
208
217
|
for (const aid of this.identities)
|
|
209
218
|
await this.connectAid(aid);
|
|
219
|
+
// AUN 插件直接连接本地密钥库中的所有 AID,不依赖 ec 进程或 CLI。
|
|
220
|
+
for (const aid of this.listStoreAids())
|
|
221
|
+
if (!this.clients.has(aid))
|
|
222
|
+
await this.connectAid(aid);
|
|
210
223
|
}
|
|
211
224
|
async connectAid(aid) {
|
|
212
225
|
try {
|
|
@@ -214,12 +227,14 @@ class AunPlugin {
|
|
|
214
227
|
if (!loaded.ok || !loaded.data)
|
|
215
228
|
throw new Error(loaded.error?.message ?? "本地密钥库中不存在该 AID");
|
|
216
229
|
const client = new this.sdk.AUNClient(loaded.data.aid);
|
|
217
|
-
const subscription =
|
|
230
|
+
const subscription = this.identities.has(aid) || this.legacyCreatedAids.has(aid)
|
|
231
|
+
? client.on("message.received", (payload) => this.onMessage(payload, aid))
|
|
232
|
+
: undefined;
|
|
218
233
|
try {
|
|
219
234
|
await client.connect();
|
|
220
235
|
}
|
|
221
236
|
catch (error) {
|
|
222
|
-
subscription
|
|
237
|
+
subscription?.unsubscribe();
|
|
223
238
|
await client.close();
|
|
224
239
|
throw error;
|
|
225
240
|
}
|
|
@@ -236,7 +251,7 @@ class AunPlugin {
|
|
|
236
251
|
async deactivate(_reason) {
|
|
237
252
|
this.status = "degraded";
|
|
238
253
|
for (const { client, subscription } of this.clients.values()) {
|
|
239
|
-
subscription
|
|
254
|
+
subscription?.unsubscribe();
|
|
240
255
|
await client.close();
|
|
241
256
|
}
|
|
242
257
|
this.clients.clear();
|
|
@@ -253,10 +268,13 @@ class AunPlugin {
|
|
|
253
268
|
async handle(_request) { throw new Error("AUN 是入站通道插件"); }
|
|
254
269
|
path() {
|
|
255
270
|
const configured = this.config.aun_path;
|
|
256
|
-
|
|
271
|
+
if (typeof configured === "string" && configured.trim())
|
|
272
|
+
return configured;
|
|
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"));
|
|
257
274
|
}
|
|
258
275
|
newStore() {
|
|
259
|
-
|
|
276
|
+
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");
|
|
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 });
|
|
260
278
|
}
|
|
261
279
|
createAid = async (request, response) => {
|
|
262
280
|
let input;
|
|
@@ -301,8 +319,8 @@ class AunPlugin {
|
|
|
301
319
|
}
|
|
302
320
|
listIdentities = async (_request, response) => {
|
|
303
321
|
const groups = await this.identity.list();
|
|
304
|
-
const connected = new Set([...groups.evolcore, ...groups.muAgentBridge
|
|
305
|
-
const localAids = (
|
|
322
|
+
const connected = new Set([...groups.evolcore, ...groups.muAgentBridge]);
|
|
323
|
+
const localAids = this.listStoreAids().filter((aid) => !connected.has(aid));
|
|
306
324
|
this.json(response, 200, { groups, localAids, bindings: this.bindings, bindingTimes: this.bindingTimes });
|
|
307
325
|
};
|
|
308
326
|
saveSettings = async (request, response) => {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
configForm.elements.encryption_seed.value = "";
|
|
32
32
|
}
|
|
33
33
|
list.replaceChildren();
|
|
34
|
-
const entries = [["本工程 · 已连接", identities.groups.muAgentBridge || []], ["
|
|
34
|
+
const entries = [["本工程 · 已连接", identities.groups.muAgentBridge || []], ["EvolCore · 已连接", identities.groups.evolcore || []]]
|
|
35
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 })));
|
|
36
36
|
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
37
|
for (const { aid, label, bound } of entries) {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
select.value = bound; select.onchange = () => { if (select.value) void bind(aid, select.value); };
|
|
43
43
|
cell.append(select); row.append(cell); list.append(row);
|
|
44
44
|
}
|
|
45
|
-
if (!list.children.length) { const row = document.createElement("tr"); const cell = document.createElement("td"); cell.colSpan = 4; cell.textContent = "
|
|
46
|
-
show(`${(identities.groups.
|
|
45
|
+
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`);
|
|
47
47
|
} catch (error) { show(String(error), true); }
|
|
48
48
|
finally { loading = false; }
|
|
49
49
|
}
|
|
@@ -40,7 +40,14 @@ class QwenCdpClient {
|
|
|
40
40
|
if (this.socket)
|
|
41
41
|
return;
|
|
42
42
|
const fetchImpl = this.options.fetchImpl ?? fetch;
|
|
43
|
-
|
|
43
|
+
let response;
|
|
44
|
+
try {
|
|
45
|
+
response = await fetchImpl(`http://127.0.0.1:${this.options.port}/json`);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const code = error?.cause?.code ?? String(error);
|
|
49
|
+
throw new Error(`无法连接千问办公 CDP 端口 ${this.options.port}(请先以 --remote-debugging-port=${this.options.port} 启动千问办公客户端): ${code}`);
|
|
50
|
+
}
|
|
44
51
|
if (!response.ok)
|
|
45
52
|
throw new Error(`CDP /json HTTP ${response.status}`);
|
|
46
53
|
const targets = await response.json();
|
|
@@ -14,7 +14,7 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
14
14
|
const node = () => ({ children: [], elements: new Proxy({}, { get: () => ({ value: "", replaceChildren() { } }) }), append(...items) { this.children.push(...items); }, replaceChildren(...items) { this.children = items; }, setAttribute() { } });
|
|
15
15
|
const elements = new Map();
|
|
16
16
|
const identities = {
|
|
17
|
-
groups: { muAgentBridge: ["offline-order.agentid.cn", "old.agentid.cn", "new.agentid.cn", "unknown.agentid.cn"],
|
|
17
|
+
groups: { muAgentBridge: ["offline-order.agentid.cn", "old.agentid.cn", "new.agentid.cn", "unknown.agentid.cn"], evolcore: ["external.agentid.cn"] },
|
|
18
18
|
bindings: { "old.agentid.cn": "dsh", "new.agentid.cn": "doubao", "unknown.agentid.cn": "workbuddy" },
|
|
19
19
|
bindingTimes: { "old.agentid.cn": "2026-10-09T00:00:00.000Z", "new.agentid.cn": "2026-10-10T00:00:00.000Z", "external.agentid.cn": "2026-10-11T00:00:00.000Z" },
|
|
20
20
|
};
|
|
@@ -28,12 +28,57 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
28
28
|
await new Promise((resolve) => setImmediate(resolve));
|
|
29
29
|
strict_1.default.deepEqual(elements.get("#identities").children.map((row) => row.children[0].textContent), ["new.agentid.cn", "old.agentid.cn", "unknown.agentid.cn", "external.agentid.cn", "offline-order.agentid.cn"]);
|
|
30
30
|
});
|
|
31
|
+
(0, node_test_1.default)("AUN 插件直接从本地 keystore 连接 AID,不调用 EvolCore CLI", async () => {
|
|
32
|
+
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "aun-local-connect-"));
|
|
33
|
+
const dataDir = (0, node_path_1.join)(root, "state", "aun");
|
|
34
|
+
const aunPath = (0, node_path_1.join)(root, "evolcore");
|
|
35
|
+
const before = process.env.EVOLCORE_HOME;
|
|
36
|
+
const connects = [];
|
|
37
|
+
const subscriptions = [];
|
|
38
|
+
const sdk = {
|
|
39
|
+
AIDStore: class {
|
|
40
|
+
list() { return { ok: true, data: { identities: [{ aid: "existing.agentid.cn" }] } }; }
|
|
41
|
+
load(aid) { return { ok: true, data: { aid } }; }
|
|
42
|
+
close() { }
|
|
43
|
+
},
|
|
44
|
+
AUNClient: class {
|
|
45
|
+
aid;
|
|
46
|
+
constructor(aid) {
|
|
47
|
+
this.aid = aid;
|
|
48
|
+
}
|
|
49
|
+
on() { subscriptions.push(this.aid); return { unsubscribe() { } }; }
|
|
50
|
+
async connect() { connects.push(this.aid); }
|
|
51
|
+
async close() { }
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const plugin = new aun_1.AunPlugin({ sdk, ingress: { publish: async () => undefined } });
|
|
55
|
+
try {
|
|
56
|
+
process.env.EVOLCORE_HOME = aunPath;
|
|
57
|
+
await plugin.activate({ dataDir, config: {}, logger: { info() { }, warn() { }, error() { } }, callPlugin: async () => ({ text: "" }), pluginStatus: () => "ready", http: { register() { }, unregister() { } } });
|
|
58
|
+
strict_1.default.deepEqual(connects, ["existing.agentid.cn"]);
|
|
59
|
+
strict_1.default.deepEqual(subscriptions, []);
|
|
60
|
+
strict_1.default.deepEqual(await plugin.identity.list(), { evolcore: ["existing.agentid.cn"], muAgentBridge: [], localMuAgentBridge: [] });
|
|
61
|
+
await plugin.deactivate("stop");
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (before === undefined)
|
|
65
|
+
delete process.env.EVOLCORE_HOME;
|
|
66
|
+
else
|
|
67
|
+
process.env.EVOLCORE_HOME = before;
|
|
68
|
+
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
31
71
|
(0, node_test_1.default)("AUN 设置页及身份接口由插件注册并随停用注销", async () => {
|
|
32
72
|
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "aun-management-"));
|
|
33
73
|
const routes = new Map();
|
|
34
74
|
const sdk = { AIDStore: class {
|
|
35
75
|
list() { return { ok: true, data: { identities: [{ aid: "external.agentid.cn" }] } }; }
|
|
76
|
+
load(aid) { return { ok: true, data: { aid } }; }
|
|
36
77
|
close() { }
|
|
78
|
+
}, AUNClient: class {
|
|
79
|
+
on() { throw new Error("不应订阅 EvolCore 身份"); }
|
|
80
|
+
async connect() { }
|
|
81
|
+
async close() { }
|
|
37
82
|
} };
|
|
38
83
|
const plugin = new aun_1.AunPlugin({ sdk, ingress: { publish: async () => undefined } });
|
|
39
84
|
try {
|
|
@@ -49,8 +94,7 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
49
94
|
strict_1.default.equal(response.statusCode, 200);
|
|
50
95
|
strict_1.default.match(String(response.body), /AUN 身份/);
|
|
51
96
|
await routes.get("GET /api/plugins/aun/identities")({}, response);
|
|
52
|
-
strict_1.default.deepEqual(JSON.parse(response.body).groups.
|
|
53
|
-
strict_1.default.deepEqual(JSON.parse(response.body).groups.evolcore, []);
|
|
97
|
+
strict_1.default.deepEqual(JSON.parse(response.body).groups.evolcore, ["external.agentid.cn"]);
|
|
54
98
|
strict_1.default.deepEqual(JSON.parse(response.body).bindingTimes, {});
|
|
55
99
|
await routes.get("POST /api/plugins/aun/settings")((async function* () { yield Buffer.from(JSON.stringify({ agent_plugin: "dsh", allow_from: "peer.agentid.cn", aun_path: "" })); })(), response);
|
|
56
100
|
const saved = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(root, "config.json"), "utf8"));
|
|
@@ -64,7 +108,7 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
64
108
|
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
65
109
|
}
|
|
66
110
|
});
|
|
67
|
-
(0, node_test_1.default)("
|
|
111
|
+
(0, node_test_1.default)("旧版创建身份按来源归入本工程且只显示已连接身份", async () => {
|
|
68
112
|
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "aun-origin-"));
|
|
69
113
|
const dataDir = (0, node_path_1.join)(root, "aun");
|
|
70
114
|
await (0, promises_1.mkdir)(dataDir);
|
|
@@ -74,11 +118,15 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
74
118
|
list() { return { ok: true, data: { identities: storeIds.map((aid) => ({ aid })) } }; }
|
|
75
119
|
load(aid) { return { ok: true, data: { aid } }; }
|
|
76
120
|
close() { }
|
|
121
|
+
}, AUNClient: class {
|
|
122
|
+
on() { return { unsubscribe() { } }; }
|
|
123
|
+
async connect() { }
|
|
124
|
+
async close() { }
|
|
77
125
|
} };
|
|
78
126
|
const plugin = new aun_1.AunPlugin({ sdk, ingress: { publish: async () => undefined } });
|
|
79
127
|
try {
|
|
80
128
|
await plugin.activate({ dataDir, config: {}, logger: { info() { }, warn() { }, error() { } }, callPlugin: async () => ({ text: "" }), pluginStatus: () => "ready", http: { register() { }, unregister() { } } });
|
|
81
|
-
strict_1.default.deepEqual(await plugin.identity.list(), { evolcore: [], muAgentBridge: [
|
|
129
|
+
strict_1.default.deepEqual(await plugin.identity.list(), { evolcore: ["external.agentid.cn"], muAgentBridge: ["doubao-lih.agentid.cn", "dshlihui.agentid.cn"], localMuAgentBridge: [] });
|
|
82
130
|
await plugin.deactivate("stop");
|
|
83
131
|
}
|
|
84
132
|
finally {
|
|
@@ -96,7 +144,7 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
96
144
|
registered = [];
|
|
97
145
|
async register(input) { calls.push(`register:${input.aid}:${input.owner}`); this.registered.push(input.aid); return registration; }
|
|
98
146
|
load(aid) { return !loadOk || aid === loadFailAid ? { ok: false, error: { message: "本地身份不存在" } } : { ok: true, data: { aid } }; }
|
|
99
|
-
list() { return { ok: true, data: { identities: this.registered.
|
|
147
|
+
list() { return { ok: true, data: { identities: this.registered.map((aid) => ({ aid })) } }; }
|
|
100
148
|
close() { calls.push("store.close"); }
|
|
101
149
|
},
|
|
102
150
|
AUNClient: class {
|
|
@@ -126,14 +174,10 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
126
174
|
await route.handler(second, response);
|
|
127
175
|
strict_1.default.equal(response.statusCode, 201);
|
|
128
176
|
strict_1.default.equal(clients.length, 2);
|
|
129
|
-
//
|
|
177
|
+
// 本工程身份由 AUN 插件直接关联和收发。
|
|
130
178
|
await plugin.identity.bind("dsh", "bridge.agentid.pub", 26107);
|
|
131
179
|
const boundAt = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(root, "config.json"), "utf8")).binding_times["bridge.agentid.pub"];
|
|
132
180
|
strict_1.default.ok(Number.isFinite(Date.parse(boundAt)));
|
|
133
|
-
// 本地密钥库存在但尚未连接的 AID 也可以关联(会先建立连接)
|
|
134
|
-
await plugin.identity.bind("doubao", "offline-store.agentid.cn", 26107);
|
|
135
|
-
strict_1.default.ok(JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(root, "config.json"), "utf8")).bindings["offline-store.agentid.cn"]);
|
|
136
|
-
strict_1.default.equal(clients.length, 3);
|
|
137
181
|
clients[0].emit({ from: "peer.agentid.pub", message_id: "m1", payload: { text: "你好" } });
|
|
138
182
|
strict_1.default.equal(received[0].agentPlugin, "dsh");
|
|
139
183
|
await received[0].reply("收到");
|
|
@@ -144,12 +188,12 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
144
188
|
clients[0].emit({ from: "peer.agentid.pub", message_id: "m1", payload: { text: "重复消息" } });
|
|
145
189
|
strict_1.default.equal(received.length, 3);
|
|
146
190
|
await plugin.deactivate("stop");
|
|
147
|
-
strict_1.default.equal(calls.filter((call) => call === "client.close").length,
|
|
191
|
+
strict_1.default.equal(calls.filter((call) => call === "client.close").length, 2);
|
|
148
192
|
strict_1.default.equal(calls.at(-1), "store.close");
|
|
149
193
|
await plugin.activate({ dataDir: root, config: JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(root, "config.json"), "utf8")), logger: { info() { }, warn() { }, error() { } }, callPlugin: async () => ({ text: "" }), pluginStatus: () => "ready", http: { register() { }, unregister() { } } });
|
|
150
194
|
const health = await plugin.health();
|
|
151
|
-
strict_1.default.deepEqual(health.details?.aids, ["bridge.agentid.pub", "second.agentid.pub"
|
|
152
|
-
strict_1.default.deepEqual(health.details?.bindings, { "bridge.agentid.pub": "dsh"
|
|
195
|
+
strict_1.default.deepEqual(health.details?.aids, ["bridge.agentid.pub", "second.agentid.pub"]);
|
|
196
|
+
strict_1.default.deepEqual(health.details?.bindings, { "bridge.agentid.pub": "dsh" });
|
|
153
197
|
await routes.find((entry) => entry.path === "/api/plugins/aun/identities").handler({}, response);
|
|
154
198
|
strict_1.default.equal(response.body.bindingTimes["bridge.agentid.pub"], boundAt);
|
|
155
199
|
await strict_1.default.rejects(plugin.identity.bind("dsh", "bad", 26107), /AID 格式无效/);
|
|
@@ -163,9 +207,9 @@ const aun_1 = require("../src-ts/plugins/aun");
|
|
|
163
207
|
registration = { ok: true, data: {} };
|
|
164
208
|
loadOk = false;
|
|
165
209
|
await strict_1.default.rejects(plugin.identity.create("missing.agentid.pub", "owner.agentid.pub"), /本地身份不存在/);
|
|
166
|
-
//
|
|
210
|
+
// 断开的 AID 不能关联。
|
|
167
211
|
loadFailAid = "not-in-store.agentid.cn";
|
|
168
|
-
await strict_1.default.rejects(plugin.identity.bind("dsh", "not-in-store.agentid.cn", 26107),
|
|
212
|
+
await strict_1.default.rejects(plugin.identity.bind("dsh", "not-in-store.agentid.cn", 26107), /当前未连接/);
|
|
169
213
|
loadFailAid = "";
|
|
170
214
|
await plugin.deactivate("stop");
|
|
171
215
|
}
|