mu-agent-bridge 1.0.20 → 1.0.21

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.
@@ -5,7 +5,7 @@ const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
6
  const MANIFEST = {
7
7
  id: "abweb",
8
- version: "1.0.5",
8
+ version: "1.0.6",
9
9
  displayName: "Agent Bridge Web",
10
10
  entry: "dist/index.js",
11
11
  apiVersion: "1",
@@ -145,7 +145,6 @@
145
145
  void loadCatalog().catch((cause) => { catalogNode.textContent = `远程插件目录暂时不可用:${cause instanceof Error ? cause.message : String(cause)}`; });
146
146
  }
147
147
  catch (cause) {
148
- node("#access-panel").hidden = false;
149
148
  error(cause instanceof Error ? cause.message : String(cause));
150
149
  }
151
150
  finally {
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const strict_1 = __importDefault(require("node:assert/strict"));
7
+ const node_test_1 = __importDefault(require("node:test"));
8
+ const promises_1 = require("node:fs/promises");
9
+ const node_vm_1 = require("node:vm");
10
+ class Element {
11
+ hidden = true;
12
+ value = "";
13
+ textContent = "";
14
+ options = [];
15
+ selectedIndex = 0;
16
+ onclick;
17
+ replaceChildren() { }
18
+ append() { }
19
+ setAttribute() { }
20
+ }
21
+ (0, node_test_1.default)("ABWeb缓存登录在刷新和后台暂时不可用时保留,到期才重新配对", async () => {
22
+ const script = await (0, promises_1.readFile)("src-ts/plugins/abweb/public/app.js", "utf8");
23
+ let now = Date.now();
24
+ const storage = new Map();
25
+ let unavailable = false;
26
+ const calls = [];
27
+ const open = async () => {
28
+ const nodes = new Map();
29
+ const node = (selector) => { if (!nodes.has(selector))
30
+ nodes.set(selector, new Element()); return nodes.get(selector); };
31
+ (0, node_vm_1.runInNewContext)(script, {
32
+ document: { querySelector: node, createElement: () => new Element(), hidden: false },
33
+ localStorage: { getItem: (key) => storage.get(key) ?? null, setItem: (key, value) => storage.set(key, value), removeItem: (key) => storage.delete(key) },
34
+ Date: class extends Date {
35
+ static now() { return now; }
36
+ },
37
+ setInterval() { }, confirm: () => false,
38
+ fetch: async (path, options) => {
39
+ calls.push({ path, token: options.headers.authorization });
40
+ if (unavailable)
41
+ throw new Error("后台正在重启");
42
+ if (path === "/api/pair")
43
+ return { ok: true, status: 200, json: async () => ({ token: "测试会话", expiresAt: now + 86400000 }) };
44
+ const authorized = options.headers.authorization === "Bearer 测试会话" && Number(storage.get("mab-login-expires-at")) > now;
45
+ return { ok: authorized, status: authorized ? 200 : 401, json: async () => ({ plugins: [], messages: [], sessions: [], mode: "auto-install" }) };
46
+ },
47
+ });
48
+ await new Promise(resolve => setImmediate(resolve));
49
+ return node;
50
+ };
51
+ const first = await open();
52
+ strict_1.default.equal(first("#access-panel").hidden, false);
53
+ first("#pair-code").value = "123456";
54
+ first("#pair-button").onclick();
55
+ await new Promise(resolve => setImmediate(resolve));
56
+ strict_1.default.equal(first("#access-panel").hidden, true);
57
+ const expiry = storage.get("mab-login-expires-at");
58
+ now += 23 * 3600000;
59
+ const refreshed = await open();
60
+ strict_1.default.equal(refreshed("#access-panel").hidden, true);
61
+ unavailable = true;
62
+ const restarting = await open();
63
+ strict_1.default.equal(restarting("#access-panel").hidden, true, "后台暂时不可用不能提示重新配对");
64
+ strict_1.default.equal(storage.get("mab-login-token"), "测试会话");
65
+ unavailable = false;
66
+ strict_1.default.equal((await open())("#access-panel").hidden, true);
67
+ strict_1.default.equal(storage.get("mab-login-expires-at"), expiry);
68
+ now = Number(expiry);
69
+ strict_1.default.equal((await open())("#access-panel").hidden, false);
70
+ strict_1.default.equal(storage.has("mab-login-token"), false);
71
+ strict_1.default.equal(calls.filter(call => call.path === "/api/pair").length, 1);
72
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mu-agent-bridge",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "将 AUN Agent 连接到本地桌面 AI 客户端的插件平台。",
5
5
  "main": "dist/src-ts/cli.js",
6
6
  "bin": {
@@ -5,7 +5,7 @@ const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
6
  const MANIFEST = {
7
7
  id: "abweb",
8
- version: "1.0.5",
8
+ version: "1.0.6",
9
9
  displayName: "Agent Bridge Web",
10
10
  entry: "dist/index.js",
11
11
  apiVersion: "1",
@@ -145,7 +145,6 @@
145
145
  void loadCatalog().catch((cause) => { catalogNode.textContent = `远程插件目录暂时不可用:${cause instanceof Error ? cause.message : String(cause)}`; });
146
146
  }
147
147
  catch (cause) {
148
- node("#access-panel").hidden = false;
149
148
  error(cause instanceof Error ? cause.message : String(cause));
150
149
  }
151
150
  finally {
@@ -101,7 +101,7 @@
101
101
  sessionTable.append(row);
102
102
  }
103
103
  if (refreshCatalog) void loadCatalog().catch((cause) => { catalogNode.textContent = `远程插件目录暂时不可用:${cause instanceof Error ? cause.message : String(cause)}`; });
104
- } catch (cause) { node<HTMLElement>("#access-panel").hidden = false; error(cause instanceof Error ? cause.message : String(cause)); }
104
+ } catch (cause) { error(cause instanceof Error ? cause.message : String(cause)); }
105
105
  finally { loading = false; }
106
106
  }
107
107
  function renderChannels(items: Plugin[]): void {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "abweb",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "management",
5
5
  "displayName": "Agent Bridge Web",
6
6
  "entry": "dist/src-ts/plugins/abweb/index.js",