computesdk 2.1.1 → 2.1.2
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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +44 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3700,6 +3700,7 @@ declare class Sandbox {
|
|
|
3700
3700
|
* @param options.env - Environment variables (server uses cmd.Env)
|
|
3701
3701
|
* @param options.onStdout - Callback for streaming stdout data
|
|
3702
3702
|
* @param options.onStderr - Callback for streaming stderr data
|
|
3703
|
+
* @param options.timeout - Timeout in seconds (max 300 for long-running commands)
|
|
3703
3704
|
* @returns Command execution result
|
|
3704
3705
|
*
|
|
3705
3706
|
* @example
|
|
@@ -3721,6 +3722,9 @@ declare class Sandbox {
|
|
|
3721
3722
|
* onStdout: (data) => console.log(data),
|
|
3722
3723
|
* onStderr: (data) => console.error(data),
|
|
3723
3724
|
* })
|
|
3725
|
+
*
|
|
3726
|
+
* // With timeout for long-running commands
|
|
3727
|
+
* await sandbox.runCommand('npm install', { timeout: 120 })
|
|
3724
3728
|
* ```
|
|
3725
3729
|
*/
|
|
3726
3730
|
runCommand(command: string, options?: {
|
|
@@ -3729,6 +3733,8 @@ declare class Sandbox {
|
|
|
3729
3733
|
env?: Record<string, string>;
|
|
3730
3734
|
onStdout?: (data: string) => void;
|
|
3731
3735
|
onStderr?: (data: string) => void;
|
|
3736
|
+
/** Timeout in seconds (max 300 for long-running commands) */
|
|
3737
|
+
timeout?: number;
|
|
3732
3738
|
}): Promise<{
|
|
3733
3739
|
stdout: string;
|
|
3734
3740
|
stderr: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3700,6 +3700,7 @@ declare class Sandbox {
|
|
|
3700
3700
|
* @param options.env - Environment variables (server uses cmd.Env)
|
|
3701
3701
|
* @param options.onStdout - Callback for streaming stdout data
|
|
3702
3702
|
* @param options.onStderr - Callback for streaming stderr data
|
|
3703
|
+
* @param options.timeout - Timeout in seconds (max 300 for long-running commands)
|
|
3703
3704
|
* @returns Command execution result
|
|
3704
3705
|
*
|
|
3705
3706
|
* @example
|
|
@@ -3721,6 +3722,9 @@ declare class Sandbox {
|
|
|
3721
3722
|
* onStdout: (data) => console.log(data),
|
|
3722
3723
|
* onStderr: (data) => console.error(data),
|
|
3723
3724
|
* })
|
|
3725
|
+
*
|
|
3726
|
+
* // With timeout for long-running commands
|
|
3727
|
+
* await sandbox.runCommand('npm install', { timeout: 120 })
|
|
3724
3728
|
* ```
|
|
3725
3729
|
*/
|
|
3726
3730
|
runCommand(command: string, options?: {
|
|
@@ -3729,6 +3733,8 @@ declare class Sandbox {
|
|
|
3729
3733
|
env?: Record<string, string>;
|
|
3730
3734
|
onStdout?: (data: string) => void;
|
|
3731
3735
|
onStderr?: (data: string) => void;
|
|
3736
|
+
/** Timeout in seconds (max 300 for long-running commands) */
|
|
3737
|
+
timeout?: number;
|
|
3732
3738
|
}): Promise<{
|
|
3733
3739
|
stdout: string;
|
|
3734
3740
|
stderr: string;
|
package/dist/index.js
CHANGED
|
@@ -2364,7 +2364,9 @@ var Sandbox = class {
|
|
|
2364
2364
|
terminal.setWaitCommandHandler(async (cmdId, timeout) => {
|
|
2365
2365
|
const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
|
|
2366
2366
|
const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
|
|
2367
|
-
return this.request(endpoint
|
|
2367
|
+
return this.request(endpoint, {
|
|
2368
|
+
headers: timeout ? { "X-Request-Timeout": timeout.toString() } : void 0
|
|
2369
|
+
});
|
|
2368
2370
|
});
|
|
2369
2371
|
terminal.setDestroyHandler(async () => {
|
|
2370
2372
|
await this.request(`/terminals/${terminalId}`, {
|
|
@@ -2380,6 +2382,11 @@ var Sandbox = class {
|
|
|
2380
2382
|
async request(endpoint, options = {}) {
|
|
2381
2383
|
const controller = new AbortController();
|
|
2382
2384
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
2385
|
+
if (process.env.COMPUTESDK_DEBUG) {
|
|
2386
|
+
console.log(`[ComputeSDK] Request: ${options.method || "GET"} ${this.config.sandboxUrl}${endpoint}`);
|
|
2387
|
+
console.log(`[ComputeSDK] Sandbox ID: ${this.config.sandboxId}`);
|
|
2388
|
+
console.log(`[ComputeSDK] Token: ${this._token || "(no token)"}`);
|
|
2389
|
+
}
|
|
2383
2390
|
try {
|
|
2384
2391
|
const headers = {
|
|
2385
2392
|
...this.config.headers
|
|
@@ -2422,6 +2429,15 @@ API request failed (${response.status}): ${error}`
|
|
|
2422
2429
|
);
|
|
2423
2430
|
}
|
|
2424
2431
|
}
|
|
2432
|
+
if (response.status === 403 && process.env.COMPUTESDK_DEBUG) {
|
|
2433
|
+
console.error(`[ComputeSDK] 403 Forbidden Debug Info:`);
|
|
2434
|
+
console.error(` Endpoint: ${endpoint}`);
|
|
2435
|
+
console.error(` Method: ${options.method || "GET"}`);
|
|
2436
|
+
console.error(` Sandbox URL: ${this.config.sandboxUrl}`);
|
|
2437
|
+
console.error(` Sandbox ID: ${this.config.sandboxId}`);
|
|
2438
|
+
console.error(` Token: ${this._token || "(no token)"}`);
|
|
2439
|
+
console.error(` Error: ${error}`);
|
|
2440
|
+
}
|
|
2425
2441
|
throw new Error(`API request failed (${response.status}): ${error}`);
|
|
2426
2442
|
}
|
|
2427
2443
|
return data;
|
|
@@ -2941,7 +2957,9 @@ API request failed (${response.status}): ${error}`
|
|
|
2941
2957
|
async waitForCommand(terminalId, cmdId, timeout) {
|
|
2942
2958
|
const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
|
|
2943
2959
|
const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
|
|
2944
|
-
return this.request(endpoint
|
|
2960
|
+
return this.request(endpoint, {
|
|
2961
|
+
headers: timeout ? { "X-Request-Timeout": timeout.toString() } : void 0
|
|
2962
|
+
});
|
|
2945
2963
|
}
|
|
2946
2964
|
/**
|
|
2947
2965
|
* Wait for a background command to complete using long-polling
|
|
@@ -3392,6 +3410,7 @@ API request failed (${response.status}): ${error}`
|
|
|
3392
3410
|
* @param options.env - Environment variables (server uses cmd.Env)
|
|
3393
3411
|
* @param options.onStdout - Callback for streaming stdout data
|
|
3394
3412
|
* @param options.onStderr - Callback for streaming stderr data
|
|
3413
|
+
* @param options.timeout - Timeout in seconds (max 300 for long-running commands)
|
|
3395
3414
|
* @returns Command execution result
|
|
3396
3415
|
*
|
|
3397
3416
|
* @example
|
|
@@ -3413,11 +3432,21 @@ API request failed (${response.status}): ${error}`
|
|
|
3413
3432
|
* onStdout: (data) => console.log(data),
|
|
3414
3433
|
* onStderr: (data) => console.error(data),
|
|
3415
3434
|
* })
|
|
3435
|
+
*
|
|
3436
|
+
* // With timeout for long-running commands
|
|
3437
|
+
* await sandbox.runCommand('npm install', { timeout: 120 })
|
|
3416
3438
|
* ```
|
|
3417
3439
|
*/
|
|
3418
3440
|
async runCommand(command, options) {
|
|
3419
3441
|
const hasStreamingCallbacks = options?.onStdout || options?.onStderr;
|
|
3420
3442
|
if (!hasStreamingCallbacks) {
|
|
3443
|
+
if (options?.timeout && !options?.background) {
|
|
3444
|
+
return this.run.command(command, {
|
|
3445
|
+
...options,
|
|
3446
|
+
background: true,
|
|
3447
|
+
waitForCompletion: { timeoutSeconds: options.timeout }
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3421
3450
|
return this.run.command(command, options);
|
|
3422
3451
|
}
|
|
3423
3452
|
const ws = await this.ensureWebSocket();
|
|
@@ -3475,9 +3504,20 @@ API request failed (${response.status}): ${error}`
|
|
|
3475
3504
|
durationMs: 0
|
|
3476
3505
|
};
|
|
3477
3506
|
}
|
|
3478
|
-
|
|
3507
|
+
const commandPromise = new Promise((resolve) => {
|
|
3479
3508
|
resolvePromise = resolve;
|
|
3480
3509
|
});
|
|
3510
|
+
if (options?.timeout) {
|
|
3511
|
+
const timeoutMs = options.timeout * 1e3;
|
|
3512
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
3513
|
+
setTimeout(() => {
|
|
3514
|
+
cleanup();
|
|
3515
|
+
reject(new Error(`Command timed out after ${options.timeout} seconds`));
|
|
3516
|
+
}, timeoutMs);
|
|
3517
|
+
});
|
|
3518
|
+
return Promise.race([commandPromise, timeoutPromise]);
|
|
3519
|
+
}
|
|
3520
|
+
return commandPromise;
|
|
3481
3521
|
}
|
|
3482
3522
|
/**
|
|
3483
3523
|
* Get server information
|
|
@@ -4079,7 +4119,7 @@ Get your API key at: https://computesdk.com/dashboard`
|
|
|
4079
4119
|
const providerHeaders = buildProviderHeaders2(config);
|
|
4080
4120
|
return {
|
|
4081
4121
|
apiKey: computesdkApiKey,
|
|
4082
|
-
gatewayUrl: config.gatewayUrl || GATEWAY_URL,
|
|
4122
|
+
gatewayUrl: config.gatewayUrl || process.env.COMPUTESDK_GATEWAY_URL || GATEWAY_URL,
|
|
4083
4123
|
provider: config.provider,
|
|
4084
4124
|
providerHeaders,
|
|
4085
4125
|
requestTimeoutMs: config.requestTimeoutMs,
|