@glodon-aiot/bot-client-sdk 3.26.0-alpha.13 → 3.26.0-alpha.15
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 +6 -6
- package/dist/es/BotClient.mjs +153 -137
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +99 -82
- package/dist/es/builtinTools/paths.mjs +28 -22
- package/dist/es/builtinTools/platformSkills.mjs +210 -0
- package/dist/es/builtinTools/schemas.mjs +2 -2
- package/dist/es/builtinTools/tools.mjs +256 -233
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +19 -18
- package/dist/es/localFiles/host/protocol.mjs +1 -1
- package/dist/es/localFiles/host/sandboxClient.mjs +171 -100
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +46 -44
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +36 -36
- package/dist/src/builtinTools/command.d.ts +7 -0
- package/dist/src/builtinTools/paths.d.ts +1 -0
- package/dist/src/builtinTools/platformSkills.d.ts +67 -0
- package/dist/src/builtinTools/tools.d.ts +4 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +1 -1
- package/dist/src/localFiles/host/sandboxClient.d.ts +15 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +3 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ const client = new BotClient(token, {
|
|
|
156
156
|
|
|
157
157
|
`localFiles` 启用后,SDK 把内置工具注册到 `pluginCode` `builtin_tools`。`client.localWorkspace` 只在 `localFiles.enabled === true` 时存在。
|
|
158
158
|
|
|
159
|
-
`shell` / `run_file` / `run_skill_script` 按[命令和脚本](#命令和脚本)选择执行器:注入的 `commandRunner` → 已就绪的协议
|
|
159
|
+
`shell` / `run_file` / `run_skill_script` 按[命令和脚本](#命令和脚本)选择执行器:注入的 `commandRunner` → 已就绪的协议 1 沙箱 → 无宿主页面中的 just-bash / Pyodide(默认开启)→ 否则 501。宿主工作区已授权但沙箱未就绪时直接失败,不降级到浏览器运行时。
|
|
160
160
|
|
|
161
161
|
业务 `plugins` 里如果已经有 `builtin_tools` 这个 key,内置工具不会注册,`error` 事件会带上原因。同一页面只支持一个启用了内置插件的 `BotClient`(插件表是全局配置)。
|
|
162
162
|
|
|
@@ -240,7 +240,7 @@ const client = new BotClient(token, {
|
|
|
240
240
|
const workspace = client.localWorkspace;
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
`transfer` 仍可供旧的上传下载实现使用。当前注册的内置工具不走这套传输。宿主沙箱由 `workspace.sandbox.state === "ready"` 且 `protocol ===
|
|
243
|
+
`transfer` 仍可供旧的上传下载实现使用。当前注册的内置工具不走这套传输。宿主沙箱由 `workspace.sandbox.state === "ready"` 且 `protocol === 1` 表示可用,不在 `commandRuntime` 里配置;`capabilities` 只用于兼容旧的 workspace 消息。
|
|
244
244
|
|
|
245
245
|
### 十一个工具
|
|
246
246
|
|
|
@@ -460,11 +460,11 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
460
460
|
### 执行器选择顺序
|
|
461
461
|
|
|
462
462
|
1. **注入的** `LocalWorkspace.commandRunner`(测试 / 自定义,优先级最高)
|
|
463
|
-
2. **沙箱直连**:宿主工作区已授权,且 `sandbox.state` 为 `ready`、`protocol` 为 `
|
|
463
|
+
2. **沙箱直连**:宿主工作区已授权,且 `sandbox.state` 为 `ready`、`protocol` 为 `1` → 页面对 `ws://127.0.0.1` 发 WebSocket,不经宿主转发文件和命令
|
|
464
464
|
3. **浏览器运行时**:没有宿主 WebView 时,`commandRuntime.browser.enabled` 默认为 `true` → just-bash + Pyodide Worker
|
|
465
465
|
4. 以上皆不可用 → **501**
|
|
466
466
|
|
|
467
|
-
宿主工作区已经授权时,沙箱没就绪不会改走浏览器运行时。`starting` 时说明正在启动;失败说明使用 `sandbox.message`。协议不是
|
|
467
|
+
宿主工作区已经授权时,沙箱没就绪不会改走浏览器运行时。`starting` 时说明正在启动;失败说明使用 `sandbox.message`。协议不是 1 时另发一次 `error` 事件。收到 `bye`、`exited` 或 `failed` 后,在途调用以 `AbortError` 失败且不会重放;只有新的 `ready` 到达后才使用新地址和令牌连接。
|
|
468
468
|
|
|
469
469
|
参照宿主:`examples/qt-workspace-host`。
|
|
470
470
|
|
|
@@ -532,7 +532,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
532
532
|
"state": "ready",
|
|
533
533
|
"url": "ws://127.0.0.1:53124",
|
|
534
534
|
"token": "<32 字节十六进制>",
|
|
535
|
-
"protocol":
|
|
535
|
+
"protocol": 1
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
```
|
|
@@ -547,7 +547,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
547
547
|
|
|
548
548
|
脚本跑完、用户在资源管理器里改文件,都应推送。Qt 示例用目录监视做这件事,默认不监视 `.git`、`node_modules`、`__pycache__` 内部。
|
|
549
549
|
|
|
550
|
-
文件和命令不经过宿主。页面连上沙箱后发协议
|
|
550
|
+
文件和命令不经过宿主。页面连上沙箱后发协议 1 的文本帧和二进制分片:`read` 按 `offset` / `maxBytes` 取窗口,`write` 按偏移写入临时文件再改名。占用时原文件不变。命令输出流式返回,SDK 每个流只保留最后 16000 字符;若有 `logPath`,截断说明里带上 `tmp/sandbox-exec/<id>.log`。
|
|
551
551
|
|
|
552
552
|
取消命令只发 `{ "op": "cancel", "id" }`,不关闭套接字。收到 `bye`、`exited` 或 `failed` 时,在途调用失败且不重放。下一次 `ready` 使用新令牌再连。
|
|
553
553
|
|
package/dist/es/BotClient.mjs
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
var x = Object.defineProperty, b = Object.defineProperties;
|
|
2
2
|
var R = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
3
|
+
var v = Object.getOwnPropertySymbols;
|
|
4
4
|
var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
E.call(
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
L.call(
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var l = (
|
|
14
|
-
var
|
|
5
|
+
var m = (h, i, e) => i in h ? x(h, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[i] = e, _ = (h, i) => {
|
|
6
|
+
for (var e in i || (i = {}))
|
|
7
|
+
E.call(i, e) && m(h, e, i[e]);
|
|
8
|
+
if (v)
|
|
9
|
+
for (var e of v(i))
|
|
10
|
+
L.call(i, e) && m(h, e, i[e]);
|
|
11
|
+
return h;
|
|
12
|
+
}, u = (h, i) => b(h, R(i));
|
|
13
|
+
var l = (h, i, e) => (m(h, typeof i != "symbol" ? i + "" : i, e), e);
|
|
14
|
+
var p = (h, i, e) => new Promise((t, o) => {
|
|
15
15
|
var n = (a) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
s(e.next(a));
|
|
18
|
+
} catch (c) {
|
|
19
|
+
o(c);
|
|
20
20
|
}
|
|
21
21
|
}, r = (a) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
s(e.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((e = e.apply(h, i)).next());
|
|
29
29
|
});
|
|
30
30
|
import { parseJWT as y } from "./utils.mjs";
|
|
31
31
|
import W from "./Logger.mjs";
|
|
32
|
-
import { getAIShopService as M, getCVForceService as
|
|
33
|
-
import { configure as k, configuration as
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
32
|
+
import { getAIShopService as M, getCVForceService as T } from "./api/index.mjs";
|
|
33
|
+
import { configure as k, configuration as f, setActiveLocalWorkspace as S, refreshBuiltinPlugins as w } from "./Config.mjs";
|
|
34
|
+
import { PlatformSkillSync as C } from "./builtinTools/platformSkills.mjs";
|
|
35
|
+
import { HostBridgeAdapter as B } from "./localFiles/adapters/HostBridgeAdapter.mjs";
|
|
36
|
+
import { connectHostBridge as V } from "./localFiles/host/connectHostBridge.mjs";
|
|
37
|
+
import { LocalWorkspace as O } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
38
|
+
import { createIndexedDbStore as H } from "./localFiles/workspace/handleStore.mjs";
|
|
39
|
+
import { createDefaultSessionFileTransfer as P } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
40
|
+
import { ApplicationTypes as g, PromptVariableType as A } from "@glodon-aiot/apis";
|
|
39
41
|
import D from "./AgentSession.mjs";
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
42
|
+
import F from "./DialogSession.mjs";
|
|
43
|
+
import j from "./EventBus.mjs";
|
|
44
|
+
import Q from "./package.json.mjs";
|
|
43
45
|
const I = new W("[BotClient] ");
|
|
44
|
-
class
|
|
45
|
-
constructor(
|
|
46
|
+
class ni {
|
|
47
|
+
constructor(i, e, t = !0, o = {
|
|
46
48
|
analytics: {
|
|
47
49
|
enabled: !1
|
|
48
50
|
}
|
|
49
51
|
}) {
|
|
50
|
-
l(this, "event", new
|
|
52
|
+
l(this, "event", new j());
|
|
51
53
|
l(this, "cvforceApi");
|
|
52
54
|
//从token解析出来的用户信息
|
|
53
55
|
l(this, "_applicationId");
|
|
@@ -62,37 +64,50 @@ class ie {
|
|
|
62
64
|
l(this, "_promptVariables", []);
|
|
63
65
|
l(this, "_localWorkspace");
|
|
64
66
|
l(this, "_disconnectHost");
|
|
65
|
-
if (this._token =
|
|
67
|
+
if (this._token = i, this.lazyload = t, this.sdkConfigs = o, k(e, {
|
|
66
68
|
refreshBuiltinPlugins: !1
|
|
67
|
-
}), this._applicationId = y(
|
|
69
|
+
}), this._applicationId = y(i).rid || f.applicationId, !this._applicationId)
|
|
68
70
|
throw "token is not vaild";
|
|
69
71
|
this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
|
|
70
|
-
k(_(
|
|
71
|
-
stream:
|
|
72
|
+
k(u(_({}, e), {
|
|
73
|
+
stream: e.stream === void 0 ? (n == null ? void 0 : n.type) === g.Dialog || (n == null ? void 0 : n.type) === g.Agent : e.stream
|
|
72
74
|
})), this.event.emit("ready");
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
setupLocalWorkspace() {
|
|
76
|
-
var
|
|
77
|
-
const
|
|
78
|
-
if (!(
|
|
78
|
+
var o, n;
|
|
79
|
+
const i = (o = f.builtinPlugins) == null ? void 0 : o.localFiles;
|
|
80
|
+
if (!(i != null && i.enabled)) {
|
|
79
81
|
S(void 0), w();
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
|
-
const
|
|
84
|
+
const e = [], t = (n = i.backend) != null ? n : "file-system-access";
|
|
83
85
|
if (t !== "file-system-access" && t !== "host-bridge")
|
|
84
|
-
|
|
86
|
+
e.push(new Error(`[LocalFiles] 不支持的 backend:${i.backend}`));
|
|
85
87
|
else {
|
|
86
|
-
const r = M(
|
|
87
|
-
this._localWorkspace = new
|
|
88
|
+
const r = M(f.apiRoot, this.token, (s, a) => I.error(a));
|
|
89
|
+
this._localWorkspace = new O({
|
|
88
90
|
applicationId: this._applicationId,
|
|
89
|
-
config:
|
|
90
|
-
store:
|
|
91
|
+
config: i,
|
|
92
|
+
store: H(),
|
|
91
93
|
picker: t === "host-bridge" ? null : void 0,
|
|
92
|
-
transfer:
|
|
93
|
-
}), S(this._localWorkspace),
|
|
94
|
+
transfer: P(() => this.cvforceApi, () => r)
|
|
95
|
+
}), S(this._localWorkspace), this._localWorkspace.platformSkills = new C({
|
|
96
|
+
applicationId: () => this._applicationId,
|
|
97
|
+
getToken: () => this.token,
|
|
98
|
+
getSkills: () => {
|
|
99
|
+
var s, a, c, d;
|
|
100
|
+
return (d = (c = (a = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : a[0]) == null ? void 0 : c.skills) != null ? d : [];
|
|
101
|
+
},
|
|
102
|
+
apiRoot: () => f.apiRoot,
|
|
103
|
+
getSandbox: () => {
|
|
104
|
+
var a;
|
|
105
|
+
const s = (a = this._localWorkspace) == null ? void 0 : a.adapter;
|
|
106
|
+
return s instanceof B ? s.sandbox : void 0;
|
|
107
|
+
}
|
|
108
|
+
}), t === "host-bridge" ? this._disconnectHost = V(this._localWorkspace) : this._localWorkspace.restore();
|
|
94
109
|
}
|
|
95
|
-
|
|
110
|
+
e.push(...w()), e.length && Promise.resolve().then(() => e.forEach((r) => this.event.emit("error", r)));
|
|
96
111
|
}
|
|
97
112
|
/** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
|
|
98
113
|
get localWorkspace() {
|
|
@@ -105,8 +120,8 @@ class ie {
|
|
|
105
120
|
get ready() {
|
|
106
121
|
return this._ready;
|
|
107
122
|
}
|
|
108
|
-
set ready(
|
|
109
|
-
this._ready =
|
|
123
|
+
set ready(i) {
|
|
124
|
+
this._ready = i;
|
|
110
125
|
}
|
|
111
126
|
get questionContextMaxLength() {
|
|
112
127
|
return this.checkReady(), this._questionContextMaxLength;
|
|
@@ -115,49 +130,49 @@ class ie {
|
|
|
115
130
|
return this.checkReady(), this._promptVariables;
|
|
116
131
|
}
|
|
117
132
|
get knowledges() {
|
|
118
|
-
var
|
|
119
|
-
return this.checkReady(), (
|
|
133
|
+
var i;
|
|
134
|
+
return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
|
|
120
135
|
}
|
|
121
136
|
get sessions() {
|
|
122
137
|
return this.checkReady(), this._sessions;
|
|
123
138
|
}
|
|
124
|
-
set sessions(
|
|
125
|
-
this.checkReady(), this._sessions =
|
|
139
|
+
set sessions(i) {
|
|
140
|
+
this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
|
|
126
141
|
}
|
|
127
142
|
loadApplication() {
|
|
128
|
-
return
|
|
129
|
-
var
|
|
143
|
+
return p(this, null, function* () {
|
|
144
|
+
var e, t, o, n, r;
|
|
130
145
|
this._application = yield this.cvforceApi.getApplicationId(
|
|
131
146
|
this._applicationId,
|
|
132
147
|
// 这里记录应用的名称和版本,以便后期数据分析
|
|
133
148
|
{
|
|
134
|
-
ui: (
|
|
149
|
+
ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
|
|
135
150
|
uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
|
|
136
|
-
sdkVersion:
|
|
151
|
+
sdkVersion: Q.version
|
|
137
152
|
}
|
|
138
|
-
).then((
|
|
139
|
-
arrange: [_(
|
|
140
|
-
recommendQuestionOpen:
|
|
153
|
+
).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(_({}, s), {
|
|
154
|
+
arrange: [u(_({}, s.arrange[0]), {
|
|
155
|
+
recommendQuestionOpen: f.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
|
|
141
156
|
})]
|
|
142
157
|
})));
|
|
143
|
-
const
|
|
144
|
-
return
|
|
158
|
+
const i = (r = (n = (o = this._application) == null ? void 0 : o.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
|
|
159
|
+
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
|
|
145
160
|
type: A.User
|
|
146
161
|
}), this.cvforceApi.getPrompts(this._applicationId, {
|
|
147
162
|
type: A.System
|
|
148
|
-
})]).then(([
|
|
163
|
+
})]).then(([s, a]) => [...s, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
149
164
|
});
|
|
150
165
|
}
|
|
151
166
|
getService() {
|
|
152
|
-
return this.cvforceApi ? this.cvforceApi :
|
|
167
|
+
return this.cvforceApi ? this.cvforceApi : T(f.apiRoot, this.token, (i, e) => I.error(e));
|
|
153
168
|
}
|
|
154
169
|
get token() {
|
|
155
170
|
return this._token;
|
|
156
171
|
}
|
|
157
|
-
set token(
|
|
158
|
-
this.checkReady(), this._token =
|
|
159
|
-
const
|
|
160
|
-
this._applicationId !==
|
|
172
|
+
set token(i) {
|
|
173
|
+
this.checkReady(), this._token = i, this.ready = !1;
|
|
174
|
+
const e = y(i).rid;
|
|
175
|
+
this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
|
|
161
176
|
this.event.emit("ready");
|
|
162
177
|
}), this.clean());
|
|
163
178
|
}
|
|
@@ -168,35 +183,35 @@ class ie {
|
|
|
168
183
|
return this.checkReady(), this._application;
|
|
169
184
|
}
|
|
170
185
|
get activeSession() {
|
|
171
|
-
var
|
|
172
|
-
return this.checkReady(), ((
|
|
186
|
+
var i;
|
|
187
|
+
return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
|
|
173
188
|
}
|
|
174
|
-
set activeSession(
|
|
175
|
-
this.checkReady(), this.loadSession(
|
|
176
|
-
this._activeSession && this._activeSession.id !==
|
|
189
|
+
set activeSession(i) {
|
|
190
|
+
this.checkReady(), this.loadSession(i).then((e) => {
|
|
191
|
+
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
|
|
177
192
|
});
|
|
178
193
|
}
|
|
179
|
-
createSession(
|
|
180
|
-
return
|
|
194
|
+
createSession(i, e, t, o, n) {
|
|
195
|
+
return p(this, null, function* () {
|
|
181
196
|
const r = this;
|
|
182
|
-
return new Promise((
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
else if (
|
|
187
|
-
|
|
197
|
+
return new Promise((s, a) => {
|
|
198
|
+
const c = (d) => p(this, null, function* () {
|
|
199
|
+
if (d === g.Agent)
|
|
200
|
+
s(new D(i, e, t, o, n, r));
|
|
201
|
+
else if (d === g.Dialog)
|
|
202
|
+
s(new F(i, e, t, o, n, r));
|
|
188
203
|
else
|
|
189
|
-
throw Error(`不支持的应用类型:${
|
|
204
|
+
throw Error(`不支持的应用类型:${d}`);
|
|
190
205
|
});
|
|
191
206
|
if (this.ready) {
|
|
192
207
|
if (!this._application)
|
|
193
208
|
throw Error("client is not ready");
|
|
194
|
-
|
|
209
|
+
c(this._application.type);
|
|
195
210
|
} else
|
|
196
211
|
this.event.on("ready", () => {
|
|
197
212
|
if (!this._application)
|
|
198
213
|
throw Error("_application is null");
|
|
199
|
-
|
|
214
|
+
c(this._application.type);
|
|
200
215
|
}, !0);
|
|
201
216
|
});
|
|
202
217
|
});
|
|
@@ -204,38 +219,38 @@ class ie {
|
|
|
204
219
|
/**
|
|
205
220
|
* 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
|
|
206
221
|
*/
|
|
207
|
-
getArtifacts(
|
|
208
|
-
return
|
|
222
|
+
getArtifacts(i) {
|
|
223
|
+
return p(this, null, function* () {
|
|
209
224
|
var n, r;
|
|
210
225
|
this.checkReady();
|
|
211
|
-
const
|
|
212
|
-
if (!
|
|
226
|
+
const e = i || ((n = this._activeSession) == null ? void 0 : n.id);
|
|
227
|
+
if (!e)
|
|
213
228
|
throw new Error("session id is not defined");
|
|
214
|
-
const t = this._sessions.find((
|
|
229
|
+
const t = this._sessions.find((s) => s.id === e);
|
|
215
230
|
if (t)
|
|
216
231
|
return t.getArtifacts();
|
|
217
|
-
const
|
|
218
|
-
return (r =
|
|
232
|
+
const o = yield this.cvforceApi.getSessionArtifacts(this._applicationId, e);
|
|
233
|
+
return (r = o == null ? void 0 : o.artifacts) != null ? r : [];
|
|
219
234
|
});
|
|
220
235
|
}
|
|
221
|
-
getSessions(
|
|
222
|
-
return
|
|
223
|
-
return new Promise((
|
|
224
|
-
const
|
|
236
|
+
getSessions(i) {
|
|
237
|
+
return p(this, null, function* () {
|
|
238
|
+
return new Promise((e, t) => {
|
|
239
|
+
const o = () => this.cvforceApi.listSessions(this._applicationId, i).then((n) => p(this, null, function* () {
|
|
225
240
|
const r = [];
|
|
226
|
-
for (const
|
|
227
|
-
const a = this._sessions.find((
|
|
241
|
+
for (const s of n) {
|
|
242
|
+
const a = this._sessions.find((c) => c.id === s.id);
|
|
228
243
|
if (a)
|
|
229
|
-
a.data =
|
|
244
|
+
a.data = s, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
|
|
230
245
|
else {
|
|
231
|
-
const
|
|
232
|
-
r.push(
|
|
246
|
+
const c = yield this.createSession(this.token, s.id, s, this.lazyload, this._application || void 0);
|
|
247
|
+
r.push(c);
|
|
233
248
|
}
|
|
234
249
|
}
|
|
235
|
-
if (
|
|
236
|
-
const
|
|
237
|
-
for (const
|
|
238
|
-
a.set(
|
|
250
|
+
if (i != null && i.pageSize) {
|
|
251
|
+
const s = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
|
|
252
|
+
for (const c of s)
|
|
253
|
+
a.set(c.id, c);
|
|
239
254
|
return this.sessions = Array.from(a.values()), this.sessions;
|
|
240
255
|
} else
|
|
241
256
|
return this.sessions = r, r;
|
|
@@ -243,21 +258,22 @@ class ie {
|
|
|
243
258
|
if (this.ready) {
|
|
244
259
|
if (!this._application)
|
|
245
260
|
throw Error("_application is null");
|
|
246
|
-
|
|
261
|
+
e(o());
|
|
247
262
|
} else
|
|
248
263
|
this.event.on("ready", () => {
|
|
249
264
|
if (!this._application)
|
|
250
265
|
throw Error("_application is null");
|
|
251
|
-
|
|
266
|
+
e(o());
|
|
252
267
|
}, !0);
|
|
253
268
|
});
|
|
254
269
|
});
|
|
255
270
|
}
|
|
256
|
-
loadSession(
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
271
|
+
loadSession(i = "", e) {
|
|
272
|
+
return p(this, null, function* () {
|
|
273
|
+
var o, n;
|
|
274
|
+
this.checkReady(), (n = (o = this._localWorkspace) == null ? void 0 : o.platformSkills) == null || n.sync();
|
|
275
|
+
let t = this.sessions.find((r) => r.id === i);
|
|
276
|
+
if (t || (t = yield this.createSession(this.token, i, e), this._sessions.push(t)), this._activeSession) {
|
|
261
277
|
if (this._activeSession === t)
|
|
262
278
|
return t;
|
|
263
279
|
this._activeSession.inactivate();
|
|
@@ -268,61 +284,61 @@ class ie {
|
|
|
268
284
|
});
|
|
269
285
|
}
|
|
270
286
|
reload() {
|
|
271
|
-
return this.loadApplication().then(() =>
|
|
287
|
+
return this.loadApplication().then(() => p(this, null, function* () {
|
|
272
288
|
return yield this.getSessions(), this.event.emit("ready"), this;
|
|
273
289
|
}));
|
|
274
290
|
}
|
|
275
|
-
reloadSession(
|
|
276
|
-
return
|
|
291
|
+
reloadSession(i) {
|
|
292
|
+
return p(this, null, function* () {
|
|
277
293
|
yield this.reload();
|
|
278
|
-
let
|
|
279
|
-
if (!
|
|
294
|
+
let e = this._sessions.find((t) => t.id === i) || this._activeSession;
|
|
295
|
+
if (!e) {
|
|
280
296
|
console.warn("reloadSession session failed.");
|
|
281
297
|
return;
|
|
282
298
|
}
|
|
283
|
-
return yield
|
|
299
|
+
return yield e.reload(), e;
|
|
284
300
|
});
|
|
285
301
|
}
|
|
286
|
-
setTop(
|
|
287
|
-
return
|
|
288
|
-
let
|
|
289
|
-
if (!
|
|
302
|
+
setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
|
|
303
|
+
return p(this, null, function* () {
|
|
304
|
+
let o = i ? this._sessions.find((n) => n.id === i) : this._activeSession;
|
|
305
|
+
if (!o) {
|
|
290
306
|
console.warn("setTop session failed.");
|
|
291
307
|
return;
|
|
292
308
|
}
|
|
293
|
-
return yield
|
|
309
|
+
return yield o.setTop(e), this.getSessions({
|
|
294
310
|
order: t
|
|
295
311
|
});
|
|
296
312
|
});
|
|
297
313
|
}
|
|
298
|
-
addEventListener(
|
|
299
|
-
if (typeof
|
|
314
|
+
addEventListener(i, e, t = !1) {
|
|
315
|
+
if (typeof e != "function")
|
|
300
316
|
throw Error("event listener is not a function");
|
|
301
317
|
if (t) {
|
|
302
|
-
this.event.once(
|
|
318
|
+
this.event.once(i, e);
|
|
303
319
|
return;
|
|
304
320
|
}
|
|
305
|
-
this.event.on(
|
|
321
|
+
this.event.on(i, e);
|
|
306
322
|
}
|
|
307
|
-
removeEventListener(
|
|
308
|
-
this.event.off(
|
|
323
|
+
removeEventListener(i, e) {
|
|
324
|
+
this.event.off(i, e);
|
|
309
325
|
}
|
|
310
|
-
removeSession(
|
|
311
|
-
return
|
|
326
|
+
removeSession(i, e) {
|
|
327
|
+
return p(this, null, function* () {
|
|
312
328
|
this.checkReady();
|
|
313
329
|
let t = -1;
|
|
314
|
-
if (typeof
|
|
315
|
-
const
|
|
316
|
-
|
|
330
|
+
if (typeof i == "string" ? t = this._sessions.findIndex((o) => o.id === i) : t = this._sessions.findIndex((o) => o.id === i.id), t > -1) {
|
|
331
|
+
const o = this._sessions[t];
|
|
332
|
+
e && (yield o.delete()), this._sessions.splice(t, 1);
|
|
317
333
|
} else
|
|
318
334
|
console.warn("session delete failed, session is not exist.");
|
|
319
335
|
});
|
|
320
336
|
}
|
|
321
337
|
clean() {
|
|
322
|
-
var
|
|
323
|
-
(
|
|
338
|
+
var i;
|
|
339
|
+
(i = this._disconnectHost) == null || i.call(this), this._disconnectHost = void 0, this._sessions.forEach((e) => e.destroy()), this.sessions = [];
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
342
|
export {
|
|
327
|
-
|
|
343
|
+
ni as default
|
|
328
344
|
};
|