@glodon-aiot/bot-client-sdk 3.26.0-alpha.23 → 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/README.md +180 -130
- package/dist/es/AgentSession.mjs +148 -129
- package/dist/es/BotClient.mjs +154 -136
- package/dist/es/Config.mjs +56 -89
- package/dist/es/Session.mjs +35 -23
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +262 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +69 -0
- package/dist/es/builtinTools/platformSkills.mjs +210 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +494 -0
- package/dist/es/index.mjs +66 -64
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
- package/dist/es/localFiles/constants.mjs +24 -29
- package/dist/es/localFiles/errors.mjs +21 -19
- package/dist/es/localFiles/host/connectHostBridge.mjs +37 -34
- package/dist/es/localFiles/host/protocol.mjs +27 -13
- package/dist/es/localFiles/host/sandboxClient.mjs +476 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +40 -86
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +167 -86
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- 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 +38 -29
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/lib/index.js +379 -10
- package/dist/src/AgentSession.d.ts +2 -0
- package/dist/src/Config.d.ts +5 -7
- package/dist/src/Session.d.ts +6 -0
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +35 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +16 -0
- package/dist/src/builtinTools/platformSkills.d.ts +67 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +64 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
- package/dist/src/localFiles/constants.d.ts +3 -13
- package/dist/src/localFiles/host/protocol.d.ts +34 -16
- package/dist/src/localFiles/host/sandboxClient.d.ts +104 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +11 -6
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +2 -5
- package/dist/src/localFiles/types.d.ts +16 -23
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- 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/dist/src/sessionUpload.d.ts +14 -0
- package/package.json +13 -4
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var L = Object.getOwnPropertySymbols;
|
|
3
|
+
var j = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var $ = (r, t, e) => t in r ? D(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, S = (r, t) => {
|
|
5
|
+
for (var e in t || (t = {}))
|
|
6
|
+
j.call(t, e) && $(r, e, t[e]);
|
|
7
|
+
if (L)
|
|
8
|
+
for (var e of L(t))
|
|
9
|
+
M.call(t, e) && $(r, e, t[e]);
|
|
10
|
+
return r;
|
|
11
|
+
};
|
|
12
|
+
var w = (r, t, e) => ($(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
13
|
+
var g = (r, t, e) => new Promise((a, s) => {
|
|
14
|
+
var o = (d) => {
|
|
15
|
+
try {
|
|
16
|
+
n(e.next(d));
|
|
17
|
+
} catch (i) {
|
|
18
|
+
s(i);
|
|
19
|
+
}
|
|
20
|
+
}, c = (d) => {
|
|
21
|
+
try {
|
|
22
|
+
n(e.throw(d));
|
|
23
|
+
} catch (i) {
|
|
24
|
+
s(i);
|
|
25
|
+
}
|
|
26
|
+
}, n = (d) => d.done ? a(d.value) : Promise.resolve(d.value).then(o, c);
|
|
27
|
+
n((e = e.apply(r, t)).next());
|
|
28
|
+
});
|
|
29
|
+
import { domError as x } from "../../localFiles/adapters/WorkspaceFileAdapter.mjs";
|
|
30
|
+
import { ToolError as O, ToolCode as R } from "../../localFiles/errors.mjs";
|
|
31
|
+
import { readBytes as W } from "../../localFiles/tools/runtime.mjs";
|
|
32
|
+
import { WORKSPACE_MOUNT as l } from "../constants.mjs";
|
|
33
|
+
import { DEFAULT_PYODIDE_INDEX_URL as A, PYODIDE_PACKAGES as U } from "./assets.mjs";
|
|
34
|
+
import N from "./pyodideRunner.py.mjs";
|
|
35
|
+
import T from "./pyodideWorker.mjs";
|
|
36
|
+
const B = `浏览器环境不能安装依赖。可以直接 import ${U.join("、")},需要其他包请改用宿主环境。
|
|
37
|
+
`, C = 10 * 1024 * 1024, I = 64 * 1024 * 1024;
|
|
38
|
+
function F(r) {
|
|
39
|
+
return !r || r === "." || r === "/" ? l : r === l || r.startsWith(`${l}/`) ? r : `${l}/${r.replace(/^\/+/, "")}`;
|
|
40
|
+
}
|
|
41
|
+
function v(r) {
|
|
42
|
+
if (r === l)
|
|
43
|
+
return "";
|
|
44
|
+
if (r.startsWith(`${l}/`))
|
|
45
|
+
return r.slice(l.length + 1);
|
|
46
|
+
}
|
|
47
|
+
const Y = /* @__PURE__ */ new Set(["-u", "-B", "-E", "-s", "-S", "-I", "-O", "-OO", "-q", "-b", "-bb"]);
|
|
48
|
+
function y(r, t, e = "") {
|
|
49
|
+
return {
|
|
50
|
+
exitCode: r,
|
|
51
|
+
stdout: e,
|
|
52
|
+
stderr: t
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function X(r, t) {
|
|
56
|
+
const e = [];
|
|
57
|
+
for (const a of (t.startsWith("/") ? t : `${r}/${t}`).split("/"))
|
|
58
|
+
!a || a === "." || (a === ".." ? e.pop() : e.push(a));
|
|
59
|
+
return `/${e.join("/")}`;
|
|
60
|
+
}
|
|
61
|
+
function z(r, t, e) {
|
|
62
|
+
const a = new Uint8Array(0);
|
|
63
|
+
for (let s = 0; s < r.length; s += 1) {
|
|
64
|
+
const o = r[s], c = r.slice(s + 1);
|
|
65
|
+
if (o === "-c" || o.startsWith("-c") && !o.startsWith("--")) {
|
|
66
|
+
const n = o === "-c" ? c.shift() : o.slice(2);
|
|
67
|
+
return n === void 0 ? y(2, `python3: -c 后面缺少代码
|
|
68
|
+
`) : {
|
|
69
|
+
mode: "c",
|
|
70
|
+
target: n,
|
|
71
|
+
argv: ["-c", ...c],
|
|
72
|
+
stdin: e
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (o === "-m") {
|
|
76
|
+
const n = c.shift();
|
|
77
|
+
return n ? n === "pip" || n === "ensurepip" ? y(1, B) : {
|
|
78
|
+
mode: "m",
|
|
79
|
+
target: n,
|
|
80
|
+
argv: [n, ...c],
|
|
81
|
+
stdin: e
|
|
82
|
+
} : y(2, `python3: -m 后面缺少模块名
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
if (o === "-V" || o === "--version")
|
|
86
|
+
return {
|
|
87
|
+
mode: "c",
|
|
88
|
+
target: "import sys; print('Python ' + sys.version.split()[0])",
|
|
89
|
+
argv: ["-c"],
|
|
90
|
+
stdin: e
|
|
91
|
+
};
|
|
92
|
+
if (o === "-h" || o === "--help")
|
|
93
|
+
return y(0, "", `usage: python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...
|
|
94
|
+
`);
|
|
95
|
+
if (!(Y.has(o) || /^-[WX]./.test(o))) {
|
|
96
|
+
if (o === "-W" || o === "-X") {
|
|
97
|
+
s += 1;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
return o === "-" ? {
|
|
101
|
+
mode: "c",
|
|
102
|
+
target: new TextDecoder().decode(e),
|
|
103
|
+
argv: ["-", ...c],
|
|
104
|
+
stdin: a
|
|
105
|
+
} : o.startsWith("-") ? y(2, `python3: 浏览器环境不支持参数 ${o}
|
|
106
|
+
`) : {
|
|
107
|
+
mode: "file",
|
|
108
|
+
target: X(t, o),
|
|
109
|
+
argv: [o, ...c],
|
|
110
|
+
stdin: e
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return e.length > 0 ? {
|
|
115
|
+
mode: "c",
|
|
116
|
+
target: new TextDecoder().decode(e),
|
|
117
|
+
argv: [""],
|
|
118
|
+
stdin: a
|
|
119
|
+
} : y(2, `浏览器环境不支持交互式 Python,请用 python3 -c "…" 或脚本文件。
|
|
120
|
+
`);
|
|
121
|
+
}
|
|
122
|
+
function P(r) {
|
|
123
|
+
var t;
|
|
124
|
+
return r && typeof r == "object" ? String((t = r.name) != null ? t : "") : "";
|
|
125
|
+
}
|
|
126
|
+
function k(r) {
|
|
127
|
+
return r instanceof Error ? r.message : String(r);
|
|
128
|
+
}
|
|
129
|
+
function b(r, t) {
|
|
130
|
+
return new Promise((e, a) => {
|
|
131
|
+
if (!r)
|
|
132
|
+
return;
|
|
133
|
+
const s = () => {
|
|
134
|
+
t == null || t(), a(x("AbortError"));
|
|
135
|
+
};
|
|
136
|
+
r.aborted ? s() : r.addEventListener("abort", s, {
|
|
137
|
+
once: !0
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function G(r) {
|
|
142
|
+
const t = URL.createObjectURL(new Blob([r], {
|
|
143
|
+
type: "text/javascript"
|
|
144
|
+
})), e = new Worker(t, {
|
|
145
|
+
type: "module"
|
|
146
|
+
}), a = () => URL.revokeObjectURL(t);
|
|
147
|
+
return e.addEventListener("message", a, {
|
|
148
|
+
once: !0
|
|
149
|
+
}), e.addEventListener("error", a, {
|
|
150
|
+
once: !0
|
|
151
|
+
}), e;
|
|
152
|
+
}
|
|
153
|
+
class et {
|
|
154
|
+
constructor(t) {
|
|
155
|
+
w(this, "state");
|
|
156
|
+
w(this, "queue", Promise.resolve());
|
|
157
|
+
w(this, "nextId", 0);
|
|
158
|
+
this.options = t;
|
|
159
|
+
}
|
|
160
|
+
get indexURL() {
|
|
161
|
+
return this.options.indexURL || A;
|
|
162
|
+
}
|
|
163
|
+
loadError(t) {
|
|
164
|
+
return new O(R.NotImplemented, `Python 运行环境加载失败,请确认页面能访问 ${this.indexURL}(CSP 需在 script-src、connect-src 放行该地址,worker-src 放行 blob:)。${t}`);
|
|
165
|
+
}
|
|
166
|
+
dispose(t, e) {
|
|
167
|
+
this.state === t && (this.state = void 0), t.worker.terminate(), t.pending.forEach(({
|
|
168
|
+
reject: a
|
|
169
|
+
}) => a(e)), t.pending.clear();
|
|
170
|
+
}
|
|
171
|
+
spawn() {
|
|
172
|
+
var o;
|
|
173
|
+
let t;
|
|
174
|
+
try {
|
|
175
|
+
t = ((o = this.options.createWorker) != null ? o : G)(T);
|
|
176
|
+
} catch (c) {
|
|
177
|
+
throw this.loadError(`(${k(c)})`);
|
|
178
|
+
}
|
|
179
|
+
let e;
|
|
180
|
+
const a = new Promise((c, n) => e = {
|
|
181
|
+
resolve: c,
|
|
182
|
+
reject: n
|
|
183
|
+
}), s = {
|
|
184
|
+
worker: t,
|
|
185
|
+
ready: a,
|
|
186
|
+
pending: /* @__PURE__ */ new Map()
|
|
187
|
+
};
|
|
188
|
+
return a.catch(() => {
|
|
189
|
+
}), t.onmessage = ({
|
|
190
|
+
data: c
|
|
191
|
+
}) => {
|
|
192
|
+
var d;
|
|
193
|
+
const n = c;
|
|
194
|
+
if (n.type === "ready")
|
|
195
|
+
e.resolve();
|
|
196
|
+
else if (n.type === "failed") {
|
|
197
|
+
const i = this.loadError(`(${n.message})`);
|
|
198
|
+
e.reject(i), this.dispose(s, i);
|
|
199
|
+
} else
|
|
200
|
+
n.type === "result" && ((d = s.pending.get(n.id)) == null || d.resolve(n), s.pending.delete(n.id));
|
|
201
|
+
}, t.onerror = (c) => {
|
|
202
|
+
var i;
|
|
203
|
+
const n = k((i = c == null ? void 0 : c.message) != null ? i : c), d = this.loadError(`(${n})`);
|
|
204
|
+
e.reject(d), this.dispose(s, new Error(`Python 运行环境意外退出:${n}`));
|
|
205
|
+
}, t.postMessage({
|
|
206
|
+
type: "init",
|
|
207
|
+
indexURL: this.indexURL,
|
|
208
|
+
packages: U,
|
|
209
|
+
runner: N
|
|
210
|
+
}), s;
|
|
211
|
+
}
|
|
212
|
+
run(t) {
|
|
213
|
+
const e = this.queue.then(() => this.runNow(t));
|
|
214
|
+
return this.queue = e.catch(() => {
|
|
215
|
+
}), e;
|
|
216
|
+
}
|
|
217
|
+
runNow(t) {
|
|
218
|
+
return g(this, null, function* () {
|
|
219
|
+
var p, h, m;
|
|
220
|
+
const e = F(t.cwd), a = z(t.args, e, (p = t.stdin) != null ? p : new Uint8Array(0));
|
|
221
|
+
if (!("mode" in a))
|
|
222
|
+
return a;
|
|
223
|
+
if ((h = t.signal) != null && h.aborted)
|
|
224
|
+
throw x("AbortError");
|
|
225
|
+
const s = (m = this.state) != null ? m : this.state = this.spawn();
|
|
226
|
+
yield Promise.race([s.ready, b(t.signal)]);
|
|
227
|
+
const o = yield this.collect(t.signal), c = this.nextId += 1, n = new Promise((u, E) => s.pending.set(c, {
|
|
228
|
+
resolve: u,
|
|
229
|
+
reject: E
|
|
230
|
+
}));
|
|
231
|
+
s.worker.postMessage(S({
|
|
232
|
+
type: "run",
|
|
233
|
+
id: c,
|
|
234
|
+
files: o.files,
|
|
235
|
+
dirs: o.dirs,
|
|
236
|
+
cwd: e
|
|
237
|
+
}, a), o.files.map((u) => u.data.buffer));
|
|
238
|
+
const d = yield Promise.race([n, b(t.signal, () => this.dispose(s, x("AbortError")))]), i = [];
|
|
239
|
+
if (o.skipped.length > 0) {
|
|
240
|
+
const u = o.skipped.slice(0, 5).map((_) => `/${_}`), E = o.skipped.length > u.length ? ` 等 ${o.skipped.length} 个` : "";
|
|
241
|
+
i.push(`提示:${u.join("、")}${E}文件超过同步上限(单个 10 MB、合计 64 MB),Python 里看不到。`);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
exitCode: (yield this.writeBack(d, o, i)) && d.exitCode === 0 ? 1 : d.exitCode,
|
|
245
|
+
stdout: d.stdout,
|
|
246
|
+
stderr: d.stderr + i.map((u) => `${u}
|
|
247
|
+
`).join("")
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/** 执行前把整个工作区读进 Pyodide。 */
|
|
252
|
+
collect(t) {
|
|
253
|
+
return g(this, null, function* () {
|
|
254
|
+
const {
|
|
255
|
+
adapter: e,
|
|
256
|
+
sensitive: a
|
|
257
|
+
} = this.options, s = {
|
|
258
|
+
files: [],
|
|
259
|
+
dirs: [],
|
|
260
|
+
synced: /* @__PURE__ */ new Set(),
|
|
261
|
+
skipped: []
|
|
262
|
+
};
|
|
263
|
+
let o = 0;
|
|
264
|
+
const c = (n) => g(this, null, function* () {
|
|
265
|
+
var i, f;
|
|
266
|
+
let d;
|
|
267
|
+
try {
|
|
268
|
+
d = yield e.listEntries(n, t);
|
|
269
|
+
} catch (p) {
|
|
270
|
+
if (P(p) === "NotFoundError" || P(p) === "TypeMismatchError")
|
|
271
|
+
return;
|
|
272
|
+
throw p;
|
|
273
|
+
}
|
|
274
|
+
s.dirs.push(n ? `${l}/${n}` : l);
|
|
275
|
+
for (const p of d.sort((h, m) => h.name.localeCompare(m.name))) {
|
|
276
|
+
const h = n ? `${n}/${p.name}` : p.name;
|
|
277
|
+
if (p.kind === "directory") {
|
|
278
|
+
yield c(h);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (a.match(h, "read"))
|
|
282
|
+
continue;
|
|
283
|
+
const m = (f = (i = p.size) != null ? i : (yield e.stat(h)).size) != null ? f : 0;
|
|
284
|
+
if (m > C || o + m > I) {
|
|
285
|
+
s.skipped.push(h);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const u = yield W(yield e.readFile(h));
|
|
289
|
+
o += u.byteLength, s.files.push({
|
|
290
|
+
path: `${l}/${h}`,
|
|
291
|
+
data: u
|
|
292
|
+
}), s.synced.add(h);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return yield c(""), s;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
exists(t) {
|
|
299
|
+
return g(this, null, function* () {
|
|
300
|
+
try {
|
|
301
|
+
return yield this.options.adapter.stat(t), !0;
|
|
302
|
+
} catch (e) {
|
|
303
|
+
return !1;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/** 把 Python 里的改动写回工作区,返回是否有写回失败。 */
|
|
308
|
+
writeBack(t, e, a) {
|
|
309
|
+
return g(this, null, function* () {
|
|
310
|
+
const {
|
|
311
|
+
adapter: s,
|
|
312
|
+
sensitive: o
|
|
313
|
+
} = this.options;
|
|
314
|
+
let c = !1;
|
|
315
|
+
const n = (i, f) => {
|
|
316
|
+
c = !0, a.push(`写回 ${i} 失败:${k(f)}`);
|
|
317
|
+
};
|
|
318
|
+
for (const i of t.createdDirs.sort()) {
|
|
319
|
+
const f = v(i);
|
|
320
|
+
!f || !s.createDirectory || (yield s.createDirectory(f).catch((p) => n(i, p)));
|
|
321
|
+
}
|
|
322
|
+
for (const {
|
|
323
|
+
path: i,
|
|
324
|
+
data: f
|
|
325
|
+
} of t.written) {
|
|
326
|
+
const p = v(i);
|
|
327
|
+
p && (o.match(p, "write") ? a.push(`没有写回 ${i}:敏感文件不能由命令修改。`) : !e.synced.has(p) && (yield this.exists(p)) ? a.push(`没有写回 ${i}:工作区里已有这个文件,但它没有同步进 Python,为避免覆盖已跳过。`) : yield s.writeFile(p, f, {
|
|
328
|
+
createDirectories: !0
|
|
329
|
+
}).catch((h) => n(i, h)));
|
|
330
|
+
}
|
|
331
|
+
if (t.removed.length > 0 && !s.remove)
|
|
332
|
+
return a.push(`当前工作区不支持删除,${t.removed.join("、")} 仍然保留。`), c;
|
|
333
|
+
for (const i of t.removed) {
|
|
334
|
+
const f = v(i);
|
|
335
|
+
f && (yield s.remove(f).catch((p) => {
|
|
336
|
+
P(p) !== "NotFoundError" && n(i, p);
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
const d = t.removedDirs.sort((i, f) => f.split("/").length - i.split("/").length);
|
|
340
|
+
for (const i of d) {
|
|
341
|
+
const f = v(i);
|
|
342
|
+
f && (yield s.remove(f).catch(() => {
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
return c;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
export {
|
|
350
|
+
C as MAX_SYNC_FILE_BYTES,
|
|
351
|
+
I as MAX_SYNC_TOTAL_BYTES,
|
|
352
|
+
B as NO_PIP_MESSAGE,
|
|
353
|
+
et as PythonRunner,
|
|
354
|
+
z as parsePythonArgs,
|
|
355
|
+
F as toMount
|
|
356
|
+
};
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
var s = (a, r, t) => new Promise((e, i) => {
|
|
2
|
+
var o = (d) => {
|
|
3
|
+
try {
|
|
4
|
+
u(t.next(d));
|
|
5
|
+
} catch (f) {
|
|
6
|
+
i(f);
|
|
7
|
+
}
|
|
8
|
+
}, c = (d) => {
|
|
9
|
+
try {
|
|
10
|
+
u(t.throw(d));
|
|
11
|
+
} catch (f) {
|
|
12
|
+
i(f);
|
|
13
|
+
}
|
|
14
|
+
}, u = (d) => d.done ? e(d.value) : Promise.resolve(d.value).then(o, c);
|
|
15
|
+
u((t = t.apply(a, r)).next());
|
|
16
|
+
});
|
|
17
|
+
import { readBytes as l } from "../../localFiles/tools/runtime.mjs";
|
|
18
|
+
const v = {
|
|
19
|
+
ENOENT: "no such file or directory",
|
|
20
|
+
EEXIST: "file already exists",
|
|
21
|
+
EISDIR: "illegal operation on a directory",
|
|
22
|
+
ENOTDIR: "not a directory",
|
|
23
|
+
ENOTEMPTY: "directory not empty",
|
|
24
|
+
EACCES: "permission denied",
|
|
25
|
+
EPERM: "operation not permitted",
|
|
26
|
+
EINVAL: "invalid argument",
|
|
27
|
+
EIO: "i/o error"
|
|
28
|
+
};
|
|
29
|
+
function n(a, r, t) {
|
|
30
|
+
var i;
|
|
31
|
+
const e = new Error(`${a}: ${(i = v[a]) != null ? i : a}, ${r} '${t}'`);
|
|
32
|
+
return e.code = a, e;
|
|
33
|
+
}
|
|
34
|
+
function w(a) {
|
|
35
|
+
var r;
|
|
36
|
+
return a && typeof a == "object" ? String((r = a.name) != null ? r : "") : "";
|
|
37
|
+
}
|
|
38
|
+
function y(a) {
|
|
39
|
+
const r = typeof a == "string" ? a : a == null ? void 0 : a.encoding;
|
|
40
|
+
return (r != null ? r : "utf8").toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
function E(a) {
|
|
43
|
+
let r = "";
|
|
44
|
+
for (let t = 0; t < a.length; t += 32768)
|
|
45
|
+
r += String.fromCharCode(...a.subarray(t, t + 32768));
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
function R(a, r) {
|
|
49
|
+
switch (r) {
|
|
50
|
+
case "binary":
|
|
51
|
+
case "latin1":
|
|
52
|
+
case "ascii":
|
|
53
|
+
return E(a);
|
|
54
|
+
case "base64":
|
|
55
|
+
return btoa(E(a));
|
|
56
|
+
case "hex":
|
|
57
|
+
return Array.from(a, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
58
|
+
default:
|
|
59
|
+
return new TextDecoder().decode(a);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function m(a, r) {
|
|
63
|
+
var t;
|
|
64
|
+
if (typeof a != "string")
|
|
65
|
+
return a;
|
|
66
|
+
switch (r) {
|
|
67
|
+
case "binary":
|
|
68
|
+
case "latin1":
|
|
69
|
+
case "ascii":
|
|
70
|
+
return Uint8Array.from(a, (e) => e.charCodeAt(0) & 255);
|
|
71
|
+
case "base64":
|
|
72
|
+
return Uint8Array.from(atob(a), (e) => e.charCodeAt(0));
|
|
73
|
+
case "hex":
|
|
74
|
+
return Uint8Array.from((t = a.match(/../g)) != null ? t : [], (e) => parseInt(e, 16));
|
|
75
|
+
default:
|
|
76
|
+
return new TextEncoder().encode(a);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function h(a) {
|
|
80
|
+
const r = [];
|
|
81
|
+
for (const t of a.split("/"))
|
|
82
|
+
!t || t === "." || (t === ".." ? r.pop() : r.push(t));
|
|
83
|
+
return `/${r.join("/")}`;
|
|
84
|
+
}
|
|
85
|
+
class k {
|
|
86
|
+
constructor(r, t, e) {
|
|
87
|
+
this.adapter = r, this.root = t, this.sensitive = e;
|
|
88
|
+
}
|
|
89
|
+
relative(r) {
|
|
90
|
+
const t = h(r).slice(1);
|
|
91
|
+
return this.root ? t ? `${this.root}/${t}` : this.root : t;
|
|
92
|
+
}
|
|
93
|
+
shown(r) {
|
|
94
|
+
const t = this.relative(r);
|
|
95
|
+
return t ? `/${t}` : "/";
|
|
96
|
+
}
|
|
97
|
+
isRoot(r) {
|
|
98
|
+
return h(r) === "/";
|
|
99
|
+
}
|
|
100
|
+
guard(r, t, e) {
|
|
101
|
+
const i = this.relative(r);
|
|
102
|
+
if (this.sensitive.match(i, t))
|
|
103
|
+
throw n("EACCES", e, this.shown(r));
|
|
104
|
+
return i;
|
|
105
|
+
}
|
|
106
|
+
mapError(r, t, e) {
|
|
107
|
+
if (r && typeof r == "object" && typeof r.code == "string")
|
|
108
|
+
return r;
|
|
109
|
+
switch (w(r)) {
|
|
110
|
+
case "NotFoundError":
|
|
111
|
+
return n("ENOENT", t, this.shown(e));
|
|
112
|
+
case "TypeMismatchError":
|
|
113
|
+
return n(t === "open" || t === "write" ? "EISDIR" : "ENOTDIR", t, this.shown(e));
|
|
114
|
+
case "InvalidModificationError":
|
|
115
|
+
return n(t === "rm" ? "ENOTEMPTY" : "EEXIST", t, this.shown(e));
|
|
116
|
+
case "NotAllowedError":
|
|
117
|
+
case "SecurityError":
|
|
118
|
+
case "NoModificationAllowedError":
|
|
119
|
+
return n("EACCES", t, this.shown(e));
|
|
120
|
+
default:
|
|
121
|
+
return n("EIO", t, this.shown(e));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
entry(r, t) {
|
|
125
|
+
return s(this, null, function* () {
|
|
126
|
+
try {
|
|
127
|
+
return yield this.adapter.stat(this.relative(r));
|
|
128
|
+
} catch (e) {
|
|
129
|
+
if (this.isRoot(r) && w(e) === "NotFoundError")
|
|
130
|
+
return {
|
|
131
|
+
name: this.root,
|
|
132
|
+
kind: "directory"
|
|
133
|
+
};
|
|
134
|
+
throw this.mapError(e, t, r);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
ensureRoot() {
|
|
139
|
+
return s(this, null, function* () {
|
|
140
|
+
if (this.root)
|
|
141
|
+
try {
|
|
142
|
+
yield this.adapter.stat(this.root);
|
|
143
|
+
} catch (r) {
|
|
144
|
+
if (w(r) !== "NotFoundError")
|
|
145
|
+
throw r;
|
|
146
|
+
this.adapter.createDirectory && (yield this.adapter.createDirectory(this.root));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
readFileBuffer(r) {
|
|
151
|
+
return s(this, null, function* () {
|
|
152
|
+
const t = this.guard(r, "read", "open");
|
|
153
|
+
if ((yield this.entry(r, "open")).kind !== "file")
|
|
154
|
+
throw n("EISDIR", "read", this.shown(r));
|
|
155
|
+
try {
|
|
156
|
+
return yield l(yield this.adapter.readFile(t));
|
|
157
|
+
} catch (i) {
|
|
158
|
+
throw this.mapError(i, "open", r);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
readFile(r, t) {
|
|
163
|
+
return s(this, null, function* () {
|
|
164
|
+
return R(yield this.readFileBuffer(r), y(t));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
writeFile(r, t, e) {
|
|
168
|
+
return s(this, null, function* () {
|
|
169
|
+
if (this.isRoot(r))
|
|
170
|
+
throw n("EISDIR", "open", this.shown(r));
|
|
171
|
+
const i = this.guard(r, "write", "open"), o = h(r).lastIndexOf("/") === 0;
|
|
172
|
+
try {
|
|
173
|
+
o && (yield this.ensureRoot()), yield this.adapter.writeFile(i, m(t, y(e)), {
|
|
174
|
+
createDirectories: !0
|
|
175
|
+
});
|
|
176
|
+
} catch (c) {
|
|
177
|
+
throw this.mapError(c, "open", r);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
appendFile(r, t, e) {
|
|
182
|
+
return s(this, null, function* () {
|
|
183
|
+
let i = new Uint8Array();
|
|
184
|
+
(yield this.exists(r)) && (i = yield this.readFileBuffer(r));
|
|
185
|
+
const o = m(t, y(e)), c = new Uint8Array(i.byteLength + o.byteLength);
|
|
186
|
+
c.set(i), c.set(o, i.byteLength), yield this.writeFile(r, c);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
exists(r) {
|
|
190
|
+
return s(this, null, function* () {
|
|
191
|
+
try {
|
|
192
|
+
return yield this.entry(r, "access"), !0;
|
|
193
|
+
} catch (t) {
|
|
194
|
+
return !1;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
stat(r) {
|
|
199
|
+
return s(this, null, function* () {
|
|
200
|
+
var i, o;
|
|
201
|
+
const t = yield this.entry(r, "stat"), e = t.kind === "directory";
|
|
202
|
+
return {
|
|
203
|
+
isFile: !e,
|
|
204
|
+
isDirectory: e,
|
|
205
|
+
isSymbolicLink: !1,
|
|
206
|
+
mode: e ? 493 : 420,
|
|
207
|
+
size: (i = t.size) != null ? i : 0,
|
|
208
|
+
mtime: new Date((o = t.lastModified) != null ? o : 0)
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
lstat(r) {
|
|
213
|
+
return this.stat(r);
|
|
214
|
+
}
|
|
215
|
+
mkdir(r, t) {
|
|
216
|
+
return s(this, null, function* () {
|
|
217
|
+
if (!this.adapter.createDirectory)
|
|
218
|
+
throw n("EPERM", "mkdir", this.shown(r));
|
|
219
|
+
if (yield this.exists(r)) {
|
|
220
|
+
if (t != null && t.recursive)
|
|
221
|
+
return;
|
|
222
|
+
throw n("EEXIST", "mkdir", this.shown(r));
|
|
223
|
+
}
|
|
224
|
+
if (!(t != null && t.recursive)) {
|
|
225
|
+
const e = h(r), i = e.slice(0, e.lastIndexOf("/")) || "/";
|
|
226
|
+
if (!(yield this.exists(i)))
|
|
227
|
+
throw n("ENOENT", "mkdir", this.shown(r));
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
yield this.adapter.createDirectory(this.relative(r));
|
|
231
|
+
} catch (e) {
|
|
232
|
+
throw this.mapError(e, "mkdir", r);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
readdirWithFileTypes(r) {
|
|
237
|
+
return s(this, null, function* () {
|
|
238
|
+
if ((yield this.entry(r, "scandir")).kind !== "directory")
|
|
239
|
+
throw n("ENOTDIR", "scandir", this.shown(r));
|
|
240
|
+
let e;
|
|
241
|
+
try {
|
|
242
|
+
e = yield this.adapter.listEntries(this.relative(r));
|
|
243
|
+
} catch (i) {
|
|
244
|
+
if (this.isRoot(r) && w(i) === "NotFoundError")
|
|
245
|
+
return [];
|
|
246
|
+
throw this.mapError(i, "scandir", r);
|
|
247
|
+
}
|
|
248
|
+
return e.map((i) => ({
|
|
249
|
+
name: i.name,
|
|
250
|
+
isFile: i.kind === "file",
|
|
251
|
+
isDirectory: i.kind === "directory",
|
|
252
|
+
isSymbolicLink: !1
|
|
253
|
+
})).sort((i, o) => i.name < o.name ? -1 : i.name > o.name ? 1 : 0);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
readdir(r) {
|
|
257
|
+
return s(this, null, function* () {
|
|
258
|
+
return (yield this.readdirWithFileTypes(r)).map((t) => t.name);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
rm(r, t) {
|
|
262
|
+
return s(this, null, function* () {
|
|
263
|
+
if (this.isRoot(r))
|
|
264
|
+
throw n("EPERM", "rm", this.shown(r));
|
|
265
|
+
const e = this.guard(r, "write", "rm");
|
|
266
|
+
if (!(yield this.exists(r))) {
|
|
267
|
+
if (t != null && t.force)
|
|
268
|
+
return;
|
|
269
|
+
throw n("ENOENT", "rm", this.shown(r));
|
|
270
|
+
}
|
|
271
|
+
if (!this.adapter.remove)
|
|
272
|
+
throw n("EPERM", "rm", this.shown(r));
|
|
273
|
+
try {
|
|
274
|
+
yield this.adapter.remove(e, {
|
|
275
|
+
recursive: (t == null ? void 0 : t.recursive) === !0
|
|
276
|
+
});
|
|
277
|
+
} catch (i) {
|
|
278
|
+
throw this.mapError(i, "rm", r);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
cp(r, t, e) {
|
|
283
|
+
return s(this, null, function* () {
|
|
284
|
+
if ((yield this.entry(r, "cp")).kind === "file") {
|
|
285
|
+
yield this.writeFile(t, yield this.readFileBuffer(r));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (!(e != null && e.recursive))
|
|
289
|
+
throw n("EISDIR", "cp", this.shown(r));
|
|
290
|
+
yield this.mkdir(t, {
|
|
291
|
+
recursive: !0
|
|
292
|
+
});
|
|
293
|
+
for (const o of yield this.readdir(r))
|
|
294
|
+
yield this.cp(`${h(r)}/${o}`, `${h(t)}/${o}`, e);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
mv(r, t) {
|
|
298
|
+
return s(this, null, function* () {
|
|
299
|
+
if (this.isRoot(r) || this.isRoot(t))
|
|
300
|
+
throw n("EPERM", "rename", this.shown(r));
|
|
301
|
+
const e = this.guard(r, "write", "rename"), i = this.guard(t, "write", "rename");
|
|
302
|
+
if (!this.adapter.move)
|
|
303
|
+
throw n("EPERM", "rename", this.shown(r));
|
|
304
|
+
try {
|
|
305
|
+
yield this.adapter.move(e, i);
|
|
306
|
+
} catch (o) {
|
|
307
|
+
throw this.mapError(o, "rename", r);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
resolvePath(r, t) {
|
|
312
|
+
return h(t.startsWith("/") ? t : `${r}/${t}`);
|
|
313
|
+
}
|
|
314
|
+
getAllPaths() {
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
chmod(r) {
|
|
318
|
+
return s(this, null, function* () {
|
|
319
|
+
yield this.entry(r, "chmod");
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
symlink(r, t) {
|
|
323
|
+
return s(this, null, function* () {
|
|
324
|
+
throw n("EPERM", "symlink", this.shown(t));
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
link(r, t) {
|
|
328
|
+
return s(this, null, function* () {
|
|
329
|
+
throw n("EPERM", "link", this.shown(t));
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
readlink(r) {
|
|
333
|
+
return s(this, null, function* () {
|
|
334
|
+
throw yield this.entry(r, "readlink"), n("EINVAL", "readlink", this.shown(r));
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
realpath(r) {
|
|
338
|
+
return s(this, null, function* () {
|
|
339
|
+
return yield this.entry(r, "realpath"), h(r);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
utimes(r) {
|
|
343
|
+
return s(this, null, function* () {
|
|
344
|
+
yield this.entry(r, "utime");
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
export {
|
|
349
|
+
k as WorkspaceBashFs
|
|
350
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const o = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/", s = "3.6.0", n = `${o}just-bash/${s}/just-bash.mjs`, t = "314.0.7", _ = `${o}pyodide/${t}/`, c = ["numpy", "pandas", "matplotlib", "pillow", "lxml"];
|
|
2
|
+
export {
|
|
3
|
+
o as CDN_LIBS_ROOT,
|
|
4
|
+
n as DEFAULT_BASH_MODULE_URL,
|
|
5
|
+
_ as DEFAULT_PYODIDE_INDEX_URL,
|
|
6
|
+
s as JUST_BASH_VERSION,
|
|
7
|
+
c as PYODIDE_PACKAGES,
|
|
8
|
+
t as PYODIDE_VERSION
|
|
9
|
+
};
|