@glodon-aiot/bot-client-sdk 3.5.2-beta.0 → 3.6.0-alpha.11

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