@glodon-aiot/bot-client-sdk 3.26.0-alpha.31 → 3.26.0-alpha.33

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,155 +1,207 @@
1
- var u = (e, o, t) => new Promise((c, s) => {
2
- var f = (a) => {
1
+ var L = Object.defineProperty;
2
+ var B = Object.getOwnPropertySymbols;
3
+ var T = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
4
+ var P = (e, o, t) => o in e ? L(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t, $ = (e, o) => {
5
+ for (var t in o || (o = {}))
6
+ T.call(o, t) && P(e, t, o[t]);
7
+ if (B)
8
+ for (var t of B(o))
9
+ k.call(o, t) && P(e, t, o[t]);
10
+ return e;
11
+ };
12
+ var y = (e, o, t) => new Promise((r, n) => {
13
+ var l = (f) => {
3
14
  try {
4
- p(t.next(a));
5
- } catch (r) {
6
- s(r);
15
+ d(t.next(f));
16
+ } catch (u) {
17
+ n(u);
7
18
  }
8
- }, l = (a) => {
19
+ }, a = (f) => {
9
20
  try {
10
- p(t.throw(a));
11
- } catch (r) {
12
- s(r);
21
+ d(t.throw(f));
22
+ } catch (u) {
23
+ n(u);
13
24
  }
14
- }, p = (a) => a.done ? c(a.value) : Promise.resolve(a.value).then(f, l);
15
- p((t = t.apply(e, o)).next());
25
+ }, d = (f) => f.done ? r(f.value) : Promise.resolve(f.value).then(l, a);
26
+ d((t = t.apply(e, o)).next());
16
27
  });
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) {
28
+ import { refreshBuiltinPlugins as z } from "../Config.mjs";
29
+ import H from "../Logger.mjs";
30
+ import { retainMcpSessions as A, listMcpTools as O, dropUnusedMcpSession as I, callMcpTool as U } from "./client.mjs";
31
+ import { currentLocalMcpEndpoints as b } from "./endpoints.mjs";
32
+ import { replaceLocalMcpTools as E, localMcpBindings as D, localMcpBinding as R } from "./registry.mjs";
33
+ const m = new H("[LocalMcp] ", !0);
34
+ function Z(e) {
23
35
  const o = e == null ? void 0 : e.mcps;
24
36
  return Array.isArray(o) ? o.filter((t) => t && typeof t == "object" && t.runtime === "local" && t.id) : [];
25
37
  }
26
- function C(e, o, t) {
38
+ function F(e, o, t) {
27
39
  return e == null || e.includes(o) ? !0 : !!t && e.includes(t);
28
40
  }
29
- function v(e) {
41
+ function V(e) {
30
42
  if (!e || typeof e != "object")
31
43
  return {};
32
44
  const o = {};
33
- for (const [t, c] of Object.entries(e))
34
- typeof c == "string" && (o[t] = c);
45
+ for (const [t, r] of Object.entries(e))
46
+ typeof r == "string" && (o[t] = r);
35
47
  return o;
36
48
  }
37
- function P(e) {
38
- var l, p;
49
+ function W(e) {
50
+ var a, d;
39
51
  if (!e || typeof e != "object")
40
52
  return null;
41
53
  const o = e;
42
54
  if (typeof o.code == "number" && o.code !== 200)
43
55
  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;
56
+ const t = o.data && typeof o.data == "object" ? o.data : o, r = typeof t.code == "string" ? t.code : "", n = r ? (a = t.mcpServers) == null ? void 0 : a[r] : void 0, l = typeof (n == null ? void 0 : n.url) == "string" ? n.url : void 0;
45
57
  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)
58
+ code: r,
59
+ deployType: typeof ((d = t.deployConfig) == null ? void 0 : d.type) == "string" ? t.deployConfig.type : void 0,
60
+ url: l,
61
+ headers: V(n == null ? void 0 : n.headers)
50
62
  };
51
63
  }
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)}`, {
64
+ function q(n, l, a) {
65
+ return y(this, arguments, function* (e, o, t, r = fetch) {
66
+ const d = e.replace(/\/$/, ""), f = o.startsWith("Bearer ") ? o : `Bearer ${o}`, u = yield r(`${d}/mcpmgr/v1/mcpserver/${encodeURIComponent(t)}`, {
55
67
  headers: {
56
- Authorization: a
68
+ Authorization: f
57
69
  }
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)
70
+ }), g = yield u.json().catch(() => null);
71
+ if (!u.ok)
72
+ throw new Error(`MCP 详情 HTTP ${u.status}`);
73
+ const h = W(g);
74
+ if (!h)
63
75
  throw new Error("MCP 详情不可用");
64
- return n;
76
+ return h;
65
77
  });
66
78
  }
67
- function $(e, o) {
68
- return (t, c, s) => {
69
- const f = j(e);
70
- if (!f) {
71
- c({
79
+ function G(e) {
80
+ return /^[A-Za-z][A-Za-z0-9.+-]* /.test(e) ? e : `Bearer ${e}`;
81
+ }
82
+ function J(e, o) {
83
+ if (!(o != null && o.token))
84
+ return $({}, e);
85
+ const t = {};
86
+ for (const [r, n] of Object.entries(e))
87
+ r.toLowerCase() !== "authorization" && (t[r] = n);
88
+ return t.Authorization = G(o.token), t;
89
+ }
90
+ function K(e, o, t) {
91
+ const r = e.find((n) => !o.has(n) && t(n));
92
+ return r && o.add(r), r;
93
+ }
94
+ function N(e, o, t) {
95
+ return K(e, o, (r) => r.code === t || r.id === t);
96
+ }
97
+ function Q(e, o, t) {
98
+ var l;
99
+ const r = e == null ? void 0 : e.mcpServers;
100
+ if (!r)
101
+ return;
102
+ const n = (l = r[t]) != null ? l : r[o];
103
+ return (n == null ? void 0 : n.url) || void 0;
104
+ }
105
+ function X(e, o) {
106
+ return (t, r, n) => {
107
+ const l = R(e);
108
+ if (!l) {
109
+ r({
72
110
  code: 500,
73
111
  message: "缺少 MCP 地址"
74
112
  });
75
113
  return;
76
114
  }
77
- b(f, e, t, s == null ? void 0 : s.signal, o).then((l) => c({
115
+ U(l, e, t, n == null ? void 0 : n.signal, o).then((a) => r({
78
116
  code: 0,
79
117
  message: "ok",
80
- data: l
81
- })).catch((l) => {
82
- c({
118
+ data: a
119
+ })).catch((a) => {
120
+ r({
83
121
  code: 500,
84
- message: l instanceof Error ? l.message : String(l)
122
+ message: a instanceof Error ? a.message : String(a)
85
123
  });
86
124
  });
87
125
  };
88
126
  }
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();
127
+ function ne(e) {
128
+ return y(this, null, function* () {
129
+ var h, _;
130
+ const o = (h = e.fetchImpl) != null ? h : fetch, t = e.initMcp ? Object.keys((_ = e.initMcp.mcpServers) != null ? _ : {}) : null, r = Z(e.arrange), n = b().revision, l = () => b().revision !== n || (e.isCurrent ? !e.isCurrent() : !1);
131
+ if (!r.length) {
132
+ if (l())
133
+ return;
134
+ m.log("编排里没有 runtime=local 的 MCP,不发送 register_client_mcp_tools"), E([]), A([]), z();
95
135
  return;
96
136
  }
97
- const s = yield Promise.all(c.map((r) => u(this, null, function* () {
98
- const i = r.id;
137
+ const a = [...b().servers], d = /* @__PURE__ */ new Set(), f = yield Promise.all(r.map((c) => y(this, null, function* () {
138
+ var j, w;
139
+ const s = c.id;
140
+ let p;
141
+ const v = () => {
142
+ p && (d.delete(p), p = void 0);
143
+ };
99
144
  try {
100
- const n = yield T(e.apiRoot, e.token, i, o);
101
- if (!C(t, i, n.code))
145
+ const i = yield q(e.apiRoot, e.token, s, o);
146
+ if (!F(t, s, i.code))
102
147
  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;
148
+ p = i.code ? N(a, d, i.code) : void 0;
149
+ const C = (w = (j = p == null ? void 0 : p.url) != null ? j : Q(e.initMcp, s, i.code)) != null ? w : i.url;
150
+ if (i.deployType !== "streamableHttp" || !i.code || !C)
151
+ return m.log("skip local mcp", s), v(), null;
152
+ const M = {
153
+ code: i.code,
154
+ url: C,
155
+ headers: J(i.headers, p)
156
+ }, S = yield O(M, o);
157
+ return S.length ? {
158
+ code: i.code,
159
+ url: M.url,
160
+ binding: M,
161
+ tools: S
162
+ } : (v(), null);
163
+ } catch (i) {
164
+ return v(), m.error("local mcp failed", s, i instanceof Error ? i.message : String(i)), null;
118
165
  }
119
166
  })));
120
- if (e.isCurrent && !e.isCurrent())
167
+ if (l()) {
168
+ const c = D();
169
+ for (const s of f)
170
+ s && I(s.binding, c);
121
171
  return;
122
- const f = {}, l = [];
123
- for (const r of s)
124
- if (r) {
125
- f[r.code] = {
172
+ }
173
+ const u = {}, g = [];
174
+ for (const c of f)
175
+ if (c) {
176
+ u[c.code] = {
126
177
  type: "streamableHttp",
127
- url: r.url,
128
- tools: r.tools
178
+ url: c.url,
179
+ tools: c.tools
129
180
  };
130
- for (const i of r.tools)
131
- l.push({
132
- name: i.name,
133
- binding: r.binding,
134
- handler: $(i.name, o)
181
+ for (const s of c.tools)
182
+ g.push({
183
+ name: s.name,
184
+ binding: c.binding,
185
+ handler: X(s.name, o)
135
186
  });
136
187
  }
137
- if (y(l), h(), !Object.keys(f).length || !e.socket) {
138
- d.log("没有可注册的本地 MCP 工具,不发送 register_client_mcp_tools");
188
+ if (E(g), A(g.map((c) => c.binding)), z(), !Object.keys(u).length || !e.socket) {
189
+ m.log("没有可注册的本地 MCP 工具,不发送 register_client_mcp_tools");
139
190
  return;
140
191
  }
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);
192
+ m.log("发送 register_client_mcp_tools", Object.entries(u).map(([c, s]) => `${c}: ${s.tools.map((p) => p.name).join(", ")}`).join("; ")), e.socket.emit("register_client_mcp_tools", {
193
+ mcpServers: u
194
+ }, (c) => {
195
+ const s = c && typeof c == "object" ? c.code : void 0;
196
+ typeof s == "number" && s !== 200 && m.error("register_client_mcp_tools", s);
146
197
  });
147
198
  });
148
199
  }
149
200
  export {
150
- C as detailMatchesInit,
151
- T as fetchMcpDetail,
152
- w as listedLocalMcps,
153
- P as parseMcpDetail,
154
- E as registerLocalMcp
201
+ F as detailMatchesInit,
202
+ q as fetchMcpDetail,
203
+ J as headersForEndpoint,
204
+ Z as listedLocalMcps,
205
+ W as parseMcpDetail,
206
+ ne as registerLocalMcp
155
207
  };
@@ -2,38 +2,42 @@ var f = Object.defineProperty, p = Object.defineProperties;
2
2
  var s = Object.getOwnPropertyDescriptors;
3
3
  var i = Object.getOwnPropertySymbols;
4
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]);
5
+ var r = (l, n, c) => n in l ? f(l, n, { enumerable: !0, configurable: !0, writable: !0, value: c }) : l[n] = c, e = (l, n) => {
6
+ for (var c in n || (n = {}))
7
+ M.call(n, c) && r(l, c, n[c]);
8
8
  if (i)
9
- for (var o of i(n))
10
- g.call(n, o) && r(l, o, n[o]);
9
+ for (var c of i(n))
10
+ g.call(n, c) && r(l, c, n[c]);
11
11
  return l;
12
12
  }, u = (l, n) => p(l, s(n));
13
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
14
+ let o = null;
15
+ function b(l, n, c) {
16
+ t.set(l, n), o = u(e({}, o != null ? o : {}), {
17
+ [l]: c
18
18
  });
19
19
  }
20
- function P(l) {
21
- t.clear(), c = null;
20
+ function L(l) {
21
+ t.clear(), o = null;
22
22
  for (const n of l)
23
23
  b(n.name, n.binding, n.handler);
24
- c && !Object.keys(c).length && (c = null);
24
+ o && !Object.keys(o).length && (o = null);
25
25
  }
26
- function d(l) {
26
+ function P(l) {
27
27
  return t.get(l);
28
28
  }
29
- function y(l) {
29
+ function y() {
30
+ return [...t.values()];
31
+ }
32
+ function C(l) {
30
33
  var n;
31
- !c || !Object.keys(c).length || (l[a] = e(e({}, (n = l[a]) != null ? n : {}), c));
34
+ !o || !Object.keys(o).length || (l[a] = e(e({}, (n = l[a]) != null ? n : {}), o));
32
35
  }
33
36
  export {
34
37
  a as MCP_PLUGIN_CODE,
35
- y as applyLocalMcpPlugins,
36
- d as localMcpBinding,
38
+ C as applyLocalMcpPlugins,
39
+ P as localMcpBinding,
40
+ y as localMcpBindings,
37
41
  b as rememberLocalMcpTool,
38
- P as replaceLocalMcpTools
42
+ L as replaceLocalMcpTools
39
43
  };
@@ -1,4 +1,4 @@
1
- const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.31", 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.33", 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.31", t = "glodoncv",
68
68
  access: "public",
69
69
  registry: "https://registry.npmjs.org/"
70
70
  }, y = {
71
- "@glodon-aiot/apis": "^3.26.0-alpha.31",
71
+ "@glodon-aiot/apis": "^3.26.0-alpha.33",
72
72
  axios: "0.24.0",
73
73
  buffer: "^6.0.3",
74
74
  dayjs: "^1.11.13",