@daytonaio/sdk 0.16.0-alpha.2 → 0.16.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 +9 -9
- package/dist/Daytona.js +4 -1
- package/dist/FileSystem.d.ts +40 -28
- package/dist/FileSystem.js +57 -38
- package/dist/Git.d.ts +29 -21
- package/dist/Git.js +37 -28
- package/dist/LspServer.d.ts +13 -9
- package/dist/LspServer.js +18 -13
- package/dist/Process.d.ts +9 -6
- package/dist/Process.js +72 -28
- package/dist/Sandbox.d.ts +7 -3
- package/dist/Sandbox.js +16 -7
- package/dist/index.d.ts +0 -1
- package/dist/utils/Path.d.ts +1 -0
- package/dist/utils/Path.js +50 -0
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -99,12 +99,12 @@ console.log(response.result)
|
|
|
99
99
|
```typescript
|
|
100
100
|
// Upload a file
|
|
101
101
|
await sandbox.fs.uploadFile(
|
|
102
|
-
'
|
|
102
|
+
'path/to/file.txt',
|
|
103
103
|
new File([Buffer.from('Hello, World!')], 'file.txt', { type: 'text/plain' }),
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
// Download a file
|
|
107
|
-
const content = await sandbox.fs.downloadFile('
|
|
107
|
+
const content = await sandbox.fs.downloadFile('path/to/file.txt')
|
|
108
108
|
|
|
109
109
|
// Search for files
|
|
110
110
|
const matches = await sandbox.fs.findFiles(root_dir, 'search_pattern')
|
|
@@ -114,30 +114,30 @@ const matches = await sandbox.fs.findFiles(root_dir, 'search_pattern')
|
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
116
|
// Clone a repository
|
|
117
|
-
await sandbox.git.clone('https://github.com/example/repo', '
|
|
117
|
+
await sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')
|
|
118
118
|
|
|
119
119
|
// List branches
|
|
120
|
-
const branches = await sandbox.git.branches('
|
|
120
|
+
const branches = await sandbox.git.branches('path/to/repo')
|
|
121
121
|
|
|
122
122
|
// Add files
|
|
123
|
-
await sandbox.git.add('
|
|
123
|
+
await sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
### Language Server Protocol
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
129
|
// Create and start a language server
|
|
130
|
-
const lsp = sandbox.createLspServer('typescript', '
|
|
130
|
+
const lsp = await sandbox.createLspServer('typescript', 'path/to/project')
|
|
131
131
|
await lsp.start()
|
|
132
132
|
|
|
133
133
|
// Notify the lsp for the file
|
|
134
|
-
await lsp.didOpen('
|
|
134
|
+
await lsp.didOpen('path/to/file.ts')
|
|
135
135
|
|
|
136
136
|
// Get document symbols
|
|
137
|
-
const symbols = await lsp.documentSymbols('
|
|
137
|
+
const symbols = await lsp.documentSymbols('path/to/file.ts')
|
|
138
138
|
|
|
139
139
|
// Get completions
|
|
140
|
-
const completions = await lsp.completions('
|
|
140
|
+
const completions = await lsp.completions('path/to/file.ts', {
|
|
141
141
|
line: 10,
|
|
142
142
|
character: 15,
|
|
143
143
|
})
|
package/dist/Daytona.js
CHANGED
|
@@ -129,7 +129,9 @@ class Daytona {
|
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
131
|
});
|
|
132
|
-
const axiosInstance = axios_1.default.create(
|
|
132
|
+
const axiosInstance = axios_1.default.create({
|
|
133
|
+
timeout: 24 * 60 * 60 * 1000, // 24 hours
|
|
134
|
+
});
|
|
133
135
|
axiosInstance.interceptors.response.use((response) => {
|
|
134
136
|
return response;
|
|
135
137
|
}, (error) => {
|
|
@@ -465,6 +467,7 @@ class Daytona {
|
|
|
465
467
|
accessKeyId: pushAccessCreds.accessKey,
|
|
466
468
|
secretAccessKey: pushAccessCreds.secret,
|
|
467
469
|
sessionToken: pushAccessCreds.sessionToken,
|
|
470
|
+
bucketName: pushAccessCreds.bucket,
|
|
468
471
|
});
|
|
469
472
|
const contextHashes = [];
|
|
470
473
|
for (const context of image.contextList) {
|
package/dist/FileSystem.d.ts
CHANGED
|
@@ -44,52 +44,57 @@ export interface FileUpload {
|
|
|
44
44
|
export declare class FileSystem {
|
|
45
45
|
private readonly instance;
|
|
46
46
|
private readonly toolboxApi;
|
|
47
|
-
|
|
47
|
+
private readonly getRootDir;
|
|
48
|
+
constructor(instance: SandboxInstance, toolboxApi: ToolboxApi, getRootDir: () => Promise<string>);
|
|
48
49
|
/**
|
|
49
50
|
* Create a new directory in the Sandbox with specified permissions.
|
|
50
51
|
*
|
|
51
|
-
* @param {string} path - Path where the directory should be created
|
|
52
|
+
* @param {string} path - Path where the directory should be created. Relative paths are resolved based on the user's
|
|
53
|
+
* root directory.
|
|
52
54
|
* @param {string} mode - Directory permissions in octal format (e.g. "755")
|
|
53
55
|
* @returns {Promise<void>}
|
|
54
56
|
*
|
|
55
57
|
* @example
|
|
56
58
|
* // Create a directory with standard permissions
|
|
57
|
-
* await fs.createFolder('
|
|
59
|
+
* await fs.createFolder('app/data', '755');
|
|
58
60
|
*/
|
|
59
61
|
createFolder(path: string, mode: string): Promise<void>;
|
|
60
62
|
/**
|
|
61
63
|
* Deletes a file or directory from the Sandbox.
|
|
62
64
|
*
|
|
63
|
-
* @param {string} path - Path to the file or directory to delete
|
|
65
|
+
* @param {string} path - Path to the file or directory to delete. Relative paths are resolved based on the user's
|
|
66
|
+
* root directory.
|
|
64
67
|
* @returns {Promise<void>}
|
|
65
68
|
*
|
|
66
69
|
* @example
|
|
67
70
|
* // Delete a file
|
|
68
|
-
* await fs.deleteFile('
|
|
71
|
+
* await fs.deleteFile('app/temp.log');
|
|
69
72
|
*/
|
|
70
73
|
deleteFile(path: string): Promise<void>;
|
|
71
74
|
/**
|
|
72
75
|
* Downloads a file from the Sandbox.
|
|
73
76
|
*
|
|
74
|
-
* @param {string} path - Path to the file to download
|
|
77
|
+
* @param {string} path - Path to the file to download. Relative paths are resolved based on the user's
|
|
78
|
+
* root directory.
|
|
75
79
|
* @returns {Promise<Blob>} The file contents as a Blob
|
|
76
80
|
*
|
|
77
81
|
* @example
|
|
78
82
|
* // Download and process a file
|
|
79
|
-
* const fileBlob = await fs.downloadFile('
|
|
83
|
+
* const fileBlob = await fs.downloadFile('app/data.json');
|
|
80
84
|
* console.log('File content:', fileBlob.toString());
|
|
81
85
|
*/
|
|
82
86
|
downloadFile(path: string): Promise<Blob>;
|
|
83
87
|
/**
|
|
84
88
|
* Searches for text patterns within files in the Sandbox.
|
|
85
89
|
*
|
|
86
|
-
* @param {string} path - Directory to search in
|
|
90
|
+
* @param {string} path - Directory to search in. Relative paths are resolved based on the user's
|
|
91
|
+
* root directory.
|
|
87
92
|
* @param {string} pattern - Search pattern
|
|
88
93
|
* @returns {Promise<Array<Match>>} Array of matches with file and line information
|
|
89
94
|
*
|
|
90
95
|
* @example
|
|
91
96
|
* // Find all TODO comments in TypeScript files
|
|
92
|
-
* const matches = await fs.findFiles('
|
|
97
|
+
* const matches = await fs.findFiles('app/src', 'TODO:');
|
|
93
98
|
* matches.forEach(match => {
|
|
94
99
|
* console.log(`${match.file}:${match.line}: ${match.content}`);
|
|
95
100
|
* });
|
|
@@ -98,24 +103,26 @@ export declare class FileSystem {
|
|
|
98
103
|
/**
|
|
99
104
|
* Retrieves detailed information about a file or directory.
|
|
100
105
|
*
|
|
101
|
-
* @param {string} path - Path to the file or directory
|
|
106
|
+
* @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
|
|
107
|
+
* root directory.
|
|
102
108
|
* @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
|
|
103
109
|
*
|
|
104
110
|
* @example
|
|
105
111
|
* // Get file details
|
|
106
|
-
* const info = await fs.getFileDetails('
|
|
112
|
+
* const info = await fs.getFileDetails('app/config.json');
|
|
107
113
|
* console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
|
|
108
114
|
*/
|
|
109
115
|
getFileDetails(path: string): Promise<FileInfo>;
|
|
110
116
|
/**
|
|
111
117
|
* Lists contents of a directory in the Sandbox.
|
|
112
118
|
*
|
|
113
|
-
* @param {string} path - Directory path to list
|
|
119
|
+
* @param {string} path - Directory path to list. Relative paths are resolved based on the user's
|
|
120
|
+
* root directory.
|
|
114
121
|
* @returns {Promise<FileInfo[]>} Array of file and directory information
|
|
115
122
|
*
|
|
116
123
|
* @example
|
|
117
124
|
* // List directory contents
|
|
118
|
-
* const files = await fs.listFiles('
|
|
125
|
+
* const files = await fs.listFiles('app/src');
|
|
119
126
|
* files.forEach(file => {
|
|
120
127
|
* console.log(`${file.name} (${file.size} bytes)`);
|
|
121
128
|
* });
|
|
@@ -124,19 +131,21 @@ export declare class FileSystem {
|
|
|
124
131
|
/**
|
|
125
132
|
* Moves or renames a file or directory.
|
|
126
133
|
*
|
|
127
|
-
* @param {string} source - Source path
|
|
128
|
-
*
|
|
134
|
+
* @param {string} source - Source path. Relative paths are resolved based on the user's
|
|
135
|
+
* root directory.
|
|
136
|
+
* @param {string} destination - Destination path. Relative paths are resolved based on the user's
|
|
137
|
+
* root directory.
|
|
129
138
|
* @returns {Promise<void>}
|
|
130
139
|
*
|
|
131
140
|
* @example
|
|
132
141
|
* // Move a file to a new location
|
|
133
|
-
* await fs.moveFiles('
|
|
142
|
+
* await fs.moveFiles('app/temp/data.json', 'app/data/data.json');
|
|
134
143
|
*/
|
|
135
144
|
moveFiles(source: string, destination: string): Promise<void>;
|
|
136
145
|
/**
|
|
137
146
|
* Replaces text content in multiple files.
|
|
138
147
|
*
|
|
139
|
-
* @param {string[]} files - Array of file paths to process
|
|
148
|
+
* @param {string[]} files - Array of file paths to process. Relative paths are resolved based on the user's
|
|
140
149
|
* @param {string} pattern - Pattern to replace
|
|
141
150
|
* @param {string} newValue - Replacement text
|
|
142
151
|
* @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
|
|
@@ -144,7 +153,7 @@ export declare class FileSystem {
|
|
|
144
153
|
* @example
|
|
145
154
|
* // Update version number across multiple files
|
|
146
155
|
* const results = await fs.replaceInFiles(
|
|
147
|
-
* ['
|
|
156
|
+
* ['app/package.json', 'app/version.ts'],
|
|
148
157
|
* '"version": "1.0.0"',
|
|
149
158
|
* '"version": "1.1.0"'
|
|
150
159
|
* );
|
|
@@ -153,26 +162,27 @@ export declare class FileSystem {
|
|
|
153
162
|
/**
|
|
154
163
|
* Searches for files and directories by name pattern in the Sandbox.
|
|
155
164
|
*
|
|
156
|
-
* @param {string} path - Directory to search in
|
|
165
|
+
* @param {string} path - Directory to search in. Relative paths are resolved based on the user's
|
|
157
166
|
* @param {string} pattern - File name pattern (supports globs)
|
|
158
167
|
* @returns {Promise<SearchFilesResponse>} Search results with matching files
|
|
159
168
|
*
|
|
160
169
|
* @example
|
|
161
170
|
* // Find all TypeScript files
|
|
162
|
-
* const result = await fs.searchFiles('
|
|
171
|
+
* const result = await fs.searchFiles('app', '*.ts');
|
|
163
172
|
* result.files.forEach(file => console.log(file));
|
|
164
173
|
*/
|
|
165
174
|
searchFiles(path: string, pattern: string): Promise<SearchFilesResponse>;
|
|
166
175
|
/**
|
|
167
176
|
* Sets permissions and ownership for a file or directory.
|
|
168
177
|
*
|
|
169
|
-
* @param {string} path - Path to the file or directory
|
|
178
|
+
* @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
|
|
179
|
+
* root directory.
|
|
170
180
|
* @param {FilePermissionsParams} permissions - Permission settings
|
|
171
181
|
* @returns {Promise<void>}
|
|
172
182
|
*
|
|
173
183
|
* @example
|
|
174
184
|
* // Set file permissions and ownership
|
|
175
|
-
* await fs.setFilePermissions('
|
|
185
|
+
* await fs.setFilePermissions('app/script.sh', {
|
|
176
186
|
* owner: 'daytona',
|
|
177
187
|
* group: 'users',
|
|
178
188
|
* mode: '755' // Execute permission for shell script
|
|
@@ -182,36 +192,38 @@ export declare class FileSystem {
|
|
|
182
192
|
/**
|
|
183
193
|
* Uploads a file to the Sandbox.
|
|
184
194
|
*
|
|
185
|
-
* @param {string} path - Destination path in the Sandbox
|
|
195
|
+
* @param {string} path - Destination path in the Sandbox. Relative paths are resolved based on the user's
|
|
196
|
+
* root directory.
|
|
186
197
|
* @param {File} file - File to upload
|
|
187
198
|
* @returns {Promise<void>}
|
|
188
199
|
*
|
|
189
200
|
* @example
|
|
190
201
|
* // Upload a configuration file
|
|
191
202
|
* const configFile = new File(['{"setting": "value"}'], 'config.json');
|
|
192
|
-
* await fs.uploadFile('
|
|
203
|
+
* await fs.uploadFile('app/config.json', configFile);
|
|
193
204
|
*/
|
|
194
205
|
uploadFile(path: string, file: File): Promise<void>;
|
|
195
206
|
/**
|
|
196
207
|
* Uploads multiple files to the Sandbox. The parent directories must exist.
|
|
197
208
|
* If files already exist at the destination paths, they will be overwritten.
|
|
198
209
|
*
|
|
199
|
-
* @param {FileUpload[]} files - Array of files to upload
|
|
210
|
+
* @param {FileUpload[]} files - Array of files to upload. Relative paths are resolved based on the user's
|
|
211
|
+
* root directory.
|
|
200
212
|
* @returns {Promise<void>}
|
|
201
213
|
*
|
|
202
214
|
* @example
|
|
203
215
|
* // Upload multiple text files
|
|
204
216
|
* const files = [
|
|
205
217
|
* {
|
|
206
|
-
* path: '
|
|
218
|
+
* path: 'app/data/file1.txt',
|
|
207
219
|
* content: new File(['Content of file 1'], 'file1.txt')
|
|
208
220
|
* },
|
|
209
221
|
* {
|
|
210
|
-
* path: '
|
|
222
|
+
* path: 'app/data/file2.txt',
|
|
211
223
|
* content: new File(['Content of file 2'], 'file2.txt')
|
|
212
224
|
* },
|
|
213
225
|
* {
|
|
214
|
-
* path: '
|
|
226
|
+
* path: 'app/config/settings.json',
|
|
215
227
|
* content: new File(['{"key": "value"}'], 'settings.json')
|
|
216
228
|
* }
|
|
217
229
|
* ];
|
package/dist/FileSystem.js
CHANGED
|
@@ -2,129 +2,139 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FileSystem = void 0;
|
|
4
4
|
const DaytonaError_1 = require("./errors/DaytonaError");
|
|
5
|
+
const Path_1 = require("./utils/Path");
|
|
5
6
|
/**
|
|
6
7
|
* Provides file system operations within a Sandbox.
|
|
7
8
|
*
|
|
8
9
|
* @class
|
|
9
10
|
*/
|
|
10
11
|
class FileSystem {
|
|
11
|
-
constructor(instance, toolboxApi) {
|
|
12
|
+
constructor(instance, toolboxApi, getRootDir) {
|
|
12
13
|
this.instance = instance;
|
|
13
14
|
this.toolboxApi = toolboxApi;
|
|
15
|
+
this.getRootDir = getRootDir;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Create a new directory in the Sandbox with specified permissions.
|
|
17
19
|
*
|
|
18
|
-
* @param {string} path - Path where the directory should be created
|
|
20
|
+
* @param {string} path - Path where the directory should be created. Relative paths are resolved based on the user's
|
|
21
|
+
* root directory.
|
|
19
22
|
* @param {string} mode - Directory permissions in octal format (e.g. "755")
|
|
20
23
|
* @returns {Promise<void>}
|
|
21
24
|
*
|
|
22
25
|
* @example
|
|
23
26
|
* // Create a directory with standard permissions
|
|
24
|
-
* await fs.createFolder('
|
|
27
|
+
* await fs.createFolder('app/data', '755');
|
|
25
28
|
*/
|
|
26
29
|
async createFolder(path, mode) {
|
|
27
|
-
const response = await this.toolboxApi.createFolder(this.instance.id, path, mode);
|
|
30
|
+
const response = await this.toolboxApi.createFolder(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), mode);
|
|
28
31
|
return response.data;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* Deletes a file or directory from the Sandbox.
|
|
32
35
|
*
|
|
33
|
-
* @param {string} path - Path to the file or directory to delete
|
|
36
|
+
* @param {string} path - Path to the file or directory to delete. Relative paths are resolved based on the user's
|
|
37
|
+
* root directory.
|
|
34
38
|
* @returns {Promise<void>}
|
|
35
39
|
*
|
|
36
40
|
* @example
|
|
37
41
|
* // Delete a file
|
|
38
|
-
* await fs.deleteFile('
|
|
42
|
+
* await fs.deleteFile('app/temp.log');
|
|
39
43
|
*/
|
|
40
44
|
async deleteFile(path) {
|
|
41
|
-
const response = await this.toolboxApi.deleteFile(this.instance.id, path);
|
|
45
|
+
const response = await this.toolboxApi.deleteFile(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
|
|
42
46
|
return response.data;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
49
|
* Downloads a file from the Sandbox.
|
|
46
50
|
*
|
|
47
|
-
* @param {string} path - Path to the file to download
|
|
51
|
+
* @param {string} path - Path to the file to download. Relative paths are resolved based on the user's
|
|
52
|
+
* root directory.
|
|
48
53
|
* @returns {Promise<Blob>} The file contents as a Blob
|
|
49
54
|
*
|
|
50
55
|
* @example
|
|
51
56
|
* // Download and process a file
|
|
52
|
-
* const fileBlob = await fs.downloadFile('
|
|
57
|
+
* const fileBlob = await fs.downloadFile('app/data.json');
|
|
53
58
|
* console.log('File content:', fileBlob.toString());
|
|
54
59
|
*/
|
|
55
60
|
async downloadFile(path) {
|
|
56
|
-
const response = await this.toolboxApi.downloadFile(this.instance.id, path);
|
|
61
|
+
const response = await this.toolboxApi.downloadFile(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
|
|
57
62
|
return response.data;
|
|
58
63
|
}
|
|
59
64
|
/**
|
|
60
65
|
* Searches for text patterns within files in the Sandbox.
|
|
61
66
|
*
|
|
62
|
-
* @param {string} path - Directory to search in
|
|
67
|
+
* @param {string} path - Directory to search in. Relative paths are resolved based on the user's
|
|
68
|
+
* root directory.
|
|
63
69
|
* @param {string} pattern - Search pattern
|
|
64
70
|
* @returns {Promise<Array<Match>>} Array of matches with file and line information
|
|
65
71
|
*
|
|
66
72
|
* @example
|
|
67
73
|
* // Find all TODO comments in TypeScript files
|
|
68
|
-
* const matches = await fs.findFiles('
|
|
74
|
+
* const matches = await fs.findFiles('app/src', 'TODO:');
|
|
69
75
|
* matches.forEach(match => {
|
|
70
76
|
* console.log(`${match.file}:${match.line}: ${match.content}`);
|
|
71
77
|
* });
|
|
72
78
|
*/
|
|
73
79
|
async findFiles(path, pattern) {
|
|
74
|
-
const response = await this.toolboxApi.findInFiles(this.instance.id, path, pattern);
|
|
80
|
+
const response = await this.toolboxApi.findInFiles(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), pattern);
|
|
75
81
|
return response.data;
|
|
76
82
|
}
|
|
77
83
|
/**
|
|
78
84
|
* Retrieves detailed information about a file or directory.
|
|
79
85
|
*
|
|
80
|
-
* @param {string} path - Path to the file or directory
|
|
86
|
+
* @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
|
|
87
|
+
* root directory.
|
|
81
88
|
* @returns {Promise<FileInfo>} Detailed file information including size, permissions, modification time
|
|
82
89
|
*
|
|
83
90
|
* @example
|
|
84
91
|
* // Get file details
|
|
85
|
-
* const info = await fs.getFileDetails('
|
|
92
|
+
* const info = await fs.getFileDetails('app/config.json');
|
|
86
93
|
* console.log(`Size: ${info.size}, Modified: ${info.modTime}`);
|
|
87
94
|
*/
|
|
88
95
|
async getFileDetails(path) {
|
|
89
|
-
const response = await this.toolboxApi.getFileInfo(this.instance.id, path);
|
|
96
|
+
const response = await this.toolboxApi.getFileInfo(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
|
|
90
97
|
return response.data;
|
|
91
98
|
}
|
|
92
99
|
/**
|
|
93
100
|
* Lists contents of a directory in the Sandbox.
|
|
94
101
|
*
|
|
95
|
-
* @param {string} path - Directory path to list
|
|
102
|
+
* @param {string} path - Directory path to list. Relative paths are resolved based on the user's
|
|
103
|
+
* root directory.
|
|
96
104
|
* @returns {Promise<FileInfo[]>} Array of file and directory information
|
|
97
105
|
*
|
|
98
106
|
* @example
|
|
99
107
|
* // List directory contents
|
|
100
|
-
* const files = await fs.listFiles('
|
|
108
|
+
* const files = await fs.listFiles('app/src');
|
|
101
109
|
* files.forEach(file => {
|
|
102
110
|
* console.log(`${file.name} (${file.size} bytes)`);
|
|
103
111
|
* });
|
|
104
112
|
*/
|
|
105
113
|
async listFiles(path) {
|
|
106
|
-
const response = await this.toolboxApi.listFiles(this.instance.id, undefined, path);
|
|
114
|
+
const response = await this.toolboxApi.listFiles(this.instance.id, undefined, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path));
|
|
107
115
|
return response.data;
|
|
108
116
|
}
|
|
109
117
|
/**
|
|
110
118
|
* Moves or renames a file or directory.
|
|
111
119
|
*
|
|
112
|
-
* @param {string} source - Source path
|
|
113
|
-
*
|
|
120
|
+
* @param {string} source - Source path. Relative paths are resolved based on the user's
|
|
121
|
+
* root directory.
|
|
122
|
+
* @param {string} destination - Destination path. Relative paths are resolved based on the user's
|
|
123
|
+
* root directory.
|
|
114
124
|
* @returns {Promise<void>}
|
|
115
125
|
*
|
|
116
126
|
* @example
|
|
117
127
|
* // Move a file to a new location
|
|
118
|
-
* await fs.moveFiles('
|
|
128
|
+
* await fs.moveFiles('app/temp/data.json', 'app/data/data.json');
|
|
119
129
|
*/
|
|
120
130
|
async moveFiles(source, destination) {
|
|
121
|
-
const response = await this.toolboxApi.moveFile(this.instance.id, source, destination);
|
|
131
|
+
const response = await this.toolboxApi.moveFile(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), source), (0, Path_1.prefixRelativePath)(await this.getRootDir(), destination));
|
|
122
132
|
return response.data;
|
|
123
133
|
}
|
|
124
134
|
/**
|
|
125
135
|
* Replaces text content in multiple files.
|
|
126
136
|
*
|
|
127
|
-
* @param {string[]} files - Array of file paths to process
|
|
137
|
+
* @param {string[]} files - Array of file paths to process. Relative paths are resolved based on the user's
|
|
128
138
|
* @param {string} pattern - Pattern to replace
|
|
129
139
|
* @param {string} newValue - Replacement text
|
|
130
140
|
* @returns {Promise<Array<ReplaceResult>>} Results of the replace operation for each file
|
|
@@ -132,12 +142,15 @@ class FileSystem {
|
|
|
132
142
|
* @example
|
|
133
143
|
* // Update version number across multiple files
|
|
134
144
|
* const results = await fs.replaceInFiles(
|
|
135
|
-
* ['
|
|
145
|
+
* ['app/package.json', 'app/version.ts'],
|
|
136
146
|
* '"version": "1.0.0"',
|
|
137
147
|
* '"version": "1.1.0"'
|
|
138
148
|
* );
|
|
139
149
|
*/
|
|
140
150
|
async replaceInFiles(files, pattern, newValue) {
|
|
151
|
+
for (let i = 0; i < files.length; i++) {
|
|
152
|
+
files[i] = (0, Path_1.prefixRelativePath)(await this.getRootDir(), files[i]);
|
|
153
|
+
}
|
|
141
154
|
const replaceRequest = {
|
|
142
155
|
files,
|
|
143
156
|
newValue,
|
|
@@ -149,80 +162,86 @@ class FileSystem {
|
|
|
149
162
|
/**
|
|
150
163
|
* Searches for files and directories by name pattern in the Sandbox.
|
|
151
164
|
*
|
|
152
|
-
* @param {string} path - Directory to search in
|
|
165
|
+
* @param {string} path - Directory to search in. Relative paths are resolved based on the user's
|
|
153
166
|
* @param {string} pattern - File name pattern (supports globs)
|
|
154
167
|
* @returns {Promise<SearchFilesResponse>} Search results with matching files
|
|
155
168
|
*
|
|
156
169
|
* @example
|
|
157
170
|
* // Find all TypeScript files
|
|
158
|
-
* const result = await fs.searchFiles('
|
|
171
|
+
* const result = await fs.searchFiles('app', '*.ts');
|
|
159
172
|
* result.files.forEach(file => console.log(file));
|
|
160
173
|
*/
|
|
161
174
|
async searchFiles(path, pattern) {
|
|
162
|
-
const response = await this.toolboxApi.searchFiles(this.instance.id, path, pattern);
|
|
175
|
+
const response = await this.toolboxApi.searchFiles(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), pattern);
|
|
163
176
|
return response.data;
|
|
164
177
|
}
|
|
165
178
|
/**
|
|
166
179
|
* Sets permissions and ownership for a file or directory.
|
|
167
180
|
*
|
|
168
|
-
* @param {string} path - Path to the file or directory
|
|
181
|
+
* @param {string} path - Path to the file or directory. Relative paths are resolved based on the user's
|
|
182
|
+
* root directory.
|
|
169
183
|
* @param {FilePermissionsParams} permissions - Permission settings
|
|
170
184
|
* @returns {Promise<void>}
|
|
171
185
|
*
|
|
172
186
|
* @example
|
|
173
187
|
* // Set file permissions and ownership
|
|
174
|
-
* await fs.setFilePermissions('
|
|
188
|
+
* await fs.setFilePermissions('app/script.sh', {
|
|
175
189
|
* owner: 'daytona',
|
|
176
190
|
* group: 'users',
|
|
177
191
|
* mode: '755' // Execute permission for shell script
|
|
178
192
|
* });
|
|
179
193
|
*/
|
|
180
194
|
async setFilePermissions(path, permissions) {
|
|
181
|
-
const response = await this.toolboxApi.setFilePermissions(this.instance.id, path, undefined, permissions.owner, permissions.group, permissions.mode);
|
|
195
|
+
const response = await this.toolboxApi.setFilePermissions(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), undefined, permissions.owner, permissions.group, permissions.mode);
|
|
182
196
|
return response.data;
|
|
183
197
|
}
|
|
184
198
|
/**
|
|
185
199
|
* Uploads a file to the Sandbox.
|
|
186
200
|
*
|
|
187
|
-
* @param {string} path - Destination path in the Sandbox
|
|
201
|
+
* @param {string} path - Destination path in the Sandbox. Relative paths are resolved based on the user's
|
|
202
|
+
* root directory.
|
|
188
203
|
* @param {File} file - File to upload
|
|
189
204
|
* @returns {Promise<void>}
|
|
190
205
|
*
|
|
191
206
|
* @example
|
|
192
207
|
* // Upload a configuration file
|
|
193
208
|
* const configFile = new File(['{"setting": "value"}'], 'config.json');
|
|
194
|
-
* await fs.uploadFile('
|
|
209
|
+
* await fs.uploadFile('app/config.json', configFile);
|
|
195
210
|
*/
|
|
196
211
|
async uploadFile(path, file) {
|
|
197
|
-
const response = await this.toolboxApi.uploadFile(this.instance.id, path, undefined, file);
|
|
212
|
+
const response = await this.toolboxApi.uploadFile(this.instance.id, (0, Path_1.prefixRelativePath)(await this.getRootDir(), path), undefined, file);
|
|
198
213
|
return response.data;
|
|
199
214
|
}
|
|
200
215
|
/**
|
|
201
216
|
* Uploads multiple files to the Sandbox. The parent directories must exist.
|
|
202
217
|
* If files already exist at the destination paths, they will be overwritten.
|
|
203
218
|
*
|
|
204
|
-
* @param {FileUpload[]} files - Array of files to upload
|
|
219
|
+
* @param {FileUpload[]} files - Array of files to upload. Relative paths are resolved based on the user's
|
|
220
|
+
* root directory.
|
|
205
221
|
* @returns {Promise<void>}
|
|
206
222
|
*
|
|
207
223
|
* @example
|
|
208
224
|
* // Upload multiple text files
|
|
209
225
|
* const files = [
|
|
210
226
|
* {
|
|
211
|
-
* path: '
|
|
227
|
+
* path: 'app/data/file1.txt',
|
|
212
228
|
* content: new File(['Content of file 1'], 'file1.txt')
|
|
213
229
|
* },
|
|
214
230
|
* {
|
|
215
|
-
* path: '
|
|
231
|
+
* path: 'app/data/file2.txt',
|
|
216
232
|
* content: new File(['Content of file 2'], 'file2.txt')
|
|
217
233
|
* },
|
|
218
234
|
* {
|
|
219
|
-
* path: '
|
|
235
|
+
* path: 'app/config/settings.json',
|
|
220
236
|
* content: new File(['{"key": "value"}'], 'settings.json')
|
|
221
237
|
* }
|
|
222
238
|
* ];
|
|
223
239
|
* await fs.uploadFiles(files);
|
|
224
240
|
*/
|
|
225
241
|
async uploadFiles(files) {
|
|
242
|
+
for (const file of files) {
|
|
243
|
+
file.path = (0, Path_1.prefixRelativePath)(await this.getRootDir(), file.path);
|
|
244
|
+
}
|
|
226
245
|
const results = await Promise.allSettled(files.map((file) => this.uploadFile(file.path, file.content)));
|
|
227
246
|
const failedUploads = results
|
|
228
247
|
.map((result, index) => ({
|