@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.8
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 +76 -105
- package/dist/es/AgentSession.mjs +32 -33
- package/dist/es/Config.mjs +85 -63
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +71 -63
- package/dist/es/index.mjs +48 -49
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +103 -193
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +77 -138
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
- package/dist/es/localFiles/constants.mjs +1 -1
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +18 -22
- package/dist/es/localFiles/host/protocol.mjs +5 -6
- package/dist/es/localFiles/schemas.mjs +60 -45
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +52 -71
- package/dist/es/package.json.mjs +29 -38
- package/dist/lib/index.js +9 -372
- package/dist/src/Config.d.ts +2 -2
- package/dist/src/Session.d.ts +4 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +1 -20
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -14
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
- package/dist/src/localFiles/constants.d.ts +1 -2
- package/dist/src/localFiles/host/protocol.d.ts +0 -13
- package/dist/src/localFiles/index.d.ts +2 -3
- package/dist/src/localFiles/schemas.d.ts +3 -2
- package/dist/src/localFiles/types.d.ts +1 -14
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +0 -12
- package/package.json +4 -13
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
- package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
- package/dist/es/builtinTools/command.mjs +0 -56
- package/dist/es/builtinTools/constants.mjs +0 -10
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -236
- package/dist/es/builtinTools/overview.mjs +0 -77
- package/dist/es/builtinTools/paths.mjs +0 -63
- package/dist/es/builtinTools/schemas.mjs +0 -216
- package/dist/es/builtinTools/tools.mjs +0 -471
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
- package/dist/src/builtinTools/command.d.ts +0 -26
- package/dist/src/builtinTools/constants.d.ts +0 -17
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
- package/dist/src/builtinTools/overview.d.ts +0 -5
- package/dist/src/builtinTools/paths.d.ts +0 -15
- package/dist/src/builtinTools/schemas.d.ts +0 -3
- package/dist/src/builtinTools/tools.d.ts +0 -60
package/dist/es/Config.mjs
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var O = Object.defineProperty, w = Object.defineProperties;
|
|
2
|
+
var k = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var h = Object.getOwnPropertySymbols;
|
|
4
|
+
var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var a = (e, i, o) => i in e ? O(e, i, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[i] = o, c = (e, i) => {
|
|
6
|
+
for (var o in i || (i = {}))
|
|
7
|
+
F.call(i, o) && a(e, o, i[o]);
|
|
8
|
+
if (h)
|
|
9
|
+
for (var o of h(i))
|
|
10
|
+
N.call(i, o) && a(e, o, i[o]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
import
|
|
14
|
-
import { LOCAL_FILES_PLUGIN_CODES as
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
}, R = (e, i) => w(e, k(i));
|
|
13
|
+
import f from "./Logger.mjs";
|
|
14
|
+
import { LOCAL_PYTHON_FUNCTION_CODE as y, LOCAL_FILES_PLUGIN_CODES as A, LOCAL_PYTHON_PLUGIN_CODES as E } from "./localFiles/constants.mjs";
|
|
15
|
+
import { createLocalFilesPlugin as I } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
16
|
+
import { createLocalPythonPlugin as $ } from "./localFiles/createLocalPythonPlugin.mjs";
|
|
17
|
+
const q = new f("[Config] ");
|
|
18
|
+
var _ = /* @__PURE__ */ ((e) => (e.dev = "https://aiot-dev.glodon.com/api/cvforcepd", e.test = "https://aiot-dev.glodon.com/api/cvforce", e.prod = "https://copilot.glodon.com/api/cvforce", e.local = "http://localhost:3000/api/cvforcepd", e))(_ || {});
|
|
19
|
+
let n = {
|
|
19
20
|
debug: !1,
|
|
20
21
|
env: "prod",
|
|
21
22
|
//AIoT 环境, 与apiRoot配对使用
|
|
@@ -30,74 +31,95 @@ let o = {
|
|
|
30
31
|
mcp: void 0,
|
|
31
32
|
loadRelatedQuesions: !0,
|
|
32
33
|
stream: !1
|
|
33
|
-
}, u,
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
u !== e && (u = e,
|
|
34
|
+
}, u, r, d;
|
|
35
|
+
const v = /* @__PURE__ */ new Set();
|
|
36
|
+
function T(e) {
|
|
37
|
+
u !== e && (u = e, r = void 0, d = void 0, v.clear());
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
-
if (!
|
|
39
|
+
function j() {
|
|
40
|
+
if (!r)
|
|
40
41
|
return;
|
|
41
42
|
const {
|
|
42
43
|
pluginCode: e,
|
|
43
|
-
table:
|
|
44
|
-
} =
|
|
45
|
-
if (!(!
|
|
44
|
+
table: i
|
|
45
|
+
} = r, o = n.plugins[e], l = i[e];
|
|
46
|
+
if (!(!o || o.list_directory !== l.list_directory))
|
|
46
47
|
return e;
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
if (!
|
|
49
|
+
function z() {
|
|
50
|
+
if (!d)
|
|
50
51
|
return;
|
|
51
52
|
const {
|
|
52
53
|
pluginCode: e,
|
|
53
|
-
table:
|
|
54
|
-
} =
|
|
55
|
-
if (!(!
|
|
54
|
+
table: i
|
|
55
|
+
} = d, o = n.plugins[e], l = i[e];
|
|
56
|
+
if (!(!o || o[y] !== l[y]))
|
|
56
57
|
return e;
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
-
return (e == null ? void 0 : e.pluginCode) ||
|
|
59
|
+
function S(e, i) {
|
|
60
|
+
return (e == null ? void 0 : e.pluginCode) || A[i];
|
|
60
61
|
}
|
|
61
|
-
function
|
|
62
|
-
return (e == null ? void 0 : e.pluginCode) ||
|
|
62
|
+
function D(e, i, o) {
|
|
63
|
+
return (e == null ? void 0 : e.pluginCode) || o || E[i];
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
-
var
|
|
66
|
-
const e = (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!u)
|
|
70
|
-
return t.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), o.plugins = d, t;
|
|
71
|
-
const f = n != null && n.enabled ? T(n, o.env) : void 0, s = f || (i != null && i.enabled ? N(i, o.env, f) : void 0);
|
|
72
|
-
return s ? e[s] ? t.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== u || l.pluginCode !== s) && (l = {
|
|
65
|
+
function H() {
|
|
66
|
+
var P, C, b;
|
|
67
|
+
const e = (P = n.businessPlugins) != null ? P : {}, i = (C = n.builtinPlugins) == null ? void 0 : C.localFiles, o = (b = n.builtinPlugins) == null ? void 0 : b.localPython, l = [], g = c({}, e);
|
|
68
|
+
let s, p = !1;
|
|
69
|
+
if (i != null && i.enabled && u && (s = S(i, n.env), s ? e[s] ? l.push(`[LocalFiles] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置文件工具未注册。`) : (((r == null ? void 0 : r.workspace) !== u || r.pluginCode !== s) && (r = {
|
|
73
70
|
workspace: u,
|
|
74
71
|
pluginCode: s,
|
|
75
72
|
table: I({
|
|
76
73
|
pluginCode: s,
|
|
77
74
|
workspace: u
|
|
78
75
|
})
|
|
79
|
-
}),
|
|
76
|
+
}), g[s] = r.table[s], p = !0) : l.push(`[LocalFiles] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置文件工具未注册。`)), o != null && o.enabled) {
|
|
77
|
+
const t = D(o, n.env, s);
|
|
78
|
+
if (!u)
|
|
79
|
+
l.push("[LocalPython] 运行脚本依赖已启用的本地工作区。内置脚本工具未注册。");
|
|
80
|
+
else if (!t)
|
|
81
|
+
l.push(`[LocalPython] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localPython.pluginCode,或与文件工具使用同一个 pluginCode。内置脚本工具未注册。`);
|
|
82
|
+
else if (e[t])
|
|
83
|
+
l.push(`[LocalPython] pluginCode「${t}」已被业务插件占用,已保留业务插件,内置脚本工具未注册。`);
|
|
84
|
+
else if (g[t] && !(p && t === s))
|
|
85
|
+
l.push(`[LocalPython] pluginCode「${t}」已被占用,已保留原插件,内置脚本工具未注册。`);
|
|
86
|
+
else {
|
|
87
|
+
((d == null ? void 0 : d.workspace) !== u || d.pluginCode !== t || d.approve !== o.onApprovalRequired) && (d = {
|
|
88
|
+
workspace: u,
|
|
89
|
+
pluginCode: t,
|
|
90
|
+
approve: o.onApprovalRequired,
|
|
91
|
+
table: $({
|
|
92
|
+
pluginCode: t,
|
|
93
|
+
workspace: u,
|
|
94
|
+
onApprovalRequired: o.onApprovalRequired
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
const L = d.table[t];
|
|
98
|
+
g[t] = p && t === s ? c(c({}, g[t]), L) : L;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return n.plugins = g, l;
|
|
80
102
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
103
|
+
function B() {
|
|
104
|
+
return H().filter((e) => !v.has(e)).map((e) => (v.add(e), console.error(e), new Error(e)));
|
|
83
105
|
}
|
|
84
|
-
function
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
apiRoot: (e == null ? void 0 : e.apiRoot) ||
|
|
106
|
+
function J(e) {
|
|
107
|
+
var i, o, l;
|
|
108
|
+
f.debug = (e == null ? void 0 : e.debug) || !1, n = R(c(c({}, n), e), {
|
|
109
|
+
apiRoot: (e == null ? void 0 : e.apiRoot) || n.apiRoot || (e != null && e.env ? _[e.env || "prod"] : n.apiRoot),
|
|
88
110
|
// 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
|
|
89
|
-
businessPlugins: (
|
|
90
|
-
builtinPlugins: (
|
|
91
|
-
}),
|
|
111
|
+
businessPlugins: (o = (i = e == null ? void 0 : e.plugins) != null ? i : n.businessPlugins) != null ? o : {},
|
|
112
|
+
builtinPlugins: (l = e == null ? void 0 : e.builtinPlugins) != null ? l : n.builtinPlugins
|
|
113
|
+
}), B(), f.debug && q.log("updated", n);
|
|
92
114
|
}
|
|
93
115
|
export {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
_ as ApiUrl,
|
|
117
|
+
n as configuration,
|
|
118
|
+
J as configure,
|
|
119
|
+
j as getRegisteredLocalFilesPluginCode,
|
|
120
|
+
z as getRegisteredLocalPythonPluginCode,
|
|
121
|
+
B as refreshBuiltinPlugins,
|
|
122
|
+
S as resolveLocalFilesPluginCode,
|
|
123
|
+
D as resolveLocalPythonPluginCode,
|
|
124
|
+
T as setActiveLocalWorkspace
|
|
103
125
|
};
|
|
@@ -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 {
|