@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.27.0-alpha.0
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 +246 -225
- package/dist/es/AgentSession.mjs +275 -197
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +58 -68
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +338 -284
- package/dist/es/api/index.mjs +31 -30
- package/dist/es/builtinTools/constants.mjs +12 -5
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
- package/dist/es/builtinTools/paths.mjs +34 -27
- package/dist/es/builtinTools/platformSkills.mjs +248 -0
- package/dist/es/builtinTools/schemas.mjs +63 -18
- package/dist/es/builtinTools/tools.mjs +368 -244
- package/dist/es/index.mjs +62 -61
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
- package/dist/es/localFiles/constants.mjs +24 -28
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/errors.mjs +44 -35
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/host/protocol.mjs +27 -14
- package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +22 -53
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +234 -0
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +207 -0
- package/dist/es/localMcp/registry.mjs +43 -0
- package/dist/es/package.json.mjs +29 -49
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/es/utils.mjs +24 -11
- package/dist/lib/index.js +48 -40
- package/dist/src/AgentSession.d.ts +13 -0
- package/dist/src/BotClient.d.ts +13 -1
- package/dist/src/Config.d.ts +14 -7
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +7 -0
- package/dist/src/Session.d.ts +19 -2
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/builtinTools/command.d.ts +7 -0
- package/dist/src/builtinTools/constants.d.ts +10 -2
- package/dist/src/builtinTools/paths.d.ts +3 -2
- package/dist/src/builtinTools/platformSkills.d.ts +92 -0
- package/dist/src/builtinTools/tools.d.ts +13 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
- package/dist/src/localFiles/constants.d.ts +4 -13
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +14 -3
- package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
- package/dist/src/localFiles/index.d.ts +9 -5
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +0 -2
- package/dist/src/localFiles/types.d.ts +2 -22
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +15 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +34 -0
- package/dist/src/localMcp/registry.d.ts +27 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +4 -24
package/dist/es/BotClient.mjs
CHANGED
|
@@ -1,96 +1,128 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var b = Object.defineProperty, x = Object.defineProperties;
|
|
2
|
+
var E = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var S = Object.getOwnPropertySymbols;
|
|
4
|
+
var L = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var m = (l, e, i) => e in l ? b(l, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[e] = i, g = (l, e) => {
|
|
6
6
|
for (var i in e || (e = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var i of
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
7
|
+
L.call(e, i) && m(l, i, e[i]);
|
|
8
|
+
if (S)
|
|
9
|
+
for (var i of S(e))
|
|
10
|
+
W.call(e, i) && m(l, i, e[i]);
|
|
11
|
+
return l;
|
|
12
|
+
}, u = (l, e) => x(l, E(e));
|
|
13
|
+
var h = (l, e, i) => (m(l, typeof e != "symbol" ? e + "" : e, i), i);
|
|
14
|
+
var p = (l, e, i) => new Promise((t, o) => {
|
|
15
15
|
var n = (a) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
s(i.next(a));
|
|
18
|
+
} catch (c) {
|
|
19
|
+
o(c);
|
|
20
20
|
}
|
|
21
21
|
}, r = (a) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
s(i.throw(a));
|
|
24
|
+
} catch (c) {
|
|
25
|
+
o(c);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, s = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
|
|
28
|
+
s((i = i.apply(l, e)).next());
|
|
29
29
|
});
|
|
30
|
-
import { parseJWT as y } from "./utils.mjs";
|
|
31
|
-
import
|
|
30
|
+
import { parseJWT as y, sameResourceTokenPayload as T } from "./utils.mjs";
|
|
31
|
+
import B from "./Logger.mjs";
|
|
32
32
|
import { getAIShopService as M, getCVForceService as C } from "./api/index.mjs";
|
|
33
|
-
import { configure as
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
import { configure as w, configuration as f, setActiveLocalWorkspace as A, refreshBuiltinPlugins as I } from "./Config.mjs";
|
|
34
|
+
import { PlatformSkillSync as V, pullArrangeSkills as O } from "./builtinTools/platformSkills.mjs";
|
|
35
|
+
import { HostBridgeAdapter as H } from "./localFiles/adapters/HostBridgeAdapter.mjs";
|
|
36
|
+
import { connectHostBridge as D } from "./localFiles/host/connectHostBridge.mjs";
|
|
37
|
+
import { connectLocalMcpBridge as F } from "./localMcp/endpoints.mjs";
|
|
38
|
+
import { LocalWorkspace as j } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
39
|
+
import { createIndexedDbStore as z } from "./localFiles/workspace/handleStore.mjs";
|
|
40
|
+
import { createDefaultSessionFileTransfer as Q } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
41
|
+
import { ApplicationTypes as k, PromptVariableType as R } from "@glodon-aiot/apis";
|
|
42
|
+
import J from "./AgentSession.mjs";
|
|
43
|
+
import P from "./DialogSession.mjs";
|
|
44
|
+
import $ from "./EventBus.mjs";
|
|
45
|
+
import U from "./package.json.mjs";
|
|
46
|
+
const d = new B("[BotClient] ");
|
|
47
|
+
class he {
|
|
48
|
+
constructor(e, i, t = !0, o = {
|
|
46
49
|
analytics: {
|
|
47
50
|
enabled: !1
|
|
48
51
|
}
|
|
49
52
|
}) {
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
h(this, "event", new $());
|
|
54
|
+
h(this, "cvforceApi");
|
|
52
55
|
//从token解析出来的用户信息
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
h(this, "_applicationId");
|
|
57
|
+
h(this, "_application", null);
|
|
55
58
|
//session列表,被加载过的session将会被缓存到这个列表中
|
|
56
|
-
|
|
59
|
+
h(this, "_sessions", []);
|
|
57
60
|
//活跃的session,只支持一个活跃的session
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
h(this, "_activeSession");
|
|
62
|
+
h(this, "_ready", !1);
|
|
60
63
|
//问题长度
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
h(this, "_questionContextMaxLength", 4e3);
|
|
65
|
+
h(this, "_promptVariables", []);
|
|
66
|
+
h(this, "_localWorkspace");
|
|
67
|
+
h(this, "_disconnectHost");
|
|
68
|
+
/** 后进入的会话作废尚未返回的编排刷新。 */
|
|
69
|
+
h(this, "arrangeSkillEpoch", 0);
|
|
70
|
+
if (this._token = e, this.lazyload = t, this.sdkConfigs = o, w(i, {
|
|
71
|
+
refreshBuiltinPlugins: !1
|
|
72
|
+
}), this._applicationId = y(e).rid || f.applicationId, !this._applicationId)
|
|
66
73
|
throw "token is not vaild";
|
|
67
|
-
this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
|
|
68
|
-
|
|
69
|
-
stream: i.stream === void 0 ? (n == null ? void 0 : n.type) ===
|
|
70
|
-
})), this.event.emit("ready");
|
|
74
|
+
this.cvforceApi = this.getService(), F(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
|
|
75
|
+
w(u(g({}, i), {
|
|
76
|
+
stream: i.stream === void 0 ? (n == null ? void 0 : n.type) === k.Dialog || (n == null ? void 0 : n.type) === k.Agent : i.stream
|
|
77
|
+
})), this.logReady(), this.event.emit("ready");
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
logReady() {
|
|
81
|
+
var e, i;
|
|
82
|
+
d.log("ready", {
|
|
83
|
+
applicationId: this._applicationId,
|
|
84
|
+
type: (e = this._application) == null ? void 0 : e.type,
|
|
85
|
+
stream: f.stream,
|
|
86
|
+
workspace: (i = this._localWorkspace) == null ? void 0 : i.status
|
|
71
87
|
});
|
|
72
88
|
}
|
|
73
89
|
setupLocalWorkspace() {
|
|
74
|
-
var
|
|
75
|
-
const e = (
|
|
90
|
+
var o, n, r;
|
|
91
|
+
const e = (o = f.builtinPlugins) == null ? void 0 : o.localFiles;
|
|
76
92
|
if (!(e != null && e.enabled)) {
|
|
77
|
-
|
|
93
|
+
d.log("workspace:disabled"), A(void 0), I();
|
|
78
94
|
return;
|
|
79
95
|
}
|
|
80
|
-
|
|
96
|
+
d.log("workspace:setup", {
|
|
97
|
+
backend: (n = e.backend) != null ? n : "file-system-access"
|
|
98
|
+
});
|
|
99
|
+
const i = [], t = (r = e.backend) != null ? r : "file-system-access";
|
|
81
100
|
if (t !== "file-system-access" && t !== "host-bridge")
|
|
82
101
|
i.push(new Error(`[LocalFiles] 不支持的 backend:${e.backend}`));
|
|
83
102
|
else {
|
|
84
|
-
const
|
|
85
|
-
this._localWorkspace = new
|
|
103
|
+
const s = M(f.apiRoot, () => this.token, (a, c) => d.error(c));
|
|
104
|
+
this._localWorkspace = new j({
|
|
86
105
|
applicationId: this._applicationId,
|
|
87
106
|
config: e,
|
|
88
|
-
store:
|
|
107
|
+
store: z(),
|
|
89
108
|
picker: t === "host-bridge" ? null : void 0,
|
|
90
|
-
transfer:
|
|
91
|
-
}),
|
|
109
|
+
transfer: Q(() => this.cvforceApi, () => s)
|
|
110
|
+
}), A(this._localWorkspace), this._localWorkspace.platformSkills = new V({
|
|
111
|
+
applicationId: () => this._applicationId,
|
|
112
|
+
getToken: () => this.token,
|
|
113
|
+
getSkills: () => {
|
|
114
|
+
var a, c, _, v;
|
|
115
|
+
return (v = (_ = (c = (a = this._application) == null ? void 0 : a.arrange) == null ? void 0 : c[0]) == null ? void 0 : _.skills) != null ? v : [];
|
|
116
|
+
},
|
|
117
|
+
apiRoot: () => f.apiRoot,
|
|
118
|
+
getSandbox: () => {
|
|
119
|
+
var c;
|
|
120
|
+
const a = (c = this._localWorkspace) == null ? void 0 : c.adapter;
|
|
121
|
+
return a instanceof H ? a.sandbox : void 0;
|
|
122
|
+
}
|
|
123
|
+
}), t === "host-bridge" ? this._disconnectHost = D(this._localWorkspace) : this._localWorkspace.restore();
|
|
92
124
|
}
|
|
93
|
-
i.push(...
|
|
125
|
+
i.push(...I()), i.length && Promise.resolve().then(() => i.forEach((s) => this.event.emit("error", s)));
|
|
94
126
|
}
|
|
95
127
|
/** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
|
|
96
128
|
get localWorkspace() {
|
|
@@ -123,40 +155,49 @@ class ie {
|
|
|
123
155
|
this.checkReady(), this._sessions = e, this.event.emit("sessions:updated", e);
|
|
124
156
|
}
|
|
125
157
|
loadApplication() {
|
|
126
|
-
return
|
|
127
|
-
var i, t,
|
|
158
|
+
return p(this, null, function* () {
|
|
159
|
+
var i, t, o, n, r;
|
|
128
160
|
this._application = yield this.cvforceApi.getApplicationId(
|
|
129
161
|
this._applicationId,
|
|
130
162
|
// 这里记录应用的名称和版本,以便后期数据分析
|
|
131
163
|
{
|
|
132
164
|
ui: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
|
|
133
165
|
uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
|
|
134
|
-
sdkVersion:
|
|
166
|
+
sdkVersion: U.version
|
|
135
167
|
}
|
|
136
|
-
).then((
|
|
137
|
-
arrange: [
|
|
138
|
-
recommendQuestionOpen:
|
|
168
|
+
).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), u(g({}, s), {
|
|
169
|
+
arrange: [u(g({}, s.arrange[0]), {
|
|
170
|
+
recommendQuestionOpen: f.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
|
|
139
171
|
})]
|
|
140
172
|
})));
|
|
141
|
-
const e = (r = (n = (
|
|
142
|
-
return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((
|
|
143
|
-
type:
|
|
173
|
+
const e = (r = (n = (o = this._application) == null ? void 0 : o.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
|
|
174
|
+
return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
|
|
175
|
+
type: R.User
|
|
144
176
|
}), this.cvforceApi.getPrompts(this._applicationId, {
|
|
145
|
-
type:
|
|
146
|
-
})]).then(([
|
|
177
|
+
type: R.System
|
|
178
|
+
})]).then(([s, a]) => [...s, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
147
179
|
});
|
|
148
180
|
}
|
|
149
181
|
getService() {
|
|
150
|
-
return this.cvforceApi ? this.cvforceApi : C(
|
|
182
|
+
return this.cvforceApi ? this.cvforceApi : C(f.apiRoot, () => this.token, (e, i) => d.error(i));
|
|
151
183
|
}
|
|
152
184
|
get token() {
|
|
153
185
|
return this._token;
|
|
154
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* 更新 resource token。
|
|
189
|
+
* rid / ten / ext / label 都相同时只换票,不卸会话;
|
|
190
|
+
* 任一不同时沿用原逻辑(ready 置 false,应用 id 变则重载并 clean)。
|
|
191
|
+
*/
|
|
155
192
|
set token(e) {
|
|
156
|
-
this.checkReady(), this._token
|
|
193
|
+
if (this.checkReady(), T(this._token, e)) {
|
|
194
|
+
this._token = e, this.notifySessionsResourceToken(e);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this._token = e, this.ready = !1;
|
|
157
198
|
const i = y(e).rid;
|
|
158
199
|
this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
|
|
159
|
-
this.event.emit("ready");
|
|
200
|
+
this.logReady(), this.event.emit("ready");
|
|
160
201
|
}), this.clean());
|
|
161
202
|
}
|
|
162
203
|
get applicationId() {
|
|
@@ -174,27 +215,27 @@ class ie {
|
|
|
174
215
|
this._activeSession && this._activeSession.id !== e && this._activeSession.inactivate(), this._activeSession = i;
|
|
175
216
|
});
|
|
176
217
|
}
|
|
177
|
-
createSession(e, i, t,
|
|
178
|
-
return
|
|
218
|
+
createSession(e, i, t, o, n) {
|
|
219
|
+
return p(this, null, function* () {
|
|
179
220
|
const r = this;
|
|
180
|
-
return new Promise((
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
else if (
|
|
185
|
-
|
|
221
|
+
return new Promise((s, a) => {
|
|
222
|
+
const c = (_) => p(this, null, function* () {
|
|
223
|
+
if (_ === k.Agent)
|
|
224
|
+
s(new J(e, i, t, o, n, r));
|
|
225
|
+
else if (_ === k.Dialog)
|
|
226
|
+
s(new P(e, i, t, o, n, r));
|
|
186
227
|
else
|
|
187
|
-
throw Error(`不支持的应用类型:${
|
|
228
|
+
throw Error(`不支持的应用类型:${_}`);
|
|
188
229
|
});
|
|
189
230
|
if (this.ready) {
|
|
190
231
|
if (!this._application)
|
|
191
232
|
throw Error("client is not ready");
|
|
192
|
-
|
|
233
|
+
c(this._application.type);
|
|
193
234
|
} else
|
|
194
235
|
this.event.on("ready", () => {
|
|
195
236
|
if (!this._application)
|
|
196
237
|
throw Error("_application is null");
|
|
197
|
-
|
|
238
|
+
c(this._application.type);
|
|
198
239
|
}, !0);
|
|
199
240
|
});
|
|
200
241
|
});
|
|
@@ -203,37 +244,40 @@ class ie {
|
|
|
203
244
|
* 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
|
|
204
245
|
*/
|
|
205
246
|
getArtifacts(e) {
|
|
206
|
-
return
|
|
247
|
+
return p(this, null, function* () {
|
|
207
248
|
var n, r;
|
|
208
249
|
this.checkReady();
|
|
209
250
|
const i = e || ((n = this._activeSession) == null ? void 0 : n.id);
|
|
210
251
|
if (!i)
|
|
211
252
|
throw new Error("session id is not defined");
|
|
212
|
-
const t = this._sessions.find((
|
|
253
|
+
const t = this._sessions.find((s) => s.id === i);
|
|
213
254
|
if (t)
|
|
214
255
|
return t.getArtifacts();
|
|
215
|
-
const
|
|
216
|
-
return (r =
|
|
256
|
+
const o = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
|
|
257
|
+
return (r = o == null ? void 0 : o.artifacts) != null ? r : [];
|
|
217
258
|
});
|
|
218
259
|
}
|
|
219
260
|
getSessions(e) {
|
|
220
|
-
return
|
|
261
|
+
return p(this, null, function* () {
|
|
221
262
|
return new Promise((i, t) => {
|
|
222
|
-
const
|
|
263
|
+
const o = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => p(this, null, function* () {
|
|
223
264
|
const r = [];
|
|
224
|
-
for (const
|
|
225
|
-
const a = this._sessions.find((
|
|
265
|
+
for (const s of n) {
|
|
266
|
+
const a = this._sessions.find((c) => c.id === s.id);
|
|
226
267
|
if (a)
|
|
227
|
-
a.data =
|
|
268
|
+
a.data = s, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
|
|
228
269
|
else {
|
|
229
|
-
const
|
|
230
|
-
r.push(
|
|
270
|
+
const c = yield this.createSession(this.token, s.id, s, this.lazyload, this._application || void 0);
|
|
271
|
+
r.push(c);
|
|
231
272
|
}
|
|
232
273
|
}
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
274
|
+
if (d.log("sessions", {
|
|
275
|
+
count: r.length,
|
|
276
|
+
paged: !!(e != null && e.pageSize)
|
|
277
|
+
}), e != null && e.pageSize) {
|
|
278
|
+
const s = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
|
|
279
|
+
for (const c of s)
|
|
280
|
+
a.set(c.id, c);
|
|
237
281
|
return this.sessions = Array.from(a.values()), this.sessions;
|
|
238
282
|
} else
|
|
239
283
|
return this.sessions = r, r;
|
|
@@ -241,21 +285,47 @@ class ie {
|
|
|
241
285
|
if (this.ready) {
|
|
242
286
|
if (!this._application)
|
|
243
287
|
throw Error("_application is null");
|
|
244
|
-
i(
|
|
288
|
+
i(o());
|
|
245
289
|
} else
|
|
246
290
|
this.event.on("ready", () => {
|
|
247
291
|
if (!this._application)
|
|
248
292
|
throw Error("_application is null");
|
|
249
|
-
i(
|
|
293
|
+
i(o());
|
|
250
294
|
}, !0);
|
|
251
295
|
});
|
|
252
296
|
});
|
|
253
297
|
}
|
|
298
|
+
/** 只更新 arrange[0].skills。查询失败时保留内存中的名单,会话仍可进入。 */
|
|
299
|
+
refreshArrangeSkills() {
|
|
300
|
+
return p(this, null, function* () {
|
|
301
|
+
var t, o, n;
|
|
302
|
+
const e = (o = (t = this._application) == null ? void 0 : t.arrange) == null ? void 0 : o[0], i = ++this.arrangeSkillEpoch;
|
|
303
|
+
try {
|
|
304
|
+
yield O({
|
|
305
|
+
// 已发布的 IArrange 类型尚未带上 skills,与 getSkills 一样在这里收窄。
|
|
306
|
+
arrange: e,
|
|
307
|
+
fetchApplication: () => this.cvforceApi.getApplicationId(this._applicationId),
|
|
308
|
+
stillCurrent: () => {
|
|
309
|
+
var s, a;
|
|
310
|
+
return i === this.arrangeSkillEpoch && ((a = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : a[0]) === e;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const r = (n = e == null ? void 0 : e.skills) != null ? n : [];
|
|
314
|
+
d.log("arrange:skills", r.map((s) => s.name).filter(Boolean));
|
|
315
|
+
} catch (r) {
|
|
316
|
+
d.error("刷新编排技能失败", r);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
254
320
|
loadSession(e = "", i) {
|
|
255
|
-
return
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
321
|
+
return p(this, null, function* () {
|
|
322
|
+
var o, n;
|
|
323
|
+
this.checkReady(), yield this.refreshArrangeSkills(), (n = (o = this._localWorkspace) == null ? void 0 : o.platformSkills) == null || n.sync();
|
|
324
|
+
let t = this.sessions.find((r) => r.id === e);
|
|
325
|
+
if (d.log("loadSession", {
|
|
326
|
+
sessionId: e || "(new)",
|
|
327
|
+
existing: !!t
|
|
328
|
+
}), t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
|
|
259
329
|
if (this._activeSession === t)
|
|
260
330
|
return t;
|
|
261
331
|
this._activeSession.inactivate();
|
|
@@ -266,29 +336,29 @@ class ie {
|
|
|
266
336
|
});
|
|
267
337
|
}
|
|
268
338
|
reload() {
|
|
269
|
-
return this.loadApplication().then(() =>
|
|
339
|
+
return this.loadApplication().then(() => p(this, null, function* () {
|
|
270
340
|
return yield this.getSessions(), this.event.emit("ready"), this;
|
|
271
341
|
}));
|
|
272
342
|
}
|
|
273
343
|
reloadSession(e) {
|
|
274
|
-
return
|
|
344
|
+
return p(this, null, function* () {
|
|
275
345
|
yield this.reload();
|
|
276
346
|
let i = this._sessions.find((t) => t.id === e) || this._activeSession;
|
|
277
347
|
if (!i) {
|
|
278
|
-
|
|
348
|
+
d.warn("reloadSession session failed.");
|
|
279
349
|
return;
|
|
280
350
|
}
|
|
281
351
|
return yield i.reload(), i;
|
|
282
352
|
});
|
|
283
353
|
}
|
|
284
354
|
setTop(e, i, t = "top_time desc, sort_status desc, updated_at desc") {
|
|
285
|
-
return
|
|
286
|
-
let
|
|
287
|
-
if (!
|
|
288
|
-
|
|
355
|
+
return p(this, null, function* () {
|
|
356
|
+
let o = e ? this._sessions.find((n) => n.id === e) : this._activeSession;
|
|
357
|
+
if (!o) {
|
|
358
|
+
d.warn("setTop session failed.");
|
|
289
359
|
return;
|
|
290
360
|
}
|
|
291
|
-
return yield
|
|
361
|
+
return yield o.setTop(i), this.getSessions({
|
|
292
362
|
order: t
|
|
293
363
|
});
|
|
294
364
|
});
|
|
@@ -306,21 +376,28 @@ class ie {
|
|
|
306
376
|
this.event.off(e, i);
|
|
307
377
|
}
|
|
308
378
|
removeSession(e, i) {
|
|
309
|
-
return
|
|
379
|
+
return p(this, null, function* () {
|
|
310
380
|
this.checkReady();
|
|
311
381
|
let t = -1;
|
|
312
|
-
if (typeof e == "string" ? t = this._sessions.findIndex((
|
|
313
|
-
const
|
|
314
|
-
i && (yield
|
|
382
|
+
if (typeof e == "string" ? t = this._sessions.findIndex((o) => o.id === e) : t = this._sessions.findIndex((o) => o.id === e.id), t > -1) {
|
|
383
|
+
const o = this._sessions[t];
|
|
384
|
+
i && (yield o.delete()), this._sessions.splice(t, 1);
|
|
315
385
|
} else
|
|
316
|
-
|
|
386
|
+
d.warn("session delete failed, session is not exist.");
|
|
317
387
|
});
|
|
318
388
|
}
|
|
319
389
|
clean() {
|
|
320
390
|
var e;
|
|
321
|
-
(e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this.
|
|
391
|
+
(e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this._sessions = [], this._activeSession = void 0, this.event.emit("sessions:updated", []);
|
|
392
|
+
}
|
|
393
|
+
/** 同 payload 换票后,让已连接的 Agent 会话向服务端发 `update`。 */
|
|
394
|
+
notifySessionsResourceToken(e) {
|
|
395
|
+
const i = new Set(this._sessions);
|
|
396
|
+
this._activeSession && i.add(this._activeSession);
|
|
397
|
+
for (const t of i)
|
|
398
|
+
t.updateSocketResourceToken(e);
|
|
322
399
|
}
|
|
323
400
|
}
|
|
324
401
|
export {
|
|
325
|
-
|
|
402
|
+
he as default
|
|
326
403
|
};
|
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 B = Object.defineProperty, R = Object.defineProperties;
|
|
2
|
+
var w = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var v = Object.getOwnPropertySymbols;
|
|
4
|
+
var k = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var b = (e, i, o) => i in e ? B(e, i, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[i] = o, c = (e, i) => {
|
|
6
|
+
for (var o in i || (i = {}))
|
|
7
|
+
k.call(i, o) && b(e, o, i[o]);
|
|
8
|
+
if (v)
|
|
9
|
+
for (var o of v(i))
|
|
10
|
+
E.call(i, o) && b(e, o, i[o]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
13
|
-
import
|
|
14
|
-
import { LOCAL_FILES_PLUGIN_CODES as
|
|
15
|
-
import { createBuiltinToolsPlugin as
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
}, P = (e, i) => R(e, w(i));
|
|
13
|
+
import h from "./Logger.mjs";
|
|
14
|
+
import { LOCAL_FILES_PLUGIN_CODES as I } from "./localFiles/constants.mjs";
|
|
15
|
+
import { createBuiltinToolsPlugin as S } from "./builtinTools/createBuiltinToolsPlugin.mjs";
|
|
16
|
+
import { applyLocalMcpPlugins as T } from "./localMcp/registry.mjs";
|
|
17
|
+
const C = new h("[Config] ");
|
|
18
|
+
var L = /* @__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))(L || {});
|
|
19
|
+
let n = {
|
|
19
20
|
debug: !1,
|
|
20
21
|
env: "prod",
|
|
21
22
|
//AIoT 环境, 与apiRoot配对使用
|
|
@@ -29,75 +30,64 @@ let o = {
|
|
|
29
30
|
builtinPlugins: void 0,
|
|
30
31
|
mcp: void 0,
|
|
31
32
|
loadRelatedQuesions: !0,
|
|
32
|
-
stream: !1
|
|
33
|
+
stream: !1,
|
|
34
|
+
appVersion: "latest"
|
|
33
35
|
}, u, l;
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
u !== e && (u = e, l = void 0,
|
|
36
|
+
const r = /* @__PURE__ */ new Set();
|
|
37
|
+
function G(e) {
|
|
38
|
+
u !== e && (u = e, l = void 0, r.clear());
|
|
37
39
|
}
|
|
38
|
-
function
|
|
40
|
+
function M() {
|
|
39
41
|
if (!l)
|
|
40
42
|
return;
|
|
41
43
|
const {
|
|
42
44
|
pluginCode: e,
|
|
43
|
-
table:
|
|
44
|
-
} = l,
|
|
45
|
-
if (!(!
|
|
45
|
+
table: i
|
|
46
|
+
} = l, o = n.plugins[e], t = i[e];
|
|
47
|
+
if (!(!o || o.shell !== t.shell))
|
|
46
48
|
return e;
|
|
47
49
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
return;
|
|
51
|
-
const {
|
|
52
|
-
pluginCode: e,
|
|
53
|
-
table: n
|
|
54
|
-
} = l, i = o.plugins[e], t = n[e];
|
|
55
|
-
if (!(!i || i.run_file !== t.run_file))
|
|
56
|
-
return e;
|
|
57
|
-
}
|
|
58
|
-
function T(e, n) {
|
|
59
|
-
return (e == null ? void 0 : e.pluginCode) || k[n];
|
|
50
|
+
function _(e, i) {
|
|
51
|
+
return (e == null ? void 0 : e.pluginCode) || I[i];
|
|
60
52
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const e = (v = o.businessPlugins) != null ? v : {}, n = (b = o.builtinPlugins) == null ? void 0 : b.localFiles, i = (p = o.builtinPlugins) == null ? void 0 : p.localPython, t = [], d = r({}, e);
|
|
67
|
-
if (!!!(n != null && n.enabled || i != null && i.enabled))
|
|
68
|
-
return o.plugins = d, t;
|
|
53
|
+
function O() {
|
|
54
|
+
var f, p;
|
|
55
|
+
const e = (f = n.businessPlugins) != null ? f : {}, i = (p = n.builtinPlugins) == null ? void 0 : p.localFiles, o = [], t = c({}, e);
|
|
56
|
+
if (!!!(i != null && i.enabled))
|
|
57
|
+
return g(t), o;
|
|
69
58
|
if (!u)
|
|
70
|
-
return
|
|
71
|
-
const
|
|
72
|
-
return s ? e[s] ?
|
|
59
|
+
return o.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), g(t), o;
|
|
60
|
+
const s = i != null && i.enabled ? _(i, n.env) : void 0;
|
|
61
|
+
return s ? e[s] ? o.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== u || l.pluginCode !== s) && (l = {
|
|
73
62
|
workspace: u,
|
|
74
63
|
pluginCode: s,
|
|
75
|
-
table:
|
|
64
|
+
table: S({
|
|
76
65
|
pluginCode: s,
|
|
77
66
|
workspace: u
|
|
78
67
|
})
|
|
79
|
-
}),
|
|
68
|
+
}), t[s] = l.table[s]) : o.push(`[BuiltinTools] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), g(t), o;
|
|
69
|
+
}
|
|
70
|
+
function g(e) {
|
|
71
|
+
T(e), n.plugins = e;
|
|
80
72
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
73
|
+
function W() {
|
|
74
|
+
return O().filter((e) => !r.has(e)).map((e) => (r.add(e), C.report(e), new Error(e)));
|
|
83
75
|
}
|
|
84
|
-
function
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
apiRoot: (e == null ? void 0 : e.apiRoot) ||
|
|
76
|
+
function N(e, i = {}) {
|
|
77
|
+
var o, t, d;
|
|
78
|
+
h.debug = (e == null ? void 0 : e.debug) || !1, n = P(c(c({}, n), e), {
|
|
79
|
+
apiRoot: (e == null ? void 0 : e.apiRoot) || n.apiRoot || (e != null && e.env ? L[e.env || "prod"] : n.apiRoot),
|
|
88
80
|
// 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
|
|
89
|
-
businessPlugins: (
|
|
90
|
-
builtinPlugins: (
|
|
91
|
-
}),
|
|
81
|
+
businessPlugins: (t = (o = e == null ? void 0 : e.plugins) != null ? o : n.businessPlugins) != null ? t : {},
|
|
82
|
+
builtinPlugins: (d = e == null ? void 0 : e.builtinPlugins) != null ? d : n.builtinPlugins
|
|
83
|
+
}), i.refreshBuiltinPlugins !== !1 && W(), C.log("updated", n);
|
|
92
84
|
}
|
|
93
85
|
export {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
N as resolveLocalPythonPluginCode,
|
|
102
|
-
Q as setActiveLocalWorkspace
|
|
86
|
+
L as ApiUrl,
|
|
87
|
+
n as configuration,
|
|
88
|
+
N as configure,
|
|
89
|
+
M as getRegisteredLocalFilesPluginCode,
|
|
90
|
+
W as refreshBuiltinPlugins,
|
|
91
|
+
_ as resolveLocalFilesPluginCode,
|
|
92
|
+
G as setActiveLocalWorkspace
|
|
103
93
|
};
|