@glodon-aiot/bot-client-sdk 3.7.0-alpha.3 → 3.8.0-alpha.5
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 +113 -104
- package/dist/es/DialogSession.mjs +101 -95
- package/dist/es/Session.mjs +113 -98
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +3 -3
- package/dist/src/AgentSession.d.ts +1 -0
- package/dist/src/DialogSession.d.ts +1 -0
- package/dist/src/Session.d.ts +1 -0
- package/package.json +2 -2
package/dist/es/Session.mjs
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
var Q = Object.defineProperty, T = Object.defineProperties;
|
|
2
2
|
var M = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var E = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var O = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var b = (c, e, t) => e in c ? Q(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t, f = (c, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
|
|
7
|
+
O.call(e, t) && b(c, t, e[t]);
|
|
8
8
|
if (E)
|
|
9
9
|
for (var t of E(e))
|
|
10
|
-
R.call(e, t) &&
|
|
10
|
+
R.call(e, t) && b(c, t, e[t]);
|
|
11
11
|
return c;
|
|
12
|
-
},
|
|
13
|
-
var p = (c, e, t) => (
|
|
14
|
-
var h = (c, e, t) => new Promise((i,
|
|
12
|
+
}, I = (c, e) => T(c, M(e));
|
|
13
|
+
var p = (c, e, t) => (b(c, typeof e != "symbol" ? e + "" : e, t), t);
|
|
14
|
+
var h = (c, e, t) => new Promise((i, n) => {
|
|
15
15
|
var a = (s) => {
|
|
16
16
|
try {
|
|
17
17
|
r(t.next(s));
|
|
18
18
|
} catch (l) {
|
|
19
|
-
|
|
19
|
+
n(l);
|
|
20
20
|
}
|
|
21
21
|
}, d = (s) => {
|
|
22
22
|
try {
|
|
23
23
|
r(t.throw(s));
|
|
24
24
|
} catch (l) {
|
|
25
|
-
|
|
25
|
+
n(l);
|
|
26
26
|
}
|
|
27
27
|
}, r = (s) => s.done ? i(s.value) : Promise.resolve(s.value).then(a, d);
|
|
28
28
|
r((t = t.apply(c, e)).next());
|
|
29
29
|
});
|
|
30
30
|
import { v4 as x } from "uuid";
|
|
31
|
-
import { parseJWT as
|
|
32
|
-
import { ApplicationTypes as V, PromptStatus as
|
|
33
|
-
import
|
|
31
|
+
import { parseJWT as z, removeNewlines as P, removeLeadingAndTrailingBackslashes as F } from "./utils.mjs";
|
|
32
|
+
import { ApplicationTypes as V, PromptStatus as N, PromptVariableType as L, ChatMessageRole as S } from "@glodon-aiot/apis";
|
|
33
|
+
import q from "./Logger.mjs";
|
|
34
34
|
import { configuration as A } from "./Config.mjs";
|
|
35
|
-
import
|
|
35
|
+
import U from "./EventBus.mjs";
|
|
36
36
|
import { getCVForceService as B } from "./api/index.mjs";
|
|
37
|
-
import
|
|
38
|
-
const u = new
|
|
39
|
-
var
|
|
40
|
-
class
|
|
37
|
+
import H from "dayjs";
|
|
38
|
+
const C = 100, u = new q("[Session] ");
|
|
39
|
+
var K = /* @__PURE__ */ ((c) => (c.DataRequestFailed = "data request error", c.SocketConnectionFailed = "socket error", c.IdUndefined = "session id is not defined", c.SendingEmptyContent = "failed at sending empty content", c.Frozen = "session is frozen", c.UserModeError = "failed at setting socket user mode", c.Inactive = "session is inactive", c))(K || {});
|
|
40
|
+
class ee {
|
|
41
41
|
/**
|
|
42
42
|
* Session 类的构造函数,用于初始化会话实例。
|
|
43
43
|
* @param token - 用户的身份验证令牌,用于解析应用 ID。
|
|
@@ -47,14 +47,14 @@ class Z {
|
|
|
47
47
|
* @param _application - 应用信息,可选参数。
|
|
48
48
|
* @param client - Bot 客户端实例,可选参数。
|
|
49
49
|
*/
|
|
50
|
-
constructor(e, t = "", i,
|
|
50
|
+
constructor(e, t = "", i, n, a, d) {
|
|
51
51
|
p(this, "_id");
|
|
52
52
|
p(this, "_frozen", !1);
|
|
53
53
|
//是否可发送新问题
|
|
54
54
|
p(this, "inactivating", !1);
|
|
55
55
|
p(this, "_ready", !1);
|
|
56
56
|
// ready = false;
|
|
57
|
-
p(this, "event", new
|
|
57
|
+
p(this, "event", new U());
|
|
58
58
|
//从token解析出来的用户信息
|
|
59
59
|
p(this, "_applicationId");
|
|
60
60
|
p(this, "_application", null);
|
|
@@ -72,13 +72,13 @@ class Z {
|
|
|
72
72
|
p(this, "_dataLoading", !1);
|
|
73
73
|
p(this, "_dataLoaded", !1);
|
|
74
74
|
p(this, "_mcpServers", null);
|
|
75
|
-
this.token = e, this.lazyload =
|
|
75
|
+
this.token = e, this.lazyload = n, this.client = d || null, this._applicationId = z(e).rid || A.applicationId, this.cvforceApi = this.getService(), a && (this._application = a), this.event.emit("init", {
|
|
76
76
|
applicationId: this._applicationId,
|
|
77
77
|
sessionId: t
|
|
78
78
|
}), this.loadApplicationInfo().then(() => {
|
|
79
79
|
var r;
|
|
80
80
|
if (t)
|
|
81
|
-
this._id = t, this.event.emit("data:loading"), i ? (this.data = i,
|
|
81
|
+
this._id = t, this.event.emit("data:loading"), i ? (this.data = i, n || (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((s) => h(this, null, function* () {
|
|
82
82
|
this.data = s, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
|
|
83
83
|
})).then(() => h(this, null, function* () {
|
|
84
84
|
this.messages = [], yield this.fetchMessages(), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data);
|
|
@@ -100,21 +100,27 @@ class Z {
|
|
|
100
100
|
applicationId: this._applicationId
|
|
101
101
|
}).then((l) => h(this, null, function* () {
|
|
102
102
|
var m;
|
|
103
|
-
this._id = l.id, this.data =
|
|
103
|
+
this._id = l.id, this.data = I(f({}, l), {
|
|
104
104
|
knowledges: i == null ? void 0 : i.knowledges
|
|
105
|
-
}), this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
}), this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id);
|
|
106
|
+
try {
|
|
107
|
+
yield (() => h(this, null, function* () {
|
|
108
|
+
if (i != null && i.knowledges)
|
|
109
|
+
return this.setKnowledges((i == null ? void 0 : i.knowledges) || void 0);
|
|
110
|
+
}))();
|
|
111
|
+
} catch (y) {
|
|
112
|
+
u.error(y);
|
|
113
|
+
}
|
|
114
|
+
yield (() => {
|
|
109
115
|
if (i != null && i.promptVariables) {
|
|
110
|
-
const
|
|
111
|
-
var _,
|
|
112
|
-
const
|
|
113
|
-
return
|
|
114
|
-
value:
|
|
116
|
+
const y = this._promptVariables.map((v) => {
|
|
117
|
+
var _, o;
|
|
118
|
+
const w = ((o = (_ = i.promptVariables) == null ? void 0 : _.find((g) => g.key === v.key && g.type === v.type)) == null ? void 0 : o.value) || "";
|
|
119
|
+
return I(f({}, v), {
|
|
120
|
+
value: w
|
|
115
121
|
});
|
|
116
|
-
}).sort((v,
|
|
117
|
-
return this.setPromptVariables(
|
|
122
|
+
}).sort((v, w) => v.key.localeCompare(w.key));
|
|
123
|
+
return this.setPromptVariables(y || []);
|
|
118
124
|
} else
|
|
119
125
|
return;
|
|
120
126
|
})(), 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) !== V.Agent && (this._ready = !0, this.event.emit("ready"));
|
|
@@ -169,6 +175,14 @@ class Z {
|
|
|
169
175
|
return h(this, null, function* () {
|
|
170
176
|
if (!this.data)
|
|
171
177
|
throw Error("session data is not loaded");
|
|
178
|
+
if ((e || []).some((n) => Array.isArray(n.fileIds) && n.fileIds.length === 0))
|
|
179
|
+
throw Error("fileIds cannot be an empty array");
|
|
180
|
+
if ((e || []).reduce((n, a) => {
|
|
181
|
+
var r, s;
|
|
182
|
+
const d = (s = (r = a.fileIds) == null ? void 0 : r.length) != null ? s : 0;
|
|
183
|
+
return n + (d > 0 ? d : 1);
|
|
184
|
+
}, 0) > C)
|
|
185
|
+
throw Error(`knowledges and fileIds total count cannot exceed ${C}`);
|
|
172
186
|
return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
|
|
173
187
|
knowledges: e
|
|
174
188
|
}), this.data.knowledges = e, this.event.emit("data:updated", this.data), this.event.emit("data:updated:knowledges", {
|
|
@@ -181,7 +195,7 @@ class Z {
|
|
|
181
195
|
throw Error("session id is not defined");
|
|
182
196
|
if (!this.data)
|
|
183
197
|
throw Error("session data is not loaded");
|
|
184
|
-
const e = this.promptVariables.filter((t) => t.status ===
|
|
198
|
+
const e = this.promptVariables.filter((t) => t.status === N.Quoted).filter((t) => !t.value);
|
|
185
199
|
if (e.length)
|
|
186
200
|
throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${e.map((t) => t.key).join(", ")}`);
|
|
187
201
|
}
|
|
@@ -190,12 +204,12 @@ class Z {
|
|
|
190
204
|
}
|
|
191
205
|
setPromptVariables(e) {
|
|
192
206
|
return h(this, null, function* () {
|
|
193
|
-
const t = e == null ? void 0 : e.map((a) => a.type ? a :
|
|
207
|
+
const t = e == null ? void 0 : e.map((a) => a.type ? a : I(f({}, a), {
|
|
194
208
|
type: "instruction"
|
|
195
209
|
})), i = this._promptVariables.map((a) => {
|
|
196
210
|
var r;
|
|
197
211
|
const d = ((r = t == null ? void 0 : t.find((s) => s.key === a.key && s.type === a.type)) == null ? void 0 : r.value) || a.value;
|
|
198
|
-
return
|
|
212
|
+
return I(f({}, a), {
|
|
199
213
|
value: d
|
|
200
214
|
});
|
|
201
215
|
}).sort((a, d) => a.key.localeCompare(d.key));
|
|
@@ -227,12 +241,12 @@ class Z {
|
|
|
227
241
|
*/
|
|
228
242
|
setNetOpen(e) {
|
|
229
243
|
return h(this, null, function* () {
|
|
230
|
-
var t, i,
|
|
244
|
+
var t, i, n;
|
|
231
245
|
if (u.log("setNetOpen:", e), u.log("application arrange setting value: ", (t = this._application) == null ? void 0 : t.arrange[0].enableNetOpen), ((i = this._application) == null ? void 0 : i.type) === V.Agent) {
|
|
232
246
|
console.warn("Agent Application Sessions are disabled to setNetOpen.");
|
|
233
247
|
return;
|
|
234
248
|
}
|
|
235
|
-
if (((
|
|
249
|
+
if (((n = this._application) == null ? void 0 : n.arrange[0].enableNetOpen) === !1) {
|
|
236
250
|
console.warn("This Application is disabled to change netOpen.");
|
|
237
251
|
return;
|
|
238
252
|
}
|
|
@@ -276,18 +290,18 @@ class Z {
|
|
|
276
290
|
*/
|
|
277
291
|
fetchMessages() {
|
|
278
292
|
return h(this, arguments, function* (e = {}) {
|
|
279
|
-
var i,
|
|
293
|
+
var i, n;
|
|
280
294
|
const t = {
|
|
281
295
|
pageSize: this._loadingMessagesSize
|
|
282
296
|
};
|
|
283
297
|
if (this._id) {
|
|
284
298
|
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;
|
|
285
299
|
const a = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), d = a.map((s, l) => {
|
|
286
|
-
var v,
|
|
287
|
-
let m = [],
|
|
288
|
-
return typeof ((v = s.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(s.agentHistoryList.agentList).reduce((
|
|
300
|
+
var v, w;
|
|
301
|
+
let m = [], y;
|
|
302
|
+
return typeof ((v = s.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(s.agentHistoryList.agentList).reduce((o, g) => (o[g.data.step - 1] || (o[g.data.step - 1] = []), o[g.data.step - 1].push(g), o), [])), l === a.length - 1 && (y = (w = this.data) == null ? void 0 : w.lastRelatedQuestion), I(f({}, s), {
|
|
289
303
|
actions: m,
|
|
290
|
-
relatedQuesion:
|
|
304
|
+
relatedQuesion: y
|
|
291
305
|
});
|
|
292
306
|
});
|
|
293
307
|
if (!e.endTime && !e.startTime) {
|
|
@@ -304,7 +318,7 @@ class Z {
|
|
|
304
318
|
this.messages.splice(s, l - s + 1, ...d);
|
|
305
319
|
}
|
|
306
320
|
const r = this.messages[this.messages.length - 1];
|
|
307
|
-
return r && !r.relatedQuesion && (r.relatedQuesion = (
|
|
321
|
+
return r && !r.relatedQuesion && (r.relatedQuesion = (n = this.data) == null ? void 0 : n.lastRelatedQuestion), this.event.emit("history:moreloaded", d), u.log("history:loaded", this.messages), this.event.emit("history:loaded", this.messages), this._loadingMessages = !1, d;
|
|
308
322
|
} else {
|
|
309
323
|
const a = new Error(
|
|
310
324
|
"session id is not defined"
|
|
@@ -401,45 +415,45 @@ class Z {
|
|
|
401
415
|
var _;
|
|
402
416
|
try {
|
|
403
417
|
this.validateConfigs();
|
|
404
|
-
} catch (
|
|
405
|
-
console.error(
|
|
418
|
+
} catch (o) {
|
|
419
|
+
console.error(o);
|
|
406
420
|
}
|
|
407
421
|
const {
|
|
408
|
-
stream:
|
|
422
|
+
stream: n = A.stream,
|
|
409
423
|
referenceFirst: a = !1
|
|
410
424
|
} = t, d = e.uuid || x(), r = ((_ = e.text) == null ? void 0 : _.trim()) || "", s = e.files || [], l = e.fileIds, m = e.imageContent;
|
|
411
425
|
if (!r && !s.length && !(l != null && l.length)) {
|
|
412
|
-
const
|
|
426
|
+
const o = new Error(
|
|
413
427
|
"failed at sending empty content"
|
|
414
428
|
/* SendingEmptyContent */
|
|
415
429
|
// {
|
|
416
430
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.SendingEmptyContent],
|
|
417
431
|
// }
|
|
418
432
|
);
|
|
419
|
-
return u.error(
|
|
433
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
420
434
|
}
|
|
421
435
|
if (!this._id) {
|
|
422
|
-
const
|
|
436
|
+
const o = new Error(
|
|
423
437
|
"session id is not defined"
|
|
424
438
|
/* IdUndefined */
|
|
425
439
|
// {
|
|
426
440
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
427
441
|
// }
|
|
428
442
|
);
|
|
429
|
-
return u.error(
|
|
443
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
430
444
|
}
|
|
431
445
|
if (this.frozen) {
|
|
432
|
-
const
|
|
446
|
+
const o = new Error(
|
|
433
447
|
"session is frozen"
|
|
434
448
|
/* Frozen */
|
|
435
449
|
// {
|
|
436
450
|
// cause: { code: -1, message: 'session is frozen.' },
|
|
437
451
|
// }
|
|
438
452
|
);
|
|
439
|
-
return u.error(
|
|
453
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
440
454
|
}
|
|
441
455
|
this.frozen = !0, this._stopAnswer = !1;
|
|
442
|
-
const
|
|
456
|
+
const y = {
|
|
443
457
|
sessionId: this.id,
|
|
444
458
|
role: 2,
|
|
445
459
|
content: r,
|
|
@@ -451,43 +465,43 @@ class Z {
|
|
|
451
465
|
imageContent: m
|
|
452
466
|
}, v = {
|
|
453
467
|
content: r,
|
|
454
|
-
stream:
|
|
468
|
+
stream: n,
|
|
455
469
|
requestId: d,
|
|
456
470
|
fileIds: l,
|
|
457
471
|
referenceFirst: a,
|
|
458
472
|
imageContent: m
|
|
459
473
|
};
|
|
460
|
-
this.pushMessage(
|
|
461
|
-
const
|
|
462
|
-
if (
|
|
474
|
+
this.pushMessage(y), this.event.emit("question:content", r);
|
|
475
|
+
const w = (o) => h(this, null, function* () {
|
|
476
|
+
if (o.role !== S.Robot)
|
|
463
477
|
return;
|
|
464
|
-
switch (this.removeEventListener("answer:finish",
|
|
465
|
-
finialMessage:
|
|
478
|
+
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, {
|
|
479
|
+
finialMessage: o.content
|
|
466
480
|
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
467
|
-
finialMessage:
|
|
468
|
-
})), yield this.fillMessageReference(
|
|
481
|
+
finialMessage: o.content
|
|
482
|
+
})), yield this.fillMessageReference(o), o.code) {
|
|
469
483
|
case 11915:
|
|
470
|
-
|
|
484
|
+
o.content = "请您换个问题问我吧~", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
|
|
471
485
|
break;
|
|
472
486
|
case 200:
|
|
473
|
-
|
|
487
|
+
o.index = -1, o.isLoading = !1;
|
|
474
488
|
break;
|
|
475
489
|
default:
|
|
476
|
-
|
|
490
|
+
o.content = o.message || "未知错误", o.isLoading = !1, o.index = -1, this.event.emit("message:error", o);
|
|
477
491
|
}
|
|
478
|
-
this.getRelatedQuesion(
|
|
492
|
+
this.getRelatedQuesion(o), o.isLoading = !1;
|
|
479
493
|
let g = this.messages[this.messages.length - 1];
|
|
480
494
|
if (g && g.role === S.Robot) {
|
|
481
|
-
const
|
|
482
|
-
this.messages[this.messages.length - 1] =
|
|
495
|
+
const k = f(f({}, g), o);
|
|
496
|
+
this.messages[this.messages.length - 1] = k, this.event.emit("message:updated", k);
|
|
483
497
|
} else
|
|
484
|
-
this.pushMessage(
|
|
498
|
+
this.pushMessage(o);
|
|
485
499
|
this.frozen = !1;
|
|
486
500
|
});
|
|
487
|
-
return this.addEventListener("answer:finish",
|
|
488
|
-
stream:
|
|
501
|
+
return this.addEventListener("answer:finish", w), this.sendQuestion(v, I(f({}, t), {
|
|
502
|
+
stream: n,
|
|
489
503
|
referenceFirst: a
|
|
490
|
-
})),
|
|
504
|
+
})), y;
|
|
491
505
|
});
|
|
492
506
|
}
|
|
493
507
|
getRelatedQuesion(e) {
|
|
@@ -500,7 +514,7 @@ class Z {
|
|
|
500
514
|
content: e.content
|
|
501
515
|
}).catch((r) => null);
|
|
502
516
|
if (!t) {
|
|
503
|
-
const r = [], s =
|
|
517
|
+
const r = [], s = I(f({}, e), {
|
|
504
518
|
relatedQuesion: r,
|
|
505
519
|
index: -3,
|
|
506
520
|
isLoading: !1
|
|
@@ -509,23 +523,23 @@ class Z {
|
|
|
509
523
|
relatedQuesion: r
|
|
510
524
|
}), this.event.emit("message:updated", s), s;
|
|
511
525
|
}
|
|
512
|
-
const i = (d = t.content) == null ? void 0 : d.split("*").map(
|
|
526
|
+
const i = (d = t.content) == null ? void 0 : d.split("*").map(P).map(F).filter((r) => !!r);
|
|
513
527
|
e.relatedQuesion = i, e.index = -3, e.isLoading = !1;
|
|
514
|
-
const
|
|
528
|
+
const n = I(f({}, e), {
|
|
515
529
|
relatedQuesion: i,
|
|
516
530
|
index: -3,
|
|
517
531
|
isLoading: !1
|
|
518
532
|
});
|
|
519
|
-
return this.event.emit("message:relatedQuesion:loaded",
|
|
533
|
+
return this.event.emit("message:relatedQuesion:loaded", n), this.event.emit("message:updated", n), this._id && this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
|
|
520
534
|
lastRelatedQuestion: i
|
|
521
|
-
}),
|
|
535
|
+
}), n;
|
|
522
536
|
});
|
|
523
537
|
}
|
|
524
538
|
fillMessageReference(e) {
|
|
525
539
|
return h(this, null, function* () {
|
|
526
540
|
try {
|
|
527
541
|
const t = yield Promise.all(e.reference.map((i) => this.cvforceApi.getKnowledgeIdFileId(i.knowledgeId, i.docId)));
|
|
528
|
-
e.reference = e.reference.map((i,
|
|
542
|
+
e.reference = e.reference.map((i, n) => f(f({}, i), t[n]));
|
|
529
543
|
} catch (t) {
|
|
530
544
|
console.error("Failed to fill message reference:", t);
|
|
531
545
|
}
|
|
@@ -543,14 +557,14 @@ class Z {
|
|
|
543
557
|
const {
|
|
544
558
|
stream: i = A.stream
|
|
545
559
|
} = e;
|
|
546
|
-
let
|
|
547
|
-
t.role !== S.User && (
|
|
560
|
+
let n;
|
|
561
|
+
t.role !== S.User && (n = e.oldMessageId || t.messageId, this.messages.splice(this.messages.length - 1, 1), this.event.emit("message:remove", t), this.event.emit("history:remove", t));
|
|
548
562
|
const a = this.messages[this.messages.length - 1], d = {
|
|
549
563
|
content: a.content,
|
|
550
564
|
fileIds: a.fileIds,
|
|
551
565
|
requestId: a.messageId,
|
|
552
566
|
stream: i,
|
|
553
|
-
oldMessageId:
|
|
567
|
+
oldMessageId: n
|
|
554
568
|
}, r = (s) => h(this, null, function* () {
|
|
555
569
|
if (s.role === S.Robot && s.index === -1) {
|
|
556
570
|
switch (this._id && s.content && s.index && s.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
@@ -570,7 +584,7 @@ class Z {
|
|
|
570
584
|
this.getRelatedQuesion(s), this.removeEventListener("message:content", r), this.frozen = !1;
|
|
571
585
|
}
|
|
572
586
|
});
|
|
573
|
-
this.addEventListener("message:content", r), this.sendQuestion(d,
|
|
587
|
+
this.addEventListener("message:content", r), this.sendQuestion(d, I(f({}, e), {
|
|
574
588
|
stream: i
|
|
575
589
|
}));
|
|
576
590
|
});
|
|
@@ -603,7 +617,7 @@ class Z {
|
|
|
603
617
|
// 标记消息已停止加载
|
|
604
618
|
index: -2,
|
|
605
619
|
// 消息索引,用于标识特殊状态
|
|
606
|
-
messageTime:
|
|
620
|
+
messageTime: H(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
|
|
607
621
|
// 消息时间
|
|
608
622
|
content: "",
|
|
609
623
|
// 消息内容
|
|
@@ -620,9 +634,9 @@ class Z {
|
|
|
620
634
|
if (e.index === -2)
|
|
621
635
|
return;
|
|
622
636
|
if (e.actions) {
|
|
623
|
-
const
|
|
624
|
-
if (
|
|
625
|
-
const a =
|
|
637
|
+
const n = e.actions[((i = e.actions) == null ? void 0 : i.length) - 1];
|
|
638
|
+
if (n) {
|
|
639
|
+
const a = n[n.length - 1];
|
|
626
640
|
if (a && (a.type === "BEFORE_CALL" || a.type === "FUNCTION_CALL")) {
|
|
627
641
|
const {
|
|
628
642
|
pluginName: d,
|
|
@@ -630,7 +644,7 @@ class Z {
|
|
|
630
644
|
funcCode: s,
|
|
631
645
|
funcName: l
|
|
632
646
|
} = a.data;
|
|
633
|
-
|
|
647
|
+
n.push({
|
|
634
648
|
data: {
|
|
635
649
|
pluginName: d,
|
|
636
650
|
pluginCode: r,
|
|
@@ -641,7 +655,7 @@ class Z {
|
|
|
641
655
|
type: "ABORT"
|
|
642
656
|
}), this.event.emit("message:action", {
|
|
643
657
|
messageId: e.messageId,
|
|
644
|
-
action:
|
|
658
|
+
action: n
|
|
645
659
|
});
|
|
646
660
|
}
|
|
647
661
|
}
|
|
@@ -659,7 +673,7 @@ class Z {
|
|
|
659
673
|
handleStreamAnswer(e, t) {
|
|
660
674
|
if (!e.data)
|
|
661
675
|
return;
|
|
662
|
-
const i = e.data.type,
|
|
676
|
+
const i = e.data.type, n = e.data.payload;
|
|
663
677
|
t.isReplying = !0;
|
|
664
678
|
const a = () => {
|
|
665
679
|
if (!t.searchingStatus) {
|
|
@@ -671,22 +685,22 @@ class Z {
|
|
|
671
685
|
return;
|
|
672
686
|
}
|
|
673
687
|
};
|
|
674
|
-
if (i === "error" && (t.index = -1), i === "beforeSearch" && a(), i === "searchOver" && a(), i === "search" && t.searchReference.push(
|
|
688
|
+
if (i === "error" && (t.index = -1), i === "beforeSearch" && a(), i === "searchOver" && a(), i === "search" && t.searchReference.push(n), i === "thinking") {
|
|
675
689
|
t.thinkingStatus = "start";
|
|
676
|
-
const r =
|
|
690
|
+
const r = n.choices[0];
|
|
677
691
|
t.reasoningContent = t.reasoningContent + r.delta.reasoningContent;
|
|
678
692
|
}
|
|
679
693
|
if (i === "thinkingOver") {
|
|
680
694
|
t.thinkingStatus = "end";
|
|
681
|
-
const d =
|
|
695
|
+
const d = n.thinkingSecs;
|
|
682
696
|
t.thinkingSecs = d;
|
|
683
697
|
}
|
|
684
698
|
if (i === "text") {
|
|
685
|
-
const r =
|
|
699
|
+
const r = n.choices[0];
|
|
686
700
|
t.content = t.content + r.delta.content;
|
|
687
701
|
}
|
|
688
|
-
if (i === "reference" && (t.reference =
|
|
689
|
-
const d =
|
|
702
|
+
if (i === "reference" && (t.reference = n), i === "updateSession" && n && this.data && (this.data = f(f({}, this.data), n), this.event.emit("data:updated", this.data)), i === "result") {
|
|
703
|
+
const d = n.messageId, r = n.llmModel, s = n.messageTime;
|
|
690
704
|
t.messageId = d, t.llmModel = r, t.messageTime = s;
|
|
691
705
|
}
|
|
692
706
|
i === "over" ? t.index = -1 : (t.code = e.code, t.message = e.message);
|
|
@@ -701,7 +715,7 @@ class Z {
|
|
|
701
715
|
if (!this._applicationId || !this._id)
|
|
702
716
|
throw Error("session is not avalible. id is undefined");
|
|
703
717
|
return this.cvforceApi.postComments(this._applicationId, this._id, e).then((t) => {
|
|
704
|
-
const i = this.messages.find((
|
|
718
|
+
const i = this.messages.find((n) => n.messageId === e.messageId);
|
|
705
719
|
return i && (i.comment = e, this.event.emit("message:comment", i)), t;
|
|
706
720
|
});
|
|
707
721
|
});
|
|
@@ -729,6 +743,7 @@ class Z {
|
|
|
729
743
|
}
|
|
730
744
|
}
|
|
731
745
|
export {
|
|
732
|
-
|
|
733
|
-
|
|
746
|
+
C as MAX_KNOWLEDGES_AND_FILES_COUNT,
|
|
747
|
+
K as SessionErrors,
|
|
748
|
+
ee as default
|
|
734
749
|
};
|
package/dist/es/package.json.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e = "@glodon-aiot/bot-client-sdk", t = "3.
|
|
1
|
+
const e = "@glodon-aiot/bot-client-sdk", t = "3.8.0-alpha.5", i = "glodoncv", s = "aiot bot client js sdk", n = "module", y = !1, o = [
|
|
2
2
|
"aiot",
|
|
3
3
|
"bot",
|
|
4
4
|
"bot client",
|
|
@@ -59,7 +59,7 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.7.0-alpha.3", i = "glodoncv", s
|
|
|
59
59
|
access: "public",
|
|
60
60
|
registry: "https://registry.npmjs.org/"
|
|
61
61
|
}, b = {
|
|
62
|
-
"@glodon-aiot/apis": "^3.
|
|
62
|
+
"@glodon-aiot/apis": "^3.8.0-alpha.5",
|
|
63
63
|
axios: "0.24.0",
|
|
64
64
|
buffer: "^6.0.3",
|
|
65
65
|
dayjs: "^1.11.13",
|