@genspark/sb-box 0.0.0-stage → 0.1.0
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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/index.cjs +1167 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +641 -0
- package/dist/index.d.ts +641 -0
- package/dist/index.js +1095 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
declare const SDK_VERSION = "0.1.0";
|
|
2
|
+
declare const DEFAULT_BASE_URL = "https://www.genspark.ai/api/sb-box/v1";
|
|
3
|
+
interface HttpOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
/** Default per-request timeout in seconds. */
|
|
7
|
+
timeout: number;
|
|
8
|
+
/** Retries after the first attempt for retryable calls (0 = no retry). */
|
|
9
|
+
retries: number;
|
|
10
|
+
userAgent: string;
|
|
11
|
+
fetch: typeof fetch;
|
|
12
|
+
}
|
|
13
|
+
interface RequestOptions {
|
|
14
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
15
|
+
query?: Record<string, string | number | undefined>;
|
|
16
|
+
json?: unknown;
|
|
17
|
+
body?: Uint8Array | string;
|
|
18
|
+
contentType?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/** Seconds; overrides the client default. */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/** Retry on connection errors and 502/503/504 (default false). */
|
|
23
|
+
retry?: boolean;
|
|
24
|
+
/** Honour `Retry-After` on 503 until `deadlineMs`. */
|
|
25
|
+
retryOn503Until?: number;
|
|
26
|
+
/** Return the raw Response (streams, bytes). */
|
|
27
|
+
raw?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Raw responses only: when false, the timeout covers just the headers and the
|
|
30
|
+
* caller owns the body for as long as it likes (unbounded server streams such
|
|
31
|
+
* as `connect`). Default true: the timeout bounds the whole body; past it the
|
|
32
|
+
* stream fails with `SbBoxConnectionError`.
|
|
33
|
+
*/
|
|
34
|
+
bodyDeadline?: boolean;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
declare class Http {
|
|
38
|
+
readonly opts: HttpOptions;
|
|
39
|
+
constructor(opts: HttpOptions);
|
|
40
|
+
url(path: string, query?: RequestOptions['query']): string;
|
|
41
|
+
request<T = unknown>(path: string, opts?: RequestOptions): Promise<T>;
|
|
42
|
+
raw(path: string, opts?: RequestOptions): Promise<Response>;
|
|
43
|
+
private send;
|
|
44
|
+
private parseBody;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type SandboxState = 'starting' | 'running' | 'freezing' | 'frozen' | 'exited' | 'failed' | 'unknown';
|
|
48
|
+
type ListState = SandboxState | 'all';
|
|
49
|
+
interface Regions {
|
|
50
|
+
regions: string[];
|
|
51
|
+
default: string;
|
|
52
|
+
}
|
|
53
|
+
interface Limits {
|
|
54
|
+
plan: string;
|
|
55
|
+
planRequired?: boolean;
|
|
56
|
+
limits: {
|
|
57
|
+
maxConcurrentSandboxes: number;
|
|
58
|
+
maxCpu: number;
|
|
59
|
+
maxMemoryMB: number;
|
|
60
|
+
maxDiskGB: number;
|
|
61
|
+
maxConcurrentBuilds: number;
|
|
62
|
+
[k: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
usage: {
|
|
65
|
+
runningSandboxes: number;
|
|
66
|
+
buildingTemplates: number;
|
|
67
|
+
[k: string]: unknown;
|
|
68
|
+
};
|
|
69
|
+
[k: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
interface UsageTotals {
|
|
72
|
+
runSec?: number;
|
|
73
|
+
cpuCoreSec?: number;
|
|
74
|
+
memGBSec?: number;
|
|
75
|
+
diskGBSec?: number;
|
|
76
|
+
credits?: number;
|
|
77
|
+
[k: string]: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface Usage {
|
|
80
|
+
days: number;
|
|
81
|
+
from: string;
|
|
82
|
+
to: string;
|
|
83
|
+
rateCard?: Record<string, unknown>;
|
|
84
|
+
direct?: UsageTotals;
|
|
85
|
+
daily?: Array<{
|
|
86
|
+
day: string;
|
|
87
|
+
direct?: Record<string, unknown>;
|
|
88
|
+
[k: string]: unknown;
|
|
89
|
+
}>;
|
|
90
|
+
[k: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
type TemplateStatus = 'building' | 'ready' | 'error';
|
|
93
|
+
interface Template {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
namespace: 'public' | 'private';
|
|
98
|
+
base_image?: string;
|
|
99
|
+
status: TemplateStatus;
|
|
100
|
+
buildError?: string;
|
|
101
|
+
region?: string;
|
|
102
|
+
is_owner?: boolean;
|
|
103
|
+
can_create?: boolean;
|
|
104
|
+
cogen_id?: string;
|
|
105
|
+
created_at?: string;
|
|
106
|
+
updated_at?: string;
|
|
107
|
+
cpuCount?: number;
|
|
108
|
+
memoryMB?: number;
|
|
109
|
+
diskSizeGB?: number;
|
|
110
|
+
startCmd?: string;
|
|
111
|
+
readyCmd?: string;
|
|
112
|
+
[k: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
interface TemplateBuildOptions {
|
|
115
|
+
name?: string;
|
|
116
|
+
image?: string;
|
|
117
|
+
dockerfile?: string;
|
|
118
|
+
cpuCount?: number;
|
|
119
|
+
memoryMB?: number;
|
|
120
|
+
diskSizeGB?: number;
|
|
121
|
+
startCmd?: string;
|
|
122
|
+
readyCmd?: string;
|
|
123
|
+
region?: string;
|
|
124
|
+
logPaths?: string[];
|
|
125
|
+
description?: string;
|
|
126
|
+
}
|
|
127
|
+
interface TemplateBuild {
|
|
128
|
+
templateId: string;
|
|
129
|
+
status: string;
|
|
130
|
+
region?: string;
|
|
131
|
+
owner?: string;
|
|
132
|
+
[k: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
type Permission = 'read' | 'write';
|
|
135
|
+
interface Grant {
|
|
136
|
+
grantee_id: string;
|
|
137
|
+
permission: Permission;
|
|
138
|
+
granted_at?: string;
|
|
139
|
+
expires_at?: string | null;
|
|
140
|
+
template_id?: string;
|
|
141
|
+
sandbox_id?: string;
|
|
142
|
+
[k: string]: unknown;
|
|
143
|
+
}
|
|
144
|
+
interface GrantOptions {
|
|
145
|
+
perm?: Permission;
|
|
146
|
+
expiresAt?: string;
|
|
147
|
+
reason?: string;
|
|
148
|
+
}
|
|
149
|
+
interface NetworkOptions {
|
|
150
|
+
allowInternetAccess?: boolean;
|
|
151
|
+
allowOut?: string[];
|
|
152
|
+
denyOut?: string[];
|
|
153
|
+
allowPublicTraffic?: boolean;
|
|
154
|
+
maskRequestHost?: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface CreateSandboxOptions {
|
|
157
|
+
/** Template name; defaults to `"base"` when neither name nor id is given. */
|
|
158
|
+
template?: string;
|
|
159
|
+
templateId?: string;
|
|
160
|
+
/** Lifetime in seconds. 0 / omitted = no deadline. */
|
|
161
|
+
timeout?: number;
|
|
162
|
+
onTimeout?: 'freeze' | 'kill';
|
|
163
|
+
metadata?: Record<string, string>;
|
|
164
|
+
envVars?: Record<string, string>;
|
|
165
|
+
network?: NetworkOptions;
|
|
166
|
+
}
|
|
167
|
+
interface SandboxVersion {
|
|
168
|
+
version: number;
|
|
169
|
+
frozenAt?: string;
|
|
170
|
+
label?: string;
|
|
171
|
+
[k: string]: unknown;
|
|
172
|
+
}
|
|
173
|
+
/** Full sandbox record as returned by create / get / freeze / resume / rollback / clone / reset. */
|
|
174
|
+
interface SandboxInfo {
|
|
175
|
+
id: string;
|
|
176
|
+
templateId?: string;
|
|
177
|
+
template_id?: string;
|
|
178
|
+
state: SandboxState;
|
|
179
|
+
region?: string;
|
|
180
|
+
portUrl?: string;
|
|
181
|
+
domain?: string;
|
|
182
|
+
createdAt?: string;
|
|
183
|
+
startedAt?: string;
|
|
184
|
+
frozenAt?: string;
|
|
185
|
+
timeoutAt?: string;
|
|
186
|
+
cpuCount?: number;
|
|
187
|
+
memoryMB?: number;
|
|
188
|
+
diskSizeGB?: number;
|
|
189
|
+
idleTimeout?: number;
|
|
190
|
+
versions?: SandboxVersion[];
|
|
191
|
+
metadata?: Record<string, string>;
|
|
192
|
+
trafficAccessToken?: string;
|
|
193
|
+
is_owner?: boolean;
|
|
194
|
+
has_write?: boolean;
|
|
195
|
+
cogen_id?: string;
|
|
196
|
+
created_at?: string;
|
|
197
|
+
updated_at?: string;
|
|
198
|
+
[k: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
/** Compact row from `GET /sandboxes`. */
|
|
201
|
+
interface SandboxSummary {
|
|
202
|
+
id: string;
|
|
203
|
+
template_id?: string;
|
|
204
|
+
state: SandboxState;
|
|
205
|
+
region?: string;
|
|
206
|
+
portUrl?: string;
|
|
207
|
+
domain?: string;
|
|
208
|
+
cogen_id?: string;
|
|
209
|
+
created_at?: string;
|
|
210
|
+
updated_at?: string;
|
|
211
|
+
[k: string]: unknown;
|
|
212
|
+
}
|
|
213
|
+
interface MetricPoint {
|
|
214
|
+
timestamp: string;
|
|
215
|
+
timestampUnix: number;
|
|
216
|
+
cpuCount: number;
|
|
217
|
+
cpuUsedPct: number;
|
|
218
|
+
memUsed: number;
|
|
219
|
+
memTotal: number;
|
|
220
|
+
memCache?: number;
|
|
221
|
+
diskUsed: number;
|
|
222
|
+
diskTotal: number;
|
|
223
|
+
[k: string]: unknown;
|
|
224
|
+
}
|
|
225
|
+
interface ExecOptions {
|
|
226
|
+
cwd?: string;
|
|
227
|
+
envVars?: Record<string, string>;
|
|
228
|
+
user?: string;
|
|
229
|
+
/** Seconds, default 60, max 600. */
|
|
230
|
+
timeout?: number;
|
|
231
|
+
}
|
|
232
|
+
interface CommandResult {
|
|
233
|
+
stdout: string;
|
|
234
|
+
stderr: string;
|
|
235
|
+
exitCode: number;
|
|
236
|
+
}
|
|
237
|
+
interface ExecEvent {
|
|
238
|
+
kind: 'stdout' | 'stderr' | 'exit' | 'error';
|
|
239
|
+
/** Output chunk for stdout/stderr, error message for error. */
|
|
240
|
+
data?: string;
|
|
241
|
+
exitCode?: number;
|
|
242
|
+
execId?: string;
|
|
243
|
+
stage?: string;
|
|
244
|
+
}
|
|
245
|
+
interface RunCodeOptions {
|
|
246
|
+
language?: string;
|
|
247
|
+
contextId?: string;
|
|
248
|
+
envVars?: Record<string, string>;
|
|
249
|
+
/** Seconds, default 60, max 540. */
|
|
250
|
+
timeout?: number;
|
|
251
|
+
images?: 'base64' | 'omit';
|
|
252
|
+
}
|
|
253
|
+
interface CodeError {
|
|
254
|
+
name: string;
|
|
255
|
+
value: string;
|
|
256
|
+
traceback: string | string[];
|
|
257
|
+
}
|
|
258
|
+
interface CodeResult {
|
|
259
|
+
stdout: string;
|
|
260
|
+
stderr: string;
|
|
261
|
+
executionCount?: number;
|
|
262
|
+
complete?: boolean;
|
|
263
|
+
error: CodeError | null;
|
|
264
|
+
results: Array<Record<string, unknown>>;
|
|
265
|
+
[k: string]: unknown;
|
|
266
|
+
}
|
|
267
|
+
interface StartCommandOptions {
|
|
268
|
+
cwd?: string;
|
|
269
|
+
envVars?: Record<string, string>;
|
|
270
|
+
user?: string;
|
|
271
|
+
}
|
|
272
|
+
interface ProcessInfo {
|
|
273
|
+
execId: string;
|
|
274
|
+
pid: number;
|
|
275
|
+
sandboxId?: string;
|
|
276
|
+
[k: string]: unknown;
|
|
277
|
+
}
|
|
278
|
+
interface FileEntry {
|
|
279
|
+
name: string;
|
|
280
|
+
path: string;
|
|
281
|
+
isDir: boolean;
|
|
282
|
+
size: number;
|
|
283
|
+
}
|
|
284
|
+
interface PtyOptions {
|
|
285
|
+
command?: string[];
|
|
286
|
+
rows?: number;
|
|
287
|
+
cols?: number;
|
|
288
|
+
cwd?: string;
|
|
289
|
+
envVars?: Record<string, string>;
|
|
290
|
+
}
|
|
291
|
+
interface PtyEvent {
|
|
292
|
+
kind: 'data' | 'exit';
|
|
293
|
+
data?: string;
|
|
294
|
+
exitCode?: number;
|
|
295
|
+
reason?: string;
|
|
296
|
+
}
|
|
297
|
+
interface WaitOptions {
|
|
298
|
+
/** Seconds. */
|
|
299
|
+
timeout?: number;
|
|
300
|
+
/** Poll interval in seconds. */
|
|
301
|
+
interval?: number;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** A background command started with `sandbox.commands.start()`. */
|
|
305
|
+
declare class BackgroundCommand {
|
|
306
|
+
private readonly http;
|
|
307
|
+
readonly sandboxId: string;
|
|
308
|
+
readonly execId: string;
|
|
309
|
+
readonly pid: number;
|
|
310
|
+
constructor(http: Http, sandboxId: string, execId: string, pid: number);
|
|
311
|
+
private p;
|
|
312
|
+
input(data: string): Promise<number>;
|
|
313
|
+
close(): Promise<void>;
|
|
314
|
+
/** Block until the command exits; returns its exit code. `timeout` is seconds (default 600). */
|
|
315
|
+
wait(timeout?: number): Promise<number>;
|
|
316
|
+
kill(signal?: number): Promise<void>;
|
|
317
|
+
/** Stream the command's output. Resolves to an empty stream if the server already reaped it. */
|
|
318
|
+
connect(): AsyncGenerator<ExecEvent>;
|
|
319
|
+
}
|
|
320
|
+
declare class Commands {
|
|
321
|
+
private readonly http;
|
|
322
|
+
private readonly sandboxId;
|
|
323
|
+
constructor(http: Http, sandboxId: string);
|
|
324
|
+
private p;
|
|
325
|
+
start(command: string | string[], opts?: StartCommandOptions): Promise<BackgroundCommand>;
|
|
326
|
+
list(): Promise<ProcessInfo[]>;
|
|
327
|
+
kill(pid: number, signal?: number): Promise<void>;
|
|
328
|
+
sendStdin(pid: number, data: string): Promise<void>;
|
|
329
|
+
}
|
|
330
|
+
declare class Files {
|
|
331
|
+
private readonly http;
|
|
332
|
+
private readonly sandboxId;
|
|
333
|
+
constructor(http: Http, sandboxId: string);
|
|
334
|
+
private p;
|
|
335
|
+
/** Write bytes (or a UTF-8 string). Returns the byte count written. */
|
|
336
|
+
write(path: string, data: Uint8Array | string, opts?: {
|
|
337
|
+
user?: string;
|
|
338
|
+
}): Promise<number>;
|
|
339
|
+
read(path: string, opts?: {
|
|
340
|
+
user?: string;
|
|
341
|
+
}): Promise<Uint8Array>;
|
|
342
|
+
readText(path: string, opts?: {
|
|
343
|
+
user?: string;
|
|
344
|
+
encoding?: string;
|
|
345
|
+
}): Promise<string>;
|
|
346
|
+
list(path?: string, opts?: {
|
|
347
|
+
user?: string;
|
|
348
|
+
}): Promise<FileEntry[]>;
|
|
349
|
+
}
|
|
350
|
+
/** An interactive terminal opened with `sandbox.pty.open()`. */
|
|
351
|
+
declare class PtySession {
|
|
352
|
+
private readonly http;
|
|
353
|
+
readonly sandboxId: string;
|
|
354
|
+
readonly execId: string;
|
|
355
|
+
readonly pid: number;
|
|
356
|
+
constructor(http: Http, sandboxId: string, execId: string, pid: number);
|
|
357
|
+
private p;
|
|
358
|
+
input(data: Uint8Array | string): Promise<void>;
|
|
359
|
+
resize(rows: number, cols: number): Promise<void>;
|
|
360
|
+
kill(): Promise<void>;
|
|
361
|
+
/** Stream terminal output (SSE). Ends with a `exit` event. */
|
|
362
|
+
connect(): AsyncGenerator<PtyEvent>;
|
|
363
|
+
}
|
|
364
|
+
interface PtyWsHandlers {
|
|
365
|
+
onData?: (data: string, seq?: number) => void;
|
|
366
|
+
onExit?: (exitCode: number) => void;
|
|
367
|
+
onError?: (error: string) => void;
|
|
368
|
+
}
|
|
369
|
+
/** A terminal over the WebSocket transport (`GET /sandboxes/{id}/ws/pty`). */
|
|
370
|
+
declare class PtyWebSocket {
|
|
371
|
+
private readonly ws;
|
|
372
|
+
constructor(ws: WsLike);
|
|
373
|
+
input(data: string): void;
|
|
374
|
+
resize(rows: number, cols: number): void;
|
|
375
|
+
kill(): void;
|
|
376
|
+
close(): void;
|
|
377
|
+
}
|
|
378
|
+
interface WsLike {
|
|
379
|
+
send(data: string): void;
|
|
380
|
+
close(): void;
|
|
381
|
+
addEventListener(type: string, listener: (ev: {
|
|
382
|
+
data?: unknown;
|
|
383
|
+
message?: string;
|
|
384
|
+
}) => void): void;
|
|
385
|
+
}
|
|
386
|
+
declare class Pty {
|
|
387
|
+
private readonly http;
|
|
388
|
+
private readonly sandboxId;
|
|
389
|
+
constructor(http: Http, sandboxId: string);
|
|
390
|
+
open(opts?: PtyOptions): Promise<PtySession>;
|
|
391
|
+
/**
|
|
392
|
+
* Open a terminal over WebSocket. Uses the global `WebSocket` (Node 22+, browsers) or the
|
|
393
|
+
* optional `ws` package. Resolves once the socket is open and the start frame is sent.
|
|
394
|
+
*/
|
|
395
|
+
connectWs(opts?: PtyOptions, handlers?: PtyWsHandlers): Promise<PtyWebSocket>;
|
|
396
|
+
}
|
|
397
|
+
/** Handle on one sandbox, bound to the client that created it. */
|
|
398
|
+
declare class Sandbox {
|
|
399
|
+
private readonly http;
|
|
400
|
+
readonly commands: Commands;
|
|
401
|
+
readonly files: Files;
|
|
402
|
+
readonly pty: Pty;
|
|
403
|
+
private _info;
|
|
404
|
+
constructor(http: Http, info: SandboxInfo);
|
|
405
|
+
/** The last record seen for this sandbox (call `refresh()` to update). */
|
|
406
|
+
get info(): SandboxInfo;
|
|
407
|
+
get id(): string;
|
|
408
|
+
get state(): SandboxState;
|
|
409
|
+
get templateId(): string | undefined;
|
|
410
|
+
get region(): string | undefined;
|
|
411
|
+
get metadata(): Record<string, string>;
|
|
412
|
+
get versions(): SandboxVersion[];
|
|
413
|
+
get createdAt(): string | undefined;
|
|
414
|
+
get frozenAt(): string | undefined;
|
|
415
|
+
get timeoutAt(): string | undefined;
|
|
416
|
+
/** Token to reach a sandbox created with `allowPublicTraffic: false` (create response only). */
|
|
417
|
+
get trafficAccessToken(): string | undefined;
|
|
418
|
+
/** Public URL of a port inside the sandbox. */
|
|
419
|
+
portUrl(port: number): string;
|
|
420
|
+
private p;
|
|
421
|
+
private update;
|
|
422
|
+
refresh(): Promise<this>;
|
|
423
|
+
kill(): Promise<void>;
|
|
424
|
+
/** Freeze. The server may answer 202 (still freezing); with `wait` (default) we poll until `frozen`. */
|
|
425
|
+
freeze(opts?: {
|
|
426
|
+
wait?: boolean;
|
|
427
|
+
} & WaitOptions): Promise<this>;
|
|
428
|
+
waitForState(target: SandboxState | SandboxState[], opts?: WaitOptions): Promise<this>;
|
|
429
|
+
resume(opts?: {
|
|
430
|
+
timeout?: number;
|
|
431
|
+
}): Promise<this>;
|
|
432
|
+
rollback(opts?: {
|
|
433
|
+
version?: number;
|
|
434
|
+
timeout?: number;
|
|
435
|
+
}): Promise<this>;
|
|
436
|
+
/** Clone into a new sandbox owned by the caller. Retries on 503 + Retry-After until `timeout` (s). */
|
|
437
|
+
clone(opts?: {
|
|
438
|
+
version?: number;
|
|
439
|
+
metadata?: Record<string, string>;
|
|
440
|
+
timeout?: number;
|
|
441
|
+
}): Promise<Sandbox>;
|
|
442
|
+
/** Set the lifetime deadline in seconds from now; 0 clears it. */
|
|
443
|
+
setTimeout(seconds: number): Promise<void>;
|
|
444
|
+
reset(opts?: {
|
|
445
|
+
timeout?: number;
|
|
446
|
+
}): Promise<this>;
|
|
447
|
+
metrics(opts?: {
|
|
448
|
+
start?: number;
|
|
449
|
+
end?: number;
|
|
450
|
+
}): Promise<MetricPoint[]>;
|
|
451
|
+
grant(userId: string, opts?: GrantOptions): Promise<Grant>;
|
|
452
|
+
grants(): Promise<Grant[]>;
|
|
453
|
+
revoke(userId: string): Promise<void>;
|
|
454
|
+
/** Run a command and wait for it. A non-zero exit is returned, not thrown. */
|
|
455
|
+
exec(command: string | string[], opts?: ExecOptions): Promise<CommandResult>;
|
|
456
|
+
/** Run a command and stream its output as it is produced. */
|
|
457
|
+
execStream(command: string | string[], opts?: ExecOptions): AsyncGenerator<ExecEvent>;
|
|
458
|
+
/** Execute code in the sandbox's stateful interpreter. */
|
|
459
|
+
runCode(code: string, opts?: RunCodeOptions): Promise<CodeResult>;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
declare class Templates {
|
|
463
|
+
private readonly http;
|
|
464
|
+
constructor(http: Http);
|
|
465
|
+
/** Start a build. Async: poll `get()` or use `waitReady()`. */
|
|
466
|
+
build(opts: TemplateBuildOptions): Promise<TemplateBuild>;
|
|
467
|
+
/** Poll until the template is `ready`; throws `TemplateBuildError` on `error`. */
|
|
468
|
+
waitReady(templateId: string, opts?: WaitOptions): Promise<Template>;
|
|
469
|
+
list(): Promise<Template[]>;
|
|
470
|
+
shared(): Promise<Template[]>;
|
|
471
|
+
get(templateId: string): Promise<Template>;
|
|
472
|
+
delete(templateId: string): Promise<void>;
|
|
473
|
+
grant(templateId: string, userId: string, opts?: GrantOptions): Promise<Grant>;
|
|
474
|
+
grants(templateId: string): Promise<Grant[]>;
|
|
475
|
+
revoke(templateId: string, userId: string): Promise<void>;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
interface SbBoxOptions {
|
|
479
|
+
/** API key. Falls back to `SBBOX_API_KEY`, then `GSK_API_KEY`. */
|
|
480
|
+
apiKey?: string;
|
|
481
|
+
/** Falls back to `SBBOX_BASE_URL`, then the production API. */
|
|
482
|
+
baseUrl?: string;
|
|
483
|
+
/** Default request timeout in seconds (60). */
|
|
484
|
+
timeout?: number;
|
|
485
|
+
/** Retries after the first attempt for reads and idempotent lifecycle calls (3). Set 0 to disable. */
|
|
486
|
+
retries?: number;
|
|
487
|
+
/** Appended to the User-Agent, e.g. your app name. */
|
|
488
|
+
userAgentSuffix?: string;
|
|
489
|
+
/** Custom fetch (tests, proxies). */
|
|
490
|
+
fetch?: typeof fetch;
|
|
491
|
+
}
|
|
492
|
+
declare class Sandboxes {
|
|
493
|
+
private readonly http;
|
|
494
|
+
constructor(http: Http);
|
|
495
|
+
create(opts?: CreateSandboxOptions): Promise<Sandbox>;
|
|
496
|
+
/** Compact rows. `state` filters (one or many); omitted = every live state. */
|
|
497
|
+
list(state?: ListState | ListState[]): Promise<SandboxSummary[]>;
|
|
498
|
+
shared(): Promise<Sandbox[]>;
|
|
499
|
+
get(sandboxId: string): Promise<Sandbox>;
|
|
500
|
+
/** Alias of `get()`. */
|
|
501
|
+
connect(sandboxId: string): Promise<Sandbox>;
|
|
502
|
+
private handle;
|
|
503
|
+
kill(sandboxId: string): Promise<void>;
|
|
504
|
+
freeze(sandboxId: string, opts?: {
|
|
505
|
+
wait?: boolean;
|
|
506
|
+
} & WaitOptions): Promise<Sandbox>;
|
|
507
|
+
resume(sandboxId: string, opts?: {
|
|
508
|
+
timeout?: number;
|
|
509
|
+
}): Promise<Sandbox>;
|
|
510
|
+
rollback(sandboxId: string, opts?: {
|
|
511
|
+
version?: number;
|
|
512
|
+
timeout?: number;
|
|
513
|
+
}): Promise<Sandbox>;
|
|
514
|
+
clone(sandboxId: string, opts?: {
|
|
515
|
+
version?: number;
|
|
516
|
+
metadata?: Record<string, string>;
|
|
517
|
+
timeout?: number;
|
|
518
|
+
}): Promise<Sandbox>;
|
|
519
|
+
setTimeout(sandboxId: string, seconds: number): Promise<void>;
|
|
520
|
+
reset(sandboxId: string, opts?: {
|
|
521
|
+
timeout?: number;
|
|
522
|
+
}): Promise<Sandbox>;
|
|
523
|
+
metrics(sandboxId: string, opts?: {
|
|
524
|
+
start?: number;
|
|
525
|
+
end?: number;
|
|
526
|
+
}): Promise<MetricPoint[]>;
|
|
527
|
+
grant(sandboxId: string, userId: string, opts?: GrantOptions): Promise<Grant>;
|
|
528
|
+
grants(sandboxId: string): Promise<Grant[]>;
|
|
529
|
+
revoke(sandboxId: string, userId: string): Promise<void>;
|
|
530
|
+
}
|
|
531
|
+
/** Entry point: `const sbbox = new SbBox({ apiKey })`. */
|
|
532
|
+
declare class SbBox {
|
|
533
|
+
readonly templates: Templates;
|
|
534
|
+
readonly sandboxes: Sandboxes;
|
|
535
|
+
readonly baseUrl: string;
|
|
536
|
+
private readonly http;
|
|
537
|
+
constructor(opts?: SbBoxOptions);
|
|
538
|
+
regions(): Promise<Regions>;
|
|
539
|
+
limits(): Promise<Limits>;
|
|
540
|
+
usage(days?: number): Promise<Usage>;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
interface SseMessage {
|
|
544
|
+
event: string;
|
|
545
|
+
data: string;
|
|
546
|
+
id?: string;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Parse a `text/event-stream` body into messages. `event:` defaults to `message`,
|
|
550
|
+
* multi-line `data:` is joined with `\n`, a blank line ends the event.
|
|
551
|
+
*/
|
|
552
|
+
declare function parseSse(body: ReadableStream<Uint8Array>): AsyncGenerator<SseMessage>;
|
|
553
|
+
|
|
554
|
+
/** Replace any API key that leaked into a string. */
|
|
555
|
+
declare function redact(text: string): string;
|
|
556
|
+
interface SbBoxErrorInit {
|
|
557
|
+
status: number;
|
|
558
|
+
code?: string;
|
|
559
|
+
message: string;
|
|
560
|
+
detail?: unknown;
|
|
561
|
+
retryAfter?: number;
|
|
562
|
+
requestId?: string;
|
|
563
|
+
}
|
|
564
|
+
/** Base class of every error raised by the SDK. */
|
|
565
|
+
declare class SbBoxError extends Error {
|
|
566
|
+
readonly status: number;
|
|
567
|
+
readonly code?: string;
|
|
568
|
+
/** Parsed response body (or the raw text when it was not JSON). */
|
|
569
|
+
readonly detail: unknown;
|
|
570
|
+
/** Seconds from a `Retry-After` header, when the server sent one. */
|
|
571
|
+
readonly retryAfter?: number;
|
|
572
|
+
readonly requestId?: string;
|
|
573
|
+
constructor(init: SbBoxErrorInit);
|
|
574
|
+
/** A named field from the error body (`plan`, `limit`, `balance`, `recovery`, …). */
|
|
575
|
+
field<T = unknown>(name: string): T | undefined;
|
|
576
|
+
}
|
|
577
|
+
declare class ValidationError extends SbBoxError {
|
|
578
|
+
}
|
|
579
|
+
declare class AuthenticationError extends SbBoxError {
|
|
580
|
+
}
|
|
581
|
+
declare class InsufficientCreditsError extends SbBoxError {
|
|
582
|
+
get balance(): number | undefined;
|
|
583
|
+
}
|
|
584
|
+
declare class ForbiddenError extends SbBoxError {
|
|
585
|
+
}
|
|
586
|
+
declare class PlanRequiredError extends ForbiddenError {
|
|
587
|
+
get plan(): string | undefined;
|
|
588
|
+
get upgrade(): string | undefined;
|
|
589
|
+
}
|
|
590
|
+
declare class NotFoundError extends SbBoxError {
|
|
591
|
+
}
|
|
592
|
+
declare class RegionRetiredError extends NotFoundError {
|
|
593
|
+
get region(): string | undefined;
|
|
594
|
+
}
|
|
595
|
+
declare class CommandTimeoutError extends SbBoxError {
|
|
596
|
+
get killed(): boolean;
|
|
597
|
+
}
|
|
598
|
+
declare class ConflictError extends SbBoxError {
|
|
599
|
+
}
|
|
600
|
+
declare class LimitError extends ConflictError {
|
|
601
|
+
get plan(): string | undefined;
|
|
602
|
+
get limit(): number | undefined;
|
|
603
|
+
get current(): number | undefined;
|
|
604
|
+
get requested(): number | undefined;
|
|
605
|
+
}
|
|
606
|
+
declare class InterpreterUnavailableError extends ConflictError {
|
|
607
|
+
}
|
|
608
|
+
declare class DiskLostError extends SbBoxError {
|
|
609
|
+
}
|
|
610
|
+
declare class MemoryExpiredError extends SbBoxError {
|
|
611
|
+
get recovery(): string[];
|
|
612
|
+
}
|
|
613
|
+
declare class ClientDisconnectedError extends SbBoxError {
|
|
614
|
+
}
|
|
615
|
+
declare class ServerError extends SbBoxError {
|
|
616
|
+
}
|
|
617
|
+
declare class InterpreterStartFailedError extends ServerError {
|
|
618
|
+
}
|
|
619
|
+
/** Network failure or request timeout before any HTTP status was received. */
|
|
620
|
+
declare class SbBoxConnectionError extends SbBoxError {
|
|
621
|
+
constructor(message: string, cause?: unknown);
|
|
622
|
+
}
|
|
623
|
+
/** `templates.waitReady` saw the build end in `error`. */
|
|
624
|
+
declare class TemplateBuildError extends SbBoxError {
|
|
625
|
+
readonly templateId: string;
|
|
626
|
+
readonly buildError?: string;
|
|
627
|
+
constructor(templateId: string, buildError?: string, detail?: unknown);
|
|
628
|
+
}
|
|
629
|
+
/** A `wait` helper ran past its deadline. */
|
|
630
|
+
declare class WaitTimeoutError extends SbBoxError {
|
|
631
|
+
constructor(message: string);
|
|
632
|
+
}
|
|
633
|
+
/** Extract (code, message) from either `{"detail": …}` or `{"error": …}` envelopes. */
|
|
634
|
+
declare function describeBody(body: unknown, fallback: string): {
|
|
635
|
+
code?: string;
|
|
636
|
+
message: string;
|
|
637
|
+
};
|
|
638
|
+
/** Map an HTTP failure to the SDK error class from the contract table. */
|
|
639
|
+
declare function errorFromResponse(status: number, body: unknown, headers: Headers): SbBoxError;
|
|
640
|
+
|
|
641
|
+
export { AuthenticationError, BackgroundCommand, ClientDisconnectedError, type CodeError, type CodeResult, type CommandResult, CommandTimeoutError, Commands, ConflictError, type CreateSandboxOptions, DEFAULT_BASE_URL, DiskLostError, type ExecEvent, type ExecOptions, type FileEntry, Files, ForbiddenError, type Grant, type GrantOptions, InsufficientCreditsError, InterpreterStartFailedError, InterpreterUnavailableError, LimitError, type Limits, type ListState, MemoryExpiredError, type MetricPoint, type NetworkOptions, NotFoundError, type Permission, PlanRequiredError, type ProcessInfo, Pty, type PtyEvent, type PtyOptions, PtySession, PtyWebSocket, type PtyWsHandlers, RegionRetiredError, type Regions, type RunCodeOptions, SDK_VERSION, Sandbox, type SandboxInfo, type SandboxState, type SandboxSummary, type SandboxVersion, Sandboxes, SbBox, SbBoxConnectionError, SbBoxError, type SbBoxErrorInit, type SbBoxOptions, ServerError, type SseMessage, type StartCommandOptions, type Template, type TemplateBuild, TemplateBuildError, type TemplateBuildOptions, type TemplateStatus, Templates, type Usage, type UsageTotals, ValidationError, type WaitOptions, WaitTimeoutError, describeBody, errorFromResponse, parseSse, redact };
|