@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.
@@ -1,67 +1,66 @@
1
- var S = Object.defineProperty, A = Object.defineProperties;
2
- var b = Object.getOwnPropertyDescriptors;
3
- var _ = Object.getOwnPropertySymbols;
4
- var P = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
5
- var C = (m, t, n) => t in m ? S(m, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : m[t] = n, g = (m, t) => {
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
- P.call(t, n) && C(m, n, t[n]);
8
- if (_)
9
- for (var n of _(t))
10
- x.call(t, n) && C(m, n, t[n]);
11
- return m;
12
- }, w = (m, t) => A(m, b(t));
13
- var v = (m, t, n) => new Promise((o, i) => {
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
- r(n.next(c));
17
- } catch (h) {
18
- i(h);
16
+ o(n.next(c));
17
+ } catch (g) {
18
+ i(g);
19
19
  }
20
20
  }, e = (c) => {
21
21
  try {
22
- r(n.throw(c));
23
- } catch (h) {
24
- i(h);
22
+ o(n.throw(c));
23
+ } catch (g) {
24
+ i(g);
25
25
  }
26
- }, r = (c) => c.done ? o(c.value) : Promise.resolve(c.value).then(s, e);
27
- r((n = n.apply(m, t)).next());
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 k } from "@glodon-aiot/apis";
30
- import E from "./Logger.mjs";
31
- import { configuration as u } from "./Config.mjs";
32
- import { io as q } from "socket.io-client";
33
- import { UserMode as M } from "./PayloadTypes.mjs";
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
- import N from "dayjs";
36
- const p = new E("[AgentSession] ");
37
- class H extends L {
38
- constructor(t, n = "", o, i, s, e) {
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) => v(this, null, function* () {
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: JSON.stringify(u.stream),
45
+ stream: "false",
47
46
  appId: this._applicationId,
48
47
  sessionId: this.id,
49
48
  Authorization: `${this.token}`,
50
- userMode: u.debug ? M.Debug : M.Normal
51
- }, o = new URL(u.apiRoot), i = yield q(o.origin, {
52
- path: o.pathname.replace("api", "socketio") + "/copilot",
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
- p.log("socket:connect"), this.event.emit("socket:connect"), i.emit("init");
56
+ u.log("socket:connect"), this.event.emit("socket:connect"), i.emit("init");
58
57
  }), i.on("disconnect", () => {
59
- p.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
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
- p.log("ready");
63
- const e = u.debug ? M.Debug : M.Normal;
64
- e === M.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), t(!0);
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
- p.error("error", e), this.event.emit("error", e), t(!1);
72
+ u.error("error", e), this.event.emit("error", e), t(!1);
74
73
  }
75
- }), i.on("action", (s, e) => v(this, null, function* () {
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: r,
78
+ type: o,
80
79
  data: {
81
80
  runnerIsClient: c,
82
- pluginCode: h,
83
- funcCode: d,
81
+ pluginCode: g,
82
+ funcCode: m,
84
83
  parameters: a,
85
- requestBody: j
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: k.Robot,
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
- p.warn("error", l), this.event.emit("error", l);
125
- } else if (r === "FUNCTION_CALL" && c) {
126
- if (p.log(`calling function ${d} of plugin ${h} with argument:
127
- ${JSON.stringify(a)}`), !u.plugins[h]) {
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 = u.plugins[h][d];
133
+ const l = v.plugins[g][m];
135
134
  typeof l != "function" && e({
136
135
  code: 404,
137
136
  message: "对不起,没有找到插件方法。"
138
137
  });
139
- let I = a == null ? void 0 : a.query;
138
+ let M = a == null ? void 0 : a.query;
140
139
  try {
141
- I = JSON.parse(a == null ? void 0 : a.query);
142
- } catch (R) {
140
+ M = JSON.parse(a == null ? void 0 : a.query);
141
+ } catch (_) {
143
142
  }
144
- l(I, (...R) => {
145
- this._stopAnswer || e(...R);
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), s.data.stream || s.data.stream === void 0) {
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 = g(g({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", 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 r = g({
154
+ const o = h({
176
155
  messageId: "",
177
156
  content: "",
178
- role: k.Robot,
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", r), this.pushMessage(r), this.event.emit("answer:finish", r);
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 = 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));
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) => v(this, null, function* () {
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
- p.error(a), this.event.emit("error", a), this.frozen = !1;
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: r,
189
+ data: o,
211
190
  requestId: c
212
- } = s, h = this.messages.findIndex((a) => a.messageId === c && a.role === k.User);
213
- if (h < 0)
191
+ } = s, g = this.messages.findIndex((a) => a.messageId === c && a.role === I.User);
192
+ if (g < 0)
214
193
  return;
215
- const d = h + 1;
216
- if (d >= this.messages.length) {
194
+ const m = g + 1;
195
+ if (m >= this.messages.length) {
217
196
  const a = {
218
197
  messageId: "",
219
198
  content: "",
220
- role: k.Robot,
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[d] = w(g({}, this.messages[d]), {
234
- reference: r.knowledgeReference
235
- }), yield this.fillMessageReference(this.messages[d]), this.event.emit("message:reference", r.knowledgeReference), this.event.emit("message:updated", this.messages[d])) : e === "WEB_SEARCH" && (this.messages[d] = w(g({}, this.messages[d]), {
236
- searchReference: r.knowledgeReference
237
- }), this.event.emit("message:searchreference", r.searchReference), this.event.emit("message:updated", this.messages[d]));
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 u.mcp ? new Promise((t, n) => {
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", u.mcp, (o) => {
248
- o.code === 200 ? (Object.keys(o.data).forEach((i) => {
249
- o.data[i].code !== 200 && console.error(i, "MCP Server 注册失败。", o.data[i]);
250
- }), t(!0)) : (console.error("MCP Server 注册失败。", o), n(o));
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 v(this, null, function* () {
256
- return this.ready ? this.socket ? new Promise((n, o) => {
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), o(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 v(this, null, function* () {
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", (o) => {
269
- o.code === 200 ? t(o.data) : n(o);
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 v(this, null, function* () {
254
+ return p(this, null, function* () {
276
255
  var i, s, e;
277
- let o = w(g({}, t), {
278
- promptVariables: this.promptVariables.reduce((r, c) => w(g({}, r), {
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((r) => r.id)
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 r = new Error(
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 p.warn("error", r), this.event.emit("error", r), !1;
270
+ return u.warn("error", o), this.event.emit("error", o), !1;
292
271
  }
293
- (s = this.socket) == null || s.emit("question", o);
272
+ (s = this.socket) == null || s.emit("question", r);
294
273
  return;
295
274
  }
296
- (e = this.socket) == null || e.emit("question", o);
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
- H as default
284
+ D as default
306
285
  };
@@ -1,67 +1,65 @@
1
- var w = Object.defineProperty, k = Object.defineProperties;
2
- var A = Object.getOwnPropertyDescriptors;
3
- var g = Object.getOwnPropertySymbols;
4
- var x = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
5
- var u = (a, i, e) => i in a ? w(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e, p = (a, i) => {
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
- x.call(i, e) && u(a, e, i[e]);
8
- if (g)
9
- for (var e of g(i))
10
- I.call(i, e) && u(a, e, i[e]);
11
- return a;
12
- }, f = (a, i) => k(a, A(i));
13
- var d = (a, i, e) => (u(a, typeof i != "symbol" ? i + "" : i, e), e);
14
- var h = (a, i, e) => new Promise((t, s) => {
15
- var o = (r) => {
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(r));
18
- } catch (l) {
19
- s(l);
17
+ n(e.next(a));
18
+ } catch (p) {
19
+ s(p);
20
20
  }
21
- }, c = (r) => {
21
+ }, r = (a) => {
22
22
  try {
23
- n(e.throw(r));
24
- } catch (l) {
25
- s(l);
23
+ n(e.throw(a));
24
+ } catch (p) {
25
+ s(p);
26
26
  }
27
- }, n = (r) => r.done ? t(r.value) : Promise.resolve(r.value).then(o, c);
28
- n((e = e.apply(a, i)).next());
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 m } from "./utils.mjs";
31
- import R from "./Logger.mjs";
32
- import { getCVForceService as E } from "./api/index.mjs";
33
- import { configure as S, configuration as v } from "./Config.mjs";
34
- import { ApplicationTypes as y } from "@glodon-aiot/apis";
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 R("[BotClient] ");
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
- d(this, "event", new M());
47
- d(this, "cvforceApi");
46
+ l(this, "event", new M());
47
+ l(this, "cvforceApi");
48
48
  //从token解析出来的用户信息
49
- d(this, "_applicationId");
50
- d(this, "_application", null);
49
+ l(this, "_applicationId");
50
+ l(this, "_application", null);
51
51
  //session列表,被加载过的session将会被缓存到这个列表中
52
- d(this, "_sessions", []);
52
+ l(this, "_sessions", []);
53
53
  //活跃的session,只支持一个活跃的session
54
- d(this, "_activeSession");
55
- d(this, "_ready", !1);
54
+ l(this, "_activeSession");
55
+ l(this, "_ready", !1);
56
56
  //问题长度
57
- d(this, "_questionContextMaxLength", 4e3);
58
- d(this, "_promptVariables", []);
59
- if (this._token = i, this.lazyload = t, this.sdkConfigs = s, S(e), this._applicationId = m(i).rid || v.applicationId, !this._applicationId)
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((o) => {
62
- S(f(p({}, e), {
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, o, c;
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), f(p({}, n), {
105
- arrange: [f(p({}, n.arrange[0]), {
106
- recommendQuestionOpen: v.loadRelatedQuesions && n.arrange[0].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 = (c = (o = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : o[0]) == null ? void 0 : c.llmModel;
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 : E(v.apiRoot, this.token, (i, e) => T.error(e));
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 = m(i).rid;
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, o) {
139
+ createSession(i, e, t, s, c) {
142
140
  return h(this, null, function* () {
143
- const c = this;
144
- return new Promise((n, r) => {
145
- const l = (_) => h(this, null, function* () {
146
- if (_ === y.Agent)
147
- n(new L(i, e, t, s, o, c));
148
- else if (_ === y.Dialog)
149
- n(new C(i, e, t, s, o, c));
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
- l(this._application.type);
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
- l(this._application.type);
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((o) => {
170
- const c = [];
171
- return o.forEach((n) => h(this, null, function* () {
172
- const r = this._sessions.find((l) => n.id === l.id);
173
- if (r)
174
- r.data = n, this._application ? r.application = this._application : r.loadApplicationInfo(), c.push(r);
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 l = yield this.createSession(this.token, n.id, n, this.lazyload, this._application || void 0);
177
- c.push(l);
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 = c, c;
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((o) => o.id === i) : this._activeSession;
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;
@@ -1,15 +1,15 @@
1
- var s = Object.defineProperty, v = Object.defineProperties;
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 ? 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 ? 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) => v(o, u(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 w(o) {
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
- w as configure
35
+ x as configure
37
36
  };