@glodon-aiot/bot-client-sdk 3.25.0 → 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,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 {