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/README.md +253 -541
- package/dist/index.d.mts +24 -56
- package/dist/index.d.ts +24 -56
- package/dist/index.js +29 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -188
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3616,11 +3616,39 @@ var ComputeManager = class {
|
|
|
3616
3616
|
this.ensureConfigured();
|
|
3617
3617
|
if (!this.config) {
|
|
3618
3618
|
throw new Error(
|
|
3619
|
-
|
|
3619
|
+
`No ComputeSDK configuration found.
|
|
3620
|
+
|
|
3621
|
+
Options:
|
|
3622
|
+
1. Zero-config: Set COMPUTESDK_API_KEY and provider credentials (e.g., E2B_API_KEY)
|
|
3623
|
+
2. Explicit: Call compute.setConfig({ provider: "e2b", apiKey: "...", e2b: { apiKey: "..." } })
|
|
3624
|
+
3. Use provider directly: import { e2b } from '@computesdk/e2b'
|
|
3625
|
+
|
|
3626
|
+
Docs: https://computesdk.com/docs/quickstart`
|
|
3620
3627
|
);
|
|
3621
3628
|
}
|
|
3622
3629
|
return this.config;
|
|
3623
3630
|
}
|
|
3631
|
+
/**
|
|
3632
|
+
* Explicitly configure the compute singleton
|
|
3633
|
+
*
|
|
3634
|
+
* @example
|
|
3635
|
+
* ```typescript
|
|
3636
|
+
* import { compute } from 'computesdk';
|
|
3637
|
+
*
|
|
3638
|
+
* compute.setConfig({
|
|
3639
|
+
* provider: 'e2b',
|
|
3640
|
+
* apiKey: 'computesdk_xxx',
|
|
3641
|
+
* e2b: { apiKey: 'e2b_xxx' }
|
|
3642
|
+
* });
|
|
3643
|
+
*
|
|
3644
|
+
* const sandbox = await compute.sandbox.create();
|
|
3645
|
+
* ```
|
|
3646
|
+
*/
|
|
3647
|
+
setConfig(config) {
|
|
3648
|
+
const gatewayConfig = createConfigFromExplicit(config);
|
|
3649
|
+
this.config = gatewayConfig;
|
|
3650
|
+
this.autoConfigured = false;
|
|
3651
|
+
}
|
|
3624
3652
|
};
|
|
3625
3653
|
var singletonInstance = new ComputeManager();
|
|
3626
3654
|
function computeFactory(config) {
|
|
@@ -3645,192 +3673,6 @@ var compute = new Proxy(
|
|
|
3645
3673
|
}
|
|
3646
3674
|
}
|
|
3647
3675
|
);
|
|
3648
|
-
|
|
3649
|
-
// src/request-handler.ts
|
|
3650
|
-
async function executeAction(body) {
|
|
3651
|
-
try {
|
|
3652
|
-
const { action, sandboxId } = body;
|
|
3653
|
-
if (action === "compute.sandbox.create") {
|
|
3654
|
-
const sandbox2 = await compute.sandbox.create(body.options || { runtime: "python" });
|
|
3655
|
-
return {
|
|
3656
|
-
success: true,
|
|
3657
|
-
sandboxId: sandbox2.sandboxId,
|
|
3658
|
-
provider: sandbox2.provider
|
|
3659
|
-
};
|
|
3660
|
-
}
|
|
3661
|
-
if (action === "compute.sandbox.list") {
|
|
3662
|
-
throw new Error("List operation not supported in gateway mode");
|
|
3663
|
-
}
|
|
3664
|
-
if (action === "compute.sandbox.destroy") {
|
|
3665
|
-
if (!sandboxId) {
|
|
3666
|
-
throw new Error("sandboxId is required for destroy action");
|
|
3667
|
-
}
|
|
3668
|
-
await compute.sandbox.destroy(sandboxId);
|
|
3669
|
-
return {
|
|
3670
|
-
success: true,
|
|
3671
|
-
sandboxId,
|
|
3672
|
-
provider: "gateway"
|
|
3673
|
-
};
|
|
3674
|
-
}
|
|
3675
|
-
if (!sandboxId) {
|
|
3676
|
-
throw new Error("sandboxId is required for this action");
|
|
3677
|
-
}
|
|
3678
|
-
const sandbox = await compute.sandbox.getById(sandboxId);
|
|
3679
|
-
if (!sandbox) {
|
|
3680
|
-
throw new Error(`Sandbox ${sandboxId} not found`);
|
|
3681
|
-
}
|
|
3682
|
-
if (action === "compute.sandbox.getInfo") {
|
|
3683
|
-
const result = await sandbox.getInfo();
|
|
3684
|
-
return {
|
|
3685
|
-
success: true,
|
|
3686
|
-
sandboxId,
|
|
3687
|
-
provider: sandbox.provider,
|
|
3688
|
-
info: {
|
|
3689
|
-
id: result.id,
|
|
3690
|
-
provider: result.provider,
|
|
3691
|
-
runtime: result.runtime,
|
|
3692
|
-
status: result.status,
|
|
3693
|
-
createdAt: result.createdAt.toISOString(),
|
|
3694
|
-
timeout: result.timeout,
|
|
3695
|
-
metadata: result.metadata
|
|
3696
|
-
}
|
|
3697
|
-
};
|
|
3698
|
-
}
|
|
3699
|
-
if (action === "compute.sandbox.runCode") {
|
|
3700
|
-
if (!body.code) throw new Error("code is required");
|
|
3701
|
-
const result = await sandbox.runCode(body.code, body.runtime);
|
|
3702
|
-
return {
|
|
3703
|
-
success: true,
|
|
3704
|
-
sandboxId,
|
|
3705
|
-
provider: sandbox.provider,
|
|
3706
|
-
result: {
|
|
3707
|
-
output: result.output,
|
|
3708
|
-
exitCode: result.exitCode,
|
|
3709
|
-
language: result.language
|
|
3710
|
-
}
|
|
3711
|
-
};
|
|
3712
|
-
}
|
|
3713
|
-
if (action === "compute.sandbox.runCommand") {
|
|
3714
|
-
if (!body.command) throw new Error("command is required");
|
|
3715
|
-
const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);
|
|
3716
|
-
return {
|
|
3717
|
-
success: true,
|
|
3718
|
-
sandboxId,
|
|
3719
|
-
provider: sandbox.provider,
|
|
3720
|
-
result: {
|
|
3721
|
-
stdout: result.stdout,
|
|
3722
|
-
stderr: result.stderr,
|
|
3723
|
-
exitCode: result.exitCode,
|
|
3724
|
-
durationMs: result.durationMs
|
|
3725
|
-
}
|
|
3726
|
-
};
|
|
3727
|
-
}
|
|
3728
|
-
if (action === "compute.sandbox.filesystem.readFile") {
|
|
3729
|
-
if (!body.path) throw new Error("path is required");
|
|
3730
|
-
const result = await sandbox.filesystem.readFile(body.path);
|
|
3731
|
-
return {
|
|
3732
|
-
success: true,
|
|
3733
|
-
sandboxId,
|
|
3734
|
-
provider: sandbox.provider,
|
|
3735
|
-
fileContent: result
|
|
3736
|
-
};
|
|
3737
|
-
}
|
|
3738
|
-
if (action === "compute.sandbox.filesystem.writeFile") {
|
|
3739
|
-
if (!body.path) throw new Error("path is required");
|
|
3740
|
-
if (body.content === void 0) throw new Error("content is required");
|
|
3741
|
-
await sandbox.filesystem.writeFile(body.path, body.content);
|
|
3742
|
-
return { success: true, sandboxId, provider: sandbox.provider };
|
|
3743
|
-
}
|
|
3744
|
-
if (action === "compute.sandbox.filesystem.mkdir") {
|
|
3745
|
-
if (!body.path) throw new Error("path is required");
|
|
3746
|
-
await sandbox.filesystem.mkdir(body.path);
|
|
3747
|
-
return { success: true, sandboxId, provider: sandbox.provider };
|
|
3748
|
-
}
|
|
3749
|
-
if (action === "compute.sandbox.filesystem.readdir") {
|
|
3750
|
-
if (!body.path) throw new Error("path is required");
|
|
3751
|
-
const result = await sandbox.filesystem.readdir(body.path);
|
|
3752
|
-
return {
|
|
3753
|
-
success: true,
|
|
3754
|
-
sandboxId,
|
|
3755
|
-
provider: sandbox.provider,
|
|
3756
|
-
files: result.map((entry) => ({
|
|
3757
|
-
name: entry.name,
|
|
3758
|
-
path: entry.path,
|
|
3759
|
-
isDirectory: entry.isDirectory,
|
|
3760
|
-
size: entry.size,
|
|
3761
|
-
lastModified: entry.lastModified.toISOString()
|
|
3762
|
-
}))
|
|
3763
|
-
};
|
|
3764
|
-
}
|
|
3765
|
-
if (action === "compute.sandbox.filesystem.exists") {
|
|
3766
|
-
if (!body.path) throw new Error("path is required");
|
|
3767
|
-
const result = await sandbox.filesystem.exists(body.path);
|
|
3768
|
-
return {
|
|
3769
|
-
success: true,
|
|
3770
|
-
sandboxId,
|
|
3771
|
-
provider: sandbox.provider,
|
|
3772
|
-
exists: result
|
|
3773
|
-
};
|
|
3774
|
-
}
|
|
3775
|
-
if (action === "compute.sandbox.filesystem.remove") {
|
|
3776
|
-
if (!body.path) throw new Error("path is required");
|
|
3777
|
-
await sandbox.filesystem.remove(body.path);
|
|
3778
|
-
return { success: true, sandboxId, provider: sandbox.provider };
|
|
3779
|
-
}
|
|
3780
|
-
throw new Error(`Unknown action: ${action}`);
|
|
3781
|
-
} catch (error) {
|
|
3782
|
-
return {
|
|
3783
|
-
success: false,
|
|
3784
|
-
error: error instanceof Error ? error.message : "Unknown error occurred",
|
|
3785
|
-
sandboxId: body.sandboxId || "",
|
|
3786
|
-
provider: "gateway"
|
|
3787
|
-
};
|
|
3788
|
-
}
|
|
3789
|
-
}
|
|
3790
|
-
async function handleComputeRequest(requestOrBody) {
|
|
3791
|
-
try {
|
|
3792
|
-
let body;
|
|
3793
|
-
if (requestOrBody instanceof Request) {
|
|
3794
|
-
if (requestOrBody.method !== "POST") {
|
|
3795
|
-
return Response.json({
|
|
3796
|
-
success: false,
|
|
3797
|
-
error: "Only POST requests are supported",
|
|
3798
|
-
sandboxId: "",
|
|
3799
|
-
provider: "gateway"
|
|
3800
|
-
}, { status: 405 });
|
|
3801
|
-
}
|
|
3802
|
-
try {
|
|
3803
|
-
body = await requestOrBody.json();
|
|
3804
|
-
} catch (parseError) {
|
|
3805
|
-
return Response.json({
|
|
3806
|
-
success: false,
|
|
3807
|
-
error: "Invalid JSON in request body",
|
|
3808
|
-
sandboxId: "",
|
|
3809
|
-
provider: "gateway"
|
|
3810
|
-
}, { status: 400 });
|
|
3811
|
-
}
|
|
3812
|
-
const result = await executeAction(body);
|
|
3813
|
-
return Response.json(result, {
|
|
3814
|
-
status: result.success ? 200 : 500
|
|
3815
|
-
});
|
|
3816
|
-
} else {
|
|
3817
|
-
body = requestOrBody;
|
|
3818
|
-
return await executeAction(body);
|
|
3819
|
-
}
|
|
3820
|
-
} catch (error) {
|
|
3821
|
-
const errorResponse = {
|
|
3822
|
-
success: false,
|
|
3823
|
-
error: error instanceof Error ? error.message : "Request handling failed",
|
|
3824
|
-
sandboxId: "",
|
|
3825
|
-
provider: "gateway"
|
|
3826
|
-
};
|
|
3827
|
-
if (requestOrBody instanceof Request) {
|
|
3828
|
-
return Response.json(errorResponse, { status: 500 });
|
|
3829
|
-
} else {
|
|
3830
|
-
return errorResponse;
|
|
3831
|
-
}
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
3676
|
export {
|
|
3835
3677
|
CommandExitError,
|
|
3836
3678
|
FileWatcher,
|
|
@@ -3856,7 +3698,6 @@ export {
|
|
|
3856
3698
|
getMissingEnvVars,
|
|
3857
3699
|
getProviderConfigFromEnv,
|
|
3858
3700
|
getProviderHeaders,
|
|
3859
|
-
handleComputeRequest,
|
|
3860
3701
|
isCommandExitError,
|
|
3861
3702
|
isGatewayModeEnabled,
|
|
3862
3703
|
isProviderAuthComplete,
|