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