@glodon-aiot/bot-client-sdk 3.7.0-alpha.2 → 3.8.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/AgentSession.mjs +113 -104
- package/dist/es/DialogSession.mjs +101 -95
- package/dist/es/Session.mjs +96 -87
- 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,7 +100,7 @@ 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
105
|
}), this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id), yield (() => h(this, null, function* () {
|
|
106
106
|
if (i != null && i.knowledges)
|
|
@@ -108,12 +108,12 @@ class Z {
|
|
|
108
108
|
}))(), yield (() => {
|
|
109
109
|
if (i != null && i.promptVariables) {
|
|
110
110
|
const w = this._promptVariables.map((v) => {
|
|
111
|
-
var _,
|
|
112
|
-
const
|
|
113
|
-
return
|
|
114
|
-
value:
|
|
111
|
+
var _, o;
|
|
112
|
+
const y = ((o = (_ = i.promptVariables) == null ? void 0 : _.find((g) => g.key === v.key && g.type === v.type)) == null ? void 0 : o.value) || "";
|
|
113
|
+
return I(f({}, v), {
|
|
114
|
+
value: y
|
|
115
115
|
});
|
|
116
|
-
}).sort((v,
|
|
116
|
+
}).sort((v, y) => v.key.localeCompare(y.key));
|
|
117
117
|
return this.setPromptVariables(w || []);
|
|
118
118
|
} else
|
|
119
119
|
return;
|
|
@@ -169,6 +169,14 @@ class Z {
|
|
|
169
169
|
return h(this, null, function* () {
|
|
170
170
|
if (!this.data)
|
|
171
171
|
throw Error("session data is not loaded");
|
|
172
|
+
if ((e || []).some((n) => Array.isArray(n.fileIds) && n.fileIds.length === 0))
|
|
173
|
+
throw Error("fileIds cannot be an empty array");
|
|
174
|
+
if ((e || []).reduce((n, a) => {
|
|
175
|
+
var r, s;
|
|
176
|
+
const d = (s = (r = a.fileIds) == null ? void 0 : r.length) != null ? s : 0;
|
|
177
|
+
return n + (d > 0 ? d : 1);
|
|
178
|
+
}, 0) > C)
|
|
179
|
+
throw Error(`knowledges and fileIds total count cannot exceed ${C}`);
|
|
172
180
|
return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
|
|
173
181
|
knowledges: e
|
|
174
182
|
}), this.data.knowledges = e, this.event.emit("data:updated", this.data), this.event.emit("data:updated:knowledges", {
|
|
@@ -181,7 +189,7 @@ class Z {
|
|
|
181
189
|
throw Error("session id is not defined");
|
|
182
190
|
if (!this.data)
|
|
183
191
|
throw Error("session data is not loaded");
|
|
184
|
-
const e = this.promptVariables.filter((t) => t.status ===
|
|
192
|
+
const e = this.promptVariables.filter((t) => t.status === N.Quoted).filter((t) => !t.value);
|
|
185
193
|
if (e.length)
|
|
186
194
|
throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${e.map((t) => t.key).join(", ")}`);
|
|
187
195
|
}
|
|
@@ -190,12 +198,12 @@ class Z {
|
|
|
190
198
|
}
|
|
191
199
|
setPromptVariables(e) {
|
|
192
200
|
return h(this, null, function* () {
|
|
193
|
-
const t = e == null ? void 0 : e.map((a) => a.type ? a :
|
|
201
|
+
const t = e == null ? void 0 : e.map((a) => a.type ? a : I(f({}, a), {
|
|
194
202
|
type: "instruction"
|
|
195
203
|
})), i = this._promptVariables.map((a) => {
|
|
196
204
|
var r;
|
|
197
205
|
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
|
|
206
|
+
return I(f({}, a), {
|
|
199
207
|
value: d
|
|
200
208
|
});
|
|
201
209
|
}).sort((a, d) => a.key.localeCompare(d.key));
|
|
@@ -227,12 +235,12 @@ class Z {
|
|
|
227
235
|
*/
|
|
228
236
|
setNetOpen(e) {
|
|
229
237
|
return h(this, null, function* () {
|
|
230
|
-
var t, i,
|
|
238
|
+
var t, i, n;
|
|
231
239
|
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
240
|
console.warn("Agent Application Sessions are disabled to setNetOpen.");
|
|
233
241
|
return;
|
|
234
242
|
}
|
|
235
|
-
if (((
|
|
243
|
+
if (((n = this._application) == null ? void 0 : n.arrange[0].enableNetOpen) === !1) {
|
|
236
244
|
console.warn("This Application is disabled to change netOpen.");
|
|
237
245
|
return;
|
|
238
246
|
}
|
|
@@ -276,16 +284,16 @@ class Z {
|
|
|
276
284
|
*/
|
|
277
285
|
fetchMessages() {
|
|
278
286
|
return h(this, arguments, function* (e = {}) {
|
|
279
|
-
var i,
|
|
287
|
+
var i, n;
|
|
280
288
|
const t = {
|
|
281
289
|
pageSize: this._loadingMessagesSize
|
|
282
290
|
};
|
|
283
291
|
if (this._id) {
|
|
284
292
|
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
293
|
const a = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), d = a.map((s, l) => {
|
|
286
|
-
var v,
|
|
294
|
+
var v, y;
|
|
287
295
|
let m = [], w;
|
|
288
|
-
return typeof ((v = s.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(s.agentHistoryList.agentList).reduce((
|
|
296
|
+
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 && (w = (y = this.data) == null ? void 0 : y.lastRelatedQuestion), I(f({}, s), {
|
|
289
297
|
actions: m,
|
|
290
298
|
relatedQuesion: w
|
|
291
299
|
});
|
|
@@ -304,7 +312,7 @@ class Z {
|
|
|
304
312
|
this.messages.splice(s, l - s + 1, ...d);
|
|
305
313
|
}
|
|
306
314
|
const r = this.messages[this.messages.length - 1];
|
|
307
|
-
return r && !r.relatedQuesion && (r.relatedQuesion = (
|
|
315
|
+
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
316
|
} else {
|
|
309
317
|
const a = new Error(
|
|
310
318
|
"session id is not defined"
|
|
@@ -401,42 +409,42 @@ class Z {
|
|
|
401
409
|
var _;
|
|
402
410
|
try {
|
|
403
411
|
this.validateConfigs();
|
|
404
|
-
} catch (
|
|
405
|
-
console.error(
|
|
412
|
+
} catch (o) {
|
|
413
|
+
console.error(o);
|
|
406
414
|
}
|
|
407
415
|
const {
|
|
408
|
-
stream:
|
|
416
|
+
stream: n = A.stream,
|
|
409
417
|
referenceFirst: a = !1
|
|
410
418
|
} = t, d = e.uuid || x(), r = ((_ = e.text) == null ? void 0 : _.trim()) || "", s = e.files || [], l = e.fileIds, m = e.imageContent;
|
|
411
419
|
if (!r && !s.length && !(l != null && l.length)) {
|
|
412
|
-
const
|
|
420
|
+
const o = new Error(
|
|
413
421
|
"failed at sending empty content"
|
|
414
422
|
/* SendingEmptyContent */
|
|
415
423
|
// {
|
|
416
424
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.SendingEmptyContent],
|
|
417
425
|
// }
|
|
418
426
|
);
|
|
419
|
-
return u.error(
|
|
427
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
420
428
|
}
|
|
421
429
|
if (!this._id) {
|
|
422
|
-
const
|
|
430
|
+
const o = new Error(
|
|
423
431
|
"session id is not defined"
|
|
424
432
|
/* IdUndefined */
|
|
425
433
|
// {
|
|
426
434
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
427
435
|
// }
|
|
428
436
|
);
|
|
429
|
-
return u.error(
|
|
437
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
430
438
|
}
|
|
431
439
|
if (this.frozen) {
|
|
432
|
-
const
|
|
440
|
+
const o = new Error(
|
|
433
441
|
"session is frozen"
|
|
434
442
|
/* Frozen */
|
|
435
443
|
// {
|
|
436
444
|
// cause: { code: -1, message: 'session is frozen.' },
|
|
437
445
|
// }
|
|
438
446
|
);
|
|
439
|
-
return u.error(
|
|
447
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
440
448
|
}
|
|
441
449
|
this.frozen = !0, this._stopAnswer = !1;
|
|
442
450
|
const w = {
|
|
@@ -451,41 +459,41 @@ class Z {
|
|
|
451
459
|
imageContent: m
|
|
452
460
|
}, v = {
|
|
453
461
|
content: r,
|
|
454
|
-
stream:
|
|
462
|
+
stream: n,
|
|
455
463
|
requestId: d,
|
|
456
464
|
fileIds: l,
|
|
457
465
|
referenceFirst: a,
|
|
458
466
|
imageContent: m
|
|
459
467
|
};
|
|
460
468
|
this.pushMessage(w), this.event.emit("question:content", r);
|
|
461
|
-
const
|
|
462
|
-
if (
|
|
469
|
+
const y = (o) => h(this, null, function* () {
|
|
470
|
+
if (o.role !== S.Robot)
|
|
463
471
|
return;
|
|
464
|
-
switch (this.removeEventListener("answer:finish",
|
|
465
|
-
finialMessage:
|
|
472
|
+
switch (this.removeEventListener("answer:finish", y), this._id && o.content && o.index && o.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
473
|
+
finialMessage: o.content
|
|
466
474
|
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
467
|
-
finialMessage:
|
|
468
|
-
})), yield this.fillMessageReference(
|
|
475
|
+
finialMessage: o.content
|
|
476
|
+
})), yield this.fillMessageReference(o), o.code) {
|
|
469
477
|
case 11915:
|
|
470
|
-
|
|
478
|
+
o.content = "请您换个问题问我吧~", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
|
|
471
479
|
break;
|
|
472
480
|
case 200:
|
|
473
|
-
|
|
481
|
+
o.index = -1, o.isLoading = !1;
|
|
474
482
|
break;
|
|
475
483
|
default:
|
|
476
|
-
|
|
484
|
+
o.content = o.message || "未知错误", o.isLoading = !1, o.index = -1, this.event.emit("message:error", o);
|
|
477
485
|
}
|
|
478
|
-
this.getRelatedQuesion(
|
|
486
|
+
this.getRelatedQuesion(o), o.isLoading = !1;
|
|
479
487
|
let g = this.messages[this.messages.length - 1];
|
|
480
488
|
if (g && g.role === S.Robot) {
|
|
481
|
-
const
|
|
482
|
-
this.messages[this.messages.length - 1] =
|
|
489
|
+
const k = f(f({}, g), o);
|
|
490
|
+
this.messages[this.messages.length - 1] = k, this.event.emit("message:updated", k);
|
|
483
491
|
} else
|
|
484
|
-
this.pushMessage(
|
|
492
|
+
this.pushMessage(o);
|
|
485
493
|
this.frozen = !1;
|
|
486
494
|
});
|
|
487
|
-
return this.addEventListener("answer:finish",
|
|
488
|
-
stream:
|
|
495
|
+
return this.addEventListener("answer:finish", y), this.sendQuestion(v, I(f({}, t), {
|
|
496
|
+
stream: n,
|
|
489
497
|
referenceFirst: a
|
|
490
498
|
})), w;
|
|
491
499
|
});
|
|
@@ -500,7 +508,7 @@ class Z {
|
|
|
500
508
|
content: e.content
|
|
501
509
|
}).catch((r) => null);
|
|
502
510
|
if (!t) {
|
|
503
|
-
const r = [], s =
|
|
511
|
+
const r = [], s = I(f({}, e), {
|
|
504
512
|
relatedQuesion: r,
|
|
505
513
|
index: -3,
|
|
506
514
|
isLoading: !1
|
|
@@ -509,23 +517,23 @@ class Z {
|
|
|
509
517
|
relatedQuesion: r
|
|
510
518
|
}), this.event.emit("message:updated", s), s;
|
|
511
519
|
}
|
|
512
|
-
const i = (d = t.content) == null ? void 0 : d.split("*").map(
|
|
520
|
+
const i = (d = t.content) == null ? void 0 : d.split("*").map(P).map(F).filter((r) => !!r);
|
|
513
521
|
e.relatedQuesion = i, e.index = -3, e.isLoading = !1;
|
|
514
|
-
const
|
|
522
|
+
const n = I(f({}, e), {
|
|
515
523
|
relatedQuesion: i,
|
|
516
524
|
index: -3,
|
|
517
525
|
isLoading: !1
|
|
518
526
|
});
|
|
519
|
-
return this.event.emit("message:relatedQuesion:loaded",
|
|
527
|
+
return this.event.emit("message:relatedQuesion:loaded", n), this.event.emit("message:updated", n), this._id && this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
|
|
520
528
|
lastRelatedQuestion: i
|
|
521
|
-
}),
|
|
529
|
+
}), n;
|
|
522
530
|
});
|
|
523
531
|
}
|
|
524
532
|
fillMessageReference(e) {
|
|
525
533
|
return h(this, null, function* () {
|
|
526
534
|
try {
|
|
527
535
|
const t = yield Promise.all(e.reference.map((i) => this.cvforceApi.getKnowledgeIdFileId(i.knowledgeId, i.docId)));
|
|
528
|
-
e.reference = e.reference.map((i,
|
|
536
|
+
e.reference = e.reference.map((i, n) => f(f({}, i), t[n]));
|
|
529
537
|
} catch (t) {
|
|
530
538
|
console.error("Failed to fill message reference:", t);
|
|
531
539
|
}
|
|
@@ -543,14 +551,14 @@ class Z {
|
|
|
543
551
|
const {
|
|
544
552
|
stream: i = A.stream
|
|
545
553
|
} = e;
|
|
546
|
-
let
|
|
547
|
-
t.role !== S.User && (
|
|
554
|
+
let n;
|
|
555
|
+
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
556
|
const a = this.messages[this.messages.length - 1], d = {
|
|
549
557
|
content: a.content,
|
|
550
558
|
fileIds: a.fileIds,
|
|
551
559
|
requestId: a.messageId,
|
|
552
560
|
stream: i,
|
|
553
|
-
oldMessageId:
|
|
561
|
+
oldMessageId: n
|
|
554
562
|
}, r = (s) => h(this, null, function* () {
|
|
555
563
|
if (s.role === S.Robot && s.index === -1) {
|
|
556
564
|
switch (this._id && s.content && s.index && s.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
@@ -570,7 +578,7 @@ class Z {
|
|
|
570
578
|
this.getRelatedQuesion(s), this.removeEventListener("message:content", r), this.frozen = !1;
|
|
571
579
|
}
|
|
572
580
|
});
|
|
573
|
-
this.addEventListener("message:content", r), this.sendQuestion(d,
|
|
581
|
+
this.addEventListener("message:content", r), this.sendQuestion(d, I(f({}, e), {
|
|
574
582
|
stream: i
|
|
575
583
|
}));
|
|
576
584
|
});
|
|
@@ -603,7 +611,7 @@ class Z {
|
|
|
603
611
|
// 标记消息已停止加载
|
|
604
612
|
index: -2,
|
|
605
613
|
// 消息索引,用于标识特殊状态
|
|
606
|
-
messageTime:
|
|
614
|
+
messageTime: H(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
|
|
607
615
|
// 消息时间
|
|
608
616
|
content: "",
|
|
609
617
|
// 消息内容
|
|
@@ -620,9 +628,9 @@ class Z {
|
|
|
620
628
|
if (e.index === -2)
|
|
621
629
|
return;
|
|
622
630
|
if (e.actions) {
|
|
623
|
-
const
|
|
624
|
-
if (
|
|
625
|
-
const a =
|
|
631
|
+
const n = e.actions[((i = e.actions) == null ? void 0 : i.length) - 1];
|
|
632
|
+
if (n) {
|
|
633
|
+
const a = n[n.length - 1];
|
|
626
634
|
if (a && (a.type === "BEFORE_CALL" || a.type === "FUNCTION_CALL")) {
|
|
627
635
|
const {
|
|
628
636
|
pluginName: d,
|
|
@@ -630,7 +638,7 @@ class Z {
|
|
|
630
638
|
funcCode: s,
|
|
631
639
|
funcName: l
|
|
632
640
|
} = a.data;
|
|
633
|
-
|
|
641
|
+
n.push({
|
|
634
642
|
data: {
|
|
635
643
|
pluginName: d,
|
|
636
644
|
pluginCode: r,
|
|
@@ -641,7 +649,7 @@ class Z {
|
|
|
641
649
|
type: "ABORT"
|
|
642
650
|
}), this.event.emit("message:action", {
|
|
643
651
|
messageId: e.messageId,
|
|
644
|
-
action:
|
|
652
|
+
action: n
|
|
645
653
|
});
|
|
646
654
|
}
|
|
647
655
|
}
|
|
@@ -659,7 +667,7 @@ class Z {
|
|
|
659
667
|
handleStreamAnswer(e, t) {
|
|
660
668
|
if (!e.data)
|
|
661
669
|
return;
|
|
662
|
-
const i = e.data.type,
|
|
670
|
+
const i = e.data.type, n = e.data.payload;
|
|
663
671
|
t.isReplying = !0;
|
|
664
672
|
const a = () => {
|
|
665
673
|
if (!t.searchingStatus) {
|
|
@@ -671,22 +679,22 @@ class Z {
|
|
|
671
679
|
return;
|
|
672
680
|
}
|
|
673
681
|
};
|
|
674
|
-
if (i === "error" && (t.index = -1), i === "beforeSearch" && a(), i === "searchOver" && a(), i === "search" && t.searchReference.push(
|
|
682
|
+
if (i === "error" && (t.index = -1), i === "beforeSearch" && a(), i === "searchOver" && a(), i === "search" && t.searchReference.push(n), i === "thinking") {
|
|
675
683
|
t.thinkingStatus = "start";
|
|
676
|
-
const r =
|
|
684
|
+
const r = n.choices[0];
|
|
677
685
|
t.reasoningContent = t.reasoningContent + r.delta.reasoningContent;
|
|
678
686
|
}
|
|
679
687
|
if (i === "thinkingOver") {
|
|
680
688
|
t.thinkingStatus = "end";
|
|
681
|
-
const d =
|
|
689
|
+
const d = n.thinkingSecs;
|
|
682
690
|
t.thinkingSecs = d;
|
|
683
691
|
}
|
|
684
692
|
if (i === "text") {
|
|
685
|
-
const r =
|
|
693
|
+
const r = n.choices[0];
|
|
686
694
|
t.content = t.content + r.delta.content;
|
|
687
695
|
}
|
|
688
|
-
if (i === "reference" && (t.reference =
|
|
689
|
-
const d =
|
|
696
|
+
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") {
|
|
697
|
+
const d = n.messageId, r = n.llmModel, s = n.messageTime;
|
|
690
698
|
t.messageId = d, t.llmModel = r, t.messageTime = s;
|
|
691
699
|
}
|
|
692
700
|
i === "over" ? t.index = -1 : (t.code = e.code, t.message = e.message);
|
|
@@ -701,7 +709,7 @@ class Z {
|
|
|
701
709
|
if (!this._applicationId || !this._id)
|
|
702
710
|
throw Error("session is not avalible. id is undefined");
|
|
703
711
|
return this.cvforceApi.postComments(this._applicationId, this._id, e).then((t) => {
|
|
704
|
-
const i = this.messages.find((
|
|
712
|
+
const i = this.messages.find((n) => n.messageId === e.messageId);
|
|
705
713
|
return i && (i.comment = e, this.event.emit("message:comment", i)), t;
|
|
706
714
|
});
|
|
707
715
|
});
|
|
@@ -729,6 +737,7 @@ class Z {
|
|
|
729
737
|
}
|
|
730
738
|
}
|
|
731
739
|
export {
|
|
732
|
-
|
|
733
|
-
|
|
740
|
+
C as MAX_KNOWLEDGES_AND_FILES_COUNT,
|
|
741
|
+
K as SessionErrors,
|
|
742
|
+
ee as default
|
|
734
743
|
};
|
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.4", 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.2", 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.4",
|
|
63
63
|
axios: "0.24.0",
|
|
64
64
|
buffer: "^6.0.3",
|
|
65
65
|
dayjs: "^1.11.13",
|