@blaxel/core 0.2.36-dev.185 → 0.2.36-dev.190

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 (172) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -0
  2. package/dist/{common → cjs/common}/settings.js +2 -2
  3. package/dist/{tools → cjs/types/tools}/index.d.ts +1 -0
  4. package/dist/esm/.tsbuildinfo +1 -0
  5. package/dist/esm/agents/index.js +104 -0
  6. package/dist/esm/authentication/apikey.js +20 -0
  7. package/dist/esm/authentication/clientcredentials.js +81 -0
  8. package/dist/esm/authentication/credentials.js +13 -0
  9. package/dist/esm/authentication/deviceMode.js +66 -0
  10. package/dist/esm/authentication/index.js +56 -0
  11. package/dist/esm/authentication/types.js +1 -0
  12. package/dist/esm/cache/index.js +20 -0
  13. package/dist/esm/client/authentication.js +11 -0
  14. package/dist/esm/client/client.gen.js +5 -0
  15. package/dist/esm/client/client.js +1 -0
  16. package/dist/esm/client/index.js +3 -0
  17. package/dist/esm/client/interceptors.js +14 -0
  18. package/dist/esm/client/sdk.gen.js +1649 -0
  19. package/dist/esm/client/types.gen.js +3 -0
  20. package/dist/esm/common/autoload.js +23 -0
  21. package/dist/esm/common/env.js +36 -0
  22. package/dist/esm/common/errors.js +14 -0
  23. package/dist/esm/common/internal.js +182 -0
  24. package/dist/esm/common/internal.test.js +37 -0
  25. package/dist/esm/common/logger.js +65 -0
  26. package/dist/esm/common/node.js +20 -0
  27. package/dist/esm/common/settings.js +167 -0
  28. package/dist/esm/index.browser.test.js +10 -0
  29. package/dist/esm/index.js +17 -0
  30. package/dist/esm/jobs/index.js +3 -0
  31. package/dist/esm/jobs/jobs.js +86 -0
  32. package/dist/esm/jobs/start.js +62 -0
  33. package/dist/esm/jobs/types.js +1 -0
  34. package/dist/esm/mcp/client.js +243 -0
  35. package/dist/esm/mcp/index.js +2 -0
  36. package/dist/esm/mcp/server.js +176 -0
  37. package/dist/esm/models/index.js +25 -0
  38. package/dist/esm/package.json +1 -0
  39. package/dist/esm/sandbox/action.js +79 -0
  40. package/dist/esm/sandbox/client/client.gen.js +3 -0
  41. package/dist/esm/sandbox/client/index.js +3 -0
  42. package/dist/esm/sandbox/client/sdk.gen.js +270 -0
  43. package/dist/esm/sandbox/client/types.gen.js +2 -0
  44. package/dist/esm/sandbox/filesystem/filesystem.js +272 -0
  45. package/dist/esm/sandbox/filesystem/index.js +2 -0
  46. package/dist/esm/sandbox/filesystem/types.js +1 -0
  47. package/dist/esm/sandbox/index.js +7 -0
  48. package/dist/esm/sandbox/network/index.js +1 -0
  49. package/dist/esm/sandbox/network/network.js +6 -0
  50. package/dist/esm/sandbox/preview.js +141 -0
  51. package/dist/esm/sandbox/process/index.js +1 -0
  52. package/dist/esm/sandbox/process/process.js +185 -0
  53. package/dist/esm/sandbox/sandbox.js +174 -0
  54. package/dist/esm/sandbox/session.js +119 -0
  55. package/dist/esm/sandbox/types.js +76 -0
  56. package/dist/esm/telemetry/telemetry.js +74 -0
  57. package/dist/esm/tools/index.js +44 -0
  58. package/dist/esm/tools/mcpTool.js +213 -0
  59. package/dist/esm/tools/types.js +1 -0
  60. package/dist/esm/tools/zodSchema.js +43 -0
  61. package/dist/esm/volume/index.js +109 -0
  62. package/package.json +17 -30
  63. /package/dist/{agents → cjs/agents}/index.js +0 -0
  64. /package/dist/{authentication → cjs/authentication}/apikey.js +0 -0
  65. /package/dist/{authentication → cjs/authentication}/clientcredentials.js +0 -0
  66. /package/dist/{authentication → cjs/authentication}/credentials.js +0 -0
  67. /package/dist/{authentication → cjs/authentication}/deviceMode.js +0 -0
  68. /package/dist/{authentication → cjs/authentication}/index.js +0 -0
  69. /package/dist/{authentication → cjs/authentication}/types.js +0 -0
  70. /package/dist/{cache → cjs/cache}/index.js +0 -0
  71. /package/dist/{client → cjs/client}/authentication.js +0 -0
  72. /package/dist/{client → cjs/client}/client.gen.js +0 -0
  73. /package/dist/{client → cjs/client}/client.js +0 -0
  74. /package/dist/{client → cjs/client}/index.js +0 -0
  75. /package/dist/{client → cjs/client}/interceptors.js +0 -0
  76. /package/dist/{client → cjs/client}/sdk.gen.js +0 -0
  77. /package/dist/{client → cjs/client}/types.gen.js +0 -0
  78. /package/dist/{common → cjs/common}/autoload.js +0 -0
  79. /package/dist/{common → cjs/common}/env.js +0 -0
  80. /package/dist/{common → cjs/common}/errors.js +0 -0
  81. /package/dist/{common → cjs/common}/internal.js +0 -0
  82. /package/dist/{common → cjs/common}/internal.test.js +0 -0
  83. /package/dist/{common → cjs/common}/logger.js +0 -0
  84. /package/dist/{common → cjs/common}/node.js +0 -0
  85. /package/dist/{index.browser.test.js → cjs/index.browser.test.js} +0 -0
  86. /package/dist/{index.js → cjs/index.js} +0 -0
  87. /package/dist/{jobs → cjs/jobs}/index.js +0 -0
  88. /package/dist/{jobs → cjs/jobs}/jobs.js +0 -0
  89. /package/dist/{jobs → cjs/jobs}/start.js +0 -0
  90. /package/dist/{jobs → cjs/jobs}/types.js +0 -0
  91. /package/dist/{mcp → cjs/mcp}/client.js +0 -0
  92. /package/dist/{mcp → cjs/mcp}/index.js +0 -0
  93. /package/dist/{mcp → cjs/mcp}/server.js +0 -0
  94. /package/dist/{models → cjs/models}/index.js +0 -0
  95. /package/dist/{sandbox → cjs/sandbox}/action.js +0 -0
  96. /package/dist/{sandbox → cjs/sandbox}/client/client.gen.js +0 -0
  97. /package/dist/{sandbox → cjs/sandbox}/client/index.js +0 -0
  98. /package/dist/{sandbox → cjs/sandbox}/client/sdk.gen.js +0 -0
  99. /package/dist/{sandbox → cjs/sandbox}/client/types.gen.js +0 -0
  100. /package/dist/{sandbox → cjs/sandbox}/filesystem/filesystem.js +0 -0
  101. /package/dist/{sandbox → cjs/sandbox}/filesystem/index.js +0 -0
  102. /package/dist/{sandbox → cjs/sandbox}/filesystem/types.js +0 -0
  103. /package/dist/{sandbox → cjs/sandbox}/index.js +0 -0
  104. /package/dist/{sandbox → cjs/sandbox}/network/index.js +0 -0
  105. /package/dist/{sandbox → cjs/sandbox}/network/network.js +0 -0
  106. /package/dist/{sandbox → cjs/sandbox}/preview.js +0 -0
  107. /package/dist/{sandbox → cjs/sandbox}/process/index.js +0 -0
  108. /package/dist/{sandbox → cjs/sandbox}/process/process.js +0 -0
  109. /package/dist/{sandbox → cjs/sandbox}/sandbox.js +0 -0
  110. /package/dist/{sandbox → cjs/sandbox}/session.js +0 -0
  111. /package/dist/{sandbox → cjs/sandbox}/types.js +0 -0
  112. /package/dist/{telemetry → cjs/telemetry}/telemetry.js +0 -0
  113. /package/dist/{tools → cjs/tools}/index.js +0 -0
  114. /package/dist/{tools → cjs/tools}/mcpTool.js +0 -0
  115. /package/dist/{tools → cjs/tools}/types.js +0 -0
  116. /package/dist/{tools → cjs/tools}/zodSchema.js +0 -0
  117. /package/dist/{agents → cjs/types/agents}/index.d.ts +0 -0
  118. /package/dist/{authentication → cjs/types/authentication}/apikey.d.ts +0 -0
  119. /package/dist/{authentication → cjs/types/authentication}/clientcredentials.d.ts +0 -0
  120. /package/dist/{authentication → cjs/types/authentication}/credentials.d.ts +0 -0
  121. /package/dist/{authentication → cjs/types/authentication}/deviceMode.d.ts +0 -0
  122. /package/dist/{authentication → cjs/types/authentication}/index.d.ts +0 -0
  123. /package/dist/{authentication → cjs/types/authentication}/types.d.ts +0 -0
  124. /package/dist/{cache → cjs/types/cache}/index.d.ts +0 -0
  125. /package/dist/{client → cjs/types/client}/authentication.d.ts +0 -0
  126. /package/dist/{client → cjs/types/client}/client.d.ts +0 -0
  127. /package/dist/{client → cjs/types/client}/client.gen.d.ts +0 -0
  128. /package/dist/{client → cjs/types/client}/index.d.ts +0 -0
  129. /package/dist/{client → cjs/types/client}/interceptors.d.ts +0 -0
  130. /package/dist/{client → cjs/types/client}/sdk.gen.d.ts +0 -0
  131. /package/dist/{client → cjs/types/client}/types.gen.d.ts +0 -0
  132. /package/dist/{common → cjs/types/common}/autoload.d.ts +0 -0
  133. /package/dist/{common → cjs/types/common}/env.d.ts +0 -0
  134. /package/dist/{common → cjs/types/common}/errors.d.ts +0 -0
  135. /package/dist/{common → cjs/types/common}/internal.d.ts +0 -0
  136. /package/dist/{common → cjs/types/common}/internal.test.d.ts +0 -0
  137. /package/dist/{common → cjs/types/common}/logger.d.ts +0 -0
  138. /package/dist/{common → cjs/types/common}/node.d.ts +0 -0
  139. /package/dist/{common → cjs/types/common}/settings.d.ts +0 -0
  140. /package/dist/{index.browser.test.d.ts → cjs/types/index.browser.test.d.ts} +0 -0
  141. /package/dist/{index.d.ts → cjs/types/index.d.ts} +0 -0
  142. /package/dist/{jobs → cjs/types/jobs}/index.d.ts +0 -0
  143. /package/dist/{jobs → cjs/types/jobs}/jobs.d.ts +0 -0
  144. /package/dist/{jobs → cjs/types/jobs}/start.d.ts +0 -0
  145. /package/dist/{jobs → cjs/types/jobs}/types.d.ts +0 -0
  146. /package/dist/{mcp → cjs/types/mcp}/client.d.ts +0 -0
  147. /package/dist/{mcp → cjs/types/mcp}/index.d.ts +0 -0
  148. /package/dist/{mcp → cjs/types/mcp}/server.d.ts +0 -0
  149. /package/dist/{models → cjs/types/models}/index.d.ts +0 -0
  150. /package/dist/{sandbox → cjs/types/sandbox}/action.d.ts +0 -0
  151. /package/dist/{sandbox → cjs/types/sandbox}/client/client.gen.d.ts +0 -0
  152. /package/dist/{sandbox → cjs/types/sandbox}/client/index.d.ts +0 -0
  153. /package/dist/{sandbox → cjs/types/sandbox}/client/sdk.gen.d.ts +0 -0
  154. /package/dist/{sandbox → cjs/types/sandbox}/client/types.gen.d.ts +0 -0
  155. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/filesystem.d.ts +0 -0
  156. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/index.d.ts +0 -0
  157. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/types.d.ts +0 -0
  158. /package/dist/{sandbox → cjs/types/sandbox}/index.d.ts +0 -0
  159. /package/dist/{sandbox → cjs/types/sandbox}/network/index.d.ts +0 -0
  160. /package/dist/{sandbox → cjs/types/sandbox}/network/network.d.ts +0 -0
  161. /package/dist/{sandbox → cjs/types/sandbox}/preview.d.ts +0 -0
  162. /package/dist/{sandbox → cjs/types/sandbox}/process/index.d.ts +0 -0
  163. /package/dist/{sandbox → cjs/types/sandbox}/process/process.d.ts +0 -0
  164. /package/dist/{sandbox → cjs/types/sandbox}/sandbox.d.ts +0 -0
  165. /package/dist/{sandbox → cjs/types/sandbox}/session.d.ts +0 -0
  166. /package/dist/{sandbox → cjs/types/sandbox}/types.d.ts +0 -0
  167. /package/dist/{telemetry → cjs/types/telemetry}/telemetry.d.ts +0 -0
  168. /package/dist/{tools → cjs/types/tools}/mcpTool.d.ts +0 -0
  169. /package/dist/{tools → cjs/types/tools}/types.d.ts +0 -0
  170. /package/dist/{tools → cjs/types/tools}/zodSchema.d.ts +0 -0
  171. /package/dist/{volume → cjs/types/volume}/index.d.ts +0 -0
  172. /package/dist/{volume → cjs/volume}/index.js +0 -0
@@ -0,0 +1,270 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { client as _heyApiClient } from "./client.gen.js";
3
+ /**
4
+ * Delete file or directory
5
+ * Delete a file or directory
6
+ */
7
+ export const deleteFilesystemByPath = (options) => {
8
+ return (options.client ?? _heyApiClient).delete({
9
+ security: [
10
+ {
11
+ scheme: 'bearer',
12
+ type: 'http'
13
+ }
14
+ ],
15
+ url: '/filesystem/{path}',
16
+ ...options
17
+ });
18
+ };
19
+ /**
20
+ * Get file or directory information
21
+ * Get content of a file or listing of a directory
22
+ */
23
+ export const getFilesystemByPath = (options) => {
24
+ return (options.client ?? _heyApiClient).get({
25
+ security: [
26
+ {
27
+ scheme: 'bearer',
28
+ type: 'http'
29
+ }
30
+ ],
31
+ url: '/filesystem/{path}',
32
+ ...options
33
+ });
34
+ };
35
+ /**
36
+ * Create or update a file or directory
37
+ * Create or update a file or directory
38
+ */
39
+ export const putFilesystemByPath = (options) => {
40
+ return (options.client ?? _heyApiClient).put({
41
+ security: [
42
+ {
43
+ scheme: 'bearer',
44
+ type: 'http'
45
+ }
46
+ ],
47
+ url: '/filesystem/{path}',
48
+ ...options,
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ ...options?.headers
52
+ }
53
+ });
54
+ };
55
+ /**
56
+ * Stop monitoring ports for a process
57
+ * Stop monitoring for new ports opened by a process
58
+ */
59
+ export const deleteNetworkProcessByPidMonitor = (options) => {
60
+ return (options.client ?? _heyApiClient).delete({
61
+ security: [
62
+ {
63
+ scheme: 'bearer',
64
+ type: 'http'
65
+ }
66
+ ],
67
+ url: '/network/process/{pid}/monitor',
68
+ ...options
69
+ });
70
+ };
71
+ /**
72
+ * Start monitoring ports for a process
73
+ * Start monitoring for new ports opened by a process
74
+ */
75
+ export const postNetworkProcessByPidMonitor = (options) => {
76
+ return (options.client ?? _heyApiClient).post({
77
+ security: [
78
+ {
79
+ scheme: 'bearer',
80
+ type: 'http'
81
+ }
82
+ ],
83
+ url: '/network/process/{pid}/monitor',
84
+ ...options,
85
+ headers: {
86
+ 'Content-Type': 'application/json',
87
+ ...options?.headers
88
+ }
89
+ });
90
+ };
91
+ /**
92
+ * Get open ports for a process
93
+ * Get a list of all open ports for a process
94
+ */
95
+ export const getNetworkProcessByPidPorts = (options) => {
96
+ return (options.client ?? _heyApiClient).get({
97
+ security: [
98
+ {
99
+ scheme: 'bearer',
100
+ type: 'http'
101
+ }
102
+ ],
103
+ url: '/network/process/{pid}/ports',
104
+ ...options
105
+ });
106
+ };
107
+ /**
108
+ * List all processes
109
+ * Get a list of all running and completed processes
110
+ */
111
+ export const getProcess = (options) => {
112
+ return (options?.client ?? _heyApiClient).get({
113
+ security: [
114
+ {
115
+ scheme: 'bearer',
116
+ type: 'http'
117
+ }
118
+ ],
119
+ url: '/process',
120
+ ...options
121
+ });
122
+ };
123
+ /**
124
+ * Execute a command
125
+ * Execute a command and return process information
126
+ */
127
+ export const postProcess = (options) => {
128
+ return (options.client ?? _heyApiClient).post({
129
+ security: [
130
+ {
131
+ scheme: 'bearer',
132
+ type: 'http'
133
+ }
134
+ ],
135
+ url: '/process',
136
+ ...options,
137
+ headers: {
138
+ 'Content-Type': 'application/json',
139
+ ...options?.headers
140
+ }
141
+ });
142
+ };
143
+ /**
144
+ * Stop a process
145
+ * Gracefully stop a running process
146
+ */
147
+ export const deleteProcessByIdentifier = (options) => {
148
+ return (options.client ?? _heyApiClient).delete({
149
+ security: [
150
+ {
151
+ scheme: 'bearer',
152
+ type: 'http'
153
+ }
154
+ ],
155
+ url: '/process/{identifier}',
156
+ ...options
157
+ });
158
+ };
159
+ /**
160
+ * Get process by identifier
161
+ * Get information about a process by its PID or name
162
+ */
163
+ export const getProcessByIdentifier = (options) => {
164
+ return (options.client ?? _heyApiClient).get({
165
+ security: [
166
+ {
167
+ scheme: 'bearer',
168
+ type: 'http'
169
+ }
170
+ ],
171
+ url: '/process/{identifier}',
172
+ ...options
173
+ });
174
+ };
175
+ /**
176
+ * Kill a process
177
+ * Forcefully kill a running process
178
+ */
179
+ export const deleteProcessByIdentifierKill = (options) => {
180
+ return (options.client ?? _heyApiClient).delete({
181
+ security: [
182
+ {
183
+ scheme: 'bearer',
184
+ type: 'http'
185
+ }
186
+ ],
187
+ url: '/process/{identifier}/kill',
188
+ ...options
189
+ });
190
+ };
191
+ /**
192
+ * Get process logs
193
+ * Get the stdout and stderr output of a process
194
+ */
195
+ export const getProcessByIdentifierLogs = (options) => {
196
+ return (options.client ?? _heyApiClient).get({
197
+ security: [
198
+ {
199
+ scheme: 'bearer',
200
+ type: 'http'
201
+ }
202
+ ],
203
+ url: '/process/{identifier}/logs',
204
+ ...options
205
+ });
206
+ };
207
+ /**
208
+ * Stream process logs in real time
209
+ * Streams the stdout and stderr output of a process in real time, one line per log, prefixed with 'stdout:' or 'stderr:'. Closes when the process exits or the client disconnects.
210
+ */
211
+ export const getProcessByIdentifierLogsStream = (options) => {
212
+ return (options.client ?? _heyApiClient).get({
213
+ security: [
214
+ {
215
+ scheme: 'bearer',
216
+ type: 'http'
217
+ }
218
+ ],
219
+ url: '/process/{identifier}/logs/stream',
220
+ ...options
221
+ });
222
+ };
223
+ /**
224
+ * Stream file modification events in a directory
225
+ * Streams the path of modified files (one per line) in the given directory. Closes when the client disconnects.
226
+ */
227
+ export const getWatchFilesystemByPath = (options) => {
228
+ return (options.client ?? _heyApiClient).get({
229
+ security: [
230
+ {
231
+ scheme: 'bearer',
232
+ type: 'http'
233
+ }
234
+ ],
235
+ url: '/watch/filesystem/{path}',
236
+ ...options
237
+ });
238
+ };
239
+ /**
240
+ * Stream process logs in real time via WebSocket
241
+ * Streams the stdout and stderr output of a process in real time as JSON messages.
242
+ */
243
+ export const getWsProcessByIdentifierLogsStream = (options) => {
244
+ return (options.client ?? _heyApiClient).get({
245
+ security: [
246
+ {
247
+ scheme: 'bearer',
248
+ type: 'http'
249
+ }
250
+ ],
251
+ url: '/ws/process/{identifier}/logs/stream',
252
+ ...options
253
+ });
254
+ };
255
+ /**
256
+ * Stream file modification events in a directory via WebSocket
257
+ * Streams JSON events of modified files in the given directory. Closes when the client disconnects.
258
+ */
259
+ export const getWsWatchFilesystemByPath = (options) => {
260
+ return (options.client ?? _heyApiClient).get({
261
+ security: [
262
+ {
263
+ scheme: 'bearer',
264
+ type: 'http'
265
+ }
266
+ ],
267
+ url: '/ws/watch/filesystem/{path}',
268
+ ...options
269
+ });
270
+ };
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,272 @@
1
+ import { settings } from "../../common/settings.js";
2
+ import { SandboxAction } from "../action.js";
3
+ import { deleteFilesystemByPath, getFilesystemByPath, getWatchFilesystemByPath, putFilesystemByPath } from "../client/index.js";
4
+ export class SandboxFileSystem extends SandboxAction {
5
+ constructor(sandbox) {
6
+ super(sandbox);
7
+ }
8
+ async mkdir(path, permissions = "0755") {
9
+ path = this.formatPath(path);
10
+ const { response, data, error } = await putFilesystemByPath({
11
+ path: { path },
12
+ body: { isDirectory: true, permissions },
13
+ baseUrl: this.url,
14
+ client: this.client,
15
+ });
16
+ this.handleResponseError(response, data, error);
17
+ return data;
18
+ }
19
+ async write(path, content) {
20
+ path = this.formatPath(path);
21
+ const { response, data, error } = await putFilesystemByPath({
22
+ path: { path },
23
+ body: { content },
24
+ baseUrl: this.url,
25
+ client: this.client,
26
+ });
27
+ this.handleResponseError(response, data, error);
28
+ return data;
29
+ }
30
+ async writeBinary(path, content) {
31
+ path = this.formatPath(path);
32
+ const formData = new FormData();
33
+ // Convert content to Blob regardless of input type
34
+ let fileBlob;
35
+ if (content instanceof Blob || content instanceof File) {
36
+ fileBlob = content;
37
+ }
38
+ else if (Buffer.isBuffer(content)) {
39
+ // Convert Buffer to Blob
40
+ fileBlob = new Blob([content]);
41
+ }
42
+ else if (content instanceof Uint8Array) {
43
+ // Convert Uint8Array to Blob
44
+ fileBlob = new Blob([content]);
45
+ }
46
+ else {
47
+ throw new Error("Unsupported content type");
48
+ }
49
+ // Append the file as a Blob
50
+ formData.append("file", fileBlob, "test-binary.bin");
51
+ formData.append("permissions", "0644");
52
+ formData.append("path", path);
53
+ // Build URL
54
+ let url = `${this.url}/filesystem/${path}`;
55
+ if (this.forcedUrl) {
56
+ url = `${this.forcedUrl.toString()}/filesystem/${path}`;
57
+ }
58
+ // Make the request using fetch instead of axios for better FormData handling
59
+ const response = await fetch(url, {
60
+ method: 'PUT',
61
+ headers: {
62
+ ...settings.headers,
63
+ },
64
+ body: formData,
65
+ });
66
+ if (!response.ok) {
67
+ const errorText = await response.text();
68
+ throw new Error(`Failed to write binary: ${response.status} ${errorText}`);
69
+ }
70
+ return await response.json();
71
+ }
72
+ async writeTree(files, destinationPath = null) {
73
+ const options = {
74
+ body: {
75
+ files: files.reduce((acc, file) => {
76
+ acc[file.path] = file.content;
77
+ return acc;
78
+ }, {}),
79
+ },
80
+ baseUrl: this.url,
81
+ client: this.client,
82
+ };
83
+ const path = destinationPath ?? "";
84
+ const { response, data, error } = await this.client.put({
85
+ url: `/filesystem/tree/${path}`,
86
+ ...options,
87
+ headers: {
88
+ 'Content-Type': 'application/json',
89
+ }
90
+ });
91
+ this.handleResponseError(response, data, error);
92
+ return data;
93
+ }
94
+ async read(path) {
95
+ path = this.formatPath(path);
96
+ const { response, data, error } = await getFilesystemByPath({
97
+ path: { path },
98
+ baseUrl: this.url,
99
+ client: this.client,
100
+ });
101
+ this.handleResponseError(response, data, error);
102
+ if (data && 'content' in data) {
103
+ return data.content;
104
+ }
105
+ throw new Error("Unsupported file type");
106
+ }
107
+ async rm(path, recursive = false) {
108
+ path = this.formatPath(path);
109
+ const { response, data, error } = await deleteFilesystemByPath({
110
+ path: { path },
111
+ query: { recursive },
112
+ baseUrl: this.url,
113
+ client: this.client,
114
+ });
115
+ this.handleResponseError(response, data, error);
116
+ return data;
117
+ }
118
+ async ls(path) {
119
+ path = this.formatPath(path);
120
+ const { response, data, error } = await getFilesystemByPath({
121
+ path: { path },
122
+ baseUrl: this.url,
123
+ client: this.client,
124
+ });
125
+ this.handleResponseError(response, data, error);
126
+ if (!data || !('files' in data || 'subdirectories' in data)) {
127
+ throw new Error(JSON.stringify({ error: "Directory not found" }));
128
+ }
129
+ return data;
130
+ }
131
+ async cp(source, destination) {
132
+ source = this.formatPath(source);
133
+ destination = this.formatPath(destination);
134
+ const { response, data, error } = await getFilesystemByPath({
135
+ path: { path: source },
136
+ baseUrl: this.url,
137
+ client: this.client,
138
+ });
139
+ this.handleResponseError(response, data, error);
140
+ if (data && ('files' in data || 'subdirectories' in data)) {
141
+ // Create destination directory
142
+ await this.mkdir(destination);
143
+ // Process subdirectories in batches of 5
144
+ const subdirectories = data.subdirectories || [];
145
+ for (let i = 0; i < subdirectories.length; i += 5) {
146
+ const batch = subdirectories.slice(i, i + 5);
147
+ await Promise.all(batch.map(async (subdir) => {
148
+ const sourcePath = subdir.path || `${source}/${subdir.path}`;
149
+ const destPath = `${destination}/${subdir.path}`;
150
+ await this.cp(sourcePath, destPath);
151
+ }));
152
+ }
153
+ // Process files in batches of 10
154
+ const files = data.files || [];
155
+ for (let i = 0; i < files.length; i += 10) {
156
+ const batch = files.slice(i, i + 10);
157
+ await Promise.all(batch.map(async (file) => {
158
+ const sourcePath = file.path || `${source}/${file.path}`;
159
+ const destPath = `${destination}/${file.path}`;
160
+ const fileContent = await this.read(sourcePath);
161
+ if (typeof fileContent === 'string') {
162
+ await this.write(destPath, fileContent);
163
+ }
164
+ }));
165
+ }
166
+ return {
167
+ message: "Directory copied successfully",
168
+ source,
169
+ destination,
170
+ };
171
+ }
172
+ else if (data && 'content' in data) {
173
+ await this.write(destination, data.content);
174
+ return {
175
+ message: "File copied successfully",
176
+ source,
177
+ destination,
178
+ };
179
+ }
180
+ throw new Error("Unsupported file type");
181
+ }
182
+ watch(path, callback, options) {
183
+ path = this.formatPath(path);
184
+ let closed = false;
185
+ const controller = new AbortController();
186
+ const start = async () => {
187
+ const query = {};
188
+ if (options?.ignore) {
189
+ query.ignore = options.ignore.join(",");
190
+ }
191
+ const { response, data, error } = await getWatchFilesystemByPath({
192
+ client: this.client,
193
+ path: { path },
194
+ query,
195
+ baseUrl: this.url,
196
+ parseAs: 'stream',
197
+ signal: controller.signal,
198
+ });
199
+ if (error)
200
+ throw new Error(error instanceof Error ? error.message : JSON.stringify(error));
201
+ const stream = data ?? response.body;
202
+ if (!stream)
203
+ throw new Error('No stream returned');
204
+ const reader = stream.getReader();
205
+ let buffer = '';
206
+ const decoder = new TextDecoder();
207
+ try {
208
+ while (!closed) {
209
+ const { value, done } = await reader.read();
210
+ if (done)
211
+ break;
212
+ buffer += decoder.decode(value, { stream: true });
213
+ const lines = buffer.split('\n');
214
+ buffer = lines.pop();
215
+ for (const line of lines) {
216
+ const trimmed = line.trim();
217
+ if (!trimmed)
218
+ continue;
219
+ const fileEvent = JSON.parse(line.trim());
220
+ if (options?.withContent && ["CREATE", "WRITE"].includes(fileEvent.op)) {
221
+ try {
222
+ let filePath = "";
223
+ if (fileEvent.path.endsWith("/")) {
224
+ filePath = fileEvent.path + fileEvent.name;
225
+ }
226
+ else {
227
+ filePath = fileEvent.path + "/" + fileEvent.name;
228
+ }
229
+ const content = await this.read(filePath);
230
+ await callback({ ...fileEvent, content });
231
+ }
232
+ catch {
233
+ await callback({ ...fileEvent, content: undefined });
234
+ }
235
+ }
236
+ else {
237
+ await callback(fileEvent);
238
+ }
239
+ }
240
+ }
241
+ }
242
+ finally {
243
+ reader.releaseLock();
244
+ }
245
+ };
246
+ start().catch((err) => {
247
+ // Suppress AbortError when closing
248
+ if (!(err && typeof err === 'object' && 'name' in err && err.name === 'AbortError')) {
249
+ if (options?.onError) {
250
+ options.onError(err instanceof Error ? err : new Error(String(err)));
251
+ }
252
+ }
253
+ closed = true;
254
+ controller.abort();
255
+ });
256
+ return {
257
+ close: () => {
258
+ closed = true;
259
+ controller.abort();
260
+ },
261
+ };
262
+ }
263
+ formatPath(path) {
264
+ if (path === "/") {
265
+ return path;
266
+ }
267
+ if (path.startsWith("/")) {
268
+ path = path.slice(1);
269
+ }
270
+ return path;
271
+ }
272
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./filesystem.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export {
2
+ /* Export SDK functions */
3
+ deleteFilesystemByPath, deleteNetworkProcessByPidMonitor, deleteProcessByIdentifier, deleteProcessByIdentifierKill, getFilesystemByPath, getNetworkProcessByPidPorts, getProcess, getProcessByIdentifier, getProcessByIdentifierLogs, getProcessByIdentifierLogsStream, postNetworkProcessByPidMonitor, postProcess, putFilesystemByPath } from "./client/index.js";
4
+ export * from "./filesystem/index.js";
5
+ export * from "./sandbox.js";
6
+ export * from "./types.js";
7
+ // Re-export everything from client except ClientOptions to avoid conflict
@@ -0,0 +1 @@
1
+ export * from "./network.js";
@@ -0,0 +1,6 @@
1
+ import { SandboxAction } from "../action.js";
2
+ export class SandboxNetwork extends SandboxAction {
3
+ constructor(sandbox) {
4
+ super(sandbox);
5
+ }
6
+ }