@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
|
@@ -5,24 +5,24 @@ var m = (r, t) => {
|
|
|
5
5
|
throw Error("Symbol." + r + " is not defined");
|
|
6
6
|
};
|
|
7
7
|
var g = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
8
|
-
var
|
|
8
|
+
var b = (r, t, e) => (g(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
9
9
|
var o = (r, t, e) => new Promise((s, a) => {
|
|
10
10
|
var n = (i) => {
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
l(e.next(i));
|
|
13
13
|
} catch (c) {
|
|
14
14
|
a(c);
|
|
15
15
|
}
|
|
16
16
|
}, d = (i) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
l(e.throw(i));
|
|
19
19
|
} catch (c) {
|
|
20
20
|
a(c);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
23
|
-
|
|
22
|
+
}, l = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(n, d);
|
|
23
|
+
l((e = e.apply(r, t)).next());
|
|
24
24
|
});
|
|
25
|
-
var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (n) => new Promise((d,
|
|
25
|
+
var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (n) => new Promise((d, l, i) => (n = a.call(r, n), i = n.done, Promise.resolve(n.value).then((c) => d({ value: c, done: i }), l)))), e("next"), e("return"), t);
|
|
26
26
|
import { throwIfAborted as u } from "../errors.mjs";
|
|
27
27
|
import { SandboxClient as v } from "../host/sandboxClient.mjs";
|
|
28
28
|
import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
|
|
@@ -36,11 +36,11 @@ function x(r, t) {
|
|
|
36
36
|
}
|
|
37
37
|
class S {
|
|
38
38
|
constructor(t, e = "", s = new v()) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
b(this, "displayName");
|
|
40
|
+
b(this, "capabilities", /* @__PURE__ */ new Set());
|
|
41
|
+
b(this, "sandboxVersion");
|
|
42
|
+
b(this, "sandboxProtocol");
|
|
43
|
+
b(this, "sandbox");
|
|
44
44
|
this.displayName = e, this.sandbox = s;
|
|
45
45
|
}
|
|
46
46
|
setCapabilities(t, e = {}) {
|
|
@@ -50,7 +50,7 @@ class S {
|
|
|
50
50
|
applySandbox(t) {
|
|
51
51
|
this.sandboxProtocol = t == null ? void 0 : t.protocol, this.sandbox.apply(t);
|
|
52
52
|
}
|
|
53
|
-
/** 沙箱已就绪且协议为
|
|
53
|
+
/** 沙箱已就绪且协议为 1 时,命令走直连。 */
|
|
54
54
|
get canExec() {
|
|
55
55
|
return this.sandbox.ready;
|
|
56
56
|
}
|
|
@@ -101,7 +101,8 @@ class S {
|
|
|
101
101
|
cwd: t.cwd,
|
|
102
102
|
command: t.command,
|
|
103
103
|
argv: t.argv,
|
|
104
|
-
timeoutMs: t.timeoutMs
|
|
104
|
+
timeoutMs: t.timeoutMs,
|
|
105
|
+
skill: t.skill
|
|
105
106
|
}, t.signal, t.onOutput);
|
|
106
107
|
if (e.timedOut)
|
|
107
108
|
throw w("AbortError", "命令运行超时。");
|
|
@@ -121,8 +122,8 @@ class S {
|
|
|
121
122
|
const d = [];
|
|
122
123
|
try {
|
|
123
124
|
for (var N = f(M(e)), z, L, F; z = !(L = yield N.next()).done; z = !1) {
|
|
124
|
-
const
|
|
125
|
-
u(s.signal), d.push(
|
|
125
|
+
const y = L.value;
|
|
126
|
+
u(s.signal), d.push(y);
|
|
126
127
|
}
|
|
127
128
|
} catch (L) {
|
|
128
129
|
F = [L];
|
|
@@ -134,10 +135,10 @@ class S {
|
|
|
134
135
|
throw F[0];
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
const
|
|
138
|
+
const l = d.reduce((y, h) => y + h.byteLength, 0), i = new Uint8Array(l);
|
|
138
139
|
let c = 0;
|
|
139
|
-
d.forEach((
|
|
140
|
-
i.set(
|
|
140
|
+
d.forEach((y) => {
|
|
141
|
+
i.set(y, c), c += y.byteLength;
|
|
141
142
|
}), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
|
|
142
143
|
});
|
|
143
144
|
}
|
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
1
|
+
var M = Object.defineProperty, O = Object.defineProperties;
|
|
2
|
+
var j = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var v = Object.getOwnPropertySymbols;
|
|
4
|
+
var B = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var A = (a, t, e) => t in a ? M(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e, y = (a, t) => {
|
|
5
6
|
for (var e in t || (t = {}))
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
for (var e of
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
};
|
|
12
|
-
var m = (
|
|
13
|
-
var
|
|
14
|
-
var o = (
|
|
7
|
+
B.call(t, e) && A(a, e, t[e]);
|
|
8
|
+
if (v)
|
|
9
|
+
for (var e of v(t))
|
|
10
|
+
T.call(t, e) && A(a, e, t[e]);
|
|
11
|
+
return a;
|
|
12
|
+
}, x = (a, t) => O(a, j(t));
|
|
13
|
+
var m = (a, t, e) => (A(a, typeof t != "symbol" ? t + "" : t, e), e);
|
|
14
|
+
var p = (a, t, e) => new Promise((r, s) => {
|
|
15
|
+
var o = (i) => {
|
|
15
16
|
try {
|
|
16
|
-
|
|
17
|
+
l(e.next(i));
|
|
17
18
|
} catch (h) {
|
|
18
19
|
s(h);
|
|
19
20
|
}
|
|
20
|
-
}, n = (
|
|
21
|
+
}, n = (i) => {
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
+
l(e.throw(i));
|
|
23
24
|
} catch (h) {
|
|
24
25
|
s(h);
|
|
25
26
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
27
|
+
}, l = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(o, n);
|
|
28
|
+
l((e = e.apply(a, 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
|
|
34
|
-
function E(
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
37
|
-
if (
|
|
38
|
-
return new Uint8Array(
|
|
31
|
+
import { domError as f } from "../adapters/WorkspaceFileAdapter.mjs";
|
|
32
|
+
import { SANDBOX_PROTOCOL as S } from "./protocol.mjs";
|
|
33
|
+
import { decodeBinaryFrame as b, MAX_BINARY_PAYLOAD as N, encodeBinaryFrame as P } from "./sandboxFrames.mjs";
|
|
34
|
+
const k = "沙箱已退出。";
|
|
35
|
+
function E(a) {
|
|
36
|
+
if (a instanceof Uint8Array)
|
|
37
|
+
return a;
|
|
38
|
+
if (a instanceof ArrayBuffer)
|
|
39
|
+
return new Uint8Array(a);
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
-
const s =
|
|
42
|
-
if (!t && !e && !r &&
|
|
41
|
+
function C(a, t, e, r) {
|
|
42
|
+
const s = a.length > w ? a.slice(a.length - w) : a;
|
|
43
|
+
if (!t && !e && !r && a.length <= w)
|
|
43
44
|
return s;
|
|
44
45
|
let o = `
|
|
45
46
|
…输出已截断`;
|
|
46
47
|
return e && (o += `,完整输出见 ${e}`), r && (o += ",日志已截断"), s + o;
|
|
47
48
|
}
|
|
48
|
-
class
|
|
49
|
+
class L {
|
|
49
50
|
constructor(t = (e) => new WebSocket(e)) {
|
|
50
51
|
m(this, "notice");
|
|
51
52
|
m(this, "socket");
|
|
@@ -58,22 +59,22 @@ class D {
|
|
|
58
59
|
}
|
|
59
60
|
get ready() {
|
|
60
61
|
const t = this.notice;
|
|
61
|
-
return (t == null ? void 0 : t.state) === "ready" && t.protocol ===
|
|
62
|
+
return (t == null ? void 0 : t.state) === "ready" && t.protocol === S && !!(t.url && t.token);
|
|
62
63
|
}
|
|
63
64
|
unavailableMessage() {
|
|
64
65
|
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" ?
|
|
66
|
+
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" ? k : "沙箱没有就绪。";
|
|
66
67
|
}
|
|
67
68
|
apply(t) {
|
|
68
69
|
const e = this.notice;
|
|
69
70
|
if (this.notice = t, !this.ready || !(t != null && t.url) || !t.token) {
|
|
70
|
-
this.failAll(
|
|
71
|
+
this.failAll(f("NotAllowedError", this.unavailableMessage())), this.stop();
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
|
-
(e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(
|
|
74
|
+
(e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(f("AbortError", k)), this.stop(), this.connect(t.url, t.token));
|
|
74
75
|
}
|
|
75
76
|
stat(t) {
|
|
76
|
-
return
|
|
77
|
+
return p(this, null, function* () {
|
|
77
78
|
return this.invoke({
|
|
78
79
|
op: "stat",
|
|
79
80
|
path: t
|
|
@@ -81,7 +82,7 @@ class D {
|
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
list(t, e) {
|
|
84
|
-
return
|
|
85
|
+
return p(this, null, function* () {
|
|
85
86
|
return this.invoke({
|
|
86
87
|
op: "list",
|
|
87
88
|
path: t
|
|
@@ -89,33 +90,33 @@ class D {
|
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
read(o) {
|
|
92
|
-
return
|
|
93
|
+
return p(this, arguments, function* (t, e = 0, r = 50 * 1024 * 1024, s) {
|
|
93
94
|
const n = this.begin({
|
|
94
95
|
op: "read",
|
|
95
96
|
path: t,
|
|
96
97
|
offset: e,
|
|
97
98
|
maxBytes: r
|
|
98
|
-
}, s),
|
|
99
|
-
let
|
|
100
|
-
for (; !
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
99
|
+
}, s), l = [];
|
|
100
|
+
let i;
|
|
101
|
+
for (; !i; ) {
|
|
102
|
+
const d = yield this.next(n), g = E(d);
|
|
103
|
+
if (g) {
|
|
104
|
+
l.push(b(g).payload);
|
|
104
105
|
continue;
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
+
i = d;
|
|
107
108
|
}
|
|
108
|
-
if (this.calls.delete(n),
|
|
109
|
-
throw
|
|
110
|
-
const h =
|
|
111
|
-
let
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
}),
|
|
109
|
+
if (this.calls.delete(n), i.ok === !1)
|
|
110
|
+
throw f(String(i.name || "NotAllowedError"), String(i.message || "读取失败。"));
|
|
111
|
+
const h = l.reduce((d, g) => d + g.length, 0), c = new Uint8Array(h);
|
|
112
|
+
let u = 0;
|
|
113
|
+
return l.forEach((d) => {
|
|
114
|
+
c.set(d, u), u += d.length;
|
|
115
|
+
}), c;
|
|
115
116
|
});
|
|
116
117
|
}
|
|
117
118
|
write(t, e, r, s) {
|
|
118
|
-
return
|
|
119
|
+
return p(this, null, function* () {
|
|
119
120
|
const o = this.begin({
|
|
120
121
|
op: "write",
|
|
121
122
|
path: t,
|
|
@@ -124,23 +125,93 @@ class D {
|
|
|
124
125
|
}, s);
|
|
125
126
|
let n = 0;
|
|
126
127
|
for (; n < e.length; ) {
|
|
127
|
-
const
|
|
128
|
-
this.send(P(o, n, h === e.length,
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
throw this.calls.delete(o),
|
|
132
|
-
if (
|
|
128
|
+
const i = e.subarray(n, n + N), h = n + i.length;
|
|
129
|
+
this.send(P(o, n, h === e.length, i)), n = h;
|
|
130
|
+
const u = yield this.next(o);
|
|
131
|
+
if (u.ok === !1)
|
|
132
|
+
throw this.calls.delete(o), f(String(u.name || "NotAllowedError"), String(u.message || "写入失败。"));
|
|
133
|
+
if (u.op !== "ack" && u.ok === !0) {
|
|
133
134
|
this.calls.delete(o);
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
const
|
|
138
|
-
if (this.calls.delete(o),
|
|
139
|
-
throw
|
|
138
|
+
const l = yield this.next(o);
|
|
139
|
+
if (this.calls.delete(o), l.ok === !1)
|
|
140
|
+
throw f(String(l.name || "NotAllowedError"), String(l.message || "写入失败。"));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
skillStatus(t, e) {
|
|
144
|
+
return p(this, null, function* () {
|
|
145
|
+
const r = yield this.invoke({
|
|
146
|
+
op: "skillStatus",
|
|
147
|
+
applicationId: t
|
|
148
|
+
}, e);
|
|
149
|
+
return Array.isArray(r.skills) ? r.skills : [];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
skillRead(t, e, r, s, o) {
|
|
153
|
+
return p(this, null, function* () {
|
|
154
|
+
const n = this.begin({
|
|
155
|
+
op: "skillRead",
|
|
156
|
+
applicationId: t,
|
|
157
|
+
skillId: e,
|
|
158
|
+
version: r,
|
|
159
|
+
path: s
|
|
160
|
+
}, o), l = [];
|
|
161
|
+
let i;
|
|
162
|
+
for (; !i; ) {
|
|
163
|
+
const d = yield this.next(n), g = E(d);
|
|
164
|
+
if (g) {
|
|
165
|
+
l.push(b(g).payload);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
i = d;
|
|
169
|
+
}
|
|
170
|
+
if (this.calls.delete(n), i.ok === !1)
|
|
171
|
+
throw f(String(i.name || "NotAllowedError"), String(i.message || "读取失败。"));
|
|
172
|
+
const h = l.reduce((d, g) => d + g.length, 0), c = new Uint8Array(h);
|
|
173
|
+
let u = 0;
|
|
174
|
+
return l.forEach((d) => {
|
|
175
|
+
c.set(d, u), u += d.length;
|
|
176
|
+
}), c;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
installSkill(t, e, r) {
|
|
180
|
+
return p(this, null, function* () {
|
|
181
|
+
const s = this.begin(x(y({
|
|
182
|
+
op: "installSkill"
|
|
183
|
+
}, t), {
|
|
184
|
+
size: e.length
|
|
185
|
+
}), r);
|
|
186
|
+
let o = 0;
|
|
187
|
+
for (; o < e.length; ) {
|
|
188
|
+
const l = e.subarray(o, o + N), i = o + l.length;
|
|
189
|
+
this.send(P(s, o, i === e.length, l)), o = i;
|
|
190
|
+
const h = yield this.next(s);
|
|
191
|
+
if (h.ok === !1)
|
|
192
|
+
throw this.calls.delete(s), f(String(h.name || "NotAllowedError"), String(h.message || "安装失败。"));
|
|
193
|
+
if (h.op !== "ack" && h.ok === !0) {
|
|
194
|
+
this.calls.delete(s);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const n = yield this.next(s);
|
|
199
|
+
if (this.calls.delete(s), n.ok === !1)
|
|
200
|
+
throw f(String(n.name || "NotAllowedError"), String(n.message || "安装失败。"));
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
skillPrune(t, e, r, s) {
|
|
204
|
+
return p(this, null, function* () {
|
|
205
|
+
yield this.invoke({
|
|
206
|
+
op: "skillPrune",
|
|
207
|
+
applicationId: t,
|
|
208
|
+
keep: e,
|
|
209
|
+
busy: r
|
|
210
|
+
}, s);
|
|
140
211
|
});
|
|
141
212
|
}
|
|
142
213
|
mkdir(t) {
|
|
143
|
-
return
|
|
214
|
+
return p(this, null, function* () {
|
|
144
215
|
yield this.invoke({
|
|
145
216
|
op: "mkdir",
|
|
146
217
|
path: t
|
|
@@ -148,7 +219,7 @@ class D {
|
|
|
148
219
|
});
|
|
149
220
|
}
|
|
150
221
|
remove(t, e) {
|
|
151
|
-
return
|
|
222
|
+
return p(this, null, function* () {
|
|
152
223
|
yield this.invoke({
|
|
153
224
|
op: "remove",
|
|
154
225
|
path: t,
|
|
@@ -157,7 +228,7 @@ class D {
|
|
|
157
228
|
});
|
|
158
229
|
}
|
|
159
230
|
move(t, e) {
|
|
160
|
-
return
|
|
231
|
+
return p(this, null, function* () {
|
|
161
232
|
yield this.invoke({
|
|
162
233
|
op: "move",
|
|
163
234
|
from: t,
|
|
@@ -166,35 +237,35 @@ class D {
|
|
|
166
237
|
});
|
|
167
238
|
}
|
|
168
239
|
exec(t, e, r) {
|
|
169
|
-
return
|
|
240
|
+
return p(this, null, function* () {
|
|
170
241
|
var h;
|
|
171
|
-
const s = this.begin(
|
|
242
|
+
const s = this.begin(y({}, t), e, () => {
|
|
172
243
|
this.send({
|
|
173
|
-
protocol:
|
|
244
|
+
protocol: S,
|
|
174
245
|
id: s,
|
|
175
246
|
op: "cancel"
|
|
176
247
|
});
|
|
177
248
|
});
|
|
178
|
-
let o = "", n = "",
|
|
249
|
+
let o = "", n = "", l = !1, i = !1;
|
|
179
250
|
for (; this.calls.has(s); ) {
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
r == null || r(
|
|
251
|
+
const c = yield this.next(s);
|
|
252
|
+
if (c.op === "stdout" || c.op === "stderr") {
|
|
253
|
+
const g = String((h = c.text) != null ? h : "");
|
|
254
|
+
r == null || r(c.op, g), c.op === "stdout" ? (o += g, o.length > w && (l = !0), o = o.slice(-w)) : (n += g, n.length > w && (i = !0), n = n.slice(-w));
|
|
184
255
|
continue;
|
|
185
256
|
}
|
|
186
|
-
if (this.calls.delete(s),
|
|
187
|
-
throw
|
|
188
|
-
const
|
|
257
|
+
if (this.calls.delete(s), c.ok === !1)
|
|
258
|
+
throw f(String(c.name || "NotAllowedError"), String(c.message || "命令失败。"));
|
|
259
|
+
const u = typeof c.logPath == "string" ? c.logPath : void 0, d = c.logTruncated === !0;
|
|
189
260
|
return {
|
|
190
|
-
exitCode: typeof
|
|
191
|
-
timedOut:
|
|
192
|
-
stdout:
|
|
193
|
-
stderr:
|
|
194
|
-
cwd: typeof
|
|
261
|
+
exitCode: typeof c.exitCode == "number" ? c.exitCode : 1,
|
|
262
|
+
timedOut: c.timedOut === !0,
|
|
263
|
+
stdout: C(o, l, u, d),
|
|
264
|
+
stderr: C(n, i, u, d),
|
|
265
|
+
cwd: typeof c.cwd == "string" ? c.cwd : void 0
|
|
195
266
|
};
|
|
196
267
|
}
|
|
197
|
-
throw
|
|
268
|
+
throw f("AbortError", k);
|
|
198
269
|
});
|
|
199
270
|
}
|
|
200
271
|
invoke(t, e) {
|
|
@@ -203,42 +274,42 @@ class D {
|
|
|
203
274
|
this.calls.delete(r);
|
|
204
275
|
const o = s;
|
|
205
276
|
if (o.ok === !1)
|
|
206
|
-
throw
|
|
277
|
+
throw f(String(o.name || "NotAllowedError"), String(o.message || "请求失败。"));
|
|
207
278
|
return o;
|
|
208
279
|
});
|
|
209
280
|
}
|
|
210
281
|
begin(t, e, r) {
|
|
211
282
|
if (!this.ready)
|
|
212
|
-
throw
|
|
283
|
+
throw f("NotAllowedError", this.unavailableMessage());
|
|
213
284
|
if (e != null && e.aborted)
|
|
214
|
-
throw
|
|
285
|
+
throw f("AbortError");
|
|
215
286
|
const s = `sbx-${++this.seq}`;
|
|
216
287
|
let o = () => {
|
|
217
288
|
};
|
|
218
289
|
const n = {
|
|
219
290
|
messages: [],
|
|
220
291
|
waiters: [],
|
|
221
|
-
reject: (
|
|
292
|
+
reject: (i) => o(i)
|
|
222
293
|
};
|
|
223
294
|
this.calls.set(s, n);
|
|
224
|
-
const
|
|
225
|
-
r == null || r(), n.reject(
|
|
295
|
+
const l = () => {
|
|
296
|
+
r == null || r(), n.reject(f("AbortError"));
|
|
226
297
|
};
|
|
227
|
-
return e == null || e.addEventListener("abort",
|
|
298
|
+
return e == null || e.addEventListener("abort", l, {
|
|
228
299
|
once: !0
|
|
229
|
-
}), o = (
|
|
230
|
-
e == null || e.removeEventListener("abort",
|
|
300
|
+
}), o = (i) => {
|
|
301
|
+
e == null || e.removeEventListener("abort", l), this.calls.delete(s);
|
|
231
302
|
const h = n.waiters.shift();
|
|
232
|
-
h && h(Promise.reject(
|
|
233
|
-
}, this.send(
|
|
234
|
-
protocol:
|
|
303
|
+
h && h(Promise.reject(i));
|
|
304
|
+
}, this.send(y({
|
|
305
|
+
protocol: S,
|
|
235
306
|
id: s
|
|
236
307
|
}, t)), s;
|
|
237
308
|
}
|
|
238
309
|
next(t) {
|
|
239
310
|
const e = this.calls.get(t);
|
|
240
311
|
if (!e)
|
|
241
|
-
return Promise.reject(
|
|
312
|
+
return Promise.reject(f("AbortError", k));
|
|
242
313
|
const r = e.messages.shift();
|
|
243
314
|
return r !== void 0 ? Promise.resolve(r) : new Promise((s, o) => {
|
|
244
315
|
e.waiters.push(s), e.reject = (n) => {
|
|
@@ -259,21 +330,21 @@ class D {
|
|
|
259
330
|
const r = ++this.generation, s = this.openSocket(t);
|
|
260
331
|
this.socket = s, this.authed = !1, s.binaryType = "arraybuffer", s.onopen = () => {
|
|
261
332
|
r === this.generation && s.send(JSON.stringify({
|
|
262
|
-
protocol:
|
|
333
|
+
protocol: S,
|
|
263
334
|
op: "auth",
|
|
264
335
|
token: e
|
|
265
336
|
}));
|
|
266
337
|
}, s.onmessage = (o) => {
|
|
267
338
|
r === this.generation && this.onFrame(o.data);
|
|
268
339
|
}, s.onclose = () => {
|
|
269
|
-
r === this.generation && (this.authed = !1, this.failAll(
|
|
340
|
+
r === this.generation && (this.authed = !1, this.failAll(f("AbortError", k)));
|
|
270
341
|
}, s.onerror = () => {
|
|
271
342
|
};
|
|
272
343
|
}
|
|
273
344
|
onFrame(t) {
|
|
274
345
|
const e = E(t);
|
|
275
346
|
if (e) {
|
|
276
|
-
const s =
|
|
347
|
+
const s = b(e);
|
|
277
348
|
this.push(s.id, e);
|
|
278
349
|
return;
|
|
279
350
|
}
|
|
@@ -292,7 +363,7 @@ class D {
|
|
|
292
363
|
return;
|
|
293
364
|
}
|
|
294
365
|
if (r.op === "bye") {
|
|
295
|
-
this.failAll(
|
|
366
|
+
this.failAll(f("AbortError", k)), this.stop();
|
|
296
367
|
return;
|
|
297
368
|
}
|
|
298
369
|
typeof r.id == "string" && this.push(r.id, r);
|
|
@@ -320,5 +391,5 @@ class D {
|
|
|
320
391
|
}
|
|
321
392
|
}
|
|
322
393
|
export {
|
|
323
|
-
|
|
394
|
+
L as SandboxClient
|
|
324
395
|
};
|