@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.10
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/README.md +555 -98
- package/dist/es/AgentSession.mjs +231 -167
- package/dist/es/BotClient.mjs +188 -136
- package/dist/es/Config.mjs +89 -26
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +83 -63
- package/dist/es/api/index.mjs +42 -33
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +244 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +63 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +471 -0
- package/dist/es/index.mjs +69 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +157 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
- package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
- package/dist/es/localFiles/constants.mjs +47 -0
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +53 -0
- package/dist/es/localFiles/host/protocol.mjs +27 -0
- package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +312 -0
- package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
- package/dist/es/localFiles/security/glob.mjs +28 -0
- package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
- package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
- package/dist/es/localFiles/tools/readTools.mjs +333 -0
- package/dist/es/localFiles/tools/runtime.mjs +108 -0
- package/dist/es/localFiles/tools/transferTools.mjs +228 -0
- package/dist/es/localFiles/tools/writeTools.mjs +173 -0
- package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
- package/dist/es/localFiles/validate.mjs +66 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
- package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
- package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
- package/dist/es/package.json.mjs +38 -29
- package/dist/lib/index.js +374 -5
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +25 -1
- package/dist/src/Session.d.ts +9 -1
- package/dist/src/api/index.d.ts +3 -1
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +28 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +15 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +60 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +37 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
- package/dist/src/localFiles/constants.d.ts +51 -0
- package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
- package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
- package/dist/src/localFiles/errors.d.ts +34 -0
- package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
- package/dist/src/localFiles/host/protocol.d.ts +40 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +22 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +29 -0
- package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
- package/dist/src/localFiles/security/glob.d.ts +3 -0
- package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
- package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
- package/dist/src/localFiles/tools/readTools.d.ts +7 -0
- package/dist/src/localFiles/tools/runtime.d.ts +43 -0
- package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
- package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
- package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
- package/dist/src/localFiles/types.d.ts +319 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +13 -4
|
@@ -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((
|
|
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 ?
|
|
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,
|
|
39
|
-
super(s,
|
|
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,
|
|
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:
|
|
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=${
|
|
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
|
|
80
|
+
let a = {};
|
|
81
81
|
try {
|
|
82
|
-
|
|
83
|
-
} catch (
|
|
82
|
+
a = JSON.parse(g.data);
|
|
83
|
+
} catch (E) {
|
|
84
84
|
}
|
|
85
|
-
(
|
|
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:
|
|
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
|
|
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:
|
|
110
|
+
sessionId: t,
|
|
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(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:
|
|
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,
|
|
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:
|
|
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=${
|
|
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
|
|
183
|
+
let a = {};
|
|
184
184
|
try {
|
|
185
|
-
|
|
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 (
|
|
190
|
-
return m.index = -1, m.code =
|
|
191
|
-
code:
|
|
192
|
-
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(
|
|
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,
|
|
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
|
-
} =
|
|
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((
|
|
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((
|
|
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: (
|
|
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),
|
|
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: (
|
|
248
|
-
this._stopAnswer || (p.log(
|
|
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((
|
|
277
|
-
id:
|
|
278
|
-
fileIds:
|
|
279
|
-
} :
|
|
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 {
|
package/dist/es/Session.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var
|
|
1
|
+
var T = Object.defineProperty, C = Object.defineProperties;
|
|
2
2
|
var M = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var E = Object.getOwnPropertySymbols;
|
|
4
4
|
var R = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var b = (l, e, t) => e in l ?
|
|
5
|
+
var b = (l, e, t) => e in l ? T(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t, f = (l, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
7
|
R.call(e, t) && b(l, t, e[t]);
|
|
8
8
|
if (E)
|
|
9
9
|
for (var t of E(e))
|
|
10
10
|
O.call(e, t) && b(l, t, e[t]);
|
|
11
11
|
return l;
|
|
12
|
-
}, I = (l, e) =>
|
|
12
|
+
}, I = (l, e) => C(l, M(e));
|
|
13
13
|
var p = (l, e, t) => (b(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
14
|
-
var c = (l, e, t) => new Promise((s,
|
|
14
|
+
var c = (l, e, t) => new Promise((s, a) => {
|
|
15
15
|
var n = (i) => {
|
|
16
16
|
try {
|
|
17
17
|
r(t.next(i));
|
|
18
18
|
} catch (h) {
|
|
19
|
-
|
|
19
|
+
a(h);
|
|
20
20
|
}
|
|
21
21
|
}, d = (i) => {
|
|
22
22
|
try {
|
|
23
23
|
r(t.throw(i));
|
|
24
24
|
} catch (h) {
|
|
25
|
-
|
|
25
|
+
a(h);
|
|
26
26
|
}
|
|
27
27
|
}, r = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(n, d);
|
|
28
28
|
r((t = t.apply(l, e)).next());
|
|
@@ -47,7 +47,7 @@ class te {
|
|
|
47
47
|
* @param _application - 应用信息,可选参数。
|
|
48
48
|
* @param client - Bot 客户端实例,可选参数。
|
|
49
49
|
*/
|
|
50
|
-
constructor(e, t = "", s,
|
|
50
|
+
constructor(e, t = "", s, a, n, d) {
|
|
51
51
|
p(this, "_id");
|
|
52
52
|
p(this, "_frozen", !1);
|
|
53
53
|
//是否可发送新问题
|
|
@@ -72,13 +72,13 @@ class te {
|
|
|
72
72
|
p(this, "_dataLoading", !1);
|
|
73
73
|
p(this, "_dataLoaded", !1);
|
|
74
74
|
p(this, "_mcpServers", null);
|
|
75
|
-
this.token = e, this.lazyload =
|
|
75
|
+
this.token = e, this.lazyload = a, this.client = d || null, this._applicationId = z(e).rid || S.applicationId, this.cvforceApi = this.getService(), n && (this._application = n), this.event.emit("init", {
|
|
76
76
|
applicationId: this._applicationId,
|
|
77
77
|
sessionId: t
|
|
78
78
|
}), this.loadApplicationInfo().then(() => {
|
|
79
79
|
var r;
|
|
80
80
|
if (t)
|
|
81
|
-
this._id = t, this.event.emit("data:loading"), s ? (this.data = s,
|
|
81
|
+
this._id = t, this.event.emit("data:loading"), s ? (this.data = s, a || (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((i) => c(this, null, function* () {
|
|
82
82
|
this.data = i, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t);
|
|
83
83
|
})).then(() => c(this, null, function* () {
|
|
84
84
|
this.messages = [], yield this.fetchMessages(), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data);
|
|
@@ -114,8 +114,8 @@ class te {
|
|
|
114
114
|
yield (() => {
|
|
115
115
|
if (s != null && s.promptVariables) {
|
|
116
116
|
const y = this._promptVariables.map((v) => {
|
|
117
|
-
var _,
|
|
118
|
-
const w = ((
|
|
117
|
+
var _, o;
|
|
118
|
+
const w = ((o = (_ = s.promptVariables) == null ? void 0 : _.find((g) => g.key === v.key && g.type === v.type)) == null ? void 0 : o.value) || "";
|
|
119
119
|
return I(f({}, v), {
|
|
120
120
|
value: w
|
|
121
121
|
});
|
|
@@ -175,12 +175,12 @@ class te {
|
|
|
175
175
|
return c(this, null, function* () {
|
|
176
176
|
if (!this.data)
|
|
177
177
|
throw Error("session data is not loaded");
|
|
178
|
-
if ((e || []).some((
|
|
178
|
+
if ((e || []).some((a) => Array.isArray(a.fileIds) && a.fileIds.length === 0))
|
|
179
179
|
throw Error("fileIds cannot be an empty array");
|
|
180
|
-
if ((e || []).reduce((
|
|
180
|
+
if ((e || []).reduce((a, n) => {
|
|
181
181
|
var r, i;
|
|
182
182
|
const d = (i = (r = n.fileIds) == null ? void 0 : r.length) != null ? i : 0;
|
|
183
|
-
return
|
|
183
|
+
return a + (d > 0 ? d : 1);
|
|
184
184
|
}, 0) > V)
|
|
185
185
|
throw Error(`knowledges and fileIds total count cannot exceed ${V}`);
|
|
186
186
|
return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
|
|
@@ -241,12 +241,12 @@ class te {
|
|
|
241
241
|
*/
|
|
242
242
|
setNetOpen(e) {
|
|
243
243
|
return c(this, null, function* () {
|
|
244
|
-
var t, s,
|
|
244
|
+
var t, s, a;
|
|
245
245
|
if (u.log("setNetOpen:", e), u.log("application arrange setting value: ", (t = this._application) == null ? void 0 : t.arrange[0].enableNetOpen), ((s = this._application) == null ? void 0 : s.type) === Q.Agent) {
|
|
246
246
|
console.warn("Agent Application Sessions are disabled to setNetOpen.");
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
|
-
if (((
|
|
249
|
+
if (((a = this._application) == null ? void 0 : a.arrange[0].enableNetOpen) === !1) {
|
|
250
250
|
console.warn("This Application is disabled to change netOpen.");
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
@@ -290,7 +290,7 @@ class te {
|
|
|
290
290
|
*/
|
|
291
291
|
fetchMessages() {
|
|
292
292
|
return c(this, arguments, function* (e = {}) {
|
|
293
|
-
var s,
|
|
293
|
+
var s, a;
|
|
294
294
|
const t = {
|
|
295
295
|
pageSize: this._loadingMessagesSize
|
|
296
296
|
};
|
|
@@ -299,7 +299,7 @@ class te {
|
|
|
299
299
|
const n = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), d = n.map((i, h) => {
|
|
300
300
|
var v, w;
|
|
301
301
|
let m = [], y;
|
|
302
|
-
return typeof ((v = i.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(i.agentHistoryList.agentList).reduce((
|
|
302
|
+
return typeof ((v = i.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(i.agentHistoryList.agentList).reduce((o, g) => (o[g.data.step - 1] || (o[g.data.step - 1] = []), o[g.data.step - 1].push(g), o), [])), h === n.length - 1 && (y = (w = this.data) == null ? void 0 : w.lastRelatedQuestion), I(f({}, i), {
|
|
303
303
|
actions: m,
|
|
304
304
|
relatedQuesion: y,
|
|
305
305
|
fromHistory: !0
|
|
@@ -319,7 +319,7 @@ class te {
|
|
|
319
319
|
this.messages.splice(i, h - i + 1, ...d);
|
|
320
320
|
}
|
|
321
321
|
const r = this.messages[this.messages.length - 1];
|
|
322
|
-
return r && !r.relatedQuesion && (r.relatedQuesion = (
|
|
322
|
+
return r && !r.relatedQuesion && (r.relatedQuesion = (a = this.data) == null ? void 0 : a.lastRelatedQuestion), this.event.emit("history:moreloaded", d), u.log("history:loaded", this.messages), this.event.emit("history:loaded", this.messages), this._loadingMessages = !1, d;
|
|
323
323
|
} else {
|
|
324
324
|
const n = new Error(
|
|
325
325
|
"session id is not defined"
|
|
@@ -401,6 +401,14 @@ class te {
|
|
|
401
401
|
inactivate(e = !1) {
|
|
402
402
|
return this.socket ? this._frozen ? (e || (this.inactivating = !0), this.activing = !1, !0) : (this.socket.close(), this.socket = null, this.event.emit("inactivated"), this.active = !1, this.activing = !1, !0) : (this.activing = !1, !0);
|
|
403
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* 会话标题摘要开关。应用详情返回布尔值时用该值,字段缺失时默认开启。
|
|
406
|
+
*/
|
|
407
|
+
resolveEnableTitleSummary() {
|
|
408
|
+
var t, s, a;
|
|
409
|
+
const e = (a = (s = (t = this.application) == null ? void 0 : t.arrange) == null ? void 0 : s[0]) == null ? void 0 : a.autoGenerateSessionTitle;
|
|
410
|
+
return typeof e == "boolean" ? e : !0;
|
|
411
|
+
}
|
|
404
412
|
//TODO: remove mcp server
|
|
405
413
|
// abstract removeMcpServers(mcpServers: MCPConfig): Promise<boolean>;
|
|
406
414
|
get dataLoaded() {
|
|
@@ -416,42 +424,42 @@ class te {
|
|
|
416
424
|
var _;
|
|
417
425
|
try {
|
|
418
426
|
this.validateConfigs();
|
|
419
|
-
} catch (
|
|
420
|
-
console.error(
|
|
427
|
+
} catch (o) {
|
|
428
|
+
console.error(o);
|
|
421
429
|
}
|
|
422
430
|
const {
|
|
423
|
-
stream:
|
|
431
|
+
stream: a = S.stream,
|
|
424
432
|
referenceFirst: n = !1
|
|
425
433
|
} = t, d = e.uuid || x(), r = ((_ = e.text) == null ? void 0 : _.trim()) || "", i = e.files || [], h = e.fileIds, m = e.imageContent;
|
|
426
434
|
if (!r && !i.length && !(h != null && h.length)) {
|
|
427
|
-
const
|
|
435
|
+
const o = new Error(
|
|
428
436
|
"failed at sending empty content"
|
|
429
437
|
/* SendingEmptyContent */
|
|
430
438
|
// {
|
|
431
439
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.SendingEmptyContent],
|
|
432
440
|
// }
|
|
433
441
|
);
|
|
434
|
-
return u.error(
|
|
442
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
435
443
|
}
|
|
436
444
|
if (!this._id) {
|
|
437
|
-
const
|
|
445
|
+
const o = new Error(
|
|
438
446
|
"session id is not defined"
|
|
439
447
|
/* IdUndefined */
|
|
440
448
|
// {
|
|
441
449
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
442
450
|
// }
|
|
443
451
|
);
|
|
444
|
-
return u.error(
|
|
452
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
445
453
|
}
|
|
446
454
|
if (this.frozen) {
|
|
447
|
-
const
|
|
455
|
+
const o = new Error(
|
|
448
456
|
"session is frozen"
|
|
449
457
|
/* Frozen */
|
|
450
458
|
// {
|
|
451
459
|
// cause: { code: -1, message: 'session is frozen.' },
|
|
452
460
|
// }
|
|
453
461
|
);
|
|
454
|
-
return u.error(
|
|
462
|
+
return u.error(o), this.event.emit("error", o), !1;
|
|
455
463
|
}
|
|
456
464
|
this.frozen = !0, this._stopAnswer = !1;
|
|
457
465
|
const y = {
|
|
@@ -466,44 +474,44 @@ class te {
|
|
|
466
474
|
imageContent: m
|
|
467
475
|
}, v = {
|
|
468
476
|
content: r,
|
|
469
|
-
stream:
|
|
477
|
+
stream: a,
|
|
470
478
|
requestId: d,
|
|
471
479
|
fileIds: h,
|
|
472
480
|
referenceFirst: n,
|
|
473
481
|
imageContent: m
|
|
474
482
|
};
|
|
475
483
|
this.pushMessage(y), this.event.emit("question:content", r);
|
|
476
|
-
const w = (
|
|
477
|
-
if (
|
|
484
|
+
const w = (o) => c(this, null, function* () {
|
|
485
|
+
if (o.role !== A.Robot)
|
|
478
486
|
return;
|
|
479
|
-
switch (this.removeEventListener("answer:finish", w), this._id &&
|
|
480
|
-
finialMessage:
|
|
487
|
+
switch (this.removeEventListener("answer:finish", w), this._id && o.content && o.index && o.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
488
|
+
finialMessage: o.content
|
|
481
489
|
}), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
|
|
482
|
-
finialMessage:
|
|
483
|
-
})), yield this.fillMessageReference(
|
|
490
|
+
finialMessage: o.content
|
|
491
|
+
})), yield this.fillMessageReference(o), o.code) {
|
|
484
492
|
case 11915:
|
|
485
|
-
|
|
493
|
+
o.content = "请您换个问题问我吧~", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
|
|
486
494
|
break;
|
|
487
495
|
case 11916:
|
|
488
|
-
|
|
496
|
+
o.content = "尊敬的用户您好,让我们换个话题再聊聊吧。", o.index = -1, o.isSensitive = !0, o.isLoading = !1, o.sessionId = this._id || "", this.event.emit("message:error", o);
|
|
489
497
|
break;
|
|
490
498
|
case 200:
|
|
491
|
-
|
|
499
|
+
o.index = -1, o.isLoading = !1;
|
|
492
500
|
break;
|
|
493
501
|
default:
|
|
494
|
-
|
|
502
|
+
o.content = o.message || "未知错误", o.isLoading = !1, o.index = -1, this.event.emit("message:error", o);
|
|
495
503
|
}
|
|
496
|
-
this.getRelatedQuesion(
|
|
504
|
+
this.getRelatedQuesion(o), o.isLoading = !1;
|
|
497
505
|
let g = this.messages[this.messages.length - 1];
|
|
498
506
|
if (g && g.role === A.Robot) {
|
|
499
|
-
const k = f(f({}, g),
|
|
507
|
+
const k = f(f({}, g), o);
|
|
500
508
|
this.messages[this.messages.length - 1] = k, this.event.emit("message:updated", k);
|
|
501
509
|
} else
|
|
502
|
-
this.pushMessage(
|
|
510
|
+
this.pushMessage(o);
|
|
503
511
|
this.frozen = !1;
|
|
504
512
|
});
|
|
505
513
|
return this.addEventListener("answer:finish", w), this.sendQuestion(v, I(f({}, t), {
|
|
506
|
-
stream:
|
|
514
|
+
stream: a,
|
|
507
515
|
referenceFirst: n
|
|
508
516
|
})), y;
|
|
509
517
|
});
|
|
@@ -525,10 +533,10 @@ class te {
|
|
|
525
533
|
if (s === null)
|
|
526
534
|
return e;
|
|
527
535
|
this.event.emit("message:relatedQuesion:loading", e);
|
|
528
|
-
const
|
|
536
|
+
const a = yield this.cvforceApi.postGeneques({
|
|
529
537
|
content: s
|
|
530
538
|
}).catch((h) => null);
|
|
531
|
-
if (!
|
|
539
|
+
if (!a) {
|
|
532
540
|
const h = [], m = I(f({}, e), {
|
|
533
541
|
relatedQuesion: h,
|
|
534
542
|
index: -3,
|
|
@@ -538,7 +546,7 @@ class te {
|
|
|
538
546
|
relatedQuesion: h
|
|
539
547
|
}), this.event.emit("message:updated", m), m;
|
|
540
548
|
}
|
|
541
|
-
const n = (i =
|
|
549
|
+
const n = (i = a.content) == null ? void 0 : i.split("*").map(F).map(N).filter((h) => !!h);
|
|
542
550
|
e.relatedQuesion = n, e.index = -3, e.isLoading = !1;
|
|
543
551
|
const d = I(f({}, e), {
|
|
544
552
|
relatedQuesion: n,
|
|
@@ -554,7 +562,7 @@ class te {
|
|
|
554
562
|
return c(this, null, function* () {
|
|
555
563
|
try {
|
|
556
564
|
const t = yield Promise.all(e.reference.map((s) => this.cvforceApi.getKnowledgeIdFileId(s.knowledgeId, s.docId)));
|
|
557
|
-
e.reference = e.reference.map((s,
|
|
565
|
+
e.reference = e.reference.map((s, a) => f(f({}, s), t[a]));
|
|
558
566
|
} catch (t) {
|
|
559
567
|
console.error("Failed to fill message reference:", t);
|
|
560
568
|
}
|
|
@@ -572,14 +580,14 @@ class te {
|
|
|
572
580
|
const {
|
|
573
581
|
stream: s = S.stream
|
|
574
582
|
} = e;
|
|
575
|
-
let
|
|
576
|
-
t.role !== A.User && (
|
|
583
|
+
let a;
|
|
584
|
+
t.role !== A.User && (a = e.oldMessageId || t.messageId, this.messages.splice(this.messages.length - 1, 1), this.event.emit("message:remove", t), this.event.emit("history:remove", t));
|
|
577
585
|
const n = this.messages[this.messages.length - 1], d = {
|
|
578
586
|
content: n.content,
|
|
579
587
|
fileIds: n.fileIds,
|
|
580
588
|
requestId: n.messageId,
|
|
581
589
|
stream: s,
|
|
582
|
-
oldMessageId:
|
|
590
|
+
oldMessageId: a
|
|
583
591
|
}, r = (i) => c(this, null, function* () {
|
|
584
592
|
if (i.role === A.Robot && i.index === -1) {
|
|
585
593
|
switch (this._id && i.content && i.index && i.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
|
|
@@ -652,9 +660,9 @@ class te {
|
|
|
652
660
|
if (e.index === -2)
|
|
653
661
|
return;
|
|
654
662
|
if (e.actions) {
|
|
655
|
-
const
|
|
656
|
-
if (
|
|
657
|
-
const n =
|
|
663
|
+
const a = e.actions[((s = e.actions) == null ? void 0 : s.length) - 1];
|
|
664
|
+
if (a) {
|
|
665
|
+
const n = a[a.length - 1];
|
|
658
666
|
if (n && (n.type === "BEFORE_CALL" || n.type === "FUNCTION_CALL")) {
|
|
659
667
|
const {
|
|
660
668
|
pluginName: d,
|
|
@@ -662,7 +670,7 @@ class te {
|
|
|
662
670
|
funcCode: i,
|
|
663
671
|
funcName: h
|
|
664
672
|
} = n.data;
|
|
665
|
-
|
|
673
|
+
a.push({
|
|
666
674
|
data: {
|
|
667
675
|
pluginName: d,
|
|
668
676
|
pluginCode: r,
|
|
@@ -673,7 +681,7 @@ class te {
|
|
|
673
681
|
type: "ABORT"
|
|
674
682
|
}), this.event.emit("message:action", {
|
|
675
683
|
messageId: e.messageId,
|
|
676
|
-
action:
|
|
684
|
+
action: a
|
|
677
685
|
});
|
|
678
686
|
}
|
|
679
687
|
}
|
|
@@ -692,7 +700,7 @@ class te {
|
|
|
692
700
|
var d;
|
|
693
701
|
if (!e.data)
|
|
694
702
|
return;
|
|
695
|
-
const s = e.data.type,
|
|
703
|
+
const s = e.data.type, a = e.data.payload;
|
|
696
704
|
t.isReplying = !0;
|
|
697
705
|
const n = () => {
|
|
698
706
|
if (!t.searchingStatus) {
|
|
@@ -704,22 +712,22 @@ class te {
|
|
|
704
712
|
return;
|
|
705
713
|
}
|
|
706
714
|
};
|
|
707
|
-
if (s === "error" && (t.index = -1), s === "beforeSearch" && n(), s === "searchOver" && n(), s === "search" && t.searchReference.push(
|
|
715
|
+
if (s === "error" && (t.index = -1), s === "beforeSearch" && n(), s === "searchOver" && n(), s === "search" && t.searchReference.push(a), s === "thinking") {
|
|
708
716
|
t.thinkingStatus = "start";
|
|
709
|
-
const i =
|
|
717
|
+
const i = a.choices[0];
|
|
710
718
|
t.reasoningContent = (t.reasoningContent || "") + ((d = i.delta.reasoningContent) != null ? d : "");
|
|
711
719
|
}
|
|
712
720
|
if (s === "thinkingOver") {
|
|
713
721
|
t.thinkingStatus = "end";
|
|
714
|
-
const r =
|
|
722
|
+
const r = a.thinkingSecs;
|
|
715
723
|
t.thinkingSecs = r;
|
|
716
724
|
}
|
|
717
725
|
if (s === "text") {
|
|
718
|
-
const i =
|
|
726
|
+
const i = a.choices[0];
|
|
719
727
|
t.content = (t.content || "") + i.delta.content;
|
|
720
728
|
}
|
|
721
|
-
if (s === "reference" && (t.reference =
|
|
722
|
-
const r =
|
|
729
|
+
if (s === "reference" && (t.reference = a), s === "updateSession" && a && this.data && (this.data = f(f({}, this.data), a), this.event.emit("data:updated", this.data)), s === "result") {
|
|
730
|
+
const r = a.messageId, i = a.llmModel, h = a.messageTime;
|
|
723
731
|
t.messageId = r, t.llmModel = i, t.messageTime = h;
|
|
724
732
|
}
|
|
725
733
|
s === "over" ? t.index = -1 : (t.code = e.code, t.message = e.message);
|
|
@@ -729,12 +737,24 @@ class te {
|
|
|
729
737
|
* @param params - 评论参数,包含评论相关的信息,如消息 ID 等
|
|
730
738
|
* @returns 返回调用 API 提交评论后的响应结果
|
|
731
739
|
*/
|
|
740
|
+
/**
|
|
741
|
+
* 获取当前会话的产出物。没有产出物时返回空数组。
|
|
742
|
+
*/
|
|
743
|
+
getArtifacts() {
|
|
744
|
+
return c(this, null, function* () {
|
|
745
|
+
var t;
|
|
746
|
+
if (!this._applicationId || !this._id)
|
|
747
|
+
throw Error("session is not avalible. id is undefined");
|
|
748
|
+
const e = yield this.cvforceApi.getSessionArtifacts(this._applicationId, this._id);
|
|
749
|
+
return (t = e == null ? void 0 : e.artifacts) != null ? t : [];
|
|
750
|
+
});
|
|
751
|
+
}
|
|
732
752
|
postMessageComment(e) {
|
|
733
753
|
return c(this, null, function* () {
|
|
734
754
|
if (!this._applicationId || !this._id)
|
|
735
755
|
throw Error("session is not avalible. id is undefined");
|
|
736
756
|
return this.cvforceApi.postComments(this._applicationId, this._id, e).then((t) => {
|
|
737
|
-
const s = this.messages.find((
|
|
757
|
+
const s = this.messages.find((a) => a.messageId === e.messageId);
|
|
738
758
|
return s && (s.comment = e, this.event.emit("message:comment", s)), t;
|
|
739
759
|
});
|
|
740
760
|
});
|