computesdk 1.10.1 → 1.10.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 CHANGED
@@ -3089,10 +3089,12 @@ interface ExplicitComputeConfig {
3089
3089
  };
3090
3090
  }
3091
3091
  /**
3092
- * Options for creating a sandbox
3092
+ * Options for creating a sandbox via the gateway
3093
+ *
3094
+ * Note: Runtime is determined by the provider, not specified at creation time.
3095
+ * Use sandbox.runCode(code, runtime) to specify which runtime to use for execution.
3093
3096
  */
3094
3097
  interface CreateSandboxOptions {
3095
- runtime?: 'node' | 'python';
3096
3098
  timeout?: number;
3097
3099
  templateId?: string;
3098
3100
  metadata?: Record<string, any>;
@@ -3134,6 +3136,23 @@ declare class ComputeManager {
3134
3136
  * Get gateway config, throwing if not configured
3135
3137
  */
3136
3138
  private getGatewayConfig;
3139
+ /**
3140
+ * Explicitly configure the compute singleton
3141
+ *
3142
+ * @example
3143
+ * ```typescript
3144
+ * import { compute } from 'computesdk';
3145
+ *
3146
+ * compute.setConfig({
3147
+ * provider: 'e2b',
3148
+ * apiKey: 'computesdk_xxx',
3149
+ * e2b: { apiKey: 'e2b_xxx' }
3150
+ * });
3151
+ *
3152
+ * const sandbox = await compute.sandbox.create();
3153
+ * ```
3154
+ */
3155
+ setConfig(config: ExplicitComputeConfig): void;
3137
3156
  sandbox: {
3138
3157
  /**
3139
3158
  * Create a new sandbox
@@ -3175,6 +3194,8 @@ declare class ComputeManager {
3175
3194
  interface CallableCompute extends ComputeManager {
3176
3195
  /** Create a new compute instance with explicit configuration */
3177
3196
  (config: ExplicitComputeConfig): ComputeManager;
3197
+ /** Explicitly configure the singleton */
3198
+ setConfig(config: ExplicitComputeConfig): void;
3178
3199
  }
3179
3200
  /**
3180
3201
  * Callable compute - works as both singleton and factory function
@@ -3270,57 +3291,4 @@ declare const PROVIDER_ENV_VARS: {
3270
3291
  readonly blaxel: readonly ["BL_API_KEY", "BL_WORKSPACE"];
3271
3292
  };
3272
3293
 
3273
- /**
3274
- * Simplified Request Handler for Web Framework Integration
3275
- *
3276
- * Handles JSON requests for sandbox and code execution operations.
3277
- */
3278
- type GatewayRuntime = 'node' | 'python';
3279
- /**
3280
- * Request structure supporting sandbox and code execution capabilities
3281
- */
3282
- interface ComputeRequest {
3283
- /** Action in dot notation (e.g., 'compute.sandbox.create') */
3284
- action: string;
3285
- /** Parameters for the action */
3286
- sandboxId?: string;
3287
- code?: string;
3288
- command?: string;
3289
- args?: string[];
3290
- runtime?: GatewayRuntime;
3291
- path?: string;
3292
- content?: string;
3293
- /** Command options (for runCommand action) */
3294
- commandOptions?: {
3295
- background?: boolean;
3296
- };
3297
- /** Sandbox creation options */
3298
- options?: {
3299
- runtime?: GatewayRuntime;
3300
- timeout?: number;
3301
- name?: string;
3302
- namespace?: string;
3303
- };
3304
- }
3305
- /**
3306
- * Response structure for compute operations
3307
- */
3308
- interface ComputeResponse {
3309
- success: boolean;
3310
- error?: string;
3311
- sandboxId: string;
3312
- provider: string;
3313
- [key: string]: any;
3314
- }
3315
- /**
3316
- * Main request handler - handles HTTP requests and pre-parsed bodies
3317
- */
3318
- declare function handleComputeRequest(requestOrBody: Request | ComputeRequest): Promise<Response | ComputeResponse>;
3319
- /**
3320
- * Parameters for handleComputeRequest
3321
- */
3322
- interface HandleComputeRequestParams {
3323
- request: ComputeRequest;
3324
- }
3325
-
3326
- export { type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions$1 as CreateSandboxOptions, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, type HandleComputeRequestParams, 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, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
3294
+ export { type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, 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, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
package/dist/index.d.ts CHANGED
@@ -3089,10 +3089,12 @@ interface ExplicitComputeConfig {
3089
3089
  };
3090
3090
  }
3091
3091
  /**
3092
- * Options for creating a sandbox
3092
+ * Options for creating a sandbox via the gateway
3093
+ *
3094
+ * Note: Runtime is determined by the provider, not specified at creation time.
3095
+ * Use sandbox.runCode(code, runtime) to specify which runtime to use for execution.
3093
3096
  */
3094
3097
  interface CreateSandboxOptions {
3095
- runtime?: 'node' | 'python';
3096
3098
  timeout?: number;
3097
3099
  templateId?: string;
3098
3100
  metadata?: Record<string, any>;
@@ -3134,6 +3136,23 @@ declare class ComputeManager {
3134
3136
  * Get gateway config, throwing if not configured
3135
3137
  */
3136
3138
  private getGatewayConfig;
3139
+ /**
3140
+ * Explicitly configure the compute singleton
3141
+ *
3142
+ * @example
3143
+ * ```typescript
3144
+ * import { compute } from 'computesdk';
3145
+ *
3146
+ * compute.setConfig({
3147
+ * provider: 'e2b',
3148
+ * apiKey: 'computesdk_xxx',
3149
+ * e2b: { apiKey: 'e2b_xxx' }
3150
+ * });
3151
+ *
3152
+ * const sandbox = await compute.sandbox.create();
3153
+ * ```
3154
+ */
3155
+ setConfig(config: ExplicitComputeConfig): void;
3137
3156
  sandbox: {
3138
3157
  /**
3139
3158
  * Create a new sandbox
@@ -3175,6 +3194,8 @@ declare class ComputeManager {
3175
3194
  interface CallableCompute extends ComputeManager {
3176
3195
  /** Create a new compute instance with explicit configuration */
3177
3196
  (config: ExplicitComputeConfig): ComputeManager;
3197
+ /** Explicitly configure the singleton */
3198
+ setConfig(config: ExplicitComputeConfig): void;
3178
3199
  }
3179
3200
  /**
3180
3201
  * Callable compute - works as both singleton and factory function
@@ -3270,57 +3291,4 @@ declare const PROVIDER_ENV_VARS: {
3270
3291
  readonly blaxel: readonly ["BL_API_KEY", "BL_WORKSPACE"];
3271
3292
  };
3272
3293
 
3273
- /**
3274
- * Simplified Request Handler for Web Framework Integration
3275
- *
3276
- * Handles JSON requests for sandbox and code execution operations.
3277
- */
3278
- type GatewayRuntime = 'node' | 'python';
3279
- /**
3280
- * Request structure supporting sandbox and code execution capabilities
3281
- */
3282
- interface ComputeRequest {
3283
- /** Action in dot notation (e.g., 'compute.sandbox.create') */
3284
- action: string;
3285
- /** Parameters for the action */
3286
- sandboxId?: string;
3287
- code?: string;
3288
- command?: string;
3289
- args?: string[];
3290
- runtime?: GatewayRuntime;
3291
- path?: string;
3292
- content?: string;
3293
- /** Command options (for runCommand action) */
3294
- commandOptions?: {
3295
- background?: boolean;
3296
- };
3297
- /** Sandbox creation options */
3298
- options?: {
3299
- runtime?: GatewayRuntime;
3300
- timeout?: number;
3301
- name?: string;
3302
- namespace?: string;
3303
- };
3304
- }
3305
- /**
3306
- * Response structure for compute operations
3307
- */
3308
- interface ComputeResponse {
3309
- success: boolean;
3310
- error?: string;
3311
- sandboxId: string;
3312
- provider: string;
3313
- [key: string]: any;
3314
- }
3315
- /**
3316
- * Main request handler - handles HTTP requests and pre-parsed bodies
3317
- */
3318
- declare function handleComputeRequest(requestOrBody: Request | ComputeRequest): Promise<Response | ComputeResponse>;
3319
- /**
3320
- * Parameters for handleComputeRequest
3321
- */
3322
- interface HandleComputeRequestParams {
3323
- request: ComputeRequest;
3324
- }
3325
-
3326
- export { type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions$1 as CreateSandboxOptions, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, type HandleComputeRequestParams, 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, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
3294
+ export { type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, 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, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
package/dist/index.js CHANGED
@@ -44,7 +44,6 @@ __export(index_exports, {
44
44
  getMissingEnvVars: () => getMissingEnvVars,
45
45
  getProviderConfigFromEnv: () => getProviderConfigFromEnv,
46
46
  getProviderHeaders: () => getProviderHeaders,
47
- handleComputeRequest: () => handleComputeRequest,
48
47
  isCommandExitError: () => isCommandExitError,
49
48
  isGatewayModeEnabled: () => isGatewayModeEnabled,
50
49
  isProviderAuthComplete: () => isProviderAuthComplete,
@@ -3670,11 +3669,39 @@ var ComputeManager = class {
3670
3669
  this.ensureConfigured();
3671
3670
  if (!this.config) {
3672
3671
  throw new Error(
3673
- 'No gateway configuration found.\n\nOptions:\n1. Zero-config mode: Set COMPUTESDK_API_KEY and provider credentials (e.g., E2B_API_KEY)\n2. Explicit mode: Call compute({ provider: "e2b", apiKey: "...", e2b: { apiKey: "..." } })\n3. Direct mode: Import createCompute from @computesdk/provider to bypass the gateway\n\nDocs: https://computesdk.com/docs/quickstart'
3672
+ `No ComputeSDK configuration found.
3673
+
3674
+ Options:
3675
+ 1. Zero-config: Set COMPUTESDK_API_KEY and provider credentials (e.g., E2B_API_KEY)
3676
+ 2. Explicit: Call compute.setConfig({ provider: "e2b", apiKey: "...", e2b: { apiKey: "..." } })
3677
+ 3. Use provider directly: import { e2b } from '@computesdk/e2b'
3678
+
3679
+ Docs: https://computesdk.com/docs/quickstart`
3674
3680
  );
3675
3681
  }
3676
3682
  return this.config;
3677
3683
  }
3684
+ /**
3685
+ * Explicitly configure the compute singleton
3686
+ *
3687
+ * @example
3688
+ * ```typescript
3689
+ * import { compute } from 'computesdk';
3690
+ *
3691
+ * compute.setConfig({
3692
+ * provider: 'e2b',
3693
+ * apiKey: 'computesdk_xxx',
3694
+ * e2b: { apiKey: 'e2b_xxx' }
3695
+ * });
3696
+ *
3697
+ * const sandbox = await compute.sandbox.create();
3698
+ * ```
3699
+ */
3700
+ setConfig(config) {
3701
+ const gatewayConfig = createConfigFromExplicit(config);
3702
+ this.config = gatewayConfig;
3703
+ this.autoConfigured = false;
3704
+ }
3678
3705
  };
3679
3706
  var singletonInstance = new ComputeManager();
3680
3707
  function computeFactory(config) {
@@ -3699,192 +3726,6 @@ var compute = new Proxy(
3699
3726
  }
3700
3727
  }
3701
3728
  );
3702
-
3703
- // src/request-handler.ts
3704
- async function executeAction(body) {
3705
- try {
3706
- const { action, sandboxId } = body;
3707
- if (action === "compute.sandbox.create") {
3708
- const sandbox2 = await compute.sandbox.create(body.options || { runtime: "python" });
3709
- return {
3710
- success: true,
3711
- sandboxId: sandbox2.sandboxId,
3712
- provider: sandbox2.provider
3713
- };
3714
- }
3715
- if (action === "compute.sandbox.list") {
3716
- throw new Error("List operation not supported in gateway mode");
3717
- }
3718
- if (action === "compute.sandbox.destroy") {
3719
- if (!sandboxId) {
3720
- throw new Error("sandboxId is required for destroy action");
3721
- }
3722
- await compute.sandbox.destroy(sandboxId);
3723
- return {
3724
- success: true,
3725
- sandboxId,
3726
- provider: "gateway"
3727
- };
3728
- }
3729
- if (!sandboxId) {
3730
- throw new Error("sandboxId is required for this action");
3731
- }
3732
- const sandbox = await compute.sandbox.getById(sandboxId);
3733
- if (!sandbox) {
3734
- throw new Error(`Sandbox ${sandboxId} not found`);
3735
- }
3736
- if (action === "compute.sandbox.getInfo") {
3737
- const result = await sandbox.getInfo();
3738
- return {
3739
- success: true,
3740
- sandboxId,
3741
- provider: sandbox.provider,
3742
- info: {
3743
- id: result.id,
3744
- provider: result.provider,
3745
- runtime: result.runtime,
3746
- status: result.status,
3747
- createdAt: result.createdAt.toISOString(),
3748
- timeout: result.timeout,
3749
- metadata: result.metadata
3750
- }
3751
- };
3752
- }
3753
- if (action === "compute.sandbox.runCode") {
3754
- if (!body.code) throw new Error("code is required");
3755
- const result = await sandbox.runCode(body.code, body.runtime);
3756
- return {
3757
- success: true,
3758
- sandboxId,
3759
- provider: sandbox.provider,
3760
- result: {
3761
- output: result.output,
3762
- exitCode: result.exitCode,
3763
- language: result.language
3764
- }
3765
- };
3766
- }
3767
- if (action === "compute.sandbox.runCommand") {
3768
- if (!body.command) throw new Error("command is required");
3769
- const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);
3770
- return {
3771
- success: true,
3772
- sandboxId,
3773
- provider: sandbox.provider,
3774
- result: {
3775
- stdout: result.stdout,
3776
- stderr: result.stderr,
3777
- exitCode: result.exitCode,
3778
- durationMs: result.durationMs
3779
- }
3780
- };
3781
- }
3782
- if (action === "compute.sandbox.filesystem.readFile") {
3783
- if (!body.path) throw new Error("path is required");
3784
- const result = await sandbox.filesystem.readFile(body.path);
3785
- return {
3786
- success: true,
3787
- sandboxId,
3788
- provider: sandbox.provider,
3789
- fileContent: result
3790
- };
3791
- }
3792
- if (action === "compute.sandbox.filesystem.writeFile") {
3793
- if (!body.path) throw new Error("path is required");
3794
- if (body.content === void 0) throw new Error("content is required");
3795
- await sandbox.filesystem.writeFile(body.path, body.content);
3796
- return { success: true, sandboxId, provider: sandbox.provider };
3797
- }
3798
- if (action === "compute.sandbox.filesystem.mkdir") {
3799
- if (!body.path) throw new Error("path is required");
3800
- await sandbox.filesystem.mkdir(body.path);
3801
- return { success: true, sandboxId, provider: sandbox.provider };
3802
- }
3803
- if (action === "compute.sandbox.filesystem.readdir") {
3804
- if (!body.path) throw new Error("path is required");
3805
- const result = await sandbox.filesystem.readdir(body.path);
3806
- return {
3807
- success: true,
3808
- sandboxId,
3809
- provider: sandbox.provider,
3810
- files: result.map((entry) => ({
3811
- name: entry.name,
3812
- path: entry.path,
3813
- isDirectory: entry.isDirectory,
3814
- size: entry.size,
3815
- lastModified: entry.lastModified.toISOString()
3816
- }))
3817
- };
3818
- }
3819
- if (action === "compute.sandbox.filesystem.exists") {
3820
- if (!body.path) throw new Error("path is required");
3821
- const result = await sandbox.filesystem.exists(body.path);
3822
- return {
3823
- success: true,
3824
- sandboxId,
3825
- provider: sandbox.provider,
3826
- exists: result
3827
- };
3828
- }
3829
- if (action === "compute.sandbox.filesystem.remove") {
3830
- if (!body.path) throw new Error("path is required");
3831
- await sandbox.filesystem.remove(body.path);
3832
- return { success: true, sandboxId, provider: sandbox.provider };
3833
- }
3834
- throw new Error(`Unknown action: ${action}`);
3835
- } catch (error) {
3836
- return {
3837
- success: false,
3838
- error: error instanceof Error ? error.message : "Unknown error occurred",
3839
- sandboxId: body.sandboxId || "",
3840
- provider: "gateway"
3841
- };
3842
- }
3843
- }
3844
- async function handleComputeRequest(requestOrBody) {
3845
- try {
3846
- let body;
3847
- if (requestOrBody instanceof Request) {
3848
- if (requestOrBody.method !== "POST") {
3849
- return Response.json({
3850
- success: false,
3851
- error: "Only POST requests are supported",
3852
- sandboxId: "",
3853
- provider: "gateway"
3854
- }, { status: 405 });
3855
- }
3856
- try {
3857
- body = await requestOrBody.json();
3858
- } catch (parseError) {
3859
- return Response.json({
3860
- success: false,
3861
- error: "Invalid JSON in request body",
3862
- sandboxId: "",
3863
- provider: "gateway"
3864
- }, { status: 400 });
3865
- }
3866
- const result = await executeAction(body);
3867
- return Response.json(result, {
3868
- status: result.success ? 200 : 500
3869
- });
3870
- } else {
3871
- body = requestOrBody;
3872
- return await executeAction(body);
3873
- }
3874
- } catch (error) {
3875
- const errorResponse = {
3876
- success: false,
3877
- error: error instanceof Error ? error.message : "Request handling failed",
3878
- sandboxId: "",
3879
- provider: "gateway"
3880
- };
3881
- if (requestOrBody instanceof Request) {
3882
- return Response.json(errorResponse, { status: 500 });
3883
- } else {
3884
- return errorResponse;
3885
- }
3886
- }
3887
- }
3888
3729
  // Annotate the CommonJS export names for ESM import in node:
3889
3730
  0 && (module.exports = {
3890
3731
  CommandExitError,
@@ -3911,7 +3752,6 @@ async function handleComputeRequest(requestOrBody) {
3911
3752
  getMissingEnvVars,
3912
3753
  getProviderConfigFromEnv,
3913
3754
  getProviderHeaders,
3914
- handleComputeRequest,
3915
3755
  isCommandExitError,
3916
3756
  isGatewayModeEnabled,
3917
3757
  isProviderAuthComplete,