computesdk 1.12.1 → 1.15.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/dist/index.d.mts CHANGED
@@ -1109,8 +1109,10 @@ declare class Terminal {
1109
1109
  interface ServerStartOptions {
1110
1110
  /** Unique server identifier (URL-safe) */
1111
1111
  slug: string;
1112
- /** Command to start the server */
1113
- command: string;
1112
+ /** Install command to run before starting (optional, runs blocking, e.g., "npm install") */
1113
+ install?: string;
1114
+ /** Command to start the server (e.g., "npm run dev") */
1115
+ start: string;
1114
1116
  /** Working directory (optional) */
1115
1117
  path?: string;
1116
1118
  /** Path to .env file relative to path (optional) */
@@ -1139,14 +1141,22 @@ interface ServerStartOptions {
1139
1141
  * // Start a basic server
1140
1142
  * const server = await sandbox.server.start({
1141
1143
  * slug: 'api',
1142
- * command: 'npm start',
1144
+ * start: 'npm start',
1145
+ * path: '/app',
1146
+ * });
1147
+ *
1148
+ * // Start with install command (runs before start)
1149
+ * const server = await sandbox.server.start({
1150
+ * slug: 'web',
1151
+ * install: 'npm install',
1152
+ * start: 'npm run dev',
1143
1153
  * path: '/app',
1144
1154
  * });
1145
1155
  *
1146
1156
  * // Start with supervisor settings (auto-restart on failure)
1147
1157
  * const server = await sandbox.server.start({
1148
1158
  * slug: 'web',
1149
- * command: 'node server.js',
1159
+ * start: 'node server.js',
1150
1160
  * path: '/app',
1151
1161
  * environment: { NODE_ENV: 'production', PORT: '3000' },
1152
1162
  * restart_policy: 'on-failure',
@@ -1167,6 +1177,24 @@ interface ServerStartOptions {
1167
1177
  * await sandbox.server.restart('api');
1168
1178
  * ```
1169
1179
  */
1180
+ /**
1181
+ * Options for retrieving server logs
1182
+ */
1183
+ interface ServerLogsOptions {
1184
+ /** Which output stream to return: 'stdout', 'stderr', or 'combined' (default) */
1185
+ stream?: ServerLogStream;
1186
+ }
1187
+ /**
1188
+ * Server logs info returned from the logs method
1189
+ */
1190
+ interface ServerLogsInfo {
1191
+ /** Server slug identifier */
1192
+ slug: string;
1193
+ /** Which stream was returned */
1194
+ stream: ServerLogStream;
1195
+ /** The captured logs */
1196
+ logs: string;
1197
+ }
1170
1198
  declare class Server {
1171
1199
  private startHandler;
1172
1200
  private listHandler;
@@ -1174,6 +1202,7 @@ declare class Server {
1174
1202
  private stopHandler;
1175
1203
  private restartHandler;
1176
1204
  private updateStatusHandler;
1205
+ private logsHandler;
1177
1206
  constructor(handlers: {
1178
1207
  start: (options: ServerStartOptions) => Promise<ServerResponse>;
1179
1208
  list: () => Promise<ServersListResponse>;
@@ -1181,10 +1210,15 @@ declare class Server {
1181
1210
  stop: (slug: string) => Promise<ServerStopResponse | void>;
1182
1211
  restart: (slug: string) => Promise<ServerResponse>;
1183
1212
  updateStatus: (slug: string, status: ServerStatus) => Promise<void>;
1213
+ logs: (slug: string, options?: ServerLogsOptions) => Promise<ServerLogsResponse>;
1184
1214
  });
1185
1215
  /**
1186
1216
  * Start a new managed server with optional supervisor settings
1187
1217
  *
1218
+ * **Install Phase:**
1219
+ * If `install` is provided, it runs blocking before `start` (e.g., "npm install").
1220
+ * The server status will be `installing` during this phase.
1221
+ *
1188
1222
  * **Restart Policies:**
1189
1223
  * - `never` (default): No automatic restart on exit
1190
1224
  * - `on-failure`: Restart only on non-zero exit code
@@ -1202,14 +1236,15 @@ declare class Server {
1202
1236
  * // Basic server
1203
1237
  * const server = await sandbox.server.start({
1204
1238
  * slug: 'web',
1205
- * command: 'npm run dev',
1239
+ * start: 'npm run dev',
1206
1240
  * path: '/app',
1207
1241
  * });
1208
1242
  *
1209
- * // With supervisor settings
1243
+ * // With install command
1210
1244
  * const server = await sandbox.server.start({
1211
1245
  * slug: 'api',
1212
- * command: 'node server.js',
1246
+ * install: 'npm install',
1247
+ * start: 'node server.js',
1213
1248
  * environment: { NODE_ENV: 'production' },
1214
1249
  * restart_policy: 'always',
1215
1250
  * max_restarts: 0, // unlimited
@@ -1245,6 +1280,26 @@ declare class Server {
1245
1280
  * @param status - New status
1246
1281
  */
1247
1282
  updateStatus(slug: string, status: ServerStatus): Promise<void>;
1283
+ /**
1284
+ * Retrieve captured output (logs) for a managed server
1285
+ * @param slug - The server slug
1286
+ * @param options - Options for log retrieval
1287
+ * @returns Server logs info
1288
+ *
1289
+ * @example
1290
+ * ```typescript
1291
+ * // Get combined logs (default)
1292
+ * const logs = await sandbox.server.logs('api');
1293
+ * console.log(logs.logs);
1294
+ *
1295
+ * // Get only stdout
1296
+ * const stdout = await sandbox.server.logs('api', { stream: 'stdout' });
1297
+ *
1298
+ * // Get only stderr
1299
+ * const stderr = await sandbox.server.logs('api', { stream: 'stderr' });
1300
+ * ```
1301
+ */
1302
+ logs(slug: string, options?: ServerLogsOptions): Promise<ServerLogsInfo>;
1248
1303
  }
1249
1304
 
1250
1305
  /**
@@ -1922,6 +1977,158 @@ declare class Child {
1922
1977
  }): Promise<void>;
1923
1978
  }
1924
1979
 
1980
+ /**
1981
+ * Overlay - Resource namespace for filesystem overlay operations
1982
+ *
1983
+ * Overlays enable instant sandbox setup from template directories by copying
1984
+ * files directly for isolation, with heavy directories copied in the background.
1985
+ */
1986
+ /**
1987
+ * Options for creating an overlay
1988
+ */
1989
+ interface CreateOverlayOptions {
1990
+ /** Absolute path to source directory (template) */
1991
+ source: string;
1992
+ /** Relative path in sandbox where overlay will be mounted */
1993
+ target: string;
1994
+ /** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
1995
+ ignore?: string[];
1996
+ }
1997
+ /**
1998
+ * Copy status for overlay background operations
1999
+ */
2000
+ type OverlayCopyStatus = 'pending' | 'in_progress' | 'complete' | 'failed';
2001
+ /**
2002
+ * Statistics about an overlay
2003
+ */
2004
+ interface OverlayStats {
2005
+ /** Number of copied files */
2006
+ copiedFiles: number;
2007
+ /** Number of copied directories (heavy dirs copied in background) */
2008
+ copiedDirs: number;
2009
+ /** Paths that were skipped (e.g., .git, ignored patterns) */
2010
+ skipped: string[];
2011
+ }
2012
+ /**
2013
+ * Overlay information (client-side normalized type)
2014
+ */
2015
+ interface OverlayInfo {
2016
+ /** Unique overlay identifier */
2017
+ id: string;
2018
+ /** Absolute path to source directory */
2019
+ source: string;
2020
+ /** Relative path in sandbox */
2021
+ target: string;
2022
+ /** When the overlay was created */
2023
+ createdAt: string;
2024
+ /** Statistics about the overlay */
2025
+ stats: OverlayStats;
2026
+ /** Copy status for background operations */
2027
+ copyStatus: OverlayCopyStatus;
2028
+ /** Error message if copy failed */
2029
+ copyError?: string;
2030
+ }
2031
+ /**
2032
+ * API response for overlay operations (snake_case from server)
2033
+ */
2034
+ interface OverlayResponse {
2035
+ id: string;
2036
+ source: string;
2037
+ target: string;
2038
+ created_at: string;
2039
+ stats: {
2040
+ copied_files: number;
2041
+ copied_dirs: number;
2042
+ skipped: string[];
2043
+ };
2044
+ copy_status: string;
2045
+ copy_error?: string;
2046
+ }
2047
+ /**
2048
+ * API response for listing overlays
2049
+ */
2050
+ interface OverlayListResponse {
2051
+ overlays: OverlayResponse[];
2052
+ }
2053
+ /**
2054
+ * Overlay resource namespace
2055
+ *
2056
+ * @example
2057
+ * ```typescript
2058
+ * // Create an overlay from a template directory
2059
+ * const overlay = await sandbox.filesystem.overlay.create({
2060
+ * source: '/templates/nextjs',
2061
+ * target: 'project',
2062
+ * });
2063
+ * console.log(overlay.copyStatus); // 'pending' | 'in_progress' | 'complete' | 'failed'
2064
+ *
2065
+ * // List all overlays
2066
+ * const overlays = await sandbox.filesystem.overlay.list();
2067
+ *
2068
+ * // Get a specific overlay (useful for polling copy status)
2069
+ * const overlay = await sandbox.filesystem.overlay.retrieve('overlay-id');
2070
+ * if (overlay.copyStatus === 'complete') {
2071
+ * console.log('Background copy finished!');
2072
+ * }
2073
+ *
2074
+ * // Delete an overlay
2075
+ * await sandbox.filesystem.overlay.destroy('overlay-id');
2076
+ * ```
2077
+ */
2078
+ declare class Overlay {
2079
+ private createHandler;
2080
+ private listHandler;
2081
+ private retrieveHandler;
2082
+ private destroyHandler;
2083
+ constructor(handlers: {
2084
+ create: (options: CreateOverlayOptions) => Promise<OverlayResponse>;
2085
+ list: () => Promise<OverlayListResponse>;
2086
+ retrieve: (id: string) => Promise<OverlayResponse>;
2087
+ destroy: (id: string) => Promise<void>;
2088
+ });
2089
+ /**
2090
+ * Create a new overlay from a template directory
2091
+ *
2092
+ * The overlay copies files from the source directory into the target path
2093
+ * for better isolation. Heavy directories (node_modules, .venv, etc.) are
2094
+ * copied in the background. Use the `ignore` option to exclude files/directories.
2095
+ *
2096
+ * @param options - Overlay creation options
2097
+ * @param options.source - Absolute path to source directory
2098
+ * @param options.target - Relative path in sandbox
2099
+ * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
2100
+ * @returns Overlay info with copy status
2101
+ */
2102
+ create(options: CreateOverlayOptions): Promise<OverlayInfo>;
2103
+ /**
2104
+ * List all overlays for the current sandbox
2105
+ * @returns Array of overlay info
2106
+ */
2107
+ list(): Promise<OverlayInfo[]>;
2108
+ /**
2109
+ * Retrieve a specific overlay by ID
2110
+ *
2111
+ * Useful for polling the copy status of an overlay.
2112
+ *
2113
+ * @param id - Overlay ID
2114
+ * @returns Overlay info
2115
+ */
2116
+ retrieve(id: string): Promise<OverlayInfo>;
2117
+ /**
2118
+ * Destroy (delete) an overlay
2119
+ * @param id - Overlay ID
2120
+ */
2121
+ destroy(id: string): Promise<void>;
2122
+ /**
2123
+ * Convert API response to OverlayInfo
2124
+ */
2125
+ private toOverlayInfo;
2126
+ /**
2127
+ * Validate and return copy status, defaulting to 'pending' for unknown values
2128
+ */
2129
+ private validateCopyStatus;
2130
+ }
2131
+
1925
2132
  /**
1926
2133
  * Binary WebSocket Protocol Implementation
1927
2134
  *
@@ -2030,6 +2237,14 @@ declare function isCommandExitError(error: unknown): error is CommandExitError;
2030
2237
  * Node.js: Pass WebSocket implementation (e.g., 'ws' library)
2031
2238
  */
2032
2239
 
2240
+ /**
2241
+ * Extended filesystem interface with overlay support
2242
+ */
2243
+ interface ExtendedFileSystem extends SandboxFileSystem {
2244
+ /** Overlay operations for template directories */
2245
+ readonly overlay: Overlay;
2246
+ }
2247
+
2033
2248
  /**
2034
2249
  * WebSocket constructor type
2035
2250
  */
@@ -2356,6 +2571,7 @@ interface TerminalResponse {
2356
2571
  /**
2357
2572
  * Server status types
2358
2573
  *
2574
+ * - `installing`: Running install command (e.g., npm install) before starting
2359
2575
  * - `starting`: Initial startup of the server process
2360
2576
  * - `running`: Server process is running
2361
2577
  * - `ready`: Server is running and ready to accept traffic
@@ -2363,7 +2579,7 @@ interface TerminalResponse {
2363
2579
  * - `stopped`: Server was intentionally stopped
2364
2580
  * - `restarting`: Server is being automatically restarted by the supervisor
2365
2581
  */
2366
- type ServerStatus = 'starting' | 'running' | 'ready' | 'failed' | 'stopped' | 'restarting';
2582
+ type ServerStatus = 'installing' | 'starting' | 'running' | 'ready' | 'failed' | 'stopped' | 'restarting';
2367
2583
  /**
2368
2584
  * Server restart policy
2369
2585
  * - `never`: No automatic restart (default)
@@ -2377,8 +2593,10 @@ type RestartPolicy = 'never' | 'on-failure' | 'always';
2377
2593
  interface ServerInfo {
2378
2594
  /** Unique server identifier */
2379
2595
  slug: string;
2596
+ /** Install command (optional, runs blocking before start) */
2597
+ install?: string;
2380
2598
  /** Command used to start the server */
2381
- command: string;
2599
+ start: string;
2382
2600
  /** Working directory path */
2383
2601
  path: string;
2384
2602
  /** Original path before resolution */
@@ -2442,6 +2660,22 @@ interface ServerStopResponse {
2442
2660
  slug: string;
2443
2661
  };
2444
2662
  }
2663
+ /**
2664
+ * Server logs stream type
2665
+ */
2666
+ type ServerLogStream = 'stdout' | 'stderr' | 'combined';
2667
+ /**
2668
+ * Server logs response
2669
+ */
2670
+ interface ServerLogsResponse {
2671
+ status: string;
2672
+ message: string;
2673
+ data: {
2674
+ slug: string;
2675
+ stream: ServerLogStream;
2676
+ logs: string;
2677
+ };
2678
+ }
2445
2679
  /**
2446
2680
  * Server status update response
2447
2681
  */
@@ -2593,7 +2827,7 @@ interface BatchWriteResponse {
2593
2827
  declare class Sandbox {
2594
2828
  readonly sandboxId: string;
2595
2829
  readonly provider: string;
2596
- readonly filesystem: SandboxFileSystem;
2830
+ readonly filesystem: ExtendedFileSystem;
2597
2831
  readonly terminal: Terminal;
2598
2832
  readonly run: Run;
2599
2833
  readonly server: Server;
@@ -2827,6 +3061,47 @@ declare class Sandbox {
2827
3061
  operation: 'write' | 'delete';
2828
3062
  content?: string;
2829
3063
  }>): Promise<BatchWriteResponse>;
3064
+ /**
3065
+ * Create a new filesystem overlay from a template directory
3066
+ *
3067
+ * Overlays enable instant sandbox setup by symlinking template files first,
3068
+ * then copying heavy directories (node_modules, .venv, etc.) in the background.
3069
+ *
3070
+ * @param options - Overlay creation options
3071
+ * @param options.source - Absolute path to source directory (template)
3072
+ * @param options.target - Relative path in sandbox where overlay will be mounted
3073
+ * @returns Overlay response with copy status
3074
+ *
3075
+ * @example
3076
+ * ```typescript
3077
+ * // Prefer using sandbox.filesystem.overlay.create() for camelCase response
3078
+ * const overlay = await sandbox.filesystem.overlay.create({
3079
+ * source: '/templates/nextjs',
3080
+ * target: 'project',
3081
+ * });
3082
+ * console.log(overlay.copyStatus); // 'pending' | 'in_progress' | 'complete' | 'failed'
3083
+ * ```
3084
+ */
3085
+ createOverlay(options: CreateOverlayOptions): Promise<OverlayResponse>;
3086
+ /**
3087
+ * List all filesystem overlays for the current sandbox
3088
+ * @returns List of overlays with their copy status
3089
+ */
3090
+ listOverlays(): Promise<OverlayListResponse>;
3091
+ /**
3092
+ * Get a specific filesystem overlay by ID
3093
+ *
3094
+ * Useful for polling the copy status of an overlay.
3095
+ *
3096
+ * @param id - Overlay ID
3097
+ * @returns Overlay details with current copy status
3098
+ */
3099
+ getOverlay(id: string): Promise<OverlayResponse>;
3100
+ /**
3101
+ * Delete a filesystem overlay
3102
+ * @param id - Overlay ID
3103
+ */
3104
+ deleteOverlay(id: string): Promise<void>;
2830
3105
  /**
2831
3106
  * Create a new persistent terminal session
2832
3107
  *
@@ -2978,7 +3253,8 @@ declare class Sandbox {
2978
3253
  *
2979
3254
  * @param options - Server configuration
2980
3255
  * @param options.slug - Unique server identifier
2981
- * @param options.command - Command to start the server
3256
+ * @param options.install - Install command (optional, runs blocking before start, e.g., "npm install")
3257
+ * @param options.start - Command to start the server (e.g., "npm run dev")
2982
3258
  * @param options.path - Working directory (optional)
2983
3259
  * @param options.env_file - Path to .env file relative to path (optional)
2984
3260
  * @param options.environment - Inline environment variables (merged with env_file if both provided)
@@ -2992,14 +3268,15 @@ declare class Sandbox {
2992
3268
  * // Basic server
2993
3269
  * await sandbox.startServer({
2994
3270
  * slug: 'web',
2995
- * command: 'npm run dev',
3271
+ * start: 'npm run dev',
2996
3272
  * path: '/app',
2997
3273
  * });
2998
3274
  *
2999
- * // With supervisor settings
3275
+ * // With install command and supervisor settings
3000
3276
  * await sandbox.startServer({
3001
3277
  * slug: 'api',
3002
- * command: 'node server.js',
3278
+ * install: 'npm install',
3279
+ * start: 'node server.js',
3003
3280
  * path: '/app',
3004
3281
  * environment: { NODE_ENV: 'production', PORT: '3000' },
3005
3282
  * restart_policy: 'on-failure',
@@ -3011,7 +3288,8 @@ declare class Sandbox {
3011
3288
  */
3012
3289
  startServer(options: {
3013
3290
  slug: string;
3014
- command: string;
3291
+ install?: string;
3292
+ start: string;
3015
3293
  path?: string;
3016
3294
  env_file?: string;
3017
3295
  environment?: Record<string, string>;
@@ -3035,6 +3313,14 @@ declare class Sandbox {
3035
3313
  * @param slug - Server slug
3036
3314
  */
3037
3315
  restartServer(slug: string): Promise<ServerResponse>;
3316
+ /**
3317
+ * Get logs for a managed server
3318
+ * @param slug - Server slug
3319
+ * @param options - Options for log retrieval
3320
+ */
3321
+ getServerLogs(slug: string, options?: {
3322
+ stream?: ServerLogStream;
3323
+ }): Promise<ServerLogsResponse>;
3038
3324
  /**
3039
3325
  * Update server status (internal use)
3040
3326
  * @param slug - Server slug