@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.
- package/dist/es/DialogSession.mjs +104 -102
- package/dist/es/Session.mjs +112 -110
- package/dist/es/package.json.mjs +11 -11
- package/dist/lib/index.js +3 -3
- package/dist/src/Session.d.ts +4 -1
- package/package.json +2 -2
- package/dist/agent-cli-sdk.js +0 -33141
- package/dist/agent-cli-sdk.umd.cjs +0 -140
- package/dist/src/__ tests __/AgentClient.spec.d.ts +0 -1
- package/dist/src/__ tests __/AgentSession.spec.d.ts +0 -1
- package/dist/src/__ tests __/DialogClient.spec.d.ts +0 -1
|
@@ -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
|
|
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) &&
|
|
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) &&
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var w = (
|
|
14
|
-
var
|
|
15
|
-
var
|
|
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
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
i(a.next(r));
|
|
18
|
+
} catch (o) {
|
|
19
|
+
d(o);
|
|
20
20
|
}
|
|
21
21
|
}, e = (r) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
i(a.throw(r));
|
|
24
|
+
} catch (o) {
|
|
25
|
+
d(o);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
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
|
|
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
|
|
35
|
-
import { fetchEventSource as
|
|
36
|
-
const
|
|
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,
|
|
39
|
-
super(a,
|
|
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) =>
|
|
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,
|
|
48
|
-
return
|
|
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:
|
|
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
|
-
},
|
|
64
|
-
stream:
|
|
63
|
+
}, o = y(u({}, d), {
|
|
64
|
+
stream: S.stream
|
|
65
65
|
});
|
|
66
|
-
|
|
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(
|
|
72
|
+
body: JSON.stringify(o),
|
|
73
73
|
openWhenHidden: !0,
|
|
74
|
-
signal:
|
|
75
|
-
onopen(
|
|
76
|
-
return
|
|
74
|
+
signal: h,
|
|
75
|
+
onopen(g) {
|
|
76
|
+
return g.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
|
|
77
77
|
},
|
|
78
|
-
onmessage(
|
|
79
|
-
if (!
|
|
80
|
-
let
|
|
78
|
+
onmessage(g) {
|
|
79
|
+
if (!g.data.includes('{"code": ')) {
|
|
80
|
+
let s = {};
|
|
81
81
|
try {
|
|
82
|
-
|
|
82
|
+
s = JSON.parse(g.data);
|
|
83
83
|
} catch (_) {
|
|
84
84
|
}
|
|
85
|
-
(
|
|
86
|
-
const
|
|
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:
|
|
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(
|
|
99
|
+
return (e == null ? void 0 : e.onmessage) && e.onmessage(c);
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
if (r.reference =
|
|
103
|
-
const
|
|
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:
|
|
110
|
+
sessionId: l,
|
|
111
111
|
messageTime: r.messageTime,
|
|
112
112
|
isReplying: !0
|
|
113
113
|
};
|
|
114
|
-
e != null && e.onmessage && e.onmessage(
|
|
114
|
+
e != null && e.onmessage && e.onmessage(s);
|
|
115
115
|
} else
|
|
116
|
-
return e != null && e.onclose && e.onclose(r),
|
|
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
|
|
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:
|
|
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(
|
|
140
|
+
e != null && e.onclose && e.onclose(g);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
postChatV3EventSource(a,
|
|
146
|
-
return
|
|
147
|
-
const r = this,
|
|
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:
|
|
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
|
-
},
|
|
166
|
-
stream:
|
|
165
|
+
}, g = y(u({}, d), {
|
|
166
|
+
stream: S.stream
|
|
167
167
|
});
|
|
168
|
-
|
|
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(
|
|
174
|
+
body: JSON.stringify(g),
|
|
175
175
|
openWhenHidden: !0,
|
|
176
|
-
signal:
|
|
177
|
-
onopen(
|
|
178
|
-
return
|
|
176
|
+
signal: h,
|
|
177
|
+
onopen(t) {
|
|
178
|
+
return t.ok && e != null && e.onopen && e.onopen(), Promise.resolve();
|
|
179
179
|
},
|
|
180
|
-
onmessage(
|
|
181
|
-
if (!
|
|
180
|
+
onmessage(t) {
|
|
181
|
+
if (!t.data && !t.event && !t.id && !t.retry)
|
|
182
182
|
return;
|
|
183
|
-
let
|
|
183
|
+
let s = {};
|
|
184
184
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
console.error("parse eventData to JSON failed. ",
|
|
185
|
+
s = JSON.parse(t.data);
|
|
186
|
+
} catch (c) {
|
|
187
|
+
console.error("parse eventData to JSON failed. ", t.data);
|
|
188
188
|
}
|
|
189
|
-
if (
|
|
190
|
-
return
|
|
191
|
-
code:
|
|
192
|
-
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(
|
|
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
|
|
200
|
+
const t = y(u({}, o), {
|
|
201
201
|
isReplying: !1
|
|
202
202
|
});
|
|
203
|
-
e != null && e.onclose && e.onclose(
|
|
203
|
+
e != null && e.onclose && e.onclose(t);
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
|
-
sendQuestion(a,
|
|
209
|
-
return
|
|
210
|
-
var
|
|
208
|
+
sendQuestion(a, l) {
|
|
209
|
+
return f(this, null, function* () {
|
|
210
|
+
var g;
|
|
211
211
|
const {
|
|
212
|
-
content:
|
|
213
|
-
fileIds:
|
|
214
|
-
oldMessageId: e
|
|
212
|
+
content: d,
|
|
213
|
+
fileIds: h,
|
|
214
|
+
oldMessageId: e,
|
|
215
|
+
imageContent: i
|
|
215
216
|
} = a, {
|
|
216
|
-
stream:
|
|
217
|
-
referenceFirst:
|
|
218
|
-
} =
|
|
217
|
+
stream: r,
|
|
218
|
+
referenceFirst: o
|
|
219
|
+
} = l;
|
|
219
220
|
if (this.active || (yield this.activate()), this._id) {
|
|
220
|
-
let
|
|
221
|
-
content:
|
|
222
|
-
fileIds:
|
|
223
|
-
referenceFirst:
|
|
221
|
+
let t = {
|
|
222
|
+
content: d,
|
|
223
|
+
fileIds: h,
|
|
224
|
+
referenceFirst: o,
|
|
224
225
|
oldMessageId: e,
|
|
225
|
-
promptVariables: this.promptVariables.filter((s) => s.type ===
|
|
226
|
-
[
|
|
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 ===
|
|
229
|
-
[
|
|
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: (
|
|
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,
|
|
237
|
+
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, t, this.ctrl.signal, {
|
|
236
238
|
onopen: () => {
|
|
237
|
-
|
|
239
|
+
v.log("open", this.ctrl);
|
|
238
240
|
},
|
|
239
241
|
onmessage: (s) => {
|
|
240
242
|
if (this._stopAnswer)
|
|
241
243
|
return;
|
|
242
|
-
let
|
|
243
|
-
|
|
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) =>
|
|
246
|
-
this._stopAnswer || (
|
|
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
|
|
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
|
|
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
|
|
271
|
+
return f(this, null, function* () {
|
|
270
272
|
throw new Error("MCP registration is not supported by DialogSession");
|
|
271
273
|
});
|
|
272
274
|
}
|