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 +301 -15
- package/dist/index.d.ts +301 -15
- package/dist/index.js +204 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1335,10 +1335,15 @@ var Server = class {
|
|
|
1335
1335
|
this.stopHandler = handlers.stop;
|
|
1336
1336
|
this.restartHandler = handlers.restart;
|
|
1337
1337
|
this.updateStatusHandler = handlers.updateStatus;
|
|
1338
|
+
this.logsHandler = handlers.logs;
|
|
1338
1339
|
}
|
|
1339
1340
|
/**
|
|
1340
1341
|
* Start a new managed server with optional supervisor settings
|
|
1341
1342
|
*
|
|
1343
|
+
* **Install Phase:**
|
|
1344
|
+
* If `install` is provided, it runs blocking before `start` (e.g., "npm install").
|
|
1345
|
+
* The server status will be `installing` during this phase.
|
|
1346
|
+
*
|
|
1342
1347
|
* **Restart Policies:**
|
|
1343
1348
|
* - `never` (default): No automatic restart on exit
|
|
1344
1349
|
* - `on-failure`: Restart only on non-zero exit code
|
|
@@ -1356,14 +1361,15 @@ var Server = class {
|
|
|
1356
1361
|
* // Basic server
|
|
1357
1362
|
* const server = await sandbox.server.start({
|
|
1358
1363
|
* slug: 'web',
|
|
1359
|
-
*
|
|
1364
|
+
* start: 'npm run dev',
|
|
1360
1365
|
* path: '/app',
|
|
1361
1366
|
* });
|
|
1362
1367
|
*
|
|
1363
|
-
* // With
|
|
1368
|
+
* // With install command
|
|
1364
1369
|
* const server = await sandbox.server.start({
|
|
1365
1370
|
* slug: 'api',
|
|
1366
|
-
*
|
|
1371
|
+
* install: 'npm install',
|
|
1372
|
+
* start: 'node server.js',
|
|
1367
1373
|
* environment: { NODE_ENV: 'production' },
|
|
1368
1374
|
* restart_policy: 'always',
|
|
1369
1375
|
* max_restarts: 0, // unlimited
|
|
@@ -1415,6 +1421,29 @@ var Server = class {
|
|
|
1415
1421
|
async updateStatus(slug, status) {
|
|
1416
1422
|
await this.updateStatusHandler(slug, status);
|
|
1417
1423
|
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Retrieve captured output (logs) for a managed server
|
|
1426
|
+
* @param slug - The server slug
|
|
1427
|
+
* @param options - Options for log retrieval
|
|
1428
|
+
* @returns Server logs info
|
|
1429
|
+
*
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```typescript
|
|
1432
|
+
* // Get combined logs (default)
|
|
1433
|
+
* const logs = await sandbox.server.logs('api');
|
|
1434
|
+
* console.log(logs.logs);
|
|
1435
|
+
*
|
|
1436
|
+
* // Get only stdout
|
|
1437
|
+
* const stdout = await sandbox.server.logs('api', { stream: 'stdout' });
|
|
1438
|
+
*
|
|
1439
|
+
* // Get only stderr
|
|
1440
|
+
* const stderr = await sandbox.server.logs('api', { stream: 'stderr' });
|
|
1441
|
+
* ```
|
|
1442
|
+
*/
|
|
1443
|
+
async logs(slug, options) {
|
|
1444
|
+
const response = await this.logsHandler(slug, options);
|
|
1445
|
+
return response.data;
|
|
1446
|
+
}
|
|
1418
1447
|
};
|
|
1419
1448
|
|
|
1420
1449
|
// src/client/resources/watcher.ts
|
|
@@ -1845,6 +1874,88 @@ var Child = class {
|
|
|
1845
1874
|
}
|
|
1846
1875
|
};
|
|
1847
1876
|
|
|
1877
|
+
// src/client/resources/overlay.ts
|
|
1878
|
+
var Overlay = class {
|
|
1879
|
+
constructor(handlers) {
|
|
1880
|
+
this.createHandler = handlers.create;
|
|
1881
|
+
this.listHandler = handlers.list;
|
|
1882
|
+
this.retrieveHandler = handlers.retrieve;
|
|
1883
|
+
this.destroyHandler = handlers.destroy;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Create a new overlay from a template directory
|
|
1887
|
+
*
|
|
1888
|
+
* The overlay copies files from the source directory into the target path
|
|
1889
|
+
* for better isolation. Heavy directories (node_modules, .venv, etc.) are
|
|
1890
|
+
* copied in the background. Use the `ignore` option to exclude files/directories.
|
|
1891
|
+
*
|
|
1892
|
+
* @param options - Overlay creation options
|
|
1893
|
+
* @param options.source - Absolute path to source directory
|
|
1894
|
+
* @param options.target - Relative path in sandbox
|
|
1895
|
+
* @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
|
|
1896
|
+
* @returns Overlay info with copy status
|
|
1897
|
+
*/
|
|
1898
|
+
async create(options) {
|
|
1899
|
+
const response = await this.createHandler(options);
|
|
1900
|
+
return this.toOverlayInfo(response);
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* List all overlays for the current sandbox
|
|
1904
|
+
* @returns Array of overlay info
|
|
1905
|
+
*/
|
|
1906
|
+
async list() {
|
|
1907
|
+
const response = await this.listHandler();
|
|
1908
|
+
return response.overlays.map((o) => this.toOverlayInfo(o));
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Retrieve a specific overlay by ID
|
|
1912
|
+
*
|
|
1913
|
+
* Useful for polling the copy status of an overlay.
|
|
1914
|
+
*
|
|
1915
|
+
* @param id - Overlay ID
|
|
1916
|
+
* @returns Overlay info
|
|
1917
|
+
*/
|
|
1918
|
+
async retrieve(id) {
|
|
1919
|
+
const response = await this.retrieveHandler(id);
|
|
1920
|
+
return this.toOverlayInfo(response);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Destroy (delete) an overlay
|
|
1924
|
+
* @param id - Overlay ID
|
|
1925
|
+
*/
|
|
1926
|
+
async destroy(id) {
|
|
1927
|
+
return this.destroyHandler(id);
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Convert API response to OverlayInfo
|
|
1931
|
+
*/
|
|
1932
|
+
toOverlayInfo(response) {
|
|
1933
|
+
return {
|
|
1934
|
+
id: response.id,
|
|
1935
|
+
source: response.source,
|
|
1936
|
+
target: response.target,
|
|
1937
|
+
createdAt: response.created_at,
|
|
1938
|
+
stats: {
|
|
1939
|
+
copiedFiles: response.stats.copied_files,
|
|
1940
|
+
copiedDirs: response.stats.copied_dirs,
|
|
1941
|
+
skipped: response.stats.skipped
|
|
1942
|
+
},
|
|
1943
|
+
copyStatus: this.validateCopyStatus(response.copy_status),
|
|
1944
|
+
copyError: response.copy_error
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Validate and return copy status, defaulting to 'pending' for unknown values
|
|
1949
|
+
*/
|
|
1950
|
+
validateCopyStatus(status) {
|
|
1951
|
+
const validStatuses = ["pending", "in_progress", "complete", "failed"];
|
|
1952
|
+
if (validStatuses.includes(status)) {
|
|
1953
|
+
return status;
|
|
1954
|
+
}
|
|
1955
|
+
return "pending";
|
|
1956
|
+
}
|
|
1957
|
+
};
|
|
1958
|
+
|
|
1848
1959
|
// src/client/types.ts
|
|
1849
1960
|
var CommandExitError = class extends Error {
|
|
1850
1961
|
constructor(result) {
|
|
@@ -1939,7 +2050,13 @@ var Sandbox = class {
|
|
|
1939
2050
|
},
|
|
1940
2051
|
remove: async (path) => {
|
|
1941
2052
|
await this.deleteFile(path);
|
|
1942
|
-
}
|
|
2053
|
+
},
|
|
2054
|
+
overlay: new Overlay({
|
|
2055
|
+
create: async (options) => this.createOverlay(options),
|
|
2056
|
+
list: async () => this.listOverlays(),
|
|
2057
|
+
retrieve: async (id) => this.getOverlay(id),
|
|
2058
|
+
destroy: async (id) => this.deleteOverlay(id)
|
|
2059
|
+
})
|
|
1943
2060
|
};
|
|
1944
2061
|
this.terminal = new Terminal({
|
|
1945
2062
|
create: async (options) => this.createTerminal(options),
|
|
@@ -1984,7 +2101,8 @@ var Sandbox = class {
|
|
|
1984
2101
|
restart: async (slug) => this.restartServer(slug),
|
|
1985
2102
|
updateStatus: async (slug, status) => {
|
|
1986
2103
|
await this.updateServerStatus(slug, status);
|
|
1987
|
-
}
|
|
2104
|
+
},
|
|
2105
|
+
logs: async (slug, options) => this.getServerLogs(slug, options)
|
|
1988
2106
|
});
|
|
1989
2107
|
this.watcher = new Watcher({
|
|
1990
2108
|
create: async (path, options) => this.createWatcher(path, options),
|
|
@@ -2424,6 +2542,63 @@ API request failed (${response.status}): ${error}`
|
|
|
2424
2542
|
});
|
|
2425
2543
|
}
|
|
2426
2544
|
// ============================================================================
|
|
2545
|
+
// Filesystem Overlays
|
|
2546
|
+
// ============================================================================
|
|
2547
|
+
/**
|
|
2548
|
+
* Create a new filesystem overlay from a template directory
|
|
2549
|
+
*
|
|
2550
|
+
* Overlays enable instant sandbox setup by symlinking template files first,
|
|
2551
|
+
* then copying heavy directories (node_modules, .venv, etc.) in the background.
|
|
2552
|
+
*
|
|
2553
|
+
* @param options - Overlay creation options
|
|
2554
|
+
* @param options.source - Absolute path to source directory (template)
|
|
2555
|
+
* @param options.target - Relative path in sandbox where overlay will be mounted
|
|
2556
|
+
* @returns Overlay response with copy status
|
|
2557
|
+
*
|
|
2558
|
+
* @example
|
|
2559
|
+
* ```typescript
|
|
2560
|
+
* // Prefer using sandbox.filesystem.overlay.create() for camelCase response
|
|
2561
|
+
* const overlay = await sandbox.filesystem.overlay.create({
|
|
2562
|
+
* source: '/templates/nextjs',
|
|
2563
|
+
* target: 'project',
|
|
2564
|
+
* });
|
|
2565
|
+
* console.log(overlay.copyStatus); // 'pending' | 'in_progress' | 'complete' | 'failed'
|
|
2566
|
+
* ```
|
|
2567
|
+
*/
|
|
2568
|
+
async createOverlay(options) {
|
|
2569
|
+
return this.request("/filesystem/overlays", {
|
|
2570
|
+
method: "POST",
|
|
2571
|
+
body: JSON.stringify(options)
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
/**
|
|
2575
|
+
* List all filesystem overlays for the current sandbox
|
|
2576
|
+
* @returns List of overlays with their copy status
|
|
2577
|
+
*/
|
|
2578
|
+
async listOverlays() {
|
|
2579
|
+
return this.request("/filesystem/overlays");
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* Get a specific filesystem overlay by ID
|
|
2583
|
+
*
|
|
2584
|
+
* Useful for polling the copy status of an overlay.
|
|
2585
|
+
*
|
|
2586
|
+
* @param id - Overlay ID
|
|
2587
|
+
* @returns Overlay details with current copy status
|
|
2588
|
+
*/
|
|
2589
|
+
async getOverlay(id) {
|
|
2590
|
+
return this.request(`/filesystem/overlays/${id}`);
|
|
2591
|
+
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Delete a filesystem overlay
|
|
2594
|
+
* @param id - Overlay ID
|
|
2595
|
+
*/
|
|
2596
|
+
async deleteOverlay(id) {
|
|
2597
|
+
return this.request(`/filesystem/overlays/${id}`, {
|
|
2598
|
+
method: "DELETE"
|
|
2599
|
+
});
|
|
2600
|
+
}
|
|
2601
|
+
// ============================================================================
|
|
2427
2602
|
// Terminal Management
|
|
2428
2603
|
// ============================================================================
|
|
2429
2604
|
/**
|
|
@@ -2772,7 +2947,8 @@ API request failed (${response.status}): ${error}`
|
|
|
2772
2947
|
*
|
|
2773
2948
|
* @param options - Server configuration
|
|
2774
2949
|
* @param options.slug - Unique server identifier
|
|
2775
|
-
* @param options.
|
|
2950
|
+
* @param options.install - Install command (optional, runs blocking before start, e.g., "npm install")
|
|
2951
|
+
* @param options.start - Command to start the server (e.g., "npm run dev")
|
|
2776
2952
|
* @param options.path - Working directory (optional)
|
|
2777
2953
|
* @param options.env_file - Path to .env file relative to path (optional)
|
|
2778
2954
|
* @param options.environment - Inline environment variables (merged with env_file if both provided)
|
|
@@ -2786,14 +2962,15 @@ API request failed (${response.status}): ${error}`
|
|
|
2786
2962
|
* // Basic server
|
|
2787
2963
|
* await sandbox.startServer({
|
|
2788
2964
|
* slug: 'web',
|
|
2789
|
-
*
|
|
2965
|
+
* start: 'npm run dev',
|
|
2790
2966
|
* path: '/app',
|
|
2791
2967
|
* });
|
|
2792
2968
|
*
|
|
2793
|
-
* // With supervisor settings
|
|
2969
|
+
* // With install command and supervisor settings
|
|
2794
2970
|
* await sandbox.startServer({
|
|
2795
2971
|
* slug: 'api',
|
|
2796
|
-
*
|
|
2972
|
+
* install: 'npm install',
|
|
2973
|
+
* start: 'node server.js',
|
|
2797
2974
|
* path: '/app',
|
|
2798
2975
|
* environment: { NODE_ENV: 'production', PORT: '3000' },
|
|
2799
2976
|
* restart_policy: 'on-failure',
|
|
@@ -2840,6 +3017,21 @@ API request failed (${response.status}): ${error}`
|
|
|
2840
3017
|
}
|
|
2841
3018
|
);
|
|
2842
3019
|
}
|
|
3020
|
+
/**
|
|
3021
|
+
* Get logs for a managed server
|
|
3022
|
+
* @param slug - Server slug
|
|
3023
|
+
* @param options - Options for log retrieval
|
|
3024
|
+
*/
|
|
3025
|
+
async getServerLogs(slug, options) {
|
|
3026
|
+
const params = new URLSearchParams();
|
|
3027
|
+
if (options?.stream) {
|
|
3028
|
+
params.set("stream", options.stream);
|
|
3029
|
+
}
|
|
3030
|
+
const queryString = params.toString();
|
|
3031
|
+
return this.request(
|
|
3032
|
+
`/servers/${encodeURIComponent(slug)}/logs${queryString ? `?${queryString}` : ""}`
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
2843
3035
|
/**
|
|
2844
3036
|
* Update server status (internal use)
|
|
2845
3037
|
* @param slug - Server slug
|
|
@@ -3121,7 +3313,9 @@ var PROVIDER_HEADERS = {
|
|
|
3121
3313
|
tokenSecret: "X-Modal-Token-Secret"
|
|
3122
3314
|
},
|
|
3123
3315
|
railway: {
|
|
3124
|
-
apiToken: "X-Railway-API-
|
|
3316
|
+
apiToken: "X-Railway-API-Key",
|
|
3317
|
+
projectId: "X-Railway-Project-ID",
|
|
3318
|
+
environmentId: "X-Railway-Environment-ID"
|
|
3125
3319
|
},
|
|
3126
3320
|
daytona: {
|
|
3127
3321
|
apiKey: "X-Daytona-API-Key"
|