@glodon-aiot/bot-client-sdk 3.26.0-alpha.21 → 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/dist/es/AgentSession.mjs +148 -129
- package/dist/es/Config.mjs +57 -53
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +47 -46
- package/dist/es/builtinTools/schemas.mjs +11 -11
- package/dist/es/localFiles/host/sandboxClient.mjs +237 -181
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +46 -39
- 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 +2 -2
- package/dist/lib/index.js +48 -43
- package/dist/src/AgentSession.d.ts +2 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +23 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +5 -2
- 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/package.json +2 -2
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,125 +1,127 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var L = Object.defineProperty, q = Object.defineProperties;
|
|
2
|
+
var j = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var P = Object.getOwnPropertySymbols;
|
|
4
4
|
var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var M = (
|
|
5
|
+
var M = (o, c, e) => c in o ? L(o, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[c] = e, h = (o, c) => {
|
|
6
6
|
for (var e in c || (c = {}))
|
|
7
|
-
F.call(c, e) && M(
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
N.call(c, e) && M(
|
|
11
|
-
return
|
|
12
|
-
}, w = (
|
|
13
|
-
var
|
|
14
|
-
var y = (
|
|
7
|
+
F.call(c, e) && M(o, e, c[e]);
|
|
8
|
+
if (P)
|
|
9
|
+
for (var e of P(c))
|
|
10
|
+
N.call(c, e) && M(o, e, c[e]);
|
|
11
|
+
return o;
|
|
12
|
+
}, w = (o, c) => q(o, j(c));
|
|
13
|
+
var R = (o, c, e) => (M(o, typeof c != "symbol" ? c + "" : c, e), e);
|
|
14
|
+
var y = (o, c, e) => new Promise((r, a) => {
|
|
15
15
|
var n = (i) => {
|
|
16
16
|
try {
|
|
17
17
|
s(e.next(i));
|
|
18
|
-
} catch (
|
|
19
|
-
a(
|
|
18
|
+
} catch (l) {
|
|
19
|
+
a(l);
|
|
20
20
|
}
|
|
21
21
|
}, t = (i) => {
|
|
22
22
|
try {
|
|
23
23
|
s(e.throw(i));
|
|
24
|
-
} catch (
|
|
25
|
-
a(
|
|
24
|
+
} catch (l) {
|
|
25
|
+
a(l);
|
|
26
26
|
}
|
|
27
|
-
}, s = (i) => i.done ?
|
|
28
|
-
s((e = e.apply(
|
|
27
|
+
}, s = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(n, t);
|
|
28
|
+
s((e = e.apply(o, c)).next());
|
|
29
29
|
});
|
|
30
|
-
import { ChatMessageRole as
|
|
30
|
+
import { ChatMessageRole as C, PromptVariableType as A } from "@glodon-aiot/apis";
|
|
31
31
|
import O from "./Logger.mjs";
|
|
32
|
-
import { configuration as
|
|
32
|
+
import { configuration as u } from "./Config.mjs";
|
|
33
33
|
import { io as U } from "socket.io-client";
|
|
34
|
-
import { UserMode as
|
|
35
|
-
import D, { SessionErrors as
|
|
34
|
+
import { UserMode as k } from "./PayloadTypes.mjs";
|
|
35
|
+
import D, { SessionErrors as I } from "./Session.mjs";
|
|
36
36
|
import V from "dayjs";
|
|
37
37
|
import { v4 as J } from "uuid";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
import { registerLocalMcp as Y } from "./localMcp/register.mjs";
|
|
39
|
+
const m = new O("[AgentSession] ");
|
|
40
|
+
function _(o) {
|
|
41
|
+
if (typeof o != "string")
|
|
42
|
+
return o;
|
|
43
|
+
const c = o.trim();
|
|
43
44
|
if (c)
|
|
44
45
|
try {
|
|
45
46
|
return JSON.parse(c);
|
|
46
47
|
} catch (e) {
|
|
47
|
-
return
|
|
48
|
+
return o;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
51
|
+
function T(o) {
|
|
52
|
+
return o == null || o === "" || typeof o == "object" && !Array.isArray(o) && Object.keys(o).length === 0;
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
-
const e = _(
|
|
55
|
-
if (!
|
|
54
|
+
function $(o, c) {
|
|
55
|
+
const e = _(o == null ? void 0 : o.query);
|
|
56
|
+
if (!T(e))
|
|
56
57
|
return e;
|
|
57
|
-
const
|
|
58
|
-
return
|
|
58
|
+
const r = _(c);
|
|
59
|
+
return T(r) && e != null ? e : r;
|
|
59
60
|
}
|
|
60
|
-
class
|
|
61
|
-
constructor(e,
|
|
62
|
-
super(e,
|
|
63
|
-
|
|
61
|
+
class se extends D {
|
|
62
|
+
constructor(e, r = "", a, n, t, s) {
|
|
63
|
+
super(e, r, a, n, t, s);
|
|
64
|
+
R(this, "inflightCalls", /* @__PURE__ */ new Set());
|
|
65
|
+
R(this, "localMcpTicket", 0);
|
|
64
66
|
}
|
|
65
67
|
prepareConnection() {
|
|
66
68
|
return new Promise((e) => y(this, null, function* () {
|
|
67
69
|
this.socket && e(!0);
|
|
68
|
-
const
|
|
70
|
+
const r = {
|
|
69
71
|
version: "1.0",
|
|
70
|
-
stream: JSON.stringify(
|
|
72
|
+
stream: JSON.stringify(u.stream),
|
|
71
73
|
appId: this._applicationId,
|
|
72
74
|
sessionId: this.id,
|
|
73
75
|
Authorization: `${this.token}`,
|
|
74
|
-
userMode:
|
|
75
|
-
}, a = new URL(
|
|
76
|
+
userMode: u.debug ? k.Debug : k.Normal
|
|
77
|
+
}, a = new URL(u.apiRoot), n = yield U(a.origin, {
|
|
76
78
|
path: a.pathname.replace("api", "socketio") + "/copilot",
|
|
77
|
-
query:
|
|
79
|
+
query: r,
|
|
78
80
|
transports: ["websocket"]
|
|
79
81
|
});
|
|
80
82
|
n.on("connect", () => {
|
|
81
|
-
|
|
83
|
+
m.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
|
|
82
84
|
}), n.on("disconnect", () => {
|
|
83
|
-
|
|
85
|
+
m.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
|
|
84
86
|
}), n.on("ready", (t) => {
|
|
85
87
|
if (t.code === 200) {
|
|
86
|
-
|
|
87
|
-
const s =
|
|
88
|
-
s ===
|
|
88
|
+
m.log("ready");
|
|
89
|
+
const s = u.debug ? k.Debug : k.Normal;
|
|
90
|
+
s === k.Debug && t.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
|
|
89
91
|
} else {
|
|
90
92
|
this._ready && (this._ready = !1);
|
|
91
93
|
const s = new Error(
|
|
92
|
-
|
|
94
|
+
I.SocketConnectionFailed
|
|
93
95
|
// , {
|
|
94
96
|
// cause: data,
|
|
95
97
|
// }
|
|
96
98
|
);
|
|
97
|
-
|
|
99
|
+
m.error("error", s), this.event.emit("error", s), e(!1);
|
|
98
100
|
}
|
|
99
101
|
}), n.on("action", (t, s) => y(this, null, function* () {
|
|
100
|
-
var
|
|
102
|
+
var S;
|
|
101
103
|
if (this._stopAnswer || !this.id)
|
|
102
104
|
return;
|
|
103
105
|
const {
|
|
104
106
|
type: i,
|
|
105
107
|
data: {
|
|
106
|
-
runnerIsClient:
|
|
107
|
-
pluginCode:
|
|
108
|
+
runnerIsClient: l,
|
|
109
|
+
pluginCode: d,
|
|
108
110
|
funcCode: g,
|
|
109
|
-
parameters:
|
|
110
|
-
requestBody:
|
|
111
|
+
parameters: f,
|
|
112
|
+
requestBody: E
|
|
111
113
|
}
|
|
112
|
-
} = t,
|
|
113
|
-
if (!
|
|
114
|
-
|
|
115
|
-
messageId:
|
|
114
|
+
} = t, p = this.messages[this.messages.length - 1];
|
|
115
|
+
if (!p.messageId)
|
|
116
|
+
p.actions || (p.actions = []), p.actions[t.data.step - 1] || (p.actions[t.data.step - 1] = []), p.actions[t.data.step - 1].push(t), this.event.emit("message:action", {
|
|
117
|
+
messageId: p.messageId,
|
|
116
118
|
action: t
|
|
117
|
-
}), this.event.emit("message:updated",
|
|
119
|
+
}), this.event.emit("message:updated", p);
|
|
118
120
|
else {
|
|
119
|
-
const
|
|
121
|
+
const v = {
|
|
120
122
|
messageId: "",
|
|
121
123
|
content: "",
|
|
122
|
-
role:
|
|
124
|
+
role: C.Robot,
|
|
123
125
|
sessionId: this.id,
|
|
124
126
|
reference: [],
|
|
125
127
|
searchReference: [],
|
|
@@ -131,14 +133,14 @@ class Z extends D {
|
|
|
131
133
|
},
|
|
132
134
|
isReplying: !0
|
|
133
135
|
};
|
|
134
|
-
this.pushMessage(
|
|
135
|
-
messageId:
|
|
136
|
+
this.pushMessage(v), this.event.emit("message:action", {
|
|
137
|
+
messageId: v.messageId,
|
|
136
138
|
action: t
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
if (this.inactivating) {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
+
const v = new Error(
|
|
143
|
+
I.Inactive
|
|
142
144
|
// {
|
|
143
145
|
// cause: {
|
|
144
146
|
// code: -1,
|
|
@@ -147,30 +149,30 @@ class Z extends D {
|
|
|
147
149
|
// },
|
|
148
150
|
// }
|
|
149
151
|
);
|
|
150
|
-
|
|
151
|
-
} else if (i === "FUNCTION_CALL" &&
|
|
152
|
-
|
|
153
|
-
${JSON.stringify(
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
152
|
+
m.warn("error", v), this.event.emit("error", v);
|
|
153
|
+
} else if (i === "FUNCTION_CALL" && l) {
|
|
154
|
+
m.log(`calling function ${g} of plugin ${d} with argument:
|
|
155
|
+
${JSON.stringify(f)}`);
|
|
156
|
+
const v = (S = u.plugins) == null ? void 0 : S[d];
|
|
157
|
+
if (!v) {
|
|
156
158
|
s({
|
|
157
159
|
code: 404,
|
|
158
160
|
message: "没有找到插件。"
|
|
159
161
|
});
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
|
-
const
|
|
163
|
-
if (typeof
|
|
164
|
+
const b = v[g];
|
|
165
|
+
if (typeof b != "function") {
|
|
164
166
|
s({
|
|
165
167
|
code: 404,
|
|
166
168
|
message: "没有找到插件方法。"
|
|
167
169
|
});
|
|
168
170
|
return;
|
|
169
171
|
}
|
|
170
|
-
const
|
|
171
|
-
this.invokeClientPlugin(
|
|
172
|
+
const x = $(f, E);
|
|
173
|
+
this.invokeClientPlugin(b, x, s, {
|
|
172
174
|
requestId: t.requestId,
|
|
173
|
-
pluginCode:
|
|
175
|
+
pluginCode: d,
|
|
174
176
|
functionCode: g
|
|
175
177
|
});
|
|
176
178
|
}
|
|
@@ -178,12 +180,12 @@ class Z extends D {
|
|
|
178
180
|
if (!this._stopAnswer)
|
|
179
181
|
if (t.data.code !== 200 && (t.data.index = -1), t.data.stream || t.data.stream === void 0) {
|
|
180
182
|
let s = this.messages[this.messages.length - 1];
|
|
181
|
-
if (s && s.role ===
|
|
183
|
+
if (s && s.role === C.Robot)
|
|
182
184
|
this.handleStreamAnswer(t.data, s), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s), s.index === -1 && (s.isReplying = !1, this.event.emit("answer:finish", s));
|
|
183
185
|
else {
|
|
184
186
|
const i = {
|
|
185
187
|
content: "",
|
|
186
|
-
role:
|
|
188
|
+
role: C.Robot,
|
|
187
189
|
reference: [],
|
|
188
190
|
searchReference: [],
|
|
189
191
|
messageId: "",
|
|
@@ -205,15 +207,15 @@ class Z extends D {
|
|
|
205
207
|
};
|
|
206
208
|
this.handleStreamAnswer(t.data, i), this.pushMessage(i), this.event.emit("message:content", i), i.index === -1 && (i.isReplying = !1, this.event.emit("answer:finish", i));
|
|
207
209
|
}
|
|
208
|
-
} else if (t.data.updateSession && this.data && (this.data =
|
|
210
|
+
} else if (t.data.updateSession && this.data && (this.data = h(h({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
|
|
209
211
|
let s = this.messages[this.messages.length - 1];
|
|
210
212
|
if (s && !s.messageId)
|
|
211
|
-
s =
|
|
213
|
+
s = h(h({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
|
|
212
214
|
else {
|
|
213
|
-
const i =
|
|
215
|
+
const i = h({
|
|
214
216
|
messageId: "",
|
|
215
217
|
content: "",
|
|
216
|
-
role:
|
|
218
|
+
role: C.Robot,
|
|
217
219
|
sessionId: this.id,
|
|
218
220
|
reference: [],
|
|
219
221
|
searchReference: [],
|
|
@@ -229,10 +231,10 @@ class Z extends D {
|
|
|
229
231
|
}
|
|
230
232
|
} else {
|
|
231
233
|
let s = this.messages[this.messages.length - 1];
|
|
232
|
-
s && !s.messageId ? (s =
|
|
234
|
+
s && !s.messageId ? (s = h(h({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(h({
|
|
233
235
|
messageId: "",
|
|
234
236
|
content: "",
|
|
235
|
-
role:
|
|
237
|
+
role: C.Robot,
|
|
236
238
|
sessionId: this.id,
|
|
237
239
|
reference: [],
|
|
238
240
|
searchReference: [],
|
|
@@ -249,28 +251,28 @@ class Z extends D {
|
|
|
249
251
|
if (this._stopAnswer)
|
|
250
252
|
return;
|
|
251
253
|
if (!this.id) {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
+
const f = new Error(
|
|
255
|
+
I.IdUndefined
|
|
254
256
|
// {
|
|
255
257
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
256
258
|
// }
|
|
257
259
|
);
|
|
258
|
-
|
|
260
|
+
m.error(f), this.event.emit("error", f), this.frozen = !1;
|
|
259
261
|
return;
|
|
260
262
|
}
|
|
261
263
|
const {
|
|
262
264
|
type: s,
|
|
263
265
|
data: i,
|
|
264
|
-
requestId:
|
|
265
|
-
} = t,
|
|
266
|
-
if (
|
|
266
|
+
requestId: l
|
|
267
|
+
} = t, d = this.messages.findIndex((f) => f.messageId === l && f.role === C.User);
|
|
268
|
+
if (d < 0)
|
|
267
269
|
return;
|
|
268
|
-
const g =
|
|
270
|
+
const g = d + 1;
|
|
269
271
|
if (g >= this.messages.length) {
|
|
270
|
-
const
|
|
272
|
+
const f = {
|
|
271
273
|
messageId: "",
|
|
272
274
|
content: "",
|
|
273
|
-
role:
|
|
275
|
+
role: C.Robot,
|
|
274
276
|
sessionId: this.id,
|
|
275
277
|
reference: [],
|
|
276
278
|
searchReference: [],
|
|
@@ -282,59 +284,76 @@ class Z extends D {
|
|
|
282
284
|
},
|
|
283
285
|
isReplying: !0
|
|
284
286
|
};
|
|
285
|
-
this.pushMessage(
|
|
287
|
+
this.pushMessage(f);
|
|
286
288
|
}
|
|
287
|
-
s === "KG" ? (this.messages[g] = w(
|
|
289
|
+
s === "KG" ? (this.messages[g] = w(h({}, this.messages[g]), {
|
|
288
290
|
reference: i.knowledgeReference
|
|
289
|
-
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(
|
|
291
|
+
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(h({}, this.messages[g]), {
|
|
290
292
|
searchReference: i.knowledgeReference
|
|
291
293
|
}), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
292
294
|
})), this.socket = n, n.open();
|
|
293
295
|
}));
|
|
294
296
|
}
|
|
295
297
|
registerMcpFromClientConfig() {
|
|
296
|
-
return
|
|
298
|
+
return u.mcp ? new Promise((e, r) => {
|
|
297
299
|
if (!this.socket) {
|
|
298
|
-
|
|
300
|
+
r("socket is undefined");
|
|
299
301
|
return;
|
|
300
302
|
}
|
|
301
|
-
this.socket.emit("add_mcp_servers",
|
|
303
|
+
this.socket.emit("add_mcp_servers", u.mcp, (a) => {
|
|
302
304
|
a.code === 200 ? (Object.keys(a.data).forEach((n) => {
|
|
303
305
|
a.data[n].code !== 200 && console.error(n, "MCP Server 注册失败。", a.data[n]);
|
|
304
|
-
}), e(!0)) : (console.error("MCP Server 注册失败。", a),
|
|
306
|
+
}), e(!0)) : (console.error("MCP Server 注册失败。", a), r(a));
|
|
305
307
|
});
|
|
306
308
|
}) : Promise.resolve(!0);
|
|
307
309
|
}
|
|
310
|
+
registerLocalMcp() {
|
|
311
|
+
var a, n;
|
|
312
|
+
const e = this.socket;
|
|
313
|
+
if (!e)
|
|
314
|
+
return;
|
|
315
|
+
const r = ++this.localMcpTicket;
|
|
316
|
+
Y({
|
|
317
|
+
arrange: (n = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : n[0],
|
|
318
|
+
initMcp: u.mcp,
|
|
319
|
+
apiRoot: u.apiRoot,
|
|
320
|
+
token: this.token,
|
|
321
|
+
socket: e,
|
|
322
|
+
isCurrent: () => r === this.localMcpTicket
|
|
323
|
+
}).catch((t) => {
|
|
324
|
+
m.error("local mcp", t instanceof Error ? t.message : String(t));
|
|
325
|
+
});
|
|
326
|
+
}
|
|
308
327
|
addMcpServers(e) {
|
|
309
328
|
return y(this, null, function* () {
|
|
310
|
-
return this.ready ? this.socket ? new Promise((
|
|
329
|
+
return this.ready ? this.socket ? new Promise((r, a) => {
|
|
311
330
|
this.socket && this.socket.emit("add_mcp_servers", e, (n) => {
|
|
312
331
|
n.code === 200 ? (Object.keys(n.data).forEach((t) => {
|
|
313
332
|
n.data[t].code !== 200 && console.error(t, "MCP Server 注册失败。", n.data[t]);
|
|
314
|
-
}),
|
|
333
|
+
}), r(!0)) : (console.error("MCP Server 注册失败。", n), a(n));
|
|
315
334
|
});
|
|
316
335
|
}) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
|
|
317
336
|
});
|
|
318
337
|
}
|
|
319
338
|
listMcpServers() {
|
|
320
339
|
return y(this, null, function* () {
|
|
321
|
-
return this.ready ? this.socket ? new Promise((e,
|
|
340
|
+
return this.ready ? this.socket ? new Promise((e, r) => {
|
|
322
341
|
this.socket && this.socket.emit("list_mcp_servers", (a) => {
|
|
323
|
-
a.code === 200 ? e(a.data) :
|
|
342
|
+
a.code === 200 ? e(a.data) : r(a);
|
|
324
343
|
});
|
|
325
344
|
}) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
|
|
326
345
|
});
|
|
327
346
|
}
|
|
328
|
-
sendQuestion(e,
|
|
347
|
+
sendQuestion(e, r) {
|
|
329
348
|
return y(this, null, function* () {
|
|
330
349
|
var n, t, s;
|
|
331
350
|
this.convertKnowledgesToChatFormat(this.knowledges);
|
|
332
|
-
let a = w(
|
|
333
|
-
promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i,
|
|
334
|
-
[
|
|
351
|
+
let a = w(h({}, e), {
|
|
352
|
+
promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, l) => w(h({}, i), {
|
|
353
|
+
[l.key]: l.value
|
|
335
354
|
}), {}),
|
|
336
|
-
systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i,
|
|
337
|
-
[
|
|
355
|
+
systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, l) => w(h({}, i), {
|
|
356
|
+
[l.key]: l.value
|
|
338
357
|
}), {}),
|
|
339
358
|
knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
|
|
340
359
|
//agent支持指定文件时再放开
|
|
@@ -344,12 +363,12 @@ class Z extends D {
|
|
|
344
363
|
if (!this.active) {
|
|
345
364
|
if (yield this.activate(), !this.socket) {
|
|
346
365
|
const i = new Error(
|
|
347
|
-
|
|
366
|
+
I.SocketConnectionFailed
|
|
348
367
|
// {
|
|
349
368
|
// cause: { code: -1, message: 'socket is null' },
|
|
350
369
|
// }
|
|
351
370
|
);
|
|
352
|
-
return
|
|
371
|
+
return m.warn("error", i), this.event.emit("error", i), !1;
|
|
353
372
|
}
|
|
354
373
|
(t = this.socket) == null || t.emit("question", a);
|
|
355
374
|
return;
|
|
@@ -361,13 +380,13 @@ class Z extends D {
|
|
|
361
380
|
* 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
|
|
362
381
|
* 停止回答或调用被取消后不再回传。
|
|
363
382
|
*/
|
|
364
|
-
invokeClientPlugin(e,
|
|
383
|
+
invokeClientPlugin(e, r, a, n) {
|
|
365
384
|
const t = new AbortController();
|
|
366
385
|
this.inflightCalls.add(t);
|
|
367
386
|
let s = !1;
|
|
368
|
-
const i = (...
|
|
369
|
-
s || (s = !0, this.inflightCalls.delete(t), !(this._stopAnswer || t.signal.aborted) && a(...
|
|
370
|
-
},
|
|
387
|
+
const i = (...d) => {
|
|
388
|
+
s || (s = !0, this.inflightCalls.delete(t), !(this._stopAnswer || t.signal.aborted) && a(...d));
|
|
389
|
+
}, l = {
|
|
371
390
|
requestId: n.requestId || J(),
|
|
372
391
|
applicationId: this._applicationId,
|
|
373
392
|
sessionId: this.id,
|
|
@@ -376,15 +395,15 @@ class Z extends D {
|
|
|
376
395
|
signal: t.signal
|
|
377
396
|
};
|
|
378
397
|
try {
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
398
|
+
const d = e(r, i, l);
|
|
399
|
+
d && typeof d.catch == "function" && d.catch((g) => {
|
|
400
|
+
m.error("client plugin failed", g), i({
|
|
382
401
|
code: 500,
|
|
383
402
|
message: "客户端插件执行失败。"
|
|
384
403
|
});
|
|
385
404
|
});
|
|
386
|
-
} catch (
|
|
387
|
-
|
|
405
|
+
} catch (d) {
|
|
406
|
+
m.error("client plugin failed", d), i({
|
|
388
407
|
code: 500,
|
|
389
408
|
message: "客户端插件执行失败。"
|
|
390
409
|
});
|
|
@@ -392,7 +411,7 @@ class Z extends D {
|
|
|
392
411
|
}
|
|
393
412
|
abortClientPluginCalls() {
|
|
394
413
|
const e = Array.from(this.inflightCalls);
|
|
395
|
-
this.inflightCalls.clear(), e.forEach((
|
|
414
|
+
this.inflightCalls.clear(), e.forEach((r) => r.abort());
|
|
396
415
|
}
|
|
397
416
|
stopAnswer() {
|
|
398
417
|
var e;
|
|
@@ -405,12 +424,12 @@ class Z extends D {
|
|
|
405
424
|
return this.abortClientPluginCalls(), super.destroy();
|
|
406
425
|
}
|
|
407
426
|
convertKnowledgesToChatFormat(e) {
|
|
408
|
-
return e ? e.map((
|
|
409
|
-
id:
|
|
410
|
-
fileIds:
|
|
411
|
-
} :
|
|
427
|
+
return e ? e.map((r) => r != null && r.fileIds ? {
|
|
428
|
+
id: r.id,
|
|
429
|
+
fileIds: r.fileIds
|
|
430
|
+
} : r.id) : [];
|
|
412
431
|
}
|
|
413
432
|
}
|
|
414
433
|
export {
|
|
415
|
-
|
|
434
|
+
se as default
|
|
416
435
|
};
|
package/dist/es/Config.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var L = Object.defineProperty, B = Object.defineProperties;
|
|
2
|
+
var R = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var b = Object.getOwnPropertySymbols;
|
|
4
|
+
var w = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var P = (e, o, i) => o in e ? L(e, o, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[o] = i, c = (e, o) => {
|
|
6
|
+
for (var i in o || (o = {}))
|
|
7
|
+
w.call(o, i) && P(e, i, o[i]);
|
|
8
|
+
if (b)
|
|
9
|
+
for (var i of b(o))
|
|
10
|
+
k.call(o, i) && P(e, i, o[i]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
import
|
|
14
|
-
import { LOCAL_FILES_PLUGIN_CODES as
|
|
15
|
-
import { createBuiltinToolsPlugin as
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
}, h = (e, o) => B(e, R(o));
|
|
13
|
+
import r from "./Logger.mjs";
|
|
14
|
+
import { LOCAL_FILES_PLUGIN_CODES as E } from "./localFiles/constants.mjs";
|
|
15
|
+
import { createBuiltinToolsPlugin as I } from "./builtinTools/createBuiltinToolsPlugin.mjs";
|
|
16
|
+
import { applyLocalMcpPlugins as S } from "./localMcp/registry.mjs";
|
|
17
|
+
const T = new r("[Config] ");
|
|
18
|
+
var C = /* @__PURE__ */ ((e) => (e.dev = "https://aiot-dev.glodon.com/api/cvforcepd", e.test = "https://aiot-dev.glodon.com/api/cvforce", e.prod = "https://copilot.glodon.com/api/cvforce", e.local = "http://localhost:3000/api/cvforcepd", e))(C || {});
|
|
18
19
|
let n = {
|
|
19
20
|
debug: !1,
|
|
20
21
|
env: "prod",
|
|
@@ -30,59 +31,62 @@ let n = {
|
|
|
30
31
|
mcp: void 0,
|
|
31
32
|
loadRelatedQuesions: !0,
|
|
32
33
|
stream: !1
|
|
33
|
-
}, u,
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
u !== e && (u = e,
|
|
34
|
+
}, u, l;
|
|
35
|
+
const f = /* @__PURE__ */ new Set();
|
|
36
|
+
function G(e) {
|
|
37
|
+
u !== e && (u = e, l = void 0, f.clear());
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
-
if (!
|
|
39
|
+
function M() {
|
|
40
|
+
if (!l)
|
|
40
41
|
return;
|
|
41
42
|
const {
|
|
42
43
|
pluginCode: e,
|
|
43
|
-
table:
|
|
44
|
-
} =
|
|
45
|
-
if (!(!
|
|
44
|
+
table: o
|
|
45
|
+
} = l, i = n.plugins[e], t = o[e];
|
|
46
|
+
if (!(!i || i.shell !== t.shell))
|
|
46
47
|
return e;
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
return (e == null ? void 0 : e.pluginCode) ||
|
|
49
|
+
function _(e, o) {
|
|
50
|
+
return (e == null ? void 0 : e.pluginCode) || E[o];
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
-
var
|
|
53
|
-
const e = (
|
|
54
|
-
if (!!!(
|
|
55
|
-
return
|
|
52
|
+
function O() {
|
|
53
|
+
var p, v;
|
|
54
|
+
const e = (p = n.businessPlugins) != null ? p : {}, o = (v = n.builtinPlugins) == null ? void 0 : v.localFiles, i = [], t = c({}, e);
|
|
55
|
+
if (!!!(o != null && o.enabled))
|
|
56
|
+
return g(t), i;
|
|
56
57
|
if (!u)
|
|
57
|
-
return
|
|
58
|
-
const
|
|
59
|
-
return
|
|
58
|
+
return i.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), g(t), i;
|
|
59
|
+
const s = o != null && o.enabled ? _(o, n.env) : void 0;
|
|
60
|
+
return s ? e[s] ? i.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== u || l.pluginCode !== s) && (l = {
|
|
60
61
|
workspace: u,
|
|
61
|
-
pluginCode:
|
|
62
|
-
table:
|
|
63
|
-
pluginCode:
|
|
62
|
+
pluginCode: s,
|
|
63
|
+
table: I({
|
|
64
|
+
pluginCode: s,
|
|
64
65
|
workspace: u
|
|
65
66
|
})
|
|
66
|
-
}), t[
|
|
67
|
+
}), t[s] = l.table[s]) : i.push(`[BuiltinTools] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), g(t), i;
|
|
67
68
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
69
|
+
function g(e) {
|
|
70
|
+
S(e), n.plugins = e;
|
|
70
71
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
function W() {
|
|
73
|
+
return O().filter((e) => !f.has(e)).map((e) => (f.add(e), console.error(e), new Error(e)));
|
|
74
|
+
}
|
|
75
|
+
function N(e, o = {}) {
|
|
76
|
+
var i, t, d;
|
|
77
|
+
r.debug = (e == null ? void 0 : e.debug) || !1, n = h(c(c({}, n), e), {
|
|
78
|
+
apiRoot: (e == null ? void 0 : e.apiRoot) || n.apiRoot || (e != null && e.env ? C[e.env || "prod"] : n.apiRoot),
|
|
75
79
|
// 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
|
|
76
|
-
businessPlugins: (t = (
|
|
80
|
+
businessPlugins: (t = (i = e == null ? void 0 : e.plugins) != null ? i : n.businessPlugins) != null ? t : {},
|
|
77
81
|
builtinPlugins: (d = e == null ? void 0 : e.builtinPlugins) != null ? d : n.builtinPlugins
|
|
78
|
-
}),
|
|
82
|
+
}), o.refreshBuiltinPlugins !== !1 && W(), r.debug && T.log("updated", n);
|
|
79
83
|
}
|
|
80
84
|
export {
|
|
81
|
-
|
|
85
|
+
C as ApiUrl,
|
|
82
86
|
n as configuration,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
N as configure,
|
|
88
|
+
M as getRegisteredLocalFilesPluginCode,
|
|
89
|
+
W as refreshBuiltinPlugins,
|
|
90
|
+
_ as resolveLocalFilesPluginCode,
|
|
91
|
+
G as setActiveLocalWorkspace
|
|
88
92
|
};
|