computesdk 1.18.0 → 1.18.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 +33 -5
- package/dist/index.d.ts +33 -5
- package/dist/index.js +87 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1064,7 +1064,7 @@ declare class Terminal {
|
|
|
1064
1064
|
pty?: boolean;
|
|
1065
1065
|
}) => Promise<TerminalInstance>;
|
|
1066
1066
|
list: () => Promise<TerminalResponse[]>;
|
|
1067
|
-
retrieve: (id: string) => Promise<
|
|
1067
|
+
retrieve: (id: string) => Promise<TerminalInstance>;
|
|
1068
1068
|
destroy: (id: string) => Promise<void>;
|
|
1069
1069
|
});
|
|
1070
1070
|
/**
|
|
@@ -1089,9 +1089,9 @@ declare class Terminal {
|
|
|
1089
1089
|
/**
|
|
1090
1090
|
* Retrieve a specific terminal by ID
|
|
1091
1091
|
* @param id - The terminal ID
|
|
1092
|
-
* @returns Terminal
|
|
1092
|
+
* @returns Terminal instance
|
|
1093
1093
|
*/
|
|
1094
|
-
retrieve(id: string): Promise<
|
|
1094
|
+
retrieve(id: string): Promise<TerminalInstance>;
|
|
1095
1095
|
/**
|
|
1096
1096
|
* Destroy a terminal by ID
|
|
1097
1097
|
* @param id - The terminal ID
|
|
@@ -2040,6 +2040,12 @@ interface WaitForCompletionOptions {
|
|
|
2040
2040
|
/** Backoff multiplier for exponential backoff (default: 1.5) */
|
|
2041
2041
|
backoffFactor?: number;
|
|
2042
2042
|
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Strategy for creating an overlay
|
|
2045
|
+
* - 'copy': Full copy of all files (standard behavior)
|
|
2046
|
+
* - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
|
|
2047
|
+
*/
|
|
2048
|
+
type OverlayStrategy = 'copy' | 'smart';
|
|
2043
2049
|
/**
|
|
2044
2050
|
* Options for creating an overlay
|
|
2045
2051
|
*/
|
|
@@ -2050,6 +2056,8 @@ interface CreateOverlayOptions {
|
|
|
2050
2056
|
target: string;
|
|
2051
2057
|
/** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
|
|
2052
2058
|
ignore?: string[];
|
|
2059
|
+
/** Strategy to use (default: 'smart') */
|
|
2060
|
+
strategy?: OverlayStrategy;
|
|
2053
2061
|
/** If true, wait for background copy to complete before returning (default: false) */
|
|
2054
2062
|
waitForCompletion?: boolean | WaitForCompletionOptions;
|
|
2055
2063
|
}
|
|
@@ -2078,6 +2086,8 @@ interface OverlayInfo {
|
|
|
2078
2086
|
source: string;
|
|
2079
2087
|
/** Relative path in sandbox */
|
|
2080
2088
|
target: string;
|
|
2089
|
+
/** Strategy used for the overlay */
|
|
2090
|
+
strategy: OverlayStrategy;
|
|
2081
2091
|
/** When the overlay was created */
|
|
2082
2092
|
createdAt: string;
|
|
2083
2093
|
/** Statistics about the overlay */
|
|
@@ -2094,6 +2104,7 @@ interface OverlayResponse {
|
|
|
2094
2104
|
id: string;
|
|
2095
2105
|
source: string;
|
|
2096
2106
|
target: string;
|
|
2107
|
+
strategy?: string;
|
|
2097
2108
|
created_at: string;
|
|
2098
2109
|
stats: {
|
|
2099
2110
|
copied_files: number;
|
|
@@ -2166,6 +2177,7 @@ declare class Overlay {
|
|
|
2166
2177
|
* @param options.source - Absolute path to source directory
|
|
2167
2178
|
* @param options.target - Relative path in sandbox
|
|
2168
2179
|
* @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
|
|
2180
|
+
* @param options.strategy - Strategy to use ('copy' or 'smart')
|
|
2169
2181
|
* @param options.waitForCompletion - If true or options object, wait for background copy to complete
|
|
2170
2182
|
* @returns Overlay info with copy status
|
|
2171
2183
|
*/
|
|
@@ -2205,6 +2217,10 @@ declare class Overlay {
|
|
|
2205
2217
|
* Convert API response to OverlayInfo
|
|
2206
2218
|
*/
|
|
2207
2219
|
private toOverlayInfo;
|
|
2220
|
+
/**
|
|
2221
|
+
* Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
|
|
2222
|
+
*/
|
|
2223
|
+
private validateStrategy;
|
|
2208
2224
|
/**
|
|
2209
2225
|
* Validate and return copy status, defaulting to 'pending' for unknown values
|
|
2210
2226
|
*/
|
|
@@ -2925,11 +2941,16 @@ declare class Sandbox {
|
|
|
2925
2941
|
private _token;
|
|
2926
2942
|
private _ws;
|
|
2927
2943
|
private WebSocketImpl;
|
|
2944
|
+
private _terminals;
|
|
2928
2945
|
constructor(config: SandboxConfig);
|
|
2929
2946
|
/**
|
|
2930
2947
|
* Get or create internal WebSocket manager
|
|
2931
2948
|
*/
|
|
2932
2949
|
private ensureWebSocket;
|
|
2950
|
+
/**
|
|
2951
|
+
* Create and configure a TerminalInstance from response data
|
|
2952
|
+
*/
|
|
2953
|
+
private hydrateTerminal;
|
|
2933
2954
|
private request;
|
|
2934
2955
|
/**
|
|
2935
2956
|
* Check service health
|
|
@@ -3231,7 +3252,7 @@ declare class Sandbox {
|
|
|
3231
3252
|
/**
|
|
3232
3253
|
* Get terminal by ID
|
|
3233
3254
|
*/
|
|
3234
|
-
getTerminal(id: string): Promise<
|
|
3255
|
+
getTerminal(id: string): Promise<TerminalInstance>;
|
|
3235
3256
|
/**
|
|
3236
3257
|
* List all commands executed in a terminal (exec mode only)
|
|
3237
3258
|
* @param terminalId - The terminal ID
|
|
@@ -3590,6 +3611,7 @@ declare const PROVIDER_AUTH: {
|
|
|
3590
3611
|
readonly cloudflare: readonly [readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]];
|
|
3591
3612
|
readonly codesandbox: readonly [readonly ["CSB_API_KEY"]];
|
|
3592
3613
|
readonly blaxel: readonly [readonly ["BL_API_KEY", "BL_WORKSPACE"]];
|
|
3614
|
+
readonly namespace: readonly [readonly ["NSC_TOKEN"]];
|
|
3593
3615
|
};
|
|
3594
3616
|
/**
|
|
3595
3617
|
* All supported provider names (excluding gateway which is special)
|
|
@@ -3705,6 +3727,9 @@ interface ExplicitComputeConfig {
|
|
|
3705
3727
|
apiKey?: string;
|
|
3706
3728
|
workspace?: string;
|
|
3707
3729
|
};
|
|
3730
|
+
namespace?: {
|
|
3731
|
+
token?: string;
|
|
3732
|
+
};
|
|
3708
3733
|
}
|
|
3709
3734
|
/**
|
|
3710
3735
|
* Options for creating a sandbox via the gateway
|
|
@@ -3721,6 +3746,8 @@ interface CreateSandboxOptions {
|
|
|
3721
3746
|
namespace?: string;
|
|
3722
3747
|
/** Docker image to use for the sandbox (for infrastructure providers like Railway) */
|
|
3723
3748
|
image?: string;
|
|
3749
|
+
/** Provider-specific snapshot to create from (e.g., Vercel snapshots) */
|
|
3750
|
+
snapshotId?: string;
|
|
3724
3751
|
}
|
|
3725
3752
|
/**
|
|
3726
3753
|
* Options for finding or creating a named sandbox
|
|
@@ -3896,7 +3923,7 @@ declare const GATEWAY_URL = "https://gateway.computesdk.com";
|
|
|
3896
3923
|
* Provider detection priority order
|
|
3897
3924
|
* When multiple provider credentials are detected, use the first one in this list
|
|
3898
3925
|
*/
|
|
3899
|
-
declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel"];
|
|
3926
|
+
declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel", "namespace"];
|
|
3900
3927
|
/**
|
|
3901
3928
|
* Required environment variables for each provider
|
|
3902
3929
|
* @deprecated Use PROVIDER_AUTH from provider-config instead
|
|
@@ -3912,6 +3939,7 @@ declare const PROVIDER_ENV_VARS: {
|
|
|
3912
3939
|
readonly cloudflare: readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"];
|
|
3913
3940
|
readonly codesandbox: readonly ["CSB_API_KEY"];
|
|
3914
3941
|
readonly blaxel: readonly ["BL_API_KEY", "BL_WORKSPACE"];
|
|
3942
|
+
readonly namespace: readonly ["NSC_TOKEN"];
|
|
3915
3943
|
};
|
|
3916
3944
|
|
|
3917
3945
|
export { type CallableCompute, type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, type ExplicitComputeConfig, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, MessageType, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type ProviderName, type ProviderSandboxInfo, type RunCommandOptions, type Runtime, Sandbox, type SandboxFileSystem, type SandboxInfo$1 as SandboxInfo, type Sandbox$1 as SandboxInterface, type SandboxStatus, SignalService, TerminalInstance, type WebSocketConstructor, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1064,7 +1064,7 @@ declare class Terminal {
|
|
|
1064
1064
|
pty?: boolean;
|
|
1065
1065
|
}) => Promise<TerminalInstance>;
|
|
1066
1066
|
list: () => Promise<TerminalResponse[]>;
|
|
1067
|
-
retrieve: (id: string) => Promise<
|
|
1067
|
+
retrieve: (id: string) => Promise<TerminalInstance>;
|
|
1068
1068
|
destroy: (id: string) => Promise<void>;
|
|
1069
1069
|
});
|
|
1070
1070
|
/**
|
|
@@ -1089,9 +1089,9 @@ declare class Terminal {
|
|
|
1089
1089
|
/**
|
|
1090
1090
|
* Retrieve a specific terminal by ID
|
|
1091
1091
|
* @param id - The terminal ID
|
|
1092
|
-
* @returns Terminal
|
|
1092
|
+
* @returns Terminal instance
|
|
1093
1093
|
*/
|
|
1094
|
-
retrieve(id: string): Promise<
|
|
1094
|
+
retrieve(id: string): Promise<TerminalInstance>;
|
|
1095
1095
|
/**
|
|
1096
1096
|
* Destroy a terminal by ID
|
|
1097
1097
|
* @param id - The terminal ID
|
|
@@ -2040,6 +2040,12 @@ interface WaitForCompletionOptions {
|
|
|
2040
2040
|
/** Backoff multiplier for exponential backoff (default: 1.5) */
|
|
2041
2041
|
backoffFactor?: number;
|
|
2042
2042
|
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Strategy for creating an overlay
|
|
2045
|
+
* - 'copy': Full copy of all files (standard behavior)
|
|
2046
|
+
* - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
|
|
2047
|
+
*/
|
|
2048
|
+
type OverlayStrategy = 'copy' | 'smart';
|
|
2043
2049
|
/**
|
|
2044
2050
|
* Options for creating an overlay
|
|
2045
2051
|
*/
|
|
@@ -2050,6 +2056,8 @@ interface CreateOverlayOptions {
|
|
|
2050
2056
|
target: string;
|
|
2051
2057
|
/** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
|
|
2052
2058
|
ignore?: string[];
|
|
2059
|
+
/** Strategy to use (default: 'smart') */
|
|
2060
|
+
strategy?: OverlayStrategy;
|
|
2053
2061
|
/** If true, wait for background copy to complete before returning (default: false) */
|
|
2054
2062
|
waitForCompletion?: boolean | WaitForCompletionOptions;
|
|
2055
2063
|
}
|
|
@@ -2078,6 +2086,8 @@ interface OverlayInfo {
|
|
|
2078
2086
|
source: string;
|
|
2079
2087
|
/** Relative path in sandbox */
|
|
2080
2088
|
target: string;
|
|
2089
|
+
/** Strategy used for the overlay */
|
|
2090
|
+
strategy: OverlayStrategy;
|
|
2081
2091
|
/** When the overlay was created */
|
|
2082
2092
|
createdAt: string;
|
|
2083
2093
|
/** Statistics about the overlay */
|
|
@@ -2094,6 +2104,7 @@ interface OverlayResponse {
|
|
|
2094
2104
|
id: string;
|
|
2095
2105
|
source: string;
|
|
2096
2106
|
target: string;
|
|
2107
|
+
strategy?: string;
|
|
2097
2108
|
created_at: string;
|
|
2098
2109
|
stats: {
|
|
2099
2110
|
copied_files: number;
|
|
@@ -2166,6 +2177,7 @@ declare class Overlay {
|
|
|
2166
2177
|
* @param options.source - Absolute path to source directory
|
|
2167
2178
|
* @param options.target - Relative path in sandbox
|
|
2168
2179
|
* @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
|
|
2180
|
+
* @param options.strategy - Strategy to use ('copy' or 'smart')
|
|
2169
2181
|
* @param options.waitForCompletion - If true or options object, wait for background copy to complete
|
|
2170
2182
|
* @returns Overlay info with copy status
|
|
2171
2183
|
*/
|
|
@@ -2205,6 +2217,10 @@ declare class Overlay {
|
|
|
2205
2217
|
* Convert API response to OverlayInfo
|
|
2206
2218
|
*/
|
|
2207
2219
|
private toOverlayInfo;
|
|
2220
|
+
/**
|
|
2221
|
+
* Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
|
|
2222
|
+
*/
|
|
2223
|
+
private validateStrategy;
|
|
2208
2224
|
/**
|
|
2209
2225
|
* Validate and return copy status, defaulting to 'pending' for unknown values
|
|
2210
2226
|
*/
|
|
@@ -2925,11 +2941,16 @@ declare class Sandbox {
|
|
|
2925
2941
|
private _token;
|
|
2926
2942
|
private _ws;
|
|
2927
2943
|
private WebSocketImpl;
|
|
2944
|
+
private _terminals;
|
|
2928
2945
|
constructor(config: SandboxConfig);
|
|
2929
2946
|
/**
|
|
2930
2947
|
* Get or create internal WebSocket manager
|
|
2931
2948
|
*/
|
|
2932
2949
|
private ensureWebSocket;
|
|
2950
|
+
/**
|
|
2951
|
+
* Create and configure a TerminalInstance from response data
|
|
2952
|
+
*/
|
|
2953
|
+
private hydrateTerminal;
|
|
2933
2954
|
private request;
|
|
2934
2955
|
/**
|
|
2935
2956
|
* Check service health
|
|
@@ -3231,7 +3252,7 @@ declare class Sandbox {
|
|
|
3231
3252
|
/**
|
|
3232
3253
|
* Get terminal by ID
|
|
3233
3254
|
*/
|
|
3234
|
-
getTerminal(id: string): Promise<
|
|
3255
|
+
getTerminal(id: string): Promise<TerminalInstance>;
|
|
3235
3256
|
/**
|
|
3236
3257
|
* List all commands executed in a terminal (exec mode only)
|
|
3237
3258
|
* @param terminalId - The terminal ID
|
|
@@ -3590,6 +3611,7 @@ declare const PROVIDER_AUTH: {
|
|
|
3590
3611
|
readonly cloudflare: readonly [readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]];
|
|
3591
3612
|
readonly codesandbox: readonly [readonly ["CSB_API_KEY"]];
|
|
3592
3613
|
readonly blaxel: readonly [readonly ["BL_API_KEY", "BL_WORKSPACE"]];
|
|
3614
|
+
readonly namespace: readonly [readonly ["NSC_TOKEN"]];
|
|
3593
3615
|
};
|
|
3594
3616
|
/**
|
|
3595
3617
|
* All supported provider names (excluding gateway which is special)
|
|
@@ -3705,6 +3727,9 @@ interface ExplicitComputeConfig {
|
|
|
3705
3727
|
apiKey?: string;
|
|
3706
3728
|
workspace?: string;
|
|
3707
3729
|
};
|
|
3730
|
+
namespace?: {
|
|
3731
|
+
token?: string;
|
|
3732
|
+
};
|
|
3708
3733
|
}
|
|
3709
3734
|
/**
|
|
3710
3735
|
* Options for creating a sandbox via the gateway
|
|
@@ -3721,6 +3746,8 @@ interface CreateSandboxOptions {
|
|
|
3721
3746
|
namespace?: string;
|
|
3722
3747
|
/** Docker image to use for the sandbox (for infrastructure providers like Railway) */
|
|
3723
3748
|
image?: string;
|
|
3749
|
+
/** Provider-specific snapshot to create from (e.g., Vercel snapshots) */
|
|
3750
|
+
snapshotId?: string;
|
|
3724
3751
|
}
|
|
3725
3752
|
/**
|
|
3726
3753
|
* Options for finding or creating a named sandbox
|
|
@@ -3896,7 +3923,7 @@ declare const GATEWAY_URL = "https://gateway.computesdk.com";
|
|
|
3896
3923
|
* Provider detection priority order
|
|
3897
3924
|
* When multiple provider credentials are detected, use the first one in this list
|
|
3898
3925
|
*/
|
|
3899
|
-
declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel"];
|
|
3926
|
+
declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel", "namespace"];
|
|
3900
3927
|
/**
|
|
3901
3928
|
* Required environment variables for each provider
|
|
3902
3929
|
* @deprecated Use PROVIDER_AUTH from provider-config instead
|
|
@@ -3912,6 +3939,7 @@ declare const PROVIDER_ENV_VARS: {
|
|
|
3912
3939
|
readonly cloudflare: readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"];
|
|
3913
3940
|
readonly codesandbox: readonly ["CSB_API_KEY"];
|
|
3914
3941
|
readonly blaxel: readonly ["BL_API_KEY", "BL_WORKSPACE"];
|
|
3942
|
+
readonly namespace: readonly ["NSC_TOKEN"];
|
|
3915
3943
|
};
|
|
3916
3944
|
|
|
3917
3945
|
export { type CallableCompute, type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, type ExplicitComputeConfig, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, MessageType, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type ProviderName, type ProviderSandboxInfo, type RunCommandOptions, type Runtime, Sandbox, type SandboxFileSystem, type SandboxInfo$1 as SandboxInfo, type Sandbox$1 as SandboxInterface, type SandboxStatus, SignalService, TerminalInstance, type WebSocketConstructor, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
|
package/dist/index.js
CHANGED
|
@@ -1365,7 +1365,7 @@ var Terminal = class {
|
|
|
1365
1365
|
/**
|
|
1366
1366
|
* Retrieve a specific terminal by ID
|
|
1367
1367
|
* @param id - The terminal ID
|
|
1368
|
-
* @returns Terminal
|
|
1368
|
+
* @returns Terminal instance
|
|
1369
1369
|
*/
|
|
1370
1370
|
async retrieve(id) {
|
|
1371
1371
|
return this.retrieveHandler(id);
|
|
@@ -1975,6 +1975,7 @@ var Overlay = class {
|
|
|
1975
1975
|
* @param options.source - Absolute path to source directory
|
|
1976
1976
|
* @param options.target - Relative path in sandbox
|
|
1977
1977
|
* @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
|
|
1978
|
+
* @param options.strategy - Strategy to use ('copy' or 'smart')
|
|
1978
1979
|
* @param options.waitForCompletion - If true or options object, wait for background copy to complete
|
|
1979
1980
|
* @returns Overlay info with copy status
|
|
1980
1981
|
*/
|
|
@@ -2064,6 +2065,7 @@ Try increasing maxRetries or check if the source directory is very large.`
|
|
|
2064
2065
|
id: response.id,
|
|
2065
2066
|
source: response.source,
|
|
2066
2067
|
target: response.target,
|
|
2068
|
+
strategy: this.validateStrategy(response.strategy),
|
|
2067
2069
|
createdAt: response.created_at,
|
|
2068
2070
|
stats: {
|
|
2069
2071
|
copiedFiles: response.stats.copied_files,
|
|
@@ -2074,6 +2076,16 @@ Try increasing maxRetries or check if the source directory is very large.`
|
|
|
2074
2076
|
copyError: response.copy_error
|
|
2075
2077
|
};
|
|
2076
2078
|
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
|
|
2081
|
+
*/
|
|
2082
|
+
validateStrategy(strategy) {
|
|
2083
|
+
const validStrategies = ["copy", "smart"];
|
|
2084
|
+
if (strategy && validStrategies.includes(strategy)) {
|
|
2085
|
+
return strategy;
|
|
2086
|
+
}
|
|
2087
|
+
return "copy";
|
|
2088
|
+
}
|
|
2077
2089
|
/**
|
|
2078
2090
|
* Validate and return copy status, defaulting to 'pending' for unknown values
|
|
2079
2091
|
*/
|
|
@@ -2104,6 +2116,7 @@ var Sandbox = class {
|
|
|
2104
2116
|
constructor(config) {
|
|
2105
2117
|
this._token = null;
|
|
2106
2118
|
this._ws = null;
|
|
2119
|
+
this._terminals = /* @__PURE__ */ new Map();
|
|
2107
2120
|
this.sandboxId = config.sandboxId;
|
|
2108
2121
|
this.provider = config.provider;
|
|
2109
2122
|
let sandboxUrlResolved = config.sandboxUrl;
|
|
@@ -2310,6 +2323,44 @@ var Sandbox = class {
|
|
|
2310
2323
|
}
|
|
2311
2324
|
return this._ws;
|
|
2312
2325
|
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Create and configure a TerminalInstance from response data
|
|
2328
|
+
*/
|
|
2329
|
+
async hydrateTerminal(data, ws) {
|
|
2330
|
+
const terminal = new TerminalInstance(
|
|
2331
|
+
data.id,
|
|
2332
|
+
data.pty,
|
|
2333
|
+
data.status,
|
|
2334
|
+
data.channel || null,
|
|
2335
|
+
ws || null,
|
|
2336
|
+
data.encoding || "raw"
|
|
2337
|
+
);
|
|
2338
|
+
const terminalId = data.id;
|
|
2339
|
+
terminal.setExecuteHandler(async (command, background) => {
|
|
2340
|
+
return this.request(`/terminals/${terminalId}/execute`, {
|
|
2341
|
+
method: "POST",
|
|
2342
|
+
body: JSON.stringify({ command, background })
|
|
2343
|
+
});
|
|
2344
|
+
});
|
|
2345
|
+
terminal.setListCommandsHandler(async () => {
|
|
2346
|
+
return this.request(`/terminals/${terminalId}/commands`);
|
|
2347
|
+
});
|
|
2348
|
+
terminal.setRetrieveCommandHandler(async (cmdId) => {
|
|
2349
|
+
return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
|
|
2350
|
+
});
|
|
2351
|
+
terminal.setWaitCommandHandler(async (cmdId, timeout) => {
|
|
2352
|
+
const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
|
|
2353
|
+
const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
|
|
2354
|
+
return this.request(endpoint);
|
|
2355
|
+
});
|
|
2356
|
+
terminal.setDestroyHandler(async () => {
|
|
2357
|
+
await this.request(`/terminals/${terminalId}`, {
|
|
2358
|
+
method: "DELETE"
|
|
2359
|
+
});
|
|
2360
|
+
this._terminals.delete(terminalId);
|
|
2361
|
+
});
|
|
2362
|
+
return terminal;
|
|
2363
|
+
}
|
|
2313
2364
|
// ============================================================================
|
|
2314
2365
|
// Private Helper Methods
|
|
2315
2366
|
// ============================================================================
|
|
@@ -2816,37 +2867,8 @@ API request failed (${response.status}): ${error}`
|
|
|
2816
2867
|
}
|
|
2817
2868
|
});
|
|
2818
2869
|
}
|
|
2819
|
-
const terminal =
|
|
2820
|
-
|
|
2821
|
-
response.data.pty,
|
|
2822
|
-
response.data.status,
|
|
2823
|
-
response.data.channel || null,
|
|
2824
|
-
ws,
|
|
2825
|
-
response.data.encoding || "raw"
|
|
2826
|
-
);
|
|
2827
|
-
const terminalId = response.data.id;
|
|
2828
|
-
terminal.setExecuteHandler(async (command, background) => {
|
|
2829
|
-
return this.request(`/terminals/${terminalId}/execute`, {
|
|
2830
|
-
method: "POST",
|
|
2831
|
-
body: JSON.stringify({ command, background })
|
|
2832
|
-
});
|
|
2833
|
-
});
|
|
2834
|
-
terminal.setListCommandsHandler(async () => {
|
|
2835
|
-
return this.request(`/terminals/${terminalId}/commands`);
|
|
2836
|
-
});
|
|
2837
|
-
terminal.setRetrieveCommandHandler(async (cmdId) => {
|
|
2838
|
-
return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
|
|
2839
|
-
});
|
|
2840
|
-
terminal.setWaitCommandHandler(async (cmdId, timeout) => {
|
|
2841
|
-
const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
|
|
2842
|
-
const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
|
|
2843
|
-
return this.request(endpoint);
|
|
2844
|
-
});
|
|
2845
|
-
terminal.setDestroyHandler(async () => {
|
|
2846
|
-
await this.request(`/terminals/${terminalId}`, {
|
|
2847
|
-
method: "DELETE"
|
|
2848
|
-
});
|
|
2849
|
-
});
|
|
2870
|
+
const terminal = await this.hydrateTerminal(response.data, ws);
|
|
2871
|
+
this._terminals.set(terminal.id, terminal);
|
|
2850
2872
|
return terminal;
|
|
2851
2873
|
}
|
|
2852
2874
|
/**
|
|
@@ -2860,7 +2882,18 @@ API request failed (${response.status}): ${error}`
|
|
|
2860
2882
|
* Get terminal by ID
|
|
2861
2883
|
*/
|
|
2862
2884
|
async getTerminal(id) {
|
|
2863
|
-
|
|
2885
|
+
const cached = this._terminals.get(id);
|
|
2886
|
+
if (cached) {
|
|
2887
|
+
return cached;
|
|
2888
|
+
}
|
|
2889
|
+
const response = await this.request(`/terminals/${id}`);
|
|
2890
|
+
let ws = null;
|
|
2891
|
+
if (response.data.pty) {
|
|
2892
|
+
ws = await this.ensureWebSocket();
|
|
2893
|
+
}
|
|
2894
|
+
const terminal = await this.hydrateTerminal(response.data, ws);
|
|
2895
|
+
this._terminals.set(id, terminal);
|
|
2896
|
+
return terminal;
|
|
2864
2897
|
}
|
|
2865
2898
|
// ============================================================================
|
|
2866
2899
|
// Command Tracking (Exec Mode Terminals)
|
|
@@ -3464,6 +3497,7 @@ API request failed (${response.status}): ${error}`
|
|
|
3464
3497
|
this._ws.disconnect();
|
|
3465
3498
|
this._ws = null;
|
|
3466
3499
|
}
|
|
3500
|
+
this._terminals.clear();
|
|
3467
3501
|
}
|
|
3468
3502
|
};
|
|
3469
3503
|
|
|
@@ -3481,7 +3515,8 @@ var PROVIDER_AUTH = {
|
|
|
3481
3515
|
runloop: [["RUNLOOP_API_KEY"]],
|
|
3482
3516
|
cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
|
|
3483
3517
|
codesandbox: [["CSB_API_KEY"]],
|
|
3484
|
-
blaxel: [["BL_API_KEY", "BL_WORKSPACE"]]
|
|
3518
|
+
blaxel: [["BL_API_KEY", "BL_WORKSPACE"]],
|
|
3519
|
+
namespace: [["NSC_TOKEN"]]
|
|
3485
3520
|
};
|
|
3486
3521
|
var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
|
|
3487
3522
|
var PROVIDER_HEADERS = {
|
|
@@ -3523,6 +3558,9 @@ var PROVIDER_HEADERS = {
|
|
|
3523
3558
|
blaxel: {
|
|
3524
3559
|
apiKey: "X-BL-API-Key",
|
|
3525
3560
|
workspace: "X-BL-Workspace"
|
|
3561
|
+
},
|
|
3562
|
+
namespace: {
|
|
3563
|
+
token: "X-Namespace-Token"
|
|
3526
3564
|
}
|
|
3527
3565
|
};
|
|
3528
3566
|
var PROVIDER_ENV_MAP = {
|
|
@@ -3564,6 +3602,9 @@ var PROVIDER_ENV_MAP = {
|
|
|
3564
3602
|
blaxel: {
|
|
3565
3603
|
BL_API_KEY: "apiKey",
|
|
3566
3604
|
BL_WORKSPACE: "workspace"
|
|
3605
|
+
},
|
|
3606
|
+
namespace: {
|
|
3607
|
+
NSC_TOKEN: "token"
|
|
3567
3608
|
}
|
|
3568
3609
|
};
|
|
3569
3610
|
var PROVIDER_DASHBOARD_URLS = {
|
|
@@ -3576,7 +3617,8 @@ var PROVIDER_DASHBOARD_URLS = {
|
|
|
3576
3617
|
runloop: "https://runloop.ai/dashboard",
|
|
3577
3618
|
cloudflare: "https://dash.cloudflare.com/profile/api-tokens",
|
|
3578
3619
|
codesandbox: "https://codesandbox.io/dashboard/settings",
|
|
3579
|
-
blaxel: "https://blaxel.ai/dashboard"
|
|
3620
|
+
blaxel: "https://blaxel.ai/dashboard",
|
|
3621
|
+
namespace: "https://cloud.namespace.so"
|
|
3580
3622
|
};
|
|
3581
3623
|
function isValidProvider(name) {
|
|
3582
3624
|
return name in PROVIDER_AUTH;
|
|
@@ -3644,7 +3686,8 @@ var PROVIDER_PRIORITY = [
|
|
|
3644
3686
|
"vercel",
|
|
3645
3687
|
"cloudflare",
|
|
3646
3688
|
"codesandbox",
|
|
3647
|
-
"blaxel"
|
|
3689
|
+
"blaxel",
|
|
3690
|
+
"namespace"
|
|
3648
3691
|
];
|
|
3649
3692
|
var PROVIDER_ENV_VARS = {
|
|
3650
3693
|
e2b: ["E2B_API_KEY"],
|
|
@@ -3656,7 +3699,8 @@ var PROVIDER_ENV_VARS = {
|
|
|
3656
3699
|
vercel: ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"],
|
|
3657
3700
|
cloudflare: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"],
|
|
3658
3701
|
codesandbox: ["CSB_API_KEY"],
|
|
3659
|
-
blaxel: ["BL_API_KEY", "BL_WORKSPACE"]
|
|
3702
|
+
blaxel: ["BL_API_KEY", "BL_WORKSPACE"],
|
|
3703
|
+
namespace: ["NSC_TOKEN"]
|
|
3660
3704
|
};
|
|
3661
3705
|
|
|
3662
3706
|
// src/auto-detect.ts
|
|
@@ -3773,6 +3817,11 @@ function getProviderHeaders(provider) {
|
|
|
3773
3817
|
headers["X-Blaxel-Workspace"] = process.env.BL_WORKSPACE;
|
|
3774
3818
|
}
|
|
3775
3819
|
break;
|
|
3820
|
+
case "namespace":
|
|
3821
|
+
if (process.env.NSC_TOKEN) {
|
|
3822
|
+
headers["X-Namespace-Token"] = process.env.NSC_TOKEN;
|
|
3823
|
+
}
|
|
3824
|
+
break;
|
|
3776
3825
|
}
|
|
3777
3826
|
return headers;
|
|
3778
3827
|
}
|
|
@@ -3809,6 +3858,7 @@ To fix this, set one of the following:
|
|
|
3809
3858
|
Cloudflare: export CLOUDFLARE_API_TOKEN=xxx CLOUDFLARE_ACCOUNT_ID=xxx
|
|
3810
3859
|
CodeSandbox: export CSB_API_KEY=xxx
|
|
3811
3860
|
Blaxel: export BL_API_KEY=xxx BL_WORKSPACE=xxx
|
|
3861
|
+
Namespace: export NSC_TOKEN=xxx
|
|
3812
3862
|
|
|
3813
3863
|
Or set COMPUTESDK_PROVIDER to specify explicitly:
|
|
3814
3864
|
export COMPUTESDK_PROVIDER=e2b
|