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