@glodon-aiot/bot-client-sdk 3.26.0-alpha.4 → 3.26.0-alpha.8

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,16 +1,16 @@
1
- var T = Object.defineProperty, j = Object.defineProperties;
1
+ var q = Object.defineProperty, j = Object.defineProperties;
2
2
  var L = Object.getOwnPropertyDescriptors;
3
- var S = Object.getOwnPropertySymbols;
3
+ var b = Object.getOwnPropertySymbols;
4
4
  var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
- var M = (r, c, e) => c in r ? T(r, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[c] = e, h = (r, c) => {
5
+ var M = (r, c, e) => c in r ? q(r, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[c] = e, m = (r, c) => {
6
6
  for (var e in c || (c = {}))
7
7
  F.call(c, e) && M(r, e, c[e]);
8
- if (S)
9
- for (var e of S(c))
8
+ if (b)
9
+ for (var e of b(c))
10
10
  N.call(c, e) && M(r, e, c[e]);
11
11
  return r;
12
12
  }, w = (r, c) => j(r, L(c));
13
- var b = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
13
+ var P = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
14
14
  var y = (r, c, e) => new Promise((o, a) => {
15
15
  var n = (i) => {
16
16
  try {
@@ -47,20 +47,20 @@ function _(r) {
47
47
  return r;
48
48
  }
49
49
  }
50
- function x(r) {
50
+ function E(r) {
51
51
  return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
52
52
  }
53
53
  function Y(r, c) {
54
54
  const e = _(r == null ? void 0 : r.query);
55
- if (!x(e))
55
+ if (!E(e))
56
56
  return e;
57
57
  const o = _(c);
58
- return x(o) && e != null ? e : o;
58
+ return E(o) && e != null ? e : o;
59
59
  }
60
60
  class Z extends D {
61
61
  constructor(e, o = "", a, n, t, s) {
62
62
  super(e, o, a, n, t, s);
63
- b(this, "inflightCalls", /* @__PURE__ */ new Set());
63
+ P(this, "inflightCalls", /* @__PURE__ */ new Set());
64
64
  }
65
65
  prepareConnection() {
66
66
  return new Promise((e) => y(this, null, function* () {
@@ -106,8 +106,8 @@ class Z extends D {
106
106
  runnerIsClient: d,
107
107
  pluginCode: l,
108
108
  funcCode: g,
109
- parameters: m,
110
- requestBody: E
109
+ parameters: h,
110
+ requestBody: x
111
111
  }
112
112
  } = t, u = this.messages[this.messages.length - 1];
113
113
  if (!u.messageId)
@@ -150,7 +150,7 @@ class Z extends D {
150
150
  f.warn("error", p), this.event.emit("error", p);
151
151
  } else if (i === "FUNCTION_CALL" && d) {
152
152
  f.log(`calling function ${g} of plugin ${l} with argument:
153
- ${JSON.stringify(m)}`);
153
+ ${JSON.stringify(h)}`);
154
154
  const p = (R = C.plugins) == null ? void 0 : R[l];
155
155
  if (!p) {
156
156
  s({
@@ -159,16 +159,16 @@ class Z extends D {
159
159
  });
160
160
  return;
161
161
  }
162
- const P = p[g];
163
- if (typeof P != "function") {
162
+ const S = p[g];
163
+ if (typeof S != "function") {
164
164
  s({
165
165
  code: 404,
166
166
  message: "没有找到插件方法。"
167
167
  });
168
168
  return;
169
169
  }
170
- const q = Y(m, E);
171
- this.invokeClientPlugin(P, q, s, {
170
+ const T = Y(h, x);
171
+ this.invokeClientPlugin(S, T, s, {
172
172
  requestId: t.requestId,
173
173
  pluginCode: l,
174
174
  functionCode: g
@@ -205,12 +205,12 @@ class Z extends D {
205
205
  };
206
206
  this.handleStreamAnswer(t.data, i), this.pushMessage(i), this.event.emit("message:content", i), i.index === -1 && (i.isReplying = !1, this.event.emit("answer:finish", i));
207
207
  }
208
- } else if (t.data.updateSession && this.data && (this.data = h(h({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
208
+ } else if (t.data.updateSession && this.data && (this.data = m(m({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
209
209
  let s = this.messages[this.messages.length - 1];
210
210
  if (s && !s.messageId)
211
- s = h(h({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
211
+ s = m(m({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
212
212
  else {
213
- const i = h({
213
+ const i = m({
214
214
  messageId: "",
215
215
  content: "",
216
216
  role: v.Robot,
@@ -229,7 +229,7 @@ class Z extends D {
229
229
  }
230
230
  } else {
231
231
  let s = this.messages[this.messages.length - 1];
232
- s && !s.messageId ? (s = h(h({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(h({
232
+ s && !s.messageId ? (s = m(m({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(m({
233
233
  messageId: "",
234
234
  content: "",
235
235
  role: v.Robot,
@@ -249,25 +249,25 @@ class Z extends D {
249
249
  if (this._stopAnswer)
250
250
  return;
251
251
  if (!this.id) {
252
- const m = new Error(
252
+ const h = new Error(
253
253
  k.IdUndefined
254
254
  // {
255
255
  // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
256
256
  // }
257
257
  );
258
- f.error(m), this.event.emit("error", m), this.frozen = !1;
258
+ f.error(h), this.event.emit("error", h), this.frozen = !1;
259
259
  return;
260
260
  }
261
261
  const {
262
262
  type: s,
263
263
  data: i,
264
264
  requestId: d
265
- } = t, l = this.messages.findIndex((m) => m.messageId === d && m.role === v.User);
265
+ } = t, l = this.messages.findIndex((h) => h.messageId === d && h.role === v.User);
266
266
  if (l < 0)
267
267
  return;
268
268
  const g = l + 1;
269
269
  if (g >= this.messages.length) {
270
- const m = {
270
+ const h = {
271
271
  messageId: "",
272
272
  content: "",
273
273
  role: v.Robot,
@@ -282,11 +282,11 @@ class Z extends D {
282
282
  },
283
283
  isReplying: !0
284
284
  };
285
- this.pushMessage(m);
285
+ this.pushMessage(h);
286
286
  }
287
- s === "KG" ? (this.messages[g] = w(h({}, this.messages[g]), {
287
+ s === "KG" ? (this.messages[g] = w(m({}, this.messages[g]), {
288
288
  reference: i.knowledgeReference
289
- }), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(h({}, this.messages[g]), {
289
+ }), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(m({}, this.messages[g]), {
290
290
  searchReference: i.knowledgeReference
291
291
  }), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
292
292
  })), this.socket = n, n.open();
@@ -329,18 +329,17 @@ class Z extends D {
329
329
  return y(this, null, function* () {
330
330
  var n, t, s;
331
331
  this.convertKnowledgesToChatFormat(this.knowledges);
332
- let a = w(h({}, e), {
333
- promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(h({}, i), {
332
+ let a = w(m({}, e), {
333
+ promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(m({}, i), {
334
334
  [d.key]: d.value
335
335
  }), {}),
336
- systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(h({}, i), {
336
+ systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(m({}, i), {
337
337
  [d.key]: d.value
338
338
  }), {}),
339
339
  knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
340
340
  //agent支持指定文件时再放开
341
341
  // knowledges: knowledgesForChat,
342
- //开启内容摘要
343
- enableTitleSummary: !0
342
+ enableTitleSummary: this.resolveEnableTitleSummary()
344
343
  });
345
344
  if (!this.active) {
346
345
  if (yield this.activate(), !this.socket) {
@@ -11,7 +11,7 @@ var R = (l, c, s) => c in l ? I(l, c, { enumerable: !0, configurable: !0, writab
11
11
  return l;
12
12
  }, y = (l, c) => A(l, P(c));
13
13
  var M = (l, c, s) => (R(l, typeof c != "symbol" ? c + "" : c, s), s);
14
- var f = (l, c, s) => new Promise((a, d) => {
14
+ var f = (l, c, s) => new Promise((t, d) => {
15
15
  var h = (r) => {
16
16
  try {
17
17
  i(s.next(r));
@@ -24,7 +24,7 @@ var f = (l, c, s) => new Promise((a, d) => {
24
24
  } catch (m) {
25
25
  d(m);
26
26
  }
27
- }, i = (r) => r.done ? a(r.value) : Promise.resolve(r.value).then(h, e);
27
+ }, i = (r) => r.done ? t(r.value) : Promise.resolve(r.value).then(h, e);
28
28
  i((s = s.apply(l, c)).next());
29
29
  });
30
30
  import { IHistoryRole as C, PromptVariableType as v, ChatMessageRole as O } from "@glodon-aiot/apis";
@@ -35,8 +35,8 @@ import { configuration as S } from "./Config.mjs";
35
35
  import { fetchEventSource as T } from "./api/fetchEventSource/fetch.mjs";
36
36
  const p = new V("[DialogSession] ");
37
37
  class k extends $ {
38
- constructor(s, a = "", d, h, e, i) {
39
- super(s, a, d, h, e, i);
38
+ constructor(s, t = "", d, h, e, i) {
39
+ super(s, t, d, h, e, i);
40
40
  M(this, "ctrl", new AbortController());
41
41
  }
42
42
  prepareConnection() {
@@ -44,14 +44,14 @@ class k extends $ {
44
44
  this._ready = !0, this.event.emit("ready"), this.frozen = !1, s(!0);
45
45
  }));
46
46
  }
47
- postChatV2EventSource(s, a, d, h, e, i) {
47
+ postChatV2EventSource(s, t, d, h, e, i) {
48
48
  return f(this, null, function* () {
49
49
  const r = {
50
50
  code: 0,
51
51
  // messageId: uuidv4(),
52
52
  content: "",
53
53
  role: C.Robot,
54
- sessionId: a,
54
+ sessionId: t,
55
55
  reference: [],
56
56
  searchReference: [],
57
57
  messageTime: "",
@@ -63,7 +63,7 @@ class k extends $ {
63
63
  }, m = y(u({}, d), {
64
64
  stream: S.stream
65
65
  });
66
- T(`${S.apiRoot}/chat/v2/chat?applicationId=${s}&sessionId=${a}`, {
66
+ T(`${S.apiRoot}/chat/v2/chat?applicationId=${s}&sessionId=${t}`, {
67
67
  method: "POST",
68
68
  headers: {
69
69
  Authorization: `Bearer ${this.token}`,
@@ -77,19 +77,19 @@ class k extends $ {
77
77
  },
78
78
  onmessage(g) {
79
79
  if (!g.data.includes('{"code": ')) {
80
- let t = {};
80
+ let a = {};
81
81
  try {
82
- t = JSON.parse(g.data);
83
- } catch (J) {
82
+ a = JSON.parse(g.data);
83
+ } catch (E) {
84
84
  }
85
- (t == null ? void 0 : t.mtype) === "search" ? r.searchReference.push(t) : r.content = r.content + g.data;
85
+ (a == null ? void 0 : a.mtype) === "search" ? r.searchReference.push(a) : r.content = r.content + g.data;
86
86
  const o = {
87
87
  content: r.content,
88
88
  role: 1,
89
89
  reference: r.reference,
90
90
  searchReference: r.searchReference,
91
91
  messageId: r.messageId,
92
- sessionId: a,
92
+ sessionId: t,
93
93
  messageTime: _(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
94
94
  comment: {
95
95
  isAgree: 0
@@ -100,18 +100,18 @@ class k extends $ {
100
100
  }
101
101
  const n = JSON.parse(g.data);
102
102
  if (r.reference = n.data.reference, r.searchReference = n.data.searchReference, r.messageTime = n.data.messageTime, r.messageId = n.data.messageId, r.llmModel = n.data.llmModel, r.content = n.data.content, r.code = n.code, n.code === 200) {
103
- const t = {
103
+ const a = {
104
104
  code: r.code,
105
105
  content: r.content,
106
106
  role: 1,
107
107
  reference: r.reference,
108
108
  searchReference: r.searchReference,
109
109
  messageId: r.messageId,
110
- sessionId: a,
110
+ sessionId: t,
111
111
  messageTime: r.messageTime,
112
112
  isReplying: !0
113
113
  };
114
- e != null && e.onmessage && e.onmessage(t);
114
+ e != null && e.onmessage && e.onmessage(a);
115
115
  } else
116
116
  return e != null && e.onclose && e.onclose(r), i && i({
117
117
  code: r.code,
@@ -129,7 +129,7 @@ class k extends $ {
129
129
  reference: r.reference,
130
130
  searchReference: r.searchReference,
131
131
  messageId: r.messageId,
132
- sessionId: a,
132
+ sessionId: t,
133
133
  messageTime: r.messageTime,
134
134
  comment: {
135
135
  isAgree: 0
@@ -142,14 +142,14 @@ class k extends $ {
142
142
  });
143
143
  });
144
144
  }
145
- postChatV3EventSource(s, a, d, h, e, i) {
145
+ postChatV3EventSource(s, t, d, h, e, i) {
146
146
  return f(this, null, function* () {
147
147
  const r = this, m = {
148
148
  code: 0,
149
149
  // messageId: uuidv4(),
150
150
  content: "",
151
151
  role: C.Robot,
152
- sessionId: a,
152
+ sessionId: t,
153
153
  reference: [],
154
154
  searchReference: [],
155
155
  messageTime: "",
@@ -165,7 +165,7 @@ class k extends $ {
165
165
  }, g = y(u({}, d), {
166
166
  stream: S.stream
167
167
  });
168
- T(`${S.apiRoot}/chat/v3/chat?applicationId=${s}&sessionId=${a}`, {
168
+ T(`${S.apiRoot}/chat/v3/chat?applicationId=${s}&sessionId=${t}`, {
169
169
  method: "POST",
170
170
  headers: {
171
171
  Authorization: `Bearer ${this.token}`,
@@ -180,18 +180,18 @@ class k extends $ {
180
180
  onmessage(n) {
181
181
  if (!n.data && !n.event && !n.id && !n.retry)
182
182
  return;
183
- let t = {};
183
+ let a = {};
184
184
  try {
185
- t = JSON.parse(n.data);
185
+ a = JSON.parse(n.data);
186
186
  } catch (o) {
187
187
  console.error("parse eventData to JSON failed. ", n.data);
188
188
  }
189
- if (t.code !== 200)
190
- return m.index = -1, m.code = t.code, m.message = t.message, e != null && e.onmessage && e.onmessage(m), i && i({
191
- code: t.code,
192
- message: t.message
189
+ if (a.code !== 200)
190
+ return m.index = -1, m.code = a.code, m.message = a.message, e != null && e.onmessage && e.onmessage(m), i && i({
191
+ code: a.code,
192
+ message: a.message
193
193
  });
194
- r.handleStreamAnswer(t, m), e != null && e.onmessage && e.onmessage(m);
194
+ r.handleStreamAnswer(a, m), e != null && e.onmessage && e.onmessage(m);
195
195
  },
196
196
  onerror() {
197
197
  e != null && e.onerror && e.onerror();
@@ -205,7 +205,7 @@ class k extends $ {
205
205
  });
206
206
  });
207
207
  }
208
- sendQuestion(s, a) {
208
+ sendQuestion(s, t) {
209
209
  return f(this, null, function* () {
210
210
  const {
211
211
  content: d,
@@ -215,7 +215,7 @@ class k extends $ {
215
215
  } = s, {
216
216
  stream: r,
217
217
  referenceFirst: m
218
- } = a;
218
+ } = t;
219
219
  if (this.active || (yield this.activate()), this._id) {
220
220
  const g = this.convertKnowledgesToChatFormat(this.knowledges);
221
221
  let n = {
@@ -223,29 +223,28 @@ class k extends $ {
223
223
  fileIds: h,
224
224
  referenceFirst: m,
225
225
  oldMessageId: e,
226
- promptVariables: this.promptVariables.filter((t) => t.type === v.User).reduce((t, o) => y(u({}, t), {
226
+ promptVariables: this.promptVariables.filter((a) => a.type === v.User).reduce((a, o) => y(u({}, a), {
227
227
  [o.key]: o.value
228
228
  }), {}),
229
- systemPromptVariables: this.promptVariables.filter((t) => t.type === v.System).reduce((t, o) => y(u({}, t), {
229
+ systemPromptVariables: this.promptVariables.filter((a) => a.type === v.System).reduce((a, o) => y(u({}, a), {
230
230
  [o.key]: o.value
231
231
  }), {}),
232
232
  knowledges: g,
233
- //开启内容摘要
234
- enableTitleSummary: !0,
233
+ enableTitleSummary: this.resolveEnableTitleSummary(),
235
234
  imageContent: i
236
235
  };
237
236
  this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
238
237
  onopen: () => {
239
238
  p.log("open", this.ctrl);
240
239
  },
241
- onmessage: (t) => {
240
+ onmessage: (a) => {
242
241
  if (this._stopAnswer)
243
242
  return;
244
243
  let o = this.messages[this.messages.length - 1];
245
- o && o.role === O.Robot ? (o = u(u({}, o), t), this.messages[this.messages.length - 1] = o, this.event.emit("message:content", o), this.event.emit("message:updated", o)) : (this.pushMessage(t), this.event.emit("message:content", t));
244
+ o && o.role === O.Robot ? (o = u(u({}, o), a), this.messages[this.messages.length - 1] = o, this.event.emit("message:content", o), this.event.emit("message:updated", o)) : (this.pushMessage(a), this.event.emit("message:content", a));
246
245
  },
247
- onclose: (t) => f(this, null, function* () {
248
- this._stopAnswer || (p.log(t, "onclose"), this.event.emit("answer:finish", t));
246
+ onclose: (a) => f(this, null, function* () {
247
+ this._stopAnswer || (p.log(a, "onclose"), this.event.emit("answer:finish", a));
249
248
  }),
250
249
  onerror: () => {
251
250
  this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
@@ -273,10 +272,10 @@ class k extends $ {
273
272
  });
274
273
  }
275
274
  convertKnowledgesToChatFormat(s) {
276
- return s ? s.map((a) => a != null && a.fileIds ? {
277
- id: a.id,
278
- fileIds: a.fileIds
279
- } : a.id) : [];
275
+ return s ? s.map((t) => t != null && t.fileIds ? {
276
+ id: t.id,
277
+ fileIds: t.fileIds
278
+ } : t.id) : [];
280
279
  }
281
280
  }
282
281
  export {