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