mu-agent-bridge 1.0.45 → 1.0.46
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/dist/src-ts/cli.js +19 -5
- package/dist/tests-ts/aun-plugin.test.js +33 -0
- package/package.json +1 -1
package/dist/src-ts/cli.js
CHANGED
|
@@ -173,13 +173,23 @@ async function startDaemon() {
|
|
|
173
173
|
child.unref();
|
|
174
174
|
}
|
|
175
175
|
async function startUpdatedDaemon() {
|
|
176
|
-
|
|
176
|
+
let child;
|
|
177
|
+
const env = { ...process.env, AGENT_BRIDGE_CORE_UPDATE_CHILD: "1" };
|
|
178
|
+
if (process.platform === "win32" && !env.AGENT_BRIDGE_TOKEN) {
|
|
179
|
+
try {
|
|
180
|
+
env.AGENT_BRIDGE_TOKEN = (await (0, promises_1.readFile)((0, node_path_1.resolve)(process.env.USERPROFILE ?? (0, node_os_1.homedir)(), ".mab", "token.txt"), "utf8")).trim();
|
|
181
|
+
env.AGENT_BRIDGE_HOST ??= "0.0.0.0";
|
|
182
|
+
env.AGENT_BRIDGE_PORT ??= "26107";
|
|
183
|
+
}
|
|
184
|
+
catch { /* 当前 Windows 安装未使用 mab 启动器 */ }
|
|
185
|
+
}
|
|
186
|
+
child = (0, node_child_process_1.spawn)(process.execPath, [(0, node_path_1.resolve)(__dirname, "cli.js"), "start"], { detached: true, stdio: "ignore", windowsHide: true, env });
|
|
177
187
|
let launchFailed = false;
|
|
178
|
-
child
|
|
179
|
-
child
|
|
188
|
+
child?.once("error", () => { launchFailed = true; });
|
|
189
|
+
child?.unref();
|
|
180
190
|
const healthy = async () => {
|
|
181
191
|
for (let attempt = 0; attempt < 30; attempt++) {
|
|
182
|
-
if (launchFailed || child.exitCode !== null || child.signalCode !== null)
|
|
192
|
+
if (launchFailed || child && (child.exitCode !== null || child.signalCode !== null))
|
|
183
193
|
return false;
|
|
184
194
|
const address = await daemonAddress();
|
|
185
195
|
try {
|
|
@@ -195,7 +205,7 @@ async function startUpdatedDaemon() {
|
|
|
195
205
|
}
|
|
196
206
|
return false;
|
|
197
207
|
};
|
|
198
|
-
return {
|
|
208
|
+
return { healthy };
|
|
199
209
|
}
|
|
200
210
|
async function stop() {
|
|
201
211
|
await stopDaemon();
|
|
@@ -371,6 +381,10 @@ async function main() {
|
|
|
371
381
|
if (args[0] === "--self-test")
|
|
372
382
|
return selfTest(args[1] ?? "hi");
|
|
373
383
|
if (args[0] === "--serve" || args[0] === "start") {
|
|
384
|
+
if (process.env.AGENT_BRIDGE_CORE_UPDATE_CHILD === "1") {
|
|
385
|
+
delete process.env.AGENT_BRIDGE_CORE_UPDATE_CHILD;
|
|
386
|
+
return serve();
|
|
387
|
+
}
|
|
374
388
|
const logs = new log_store_1.LogStore((0, node_path_1.resolve)(stateDirectory(), "logs"));
|
|
375
389
|
let launched;
|
|
376
390
|
const updated = await (0, core_updater_1.updateCoreAtStartup)({
|
|
@@ -74,6 +74,37 @@ async function runAunCommand(routes, response, argv) {
|
|
|
74
74
|
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
+
(0, node_test_1.default)("AUN 绑定目标未就绪时不调用插件且不改动其它 AID", async () => {
|
|
78
|
+
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "aun-unready-binding-"));
|
|
79
|
+
let receive;
|
|
80
|
+
const sent = [];
|
|
81
|
+
let published = false;
|
|
82
|
+
const sdk = {
|
|
83
|
+
AIDStore: class {
|
|
84
|
+
list() { return { ok: true, data: { identities: [{ aid: "selected.agentid.cn" }, { aid: "other.agentid.cn" }] } }; }
|
|
85
|
+
load(aid) { return { ok: true, data: { aid } }; }
|
|
86
|
+
close() { }
|
|
87
|
+
},
|
|
88
|
+
AUNClient: class {
|
|
89
|
+
async connect() { }
|
|
90
|
+
async close() { }
|
|
91
|
+
on(_event, handler) { receive = handler; return { unsubscribe() { } }; }
|
|
92
|
+
async call(_method, params) { sent.push(params); }
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const plugin = new aun_1.AunPlugin({ sdk, ingress: { publish: async () => { published = true; } } });
|
|
96
|
+
try {
|
|
97
|
+
await plugin.activate({ dataDir: root, config: { bindings: { "selected.agentid.cn": "qwenwork", "other.agentid.cn": "workbuddy" } }, logger: { info() { }, warn() { }, error() { } }, callPlugin: async () => ({ text: "" }), pluginStatus: () => "discovered", http: { register() { }, unregister() { } } });
|
|
98
|
+
await receive({ from: "peer.agentid.cn", message_id: "unready-1", payload: { text: "不要转发" } });
|
|
99
|
+
strict_1.default.equal(published, false);
|
|
100
|
+
strict_1.default.deepEqual(sent, [{ to: "peer.agentid.cn", payload: { type: "text", text: "绑定的 Agent 插件 qwenwork 尚未就绪,消息未转发;AID 关联保持不变。" }, encrypt: true }]);
|
|
101
|
+
strict_1.default.deepEqual((await plugin.health()).details?.bindings, { "selected.agentid.cn": "qwenwork", "other.agentid.cn": "workbuddy" });
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await plugin.deactivate("stop");
|
|
105
|
+
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
77
108
|
async function withAunAttachmentPlugin(run, publish, config = { allow_from: "peer.agentid.cn", bindings: { "local.agentid.cn": "qwenwork" } }) {
|
|
78
109
|
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "aun-attachments-plugin-"));
|
|
79
110
|
let handler;
|
|
@@ -405,6 +436,8 @@ async function withAunAttachmentPlugin(run, publish, config = { allow_from: "pee
|
|
|
405
436
|
const plugin = new aun_1.AunPlugin({ sdk, ingress: { publish: async () => undefined } });
|
|
406
437
|
try {
|
|
407
438
|
await plugin.activate({ dataDir: root, config: { bindings: { [aids[0]]: "qwenwork", [aids[1]]: "qwenwork" }, binding_times: { [aids[0]]: "old-1", [aids[1]]: "old-2" } }, logger: { info() { }, warn() { }, error() { } }, callPlugin: async () => ({ text: "" }), pluginStatus: () => "ready", http: { register() { }, unregister() { } } });
|
|
439
|
+
await plugin.identity.bind("qwenwork", aids[0], 26107);
|
|
440
|
+
strict_1.default.deepEqual((await plugin.health()).details?.bindings, { [aids[0]]: "qwenwork", [aids[1]]: "qwenwork" });
|
|
408
441
|
await plugin.identity.bind("workbuddy", aids[0], 26107);
|
|
409
442
|
strict_1.default.deepEqual((await plugin.health()).details?.bindings, { [aids[0]]: "workbuddy", [aids[1]]: "qwenwork" });
|
|
410
443
|
await plugin.identity.unbind("workbuddy", aids[0], 26107);
|