@glodon-aiot/agent-cli-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 +68 -62
- package/dist/es/BotClient.mjs +75 -75
- package/dist/es/Config.mjs +16 -13
- package/dist/es/Session.mjs +183 -172
- package/dist/es/utils.mjs +16 -9
- package/dist/lib/index.js +5 -4
- 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,39 +1,39 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var b = Object.defineProperty, A = Object.defineProperties;
|
|
2
|
+
var E = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var R = Object.getOwnPropertySymbols;
|
|
4
|
+
var q = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var S = (d, t, n) => t in d ? b(d, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : d[t] = n, g = (d, t) => {
|
|
6
6
|
for (var n in t || (t = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var n of
|
|
10
|
-
|
|
7
|
+
q.call(t, n) && S(d, n, t[n]);
|
|
8
|
+
if (R)
|
|
9
|
+
for (var n of R(t))
|
|
10
|
+
x.call(t, n) && S(d, n, t[n]);
|
|
11
11
|
return d;
|
|
12
|
-
}, k = (d, t) =>
|
|
12
|
+
}, k = (d, t) => A(d, E(t));
|
|
13
13
|
var v = (d, t, n) => new Promise((r, i) => {
|
|
14
14
|
var s = (c) => {
|
|
15
15
|
try {
|
|
16
16
|
o(n.next(c));
|
|
17
|
-
} catch (
|
|
18
|
-
i(
|
|
17
|
+
} catch (h) {
|
|
18
|
+
i(h);
|
|
19
19
|
}
|
|
20
20
|
}, e = (c) => {
|
|
21
21
|
try {
|
|
22
22
|
o(n.throw(c));
|
|
23
|
-
} catch (
|
|
24
|
-
i(
|
|
23
|
+
} catch (h) {
|
|
24
|
+
i(h);
|
|
25
25
|
}
|
|
26
26
|
}, o = (c) => c.done ? r(c.value) : Promise.resolve(c.value).then(s, e);
|
|
27
27
|
o((n = n.apply(d, t)).next());
|
|
28
28
|
});
|
|
29
29
|
import { ChatMessageRole as I } from "@glodon-aiot/apis";
|
|
30
|
-
import
|
|
31
|
-
import { configuration as
|
|
32
|
-
import { io as
|
|
30
|
+
import L from "./Logger.mjs";
|
|
31
|
+
import { configuration as u } from "./Config.mjs";
|
|
32
|
+
import { io as N } from "socket.io-client";
|
|
33
33
|
import { UserMode as w } from "./PayloadTypes.mjs";
|
|
34
|
-
import
|
|
35
|
-
const p = new
|
|
36
|
-
class
|
|
34
|
+
import O, { SessionErrors as y } from "./Session.mjs";
|
|
35
|
+
const p = new L("[AgentSession] ");
|
|
36
|
+
class B extends O {
|
|
37
37
|
constructor(t, n = "", r, i, s, e) {
|
|
38
38
|
super(t, n, r, i, s, e);
|
|
39
39
|
}
|
|
@@ -42,12 +42,12 @@ class D extends L {
|
|
|
42
42
|
this.socket && t(!0);
|
|
43
43
|
const n = {
|
|
44
44
|
version: "1.0",
|
|
45
|
-
stream: JSON.stringify(
|
|
45
|
+
stream: JSON.stringify(u.stream === void 0 ? !0 : u.stream),
|
|
46
46
|
appId: this._applicationId,
|
|
47
47
|
sessionId: this.id,
|
|
48
48
|
Authorization: `${this.token}`,
|
|
49
|
-
userMode:
|
|
50
|
-
}, r = new URL(
|
|
49
|
+
userMode: u.debug ? w.Debug : w.Normal
|
|
50
|
+
}, r = new URL(u.apiRoot), i = yield N(r.origin, {
|
|
51
51
|
path: r.pathname.replace("api", "socketio") + "/copilot",
|
|
52
52
|
query: n,
|
|
53
53
|
transports: ["websocket"]
|
|
@@ -59,7 +59,7 @@ class D extends L {
|
|
|
59
59
|
}), i.on("ready", (s) => {
|
|
60
60
|
if (s.code === 200) {
|
|
61
61
|
p.log("ready");
|
|
62
|
-
const e =
|
|
62
|
+
const e = u.debug ? w.Debug : w.Normal;
|
|
63
63
|
e === w.Debug && s.userMode, this._ready = !0, this.event.emit("ready"), this.frozen = !1, this.registerMcpFromClientConfig(), t(!0);
|
|
64
64
|
} else {
|
|
65
65
|
this._ready && (this._ready = !1);
|
|
@@ -72,25 +72,26 @@ class D extends L {
|
|
|
72
72
|
p.error("error", e), this.event.emit("error", e), t(!1);
|
|
73
73
|
}
|
|
74
74
|
}), i.on("action", (s, e) => v(this, null, function* () {
|
|
75
|
+
var M;
|
|
75
76
|
if (this._stopAnswer || !this.id)
|
|
76
77
|
return;
|
|
77
78
|
const {
|
|
78
79
|
type: o,
|
|
79
80
|
data: {
|
|
80
81
|
runnerIsClient: c,
|
|
81
|
-
pluginCode:
|
|
82
|
+
pluginCode: h,
|
|
82
83
|
funcCode: m,
|
|
83
84
|
parameters: a,
|
|
84
|
-
requestBody:
|
|
85
|
+
requestBody: U
|
|
85
86
|
}
|
|
86
|
-
} = s,
|
|
87
|
-
if (!
|
|
88
|
-
|
|
89
|
-
messageId:
|
|
87
|
+
} = s, f = this.messages[this.messages.length - 1];
|
|
88
|
+
if (!f.messageId)
|
|
89
|
+
f.actions || (f.actions = []), f.actions[s.data.step - 1] || (f.actions[s.data.step - 1] = []), f.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
|
|
90
|
+
messageId: f.messageId,
|
|
90
91
|
action: s
|
|
91
|
-
}), this.event.emit("message:updated",
|
|
92
|
+
}), this.event.emit("message:updated", f);
|
|
92
93
|
else {
|
|
93
|
-
const
|
|
94
|
+
const l = {
|
|
94
95
|
messageId: "",
|
|
95
96
|
content: "",
|
|
96
97
|
role: I.Robot,
|
|
@@ -104,13 +105,13 @@ class D extends L {
|
|
|
104
105
|
isAgree: 0
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
|
-
this.pushMessage(
|
|
108
|
-
messageId:
|
|
108
|
+
this.pushMessage(l), this.event.emit("message:action", {
|
|
109
|
+
messageId: l.messageId,
|
|
109
110
|
action: s
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
if (this.inactivating) {
|
|
113
|
-
const
|
|
114
|
+
const l = new Error(
|
|
114
115
|
y.Inactive
|
|
115
116
|
// {
|
|
116
117
|
// cause: {
|
|
@@ -120,28 +121,33 @@ class D extends L {
|
|
|
120
121
|
// },
|
|
121
122
|
// }
|
|
122
123
|
);
|
|
123
|
-
p.warn("error",
|
|
124
|
+
p.warn("error", l), this.event.emit("error", l);
|
|
124
125
|
} else if (o === "FUNCTION_CALL" && c) {
|
|
125
|
-
|
|
126
|
-
${JSON.stringify(a)}`)
|
|
126
|
+
p.log(`calling function ${m} of plugin ${h} with argument:
|
|
127
|
+
${JSON.stringify(a)}`);
|
|
128
|
+
const l = (M = u.plugins) == null ? void 0 : M[h];
|
|
129
|
+
if (!l) {
|
|
127
130
|
e({
|
|
128
131
|
code: 404,
|
|
129
|
-
message: "
|
|
132
|
+
message: "没有找到插件。"
|
|
130
133
|
});
|
|
131
134
|
return;
|
|
132
135
|
}
|
|
133
|
-
const
|
|
134
|
-
typeof
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
const C = l[m];
|
|
137
|
+
if (typeof C != "function") {
|
|
138
|
+
e({
|
|
139
|
+
code: 404,
|
|
140
|
+
message: "没有找到插件方法。"
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
let _ = a == null ? void 0 : a.query;
|
|
139
145
|
try {
|
|
140
|
-
|
|
141
|
-
} catch (
|
|
146
|
+
_ = JSON.parse(a == null ? void 0 : a.query);
|
|
147
|
+
} catch (P) {
|
|
142
148
|
}
|
|
143
|
-
|
|
144
|
-
this._stopAnswer || e(...
|
|
149
|
+
C(_, (...P) => {
|
|
150
|
+
this._stopAnswer || e(...P);
|
|
145
151
|
});
|
|
146
152
|
}
|
|
147
153
|
})), i.on("answer", (s) => {
|
|
@@ -149,9 +155,9 @@ class D extends L {
|
|
|
149
155
|
if (s.data.code !== 200 && (s.data.index = -1, this.event.emit("error", s.data)), s.data.index === -1) {
|
|
150
156
|
let e = this.messages[this.messages.length - 1];
|
|
151
157
|
if (e && !e.messageId)
|
|
152
|
-
e =
|
|
158
|
+
e = g(g({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", e);
|
|
153
159
|
else {
|
|
154
|
-
const o =
|
|
160
|
+
const o = g({
|
|
155
161
|
messageId: "",
|
|
156
162
|
content: "",
|
|
157
163
|
role: I.Robot,
|
|
@@ -169,7 +175,7 @@ class D extends L {
|
|
|
169
175
|
}
|
|
170
176
|
} else {
|
|
171
177
|
let e = this.messages[this.messages.length - 1];
|
|
172
|
-
e && !e.messageId ? (e =
|
|
178
|
+
e && !e.messageId ? (e = g(g({}, 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));
|
|
173
179
|
}
|
|
174
180
|
}), i.on("reference", (s) => v(this, null, function* () {
|
|
175
181
|
if (this._stopAnswer)
|
|
@@ -188,10 +194,10 @@ class D extends L {
|
|
|
188
194
|
type: e,
|
|
189
195
|
data: o,
|
|
190
196
|
requestId: c
|
|
191
|
-
} = s,
|
|
192
|
-
if (
|
|
197
|
+
} = s, h = this.messages.findIndex((a) => a.messageId === c && a.role === I.User);
|
|
198
|
+
if (h < 0)
|
|
193
199
|
return;
|
|
194
|
-
const m =
|
|
200
|
+
const m = h + 1;
|
|
195
201
|
if (m >= this.messages.length) {
|
|
196
202
|
const a = {
|
|
197
203
|
messageId: "",
|
|
@@ -209,21 +215,21 @@ class D extends L {
|
|
|
209
215
|
};
|
|
210
216
|
this.pushMessage(a);
|
|
211
217
|
}
|
|
212
|
-
e === "KG" ? (this.messages[m] = k(
|
|
218
|
+
e === "KG" ? (this.messages[m] = k(g({}, this.messages[m]), {
|
|
213
219
|
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(
|
|
220
|
+
}), 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(g({}, this.messages[m]), {
|
|
215
221
|
searchReference: o.knowledgeReference
|
|
216
222
|
}), this.event.emit("message:searchreference", o.searchReference), this.event.emit("message:updated", this.messages[m]));
|
|
217
223
|
})), this.socket = i, i.open();
|
|
218
224
|
}));
|
|
219
225
|
}
|
|
220
226
|
registerMcpFromClientConfig() {
|
|
221
|
-
return
|
|
227
|
+
return u.mcp ? new Promise((t, n) => {
|
|
222
228
|
if (!this.socket) {
|
|
223
229
|
n("socket is undefined");
|
|
224
230
|
return;
|
|
225
231
|
}
|
|
226
|
-
this.socket.emit("add_mcp_servers",
|
|
232
|
+
this.socket.emit("add_mcp_servers", u.mcp, (r) => {
|
|
227
233
|
r.code === 200 ? (Object.keys(r.data).forEach((i) => {
|
|
228
234
|
r.data[i].code !== 200 && console.error(i, "MCP Server 注册失败。", r.data[i]);
|
|
229
235
|
}), t(!0)) : (console.error("MCP Server 注册失败。", r), n(r));
|
|
@@ -253,8 +259,8 @@ class D extends L {
|
|
|
253
259
|
sendQuestion(t, n) {
|
|
254
260
|
return v(this, null, function* () {
|
|
255
261
|
var i, s, e;
|
|
256
|
-
let r = k(
|
|
257
|
-
promptVariables: this.promptVariables.reduce((o, c) => k(
|
|
262
|
+
let r = k(g({}, t), {
|
|
263
|
+
promptVariables: this.promptVariables.reduce((o, c) => k(g({}, o), {
|
|
258
264
|
[c.key]: c.value
|
|
259
265
|
}), {}),
|
|
260
266
|
knowledges: (i = this.knowledges) == null ? void 0 : i.map((o) => o.id)
|
|
@@ -281,5 +287,5 @@ class D extends L {
|
|
|
281
287
|
}
|
|
282
288
|
}
|
|
283
289
|
export {
|
|
284
|
-
|
|
290
|
+
B as default
|
|
285
291
|
};
|
package/dist/es/BotClient.mjs
CHANGED
|
@@ -2,42 +2,42 @@ var w = Object.defineProperty, k = Object.defineProperties;
|
|
|
2
2
|
var A = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var g = Object.getOwnPropertySymbols;
|
|
4
4
|
var x = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var u = (
|
|
6
|
-
for (var
|
|
7
|
-
x.call(i,
|
|
5
|
+
var u = (n, i, t) => i in n ? w(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t, d = (n, i) => {
|
|
6
|
+
for (var t in i || (i = {}))
|
|
7
|
+
x.call(i, t) && u(n, t, i[t]);
|
|
8
8
|
if (g)
|
|
9
|
-
for (var
|
|
10
|
-
I.call(i,
|
|
11
|
-
return
|
|
12
|
-
}, f = (
|
|
13
|
-
var l = (
|
|
14
|
-
var c = (
|
|
15
|
-
var
|
|
9
|
+
for (var t of g(i))
|
|
10
|
+
I.call(i, t) && u(n, t, i[t]);
|
|
11
|
+
return n;
|
|
12
|
+
}, f = (n, i) => k(n, A(i));
|
|
13
|
+
var l = (n, i, t) => (u(n, typeof i != "symbol" ? i + "" : i, t), t);
|
|
14
|
+
var c = (n, i, t) => new Promise((e, s) => {
|
|
15
|
+
var o = (a) => {
|
|
16
16
|
try {
|
|
17
|
-
r(
|
|
17
|
+
r(t.next(a));
|
|
18
18
|
} catch (h) {
|
|
19
19
|
s(h);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, p = (a) => {
|
|
22
22
|
try {
|
|
23
|
-
r(
|
|
23
|
+
r(t.throw(a));
|
|
24
24
|
} catch (h) {
|
|
25
25
|
s(h);
|
|
26
26
|
}
|
|
27
|
-
}, r = (a) => a.done ?
|
|
28
|
-
r((
|
|
27
|
+
}, r = (a) => a.done ? e(a.value) : Promise.resolve(a.value).then(o, p);
|
|
28
|
+
r((t = t.apply(n, i)).next());
|
|
29
29
|
});
|
|
30
30
|
import { parseJWT as m } from "./utils.mjs";
|
|
31
31
|
import R from "./Logger.mjs";
|
|
32
32
|
import { getCVForceService as E } from "./api/index.mjs";
|
|
33
|
-
import { configure as S, configuration as
|
|
34
|
-
import { ApplicationTypes as
|
|
33
|
+
import { configure as S, configuration as v } from "./Config.mjs";
|
|
34
|
+
import { ApplicationTypes as y } from "@glodon-aiot/apis";
|
|
35
35
|
import L from "./AgentSession.mjs";
|
|
36
36
|
import M from "./DialogSession.mjs";
|
|
37
37
|
import C from "./EventBus.mjs";
|
|
38
38
|
const T = new R("[BotClient] ");
|
|
39
39
|
class z {
|
|
40
|
-
constructor(i,
|
|
40
|
+
constructor(i, t, e = !0) {
|
|
41
41
|
l(this, "event", new C());
|
|
42
42
|
l(this, "cvforceApi");
|
|
43
43
|
//从token解析出来的用户信息
|
|
@@ -51,11 +51,11 @@ class z {
|
|
|
51
51
|
//问题长度
|
|
52
52
|
l(this, "_questionContextMaxLength", 4e3);
|
|
53
53
|
l(this, "_promptVariables", []);
|
|
54
|
-
if (this._token = i, this.lazyload =
|
|
54
|
+
if (this._token = i, this.lazyload = e, S(t), this._applicationId = m(i).rid || v.applicationId, !this._applicationId)
|
|
55
55
|
throw "token is not vaild";
|
|
56
56
|
this.cvforceApi = this.getService(), this.loadApplication().then((s) => {
|
|
57
|
-
S(f(
|
|
58
|
-
stream:
|
|
57
|
+
S(f(d({}, t), {
|
|
58
|
+
stream: t.stream === void 0 ? (s == null ? void 0 : s.type) === y.Dialog : t.stream
|
|
59
59
|
})), this.event.emit("ready");
|
|
60
60
|
});
|
|
61
61
|
}
|
|
@@ -87,26 +87,26 @@ class z {
|
|
|
87
87
|
}
|
|
88
88
|
loadApplication() {
|
|
89
89
|
return c(this, null, function* () {
|
|
90
|
-
var
|
|
91
|
-
this._application = yield this.cvforceApi.getApplicationId(this._applicationId).then((
|
|
92
|
-
arrange: [f(
|
|
93
|
-
recommendQuestionOpen:
|
|
90
|
+
var t, e, s;
|
|
91
|
+
this._application = yield this.cvforceApi.getApplicationId(this._applicationId).then((o) => f(d({}, o), {
|
|
92
|
+
arrange: [f(d({}, o.arrange[0]), {
|
|
93
|
+
recommendQuestionOpen: v.loadRelatedQuesions && o.arrange[0].recommendQuestionOpen
|
|
94
94
|
})]
|
|
95
|
-
}))
|
|
96
|
-
const i = (s = (
|
|
97
|
-
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((
|
|
95
|
+
}));
|
|
96
|
+
const i = (s = (e = (t = this._application) == null ? void 0 : t.arrange) == null ? void 0 : e[0]) == null ? void 0 : s.llmModel;
|
|
97
|
+
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((o) => o.maxModelLength)), this._promptVariables = yield this.cvforceApi.getPrompts(this._applicationId), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
getService() {
|
|
101
|
-
return this.cvforceApi ? this.cvforceApi : E(
|
|
101
|
+
return this.cvforceApi ? this.cvforceApi : E(v.apiRoot, this.token, (i, t) => T.error(t));
|
|
102
102
|
}
|
|
103
103
|
get token() {
|
|
104
104
|
return this._token;
|
|
105
105
|
}
|
|
106
106
|
set token(i) {
|
|
107
107
|
this.checkReady(), this._token = i, this.ready = !1;
|
|
108
|
-
const
|
|
109
|
-
this._applicationId !==
|
|
108
|
+
const t = m(i).rid;
|
|
109
|
+
this._applicationId !== t && (this._applicationId = t, this._application = null, this.loadApplication().then(() => {
|
|
110
110
|
this.event.emit("ready");
|
|
111
111
|
}), this.clean());
|
|
112
112
|
}
|
|
@@ -121,19 +121,19 @@ class z {
|
|
|
121
121
|
return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
|
|
122
122
|
}
|
|
123
123
|
set activeSession(i) {
|
|
124
|
-
this.checkReady(), this.loadSession(i).then((
|
|
125
|
-
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession =
|
|
124
|
+
this.checkReady(), this.loadSession(i).then((t) => {
|
|
125
|
+
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = t;
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
createSession(i,
|
|
128
|
+
createSession(i, t, e, s, o) {
|
|
129
129
|
return c(this, null, function* () {
|
|
130
|
-
const
|
|
130
|
+
const p = this;
|
|
131
131
|
return new Promise((r, a) => {
|
|
132
132
|
const h = (_) => c(this, null, function* () {
|
|
133
|
-
if (_ ===
|
|
134
|
-
r(new L(i,
|
|
135
|
-
else if (_ ===
|
|
136
|
-
r(new M(i,
|
|
133
|
+
if (_ === y.Agent)
|
|
134
|
+
r(new L(i, t, e, s, o, p));
|
|
135
|
+
else if (_ === y.Dialog)
|
|
136
|
+
r(new M(i, t, e, s, o, p));
|
|
137
137
|
else
|
|
138
138
|
throw Error(`不支持的应用类型:${_}`);
|
|
139
139
|
});
|
|
@@ -152,44 +152,44 @@ class z {
|
|
|
152
152
|
}
|
|
153
153
|
getSessions(i) {
|
|
154
154
|
return c(this, null, function* () {
|
|
155
|
-
return new Promise((
|
|
156
|
-
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((
|
|
157
|
-
const
|
|
158
|
-
return
|
|
155
|
+
return new Promise((t, e) => {
|
|
156
|
+
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((o) => {
|
|
157
|
+
const p = [];
|
|
158
|
+
return o.forEach((r) => c(this, null, function* () {
|
|
159
159
|
const a = this._sessions.find((h) => r.id === h.id);
|
|
160
160
|
if (a)
|
|
161
|
-
a.data = r, this._application ? a.application = this._application : a.loadApplicationInfo(),
|
|
161
|
+
a.data = r, this._application ? a.application = this._application : a.loadApplicationInfo(), p.push(a);
|
|
162
162
|
else {
|
|
163
163
|
const h = yield this.createSession(this.token, r.id, r, this.lazyload, this._application || void 0);
|
|
164
|
-
|
|
164
|
+
p.push(h);
|
|
165
165
|
}
|
|
166
|
-
})), this.sessions =
|
|
166
|
+
})), this.sessions = p, p;
|
|
167
167
|
});
|
|
168
168
|
if (this.ready) {
|
|
169
169
|
if (!this._application)
|
|
170
170
|
throw Error("_application is null");
|
|
171
|
-
|
|
171
|
+
t(s());
|
|
172
172
|
} else
|
|
173
173
|
this.event.on("ready", () => {
|
|
174
174
|
if (!this._application)
|
|
175
175
|
throw Error("_application is null");
|
|
176
|
-
|
|
176
|
+
t(s());
|
|
177
177
|
}, !0);
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
|
-
loadSession(i = "",
|
|
181
|
+
loadSession(i = "", t) {
|
|
182
182
|
return c(this, null, function* () {
|
|
183
183
|
this.checkReady();
|
|
184
|
-
let
|
|
185
|
-
if (
|
|
186
|
-
if (this._activeSession ===
|
|
187
|
-
return
|
|
184
|
+
let e = this.sessions.find((s) => s.id === i);
|
|
185
|
+
if (e || (e = yield this.createSession(this.token, i, t), this._sessions.push(e)), this._activeSession) {
|
|
186
|
+
if (this._activeSession === e)
|
|
187
|
+
return e;
|
|
188
188
|
this._activeSession.inactivate();
|
|
189
189
|
}
|
|
190
|
-
return
|
|
191
|
-
this._activeSession !==
|
|
192
|
-
}, !0),
|
|
190
|
+
return e.id ? (yield e.activate(), this._activeSession = e) : e.addEventListener("data:loaded", () => {
|
|
191
|
+
this._activeSession !== e && (e == null || e.activate(), this._activeSession = e);
|
|
192
|
+
}, !0), e;
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
reload() {
|
|
@@ -200,45 +200,45 @@ class z {
|
|
|
200
200
|
reloadSession(i) {
|
|
201
201
|
return c(this, null, function* () {
|
|
202
202
|
yield this.reload();
|
|
203
|
-
let
|
|
204
|
-
if (!
|
|
203
|
+
let t = this._sessions.find((e) => e.id === i) || this._activeSession;
|
|
204
|
+
if (!t) {
|
|
205
205
|
console.warn("reloadSession session failed.");
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
return yield
|
|
208
|
+
return yield t.reload(), t;
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
|
-
setTop(i,
|
|
211
|
+
setTop(i, t, e = "top_time desc, sort_status desc, updated_at desc") {
|
|
212
212
|
return c(this, null, function* () {
|
|
213
|
-
let s = i ? this._sessions.find((
|
|
213
|
+
let s = i ? this._sessions.find((o) => o.id === i) : this._activeSession;
|
|
214
214
|
if (!s) {
|
|
215
215
|
console.warn("setTop session failed.");
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
|
-
return yield s.setTop(
|
|
219
|
-
order:
|
|
218
|
+
return yield s.setTop(t), this.getSessions({
|
|
219
|
+
order: e
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
-
addEventListener(i,
|
|
224
|
-
if (typeof
|
|
223
|
+
addEventListener(i, t, e = !1) {
|
|
224
|
+
if (typeof t != "function")
|
|
225
225
|
throw Error("event listener is not a function");
|
|
226
|
-
if (
|
|
227
|
-
this.event.once(i,
|
|
226
|
+
if (e) {
|
|
227
|
+
this.event.once(i, t);
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
-
this.event.on(i,
|
|
230
|
+
this.event.on(i, t);
|
|
231
231
|
}
|
|
232
|
-
removeEventListener(i,
|
|
233
|
-
this.event.off(i,
|
|
232
|
+
removeEventListener(i, t) {
|
|
233
|
+
this.event.off(i, t);
|
|
234
234
|
}
|
|
235
|
-
removeSession(i,
|
|
235
|
+
removeSession(i, t) {
|
|
236
236
|
return c(this, null, function* () {
|
|
237
237
|
this.checkReady();
|
|
238
|
-
let
|
|
239
|
-
if (typeof i == "string" ?
|
|
240
|
-
const s = this._sessions[
|
|
241
|
-
|
|
238
|
+
let e = -1;
|
|
239
|
+
if (typeof i == "string" ? e = this._sessions.findIndex((s) => s.id === i) : e = this._sessions.findIndex((s) => s.id === i.id), e > -1) {
|
|
240
|
+
const s = this._sessions[e];
|
|
241
|
+
t && (yield s.delete()), this._sessions.splice(e, 1);
|
|
242
242
|
} else
|
|
243
243
|
console.warn("session delete failed, session is not exist.");
|
|
244
244
|
});
|
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
|
};
|