@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.26.1
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 +271 -225
- package/dist/es/AgentSession.mjs +301 -228
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +56 -67
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/PayloadTypes.mjs +13 -2
- package/dist/es/Session.mjs +405 -312
- 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 +73 -67
- 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 +34 -54
- 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 +6 -7
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +20 -0
- package/dist/src/Session.d.ts +24 -3
- 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 +6 -3
- 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
|
@@ -1,43 +1,90 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
1
|
+
var _ = Object.defineProperty, j = Object.defineProperties;
|
|
2
|
+
var B = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var x = Object.getOwnPropertySymbols;
|
|
4
|
+
var L = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var v = (i, t, e) => t in i ? _(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, k = (i, t) => {
|
|
5
6
|
for (var e in t || (t = {}))
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
for (var e of
|
|
9
|
-
M.call(t, e) &&
|
|
7
|
+
L.call(t, e) && v(i, e, t[e]);
|
|
8
|
+
if (x)
|
|
9
|
+
for (var e of x(t))
|
|
10
|
+
M.call(t, e) && v(i, e, t[e]);
|
|
10
11
|
return i;
|
|
11
|
-
};
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var o = (
|
|
12
|
+
}, N = (i, t) => j(i, B(t));
|
|
13
|
+
var y = (i, t, e) => (v(i, typeof t != "symbol" ? t + "" : t, e), e);
|
|
14
|
+
var d = (i, t, e) => new Promise((r, s) => {
|
|
15
|
+
var o = (l) => {
|
|
15
16
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
s(
|
|
17
|
+
a(e.next(l));
|
|
18
|
+
} catch (u) {
|
|
19
|
+
s(u);
|
|
19
20
|
}
|
|
20
|
-
}, n = (
|
|
21
|
+
}, n = (l) => {
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
s(
|
|
23
|
+
a(e.throw(l));
|
|
24
|
+
} catch (u) {
|
|
25
|
+
s(u);
|
|
25
26
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
27
|
+
}, a = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(o, n);
|
|
28
|
+
a((e = e.apply(i, t)).next());
|
|
28
29
|
});
|
|
29
30
|
import { MAX_COMMAND_OUTPUT_CHARS as w } from "../../builtinTools/command.mjs";
|
|
30
|
-
import { domError as
|
|
31
|
-
import { SANDBOX_PROTOCOL as
|
|
32
|
-
import { decodeBinaryFrame as
|
|
33
|
-
const
|
|
31
|
+
import { domError as f } from "../adapters/WorkspaceFileAdapter.mjs";
|
|
32
|
+
import { SANDBOX_PROTOCOL as A, SANDBOX_MAX_FILE_BYTES as U } from "./protocol.mjs";
|
|
33
|
+
import { decodeBinaryFrame as S, MAX_BINARY_PAYLOAD as T, encodeBinaryFrame as F } from "./sandboxFrames.mjs";
|
|
34
|
+
const C = {
|
|
35
|
+
revision: 0,
|
|
36
|
+
network: {
|
|
37
|
+
mode: "off",
|
|
38
|
+
allow: []
|
|
39
|
+
},
|
|
40
|
+
packages: {
|
|
41
|
+
python: {
|
|
42
|
+
enabled: !0
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function O(i) {
|
|
47
|
+
var r, s, o, n, a, l, u;
|
|
48
|
+
if (!i || typeof i != "object")
|
|
49
|
+
return;
|
|
50
|
+
const t = i, e = (r = t.network) == null ? void 0 : r.mode;
|
|
51
|
+
if (!(e !== "off" && e !== "allowlist" && e !== "open"))
|
|
52
|
+
return k({
|
|
53
|
+
revision: typeof t.revision == "number" ? t.revision : 0,
|
|
54
|
+
network: {
|
|
55
|
+
mode: e,
|
|
56
|
+
allow: Array.isArray((s = t.network) == null ? void 0 : s.allow) ? t.network.allow.filter((c) => typeof c == "string") : []
|
|
57
|
+
},
|
|
58
|
+
packages: {
|
|
59
|
+
python: {
|
|
60
|
+
enabled: ((n = (o = t.packages) == null ? void 0 : o.python) == null ? void 0 : n.enabled) !== !1
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, Number.isInteger((a = t.exec) == null ? void 0 : a.maxConcurrent) && ((l = t.exec) == null ? void 0 : l.maxConcurrent) >= 1 ? {
|
|
64
|
+
exec: {
|
|
65
|
+
maxConcurrent: (u = t.exec) == null ? void 0 : u.maxConcurrent
|
|
66
|
+
}
|
|
67
|
+
} : {});
|
|
68
|
+
}
|
|
69
|
+
function $(i) {
|
|
70
|
+
const t = i == null ? void 0 : i.denied;
|
|
71
|
+
return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
|
|
72
|
+
}
|
|
73
|
+
function D(i, t) {
|
|
74
|
+
if (!t.length)
|
|
75
|
+
return i;
|
|
76
|
+
const e = `宿主网络策略拒绝了:${t.join("、")}。不要重试这些地址;需要时请用户在宿主设置里允许。`;
|
|
77
|
+
return i ? `${i}
|
|
78
|
+
${e}` : e;
|
|
79
|
+
}
|
|
80
|
+
const m = "沙箱已退出。";
|
|
34
81
|
function E(i) {
|
|
35
82
|
if (i instanceof Uint8Array)
|
|
36
83
|
return i;
|
|
37
84
|
if (i instanceof ArrayBuffer)
|
|
38
85
|
return new Uint8Array(i);
|
|
39
86
|
}
|
|
40
|
-
function
|
|
87
|
+
function P(i, t, e, r) {
|
|
41
88
|
const s = i.length > w ? i.slice(i.length - w) : i;
|
|
42
89
|
if (!t && !e && !r && i.length <= w)
|
|
43
90
|
return s;
|
|
@@ -45,43 +92,70 @@ function x(i, t, e, r) {
|
|
|
45
92
|
…输出已截断`;
|
|
46
93
|
return e && (o += `,完整输出见 ${e}`), r && (o += ",日志已截断"), s + o;
|
|
47
94
|
}
|
|
48
|
-
class
|
|
95
|
+
class J {
|
|
49
96
|
constructor(t = (e) => new WebSocket(e)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
97
|
+
y(this, "notice");
|
|
98
|
+
/** 沙箱最近一次告知的网络策略。 */
|
|
99
|
+
y(this, "policy", C);
|
|
100
|
+
y(this, "socket");
|
|
101
|
+
y(this, "generation", 0);
|
|
102
|
+
y(this, "authed", !1);
|
|
103
|
+
y(this, "seq", 0);
|
|
104
|
+
y(this, "calls", /* @__PURE__ */ new Map());
|
|
105
|
+
y(this, "outgoing", []);
|
|
57
106
|
this.openSocket = t;
|
|
58
107
|
}
|
|
59
108
|
get ready() {
|
|
60
109
|
const t = this.notice;
|
|
61
|
-
return (t == null ? void 0 : t.state) === "ready" && t.protocol ===
|
|
110
|
+
return (t == null ? void 0 : t.state) === "ready" && t.protocol === A && !!(t.url && t.token);
|
|
62
111
|
}
|
|
63
112
|
unavailableMessage() {
|
|
64
113
|
var t, e, r, s;
|
|
65
|
-
return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((r = this.notice) == null ? void 0 : r.state) === "exited" || ((s = this.notice) == null ? void 0 : s.state) === "failed" ?
|
|
114
|
+
return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((r = this.notice) == null ? void 0 : r.state) === "exited" || ((s = this.notice) == null ? void 0 : s.state) === "failed" ? m : "沙箱没有就绪。";
|
|
66
115
|
}
|
|
67
116
|
apply(t) {
|
|
68
117
|
const e = this.notice;
|
|
69
118
|
if (this.notice = t, !this.ready || !(t != null && t.url) || !t.token) {
|
|
70
|
-
this.failAll(
|
|
119
|
+
this.failAll(f("NotAllowedError", this.unavailableMessage())), this.stop();
|
|
71
120
|
return;
|
|
72
121
|
}
|
|
73
|
-
(e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(
|
|
122
|
+
(e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(f("AbortError", m)), this.stop(), this.connect(t.url, t.token));
|
|
123
|
+
}
|
|
124
|
+
/** `ws://127.0.0.1:port` 的主机和端口,文件地址拼在它前面。 */
|
|
125
|
+
httpOrigin() {
|
|
126
|
+
var e;
|
|
127
|
+
const t = (e = this.notice) == null ? void 0 : e.url;
|
|
128
|
+
return t != null && t.startsWith("ws://") ? t.slice(5).replace(/\/$/, "") : "";
|
|
74
129
|
}
|
|
75
130
|
stat(t) {
|
|
76
|
-
return
|
|
131
|
+
return d(this, null, function* () {
|
|
77
132
|
return this.invoke({
|
|
78
133
|
op: "stat",
|
|
79
134
|
path: t
|
|
80
135
|
});
|
|
81
136
|
});
|
|
82
137
|
}
|
|
138
|
+
url(t) {
|
|
139
|
+
return d(this, null, function* () {
|
|
140
|
+
const r = (yield this.invoke({
|
|
141
|
+
op: "url",
|
|
142
|
+
path: t
|
|
143
|
+
})).ticket;
|
|
144
|
+
if (typeof r != "string" || !/^[a-f0-9]{32}$/.test(r))
|
|
145
|
+
throw f("NotAllowedError", "地址无效。");
|
|
146
|
+
return r;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
releaseUrl(t) {
|
|
150
|
+
return d(this, null, function* () {
|
|
151
|
+
yield this.invoke({
|
|
152
|
+
op: "releaseUrl",
|
|
153
|
+
ticket: t
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
83
157
|
list(t, e) {
|
|
84
|
-
return
|
|
158
|
+
return d(this, null, function* () {
|
|
85
159
|
return this.invoke({
|
|
86
160
|
op: "list",
|
|
87
161
|
path: t
|
|
@@ -89,58 +163,125 @@ class D {
|
|
|
89
163
|
});
|
|
90
164
|
}
|
|
91
165
|
read(o) {
|
|
92
|
-
return
|
|
166
|
+
return d(this, arguments, function* (t, e = 0, r = U, s) {
|
|
93
167
|
const n = this.begin({
|
|
94
168
|
op: "read",
|
|
95
169
|
path: t,
|
|
96
170
|
offset: e,
|
|
97
171
|
maxBytes: r
|
|
98
|
-
}, s),
|
|
99
|
-
let
|
|
100
|
-
for (; !
|
|
101
|
-
const
|
|
172
|
+
}, s), a = [];
|
|
173
|
+
let l;
|
|
174
|
+
for (; !l; ) {
|
|
175
|
+
const h = yield this.next(n), p = E(h);
|
|
102
176
|
if (p) {
|
|
103
|
-
|
|
177
|
+
a.push(S(p).payload);
|
|
104
178
|
continue;
|
|
105
179
|
}
|
|
106
|
-
|
|
180
|
+
l = h;
|
|
107
181
|
}
|
|
108
|
-
if (this.calls.delete(n),
|
|
109
|
-
throw
|
|
110
|
-
const
|
|
111
|
-
let
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
}),
|
|
182
|
+
if (this.calls.delete(n), l.ok === !1)
|
|
183
|
+
throw f(String(l.name || "NotAllowedError"), String(l.message || "读取失败。"));
|
|
184
|
+
const u = a.reduce((h, p) => h + p.length, 0), c = new Uint8Array(u);
|
|
185
|
+
let g = 0;
|
|
186
|
+
return a.forEach((h) => {
|
|
187
|
+
c.set(h, g), g += h.length;
|
|
188
|
+
}), c;
|
|
115
189
|
});
|
|
116
190
|
}
|
|
117
191
|
write(t, e, r, s) {
|
|
118
|
-
return
|
|
192
|
+
return d(this, null, function* () {
|
|
119
193
|
const o = this.begin({
|
|
120
194
|
op: "write",
|
|
121
195
|
path: t,
|
|
122
196
|
size: e.length,
|
|
123
197
|
createDirectories: r
|
|
124
198
|
}, s);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
199
|
+
yield this.upload(o, e, "写入失败。");
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
skillStatus(t, e) {
|
|
203
|
+
return d(this, null, function* () {
|
|
204
|
+
const r = yield this.invoke({
|
|
205
|
+
op: "skillStatus",
|
|
206
|
+
applicationId: t
|
|
207
|
+
}, e);
|
|
208
|
+
return Array.isArray(r.skills) ? r.skills : [];
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
skillRead(t, e, r, s, o) {
|
|
212
|
+
return d(this, null, function* () {
|
|
213
|
+
const n = this.begin({
|
|
214
|
+
op: "skillRead",
|
|
215
|
+
applicationId: t,
|
|
216
|
+
skillId: e,
|
|
217
|
+
version: r,
|
|
218
|
+
path: s
|
|
219
|
+
}, o), a = [];
|
|
220
|
+
let l;
|
|
221
|
+
for (; !l; ) {
|
|
222
|
+
const h = yield this.next(n), p = E(h);
|
|
223
|
+
if (p) {
|
|
224
|
+
a.push(S(p).payload);
|
|
225
|
+
continue;
|
|
135
226
|
}
|
|
227
|
+
l = h;
|
|
136
228
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
229
|
+
if (this.calls.delete(n), l.ok === !1)
|
|
230
|
+
throw f(String(l.name || "NotAllowedError"), String(l.message || "读取失败。"));
|
|
231
|
+
const u = a.reduce((h, p) => h + p.length, 0), c = new Uint8Array(u);
|
|
232
|
+
let g = 0;
|
|
233
|
+
return a.forEach((h) => {
|
|
234
|
+
c.set(h, g), g += h.length;
|
|
235
|
+
}), c;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
skillList(t, e, r, s, o) {
|
|
239
|
+
return d(this, null, function* () {
|
|
240
|
+
const n = yield this.invoke({
|
|
241
|
+
op: "skillList",
|
|
242
|
+
applicationId: t,
|
|
243
|
+
skillId: e,
|
|
244
|
+
version: r,
|
|
245
|
+
path: s
|
|
246
|
+
}, o);
|
|
247
|
+
return typeof n.files == "string" ? n.files : "";
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
skillGrep(t, e, r, s, o, n) {
|
|
251
|
+
return d(this, null, function* () {
|
|
252
|
+
const a = yield this.invoke({
|
|
253
|
+
op: "skillGrep",
|
|
254
|
+
applicationId: t,
|
|
255
|
+
skillId: e,
|
|
256
|
+
version: r,
|
|
257
|
+
path: s,
|
|
258
|
+
pattern: o
|
|
259
|
+
}, n);
|
|
260
|
+
return typeof a.matches == "string" ? a.matches : "";
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
installSkill(t, e, r) {
|
|
264
|
+
return d(this, null, function* () {
|
|
265
|
+
const s = this.begin(N(k({
|
|
266
|
+
op: "installSkill"
|
|
267
|
+
}, t), {
|
|
268
|
+
size: e.length
|
|
269
|
+
}), r);
|
|
270
|
+
yield this.upload(s, e, "安装失败。");
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
skillPrune(t, e, r, s) {
|
|
274
|
+
return d(this, null, function* () {
|
|
275
|
+
yield this.invoke({
|
|
276
|
+
op: "skillPrune",
|
|
277
|
+
applicationId: t,
|
|
278
|
+
keep: e,
|
|
279
|
+
busy: r
|
|
280
|
+
}, s);
|
|
140
281
|
});
|
|
141
282
|
}
|
|
142
283
|
mkdir(t) {
|
|
143
|
-
return
|
|
284
|
+
return d(this, null, function* () {
|
|
144
285
|
yield this.invoke({
|
|
145
286
|
op: "mkdir",
|
|
146
287
|
path: t
|
|
@@ -148,7 +289,7 @@ class D {
|
|
|
148
289
|
});
|
|
149
290
|
}
|
|
150
291
|
remove(t, e) {
|
|
151
|
-
return
|
|
292
|
+
return d(this, null, function* () {
|
|
152
293
|
yield this.invoke({
|
|
153
294
|
op: "remove",
|
|
154
295
|
path: t,
|
|
@@ -157,7 +298,7 @@ class D {
|
|
|
157
298
|
});
|
|
158
299
|
}
|
|
159
300
|
move(t, e) {
|
|
160
|
-
return
|
|
301
|
+
return d(this, null, function* () {
|
|
161
302
|
yield this.invoke({
|
|
162
303
|
op: "move",
|
|
163
304
|
from: t,
|
|
@@ -166,35 +307,31 @@ class D {
|
|
|
166
307
|
});
|
|
167
308
|
}
|
|
168
309
|
exec(t, e, r) {
|
|
169
|
-
return
|
|
170
|
-
var
|
|
171
|
-
const s = this.begin(
|
|
172
|
-
|
|
173
|
-
protocol: k,
|
|
174
|
-
id: s,
|
|
175
|
-
op: "cancel"
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
let o = "", n = "", c = !1, a = !1;
|
|
310
|
+
return d(this, null, function* () {
|
|
311
|
+
var u;
|
|
312
|
+
const s = this.begin(k({}, t), e);
|
|
313
|
+
let o = "", n = "", a = !1, l = !1;
|
|
179
314
|
for (; this.calls.has(s); ) {
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
r == null || r(
|
|
315
|
+
const c = yield this.next(s);
|
|
316
|
+
if (c.op === "stdout" || c.op === "stderr") {
|
|
317
|
+
const b = String((u = c.text) != null ? u : "");
|
|
318
|
+
r == null || r(c.op, b), c.op === "stdout" ? (o += b, o.length > w && (a = !0), o = o.slice(-w)) : (n += b, n.length > w && (l = !0), n = n.slice(-w));
|
|
184
319
|
continue;
|
|
185
320
|
}
|
|
186
|
-
if (this.calls.delete(s),
|
|
187
|
-
throw
|
|
188
|
-
const
|
|
189
|
-
return {
|
|
190
|
-
exitCode: typeof
|
|
191
|
-
timedOut:
|
|
192
|
-
stdout:
|
|
193
|
-
stderr:
|
|
194
|
-
cwd: typeof
|
|
195
|
-
}
|
|
321
|
+
if (this.calls.delete(s), c.ok === !1)
|
|
322
|
+
throw f(String(c.name || "NotAllowedError"), String(c.message || "命令失败。"));
|
|
323
|
+
const g = typeof c.logPath == "string" ? c.logPath : void 0, h = c.logTruncated === !0, p = $(c.network);
|
|
324
|
+
return k({
|
|
325
|
+
exitCode: typeof c.exitCode == "number" ? c.exitCode : 1,
|
|
326
|
+
timedOut: c.timedOut === !0,
|
|
327
|
+
stdout: P(o, a, g, h),
|
|
328
|
+
stderr: D(P(n, l, g, h), p),
|
|
329
|
+
cwd: typeof c.cwd == "string" ? c.cwd : void 0
|
|
330
|
+
}, p.length ? {
|
|
331
|
+
denied: p
|
|
332
|
+
} : {});
|
|
196
333
|
}
|
|
197
|
-
throw
|
|
334
|
+
throw f("AbortError", m);
|
|
198
335
|
});
|
|
199
336
|
}
|
|
200
337
|
invoke(t, e) {
|
|
@@ -203,42 +340,69 @@ class D {
|
|
|
203
340
|
this.calls.delete(r);
|
|
204
341
|
const o = s;
|
|
205
342
|
if (o.ok === !1)
|
|
206
|
-
throw
|
|
343
|
+
throw f(String(o.name || "NotAllowedError"), String(o.message || "请求失败。"));
|
|
207
344
|
return o;
|
|
208
345
|
});
|
|
209
346
|
}
|
|
210
|
-
|
|
347
|
+
/**
|
|
348
|
+
* 沙箱轮到这次上传时先回 offset 为 0 的 ack,之后每个 ack 再发下一片。
|
|
349
|
+
* 排队期间不发数据,沙箱不用替排队的请求存分片。
|
|
350
|
+
*/
|
|
351
|
+
upload(t, e, r) {
|
|
352
|
+
return d(this, null, function* () {
|
|
353
|
+
let s = 0;
|
|
354
|
+
for (; ; ) {
|
|
355
|
+
const o = yield this.next(t);
|
|
356
|
+
if (o.ok === !1)
|
|
357
|
+
throw this.calls.delete(t), f(String(o.name || "NotAllowedError"), String(o.message || r));
|
|
358
|
+
if (o.ok === !0) {
|
|
359
|
+
this.calls.delete(t);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (o.op !== "ack" || s >= e.length)
|
|
363
|
+
continue;
|
|
364
|
+
const n = e.subarray(s, s + T), a = s + n.length;
|
|
365
|
+
this.send(F(t, s, a === e.length, n)), s = a;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/** 取消时通知沙箱:命令会被结束,还在排队的文件请求会被移出队列。 */
|
|
370
|
+
begin(t, e) {
|
|
211
371
|
if (!this.ready)
|
|
212
|
-
throw
|
|
372
|
+
throw f("NotAllowedError", this.unavailableMessage());
|
|
213
373
|
if (e != null && e.aborted)
|
|
214
|
-
throw
|
|
215
|
-
const
|
|
216
|
-
let
|
|
374
|
+
throw f("AbortError");
|
|
375
|
+
const r = `sbx-${++this.seq}`;
|
|
376
|
+
let s = () => {
|
|
217
377
|
};
|
|
218
|
-
const
|
|
378
|
+
const o = {
|
|
219
379
|
messages: [],
|
|
220
380
|
waiters: [],
|
|
221
|
-
reject: (a) =>
|
|
381
|
+
reject: (a) => s(a)
|
|
222
382
|
};
|
|
223
|
-
this.calls.set(
|
|
224
|
-
const
|
|
225
|
-
|
|
383
|
+
this.calls.set(r, o);
|
|
384
|
+
const n = () => {
|
|
385
|
+
this.send({
|
|
386
|
+
protocol: A,
|
|
387
|
+
id: r,
|
|
388
|
+
op: "cancel"
|
|
389
|
+
}), o.reject(f("AbortError"));
|
|
226
390
|
};
|
|
227
|
-
return e == null || e.addEventListener("abort",
|
|
391
|
+
return e == null || e.addEventListener("abort", n, {
|
|
228
392
|
once: !0
|
|
229
|
-
}),
|
|
230
|
-
e == null || e.removeEventListener("abort",
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
}, this.send(
|
|
234
|
-
protocol:
|
|
235
|
-
id:
|
|
236
|
-
}, t)),
|
|
393
|
+
}), s = (a) => {
|
|
394
|
+
e == null || e.removeEventListener("abort", n), this.calls.delete(r);
|
|
395
|
+
const l = o.waiters.shift();
|
|
396
|
+
l && l(Promise.reject(a));
|
|
397
|
+
}, this.send(k({
|
|
398
|
+
protocol: A,
|
|
399
|
+
id: r
|
|
400
|
+
}, t)), r;
|
|
237
401
|
}
|
|
238
402
|
next(t) {
|
|
239
403
|
const e = this.calls.get(t);
|
|
240
404
|
if (!e)
|
|
241
|
-
return Promise.reject(
|
|
405
|
+
return Promise.reject(f("AbortError", m));
|
|
242
406
|
const r = e.messages.shift();
|
|
243
407
|
return r !== void 0 ? Promise.resolve(r) : new Promise((s, o) => {
|
|
244
408
|
e.waiters.push(s), e.reject = (n) => {
|
|
@@ -259,40 +423,45 @@ class D {
|
|
|
259
423
|
const r = ++this.generation, s = this.openSocket(t);
|
|
260
424
|
this.socket = s, this.authed = !1, s.binaryType = "arraybuffer", s.onopen = () => {
|
|
261
425
|
r === this.generation && s.send(JSON.stringify({
|
|
262
|
-
protocol:
|
|
426
|
+
protocol: A,
|
|
263
427
|
op: "auth",
|
|
264
428
|
token: e
|
|
265
429
|
}));
|
|
266
430
|
}, s.onmessage = (o) => {
|
|
267
431
|
r === this.generation && this.onFrame(o.data);
|
|
268
432
|
}, s.onclose = () => {
|
|
269
|
-
r === this.generation && (this.authed = !1, this.failAll(
|
|
433
|
+
r === this.generation && (this.authed = !1, this.failAll(f("AbortError", m)));
|
|
270
434
|
}, s.onerror = () => {
|
|
271
435
|
};
|
|
272
436
|
}
|
|
273
437
|
onFrame(t) {
|
|
438
|
+
var s, o;
|
|
274
439
|
const e = E(t);
|
|
275
440
|
if (e) {
|
|
276
|
-
const
|
|
277
|
-
this.push(
|
|
441
|
+
const n = S(e);
|
|
442
|
+
this.push(n.id, e);
|
|
278
443
|
return;
|
|
279
444
|
}
|
|
280
445
|
let r;
|
|
281
446
|
try {
|
|
282
447
|
r = JSON.parse(String(t));
|
|
283
|
-
} catch (
|
|
448
|
+
} catch (n) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (r.op === "policy" && r.id === void 0) {
|
|
452
|
+
this.policy = (s = O(r.policy)) != null ? s : this.policy;
|
|
284
453
|
return;
|
|
285
454
|
}
|
|
286
455
|
if (r.op === "auth") {
|
|
287
456
|
if (r.ok === !0) {
|
|
288
|
-
this.authed = !0;
|
|
289
|
-
const
|
|
290
|
-
this.outgoing = [],
|
|
457
|
+
this.policy = (o = O(r.policy)) != null ? o : C, this.authed = !0;
|
|
458
|
+
const n = this.outgoing;
|
|
459
|
+
this.outgoing = [], n.forEach((a) => a());
|
|
291
460
|
}
|
|
292
461
|
return;
|
|
293
462
|
}
|
|
294
463
|
if (r.op === "bye") {
|
|
295
|
-
this.failAll(
|
|
464
|
+
this.failAll(f("AbortError", m)), this.stop();
|
|
296
465
|
return;
|
|
297
466
|
}
|
|
298
467
|
typeof r.id == "string" && this.push(r.id, r);
|
|
@@ -320,5 +489,6 @@ class D {
|
|
|
320
489
|
}
|
|
321
490
|
}
|
|
322
491
|
export {
|
|
323
|
-
|
|
492
|
+
C as OFFLINE_POLICY,
|
|
493
|
+
J as SandboxClient
|
|
324
494
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const g = {
|
|
2
|
+
png: "image/png",
|
|
3
|
+
jpg: "image/jpeg",
|
|
4
|
+
jpeg: "image/jpeg",
|
|
5
|
+
gif: "image/gif",
|
|
6
|
+
webp: "image/webp",
|
|
7
|
+
bmp: "image/bmp",
|
|
8
|
+
avif: "image/avif",
|
|
9
|
+
ico: "image/x-icon",
|
|
10
|
+
svg: "image/svg+xml",
|
|
11
|
+
mp3: "audio/mpeg",
|
|
12
|
+
wav: "audio/wav",
|
|
13
|
+
ogg: "audio/ogg",
|
|
14
|
+
m4a: "audio/mp4",
|
|
15
|
+
aac: "audio/aac",
|
|
16
|
+
flac: "audio/flac",
|
|
17
|
+
mp4: "video/mp4",
|
|
18
|
+
webm: "video/webm",
|
|
19
|
+
mov: "video/quicktime",
|
|
20
|
+
m4v: "video/mp4",
|
|
21
|
+
ogv: "video/ogg",
|
|
22
|
+
pdf: "application/pdf"
|
|
23
|
+
}, m = "只能预览图片、音视频和 PDF。";
|
|
24
|
+
function p(o) {
|
|
25
|
+
var a;
|
|
26
|
+
const i = (a = o.split("/").pop()) != null ? a : "", e = i.lastIndexOf(".");
|
|
27
|
+
if (!(e <= 0))
|
|
28
|
+
return g[i.slice(e + 1).toLowerCase()];
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
m as PREVIEW_TYPE_MESSAGE,
|
|
32
|
+
p as mediaTypeOf
|
|
33
|
+
};
|