withruntime 0.2.2 → 0.3.1
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/README.md +70 -4
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +1291 -0
- package/dist/client.d.ts +123 -0
- package/dist/client.js +160 -0
- package/dist/credentials.d.ts +44 -0
- package/dist/credentials.js +180 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.js +106 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +25 -0
- package/dist/login.d.ts +119 -0
- package/dist/login.js +367 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.js +221 -0
- package/dist/page.d.ts +13 -0
- package/dist/page.js +39 -0
- package/dist/products/desktop.d.ts +103 -0
- package/dist/products/desktop.js +38 -0
- package/dist/products/images.d.ts +121 -0
- package/dist/products/images.js +64 -0
- package/dist/products/index.d.ts +31 -0
- package/dist/products/index.js +37 -0
- package/dist/products/interpreter.d.ts +88 -0
- package/dist/products/interpreter.js +81 -0
- package/dist/products/limits.d.ts +25 -0
- package/dist/products/limits.js +10 -0
- package/dist/products/network.d.ts +47 -0
- package/dist/products/network.js +19 -0
- package/dist/products/previews.d.ts +54 -0
- package/dist/products/previews.js +30 -0
- package/dist/products/referrals.d.ts +36 -0
- package/dist/products/referrals.js +8 -0
- package/dist/products/volumes.d.ts +47 -0
- package/dist/products/volumes.js +27 -0
- package/dist/sandbox.d.ts +192 -0
- package/dist/sandbox.js +628 -0
- package/dist/snapshots.d.ts +50 -0
- package/dist/snapshots.js +55 -0
- package/dist/tar.d.ts +3 -0
- package/dist/tar.js +116 -0
- package/dist/transport.d.ts +65 -0
- package/dist/transport.js +261 -0
- package/dist/types.d.ts +175 -0
- package/dist/types.js +1 -0
- package/package.json +54 -8
- package/cli.js +0 -7
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Page } from "./page.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "./transport.js";
|
|
3
|
+
import type { CommandResult, ExecOptions, FileEntry, OutputEvent, ProcessInfo, SandboxInfo } from "./types.js";
|
|
4
|
+
import { type SandboxExtensions } from "./products/index.js";
|
|
5
|
+
import type { Snapshot, SnapshotOptions } from "./snapshots.js";
|
|
6
|
+
/** A running (or stopped) sandbox. Every method is one API call or a short
|
|
7
|
+
* sequence of them; `await using sbx = await Sandbox.create()` stops it for
|
|
8
|
+
* you at the end of the block. */
|
|
9
|
+
export interface Sandbox extends SandboxExtensions {
|
|
10
|
+
}
|
|
11
|
+
export declare class Sandbox implements AsyncDisposable {
|
|
12
|
+
#private;
|
|
13
|
+
readonly files: Files;
|
|
14
|
+
readonly processes: Processes;
|
|
15
|
+
constructor(transport: Transport, info: SandboxInfo);
|
|
16
|
+
get id(): string;
|
|
17
|
+
/** What the API last said about this sandbox. `refresh()` asks again. */
|
|
18
|
+
get info(): SandboxInfo;
|
|
19
|
+
get state(): SandboxInfo["state"];
|
|
20
|
+
refresh(options?: RequestOptions): Promise<this>;
|
|
21
|
+
/** Waits (server-side, no polling) until the sandbox reaches `state`. */
|
|
22
|
+
waitFor(state: "running" | "paused" | "stopped", options?: {
|
|
23
|
+
timeoutSeconds?: number;
|
|
24
|
+
} & RequestOptions): Promise<this>;
|
|
25
|
+
/** Runs a command and returns its exit code and output. A string runs under
|
|
26
|
+
* `bash -c`; an array runs without a shell. With onStdout/onStderr the output
|
|
27
|
+
* streams as it happens. A timeout is a result (timedOut: true, the output so
|
|
28
|
+
* far), never an error; `check: true` throws CommandError on a non-zero exit. */
|
|
29
|
+
exec(command: string | readonly string[], options?: ExecOptions): Promise<CommandResult>;
|
|
30
|
+
/** The command's events as they happen: start, stdout, stderr, exit. Resumes
|
|
31
|
+
* by itself when the server ends a long stream, so it never drops output. */
|
|
32
|
+
execStream(command: string | readonly string[], options?: ExecOptions): AsyncGenerator<OutputEvent>;
|
|
33
|
+
/** Starts a background process (a server, a watcher, a REPL) and returns at
|
|
34
|
+
* once. `stdin: "pipe"` keeps its input open for write(); `pty` gives it a
|
|
35
|
+
* terminal. */
|
|
36
|
+
spawn(command: string | readonly string[], options?: Omit<ExecOptions, "onStdout" | "onStderr" | "check" | "stdin"> & {
|
|
37
|
+
/** "pipe" keeps input open for write(); any other text is given once, then closed. */
|
|
38
|
+
stdin?: string;
|
|
39
|
+
pty?: {
|
|
40
|
+
cols?: number;
|
|
41
|
+
rows?: number;
|
|
42
|
+
};
|
|
43
|
+
}): Promise<Process>;
|
|
44
|
+
/** An interactive terminal over a WebSocket. Bytes you write are typed;
|
|
45
|
+
* onData receives what the terminal prints. */
|
|
46
|
+
terminal(options?: {
|
|
47
|
+
cols?: number;
|
|
48
|
+
rows?: number;
|
|
49
|
+
command?: string;
|
|
50
|
+
cwd?: string;
|
|
51
|
+
/** Attach to a process started with a pty instead of a new shell. */
|
|
52
|
+
processId?: string;
|
|
53
|
+
onData?: (data: Uint8Array) => void;
|
|
54
|
+
}): Promise<Terminal>;
|
|
55
|
+
stop(options?: RequestOptions & {
|
|
56
|
+
wait?: boolean;
|
|
57
|
+
}): Promise<this>;
|
|
58
|
+
pause(options?: RequestOptions & {
|
|
59
|
+
wait?: boolean;
|
|
60
|
+
}): Promise<this>;
|
|
61
|
+
/** Carries on a paused sandbox; `timeoutSeconds` is its new lease. */
|
|
62
|
+
wake(options?: RequestOptions & {
|
|
63
|
+
wait?: boolean;
|
|
64
|
+
timeoutSeconds?: number;
|
|
65
|
+
}): Promise<this>;
|
|
66
|
+
/** More time before the lease ends (at most an hour ahead of now). */
|
|
67
|
+
extend(seconds: number, options?: RequestOptions): Promise<this>;
|
|
68
|
+
/** Days a paused sandbox is kept before deletion (1 to 365). */
|
|
69
|
+
setRetention(days: number, options?: RequestOptions): Promise<this>;
|
|
70
|
+
/** Keeps this sandbox's whole machine (files, memory, running processes) as
|
|
71
|
+
* a snapshot to start new sandboxes from. A running sandbox is paused for
|
|
72
|
+
* the moment it takes, then woken; a paused one stays paused. */
|
|
73
|
+
snapshot(options?: SnapshotOptions & RequestOptions): Promise<Snapshot>;
|
|
74
|
+
/** Copies of this sandbox as it is now (files, memory, running processes),
|
|
75
|
+
* each its own sandbox, answered once they run. A running sandbox is paused
|
|
76
|
+
* for the moment its snapshot takes, then woken. One without `count`; an
|
|
77
|
+
* array with it. */
|
|
78
|
+
fork(options?: {
|
|
79
|
+
name?: string;
|
|
80
|
+
labels?: Record<string, string>;
|
|
81
|
+
keepSnapshot?: boolean;
|
|
82
|
+
} & RequestOptions): Promise<Sandbox>;
|
|
83
|
+
fork(options: {
|
|
84
|
+
count: number;
|
|
85
|
+
name?: string;
|
|
86
|
+
labels?: Record<string, string>;
|
|
87
|
+
keepSnapshot?: boolean;
|
|
88
|
+
} & RequestOptions): Promise<Sandbox[]>;
|
|
89
|
+
/** Starts a stopped persistent sandbox again from its disk (memory is not kept). */
|
|
90
|
+
restart(options?: RequestOptions & {
|
|
91
|
+
wait?: boolean;
|
|
92
|
+
}): Promise<this>;
|
|
93
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
94
|
+
toJSON(): SandboxInfo;
|
|
95
|
+
}
|
|
96
|
+
export declare class Processes {
|
|
97
|
+
private readonly t;
|
|
98
|
+
private readonly sandboxId;
|
|
99
|
+
constructor(t: Transport, sandboxId: string);
|
|
100
|
+
list(): Promise<ProcessInfo[]>;
|
|
101
|
+
get(processId: string): Promise<Process>;
|
|
102
|
+
/** Output events from `cursor` until the process exits, across stream slices. */
|
|
103
|
+
follow(processId: string, options?: {
|
|
104
|
+
cursor?: number;
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
}): AsyncGenerator<OutputEvent>;
|
|
107
|
+
}
|
|
108
|
+
/** A background process: its output, its input, its end. */
|
|
109
|
+
export declare class Process {
|
|
110
|
+
#private;
|
|
111
|
+
private readonly t;
|
|
112
|
+
readonly sandboxId: string;
|
|
113
|
+
info: ProcessInfo;
|
|
114
|
+
constructor(t: Transport, sandboxId: string, info: ProcessInfo);
|
|
115
|
+
get id(): string;
|
|
116
|
+
/** Every output event from the start (or `cursor`) until exit. */
|
|
117
|
+
output(options?: {
|
|
118
|
+
cursor?: number;
|
|
119
|
+
signal?: AbortSignal;
|
|
120
|
+
}): AsyncGenerator<OutputEvent>;
|
|
121
|
+
/** Waits for the process to end and returns its result. */
|
|
122
|
+
wait(options?: {
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
}): Promise<CommandResult>;
|
|
125
|
+
/** Sends input. Offsets are tracked for you, so a retried write is never typed twice. */
|
|
126
|
+
write(data: string | Uint8Array, options?: {
|
|
127
|
+
eof?: boolean;
|
|
128
|
+
}): Promise<void>;
|
|
129
|
+
kill(signal?: "SIGTERM" | "SIGKILL" | "SIGINT" | "SIGHUP" | "SIGQUIT" | "SIGUSR1" | "SIGUSR2"): Promise<void>;
|
|
130
|
+
resize(cols: number, rows: number): Promise<void>;
|
|
131
|
+
refresh(): Promise<ProcessInfo>;
|
|
132
|
+
}
|
|
133
|
+
export declare class Terminal {
|
|
134
|
+
#private;
|
|
135
|
+
private readonly socket;
|
|
136
|
+
readonly exited: Promise<number | null>;
|
|
137
|
+
private constructor();
|
|
138
|
+
get processId(): string | undefined;
|
|
139
|
+
static open(socket: WebSocket, onData?: (data: Uint8Array) => void): Promise<Terminal>;
|
|
140
|
+
write(data: string | Uint8Array): void;
|
|
141
|
+
resize(cols: number, rows: number): void;
|
|
142
|
+
close(): void;
|
|
143
|
+
}
|
|
144
|
+
/** Files in the sandbox. Paths are absolute; any path the sandbox user may use. */
|
|
145
|
+
export declare class Files {
|
|
146
|
+
#private;
|
|
147
|
+
private readonly t;
|
|
148
|
+
private readonly sandboxId;
|
|
149
|
+
constructor(t: Transport, sandboxId: string);
|
|
150
|
+
/** A file's bytes, any size. */
|
|
151
|
+
read(path: string, options?: RequestOptions): Promise<Uint8Array>;
|
|
152
|
+
readText(path: string, options?: RequestOptions): Promise<string>;
|
|
153
|
+
/** Writes a file of any size, atomically, making parent directories. Large
|
|
154
|
+
* ones go in parallel 1 MiB chunks checked against their SHA-256. */
|
|
155
|
+
write(path: string, data: string | Uint8Array, options?: RequestOptions): Promise<{
|
|
156
|
+
path: string;
|
|
157
|
+
size: number;
|
|
158
|
+
}>;
|
|
159
|
+
/** Directory entries; `depth` goes deeper, `glob` filters (e.g. "**\/*.py"). */
|
|
160
|
+
list(path?: string, options?: {
|
|
161
|
+
depth?: number;
|
|
162
|
+
glob?: string;
|
|
163
|
+
hidden?: boolean;
|
|
164
|
+
limit?: number;
|
|
165
|
+
}): Promise<FileEntry[]>;
|
|
166
|
+
glob(pattern: string, root?: string): Promise<FileEntry[]>;
|
|
167
|
+
stat(path: string): Promise<(FileEntry & {
|
|
168
|
+
exists: true;
|
|
169
|
+
}) | {
|
|
170
|
+
exists: false;
|
|
171
|
+
path: string;
|
|
172
|
+
}>;
|
|
173
|
+
exists(path: string): Promise<boolean>;
|
|
174
|
+
mkdir(path: string, options?: {
|
|
175
|
+
parents?: boolean;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
remove(path: string, options?: {
|
|
178
|
+
recursive?: boolean;
|
|
179
|
+
}): Promise<boolean>;
|
|
180
|
+
rename(from: string, to: string, options?: {
|
|
181
|
+
overwrite?: boolean;
|
|
182
|
+
}): Promise<void>;
|
|
183
|
+
/** Copies a local file or directory into the sandbox. A directory travels as
|
|
184
|
+
* one gzipped tar and is unpacked in place. */
|
|
185
|
+
upload(localPath: string, remotePath: string): Promise<void>;
|
|
186
|
+
/** Copies a file or directory out of the sandbox. */
|
|
187
|
+
download(remotePath: string, localPath: string): Promise<void>;
|
|
188
|
+
}
|
|
189
|
+
export declare function sandboxPage(t: Transport, body: {
|
|
190
|
+
data: SandboxInfo[];
|
|
191
|
+
nextCursor: string | null;
|
|
192
|
+
}, query: Record<string, unknown>): Page<Sandbox>;
|