withruntime 0.17.2 → 0.21.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.
Files changed (52) hide show
  1. package/COMPATIBILITY.md +32 -1
  2. package/README.md +19 -0
  3. package/README.src.md +19 -0
  4. package/dist/agents/index.d.ts +11 -0
  5. package/dist/agents/index.js +12 -0
  6. package/dist/agents-cli.d.ts +10 -0
  7. package/dist/agents-cli.js +362 -0
  8. package/dist/apps-cli.d.ts +14 -0
  9. package/dist/apps-cli.js +737 -0
  10. package/dist/builds/index.d.ts +10 -0
  11. package/dist/builds/index.js +11 -0
  12. package/dist/cli-words.js +11 -0
  13. package/dist/cli.d.ts +4 -0
  14. package/dist/cli.js +104 -6
  15. package/dist/client.d.ts +19 -0
  16. package/dist/client.js +20 -0
  17. package/dist/cloudflare/errors.d.ts +23 -0
  18. package/dist/cloudflare/errors.js +16 -0
  19. package/dist/cloudflare/index.d.ts +82 -9
  20. package/dist/cloudflare/index.js +162 -38
  21. package/dist/cloudflare/interpreter.js +14 -5
  22. package/dist/cloudflare/mime.d.ts +1 -0
  23. package/dist/cloudflare/mime.js +66 -0
  24. package/dist/cloudflare/streams.d.ts +8 -0
  25. package/dist/cloudflare/streams.js +30 -0
  26. package/dist/cloudflare/types.d.ts +338 -0
  27. package/dist/cloudflare/types.js +80 -0
  28. package/dist/cloudflare/worker.d.ts +297 -10
  29. package/dist/cloudflare/worker.js +203 -17
  30. package/dist/containers/index.d.ts +10 -0
  31. package/dist/containers/index.js +11 -0
  32. package/dist/daytona/sandbox.d.ts +2 -1
  33. package/dist/daytona/sandbox.js +2 -1
  34. package/dist/identity.js +18 -2
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.js +1 -0
  37. package/dist/product-names.js +3 -0
  38. package/dist/products/agents.d.ts +272 -0
  39. package/dist/products/agents.js +251 -0
  40. package/dist/products/builds.d.ts +11 -1
  41. package/dist/products/builds.js +7 -0
  42. package/dist/products/containers.d.ts +71 -0
  43. package/dist/products/containers.js +6 -0
  44. package/dist/products/index.d.ts +6 -0
  45. package/dist/products/index.js +7 -0
  46. package/dist/sandbox.d.ts +4 -0
  47. package/dist/transport.d.ts +2 -2
  48. package/dist/transport.js +1 -1
  49. package/dist/tunnel.js +1 -1
  50. package/dist/types.d.ts +11 -0
  51. package/dist/vercel/errors.d.ts +1 -1
  52. package/package.json +16 -1
@@ -0,0 +1,338 @@
1
+ import type { ExecResult, BucketProvider } from "./index.js";
2
+ import type { ExecutionError, OutputMessage, Result } from "./interpreter.js";
3
+ export interface ExecEvent {
4
+ type: "start" | "stdout" | "stderr" | "complete" | "error";
5
+ timestamp: string;
6
+ data?: string;
7
+ command?: string;
8
+ exitCode?: number;
9
+ result?: ExecResult;
10
+ error?: string;
11
+ sessionId?: string;
12
+ pid?: number;
13
+ }
14
+ export interface LogEvent {
15
+ type: "stdout" | "stderr" | "exit" | "error";
16
+ timestamp: string;
17
+ data: string;
18
+ processId: string;
19
+ sessionId?: string;
20
+ exitCode?: number;
21
+ }
22
+ export interface ExecutionResult {
23
+ code: string;
24
+ logs: {
25
+ stdout: string[];
26
+ stderr: string[];
27
+ };
28
+ error?: ExecutionError;
29
+ executionCount?: number;
30
+ results: {
31
+ text?: string;
32
+ html?: string;
33
+ png?: string;
34
+ jpeg?: string;
35
+ svg?: string;
36
+ latex?: string;
37
+ markdown?: string;
38
+ javascript?: string;
39
+ json?: any;
40
+ chart?: unknown;
41
+ data?: any;
42
+ }[];
43
+ }
44
+ export type ProcessStatus = "starting" | "running" | "completed" | "failed" | "killed" | "error";
45
+ export interface ListFilesOptions {
46
+ recursive?: boolean;
47
+ includeHidden?: boolean;
48
+ sessionId?: string;
49
+ }
50
+ export interface WaitForLogResult {
51
+ line: string;
52
+ match?: RegExpMatchArray;
53
+ }
54
+ export interface ExecutionCallbacks {
55
+ onStdout?: (output: OutputMessage) => void | Promise<void>;
56
+ onStderr?: (output: OutputMessage) => void | Promise<void>;
57
+ onResult?: (result: Result) => void | Promise<void>;
58
+ onError?: (error: ExecutionError) => void | Promise<void>;
59
+ }
60
+ export interface BaseExecOptions {
61
+ timeout?: number;
62
+ env?: Record<string, string | undefined>;
63
+ cwd?: string;
64
+ encoding?: string;
65
+ }
66
+ export interface BucketCredentials {
67
+ accessKeyId: string;
68
+ secretAccessKey: string;
69
+ }
70
+ export interface LocalMountBucketOptions {
71
+ localBucket: true;
72
+ prefix?: string;
73
+ readOnly?: boolean;
74
+ }
75
+ export interface RemoteMountBucketOptions {
76
+ endpoint: string;
77
+ provider?: BucketProvider;
78
+ credentials?: BucketCredentials;
79
+ readOnly?: boolean;
80
+ s3fsOptions?: string[];
81
+ prefix?: string;
82
+ credentialProxy?: boolean;
83
+ }
84
+ export interface PtyOptions {
85
+ cols?: number;
86
+ rows?: number;
87
+ shell?: string;
88
+ }
89
+ export interface QuickTunnelInfo {
90
+ id: string;
91
+ port: number;
92
+ url: string;
93
+ hostname: string;
94
+ createdAt: string;
95
+ name?: never;
96
+ }
97
+ export interface NamedTunnelInfo {
98
+ id: string;
99
+ port: number;
100
+ url: string;
101
+ hostname: string;
102
+ createdAt: string;
103
+ name: string;
104
+ }
105
+ export type TunnelInfo = QuickTunnelInfo | NamedTunnelInfo;
106
+ export interface TunnelOptions {
107
+ name?: string;
108
+ }
109
+ export interface DirectoryBackup {
110
+ readonly id: string;
111
+ readonly dir: string;
112
+ readonly localBucket?: boolean;
113
+ }
114
+ export interface BackupOptions {
115
+ dir: string;
116
+ name?: string;
117
+ ttl?: number;
118
+ gitignore?: boolean;
119
+ excludes?: string[];
120
+ localBucket?: boolean;
121
+ compression?: {
122
+ format?: "gzip" | "lz4" | "zstd";
123
+ threads?: number;
124
+ };
125
+ multipart?: boolean;
126
+ }
127
+ export interface RestoreBackupResult {
128
+ success: boolean;
129
+ dir: string;
130
+ id: string;
131
+ }
132
+ export type FileWatchSSEEvent = {
133
+ type: "watching";
134
+ path: string;
135
+ watchId: string;
136
+ } | {
137
+ type: "event";
138
+ eventType: "create" | "modify" | "delete" | "move_from" | "move_to" | "attrib";
139
+ path: string;
140
+ isDirectory: boolean;
141
+ timestamp: string;
142
+ } | {
143
+ type: "error";
144
+ error: string;
145
+ } | {
146
+ type: "stopped";
147
+ reason: string;
148
+ };
149
+ type ProcessRecord = {
150
+ id: string;
151
+ pid?: number;
152
+ command: string;
153
+ status: ProcessStatus;
154
+ startTime: string;
155
+ endTime?: string;
156
+ exitCode?: number;
157
+ };
158
+ export interface BaseApiResponse {
159
+ success: boolean;
160
+ timestamp: string;
161
+ }
162
+ export interface ProcessStartResult extends BaseApiResponse {
163
+ processId: string;
164
+ pid?: number;
165
+ command: string;
166
+ }
167
+ export interface ProcessListResult extends BaseApiResponse {
168
+ processes: ProcessRecord[];
169
+ }
170
+ export interface ProcessInfoResult extends BaseApiResponse {
171
+ process: ProcessRecord;
172
+ }
173
+ export interface ProcessKillResult extends BaseApiResponse {
174
+ processId: string;
175
+ signal?: string;
176
+ }
177
+ export interface ProcessLogsResult extends BaseApiResponse {
178
+ processId: string;
179
+ stdout: string;
180
+ stderr: string;
181
+ }
182
+ export interface ProcessCleanupResult extends BaseApiResponse {
183
+ message?: string;
184
+ killedCount?: number;
185
+ cleanedCount: number;
186
+ }
187
+ export type SandboxTransport = "http" | "websocket" | "rpc";
188
+ export type ContainerUnavailableReason = "container_starting" | "container_unhealthy" | "container_replaced" | "rpc_upgrade_failed" | "no_container_instance_available" | "max_container_instances_exceeded" | "container_unreachable";
189
+ export interface ContainerUnavailableContext {
190
+ reason: ContainerUnavailableReason;
191
+ retryable: true;
192
+ retryAfterMs?: number;
193
+ originalMessage?: string;
194
+ }
195
+ export type OperationInterruptedReason = "runtime_replaced" | "transport_disposed" | "sandbox_lifetime_changed" | "recovery_exhausted";
196
+ export interface OperationInterruptedContext {
197
+ reason: OperationInterruptedReason;
198
+ operation: string;
199
+ phase: string;
200
+ admitted: boolean | "unknown";
201
+ retryable: boolean;
202
+ recoveryAttempts?: number;
203
+ maxRecoveryAttempts?: number;
204
+ containerExitCode?: number;
205
+ stopReason?: string;
206
+ }
207
+ export type RPCTransportErrorKind = "peer_closed" | "connection_failed" | "upgrade_failed" | "invalid_frame" | "protocol_error" | "session_disposed" | "unknown";
208
+ export interface RPCTransportContext {
209
+ kind: RPCTransportErrorKind;
210
+ originalMessage: string;
211
+ errorName: string;
212
+ closeCode?: number;
213
+ closeReason?: string;
214
+ }
215
+ export interface ContainerStub {
216
+ containerFetch(url: string, options: RequestInit, port?: number): Promise<Response>;
217
+ fetch(request: Request): Promise<Response>;
218
+ }
219
+ export interface SessionRequest {
220
+ sessionId?: string;
221
+ }
222
+ export interface CommandsResponse extends BaseApiResponse {
223
+ availableCommands: string[];
224
+ count: number;
225
+ }
226
+ export interface CommandExecuteResponse extends BaseApiResponse {
227
+ stdout: string;
228
+ stderr: string;
229
+ exitCode: number;
230
+ command: string;
231
+ }
232
+ export interface CreateSessionRequest {
233
+ id: string;
234
+ env?: Record<string, string | undefined>;
235
+ cwd?: string;
236
+ commandTimeoutMs?: number;
237
+ }
238
+ export interface CreateSessionResponse extends BaseApiResponse {
239
+ id: string;
240
+ message: string;
241
+ containerPlacementId?: string | null;
242
+ }
243
+ export interface DeleteSessionRequest {
244
+ sessionId: string;
245
+ }
246
+ export interface DeleteSessionResponse extends BaseApiResponse {
247
+ sessionId: string;
248
+ }
249
+ export interface ExecuteRequest {
250
+ command: string;
251
+ sessionId?: string;
252
+ background?: boolean;
253
+ timeoutMs?: number;
254
+ env?: Record<string, string | undefined>;
255
+ cwd?: string;
256
+ origin?: "user" | "internal";
257
+ }
258
+ export interface FileOperationRequest extends SessionRequest {
259
+ path: string;
260
+ newPath?: string;
261
+ }
262
+ export interface GitCheckoutRequest extends SessionRequest {
263
+ repoUrl: string;
264
+ branch?: string;
265
+ targetDir?: string;
266
+ depth?: number;
267
+ timeoutMs?: number;
268
+ }
269
+ export interface MkdirRequest extends SessionRequest {
270
+ path: string;
271
+ recursive?: boolean;
272
+ }
273
+ export interface PingResponse extends BaseApiResponse {
274
+ message: string;
275
+ uptime?: number;
276
+ }
277
+ export interface ReadFileRequest extends SessionRequest {
278
+ path: string;
279
+ encoding?: string;
280
+ }
281
+ export interface WriteFileRequest extends SessionRequest {
282
+ path: string;
283
+ content: string;
284
+ encoding?: string;
285
+ }
286
+ export interface StartProcessRequest {
287
+ command: string;
288
+ sessionId?: string;
289
+ processId?: string;
290
+ timeoutMs?: number;
291
+ env?: Record<string, string | undefined>;
292
+ cwd?: string;
293
+ encoding?: string;
294
+ autoCleanup?: boolean;
295
+ origin?: "user" | "internal";
296
+ }
297
+ export interface RequestConfig extends RequestInit {
298
+ endpoint: string;
299
+ data?: Record<string, unknown>;
300
+ }
301
+ export type ResponseHandler<T> = (response: Response) => Promise<T>;
302
+ export interface SandboxClientOptions {
303
+ baseUrl?: string;
304
+ port?: number;
305
+ stub?: ContainerStub;
306
+ defaultHeaders?: Record<string, string>;
307
+ retryTimeoutMs?: number;
308
+ }
309
+ export declare class SandboxClient {
310
+ constructor(..._args: unknown[]);
311
+ }
312
+ export declare class CommandClient {
313
+ constructor(..._args: unknown[]);
314
+ }
315
+ export declare class FileClient {
316
+ constructor(..._args: unknown[]);
317
+ }
318
+ export declare class GitClient {
319
+ constructor(..._args: unknown[]);
320
+ }
321
+ export declare class PortClient {
322
+ constructor(..._args: unknown[]);
323
+ }
324
+ export declare class ProcessClient {
325
+ constructor(..._args: unknown[]);
326
+ }
327
+ export declare class UtilityClient {
328
+ constructor(..._args: unknown[]);
329
+ }
330
+ export declare class BackupClient {
331
+ constructor(..._args: unknown[]);
332
+ }
333
+ export declare class InterpreterClient {
334
+ constructor(..._args: unknown[]);
335
+ }
336
+ export declare function isDurableObjectCodeUpdateReset(error: unknown): boolean;
337
+ export declare function isPlatformTransientError(error: unknown): boolean;
338
+ export {};
@@ -0,0 +1,80 @@
1
+ /** The rest of @cloudflare/sandbox 0.12.10's exported types, in its shapes, so
2
+ * TypeScript that names them still compiles after the import changes. Its
3
+ * container clients (CommandClient and the others) are refused: Runtime's API
4
+ * is the client. */
5
+ import { refusal } from "../compat/core.js";
6
+ const CLIENT = "Runtime's API is the client; call the Sandbox's methods";
7
+ function client(name) {
8
+ throw refusal("Cloudflare", name, CLIENT);
9
+ }
10
+ export class SandboxClient {
11
+ constructor(..._args) {
12
+ client("SandboxClient");
13
+ }
14
+ }
15
+ export class CommandClient {
16
+ constructor(..._args) {
17
+ client("CommandClient");
18
+ }
19
+ }
20
+ export class FileClient {
21
+ constructor(..._args) {
22
+ client("FileClient");
23
+ }
24
+ }
25
+ export class GitClient {
26
+ constructor(..._args) {
27
+ client("GitClient");
28
+ }
29
+ }
30
+ export class PortClient {
31
+ constructor(..._args) {
32
+ client("PortClient");
33
+ }
34
+ }
35
+ export class ProcessClient {
36
+ constructor(..._args) {
37
+ client("ProcessClient");
38
+ }
39
+ }
40
+ export class UtilityClient {
41
+ constructor(..._args) {
42
+ client("UtilityClient");
43
+ }
44
+ }
45
+ export class BackupClient {
46
+ constructor(..._args) {
47
+ client("BackupClient");
48
+ }
49
+ }
50
+ export class InterpreterClient {
51
+ constructor(..._args) {
52
+ client("InterpreterClient");
53
+ }
54
+ }
55
+ // Cloudflare's platform-error predicates. Runtime's API answers in its own
56
+ // errors, so these match only the messages Cloudflare's platform uses.
57
+ const causes = function* (error) {
58
+ for (let e = error, depth = 0; e != null && depth < 8; depth++) {
59
+ yield e;
60
+ e = e.cause;
61
+ }
62
+ };
63
+ const message = (e) => (e instanceof Error ? e.message : typeof e === "string" ? e : "");
64
+ const RESET = /reset because its code was updated|this script has been upgraded/i;
65
+ export function isDurableObjectCodeUpdateReset(error) {
66
+ for (const e of causes(error))
67
+ if (RESET.test(message(e)))
68
+ return true;
69
+ return false;
70
+ }
71
+ export function isPlatformTransientError(error) {
72
+ for (const e of causes(error)) {
73
+ const text = message(e);
74
+ if (RESET.test(text) ||
75
+ /network connection lost/i.test(text) ||
76
+ /internal error while starting up durable object storage caused object to be reset/i.test(text))
77
+ return true;
78
+ }
79
+ return false;
80
+ }