@cloudflare/sandbox 0.4.12 → 0.4.15
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/.turbo/turbo-build.log +13 -47
- package/CHANGELOG.md +46 -16
- package/Dockerfile +78 -31
- package/README.md +9 -2
- package/dist/index.d.ts +1889 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3144 -65
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/clients/base-client.ts +39 -24
- package/src/clients/command-client.ts +8 -8
- package/src/clients/file-client.ts +31 -26
- package/src/clients/git-client.ts +3 -4
- package/src/clients/index.ts +12 -16
- package/src/clients/interpreter-client.ts +51 -47
- package/src/clients/port-client.ts +10 -10
- package/src/clients/process-client.ts +11 -8
- package/src/clients/sandbox-client.ts +2 -4
- package/src/clients/types.ts +6 -2
- package/src/clients/utility-client.ts +10 -6
- package/src/errors/adapter.ts +90 -32
- package/src/errors/classes.ts +189 -64
- package/src/errors/index.ts +9 -5
- package/src/file-stream.ts +11 -6
- package/src/index.ts +22 -15
- package/src/interpreter.ts +50 -41
- package/src/request-handler.ts +24 -21
- package/src/sandbox.ts +339 -149
- package/src/security.ts +21 -6
- package/src/sse-parser.ts +4 -3
- package/src/version.ts +1 -1
- package/tests/base-client.test.ts +116 -80
- package/tests/command-client.test.ts +149 -112
- package/tests/file-client.test.ts +309 -197
- package/tests/file-stream.test.ts +24 -20
- package/tests/get-sandbox.test.ts +10 -10
- package/tests/git-client.test.ts +188 -101
- package/tests/port-client.test.ts +100 -108
- package/tests/process-client.test.ts +204 -179
- package/tests/request-handler.test.ts +117 -65
- package/tests/sandbox.test.ts +219 -67
- package/tests/sse-parser.test.ts +17 -16
- package/tests/utility-client.test.ts +79 -72
- package/tsdown.config.ts +12 -0
- package/vitest.config.ts +6 -6
- package/dist/chunk-BFVUNTP4.js +0 -104
- package/dist/chunk-BFVUNTP4.js.map +0 -1
- package/dist/chunk-EKSWCBCA.js +0 -86
- package/dist/chunk-EKSWCBCA.js.map +0 -1
- package/dist/chunk-JXZMAU2C.js +0 -559
- package/dist/chunk-JXZMAU2C.js.map +0 -1
- package/dist/chunk-UJ3TV4M6.js +0 -7
- package/dist/chunk-UJ3TV4M6.js.map +0 -1
- package/dist/chunk-YE265ASX.js +0 -2484
- package/dist/chunk-YE265ASX.js.map +0 -1
- package/dist/chunk-Z532A7QC.js +0 -78
- package/dist/chunk-Z532A7QC.js.map +0 -1
- package/dist/file-stream.d.ts +0 -43
- package/dist/file-stream.js +0 -9
- package/dist/file-stream.js.map +0 -1
- package/dist/interpreter.d.ts +0 -33
- package/dist/interpreter.js +0 -8
- package/dist/interpreter.js.map +0 -1
- package/dist/request-handler.d.ts +0 -18
- package/dist/request-handler.js +0 -13
- package/dist/request-handler.js.map +0 -1
- package/dist/sandbox-CLZWpfGc.d.ts +0 -613
- package/dist/sandbox.d.ts +0 -4
- package/dist/sandbox.js +0 -13
- package/dist/sandbox.js.map +0 -1
- package/dist/security.d.ts +0 -31
- package/dist/security.js +0 -13
- package/dist/security.js.map +0 -1
- package/dist/sse-parser.d.ts +0 -28
- package/dist/sse-parser.js +0 -11
- package/dist/sse-parser.js.map +0 -1
- package/dist/version.d.ts +0 -8
- package/dist/version.js +0 -7
- package/dist/version.js.map +0 -1
package/src/errors/classes.ts
CHANGED
|
@@ -9,7 +9,8 @@ import type {
|
|
|
9
9
|
CodeExecutionContext,
|
|
10
10
|
CommandErrorContext,
|
|
11
11
|
CommandNotFoundContext,
|
|
12
|
-
ContextNotFoundContext,
|
|
12
|
+
ContextNotFoundContext,
|
|
13
|
+
ErrorResponse,
|
|
13
14
|
FileExistsContext,
|
|
14
15
|
FileNotFoundContext,
|
|
15
16
|
FileSystemContext,
|
|
@@ -25,7 +26,7 @@ import type {
|
|
|
25
26
|
PortNotExposedContext,
|
|
26
27
|
ProcessErrorContext,
|
|
27
28
|
ProcessNotFoundContext,
|
|
28
|
-
ValidationFailedContext
|
|
29
|
+
ValidationFailedContext
|
|
29
30
|
} from '@repo/shared/errors';
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -39,13 +40,27 @@ export class SandboxError<TContext = Record<string, unknown>> extends Error {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
// Convenience accessors
|
|
42
|
-
get code() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
get
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
get
|
|
43
|
+
get code() {
|
|
44
|
+
return this.errorResponse.code;
|
|
45
|
+
}
|
|
46
|
+
get context() {
|
|
47
|
+
return this.errorResponse.context;
|
|
48
|
+
}
|
|
49
|
+
get httpStatus() {
|
|
50
|
+
return this.errorResponse.httpStatus;
|
|
51
|
+
}
|
|
52
|
+
get operation() {
|
|
53
|
+
return this.errorResponse.operation;
|
|
54
|
+
}
|
|
55
|
+
get suggestion() {
|
|
56
|
+
return this.errorResponse.suggestion;
|
|
57
|
+
}
|
|
58
|
+
get timestamp() {
|
|
59
|
+
return this.errorResponse.timestamp;
|
|
60
|
+
}
|
|
61
|
+
get documentation() {
|
|
62
|
+
return this.errorResponse.documentation;
|
|
63
|
+
}
|
|
49
64
|
|
|
50
65
|
// Custom serialization for logging
|
|
51
66
|
toJSON() {
|
|
@@ -78,7 +93,9 @@ export class FileNotFoundError extends SandboxError<FileNotFoundContext> {
|
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
// Type-safe accessors
|
|
81
|
-
get path() {
|
|
96
|
+
get path() {
|
|
97
|
+
return this.context.path;
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
/**
|
|
@@ -91,7 +108,9 @@ export class FileExistsError extends SandboxError<FileExistsContext> {
|
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
// Type-safe accessor
|
|
94
|
-
get path() {
|
|
111
|
+
get path() {
|
|
112
|
+
return this.context.path;
|
|
113
|
+
}
|
|
95
114
|
}
|
|
96
115
|
|
|
97
116
|
/**
|
|
@@ -104,9 +123,15 @@ export class FileSystemError extends SandboxError<FileSystemContext> {
|
|
|
104
123
|
}
|
|
105
124
|
|
|
106
125
|
// Type-safe accessors
|
|
107
|
-
get path() {
|
|
108
|
-
|
|
109
|
-
|
|
126
|
+
get path() {
|
|
127
|
+
return this.context.path;
|
|
128
|
+
}
|
|
129
|
+
get stderr() {
|
|
130
|
+
return this.context.stderr;
|
|
131
|
+
}
|
|
132
|
+
get exitCode() {
|
|
133
|
+
return this.context.exitCode;
|
|
134
|
+
}
|
|
110
135
|
}
|
|
111
136
|
|
|
112
137
|
/**
|
|
@@ -118,7 +143,9 @@ export class PermissionDeniedError extends SandboxError<FileSystemContext> {
|
|
|
118
143
|
this.name = 'PermissionDeniedError';
|
|
119
144
|
}
|
|
120
145
|
|
|
121
|
-
get path() {
|
|
146
|
+
get path() {
|
|
147
|
+
return this.context.path;
|
|
148
|
+
}
|
|
122
149
|
}
|
|
123
150
|
|
|
124
151
|
// ============================================================================
|
|
@@ -135,7 +162,9 @@ export class CommandNotFoundError extends SandboxError<CommandNotFoundContext> {
|
|
|
135
162
|
}
|
|
136
163
|
|
|
137
164
|
// Type-safe accessor
|
|
138
|
-
get command() {
|
|
165
|
+
get command() {
|
|
166
|
+
return this.context.command;
|
|
167
|
+
}
|
|
139
168
|
}
|
|
140
169
|
|
|
141
170
|
/**
|
|
@@ -148,10 +177,18 @@ export class CommandError extends SandboxError<CommandErrorContext> {
|
|
|
148
177
|
}
|
|
149
178
|
|
|
150
179
|
// Type-safe accessors
|
|
151
|
-
get command() {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
get
|
|
180
|
+
get command() {
|
|
181
|
+
return this.context.command;
|
|
182
|
+
}
|
|
183
|
+
get exitCode() {
|
|
184
|
+
return this.context.exitCode;
|
|
185
|
+
}
|
|
186
|
+
get stdout() {
|
|
187
|
+
return this.context.stdout;
|
|
188
|
+
}
|
|
189
|
+
get stderr() {
|
|
190
|
+
return this.context.stderr;
|
|
191
|
+
}
|
|
155
192
|
}
|
|
156
193
|
|
|
157
194
|
// ============================================================================
|
|
@@ -168,7 +205,9 @@ export class ProcessNotFoundError extends SandboxError<ProcessNotFoundContext> {
|
|
|
168
205
|
}
|
|
169
206
|
|
|
170
207
|
// Type-safe accessor
|
|
171
|
-
get processId() {
|
|
208
|
+
get processId() {
|
|
209
|
+
return this.context.processId;
|
|
210
|
+
}
|
|
172
211
|
}
|
|
173
212
|
|
|
174
213
|
/**
|
|
@@ -181,10 +220,18 @@ export class ProcessError extends SandboxError<ProcessErrorContext> {
|
|
|
181
220
|
}
|
|
182
221
|
|
|
183
222
|
// Type-safe accessors
|
|
184
|
-
get processId() {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
get
|
|
223
|
+
get processId() {
|
|
224
|
+
return this.context.processId;
|
|
225
|
+
}
|
|
226
|
+
get pid() {
|
|
227
|
+
return this.context.pid;
|
|
228
|
+
}
|
|
229
|
+
get exitCode() {
|
|
230
|
+
return this.context.exitCode;
|
|
231
|
+
}
|
|
232
|
+
get stderr() {
|
|
233
|
+
return this.context.stderr;
|
|
234
|
+
}
|
|
188
235
|
}
|
|
189
236
|
|
|
190
237
|
// ============================================================================
|
|
@@ -201,8 +248,12 @@ export class PortAlreadyExposedError extends SandboxError<PortAlreadyExposedCont
|
|
|
201
248
|
}
|
|
202
249
|
|
|
203
250
|
// Type-safe accessors
|
|
204
|
-
get port() {
|
|
205
|
-
|
|
251
|
+
get port() {
|
|
252
|
+
return this.context.port;
|
|
253
|
+
}
|
|
254
|
+
get portName() {
|
|
255
|
+
return this.context.portName;
|
|
256
|
+
}
|
|
206
257
|
}
|
|
207
258
|
|
|
208
259
|
/**
|
|
@@ -215,7 +266,9 @@ export class PortNotExposedError extends SandboxError<PortNotExposedContext> {
|
|
|
215
266
|
}
|
|
216
267
|
|
|
217
268
|
// Type-safe accessor
|
|
218
|
-
get port() {
|
|
269
|
+
get port() {
|
|
270
|
+
return this.context.port;
|
|
271
|
+
}
|
|
219
272
|
}
|
|
220
273
|
|
|
221
274
|
/**
|
|
@@ -228,8 +281,12 @@ export class InvalidPortError extends SandboxError<InvalidPortContext> {
|
|
|
228
281
|
}
|
|
229
282
|
|
|
230
283
|
// Type-safe accessors
|
|
231
|
-
get port() {
|
|
232
|
-
|
|
284
|
+
get port() {
|
|
285
|
+
return this.context.port;
|
|
286
|
+
}
|
|
287
|
+
get reason() {
|
|
288
|
+
return this.context.reason;
|
|
289
|
+
}
|
|
233
290
|
}
|
|
234
291
|
|
|
235
292
|
/**
|
|
@@ -242,8 +299,12 @@ export class ServiceNotRespondingError extends SandboxError<PortErrorContext> {
|
|
|
242
299
|
}
|
|
243
300
|
|
|
244
301
|
// Type-safe accessors
|
|
245
|
-
get port() {
|
|
246
|
-
|
|
302
|
+
get port() {
|
|
303
|
+
return this.context.port;
|
|
304
|
+
}
|
|
305
|
+
get portName() {
|
|
306
|
+
return this.context.portName;
|
|
307
|
+
}
|
|
247
308
|
}
|
|
248
309
|
|
|
249
310
|
/**
|
|
@@ -256,7 +317,9 @@ export class PortInUseError extends SandboxError<PortErrorContext> {
|
|
|
256
317
|
}
|
|
257
318
|
|
|
258
319
|
// Type-safe accessor
|
|
259
|
-
get port() {
|
|
320
|
+
get port() {
|
|
321
|
+
return this.context.port;
|
|
322
|
+
}
|
|
260
323
|
}
|
|
261
324
|
|
|
262
325
|
/**
|
|
@@ -269,9 +332,15 @@ export class PortError extends SandboxError<PortErrorContext> {
|
|
|
269
332
|
}
|
|
270
333
|
|
|
271
334
|
// Type-safe accessors
|
|
272
|
-
get port() {
|
|
273
|
-
|
|
274
|
-
|
|
335
|
+
get port() {
|
|
336
|
+
return this.context.port;
|
|
337
|
+
}
|
|
338
|
+
get portName() {
|
|
339
|
+
return this.context.portName;
|
|
340
|
+
}
|
|
341
|
+
get stderr() {
|
|
342
|
+
return this.context.stderr;
|
|
343
|
+
}
|
|
275
344
|
}
|
|
276
345
|
|
|
277
346
|
/**
|
|
@@ -298,7 +367,9 @@ export class GitRepositoryNotFoundError extends SandboxError<GitRepositoryNotFou
|
|
|
298
367
|
}
|
|
299
368
|
|
|
300
369
|
// Type-safe accessor
|
|
301
|
-
get repository() {
|
|
370
|
+
get repository() {
|
|
371
|
+
return this.context.repository;
|
|
372
|
+
}
|
|
302
373
|
}
|
|
303
374
|
|
|
304
375
|
/**
|
|
@@ -311,7 +382,9 @@ export class GitAuthenticationError extends SandboxError<GitAuthFailedContext> {
|
|
|
311
382
|
}
|
|
312
383
|
|
|
313
384
|
// Type-safe accessor
|
|
314
|
-
get repository() {
|
|
385
|
+
get repository() {
|
|
386
|
+
return this.context.repository;
|
|
387
|
+
}
|
|
315
388
|
}
|
|
316
389
|
|
|
317
390
|
/**
|
|
@@ -324,8 +397,12 @@ export class GitBranchNotFoundError extends SandboxError<GitBranchNotFoundContex
|
|
|
324
397
|
}
|
|
325
398
|
|
|
326
399
|
// Type-safe accessors
|
|
327
|
-
get branch() {
|
|
328
|
-
|
|
400
|
+
get branch() {
|
|
401
|
+
return this.context.branch;
|
|
402
|
+
}
|
|
403
|
+
get repository() {
|
|
404
|
+
return this.context.repository;
|
|
405
|
+
}
|
|
329
406
|
}
|
|
330
407
|
|
|
331
408
|
/**
|
|
@@ -338,9 +415,15 @@ export class GitNetworkError extends SandboxError<GitErrorContext> {
|
|
|
338
415
|
}
|
|
339
416
|
|
|
340
417
|
// Type-safe accessors
|
|
341
|
-
get repository() {
|
|
342
|
-
|
|
343
|
-
|
|
418
|
+
get repository() {
|
|
419
|
+
return this.context.repository;
|
|
420
|
+
}
|
|
421
|
+
get branch() {
|
|
422
|
+
return this.context.branch;
|
|
423
|
+
}
|
|
424
|
+
get targetDir() {
|
|
425
|
+
return this.context.targetDir;
|
|
426
|
+
}
|
|
344
427
|
}
|
|
345
428
|
|
|
346
429
|
/**
|
|
@@ -353,10 +436,18 @@ export class GitCloneError extends SandboxError<GitErrorContext> {
|
|
|
353
436
|
}
|
|
354
437
|
|
|
355
438
|
// Type-safe accessors
|
|
356
|
-
get repository() {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
get
|
|
439
|
+
get repository() {
|
|
440
|
+
return this.context.repository;
|
|
441
|
+
}
|
|
442
|
+
get targetDir() {
|
|
443
|
+
return this.context.targetDir;
|
|
444
|
+
}
|
|
445
|
+
get stderr() {
|
|
446
|
+
return this.context.stderr;
|
|
447
|
+
}
|
|
448
|
+
get exitCode() {
|
|
449
|
+
return this.context.exitCode;
|
|
450
|
+
}
|
|
360
451
|
}
|
|
361
452
|
|
|
362
453
|
/**
|
|
@@ -369,9 +460,15 @@ export class GitCheckoutError extends SandboxError<GitErrorContext> {
|
|
|
369
460
|
}
|
|
370
461
|
|
|
371
462
|
// Type-safe accessors
|
|
372
|
-
get branch() {
|
|
373
|
-
|
|
374
|
-
|
|
463
|
+
get branch() {
|
|
464
|
+
return this.context.branch;
|
|
465
|
+
}
|
|
466
|
+
get repository() {
|
|
467
|
+
return this.context.repository;
|
|
468
|
+
}
|
|
469
|
+
get stderr() {
|
|
470
|
+
return this.context.stderr;
|
|
471
|
+
}
|
|
375
472
|
}
|
|
376
473
|
|
|
377
474
|
/**
|
|
@@ -384,7 +481,9 @@ export class InvalidGitUrlError extends SandboxError<ValidationFailedContext> {
|
|
|
384
481
|
}
|
|
385
482
|
|
|
386
483
|
// Type-safe accessor
|
|
387
|
-
get validationErrors() {
|
|
484
|
+
get validationErrors() {
|
|
485
|
+
return this.context.validationErrors;
|
|
486
|
+
}
|
|
388
487
|
}
|
|
389
488
|
|
|
390
489
|
/**
|
|
@@ -397,11 +496,21 @@ export class GitError extends SandboxError<GitErrorContext> {
|
|
|
397
496
|
}
|
|
398
497
|
|
|
399
498
|
// Type-safe accessors
|
|
400
|
-
get repository() {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
get
|
|
404
|
-
|
|
499
|
+
get repository() {
|
|
500
|
+
return this.context.repository;
|
|
501
|
+
}
|
|
502
|
+
get branch() {
|
|
503
|
+
return this.context.branch;
|
|
504
|
+
}
|
|
505
|
+
get targetDir() {
|
|
506
|
+
return this.context.targetDir;
|
|
507
|
+
}
|
|
508
|
+
get stderr() {
|
|
509
|
+
return this.context.stderr;
|
|
510
|
+
}
|
|
511
|
+
get exitCode() {
|
|
512
|
+
return this.context.exitCode;
|
|
513
|
+
}
|
|
405
514
|
}
|
|
406
515
|
|
|
407
516
|
// ============================================================================
|
|
@@ -418,8 +527,12 @@ export class InterpreterNotReadyError extends SandboxError<InterpreterNotReadyCo
|
|
|
418
527
|
}
|
|
419
528
|
|
|
420
529
|
// Type-safe accessors
|
|
421
|
-
get retryAfter() {
|
|
422
|
-
|
|
530
|
+
get retryAfter() {
|
|
531
|
+
return this.context.retryAfter;
|
|
532
|
+
}
|
|
533
|
+
get progress() {
|
|
534
|
+
return this.context.progress;
|
|
535
|
+
}
|
|
423
536
|
}
|
|
424
537
|
|
|
425
538
|
/**
|
|
@@ -432,7 +545,9 @@ export class ContextNotFoundError extends SandboxError<ContextNotFoundContext> {
|
|
|
432
545
|
}
|
|
433
546
|
|
|
434
547
|
// Type-safe accessor
|
|
435
|
-
get contextId() {
|
|
548
|
+
get contextId() {
|
|
549
|
+
return this.context.contextId;
|
|
550
|
+
}
|
|
436
551
|
}
|
|
437
552
|
|
|
438
553
|
/**
|
|
@@ -445,10 +560,18 @@ export class CodeExecutionError extends SandboxError<CodeExecutionContext> {
|
|
|
445
560
|
}
|
|
446
561
|
|
|
447
562
|
// Type-safe accessors
|
|
448
|
-
get contextId() {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
get
|
|
563
|
+
get contextId() {
|
|
564
|
+
return this.context.contextId;
|
|
565
|
+
}
|
|
566
|
+
get ename() {
|
|
567
|
+
return this.context.ename;
|
|
568
|
+
}
|
|
569
|
+
get evalue() {
|
|
570
|
+
return this.context.evalue;
|
|
571
|
+
}
|
|
572
|
+
get traceback() {
|
|
573
|
+
return this.context.traceback;
|
|
574
|
+
}
|
|
452
575
|
}
|
|
453
576
|
|
|
454
577
|
// ============================================================================
|
|
@@ -465,5 +588,7 @@ export class ValidationFailedError extends SandboxError<ValidationFailedContext>
|
|
|
465
588
|
}
|
|
466
589
|
|
|
467
590
|
// Type-safe accessor
|
|
468
|
-
get validationErrors() {
|
|
591
|
+
get validationErrors() {
|
|
592
|
+
return this.context.validationErrors;
|
|
593
|
+
}
|
|
469
594
|
}
|
package/src/errors/index.ts
CHANGED
|
@@ -39,11 +39,13 @@
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
// Re-export context types for advanced usage
|
|
42
|
-
export type {
|
|
42
|
+
export type {
|
|
43
43
|
CodeExecutionContext,
|
|
44
44
|
CommandErrorContext,
|
|
45
45
|
CommandNotFoundContext,
|
|
46
|
-
ContextNotFoundContext,
|
|
46
|
+
ContextNotFoundContext,
|
|
47
|
+
ErrorCodeType,
|
|
48
|
+
ErrorResponse,
|
|
47
49
|
FileExistsContext,
|
|
48
50
|
FileNotFoundContext,
|
|
49
51
|
FileSystemContext,
|
|
@@ -53,13 +55,15 @@ export type {
|
|
|
53
55
|
GitRepositoryNotFoundContext,
|
|
54
56
|
InternalErrorContext,
|
|
55
57
|
InterpreterNotReadyContext,
|
|
56
|
-
InvalidPortContext,
|
|
58
|
+
InvalidPortContext,
|
|
59
|
+
OperationType,
|
|
57
60
|
PortAlreadyExposedContext,
|
|
58
61
|
PortErrorContext,
|
|
59
62
|
PortNotExposedContext,
|
|
60
63
|
ProcessErrorContext,
|
|
61
64
|
ProcessNotFoundContext,
|
|
62
|
-
ValidationFailedContext
|
|
65
|
+
ValidationFailedContext
|
|
66
|
+
} from '@repo/shared/errors';
|
|
63
67
|
// Re-export shared types and constants
|
|
64
68
|
export { ErrorCode, Operation } from '@repo/shared/errors';
|
|
65
69
|
|
|
@@ -101,5 +105,5 @@ export {
|
|
|
101
105
|
SandboxError,
|
|
102
106
|
ServiceNotRespondingError,
|
|
103
107
|
// Validation Errors
|
|
104
|
-
ValidationFailedError
|
|
108
|
+
ValidationFailedError
|
|
105
109
|
} from './classes';
|
package/src/file-stream.ts
CHANGED
|
@@ -3,7 +3,9 @@ import type { FileChunk, FileMetadata, FileStreamEvent } from '@repo/shared';
|
|
|
3
3
|
/**
|
|
4
4
|
* Parse SSE (Server-Sent Events) lines from a stream
|
|
5
5
|
*/
|
|
6
|
-
async function* parseSSE(
|
|
6
|
+
async function* parseSSE(
|
|
7
|
+
stream: ReadableStream<Uint8Array>
|
|
8
|
+
): AsyncGenerator<FileStreamEvent> {
|
|
7
9
|
const reader = stream.getReader();
|
|
8
10
|
const decoder = new TextDecoder();
|
|
9
11
|
let buffer = '';
|
|
@@ -59,7 +61,9 @@ async function* parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<Fil
|
|
|
59
61
|
* }
|
|
60
62
|
* ```
|
|
61
63
|
*/
|
|
62
|
-
export async function* streamFile(
|
|
64
|
+
export async function* streamFile(
|
|
65
|
+
stream: ReadableStream<Uint8Array>
|
|
66
|
+
): AsyncGenerator<FileChunk, FileMetadata> {
|
|
63
67
|
let metadata: FileMetadata | null = null;
|
|
64
68
|
|
|
65
69
|
for await (const event of parseSSE(stream)) {
|
|
@@ -69,7 +73,7 @@ export async function* streamFile(stream: ReadableStream<Uint8Array>): AsyncGene
|
|
|
69
73
|
mimeType: event.mimeType,
|
|
70
74
|
size: event.size,
|
|
71
75
|
isBinary: event.isBinary,
|
|
72
|
-
encoding: event.encoding
|
|
76
|
+
encoding: event.encoding
|
|
73
77
|
};
|
|
74
78
|
break;
|
|
75
79
|
|
|
@@ -144,8 +148,9 @@ export async function collectFile(stream: ReadableStream<Uint8Array>): Promise<{
|
|
|
144
148
|
// Combine chunks based on type
|
|
145
149
|
if (metadata.isBinary) {
|
|
146
150
|
// Binary file - combine Uint8Arrays
|
|
147
|
-
const totalLength = chunks.reduce(
|
|
148
|
-
sum + (chunk instanceof Uint8Array ? chunk.length : 0),
|
|
151
|
+
const totalLength = chunks.reduce(
|
|
152
|
+
(sum, chunk) => sum + (chunk instanceof Uint8Array ? chunk.length : 0),
|
|
153
|
+
0
|
|
149
154
|
);
|
|
150
155
|
const combined = new Uint8Array(totalLength);
|
|
151
156
|
let offset = 0;
|
|
@@ -158,7 +163,7 @@ export async function collectFile(stream: ReadableStream<Uint8Array>): Promise<{
|
|
|
158
163
|
return { content: combined, metadata };
|
|
159
164
|
} else {
|
|
160
165
|
// Text file - combine strings
|
|
161
|
-
const combined = chunks.filter(c => typeof c === 'string').join('');
|
|
166
|
+
const combined = chunks.filter((c) => typeof c === 'string').join('');
|
|
162
167
|
return { content: combined, metadata };
|
|
163
168
|
}
|
|
164
169
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Export the main Sandbox class and utilities
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
// Export the new client architecture
|
|
5
4
|
export {
|
|
6
5
|
CommandClient,
|
|
@@ -10,8 +9,8 @@ export {
|
|
|
10
9
|
ProcessClient,
|
|
11
10
|
SandboxClient,
|
|
12
11
|
UtilityClient
|
|
13
|
-
} from
|
|
14
|
-
export { getSandbox, Sandbox } from
|
|
12
|
+
} from './clients';
|
|
13
|
+
export { getSandbox, Sandbox } from './sandbox';
|
|
15
14
|
|
|
16
15
|
// Legacy types are now imported from the new client architecture
|
|
17
16
|
|
|
@@ -20,21 +19,20 @@ export type {
|
|
|
20
19
|
BaseExecOptions,
|
|
21
20
|
ExecEvent,
|
|
22
21
|
ExecOptions,
|
|
23
|
-
ExecResult,
|
|
22
|
+
ExecResult,
|
|
23
|
+
FileChunk,
|
|
24
|
+
FileMetadata,
|
|
25
|
+
FileStreamEvent,
|
|
24
26
|
ISandbox,
|
|
25
27
|
LogEvent,
|
|
26
28
|
Process,
|
|
27
29
|
ProcessOptions,
|
|
28
30
|
ProcessStatus,
|
|
29
|
-
StreamOptions
|
|
30
|
-
} from
|
|
31
|
+
StreamOptions
|
|
32
|
+
} from '@repo/shared';
|
|
31
33
|
export * from '@repo/shared';
|
|
32
34
|
// Export type guards for runtime validation
|
|
33
|
-
export {
|
|
34
|
-
isExecResult,
|
|
35
|
-
isProcess,
|
|
36
|
-
isProcessStatus
|
|
37
|
-
} from "@repo/shared";
|
|
35
|
+
export { isExecResult, isProcess, isProcessStatus } from '@repo/shared';
|
|
38
36
|
// Export all client types from new architecture
|
|
39
37
|
export type {
|
|
40
38
|
BaseApiResponse,
|
|
@@ -79,15 +77,24 @@ export type {
|
|
|
79
77
|
StartProcessRequest,
|
|
80
78
|
UnexposePortRequest,
|
|
81
79
|
WriteFileRequest
|
|
82
|
-
} from
|
|
83
|
-
export type {
|
|
80
|
+
} from './clients';
|
|
81
|
+
export type {
|
|
82
|
+
ExecutionCallbacks,
|
|
83
|
+
InterpreterClient
|
|
84
|
+
} from './clients/interpreter-client.js';
|
|
84
85
|
// Export file streaming utilities for binary file support
|
|
85
86
|
export { collectFile, streamFile } from './file-stream';
|
|
86
87
|
// Export interpreter functionality
|
|
87
88
|
export { CodeInterpreter } from './interpreter.js';
|
|
88
89
|
// Re-export request handler utilities
|
|
89
90
|
export {
|
|
90
|
-
proxyToSandbox,
|
|
91
|
+
proxyToSandbox,
|
|
92
|
+
type RouteInfo,
|
|
93
|
+
type SandboxEnv
|
|
91
94
|
} from './request-handler';
|
|
92
95
|
// Export SSE parser for converting ReadableStream to AsyncIterable
|
|
93
|
-
export {
|
|
96
|
+
export {
|
|
97
|
+
asyncIterableToSSEStream,
|
|
98
|
+
parseSSEStream,
|
|
99
|
+
responseToAsyncIterable
|
|
100
|
+
} from './sse-parser';
|