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

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,57 +1,57 @@
1
- var b = Object.defineProperty, A = Object.defineProperties;
2
- var I = Object.getOwnPropertyDescriptors;
3
- var M = Object.getOwnPropertySymbols;
4
- var k = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
5
- var R = (o, n, a) => n in o ? b(o, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[n] = a, f = (o, n) => {
6
- for (var a in n || (n = {}))
7
- k.call(n, a) && R(o, a, n[a]);
8
- if (M)
9
- for (var a of M(n))
10
- D.call(n, a) && R(o, a, n[a]);
11
- return o;
12
- }, u = (o, n) => A(o, I(n));
13
- var w = (o, n, a) => (R(o, typeof n != "symbol" ? n + "" : n, a), a);
14
- var h = (o, n, a) => new Promise((m, i) => {
15
- var d = (r) => {
1
+ var A = Object.defineProperty, O = Object.defineProperties;
2
+ var D = Object.getOwnPropertyDescriptors;
3
+ var C = Object.getOwnPropertySymbols;
4
+ var P = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
5
+ var w = (i, c, t) => c in i ? A(i, c, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[c] = t, u = (i, c) => {
6
+ for (var t in c || (c = {}))
7
+ P.call(c, t) && w(i, t, c[t]);
8
+ if (C)
9
+ for (var t of C(c))
10
+ $.call(c, t) && w(i, t, c[t]);
11
+ return i;
12
+ }, R = (i, c) => O(i, D(c));
13
+ var v = (i, c, t) => (w(i, typeof c != "symbol" ? c + "" : c, t), t);
14
+ var f = (i, c, t) => new Promise((o, m) => {
15
+ var d = (e) => {
16
16
  try {
17
- g(a.next(r));
18
- } catch (c) {
19
- i(c);
17
+ g(t.next(e));
18
+ } catch (l) {
19
+ m(l);
20
20
  }
21
- }, e = (r) => {
21
+ }, s = (e) => {
22
22
  try {
23
- g(a.throw(r));
24
- } catch (c) {
25
- i(c);
23
+ g(t.throw(e));
24
+ } catch (l) {
25
+ m(l);
26
26
  }
27
- }, g = (r) => r.done ? m(r.value) : Promise.resolve(r.value).then(d, e);
28
- g((a = a.apply(o, n)).next());
27
+ }, g = (e) => e.done ? o(e.value) : Promise.resolve(e.value).then(d, s);
28
+ g((t = t.apply(i, c)).next());
29
29
  });
30
- import { IHistoryRole as C, ChatMessageRole as P } from "@glodon-aiot/apis";
31
- import p from "./Logger.mjs";
32
- import O from "./Session.mjs";
33
- import $ from "dayjs";
34
- import { configuration as y } from "./Config.mjs";
35
- import { fetchEventSource as v } from "./api/fetchEventSource/fetch.mjs";
36
- const T = new p("[DialogSession] ");
37
- class j extends O {
38
- constructor(a, m = "", i, d, e, g) {
39
- super(a, m, i, d, e, g);
40
- w(this, "ctrl", new AbortController());
30
+ import { IHistoryRole as k, ChatMessageRole as _ } from "@glodon-aiot/apis";
31
+ import x from "./Logger.mjs";
32
+ import J from "./Session.mjs";
33
+ import N from "dayjs";
34
+ import { configuration as T } from "./Config.mjs";
35
+ import { fetchEventSource as p } from "./api/fetchEventSource/fetch.mjs";
36
+ const I = new x("[DialogSession] ");
37
+ class H extends J {
38
+ constructor(t, o = "", m, d, s, g) {
39
+ super(t, o, m, d, s, g);
40
+ v(this, "ctrl", new AbortController());
41
41
  }
42
42
  prepareConnection() {
43
- return new Promise((a) => h(this, null, function* () {
44
- this._ready = !0, this.event.emit("ready"), this.frozen = !1, a(!0);
43
+ return new Promise((t) => f(this, null, function* () {
44
+ this._ready = !0, this.event.emit("ready"), this.frozen = !1, t(!0);
45
45
  }));
46
46
  }
47
- postChatV2EventSource(a, m, i, d, e, g) {
48
- return h(this, null, function* () {
49
- const r = {
47
+ postChatV2EventSource(t, o, m, d, s, g) {
48
+ return f(this, null, function* () {
49
+ const e = {
50
50
  code: 0,
51
51
  // messageId: uuidv4(),
52
52
  content: "",
53
- role: C.Robot,
54
- sessionId: m,
53
+ role: k.Robot,
54
+ sessionId: o,
55
55
  reference: [],
56
56
  searchReference: [],
57
57
  messageTime: "",
@@ -60,96 +60,96 @@ class j extends O {
60
60
  isAgree: 0
61
61
  },
62
62
  isReplying: !1
63
- }, c = u(f({}, i), {
64
- stream: y.stream
63
+ }, l = R(u({}, m), {
64
+ stream: !0
65
65
  });
66
- v(`${y.apiRoot}/chat/v2/chat?applicationId=${a}&sessionId=${m}`, {
66
+ p(`${T.apiRoot}/chat/v2/chat?applicationId=${t}&sessionId=${o}`, {
67
67
  method: "POST",
68
68
  headers: {
69
69
  Authorization: `Bearer ${this.token}`,
70
70
  "Content-Type": "application/json"
71
71
  },
72
- body: JSON.stringify(c),
72
+ body: JSON.stringify(l),
73
73
  openWhenHidden: !0,
74
74
  signal: d,
75
- onopen(l) {
76
- return l.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
75
+ onopen(n) {
76
+ return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
77
77
  },
78
- onmessage(l) {
79
- if (!l.data.includes('{"code": ')) {
80
- let t = {};
78
+ onmessage(n) {
79
+ if (!n.data.includes('{"code": ')) {
80
+ let a = {};
81
81
  try {
82
- t = JSON.parse(l.data);
83
- } catch (_) {
82
+ a = JSON.parse(n.data);
83
+ } catch (M) {
84
84
  }
85
- (t == null ? void 0 : t.mtype) === "search" ? r.searchReference.push(t) : r.content = r.content + l.data;
86
- const S = {
87
- content: r.content,
85
+ (a == null ? void 0 : a.mtype) === "search" ? e.searchReference.push(a) : e.content = e.content + n.data;
86
+ const h = {
87
+ content: e.content,
88
88
  role: 1,
89
- reference: r.reference,
90
- searchReference: r.searchReference,
91
- messageId: r.messageId,
92
- sessionId: m,
93
- messageTime: $(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
89
+ reference: e.reference,
90
+ searchReference: e.searchReference,
91
+ messageId: e.messageId,
92
+ sessionId: o,
93
+ messageTime: N(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
94
94
  comment: {
95
95
  isAgree: 0
96
96
  },
97
97
  isReplying: !0
98
98
  };
99
- return (e == null ? void 0 : e.onmessage) && e.onmessage(S);
99
+ return (s == null ? void 0 : s.onmessage) && s.onmessage(h);
100
100
  }
101
- const s = JSON.parse(l.data);
102
- if (r.reference = s.data.reference, r.searchReference = s.data.searchReference, r.messageTime = s.data.messageTime, r.messageId = s.data.messageId, r.llmModel = s.data.llmModel, r.content = s.data.content, r.code = s.code, s.code === 200) {
103
- const t = {
104
- code: r.code,
105
- content: r.content,
101
+ const r = JSON.parse(n.data);
102
+ if (e.reference = r.data.reference, e.searchReference = r.data.searchReference, e.messageTime = r.data.messageTime, e.messageId = r.data.messageId, e.llmModel = r.data.llmModel, e.content = r.data.content, e.code = r.code, r.code === 200) {
103
+ const a = {
104
+ code: e.code,
105
+ content: e.content,
106
106
  role: 1,
107
- reference: r.reference,
108
- searchReference: r.searchReference,
109
- messageId: r.messageId,
110
- sessionId: m,
111
- messageTime: r.messageTime,
107
+ reference: e.reference,
108
+ searchReference: e.searchReference,
109
+ messageId: e.messageId,
110
+ sessionId: o,
111
+ messageTime: e.messageTime,
112
112
  isReplying: !0
113
113
  };
114
- e != null && e.onmessage && e.onmessage(t);
114
+ s != null && s.onmessage && s.onmessage(a);
115
115
  } else
116
- return e != null && e.onclose && e.onclose(r), g && g({
117
- code: r.code,
118
- message: r.message
116
+ return s != null && s.onclose && s.onclose(e), g && g({
117
+ code: e.code,
118
+ message: e.message
119
119
  });
120
120
  },
121
121
  onerror() {
122
- e != null && e.onerror && e.onerror();
122
+ s != null && s.onerror && s.onerror();
123
123
  },
124
124
  onclose() {
125
- const l = {
126
- code: r.code,
127
- content: r.content,
125
+ const n = {
126
+ code: e.code,
127
+ content: e.content,
128
128
  role: 1,
129
- reference: r.reference,
130
- searchReference: r.searchReference,
131
- messageId: r.messageId,
132
- sessionId: m,
133
- messageTime: r.messageTime,
129
+ reference: e.reference,
130
+ searchReference: e.searchReference,
131
+ messageId: e.messageId,
132
+ sessionId: o,
133
+ messageTime: e.messageTime,
134
134
  comment: {
135
135
  isAgree: 0
136
136
  },
137
137
  isReplying: !1,
138
138
  index: -1
139
139
  };
140
- e != null && e.onclose && e.onclose(l);
140
+ s != null && s.onclose && s.onclose(n);
141
141
  }
142
142
  });
143
143
  });
144
144
  }
145
- postChatV3EventSource(a, m, i, d, e, g) {
146
- return h(this, null, function* () {
147
- const r = this, c = {
145
+ postChatV3EventSource(t, o, m, d, s, g) {
146
+ return f(this, null, function* () {
147
+ const e = {
148
148
  code: 0,
149
149
  // messageId: uuidv4(),
150
150
  content: "",
151
- role: C.Robot,
152
- sessionId: m,
151
+ role: k.Robot,
152
+ sessionId: o,
153
153
  reference: [],
154
154
  searchReference: [],
155
155
  messageTime: "",
@@ -162,10 +162,10 @@ class j extends O {
162
162
  thinkingSecs: "",
163
163
  thinkingStatus: "",
164
164
  searchingStatus: ""
165
- }, l = u(f({}, i), {
166
- stream: y.stream
165
+ }, l = R(u({}, m), {
166
+ stream: !0
167
167
  });
168
- v(`${y.apiRoot}/chat/v3/chat?applicationId=${a}&sessionId=${m}`, {
168
+ p(`${T.apiRoot}/chat/v3/chat?applicationId=${t}&sessionId=${o}`, {
169
169
  method: "POST",
170
170
  headers: {
171
171
  Authorization: `Bearer ${this.token}`,
@@ -174,71 +174,101 @@ class j extends O {
174
174
  body: JSON.stringify(l),
175
175
  openWhenHidden: !0,
176
176
  signal: d,
177
- onopen(s) {
178
- return s.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
177
+ onopen(n) {
178
+ return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
179
179
  },
180
- onmessage(s) {
181
- if (!s.data && !s.event && !s.id && !s.retry)
180
+ onmessage(n) {
181
+ if (!n.data && !n.event && !n.id && !n.retry)
182
182
  return;
183
- let t = {};
183
+ let r = {};
184
184
  try {
185
- t = JSON.parse(s.data);
186
- } catch (S) {
187
- console.error("parse eventData to JSON failed. ", s.data);
185
+ r = JSON.parse(n.data);
186
+ } catch (y) {
187
+ console.error("parse eventData to JSON failed. ", n.data);
188
188
  }
189
- if (t.code !== 200)
190
- return c.index = -1, c.code = t.code, c.message = t.message, e != null && e.onmessage && e.onmessage(c), g && g({
191
- code: t.code,
192
- message: t.message
189
+ if (r.code !== 200)
190
+ return e.index = -1, e.code = r.code, e.message = r.message, s != null && s.onmessage && s.onmessage(e), g && g({
191
+ code: r.code,
192
+ message: r.message
193
193
  });
194
- r.handleStreamAnswer(t, c), e != null && e.onmessage && e.onmessage(c);
194
+ const a = r.data.type, h = r.data.payload;
195
+ e.isReplying = !0;
196
+ const M = () => {
197
+ if (!e.searchingStatus) {
198
+ e.searchingStatus = "start";
199
+ return;
200
+ }
201
+ if (e.searchingStatus === "start") {
202
+ e.searchingStatus = "end";
203
+ return;
204
+ }
205
+ };
206
+ if (a === "beforeSearch" && M(), a === "searchOver" && M(), a === "search" && e.searchReference.push(h), a === "thinking") {
207
+ e.thinkingStatus = "start";
208
+ const S = h.choices[0];
209
+ e.reasoningContent = e.reasoningContent + S.delta.reasoningContent;
210
+ }
211
+ if (a === "thinkingOver") {
212
+ e.thinkingStatus = "end";
213
+ const y = h.thinkingSecs;
214
+ e.thinkingSecs = y;
215
+ }
216
+ if (a === "text") {
217
+ const S = h.choices[0];
218
+ e.content = e.content + S.delta.content;
219
+ }
220
+ if (a === "reference" && (e.reference = h), a === "result") {
221
+ const y = h.messageId, S = h.llmModel, b = h.messageTime;
222
+ e.messageId = y, e.llmModel = S, e.messageTime = b, e.sessionId = o;
223
+ }
224
+ a === "over" ? e.index = -1 : (e.code = r.code, e.message = r.message), s != null && s.onmessage && s.onmessage(e);
195
225
  },
196
226
  onerror() {
197
- e != null && e.onerror && e.onerror();
227
+ s != null && s.onerror && s.onerror();
198
228
  },
199
229
  onclose() {
200
- const s = u(f({}, c), {
230
+ const n = R(u({}, e), {
201
231
  isReplying: !1
202
232
  });
203
- e != null && e.onclose && e.onclose(s);
233
+ s != null && s.onclose && s.onclose(n);
204
234
  }
205
235
  });
206
236
  });
207
237
  }
208
- sendQuestion(a, m) {
209
- return h(this, null, function* () {
210
- var c;
238
+ sendQuestion(t, o) {
239
+ return f(this, null, function* () {
240
+ var l;
211
241
  const {
212
- content: i,
242
+ content: m,
213
243
  fileIds: d,
214
- oldMessageId: e
215
- } = a, {
244
+ oldMessageId: s
245
+ } = t, {
216
246
  stream: g,
217
- referenceFirst: r
218
- } = m;
247
+ referenceFirst: e
248
+ } = o;
219
249
  if (this.active || (yield this.activate()), this._id) {
220
- let l = {
221
- content: i,
250
+ let n = {
251
+ content: m,
222
252
  fileIds: d,
223
- referenceFirst: r,
224
- oldMessageId: e,
225
- promptVariables: this.promptVariables.reduce((s, t) => u(f({}, s), {
226
- [t.key]: t.value
253
+ referenceFirst: e,
254
+ oldMessageId: s,
255
+ promptVariables: this.promptVariables.reduce((r, a) => R(u({}, r), {
256
+ [a.key]: a.value
227
257
  }), {}),
228
- knowledges: (c = this.knowledges) == null ? void 0 : c.map((s) => s.id)
258
+ knowledges: (l = this.knowledges) == null ? void 0 : l.map((r) => r.id)
229
259
  };
230
- this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, l, this.ctrl.signal, {
260
+ this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
231
261
  onopen: () => {
232
- T.log("open", this.ctrl);
262
+ I.log("open", this.ctrl);
233
263
  },
234
- onmessage: (s) => {
264
+ onmessage: (r) => {
235
265
  if (this._stopAnswer)
236
266
  return;
237
- let t = this.messages[this.messages.length - 1];
238
- t && t.role === P.Robot ? (t = f(f({}, t), s), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t)) : (this.pushMessage(s), this.event.emit("message:content", s));
267
+ let a = this.messages[this.messages.length - 1];
268
+ a && a.role === _.Robot ? (a = u(u({}, a), r), this.messages[this.messages.length - 1] = a, this.event.emit("message:content", a), this.event.emit("message:updated", a)) : (this.pushMessage(r), this.event.emit("message:content", r));
239
269
  },
240
- onclose: (s) => h(this, null, function* () {
241
- this._stopAnswer || (T.log(s, "onclose"), this.event.emit("answer:finish", s));
270
+ onclose: (r) => f(this, null, function* () {
271
+ this._stopAnswer || (I.log(r, "onclose"), this.event.emit("answer:finish", r));
242
272
  }),
243
273
  onerror: () => {
244
274
  this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
@@ -251,21 +281,21 @@ class j extends O {
251
281
  this.ctrl.abort();
252
282
  }
253
283
  registerMcpFromClientConfig() {
254
- return h(this, null, function* () {
284
+ return f(this, null, function* () {
255
285
  throw new Error("MCP registration is not supported by DialogSession");
256
286
  });
257
287
  }
258
- addMcpServers(a) {
259
- return h(this, null, function* () {
288
+ addMcpServers(t) {
289
+ return f(this, null, function* () {
260
290
  throw new Error("MCP registration is not supported by DialogSession");
261
291
  });
262
292
  }
263
293
  listMcpServers() {
264
- return h(this, null, function* () {
294
+ return f(this, null, function* () {
265
295
  throw new Error("MCP registration is not supported by DialogSession");
266
296
  });
267
297
  }
268
298
  }
269
299
  export {
270
- j as default
300
+ H as default
271
301
  };