@glodon-aiot/bot-client-sdk 3.25.0-alpha.9 → 3.25.1-alpha.0
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 +69 -63
- package/dist/es/BotClient.mjs +73 -73
- package/dist/es/Config.mjs +16 -13
- package/dist/es/Session.mjs +163 -152
- package/dist/es/package.json.mjs +2 -2
- package/dist/es/utils.mjs +16 -9
- package/dist/lib/index.js +4 -3
- package/dist/src/Session.d.ts +1 -0
- package/dist/src/utils.d.ts +5 -0
- package/package.json +2 -2
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var b = Object.defineProperty, T = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var _ = Object.getOwnPropertySymbols;
|
|
4
|
+
var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var A = (m, t, i) => t in m ? b(m, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : m[t] = i, d = (m, t) => {
|
|
6
6
|
for (var i in t || (t = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var i of
|
|
10
|
-
|
|
7
|
+
E.call(t, i) && A(m, i, t[i]);
|
|
8
|
+
if (_)
|
|
9
|
+
for (var i of _(t))
|
|
10
|
+
L.call(t, i) && A(m, i, t[i]);
|
|
11
11
|
return m;
|
|
12
|
-
}, w = (m, t) =>
|
|
13
|
-
var
|
|
12
|
+
}, w = (m, t) => T(m, x(t));
|
|
13
|
+
var p = (m, t, i) => new Promise((o, r) => {
|
|
14
14
|
var s = (a) => {
|
|
15
15
|
try {
|
|
16
16
|
n(i.next(a));
|
|
@@ -26,41 +26,41 @@ var v = (m, t, i) => new Promise((o, r) => {
|
|
|
26
26
|
}, n = (a) => a.done ? o(a.value) : Promise.resolve(a.value).then(s, e);
|
|
27
27
|
n((i = i.apply(m, t)).next());
|
|
28
28
|
});
|
|
29
|
-
import { ChatMessageRole as
|
|
30
|
-
import
|
|
31
|
-
import { configuration as
|
|
32
|
-
import { io as
|
|
29
|
+
import { ChatMessageRole as v, PromptVariableType as P } from "@glodon-aiot/apis";
|
|
30
|
+
import q from "./Logger.mjs";
|
|
31
|
+
import { configuration as y } from "./Config.mjs";
|
|
32
|
+
import { io as F } from "socket.io-client";
|
|
33
33
|
import { UserMode as I } from "./PayloadTypes.mjs";
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
const
|
|
37
|
-
class
|
|
34
|
+
import N, { SessionErrors as M } from "./Session.mjs";
|
|
35
|
+
import U from "dayjs";
|
|
36
|
+
const u = new q("[AgentSession] ");
|
|
37
|
+
class K extends N {
|
|
38
38
|
constructor(t, i = "", o, r, s, e) {
|
|
39
39
|
super(t, i, o, r, s, e);
|
|
40
40
|
}
|
|
41
41
|
prepareConnection() {
|
|
42
|
-
return new Promise((t) =>
|
|
42
|
+
return new Promise((t) => p(this, null, function* () {
|
|
43
43
|
this.socket && t(!0);
|
|
44
44
|
const i = {
|
|
45
45
|
version: "1.0",
|
|
46
|
-
stream: JSON.stringify(
|
|
46
|
+
stream: JSON.stringify(y.stream),
|
|
47
47
|
appId: this._applicationId,
|
|
48
48
|
sessionId: this.id,
|
|
49
49
|
Authorization: `${this.token}`,
|
|
50
|
-
userMode:
|
|
51
|
-
}, o = new URL(
|
|
50
|
+
userMode: y.debug ? I.Debug : I.Normal
|
|
51
|
+
}, o = new URL(y.apiRoot), r = yield F(o.origin, {
|
|
52
52
|
path: o.pathname.replace("api", "socketio") + "/copilot",
|
|
53
53
|
query: i,
|
|
54
54
|
transports: ["websocket"]
|
|
55
55
|
});
|
|
56
56
|
r.on("connect", () => {
|
|
57
|
-
|
|
57
|
+
u.log("socket:connect"), this.event.emit("socket:connect"), r.emit("init");
|
|
58
58
|
}), r.on("disconnect", () => {
|
|
59
|
-
|
|
59
|
+
u.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
|
|
60
60
|
}), r.on("ready", (s) => {
|
|
61
61
|
if (s.code === 200) {
|
|
62
|
-
|
|
63
|
-
const e =
|
|
62
|
+
u.log("ready");
|
|
63
|
+
const e = y.debug ? I.Debug : I.Normal;
|
|
64
64
|
e === I.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), t(!0);
|
|
65
65
|
} else {
|
|
66
66
|
this._ready && (this._ready = !1);
|
|
@@ -70,9 +70,10 @@ class H extends q {
|
|
|
70
70
|
// cause: data,
|
|
71
71
|
// }
|
|
72
72
|
);
|
|
73
|
-
|
|
73
|
+
u.error("error", e), this.event.emit("error", e), t(!1);
|
|
74
74
|
}
|
|
75
|
-
}), r.on("action", (s, e) =>
|
|
75
|
+
}), r.on("action", (s, e) => p(this, null, function* () {
|
|
76
|
+
var k;
|
|
76
77
|
if (this._stopAnswer || !this.id)
|
|
77
78
|
return;
|
|
78
79
|
const {
|
|
@@ -82,7 +83,7 @@ class H extends q {
|
|
|
82
83
|
pluginCode: h,
|
|
83
84
|
funcCode: g,
|
|
84
85
|
parameters: c,
|
|
85
|
-
requestBody:
|
|
86
|
+
requestBody: j
|
|
86
87
|
}
|
|
87
88
|
} = s, l = this.messages[this.messages.length - 1];
|
|
88
89
|
if (!l.messageId)
|
|
@@ -94,7 +95,7 @@ class H extends q {
|
|
|
94
95
|
const f = {
|
|
95
96
|
messageId: "",
|
|
96
97
|
content: "",
|
|
97
|
-
role:
|
|
98
|
+
role: v.Robot,
|
|
98
99
|
sessionId: this.id,
|
|
99
100
|
reference: [],
|
|
100
101
|
searchReference: [],
|
|
@@ -122,45 +123,50 @@ class H extends q {
|
|
|
122
123
|
// },
|
|
123
124
|
// }
|
|
124
125
|
);
|
|
125
|
-
|
|
126
|
+
u.warn("error", f), this.event.emit("error", f);
|
|
126
127
|
} else if (n === "FUNCTION_CALL" && a) {
|
|
127
|
-
|
|
128
|
-
${JSON.stringify(c)}`)
|
|
128
|
+
u.log(`calling function ${g} of plugin ${h} with argument:
|
|
129
|
+
${JSON.stringify(c)}`);
|
|
130
|
+
const f = (k = y.plugins) == null ? void 0 : k[h];
|
|
131
|
+
if (!f) {
|
|
129
132
|
e({
|
|
130
133
|
code: 404,
|
|
131
|
-
message: "
|
|
134
|
+
message: "没有找到插件。"
|
|
132
135
|
});
|
|
133
136
|
return;
|
|
134
137
|
}
|
|
135
|
-
const
|
|
136
|
-
typeof
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const R = f[g];
|
|
139
|
+
if (typeof R != "function") {
|
|
140
|
+
e({
|
|
141
|
+
code: 404,
|
|
142
|
+
message: "没有找到插件方法。"
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let S = c == null ? void 0 : c.query;
|
|
141
147
|
try {
|
|
142
|
-
|
|
143
|
-
} catch (
|
|
148
|
+
S = JSON.parse(c == null ? void 0 : c.query);
|
|
149
|
+
} catch (C) {
|
|
144
150
|
}
|
|
145
|
-
|
|
146
|
-
this._stopAnswer || e(...
|
|
151
|
+
R(S, (...C) => {
|
|
152
|
+
this._stopAnswer || e(...C);
|
|
147
153
|
});
|
|
148
154
|
}
|
|
149
155
|
})), r.on("answer", (s) => {
|
|
150
156
|
if (!this._stopAnswer)
|
|
151
157
|
if (s.data.code !== 200 && (s.data.index = -1), s.data.stream || s.data.stream === void 0) {
|
|
152
158
|
let e = this.messages[this.messages.length - 1];
|
|
153
|
-
if (e && e.role ===
|
|
159
|
+
if (e && e.role === v.Robot)
|
|
154
160
|
this.handleStreamAnswer(s.data, e), this.messages[this.messages.length - 1] = e, this.event.emit("message:content", e), this.event.emit("message:updated", e), e.index === -1 && (e.isReplying = !1, this.event.emit("answer:finish", e));
|
|
155
161
|
else {
|
|
156
162
|
const n = {
|
|
157
163
|
content: "",
|
|
158
|
-
role:
|
|
164
|
+
role: v.Robot,
|
|
159
165
|
reference: [],
|
|
160
166
|
searchReference: [],
|
|
161
167
|
messageId: "",
|
|
162
168
|
sessionId: this.id,
|
|
163
|
-
messageTime:
|
|
169
|
+
messageTime: U(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
|
|
164
170
|
comment: {
|
|
165
171
|
isAgree: 0
|
|
166
172
|
},
|
|
@@ -185,7 +191,7 @@ class H extends q {
|
|
|
185
191
|
const n = d({
|
|
186
192
|
messageId: "",
|
|
187
193
|
content: "",
|
|
188
|
-
role:
|
|
194
|
+
role: v.Robot,
|
|
189
195
|
sessionId: this.id,
|
|
190
196
|
reference: [],
|
|
191
197
|
searchReference: [],
|
|
@@ -204,7 +210,7 @@ class H extends q {
|
|
|
204
210
|
e && !e.messageId ? (e = d(d({}, e), s.data), this.messages[this.messages.length - 1] = e, this.event.emit("message:content", e), this.event.emit("message:updated", e)) : (this.pushMessage(d({
|
|
205
211
|
messageId: "",
|
|
206
212
|
content: "",
|
|
207
|
-
role:
|
|
213
|
+
role: v.Robot,
|
|
208
214
|
sessionId: this.id,
|
|
209
215
|
reference: [],
|
|
210
216
|
searchReference: [],
|
|
@@ -217,7 +223,7 @@ class H extends q {
|
|
|
217
223
|
isReplying: !0
|
|
218
224
|
}, s.data)), this.event.emit("message:content", s.data));
|
|
219
225
|
}
|
|
220
|
-
}), r.on("reference", (s) =>
|
|
226
|
+
}), r.on("reference", (s) => p(this, null, function* () {
|
|
221
227
|
if (this._stopAnswer)
|
|
222
228
|
return;
|
|
223
229
|
if (!this.id) {
|
|
@@ -227,14 +233,14 @@ class H extends q {
|
|
|
227
233
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
228
234
|
// }
|
|
229
235
|
);
|
|
230
|
-
|
|
236
|
+
u.error(c), this.event.emit("error", c), this.frozen = !1;
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
233
239
|
const {
|
|
234
240
|
type: e,
|
|
235
241
|
data: n,
|
|
236
242
|
requestId: a
|
|
237
|
-
} = s, h = this.messages.findIndex((c) => c.messageId === a && c.role ===
|
|
243
|
+
} = s, h = this.messages.findIndex((c) => c.messageId === a && c.role === v.User);
|
|
238
244
|
if (h < 0)
|
|
239
245
|
return;
|
|
240
246
|
const g = h + 1;
|
|
@@ -242,7 +248,7 @@ class H extends q {
|
|
|
242
248
|
const c = {
|
|
243
249
|
messageId: "",
|
|
244
250
|
content: "",
|
|
245
|
-
role:
|
|
251
|
+
role: v.Robot,
|
|
246
252
|
sessionId: this.id,
|
|
247
253
|
reference: [],
|
|
248
254
|
searchReference: [],
|
|
@@ -265,12 +271,12 @@ class H extends q {
|
|
|
265
271
|
}));
|
|
266
272
|
}
|
|
267
273
|
registerMcpFromClientConfig() {
|
|
268
|
-
return
|
|
274
|
+
return y.mcp ? new Promise((t, i) => {
|
|
269
275
|
if (!this.socket) {
|
|
270
276
|
i("socket is undefined");
|
|
271
277
|
return;
|
|
272
278
|
}
|
|
273
|
-
this.socket.emit("add_mcp_servers",
|
|
279
|
+
this.socket.emit("add_mcp_servers", y.mcp, (o) => {
|
|
274
280
|
o.code === 200 ? (Object.keys(o.data).forEach((r) => {
|
|
275
281
|
o.data[r].code !== 200 && console.error(r, "MCP Server 注册失败。", o.data[r]);
|
|
276
282
|
}), t(!0)) : (console.error("MCP Server 注册失败。", o), i(o));
|
|
@@ -278,7 +284,7 @@ class H extends q {
|
|
|
278
284
|
}) : Promise.resolve(!0);
|
|
279
285
|
}
|
|
280
286
|
addMcpServers(t) {
|
|
281
|
-
return
|
|
287
|
+
return p(this, null, function* () {
|
|
282
288
|
return this.ready ? this.socket ? new Promise((i, o) => {
|
|
283
289
|
this.socket && this.socket.emit("add_mcp_servers", t, (r) => {
|
|
284
290
|
r.code === 200 ? (Object.keys(r.data).forEach((s) => {
|
|
@@ -289,7 +295,7 @@ class H extends q {
|
|
|
289
295
|
});
|
|
290
296
|
}
|
|
291
297
|
listMcpServers() {
|
|
292
|
-
return
|
|
298
|
+
return p(this, null, function* () {
|
|
293
299
|
return this.ready ? this.socket ? new Promise((t, i) => {
|
|
294
300
|
this.socket && this.socket.emit("list_mcp_servers", (o) => {
|
|
295
301
|
o.code === 200 ? t(o.data) : i(o);
|
|
@@ -298,14 +304,14 @@ class H extends q {
|
|
|
298
304
|
});
|
|
299
305
|
}
|
|
300
306
|
sendQuestion(t, i) {
|
|
301
|
-
return
|
|
307
|
+
return p(this, null, function* () {
|
|
302
308
|
var r, s, e;
|
|
303
309
|
this.convertKnowledgesToChatFormat(this.knowledges);
|
|
304
310
|
let o = w(d({}, t), {
|
|
305
|
-
promptVariables: this.promptVariables.filter((n) => n.type ===
|
|
311
|
+
promptVariables: this.promptVariables.filter((n) => n.type === P.User).reduce((n, a) => w(d({}, n), {
|
|
306
312
|
[a.key]: a.value
|
|
307
313
|
}), {}),
|
|
308
|
-
systemPromptVariables: this.promptVariables.filter((n) => n.type ===
|
|
314
|
+
systemPromptVariables: this.promptVariables.filter((n) => n.type === P.System).reduce((n, a) => w(d({}, n), {
|
|
309
315
|
[a.key]: a.value
|
|
310
316
|
}), {}),
|
|
311
317
|
knowledges: (r = this.knowledges) == null ? void 0 : r.map((n) => n.id),
|
|
@@ -322,7 +328,7 @@ class H extends q {
|
|
|
322
328
|
// cause: { code: -1, message: 'socket is null' },
|
|
323
329
|
// }
|
|
324
330
|
);
|
|
325
|
-
return
|
|
331
|
+
return u.warn("error", n), this.event.emit("error", n), !1;
|
|
326
332
|
}
|
|
327
333
|
(s = this.socket) == null || s.emit("question", o);
|
|
328
334
|
return;
|
|
@@ -342,5 +348,5 @@ class H extends q {
|
|
|
342
348
|
}
|
|
343
349
|
}
|
|
344
350
|
export {
|
|
345
|
-
|
|
351
|
+
K as default
|
|
346
352
|
};
|
package/dist/es/BotClient.mjs
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
var k = Object.defineProperty, A = Object.defineProperties;
|
|
2
2
|
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
3
|
+
var y = Object.getOwnPropertySymbols;
|
|
4
4
|
var I = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var g = (r,
|
|
6
|
-
for (var
|
|
7
|
-
I.call(
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
R.call(
|
|
5
|
+
var g = (r, i, e) => i in r ? k(r, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[i] = e, p = (r, i) => {
|
|
6
|
+
for (var e in i || (i = {}))
|
|
7
|
+
I.call(i, e) && g(r, e, i[e]);
|
|
8
|
+
if (y)
|
|
9
|
+
for (var e of y(i))
|
|
10
|
+
R.call(i, e) && g(r, e, i[e]);
|
|
11
11
|
return r;
|
|
12
|
-
}, f = (r,
|
|
13
|
-
var d = (r,
|
|
14
|
-
var l = (r,
|
|
12
|
+
}, f = (r, i) => A(r, x(i));
|
|
13
|
+
var d = (r, i, e) => (g(r, typeof i != "symbol" ? i + "" : i, e), e);
|
|
14
|
+
var l = (r, i, e) => new Promise((t, n) => {
|
|
15
15
|
var a = (o) => {
|
|
16
16
|
try {
|
|
17
|
-
s(
|
|
17
|
+
s(e.next(o));
|
|
18
18
|
} catch (c) {
|
|
19
19
|
n(c);
|
|
20
20
|
}
|
|
21
21
|
}, h = (o) => {
|
|
22
22
|
try {
|
|
23
|
-
s(
|
|
23
|
+
s(e.throw(o));
|
|
24
24
|
} catch (c) {
|
|
25
25
|
n(c);
|
|
26
26
|
}
|
|
27
27
|
}, s = (o) => o.done ? t(o.value) : Promise.resolve(o.value).then(a, h);
|
|
28
|
-
s((
|
|
28
|
+
s((e = e.apply(r, i)).next());
|
|
29
29
|
});
|
|
30
30
|
import { parseJWT as m } from "./utils.mjs";
|
|
31
31
|
import E from "./Logger.mjs";
|
|
32
32
|
import { getCVForceService as M } from "./api/index.mjs";
|
|
33
|
-
import { configure as S, configuration as
|
|
33
|
+
import { configure as S, configuration as v } from "./Config.mjs";
|
|
34
34
|
import { ApplicationTypes as _, PromptVariableType as w } from "@glodon-aiot/apis";
|
|
35
35
|
import C from "./AgentSession.mjs";
|
|
36
36
|
import L from "./DialogSession.mjs";
|
|
37
|
-
import
|
|
38
|
-
import
|
|
37
|
+
import T from "./EventBus.mjs";
|
|
38
|
+
import V from "./package.json.mjs";
|
|
39
39
|
const b = new E("[BotClient] ");
|
|
40
40
|
class W {
|
|
41
|
-
constructor(
|
|
41
|
+
constructor(i, e, t = !0, n = {
|
|
42
42
|
analytics: {
|
|
43
43
|
enabled: !1
|
|
44
44
|
}
|
|
45
45
|
}) {
|
|
46
|
-
d(this, "event", new
|
|
46
|
+
d(this, "event", new T());
|
|
47
47
|
d(this, "cvforceApi");
|
|
48
48
|
//从token解析出来的用户信息
|
|
49
49
|
d(this, "_applicationId");
|
|
@@ -56,11 +56,11 @@ class W {
|
|
|
56
56
|
//问题长度
|
|
57
57
|
d(this, "_questionContextMaxLength", 4e3);
|
|
58
58
|
d(this, "_promptVariables", []);
|
|
59
|
-
if (this._token =
|
|
59
|
+
if (this._token = i, this.lazyload = t, this.sdkConfigs = n, S(e), this._applicationId = m(i).rid || v.applicationId, !this._applicationId)
|
|
60
60
|
throw "token is not vaild";
|
|
61
61
|
this.cvforceApi = this.getService(), this.loadApplication().then((a) => {
|
|
62
|
-
S(f(p({},
|
|
63
|
-
stream:
|
|
62
|
+
S(f(p({}, e), {
|
|
63
|
+
stream: e.stream === void 0 ? (a == null ? void 0 : a.type) === _.Dialog || (a == null ? void 0 : a.type) === _.Agent : e.stream
|
|
64
64
|
})), this.event.emit("ready");
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -71,8 +71,8 @@ class W {
|
|
|
71
71
|
get ready() {
|
|
72
72
|
return this._ready;
|
|
73
73
|
}
|
|
74
|
-
set ready(
|
|
75
|
-
this._ready =
|
|
74
|
+
set ready(i) {
|
|
75
|
+
this._ready = i;
|
|
76
76
|
}
|
|
77
77
|
get questionContextMaxLength() {
|
|
78
78
|
return this.checkReady(), this._questionContextMaxLength;
|
|
@@ -81,33 +81,33 @@ class W {
|
|
|
81
81
|
return this.checkReady(), this._promptVariables;
|
|
82
82
|
}
|
|
83
83
|
get knowledges() {
|
|
84
|
-
var
|
|
85
|
-
return this.checkReady(), (
|
|
84
|
+
var i;
|
|
85
|
+
return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
|
|
86
86
|
}
|
|
87
87
|
get sessions() {
|
|
88
88
|
return this.checkReady(), this._sessions;
|
|
89
89
|
}
|
|
90
|
-
set sessions(
|
|
91
|
-
this.checkReady(), this._sessions =
|
|
90
|
+
set sessions(i) {
|
|
91
|
+
this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
|
|
92
92
|
}
|
|
93
93
|
loadApplication() {
|
|
94
94
|
return l(this, null, function* () {
|
|
95
|
-
var
|
|
95
|
+
var e, t, n, a, h;
|
|
96
96
|
this._application = yield this.cvforceApi.getApplicationId(
|
|
97
97
|
this._applicationId,
|
|
98
98
|
// 这里记录应用的名称和版本,以便后期数据分析
|
|
99
99
|
{
|
|
100
|
-
ui: (
|
|
100
|
+
ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
|
|
101
101
|
uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
|
|
102
|
-
sdkVersion:
|
|
102
|
+
sdkVersion: V.version
|
|
103
103
|
}
|
|
104
|
-
).then((s) => (typeof s.arrange[0].
|
|
104
|
+
).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), f(p({}, s), {
|
|
105
105
|
arrange: [f(p({}, s.arrange[0]), {
|
|
106
|
-
recommendQuestionOpen:
|
|
106
|
+
recommendQuestionOpen: v.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
|
|
107
107
|
})]
|
|
108
108
|
})));
|
|
109
|
-
const
|
|
110
|
-
return
|
|
109
|
+
const i = (h = (a = (n = this._application) == null ? void 0 : n.arrange) == null ? void 0 : a[0]) == null ? void 0 : h.llmModel;
|
|
110
|
+
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
|
|
111
111
|
type: w.User
|
|
112
112
|
}), this.cvforceApi.getPrompts(this._applicationId, {
|
|
113
113
|
type: w.System
|
|
@@ -115,15 +115,15 @@ class W {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
getService() {
|
|
118
|
-
return this.cvforceApi ? this.cvforceApi : M(
|
|
118
|
+
return this.cvforceApi ? this.cvforceApi : M(v.apiRoot, this.token, (i, e) => b.error(e));
|
|
119
119
|
}
|
|
120
120
|
get token() {
|
|
121
121
|
return this._token;
|
|
122
122
|
}
|
|
123
|
-
set token(
|
|
124
|
-
this.checkReady(), this._token =
|
|
125
|
-
const
|
|
126
|
-
this._applicationId !==
|
|
123
|
+
set token(i) {
|
|
124
|
+
this.checkReady(), this._token = i, this.ready = !1;
|
|
125
|
+
const e = m(i).rid;
|
|
126
|
+
this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
|
|
127
127
|
this.event.emit("ready");
|
|
128
128
|
}), this.clean());
|
|
129
129
|
}
|
|
@@ -134,23 +134,23 @@ class W {
|
|
|
134
134
|
return this.checkReady(), this._application;
|
|
135
135
|
}
|
|
136
136
|
get activeSession() {
|
|
137
|
-
var
|
|
138
|
-
return this.checkReady(), ((
|
|
137
|
+
var i;
|
|
138
|
+
return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
|
|
139
139
|
}
|
|
140
|
-
set activeSession(
|
|
141
|
-
this.checkReady(), this.loadSession(
|
|
142
|
-
this._activeSession && this._activeSession.id !==
|
|
140
|
+
set activeSession(i) {
|
|
141
|
+
this.checkReady(), this.loadSession(i).then((e) => {
|
|
142
|
+
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
createSession(
|
|
145
|
+
createSession(i, e, t, n, a) {
|
|
146
146
|
return l(this, null, function* () {
|
|
147
147
|
const h = this;
|
|
148
148
|
return new Promise((s, o) => {
|
|
149
149
|
const c = (u) => l(this, null, function* () {
|
|
150
150
|
if (u === _.Agent)
|
|
151
|
-
s(new C(
|
|
151
|
+
s(new C(i, e, t, n, a, h));
|
|
152
152
|
else if (u === _.Dialog)
|
|
153
|
-
s(new L(
|
|
153
|
+
s(new L(i, e, t, n, a, h));
|
|
154
154
|
else
|
|
155
155
|
throw Error(`不支持的应用类型:${u}`);
|
|
156
156
|
});
|
|
@@ -167,10 +167,10 @@ class W {
|
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
getSessions(
|
|
170
|
+
getSessions(i) {
|
|
171
171
|
return l(this, null, function* () {
|
|
172
|
-
return new Promise((
|
|
173
|
-
const n = () => this.cvforceApi.listSessions(this._applicationId,
|
|
172
|
+
return new Promise((e, t) => {
|
|
173
|
+
const n = () => this.cvforceApi.listSessions(this._applicationId, i).then((a) => l(this, null, function* () {
|
|
174
174
|
const h = [];
|
|
175
175
|
for (const s of a) {
|
|
176
176
|
const o = this._sessions.find((c) => c.id === s.id);
|
|
@@ -181,7 +181,7 @@ class W {
|
|
|
181
181
|
h.push(c);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
if (
|
|
184
|
+
if (i != null && i.pageSize) {
|
|
185
185
|
const s = [...this._sessions, ...h], o = /* @__PURE__ */ new Map();
|
|
186
186
|
for (const c of s)
|
|
187
187
|
o.set(c.id, c);
|
|
@@ -192,21 +192,21 @@ class W {
|
|
|
192
192
|
if (this.ready) {
|
|
193
193
|
if (!this._application)
|
|
194
194
|
throw Error("_application is null");
|
|
195
|
-
|
|
195
|
+
e(n());
|
|
196
196
|
} else
|
|
197
197
|
this.event.on("ready", () => {
|
|
198
198
|
if (!this._application)
|
|
199
199
|
throw Error("_application is null");
|
|
200
|
-
|
|
200
|
+
e(n());
|
|
201
201
|
}, !0);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
loadSession(
|
|
205
|
+
loadSession(i = "", e) {
|
|
206
206
|
return l(this, null, function* () {
|
|
207
207
|
this.checkReady();
|
|
208
|
-
let t = this.sessions.find((n) => n.id ===
|
|
209
|
-
if (t || (t = yield this.createSession(this.token,
|
|
208
|
+
let t = this.sessions.find((n) => n.id === i);
|
|
209
|
+
if (t || (t = yield this.createSession(this.token, i, e), this._sessions.push(t)), this._activeSession) {
|
|
210
210
|
if (this._activeSession === t)
|
|
211
211
|
return t;
|
|
212
212
|
this._activeSession.inactivate();
|
|
@@ -221,54 +221,54 @@ class W {
|
|
|
221
221
|
return yield this.getSessions(), this.event.emit("ready"), this;
|
|
222
222
|
}));
|
|
223
223
|
}
|
|
224
|
-
reloadSession(
|
|
224
|
+
reloadSession(i) {
|
|
225
225
|
return l(this, null, function* () {
|
|
226
226
|
yield this.reload();
|
|
227
|
-
let
|
|
228
|
-
if (!
|
|
227
|
+
let e = this._sessions.find((t) => t.id === i) || this._activeSession;
|
|
228
|
+
if (!e) {
|
|
229
229
|
console.warn("reloadSession session failed.");
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
|
-
return yield
|
|
232
|
+
return yield e.reload(), e;
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
-
setTop(
|
|
235
|
+
setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
|
|
236
236
|
return l(this, null, function* () {
|
|
237
|
-
let n =
|
|
237
|
+
let n = i ? this._sessions.find((a) => a.id === i) : this._activeSession;
|
|
238
238
|
if (!n) {
|
|
239
239
|
console.warn("setTop session failed.");
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
|
-
return yield n.setTop(
|
|
242
|
+
return yield n.setTop(e), this.getSessions({
|
|
243
243
|
order: t
|
|
244
244
|
});
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
addEventListener(
|
|
248
|
-
if (typeof
|
|
247
|
+
addEventListener(i, e, t = !1) {
|
|
248
|
+
if (typeof e != "function")
|
|
249
249
|
throw Error("event listener is not a function");
|
|
250
250
|
if (t) {
|
|
251
|
-
this.event.once(
|
|
251
|
+
this.event.once(i, e);
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
|
-
this.event.on(
|
|
254
|
+
this.event.on(i, e);
|
|
255
255
|
}
|
|
256
|
-
removeEventListener(
|
|
257
|
-
this.event.off(
|
|
256
|
+
removeEventListener(i, e) {
|
|
257
|
+
this.event.off(i, e);
|
|
258
258
|
}
|
|
259
|
-
removeSession(
|
|
259
|
+
removeSession(i, e) {
|
|
260
260
|
return l(this, null, function* () {
|
|
261
261
|
this.checkReady();
|
|
262
262
|
let t = -1;
|
|
263
|
-
if (typeof
|
|
263
|
+
if (typeof i == "string" ? t = this._sessions.findIndex((n) => n.id === i) : t = this._sessions.findIndex((n) => n.id === i.id), t > -1) {
|
|
264
264
|
const n = this._sessions[t];
|
|
265
|
-
|
|
265
|
+
e && (yield n.delete()), this._sessions.splice(t, 1);
|
|
266
266
|
} else
|
|
267
267
|
console.warn("session delete failed, session is not exist.");
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
clean() {
|
|
271
|
-
this._sessions.forEach((
|
|
271
|
+
this._sessions.forEach((i) => i.destroy()), this.sessions = [];
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
export {
|
package/dist/es/Config.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var u = Object.defineProperty, f = Object.defineProperties;
|
|
2
|
+
var v = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var n = Object.getOwnPropertySymbols;
|
|
4
4
|
var p = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var g = (o, t, e) => t in o ?
|
|
5
|
+
var g = (o, t, e) => t in o ? u(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, c = (o, t) => {
|
|
6
6
|
for (var e in t || (t = {}))
|
|
7
7
|
p.call(t, e) && g(o, e, t[e]);
|
|
8
8
|
if (n)
|
|
9
9
|
for (var e of n(t))
|
|
10
10
|
h.call(t, e) && g(o, e, t[e]);
|
|
11
11
|
return o;
|
|
12
|
-
}, l = (o, t) =>
|
|
12
|
+
}, l = (o, t) => f(o, v(t));
|
|
13
13
|
import d from "./Logger.mjs";
|
|
14
14
|
const R = new d("[Config] ");
|
|
15
|
-
var
|
|
16
|
-
let
|
|
15
|
+
var s = /* @__PURE__ */ ((o) => (o.dev = "https://aiot-dev.glodon.com/api/cvforcepd", o.test = "https://aiot-dev.glodon.com/api/cvforce", o.prod = "https://copilot.glodon.com/api/cvforce", o.local = "http://localhost:3000/api/cvforcepd", o))(s || {});
|
|
16
|
+
let i = {
|
|
17
17
|
debug: !1,
|
|
18
18
|
env: "prod",
|
|
19
19
|
//AIoT 环境, 与apiRoot配对使用
|
|
@@ -25,13 +25,16 @@ let c = {
|
|
|
25
25
|
loadRelatedQuesions: !0,
|
|
26
26
|
stream: !1
|
|
27
27
|
};
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function x(o) {
|
|
29
|
+
var t, e;
|
|
30
|
+
d.debug = (o == null ? void 0 : o.debug) || !1, i = l(c(c({}, i), o), {
|
|
31
|
+
apiRoot: (o == null ? void 0 : o.apiRoot) || i.apiRoot || (o != null && o.env ? s[o.env || "prod"] : i.apiRoot),
|
|
32
|
+
// 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
|
|
33
|
+
plugins: (e = (t = o == null ? void 0 : o.plugins) != null ? t : i.plugins) != null ? e : {}
|
|
34
|
+
}), d.debug && R.log("updated", i);
|
|
32
35
|
}
|
|
33
36
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
s as ApiUrl,
|
|
38
|
+
i as configuration,
|
|
39
|
+
x as configure
|
|
37
40
|
};
|