@cloudflare/sandbox 0.0.0-7fd1847 → 0.0.0-80fd0f2

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 (74) hide show
  1. package/CHANGELOG.md +110 -15
  2. package/Dockerfile +84 -31
  3. package/README.md +9 -2
  4. package/dist/index.d.ts +1924 -9
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +3245 -64
  7. package/dist/index.js.map +1 -1
  8. package/package.json +9 -9
  9. package/src/clients/base-client.ts +39 -24
  10. package/src/clients/command-client.ts +8 -8
  11. package/src/clients/file-client.ts +51 -20
  12. package/src/clients/git-client.ts +9 -3
  13. package/src/clients/index.ts +12 -15
  14. package/src/clients/interpreter-client.ts +51 -47
  15. package/src/clients/port-client.ts +10 -10
  16. package/src/clients/process-client.ts +11 -8
  17. package/src/clients/sandbox-client.ts +2 -4
  18. package/src/clients/types.ts +6 -2
  19. package/src/clients/utility-client.ts +34 -5
  20. package/src/errors/adapter.ts +90 -32
  21. package/src/errors/classes.ts +189 -64
  22. package/src/errors/index.ts +9 -5
  23. package/src/file-stream.ts +11 -6
  24. package/src/index.ts +22 -15
  25. package/src/interpreter.ts +50 -41
  26. package/src/request-handler.ts +34 -21
  27. package/src/sandbox.ts +469 -150
  28. package/src/security.ts +21 -6
  29. package/src/sse-parser.ts +4 -3
  30. package/src/version.ts +6 -0
  31. package/tests/base-client.test.ts +116 -80
  32. package/tests/command-client.test.ts +149 -112
  33. package/tests/file-client.test.ts +373 -185
  34. package/tests/file-stream.test.ts +24 -20
  35. package/tests/get-sandbox.test.ts +149 -0
  36. package/tests/git-client.test.ts +260 -101
  37. package/tests/port-client.test.ts +100 -108
  38. package/tests/process-client.test.ts +204 -179
  39. package/tests/request-handler.test.ts +292 -0
  40. package/tests/sandbox.test.ts +303 -62
  41. package/tests/sse-parser.test.ts +17 -16
  42. package/tests/utility-client.test.ts +129 -56
  43. package/tests/version.test.ts +16 -0
  44. package/tsdown.config.ts +12 -0
  45. package/vitest.config.ts +6 -6
  46. package/dist/chunk-BFVUNTP4.js +0 -104
  47. package/dist/chunk-BFVUNTP4.js.map +0 -1
  48. package/dist/chunk-EKSWCBCA.js +0 -86
  49. package/dist/chunk-EKSWCBCA.js.map +0 -1
  50. package/dist/chunk-EXQOIRZI.js +0 -2351
  51. package/dist/chunk-EXQOIRZI.js.map +0 -1
  52. package/dist/chunk-JXZMAU2C.js +0 -559
  53. package/dist/chunk-JXZMAU2C.js.map +0 -1
  54. package/dist/chunk-Z532A7QC.js +0 -78
  55. package/dist/chunk-Z532A7QC.js.map +0 -1
  56. package/dist/file-stream.d.ts +0 -43
  57. package/dist/file-stream.js +0 -9
  58. package/dist/file-stream.js.map +0 -1
  59. package/dist/interpreter.d.ts +0 -33
  60. package/dist/interpreter.js +0 -8
  61. package/dist/interpreter.js.map +0 -1
  62. package/dist/request-handler.d.ts +0 -18
  63. package/dist/request-handler.js +0 -12
  64. package/dist/request-handler.js.map +0 -1
  65. package/dist/sandbox-D9K2ypln.d.ts +0 -583
  66. package/dist/sandbox.d.ts +0 -4
  67. package/dist/sandbox.js +0 -12
  68. package/dist/sandbox.js.map +0 -1
  69. package/dist/security.d.ts +0 -31
  70. package/dist/security.js +0 -13
  71. package/dist/security.js.map +0 -1
  72. package/dist/sse-parser.d.ts +0 -28
  73. package/dist/sse-parser.js +0 -11
  74. package/dist/sse-parser.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,9 +1,1924 @@
1
- export { B as BaseApiResponse, C as CommandClient, f as CommandExecuteResponse, c as CommandsResponse, d as ContainerStub, E as ErrorResponse, e as ExecuteRequest, p as ExecutionCallbacks, h as ExposePortRequest, F as FileClient, i as FileOperationRequest, j as GitCheckoutRequest, G as GitClient, I as InterpreterClient, M as MkdirRequest, k as PingResponse, P as PortClient, a as ProcessClient, R as ReadFileRequest, l as RequestConfig, m as ResponseHandler, b as Sandbox, S as SandboxClient, H as SandboxClientOptions, n as SessionRequest, o as UnexposePortRequest, U as UtilityClient, W as WriteFileRequest, g as getSandbox } from './sandbox-D9K2ypln.js';
2
- export * from '@repo/shared';
3
- export { BaseExecOptions, ExecEvent, ExecOptions, ExecResult, FileChunk, FileMetadata, FileStreamEvent, GitCheckoutResult, ISandbox, LogEvent, PortCloseResult, PortExposeResult, PortListResult, Process, ProcessCleanupResult, ProcessInfoResult, ProcessKillResult, ProcessListResult, ProcessLogsResult, ProcessOptions, ProcessStartResult, ProcessStatus, StartProcessRequest, StreamOptions, isExecResult, isProcess, isProcessStatus } from '@repo/shared';
4
- export { collectFile, streamFile } from './file-stream.js';
5
- export { CodeInterpreter } from './interpreter.js';
6
- export { RouteInfo, SandboxEnv, proxyToSandbox } from './request-handler.js';
7
- export { asyncIterableToSSEStream, parseSSEStream, responseToAsyncIterable } from './sse-parser.js';
8
- import 'cloudflare:workers';
9
- import '@cloudflare/containers';
1
+ import { Container } from "@cloudflare/containers";
2
+
3
+ //#region ../shared/dist/logger/types.d.ts
4
+
5
+ /**
6
+ * Logger types for Cloudflare Sandbox SDK
7
+ *
8
+ * Provides structured, trace-aware logging across Worker, Durable Object, and Container.
9
+ */
10
+ /**
11
+ * Log levels (from most to least verbose)
12
+ */
13
+ declare enum LogLevel {
14
+ DEBUG = 0,
15
+ INFO = 1,
16
+ WARN = 2,
17
+ ERROR = 3,
18
+ }
19
+ type LogComponent = 'container' | 'sandbox-do' | 'executor';
20
+ /**
21
+ * Context metadata included in every log entry
22
+ */
23
+ interface LogContext {
24
+ /**
25
+ * Unique trace ID for request correlation across distributed components
26
+ * Format: "tr_" + 16 hex chars (e.g., "tr_7f3a9b2c4e5d6f1a")
27
+ */
28
+ traceId: string;
29
+ /**
30
+ * Component that generated the log
31
+ */
32
+ component: LogComponent;
33
+ /**
34
+ * Sandbox identifier (which sandbox instance)
35
+ */
36
+ sandboxId?: string;
37
+ /**
38
+ * Session identifier (which session within sandbox)
39
+ */
40
+ sessionId?: string;
41
+ /**
42
+ * Process identifier (which background process)
43
+ */
44
+ processId?: string;
45
+ /**
46
+ * Command identifier (which command execution)
47
+ */
48
+ commandId?: string;
49
+ /**
50
+ * Operation name (e.g., 'exec', 'startProcess', 'writeFile')
51
+ */
52
+ operation?: string;
53
+ /**
54
+ * Duration in milliseconds
55
+ */
56
+ duration?: number;
57
+ /**
58
+ * Extensible for additional metadata
59
+ */
60
+ [key: string]: unknown;
61
+ }
62
+ /**
63
+ * Logger interface for structured logging
64
+ *
65
+ * All methods accept optional context that gets merged with the logger's base context.
66
+ */
67
+ interface Logger {
68
+ /**
69
+ * Log debug-level message (most verbose, typically disabled in production)
70
+ *
71
+ * @param message Human-readable message
72
+ * @param context Optional additional context
73
+ */
74
+ debug(message: string, context?: Partial<LogContext>): void;
75
+ /**
76
+ * Log info-level message (normal operational events)
77
+ *
78
+ * @param message Human-readable message
79
+ * @param context Optional additional context
80
+ */
81
+ info(message: string, context?: Partial<LogContext>): void;
82
+ /**
83
+ * Log warning-level message (recoverable issues, degraded state)
84
+ *
85
+ * @param message Human-readable message
86
+ * @param context Optional additional context
87
+ */
88
+ warn(message: string, context?: Partial<LogContext>): void;
89
+ /**
90
+ * Log error-level message (failures, exceptions)
91
+ *
92
+ * @param message Human-readable message
93
+ * @param error Optional Error object to include
94
+ * @param context Optional additional context
95
+ */
96
+ error(message: string, error?: Error, context?: Partial<LogContext>): void;
97
+ /**
98
+ * Create a child logger with additional context
99
+ *
100
+ * The child logger inherits all context from the parent and adds new context.
101
+ * This is useful for adding operation-specific context without passing through parameters.
102
+ *
103
+ * @param context Additional context to merge
104
+ * @returns New logger instance with merged context
105
+ *
106
+ * @example
107
+ * const logger = createLogger({ component: 'sandbox-do', traceId: 'tr_abc123' });
108
+ * const execLogger = logger.child({ operation: 'exec', commandId: 'cmd-456' });
109
+ * execLogger.info('Command started'); // Includes all context: component, traceId, operation, commandId
110
+ */
111
+ child(context: Partial<LogContext>): Logger;
112
+ }
113
+ //#endregion
114
+ //#region ../shared/dist/logger/trace-context.d.ts
115
+ /**
116
+ * Trace context utilities for request correlation
117
+ *
118
+ * Trace IDs enable correlating logs across distributed components:
119
+ * Worker → Durable Object → Container → back
120
+ *
121
+ * The trace ID is propagated via the X-Trace-Id HTTP header.
122
+ */
123
+ /**
124
+ * Utility for managing trace context across distributed components
125
+ */
126
+ declare class TraceContext {
127
+ /**
128
+ * HTTP header name for trace ID propagation
129
+ */
130
+ private static readonly TRACE_HEADER;
131
+ /**
132
+ * Generate a new trace ID
133
+ *
134
+ * Format: "tr_" + 16 random hex characters
135
+ * Example: "tr_7f3a9b2c4e5d6f1a"
136
+ *
137
+ * @returns Newly generated trace ID
138
+ */
139
+ static generate(): string;
140
+ /**
141
+ * Extract trace ID from HTTP request headers
142
+ *
143
+ * @param headers Request headers
144
+ * @returns Trace ID if present, null otherwise
145
+ */
146
+ static fromHeaders(headers: Headers): string | null;
147
+ /**
148
+ * Create headers object with trace ID for outgoing requests
149
+ *
150
+ * @param traceId Trace ID to include
151
+ * @returns Headers object with X-Trace-Id set
152
+ */
153
+ static toHeaders(traceId: string): Record<string, string>;
154
+ /**
155
+ * Get the header name used for trace ID propagation
156
+ *
157
+ * @returns Header name ("X-Trace-Id")
158
+ */
159
+ static getHeaderName(): string;
160
+ }
161
+ //#endregion
162
+ //#region ../shared/dist/logger/index.d.ts
163
+
164
+ /**
165
+ * Create a no-op logger for testing
166
+ *
167
+ * Returns a logger that implements the Logger interface but does nothing.
168
+ * Useful for tests that don't need actual logging output.
169
+ *
170
+ * @returns No-op logger instance
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // In tests
175
+ * const client = new HttpClient({
176
+ * baseUrl: 'http://test.com',
177
+ * logger: createNoOpLogger() // Optional - tests can enable real logging if needed
178
+ * });
179
+ * ```
180
+ */
181
+ declare function createNoOpLogger(): Logger;
182
+ /**
183
+ * Get the current logger from AsyncLocalStorage
184
+ *
185
+ * @throws Error if no logger is initialized in the current async context
186
+ * @returns Current logger instance
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * function someHelperFunction() {
191
+ * const logger = getLogger(); // Automatically has all context!
192
+ * logger.info('Helper called');
193
+ * }
194
+ * ```
195
+ */
196
+ declare function getLogger(): Logger;
197
+ /**
198
+ * Run a function with a logger stored in AsyncLocalStorage
199
+ *
200
+ * The logger is available to all code within the function via getLogger().
201
+ * This is typically called at request entry points (fetch handler) and when
202
+ * creating child loggers with additional context.
203
+ *
204
+ * @param logger Logger instance to store in context
205
+ * @param fn Function to execute with logger context
206
+ * @returns Result of the function
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * // At request entry point
211
+ * async fetch(request: Request): Promise<Response> {
212
+ * const logger = createLogger({ component: 'sandbox-do', traceId: 'tr_abc' });
213
+ * return runWithLogger(logger, async () => {
214
+ * return await this.handleRequest(request);
215
+ * });
216
+ * }
217
+ *
218
+ * // When adding operation context
219
+ * async exec(command: string) {
220
+ * const logger = getLogger().child({ operation: 'exec', commandId: 'cmd-123' });
221
+ * return runWithLogger(logger, async () => {
222
+ * logger.info('Command started');
223
+ * await this.executeCommand(command); // Nested calls get the child logger
224
+ * logger.info('Command completed');
225
+ * });
226
+ * }
227
+ * ```
228
+ */
229
+ declare function runWithLogger<T>(logger: Logger, fn: () => T | Promise<T>): T | Promise<T>;
230
+ /**
231
+ * Create a new logger instance
232
+ *
233
+ * @param context Base context for the logger. Must include 'component'.
234
+ * TraceId will be auto-generated if not provided.
235
+ * @returns New logger instance
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * // In Durable Object
240
+ * const logger = createLogger({
241
+ * component: 'sandbox-do',
242
+ * traceId: TraceContext.fromHeaders(request.headers) || TraceContext.generate(),
243
+ * sandboxId: this.id
244
+ * });
245
+ *
246
+ * // In Container
247
+ * const logger = createLogger({
248
+ * component: 'container',
249
+ * traceId: TraceContext.fromHeaders(request.headers)!,
250
+ * sessionId: this.id
251
+ * });
252
+ * ```
253
+ */
254
+ declare function createLogger(context: Partial<LogContext> & {
255
+ component: LogComponent;
256
+ }): Logger;
257
+ //#endregion
258
+ //#region ../shared/dist/git.d.ts
259
+ /**
260
+ * Redact credentials from URLs for secure logging
261
+ *
262
+ * Replaces any credentials (username:password, tokens, etc.) embedded
263
+ * in URLs with ****** to prevent sensitive data exposure in logs.
264
+ * Works with URLs embedded in text (e.g., "Error: https://token@github.com/repo.git failed")
265
+ *
266
+ * @param text - String that may contain URLs with credentials
267
+ * @returns String with credentials redacted from any URLs
268
+ */
269
+ declare function redactCredentials(text: string): string;
270
+ /**
271
+ * Sanitize data by redacting credentials from any strings
272
+ * Recursively processes objects and arrays to ensure credentials are never leaked
273
+ */
274
+ declare function sanitizeGitData<T>(data: T): T;
275
+ /**
276
+ * Logger wrapper that automatically sanitizes git credentials
277
+ */
278
+ declare class GitLogger implements Logger {
279
+ private readonly baseLogger;
280
+ constructor(baseLogger: Logger);
281
+ private sanitizeContext;
282
+ private sanitizeError;
283
+ debug(message: string, context?: Partial<LogContext>): void;
284
+ info(message: string, context?: Partial<LogContext>): void;
285
+ warn(message: string, context?: Partial<LogContext>): void;
286
+ error(message: string, error?: Error, context?: Partial<LogContext>): void;
287
+ child(context: Partial<LogContext>): Logger;
288
+ }
289
+ //#endregion
290
+ //#region ../shared/dist/interpreter-types.d.ts
291
+ interface CreateContextOptions {
292
+ /**
293
+ * Programming language for the context
294
+ * @default 'python'
295
+ */
296
+ language?: 'python' | 'javascript' | 'typescript';
297
+ /**
298
+ * Working directory for the context
299
+ * @default '/workspace'
300
+ */
301
+ cwd?: string;
302
+ /**
303
+ * Environment variables for the context
304
+ */
305
+ envVars?: Record<string, string>;
306
+ /**
307
+ * Request timeout in milliseconds
308
+ * @default 30000
309
+ */
310
+ timeout?: number;
311
+ }
312
+ interface CodeContext {
313
+ /**
314
+ * Unique identifier for the context
315
+ */
316
+ readonly id: string;
317
+ /**
318
+ * Programming language of the context
319
+ */
320
+ readonly language: string;
321
+ /**
322
+ * Current working directory
323
+ */
324
+ readonly cwd: string;
325
+ /**
326
+ * When the context was created
327
+ */
328
+ readonly createdAt: Date;
329
+ /**
330
+ * When the context was last used
331
+ */
332
+ readonly lastUsed: Date;
333
+ }
334
+ interface RunCodeOptions {
335
+ /**
336
+ * Context to run the code in. If not provided, uses default context for the language
337
+ */
338
+ context?: CodeContext;
339
+ /**
340
+ * Language to use if context is not provided
341
+ * @default 'python'
342
+ */
343
+ language?: 'python' | 'javascript' | 'typescript';
344
+ /**
345
+ * Environment variables for this execution
346
+ */
347
+ envVars?: Record<string, string>;
348
+ /**
349
+ * Execution timeout in milliseconds
350
+ * @default 60000
351
+ */
352
+ timeout?: number;
353
+ /**
354
+ * AbortSignal for cancelling execution
355
+ */
356
+ signal?: AbortSignal;
357
+ /**
358
+ * Callback for stdout output
359
+ */
360
+ onStdout?: (output: OutputMessage) => void | Promise<void>;
361
+ /**
362
+ * Callback for stderr output
363
+ */
364
+ onStderr?: (output: OutputMessage) => void | Promise<void>;
365
+ /**
366
+ * Callback for execution results (charts, tables, etc)
367
+ */
368
+ onResult?: (result: Result) => void | Promise<void>;
369
+ /**
370
+ * Callback for execution errors
371
+ */
372
+ onError?: (error: ExecutionError) => void | Promise<void>;
373
+ }
374
+ interface OutputMessage {
375
+ /**
376
+ * The output text
377
+ */
378
+ text: string;
379
+ /**
380
+ * Timestamp of the output
381
+ */
382
+ timestamp: number;
383
+ }
384
+ interface Result {
385
+ /**
386
+ * Plain text representation
387
+ */
388
+ text?: string;
389
+ /**
390
+ * HTML representation (tables, formatted output)
391
+ */
392
+ html?: string;
393
+ /**
394
+ * PNG image data (base64 encoded)
395
+ */
396
+ png?: string;
397
+ /**
398
+ * JPEG image data (base64 encoded)
399
+ */
400
+ jpeg?: string;
401
+ /**
402
+ * SVG image data
403
+ */
404
+ svg?: string;
405
+ /**
406
+ * LaTeX representation
407
+ */
408
+ latex?: string;
409
+ /**
410
+ * Markdown representation
411
+ */
412
+ markdown?: string;
413
+ /**
414
+ * JavaScript code to execute
415
+ */
416
+ javascript?: string;
417
+ /**
418
+ * JSON data
419
+ */
420
+ json?: any;
421
+ /**
422
+ * Chart data if the result is a visualization
423
+ */
424
+ chart?: ChartData;
425
+ /**
426
+ * Raw data object
427
+ */
428
+ data?: any;
429
+ /**
430
+ * Available output formats
431
+ */
432
+ formats(): string[];
433
+ }
434
+ interface ChartData {
435
+ /**
436
+ * Type of chart
437
+ */
438
+ type: 'line' | 'bar' | 'scatter' | 'pie' | 'histogram' | 'heatmap' | 'unknown';
439
+ /**
440
+ * Chart title
441
+ */
442
+ title?: string;
443
+ /**
444
+ * Chart data (format depends on library)
445
+ */
446
+ data: any;
447
+ /**
448
+ * Chart layout/configuration
449
+ */
450
+ layout?: any;
451
+ /**
452
+ * Additional configuration
453
+ */
454
+ config?: any;
455
+ /**
456
+ * Library that generated the chart
457
+ */
458
+ library?: 'matplotlib' | 'plotly' | 'altair' | 'seaborn' | 'unknown';
459
+ /**
460
+ * Base64 encoded image if available
461
+ */
462
+ image?: string;
463
+ }
464
+ interface ExecutionError {
465
+ /**
466
+ * Error name/type (e.g., 'NameError', 'SyntaxError')
467
+ */
468
+ name: string;
469
+ /**
470
+ * Error message
471
+ */
472
+ message: string;
473
+ /**
474
+ * Stack trace
475
+ */
476
+ traceback: string[];
477
+ /**
478
+ * Line number where error occurred
479
+ */
480
+ lineNumber?: number;
481
+ }
482
+ interface ExecutionResult {
483
+ code: string;
484
+ logs: {
485
+ stdout: string[];
486
+ stderr: string[];
487
+ };
488
+ error?: ExecutionError;
489
+ executionCount?: number;
490
+ results: Array<{
491
+ text?: string;
492
+ html?: string;
493
+ png?: string;
494
+ jpeg?: string;
495
+ svg?: string;
496
+ latex?: string;
497
+ markdown?: string;
498
+ javascript?: string;
499
+ json?: any;
500
+ chart?: ChartData;
501
+ data?: any;
502
+ }>;
503
+ }
504
+ declare class Execution {
505
+ readonly code: string;
506
+ readonly context: CodeContext;
507
+ /**
508
+ * All results from the execution
509
+ */
510
+ results: Result[];
511
+ /**
512
+ * Accumulated stdout and stderr
513
+ */
514
+ logs: {
515
+ stdout: string[];
516
+ stderr: string[];
517
+ };
518
+ /**
519
+ * Execution error if any
520
+ */
521
+ error?: ExecutionError;
522
+ /**
523
+ * Execution count (for interpreter)
524
+ */
525
+ executionCount?: number;
526
+ constructor(code: string, context: CodeContext);
527
+ /**
528
+ * Convert to a plain object for serialization
529
+ */
530
+ toJSON(): ExecutionResult;
531
+ }
532
+ declare class ResultImpl implements Result {
533
+ private raw;
534
+ constructor(raw: any);
535
+ get text(): string | undefined;
536
+ get html(): string | undefined;
537
+ get png(): string | undefined;
538
+ get jpeg(): string | undefined;
539
+ get svg(): string | undefined;
540
+ get latex(): string | undefined;
541
+ get markdown(): string | undefined;
542
+ get javascript(): string | undefined;
543
+ get json(): any;
544
+ get chart(): ChartData | undefined;
545
+ get data(): any;
546
+ formats(): string[];
547
+ }
548
+ //#endregion
549
+ //#region ../shared/dist/request-types.d.ts
550
+ /**
551
+ * Request to start a background process
552
+ * Uses flat structure consistent with other endpoints
553
+ */
554
+ interface StartProcessRequest {
555
+ command: string;
556
+ sessionId?: string;
557
+ processId?: string;
558
+ timeoutMs?: number;
559
+ env?: Record<string, string>;
560
+ cwd?: string;
561
+ encoding?: string;
562
+ autoCleanup?: boolean;
563
+ }
564
+ /**
565
+ * Request to delete a file
566
+ */
567
+ interface DeleteFileRequest {
568
+ path: string;
569
+ sessionId?: string;
570
+ }
571
+ /**
572
+ * Request to rename a file
573
+ */
574
+ interface RenameFileRequest {
575
+ oldPath: string;
576
+ newPath: string;
577
+ sessionId?: string;
578
+ }
579
+ /**
580
+ * Request to move a file
581
+ */
582
+ interface MoveFileRequest {
583
+ sourcePath: string;
584
+ destinationPath: string;
585
+ sessionId?: string;
586
+ }
587
+ /**
588
+ * Request to check if a file or directory exists
589
+ */
590
+ interface FileExistsRequest {
591
+ path: string;
592
+ sessionId?: string;
593
+ }
594
+ /**
595
+ * Request to create a session
596
+ */
597
+ interface SessionCreateRequest {
598
+ id?: string;
599
+ name?: string;
600
+ env?: Record<string, string>;
601
+ cwd?: string;
602
+ }
603
+ /**
604
+ * Request to delete a session
605
+ */
606
+ interface SessionDeleteRequest {
607
+ sessionId: string;
608
+ }
609
+ //#endregion
610
+ //#region ../shared/dist/types.d.ts
611
+ interface BaseExecOptions {
612
+ /**
613
+ * Maximum execution time in milliseconds
614
+ */
615
+ timeout?: number;
616
+ /**
617
+ * Environment variables for the command
618
+ */
619
+ env?: Record<string, string>;
620
+ /**
621
+ * Working directory for command execution
622
+ */
623
+ cwd?: string;
624
+ /**
625
+ * Text encoding for output (default: 'utf8')
626
+ */
627
+ encoding?: string;
628
+ }
629
+ interface ExecOptions extends BaseExecOptions {
630
+ /**
631
+ * Enable real-time output streaming via callbacks
632
+ */
633
+ stream?: boolean;
634
+ /**
635
+ * Callback for real-time output data
636
+ */
637
+ onOutput?: (stream: 'stdout' | 'stderr', data: string) => void;
638
+ /**
639
+ * Callback when command completes (only when stream: true)
640
+ */
641
+ onComplete?: (result: ExecResult) => void;
642
+ /**
643
+ * Callback for execution errors
644
+ */
645
+ onError?: (error: Error) => void;
646
+ /**
647
+ * AbortSignal for cancelling execution
648
+ */
649
+ signal?: AbortSignal;
650
+ }
651
+ interface ExecResult {
652
+ /**
653
+ * Whether the command succeeded (exitCode === 0)
654
+ */
655
+ success: boolean;
656
+ /**
657
+ * Process exit code
658
+ */
659
+ exitCode: number;
660
+ /**
661
+ * Standard output content
662
+ */
663
+ stdout: string;
664
+ /**
665
+ * Standard error content
666
+ */
667
+ stderr: string;
668
+ /**
669
+ * Command that was executed
670
+ */
671
+ command: string;
672
+ /**
673
+ * Execution duration in milliseconds
674
+ */
675
+ duration: number;
676
+ /**
677
+ * ISO timestamp when command started
678
+ */
679
+ timestamp: string;
680
+ /**
681
+ * Session ID if provided
682
+ */
683
+ sessionId?: string;
684
+ }
685
+ interface ProcessOptions extends BaseExecOptions {
686
+ /**
687
+ * Custom process ID for later reference
688
+ * If not provided, a UUID will be generated
689
+ */
690
+ processId?: string;
691
+ /**
692
+ * Automatically cleanup process record after exit (default: true)
693
+ */
694
+ autoCleanup?: boolean;
695
+ /**
696
+ * Callback when process exits
697
+ */
698
+ onExit?: (code: number | null) => void;
699
+ /**
700
+ * Callback for real-time output (background processes)
701
+ */
702
+ onOutput?: (stream: 'stdout' | 'stderr', data: string) => void;
703
+ /**
704
+ * Callback when process starts successfully
705
+ */
706
+ onStart?: (process: Process) => void;
707
+ /**
708
+ * Callback for process errors
709
+ */
710
+ onError?: (error: Error) => void;
711
+ }
712
+ type ProcessStatus = 'starting' | 'running' | 'completed' | 'failed' | 'killed' | 'error';
713
+ interface Process {
714
+ /**
715
+ * Unique process identifier
716
+ */
717
+ readonly id: string;
718
+ /**
719
+ * System process ID (if available and running)
720
+ */
721
+ readonly pid?: number;
722
+ /**
723
+ * Command that was executed
724
+ */
725
+ readonly command: string;
726
+ /**
727
+ * Current process status
728
+ */
729
+ readonly status: ProcessStatus;
730
+ /**
731
+ * When the process was started
732
+ */
733
+ readonly startTime: Date;
734
+ /**
735
+ * When the process ended (if completed)
736
+ */
737
+ readonly endTime?: Date;
738
+ /**
739
+ * Process exit code (if completed)
740
+ */
741
+ readonly exitCode?: number;
742
+ /**
743
+ * Session ID if provided
744
+ */
745
+ readonly sessionId?: string;
746
+ /**
747
+ * Kill the process
748
+ */
749
+ kill(signal?: string): Promise<void>;
750
+ /**
751
+ * Get current process status (refreshed)
752
+ */
753
+ getStatus(): Promise<ProcessStatus>;
754
+ /**
755
+ * Get accumulated logs
756
+ */
757
+ getLogs(): Promise<{
758
+ stdout: string;
759
+ stderr: string;
760
+ }>;
761
+ }
762
+ interface ExecEvent {
763
+ type: 'start' | 'stdout' | 'stderr' | 'complete' | 'error';
764
+ timestamp: string;
765
+ data?: string;
766
+ command?: string;
767
+ exitCode?: number;
768
+ result?: ExecResult;
769
+ error?: string;
770
+ sessionId?: string;
771
+ }
772
+ interface LogEvent {
773
+ type: 'stdout' | 'stderr' | 'exit' | 'error';
774
+ timestamp: string;
775
+ data: string;
776
+ processId: string;
777
+ sessionId?: string;
778
+ exitCode?: number;
779
+ }
780
+ interface StreamOptions extends BaseExecOptions {
781
+ /**
782
+ * Buffer size for streaming output
783
+ */
784
+ bufferSize?: number;
785
+ /**
786
+ * AbortSignal for cancelling stream
787
+ */
788
+ signal?: AbortSignal;
789
+ }
790
+ interface SessionOptions {
791
+ /**
792
+ * Optional session ID (auto-generated if not provided)
793
+ */
794
+ id?: string;
795
+ /**
796
+ * Session name for identification
797
+ */
798
+ name?: string;
799
+ /**
800
+ * Environment variables for this session
801
+ */
802
+ env?: Record<string, string>;
803
+ /**
804
+ * Working directory
805
+ */
806
+ cwd?: string;
807
+ /**
808
+ * Enable PID namespace isolation (requires CAP_SYS_ADMIN)
809
+ */
810
+ isolation?: boolean;
811
+ }
812
+ interface SandboxOptions {
813
+ /**
814
+ * Duration after which the sandbox instance will sleep if no requests are received
815
+ * Can be:
816
+ * - A string like "30s", "3m", "5m", "1h" (seconds, minutes, or hours)
817
+ * - A number representing seconds (e.g., 180 for 3 minutes)
818
+ * Default: "10m" (10 minutes)
819
+ *
820
+ * Note: Ignored when keepAlive is true
821
+ */
822
+ sleepAfter?: string | number;
823
+ /**
824
+ * Base URL for the sandbox API
825
+ */
826
+ baseUrl?: string;
827
+ /**
828
+ * Keep the container alive indefinitely by preventing automatic shutdown
829
+ * When true, the container will never auto-timeout and must be explicitly destroyed
830
+ * - Any scenario where activity can't be automatically detected
831
+ *
832
+ * Important: You MUST call sandbox.destroy() when done to avoid resource leaks
833
+ *
834
+ * Default: false
835
+ */
836
+ keepAlive?: boolean;
837
+ }
838
+ /**
839
+ * Execution session - isolated execution context within a sandbox
840
+ * Returned by sandbox.createSession()
841
+ * Provides the same API as ISandbox but bound to a specific session
842
+ */
843
+ interface MkdirResult {
844
+ success: boolean;
845
+ path: string;
846
+ recursive: boolean;
847
+ timestamp: string;
848
+ exitCode?: number;
849
+ }
850
+ interface WriteFileResult {
851
+ success: boolean;
852
+ path: string;
853
+ timestamp: string;
854
+ exitCode?: number;
855
+ }
856
+ interface ReadFileResult {
857
+ success: boolean;
858
+ path: string;
859
+ content: string;
860
+ timestamp: string;
861
+ exitCode?: number;
862
+ /**
863
+ * Encoding used for content (utf-8 for text, base64 for binary)
864
+ */
865
+ encoding?: 'utf-8' | 'base64';
866
+ /**
867
+ * Whether the file is detected as binary
868
+ */
869
+ isBinary?: boolean;
870
+ /**
871
+ * MIME type of the file (e.g., 'image/png', 'text/plain')
872
+ */
873
+ mimeType?: string;
874
+ /**
875
+ * File size in bytes
876
+ */
877
+ size?: number;
878
+ }
879
+ interface DeleteFileResult {
880
+ success: boolean;
881
+ path: string;
882
+ timestamp: string;
883
+ exitCode?: number;
884
+ }
885
+ interface RenameFileResult {
886
+ success: boolean;
887
+ path: string;
888
+ newPath: string;
889
+ timestamp: string;
890
+ exitCode?: number;
891
+ }
892
+ interface MoveFileResult {
893
+ success: boolean;
894
+ path: string;
895
+ newPath: string;
896
+ timestamp: string;
897
+ exitCode?: number;
898
+ }
899
+ interface FileExistsResult {
900
+ success: boolean;
901
+ path: string;
902
+ exists: boolean;
903
+ timestamp: string;
904
+ }
905
+ interface FileInfo {
906
+ name: string;
907
+ absolutePath: string;
908
+ relativePath: string;
909
+ type: 'file' | 'directory' | 'symlink' | 'other';
910
+ size: number;
911
+ modifiedAt: string;
912
+ mode: string;
913
+ permissions: {
914
+ readable: boolean;
915
+ writable: boolean;
916
+ executable: boolean;
917
+ };
918
+ }
919
+ interface ListFilesOptions {
920
+ recursive?: boolean;
921
+ includeHidden?: boolean;
922
+ }
923
+ interface ListFilesResult {
924
+ success: boolean;
925
+ path: string;
926
+ files: FileInfo[];
927
+ count: number;
928
+ timestamp: string;
929
+ exitCode?: number;
930
+ }
931
+ interface GitCheckoutResult {
932
+ success: boolean;
933
+ repoUrl: string;
934
+ branch: string;
935
+ targetDir: string;
936
+ timestamp: string;
937
+ exitCode?: number;
938
+ }
939
+ /**
940
+ * SSE events for file streaming
941
+ */
942
+ type FileStreamEvent = {
943
+ type: 'metadata';
944
+ mimeType: string;
945
+ size: number;
946
+ isBinary: boolean;
947
+ encoding: 'utf-8' | 'base64';
948
+ } | {
949
+ type: 'chunk';
950
+ data: string;
951
+ } | {
952
+ type: 'complete';
953
+ bytesRead: number;
954
+ } | {
955
+ type: 'error';
956
+ error: string;
957
+ };
958
+ /**
959
+ * File metadata from streaming
960
+ */
961
+ interface FileMetadata {
962
+ mimeType: string;
963
+ size: number;
964
+ isBinary: boolean;
965
+ encoding: 'utf-8' | 'base64';
966
+ }
967
+ /**
968
+ * File stream chunk - either string (text) or Uint8Array (binary, auto-decoded)
969
+ */
970
+ type FileChunk = string | Uint8Array;
971
+ interface ProcessStartResult {
972
+ success: boolean;
973
+ processId: string;
974
+ pid?: number;
975
+ command: string;
976
+ timestamp: string;
977
+ }
978
+ interface ProcessListResult {
979
+ success: boolean;
980
+ processes: Array<{
981
+ id: string;
982
+ pid?: number;
983
+ command: string;
984
+ status: ProcessStatus;
985
+ startTime: string;
986
+ endTime?: string;
987
+ exitCode?: number;
988
+ }>;
989
+ timestamp: string;
990
+ }
991
+ interface ProcessInfoResult {
992
+ success: boolean;
993
+ process: {
994
+ id: string;
995
+ pid?: number;
996
+ command: string;
997
+ status: ProcessStatus;
998
+ startTime: string;
999
+ endTime?: string;
1000
+ exitCode?: number;
1001
+ };
1002
+ timestamp: string;
1003
+ }
1004
+ interface ProcessKillResult {
1005
+ success: boolean;
1006
+ processId: string;
1007
+ signal?: string;
1008
+ timestamp: string;
1009
+ }
1010
+ interface ProcessLogsResult {
1011
+ success: boolean;
1012
+ processId: string;
1013
+ stdout: string;
1014
+ stderr: string;
1015
+ timestamp: string;
1016
+ }
1017
+ interface ProcessCleanupResult {
1018
+ success: boolean;
1019
+ cleanedCount: number;
1020
+ timestamp: string;
1021
+ }
1022
+ interface SessionCreateResult {
1023
+ success: boolean;
1024
+ sessionId: string;
1025
+ name?: string;
1026
+ cwd?: string;
1027
+ timestamp: string;
1028
+ }
1029
+ interface SessionDeleteResult {
1030
+ success: boolean;
1031
+ sessionId: string;
1032
+ timestamp: string;
1033
+ }
1034
+ interface EnvSetResult {
1035
+ success: boolean;
1036
+ timestamp: string;
1037
+ }
1038
+ interface PortExposeResult {
1039
+ success: boolean;
1040
+ port: number;
1041
+ url: string;
1042
+ timestamp: string;
1043
+ }
1044
+ interface PortStatusResult {
1045
+ success: boolean;
1046
+ port: number;
1047
+ status: 'active' | 'inactive';
1048
+ url?: string;
1049
+ timestamp: string;
1050
+ }
1051
+ interface PortListResult {
1052
+ success: boolean;
1053
+ ports: Array<{
1054
+ port: number;
1055
+ url: string;
1056
+ status: 'active' | 'inactive';
1057
+ }>;
1058
+ timestamp: string;
1059
+ }
1060
+ interface PortCloseResult {
1061
+ success: boolean;
1062
+ port: number;
1063
+ timestamp: string;
1064
+ }
1065
+ interface InterpreterHealthResult {
1066
+ success: boolean;
1067
+ status: 'healthy' | 'unhealthy';
1068
+ timestamp: string;
1069
+ }
1070
+ interface ContextCreateResult {
1071
+ success: boolean;
1072
+ contextId: string;
1073
+ language: string;
1074
+ cwd?: string;
1075
+ timestamp: string;
1076
+ }
1077
+ interface ContextListResult {
1078
+ success: boolean;
1079
+ contexts: Array<{
1080
+ id: string;
1081
+ language: string;
1082
+ cwd?: string;
1083
+ }>;
1084
+ timestamp: string;
1085
+ }
1086
+ interface ContextDeleteResult {
1087
+ success: boolean;
1088
+ contextId: string;
1089
+ timestamp: string;
1090
+ }
1091
+ interface HealthCheckResult {
1092
+ success: boolean;
1093
+ status: 'healthy' | 'unhealthy';
1094
+ timestamp: string;
1095
+ }
1096
+ interface ShutdownResult {
1097
+ success: boolean;
1098
+ message: string;
1099
+ timestamp: string;
1100
+ }
1101
+ interface ExecutionSession {
1102
+ /** Unique session identifier */
1103
+ readonly id: string;
1104
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
1105
+ execStream(command: string, options?: StreamOptions): Promise<ReadableStream<Uint8Array>>;
1106
+ startProcess(command: string, options?: ProcessOptions): Promise<Process>;
1107
+ listProcesses(): Promise<Process[]>;
1108
+ getProcess(id: string): Promise<Process | null>;
1109
+ killProcess(id: string, signal?: string): Promise<void>;
1110
+ killAllProcesses(): Promise<number>;
1111
+ cleanupCompletedProcesses(): Promise<number>;
1112
+ getProcessLogs(id: string): Promise<{
1113
+ stdout: string;
1114
+ stderr: string;
1115
+ processId: string;
1116
+ }>;
1117
+ streamProcessLogs(processId: string, options?: {
1118
+ signal?: AbortSignal;
1119
+ }): Promise<ReadableStream<Uint8Array>>;
1120
+ writeFile(path: string, content: string, options?: {
1121
+ encoding?: string;
1122
+ }): Promise<WriteFileResult>;
1123
+ readFile(path: string, options?: {
1124
+ encoding?: string;
1125
+ }): Promise<ReadFileResult>;
1126
+ readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
1127
+ mkdir(path: string, options?: {
1128
+ recursive?: boolean;
1129
+ }): Promise<MkdirResult>;
1130
+ deleteFile(path: string): Promise<DeleteFileResult>;
1131
+ renameFile(oldPath: string, newPath: string): Promise<RenameFileResult>;
1132
+ moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResult>;
1133
+ listFiles(path: string, options?: ListFilesOptions): Promise<ListFilesResult>;
1134
+ exists(path: string): Promise<FileExistsResult>;
1135
+ gitCheckout(repoUrl: string, options?: {
1136
+ branch?: string;
1137
+ targetDir?: string;
1138
+ }): Promise<GitCheckoutResult>;
1139
+ setEnvVars(envVars: Record<string, string>): Promise<void>;
1140
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
1141
+ runCode(code: string, options?: RunCodeOptions): Promise<ExecutionResult>;
1142
+ runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream<Uint8Array>>;
1143
+ listCodeContexts(): Promise<CodeContext[]>;
1144
+ deleteCodeContext(contextId: string): Promise<void>;
1145
+ }
1146
+ interface ISandbox {
1147
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
1148
+ startProcess(command: string, options?: ProcessOptions): Promise<Process>;
1149
+ listProcesses(): Promise<Process[]>;
1150
+ getProcess(id: string): Promise<Process | null>;
1151
+ killProcess(id: string, signal?: string): Promise<void>;
1152
+ killAllProcesses(): Promise<number>;
1153
+ execStream(command: string, options?: StreamOptions): Promise<ReadableStream<Uint8Array>>;
1154
+ streamProcessLogs(processId: string, options?: {
1155
+ signal?: AbortSignal;
1156
+ }): Promise<ReadableStream<Uint8Array>>;
1157
+ cleanupCompletedProcesses(): Promise<number>;
1158
+ getProcessLogs(id: string): Promise<{
1159
+ stdout: string;
1160
+ stderr: string;
1161
+ processId: string;
1162
+ }>;
1163
+ writeFile(path: string, content: string, options?: {
1164
+ encoding?: string;
1165
+ }): Promise<WriteFileResult>;
1166
+ readFile(path: string, options?: {
1167
+ encoding?: string;
1168
+ }): Promise<ReadFileResult>;
1169
+ readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
1170
+ mkdir(path: string, options?: {
1171
+ recursive?: boolean;
1172
+ }): Promise<MkdirResult>;
1173
+ deleteFile(path: string): Promise<DeleteFileResult>;
1174
+ renameFile(oldPath: string, newPath: string): Promise<RenameFileResult>;
1175
+ moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResult>;
1176
+ listFiles(path: string, options?: ListFilesOptions): Promise<ListFilesResult>;
1177
+ exists(path: string, sessionId?: string): Promise<FileExistsResult>;
1178
+ gitCheckout(repoUrl: string, options?: {
1179
+ branch?: string;
1180
+ targetDir?: string;
1181
+ }): Promise<GitCheckoutResult>;
1182
+ createSession(options?: SessionOptions): Promise<ExecutionSession>;
1183
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
1184
+ runCode(code: string, options?: RunCodeOptions): Promise<ExecutionResult>;
1185
+ runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
1186
+ listCodeContexts(): Promise<CodeContext[]>;
1187
+ deleteCodeContext(contextId: string): Promise<void>;
1188
+ wsConnect(request: Request, port: number): Promise<Response>;
1189
+ }
1190
+ declare function isExecResult(value: any): value is ExecResult;
1191
+ declare function isProcess(value: any): value is Process;
1192
+ declare function isProcessStatus(value: string): value is ProcessStatus;
1193
+ //#endregion
1194
+ //#region src/clients/types.d.ts
1195
+ /**
1196
+ * Minimal interface for container fetch functionality
1197
+ */
1198
+ interface ContainerStub {
1199
+ containerFetch(url: string, options: RequestInit, port?: number): Promise<Response>;
1200
+ }
1201
+ /**
1202
+ * Shared HTTP client configuration options
1203
+ */
1204
+ interface HttpClientOptions {
1205
+ logger?: Logger;
1206
+ baseUrl?: string;
1207
+ port?: number;
1208
+ stub?: ContainerStub;
1209
+ onCommandComplete?: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string) => void;
1210
+ onError?: (error: string, command?: string) => void;
1211
+ }
1212
+ /**
1213
+ * Base response interface for all API responses
1214
+ */
1215
+ interface BaseApiResponse {
1216
+ success: boolean;
1217
+ timestamp: string;
1218
+ }
1219
+ /**
1220
+ * Legacy error response interface - deprecated, use ApiErrorResponse
1221
+ */
1222
+ interface ErrorResponse {
1223
+ error: string;
1224
+ details?: string;
1225
+ code?: string;
1226
+ }
1227
+ /**
1228
+ * HTTP request configuration
1229
+ */
1230
+ interface RequestConfig extends RequestInit {
1231
+ endpoint: string;
1232
+ data?: Record<string, any>;
1233
+ }
1234
+ /**
1235
+ * Typed response handler
1236
+ */
1237
+ type ResponseHandler<T> = (response: Response) => Promise<T>;
1238
+ /**
1239
+ * Common session-aware request interface
1240
+ */
1241
+ interface SessionRequest {
1242
+ sessionId?: string;
1243
+ }
1244
+ //#endregion
1245
+ //#region src/clients/base-client.d.ts
1246
+ /**
1247
+ * Abstract base class providing common HTTP functionality for all domain clients
1248
+ */
1249
+ declare abstract class BaseHttpClient {
1250
+ protected baseUrl: string;
1251
+ protected options: HttpClientOptions;
1252
+ protected logger: Logger;
1253
+ constructor(options?: HttpClientOptions);
1254
+ /**
1255
+ * Core HTTP request method with automatic retry for container provisioning delays
1256
+ */
1257
+ protected doFetch(path: string, options?: RequestInit): Promise<Response>;
1258
+ /**
1259
+ * Make a POST request with JSON body
1260
+ */
1261
+ protected post<T>(endpoint: string, data: Record<string, any>, responseHandler?: ResponseHandler<T>): Promise<T>;
1262
+ /**
1263
+ * Make a GET request
1264
+ */
1265
+ protected get<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
1266
+ /**
1267
+ * Make a DELETE request
1268
+ */
1269
+ protected delete<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
1270
+ /**
1271
+ * Handle HTTP response with error checking and parsing
1272
+ */
1273
+ protected handleResponse<T>(response: Response, customHandler?: ResponseHandler<T>): Promise<T>;
1274
+ /**
1275
+ * Handle error responses with consistent error throwing
1276
+ */
1277
+ protected handleErrorResponse(response: Response): Promise<never>;
1278
+ /**
1279
+ * Create a streaming response handler for Server-Sent Events
1280
+ */
1281
+ protected handleStreamResponse(response: Response): Promise<ReadableStream<Uint8Array>>;
1282
+ /**
1283
+ * Utility method to log successful operations
1284
+ */
1285
+ protected logSuccess(operation: string, details?: string): void;
1286
+ /**
1287
+ * Utility method to log errors intelligently
1288
+ * Only logs unexpected errors (5xx), not expected errors (4xx)
1289
+ *
1290
+ * - 4xx errors (validation, not found, conflicts): Don't log (expected client errors)
1291
+ * - 5xx errors (server failures, internal errors): DO log (unexpected server errors)
1292
+ */
1293
+ protected logError(operation: string, error: unknown): void;
1294
+ /**
1295
+ * Check if 503 response is from container provisioning (retryable)
1296
+ * vs user application (not retryable)
1297
+ */
1298
+ private isContainerProvisioningError;
1299
+ private executeFetch;
1300
+ }
1301
+ //#endregion
1302
+ //#region src/clients/command-client.d.ts
1303
+ /**
1304
+ * Request interface for command execution
1305
+ */
1306
+ interface ExecuteRequest extends SessionRequest {
1307
+ command: string;
1308
+ timeoutMs?: number;
1309
+ }
1310
+ /**
1311
+ * Response interface for command execution
1312
+ */
1313
+ interface ExecuteResponse extends BaseApiResponse {
1314
+ stdout: string;
1315
+ stderr: string;
1316
+ exitCode: number;
1317
+ command: string;
1318
+ }
1319
+ /**
1320
+ * Client for command execution operations
1321
+ */
1322
+ declare class CommandClient extends BaseHttpClient {
1323
+ /**
1324
+ * Execute a command and return the complete result
1325
+ * @param command - The command to execute
1326
+ * @param sessionId - The session ID for this command execution
1327
+ * @param timeoutMs - Optional timeout in milliseconds (unlimited by default)
1328
+ */
1329
+ execute(command: string, sessionId: string, timeoutMs?: number): Promise<ExecuteResponse>;
1330
+ /**
1331
+ * Execute a command and return a stream of events
1332
+ * @param command - The command to execute
1333
+ * @param sessionId - The session ID for this command execution
1334
+ */
1335
+ executeStream(command: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
1336
+ }
1337
+ //#endregion
1338
+ //#region src/clients/file-client.d.ts
1339
+ /**
1340
+ * Request interface for creating directories
1341
+ */
1342
+ interface MkdirRequest extends SessionRequest {
1343
+ path: string;
1344
+ recursive?: boolean;
1345
+ }
1346
+ /**
1347
+ * Request interface for writing files
1348
+ */
1349
+ interface WriteFileRequest extends SessionRequest {
1350
+ path: string;
1351
+ content: string;
1352
+ encoding?: string;
1353
+ }
1354
+ /**
1355
+ * Request interface for reading files
1356
+ */
1357
+ interface ReadFileRequest extends SessionRequest {
1358
+ path: string;
1359
+ encoding?: string;
1360
+ }
1361
+ /**
1362
+ * Request interface for file operations (delete, rename, move)
1363
+ */
1364
+ interface FileOperationRequest extends SessionRequest {
1365
+ path: string;
1366
+ newPath?: string;
1367
+ }
1368
+ /**
1369
+ * Client for file system operations
1370
+ */
1371
+ declare class FileClient extends BaseHttpClient {
1372
+ /**
1373
+ * Create a directory
1374
+ * @param path - Directory path to create
1375
+ * @param sessionId - The session ID for this operation
1376
+ * @param options - Optional settings (recursive)
1377
+ */
1378
+ mkdir(path: string, sessionId: string, options?: {
1379
+ recursive?: boolean;
1380
+ }): Promise<MkdirResult>;
1381
+ /**
1382
+ * Write content to a file
1383
+ * @param path - File path to write to
1384
+ * @param content - Content to write
1385
+ * @param sessionId - The session ID for this operation
1386
+ * @param options - Optional settings (encoding)
1387
+ */
1388
+ writeFile(path: string, content: string, sessionId: string, options?: {
1389
+ encoding?: string;
1390
+ }): Promise<WriteFileResult>;
1391
+ /**
1392
+ * Read content from a file
1393
+ * @param path - File path to read from
1394
+ * @param sessionId - The session ID for this operation
1395
+ * @param options - Optional settings (encoding)
1396
+ */
1397
+ readFile(path: string, sessionId: string, options?: {
1398
+ encoding?: string;
1399
+ }): Promise<ReadFileResult>;
1400
+ /**
1401
+ * Stream a file using Server-Sent Events
1402
+ * Returns a ReadableStream of SSE events containing metadata, chunks, and completion
1403
+ * @param path - File path to stream
1404
+ * @param sessionId - The session ID for this operation
1405
+ */
1406
+ readFileStream(path: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
1407
+ /**
1408
+ * Delete a file
1409
+ * @param path - File path to delete
1410
+ * @param sessionId - The session ID for this operation
1411
+ */
1412
+ deleteFile(path: string, sessionId: string): Promise<DeleteFileResult>;
1413
+ /**
1414
+ * Rename a file
1415
+ * @param path - Current file path
1416
+ * @param newPath - New file path
1417
+ * @param sessionId - The session ID for this operation
1418
+ */
1419
+ renameFile(path: string, newPath: string, sessionId: string): Promise<RenameFileResult>;
1420
+ /**
1421
+ * Move a file
1422
+ * @param path - Current file path
1423
+ * @param newPath - Destination file path
1424
+ * @param sessionId - The session ID for this operation
1425
+ */
1426
+ moveFile(path: string, newPath: string, sessionId: string): Promise<MoveFileResult>;
1427
+ /**
1428
+ * List files in a directory
1429
+ * @param path - Directory path to list
1430
+ * @param sessionId - The session ID for this operation
1431
+ * @param options - Optional settings (recursive, includeHidden)
1432
+ */
1433
+ listFiles(path: string, sessionId: string, options?: ListFilesOptions): Promise<ListFilesResult>;
1434
+ /**
1435
+ * Check if a file or directory exists
1436
+ * @param path - Path to check
1437
+ * @param sessionId - The session ID for this operation
1438
+ */
1439
+ exists(path: string, sessionId: string): Promise<FileExistsResult>;
1440
+ }
1441
+ //#endregion
1442
+ //#region src/clients/git-client.d.ts
1443
+ /**
1444
+ * Request interface for Git checkout operations
1445
+ */
1446
+ interface GitCheckoutRequest extends SessionRequest {
1447
+ repoUrl: string;
1448
+ branch?: string;
1449
+ targetDir?: string;
1450
+ }
1451
+ /**
1452
+ * Client for Git repository operations
1453
+ */
1454
+ declare class GitClient extends BaseHttpClient {
1455
+ constructor(options?: HttpClientOptions);
1456
+ /**
1457
+ * Clone a Git repository
1458
+ * @param repoUrl - URL of the Git repository to clone
1459
+ * @param sessionId - The session ID for this operation
1460
+ * @param options - Optional settings (branch, targetDir)
1461
+ */
1462
+ checkout(repoUrl: string, sessionId: string, options?: {
1463
+ branch?: string;
1464
+ targetDir?: string;
1465
+ }): Promise<GitCheckoutResult>;
1466
+ /**
1467
+ * Extract repository name from URL for default directory name
1468
+ */
1469
+ private extractRepoName;
1470
+ }
1471
+ //#endregion
1472
+ //#region src/clients/interpreter-client.d.ts
1473
+ interface ExecutionCallbacks {
1474
+ onStdout?: (output: OutputMessage) => void | Promise<void>;
1475
+ onStderr?: (output: OutputMessage) => void | Promise<void>;
1476
+ onResult?: (result: Result) => void | Promise<void>;
1477
+ onError?: (error: ExecutionError) => void | Promise<void>;
1478
+ }
1479
+ declare class InterpreterClient extends BaseHttpClient {
1480
+ private readonly maxRetries;
1481
+ private readonly retryDelayMs;
1482
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
1483
+ runCodeStream(contextId: string | undefined, code: string, language: string | undefined, callbacks: ExecutionCallbacks, timeoutMs?: number): Promise<void>;
1484
+ listCodeContexts(): Promise<CodeContext[]>;
1485
+ deleteCodeContext(contextId: string): Promise<void>;
1486
+ /**
1487
+ * Execute an operation with automatic retry for transient errors
1488
+ */
1489
+ private executeWithRetry;
1490
+ private isRetryableError;
1491
+ private parseErrorResponse;
1492
+ private readLines;
1493
+ private parseExecutionResult;
1494
+ }
1495
+ //#endregion
1496
+ //#region src/clients/port-client.d.ts
1497
+ /**
1498
+ * Request interface for exposing ports
1499
+ */
1500
+ interface ExposePortRequest {
1501
+ port: number;
1502
+ name?: string;
1503
+ }
1504
+ /**
1505
+ * Request interface for unexposing ports
1506
+ */
1507
+ interface UnexposePortRequest {
1508
+ port: number;
1509
+ }
1510
+ /**
1511
+ * Client for port management and preview URL operations
1512
+ */
1513
+ declare class PortClient extends BaseHttpClient {
1514
+ /**
1515
+ * Expose a port and get a preview URL
1516
+ * @param port - Port number to expose
1517
+ * @param sessionId - The session ID for this operation
1518
+ * @param name - Optional name for the port
1519
+ */
1520
+ exposePort(port: number, sessionId: string, name?: string): Promise<PortExposeResult>;
1521
+ /**
1522
+ * Unexpose a port and remove its preview URL
1523
+ * @param port - Port number to unexpose
1524
+ * @param sessionId - The session ID for this operation
1525
+ */
1526
+ unexposePort(port: number, sessionId: string): Promise<PortCloseResult>;
1527
+ /**
1528
+ * Get all currently exposed ports
1529
+ * @param sessionId - The session ID for this operation
1530
+ */
1531
+ getExposedPorts(sessionId: string): Promise<PortListResult>;
1532
+ }
1533
+ //#endregion
1534
+ //#region src/clients/process-client.d.ts
1535
+ /**
1536
+ * Client for background process management
1537
+ */
1538
+ declare class ProcessClient extends BaseHttpClient {
1539
+ /**
1540
+ * Start a background process
1541
+ * @param command - Command to execute as a background process
1542
+ * @param sessionId - The session ID for this operation
1543
+ * @param options - Optional settings (processId)
1544
+ */
1545
+ startProcess(command: string, sessionId: string, options?: {
1546
+ processId?: string;
1547
+ }): Promise<ProcessStartResult>;
1548
+ /**
1549
+ * List all processes (sandbox-scoped, not session-scoped)
1550
+ */
1551
+ listProcesses(): Promise<ProcessListResult>;
1552
+ /**
1553
+ * Get information about a specific process (sandbox-scoped, not session-scoped)
1554
+ * @param processId - ID of the process to retrieve
1555
+ */
1556
+ getProcess(processId: string): Promise<ProcessInfoResult>;
1557
+ /**
1558
+ * Kill a specific process (sandbox-scoped, not session-scoped)
1559
+ * @param processId - ID of the process to kill
1560
+ */
1561
+ killProcess(processId: string): Promise<ProcessKillResult>;
1562
+ /**
1563
+ * Kill all running processes (sandbox-scoped, not session-scoped)
1564
+ */
1565
+ killAllProcesses(): Promise<ProcessCleanupResult>;
1566
+ /**
1567
+ * Get logs from a specific process (sandbox-scoped, not session-scoped)
1568
+ * @param processId - ID of the process to get logs from
1569
+ */
1570
+ getProcessLogs(processId: string): Promise<ProcessLogsResult>;
1571
+ /**
1572
+ * Stream logs from a specific process (sandbox-scoped, not session-scoped)
1573
+ * @param processId - ID of the process to stream logs from
1574
+ */
1575
+ streamProcessLogs(processId: string): Promise<ReadableStream<Uint8Array>>;
1576
+ }
1577
+ //#endregion
1578
+ //#region src/clients/utility-client.d.ts
1579
+ /**
1580
+ * Response interface for ping operations
1581
+ */
1582
+ interface PingResponse extends BaseApiResponse {
1583
+ message: string;
1584
+ uptime?: number;
1585
+ }
1586
+ /**
1587
+ * Response interface for getting available commands
1588
+ */
1589
+ interface CommandsResponse extends BaseApiResponse {
1590
+ availableCommands: string[];
1591
+ count: number;
1592
+ }
1593
+ /**
1594
+ * Request interface for creating sessions
1595
+ */
1596
+ interface CreateSessionRequest {
1597
+ id: string;
1598
+ env?: Record<string, string>;
1599
+ cwd?: string;
1600
+ }
1601
+ /**
1602
+ * Response interface for creating sessions
1603
+ */
1604
+ interface CreateSessionResponse extends BaseApiResponse {
1605
+ id: string;
1606
+ message: string;
1607
+ }
1608
+ /**
1609
+ * Client for health checks and utility operations
1610
+ */
1611
+ declare class UtilityClient extends BaseHttpClient {
1612
+ /**
1613
+ * Ping the sandbox to check if it's responsive
1614
+ */
1615
+ ping(): Promise<string>;
1616
+ /**
1617
+ * Get list of available commands in the sandbox environment
1618
+ */
1619
+ getCommands(): Promise<string[]>;
1620
+ /**
1621
+ * Create a new execution session
1622
+ * @param options - Session configuration (id, env, cwd)
1623
+ */
1624
+ createSession(options: CreateSessionRequest): Promise<CreateSessionResponse>;
1625
+ /**
1626
+ * Get the container version
1627
+ * Returns the version embedded in the Docker image during build
1628
+ */
1629
+ getVersion(): Promise<string>;
1630
+ }
1631
+ //#endregion
1632
+ //#region src/clients/sandbox-client.d.ts
1633
+ /**
1634
+ * Main sandbox client that composes all domain-specific clients
1635
+ * Provides organized access to all sandbox functionality
1636
+ */
1637
+ declare class SandboxClient {
1638
+ readonly commands: CommandClient;
1639
+ readonly files: FileClient;
1640
+ readonly processes: ProcessClient;
1641
+ readonly ports: PortClient;
1642
+ readonly git: GitClient;
1643
+ readonly interpreter: InterpreterClient;
1644
+ readonly utils: UtilityClient;
1645
+ constructor(options: HttpClientOptions);
1646
+ }
1647
+ //#endregion
1648
+ //#region src/sandbox.d.ts
1649
+ declare function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string, options?: SandboxOptions): Sandbox;
1650
+ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
1651
+ defaultPort: number;
1652
+ sleepAfter: string | number;
1653
+ client: SandboxClient;
1654
+ private codeInterpreter;
1655
+ private sandboxName;
1656
+ private baseUrl;
1657
+ private portTokens;
1658
+ private defaultSession;
1659
+ envVars: Record<string, string>;
1660
+ private logger;
1661
+ private keepAliveEnabled;
1662
+ constructor(ctx: DurableObjectState<{}>, env: Env);
1663
+ setSandboxName(name: string): Promise<void>;
1664
+ setBaseUrl(baseUrl: string): Promise<void>;
1665
+ setSleepAfter(sleepAfter: string | number): Promise<void>;
1666
+ setKeepAlive(keepAlive: boolean): Promise<void>;
1667
+ setEnvVars(envVars: Record<string, string>): Promise<void>;
1668
+ /**
1669
+ * Cleanup and destroy the sandbox container
1670
+ */
1671
+ destroy(): Promise<void>;
1672
+ onStart(): void;
1673
+ /**
1674
+ * Check if the container version matches the SDK version
1675
+ * Logs a warning if there's a mismatch
1676
+ */
1677
+ private checkVersionCompatibility;
1678
+ onStop(): void;
1679
+ onError(error: unknown): void;
1680
+ /**
1681
+ * Override onActivityExpired to prevent automatic shutdown when keepAlive is enabled
1682
+ * When keepAlive is disabled, calls parent implementation which stops the container
1683
+ */
1684
+ onActivityExpired(): Promise<void>;
1685
+ fetch(request: Request): Promise<Response>;
1686
+ wsConnect(request: Request, port: number): Promise<Response>;
1687
+ private determinePort;
1688
+ /**
1689
+ * Ensure default session exists - lazy initialization
1690
+ * This is called automatically by all public methods that need a session
1691
+ *
1692
+ * The session is persisted to Durable Object storage to survive hot reloads
1693
+ * during development. If a session already exists in the container after reload,
1694
+ * we reuse it instead of trying to create a new one.
1695
+ */
1696
+ private ensureDefaultSession;
1697
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
1698
+ /**
1699
+ * Internal session-aware exec implementation
1700
+ * Used by both public exec() and session wrappers
1701
+ */
1702
+ private execWithSession;
1703
+ private executeWithStreaming;
1704
+ private mapExecuteResponseToExecResult;
1705
+ /**
1706
+ * Create a Process domain object from HTTP client DTO
1707
+ * Centralizes process object creation with bound methods
1708
+ * This eliminates duplication across startProcess, listProcesses, getProcess, and session wrappers
1709
+ */
1710
+ private createProcessFromDTO;
1711
+ startProcess(command: string, options?: ProcessOptions, sessionId?: string): Promise<Process>;
1712
+ listProcesses(sessionId?: string): Promise<Process[]>;
1713
+ getProcess(id: string, sessionId?: string): Promise<Process | null>;
1714
+ killProcess(id: string, signal?: string, sessionId?: string): Promise<void>;
1715
+ killAllProcesses(sessionId?: string): Promise<number>;
1716
+ cleanupCompletedProcesses(sessionId?: string): Promise<number>;
1717
+ getProcessLogs(id: string, sessionId?: string): Promise<{
1718
+ stdout: string;
1719
+ stderr: string;
1720
+ processId: string;
1721
+ }>;
1722
+ execStream(command: string, options?: StreamOptions): Promise<ReadableStream<Uint8Array>>;
1723
+ /**
1724
+ * Internal session-aware execStream implementation
1725
+ */
1726
+ private execStreamWithSession;
1727
+ /**
1728
+ * Stream logs from a background process as a ReadableStream.
1729
+ */
1730
+ streamProcessLogs(processId: string, options?: {
1731
+ signal?: AbortSignal;
1732
+ }): Promise<ReadableStream<Uint8Array>>;
1733
+ gitCheckout(repoUrl: string, options: {
1734
+ branch?: string;
1735
+ targetDir?: string;
1736
+ sessionId?: string;
1737
+ }): Promise<GitCheckoutResult>;
1738
+ mkdir(path: string, options?: {
1739
+ recursive?: boolean;
1740
+ sessionId?: string;
1741
+ }): Promise<MkdirResult>;
1742
+ writeFile(path: string, content: string, options?: {
1743
+ encoding?: string;
1744
+ sessionId?: string;
1745
+ }): Promise<WriteFileResult>;
1746
+ deleteFile(path: string, sessionId?: string): Promise<DeleteFileResult>;
1747
+ renameFile(oldPath: string, newPath: string, sessionId?: string): Promise<RenameFileResult>;
1748
+ moveFile(sourcePath: string, destinationPath: string, sessionId?: string): Promise<MoveFileResult>;
1749
+ readFile(path: string, options?: {
1750
+ encoding?: string;
1751
+ sessionId?: string;
1752
+ }): Promise<ReadFileResult>;
1753
+ /**
1754
+ * Stream a file from the sandbox using Server-Sent Events
1755
+ * Returns a ReadableStream that can be consumed with streamFile() or collectFile() utilities
1756
+ * @param path - Path to the file to stream
1757
+ * @param options - Optional session ID
1758
+ */
1759
+ readFileStream(path: string, options?: {
1760
+ sessionId?: string;
1761
+ }): Promise<ReadableStream<Uint8Array>>;
1762
+ listFiles(path: string, options?: {
1763
+ recursive?: boolean;
1764
+ includeHidden?: boolean;
1765
+ }): Promise<ListFilesResult>;
1766
+ exists(path: string, sessionId?: string): Promise<FileExistsResult>;
1767
+ exposePort(port: number, options: {
1768
+ name?: string;
1769
+ hostname: string;
1770
+ }): Promise<{
1771
+ url: string;
1772
+ port: number;
1773
+ name: string | undefined;
1774
+ }>;
1775
+ unexposePort(port: number): Promise<void>;
1776
+ getExposedPorts(hostname: string): Promise<{
1777
+ url: string;
1778
+ port: number;
1779
+ status: "active" | "inactive";
1780
+ }[]>;
1781
+ isPortExposed(port: number): Promise<boolean>;
1782
+ validatePortToken(port: number, token: string): Promise<boolean>;
1783
+ private generatePortToken;
1784
+ private persistPortTokens;
1785
+ private constructPreviewUrl;
1786
+ /**
1787
+ * Create isolated execution session for advanced use cases
1788
+ * Returns ExecutionSession with full sandbox API bound to specific session
1789
+ */
1790
+ createSession(options?: SessionOptions): Promise<ExecutionSession>;
1791
+ /**
1792
+ * Get an existing session by ID
1793
+ * Returns ExecutionSession wrapper bound to the specified session
1794
+ *
1795
+ * This is useful for retrieving sessions across different requests/contexts
1796
+ * without storing the ExecutionSession object (which has RPC lifecycle limitations)
1797
+ *
1798
+ * @param sessionId - The ID of an existing session
1799
+ * @returns ExecutionSession wrapper bound to the session
1800
+ */
1801
+ getSession(sessionId: string): Promise<ExecutionSession>;
1802
+ /**
1803
+ * Internal helper to create ExecutionSession wrapper for a given sessionId
1804
+ * Used by both createSession and getSession
1805
+ */
1806
+ private getSessionWrapper;
1807
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
1808
+ runCode(code: string, options?: RunCodeOptions): Promise<ExecutionResult>;
1809
+ runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
1810
+ listCodeContexts(): Promise<CodeContext[]>;
1811
+ deleteCodeContext(contextId: string): Promise<void>;
1812
+ }
1813
+ //#endregion
1814
+ //#region src/file-stream.d.ts
1815
+ /**
1816
+ * Stream a file from the sandbox with automatic base64 decoding for binary files
1817
+ *
1818
+ * @param stream - The ReadableStream from readFileStream()
1819
+ * @returns AsyncGenerator that yields FileChunk (string for text, Uint8Array for binary)
1820
+ *
1821
+ * @example
1822
+ * ```ts
1823
+ * const stream = await sandbox.readFileStream('/path/to/file.png');
1824
+ * for await (const chunk of streamFile(stream)) {
1825
+ * if (chunk instanceof Uint8Array) {
1826
+ * // Binary chunk
1827
+ * console.log('Binary chunk:', chunk.length, 'bytes');
1828
+ * } else {
1829
+ * // Text chunk
1830
+ * console.log('Text chunk:', chunk);
1831
+ * }
1832
+ * }
1833
+ * ```
1834
+ */
1835
+ declare function streamFile(stream: ReadableStream<Uint8Array>): AsyncGenerator<FileChunk, FileMetadata>;
1836
+ /**
1837
+ * Collect an entire file into memory from a stream
1838
+ *
1839
+ * @param stream - The ReadableStream from readFileStream()
1840
+ * @returns Object containing the file content and metadata
1841
+ *
1842
+ * @example
1843
+ * ```ts
1844
+ * const stream = await sandbox.readFileStream('/path/to/file.txt');
1845
+ * const { content, metadata } = await collectFile(stream);
1846
+ * console.log('Content:', content);
1847
+ * console.log('MIME type:', metadata.mimeType);
1848
+ * ```
1849
+ */
1850
+ declare function collectFile(stream: ReadableStream<Uint8Array>): Promise<{
1851
+ content: string | Uint8Array;
1852
+ metadata: FileMetadata;
1853
+ }>;
1854
+ //#endregion
1855
+ //#region src/interpreter.d.ts
1856
+ declare class CodeInterpreter {
1857
+ private interpreterClient;
1858
+ private contexts;
1859
+ constructor(sandbox: Sandbox);
1860
+ /**
1861
+ * Create a new code execution context
1862
+ */
1863
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
1864
+ /**
1865
+ * Run code with optional context
1866
+ */
1867
+ runCode(code: string, options?: RunCodeOptions): Promise<Execution>;
1868
+ /**
1869
+ * Run code and return a streaming response
1870
+ */
1871
+ runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
1872
+ /**
1873
+ * List all code contexts
1874
+ */
1875
+ listCodeContexts(): Promise<CodeContext[]>;
1876
+ /**
1877
+ * Delete a code context
1878
+ */
1879
+ deleteCodeContext(contextId: string): Promise<void>;
1880
+ private getOrCreateDefaultContext;
1881
+ }
1882
+ //#endregion
1883
+ //#region src/request-handler.d.ts
1884
+ interface SandboxEnv {
1885
+ Sandbox: DurableObjectNamespace<Sandbox>;
1886
+ }
1887
+ interface RouteInfo {
1888
+ port: number;
1889
+ sandboxId: string;
1890
+ path: string;
1891
+ token: string;
1892
+ }
1893
+ declare function proxyToSandbox<E extends SandboxEnv>(request: Request, env: E): Promise<Response | null>;
1894
+ //#endregion
1895
+ //#region src/sse-parser.d.ts
1896
+ /**
1897
+ * Server-Sent Events (SSE) parser for streaming responses
1898
+ * Converts ReadableStream<Uint8Array> to typed AsyncIterable<T>
1899
+ */
1900
+ /**
1901
+ * Parse a ReadableStream of SSE events into typed AsyncIterable
1902
+ * @param stream - The ReadableStream from fetch response
1903
+ * @param signal - Optional AbortSignal for cancellation
1904
+ */
1905
+ declare function parseSSEStream<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncIterable<T>;
1906
+ /**
1907
+ * Helper to convert a Response with SSE stream directly to AsyncIterable
1908
+ * @param response - Response object with SSE stream
1909
+ * @param signal - Optional AbortSignal for cancellation
1910
+ */
1911
+ declare function responseToAsyncIterable<T>(response: Response, signal?: AbortSignal): AsyncIterable<T>;
1912
+ /**
1913
+ * Create an SSE-formatted ReadableStream from an AsyncIterable
1914
+ * (Useful for Worker endpoints that need to forward AsyncIterable as SSE)
1915
+ * @param events - AsyncIterable of events
1916
+ * @param options - Stream options
1917
+ */
1918
+ declare function asyncIterableToSSEStream<T>(events: AsyncIterable<T>, options?: {
1919
+ signal?: AbortSignal;
1920
+ serialize?: (event: T) => string;
1921
+ }): ReadableStream<Uint8Array>;
1922
+ //#endregion
1923
+ export { type BaseApiResponse, type BaseExecOptions, type ChartData, type CodeContext, CodeInterpreter, CommandClient, type ExecuteResponse as CommandExecuteResponse, type CommandsResponse, type ContainerStub, ContextCreateResult, ContextDeleteResult, ContextListResult, type CreateContextOptions, DeleteFileRequest, DeleteFileResult, EnvSetResult, type ErrorResponse, type ExecEvent, type ExecOptions, type ExecResult, type ExecuteRequest, Execution, type ExecutionCallbacks, type ExecutionError, type ExecutionResult, ExecutionSession, type ExposePortRequest, type FileChunk, FileClient, FileExistsRequest, FileExistsResult, FileInfo, type FileMetadata, type FileOperationRequest, type FileStreamEvent, type GitCheckoutRequest, type GitCheckoutResult, GitClient, GitLogger, HealthCheckResult, type ISandbox, type InterpreterClient, InterpreterHealthResult, ListFilesOptions, ListFilesResult, type LogContext, type LogEvent, type LogLevel, LogLevel as LogLevelEnum, type Logger, type MkdirRequest, MkdirResult, MoveFileRequest, MoveFileResult, type OutputMessage, type PingResponse, PortClient, type PortCloseResult, type PortExposeResult, type PortListResult, PortStatusResult, type Process, type ProcessCleanupResult, ProcessClient, type ProcessInfoResult, type ProcessKillResult, type ProcessListResult, type ProcessLogsResult, type ProcessOptions, type ProcessStartResult, type ProcessStatus, type ReadFileRequest, ReadFileResult, RenameFileRequest, RenameFileResult, type RequestConfig, type ResponseHandler, type Result, ResultImpl, type RouteInfo, type RunCodeOptions, Sandbox, SandboxClient, type HttpClientOptions as SandboxClientOptions, type SandboxEnv, SandboxOptions, SessionCreateRequest, SessionCreateResult, SessionDeleteRequest, SessionDeleteResult, SessionOptions, type SessionRequest, ShutdownResult, type StartProcessRequest, type StreamOptions, TraceContext, type UnexposePortRequest, UtilityClient, type WriteFileRequest, WriteFileResult, asyncIterableToSSEStream, collectFile, createLogger, createNoOpLogger, getLogger, getSandbox, isExecResult, isProcess, isProcessStatus, parseSSEStream, proxyToSandbox, redactCredentials, responseToAsyncIterable, runWithLogger, sanitizeGitData, streamFile };
1924
+ //# sourceMappingURL=index.d.ts.map