@glodon-aiot/bot-client-sdk 3.26.0-alpha.33 → 3.26.0-alpha.34
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 +230 -214
- package/dist/es/BotClient.mjs +127 -85
- package/dist/es/Config.mjs +42 -42
- package/dist/es/DialogSession.mjs +121 -116
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +306 -277
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +69 -69
- package/dist/es/builtinTools/platformSkills.mjs +85 -59
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +39 -34
- package/dist/es/localMcp/register.mjs +3 -3
- package/dist/es/package.json.mjs +28 -50
- package/dist/lib/index.js +44 -44
- package/dist/src/AgentSession.d.ts +1 -0
- package/dist/src/BotClient.d.ts +6 -1
- package/dist/src/Config.d.ts +2 -1
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/Session.d.ts +4 -2
- package/dist/src/builtinTools/platformSkills.d.ts +22 -1
- package/dist/src/constant.d.ts +1 -1
- package/package.json +3 -25
package/dist/es/Session.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
var T = Object.defineProperty,
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var R = Object.prototype.hasOwnProperty,
|
|
5
|
-
var
|
|
1
|
+
var T = Object.defineProperty, M = Object.defineProperties;
|
|
2
|
+
var O = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var x = Object.getOwnPropertySymbols;
|
|
4
|
+
var R = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var k = (p, e, t) => e in p ? T(p, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[e] = t, u = (p, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
R.call(e, t) &&
|
|
8
|
-
if (
|
|
9
|
-
for (var t of
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}, y = (
|
|
13
|
-
var
|
|
14
|
-
var c = (
|
|
15
|
-
var n = (
|
|
7
|
+
R.call(e, t) && k(p, t, e[t]);
|
|
8
|
+
if (x)
|
|
9
|
+
for (var t of x(e))
|
|
10
|
+
z.call(e, t) && k(p, t, e[t]);
|
|
11
|
+
return p;
|
|
12
|
+
}, y = (p, e) => M(p, O(e));
|
|
13
|
+
var f = (p, e, t) => (k(p, typeof e != "symbol" ? e + "" : e, t), t);
|
|
14
|
+
var c = (p, e, t) => new Promise((i, o) => {
|
|
15
|
+
var n = (a) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
d(t.next(a));
|
|
18
|
+
} catch (s) {
|
|
19
|
+
o(s);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, h = (a) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
d(t.throw(a));
|
|
24
|
+
} catch (s) {
|
|
25
|
+
o(s);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, d = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(n, h);
|
|
28
|
+
d((t = t.apply(p, e)).next());
|
|
29
29
|
});
|
|
30
|
-
import { v4 as
|
|
31
|
-
import { parseJWT as
|
|
32
|
-
import { ApplicationTypes as
|
|
33
|
-
import
|
|
34
|
-
import { configuration as
|
|
35
|
-
import
|
|
36
|
-
import { getCVForceService as
|
|
37
|
-
import
|
|
38
|
-
import { uploadSessionFile as
|
|
39
|
-
const V = 100,
|
|
40
|
-
var
|
|
41
|
-
class
|
|
30
|
+
import { v4 as Q } from "uuid";
|
|
31
|
+
import { parseJWT as P, resolveRelatedQuestionContent as F, removeNewlines as q, removeLeadingAndTrailingBackslashes as N } from "./utils.mjs";
|
|
32
|
+
import { ApplicationTypes as C, PromptStatus as U, PromptVariableType as L, ChatMessageRole as S } from "@glodon-aiot/apis";
|
|
33
|
+
import B from "./Logger.mjs";
|
|
34
|
+
import { configuration as _ } from "./Config.mjs";
|
|
35
|
+
import H from "./EventBus.mjs";
|
|
36
|
+
import { getCVForceService as K } from "./api/index.mjs";
|
|
37
|
+
import Y from "dayjs";
|
|
38
|
+
import { uploadSessionFile as G } from "./sessionUpload.mjs";
|
|
39
|
+
const V = 100, l = new B("[Session] ");
|
|
40
|
+
var j = /* @__PURE__ */ ((p) => (p.DataRequestFailed = "data request error", p.SocketConnectionFailed = "socket error", p.IdUndefined = "session id is not defined", p.SendingEmptyContent = "failed at sending empty content", p.Frozen = "session is frozen", p.UserModeError = "failed at setting socket user mode", p.Inactive = "session is inactive", p))(j || {});
|
|
41
|
+
class ne {
|
|
42
42
|
/**
|
|
43
43
|
* Session 类的构造函数,用于初始化会话实例。
|
|
44
44
|
* @param token - 用户的身份验证令牌,用于解析应用 ID。
|
|
@@ -48,87 +48,91 @@ class se {
|
|
|
48
48
|
* @param _application - 应用信息,可选参数。
|
|
49
49
|
* @param client - Bot 客户端实例,可选参数。
|
|
50
50
|
*/
|
|
51
|
-
constructor(e, t = "",
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
constructor(e, t = "", i, o, n, h) {
|
|
52
|
+
f(this, "_id");
|
|
53
|
+
f(this, "_frozen", !1);
|
|
54
54
|
//是否可发送新问题
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
f(this, "inactivating", !1);
|
|
56
|
+
f(this, "_ready", !1);
|
|
57
57
|
// ready = false;
|
|
58
|
-
|
|
58
|
+
f(this, "event", new H());
|
|
59
59
|
//从token解析出来的用户信息
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.token = e, this.lazyload =
|
|
60
|
+
f(this, "_applicationId");
|
|
61
|
+
f(this, "_application", null);
|
|
62
|
+
f(this, "data", null);
|
|
63
|
+
f(this, "client", null);
|
|
64
|
+
f(this, "messages", []);
|
|
65
|
+
f(this, "_loadingMessages", !1);
|
|
66
|
+
f(this, "_loadingMessagesSize", 10);
|
|
67
|
+
f(this, "cvforceApi");
|
|
68
|
+
f(this, "socket", null);
|
|
69
|
+
f(this, "_promptVariables", []);
|
|
70
|
+
f(this, "_sessionActive", !1);
|
|
71
|
+
f(this, "activing", !1);
|
|
72
|
+
f(this, "_stopAnswer", !1);
|
|
73
|
+
f(this, "_dataLoading", !1);
|
|
74
|
+
f(this, "_dataLoaded", !1);
|
|
75
|
+
f(this, "_mcpServers", null);
|
|
76
|
+
this.token = e, this.lazyload = o, this.client = h || null, this._applicationId = P(e).rid || _.applicationId, this.cvforceApi = this.getService(), n && (this._application = n), this.event.emit("init", {
|
|
77
77
|
applicationId: this._applicationId,
|
|
78
78
|
sessionId: t
|
|
79
79
|
}), this.loadApplicationInfo().then(() => {
|
|
80
|
-
var
|
|
80
|
+
var d;
|
|
81
81
|
if (t)
|
|
82
|
-
this._id = t, this.event.emit("data:loading"),
|
|
83
|
-
this.data =
|
|
82
|
+
this._id = t, this.event.emit("data:loading"), i ? (this.data = i, o || (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((a) => c(this, null, function* () {
|
|
83
|
+
this.data = a, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
|
|
84
84
|
})).then(() => c(this, null, function* () {
|
|
85
85
|
this.messages = [], yield this.fetchMessages(), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data);
|
|
86
|
-
})))) : (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((
|
|
87
|
-
this.data =
|
|
86
|
+
})))) : (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((a) => c(this, null, function* () {
|
|
87
|
+
this.data = a, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
|
|
88
88
|
})).then(() => c(this, null, function* () {
|
|
89
89
|
this.messages = [], yield this.fetchMessages(), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._dataLoading = !1, this._dataLoaded = !0;
|
|
90
90
|
})));
|
|
91
91
|
else {
|
|
92
|
-
const
|
|
92
|
+
const a = (i == null ? void 0 : i.name) || "新建会话";
|
|
93
93
|
this.event.emit("data:creating", {
|
|
94
94
|
applicationId: this._applicationId,
|
|
95
|
-
name:
|
|
95
|
+
name: a
|
|
96
96
|
}), this.event.emit("data:loading"), this.cvforceApi.postSession(this.applicationId, {
|
|
97
|
-
name:
|
|
97
|
+
name: a,
|
|
98
98
|
// @ts-ignore
|
|
99
|
-
netOpen:
|
|
100
|
-
knowledgeIdList: (
|
|
99
|
+
netOpen: i == null ? void 0 : i.netOpen,
|
|
100
|
+
knowledgeIdList: (d = i == null ? void 0 : i.knowledges) == null ? void 0 : d.map((s) => s.id),
|
|
101
101
|
applicationId: this._applicationId
|
|
102
|
-
}).then((
|
|
102
|
+
}).then((s) => c(this, null, function* () {
|
|
103
103
|
var m;
|
|
104
|
-
this._id =
|
|
105
|
-
knowledges:
|
|
104
|
+
this._id = s.id, this.data = y(u({}, s), {
|
|
105
|
+
knowledges: i == null ? void 0 : i.knowledges
|
|
106
106
|
}), this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id);
|
|
107
107
|
try {
|
|
108
108
|
yield (() => c(this, null, function* () {
|
|
109
|
-
if (
|
|
110
|
-
return this.setKnowledges((
|
|
109
|
+
if (i != null && i.knowledges)
|
|
110
|
+
return this.setKnowledges((i == null ? void 0 : i.knowledges) || void 0);
|
|
111
111
|
}))();
|
|
112
112
|
} catch (I) {
|
|
113
|
-
|
|
113
|
+
l.error(I);
|
|
114
114
|
}
|
|
115
115
|
yield (() => {
|
|
116
|
-
if (
|
|
117
|
-
const I = this._promptVariables.map((
|
|
118
|
-
var
|
|
119
|
-
const w = ((
|
|
120
|
-
return y(
|
|
116
|
+
if (i != null && i.promptVariables) {
|
|
117
|
+
const I = this._promptVariables.map((g) => {
|
|
118
|
+
var A, v;
|
|
119
|
+
const w = ((v = (A = i.promptVariables) == null ? void 0 : A.find((r) => r.key === g.key && r.type === g.type)) == null ? void 0 : v.value) || "";
|
|
120
|
+
return y(u({}, g), {
|
|
121
121
|
value: w
|
|
122
122
|
});
|
|
123
|
-
}).sort((
|
|
123
|
+
}).sort((g, w) => g.key.localeCompare(w.key));
|
|
124
124
|
return this.setPromptVariables(I || []);
|
|
125
125
|
} else
|
|
126
126
|
return;
|
|
127
|
-
})(), this.event.emit("data:created", this.data), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), ((m = this.application) == null ? void 0 : m.type) !==
|
|
127
|
+
})(), this.event.emit("data:created", this.data), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), ((m = this.application) == null ? void 0 : m.type) !== C.Agent && (this._ready = !0, this.event.emit("ready"));
|
|
128
128
|
}));
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
+
/** 是否为当前正在使用的会话。 */
|
|
133
|
+
get active() {
|
|
134
|
+
return this._sessionActive;
|
|
135
|
+
}
|
|
132
136
|
fetchData() {
|
|
133
137
|
return c(this, null, function* () {
|
|
134
138
|
if (!this.data)
|
|
@@ -176,12 +180,12 @@ class se {
|
|
|
176
180
|
return c(this, null, function* () {
|
|
177
181
|
if (!this.data)
|
|
178
182
|
throw Error("session data is not loaded");
|
|
179
|
-
if ((e || []).some((
|
|
183
|
+
if ((e || []).some((o) => Array.isArray(o.fileIds) && o.fileIds.length === 0))
|
|
180
184
|
throw Error("fileIds cannot be an empty array");
|
|
181
|
-
if ((e || []).reduce((
|
|
182
|
-
var
|
|
183
|
-
const
|
|
184
|
-
return
|
|
185
|
+
if ((e || []).reduce((o, n) => {
|
|
186
|
+
var d, a;
|
|
187
|
+
const h = (a = (d = n.fileIds) == null ? void 0 : d.length) != null ? a : 0;
|
|
188
|
+
return o + (h > 0 ? h : 1);
|
|
185
189
|
}, 0) > V)
|
|
186
190
|
throw Error(`knowledges and fileIds total count cannot exceed ${V}`);
|
|
187
191
|
return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
|
|
@@ -196,7 +200,7 @@ class se {
|
|
|
196
200
|
throw Error("session id is not defined");
|
|
197
201
|
if (!this.data)
|
|
198
202
|
throw Error("session data is not loaded");
|
|
199
|
-
const e = this.promptVariables.filter((t) => t.status ===
|
|
203
|
+
const e = this.promptVariables.filter((t) => t.status === U.Quoted).filter((t) => !t.value);
|
|
200
204
|
if (e.length)
|
|
201
205
|
throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${e.map((t) => t.key).join(", ")}`);
|
|
202
206
|
}
|
|
@@ -205,16 +209,16 @@ class se {
|
|
|
205
209
|
}
|
|
206
210
|
setPromptVariables(e) {
|
|
207
211
|
return c(this, null, function* () {
|
|
208
|
-
const t = e == null ? void 0 : e.map((n) => n.type ? n : y(
|
|
212
|
+
const t = e == null ? void 0 : e.map((n) => n.type ? n : y(u({}, n), {
|
|
209
213
|
type: "instruction"
|
|
210
|
-
})),
|
|
211
|
-
var
|
|
212
|
-
const
|
|
213
|
-
return y(
|
|
214
|
-
value:
|
|
214
|
+
})), i = this._promptVariables.map((n) => {
|
|
215
|
+
var d;
|
|
216
|
+
const h = ((d = t == null ? void 0 : t.find((a) => a.key === n.key && a.type === n.type)) == null ? void 0 : d.value) || n.value;
|
|
217
|
+
return y(u({}, n), {
|
|
218
|
+
value: h
|
|
215
219
|
});
|
|
216
|
-
}).sort((n,
|
|
217
|
-
if (!(yield Promise.all(
|
|
220
|
+
}).sort((n, h) => n.key.localeCompare(h.key));
|
|
221
|
+
if (!(yield Promise.all(i.filter((n) => !(n.type === L.User && n.key === "query") && !(n.type === L.System && n.key === "datetime")).map((n) => {
|
|
218
222
|
if (!this.data)
|
|
219
223
|
throw Error("session data is not loaded");
|
|
220
224
|
if (!(!n.id || !n.key))
|
|
@@ -242,13 +246,13 @@ class se {
|
|
|
242
246
|
*/
|
|
243
247
|
setNetOpen(e) {
|
|
244
248
|
return c(this, null, function* () {
|
|
245
|
-
var t,
|
|
246
|
-
if (
|
|
247
|
-
|
|
249
|
+
var t, i, o;
|
|
250
|
+
if (l.log("setNetOpen:", e), l.log("application arrange setting value: ", (t = this._application) == null ? void 0 : t.arrange[0].enableNetOpen), ((i = this._application) == null ? void 0 : i.type) === C.Agent) {
|
|
251
|
+
l.warn("Agent Application Sessions are disabled to setNetOpen.");
|
|
248
252
|
return;
|
|
249
253
|
}
|
|
250
|
-
if (((
|
|
251
|
-
|
|
254
|
+
if (((o = this._application) == null ? void 0 : o.arrange[0].enableNetOpen) === !1) {
|
|
255
|
+
l.warn("This Application is disabled to change netOpen.");
|
|
252
256
|
return;
|
|
253
257
|
}
|
|
254
258
|
if (!this.data)
|
|
@@ -256,26 +260,26 @@ class se {
|
|
|
256
260
|
return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
|
|
257
261
|
netOpen: e ? 1 : 2
|
|
258
262
|
/* disable */
|
|
259
|
-
}), this.data.netOpen = e,
|
|
263
|
+
}), this.data.netOpen = e, l.log("data:updated", this.data), this.event.emit("data:updated", this.data), this.event.emit("data:updated:netOpen", {
|
|
260
264
|
netOpen: e
|
|
261
265
|
}), e;
|
|
262
266
|
});
|
|
263
267
|
}
|
|
264
268
|
getService() {
|
|
265
|
-
return
|
|
266
|
-
const
|
|
269
|
+
return K(_.apiRoot, this.token, (e, t) => {
|
|
270
|
+
const i = new Error("data request error", {
|
|
267
271
|
cause: {
|
|
268
272
|
status: e,
|
|
269
273
|
message: t
|
|
270
274
|
}
|
|
271
275
|
});
|
|
272
|
-
|
|
276
|
+
l.error(i), this.event.emit("error", i);
|
|
273
277
|
});
|
|
274
278
|
}
|
|
275
|
-
addEventListener(e, t,
|
|
279
|
+
addEventListener(e, t, i = !1) {
|
|
276
280
|
if (typeof t != "function")
|
|
277
281
|
throw Error("event listener is not a function");
|
|
278
|
-
if (
|
|
282
|
+
if (i) {
|
|
279
283
|
this.event.once(e, t);
|
|
280
284
|
return;
|
|
281
285
|
}
|
|
@@ -291,36 +295,36 @@ class se {
|
|
|
291
295
|
*/
|
|
292
296
|
fetchMessages() {
|
|
293
297
|
return c(this, arguments, function* (e = {}) {
|
|
294
|
-
var
|
|
298
|
+
var i, o;
|
|
295
299
|
const t = {
|
|
296
300
|
pageSize: this._loadingMessagesSize
|
|
297
301
|
};
|
|
298
302
|
if (this._id) {
|
|
299
|
-
e =
|
|
300
|
-
const n = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e),
|
|
301
|
-
var
|
|
303
|
+
e = u(u({}, t), e), this.event.emit("history:loading"), l.log("history:loading"), (e.endTime || e.startTime) && (this.event.emit("history:moreloading", e), l.log("history:moreloading", e)), this._loadingMessages = !0;
|
|
304
|
+
const n = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), h = n.map((a, s) => {
|
|
305
|
+
var g, w;
|
|
302
306
|
let m = [], I;
|
|
303
|
-
return typeof ((
|
|
307
|
+
return typeof ((g = a.agentHistoryList) == null ? void 0 : g.agentList) == "string" && (m = JSON.parse(a.agentHistoryList.agentList).reduce((v, r) => (v[r.data.step - 1] || (v[r.data.step - 1] = []), v[r.data.step - 1].push(r), v), [])), s === n.length - 1 && (I = (w = this.data) == null ? void 0 : w.lastRelatedQuestion), y(u({}, a), {
|
|
304
308
|
actions: m,
|
|
305
309
|
relatedQuesion: I,
|
|
306
310
|
fromHistory: !0
|
|
307
311
|
});
|
|
308
312
|
});
|
|
309
313
|
if (!e.endTime && !e.startTime) {
|
|
310
|
-
const
|
|
311
|
-
|
|
314
|
+
const a = this.messages[this.messages.length - 1];
|
|
315
|
+
a && !a.relatedQuesion && (a.relatedQuesion = (i = this.data) == null ? void 0 : i.lastRelatedQuestion), this.messages = [...h, ...this.messages];
|
|
312
316
|
} else if (e.endTime && !e.startTime) {
|
|
313
|
-
const
|
|
314
|
-
this.messages.splice(0,
|
|
317
|
+
const a = this.messages.findIndex((s) => s.ts === e.endTime);
|
|
318
|
+
this.messages.splice(0, a + 1), this.messages = [...h, ...this.messages];
|
|
315
319
|
} else if (!e.endTime && e.startTime) {
|
|
316
|
-
const
|
|
317
|
-
this.messages.splice(
|
|
320
|
+
const a = this.messages.findLastIndex((s) => s.ts === e.endTime);
|
|
321
|
+
this.messages.splice(a, this.messages.length - a - 1), this.messages = [...this.messages, ...h];
|
|
318
322
|
} else {
|
|
319
|
-
const
|
|
320
|
-
this.messages.splice(
|
|
323
|
+
const a = this.messages.findIndex((m) => m.ts === e.endTime), s = this.messages.findLastIndex((m) => m.ts === e.endTime);
|
|
324
|
+
this.messages.splice(a, s - a + 1, ...h);
|
|
321
325
|
}
|
|
322
|
-
const
|
|
323
|
-
return
|
|
326
|
+
const d = this.messages[this.messages.length - 1];
|
|
327
|
+
return d && !d.relatedQuesion && (d.relatedQuesion = (o = this.data) == null ? void 0 : o.lastRelatedQuestion), this.event.emit("history:moreloaded", h), l.log("history:loaded", this.messages), this.event.emit("history:loaded", this.messages), this._loadingMessages = !1, h;
|
|
324
328
|
} else {
|
|
325
329
|
const n = new Error(
|
|
326
330
|
"session id is not defined"
|
|
@@ -329,7 +333,7 @@ class se {
|
|
|
329
333
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
330
334
|
// }
|
|
331
335
|
);
|
|
332
|
-
return
|
|
336
|
+
return l.error(n), this.event.emit("error", n), !1;
|
|
333
337
|
}
|
|
334
338
|
});
|
|
335
339
|
}
|
|
@@ -341,14 +345,14 @@ class se {
|
|
|
341
345
|
throw Error("name is empty");
|
|
342
346
|
return this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
343
347
|
name: e
|
|
344
|
-
}),
|
|
348
|
+
}), l.log("data:updated", this.messages), this.event.emit("data:updated", this.data), this.event.emit("data:updated:name", {
|
|
345
349
|
name: e
|
|
346
350
|
}), !0;
|
|
347
351
|
});
|
|
348
352
|
}
|
|
349
353
|
pushMessage(e) {
|
|
350
354
|
return c(this, null, function* () {
|
|
351
|
-
this.messages.push(e),
|
|
355
|
+
this.messages.push(e), l.log("history:add", e), this.event.emit("history:add", e), this.event.emit("message:new", e), this.event.emit("message:updated", e);
|
|
352
356
|
});
|
|
353
357
|
}
|
|
354
358
|
reloadSessionInfo() {
|
|
@@ -357,7 +361,7 @@ class se {
|
|
|
357
361
|
return this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, this._id).then((e) => c(this, null, function* () {
|
|
358
362
|
if (this.data = e, !this._id)
|
|
359
363
|
throw Error("session is not created yet");
|
|
360
|
-
return this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id),
|
|
364
|
+
return this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id), l.log("data:updated", this.data), this.event.emit("data:updated", this.data), this.data;
|
|
361
365
|
})).then(() => c(this, null, function* () {
|
|
362
366
|
return this.messages = [], yield this.fetchMessages(), this._dataLoading = !1, this._dataLoaded = !0, this.event.emit("data:loaded", this.data), this;
|
|
363
367
|
}));
|
|
@@ -377,37 +381,38 @@ class se {
|
|
|
377
381
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
378
382
|
// }
|
|
379
383
|
);
|
|
380
|
-
return
|
|
384
|
+
return l.error(e), this.event.emit("error", e), !1;
|
|
381
385
|
}
|
|
382
386
|
return this.event.emit("data:deleting"), yield this.cvforceApi.delSessionsId(this.applicationId, this.id), this.event.emit("data:deleted"), this.destroy();
|
|
383
387
|
});
|
|
384
388
|
}
|
|
385
389
|
activate() {
|
|
386
390
|
return c(this, null, function* () {
|
|
391
|
+
var t;
|
|
387
392
|
if (this.activing)
|
|
388
|
-
return new Promise((
|
|
393
|
+
return new Promise((i) => {
|
|
389
394
|
this.addEventListener("activated", () => {
|
|
390
|
-
|
|
395
|
+
i(!0);
|
|
391
396
|
}, !0);
|
|
392
397
|
});
|
|
393
398
|
if (!this._id)
|
|
394
399
|
throw Error("session is not avalible. id is undefined");
|
|
395
|
-
this.activing = !0;
|
|
400
|
+
l.log("activate", this._id), this.activing = !0;
|
|
396
401
|
const e = this._id;
|
|
397
|
-
return this._dataLoading = !0, this._dataLoaded = !1, this.data = yield this.cvforceApi.getSession(this.applicationId, e).then((
|
|
398
|
-
return this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, e),
|
|
399
|
-
})), this.messages.length || (this.messages = [], yield this.fetchMessages()), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._dataLoaded = !0, this._dataLoading = !1, this.inactivating = !1, this.frozen = !0, yield this.prepareConnection(), this.event.emit("activated", this.socket), this.
|
|
402
|
+
return this._dataLoading = !0, this._dataLoaded = !1, this.data = yield this.cvforceApi.getSession(this.applicationId, e).then((i) => c(this, null, function* () {
|
|
403
|
+
return this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, e), i;
|
|
404
|
+
})), this.messages.length || (this.messages = [], yield this.fetchMessages()), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._dataLoaded = !0, this._dataLoading = !1, this.inactivating = !1, (t = this.socket) != null && t.connected || (this.frozen = !0), yield this.prepareConnection(), this.event.emit("activated", this.socket), l.log("activated", this._id), this._sessionActive = !0, this.activing = !1, this;
|
|
400
405
|
});
|
|
401
406
|
}
|
|
402
407
|
inactivate(e = !1) {
|
|
403
|
-
return this.socket ? this._frozen ? (e || (this.inactivating = !0), this.activing = !1, !0) : (this.socket.close(), this.socket = null, this.event.emit("inactivated"), this.
|
|
408
|
+
return this.socket ? (l.log("inactivate", this.id), this._frozen ? (e || (this.inactivating = !0), this.activing = !1, !0) : (this.socket.close(), this.socket = null, this.event.emit("inactivated"), this._sessionActive = !1, this.activing = !1, !0)) : (this.activing = !1, !0);
|
|
404
409
|
}
|
|
405
410
|
/**
|
|
406
411
|
* 会话标题摘要开关。应用详情返回布尔值时用该值,字段缺失时默认开启。
|
|
407
412
|
*/
|
|
408
413
|
resolveEnableTitleSummary() {
|
|
409
|
-
var t,
|
|
410
|
-
const e = (
|
|
414
|
+
var t, i, o;
|
|
415
|
+
const e = (o = (i = (t = this.application) == null ? void 0 : t.arrange) == null ? void 0 : i[0]) == null ? void 0 : o.autoGenerateSessionTitle;
|
|
411
416
|
return typeof e == "boolean" ? e : !0;
|
|
412
417
|
}
|
|
413
418
|
//TODO: remove mcp server
|
|
@@ -426,104 +431,114 @@ class se {
|
|
|
426
431
|
return c(this, null, function* () {
|
|
427
432
|
if (!this._id)
|
|
428
433
|
throw Error("session is not avalible. id is undefined");
|
|
429
|
-
return
|
|
434
|
+
return G(this.cvforceApi, this._id, e);
|
|
430
435
|
});
|
|
431
436
|
}
|
|
432
|
-
send(
|
|
437
|
+
send(i) {
|
|
433
438
|
return c(this, arguments, function* (e, t = {
|
|
434
|
-
stream:
|
|
439
|
+
stream: _.stream
|
|
435
440
|
}) {
|
|
436
|
-
var
|
|
441
|
+
var A, v;
|
|
437
442
|
try {
|
|
438
443
|
this.validateConfigs();
|
|
439
|
-
} catch (
|
|
440
|
-
|
|
444
|
+
} catch (r) {
|
|
445
|
+
l.report(r);
|
|
441
446
|
}
|
|
442
447
|
const {
|
|
443
|
-
stream:
|
|
448
|
+
stream: o = _.stream,
|
|
444
449
|
referenceFirst: n = !1
|
|
445
|
-
} = t,
|
|
446
|
-
if (!
|
|
447
|
-
const
|
|
450
|
+
} = t, h = e.uuid || Q(), d = ((A = e.text) == null ? void 0 : A.trim()) || "", a = e.files || [], s = e.fileIds, m = e.imageContent;
|
|
451
|
+
if (!d && !a.length && !(s != null && s.length)) {
|
|
452
|
+
const r = new Error(
|
|
448
453
|
"failed at sending empty content"
|
|
449
454
|
/* SendingEmptyContent */
|
|
450
455
|
// {
|
|
451
456
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.SendingEmptyContent],
|
|
452
457
|
// }
|
|
453
458
|
);
|
|
454
|
-
return
|
|
459
|
+
return l.error(r), this.event.emit("error", r), !1;
|
|
455
460
|
}
|
|
456
461
|
if (!this._id) {
|
|
457
|
-
const
|
|
462
|
+
const r = new Error(
|
|
458
463
|
"session id is not defined"
|
|
459
464
|
/* IdUndefined */
|
|
460
465
|
// {
|
|
461
466
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
462
467
|
// }
|
|
463
468
|
);
|
|
464
|
-
return
|
|
469
|
+
return l.error(r), this.event.emit("error", r), !1;
|
|
465
470
|
}
|
|
466
471
|
if (this.frozen) {
|
|
467
|
-
const
|
|
472
|
+
const r = new Error(
|
|
468
473
|
"session is frozen"
|
|
469
474
|
/* Frozen */
|
|
470
475
|
// {
|
|
471
476
|
// cause: { code: -1, message: 'session is frozen.' },
|
|
472
477
|
// }
|
|
473
478
|
);
|
|
474
|
-
return
|
|
479
|
+
return l.error(r), this.event.emit("error", r), !1;
|
|
475
480
|
}
|
|
476
|
-
this.frozen = !0, this._stopAnswer = !1
|
|
481
|
+
this.frozen = !0, this._stopAnswer = !1, l.log("send", {
|
|
482
|
+
sessionId: this._id,
|
|
483
|
+
stream: o,
|
|
484
|
+
contentLength: d.length,
|
|
485
|
+
fileCount: a.length,
|
|
486
|
+
fileIdCount: (v = s == null ? void 0 : s.length) != null ? v : 0
|
|
487
|
+
});
|
|
477
488
|
const I = {
|
|
478
489
|
sessionId: this.id,
|
|
479
490
|
role: 2,
|
|
480
|
-
content:
|
|
481
|
-
messageId:
|
|
491
|
+
content: d,
|
|
492
|
+
messageId: h,
|
|
482
493
|
reference: [],
|
|
483
494
|
searchReference: [],
|
|
484
495
|
messageTime: "",
|
|
485
|
-
files:
|
|
496
|
+
files: a,
|
|
486
497
|
imageContent: m
|
|
487
|
-
},
|
|
488
|
-
content:
|
|
489
|
-
stream:
|
|
490
|
-
requestId:
|
|
491
|
-
fileIds:
|
|
498
|
+
}, g = {
|
|
499
|
+
content: d,
|
|
500
|
+
stream: o,
|
|
501
|
+
requestId: h,
|
|
502
|
+
fileIds: s,
|
|
492
503
|
referenceFirst: n,
|
|
493
504
|
imageContent: m
|
|
494
505
|
};
|
|
495
|
-
this.pushMessage(I), this.event.emit("question:content",
|
|
496
|
-
const w = (
|
|
497
|
-
if (
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
506
|
+
this.pushMessage(I), this.event.emit("question:content", d);
|
|
507
|
+
const w = (r) => c(this, null, function* () {
|
|
508
|
+
if (r.role === S.Robot) {
|
|
509
|
+
this.removeEventListener("answer:finish", w);
|
|
510
|
+
try {
|
|
511
|
+
switch (this._id && r.content && r.index && r.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
512
|
+
finialMessage: r.content
|
|
513
|
+
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
514
|
+
finialMessage: r.content
|
|
515
|
+
})), yield this.fillMessageReference(r), r.code) {
|
|
516
|
+
case 11915:
|
|
517
|
+
r.content = "请您换个问题问我吧~", r.index = -1, r.isSensitive = !0, r.isLoading = !1, r.sessionId = this._id || "", this.event.emit("message:error", r);
|
|
518
|
+
break;
|
|
519
|
+
case 11916:
|
|
520
|
+
r.content = "尊敬的用户您好,让我们换个话题再聊聊吧。", r.index = -1, r.isSensitive = !0, r.isLoading = !1, r.sessionId = this._id || "", this.event.emit("message:error", r);
|
|
521
|
+
break;
|
|
522
|
+
case 200:
|
|
523
|
+
r.index = -1, r.isLoading = !1;
|
|
524
|
+
break;
|
|
525
|
+
default:
|
|
526
|
+
r.content = r.message || "未知错误", r.isLoading = !1, r.index = -1, this.event.emit("message:error", r);
|
|
527
|
+
}
|
|
528
|
+
this.getRelatedQuesion(r), r.isLoading = !1;
|
|
529
|
+
let b = this.messages[this.messages.length - 1];
|
|
530
|
+
if (b && b.role === S.Robot) {
|
|
531
|
+
const E = u(u({}, b), r);
|
|
532
|
+
this.messages[this.messages.length - 1] = E, this.event.emit("message:updated", E);
|
|
533
|
+
} else
|
|
534
|
+
this.pushMessage(r);
|
|
535
|
+
} finally {
|
|
536
|
+
this.frozen = !1;
|
|
537
|
+
}
|
|
515
538
|
}
|
|
516
|
-
this.getRelatedQuesion(o), o.isLoading = !1;
|
|
517
|
-
let g = this.messages[this.messages.length - 1];
|
|
518
|
-
if (g && g.role === A.Robot) {
|
|
519
|
-
const k = f(f({}, g), o);
|
|
520
|
-
this.messages[this.messages.length - 1] = k, this.event.emit("message:updated", k);
|
|
521
|
-
} else
|
|
522
|
-
this.pushMessage(o);
|
|
523
|
-
this.frozen = !1;
|
|
524
539
|
});
|
|
525
|
-
return this.addEventListener("answer:finish", w), this.sendQuestion(
|
|
526
|
-
stream:
|
|
540
|
+
return this.addEventListener("answer:finish", w), this.sendQuestion(g, y(u({}, t), {
|
|
541
|
+
stream: o,
|
|
527
542
|
referenceFirst: n
|
|
528
543
|
})), I;
|
|
529
544
|
});
|
|
@@ -531,99 +546,113 @@ class se {
|
|
|
531
546
|
currentUserQuestion() {
|
|
532
547
|
for (let e = this.messages.length - 1; e >= 0; e -= 1) {
|
|
533
548
|
const t = this.messages[e];
|
|
534
|
-
if (t.role ===
|
|
549
|
+
if (t.role === S.User)
|
|
535
550
|
return t.content || "";
|
|
536
551
|
}
|
|
537
552
|
return "";
|
|
538
553
|
}
|
|
539
554
|
getRelatedQuesion(e) {
|
|
540
555
|
return c(this, null, function* () {
|
|
541
|
-
var
|
|
556
|
+
var d, a;
|
|
557
|
+
const t = (d = this.application) == null ? void 0 : d.arrange[0];
|
|
542
558
|
if (!e.content || e.isSensitive || e.code !== 200)
|
|
543
|
-
return
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
559
|
+
return l.log("related:skip", {
|
|
560
|
+
code: e.code,
|
|
561
|
+
sensitive: !!e.isSensitive,
|
|
562
|
+
hasContent: !!e.content
|
|
563
|
+
}), e;
|
|
564
|
+
const i = F(t == null ? void 0 : t.recommendQuestionOpen, t == null ? void 0 : t.relatedQuestionApp, e.content, this.currentUserQuestion());
|
|
565
|
+
if (i === null)
|
|
566
|
+
return l.log("related:skip", {
|
|
567
|
+
recommendQuestionOpen: t == null ? void 0 : t.recommendQuestionOpen
|
|
568
|
+
}), e;
|
|
569
|
+
l.log("related:request", i), this.event.emit("message:relatedQuesion:loading", e);
|
|
570
|
+
const o = yield this.cvforceApi.postGeneques({
|
|
571
|
+
content: i
|
|
572
|
+
}).catch((s) => (l.error("related:failed", s), null));
|
|
573
|
+
if (l.log("related:response", o), !o) {
|
|
574
|
+
const s = [], m = y(u({}, e), {
|
|
575
|
+
relatedQuesion: s,
|
|
554
576
|
index: -3,
|
|
555
577
|
isLoading: !1
|
|
556
578
|
});
|
|
557
579
|
return this.event.emit("message:relatedQuesion:loaded", {
|
|
558
|
-
relatedQuesion:
|
|
580
|
+
relatedQuesion: s
|
|
559
581
|
}), this.event.emit("message:updated", m), m;
|
|
560
582
|
}
|
|
561
|
-
const n = (
|
|
583
|
+
const n = (a = o.content) == null ? void 0 : a.split("*").map(q).map(N).filter((s) => !!s);
|
|
562
584
|
e.relatedQuesion = n, e.index = -3, e.isLoading = !1;
|
|
563
|
-
const
|
|
585
|
+
const h = y(u({}, e), {
|
|
564
586
|
relatedQuesion: n,
|
|
565
587
|
index: -3,
|
|
566
588
|
isLoading: !1
|
|
567
589
|
});
|
|
568
|
-
return this.event.emit("message:relatedQuesion:loaded",
|
|
590
|
+
return this.event.emit("message:relatedQuesion:loaded", h), this.event.emit("message:updated", h), this._id && this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
|
|
569
591
|
lastRelatedQuestion: n
|
|
570
|
-
}),
|
|
592
|
+
}), h;
|
|
571
593
|
});
|
|
572
594
|
}
|
|
573
595
|
fillMessageReference(e) {
|
|
574
596
|
return c(this, null, function* () {
|
|
575
597
|
try {
|
|
576
|
-
const t = yield Promise.all(e.reference.map((
|
|
577
|
-
e.reference = e.reference.map((
|
|
598
|
+
const t = yield Promise.all(e.reference.map((i) => this.cvforceApi.getKnowledgeIdFileId(i.knowledgeId, i.docId)));
|
|
599
|
+
e.reference = e.reference.map((i, o) => u(u({}, i), t[o]));
|
|
578
600
|
} catch (t) {
|
|
579
|
-
|
|
601
|
+
l.error("Failed to fill message reference:", t);
|
|
580
602
|
}
|
|
581
603
|
return this.event.emit("message:updated", e), e;
|
|
582
604
|
});
|
|
583
605
|
}
|
|
584
606
|
answerAgain() {
|
|
585
607
|
return c(this, arguments, function* (e = {
|
|
586
|
-
stream:
|
|
608
|
+
stream: _.stream
|
|
587
609
|
}) {
|
|
610
|
+
var a;
|
|
588
611
|
const t = this.messages[this.messages.length - 1];
|
|
589
612
|
if (!t)
|
|
590
613
|
throw Error("message list is empty");
|
|
591
|
-
this.frozen = !0, this._stopAnswer = !1
|
|
614
|
+
this.frozen = !0, this._stopAnswer = !1, l.log("answerAgain", {
|
|
615
|
+
sessionId: this._id,
|
|
616
|
+
stream: (a = e.stream) != null ? a : _.stream
|
|
617
|
+
});
|
|
592
618
|
const {
|
|
593
|
-
stream:
|
|
619
|
+
stream: i = _.stream
|
|
594
620
|
} = e;
|
|
595
|
-
let
|
|
596
|
-
t.role !==
|
|
597
|
-
const n = this.messages[this.messages.length - 1],
|
|
621
|
+
let o;
|
|
622
|
+
t.role !== S.User && (o = e.oldMessageId || t.messageId, this.messages.splice(this.messages.length - 1, 1), this.event.emit("message:remove", t), this.event.emit("history:remove", t));
|
|
623
|
+
const n = this.messages[this.messages.length - 1], h = {
|
|
598
624
|
content: n.content,
|
|
599
625
|
fileIds: n.fileIds,
|
|
600
626
|
requestId: n.messageId,
|
|
601
|
-
stream:
|
|
602
|
-
oldMessageId:
|
|
603
|
-
},
|
|
604
|
-
if (
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
627
|
+
stream: i,
|
|
628
|
+
oldMessageId: o
|
|
629
|
+
}, d = (s) => c(this, null, function* () {
|
|
630
|
+
if (s.role === S.Robot && s.index === -1)
|
|
631
|
+
try {
|
|
632
|
+
switch (this._id && s.content && s.index && s.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
633
|
+
finialMessage: s.content
|
|
634
|
+
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
635
|
+
finialMessage: s.content
|
|
636
|
+
})), yield this.fillMessageReference(s), s.code) {
|
|
637
|
+
case 11915:
|
|
638
|
+
s.content = "请您换个问题问我吧~", s.index = -1, s.isSensitive = !0, s.isLoading = !1, s.sessionId = this._id || "", this.event.emit("message:error", s);
|
|
639
|
+
break;
|
|
640
|
+
case 11916:
|
|
641
|
+
s.content = "尊敬的用户您好,让我们换个话题再聊聊吧。", s.index = -1, s.isSensitive = !0, s.isLoading = !1, s.sessionId = this._id || "", this.event.emit("message:error", s);
|
|
642
|
+
break;
|
|
643
|
+
case 200:
|
|
644
|
+
s.index = -1, s.isLoading = !1;
|
|
645
|
+
break;
|
|
646
|
+
default:
|
|
647
|
+
s.content = s.message || "未知错误", s.isLoading = !1, s.index = -1, this.event.emit("message:error", s);
|
|
648
|
+
}
|
|
649
|
+
this.getRelatedQuesion(s);
|
|
650
|
+
} finally {
|
|
651
|
+
this.removeEventListener("message:content", d), this.frozen = !1;
|
|
621
652
|
}
|
|
622
|
-
this.getRelatedQuesion(i), this.removeEventListener("message:content", r), this.frozen = !1;
|
|
623
|
-
}
|
|
624
653
|
});
|
|
625
|
-
this.addEventListener("message:content",
|
|
626
|
-
stream:
|
|
654
|
+
this.addEventListener("message:content", d), this.sendQuestion(h, y(u({}, e), {
|
|
655
|
+
stream: i
|
|
627
656
|
}));
|
|
628
657
|
});
|
|
629
658
|
}
|
|
@@ -645,21 +674,21 @@ class se {
|
|
|
645
674
|
* @returns 返回当前会话实例
|
|
646
675
|
*/
|
|
647
676
|
suspend() {
|
|
648
|
-
var
|
|
677
|
+
var i;
|
|
649
678
|
this.stopAnswer(), this.frozen = !1, this._stopAnswer = !0;
|
|
650
679
|
let e = this.messages[this.messages.length - 1];
|
|
651
680
|
const t = {
|
|
652
|
-
messageId:
|
|
681
|
+
messageId: Q(),
|
|
653
682
|
// 生成唯一的消息 ID
|
|
654
683
|
isLoading: !1,
|
|
655
684
|
// 标记消息已停止加载
|
|
656
685
|
index: -2,
|
|
657
686
|
// 消息索引,用于标识特殊状态
|
|
658
|
-
messageTime:
|
|
687
|
+
messageTime: Y(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
|
|
659
688
|
// 消息时间
|
|
660
689
|
content: "",
|
|
661
690
|
// 消息内容
|
|
662
|
-
role:
|
|
691
|
+
role: S.System,
|
|
663
692
|
// 消息角色为系统消息
|
|
664
693
|
sessionId: this.id || "",
|
|
665
694
|
// 会话 ID
|
|
@@ -672,33 +701,33 @@ class se {
|
|
|
672
701
|
if (e.index === -2)
|
|
673
702
|
return;
|
|
674
703
|
if (e.actions) {
|
|
675
|
-
const
|
|
676
|
-
if (
|
|
677
|
-
const n =
|
|
704
|
+
const o = e.actions[((i = e.actions) == null ? void 0 : i.length) - 1];
|
|
705
|
+
if (o) {
|
|
706
|
+
const n = o[o.length - 1];
|
|
678
707
|
if (n && (n.type === "BEFORE_CALL" || n.type === "FUNCTION_CALL")) {
|
|
679
708
|
const {
|
|
680
|
-
pluginName:
|
|
681
|
-
pluginCode:
|
|
682
|
-
funcCode:
|
|
683
|
-
funcName:
|
|
709
|
+
pluginName: h,
|
|
710
|
+
pluginCode: d,
|
|
711
|
+
funcCode: a,
|
|
712
|
+
funcName: s
|
|
684
713
|
} = n.data;
|
|
685
|
-
|
|
714
|
+
o.push({
|
|
686
715
|
data: {
|
|
687
|
-
pluginName:
|
|
688
|
-
pluginCode:
|
|
689
|
-
funcCode:
|
|
690
|
-
funcName:
|
|
716
|
+
pluginName: h,
|
|
717
|
+
pluginCode: d,
|
|
718
|
+
funcCode: a,
|
|
719
|
+
funcName: s,
|
|
691
720
|
step: n.data.step + 1
|
|
692
721
|
},
|
|
693
722
|
type: "ABORT"
|
|
694
723
|
}), this.event.emit("message:action", {
|
|
695
724
|
messageId: e.messageId,
|
|
696
|
-
action:
|
|
725
|
+
action: o
|
|
697
726
|
});
|
|
698
727
|
}
|
|
699
728
|
}
|
|
700
729
|
}
|
|
701
|
-
e =
|
|
730
|
+
e = u(u({}, e), t), this.event.emit("message:content", e), this.event.emit("message:updated", e);
|
|
702
731
|
} else
|
|
703
732
|
this.pushMessage(t), this.event.emit("message:content", t);
|
|
704
733
|
return this;
|
|
@@ -709,10 +738,10 @@ class se {
|
|
|
709
738
|
* @param targetMessage - 要更新的目标聊天消息对象。
|
|
710
739
|
*/
|
|
711
740
|
handleStreamAnswer(e, t) {
|
|
712
|
-
var
|
|
741
|
+
var h;
|
|
713
742
|
if (!e.data)
|
|
714
743
|
return;
|
|
715
|
-
const
|
|
744
|
+
const i = e.data.type, o = e.data.payload;
|
|
716
745
|
t.isReplying = !0;
|
|
717
746
|
const n = () => {
|
|
718
747
|
if (!t.searchingStatus) {
|
|
@@ -724,25 +753,25 @@ class se {
|
|
|
724
753
|
return;
|
|
725
754
|
}
|
|
726
755
|
};
|
|
727
|
-
if (
|
|
756
|
+
if (i === "error" && (t.index = -1), i === "beforeSearch" && n(), i === "searchOver" && n(), i === "search" && t.searchReference.push(o), i === "thinking") {
|
|
728
757
|
t.thinkingStatus = "start";
|
|
729
|
-
const
|
|
730
|
-
t.reasoningContent = (t.reasoningContent || "") + ((
|
|
758
|
+
const a = o.choices[0];
|
|
759
|
+
t.reasoningContent = (t.reasoningContent || "") + ((h = a.delta.reasoningContent) != null ? h : "");
|
|
731
760
|
}
|
|
732
|
-
if (
|
|
761
|
+
if (i === "thinkingOver") {
|
|
733
762
|
t.thinkingStatus = "end";
|
|
734
|
-
const
|
|
735
|
-
t.thinkingSecs =
|
|
763
|
+
const d = o.thinkingSecs;
|
|
764
|
+
t.thinkingSecs = d;
|
|
736
765
|
}
|
|
737
|
-
if (
|
|
738
|
-
const
|
|
739
|
-
t.content = (t.content || "") +
|
|
766
|
+
if (i === "text") {
|
|
767
|
+
const a = o.choices[0];
|
|
768
|
+
t.content = (t.content || "") + a.delta.content;
|
|
740
769
|
}
|
|
741
|
-
if (
|
|
742
|
-
const
|
|
743
|
-
t.messageId =
|
|
770
|
+
if (i === "reference" && (t.reference = o), i === "updateSession" && o && this.data && (this.data = u(u({}, this.data), o), this.event.emit("data:updated", this.data)), i === "result") {
|
|
771
|
+
const d = o.messageId, a = o.llmModel, s = o.messageTime;
|
|
772
|
+
t.messageId = d, t.llmModel = a, t.messageTime = s;
|
|
744
773
|
}
|
|
745
|
-
|
|
774
|
+
i === "over" && (t.index = -1), e.code != null && (t.code = e.code, t.message = e.message);
|
|
746
775
|
}
|
|
747
776
|
/**
|
|
748
777
|
* 异步提交评论信息
|
|
@@ -766,8 +795,8 @@ class se {
|
|
|
766
795
|
if (!this._applicationId || !this._id)
|
|
767
796
|
throw Error("session is not avalible. id is undefined");
|
|
768
797
|
return this.cvforceApi.postComments(this._applicationId, this._id, e).then((t) => {
|
|
769
|
-
const
|
|
770
|
-
return
|
|
798
|
+
const i = this.messages.find((o) => o.messageId === e.messageId);
|
|
799
|
+
return i && (i.comment = e, this.event.emit("message:comment", i)), t;
|
|
771
800
|
});
|
|
772
801
|
});
|
|
773
802
|
}
|
|
@@ -795,6 +824,6 @@ class se {
|
|
|
795
824
|
}
|
|
796
825
|
export {
|
|
797
826
|
V as MAX_KNOWLEDGES_AND_FILES_COUNT,
|
|
798
|
-
|
|
799
|
-
|
|
827
|
+
j as SessionErrors,
|
|
828
|
+
ne as default
|
|
800
829
|
};
|