@glodon-aiot/bot-client-sdk 3.26.0-alpha.21 → 3.26.0-alpha.24

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.
@@ -1,15 +1,15 @@
1
- var _ = Object.defineProperty, b = Object.defineProperties;
2
- var C = Object.getOwnPropertyDescriptors;
1
+ var P = Object.defineProperty, S = Object.defineProperties;
2
+ var b = Object.getOwnPropertyDescriptors;
3
3
  var k = Object.getOwnPropertySymbols;
4
- var R = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable;
5
- var p = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e) => {
4
+ var H = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
5
+ var p = (r, e, t) => e in r ? P(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e) => {
6
6
  for (var t in e || (e = {}))
7
- R.call(e, t) && p(r, t, e[t]);
7
+ H.call(e, t) && p(r, t, e[t]);
8
8
  if (k)
9
9
  for (var t of k(e))
10
- H.call(e, t) && p(r, t, e[t]);
10
+ R.call(e, t) && p(r, t, e[t]);
11
11
  return r;
12
- }, P = (r, e) => b(r, C(e));
12
+ }, C = (r, e) => S(r, b(e));
13
13
  var s = (r, e, t) => (p(r, typeof e != "symbol" ? e + "" : e, t), t);
14
14
  var d = (r, e, t) => new Promise((i, n) => {
15
15
  var a = (o) => {
@@ -28,21 +28,22 @@ var d = (r, e, t) => new Promise((i, n) => {
28
28
  l((t = t.apply(r, e)).next());
29
29
  });
30
30
  import T from "../../EventBus.mjs";
31
- import { FileSystemAccessAdapter as S } from "../adapters/FileSystemAccessAdapter.mjs";
32
- import { FileSnapshotAdapter as F } from "../adapters/FileSnapshotAdapter.mjs";
33
- import { getNativeDirectoryPicker as D } from "../adapters/fsaTypes.mjs";
34
- import { LOCAL_FILES_FUNCTION_CODES as W } from "../constants.mjs";
35
- import { getDownloadUrlAllowlist as L } from "../security/downloadUrlPolicy.mjs";
36
- import { SensitiveFilePolicy as N } from "../security/sensitiveFiles.mjs";
37
- import { resolveLimits as E } from "../limits.mjs";
38
- import { createDefaultSessionFileTransfer as I } from "../transfer/SessionFileTransfer.mjs";
39
- import { createMemoryStore as q } from "./handleStore.mjs";
40
- import { watchDirectoryHandle as U } from "./watchDirectory.mjs";
41
- import { WorkspaceFiles as j } from "./WorkspaceFiles.mjs";
31
+ import { FileSystemAccessAdapter as _ } from "../adapters/FileSystemAccessAdapter.mjs";
32
+ import { HostBridgeAdapter as F } from "../adapters/HostBridgeAdapter.mjs";
33
+ import { FileSnapshotAdapter as D } from "../adapters/FileSnapshotAdapter.mjs";
34
+ import { getNativeDirectoryPicker as W } from "../adapters/fsaTypes.mjs";
35
+ import { LOCAL_FILES_FUNCTION_CODES as L } from "../constants.mjs";
36
+ import { getDownloadUrlAllowlist as N } from "../security/downloadUrlPolicy.mjs";
37
+ import { SensitiveFilePolicy as E } from "../security/sensitiveFiles.mjs";
38
+ import { resolveLimits as I } from "../limits.mjs";
39
+ import { createDefaultSessionFileTransfer as q } from "../transfer/SessionFileTransfer.mjs";
40
+ import { createMemoryStore as U } from "./handleStore.mjs";
41
+ import { watchDirectoryHandle as j } from "./watchDirectory.mjs";
42
+ import { WorkspaceFiles as x } from "./WorkspaceFiles.mjs";
42
43
  const m = {
43
44
  mode: "readwrite"
44
45
  };
45
- function x(r) {
46
+ function K(r) {
46
47
  const e = r.replace(/\\/g, "/").trim().replace(/^\.\/+/, "").replace(/\/+$/, "");
47
48
  if (!e || e === ".")
48
49
  return "";
@@ -52,10 +53,10 @@ function x(r) {
52
53
  if (!t.some((i) => !i || i === "." || i === ".."))
53
54
  return t.join("/");
54
55
  }
55
- function K(r) {
56
+ function V(r) {
56
57
  return !!r && typeof r == "object" && r.name === "AbortError";
57
58
  }
58
- class te {
59
+ class se {
59
60
  constructor(e) {
60
61
  s(this, "applicationId");
61
62
  s(this, "limits");
@@ -79,7 +80,7 @@ class te {
79
80
  s(this, "pendingHandle", null);
80
81
  s(this, "approvalHandler");
81
82
  s(this, "activeCalls", 0);
82
- s(this, "commandRunning", !1);
83
+ s(this, "activeCommands", 0);
83
84
  s(this, "inflight", /* @__PURE__ */ new Set());
84
85
  s(this, "_ready", Promise.resolve());
85
86
  s(this, "stopWatching", () => {
@@ -89,14 +90,14 @@ class te {
89
90
  s(this, "refreshAllVisible", !1);
90
91
  /** 选择、关闭会推进它。进行中的 restore 若发现已经变了,就不再覆盖当前目录。 */
91
92
  s(this, "epoch", 0);
92
- var h, l, o, c, f, g, y, v, w, A;
93
+ var h, l, o, c, f, g, v, y, w, A;
93
94
  const t = (h = e.config) != null ? h : {};
94
- this.applicationId = e.applicationId, this.store = (l = e.store) != null ? l : q(), this.picker = e.picker === null ? void 0 : (o = e.picker) != null ? o : D(), this.limits = E(t.limits), this.sensitive = new N(t.sensitiveRulesAppend), this.downloadUrlAllowlist = L(t.downloadUrlAllowlistAppend), this.allowWorkspaceWideTextSearch = !!t.allowWorkspaceWideTextSearch, this.approvalHandler = t.onApprovalRequired;
95
- const i = (c = e.transfer) != null ? c : I(() => {
95
+ this.applicationId = e.applicationId, this.store = (l = e.store) != null ? l : U(), this.picker = e.picker === null ? void 0 : (o = e.picker) != null ? o : W(), this.limits = I(t.limits), this.sensitive = new E(t.sensitiveRulesAppend), this.downloadUrlAllowlist = N(t.downloadUrlAllowlistAppend), this.allowWorkspaceWideTextSearch = !!t.allowWorkspaceWideTextSearch, this.approvalHandler = t.onApprovalRequired;
96
+ const i = (c = e.transfer) != null ? c : q(() => {
96
97
  });
97
98
  this.transfer = {
98
99
  upload: (g = (f = t.transfer) == null ? void 0 : f.upload) != null ? g : i.upload,
99
- resolveDownload: (v = (y = t.transfer) == null ? void 0 : y.resolveDownload) != null ? v : i.resolveDownload
100
+ resolveDownload: (y = (v = t.transfer) == null ? void 0 : v.resolveDownload) != null ? y : i.resolveDownload
100
101
  };
101
102
  const n = (w = e.fetch) != null ? w : typeof fetch == "function" ? fetch : void 0;
102
103
  this.fetch = n ? n.bind(globalThis) : () => Promise.reject(new Error("fetch is not available")), this.commandRunner = e.commandRunner;
@@ -105,7 +106,7 @@ class te {
105
106
  enabled: (a == null ? void 0 : a.enabled) !== !1,
106
107
  bashModuleURL: a == null ? void 0 : a.bashModuleURL,
107
108
  pyodideIndexURL: a == null ? void 0 : a.pyodideIndexURL
108
- }, this._status = this.picker ? "none" : "unsupported", this.files = new j(this);
109
+ }, this._status = this.picker ? "none" : "unsupported", this.files = new x(this);
109
110
  }
110
111
  // -------------------------------------------------------------------------
111
112
  // 状态
@@ -147,7 +148,7 @@ class te {
147
148
  this._adapter !== e && this.files.releaseAllUrls(), this._adapter = e;
148
149
  }
149
150
  attachHandle(e) {
150
- this.cancelFilesChanged(), this.pendingHandle = e, this.replaceAdapter(new S(e)), this.setStatus("granted", e.name), this.unwatchDirectory(), this.stopWatching = U(e, (t) => this.notifyFilesChanged(t));
151
+ this.cancelFilesChanged(), this.pendingHandle = e, this.replaceAdapter(new _(e)), this.setStatus("granted", e.name), this.unwatchDirectory(), this.stopWatching = j(e, (t) => this.notifyFilesChanged(t));
151
152
  }
152
153
  // -------------------------------------------------------------------------
153
154
  // 授权
@@ -173,7 +174,7 @@ class te {
173
174
  savedAt: Date.now()
174
175
  }).catch(() => {
175
176
  }), !0), (t) => {
176
- if (K(t))
177
+ if (V(t))
177
178
  return !1;
178
179
  throw t;
179
180
  });
@@ -222,7 +223,7 @@ class te {
222
223
  /** queryPermission 仍可能是 prompt,但选择框留下的句柄其实列得出目录。 */
223
224
  canList(e) {
224
225
  return d(this, null, function* () {
225
- const t = new S(e);
226
+ const t = new _(e);
226
227
  let i;
227
228
  const n = new Promise((l) => {
228
229
  i = setTimeout(() => l(!1), 2e3);
@@ -262,7 +263,7 @@ class te {
262
263
  lastModified: c.lastModified,
263
264
  blob: c
264
265
  }));
265
- this.attachAdapter(new F(a, n), n);
266
+ this.attachAdapter(new D(a, n), n);
266
267
  }
267
268
  /** 直接挂载一个 Adapter(测试或自定义后端),视为已授权。 */
268
269
  attachAdapter(e, t = e.displayName) {
@@ -278,7 +279,7 @@ class te {
278
279
  this.refreshAllVisible = !0;
279
280
  else
280
281
  for (const t of e) {
281
- const i = x(t);
282
+ const i = K(t);
282
283
  i === void 0 ? this.refreshAllVisible = !0 : this.pendingChangePaths.add(i);
283
284
  }
284
285
  clearTimeout(this.changeTimer), this.changeTimer = setTimeout(() => this.flushFilesChanged(), 150);
@@ -345,14 +346,20 @@ class te {
345
346
  e || (e = !0, this.activeCalls--);
346
347
  };
347
348
  }
348
- /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
349
+ /**
350
+ * 占用一个浏览器运行时的命令名额。本地沙箱在时页面不设上限,并发由沙箱的 exec.maxConcurrent 决定。
351
+ * 浏览器运行时一次只放一条。
352
+ */
349
353
  acquireCommand() {
350
- if (this.commandRunning)
354
+ if (this._adapter instanceof F)
355
+ return () => {
356
+ };
357
+ if (this.activeCommands >= 1)
351
358
  return null;
352
- this.commandRunning = !0;
359
+ this.activeCommands++;
353
360
  let e = !1;
354
361
  return () => {
355
- e || (e = !0, this.commandRunning = !1);
362
+ e || (e = !0, this.activeCommands--);
356
363
  };
357
364
  }
358
365
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
@@ -365,10 +372,10 @@ class te {
365
372
  this.inflight.clear(), e.forEach((t) => t.abort());
366
373
  }
367
374
  handshake() {
368
- const e = Object.fromEntries(W.map((t) => [t, !0]));
375
+ const e = Object.fromEntries(L.map((t) => [t, !0]));
369
376
  return {
370
377
  protocolVersion: "1.0",
371
- capabilities: P(u({}, e), {
378
+ capabilities: C(u({}, e), {
372
379
  cancellation: !0,
373
380
  atomicWrite: !0
374
381
  }),
@@ -409,5 +416,5 @@ class te {
409
416
  }
410
417
  }
411
418
  export {
412
- te as LocalWorkspace
419
+ se as LocalWorkspace
413
420
  };
@@ -0,0 +1,223 @@
1
+ var T = Object.defineProperty, b = Object.defineProperties;
2
+ var O = Object.getOwnPropertyDescriptors;
3
+ var j = Object.getOwnPropertySymbols;
4
+ var J = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
+ var g = (t, o, e) => o in t ? T(t, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[o] = e, v = (t, o) => {
6
+ for (var e in o || (o = {}))
7
+ J.call(o, e) && g(t, e, o[e]);
8
+ if (j)
9
+ for (var e of j(o))
10
+ N.call(o, e) && g(t, e, o[e]);
11
+ return t;
12
+ }, E = (t, o) => b(t, O(o));
13
+ var l = (t, o, e) => new Promise((r, n) => {
14
+ var i = (s) => {
15
+ try {
16
+ a(e.next(s));
17
+ } catch (d) {
18
+ n(d);
19
+ }
20
+ }, c = (s) => {
21
+ try {
22
+ a(e.throw(s));
23
+ } catch (d) {
24
+ n(d);
25
+ }
26
+ }, a = (s) => s.done ? r(s.value) : Promise.resolve(s.value).then(i, c);
27
+ a((e = e.apply(t, o)).next());
28
+ });
29
+ const m = /* @__PURE__ */ new Map(), P = 2e4;
30
+ function k(t) {
31
+ if (typeof AbortSignal != "undefined" && typeof AbortSignal.timeout == "function") {
32
+ const o = AbortSignal.timeout(P);
33
+ if (!t)
34
+ return o;
35
+ const e = new AbortController(), r = () => e.abort();
36
+ return o.addEventListener("abort", r, {
37
+ once: !0
38
+ }), t.addEventListener("abort", r, {
39
+ once: !0
40
+ }), e.signal;
41
+ }
42
+ return t;
43
+ }
44
+ function M(t) {
45
+ return `${t.url}
46
+ ${JSON.stringify(t.headers)}`;
47
+ }
48
+ function C(t) {
49
+ const o = t.trim();
50
+ if (!o)
51
+ return {};
52
+ if (o.startsWith("{") || o.startsWith("["))
53
+ return JSON.parse(o);
54
+ const e = o.split(/\n\n/);
55
+ for (let r = e.length - 1; r >= 0; r -= 1) {
56
+ const n = e[r].split(`
57
+ `).filter((i) => i.startsWith("data:")).map((i) => i.slice(5).trim()).join(`
58
+ `);
59
+ if (n.startsWith("{") || n.startsWith("["))
60
+ return JSON.parse(n);
61
+ }
62
+ throw new Error("MCP 响应不是 JSON");
63
+ }
64
+ function I(t) {
65
+ if (typeof t == "string")
66
+ return t;
67
+ if (!t || typeof t != "object")
68
+ return JSON.stringify(t != null ? t : "");
69
+ const o = t.content;
70
+ return Array.isArray(o) ? o.map((e) => e && typeof e == "object" && typeof e.text == "string" ? e.text : JSON.stringify(e)).join(`
71
+ `) : JSON.stringify(t);
72
+ }
73
+ function A(t) {
74
+ return l(this, null, function* () {
75
+ if (!(t.headers.get("content-type") || "").includes("text/event-stream") || !t.body)
76
+ return t.text();
77
+ const e = t.body.getReader(), r = new TextDecoder();
78
+ let n = "";
79
+ try {
80
+ for (; n.length < 2e6; ) {
81
+ const {
82
+ done: i,
83
+ value: c
84
+ } = yield e.read();
85
+ if (i)
86
+ break;
87
+ n += r.decode(c, {
88
+ stream: !0
89
+ });
90
+ const a = n.split(/\n\n/).filter((s) => /^\s*data:/m.test(s));
91
+ if (a.length > 0)
92
+ return a[a.length - 1];
93
+ }
94
+ return n;
95
+ } finally {
96
+ yield e.cancel().catch(() => {
97
+ });
98
+ }
99
+ });
100
+ }
101
+ function w(t, o, e, r, n) {
102
+ return l(this, null, function* () {
103
+ const i = E(v({}, t.headers), {
104
+ "content-type": "application/json",
105
+ accept: "application/json, text/event-stream"
106
+ });
107
+ e != null && e.id && (i["mcp-session-id"] = e.id), e != null && e.protocol && (i["mcp-protocol-version"] = e.protocol);
108
+ const c = yield n(t.url, {
109
+ method: "POST",
110
+ headers: i,
111
+ body: JSON.stringify(o),
112
+ signal: k(r)
113
+ }), a = yield A(c);
114
+ if (!c.ok)
115
+ throw new Error(`MCP HTTP ${c.status}: ${a.slice(0, 300)}`);
116
+ const s = C(a), d = c.headers.get("mcp-session-id");
117
+ return e && d && (e.id = d), s;
118
+ });
119
+ }
120
+ function h(t) {
121
+ const o = t.error;
122
+ if (!o || typeof o != "object")
123
+ return;
124
+ const e = o.message;
125
+ return typeof e == "string" && e ? e : "MCP 调用失败";
126
+ }
127
+ function H(t) {
128
+ const o = t instanceof Error ? t.message : String(t);
129
+ return /session/i.test(o) || o.includes("MCP HTTP 404");
130
+ }
131
+ function y(t, o, e) {
132
+ return l(this, null, function* () {
133
+ const r = M(t), n = m.get(r);
134
+ if (n != null && n.id)
135
+ return n;
136
+ const i = {
137
+ protocol: "2024-11-05",
138
+ nextId: 1
139
+ }, c = yield w(t, {
140
+ jsonrpc: "2.0",
141
+ id: i.nextId,
142
+ method: "initialize",
143
+ params: {
144
+ protocolVersion: i.protocol,
145
+ capabilities: {},
146
+ clientInfo: {
147
+ name: "bot-client-sdk",
148
+ version: "1.0.0"
149
+ }
150
+ }
151
+ }, i, o, e);
152
+ i.nextId += 1;
153
+ const a = h(c);
154
+ if (a)
155
+ throw new Error(a);
156
+ const s = c.result;
157
+ if (s && typeof s == "object") {
158
+ const d = s.protocolVersion;
159
+ typeof d == "string" && d && (i.protocol = d);
160
+ }
161
+ return yield w(t, {
162
+ jsonrpc: "2.0",
163
+ method: "notifications/initialized"
164
+ }, i, o, e), m.set(r, i), i;
165
+ });
166
+ }
167
+ function $(e) {
168
+ return l(this, arguments, function* (t, o = fetch) {
169
+ var a;
170
+ const r = yield y(t, void 0, o), n = yield w(t, {
171
+ jsonrpc: "2.0",
172
+ id: r.nextId,
173
+ method: "tools/list",
174
+ params: {}
175
+ }, r, void 0, o);
176
+ r.nextId += 1;
177
+ const i = h(n);
178
+ if (i)
179
+ throw new Error(i);
180
+ const c = n.result;
181
+ return ((a = c == null ? void 0 : c.tools) != null ? a : []).filter((s) => s.name).map((s) => ({
182
+ name: s.name,
183
+ description: s.description || "",
184
+ inputSchema: s.inputSchema || {
185
+ type: "object",
186
+ properties: {}
187
+ }
188
+ }));
189
+ });
190
+ }
191
+ function z(i, c, a, s) {
192
+ return l(this, arguments, function* (t, o, e, r, n = fetch) {
193
+ const d = M(t);
194
+ let p = yield y(t, r, n);
195
+ const x = () => w(t, {
196
+ jsonrpc: "2.0",
197
+ id: p.nextId,
198
+ method: "tools/call",
199
+ params: {
200
+ name: o,
201
+ arguments: e && typeof e == "object" ? e : {}
202
+ }
203
+ }, p, r, n);
204
+ let f;
205
+ try {
206
+ f = yield x(), p.nextId += 1;
207
+ } catch (S) {
208
+ if (!H(S))
209
+ throw S;
210
+ m.delete(d), p = yield y(t, r, n), f = yield x(), p.nextId += 1;
211
+ }
212
+ let u = h(f);
213
+ if (u && /session/i.test(u) && (m.delete(d), p = yield y(t, r, n), f = yield x(), p.nextId += 1, u = h(f)), u)
214
+ throw new Error(u);
215
+ return I(f.result);
216
+ });
217
+ }
218
+ export {
219
+ z as callMcpTool,
220
+ $ as listMcpTools,
221
+ I as mcpToolText,
222
+ C as parseMcpBody
223
+ };
@@ -0,0 +1,155 @@
1
+ var u = (e, o, t) => new Promise((c, s) => {
2
+ var f = (a) => {
3
+ try {
4
+ p(t.next(a));
5
+ } catch (r) {
6
+ s(r);
7
+ }
8
+ }, l = (a) => {
9
+ try {
10
+ p(t.throw(a));
11
+ } catch (r) {
12
+ s(r);
13
+ }
14
+ }, p = (a) => a.done ? c(a.value) : Promise.resolve(a.value).then(f, l);
15
+ p((t = t.apply(e, o)).next());
16
+ });
17
+ import { refreshBuiltinPlugins as h } from "../Config.mjs";
18
+ import M from "../Logger.mjs";
19
+ import { listMcpTools as _, callMcpTool as b } from "./client.mjs";
20
+ import { replaceLocalMcpTools as y, localMcpBinding as j } from "./registry.mjs";
21
+ const d = new M("[LocalMcp] ", !0);
22
+ function w(e) {
23
+ const o = e == null ? void 0 : e.mcps;
24
+ return Array.isArray(o) ? o.filter((t) => t && typeof t == "object" && t.runtime === "local" && t.id) : [];
25
+ }
26
+ function C(e, o, t) {
27
+ return e == null || e.includes(o) ? !0 : !!t && e.includes(t);
28
+ }
29
+ function v(e) {
30
+ if (!e || typeof e != "object")
31
+ return {};
32
+ const o = {};
33
+ for (const [t, c] of Object.entries(e))
34
+ typeof c == "string" && (o[t] = c);
35
+ return o;
36
+ }
37
+ function P(e) {
38
+ var l, p;
39
+ if (!e || typeof e != "object")
40
+ return null;
41
+ const o = e;
42
+ if (typeof o.code == "number" && o.code !== 200)
43
+ return null;
44
+ const t = o.data && typeof o.data == "object" ? o.data : o, c = typeof t.code == "string" ? t.code : "", s = c ? (l = t.mcpServers) == null ? void 0 : l[c] : void 0, f = typeof (s == null ? void 0 : s.url) == "string" ? s.url : void 0;
45
+ return {
46
+ code: c,
47
+ deployType: typeof ((p = t.deployConfig) == null ? void 0 : p.type) == "string" ? t.deployConfig.type : void 0,
48
+ url: f,
49
+ headers: v(s == null ? void 0 : s.headers)
50
+ };
51
+ }
52
+ function T(s, f, l) {
53
+ return u(this, arguments, function* (e, o, t, c = fetch) {
54
+ const p = e.replace(/\/$/, ""), a = o.startsWith("Bearer ") ? o : `Bearer ${o}`, r = yield c(`${p}/mcpmgr/v1/mcpserver/${encodeURIComponent(t)}`, {
55
+ headers: {
56
+ Authorization: a
57
+ }
58
+ }), i = yield r.json().catch(() => null);
59
+ if (!r.ok)
60
+ throw new Error(`MCP 详情 HTTP ${r.status}`);
61
+ const n = P(i);
62
+ if (!n)
63
+ throw new Error("MCP 详情不可用");
64
+ return n;
65
+ });
66
+ }
67
+ function $(e, o) {
68
+ return (t, c, s) => {
69
+ const f = j(e);
70
+ if (!f) {
71
+ c({
72
+ code: 500,
73
+ message: "缺少 MCP 地址"
74
+ });
75
+ return;
76
+ }
77
+ b(f, e, t, s == null ? void 0 : s.signal, o).then((l) => c({
78
+ code: 0,
79
+ message: "ok",
80
+ data: l
81
+ })).catch((l) => {
82
+ c({
83
+ code: 500,
84
+ message: l instanceof Error ? l.message : String(l)
85
+ });
86
+ });
87
+ };
88
+ }
89
+ function E(e) {
90
+ return u(this, null, function* () {
91
+ var p, a;
92
+ const o = (p = e.fetchImpl) != null ? p : fetch, t = e.initMcp ? Object.keys((a = e.initMcp.mcpServers) != null ? a : {}) : null, c = w(e.arrange);
93
+ if (!c.length) {
94
+ d.log("编排里没有 runtime=local 的 MCP,不发送 register_client_mcp_tools"), y([]), h();
95
+ return;
96
+ }
97
+ const s = yield Promise.all(c.map((r) => u(this, null, function* () {
98
+ const i = r.id;
99
+ try {
100
+ const n = yield T(e.apiRoot, e.token, i, o);
101
+ if (!C(t, i, n.code))
102
+ return null;
103
+ if (n.deployType !== "streamableHttp" || !n.url || !n.code)
104
+ return d.log("skip local mcp", i), null;
105
+ const m = {
106
+ code: n.code,
107
+ url: n.url,
108
+ headers: n.headers
109
+ }, g = yield _(m, o);
110
+ return g.length ? {
111
+ code: n.code,
112
+ url: n.url,
113
+ binding: m,
114
+ tools: g
115
+ } : null;
116
+ } catch (n) {
117
+ return d.error("local mcp failed", i, n instanceof Error ? n.message : String(n)), null;
118
+ }
119
+ })));
120
+ if (e.isCurrent && !e.isCurrent())
121
+ return;
122
+ const f = {}, l = [];
123
+ for (const r of s)
124
+ if (r) {
125
+ f[r.code] = {
126
+ type: "streamableHttp",
127
+ url: r.url,
128
+ tools: r.tools
129
+ };
130
+ for (const i of r.tools)
131
+ l.push({
132
+ name: i.name,
133
+ binding: r.binding,
134
+ handler: $(i.name, o)
135
+ });
136
+ }
137
+ if (y(l), h(), !Object.keys(f).length || !e.socket) {
138
+ d.log("没有可注册的本地 MCP 工具,不发送 register_client_mcp_tools");
139
+ return;
140
+ }
141
+ d.log("发送 register_client_mcp_tools", Object.entries(f).map(([r, i]) => `${r}: ${i.tools.map((n) => n.name).join(", ")}`).join("; ")), e.socket.emit("register_client_mcp_tools", {
142
+ mcpServers: f
143
+ }, (r) => {
144
+ const i = r && typeof r == "object" ? r.code : void 0;
145
+ typeof i == "number" && i !== 200 && d.error("register_client_mcp_tools", i);
146
+ });
147
+ });
148
+ }
149
+ export {
150
+ C as detailMatchesInit,
151
+ T as fetchMcpDetail,
152
+ w as listedLocalMcps,
153
+ P as parseMcpDetail,
154
+ E as registerLocalMcp
155
+ };
@@ -0,0 +1,39 @@
1
+ var f = Object.defineProperty, p = Object.defineProperties;
2
+ var s = Object.getOwnPropertyDescriptors;
3
+ var i = Object.getOwnPropertySymbols;
4
+ var M = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
5
+ var r = (l, n, o) => n in l ? f(l, n, { enumerable: !0, configurable: !0, writable: !0, value: o }) : l[n] = o, e = (l, n) => {
6
+ for (var o in n || (n = {}))
7
+ M.call(n, o) && r(l, o, n[o]);
8
+ if (i)
9
+ for (var o of i(n))
10
+ g.call(n, o) && r(l, o, n[o]);
11
+ return l;
12
+ }, u = (l, n) => p(l, s(n));
13
+ const a = "MCP", t = /* @__PURE__ */ new Map();
14
+ let c = null;
15
+ function b(l, n, o) {
16
+ t.set(l, n), c = u(e({}, c != null ? c : {}), {
17
+ [l]: o
18
+ });
19
+ }
20
+ function P(l) {
21
+ t.clear(), c = null;
22
+ for (const n of l)
23
+ b(n.name, n.binding, n.handler);
24
+ c && !Object.keys(c).length && (c = null);
25
+ }
26
+ function d(l) {
27
+ return t.get(l);
28
+ }
29
+ function y(l) {
30
+ var n;
31
+ !c || !Object.keys(c).length || (l[a] = e(e({}, (n = l[a]) != null ? n : {}), c));
32
+ }
33
+ export {
34
+ a as MCP_PLUGIN_CODE,
35
+ y as applyLocalMcpPlugins,
36
+ d as localMcpBinding,
37
+ b as rememberLocalMcpTool,
38
+ P as replaceLocalMcpTools
39
+ };
@@ -1,4 +1,4 @@
1
- const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.20", t = "glodoncv", i = "aiot bot client js sdk", n = "module", g = !1, o = [
1
+ const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.24", t = "glodoncv", i = "aiot bot client js sdk", n = "module", g = !1, o = [
2
2
  "aiot",
3
3
  "bot",
4
4
  "bot client",
@@ -68,7 +68,7 @@ const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.20", t = "glodoncv",
68
68
  access: "public",
69
69
  registry: "https://registry.npmjs.org/"
70
70
  }, y = {
71
- "@glodon-aiot/apis": "^3.26.0-alpha.20",
71
+ "@glodon-aiot/apis": "^3.26.0-alpha.24",
72
72
  axios: "0.24.0",
73
73
  buffer: "^6.0.3",
74
74
  dayjs: "^1.11.13",