@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.
@@ -1,44 +1,44 @@
1
- var T = Object.defineProperty, C = Object.defineProperties;
2
- var M = Object.getOwnPropertyDescriptors;
3
- var E = Object.getOwnPropertySymbols;
4
- var R = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable;
5
- var b = (l, e, t) => e in l ? T(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t, f = (l, e) => {
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) && b(l, t, e[t]);
8
- if (E)
9
- for (var t of E(e))
10
- O.call(e, t) && b(l, t, e[t]);
11
- return l;
12
- }, y = (l, e) => C(l, M(e));
13
- var p = (l, e, t) => (b(l, typeof e != "symbol" ? e + "" : e, t), t);
14
- var c = (l, e, t) => new Promise((s, a) => {
15
- var n = (i) => {
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
- r(t.next(i));
18
- } catch (h) {
19
- a(h);
17
+ d(t.next(a));
18
+ } catch (s) {
19
+ o(s);
20
20
  }
21
- }, d = (i) => {
21
+ }, h = (a) => {
22
22
  try {
23
- r(t.throw(i));
24
- } catch (h) {
25
- a(h);
23
+ d(t.throw(a));
24
+ } catch (s) {
25
+ o(s);
26
26
  }
27
- }, r = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(n, d);
28
- r((t = t.apply(l, e)).next());
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 x } from "uuid";
31
- import { parseJWT as z, resolveRelatedQuestionContent as P, removeNewlines as F, removeLeadingAndTrailingBackslashes as N } from "./utils.mjs";
32
- import { ApplicationTypes as Q, PromptStatus as q, PromptVariableType as L, ChatMessageRole as A } from "@glodon-aiot/apis";
33
- import U from "./Logger.mjs";
34
- import { configuration as S } from "./Config.mjs";
35
- import B from "./EventBus.mjs";
36
- import { getCVForceService as H } from "./api/index.mjs";
37
- import K from "dayjs";
38
- import { uploadSessionFile as Y } from "./sessionUpload.mjs";
39
- const V = 100, u = new U("[Session] ");
40
- var D = /* @__PURE__ */ ((l) => (l.DataRequestFailed = "data request error", l.SocketConnectionFailed = "socket error", l.IdUndefined = "session id is not defined", l.SendingEmptyContent = "failed at sending empty content", l.Frozen = "session is frozen", l.UserModeError = "failed at setting socket user mode", l.Inactive = "session is inactive", l))(D || {});
41
- class se {
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 = "", s, a, n, d) {
52
- p(this, "_id");
53
- p(this, "_frozen", !1);
51
+ constructor(e, t = "", i, o, n, h) {
52
+ f(this, "_id");
53
+ f(this, "_frozen", !1);
54
54
  //是否可发送新问题
55
- p(this, "inactivating", !1);
56
- p(this, "_ready", !1);
55
+ f(this, "inactivating", !1);
56
+ f(this, "_ready", !1);
57
57
  // ready = false;
58
- p(this, "event", new B());
58
+ f(this, "event", new H());
59
59
  //从token解析出来的用户信息
60
- p(this, "_applicationId");
61
- p(this, "_application", null);
62
- p(this, "data", null);
63
- p(this, "client", null);
64
- p(this, "messages", []);
65
- p(this, "_loadingMessages", !1);
66
- p(this, "_loadingMessagesSize", 10);
67
- p(this, "cvforceApi");
68
- p(this, "socket", null);
69
- p(this, "_promptVariables", []);
70
- p(this, "active", !1);
71
- p(this, "activing", !1);
72
- p(this, "_stopAnswer", !1);
73
- p(this, "_dataLoading", !1);
74
- p(this, "_dataLoaded", !1);
75
- p(this, "_mcpServers", null);
76
- this.token = e, this.lazyload = a, this.client = d || null, this._applicationId = z(e).rid || S.applicationId, this.cvforceApi = this.getService(), n && (this._application = n), this.event.emit("init", {
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 r;
80
+ var d;
81
81
  if (t)
82
- this._id = t, this.event.emit("data:loading"), s ? (this.data = s, a || (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((i) => c(this, null, function* () {
83
- this.data = i, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
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((i) => c(this, null, function* () {
87
- this.data = i, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
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 i = (s == null ? void 0 : s.name) || "新建会话";
92
+ const a = (i == null ? void 0 : i.name) || "新建会话";
93
93
  this.event.emit("data:creating", {
94
94
  applicationId: this._applicationId,
95
- name: i
95
+ name: a
96
96
  }), this.event.emit("data:loading"), this.cvforceApi.postSession(this.applicationId, {
97
- name: i,
97
+ name: a,
98
98
  // @ts-ignore
99
- netOpen: s == null ? void 0 : s.netOpen,
100
- knowledgeIdList: (r = s == null ? void 0 : s.knowledges) == null ? void 0 : r.map((h) => h.id),
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((h) => c(this, null, function* () {
102
+ }).then((s) => c(this, null, function* () {
103
103
  var m;
104
- this._id = h.id, this.data = y(f({}, h), {
105
- knowledges: s == null ? void 0 : s.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 (s != null && s.knowledges)
110
- return this.setKnowledges((s == null ? void 0 : s.knowledges) || void 0);
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
- u.error(I);
113
+ l.error(I);
114
114
  }
115
115
  yield (() => {
116
- if (s != null && s.promptVariables) {
117
- const I = this._promptVariables.map((v) => {
118
- var _, o;
119
- const w = ((o = (_ = s.promptVariables) == null ? void 0 : _.find((g) => g.key === v.key && g.type === v.type)) == null ? void 0 : o.value) || "";
120
- return y(f({}, v), {
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((v, w) => v.key.localeCompare(w.key));
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) !== Q.Agent && (this._ready = !0, this.event.emit("ready"));
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((a) => Array.isArray(a.fileIds) && a.fileIds.length === 0))
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((a, n) => {
182
- var r, i;
183
- const d = (i = (r = n.fileIds) == null ? void 0 : r.length) != null ? i : 0;
184
- return a + (d > 0 ? d : 1);
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 === q.Quoted).filter((t) => !t.value);
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(f({}, n), {
212
+ const t = e == null ? void 0 : e.map((n) => n.type ? n : y(u({}, n), {
209
213
  type: "instruction"
210
- })), s = this._promptVariables.map((n) => {
211
- var r;
212
- const d = ((r = t == null ? void 0 : t.find((i) => i.key === n.key && i.type === n.type)) == null ? void 0 : r.value) || n.value;
213
- return y(f({}, n), {
214
- value: d
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, d) => n.key.localeCompare(d.key));
217
- if (!(yield Promise.all(s.filter((n) => !(n.type === L.User && n.key === "query") && !(n.type === L.System && n.key === "datetime")).map((n) => {
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, s, a;
246
- if (u.log("setNetOpen:", e), u.log("application arrange setting value: ", (t = this._application) == null ? void 0 : t.arrange[0].enableNetOpen), ((s = this._application) == null ? void 0 : s.type) === Q.Agent) {
247
- console.warn("Agent Application Sessions are disabled to setNetOpen.");
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 (((a = this._application) == null ? void 0 : a.arrange[0].enableNetOpen) === !1) {
251
- console.warn("This Application is disabled to change netOpen.");
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, u.log("data:updated", this.data), this.event.emit("data:updated", this.data), this.event.emit("data:updated:netOpen", {
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 H(S.apiRoot, this.token, (e, t) => {
266
- const s = new Error("data request error", {
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
- u.error(s), this.event.emit("error", s);
276
+ l.error(i), this.event.emit("error", i);
273
277
  });
274
278
  }
275
- addEventListener(e, t, s = !1) {
279
+ addEventListener(e, t, i = !1) {
276
280
  if (typeof t != "function")
277
281
  throw Error("event listener is not a function");
278
- if (s) {
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 s, a;
298
+ var i, o;
295
299
  const t = {
296
300
  pageSize: this._loadingMessagesSize
297
301
  };
298
302
  if (this._id) {
299
- e = f(f({}, t), e), this.event.emit("history:loading"), u.log("history:loading"), (e.endTime || e.startTime) && (this.event.emit("history:moreloading", e), u.log("history:moreloading", e)), this._loadingMessages = !0;
300
- const n = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), d = n.map((i, h) => {
301
- var v, w;
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 ((v = i.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(i.agentHistoryList.agentList).reduce((o, g) => (o[g.data.step - 1] || (o[g.data.step - 1] = []), o[g.data.step - 1].push(g), o), [])), h === n.length - 1 && (I = (w = this.data) == null ? void 0 : w.lastRelatedQuestion), y(f({}, i), {
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 i = this.messages[this.messages.length - 1];
311
- i && !i.relatedQuesion && (i.relatedQuesion = (s = this.data) == null ? void 0 : s.lastRelatedQuestion), this.messages = [...d, ...this.messages];
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 i = this.messages.findIndex((h) => h.ts === e.endTime);
314
- this.messages.splice(0, i + 1), this.messages = [...d, ...this.messages];
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 i = this.messages.findLastIndex((h) => h.ts === e.endTime);
317
- this.messages.splice(i, this.messages.length - i - 1), this.messages = [...this.messages, ...d];
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 i = this.messages.findIndex((m) => m.ts === e.endTime), h = this.messages.findLastIndex((m) => m.ts === e.endTime);
320
- this.messages.splice(i, h - i + 1, ...d);
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 r = this.messages[this.messages.length - 1];
323
- return r && !r.relatedQuesion && (r.relatedQuesion = (a = this.data) == null ? void 0 : a.lastRelatedQuestion), this.event.emit("history:moreloaded", d), u.log("history:loaded", this.messages), this.event.emit("history:loaded", this.messages), this._loadingMessages = !1, d;
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 u.error(n), this.event.emit("error", n), !1;
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
- }), u.log("data:updated", this.messages), this.event.emit("data:updated", this.data), this.event.emit("data:updated:name", {
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), u.log("history:add", e), this.event.emit("history:add", e), this.event.emit("message:new", e), this.event.emit("message:updated", 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), u.log("data:updated", this.data), this.event.emit("data:updated", this.data), this.data;
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 u.error(e), this.event.emit("error", e), !1;
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((t) => {
393
+ return new Promise((i) => {
389
394
  this.addEventListener("activated", () => {
390
- t(!0);
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((t) => c(this, null, function* () {
398
- return this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, e), t;
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.active = !0, this.activing = !1, 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.active = !1, this.activing = !1, !0) : (this.activing = !1, !0);
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, s, a;
410
- const e = (a = (s = (t = this.application) == null ? void 0 : t.arrange) == null ? void 0 : s[0]) == null ? void 0 : a.autoGenerateSessionTitle;
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 Y(this.cvforceApi, this._id, e);
434
+ return G(this.cvforceApi, this._id, e);
430
435
  });
431
436
  }
432
- send(s) {
437
+ send(i) {
433
438
  return c(this, arguments, function* (e, t = {
434
- stream: S.stream
439
+ stream: _.stream
435
440
  }) {
436
- var _;
441
+ var A, v;
437
442
  try {
438
443
  this.validateConfigs();
439
- } catch (o) {
440
- console.error(o);
444
+ } catch (r) {
445
+ l.report(r);
441
446
  }
442
447
  const {
443
- stream: a = S.stream,
448
+ stream: o = _.stream,
444
449
  referenceFirst: n = !1
445
- } = t, d = e.uuid || x(), r = ((_ = e.text) == null ? void 0 : _.trim()) || "", i = e.files || [], h = e.fileIds, m = e.imageContent;
446
- if (!r && !i.length && !(h != null && h.length)) {
447
- const o = new Error(
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 u.error(o), this.event.emit("error", o), !1;
459
+ return l.error(r), this.event.emit("error", r), !1;
455
460
  }
456
461
  if (!this._id) {
457
- const o = new Error(
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 u.error(o), this.event.emit("error", o), !1;
469
+ return l.error(r), this.event.emit("error", r), !1;
465
470
  }
466
471
  if (this.frozen) {
467
- const o = new Error(
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 u.error(o), this.event.emit("error", o), !1;
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: r,
481
- messageId: d,
491
+ content: d,
492
+ messageId: h,
482
493
  reference: [],
483
494
  searchReference: [],
484
495
  messageTime: "",
485
- files: i,
496
+ files: a,
486
497
  imageContent: m
487
- }, v = {
488
- content: r,
489
- stream: a,
490
- requestId: d,
491
- fileIds: h,
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", r);
496
- const w = (o) => c(this, null, function* () {
497
- if (o.role !== A.Robot)
498
- return;
499
- switch (this.removeEventListener("answer:finish", w), this._id && o.content && o.index && o.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
500
- finialMessage: o.content
501
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
502
- finialMessage: o.content
503
- })), yield this.fillMessageReference(o), o.code) {
504
- case 11915:
505
- o.content = "请您换个问题问我吧~", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
506
- break;
507
- case 11916:
508
- o.content = "尊敬的用户您好,让我们换个话题再聊聊吧。", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
509
- break;
510
- case 200:
511
- o.index = -1, o.isLoading = !1;
512
- break;
513
- default:
514
- o.content = o.message || "未知错误", o.isLoading = !1, o.index = -1, this.event.emit("message:error", o);
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(v, y(f({}, t), {
526
- stream: a,
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 === A.User)
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 r, i;
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 e;
544
- const t = (r = this.application) == null ? void 0 : r.arrange[0], s = P(t == null ? void 0 : t.recommendQuestionOpen, t == null ? void 0 : t.relatedQuestionApp, e.content, this.currentUserQuestion());
545
- if (s === null)
546
- return e;
547
- this.event.emit("message:relatedQuesion:loading", e);
548
- const a = yield this.cvforceApi.postGeneques({
549
- content: s
550
- }).catch((h) => null);
551
- if (!a) {
552
- const h = [], m = y(f({}, e), {
553
- relatedQuesion: h,
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: h
580
+ relatedQuesion: s
559
581
  }), this.event.emit("message:updated", m), m;
560
582
  }
561
- const n = (i = a.content) == null ? void 0 : i.split("*").map(F).map(N).filter((h) => !!h);
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 d = y(f({}, e), {
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", d), this.event.emit("message:updated", d), this._id && this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
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
- }), d;
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((s) => this.cvforceApi.getKnowledgeIdFileId(s.knowledgeId, s.docId)));
577
- e.reference = e.reference.map((s, a) => f(f({}, s), t[a]));
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
- console.error("Failed to fill message reference:", t);
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: S.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: s = S.stream
619
+ stream: i = _.stream
594
620
  } = e;
595
- let a;
596
- t.role !== A.User && (a = e.oldMessageId || t.messageId, this.messages.splice(this.messages.length - 1, 1), this.event.emit("message:remove", t), this.event.emit("history:remove", t));
597
- const n = this.messages[this.messages.length - 1], d = {
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: s,
602
- oldMessageId: a
603
- }, r = (i) => c(this, null, function* () {
604
- if (i.role === A.Robot && i.index === -1) {
605
- switch (this._id && i.content && i.index && i.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
606
- finialMessage: i.content
607
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
608
- finialMessage: i.content
609
- })), yield this.fillMessageReference(i), i.code) {
610
- case 11915:
611
- i.content = "请您换个问题问我吧~", i.index = -1, i.isSensitive = !0, i.isLoading = !1, i.sessionId = this._id || "", this.event.emit("message:error", i);
612
- break;
613
- case 11916:
614
- i.content = "尊敬的用户您好,让我们换个话题再聊聊吧。", i.index = -1, i.isSensitive = !0, i.isLoading = !1, i.sessionId = this._id || "", this.event.emit("message:error", i);
615
- break;
616
- case 200:
617
- i.index = -1, i.isLoading = !1;
618
- break;
619
- default:
620
- i.content = i.message || "未知错误", i.isLoading = !1, i.index = -1, this.event.emit("message:error", i);
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", r), this.sendQuestion(d, y(f({}, e), {
626
- stream: s
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 s;
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: x(),
681
+ messageId: Q(),
653
682
  // 生成唯一的消息 ID
654
683
  isLoading: !1,
655
684
  // 标记消息已停止加载
656
685
  index: -2,
657
686
  // 消息索引,用于标识特殊状态
658
- messageTime: K(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
687
+ messageTime: Y(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
659
688
  // 消息时间
660
689
  content: "",
661
690
  // 消息内容
662
- role: A.System,
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 a = e.actions[((s = e.actions) == null ? void 0 : s.length) - 1];
676
- if (a) {
677
- const n = a[a.length - 1];
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: d,
681
- pluginCode: r,
682
- funcCode: i,
683
- funcName: h
709
+ pluginName: h,
710
+ pluginCode: d,
711
+ funcCode: a,
712
+ funcName: s
684
713
  } = n.data;
685
- a.push({
714
+ o.push({
686
715
  data: {
687
- pluginName: d,
688
- pluginCode: r,
689
- funcCode: i,
690
- funcName: h,
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: a
725
+ action: o
697
726
  });
698
727
  }
699
728
  }
700
729
  }
701
- e = f(f({}, e), t), this.event.emit("message:content", e), this.event.emit("message:updated", 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 d;
741
+ var h;
713
742
  if (!e.data)
714
743
  return;
715
- const s = e.data.type, a = e.data.payload;
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 (s === "error" && (t.index = -1), s === "beforeSearch" && n(), s === "searchOver" && n(), s === "search" && t.searchReference.push(a), s === "thinking") {
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 i = a.choices[0];
730
- t.reasoningContent = (t.reasoningContent || "") + ((d = i.delta.reasoningContent) != null ? d : "");
758
+ const a = o.choices[0];
759
+ t.reasoningContent = (t.reasoningContent || "") + ((h = a.delta.reasoningContent) != null ? h : "");
731
760
  }
732
- if (s === "thinkingOver") {
761
+ if (i === "thinkingOver") {
733
762
  t.thinkingStatus = "end";
734
- const r = a.thinkingSecs;
735
- t.thinkingSecs = r;
763
+ const d = o.thinkingSecs;
764
+ t.thinkingSecs = d;
736
765
  }
737
- if (s === "text") {
738
- const i = a.choices[0];
739
- t.content = (t.content || "") + i.delta.content;
766
+ if (i === "text") {
767
+ const a = o.choices[0];
768
+ t.content = (t.content || "") + a.delta.content;
740
769
  }
741
- if (s === "reference" && (t.reference = a), s === "updateSession" && a && this.data && (this.data = f(f({}, this.data), a), this.event.emit("data:updated", this.data)), s === "result") {
742
- const r = a.messageId, i = a.llmModel, h = a.messageTime;
743
- t.messageId = r, t.llmModel = i, t.messageTime = h;
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
- s === "over" ? t.index = -1 : (t.code = e.code, t.message = e.message);
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 s = this.messages.find((a) => a.messageId === e.messageId);
770
- return s && (s.comment = e, this.event.emit("message:comment", s)), t;
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
- D as SessionErrors,
799
- se as default
827
+ j as SessionErrors,
828
+ ne as default
800
829
  };