@glodon-aiot/bot-client-sdk 3.3.3 → 3.3.4-beta.1

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,65 +1,67 @@
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) => {
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
- 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) => {
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(a));
18
- } catch (p) {
19
- s(p);
17
+ n(e.next(o));
18
+ } catch (l) {
19
+ s(l);
20
20
  }
21
- }, r = (a) => {
21
+ }, c = (o) => {
22
22
  try {
23
- n(e.throw(a));
24
- } catch (p) {
25
- s(p);
23
+ n(e.throw(o));
24
+ } catch (l) {
25
+ s(l);
26
26
  }
27
- }, n = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(c, r);
28
- n((e = e.apply(o, 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 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
- 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 I("[BotClient] ");
40
- class F {
30
+ import { parseJWT as g } from "./utils.mjs";
31
+ import E from "./Logger.mjs";
32
+ import { getCVForceService as L } from "./api/index.mjs";
33
+ import { configure as S, configuration as y } from "./Config.mjs";
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
- l(this, "event", new M());
47
- l(this, "cvforceApi");
46
+ p(this, "event", new V());
47
+ p(this, "cvforceApi");
48
48
  //从token解析出来的用户信息
49
- l(this, "_applicationId");
50
- l(this, "_application", null);
49
+ p(this, "_applicationId");
50
+ p(this, "_application", null);
51
51
  //session列表,被加载过的session将会被缓存到这个列表中
52
- l(this, "_sessions", []);
52
+ p(this, "_sessions", []);
53
53
  //活跃的session,只支持一个活跃的session
54
- l(this, "_activeSession");
55
- l(this, "_ready", !1);
54
+ p(this, "_activeSession");
55
+ p(this, "_ready", !1);
56
56
  //问题长度
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)
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(() => {
62
- 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");
63
65
  });
64
66
  }
65
67
  checkReady() {
@@ -90,33 +92,37 @@ class F {
90
92
  }
91
93
  loadApplication() {
92
94
  return h(this, null, function* () {
93
- var e, t, s, c, r;
95
+ var e, t, s, a, c;
94
96
  this._application = yield this.cvforceApi.getApplicationId(
95
97
  this._applicationId,
96
98
  // 这里记录应用的名称和版本,以便后期数据分析
97
99
  {
98
100
  ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
99
101
  uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
100
- sdkVersion: V.version
102
+ sdkVersion: T.version
101
103
  }
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
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
+ recommendQuestionOpen: y.loadRelatedQuesions && n.arrange[0].recommendQuestionOpen
105
107
  })]
106
108
  })));
107
- const i = (r = (c = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : c[0]) == null ? void 0 : r.llmModel;
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;
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;
109
115
  });
110
116
  }
111
117
  getService() {
112
- return this.cvforceApi ? this.cvforceApi : R(g.apiRoot, this.token, (i, e) => T.error(e));
118
+ return this.cvforceApi ? this.cvforceApi : L(y.apiRoot, this.token, (i, e) => b.error(e));
113
119
  }
114
120
  get token() {
115
121
  return this._token;
116
122
  }
117
123
  set token(i) {
118
124
  this.checkReady(), this._token = i, this.ready = !1;
119
- const e = y(i).rid;
125
+ const e = g(i).rid;
120
126
  this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
121
127
  this.event.emit("ready");
122
128
  }), this.clean());
@@ -136,27 +142,27 @@ class F {
136
142
  this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
137
143
  });
138
144
  }
139
- createSession(i, e, t, s, c) {
145
+ createSession(i, e, t, s, a) {
140
146
  return h(this, null, function* () {
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));
147
+ const c = this;
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));
148
154
  else
149
- throw Error(`不支持的应用类型:${d}`);
155
+ throw Error(`不支持的应用类型:${_}`);
150
156
  });
151
157
  if (this.ready) {
152
158
  if (!this._application)
153
159
  throw Error("client is not ready");
154
- p(this._application.type);
160
+ l(this._application.type);
155
161
  } else
156
162
  this.event.on("ready", () => {
157
163
  if (!this._application)
158
164
  throw Error("_application is null");
159
- p(this._application.type);
165
+ l(this._application.type);
160
166
  }, !0);
161
167
  });
162
168
  });
@@ -164,17 +170,17 @@ class F {
164
170
  getSessions(i) {
165
171
  return h(this, null, function* () {
166
172
  return new Promise((e, t) => {
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);
173
+ const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((a) => {
174
+ const c = [];
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);
173
179
  else {
174
- const p = yield this.createSession(this.token, n.id, n, this.lazyload, this._application || void 0);
175
- r.push(p);
180
+ const l = yield this.createSession(this.token, n.id, n, this.lazyload, this._application || void 0);
181
+ c.push(l);
176
182
  }
177
- })), this.sessions = r, r;
183
+ })), this.sessions = c, c;
178
184
  });
179
185
  if (this.ready) {
180
186
  if (!this._application)
@@ -221,7 +227,7 @@ class F {
221
227
  }
222
228
  setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
223
229
  return h(this, null, function* () {
224
- let s = i ? this._sessions.find((c) => c.id === i) : this._activeSession;
230
+ let s = i ? this._sessions.find((a) => a.id === i) : this._activeSession;
225
231
  if (!s) {
226
232
  console.warn("setTop session failed.");
227
233
  return;
@@ -259,5 +265,5 @@ class F {
259
265
  }
260
266
  }
261
267
  export {
262
- F as default
268
+ U as default
263
269
  };
@@ -1,15 +1,15 @@
1
- var v = Object.defineProperty, s = Object.defineProperties;
1
+ var s = Object.defineProperty, v = 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 ? v(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 ? s(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) => s(o, u(t));
12
+ }, l = (o, t) => v(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,9 +22,10 @@ let c = {
22
22
  applicationId: "",
23
23
  plugins: {},
24
24
  mcp: void 0,
25
- loadRelatedQuesions: !0
25
+ loadRelatedQuesions: !0,
26
+ stream: !1
26
27
  };
27
- function x(o) {
28
+ function w(o) {
28
29
  d.debug = (o == null ? void 0 : o.debug) || !1, c = l(i(i({}, c), o), {
29
30
  apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
30
31
  }), d.debug && R.log("updated", c);
@@ -32,5 +33,5 @@ function x(o) {
32
33
  export {
33
34
  f as ApiUrl,
34
35
  c as configuration,
35
- x as configure
36
+ w as configure
36
37
  };