@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.8

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.
Files changed (60) hide show
  1. package/README.md +76 -105
  2. package/dist/es/AgentSession.mjs +32 -33
  3. package/dist/es/Config.mjs +85 -63
  4. package/dist/es/DialogSession.mjs +39 -40
  5. package/dist/es/Session.mjs +71 -63
  6. package/dist/es/index.mjs +48 -49
  7. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +103 -193
  8. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +77 -138
  9. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
  10. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
  11. package/dist/es/localFiles/constants.mjs +1 -1
  12. package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
  13. package/dist/es/localFiles/host/connectHostBridge.mjs +18 -22
  14. package/dist/es/localFiles/host/protocol.mjs +5 -6
  15. package/dist/es/localFiles/schemas.mjs +60 -45
  16. package/dist/es/localFiles/validate.mjs +37 -37
  17. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +52 -71
  18. package/dist/es/package.json.mjs +29 -38
  19. package/dist/lib/index.js +9 -372
  20. package/dist/src/Config.d.ts +2 -2
  21. package/dist/src/Session.d.ts +4 -0
  22. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
  23. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +1 -20
  24. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
  25. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -14
  26. package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
  27. package/dist/src/localFiles/constants.d.ts +1 -2
  28. package/dist/src/localFiles/host/protocol.d.ts +0 -13
  29. package/dist/src/localFiles/index.d.ts +2 -3
  30. package/dist/src/localFiles/schemas.d.ts +3 -2
  31. package/dist/src/localFiles/types.d.ts +1 -14
  32. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +0 -12
  33. package/package.json +4 -13
  34. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
  35. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
  36. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
  37. package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
  38. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
  39. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
  40. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
  41. package/dist/es/builtinTools/command.mjs +0 -56
  42. package/dist/es/builtinTools/constants.mjs +0 -10
  43. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -236
  44. package/dist/es/builtinTools/overview.mjs +0 -77
  45. package/dist/es/builtinTools/paths.mjs +0 -63
  46. package/dist/es/builtinTools/schemas.mjs +0 -216
  47. package/dist/es/builtinTools/tools.mjs +0 -471
  48. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
  49. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
  50. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
  51. package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
  52. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
  53. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
  54. package/dist/src/builtinTools/command.d.ts +0 -26
  55. package/dist/src/builtinTools/constants.d.ts +0 -17
  56. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
  57. package/dist/src/builtinTools/overview.d.ts +0 -5
  58. package/dist/src/builtinTools/paths.d.ts +0 -15
  59. package/dist/src/builtinTools/schemas.d.ts +0 -3
  60. package/dist/src/builtinTools/tools.d.ts +0 -60
@@ -1,471 +0,0 @@
1
- var l = (t, n, e) => new Promise((r, o) => {
2
- var c = (a) => {
3
- try {
4
- s(e.next(a));
5
- } catch (f) {
6
- o(f);
7
- }
8
- }, i = (a) => {
9
- try {
10
- s(e.throw(a));
11
- } catch (f) {
12
- o(f);
13
- }
14
- }, s = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(c, i);
15
- s((e = e.apply(t, n)).next());
16
- });
17
- import { throwIfAborted as x, ToolError as d, ToolCode as u } from "../localFiles/errors.mjs";
18
- import { looksBinary as g, utf8ByteLength as v, readBytes as j } from "../localFiles/tools/runtime.mjs";
19
- import { MAX_READ_BYTES as _, MAX_WRITE_BYTES as k, RUNNABLE_EXTENSIONS as A, SHELL_CWD as U } from "./constants.mjs";
20
- import { isImagePath as M, isPdf as I, isStructuredPath as z, structureOverview as W, extensionOf as X } from "./overview.mjs";
21
- import { resolveFilePath as m, resolveRunPath as Y, mentionsSyntheticDir as C, SYNTHETIC_DIR_MESSAGE as H, isSafeCwd as G, skillRelative as $, toVirtualPath as B } from "./paths.mjs";
22
- function E(t) {
23
- return !!t && typeof t == "object" && t.name === "NotFoundError";
24
- }
25
- function p(t) {
26
- try {
27
- return new TextDecoder("utf-8", {
28
- fatal: !0
29
- }).decode(t);
30
- } catch (n) {
31
- throw new d(u.BadRequest, "文件不是 UTF-8 文本。");
32
- }
33
- }
34
- function T(t) {
35
- return t === "" ? [] : (t.endsWith(`
36
- `) ? t.slice(0, -1) : t).split(`
37
- `);
38
- }
39
- function K(t, n, e) {
40
- if (n !== void 0 && e !== void 0 && e < n)
41
- throw new d(u.BadRequest, "end_line 不能小于 start_line。");
42
- const r = T(t), o = Math.max((n != null ? n : 1) - 1, 0), c = e != null ? e : r.length;
43
- return r.slice(o, c).join(`
44
- `);
45
- }
46
- function q(t) {
47
- if (v(t) <= _)
48
- return {
49
- text: t,
50
- truncated: !1
51
- };
52
- const n = new TextEncoder().encode(t);
53
- let e = _;
54
- for (; e > 0 && (n[e] & 192) === 128; )
55
- e -= 1;
56
- const r = new TextDecoder().decode(n.slice(0, e)), o = r.lastIndexOf(`
57
- `);
58
- return {
59
- text: o > 0 ? r.slice(0, o) : r,
60
- truncated: !0
61
- };
62
- }
63
- function y(t, n) {
64
- return l(this, null, function* () {
65
- const e = yield t.stat(n);
66
- if (e.kind !== "file")
67
- throw new d(u.BadRequest, "目标是目录,不是文件。");
68
- const r = yield j(yield t.readFile(n));
69
- return {
70
- entry: e,
71
- bytes: r
72
- };
73
- });
74
- }
75
- function L(t, n, e) {
76
- const r = typeof e == "number" ? `${e} 字节,` : "";
77
- return `${t},${r}路径 ${B(n)}。不返回正文。`;
78
- }
79
- function S(t) {
80
- const n = X(t);
81
- if (!A.includes(n))
82
- throw new d(u.BadRequest, "只能执行 .py、.sh 或 .js 文件。");
83
- return n === ".py" ? "python3" : n === ".js" ? "node" : "sh";
84
- }
85
- function N(t) {
86
- if (!t.runner)
87
- throw new d(u.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
88
- return t.runner;
89
- }
90
- function b(t, n, e, r) {
91
- return l(this, null, function* () {
92
- yield t.writeFile(n, e, {
93
- createDirectories: !0,
94
- signal: r
95
- });
96
- });
97
- }
98
- function at(t, n) {
99
- return l(this, null, function* () {
100
- const e = m(t.path);
101
- if (x(n.signal), M(e)) {
102
- const a = yield n.adapter.stat(e);
103
- if (a.kind !== "file")
104
- throw new d(u.BadRequest, "目标是目录,不是文件。");
105
- return {
106
- data: {
107
- content: L("图片", e, a.size),
108
- truncated: !1
109
- }
110
- };
111
- }
112
- const {
113
- entry: r,
114
- bytes: o
115
- } = yield y(n.adapter, e);
116
- if (I(e, o))
117
- return {
118
- data: {
119
- content: L("PDF", e, r.size),
120
- truncated: !1
121
- }
122
- };
123
- if (g(o))
124
- throw new d(u.BadRequest, "文件不是文本,无法读取正文。");
125
- const c = p(o);
126
- if (t.start_line !== void 0 || t.end_line !== void 0) {
127
- const a = K(c, t.start_line, t.end_line), f = q(a);
128
- return {
129
- data: {
130
- content: f.text,
131
- truncated: f.truncated
132
- }
133
- };
134
- }
135
- if (o.byteLength > _ && z(e))
136
- return {
137
- data: {
138
- content: W(e, c),
139
- truncated: !0
140
- }
141
- };
142
- const s = q(c);
143
- return {
144
- data: {
145
- content: s.text,
146
- truncated: s.truncated
147
- }
148
- };
149
- });
150
- }
151
- function it(t, n) {
152
- return l(this, null, function* () {
153
- const e = m(t.path);
154
- if (v(t.content) > k)
155
- throw new d(u.TooLarge, `content 按 UTF-8 计超过 ${k} 字节。请缩短后写入,或改用 append_file、edit_file。`);
156
- return x(n.signal), yield b(n.adapter, e, t.content, n.signal), {
157
- data: {}
158
- };
159
- });
160
- }
161
- function lt(t, n) {
162
- return l(this, null, function* () {
163
- const e = m(t.path);
164
- x(n.signal);
165
- let r = "";
166
- try {
167
- const {
168
- bytes: o
169
- } = yield y(n.adapter, e);
170
- if (g(o))
171
- throw new d(u.BadRequest, "文件不是文本,无法追加。");
172
- r = p(o);
173
- } catch (o) {
174
- if (!E(o))
175
- throw o;
176
- }
177
- return yield b(n.adapter, e, r + t.content, n.signal), {
178
- data: {}
179
- };
180
- });
181
- }
182
- function dt(t, n) {
183
- return l(this, null, function* () {
184
- const e = m(t.path);
185
- x(n.signal);
186
- const {
187
- bytes: r
188
- } = yield y(n.adapter, e);
189
- if (g(r))
190
- throw new d(u.BadRequest, "文件不是文本,无法修改。");
191
- const o = p(r), c = o.indexOf(t.old_text);
192
- if (c < 0) {
193
- const s = V(o, t.old_text);
194
- throw new d(u.BadRequest, `找不到与 old_text 完全相同的内容。最接近的原文从第 ${s.line} 行开始,可复制后重试:
195
- ${s.excerpt}`, {
196
- line: s.line,
197
- excerpt: s.excerpt
198
- });
199
- }
200
- const i = o.slice(0, c) + t.new_text + o.slice(c + t.old_text.length);
201
- return yield b(n.adapter, e, i, n.signal), {
202
- data: {}
203
- };
204
- });
205
- }
206
- function V(t, n) {
207
- var a;
208
- const e = T(t);
209
- if (e.length === 0)
210
- return {
211
- line: 1,
212
- excerpt: ""
213
- };
214
- const r = n.split(`
215
- `), o = ((a = r[0]) != null ? a : "").slice(0, 200);
216
- let c = 0, i = -1;
217
- for (let f = 0; f < e.length; f += 1) {
218
- const w = J(e[f], o);
219
- w > i && (i = w, c = f);
220
- }
221
- const s = Math.min(Math.max(r.length, 1), 8);
222
- return {
223
- line: c + 1,
224
- excerpt: e.slice(c, c + s).join(`
225
- `)
226
- };
227
- }
228
- function J(t, n) {
229
- if (!n)
230
- return 0;
231
- const e = t.toLowerCase(), r = n.toLowerCase();
232
- let o = 0, c = 0;
233
- for (const i of e)
234
- c < r.length && i === r[c] && (o += 1, c += 1);
235
- return o;
236
- }
237
- function Q(t) {
238
- let n = "";
239
- for (let e = 0; e < t.length; e += 1) {
240
- const r = t[e];
241
- if (r === "\\") {
242
- const o = t[e + 1];
243
- if (o === void 0) {
244
- n += "\\\\";
245
- continue;
246
- }
247
- e += 1, n += "+?|{}()".includes(o) ? `\\${o}` : o === "n" ? "\\n" : o === "t" ? "\\t" : R(o);
248
- continue;
249
- }
250
- if ("+?|{}()".includes(r)) {
251
- n += `\\${r}`;
252
- continue;
253
- }
254
- if (r === "[") {
255
- const o = t.indexOf("]", e + 1);
256
- if (o < 0) {
257
- n += "\\[";
258
- continue;
259
- }
260
- n += t.slice(e, o + 1), e = o;
261
- continue;
262
- }
263
- n += ".^$*".includes(r) ? r : R(r);
264
- }
265
- return new RegExp(n);
266
- }
267
- function R(t) {
268
- return /[\\^$.*+?()[\]{}|]/.test(t) ? `\\${t}` : t;
269
- }
270
- function Z(t) {
271
- try {
272
- return Q(t);
273
- } catch (n) {
274
- throw new d(u.BadRequest, "pattern 不是合法的 grep 基本正则。");
275
- }
276
- }
277
- function F(t, n, e, r, o) {
278
- return l(this, null, function* () {
279
- if (r > 16)
280
- return;
281
- x(e);
282
- const c = yield t.stat(n);
283
- if (yield o(n, c.kind), c.kind !== "directory")
284
- return;
285
- const i = yield t.listEntries(n, e);
286
- i.sort((s, a) => s.name < a.name ? -1 : s.name > a.name ? 1 : 0);
287
- for (const s of i) {
288
- const a = n ? `${n}/${s.name}` : s.name;
289
- yield F(t, a, e, r + 1, o);
290
- }
291
- });
292
- }
293
- function ut(t, n) {
294
- return l(this, null, function* () {
295
- const e = m(t.path), r = Z(t.pattern), o = [];
296
- yield F(n.adapter, e, n.signal, 0, (i, s) => l(this, null, function* () {
297
- if (s !== "file" || o.length >= 200)
298
- return;
299
- const {
300
- bytes: a
301
- } = yield y(n.adapter, i);
302
- if (g(a) || M(i) || I(i, a))
303
- return;
304
- let f;
305
- try {
306
- f = p(a);
307
- } catch (h) {
308
- return;
309
- }
310
- const w = T(f);
311
- for (let h = 0; h < w.length && o.length < 200; h += 1) {
312
- if (!r.test(w[h]))
313
- continue;
314
- const D = w[h].length > 500 ? `${w[h].slice(0, 500)}…` : w[h];
315
- o.push(`${B(i)}:${h + 1}:${D}`);
316
- }
317
- }));
318
- const c = o.join(`
319
- `);
320
- return {
321
- data: {
322
- matches: o.length >= 200 ? `${c}
323
- (匹配过多,已截断)` : c
324
- }
325
- };
326
- });
327
- }
328
- function tt(t, n) {
329
- let e = "^";
330
- for (let r = 0; r < t.length; r += 1) {
331
- const o = t[r];
332
- if (o === "*")
333
- e += ".*";
334
- else if (o === "?")
335
- e += ".";
336
- else if (o === "[") {
337
- const c = t.indexOf("]", r + 1);
338
- c < 0 ? e += "\\[" : (e += t.slice(r, c + 1), r = c);
339
- } else
340
- e += R(o);
341
- }
342
- return new RegExp(`${e}$`).test(n);
343
- }
344
- function ft(t, n) {
345
- return l(this, null, function* () {
346
- const e = m(t.path), r = [];
347
- yield F(n.adapter, e, n.signal, 0, (c) => l(this, null, function* () {
348
- var s;
349
- if (r.length >= 500)
350
- return;
351
- const i = (s = c.split("/").pop()) != null ? s : c;
352
- tt(t.name, i) && r.push(B(c));
353
- })), r.sort();
354
- const o = r.join(`
355
- `);
356
- return {
357
- data: {
358
- files: r.length >= 500 ? `${o}
359
- (结果过多,已截断)` : o
360
- }
361
- };
362
- });
363
- }
364
- function O(t, n, e) {
365
- return l(this, null, function* () {
366
- const r = N(e);
367
- yield y(e.adapter, t);
368
- const o = yield r.exec({
369
- argv: [S(t), t, ...n],
370
- cwd: U,
371
- timeoutMs: e.timeoutMs,
372
- signal: e.signal
373
- });
374
- return {
375
- data: {
376
- exitCode: o.exitCode,
377
- stdout: o.stdout,
378
- stderr: o.stderr
379
- }
380
- };
381
- });
382
- }
383
- function wt(t, n) {
384
- return l(this, null, function* () {
385
- const e = Y(t.path);
386
- return S(e), O(e, [], n);
387
- });
388
- }
389
- function ht(t, n) {
390
- return l(this, null, function* () {
391
- if (C(t.command) || C(n.shellCwd.cwd))
392
- return {
393
- data: {
394
- exitCode: 1,
395
- stdout: "",
396
- stderr: `${H}
397
- `
398
- }
399
- };
400
- const r = yield N(n).exec({
401
- command: t.command,
402
- cwd: n.shellCwd.cwd,
403
- timeoutMs: n.timeoutMs,
404
- signal: n.signal
405
- });
406
- return r.cwd && G(r.cwd) && (n.shellCwd.cwd = r.cwd), {
407
- data: {
408
- exitCode: r.exitCode,
409
- stdout: r.stdout,
410
- stderr: r.stderr
411
- }
412
- };
413
- });
414
- }
415
- function P(t, n) {
416
- return l(this, null, function* () {
417
- try {
418
- const {
419
- bytes: e
420
- } = yield y(n.adapter, t);
421
- if (g(e))
422
- throw new d(u.BadRequest, "技能资源不是文本。");
423
- return p(e);
424
- } catch (e) {
425
- throw E(e) ? new d(u.NotFound, "技能或资源不存在。") : e;
426
- }
427
- });
428
- }
429
- function mt(t, n) {
430
- return l(this, null, function* () {
431
- return {
432
- data: {
433
- content: yield P($(t.skill_name, "SKILL.md"), n)
434
- }
435
- };
436
- });
437
- }
438
- function yt(t, n) {
439
- return l(this, null, function* () {
440
- return {
441
- data: {
442
- content: yield P($(t.skill_name, t.resource_name), n)
443
- }
444
- };
445
- });
446
- }
447
- function xt(t, n) {
448
- return l(this, null, function* () {
449
- var r;
450
- const e = $(t.skill_name, t.script_name);
451
- S(e);
452
- try {
453
- return yield O(e, (r = t.args) != null ? r : [], n);
454
- } catch (o) {
455
- throw E(o) ? new d(u.NotFound, "技能脚本不存在。") : o;
456
- }
457
- });
458
- }
459
- export {
460
- lt as appendFile,
461
- dt as editFile,
462
- ft as find,
463
- ut as grep,
464
- mt as loadSkill,
465
- at as readFile,
466
- yt as readSkillResource,
467
- wt as runFile,
468
- xt as runSkillScript,
469
- ht as shell,
470
- it as writeFile
471
- };
@@ -1,26 +0,0 @@
1
- import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
- import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
- import { CommandRequest, CommandResult, CommandRunner } from '../command';
4
- import { WorkerLike } from './PythonRunner';
5
- export declare const NO_NODE_MESSAGE = "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 Node\uFF0C\u8BF7\u6539\u7528 python3 \u6216 shell \u547D\u4EE4\u3002\n";
6
- export interface BrowserCommandRunnerOptions {
7
- adapter: WorkspaceFileAdapter;
8
- sensitive: SensitiveFilePolicy;
9
- /** just-bash 浏览器构建的地址,默认 DEFAULT_BASH_MODULE_URL。 */
10
- moduleURL?: string;
11
- /** Pyodide 目录,默认 DEFAULT_PYODIDE_INDEX_URL。 */
12
- pyodideIndexURL?: string;
13
- createWorker?: (source: string) => WorkerLike;
14
- }
15
- /**
16
- * 纯网页里的命令执行器:just-bash 解释 shell,文件读写落到当前工作区。
17
- * 每条命令新建一个 shell,只有文件和 cwd 跨命令保留。
18
- */
19
- export declare class BrowserCommandRunner implements CommandRunner {
20
- private readonly options;
21
- private readonly python;
22
- constructor(options: BrowserCommandRunnerOptions);
23
- private load;
24
- private create;
25
- exec(request: CommandRequest): Promise<CommandResult>;
26
- }
@@ -1,67 +0,0 @@
1
- import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
2
- import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
3
- export declare const NO_PIP_MESSAGE: string;
4
- export declare const MAX_SYNC_FILE_BYTES: number;
5
- export declare const MAX_SYNC_TOTAL_BYTES: number;
6
- /** 把 shell 或工具传来的目录换成 Pyodide 里的工作区路径。 */
7
- export declare function toMount(cwd: string): string;
8
- /** Worker 的最小接口,测试里用 Node 的 worker_threads 实现。 */
9
- export interface WorkerLike {
10
- onmessage: ((event: {
11
- data: unknown;
12
- }) => void) | null;
13
- onerror: ((event: unknown) => void) | null;
14
- postMessage(message: unknown, transfer?: Transferable[]): void;
15
- terminate(): void;
16
- }
17
- export interface PythonRunnerOptions {
18
- adapter: WorkspaceFileAdapter;
19
- sensitive: SensitiveFilePolicy;
20
- /** Pyodide 目录,以 `/` 结尾,默认 DEFAULT_PYODIDE_INDEX_URL。 */
21
- indexURL?: string;
22
- createWorker?: (source: string) => WorkerLike;
23
- }
24
- export interface PythonRequest {
25
- /** `python3` 后面的参数。 */
26
- args: string[];
27
- /** shell 里的目录。`.` 或 `/workspace` 表示工作区根。 */
28
- cwd: string;
29
- stdin?: Uint8Array;
30
- signal?: AbortSignal;
31
- }
32
- export interface PythonResult {
33
- exitCode: number;
34
- stdout: string;
35
- stderr: string;
36
- }
37
- type Invocation = {
38
- mode: 'c' | 'm' | 'file';
39
- target: string;
40
- argv: string[];
41
- stdin: Uint8Array;
42
- };
43
- /** 按 python3 命令行解析参数;不需要启动解释器的情况直接给出结果。 */
44
- export declare function parsePythonArgs(args: string[], cwd: string, stdin: Uint8Array): Invocation | PythonResult;
45
- /**
46
- * 浏览器里的 python3:Pyodide 跑在专用 Worker 里,执行前把工作区文件快照同步进去,执行后把改动写回。
47
- * 同一时间只跑一个请求;超时或取消时终止 Worker,下次重新创建。
48
- */
49
- export declare class PythonRunner {
50
- private readonly options;
51
- private state?;
52
- private queue;
53
- private nextId;
54
- constructor(options: PythonRunnerOptions);
55
- private get indexURL();
56
- private loadError;
57
- private dispose;
58
- private spawn;
59
- run(request: PythonRequest): Promise<PythonResult>;
60
- private runNow;
61
- /** 执行前把整个工作区读进 Pyodide。 */
62
- private collect;
63
- private exists;
64
- /** 把 Python 里的改动写回工作区,返回是否有写回失败。 */
65
- private writeBack;
66
- }
67
- export {};
@@ -1,51 +0,0 @@
1
- import { BufferEncoding, CpOptions, FileContent, FsStat, IFileSystem, MkdirOptions, RmOptions } from 'just-bash/browser';
2
- import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
3
- import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
4
- type EncodingOption = {
5
- encoding?: BufferEncoding | null;
6
- } | BufferEncoding | undefined;
7
- interface DirentEntry {
8
- name: string;
9
- isFile: boolean;
10
- isDirectory: boolean;
11
- isSymbolicLink: boolean;
12
- }
13
- /**
14
- * 把工作区挂到 just-bash 的一个目录。root 为空表示整个工作区。
15
- * 收到的路径相对挂载点,以 `/` 开头。
16
- */
17
- export declare class WorkspaceBashFs implements IFileSystem {
18
- private readonly adapter;
19
- private readonly root;
20
- private readonly sensitive;
21
- constructor(adapter: WorkspaceFileAdapter, root: string, sensitive: SensitiveFilePolicy);
22
- private relative;
23
- private shown;
24
- private isRoot;
25
- private guard;
26
- private mapError;
27
- private entry;
28
- private ensureRoot;
29
- readFileBuffer(path: string): Promise<Uint8Array>;
30
- readFile(path: string, options?: EncodingOption): Promise<string>;
31
- writeFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
32
- appendFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
33
- exists(path: string): Promise<boolean>;
34
- stat(path: string): Promise<FsStat>;
35
- lstat(path: string): Promise<FsStat>;
36
- mkdir(path: string, options?: MkdirOptions): Promise<void>;
37
- readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
38
- readdir(path: string): Promise<string[]>;
39
- rm(path: string, options?: RmOptions): Promise<void>;
40
- cp(src: string, dest: string, options?: CpOptions): Promise<void>;
41
- mv(src: string, dest: string): Promise<void>;
42
- resolvePath(base: string, path: string): string;
43
- getAllPaths(): string[];
44
- chmod(path: string): Promise<void>;
45
- symlink(_target: string, linkPath: string): Promise<void>;
46
- link(_existingPath: string, newPath: string): Promise<void>;
47
- readlink(path: string): Promise<string>;
48
- realpath(path: string): Promise<string>;
49
- utimes(path: string): Promise<void>;
50
- }
51
- export {};
@@ -1,13 +0,0 @@
1
- /** 公司 OBS 上的前端依赖目录,按 `<包名>/<版本>/` 存放。 */
2
- export declare const CDN_LIBS_ROOT = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/";
3
- /** 必须与 package.json 里 just-bash 的版本一致;升级时先上传新版本目录。 */
4
- export declare const JUST_BASH_VERSION = "3.6.0";
5
- export declare const DEFAULT_BASH_MODULE_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/just-bash/3.6.0/just-bash.mjs";
6
- /** 必须与 package.json 里 pyodide 的版本一致;升级时先上传新版本目录。 */
7
- export declare const PYODIDE_VERSION = "314.0.7";
8
- export declare const DEFAULT_PYODIDE_INDEX_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/pyodide/314.0.7/";
9
- /**
10
- * 浏览器里可以 import 的第三方包,构建脚本按它们的依赖闭包上传 wheel 并改写 pyodide-lock.json。
11
- * 调整后需要重新构建并上传新的 Pyodide 目录。
12
- */
13
- export declare const PYODIDE_PACKAGES: string[];
@@ -1,3 +0,0 @@
1
- export type BashModule = typeof import('just-bash/browser');
2
- /** 第一次执行命令时才从 url 加载 just-bash,不进首屏。加载失败后下次重试。 */
3
- export declare function loadBash(url: string): Promise<BashModule>;
@@ -1,44 +0,0 @@
1
- /** Emscripten 的 ErrnoError 不是 Error,只带 errno 和 code。 */
2
- declare function describe(error: any): any;
3
- declare function networkDenied(url: any): TypeError;
4
- /** 只放行 indexURL 下的资源(Pyodide 自身和白名单 wheel),其余请求一律拒绝。 */
5
- declare function guardNetwork(indexURL: any): void;
6
- declare function collector(): {
7
- write(bytes: any): void;
8
- finish(): string;
9
- };
10
- declare function init({ indexURL, packages, runner }: {
11
- indexURL: any;
12
- packages: any;
13
- runner: any;
14
- }): Promise<void>;
15
- declare function dirname(path: any): any;
16
- /** 主脚本、`-c` 代码,以及主脚本目录和 cwd 下的 .py 文件里出现的 import。 */
17
- declare function sourcesToScan({ files, cwd, mode, target }: {
18
- files: any;
19
- cwd: any;
20
- mode: any;
21
- target: any;
22
- }): any[];
23
- declare function loadPackages(sources: any, stderr: any): Promise<void>;
24
- declare function lstat(path: any): any;
25
- declare function removeTree(path: any): void;
26
- declare function walk(path: any, files: any, dirs: any): void;
27
- declare function sameBytes(a: any, b: any): boolean;
28
- declare function execute(message: any): Promise<{
29
- exitCode: any;
30
- stdout: string;
31
- stderr: string;
32
- written: {
33
- path: any;
34
- data: any;
35
- }[];
36
- removed: any[];
37
- createdDirs: any[];
38
- removedDirs: string[];
39
- }>;
40
- declare const ROOTS: string[];
41
- declare const OUTPUT_LIMIT: number;
42
- declare let pyodide: null;
43
- declare let runPython: null;
44
- declare let sink: null;
@@ -1,26 +0,0 @@
1
- /** 在工作区里执行命令。由端侧宿主沙箱、浏览器运行时或测试注入实现。 */
2
- export interface CommandRequest {
3
- /** shell 命令。与 argv 二选一。 */
4
- command?: string;
5
- /** 直接执行的程序和参数,不经过 shell。 */
6
- argv?: string[];
7
- /** 工作区相对目录。`.` 表示工作区根。 */
8
- cwd: string;
9
- timeoutMs?: number;
10
- signal?: AbortSignal;
11
- }
12
- export interface CommandResult {
13
- exitCode: number;
14
- stdout: string;
15
- stderr: string;
16
- /** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
17
- cwd?: string;
18
- }
19
- export interface CommandRunner {
20
- exec(request: CommandRequest): Promise<CommandResult>;
21
- }
22
- /** stdout、stderr 各自返回给模型的字符上限。 */
23
- export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
24
- export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
25
- export declare function limitOutput(text: string): string;
26
- export declare function withOutputLimit(runner: CommandRunner): CommandRunner;