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