@glodon-aiot/bot-client-sdk 3.3.2-beta.8 → 3.3.5-alpha.16

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