@glodon-aiot/bot-client-sdk 3.3.2-beta.9 → 3.3.5-alpha.17
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 +115 -112
- package/dist/es/BotClient.mjs +69 -65
- package/dist/es/DialogSession.mjs +50 -47
- package/dist/es/Session.mjs +53 -53
- package/dist/es/package.json.mjs +11 -11
- package/dist/lib/index.js +3 -3
- package/dist/src/constant.d.ts +13 -0
- package/package.json +2 -2
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T = Object.defineProperty, A = Object.defineProperties;
|
|
2
2
|
var I = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var M = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var R = (o, n, a) => n in o ?
|
|
4
|
+
var P = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var R = (o, n, a) => n in o ? T(o, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[n] = a, f = (o, n) => {
|
|
6
6
|
for (var a in n || (n = {}))
|
|
7
|
-
|
|
7
|
+
P.call(n, a) && R(o, a, n[a]);
|
|
8
8
|
if (M)
|
|
9
9
|
for (var a of M(n))
|
|
10
|
-
|
|
10
|
+
k.call(n, a) && R(o, a, n[a]);
|
|
11
11
|
return o;
|
|
12
12
|
}, u = (o, n) => A(o, I(n));
|
|
13
13
|
var w = (o, n, a) => (R(o, typeof n != "symbol" ? n + "" : n, a), a);
|
|
14
|
-
var h = (o, n, a) => new Promise((m,
|
|
14
|
+
var h = (o, n, a) => new Promise((m, g) => {
|
|
15
15
|
var d = (r) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
l(a.next(r));
|
|
18
18
|
} catch (c) {
|
|
19
|
-
|
|
19
|
+
g(c);
|
|
20
20
|
}
|
|
21
21
|
}, e = (r) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
l(a.throw(r));
|
|
24
24
|
} catch (c) {
|
|
25
|
-
|
|
25
|
+
g(c);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, l = (r) => r.done ? m(r.value) : Promise.resolve(r.value).then(d, e);
|
|
28
|
+
l((a = a.apply(o, n)).next());
|
|
29
29
|
});
|
|
30
|
-
import { IHistoryRole as
|
|
31
|
-
import
|
|
32
|
-
import
|
|
30
|
+
import { IHistoryRole as b, PromptVariableType as p, ChatMessageRole as D } from "@glodon-aiot/apis";
|
|
31
|
+
import O from "./Logger.mjs";
|
|
32
|
+
import V from "./Session.mjs";
|
|
33
33
|
import $ from "dayjs";
|
|
34
34
|
import { configuration as y } from "./Config.mjs";
|
|
35
35
|
import { fetchEventSource as v } from "./api/fetchEventSource/fetch.mjs";
|
|
36
|
-
const
|
|
37
|
-
class
|
|
38
|
-
constructor(a, m = "",
|
|
39
|
-
super(a, m,
|
|
36
|
+
const C = new O("[DialogSession] ");
|
|
37
|
+
class B extends V {
|
|
38
|
+
constructor(a, m = "", g, d, e, l) {
|
|
39
|
+
super(a, m, g, d, e, l);
|
|
40
40
|
w(this, "ctrl", new AbortController());
|
|
41
41
|
}
|
|
42
42
|
prepareConnection() {
|
|
@@ -44,13 +44,13 @@ class j extends O {
|
|
|
44
44
|
this._ready = !0, this.event.emit("ready"), this.frozen = !1, a(!0);
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
|
-
postChatV2EventSource(a, m,
|
|
47
|
+
postChatV2EventSource(a, m, g, d, e, l) {
|
|
48
48
|
return h(this, null, function* () {
|
|
49
49
|
const r = {
|
|
50
50
|
code: 0,
|
|
51
51
|
// messageId: uuidv4(),
|
|
52
52
|
content: "",
|
|
53
|
-
role:
|
|
53
|
+
role: b.Robot,
|
|
54
54
|
sessionId: m,
|
|
55
55
|
reference: [],
|
|
56
56
|
searchReference: [],
|
|
@@ -60,7 +60,7 @@ class j extends O {
|
|
|
60
60
|
isAgree: 0
|
|
61
61
|
},
|
|
62
62
|
isReplying: !1
|
|
63
|
-
}, c = u(f({},
|
|
63
|
+
}, c = u(f({}, g), {
|
|
64
64
|
stream: y.stream
|
|
65
65
|
});
|
|
66
66
|
v(`${y.apiRoot}/chat/v2/chat?applicationId=${a}&sessionId=${m}`, {
|
|
@@ -72,17 +72,17 @@ class j extends O {
|
|
|
72
72
|
body: JSON.stringify(c),
|
|
73
73
|
openWhenHidden: !0,
|
|
74
74
|
signal: d,
|
|
75
|
-
onopen(
|
|
76
|
-
return
|
|
75
|
+
onopen(i) {
|
|
76
|
+
return i.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
|
|
77
77
|
},
|
|
78
|
-
onmessage(
|
|
79
|
-
if (!
|
|
78
|
+
onmessage(i) {
|
|
79
|
+
if (!i.data.includes('{"code": ')) {
|
|
80
80
|
let t = {};
|
|
81
81
|
try {
|
|
82
|
-
t = JSON.parse(
|
|
82
|
+
t = JSON.parse(i.data);
|
|
83
83
|
} catch (_) {
|
|
84
84
|
}
|
|
85
|
-
(t == null ? void 0 : t.mtype) === "search" ? r.searchReference.push(t) : r.content = r.content +
|
|
85
|
+
(t == null ? void 0 : t.mtype) === "search" ? r.searchReference.push(t) : r.content = r.content + i.data;
|
|
86
86
|
const S = {
|
|
87
87
|
content: r.content,
|
|
88
88
|
role: 1,
|
|
@@ -98,7 +98,7 @@ class j extends O {
|
|
|
98
98
|
};
|
|
99
99
|
return (e == null ? void 0 : e.onmessage) && e.onmessage(S);
|
|
100
100
|
}
|
|
101
|
-
const s = JSON.parse(
|
|
101
|
+
const s = JSON.parse(i.data);
|
|
102
102
|
if (r.reference = s.data.reference, r.searchReference = s.data.searchReference, r.messageTime = s.data.messageTime, r.messageId = s.data.messageId, r.llmModel = s.data.llmModel, r.content = s.data.content, r.code = s.code, s.code === 200) {
|
|
103
103
|
const t = {
|
|
104
104
|
code: r.code,
|
|
@@ -113,7 +113,7 @@ class j extends O {
|
|
|
113
113
|
};
|
|
114
114
|
e != null && e.onmessage && e.onmessage(t);
|
|
115
115
|
} else
|
|
116
|
-
return e != null && e.onclose && e.onclose(r),
|
|
116
|
+
return e != null && e.onclose && e.onclose(r), l && l({
|
|
117
117
|
code: r.code,
|
|
118
118
|
message: r.message
|
|
119
119
|
});
|
|
@@ -122,7 +122,7 @@ class j extends O {
|
|
|
122
122
|
e != null && e.onerror && e.onerror();
|
|
123
123
|
},
|
|
124
124
|
onclose() {
|
|
125
|
-
const
|
|
125
|
+
const i = {
|
|
126
126
|
code: r.code,
|
|
127
127
|
content: r.content,
|
|
128
128
|
role: 1,
|
|
@@ -137,18 +137,18 @@ class j extends O {
|
|
|
137
137
|
isReplying: !1,
|
|
138
138
|
index: -1
|
|
139
139
|
};
|
|
140
|
-
e != null && e.onclose && e.onclose(
|
|
140
|
+
e != null && e.onclose && e.onclose(i);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
postChatV3EventSource(a, m,
|
|
145
|
+
postChatV3EventSource(a, m, g, d, e, l) {
|
|
146
146
|
return h(this, null, function* () {
|
|
147
147
|
const r = this, c = {
|
|
148
148
|
code: 0,
|
|
149
149
|
// messageId: uuidv4(),
|
|
150
150
|
content: "",
|
|
151
|
-
role:
|
|
151
|
+
role: b.Robot,
|
|
152
152
|
sessionId: m,
|
|
153
153
|
reference: [],
|
|
154
154
|
searchReference: [],
|
|
@@ -162,7 +162,7 @@ class j extends O {
|
|
|
162
162
|
thinkingSecs: "",
|
|
163
163
|
thinkingStatus: "",
|
|
164
164
|
searchingStatus: ""
|
|
165
|
-
},
|
|
165
|
+
}, i = u(f({}, g), {
|
|
166
166
|
stream: y.stream
|
|
167
167
|
});
|
|
168
168
|
v(`${y.apiRoot}/chat/v3/chat?applicationId=${a}&sessionId=${m}`, {
|
|
@@ -171,7 +171,7 @@ class j extends O {
|
|
|
171
171
|
Authorization: `Bearer ${this.token}`,
|
|
172
172
|
"Content-Type": "application/json"
|
|
173
173
|
},
|
|
174
|
-
body: JSON.stringify(
|
|
174
|
+
body: JSON.stringify(i),
|
|
175
175
|
openWhenHidden: !0,
|
|
176
176
|
signal: d,
|
|
177
177
|
onopen(s) {
|
|
@@ -187,7 +187,7 @@ class j extends O {
|
|
|
187
187
|
console.error("parse eventData to JSON failed. ", s.data);
|
|
188
188
|
}
|
|
189
189
|
if (t.code !== 200)
|
|
190
|
-
return c.index = -1, c.code = t.code, c.message = t.message, e != null && e.onmessage && e.onmessage(c),
|
|
190
|
+
return c.index = -1, c.code = t.code, c.message = t.message, e != null && e.onmessage && e.onmessage(c), l && l({
|
|
191
191
|
code: t.code,
|
|
192
192
|
message: t.message
|
|
193
193
|
});
|
|
@@ -209,36 +209,39 @@ class j extends O {
|
|
|
209
209
|
return h(this, null, function* () {
|
|
210
210
|
var c;
|
|
211
211
|
const {
|
|
212
|
-
content:
|
|
212
|
+
content: g,
|
|
213
213
|
fileIds: d,
|
|
214
214
|
oldMessageId: e
|
|
215
215
|
} = a, {
|
|
216
|
-
stream:
|
|
216
|
+
stream: l,
|
|
217
217
|
referenceFirst: r
|
|
218
218
|
} = m;
|
|
219
219
|
if (this.active || (yield this.activate()), this._id) {
|
|
220
|
-
let
|
|
221
|
-
content:
|
|
220
|
+
let i = {
|
|
221
|
+
content: g,
|
|
222
222
|
fileIds: d,
|
|
223
223
|
referenceFirst: r,
|
|
224
224
|
oldMessageId: e,
|
|
225
|
-
promptVariables: this.promptVariables.reduce((s, t) => u(f({}, s), {
|
|
225
|
+
promptVariables: this.promptVariables.filter((s) => s.type === p.User).reduce((s, t) => u(f({}, s), {
|
|
226
|
+
[t.key]: t.value
|
|
227
|
+
}), {}),
|
|
228
|
+
systemPromptVariables: this.promptVariables.filter((s) => s.type === p.System).reduce((s, t) => u(f({}, s), {
|
|
226
229
|
[t.key]: t.value
|
|
227
230
|
}), {}),
|
|
228
231
|
knowledges: (c = this.knowledges) == null ? void 0 : c.map((s) => s.id)
|
|
229
232
|
};
|
|
230
|
-
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id,
|
|
233
|
+
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, i, this.ctrl.signal, {
|
|
231
234
|
onopen: () => {
|
|
232
|
-
|
|
235
|
+
C.log("open", this.ctrl);
|
|
233
236
|
},
|
|
234
237
|
onmessage: (s) => {
|
|
235
238
|
if (this._stopAnswer)
|
|
236
239
|
return;
|
|
237
240
|
let t = this.messages[this.messages.length - 1];
|
|
238
|
-
t && t.role ===
|
|
241
|
+
t && t.role === D.Robot ? (t = f(f({}, t), s), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t)) : (this.pushMessage(s), this.event.emit("message:content", s));
|
|
239
242
|
},
|
|
240
243
|
onclose: (s) => h(this, null, function* () {
|
|
241
|
-
this._stopAnswer || (
|
|
244
|
+
this._stopAnswer || (C.log(s, "onclose"), this.event.emit("answer:finish", s));
|
|
242
245
|
}),
|
|
243
246
|
onerror: () => {
|
|
244
247
|
this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
|
|
@@ -267,5 +270,5 @@ class j extends O {
|
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
export {
|
|
270
|
-
|
|
273
|
+
B as default
|
|
271
274
|
};
|
package/dist/es/Session.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var M = Object.prototype.hasOwnProperty,
|
|
5
|
-
var
|
|
1
|
+
var x = Object.defineProperty, Q = Object.defineProperties;
|
|
2
|
+
var T = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var b = Object.getOwnPropertySymbols;
|
|
4
|
+
var M = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var k = (c, e, t) => e in c ? x(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
|
-
M.call(e, t) &&
|
|
8
|
-
if (
|
|
9
|
-
for (var t of
|
|
10
|
-
|
|
7
|
+
M.call(e, t) && k(c, t, e[t]);
|
|
8
|
+
if (b)
|
|
9
|
+
for (var t of b(e))
|
|
10
|
+
R.call(e, t) && k(c, t, e[t]);
|
|
11
11
|
return c;
|
|
12
|
-
}, I = (c, e) =>
|
|
13
|
-
var l = (c, e, t) => (
|
|
12
|
+
}, I = (c, e) => Q(c, T(e));
|
|
13
|
+
var l = (c, e, t) => (k(c, typeof e != "symbol" ? e + "" : e, t), t);
|
|
14
14
|
var d = (c, e, t) => new Promise((i, a) => {
|
|
15
15
|
var o = (s) => {
|
|
16
16
|
try {
|
|
@@ -27,17 +27,17 @@ var d = (c, e, t) => new Promise((i, a) => {
|
|
|
27
27
|
}, r = (s) => s.done ? i(s.value) : Promise.resolve(s.value).then(o, h);
|
|
28
28
|
r((t = t.apply(c, e)).next());
|
|
29
29
|
});
|
|
30
|
-
import { v4 as
|
|
31
|
-
import { parseJWT as
|
|
32
|
-
import { ApplicationTypes as
|
|
33
|
-
import
|
|
30
|
+
import { v4 as E } from "uuid";
|
|
31
|
+
import { parseJWT as C, removeNewlines as O, removeLeadingAndTrailingBackslashes as z } from "./utils.mjs";
|
|
32
|
+
import { ApplicationTypes as V, PromptStatus as P, 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
|
|
36
|
-
import { getCVForceService as
|
|
37
|
-
import
|
|
38
|
-
const u = new
|
|
39
|
-
var
|
|
40
|
-
class
|
|
35
|
+
import F from "./EventBus.mjs";
|
|
36
|
+
import { getCVForceService as N } from "./api/index.mjs";
|
|
37
|
+
import B from "dayjs";
|
|
38
|
+
const u = new q("[Session] ");
|
|
39
|
+
var U = /* @__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))(U || {});
|
|
40
|
+
class X {
|
|
41
41
|
/**
|
|
42
42
|
* Session 类的构造函数,用于初始化会话实例。
|
|
43
43
|
* @param token - 用户的身份验证令牌,用于解析应用 ID。
|
|
@@ -54,7 +54,7 @@ class $ {
|
|
|
54
54
|
l(this, "inactivating", !1);
|
|
55
55
|
l(this, "_ready", !1);
|
|
56
56
|
// ready = false;
|
|
57
|
-
l(this, "event", new
|
|
57
|
+
l(this, "event", new F());
|
|
58
58
|
//从token解析出来的用户信息
|
|
59
59
|
l(this, "_applicationId");
|
|
60
60
|
l(this, "_application", null);
|
|
@@ -72,7 +72,7 @@ class $ {
|
|
|
72
72
|
l(this, "_dataLoading", !1);
|
|
73
73
|
l(this, "_dataLoaded", !1);
|
|
74
74
|
l(this, "_mcpServers", null);
|
|
75
|
-
this.token = e, this.lazyload = a, this.client = h || null, this._applicationId =
|
|
75
|
+
this.token = e, this.lazyload = a, this.client = h || null, this._applicationId = C(e).rid || A.applicationId, this.cvforceApi = this.getService(), o && (this._application = o), this.event.emit("init", {
|
|
76
76
|
applicationId: this._applicationId,
|
|
77
77
|
sessionId: t
|
|
78
78
|
}), this.loadApplicationInfo().then(() => {
|
|
@@ -107,17 +107,17 @@ class $ {
|
|
|
107
107
|
return this.setKnowledges((i == null ? void 0 : i.knowledges) || void 0);
|
|
108
108
|
}))(), yield (() => {
|
|
109
109
|
if (i != null && i.promptVariables) {
|
|
110
|
-
const
|
|
111
|
-
var
|
|
112
|
-
const n = ((v = (
|
|
110
|
+
const y = this._promptVariables.map((g) => {
|
|
111
|
+
var w, v;
|
|
112
|
+
const n = ((v = (w = i.promptVariables) == null ? void 0 : w.find((_) => _.key === g.key)) == null ? void 0 : v.value) || "";
|
|
113
113
|
return I(f({}, g), {
|
|
114
114
|
value: n
|
|
115
115
|
});
|
|
116
116
|
}).sort((g, n) => g.key.localeCompare(n.key));
|
|
117
|
-
return this.setPromptVariables(
|
|
117
|
+
return this.setPromptVariables(y || []);
|
|
118
118
|
} else
|
|
119
119
|
return;
|
|
120
|
-
})(), 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) !==
|
|
120
|
+
})(), 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"));
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
123
|
});
|
|
@@ -181,12 +181,12 @@ class $ {
|
|
|
181
181
|
throw Error("session id is not defined");
|
|
182
182
|
if (!this.data)
|
|
183
183
|
throw Error("session data is not loaded");
|
|
184
|
-
const e = this.promptVariables.filter((t) => t.status ===
|
|
184
|
+
const e = this.promptVariables.filter((t) => t.status === P.Quoted).filter((t) => !t.value);
|
|
185
185
|
if (e.length)
|
|
186
186
|
throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${e.map((t) => t.key).join(", ")}`);
|
|
187
187
|
}
|
|
188
188
|
get promptVariables() {
|
|
189
|
-
return this._promptVariables.filter((e) => e.key
|
|
189
|
+
return this._promptVariables.filter((e) => !(e.type === L.User && e.key === "query") && !(e.type === L.System && e.key === "datetime"));
|
|
190
190
|
}
|
|
191
191
|
setPromptVariables(e) {
|
|
192
192
|
return d(this, null, function* () {
|
|
@@ -197,7 +197,7 @@ class $ {
|
|
|
197
197
|
value: a
|
|
198
198
|
});
|
|
199
199
|
}).sort((i, a) => i.key.localeCompare(a.key));
|
|
200
|
-
if (yield Promise.all(t.filter((i) => i.key
|
|
200
|
+
if (yield Promise.all(t.filter((i) => !(i.type === L.User && i.key === "query") && !(i.type === L.System && i.key === "datetime")).map((i) => {
|
|
201
201
|
if (!this.data)
|
|
202
202
|
throw Error("session data is not loaded");
|
|
203
203
|
if (!(!i.id || !i.key))
|
|
@@ -224,7 +224,7 @@ class $ {
|
|
|
224
224
|
setNetOpen(e) {
|
|
225
225
|
return d(this, null, function* () {
|
|
226
226
|
var t, i, a;
|
|
227
|
-
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) ===
|
|
227
|
+
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) {
|
|
228
228
|
console.warn("Agent Application Sessions are disabled to setNetOpen.");
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
@@ -243,7 +243,7 @@ class $ {
|
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
getService() {
|
|
246
|
-
return
|
|
246
|
+
return N(A.apiRoot, this.token, (e, t) => {
|
|
247
247
|
const i = new Error(
|
|
248
248
|
"data request error"
|
|
249
249
|
/* DataRequestFailed */
|
|
@@ -281,10 +281,10 @@ class $ {
|
|
|
281
281
|
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;
|
|
282
282
|
const o = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), h = o.map((s, p) => {
|
|
283
283
|
var g, n;
|
|
284
|
-
let m = [],
|
|
285
|
-
return typeof ((g = s.agentHistoryList) == null ? void 0 : g.agentList) == "string" && (m = JSON.parse(s.agentHistoryList.agentList).reduce((v, _) => (v[_.data.step - 1] || (v[_.data.step - 1] = []), v[_.data.step - 1].push(_), v), [])), p === o.length - 1 && (
|
|
284
|
+
let m = [], y;
|
|
285
|
+
return typeof ((g = s.agentHistoryList) == null ? void 0 : g.agentList) == "string" && (m = JSON.parse(s.agentHistoryList.agentList).reduce((v, _) => (v[_.data.step - 1] || (v[_.data.step - 1] = []), v[_.data.step - 1].push(_), v), [])), p === o.length - 1 && (y = (n = this.data) == null ? void 0 : n.lastRelatedQuestion), I(f({}, s), {
|
|
286
286
|
actions: m,
|
|
287
|
-
relatedQuesion:
|
|
287
|
+
relatedQuesion: y
|
|
288
288
|
});
|
|
289
289
|
});
|
|
290
290
|
if (!e.endTime && !e.startTime) {
|
|
@@ -404,7 +404,7 @@ class $ {
|
|
|
404
404
|
const {
|
|
405
405
|
stream: a = A.stream,
|
|
406
406
|
referenceFirst: o = !1
|
|
407
|
-
} = t, h = e.uuid ||
|
|
407
|
+
} = t, h = e.uuid || E(), r = ((g = e.text) == null ? void 0 : g.trim()) || "", s = e.fileIds;
|
|
408
408
|
if (!r && /*!files.length &&*/
|
|
409
409
|
!(s != null && s.length)) {
|
|
410
410
|
const n = new Error(
|
|
@@ -453,10 +453,10 @@ class $ {
|
|
|
453
453
|
referenceFirst: o
|
|
454
454
|
};
|
|
455
455
|
this.pushMessage(p), this.event.emit("question:content", r);
|
|
456
|
-
const
|
|
457
|
-
if (n.role !==
|
|
456
|
+
const y = (n) => d(this, null, function* () {
|
|
457
|
+
if (n.role !== S.Robot)
|
|
458
458
|
return;
|
|
459
|
-
switch (this.removeEventListener("answer:finish",
|
|
459
|
+
switch (this.removeEventListener("answer:finish", y), this._id && n.content && n.index && n.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
460
460
|
finialMessage: n.content
|
|
461
461
|
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
462
462
|
finialMessage: n.content
|
|
@@ -471,15 +471,15 @@ class $ {
|
|
|
471
471
|
n.content = n.message || "未知错误", n.isLoading = !1, n.index = -1, this.event.emit("message:error", n);
|
|
472
472
|
}
|
|
473
473
|
this.getRelatedQuesion(n), n.isLoading = !1;
|
|
474
|
-
let
|
|
475
|
-
if (
|
|
476
|
-
const v = f(f({},
|
|
474
|
+
let w = this.messages[this.messages.length - 1];
|
|
475
|
+
if (w && w.role === S.Robot) {
|
|
476
|
+
const v = f(f({}, w), n);
|
|
477
477
|
this.messages[this.messages.length - 1] = v, this.event.emit("message:updated", v);
|
|
478
478
|
} else
|
|
479
479
|
this.pushMessage(n);
|
|
480
480
|
this.frozen = !1;
|
|
481
481
|
});
|
|
482
|
-
return this.addEventListener("answer:finish",
|
|
482
|
+
return this.addEventListener("answer:finish", y), this.sendQuestion(m, I(f({}, t), {
|
|
483
483
|
stream: a,
|
|
484
484
|
referenceFirst: o
|
|
485
485
|
})), p;
|
|
@@ -504,7 +504,7 @@ class $ {
|
|
|
504
504
|
relatedQuesion: r
|
|
505
505
|
}), this.event.emit("message:updated", s), s;
|
|
506
506
|
}
|
|
507
|
-
const i = (h = t.content) == null ? void 0 : h.split("*").map(
|
|
507
|
+
const i = (h = t.content) == null ? void 0 : h.split("*").map(O).map(z).filter((r) => !!r);
|
|
508
508
|
e.relatedQuesion = i, e.index = -3, e.isLoading = !1;
|
|
509
509
|
const a = I(f({}, e), {
|
|
510
510
|
relatedQuesion: i,
|
|
@@ -534,7 +534,7 @@ class $ {
|
|
|
534
534
|
stream: i = A.stream
|
|
535
535
|
} = e;
|
|
536
536
|
let a;
|
|
537
|
-
t.role !==
|
|
537
|
+
t.role !== S.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));
|
|
538
538
|
const o = this.messages[this.messages.length - 1], h = {
|
|
539
539
|
content: o.content,
|
|
540
540
|
fileIds: o.fileIds,
|
|
@@ -542,7 +542,7 @@ class $ {
|
|
|
542
542
|
stream: i,
|
|
543
543
|
oldMessageId: a
|
|
544
544
|
}, r = (s) => d(this, null, function* () {
|
|
545
|
-
if (s.role ===
|
|
545
|
+
if (s.role === S.Robot && s.index === -1) {
|
|
546
546
|
switch (this._id && s.content && s.index && s.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
547
547
|
finialMessage: s.content
|
|
548
548
|
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
@@ -587,17 +587,17 @@ class $ {
|
|
|
587
587
|
this.stopAnswer(), this.frozen = !1, this._stopAnswer = !0;
|
|
588
588
|
let e = this.messages[this.messages.length - 1];
|
|
589
589
|
const t = {
|
|
590
|
-
messageId:
|
|
590
|
+
messageId: E(),
|
|
591
591
|
// 生成唯一的消息 ID
|
|
592
592
|
isLoading: !1,
|
|
593
593
|
// 标记消息已停止加载
|
|
594
594
|
index: -2,
|
|
595
595
|
// 消息索引,用于标识特殊状态
|
|
596
|
-
messageTime:
|
|
596
|
+
messageTime: B(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
|
|
597
597
|
// 消息时间
|
|
598
598
|
content: "",
|
|
599
599
|
// 消息内容
|
|
600
|
-
role:
|
|
600
|
+
role: S.System,
|
|
601
601
|
// 消息角色为系统消息
|
|
602
602
|
sessionId: this.id || "",
|
|
603
603
|
// 会话 ID
|
|
@@ -661,7 +661,7 @@ class $ {
|
|
|
661
661
|
return;
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
|
-
if (i === "beforeSearch" && o(), i === "searchOver" && o(), i === "search" && t.searchReference.push(a), i === "thinking") {
|
|
664
|
+
if (i === "error" && (t.index = -1), i === "beforeSearch" && o(), i === "searchOver" && o(), i === "search" && t.searchReference.push(a), i === "thinking") {
|
|
665
665
|
t.thinkingStatus = "start";
|
|
666
666
|
const r = a.choices[0];
|
|
667
667
|
t.reasoningContent = t.reasoningContent + r.delta.reasoningContent;
|
|
@@ -719,6 +719,6 @@ class $ {
|
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
export {
|
|
722
|
-
|
|
723
|
-
|
|
722
|
+
U as SessionErrors,
|
|
723
|
+
X as default
|
|
724
724
|
};
|
package/dist/es/package.json.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e = "@glodon-aiot/bot-client-sdk", t = "3.3.
|
|
1
|
+
const e = "@glodon-aiot/bot-client-sdk", t = "3.3.5-alpha.17", i = "glodoncv", s = "aiot bot client js sdk", n = "module", y = !1, o = [
|
|
2
2
|
"aiot",
|
|
3
3
|
"bot",
|
|
4
4
|
"bot client",
|
|
@@ -23,7 +23,7 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.3.2-beta.9", i = "glodoncv", s =
|
|
|
23
23
|
check: "yarn prettier --check .",
|
|
24
24
|
write: "yarn prettier --write .",
|
|
25
25
|
lint: "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js"
|
|
26
|
-
},
|
|
26
|
+
}, g = {
|
|
27
27
|
"@babel/core": "^7.20.12",
|
|
28
28
|
"@commitlint/cli": "^17.0.3",
|
|
29
29
|
"@commitlint/config-conventional": "^17.0.3",
|
|
@@ -55,11 +55,11 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.3.2-beta.9", i = "glodoncv", s =
|
|
|
55
55
|
"vite-plugin-dts": "^4.3.0",
|
|
56
56
|
"vite-plugin-externalize-deps": "^0.9.0",
|
|
57
57
|
"vite-tsconfig-paths": "^5.1.4"
|
|
58
|
-
},
|
|
58
|
+
}, m = {
|
|
59
59
|
access: "public",
|
|
60
60
|
registry: "https://registry.npmjs.org/"
|
|
61
|
-
},
|
|
62
|
-
"@glodon-aiot/apis": "^3.3.
|
|
61
|
+
}, b = {
|
|
62
|
+
"@glodon-aiot/apis": "^3.3.5-alpha.17",
|
|
63
63
|
axios: "0.24.0",
|
|
64
64
|
buffer: "^6.0.3",
|
|
65
65
|
dayjs: "^1.11.13",
|
|
@@ -81,19 +81,19 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.3.2-beta.9", i = "glodoncv", s =
|
|
|
81
81
|
exports: d,
|
|
82
82
|
license: a,
|
|
83
83
|
scripts: u,
|
|
84
|
-
devDependencies:
|
|
84
|
+
devDependencies: g,
|
|
85
85
|
"lint-staged": {
|
|
86
86
|
"*.{js,css,md,jsx,less,ts,tsx,json}": "prettier --write"
|
|
87
87
|
},
|
|
88
|
-
publishConfig:
|
|
89
|
-
dependencies:
|
|
88
|
+
publishConfig: m,
|
|
89
|
+
dependencies: b
|
|
90
90
|
};
|
|
91
91
|
export {
|
|
92
92
|
i as author,
|
|
93
93
|
x as default,
|
|
94
|
-
|
|
94
|
+
b as dependencies,
|
|
95
95
|
s as description,
|
|
96
|
-
|
|
96
|
+
g as devDependencies,
|
|
97
97
|
d as exports,
|
|
98
98
|
l as files,
|
|
99
99
|
o as keywords,
|
|
@@ -101,7 +101,7 @@ export {
|
|
|
101
101
|
c as main,
|
|
102
102
|
p as module,
|
|
103
103
|
e as name,
|
|
104
|
-
|
|
104
|
+
m as publishConfig,
|
|
105
105
|
u as scripts,
|
|
106
106
|
y as sideEffects,
|
|
107
107
|
n as type,
|