@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.
@@ -1,47 +1,47 @@
1
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) => {
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
- 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]);
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, O(o));
13
- var l = (t, o, e) => new Promise((r, n) => {
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
- a(e.next(s));
17
- } catch (d) {
18
- n(d);
16
+ c(e.next(s));
17
+ } catch (f) {
18
+ r(f);
19
19
  }
20
- }, c = (s) => {
20
+ }, a = (s) => {
21
21
  try {
22
- a(e.throw(s));
23
- } catch (d) {
24
- n(d);
22
+ c(e.throw(s));
23
+ } catch (f) {
24
+ r(f);
25
25
  }
26
- }, a = (s) => s.done ? r(s.value) : Promise.resolve(s.value).then(i, c);
27
- a((e = e.apply(t, o)).next());
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 m = /* @__PURE__ */ new Map(), P = 2e4;
30
- function k(t) {
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(P);
32
+ const o = AbortSignal.timeout(N);
33
33
  if (!t)
34
34
  return o;
35
- const e = new AbortController(), r = () => e.abort();
36
- return o.addEventListener("abort", r, {
35
+ const e = new AbortController(), n = () => e.abort();
36
+ return o.addEventListener("abort", n, {
37
37
  once: !0
38
- }), t.addEventListener("abort", r, {
38
+ }), t.addEventListener("abort", n, {
39
39
  once: !0
40
40
  }), e.signal;
41
41
  }
42
42
  return t;
43
43
  }
44
- function M(t) {
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 r = e.length - 1; r >= 0; r -= 1) {
56
- const n = e[r].split(`
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 (n.startsWith("{") || n.startsWith("["))
60
- return JSON.parse(n);
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 l(this, null, function* () {
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(), r = new TextDecoder();
78
- let n = "";
77
+ const e = t.body.getReader(), n = new TextDecoder();
78
+ let r = "";
79
79
  try {
80
- for (; n.length < 2e6; ) {
80
+ for (; r.length < 2e6; ) {
81
81
  const {
82
82
  done: i,
83
- value: c
83
+ value: a
84
84
  } = yield e.read();
85
85
  if (i)
86
86
  break;
87
- n += r.decode(c, {
87
+ r += n.decode(a, {
88
88
  stream: !0
89
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];
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 n;
94
+ return r;
95
95
  } finally {
96
96
  yield e.cancel().catch(() => {
97
97
  });
98
98
  }
99
99
  });
100
100
  }
101
- function w(t, o, e, r, n) {
102
- return l(this, null, function* () {
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 c = yield n(t.url, {
108
+ const a = yield r(t.url, {
109
109
  method: "POST",
110
110
  headers: i,
111
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;
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 h(t) {
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 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;
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
- }, c = yield w(t, {
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 a = h(c);
154
- if (a)
155
- throw new Error(a);
156
- const s = c.result;
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 d = s.protocolVersion;
159
- typeof d == "string" && d && (i.protocol = d);
158
+ const f = s.protocolVersion;
159
+ typeof f == "string" && f && (i.protocol = f);
160
160
  }
161
- return yield w(t, {
161
+ return yield h(t, {
162
162
  jsonrpc: "2.0",
163
163
  method: "notifications/initialized"
164
- }, i, o, e), m.set(r, i), i;
164
+ }, i, o, e), d.set(n, i), i;
165
165
  });
166
166
  }
167
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, {
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: r.nextId,
172
+ id: n.nextId,
173
173
  method: "tools/list",
174
174
  params: {}
175
- }, r, void 0, o);
176
- r.nextId += 1;
177
- const i = h(n);
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 c = n.result;
181
- return ((a = c == null ? void 0 : c.tools) != null ? a : []).filter((s) => s.name).map((s) => ({
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, 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, {
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, r, n);
204
- let f;
203
+ }, p, n, r);
204
+ let l;
205
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;
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 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);
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
+ };