@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.4
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 +543 -98
- package/dist/es/AgentSession.mjs +230 -165
- package/dist/es/BotClient.mjs +186 -136
- package/dist/es/Config.mjs +111 -26
- package/dist/es/Session.mjs +12 -0
- package/dist/es/api/index.mjs +42 -33
- package/dist/es/index.mjs +68 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +174 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +172 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +162 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +50 -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/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +50 -0
- package/dist/es/localFiles/host/protocol.mjs +26 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +327 -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 +339 -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 +7 -4
- package/dist/lib/index.js +9 -4
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +22 -0
- package/dist/src/Session.d.ts +5 -1
- package/dist/src/api/index.d.ts +3 -1
- package/dist/src/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +17 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +18 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +26 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +39 -0
- package/dist/src/localFiles/constants.d.ts +50 -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 +33 -0
- package/dist/src/localFiles/index.d.ts +21 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +30 -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 +306 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +99 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +7 -4
package/dist/es/BotClient.mjs
CHANGED
|
@@ -1,69 +1,101 @@
|
|
|
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
|
|
1
|
+
var x = Object.defineProperty, b = Object.defineProperties;
|
|
2
|
+
var R = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var m = Object.getOwnPropertySymbols;
|
|
4
|
+
var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var v = (c, e, i) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[e] = i, f = (c, e) => {
|
|
6
|
+
for (var i in e || (e = {}))
|
|
7
|
+
E.call(e, i) && v(c, i, e[i]);
|
|
8
|
+
if (m)
|
|
9
|
+
for (var i of m(e))
|
|
10
|
+
L.call(e, i) && v(c, i, e[i]);
|
|
11
|
+
return c;
|
|
12
|
+
}, _ = (c, e) => b(c, R(e));
|
|
13
|
+
var l = (c, e, i) => (v(c, typeof e != "symbol" ? e + "" : e, i), i);
|
|
14
|
+
var d = (c, e, i) => new Promise((t, s) => {
|
|
15
|
+
var n = (a) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
o(i.next(a));
|
|
18
|
+
} catch (h) {
|
|
19
|
+
s(h);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, r = (a) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
o(i.throw(a));
|
|
24
|
+
} catch (h) {
|
|
25
|
+
s(h);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, o = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
|
|
28
|
+
o((i = i.apply(c, e)).next());
|
|
29
29
|
});
|
|
30
|
-
import { parseJWT as
|
|
31
|
-
import
|
|
32
|
-
import {
|
|
33
|
-
import { configure as
|
|
34
|
-
import {
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
import { parseJWT as y } from "./utils.mjs";
|
|
31
|
+
import W from "./Logger.mjs";
|
|
32
|
+
import { getAIShopService as M, getCVForceService as C } from "./api/index.mjs";
|
|
33
|
+
import { configure as k, configuration as p, setActiveLocalWorkspace as S, refreshBuiltinPlugins as w } from "./Config.mjs";
|
|
34
|
+
import { connectHostBridge as T } from "./localFiles/host/connectHostBridge.mjs";
|
|
35
|
+
import { LocalWorkspace as V } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
36
|
+
import { createIndexedDbStore as B } from "./localFiles/workspace/handleStore.mjs";
|
|
37
|
+
import { createDefaultSessionFileTransfer as O } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
38
|
+
import { ApplicationTypes as u, PromptVariableType as A } from "@glodon-aiot/apis";
|
|
39
|
+
import D from "./AgentSession.mjs";
|
|
40
|
+
import H from "./DialogSession.mjs";
|
|
41
|
+
import F from "./EventBus.mjs";
|
|
42
|
+
import P from "./package.json.mjs";
|
|
43
|
+
const I = new W("[BotClient] ");
|
|
44
|
+
class ie {
|
|
45
|
+
constructor(e, i, t = !0, s = {
|
|
42
46
|
analytics: {
|
|
43
47
|
enabled: !1
|
|
44
48
|
}
|
|
45
49
|
}) {
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
l(this, "event", new F());
|
|
51
|
+
l(this, "cvforceApi");
|
|
48
52
|
//从token解析出来的用户信息
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
l(this, "_applicationId");
|
|
54
|
+
l(this, "_application", null);
|
|
51
55
|
//session列表,被加载过的session将会被缓存到这个列表中
|
|
52
|
-
|
|
56
|
+
l(this, "_sessions", []);
|
|
53
57
|
//活跃的session,只支持一个活跃的session
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
l(this, "_activeSession");
|
|
59
|
+
l(this, "_ready", !1);
|
|
56
60
|
//问题长度
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
l(this, "_questionContextMaxLength", 4e3);
|
|
62
|
+
l(this, "_promptVariables", []);
|
|
63
|
+
l(this, "_localWorkspace");
|
|
64
|
+
l(this, "_disconnectHost");
|
|
65
|
+
if (this._token = e, this.lazyload = t, this.sdkConfigs = s, k(i), this._applicationId = y(e).rid || p.applicationId, !this._applicationId)
|
|
60
66
|
throw "token is not vaild";
|
|
61
|
-
this.cvforceApi = this.getService(), this.loadApplication().then((
|
|
62
|
-
|
|
63
|
-
stream:
|
|
67
|
+
this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
|
|
68
|
+
k(_(f({}, i), {
|
|
69
|
+
stream: i.stream === void 0 ? (n == null ? void 0 : n.type) === u.Dialog || (n == null ? void 0 : n.type) === u.Agent : i.stream
|
|
64
70
|
})), this.event.emit("ready");
|
|
65
71
|
});
|
|
66
72
|
}
|
|
73
|
+
setupLocalWorkspace() {
|
|
74
|
+
var s, n;
|
|
75
|
+
const e = (s = p.builtinPlugins) == null ? void 0 : s.localFiles;
|
|
76
|
+
if (!(e != null && e.enabled)) {
|
|
77
|
+
S(void 0), w();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const i = [], t = (n = e.backend) != null ? n : "file-system-access";
|
|
81
|
+
if (t !== "file-system-access" && t !== "host-bridge")
|
|
82
|
+
i.push(new Error(`[LocalFiles] 不支持的 backend:${e.backend}`));
|
|
83
|
+
else {
|
|
84
|
+
const r = M(p.apiRoot, this.token, (o, a) => I.error(a));
|
|
85
|
+
this._localWorkspace = new V({
|
|
86
|
+
applicationId: this._applicationId,
|
|
87
|
+
config: e,
|
|
88
|
+
store: B(),
|
|
89
|
+
picker: t === "host-bridge" ? null : void 0,
|
|
90
|
+
transfer: O(() => this.cvforceApi, () => r)
|
|
91
|
+
}), S(this._localWorkspace), t === "host-bridge" ? this._disconnectHost = T(this._localWorkspace) : this._localWorkspace.restore();
|
|
92
|
+
}
|
|
93
|
+
i.push(...w()), i.length && Promise.resolve().then(() => i.forEach((r) => this.event.emit("error", r)));
|
|
94
|
+
}
|
|
95
|
+
/** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
|
|
96
|
+
get localWorkspace() {
|
|
97
|
+
return this._localWorkspace;
|
|
98
|
+
}
|
|
67
99
|
checkReady() {
|
|
68
100
|
if (!this.ready)
|
|
69
101
|
throw Error("client is not ready.");
|
|
@@ -71,8 +103,8 @@ class W {
|
|
|
71
103
|
get ready() {
|
|
72
104
|
return this._ready;
|
|
73
105
|
}
|
|
74
|
-
set ready(
|
|
75
|
-
this._ready =
|
|
106
|
+
set ready(e) {
|
|
107
|
+
this._ready = e;
|
|
76
108
|
}
|
|
77
109
|
get questionContextMaxLength() {
|
|
78
110
|
return this.checkReady(), this._questionContextMaxLength;
|
|
@@ -81,49 +113,49 @@ class W {
|
|
|
81
113
|
return this.checkReady(), this._promptVariables;
|
|
82
114
|
}
|
|
83
115
|
get knowledges() {
|
|
84
|
-
var
|
|
85
|
-
return this.checkReady(), (
|
|
116
|
+
var e;
|
|
117
|
+
return this.checkReady(), (e = this._application) == null ? void 0 : e.arrange[0].knowledges;
|
|
86
118
|
}
|
|
87
119
|
get sessions() {
|
|
88
120
|
return this.checkReady(), this._sessions;
|
|
89
121
|
}
|
|
90
|
-
set sessions(
|
|
91
|
-
this.checkReady(), this._sessions =
|
|
122
|
+
set sessions(e) {
|
|
123
|
+
this.checkReady(), this._sessions = e, this.event.emit("sessions:updated", e);
|
|
92
124
|
}
|
|
93
125
|
loadApplication() {
|
|
94
|
-
return
|
|
95
|
-
var
|
|
126
|
+
return d(this, null, function* () {
|
|
127
|
+
var i, t, s, n, r;
|
|
96
128
|
this._application = yield this.cvforceApi.getApplicationId(
|
|
97
129
|
this._applicationId,
|
|
98
130
|
// 这里记录应用的名称和版本,以便后期数据分析
|
|
99
131
|
{
|
|
100
|
-
ui: (
|
|
132
|
+
ui: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
|
|
101
133
|
uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
|
|
102
|
-
sdkVersion:
|
|
134
|
+
sdkVersion: P.version
|
|
103
135
|
}
|
|
104
|
-
).then((
|
|
105
|
-
arrange: [f(
|
|
106
|
-
recommendQuestionOpen:
|
|
136
|
+
).then((o) => (typeof o.arrange[0].thinkingModeOpen != "boolean" && (o.arrange[0].thinkingModeOpen = !0), typeof o.arrange[0].thinkingTextOpen != "boolean" && (o.arrange[0].thinkingTextOpen = !0), _(f({}, o), {
|
|
137
|
+
arrange: [_(f({}, o.arrange[0]), {
|
|
138
|
+
recommendQuestionOpen: p.loadRelatedQuesions && o.arrange[0].recommendQuestionOpen
|
|
107
139
|
})]
|
|
108
140
|
})));
|
|
109
|
-
const
|
|
110
|
-
return
|
|
111
|
-
type:
|
|
141
|
+
const e = (r = (n = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
|
|
142
|
+
return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((o) => o.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
|
|
143
|
+
type: A.User
|
|
112
144
|
}), this.cvforceApi.getPrompts(this._applicationId, {
|
|
113
|
-
type:
|
|
114
|
-
})]).then(([
|
|
145
|
+
type: A.System
|
|
146
|
+
})]).then(([o, a]) => [...o, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
115
147
|
});
|
|
116
148
|
}
|
|
117
149
|
getService() {
|
|
118
|
-
return this.cvforceApi ? this.cvforceApi :
|
|
150
|
+
return this.cvforceApi ? this.cvforceApi : C(p.apiRoot, this.token, (e, i) => I.error(i));
|
|
119
151
|
}
|
|
120
152
|
get token() {
|
|
121
153
|
return this._token;
|
|
122
154
|
}
|
|
123
|
-
set token(
|
|
124
|
-
this.checkReady(), this._token =
|
|
125
|
-
const
|
|
126
|
-
this._applicationId !==
|
|
155
|
+
set token(e) {
|
|
156
|
+
this.checkReady(), this._token = e, this.ready = !1;
|
|
157
|
+
const i = y(e).rid;
|
|
158
|
+
this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
|
|
127
159
|
this.event.emit("ready");
|
|
128
160
|
}), this.clean());
|
|
129
161
|
}
|
|
@@ -134,79 +166,96 @@ class W {
|
|
|
134
166
|
return this.checkReady(), this._application;
|
|
135
167
|
}
|
|
136
168
|
get activeSession() {
|
|
137
|
-
var
|
|
138
|
-
return this.checkReady(), ((
|
|
169
|
+
var e;
|
|
170
|
+
return this.checkReady(), ((e = this._activeSession) == null ? void 0 : e.id) || "";
|
|
139
171
|
}
|
|
140
|
-
set activeSession(
|
|
141
|
-
this.checkReady(), this.loadSession(
|
|
142
|
-
this._activeSession && this._activeSession.id !==
|
|
172
|
+
set activeSession(e) {
|
|
173
|
+
this.checkReady(), this.loadSession(e).then((i) => {
|
|
174
|
+
this._activeSession && this._activeSession.id !== e && this._activeSession.inactivate(), this._activeSession = i;
|
|
143
175
|
});
|
|
144
176
|
}
|
|
145
|
-
createSession(
|
|
146
|
-
return
|
|
147
|
-
const
|
|
148
|
-
return new Promise((
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
else if (
|
|
153
|
-
|
|
177
|
+
createSession(e, i, t, s, n) {
|
|
178
|
+
return d(this, null, function* () {
|
|
179
|
+
const r = this;
|
|
180
|
+
return new Promise((o, a) => {
|
|
181
|
+
const h = (g) => d(this, null, function* () {
|
|
182
|
+
if (g === u.Agent)
|
|
183
|
+
o(new D(e, i, t, s, n, r));
|
|
184
|
+
else if (g === u.Dialog)
|
|
185
|
+
o(new H(e, i, t, s, n, r));
|
|
154
186
|
else
|
|
155
|
-
throw Error(`不支持的应用类型:${
|
|
187
|
+
throw Error(`不支持的应用类型:${g}`);
|
|
156
188
|
});
|
|
157
189
|
if (this.ready) {
|
|
158
190
|
if (!this._application)
|
|
159
191
|
throw Error("client is not ready");
|
|
160
|
-
|
|
192
|
+
h(this._application.type);
|
|
161
193
|
} else
|
|
162
194
|
this.event.on("ready", () => {
|
|
163
195
|
if (!this._application)
|
|
164
196
|
throw Error("_application is null");
|
|
165
|
-
|
|
197
|
+
h(this._application.type);
|
|
166
198
|
}, !0);
|
|
167
199
|
});
|
|
168
200
|
});
|
|
169
201
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
202
|
+
/**
|
|
203
|
+
* 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
|
|
204
|
+
*/
|
|
205
|
+
getArtifacts(e) {
|
|
206
|
+
return d(this, null, function* () {
|
|
207
|
+
var n, r;
|
|
208
|
+
this.checkReady();
|
|
209
|
+
const i = e || ((n = this._activeSession) == null ? void 0 : n.id);
|
|
210
|
+
if (!i)
|
|
211
|
+
throw new Error("session id is not defined");
|
|
212
|
+
const t = this._sessions.find((o) => o.id === i);
|
|
213
|
+
if (t)
|
|
214
|
+
return t.getArtifacts();
|
|
215
|
+
const s = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
|
|
216
|
+
return (r = s == null ? void 0 : s.artifacts) != null ? r : [];
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getSessions(e) {
|
|
220
|
+
return d(this, null, function* () {
|
|
221
|
+
return new Promise((i, t) => {
|
|
222
|
+
const s = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => d(this, null, function* () {
|
|
223
|
+
const r = [];
|
|
224
|
+
for (const o of n) {
|
|
225
|
+
const a = this._sessions.find((h) => h.id === o.id);
|
|
226
|
+
if (a)
|
|
227
|
+
a.data = o, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
|
|
179
228
|
else {
|
|
180
|
-
const
|
|
181
|
-
|
|
229
|
+
const h = yield this.createSession(this.token, o.id, o, this.lazyload, this._application || void 0);
|
|
230
|
+
r.push(h);
|
|
182
231
|
}
|
|
183
232
|
}
|
|
184
|
-
if (
|
|
185
|
-
const
|
|
186
|
-
for (const
|
|
187
|
-
|
|
188
|
-
return this.sessions = Array.from(
|
|
233
|
+
if (e != null && e.pageSize) {
|
|
234
|
+
const o = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
|
|
235
|
+
for (const h of o)
|
|
236
|
+
a.set(h.id, h);
|
|
237
|
+
return this.sessions = Array.from(a.values()), this.sessions;
|
|
189
238
|
} else
|
|
190
|
-
return this.sessions =
|
|
239
|
+
return this.sessions = r, r;
|
|
191
240
|
}));
|
|
192
241
|
if (this.ready) {
|
|
193
242
|
if (!this._application)
|
|
194
243
|
throw Error("_application is null");
|
|
195
|
-
|
|
244
|
+
i(s());
|
|
196
245
|
} else
|
|
197
246
|
this.event.on("ready", () => {
|
|
198
247
|
if (!this._application)
|
|
199
248
|
throw Error("_application is null");
|
|
200
|
-
|
|
249
|
+
i(s());
|
|
201
250
|
}, !0);
|
|
202
251
|
});
|
|
203
252
|
});
|
|
204
253
|
}
|
|
205
|
-
loadSession(
|
|
206
|
-
return
|
|
254
|
+
loadSession(e = "", i) {
|
|
255
|
+
return d(this, null, function* () {
|
|
207
256
|
this.checkReady();
|
|
208
|
-
let t = this.sessions.find((
|
|
209
|
-
if (t || (t = yield this.createSession(this.token,
|
|
257
|
+
let t = this.sessions.find((s) => s.id === e);
|
|
258
|
+
if (t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
|
|
210
259
|
if (this._activeSession === t)
|
|
211
260
|
return t;
|
|
212
261
|
this._activeSession.inactivate();
|
|
@@ -217,60 +266,61 @@ class W {
|
|
|
217
266
|
});
|
|
218
267
|
}
|
|
219
268
|
reload() {
|
|
220
|
-
return this.loadApplication().then(() =>
|
|
269
|
+
return this.loadApplication().then(() => d(this, null, function* () {
|
|
221
270
|
return yield this.getSessions(), this.event.emit("ready"), this;
|
|
222
271
|
}));
|
|
223
272
|
}
|
|
224
|
-
reloadSession(
|
|
225
|
-
return
|
|
273
|
+
reloadSession(e) {
|
|
274
|
+
return d(this, null, function* () {
|
|
226
275
|
yield this.reload();
|
|
227
|
-
let
|
|
228
|
-
if (!
|
|
276
|
+
let i = this._sessions.find((t) => t.id === e) || this._activeSession;
|
|
277
|
+
if (!i) {
|
|
229
278
|
console.warn("reloadSession session failed.");
|
|
230
279
|
return;
|
|
231
280
|
}
|
|
232
|
-
return yield
|
|
281
|
+
return yield i.reload(), i;
|
|
233
282
|
});
|
|
234
283
|
}
|
|
235
|
-
setTop(
|
|
236
|
-
return
|
|
237
|
-
let
|
|
238
|
-
if (!
|
|
284
|
+
setTop(e, i, t = "top_time desc, sort_status desc, updated_at desc") {
|
|
285
|
+
return d(this, null, function* () {
|
|
286
|
+
let s = e ? this._sessions.find((n) => n.id === e) : this._activeSession;
|
|
287
|
+
if (!s) {
|
|
239
288
|
console.warn("setTop session failed.");
|
|
240
289
|
return;
|
|
241
290
|
}
|
|
242
|
-
return yield
|
|
291
|
+
return yield s.setTop(i), this.getSessions({
|
|
243
292
|
order: t
|
|
244
293
|
});
|
|
245
294
|
});
|
|
246
295
|
}
|
|
247
|
-
addEventListener(
|
|
248
|
-
if (typeof
|
|
296
|
+
addEventListener(e, i, t = !1) {
|
|
297
|
+
if (typeof i != "function")
|
|
249
298
|
throw Error("event listener is not a function");
|
|
250
299
|
if (t) {
|
|
251
|
-
this.event.once(
|
|
300
|
+
this.event.once(e, i);
|
|
252
301
|
return;
|
|
253
302
|
}
|
|
254
|
-
this.event.on(
|
|
303
|
+
this.event.on(e, i);
|
|
255
304
|
}
|
|
256
|
-
removeEventListener(
|
|
257
|
-
this.event.off(
|
|
305
|
+
removeEventListener(e, i) {
|
|
306
|
+
this.event.off(e, i);
|
|
258
307
|
}
|
|
259
|
-
removeSession(
|
|
260
|
-
return
|
|
308
|
+
removeSession(e, i) {
|
|
309
|
+
return d(this, null, function* () {
|
|
261
310
|
this.checkReady();
|
|
262
311
|
let t = -1;
|
|
263
|
-
if (typeof
|
|
264
|
-
const
|
|
265
|
-
|
|
312
|
+
if (typeof e == "string" ? t = this._sessions.findIndex((s) => s.id === e) : t = this._sessions.findIndex((s) => s.id === e.id), t > -1) {
|
|
313
|
+
const s = this._sessions[t];
|
|
314
|
+
i && (yield s.delete()), this._sessions.splice(t, 1);
|
|
266
315
|
} else
|
|
267
316
|
console.warn("session delete failed, session is not exist.");
|
|
268
317
|
});
|
|
269
318
|
}
|
|
270
319
|
clean() {
|
|
271
|
-
|
|
320
|
+
var e;
|
|
321
|
+
(e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this.sessions = [];
|
|
272
322
|
}
|
|
273
323
|
}
|
|
274
324
|
export {
|
|
275
|
-
|
|
325
|
+
ie as default
|
|
276
326
|
};
|
package/dist/es/Config.mjs
CHANGED
|
@@ -1,40 +1,125 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
return e;
|
|
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 = {
|
|
17
20
|
debug: !1,
|
|
18
21
|
env: "prod",
|
|
19
22
|
//AIoT 环境, 与apiRoot配对使用
|
|
20
23
|
apiRoot: "https://copilot.glodon.com/api/cvforce",
|
|
21
24
|
//https://${hostname}/${PRODUCD_CODE}
|
|
22
25
|
applicationId: "",
|
|
26
|
+
/** 最终生效的插件表 = 业务插件 + 内置插件,由 configure() 计算,不要直接修改。 */
|
|
23
27
|
plugins: {},
|
|
28
|
+
/** 集成方传入的原始 plugins。 */
|
|
29
|
+
businessPlugins: {},
|
|
30
|
+
builtinPlugins: void 0,
|
|
24
31
|
mcp: void 0,
|
|
25
32
|
loadRelatedQuesions: !0,
|
|
26
33
|
stream: !1
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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());
|
|
38
|
+
}
|
|
39
|
+
function j() {
|
|
40
|
+
if (!r)
|
|
41
|
+
return;
|
|
42
|
+
const {
|
|
43
|
+
pluginCode: e,
|
|
44
|
+
table: i
|
|
45
|
+
} = r, o = n.plugins[e], l = i[e];
|
|
46
|
+
if (!(!o || o.list_directory !== l.list_directory))
|
|
47
|
+
return e;
|
|
48
|
+
}
|
|
49
|
+
function z() {
|
|
50
|
+
if (!d)
|
|
51
|
+
return;
|
|
52
|
+
const {
|
|
53
|
+
pluginCode: e,
|
|
54
|
+
table: i
|
|
55
|
+
} = d, o = n.plugins[e], l = i[e];
|
|
56
|
+
if (!(!o || o[y] !== l[y]))
|
|
57
|
+
return e;
|
|
58
|
+
}
|
|
59
|
+
function S(e, i) {
|
|
60
|
+
return (e == null ? void 0 : e.pluginCode) || A[i];
|
|
61
|
+
}
|
|
62
|
+
function D(e, i, o) {
|
|
63
|
+
return (e == null ? void 0 : e.pluginCode) || o || E[i];
|
|
64
|
+
}
|
|
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 = {
|
|
70
|
+
workspace: u,
|
|
71
|
+
pluginCode: s,
|
|
72
|
+
table: I({
|
|
73
|
+
pluginCode: s,
|
|
74
|
+
workspace: u
|
|
75
|
+
})
|
|
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;
|
|
102
|
+
}
|
|
103
|
+
function B() {
|
|
104
|
+
return H().filter((e) => !v.has(e)).map((e) => (v.add(e), console.error(e), new Error(e)));
|
|
105
|
+
}
|
|
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),
|
|
32
110
|
// 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
|
|
33
|
-
|
|
34
|
-
|
|
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);
|
|
35
114
|
}
|
|
36
115
|
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
40
125
|
};
|
package/dist/es/Session.mjs
CHANGED
|
@@ -729,6 +729,18 @@ class te {
|
|
|
729
729
|
* @param params - 评论参数,包含评论相关的信息,如消息 ID 等
|
|
730
730
|
* @returns 返回调用 API 提交评论后的响应结果
|
|
731
731
|
*/
|
|
732
|
+
/**
|
|
733
|
+
* 获取当前会话的产出物。没有产出物时返回空数组。
|
|
734
|
+
*/
|
|
735
|
+
getArtifacts() {
|
|
736
|
+
return c(this, null, function* () {
|
|
737
|
+
var t;
|
|
738
|
+
if (!this._applicationId || !this._id)
|
|
739
|
+
throw Error("session is not avalible. id is undefined");
|
|
740
|
+
const e = yield this.cvforceApi.getSessionArtifacts(this._applicationId, this._id);
|
|
741
|
+
return (t = e == null ? void 0 : e.artifacts) != null ? t : [];
|
|
742
|
+
});
|
|
743
|
+
}
|
|
732
744
|
postMessageComment(e) {
|
|
733
745
|
return c(this, null, function* () {
|
|
734
746
|
if (!this._applicationId || !this._id)
|