@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.
- package/README.md +3 -8
- package/dist/es/AgentSession.mjs +63 -59
- package/dist/es/BotClient.mjs +32 -31
- package/dist/es/localMcp/client.mjs +101 -90
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +149 -97
- package/dist/es/localMcp/registry.mjs +22 -18
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +45 -45
- package/dist/src/AgentSession.d.ts +1 -0
- package/dist/src/localMcp/client.d.ts +4 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +2 -0
- package/dist/src/localMcp/registry.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,155 +1,207 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
} catch (
|
|
6
|
-
|
|
15
|
+
d(t.next(f));
|
|
16
|
+
} catch (u) {
|
|
17
|
+
n(u);
|
|
7
18
|
}
|
|
8
|
-
},
|
|
19
|
+
}, a = (f) => {
|
|
9
20
|
try {
|
|
10
|
-
|
|
11
|
-
} catch (
|
|
12
|
-
|
|
21
|
+
d(t.throw(f));
|
|
22
|
+
} catch (u) {
|
|
23
|
+
n(u);
|
|
13
24
|
}
|
|
14
|
-
},
|
|
15
|
-
|
|
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
|
|
18
|
-
import
|
|
19
|
-
import { listMcpTools as
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
38
|
+
function F(e, o, t) {
|
|
27
39
|
return e == null || e.includes(o) ? !0 : !!t && e.includes(t);
|
|
28
40
|
}
|
|
29
|
-
function
|
|
41
|
+
function V(e) {
|
|
30
42
|
if (!e || typeof e != "object")
|
|
31
43
|
return {};
|
|
32
44
|
const o = {};
|
|
33
|
-
for (const [t,
|
|
34
|
-
typeof
|
|
45
|
+
for (const [t, r] of Object.entries(e))
|
|
46
|
+
typeof r == "string" && (o[t] = r);
|
|
35
47
|
return o;
|
|
36
48
|
}
|
|
37
|
-
function
|
|
38
|
-
var
|
|
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,
|
|
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:
|
|
47
|
-
deployType: typeof ((
|
|
48
|
-
url:
|
|
49
|
-
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
|
|
53
|
-
return
|
|
54
|
-
const
|
|
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:
|
|
68
|
+
Authorization: f
|
|
57
69
|
}
|
|
58
|
-
}),
|
|
59
|
-
if (!
|
|
60
|
-
throw new Error(`MCP 详情 HTTP ${
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
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
|
|
76
|
+
return h;
|
|
65
77
|
});
|
|
66
78
|
}
|
|
67
|
-
function
|
|
68
|
-
return (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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:
|
|
81
|
-
})).catch((
|
|
82
|
-
|
|
118
|
+
data: a
|
|
119
|
+
})).catch((a) => {
|
|
120
|
+
r({
|
|
83
121
|
code: 500,
|
|
84
|
-
message:
|
|
122
|
+
message: a instanceof Error ? a.message : String(a)
|
|
85
123
|
});
|
|
86
124
|
});
|
|
87
125
|
};
|
|
88
126
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
91
|
-
var
|
|
92
|
-
const o = (
|
|
93
|
-
if (!
|
|
94
|
-
|
|
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
|
|
98
|
-
|
|
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
|
|
101
|
-
if (!
|
|
145
|
+
const i = yield q(e.apiRoot, e.token, s, o);
|
|
146
|
+
if (!F(t, s, i.code))
|
|
102
147
|
return null;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 (
|
|
167
|
+
if (l()) {
|
|
168
|
+
const c = D();
|
|
169
|
+
for (const s of f)
|
|
170
|
+
s && I(s.binding, c);
|
|
121
171
|
return;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
172
|
+
}
|
|
173
|
+
const u = {}, g = [];
|
|
174
|
+
for (const c of f)
|
|
175
|
+
if (c) {
|
|
176
|
+
u[c.code] = {
|
|
126
177
|
type: "streamableHttp",
|
|
127
|
-
url:
|
|
128
|
-
tools:
|
|
178
|
+
url: c.url,
|
|
179
|
+
tools: c.tools
|
|
129
180
|
};
|
|
130
|
-
for (const
|
|
131
|
-
|
|
132
|
-
name:
|
|
133
|
-
binding:
|
|
134
|
-
handler:
|
|
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 (
|
|
138
|
-
|
|
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
|
-
|
|
142
|
-
mcpServers:
|
|
143
|
-
}, (
|
|
144
|
-
const
|
|
145
|
-
typeof
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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,
|
|
6
|
-
for (var
|
|
7
|
-
M.call(n,
|
|
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
|
|
10
|
-
g.call(n,
|
|
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
|
|
15
|
-
function b(l, n,
|
|
16
|
-
t.set(l, n),
|
|
17
|
-
[l]:
|
|
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
|
|
21
|
-
t.clear(),
|
|
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
|
-
|
|
24
|
+
o && !Object.keys(o).length && (o = null);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function P(l) {
|
|
27
27
|
return t.get(l);
|
|
28
28
|
}
|
|
29
|
-
function y(
|
|
29
|
+
function y() {
|
|
30
|
+
return [...t.values()];
|
|
31
|
+
}
|
|
32
|
+
function C(l) {
|
|
30
33
|
var n;
|
|
31
|
-
!
|
|
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
|
-
|
|
36
|
-
|
|
38
|
+
C as applyLocalMcpPlugins,
|
|
39
|
+
P as localMcpBinding,
|
|
40
|
+
y as localMcpBindings,
|
|
37
41
|
b as rememberLocalMcpTool,
|
|
38
|
-
|
|
42
|
+
L as replaceLocalMcpTools
|
|
39
43
|
};
|
package/dist/es/package.json.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.
|
|
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.
|
|
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",
|