@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.
- package/dist/es/AgentSession.mjs +95 -116
- package/dist/es/BotClient.mjs +66 -68
- package/dist/es/Config.mjs +6 -7
- package/dist/es/DialogSession.mjs +167 -137
- package/dist/es/Session.mjs +171 -211
- package/dist/es/package.json.mjs +11 -11
- package/dist/lib/index.js +4 -4
- package/dist/src/Config.d.ts +0 -2
- package/dist/src/Session.d.ts +0 -6
- package/dist/src/constant.d.ts +13 -0
- package/package.json +2 -2
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var d = (
|
|
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(
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
g(t.next(e));
|
|
18
|
+
} catch (l) {
|
|
19
|
+
m(l);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, s = (e) => {
|
|
22
22
|
try {
|
|
23
|
-
g(
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
g(t.throw(e));
|
|
24
|
+
} catch (l) {
|
|
25
|
+
m(l);
|
|
26
26
|
}
|
|
27
|
-
}, g = (
|
|
28
|
-
g((
|
|
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
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import { configuration as
|
|
35
|
-
import { fetchEventSource as
|
|
36
|
-
const
|
|
37
|
-
class
|
|
38
|
-
constructor(
|
|
39
|
-
super(
|
|
40
|
-
|
|
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((
|
|
44
|
-
this._ready = !0, this.event.emit("ready"), this.frozen = !1,
|
|
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(
|
|
48
|
-
return
|
|
49
|
-
const
|
|
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:
|
|
54
|
-
sessionId:
|
|
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
|
-
},
|
|
64
|
-
stream:
|
|
63
|
+
}, l = R(u({}, m), {
|
|
64
|
+
stream: !0
|
|
65
65
|
});
|
|
66
|
-
|
|
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(
|
|
72
|
+
body: JSON.stringify(l),
|
|
73
73
|
openWhenHidden: !0,
|
|
74
74
|
signal: d,
|
|
75
|
-
onopen(
|
|
76
|
-
return
|
|
75
|
+
onopen(n) {
|
|
76
|
+
return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
|
|
77
77
|
},
|
|
78
|
-
onmessage(
|
|
79
|
-
if (!
|
|
80
|
-
let
|
|
78
|
+
onmessage(n) {
|
|
79
|
+
if (!n.data.includes('{"code": ')) {
|
|
80
|
+
let a = {};
|
|
81
81
|
try {
|
|
82
|
-
|
|
83
|
-
} catch (
|
|
82
|
+
a = JSON.parse(n.data);
|
|
83
|
+
} catch (M) {
|
|
84
84
|
}
|
|
85
|
-
(
|
|
86
|
-
const
|
|
87
|
-
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:
|
|
90
|
-
searchReference:
|
|
91
|
-
messageId:
|
|
92
|
-
sessionId:
|
|
93
|
-
messageTime:
|
|
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 (
|
|
99
|
+
return (s == null ? void 0 : s.onmessage) && s.onmessage(h);
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
const
|
|
104
|
-
code:
|
|
105
|
-
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:
|
|
108
|
-
searchReference:
|
|
109
|
-
messageId:
|
|
110
|
-
sessionId:
|
|
111
|
-
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
|
-
|
|
114
|
+
s != null && s.onmessage && s.onmessage(a);
|
|
115
115
|
} else
|
|
116
|
-
return
|
|
117
|
-
code:
|
|
118
|
-
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
|
-
|
|
122
|
+
s != null && s.onerror && s.onerror();
|
|
123
123
|
},
|
|
124
124
|
onclose() {
|
|
125
|
-
const
|
|
126
|
-
code:
|
|
127
|
-
content:
|
|
125
|
+
const n = {
|
|
126
|
+
code: e.code,
|
|
127
|
+
content: e.content,
|
|
128
128
|
role: 1,
|
|
129
|
-
reference:
|
|
130
|
-
searchReference:
|
|
131
|
-
messageId:
|
|
132
|
-
sessionId:
|
|
133
|
-
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
|
-
|
|
140
|
+
s != null && s.onclose && s.onclose(n);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
postChatV3EventSource(
|
|
146
|
-
return
|
|
147
|
-
const
|
|
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:
|
|
152
|
-
sessionId:
|
|
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(
|
|
166
|
-
stream:
|
|
165
|
+
}, l = R(u({}, m), {
|
|
166
|
+
stream: !0
|
|
167
167
|
});
|
|
168
|
-
|
|
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(
|
|
178
|
-
return
|
|
177
|
+
onopen(n) {
|
|
178
|
+
return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
|
|
179
179
|
},
|
|
180
|
-
onmessage(
|
|
181
|
-
if (!
|
|
180
|
+
onmessage(n) {
|
|
181
|
+
if (!n.data && !n.event && !n.id && !n.retry)
|
|
182
182
|
return;
|
|
183
|
-
let
|
|
183
|
+
let r = {};
|
|
184
184
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
console.error("parse eventData to JSON failed. ",
|
|
185
|
+
r = JSON.parse(n.data);
|
|
186
|
+
} catch (y) {
|
|
187
|
+
console.error("parse eventData to JSON failed. ", n.data);
|
|
188
188
|
}
|
|
189
|
-
if (
|
|
190
|
-
return
|
|
191
|
-
code:
|
|
192
|
-
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.
|
|
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
|
-
|
|
227
|
+
s != null && s.onerror && s.onerror();
|
|
198
228
|
},
|
|
199
229
|
onclose() {
|
|
200
|
-
const
|
|
230
|
+
const n = R(u({}, e), {
|
|
201
231
|
isReplying: !1
|
|
202
232
|
});
|
|
203
|
-
|
|
233
|
+
s != null && s.onclose && s.onclose(n);
|
|
204
234
|
}
|
|
205
235
|
});
|
|
206
236
|
});
|
|
207
237
|
}
|
|
208
|
-
sendQuestion(
|
|
209
|
-
return
|
|
210
|
-
var
|
|
238
|
+
sendQuestion(t, o) {
|
|
239
|
+
return f(this, null, function* () {
|
|
240
|
+
var l;
|
|
211
241
|
const {
|
|
212
|
-
content:
|
|
242
|
+
content: m,
|
|
213
243
|
fileIds: d,
|
|
214
|
-
oldMessageId:
|
|
215
|
-
} =
|
|
244
|
+
oldMessageId: s
|
|
245
|
+
} = t, {
|
|
216
246
|
stream: g,
|
|
217
|
-
referenceFirst:
|
|
218
|
-
} =
|
|
247
|
+
referenceFirst: e
|
|
248
|
+
} = o;
|
|
219
249
|
if (this.active || (yield this.activate()), this._id) {
|
|
220
|
-
let
|
|
221
|
-
content:
|
|
250
|
+
let n = {
|
|
251
|
+
content: m,
|
|
222
252
|
fileIds: d,
|
|
223
|
-
referenceFirst:
|
|
224
|
-
oldMessageId:
|
|
225
|
-
promptVariables: this.promptVariables.reduce((
|
|
226
|
-
[
|
|
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: (
|
|
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,
|
|
260
|
+
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
|
|
231
261
|
onopen: () => {
|
|
232
|
-
|
|
262
|
+
I.log("open", this.ctrl);
|
|
233
263
|
},
|
|
234
|
-
onmessage: (
|
|
264
|
+
onmessage: (r) => {
|
|
235
265
|
if (this._stopAnswer)
|
|
236
266
|
return;
|
|
237
|
-
let
|
|
238
|
-
|
|
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: (
|
|
241
|
-
this._stopAnswer || (
|
|
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
|
|
284
|
+
return f(this, null, function* () {
|
|
255
285
|
throw new Error("MCP registration is not supported by DialogSession");
|
|
256
286
|
});
|
|
257
287
|
}
|
|
258
|
-
addMcpServers(
|
|
259
|
-
return
|
|
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
|
|
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
|
-
|
|
300
|
+
H as default
|
|
271
301
|
};
|