@glodon-aiot/bot-client-sdk 3.26.0-alpha.23 → 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.
- package/README.md +180 -130
- package/dist/es/AgentSession.mjs +148 -129
- package/dist/es/BotClient.mjs +154 -136
- package/dist/es/Config.mjs +56 -89
- package/dist/es/Session.mjs +35 -23
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +262 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +69 -0
- package/dist/es/builtinTools/platformSkills.mjs +210 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +494 -0
- package/dist/es/index.mjs +66 -64
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
- package/dist/es/localFiles/constants.mjs +24 -29
- package/dist/es/localFiles/errors.mjs +21 -19
- package/dist/es/localFiles/host/connectHostBridge.mjs +37 -34
- package/dist/es/localFiles/host/protocol.mjs +27 -13
- package/dist/es/localFiles/host/sandboxClient.mjs +476 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +40 -86
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +167 -86
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +223 -0
- package/dist/es/localMcp/register.mjs +155 -0
- package/dist/es/localMcp/registry.mjs +39 -0
- package/dist/es/package.json.mjs +38 -29
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/lib/index.js +379 -10
- package/dist/src/AgentSession.d.ts +2 -0
- package/dist/src/Config.d.ts +5 -7
- package/dist/src/Session.d.ts +6 -0
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +35 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +16 -0
- package/dist/src/builtinTools/platformSkills.d.ts +67 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +64 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
- package/dist/src/localFiles/constants.d.ts +3 -13
- package/dist/src/localFiles/host/protocol.d.ts +34 -16
- package/dist/src/localFiles/host/sandboxClient.d.ts +104 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +11 -6
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +2 -5
- package/dist/src/localFiles/types.d.ts +16 -23
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +11 -0
- package/dist/src/localMcp/register.d.ts +32 -0
- package/dist/src/localMcp/registry.d.ts +26 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/package.json +13 -4
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
|
@@ -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
|
+
};
|
package/dist/es/package.json.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const e = "@glodon-aiot/bot-client-sdk",
|
|
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",
|
|
5
5
|
"sdk"
|
|
6
|
-
],
|
|
6
|
+
], d = [
|
|
7
7
|
"dist"
|
|
8
|
-
], p = "./dist/es/index.mjs",
|
|
8
|
+
], p = "./dist/es/index.mjs", l = "./dist/lib/index.js", c = "./dist/src/index.d.ts", r = {
|
|
9
9
|
".": {
|
|
10
10
|
import: "./dist/es/index.mjs",
|
|
11
11
|
require: "./dist/lib/index.js",
|
|
@@ -22,8 +22,14 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.23", i = "glodoncv",
|
|
|
22
22
|
preview: "vite preview",
|
|
23
23
|
check: "yarn prettier --check .",
|
|
24
24
|
write: "yarn prettier --write .",
|
|
25
|
-
lint: "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js"
|
|
26
|
-
|
|
25
|
+
lint: "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
|
|
26
|
+
"build:just-bash": "node scripts/build-just-bash.mjs",
|
|
27
|
+
"upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
|
|
28
|
+
"build:pyodide": "node scripts/build-pyodide.mjs",
|
|
29
|
+
"upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
|
|
30
|
+
test: "vitest run",
|
|
31
|
+
"test:watch": "vitest"
|
|
32
|
+
}, b = {
|
|
27
33
|
"@babel/core": "^7.20.12",
|
|
28
34
|
"@commitlint/cli": "^17.0.3",
|
|
29
35
|
"@commitlint/config-conventional": "^17.0.3",
|
|
@@ -45,8 +51,10 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.23", i = "glodoncv",
|
|
|
45
51
|
express: "4",
|
|
46
52
|
"http-proxy-middleware": "^3.0.0",
|
|
47
53
|
"identity-obj-proxy": "^3.0.0",
|
|
54
|
+
"just-bash": "3.6.0",
|
|
48
55
|
"npm-run-all": "^4.1.5",
|
|
49
56
|
prettier: "2.7.1",
|
|
57
|
+
pyodide: "314.0.7",
|
|
50
58
|
"rollup-plugin-visualizer": "^6.0.1",
|
|
51
59
|
"socket.io": "^4.7.5",
|
|
52
60
|
"ts-node": "^10.9.2",
|
|
@@ -54,57 +62,58 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.23", i = "glodoncv",
|
|
|
54
62
|
vite: "^4.1.1",
|
|
55
63
|
"vite-plugin-dts": "^4.3.0",
|
|
56
64
|
"vite-plugin-externalize-deps": "^0.9.0",
|
|
57
|
-
"vite-tsconfig-paths": "^5.1.4"
|
|
65
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
66
|
+
vitest: "^0.34.6"
|
|
58
67
|
}, m = {
|
|
59
68
|
access: "public",
|
|
60
69
|
registry: "https://registry.npmjs.org/"
|
|
61
|
-
},
|
|
62
|
-
"@glodon-aiot/apis": "^3.26.0-alpha.
|
|
70
|
+
}, y = {
|
|
71
|
+
"@glodon-aiot/apis": "^3.26.0-alpha.24",
|
|
63
72
|
axios: "0.24.0",
|
|
64
73
|
buffer: "^6.0.3",
|
|
65
74
|
dayjs: "^1.11.13",
|
|
66
75
|
"js-base64": "^3.7.7",
|
|
67
76
|
"socket.io-client": "^4.7.5",
|
|
68
77
|
uuid: "^11.1.0"
|
|
69
|
-
},
|
|
78
|
+
}, j = {
|
|
70
79
|
name: e,
|
|
71
|
-
version:
|
|
72
|
-
author:
|
|
73
|
-
description:
|
|
80
|
+
version: s,
|
|
81
|
+
author: t,
|
|
82
|
+
description: i,
|
|
74
83
|
type: n,
|
|
75
84
|
sideEffects: !1,
|
|
76
85
|
keywords: o,
|
|
77
|
-
files:
|
|
86
|
+
files: d,
|
|
78
87
|
module: p,
|
|
79
|
-
main:
|
|
80
|
-
typings:
|
|
81
|
-
exports:
|
|
88
|
+
main: l,
|
|
89
|
+
typings: c,
|
|
90
|
+
exports: r,
|
|
82
91
|
license: a,
|
|
83
92
|
scripts: u,
|
|
84
|
-
devDependencies:
|
|
93
|
+
devDependencies: b,
|
|
85
94
|
"lint-staged": {
|
|
86
95
|
"*.{js,css,md,jsx,less,ts,tsx,json}": "prettier --write"
|
|
87
96
|
},
|
|
88
97
|
publishConfig: m,
|
|
89
|
-
dependencies:
|
|
98
|
+
dependencies: y
|
|
90
99
|
};
|
|
91
100
|
export {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
t as author,
|
|
102
|
+
j as default,
|
|
103
|
+
y as dependencies,
|
|
104
|
+
i as description,
|
|
105
|
+
b as devDependencies,
|
|
106
|
+
r as exports,
|
|
107
|
+
d as files,
|
|
99
108
|
o as keywords,
|
|
100
109
|
a as license,
|
|
101
|
-
|
|
110
|
+
l as main,
|
|
102
111
|
p as module,
|
|
103
112
|
e as name,
|
|
104
113
|
m as publishConfig,
|
|
105
114
|
u as scripts,
|
|
106
|
-
|
|
115
|
+
g as sideEffects,
|
|
107
116
|
n as type,
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
c as typings,
|
|
118
|
+
s as version
|
|
110
119
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var l = (t, e, o) => new Promise((c, n) => {
|
|
2
|
+
var p = (i) => {
|
|
3
|
+
try {
|
|
4
|
+
s(o.next(i));
|
|
5
|
+
} catch (a) {
|
|
6
|
+
n(a);
|
|
7
|
+
}
|
|
8
|
+
}, r = (i) => {
|
|
9
|
+
try {
|
|
10
|
+
s(o.throw(i));
|
|
11
|
+
} catch (a) {
|
|
12
|
+
n(a);
|
|
13
|
+
}
|
|
14
|
+
}, s = (i) => i.done ? c(i.value) : Promise.resolve(i.value).then(p, r);
|
|
15
|
+
s((o = o.apply(t, e)).next());
|
|
16
|
+
});
|
|
17
|
+
import { v4 as u } from "uuid";
|
|
18
|
+
function $(t, e, o) {
|
|
19
|
+
return l(this, null, function* () {
|
|
20
|
+
var s;
|
|
21
|
+
if (!e)
|
|
22
|
+
throw new Error("session is not avalible. id is undefined");
|
|
23
|
+
const c = d(o.name), n = yield t.postUploadTicket({
|
|
24
|
+
files: [c],
|
|
25
|
+
isv: "minio",
|
|
26
|
+
knowledgeId: e,
|
|
27
|
+
type: 1
|
|
28
|
+
}), r = (yield t.uploadMinioFile(n.minio, o)) || ((s = n.minio.fileKeys) == null ? void 0 : s[0]);
|
|
29
|
+
return {
|
|
30
|
+
url: f(n.minio, r),
|
|
31
|
+
name: o.name || c,
|
|
32
|
+
size: o.size
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function d(t) {
|
|
37
|
+
const e = t.split(/[/\\]/).pop() || "", o = /\.([A-Za-z0-9]{1,16})$/.exec(e);
|
|
38
|
+
return o ? `${u()}.${o[1].toLowerCase()}` : u();
|
|
39
|
+
}
|
|
40
|
+
function f(t, e) {
|
|
41
|
+
var n;
|
|
42
|
+
const o = (n = t.endpoints) == null ? void 0 : n[0];
|
|
43
|
+
if (!o || !t.bucket || !e)
|
|
44
|
+
throw new Error("上传没有返回文件地址。");
|
|
45
|
+
return `${t.useSSL ? "https:" : typeof location != "undefined" && location.protocol ? location.protocol : "http:"}//${o}/${t.bucket}/${e}`;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
$ as uploadSessionFile
|
|
49
|
+
};
|