@blaxel/core 0.2.10-dev.85 → 0.2.10-dev1
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 +1 -1
- package/dist/authentication/index.js +2 -4
- package/dist/cache/index.js +0 -1
- package/dist/common/env.js +6 -4
- package/dist/common/internal.js +1 -0
- package/dist/common/node.d.ts +2 -1
- package/dist/common/node.js +4 -1
- package/dist/jobs/batches.d.ts +32 -0
- package/dist/jobs/batches.js +40 -0
- package/dist/jobs/job.d.ts +33 -0
- package/dist/jobs/job.js +51 -0
- package/dist/jobs/jobs.js +1 -1
- package/dist/mcp/client.d.ts +2 -0
- package/dist/mcp/client.js +115 -52
- package/dist/sandbox/action.js +3 -3
- package/dist/sandbox/filesystem/filesystem.d.ts +1 -3
- package/dist/sandbox/filesystem/filesystem.js +0 -151
- package/dist/sandbox/filesystem/types.d.ts +0 -113
- package/dist/sandbox/filesystem/types.js +0 -24
- package/dist/sandbox/filesystem.d.ts +30 -0
- package/dist/sandbox/filesystem.js +207 -0
- package/dist/sandbox/network.d.ts +5 -0
- package/dist/sandbox/network.js +10 -0
- package/dist/sandbox/process/index.d.ts +0 -1
- package/dist/sandbox/process/index.js +0 -1
- package/dist/sandbox/process/process.d.ts +0 -3
- package/dist/sandbox/process/process.js +0 -128
- package/dist/sandbox/process.d.ts +23 -0
- package/dist/sandbox/process.js +138 -0
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +2 -2
- package/dist/tools/mcpTool.d.ts +3 -1
- package/dist/tools/mcpTool.js +16 -8
- package/package.json +1 -1
|
@@ -9,7 +9,6 @@ const node_js_1 = require("../../common/node.js");
|
|
|
9
9
|
const settings_js_1 = require("../../common/settings.js");
|
|
10
10
|
const action_js_1 = require("../action.js");
|
|
11
11
|
const index_js_1 = require("../client/index.js");
|
|
12
|
-
const types_js_1 = require("./types.js");
|
|
13
12
|
class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
14
13
|
constructor(sandbox) {
|
|
15
14
|
super(sandbox);
|
|
@@ -290,155 +289,5 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
290
289
|
}
|
|
291
290
|
return path;
|
|
292
291
|
}
|
|
293
|
-
get toolsWithoutExecute() {
|
|
294
|
-
return {
|
|
295
|
-
cp: {
|
|
296
|
-
description: "Copy a file or directory",
|
|
297
|
-
parameters: types_js_1.CpParamsSchema,
|
|
298
|
-
},
|
|
299
|
-
mkdir: {
|
|
300
|
-
description: "Create a directory",
|
|
301
|
-
parameters: types_js_1.MkdirParamsSchema,
|
|
302
|
-
},
|
|
303
|
-
ls: {
|
|
304
|
-
description: "List a directory",
|
|
305
|
-
parameters: types_js_1.LsParamsSchema,
|
|
306
|
-
},
|
|
307
|
-
rm: {
|
|
308
|
-
description: "Remove a file or directory",
|
|
309
|
-
parameters: types_js_1.RmParamsSchema,
|
|
310
|
-
},
|
|
311
|
-
read: {
|
|
312
|
-
description: "Read a file",
|
|
313
|
-
parameters: types_js_1.ReadParamsSchema,
|
|
314
|
-
},
|
|
315
|
-
write: {
|
|
316
|
-
description: "Write a file",
|
|
317
|
-
parameters: types_js_1.WriteParamsSchema,
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
get tools() {
|
|
322
|
-
return {
|
|
323
|
-
cp: {
|
|
324
|
-
description: "Copy a file or directory",
|
|
325
|
-
parameters: types_js_1.CpParamsSchema,
|
|
326
|
-
execute: async (args) => {
|
|
327
|
-
try {
|
|
328
|
-
const result = await this.cp(args.source, args.destination);
|
|
329
|
-
return JSON.stringify(result);
|
|
330
|
-
}
|
|
331
|
-
catch (e) {
|
|
332
|
-
if (e instanceof Error) {
|
|
333
|
-
return JSON.stringify({
|
|
334
|
-
message: e.message,
|
|
335
|
-
source: args.source,
|
|
336
|
-
destination: args.destination
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
return "An unknown error occurred";
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
mkdir: {
|
|
344
|
-
description: "Create a directory",
|
|
345
|
-
parameters: types_js_1.MkdirParamsSchema,
|
|
346
|
-
execute: async (args) => {
|
|
347
|
-
try {
|
|
348
|
-
const result = await this.mkdir(args.path, args.permissions);
|
|
349
|
-
return JSON.stringify(result);
|
|
350
|
-
}
|
|
351
|
-
catch (e) {
|
|
352
|
-
if (e instanceof Error) {
|
|
353
|
-
return JSON.stringify({
|
|
354
|
-
message: e.message,
|
|
355
|
-
path: args.path,
|
|
356
|
-
permissions: args.permissions
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
return "An unknown error occurred";
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
},
|
|
363
|
-
ls: {
|
|
364
|
-
description: "List a directory",
|
|
365
|
-
parameters: types_js_1.LsParamsSchema,
|
|
366
|
-
execute: async (args) => {
|
|
367
|
-
try {
|
|
368
|
-
const result = await this.ls(args.path);
|
|
369
|
-
return JSON.stringify(result);
|
|
370
|
-
}
|
|
371
|
-
catch (e) {
|
|
372
|
-
if (e instanceof Error) {
|
|
373
|
-
return JSON.stringify({
|
|
374
|
-
message: e.message,
|
|
375
|
-
path: args.path
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
return "An unknown error occurred";
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
rm: {
|
|
383
|
-
description: "Remove a file or directory",
|
|
384
|
-
parameters: types_js_1.RmParamsSchema,
|
|
385
|
-
execute: async (args) => {
|
|
386
|
-
try {
|
|
387
|
-
const result = await this.rm(args.path, args.recursive);
|
|
388
|
-
return JSON.stringify(result);
|
|
389
|
-
}
|
|
390
|
-
catch (e) {
|
|
391
|
-
if (e instanceof Error) {
|
|
392
|
-
return JSON.stringify({
|
|
393
|
-
message: e.message,
|
|
394
|
-
path: args.path,
|
|
395
|
-
recursive: args.recursive
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
return "An unknown error occurred";
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
read: {
|
|
403
|
-
description: "Read a file",
|
|
404
|
-
parameters: types_js_1.ReadParamsSchema,
|
|
405
|
-
execute: async (args) => {
|
|
406
|
-
try {
|
|
407
|
-
const result = await this.read(args.path);
|
|
408
|
-
return JSON.stringify(result);
|
|
409
|
-
}
|
|
410
|
-
catch (e) {
|
|
411
|
-
if (e instanceof Error) {
|
|
412
|
-
return JSON.stringify({
|
|
413
|
-
message: e.message,
|
|
414
|
-
path: args.path
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
return "An unknown error occurred";
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
},
|
|
421
|
-
write: {
|
|
422
|
-
description: "Write a file",
|
|
423
|
-
parameters: types_js_1.WriteParamsSchema,
|
|
424
|
-
execute: async (args) => {
|
|
425
|
-
try {
|
|
426
|
-
const result = await this.write(args.path, args.content);
|
|
427
|
-
return JSON.stringify(result);
|
|
428
|
-
}
|
|
429
|
-
catch (e) {
|
|
430
|
-
if (e instanceof Error) {
|
|
431
|
-
return JSON.stringify({
|
|
432
|
-
message: e.message,
|
|
433
|
-
path: args.path,
|
|
434
|
-
content: args.content
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return "An unknown error occurred";
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
292
|
}
|
|
444
293
|
exports.SandboxFileSystem = SandboxFileSystem;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
export type CopyResponse = {
|
|
3
2
|
message: string;
|
|
4
3
|
source: string;
|
|
@@ -14,115 +13,3 @@ export type SandboxFilesystemFile = {
|
|
|
14
13
|
path: string;
|
|
15
14
|
content: string;
|
|
16
15
|
};
|
|
17
|
-
export declare const CpParamsSchema: z.ZodObject<{
|
|
18
|
-
source: z.ZodString;
|
|
19
|
-
destination: z.ZodString;
|
|
20
|
-
}, "strip", z.ZodTypeAny, {
|
|
21
|
-
source: string;
|
|
22
|
-
destination: string;
|
|
23
|
-
}, {
|
|
24
|
-
source: string;
|
|
25
|
-
destination: string;
|
|
26
|
-
}>;
|
|
27
|
-
export declare const MkdirParamsSchema: z.ZodObject<{
|
|
28
|
-
path: z.ZodString;
|
|
29
|
-
permissions: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
30
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
-
path: string;
|
|
32
|
-
permissions: string;
|
|
33
|
-
}, {
|
|
34
|
-
path: string;
|
|
35
|
-
permissions?: string | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
export declare const LsParamsSchema: z.ZodObject<{
|
|
38
|
-
path: z.ZodString;
|
|
39
|
-
}, "strip", z.ZodTypeAny, {
|
|
40
|
-
path: string;
|
|
41
|
-
}, {
|
|
42
|
-
path: string;
|
|
43
|
-
}>;
|
|
44
|
-
export declare const RmParamsSchema: z.ZodObject<{
|
|
45
|
-
path: z.ZodString;
|
|
46
|
-
recursive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
47
|
-
}, "strip", z.ZodTypeAny, {
|
|
48
|
-
path: string;
|
|
49
|
-
recursive: boolean;
|
|
50
|
-
}, {
|
|
51
|
-
path: string;
|
|
52
|
-
recursive?: boolean | undefined;
|
|
53
|
-
}>;
|
|
54
|
-
export declare const ReadParamsSchema: z.ZodObject<{
|
|
55
|
-
path: z.ZodString;
|
|
56
|
-
}, "strip", z.ZodTypeAny, {
|
|
57
|
-
path: string;
|
|
58
|
-
}, {
|
|
59
|
-
path: string;
|
|
60
|
-
}>;
|
|
61
|
-
export declare const WriteParamsSchema: z.ZodObject<{
|
|
62
|
-
path: z.ZodString;
|
|
63
|
-
content: z.ZodString;
|
|
64
|
-
}, "strip", z.ZodTypeAny, {
|
|
65
|
-
path: string;
|
|
66
|
-
content: string;
|
|
67
|
-
}, {
|
|
68
|
-
path: string;
|
|
69
|
-
content: string;
|
|
70
|
-
}>;
|
|
71
|
-
export type ToolWithoutExecute = {
|
|
72
|
-
cp: {
|
|
73
|
-
description: string;
|
|
74
|
-
parameters: typeof CpParamsSchema;
|
|
75
|
-
};
|
|
76
|
-
mkdir: {
|
|
77
|
-
description: string;
|
|
78
|
-
parameters: typeof MkdirParamsSchema;
|
|
79
|
-
};
|
|
80
|
-
ls: {
|
|
81
|
-
description: string;
|
|
82
|
-
parameters: typeof LsParamsSchema;
|
|
83
|
-
};
|
|
84
|
-
rm: {
|
|
85
|
-
description: string;
|
|
86
|
-
parameters: typeof RmParamsSchema;
|
|
87
|
-
};
|
|
88
|
-
read: {
|
|
89
|
-
description: string;
|
|
90
|
-
parameters: typeof ReadParamsSchema;
|
|
91
|
-
};
|
|
92
|
-
write: {
|
|
93
|
-
description: string;
|
|
94
|
-
parameters: typeof WriteParamsSchema;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
export type ToolWithExecute = {
|
|
98
|
-
cp: {
|
|
99
|
-
description: string;
|
|
100
|
-
parameters: typeof CpParamsSchema;
|
|
101
|
-
execute: (args: z.infer<typeof CpParamsSchema>) => Promise<string>;
|
|
102
|
-
};
|
|
103
|
-
mkdir: {
|
|
104
|
-
description: string;
|
|
105
|
-
parameters: typeof MkdirParamsSchema;
|
|
106
|
-
execute: (args: z.infer<typeof MkdirParamsSchema>) => Promise<string>;
|
|
107
|
-
};
|
|
108
|
-
ls: {
|
|
109
|
-
description: string;
|
|
110
|
-
parameters: typeof LsParamsSchema;
|
|
111
|
-
execute: (args: z.infer<typeof LsParamsSchema>) => Promise<string>;
|
|
112
|
-
};
|
|
113
|
-
rm: {
|
|
114
|
-
description: string;
|
|
115
|
-
parameters: typeof RmParamsSchema;
|
|
116
|
-
execute: (args: z.infer<typeof RmParamsSchema>) => Promise<string>;
|
|
117
|
-
};
|
|
118
|
-
read: {
|
|
119
|
-
description: string;
|
|
120
|
-
parameters: typeof ReadParamsSchema;
|
|
121
|
-
execute: (args: z.infer<typeof ReadParamsSchema>) => Promise<string>;
|
|
122
|
-
};
|
|
123
|
-
write: {
|
|
124
|
-
description: string;
|
|
125
|
-
parameters: typeof WriteParamsSchema;
|
|
126
|
-
execute: (args: z.infer<typeof WriteParamsSchema>) => Promise<string>;
|
|
127
|
-
};
|
|
128
|
-
};
|
|
@@ -1,26 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WriteParamsSchema = exports.ReadParamsSchema = exports.RmParamsSchema = exports.LsParamsSchema = exports.MkdirParamsSchema = exports.CpParamsSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
exports.CpParamsSchema = zod_1.z.object({
|
|
6
|
-
source: zod_1.z.string().describe("Source file or directory path"),
|
|
7
|
-
destination: zod_1.z.string().describe("Destination file or directory path"),
|
|
8
|
-
}).describe("Parameters for copying a file or directory");
|
|
9
|
-
exports.MkdirParamsSchema = zod_1.z.object({
|
|
10
|
-
path: zod_1.z.string().describe("Directory path to create"),
|
|
11
|
-
permissions: zod_1.z.string().optional().default("0755").describe("Permissions for the new directory (default 0755)"),
|
|
12
|
-
}).describe("Parameters for creating a directory");
|
|
13
|
-
exports.LsParamsSchema = zod_1.z.object({
|
|
14
|
-
path: zod_1.z.string().describe("Directory path to list"),
|
|
15
|
-
}).describe("Parameters for listing a directory");
|
|
16
|
-
exports.RmParamsSchema = zod_1.z.object({
|
|
17
|
-
path: zod_1.z.string().describe("File or directory path to remove"),
|
|
18
|
-
recursive: zod_1.z.boolean().optional().default(false).describe("Whether to remove recursively (default false)"),
|
|
19
|
-
}).describe("Parameters for removing a file or directory");
|
|
20
|
-
exports.ReadParamsSchema = zod_1.z.object({
|
|
21
|
-
path: zod_1.z.string().describe("File path to read"),
|
|
22
|
-
}).describe("Parameters for reading a file");
|
|
23
|
-
exports.WriteParamsSchema = zod_1.z.object({
|
|
24
|
-
path: zod_1.z.string().describe("File path to write to"),
|
|
25
|
-
content: zod_1.z.string().describe("Content to write to the file"),
|
|
26
|
-
}).describe("Parameters for writing to a file");
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Sandbox } from "../client/types.gen.js";
|
|
2
|
+
import { SandboxAction } from "./action.js";
|
|
3
|
+
import { Directory, SuccessResponse } from "./client/index.js";
|
|
4
|
+
export type CopyResponse = {
|
|
5
|
+
message: string;
|
|
6
|
+
source: string;
|
|
7
|
+
destination: string;
|
|
8
|
+
};
|
|
9
|
+
export type WatchEvent = {
|
|
10
|
+
op: "CREATE" | "WRITE" | "REMOVE";
|
|
11
|
+
path: string;
|
|
12
|
+
name: string;
|
|
13
|
+
content?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class SandboxFileSystem extends SandboxAction {
|
|
16
|
+
constructor(sandbox: Sandbox);
|
|
17
|
+
mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
|
|
18
|
+
write(path: string, content: string): Promise<SuccessResponse>;
|
|
19
|
+
read(path: string): Promise<string>;
|
|
20
|
+
rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
|
|
21
|
+
ls(path: string): Promise<Directory>;
|
|
22
|
+
cp(source: string, destination: string): Promise<CopyResponse>;
|
|
23
|
+
watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
withContent: boolean;
|
|
26
|
+
}): {
|
|
27
|
+
close: () => void;
|
|
28
|
+
};
|
|
29
|
+
private formatPath;
|
|
30
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxFileSystem = void 0;
|
|
4
|
+
const action_js_1 = require("./action.js");
|
|
5
|
+
const index_js_1 = require("./client/index.js");
|
|
6
|
+
class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
7
|
+
constructor(sandbox) {
|
|
8
|
+
super(sandbox);
|
|
9
|
+
}
|
|
10
|
+
async mkdir(path, permissions = "0755") {
|
|
11
|
+
path = this.formatPath(path);
|
|
12
|
+
const { response, data, error } = await (0, index_js_1.putFilesystemByPath)({
|
|
13
|
+
path: { path },
|
|
14
|
+
body: { isDirectory: true, permissions },
|
|
15
|
+
baseUrl: this.url,
|
|
16
|
+
client: this.client,
|
|
17
|
+
});
|
|
18
|
+
this.handleResponseError(response, data, error);
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
async write(path, content) {
|
|
22
|
+
path = this.formatPath(path);
|
|
23
|
+
const { response, data, error } = await (0, index_js_1.putFilesystemByPath)({
|
|
24
|
+
path: { path },
|
|
25
|
+
body: { content },
|
|
26
|
+
baseUrl: this.url,
|
|
27
|
+
client: this.client,
|
|
28
|
+
});
|
|
29
|
+
this.handleResponseError(response, data, error);
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
async read(path) {
|
|
33
|
+
path = this.formatPath(path);
|
|
34
|
+
const { response, data, error } = await (0, index_js_1.getFilesystemByPath)({
|
|
35
|
+
path: { path },
|
|
36
|
+
baseUrl: this.url,
|
|
37
|
+
client: this.client,
|
|
38
|
+
});
|
|
39
|
+
this.handleResponseError(response, data, error);
|
|
40
|
+
if (data && 'content' in data) {
|
|
41
|
+
return data.content;
|
|
42
|
+
}
|
|
43
|
+
throw new Error("Unsupported file type");
|
|
44
|
+
}
|
|
45
|
+
async rm(path, recursive = false) {
|
|
46
|
+
path = this.formatPath(path);
|
|
47
|
+
const { response, data, error } = await (0, index_js_1.deleteFilesystemByPath)({
|
|
48
|
+
path: { path },
|
|
49
|
+
query: { recursive },
|
|
50
|
+
baseUrl: this.url,
|
|
51
|
+
client: this.client,
|
|
52
|
+
});
|
|
53
|
+
this.handleResponseError(response, data, error);
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
async ls(path) {
|
|
57
|
+
path = this.formatPath(path);
|
|
58
|
+
const { response, data, error } = await (0, index_js_1.getFilesystemByPath)({
|
|
59
|
+
path: { path },
|
|
60
|
+
baseUrl: this.url,
|
|
61
|
+
client: this.client,
|
|
62
|
+
});
|
|
63
|
+
this.handleResponseError(response, data, error);
|
|
64
|
+
if (!data || !('files' in data || 'subdirectories' in data)) {
|
|
65
|
+
throw new Error(JSON.stringify({ error: "Directory not found" }));
|
|
66
|
+
}
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
async cp(source, destination) {
|
|
70
|
+
source = this.formatPath(source);
|
|
71
|
+
destination = this.formatPath(destination);
|
|
72
|
+
const { response, data, error } = await (0, index_js_1.getFilesystemByPath)({
|
|
73
|
+
path: { path: source },
|
|
74
|
+
baseUrl: this.url,
|
|
75
|
+
client: this.client,
|
|
76
|
+
});
|
|
77
|
+
this.handleResponseError(response, data, error);
|
|
78
|
+
if (data && ('files' in data || 'subdirectories' in data)) {
|
|
79
|
+
// Create destination directory
|
|
80
|
+
await this.mkdir(destination);
|
|
81
|
+
// Process subdirectories in batches of 5
|
|
82
|
+
const subdirectories = data.subdirectories || [];
|
|
83
|
+
for (let i = 0; i < subdirectories.length; i += 5) {
|
|
84
|
+
const batch = subdirectories.slice(i, i + 5);
|
|
85
|
+
await Promise.all(batch.map(async (subdir) => {
|
|
86
|
+
const sourcePath = subdir.path || `${source}/${subdir.path}`;
|
|
87
|
+
const destPath = `${destination}/${subdir.path}`;
|
|
88
|
+
await this.cp(sourcePath, destPath);
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
// Process files in batches of 10
|
|
92
|
+
const files = data.files || [];
|
|
93
|
+
for (let i = 0; i < files.length; i += 10) {
|
|
94
|
+
const batch = files.slice(i, i + 10);
|
|
95
|
+
await Promise.all(batch.map(async (file) => {
|
|
96
|
+
const sourcePath = file.path || `${source}/${file.path}`;
|
|
97
|
+
const destPath = `${destination}/${file.path}`;
|
|
98
|
+
const fileContent = await this.read(sourcePath);
|
|
99
|
+
if (typeof fileContent === 'string') {
|
|
100
|
+
await this.write(destPath, fileContent);
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
message: "Directory copied successfully",
|
|
106
|
+
source,
|
|
107
|
+
destination,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else if (data && 'content' in data) {
|
|
111
|
+
await this.write(destination, data.content);
|
|
112
|
+
return {
|
|
113
|
+
message: "File copied successfully",
|
|
114
|
+
source,
|
|
115
|
+
destination,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
throw new Error("Unsupported file type");
|
|
119
|
+
}
|
|
120
|
+
watch(path, callback, options) {
|
|
121
|
+
path = this.formatPath(path);
|
|
122
|
+
let closed = false;
|
|
123
|
+
let controller = new AbortController();
|
|
124
|
+
const start = async () => {
|
|
125
|
+
const { response, data, error } = await (0, index_js_1.getWatchFilesystemByPath)({
|
|
126
|
+
client: this.client,
|
|
127
|
+
path: { path },
|
|
128
|
+
baseUrl: this.url,
|
|
129
|
+
parseAs: 'stream',
|
|
130
|
+
signal: controller.signal,
|
|
131
|
+
});
|
|
132
|
+
if (error)
|
|
133
|
+
throw error;
|
|
134
|
+
const stream = data ?? response.body;
|
|
135
|
+
if (!stream)
|
|
136
|
+
throw new Error('No stream returned');
|
|
137
|
+
const reader = stream.getReader();
|
|
138
|
+
let buffer = '';
|
|
139
|
+
const decoder = new TextDecoder();
|
|
140
|
+
try {
|
|
141
|
+
while (!closed) {
|
|
142
|
+
const { value, done } = await reader.read();
|
|
143
|
+
if (done)
|
|
144
|
+
break;
|
|
145
|
+
buffer += decoder.decode(value, { stream: true });
|
|
146
|
+
let lines = buffer.split('\n');
|
|
147
|
+
buffer = lines.pop();
|
|
148
|
+
for (const line of lines) {
|
|
149
|
+
const trimmed = line.trim();
|
|
150
|
+
if (!trimmed)
|
|
151
|
+
continue;
|
|
152
|
+
const fileEvent = JSON.parse(line.trim());
|
|
153
|
+
if (options?.withContent && ["CREATE", "WRITE"].includes(fileEvent.op)) {
|
|
154
|
+
try {
|
|
155
|
+
let filePath = "";
|
|
156
|
+
if (fileEvent.path.endsWith("/")) {
|
|
157
|
+
filePath = fileEvent.path + fileEvent.name;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
filePath = fileEvent.path + "/" + fileEvent.name;
|
|
161
|
+
}
|
|
162
|
+
const content = await this.read(filePath);
|
|
163
|
+
await callback({ ...fileEvent, content });
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
console.log(e);
|
|
167
|
+
await callback({ ...fileEvent, content: undefined });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
await callback(fileEvent);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
reader.releaseLock();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
start().catch((err) => {
|
|
181
|
+
// Suppress AbortError when closing
|
|
182
|
+
if (!(err && err.name === 'AbortError')) {
|
|
183
|
+
if (options?.onError) {
|
|
184
|
+
options.onError(err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
closed = true;
|
|
188
|
+
controller?.abort();
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
close: () => {
|
|
192
|
+
closed = true;
|
|
193
|
+
controller?.abort();
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
formatPath(path) {
|
|
198
|
+
if (path === "/") {
|
|
199
|
+
return path;
|
|
200
|
+
}
|
|
201
|
+
if (path.startsWith("/")) {
|
|
202
|
+
path = path.slice(1);
|
|
203
|
+
}
|
|
204
|
+
return path;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.SandboxFileSystem = SandboxFileSystem;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxNetwork = void 0;
|
|
4
|
+
const action_js_1 = require("./action.js");
|
|
5
|
+
class SandboxNetwork extends action_js_1.SandboxAction {
|
|
6
|
+
constructor(sandbox) {
|
|
7
|
+
super(sandbox);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SandboxNetwork = SandboxNetwork;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Sandbox } from "../../client/types.gen.js";
|
|
2
2
|
import { SandboxAction } from "../action.js";
|
|
3
3
|
import { DeleteProcessByIdentifierKillResponse, DeleteProcessByIdentifierResponse, GetProcessByIdentifierResponse, GetProcessResponse, PostProcessResponse, ProcessRequest } from "../client/index.js";
|
|
4
|
-
import { ProcessToolWithExecute, ProcessToolWithoutExecute } from "./types.js";
|
|
5
4
|
export declare class SandboxProcess extends SandboxAction {
|
|
6
5
|
constructor(sandbox: Sandbox);
|
|
7
6
|
streamLogs(identifier: string, options: {
|
|
@@ -21,6 +20,4 @@ export declare class SandboxProcess extends SandboxAction {
|
|
|
21
20
|
stop(identifier: string): Promise<DeleteProcessByIdentifierResponse>;
|
|
22
21
|
kill(identifier: string): Promise<DeleteProcessByIdentifierKillResponse>;
|
|
23
22
|
logs(identifier: string, type?: "stdout" | "stderr" | "all"): Promise<string>;
|
|
24
|
-
get toolsWithoutExecute(): ProcessToolWithoutExecute;
|
|
25
|
-
get tools(): ProcessToolWithExecute;
|
|
26
23
|
}
|