@glodon-aiot/bot-client-sdk 3.7.0-alpha.3 → 3.9.0-alpha.5

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