@glodon-aiot/bot-client-sdk 3.26.0-alpha.32 → 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/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,47 +1,47 @@
|
|
|
1
1
|
var T = Object.defineProperty, b = Object.defineProperties;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
2
|
+
var k = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var g = Object.getOwnPropertySymbols;
|
|
4
|
+
var O = Object.prototype.hasOwnProperty, J = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var M = (t, o, e) => o in t ? T(t, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[o] = e, v = (t, o) => {
|
|
6
6
|
for (var e in o || (o = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
|
|
7
|
+
O.call(o, e) && M(t, e, o[e]);
|
|
8
|
+
if (g)
|
|
9
|
+
for (var e of g(o))
|
|
10
|
+
J.call(o, e) && M(t, e, o[e]);
|
|
11
11
|
return t;
|
|
12
|
-
}, E = (t, o) => b(t,
|
|
13
|
-
var
|
|
12
|
+
}, E = (t, o) => b(t, k(o));
|
|
13
|
+
var u = (t, o, e) => new Promise((n, r) => {
|
|
14
14
|
var i = (s) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
|
|
16
|
+
c(e.next(s));
|
|
17
|
+
} catch (f) {
|
|
18
|
+
r(f);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, a = (s) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
|
|
22
|
+
c(e.throw(s));
|
|
23
|
+
} catch (f) {
|
|
24
|
+
r(f);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
26
|
+
}, c = (s) => s.done ? n(s.value) : Promise.resolve(s.value).then(i, a);
|
|
27
|
+
c((e = e.apply(t, o)).next());
|
|
28
28
|
});
|
|
29
|
-
const
|
|
30
|
-
function
|
|
29
|
+
const d = /* @__PURE__ */ new Map(), N = 2e4;
|
|
30
|
+
function P(t) {
|
|
31
31
|
if (typeof AbortSignal != "undefined" && typeof AbortSignal.timeout == "function") {
|
|
32
|
-
const o = AbortSignal.timeout(
|
|
32
|
+
const o = AbortSignal.timeout(N);
|
|
33
33
|
if (!t)
|
|
34
34
|
return o;
|
|
35
|
-
const e = new AbortController(),
|
|
36
|
-
return o.addEventListener("abort",
|
|
35
|
+
const e = new AbortController(), n = () => e.abort();
|
|
36
|
+
return o.addEventListener("abort", n, {
|
|
37
37
|
once: !0
|
|
38
|
-
}), t.addEventListener("abort",
|
|
38
|
+
}), t.addEventListener("abort", n, {
|
|
39
39
|
once: !0
|
|
40
40
|
}), e.signal;
|
|
41
41
|
}
|
|
42
42
|
return t;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function m(t) {
|
|
45
45
|
return `${t.url}
|
|
46
46
|
${JSON.stringify(t.headers)}`;
|
|
47
47
|
}
|
|
@@ -52,12 +52,12 @@ function C(t) {
|
|
|
52
52
|
if (o.startsWith("{") || o.startsWith("["))
|
|
53
53
|
return JSON.parse(o);
|
|
54
54
|
const e = o.split(/\n\n/);
|
|
55
|
-
for (let
|
|
56
|
-
const
|
|
55
|
+
for (let n = e.length - 1; n >= 0; n -= 1) {
|
|
56
|
+
const r = e[n].split(`
|
|
57
57
|
`).filter((i) => i.startsWith("data:")).map((i) => i.slice(5).trim()).join(`
|
|
58
58
|
`);
|
|
59
|
-
if (
|
|
60
|
-
return JSON.parse(
|
|
59
|
+
if (r.startsWith("{") || r.startsWith("["))
|
|
60
|
+
return JSON.parse(r);
|
|
61
61
|
}
|
|
62
62
|
throw new Error("MCP 响应不是 JSON");
|
|
63
63
|
}
|
|
@@ -71,53 +71,53 @@ function I(t) {
|
|
|
71
71
|
`) : JSON.stringify(t);
|
|
72
72
|
}
|
|
73
73
|
function A(t) {
|
|
74
|
-
return
|
|
74
|
+
return u(this, null, function* () {
|
|
75
75
|
if (!(t.headers.get("content-type") || "").includes("text/event-stream") || !t.body)
|
|
76
76
|
return t.text();
|
|
77
|
-
const e = t.body.getReader(),
|
|
78
|
-
let
|
|
77
|
+
const e = t.body.getReader(), n = new TextDecoder();
|
|
78
|
+
let r = "";
|
|
79
79
|
try {
|
|
80
|
-
for (;
|
|
80
|
+
for (; r.length < 2e6; ) {
|
|
81
81
|
const {
|
|
82
82
|
done: i,
|
|
83
|
-
value:
|
|
83
|
+
value: a
|
|
84
84
|
} = yield e.read();
|
|
85
85
|
if (i)
|
|
86
86
|
break;
|
|
87
|
-
|
|
87
|
+
r += n.decode(a, {
|
|
88
88
|
stream: !0
|
|
89
89
|
});
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
90
|
+
const c = r.split(/\n\n/).filter((s) => /^\s*data:/m.test(s));
|
|
91
|
+
if (c.length > 0)
|
|
92
|
+
return c[c.length - 1];
|
|
93
93
|
}
|
|
94
|
-
return
|
|
94
|
+
return r;
|
|
95
95
|
} finally {
|
|
96
96
|
yield e.cancel().catch(() => {
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
101
|
+
function h(t, o, e, n, r) {
|
|
102
|
+
return u(this, null, function* () {
|
|
103
103
|
const i = E(v({}, t.headers), {
|
|
104
104
|
"content-type": "application/json",
|
|
105
105
|
accept: "application/json, text/event-stream"
|
|
106
106
|
});
|
|
107
107
|
e != null && e.id && (i["mcp-session-id"] = e.id), e != null && e.protocol && (i["mcp-protocol-version"] = e.protocol);
|
|
108
|
-
const
|
|
108
|
+
const a = yield r(t.url, {
|
|
109
109
|
method: "POST",
|
|
110
110
|
headers: i,
|
|
111
111
|
body: JSON.stringify(o),
|
|
112
|
-
signal:
|
|
113
|
-
}),
|
|
114
|
-
if (!
|
|
115
|
-
throw new Error(`MCP HTTP ${
|
|
116
|
-
const s = C(
|
|
117
|
-
return e &&
|
|
112
|
+
signal: P(n)
|
|
113
|
+
}), c = yield A(a);
|
|
114
|
+
if (!a.ok)
|
|
115
|
+
throw new Error(`MCP HTTP ${a.status}: ${c.slice(0, 300)}`);
|
|
116
|
+
const s = C(c), f = a.headers.get("mcp-session-id");
|
|
117
|
+
return e && f && (e.id = f), s;
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function S(t) {
|
|
121
121
|
const o = t.error;
|
|
122
122
|
if (!o || typeof o != "object")
|
|
123
123
|
return;
|
|
@@ -128,15 +128,15 @@ function H(t) {
|
|
|
128
128
|
const o = t instanceof Error ? t.message : String(t);
|
|
129
129
|
return /session/i.test(o) || o.includes("MCP HTTP 404");
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
return
|
|
131
|
+
function w(t, o, e) {
|
|
132
|
+
return u(this, null, function* () {
|
|
133
|
+
const n = m(t), r = d.get(n);
|
|
134
|
+
if (r != null && r.id)
|
|
135
|
+
return r;
|
|
136
136
|
const i = {
|
|
137
137
|
protocol: "2024-11-05",
|
|
138
138
|
nextId: 1
|
|
139
|
-
},
|
|
139
|
+
}, a = yield h(t, {
|
|
140
140
|
jsonrpc: "2.0",
|
|
141
141
|
id: i.nextId,
|
|
142
142
|
method: "initialize",
|
|
@@ -150,35 +150,35 @@ function y(t, o, e) {
|
|
|
150
150
|
}
|
|
151
151
|
}, i, o, e);
|
|
152
152
|
i.nextId += 1;
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
throw new Error(
|
|
156
|
-
const s =
|
|
153
|
+
const c = S(a);
|
|
154
|
+
if (c)
|
|
155
|
+
throw new Error(c);
|
|
156
|
+
const s = a.result;
|
|
157
157
|
if (s && typeof s == "object") {
|
|
158
|
-
const
|
|
159
|
-
typeof
|
|
158
|
+
const f = s.protocolVersion;
|
|
159
|
+
typeof f == "string" && f && (i.protocol = f);
|
|
160
160
|
}
|
|
161
|
-
return yield
|
|
161
|
+
return yield h(t, {
|
|
162
162
|
jsonrpc: "2.0",
|
|
163
163
|
method: "notifications/initialized"
|
|
164
|
-
}, i, o, e),
|
|
164
|
+
}, i, o, e), d.set(n, i), i;
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
function $(e) {
|
|
168
|
-
return
|
|
169
|
-
var
|
|
170
|
-
const
|
|
168
|
+
return u(this, arguments, function* (t, o = fetch) {
|
|
169
|
+
var c;
|
|
170
|
+
const n = yield w(t, void 0, o), r = yield h(t, {
|
|
171
171
|
jsonrpc: "2.0",
|
|
172
|
-
id:
|
|
172
|
+
id: n.nextId,
|
|
173
173
|
method: "tools/list",
|
|
174
174
|
params: {}
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
const i =
|
|
175
|
+
}, n, void 0, o);
|
|
176
|
+
n.nextId += 1;
|
|
177
|
+
const i = S(r);
|
|
178
178
|
if (i)
|
|
179
179
|
throw new Error(i);
|
|
180
|
-
const
|
|
181
|
-
return ((
|
|
180
|
+
const a = r.result;
|
|
181
|
+
return ((c = a == null ? void 0 : a.tools) != null ? c : []).filter((s) => s.name).map((s) => ({
|
|
182
182
|
name: s.name,
|
|
183
183
|
description: s.description || "",
|
|
184
184
|
inputSchema: s.inputSchema || {
|
|
@@ -188,11 +188,11 @@ function $(e) {
|
|
|
188
188
|
}));
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
|
-
function z(i,
|
|
192
|
-
return
|
|
193
|
-
const
|
|
194
|
-
let p = yield
|
|
195
|
-
const x = () =>
|
|
191
|
+
function z(i, a, c, s) {
|
|
192
|
+
return u(this, arguments, function* (t, o, e, n, r = fetch) {
|
|
193
|
+
const f = m(t);
|
|
194
|
+
let p = yield w(t, n, r);
|
|
195
|
+
const x = () => h(t, {
|
|
196
196
|
jsonrpc: "2.0",
|
|
197
197
|
id: p.nextId,
|
|
198
198
|
method: "tools/call",
|
|
@@ -200,24 +200,35 @@ function z(i, c, a, s) {
|
|
|
200
200
|
name: o,
|
|
201
201
|
arguments: e && typeof e == "object" ? e : {}
|
|
202
202
|
}
|
|
203
|
-
}, p,
|
|
204
|
-
let
|
|
203
|
+
}, p, n, r);
|
|
204
|
+
let l;
|
|
205
205
|
try {
|
|
206
|
-
|
|
207
|
-
} catch (
|
|
208
|
-
if (!H(
|
|
209
|
-
throw
|
|
210
|
-
|
|
206
|
+
l = yield x(), p.nextId += 1;
|
|
207
|
+
} catch (j) {
|
|
208
|
+
if (!H(j))
|
|
209
|
+
throw j;
|
|
210
|
+
d.delete(f), p = yield w(t, n, r), l = yield x(), p.nextId += 1;
|
|
211
211
|
}
|
|
212
|
-
let
|
|
213
|
-
if (
|
|
214
|
-
throw new Error(
|
|
215
|
-
return I(
|
|
212
|
+
let y = S(l);
|
|
213
|
+
if (y && /session/i.test(y) && (d.delete(f), p = yield w(t, n, r), l = yield x(), p.nextId += 1, y = S(l)), y)
|
|
214
|
+
throw new Error(y);
|
|
215
|
+
return I(l.result);
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
|
+
function _(t) {
|
|
219
|
+
const o = new Set(t.map((e) => m(e)));
|
|
220
|
+
for (const e of d.keys())
|
|
221
|
+
o.has(e) || d.delete(e);
|
|
222
|
+
}
|
|
223
|
+
function B(t, o) {
|
|
224
|
+
const e = m(t);
|
|
225
|
+
o.some((n) => m(n) === e) || d.delete(e);
|
|
226
|
+
}
|
|
218
227
|
export {
|
|
219
228
|
z as callMcpTool,
|
|
229
|
+
B as dropUnusedMcpSession,
|
|
220
230
|
$ as listMcpTools,
|
|
221
231
|
I as mcpToolText,
|
|
222
|
-
C as parseMcpBody
|
|
232
|
+
C as parseMcpBody,
|
|
233
|
+
_ as retainMcpSessions
|
|
223
234
|
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var m = Object.getOwnPropertySymbols;
|
|
3
|
+
var b = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var y = (t, r, e) => r in t ? g(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e, f = (t, r) => {
|
|
5
|
+
for (var e in r || (r = {}))
|
|
6
|
+
b.call(r, e) && y(t, e, r[e]);
|
|
7
|
+
if (m)
|
|
8
|
+
for (var e of m(r))
|
|
9
|
+
L.call(r, e) && y(t, e, r[e]);
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { getHostBridge as M, parseHostMessage as w } from "../localFiles/host/protocol.mjs";
|
|
13
|
+
const p = /* @__PURE__ */ new Set();
|
|
14
|
+
let c, h = [], s, i;
|
|
15
|
+
function S() {
|
|
16
|
+
return {
|
|
17
|
+
revision: c,
|
|
18
|
+
servers: h
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function B(t) {
|
|
22
|
+
return p.add(t), () => p.delete(t);
|
|
23
|
+
}
|
|
24
|
+
function E(t) {
|
|
25
|
+
let r;
|
|
26
|
+
try {
|
|
27
|
+
r = new URL(t);
|
|
28
|
+
} catch (n) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (r.protocol !== "http:" || r.username || r.password || !r.port)
|
|
32
|
+
return;
|
|
33
|
+
const e = Number(r.port);
|
|
34
|
+
if (!Number.isInteger(e) || e < 1 || e > 65535)
|
|
35
|
+
return;
|
|
36
|
+
const o = r.hostname.toLowerCase();
|
|
37
|
+
if (!(o !== "127.0.0.1" && o !== "localhost" && o !== "::1" && o !== "[::1]"))
|
|
38
|
+
return r.href;
|
|
39
|
+
}
|
|
40
|
+
function a(t) {
|
|
41
|
+
return typeof t == "string" && t.trim() ? t.trim() : void 0;
|
|
42
|
+
}
|
|
43
|
+
function A(t) {
|
|
44
|
+
var e;
|
|
45
|
+
if (!Array.isArray(t))
|
|
46
|
+
return [];
|
|
47
|
+
const r = [];
|
|
48
|
+
for (const o of t) {
|
|
49
|
+
if (!o || typeof o != "object")
|
|
50
|
+
continue;
|
|
51
|
+
const n = o, u = a(n.code), d = (e = a(n.id)) != null ? e : u, l = typeof n.url == "string" ? E(n.url) : void 0;
|
|
52
|
+
if (!d || !l)
|
|
53
|
+
continue;
|
|
54
|
+
const v = a(n.token);
|
|
55
|
+
r.push(f(f({
|
|
56
|
+
id: d,
|
|
57
|
+
url: l
|
|
58
|
+
}, u ? {
|
|
59
|
+
code: u
|
|
60
|
+
} : {}), v ? {
|
|
61
|
+
token: v
|
|
62
|
+
} : {}));
|
|
63
|
+
}
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
function k(t) {
|
|
67
|
+
const r = t.revision;
|
|
68
|
+
return typeof r != "number" || !Number.isFinite(r) || c !== void 0 && r <= c || !Array.isArray(t.servers) ? !1 : (c = r, h = A(t.servers), p.forEach((e) => e()), !0);
|
|
69
|
+
}
|
|
70
|
+
function H() {
|
|
71
|
+
const t = M();
|
|
72
|
+
if (!t)
|
|
73
|
+
return () => {
|
|
74
|
+
};
|
|
75
|
+
if (i === t && s)
|
|
76
|
+
return s;
|
|
77
|
+
s == null || s();
|
|
78
|
+
const r = (o) => {
|
|
79
|
+
const n = w(o.data);
|
|
80
|
+
!n || n.type !== "local-mcps" || k(n);
|
|
81
|
+
};
|
|
82
|
+
t.addEventListener("message", r), i = t;
|
|
83
|
+
const e = () => {
|
|
84
|
+
t.removeEventListener("message", r), i === t && (i = void 0, s = void 0);
|
|
85
|
+
};
|
|
86
|
+
return s = e, e;
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
k as applyLocalMcpSnapshot,
|
|
90
|
+
H as connectLocalMcpBridge,
|
|
91
|
+
S as currentLocalMcpEndpoints,
|
|
92
|
+
E as loopbackMcpUrl,
|
|
93
|
+
B as subscribeLocalMcpEndpoints
|
|
94
|
+
};
|