@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.
@@ -1,16 +1,16 @@
1
- var A = Object.defineProperty, P = Object.defineProperties;
2
- var b = Object.getOwnPropertyDescriptors;
3
- var S = Object.getOwnPropertySymbols;
4
- var T = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
5
- var C = (m, t, i) => t in m ? A(m, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : m[t] = i, d = (m, t) => {
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
- T.call(t, i) && C(m, i, t[i]);
8
- if (S)
9
- for (var i of S(t))
10
- x.call(t, i) && C(m, i, t[i]);
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) => P(m, b(t));
13
- var v = (m, t, i) => new Promise((o, r) => {
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 y, PromptVariableType as _ } from "@glodon-aiot/apis";
30
- import E from "./Logger.mjs";
31
- import { configuration as u } from "./Config.mjs";
32
- import { io as L } from "socket.io-client";
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 q, { SessionErrors as M } from "./Session.mjs";
35
- import F from "dayjs";
36
- const p = new E("[AgentSession] ");
37
- class H extends q {
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) => v(this, null, function* () {
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(u.stream),
46
+ stream: JSON.stringify(y.stream),
47
47
  appId: this._applicationId,
48
48
  sessionId: this.id,
49
49
  Authorization: `${this.token}`,
50
- userMode: u.debug ? I.Debug : I.Normal
51
- }, o = new URL(u.apiRoot), r = yield L(o.origin, {
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
- p.log("socket:connect"), this.event.emit("socket:connect"), r.emit("init");
57
+ u.log("socket:connect"), this.event.emit("socket:connect"), r.emit("init");
58
58
  }), r.on("disconnect", () => {
59
- p.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
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
- p.log("ready");
63
- const e = u.debug ? I.Debug : I.Normal;
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
- p.error("error", e), this.event.emit("error", e), t(!1);
73
+ u.error("error", e), this.event.emit("error", e), t(!1);
74
74
  }
75
- }), r.on("action", (s, e) => v(this, null, function* () {
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: N
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: y.Robot,
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
- p.warn("error", f), this.event.emit("error", f);
126
+ u.warn("error", f), this.event.emit("error", f);
126
127
  } else if (n === "FUNCTION_CALL" && a) {
127
- if (p.log(`calling function ${g} of plugin ${h} with argument:
128
- ${JSON.stringify(c)}`), !u.plugins[h]) {
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 f = u.plugins[h][g];
136
- typeof f != "function" && e({
137
- code: 404,
138
- message: "对不起,没有找到插件方法。"
139
- });
140
- let k = c == null ? void 0 : c.query;
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
- k = JSON.parse(c == null ? void 0 : c.query);
143
- } catch (R) {
148
+ S = JSON.parse(c == null ? void 0 : c.query);
149
+ } catch (C) {
144
150
  }
145
- f(k, (...R) => {
146
- this._stopAnswer || e(...R);
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 === y.Robot)
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: y.Robot,
164
+ role: v.Robot,
159
165
  reference: [],
160
166
  searchReference: [],
161
167
  messageId: "",
162
168
  sessionId: this.id,
163
- messageTime: F(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
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: y.Robot,
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: y.Robot,
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) => v(this, null, function* () {
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
- p.error(c), this.event.emit("error", c), this.frozen = !1;
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 === y.User);
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: y.Robot,
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 u.mcp ? new Promise((t, i) => {
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", u.mcp, (o) => {
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 v(this, null, function* () {
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 v(this, null, function* () {
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 v(this, null, function* () {
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 === _.User).reduce((n, a) => w(d({}, n), {
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 === _.System).reduce((n, a) => w(d({}, n), {
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 p.warn("error", n), this.event.emit("error", n), !1;
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
- H as default
351
+ K as default
346
352
  };
@@ -1,49 +1,49 @@
1
1
  var k = Object.defineProperty, A = Object.defineProperties;
2
2
  var x = Object.getOwnPropertyDescriptors;
3
- var v = Object.getOwnPropertySymbols;
3
+ var y = Object.getOwnPropertySymbols;
4
4
  var I = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
5
- var g = (r, e, i) => e in r ? k(r, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[e] = i, p = (r, e) => {
6
- for (var i in e || (e = {}))
7
- I.call(e, i) && g(r, i, e[i]);
8
- if (v)
9
- for (var i of v(e))
10
- R.call(e, i) && g(r, i, e[i]);
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, e) => A(r, x(e));
13
- var d = (r, e, i) => (g(r, typeof e != "symbol" ? e + "" : e, i), i);
14
- var l = (r, e, i) => new Promise((t, n) => {
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(i.next(o));
17
+ s(e.next(o));
18
18
  } catch (c) {
19
19
  n(c);
20
20
  }
21
21
  }, h = (o) => {
22
22
  try {
23
- s(i.throw(o));
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((i = i.apply(r, e)).next());
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 y } from "./Config.mjs";
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 O from "./EventBus.mjs";
38
- import T from "./package.json.mjs";
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(e, i, t = !0, n = {
41
+ constructor(i, e, t = !0, n = {
42
42
  analytics: {
43
43
  enabled: !1
44
44
  }
45
45
  }) {
46
- d(this, "event", new O());
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 = e, this.lazyload = t, this.sdkConfigs = n, S(i), this._applicationId = m(e).rid || y.applicationId, !this._applicationId)
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({}, i), {
63
- stream: i.stream === void 0 ? (a == null ? void 0 : a.type) === _.Dialog || (a == null ? void 0 : a.type) === _.Agent : i.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(e) {
75
- this._ready = e;
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 e;
85
- return this.checkReady(), (e = this._application) == null ? void 0 : e.arrange[0].knowledges;
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(e) {
91
- this.checkReady(), this._sessions = e, this.event.emit("sessions:updated", e);
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 i, t, n, a, h;
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: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
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: T.version
102
+ sdkVersion: V.version
103
103
  }
104
- ).then((s) => (typeof s.arrange[0].recommendQuestionOpen != "boolean" && (s.arrange[0].recommendQuestionOpen = !0), 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), {
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: y.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
106
+ recommendQuestionOpen: v.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
107
107
  })]
108
108
  })));
109
- const e = (h = (a = (n = this._application) == null ? void 0 : n.arrange) == null ? void 0 : a[0]) == null ? void 0 : h.llmModel;
110
- return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
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(y.apiRoot, this.token, (e, i) => b.error(i));
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(e) {
124
- this.checkReady(), this._token = e, this.ready = !1;
125
- const i = m(e).rid;
126
- this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
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 e;
138
- return this.checkReady(), ((e = this._activeSession) == null ? void 0 : e.id) || "";
137
+ var i;
138
+ return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
139
139
  }
140
- set activeSession(e) {
141
- this.checkReady(), this.loadSession(e).then((i) => {
142
- this._activeSession && this._activeSession.id !== e && this._activeSession.inactivate(), this._activeSession = i;
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(e, i, t, n, a) {
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(e, i, t, n, a, h));
151
+ s(new C(i, e, t, n, a, h));
152
152
  else if (u === _.Dialog)
153
- s(new L(e, i, t, n, a, h));
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(e) {
170
+ getSessions(i) {
171
171
  return l(this, null, function* () {
172
- return new Promise((i, t) => {
173
- const n = () => this.cvforceApi.listSessions(this._applicationId, e).then((a) => l(this, null, function* () {
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 (e != null && e.pageSize) {
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
- i(n());
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
- i(n());
200
+ e(n());
201
201
  }, !0);
202
202
  });
203
203
  });
204
204
  }
205
- loadSession(e = "", i) {
205
+ loadSession(i = "", e) {
206
206
  return l(this, null, function* () {
207
207
  this.checkReady();
208
- let t = this.sessions.find((n) => n.id === e);
209
- if (t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
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(e) {
224
+ reloadSession(i) {
225
225
  return l(this, null, function* () {
226
226
  yield this.reload();
227
- let i = this._sessions.find((t) => t.id === e) || this._activeSession;
228
- if (!i) {
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 i.reload(), i;
232
+ return yield e.reload(), e;
233
233
  });
234
234
  }
235
- setTop(e, i, t = "top_time desc, sort_status desc, updated_at desc") {
235
+ setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
236
236
  return l(this, null, function* () {
237
- let n = e ? this._sessions.find((a) => a.id === e) : this._activeSession;
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(i), this.getSessions({
242
+ return yield n.setTop(e), this.getSessions({
243
243
  order: t
244
244
  });
245
245
  });
246
246
  }
247
- addEventListener(e, i, t = !1) {
248
- if (typeof i != "function")
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(e, i);
251
+ this.event.once(i, e);
252
252
  return;
253
253
  }
254
- this.event.on(e, i);
254
+ this.event.on(i, e);
255
255
  }
256
- removeEventListener(e, i) {
257
- this.event.off(e, i);
256
+ removeEventListener(i, e) {
257
+ this.event.off(i, e);
258
258
  }
259
- removeSession(e, i) {
259
+ removeSession(i, e) {
260
260
  return l(this, null, function* () {
261
261
  this.checkReady();
262
262
  let t = -1;
263
- if (typeof e == "string" ? t = this._sessions.findIndex((n) => n.id === e) : t = this._sessions.findIndex((n) => n.id === e.id), t > -1) {
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
- i && (yield n.delete()), this._sessions.splice(t, 1);
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((e) => e.destroy()), this.sessions = [];
271
+ this._sessions.forEach((i) => i.destroy()), this.sessions = [];
272
272
  }
273
273
  }
274
274
  export {
@@ -1,19 +1,19 @@
1
- var s = Object.defineProperty, v = Object.defineProperties;
2
- var u = Object.getOwnPropertyDescriptors;
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 ? s(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, i = (o, t) => {
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) => v(o, u(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 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 || {});
16
- let c = {
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 w(o) {
29
- d.debug = (o == null ? void 0 : o.debug) || !1, c = l(i(i({}, c), o), {
30
- apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
31
- }), d.debug && R.log("updated", c);
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
- f as ApiUrl,
35
- c as configuration,
36
- w as configure
37
+ s as ApiUrl,
38
+ i as configuration,
39
+ x as configure
37
40
  };