@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.5
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 +572 -98
- package/dist/es/AgentSession.mjs +230 -165
- package/dist/es/BotClient.mjs +186 -136
- package/dist/es/Config.mjs +89 -26
- package/dist/es/Session.mjs +12 -0
- package/dist/es/api/index.mjs +42 -33
- 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 +236 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +63 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +471 -0
- package/dist/es/index.mjs +69 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +233 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
- package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
- package/dist/es/localFiles/constants.mjs +47 -0
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +54 -0
- package/dist/es/localFiles/host/protocol.mjs +27 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +312 -0
- package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
- package/dist/es/localFiles/security/glob.mjs +28 -0
- package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
- package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
- package/dist/es/localFiles/tools/readTools.mjs +333 -0
- package/dist/es/localFiles/tools/runtime.mjs +108 -0
- package/dist/es/localFiles/tools/transferTools.mjs +228 -0
- package/dist/es/localFiles/tools/writeTools.mjs +173 -0
- package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
- package/dist/es/localFiles/validate.mjs +66 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
- package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
- package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
- package/dist/es/package.json.mjs +38 -29
- package/dist/lib/index.js +373 -5
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +22 -0
- package/dist/src/Session.d.ts +5 -1
- package/dist/src/api/index.d.ts +3 -1
- 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 +26 -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 +15 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +60 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +43 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
- package/dist/src/localFiles/constants.d.ts +51 -0
- package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
- package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
- package/dist/src/localFiles/errors.d.ts +34 -0
- package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
- package/dist/src/localFiles/host/protocol.d.ts +46 -0
- package/dist/src/localFiles/index.d.ts +22 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +29 -0
- package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
- package/dist/src/localFiles/security/glob.d.ts +3 -0
- package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
- package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
- package/dist/src/localFiles/tools/readTools.d.ts +7 -0
- package/dist/src/localFiles/tools/runtime.d.ts +43 -0
- package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
- package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
- package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
- package/dist/src/localFiles/types.d.ts +319 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +13 -4
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const n = /* @__PURE__ */ new Map();
|
|
2
|
+
function i(t) {
|
|
3
|
+
return import(
|
|
4
|
+
/* @vite-ignore */
|
|
5
|
+
/* webpackIgnore: true */
|
|
6
|
+
t
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
function a(t) {
|
|
10
|
+
let e = n.get(t);
|
|
11
|
+
return e || (e = i(t).catch((o) => {
|
|
12
|
+
throw n.delete(t), o;
|
|
13
|
+
}), n.set(t, e)), e;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
a as loadBash
|
|
17
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const n = `# 在 Pyodide 里按 python3 命令行的语义运行代码。由 pyodideWorker.js 加载,最后一个表达式 run 交给 JS 调用。
|
|
2
|
+
# 解释器在多次命令之间复用,所以每次运行前恢复 sys.path、环境变量和工作目录,并丢掉工作区里的模块缓存。
|
|
3
|
+
import io
|
|
4
|
+
import os
|
|
5
|
+
import runpy
|
|
6
|
+
import sys
|
|
7
|
+
import traceback
|
|
8
|
+
|
|
9
|
+
ROOTS = ('/workspace',)
|
|
10
|
+
BASE_PATH = list(sys.path)
|
|
11
|
+
BASE_ENV = dict(os.environ)
|
|
12
|
+
HOME = os.environ.get('HOME', '/home/pyodide')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _from_workspace(module):
|
|
16
|
+
path = getattr(module, '__file__', None) or ''
|
|
17
|
+
return any(path == root or path.startswith(root + '/') for root in ROOTS)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _reset():
|
|
21
|
+
for name, module in list(sys.modules.items()):
|
|
22
|
+
if _from_workspace(module):
|
|
23
|
+
del sys.modules[name]
|
|
24
|
+
sys.path[:] = BASE_PATH
|
|
25
|
+
os.environ.clear()
|
|
26
|
+
os.environ.update(BASE_ENV)
|
|
27
|
+
os.chdir(HOME)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _internal(frame):
|
|
31
|
+
name = frame.f_code.co_filename
|
|
32
|
+
return name == '<exec>' or name.endswith('/runpy.py')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _print_error(error):
|
|
36
|
+
tb = error.__traceback__
|
|
37
|
+
while tb is not None and _internal(tb.tb_frame):
|
|
38
|
+
tb = tb.tb_next
|
|
39
|
+
traceback.print_exception(type(error), error, tb)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _exit_code(value):
|
|
43
|
+
if value is None:
|
|
44
|
+
return 0
|
|
45
|
+
if isinstance(value, int):
|
|
46
|
+
return value & 0xFF
|
|
47
|
+
print(value, file=sys.stderr)
|
|
48
|
+
return 1
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def run(mode, target, argv, cwd, stdin):
|
|
52
|
+
_reset()
|
|
53
|
+
sys.argv = list(argv)
|
|
54
|
+
sys.stdin = io.TextIOWrapper(io.BytesIO(stdin.to_bytes()), encoding='utf-8', errors='replace')
|
|
55
|
+
try:
|
|
56
|
+
os.chdir(cwd)
|
|
57
|
+
except OSError:
|
|
58
|
+
os.chdir('/')
|
|
59
|
+
try:
|
|
60
|
+
if mode == 'c':
|
|
61
|
+
sys.path.insert(0, '')
|
|
62
|
+
exec(compile(target, '<string>', 'exec'), {'__name__': '__main__'})
|
|
63
|
+
elif mode == 'm':
|
|
64
|
+
sys.path.insert(0, os.getcwd())
|
|
65
|
+
runpy.run_module(target, run_name='__main__', alter_sys=True)
|
|
66
|
+
elif not os.path.isfile(target):
|
|
67
|
+
print(f"python3: can't open file '{target}': [Errno 2] No such file or directory", file=sys.stderr)
|
|
68
|
+
return 2
|
|
69
|
+
else:
|
|
70
|
+
sys.path.insert(0, os.path.dirname(target))
|
|
71
|
+
runpy.run_path(target, run_name='__main__')
|
|
72
|
+
return 0
|
|
73
|
+
except SystemExit as error:
|
|
74
|
+
return _exit_code(error.code)
|
|
75
|
+
except ModuleNotFoundError as error:
|
|
76
|
+
_print_error(error)
|
|
77
|
+
name = (error.name or '').split('.')[0]
|
|
78
|
+
if name:
|
|
79
|
+
print(
|
|
80
|
+
f'浏览器环境没有 {name}。这里只能用标准库和 {"、".join(PACKAGES)},需要其他包请改用宿主环境。',
|
|
81
|
+
file=sys.stderr,
|
|
82
|
+
)
|
|
83
|
+
return 1
|
|
84
|
+
except BaseException as error:
|
|
85
|
+
_print_error(error)
|
|
86
|
+
return 1
|
|
87
|
+
finally:
|
|
88
|
+
sys.stdout.flush()
|
|
89
|
+
sys.stderr.flush()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
run
|
|
93
|
+
`;
|
|
94
|
+
export {
|
|
95
|
+
n as default
|
|
96
|
+
};
|