@computesdk/codesandbox 1.5.44 → 1.5.46
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 +11 -11
- package/dist/index.d.mts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +37 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,13 +30,13 @@ import { compute } from 'computesdk';
|
|
|
30
30
|
const sandbox = await compute.sandbox.create();
|
|
31
31
|
|
|
32
32
|
// Execute JavaScript/Node.js code
|
|
33
|
-
const result = await sandbox.
|
|
33
|
+
const result = await sandbox.runCommand(`node - <<'JS'
|
|
34
34
|
const message = "Hello from CodeSandbox!";
|
|
35
35
|
console.log(message);
|
|
36
36
|
|
|
37
37
|
const data = { users: 3, tasks: 15 };
|
|
38
38
|
console.log(JSON.stringify(data, null, 2));
|
|
39
|
-
`);
|
|
39
|
+
JS`);
|
|
40
40
|
|
|
41
41
|
console.log(result.stdout);
|
|
42
42
|
// Output:
|
|
@@ -47,12 +47,12 @@ console.log(result.stdout);
|
|
|
47
47
|
// }
|
|
48
48
|
|
|
49
49
|
// Execute Python code
|
|
50
|
-
const pythonResult = await sandbox.
|
|
50
|
+
const pythonResult = await sandbox.runCommand(`python - <<'PY'
|
|
51
51
|
import json
|
|
52
52
|
data = {"framework": "CodeSandbox", "language": "Python"}
|
|
53
53
|
print(json.dumps(data, indent=2))
|
|
54
54
|
print(f"Running in: {data['framework']}")
|
|
55
|
-
|
|
55
|
+
PY`);
|
|
56
56
|
|
|
57
57
|
console.log(pythonResult.stdout);
|
|
58
58
|
// Output:
|
|
@@ -80,7 +80,7 @@ const compute = codesandbox({
|
|
|
80
80
|
|
|
81
81
|
const sandbox = await compute.sandbox.create();
|
|
82
82
|
|
|
83
|
-
const result = await sandbox.
|
|
83
|
+
const result = await sandbox.runCommand('node -e "console.log(\"Hello from CodeSandbox!\")"');
|
|
84
84
|
console.log(result.stdout);
|
|
85
85
|
|
|
86
86
|
await sandbox.destroy();
|
|
@@ -126,23 +126,23 @@ interface CodesandboxConfig {
|
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
128
|
// Execute Node.js code
|
|
129
|
-
const result = await sandbox.
|
|
129
|
+
const result = await sandbox.runCommand(`node - <<'JS'
|
|
130
130
|
const fs = require('fs');
|
|
131
131
|
const data = { timestamp: Date.now() };
|
|
132
132
|
console.log('Processing data:', JSON.stringify(data));
|
|
133
|
-
`);
|
|
133
|
+
JS`);
|
|
134
134
|
|
|
135
135
|
// Execute Python code
|
|
136
|
-
const result = await sandbox.
|
|
136
|
+
const result = await sandbox.runCommand(`python - <<'PY'
|
|
137
137
|
import datetime
|
|
138
138
|
import json
|
|
139
139
|
|
|
140
140
|
data = {'timestamp': datetime.datetime.now().isoformat()}
|
|
141
141
|
print('Processing data:', json.dumps(data))
|
|
142
|
-
|
|
142
|
+
PY`);
|
|
143
143
|
|
|
144
144
|
// Auto-detection (based on code patterns)
|
|
145
|
-
const result = await sandbox.
|
|
145
|
+
const result = await sandbox.runCommand('python -c "print(\"Auto-detected as Python\")"');
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
### Command Execution
|
|
@@ -229,4 +229,4 @@ await compute.sandbox.destroy(provider, 'sandbox-id'); // Actually hibernates
|
|
|
229
229
|
|
|
230
230
|
## License
|
|
231
231
|
|
|
232
|
-
MIT
|
|
232
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import * as _computesdk_provider from '@computesdk/provider';
|
|
2
|
-
import { Runtime } from '@computesdk/provider';
|
|
3
2
|
import { Sandbox } from '@codesandbox/sdk';
|
|
4
3
|
|
|
5
|
-
/**
|
|
6
|
-
* Codesandbox-specific configuration options
|
|
7
|
-
*/
|
|
8
4
|
interface CodesandboxConfig {
|
|
9
5
|
/** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */
|
|
10
6
|
apiKey?: string;
|
|
11
7
|
/** Template to use for new sandboxes */
|
|
12
8
|
templateId?: string;
|
|
13
|
-
/** Default runtime environment */
|
|
14
|
-
runtime?:
|
|
9
|
+
/** Default runtime environment (e.g. 'node', 'python') */
|
|
10
|
+
runtime?: string;
|
|
15
11
|
/** Execution timeout in milliseconds */
|
|
16
12
|
timeout?: number;
|
|
17
13
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a Codesandbox provider instance using the factory pattern
|
|
20
|
-
*/
|
|
21
14
|
declare const codesandbox: (config: CodesandboxConfig) => _computesdk_provider.Provider<Sandbox, any, any>;
|
|
22
15
|
|
|
23
16
|
export { type CodesandboxConfig, codesandbox };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import * as _computesdk_provider from '@computesdk/provider';
|
|
2
|
-
import { Runtime } from '@computesdk/provider';
|
|
3
2
|
import { Sandbox } from '@codesandbox/sdk';
|
|
4
3
|
|
|
5
|
-
/**
|
|
6
|
-
* Codesandbox-specific configuration options
|
|
7
|
-
*/
|
|
8
4
|
interface CodesandboxConfig {
|
|
9
5
|
/** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */
|
|
10
6
|
apiKey?: string;
|
|
11
7
|
/** Template to use for new sandboxes */
|
|
12
8
|
templateId?: string;
|
|
13
|
-
/** Default runtime environment */
|
|
14
|
-
runtime?:
|
|
9
|
+
/** Default runtime environment (e.g. 'node', 'python') */
|
|
10
|
+
runtime?: string;
|
|
15
11
|
/** Execution timeout in milliseconds */
|
|
16
12
|
timeout?: number;
|
|
17
13
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a Codesandbox provider instance using the factory pattern
|
|
20
|
-
*/
|
|
21
14
|
declare const codesandbox: (config: CodesandboxConfig) => _computesdk_provider.Provider<Sandbox, any, any>;
|
|
22
15
|
|
|
23
16
|
export { type CodesandboxConfig, codesandbox };
|
package/dist/index.js
CHANGED
|
@@ -29,27 +29,20 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
29
29
|
name: "codesandbox",
|
|
30
30
|
methods: {
|
|
31
31
|
sandbox: {
|
|
32
|
-
// Collection operations (compute.sandbox.*)
|
|
33
32
|
create: async (config, options) => {
|
|
34
33
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
35
34
|
if (!apiKey) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`
|
|
38
|
-
);
|
|
35
|
+
throw new Error(`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`);
|
|
39
36
|
}
|
|
40
37
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
41
38
|
try {
|
|
42
39
|
let sandbox;
|
|
43
40
|
let sandboxId;
|
|
44
|
-
if (options?.
|
|
45
|
-
sandbox = await sdk.sandboxes.resume(options.sandboxId);
|
|
46
|
-
sandboxId = options.sandboxId;
|
|
47
|
-
} else if (options?.snapshotId) {
|
|
41
|
+
if (options?.snapshotId) {
|
|
48
42
|
sandbox = await sdk.sandboxes.resume(options.snapshotId);
|
|
49
43
|
sandboxId = options.snapshotId;
|
|
50
44
|
} else {
|
|
51
45
|
const {
|
|
52
|
-
runtime: _runtime,
|
|
53
46
|
timeout: _timeout,
|
|
54
47
|
envs,
|
|
55
48
|
name: _name,
|
|
@@ -59,76 +52,45 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
59
52
|
sandboxId: _sandboxId,
|
|
60
53
|
namespace: _namespace,
|
|
61
54
|
directory: _directory,
|
|
62
|
-
overlays: _overlays,
|
|
63
|
-
servers: _servers,
|
|
64
55
|
...providerOptions
|
|
65
56
|
} = options || {};
|
|
66
|
-
const createOptions = {
|
|
67
|
-
...providerOptions
|
|
68
|
-
// Spread provider-specific options
|
|
69
|
-
};
|
|
57
|
+
const createOptions = { ...providerOptions };
|
|
70
58
|
const templateId = optTemplateId || config.templateId;
|
|
71
|
-
if (templateId)
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (envs && Object.keys(envs).length > 0) {
|
|
75
|
-
createOptions.envVars = envs;
|
|
76
|
-
}
|
|
59
|
+
if (templateId) createOptions.id = templateId;
|
|
60
|
+
if (envs && Object.keys(envs).length > 0) createOptions.envVars = envs;
|
|
77
61
|
sandbox = await sdk.sandboxes.create(createOptions);
|
|
78
62
|
sandboxId = sandbox.id;
|
|
79
63
|
}
|
|
80
|
-
return {
|
|
81
|
-
sandbox,
|
|
82
|
-
sandboxId
|
|
83
|
-
};
|
|
64
|
+
return { sandbox, sandboxId };
|
|
84
65
|
} catch (error) {
|
|
85
66
|
if (error instanceof Error) {
|
|
86
67
|
if (error.message.includes("unauthorized") || error.message.includes("API key")) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`
|
|
89
|
-
);
|
|
68
|
+
throw new Error(`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable.`);
|
|
90
69
|
}
|
|
91
70
|
if (error.message.includes("quota") || error.message.includes("limit")) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`
|
|
94
|
-
);
|
|
71
|
+
throw new Error(`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`);
|
|
95
72
|
}
|
|
96
73
|
}
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
99
|
-
);
|
|
74
|
+
throw new Error(`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
75
|
}
|
|
101
76
|
},
|
|
102
77
|
getById: async (config, sandboxId) => {
|
|
103
78
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
104
|
-
if (!apiKey)
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
107
|
-
);
|
|
108
|
-
}
|
|
79
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
109
80
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
110
81
|
try {
|
|
111
82
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
112
|
-
return {
|
|
113
|
-
|
|
114
|
-
sandboxId
|
|
115
|
-
};
|
|
116
|
-
} catch (error) {
|
|
83
|
+
return { sandbox, sandboxId };
|
|
84
|
+
} catch {
|
|
117
85
|
return null;
|
|
118
86
|
}
|
|
119
87
|
},
|
|
120
88
|
list: async (_config) => {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`CodeSandbox provider does not support listing sandboxes. CodeSandbox SDK does not provide a native list API. Consider using the CodeSandbox dashboard or implement your own tracking system.`
|
|
123
|
-
);
|
|
89
|
+
throw new Error(`CodeSandbox provider does not support listing sandboxes.`);
|
|
124
90
|
},
|
|
125
91
|
destroy: async (config, sandboxId) => {
|
|
126
92
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
127
|
-
if (!apiKey)
|
|
128
|
-
throw new Error(
|
|
129
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
93
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
132
94
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
133
95
|
try {
|
|
134
96
|
await sdk.sandboxes.shutdown(sandboxId);
|
|
@@ -143,38 +105,6 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
143
105
|
}
|
|
144
106
|
}
|
|
145
107
|
},
|
|
146
|
-
// Instance operations (sandbox.*)
|
|
147
|
-
runCode: async (sandbox, code, runtime) => {
|
|
148
|
-
const startTime = Date.now();
|
|
149
|
-
try {
|
|
150
|
-
const client = await sandbox.connect();
|
|
151
|
-
const effectiveRuntime = runtime || // Strong Python indicators
|
|
152
|
-
(code.includes("print(") || code.includes("import ") || code.includes("def ") || code.includes("sys.") || code.includes("json.") || code.includes("__") || code.includes('f"') || code.includes("f'") || code.includes("raise ") ? "python" : "node");
|
|
153
|
-
const encoded = Buffer.from(code).toString("base64");
|
|
154
|
-
let command;
|
|
155
|
-
if (effectiveRuntime === "python") {
|
|
156
|
-
command = `echo "${encoded}" | base64 -d | python3`;
|
|
157
|
-
} else {
|
|
158
|
-
command = `echo "${encoded}" | base64 -d | node`;
|
|
159
|
-
}
|
|
160
|
-
const output = await client.commands.run(command);
|
|
161
|
-
if (output.includes("SyntaxError") || output.includes("invalid syntax") || output.includes("Unexpected token") || output.includes("Unexpected identifier")) {
|
|
162
|
-
throw new Error(`Syntax error: ${output.trim()}`);
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
output,
|
|
166
|
-
exitCode: 0,
|
|
167
|
-
language: effectiveRuntime
|
|
168
|
-
};
|
|
169
|
-
} catch (error) {
|
|
170
|
-
if (error instanceof Error && error.message.includes("Syntax error")) {
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
throw new Error(
|
|
174
|
-
`CodeSandbox execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
108
|
runCommand: async (sandbox, command, options) => {
|
|
179
109
|
const startTime = Date.now();
|
|
180
110
|
try {
|
|
@@ -184,53 +114,30 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
184
114
|
const envPrefix = Object.entries(options.env).map(([k, v]) => `${k}="${(0, import_provider.escapeShellArg)(v)}"`).join(" ");
|
|
185
115
|
fullCommand = `${envPrefix} ${fullCommand}`;
|
|
186
116
|
}
|
|
187
|
-
if (options?.cwd) {
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
if (options?.background) {
|
|
191
|
-
fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
192
|
-
}
|
|
117
|
+
if (options?.cwd) fullCommand = `cd "${(0, import_provider.escapeShellArg)(options.cwd)}" && ${fullCommand}`;
|
|
118
|
+
if (options?.background) fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
193
119
|
const output = await client.commands.run(fullCommand);
|
|
194
|
-
return {
|
|
195
|
-
stdout: output,
|
|
196
|
-
stderr: "",
|
|
197
|
-
exitCode: 0,
|
|
198
|
-
durationMs: Date.now() - startTime
|
|
199
|
-
};
|
|
120
|
+
return { stdout: output, stderr: "", exitCode: 0, durationMs: Date.now() - startTime };
|
|
200
121
|
} catch (error) {
|
|
201
|
-
return {
|
|
202
|
-
stdout: "",
|
|
203
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
204
|
-
exitCode: 127,
|
|
205
|
-
durationMs: Date.now() - startTime
|
|
206
|
-
};
|
|
122
|
+
return { stdout: "", stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };
|
|
207
123
|
}
|
|
208
124
|
},
|
|
209
|
-
getInfo: async (sandbox) => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
timeout: 3e5,
|
|
218
|
-
metadata: {
|
|
219
|
-
cluster: sandbox.cluster,
|
|
220
|
-
bootupType: sandbox.bootupType,
|
|
221
|
-
isUpToDate: sandbox.isUpToDate
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
},
|
|
125
|
+
getInfo: async (sandbox) => ({
|
|
126
|
+
id: sandbox.id,
|
|
127
|
+
provider: "codesandbox",
|
|
128
|
+
status: "running",
|
|
129
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
130
|
+
timeout: 3e5,
|
|
131
|
+
metadata: { cluster: sandbox.cluster, bootupType: sandbox.bootupType, isUpToDate: sandbox.isUpToDate }
|
|
132
|
+
}),
|
|
225
133
|
getUrl: async (sandbox, options) => {
|
|
226
134
|
const protocol = options.protocol || "https";
|
|
227
135
|
return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;
|
|
228
136
|
},
|
|
229
|
-
// Filesystem operations using CodeSandbox client.fs API
|
|
230
137
|
filesystem: {
|
|
231
138
|
readFile: async (sandbox, path) => {
|
|
232
139
|
const client = await sandbox.connect();
|
|
233
|
-
return
|
|
140
|
+
return client.fs.readTextFile(path);
|
|
234
141
|
},
|
|
235
142
|
writeFile: async (sandbox, path, content) => {
|
|
236
143
|
const client = await sandbox.connect();
|
|
@@ -264,73 +171,43 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
264
171
|
await client.fs.remove(path);
|
|
265
172
|
}
|
|
266
173
|
},
|
|
267
|
-
|
|
268
|
-
getInstance: (sandbox) => {
|
|
269
|
-
return sandbox;
|
|
270
|
-
}
|
|
174
|
+
getInstance: (sandbox) => sandbox
|
|
271
175
|
},
|
|
272
176
|
snapshot: {
|
|
273
177
|
create: async (config, sandboxId, options) => {
|
|
274
178
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
275
|
-
if (!apiKey)
|
|
276
|
-
throw new Error(
|
|
277
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
278
|
-
);
|
|
279
|
-
}
|
|
179
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
280
180
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
281
181
|
try {
|
|
282
182
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
283
183
|
await sandbox.hibernate();
|
|
284
|
-
return {
|
|
285
|
-
id: sandbox.id,
|
|
286
|
-
provider: "codesandbox",
|
|
287
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
288
|
-
metadata: {
|
|
289
|
-
name: options?.name,
|
|
290
|
-
bootupType: sandbox.bootupType
|
|
291
|
-
}
|
|
292
|
-
};
|
|
184
|
+
return { id: sandbox.id, provider: "codesandbox", createdAt: /* @__PURE__ */ new Date(), metadata: { name: options?.name, bootupType: sandbox.bootupType } };
|
|
293
185
|
} catch (error) {
|
|
294
|
-
throw new Error(
|
|
295
|
-
`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`
|
|
296
|
-
);
|
|
186
|
+
throw new Error(`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`);
|
|
297
187
|
}
|
|
298
188
|
},
|
|
299
189
|
list: async (_config) => {
|
|
300
|
-
throw new Error(
|
|
301
|
-
`CodeSandbox provider does not support listing snapshots. Use the dashboard to manage snapshots.`
|
|
302
|
-
);
|
|
190
|
+
throw new Error(`CodeSandbox provider does not support listing snapshots.`);
|
|
303
191
|
},
|
|
304
192
|
delete: async (config, snapshotId) => {
|
|
305
193
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
306
|
-
if (!apiKey)
|
|
307
|
-
throw new Error(
|
|
308
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
309
|
-
);
|
|
310
|
-
}
|
|
194
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
311
195
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
312
196
|
try {
|
|
313
197
|
await sdk.sandboxes.shutdown(snapshotId);
|
|
314
|
-
} catch
|
|
198
|
+
} catch {
|
|
315
199
|
}
|
|
316
200
|
}
|
|
317
201
|
},
|
|
318
|
-
// Templates in CodeSandbox are handled via templateId on create
|
|
319
202
|
template: {
|
|
320
203
|
create: async (_config, _options) => {
|
|
321
|
-
throw new Error(
|
|
322
|
-
`CodeSandbox templates must be created via the CodeSandbox dashboard or CLI. Use templateId in sandbox.create() to specify a template.`
|
|
323
|
-
);
|
|
204
|
+
throw new Error(`CodeSandbox templates must be created via the dashboard.`);
|
|
324
205
|
},
|
|
325
206
|
list: async (_config) => {
|
|
326
|
-
throw new Error(
|
|
327
|
-
`CodeSandbox provider does not support listing templates via API. Use the dashboard to manage templates.`
|
|
328
|
-
);
|
|
207
|
+
throw new Error(`CodeSandbox provider does not support listing templates via API.`);
|
|
329
208
|
},
|
|
330
209
|
delete: async (_config, _templateId) => {
|
|
331
|
-
throw new Error(
|
|
332
|
-
`CodeSandbox templates must be deleted via the CodeSandbox dashboard or CLI.`
|
|
333
|
-
);
|
|
210
|
+
throw new Error(`CodeSandbox templates must be deleted via the dashboard.`);
|
|
334
211
|
}
|
|
335
212
|
}
|
|
336
213
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Codesandbox Provider - Factory-based Implementation\n * \n * Full-featured provider with filesystem support using the factory pattern.\n */\n\nimport { CodeSandbox } from '@codesandbox/sdk';\nimport type { Sandbox as CodesandboxSandbox } from '@codesandbox/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\n/**\n * Codesandbox-specific configuration options\n */\nexport interface CodesandboxConfig {\n /** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */\n apiKey?: string;\n /** Template to use for new sandboxes */\n templateId?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Codesandbox provider instance using the factory pattern\n */\nexport const codesandbox = defineProvider<CodesandboxSandbox, CodesandboxConfig, any, any>({\n name: 'codesandbox',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: CodesandboxConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n let sandbox: CodesandboxSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Resume existing CodeSandbox using sdk.sandboxes.resume()\n sandbox = await sdk.sandboxes.resume(options.sandboxId);\n sandboxId = options.sandboxId;\n } else if (options?.snapshotId) {\n // Resume from snapshot - in CodeSandbox, snapshots are hibernated sandboxes\n sandbox = await sdk.sandboxes.resume(options.snapshotId);\n sandboxId = options.snapshotId;\n } else {\n // Destructure known ComputeSDK fields, collect the rest for passthrough\n const {\n runtime: _runtime,\n timeout: _timeout,\n envs,\n name: _name,\n metadata: _metadata,\n templateId: optTemplateId,\n snapshotId: _snapshotId,\n sandboxId: _sandboxId,\n namespace: _namespace,\n directory: _directory,\n overlays: _overlays,\n servers: _servers,\n ...providerOptions\n } = options || {};\n\n // Create new CodeSandbox using sdk.sandboxes.create()\n const createOptions: any = {\n ...providerOptions, // Spread provider-specific options\n };\n\n // options.templateId takes precedence over config.templateId\n const templateId = optTemplateId || config.templateId;\n if (templateId) {\n createOptions.id = templateId;\n }\n\n // Remap envs to envVars\n if (envs && Object.keys(envs).length > 0) {\n createOptions.envVars = envs;\n }\n\n sandbox = await sdk.sandboxes.create(createOptions);\n sandboxId = sandbox.id;\n }\n\n return {\n sandbox,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`\n );\n }\n }\n throw new Error(\n `Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Resume existing sandbox using sdk.sandboxes.resume()\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n\n return {\n sandbox,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing sandboxes. CodeSandbox SDK does not provide a native list API. Consider using the CodeSandbox dashboard or implement your own tracking system.`\n );\n },\n\n destroy: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n await sdk.sandboxes.shutdown(sandboxId);\n } catch {\n // Ignore — may already be stopped\n }\n\n try {\n await sdk.sandboxes.delete(sandboxId);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (!message.includes('not found') && !message.includes('404')) {\n throw new Error(`Failed to delete CodeSandbox sandbox \"${sandboxId}\": ${message}`);\n }\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: CodesandboxSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const startTime = Date.now();\n\n try {\n // Connect to the sandbox client using sandbox.connect()\n const client = await sandbox.connect();\n\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n\n // Use base64 encoding for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n let command: string;\n\n if (effectiveRuntime === 'python') {\n // Execute Python code using client.commands.run()\n command = `echo \"${encoded}\" | base64 -d | python3`;\n } else {\n // Execute Node.js code using client.commands.run()\n command = `echo \"${encoded}\" | base64 -d | node`;\n }\n\n // Execute the command using CodeSandbox client.commands.run()\n // This returns the full output as a string\n const output = await client.commands.run(command);\n\n // Check for syntax errors in the output and throw them (similar to other providers)\n if (output.includes('SyntaxError') ||\n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier')) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n return {\n output: output,\n exitCode: 0,\n language: effectiveRuntime\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `CodeSandbox execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: CodesandboxSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n\n try {\n // Connect to the sandbox client using sandbox.connect()\n const client = await sandbox.connect();\n\n // Build command with options\n let fullCommand = command;\n\n // Handle environment variables\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(v)}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n // Handle working directory\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n // Handle background execution\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n // Execute command using CodeSandbox client.commands.run()\n const output = await client.commands.run(fullCommand);\n\n return {\n stdout: output,\n stderr: '',\n exitCode: 0,\n durationMs: Date.now() - startTime\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime\n };\n }\n },\n\n getInfo: async (sandbox: CodesandboxSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'codesandbox',\n runtime: 'node', // CodeSandbox default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n cluster: sandbox.cluster,\n bootupType: sandbox.bootupType,\n isUpToDate: sandbox.isUpToDate\n }\n };\n },\n\n getUrl: async (sandbox: CodesandboxSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const protocol = options.protocol || 'https';\n // CodeSandbox provides URLs in the format: https://{sandbox-id}.{cluster}.csb.app:{port}\n // Use the actual CodeSandbox URL format\n return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;\n },\n\n // Filesystem operations using CodeSandbox client.fs API\n filesystem: {\n readFile: async (sandbox: CodesandboxSandbox, path: string): Promise<string> => {\n // Connect to the sandbox client and use client.fs.readTextFile()\n const client = await sandbox.connect();\n return await client.fs.readTextFile(path);\n },\n\n writeFile: async (sandbox: CodesandboxSandbox, path: string, content: string): Promise<void> => {\n // Connect to the sandbox client and use client.fs.writeTextFile()\n const client = await sandbox.connect();\n await client.fs.writeTextFile(path, content);\n },\n\n mkdir: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n // CodeSandbox doesn't have a direct mkdir API, use commands to create directory\n const client = await sandbox.connect();\n await client.commands.run(`mkdir -p \"${path}\"`);\n },\n\n readdir: async (sandbox: CodesandboxSandbox, path: string): Promise<FileEntry[]> => {\n // Connect to the sandbox client and use client.fs.readdir()\n const client = await sandbox.connect();\n const entries = await client.fs.readdir(path);\n\n return entries.map((entry: any) => ({\n name: entry.name,\n type: entry.isDirectory ? 'directory' as const : 'file' as const,\n size: entry.size || 0,\n modified: entry.lastModified ? new Date(entry.lastModified) : new Date()\n }));\n },\n\n exists: async (sandbox: CodesandboxSandbox, path: string): Promise<boolean> => {\n // CodeSandbox doesn't have a direct exists API, use ls command to check\n const client = await sandbox.connect();\n try {\n await client.commands.run(`ls \"${path}\"`);\n return true;\n } catch {\n return false;\n }\n },\n\n remove: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n // Connect to the sandbox client and use client.fs.remove()\n const client = await sandbox.connect();\n await client.fs.remove(path);\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: CodesandboxSandbox): CodesandboxSandbox => {\n return sandbox;\n },\n\n },\n\n snapshot: {\n create: async (config: CodesandboxConfig, sandboxId: string, options?: { name?: string }) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Resume the sandbox first, then hibernate to create a snapshot\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n\n // Hibernate creates a checkpoint/snapshot of the sandbox\n // Cast to any to avoid type issues with SDK version\n await (sandbox as any).hibernate();\n\n // The hibernated sandbox becomes a snapshot we can fork\n return {\n id: sandbox.id,\n provider: 'codesandbox',\n createdAt: new Date(),\n metadata: {\n name: options?.name,\n bootupType: sandbox.bootupType\n }\n };\n } catch (error) {\n throw new Error(\n `Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing snapshots. Use the dashboard to manage snapshots.`\n );\n },\n\n delete: async (config: CodesandboxConfig, snapshotId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Shutdown the snapshot (hibernated sandbox)\n await sdk.sandboxes.shutdown(snapshotId);\n } catch (error) {\n // Ignore if not found\n }\n }\n },\n\n // Templates in CodeSandbox are handled via templateId on create\n template: {\n create: async (_config: CodesandboxConfig, _options: { name: string }) => {\n throw new Error(\n `CodeSandbox templates must be created via the CodeSandbox dashboard or CLI. Use templateId in sandbox.create() to specify a template.`\n );\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing templates via API. Use the dashboard to manage templates.`\n );\n },\n\n delete: async (_config: CodesandboxConfig, _templateId: string) => {\n throw new Error(\n `CodeSandbox templates must be deleted via the CodeSandbox dashboard or CLI.`\n );\n }\n }\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,iBAA4B;AAE5B,sBAA+C;AAqBxC,IAAM,kBAAc,gCAAgE;AAAA,EACzF,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,OAAO,QAA2B,YAAmC;AAE3E,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAEhG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,MAAM,IAAI,uBAAY,MAAM;AAElC,YAAI;AACF,cAAI;AACJ,cAAI;AAEJ,cAAI,SAAS,WAAW;AAEtB,sBAAU,MAAM,IAAI,UAAU,OAAO,QAAQ,SAAS;AACtD,wBAAY,QAAQ;AAAA,UACtB,WAAW,SAAS,YAAY;AAE9B,sBAAU,MAAM,IAAI,UAAU,OAAO,QAAQ,UAAU;AACvD,wBAAY,QAAQ;AAAA,UACtB,OAAO;AAEL,kBAAM;AAAA,cACJ,SAAS;AAAA,cACT,SAAS;AAAA,cACT;AAAA,cACA,MAAM;AAAA,cACN,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,YAAY;AAAA,cACZ,WAAW;AAAA,cACX,WAAW;AAAA,cACX,WAA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AQ;AAAA,YACtB;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,gBAAM,IAAI;AAAA,YACR,0CAA0C,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,UAClG;AAAA,QACF;AAAA,MACF;AAAA,MAEA,MAAM,OAAO,YAA+B;AAC1C,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,MAEA,QAAQ,OAAO,QAA2B,eAAuB;AAC/D,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAEhG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,MAAM,IAAI,uBAAY,MAAM;AAElC,YAAI;AAEF,gBAAM,IAAI,UAAU,SAAS,UAAU;AAAA,QACzC,SAAS,OAAO;AAAA,QAEhB;AAAA,MACF;AAAA,IACF;AAAA;AAAA,IAGA,UAAU;AAAA,MACR,QAAQ,OAAO,SAA4B,aAA+B;AACxE,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,MAEA,MAAM,OAAO,YAA+B;AAC1C,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,MAEA,QAAQ,OAAO,SAA4B,gBAAwB;AACjE,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Codesandbox Provider - Factory-based Implementation\n */\n\nimport { CodeSandbox } from '@codesandbox/sdk';\nimport type { Sandbox as CodesandboxSandbox } from '@codesandbox/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nimport type { CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\ntype HibernateCapableSandbox = CodesandboxSandbox & { hibernate: () => Promise<void>; };\n\nexport interface CodesandboxConfig {\n /** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */\n apiKey?: string;\n /** Template to use for new sandboxes */\n templateId?: string;\n /** Default runtime environment (e.g. 'node', 'python') */\n runtime?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\nexport const codesandbox = defineProvider<CodesandboxSandbox, CodesandboxConfig, any, any>({\n name: 'codesandbox',\n methods: {\n sandbox: {\n create: async (config: CodesandboxConfig, options?: CreateSandboxOptions) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) {\n throw new Error(`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`);\n }\n const sdk = new CodeSandbox(apiKey);\n try {\n let sandbox: CodesandboxSandbox;\n let sandboxId: string;\n if (options?.snapshotId) {\n sandbox = await sdk.sandboxes.resume(options.snapshotId);\n sandboxId = options.snapshotId;\n } else {\n const {\n timeout: _timeout, envs, name: _name, metadata: _metadata,\n templateId: optTemplateId, snapshotId: _snapshotId, sandboxId: _sandboxId,\n namespace: _namespace, directory: _directory, ...providerOptions\n } = options || {};\n const createOptions: any = { ...providerOptions };\n const templateId = optTemplateId || config.templateId;\n if (templateId) createOptions.id = templateId;\n if (envs && Object.keys(envs).length > 0) createOptions.envVars = envs;\n sandbox = await sdk.sandboxes.create(createOptions);\n sandboxId = sandbox.id;\n }\n return { sandbox, sandboxId };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable.`);\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`);\n }\n }\n throw new Error(`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n getById: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try {\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n return { sandbox, sandboxId };\n } catch { return null; }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(`CodeSandbox provider does not support listing sandboxes.`);\n },\n\n destroy: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try { await sdk.sandboxes.shutdown(sandboxId); } catch { /* ignore */ }\n try {\n await sdk.sandboxes.delete(sandboxId);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (!message.includes('not found') && !message.includes('404')) {\n throw new Error(`Failed to delete CodeSandbox sandbox \"${sandboxId}\": ${message}`);\n }\n }\n },\n\n runCommand: async (sandbox: CodesandboxSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const client = await sandbox.connect();\n let fullCommand = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env).map(([k, v]) => `${k}=\"${escapeShellArg(v)}\"`).join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n if (options?.cwd) fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n if (options?.background) fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n const output = await client.commands.run(fullCommand);\n return { stdout: output, stderr: '', exitCode: 0, durationMs: Date.now() - startTime };\n } catch (error) {\n return { stdout: '', stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };\n }\n },\n\n getInfo: async (sandbox: CodesandboxSandbox): Promise<SandboxInfo> => ({\n id: sandbox.id,\n provider: 'codesandbox',\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: { cluster: sandbox.cluster, bootupType: sandbox.bootupType, isUpToDate: sandbox.isUpToDate }\n }),\n\n getUrl: async (sandbox: CodesandboxSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const protocol = options.protocol || 'https';\n return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;\n },\n\n filesystem: {\n readFile: async (sandbox: CodesandboxSandbox, path: string): Promise<string> => {\n const client = await sandbox.connect();\n return client.fs.readTextFile(path);\n },\n writeFile: async (sandbox: CodesandboxSandbox, path: string, content: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.fs.writeTextFile(path, content);\n },\n mkdir: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.commands.run(`mkdir -p \"${path}\"`);\n },\n readdir: async (sandbox: CodesandboxSandbox, path: string): Promise<FileEntry[]> => {\n const client = await sandbox.connect();\n const entries = await client.fs.readdir(path);\n return entries.map((entry: any) => ({\n name: entry.name,\n type: entry.isDirectory ? 'directory' as const : 'file' as const,\n size: entry.size || 0,\n modified: entry.lastModified ? new Date(entry.lastModified) : new Date()\n }));\n },\n exists: async (sandbox: CodesandboxSandbox, path: string): Promise<boolean> => {\n const client = await sandbox.connect();\n try { await client.commands.run(`ls \"${path}\"`); return true; } catch { return false; }\n },\n remove: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.fs.remove(path);\n }\n },\n\n getInstance: (sandbox: CodesandboxSandbox): CodesandboxSandbox => sandbox,\n },\n\n snapshot: {\n create: async (config: CodesandboxConfig, sandboxId: string, options?: { name?: string }) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try {\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n await (sandbox as HibernateCapableSandbox).hibernate();\n return { id: sandbox.id, provider: 'codesandbox', createdAt: new Date(), metadata: { name: options?.name, bootupType: sandbox.bootupType } };\n } catch (error) {\n throw new Error(`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n list: async (_config: CodesandboxConfig) => { throw new Error(`CodeSandbox provider does not support listing snapshots.`); },\n delete: async (config: CodesandboxConfig, snapshotId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try { await sdk.sandboxes.shutdown(snapshotId); } catch { /* ignore */ }\n }\n },\n\n template: {\n create: async (_config: CodesandboxConfig, _options: { name: string }) => {\n throw new Error(`CodeSandbox templates must be created via the dashboard.`);\n },\n list: async (_config: CodesandboxConfig) => { throw new Error(`CodeSandbox provider does not support listing templates via API.`); },\n delete: async (_config: CodesandboxConfig, _templateId: string) => { throw new Error(`CodeSandbox templates must be deleted via the dashboard.`); }\n }\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAA4B;AAE5B,sBAA+C;AAiBxC,IAAM,kBAAc,gCAAgE;AAAA,EACzF,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAA2B,YAAmC;AAC3E,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAChG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI,MAAM,kGAAkG;AAAA,QACpH;AACA,cAAM,MAAM,IAAI,uBAAY,MAAM;AAClC,YAAI;AACF,cAAI;AACJ,cAAI;AACJ,cAAI,SAAS,YAAY;AACvB,sBAAU,MAAM,IAAI,UAAU,OAAO,QAAQ,UAAU;AACvD,wBAAY,QAAQ;AAAA,UACtB,OAAO;AACL,kBAAM;AAAA,cACJ,SAAS;AAAA,cAAU;AAAA,cAAM,MAAM;AAAA,cAAO,UAAU;AAAA,cAChD,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O,QAA2B,eAAuB;AAC/D,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAChG,YAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,8BAA8B;AAC3D,cAAM,MAAM,IAAI,uBAAY,MAAM;AAClC,YAAI;AAAE,gBAAM,IAAI,UAAU,SAAS,UAAU;AAAA,QAAG,QAAQ;AAAA,QAAe;AAAA,MACzE;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,QAAQ,OAAO,SAA4B,aAA+B;AACxE,cAAM,IAAI,MAAM,0DAA0D;AAAA,MAC5E;AAAA,MACA,MAAM,OAAO,YAA+B;AAAE,cAAM,IAAI,MAAM,kEAAkE;AAAA,MAAG;AAAA,MACnI,QAAQ,OAAO,SAA4B,gBAAwB;AAAE,cAAM,IAAI,MAAM,0DAA0D;AAAA,MAAG;AAAA,IACpJ;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -5,27 +5,20 @@ var codesandbox = defineProvider({
|
|
|
5
5
|
name: "codesandbox",
|
|
6
6
|
methods: {
|
|
7
7
|
sandbox: {
|
|
8
|
-
// Collection operations (compute.sandbox.*)
|
|
9
8
|
create: async (config, options) => {
|
|
10
9
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
11
10
|
if (!apiKey) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`
|
|
14
|
-
);
|
|
11
|
+
throw new Error(`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`);
|
|
15
12
|
}
|
|
16
13
|
const sdk = new CodeSandbox(apiKey);
|
|
17
14
|
try {
|
|
18
15
|
let sandbox;
|
|
19
16
|
let sandboxId;
|
|
20
|
-
if (options?.
|
|
21
|
-
sandbox = await sdk.sandboxes.resume(options.sandboxId);
|
|
22
|
-
sandboxId = options.sandboxId;
|
|
23
|
-
} else if (options?.snapshotId) {
|
|
17
|
+
if (options?.snapshotId) {
|
|
24
18
|
sandbox = await sdk.sandboxes.resume(options.snapshotId);
|
|
25
19
|
sandboxId = options.snapshotId;
|
|
26
20
|
} else {
|
|
27
21
|
const {
|
|
28
|
-
runtime: _runtime,
|
|
29
22
|
timeout: _timeout,
|
|
30
23
|
envs,
|
|
31
24
|
name: _name,
|
|
@@ -35,76 +28,45 @@ var codesandbox = defineProvider({
|
|
|
35
28
|
sandboxId: _sandboxId,
|
|
36
29
|
namespace: _namespace,
|
|
37
30
|
directory: _directory,
|
|
38
|
-
overlays: _overlays,
|
|
39
|
-
servers: _servers,
|
|
40
31
|
...providerOptions
|
|
41
32
|
} = options || {};
|
|
42
|
-
const createOptions = {
|
|
43
|
-
...providerOptions
|
|
44
|
-
// Spread provider-specific options
|
|
45
|
-
};
|
|
33
|
+
const createOptions = { ...providerOptions };
|
|
46
34
|
const templateId = optTemplateId || config.templateId;
|
|
47
|
-
if (templateId)
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (envs && Object.keys(envs).length > 0) {
|
|
51
|
-
createOptions.envVars = envs;
|
|
52
|
-
}
|
|
35
|
+
if (templateId) createOptions.id = templateId;
|
|
36
|
+
if (envs && Object.keys(envs).length > 0) createOptions.envVars = envs;
|
|
53
37
|
sandbox = await sdk.sandboxes.create(createOptions);
|
|
54
38
|
sandboxId = sandbox.id;
|
|
55
39
|
}
|
|
56
|
-
return {
|
|
57
|
-
sandbox,
|
|
58
|
-
sandboxId
|
|
59
|
-
};
|
|
40
|
+
return { sandbox, sandboxId };
|
|
60
41
|
} catch (error) {
|
|
61
42
|
if (error instanceof Error) {
|
|
62
43
|
if (error.message.includes("unauthorized") || error.message.includes("API key")) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`
|
|
65
|
-
);
|
|
44
|
+
throw new Error(`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable.`);
|
|
66
45
|
}
|
|
67
46
|
if (error.message.includes("quota") || error.message.includes("limit")) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`
|
|
70
|
-
);
|
|
47
|
+
throw new Error(`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`);
|
|
71
48
|
}
|
|
72
49
|
}
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
75
|
-
);
|
|
50
|
+
throw new Error(`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`);
|
|
76
51
|
}
|
|
77
52
|
},
|
|
78
53
|
getById: async (config, sandboxId) => {
|
|
79
54
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
80
|
-
if (!apiKey)
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
55
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
85
56
|
const sdk = new CodeSandbox(apiKey);
|
|
86
57
|
try {
|
|
87
58
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
88
|
-
return {
|
|
89
|
-
|
|
90
|
-
sandboxId
|
|
91
|
-
};
|
|
92
|
-
} catch (error) {
|
|
59
|
+
return { sandbox, sandboxId };
|
|
60
|
+
} catch {
|
|
93
61
|
return null;
|
|
94
62
|
}
|
|
95
63
|
},
|
|
96
64
|
list: async (_config) => {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`CodeSandbox provider does not support listing sandboxes. CodeSandbox SDK does not provide a native list API. Consider using the CodeSandbox dashboard or implement your own tracking system.`
|
|
99
|
-
);
|
|
65
|
+
throw new Error(`CodeSandbox provider does not support listing sandboxes.`);
|
|
100
66
|
},
|
|
101
67
|
destroy: async (config, sandboxId) => {
|
|
102
68
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
103
|
-
if (!apiKey)
|
|
104
|
-
throw new Error(
|
|
105
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
69
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
108
70
|
const sdk = new CodeSandbox(apiKey);
|
|
109
71
|
try {
|
|
110
72
|
await sdk.sandboxes.shutdown(sandboxId);
|
|
@@ -119,38 +81,6 @@ var codesandbox = defineProvider({
|
|
|
119
81
|
}
|
|
120
82
|
}
|
|
121
83
|
},
|
|
122
|
-
// Instance operations (sandbox.*)
|
|
123
|
-
runCode: async (sandbox, code, runtime) => {
|
|
124
|
-
const startTime = Date.now();
|
|
125
|
-
try {
|
|
126
|
-
const client = await sandbox.connect();
|
|
127
|
-
const effectiveRuntime = runtime || // Strong Python indicators
|
|
128
|
-
(code.includes("print(") || code.includes("import ") || code.includes("def ") || code.includes("sys.") || code.includes("json.") || code.includes("__") || code.includes('f"') || code.includes("f'") || code.includes("raise ") ? "python" : "node");
|
|
129
|
-
const encoded = Buffer.from(code).toString("base64");
|
|
130
|
-
let command;
|
|
131
|
-
if (effectiveRuntime === "python") {
|
|
132
|
-
command = `echo "${encoded}" | base64 -d | python3`;
|
|
133
|
-
} else {
|
|
134
|
-
command = `echo "${encoded}" | base64 -d | node`;
|
|
135
|
-
}
|
|
136
|
-
const output = await client.commands.run(command);
|
|
137
|
-
if (output.includes("SyntaxError") || output.includes("invalid syntax") || output.includes("Unexpected token") || output.includes("Unexpected identifier")) {
|
|
138
|
-
throw new Error(`Syntax error: ${output.trim()}`);
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
output,
|
|
142
|
-
exitCode: 0,
|
|
143
|
-
language: effectiveRuntime
|
|
144
|
-
};
|
|
145
|
-
} catch (error) {
|
|
146
|
-
if (error instanceof Error && error.message.includes("Syntax error")) {
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
throw new Error(
|
|
150
|
-
`CodeSandbox execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
84
|
runCommand: async (sandbox, command, options) => {
|
|
155
85
|
const startTime = Date.now();
|
|
156
86
|
try {
|
|
@@ -160,53 +90,30 @@ var codesandbox = defineProvider({
|
|
|
160
90
|
const envPrefix = Object.entries(options.env).map(([k, v]) => `${k}="${escapeShellArg(v)}"`).join(" ");
|
|
161
91
|
fullCommand = `${envPrefix} ${fullCommand}`;
|
|
162
92
|
}
|
|
163
|
-
if (options?.cwd) {
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
if (options?.background) {
|
|
167
|
-
fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
168
|
-
}
|
|
93
|
+
if (options?.cwd) fullCommand = `cd "${escapeShellArg(options.cwd)}" && ${fullCommand}`;
|
|
94
|
+
if (options?.background) fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
169
95
|
const output = await client.commands.run(fullCommand);
|
|
170
|
-
return {
|
|
171
|
-
stdout: output,
|
|
172
|
-
stderr: "",
|
|
173
|
-
exitCode: 0,
|
|
174
|
-
durationMs: Date.now() - startTime
|
|
175
|
-
};
|
|
96
|
+
return { stdout: output, stderr: "", exitCode: 0, durationMs: Date.now() - startTime };
|
|
176
97
|
} catch (error) {
|
|
177
|
-
return {
|
|
178
|
-
stdout: "",
|
|
179
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
180
|
-
exitCode: 127,
|
|
181
|
-
durationMs: Date.now() - startTime
|
|
182
|
-
};
|
|
98
|
+
return { stdout: "", stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };
|
|
183
99
|
}
|
|
184
100
|
},
|
|
185
|
-
getInfo: async (sandbox) => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
timeout: 3e5,
|
|
194
|
-
metadata: {
|
|
195
|
-
cluster: sandbox.cluster,
|
|
196
|
-
bootupType: sandbox.bootupType,
|
|
197
|
-
isUpToDate: sandbox.isUpToDate
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
},
|
|
101
|
+
getInfo: async (sandbox) => ({
|
|
102
|
+
id: sandbox.id,
|
|
103
|
+
provider: "codesandbox",
|
|
104
|
+
status: "running",
|
|
105
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
106
|
+
timeout: 3e5,
|
|
107
|
+
metadata: { cluster: sandbox.cluster, bootupType: sandbox.bootupType, isUpToDate: sandbox.isUpToDate }
|
|
108
|
+
}),
|
|
201
109
|
getUrl: async (sandbox, options) => {
|
|
202
110
|
const protocol = options.protocol || "https";
|
|
203
111
|
return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;
|
|
204
112
|
},
|
|
205
|
-
// Filesystem operations using CodeSandbox client.fs API
|
|
206
113
|
filesystem: {
|
|
207
114
|
readFile: async (sandbox, path) => {
|
|
208
115
|
const client = await sandbox.connect();
|
|
209
|
-
return
|
|
116
|
+
return client.fs.readTextFile(path);
|
|
210
117
|
},
|
|
211
118
|
writeFile: async (sandbox, path, content) => {
|
|
212
119
|
const client = await sandbox.connect();
|
|
@@ -240,73 +147,43 @@ var codesandbox = defineProvider({
|
|
|
240
147
|
await client.fs.remove(path);
|
|
241
148
|
}
|
|
242
149
|
},
|
|
243
|
-
|
|
244
|
-
getInstance: (sandbox) => {
|
|
245
|
-
return sandbox;
|
|
246
|
-
}
|
|
150
|
+
getInstance: (sandbox) => sandbox
|
|
247
151
|
},
|
|
248
152
|
snapshot: {
|
|
249
153
|
create: async (config, sandboxId, options) => {
|
|
250
154
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
251
|
-
if (!apiKey)
|
|
252
|
-
throw new Error(
|
|
253
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
254
|
-
);
|
|
255
|
-
}
|
|
155
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
256
156
|
const sdk = new CodeSandbox(apiKey);
|
|
257
157
|
try {
|
|
258
158
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
259
159
|
await sandbox.hibernate();
|
|
260
|
-
return {
|
|
261
|
-
id: sandbox.id,
|
|
262
|
-
provider: "codesandbox",
|
|
263
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
264
|
-
metadata: {
|
|
265
|
-
name: options?.name,
|
|
266
|
-
bootupType: sandbox.bootupType
|
|
267
|
-
}
|
|
268
|
-
};
|
|
160
|
+
return { id: sandbox.id, provider: "codesandbox", createdAt: /* @__PURE__ */ new Date(), metadata: { name: options?.name, bootupType: sandbox.bootupType } };
|
|
269
161
|
} catch (error) {
|
|
270
|
-
throw new Error(
|
|
271
|
-
`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`
|
|
272
|
-
);
|
|
162
|
+
throw new Error(`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`);
|
|
273
163
|
}
|
|
274
164
|
},
|
|
275
165
|
list: async (_config) => {
|
|
276
|
-
throw new Error(
|
|
277
|
-
`CodeSandbox provider does not support listing snapshots. Use the dashboard to manage snapshots.`
|
|
278
|
-
);
|
|
166
|
+
throw new Error(`CodeSandbox provider does not support listing snapshots.`);
|
|
279
167
|
},
|
|
280
168
|
delete: async (config, snapshotId) => {
|
|
281
169
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
282
|
-
if (!apiKey)
|
|
283
|
-
throw new Error(
|
|
284
|
-
`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`
|
|
285
|
-
);
|
|
286
|
-
}
|
|
170
|
+
if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);
|
|
287
171
|
const sdk = new CodeSandbox(apiKey);
|
|
288
172
|
try {
|
|
289
173
|
await sdk.sandboxes.shutdown(snapshotId);
|
|
290
|
-
} catch
|
|
174
|
+
} catch {
|
|
291
175
|
}
|
|
292
176
|
}
|
|
293
177
|
},
|
|
294
|
-
// Templates in CodeSandbox are handled via templateId on create
|
|
295
178
|
template: {
|
|
296
179
|
create: async (_config, _options) => {
|
|
297
|
-
throw new Error(
|
|
298
|
-
`CodeSandbox templates must be created via the CodeSandbox dashboard or CLI. Use templateId in sandbox.create() to specify a template.`
|
|
299
|
-
);
|
|
180
|
+
throw new Error(`CodeSandbox templates must be created via the dashboard.`);
|
|
300
181
|
},
|
|
301
182
|
list: async (_config) => {
|
|
302
|
-
throw new Error(
|
|
303
|
-
`CodeSandbox provider does not support listing templates via API. Use the dashboard to manage templates.`
|
|
304
|
-
);
|
|
183
|
+
throw new Error(`CodeSandbox provider does not support listing templates via API.`);
|
|
305
184
|
},
|
|
306
185
|
delete: async (_config, _templateId) => {
|
|
307
|
-
throw new Error(
|
|
308
|
-
`CodeSandbox templates must be deleted via the CodeSandbox dashboard or CLI.`
|
|
309
|
-
);
|
|
186
|
+
throw new Error(`CodeSandbox templates must be deleted via the dashboard.`);
|
|
310
187
|
}
|
|
311
188
|
}
|
|
312
189
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Codesandbox Provider - Factory-based Implementation\n * \n * Full-featured provider with filesystem support using the factory pattern.\n */\n\nimport { CodeSandbox } from '@codesandbox/sdk';\nimport type { Sandbox as CodesandboxSandbox } from '@codesandbox/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\n/**\n * Codesandbox-specific configuration options\n */\nexport interface CodesandboxConfig {\n /** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */\n apiKey?: string;\n /** Template to use for new sandboxes */\n templateId?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Codesandbox provider instance using the factory pattern\n */\nexport const codesandbox = defineProvider<CodesandboxSandbox, CodesandboxConfig, any, any>({\n name: 'codesandbox',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: CodesandboxConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n let sandbox: CodesandboxSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Resume existing CodeSandbox using sdk.sandboxes.resume()\n sandbox = await sdk.sandboxes.resume(options.sandboxId);\n sandboxId = options.sandboxId;\n } else if (options?.snapshotId) {\n // Resume from snapshot - in CodeSandbox, snapshots are hibernated sandboxes\n sandbox = await sdk.sandboxes.resume(options.snapshotId);\n sandboxId = options.snapshotId;\n } else {\n // Destructure known ComputeSDK fields, collect the rest for passthrough\n const {\n runtime: _runtime,\n timeout: _timeout,\n envs,\n name: _name,\n metadata: _metadata,\n templateId: optTemplateId,\n snapshotId: _snapshotId,\n sandboxId: _sandboxId,\n namespace: _namespace,\n directory: _directory,\n overlays: _overlays,\n servers: _servers,\n ...providerOptions\n } = options || {};\n\n // Create new CodeSandbox using sdk.sandboxes.create()\n const createOptions: any = {\n ...providerOptions, // Spread provider-specific options\n };\n\n // options.templateId takes precedence over config.templateId\n const templateId = optTemplateId || config.templateId;\n if (templateId) {\n createOptions.id = templateId;\n }\n\n // Remap envs to envVars\n if (envs && Object.keys(envs).length > 0) {\n createOptions.envVars = envs;\n }\n\n sandbox = await sdk.sandboxes.create(createOptions);\n sandboxId = sandbox.id;\n }\n\n return {\n sandbox,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable. Get your API key from https://codesandbox.io/t/api`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`\n );\n }\n }\n throw new Error(\n `Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Resume existing sandbox using sdk.sandboxes.resume()\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n\n return {\n sandbox,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing sandboxes. CodeSandbox SDK does not provide a native list API. Consider using the CodeSandbox dashboard or implement your own tracking system.`\n );\n },\n\n destroy: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n await sdk.sandboxes.shutdown(sandboxId);\n } catch {\n // Ignore — may already be stopped\n }\n\n try {\n await sdk.sandboxes.delete(sandboxId);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (!message.includes('not found') && !message.includes('404')) {\n throw new Error(`Failed to delete CodeSandbox sandbox \"${sandboxId}\": ${message}`);\n }\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: CodesandboxSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const startTime = Date.now();\n\n try {\n // Connect to the sandbox client using sandbox.connect()\n const client = await sandbox.connect();\n\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n\n // Use base64 encoding for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n let command: string;\n\n if (effectiveRuntime === 'python') {\n // Execute Python code using client.commands.run()\n command = `echo \"${encoded}\" | base64 -d | python3`;\n } else {\n // Execute Node.js code using client.commands.run()\n command = `echo \"${encoded}\" | base64 -d | node`;\n }\n\n // Execute the command using CodeSandbox client.commands.run()\n // This returns the full output as a string\n const output = await client.commands.run(command);\n\n // Check for syntax errors in the output and throw them (similar to other providers)\n if (output.includes('SyntaxError') ||\n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier')) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n return {\n output: output,\n exitCode: 0,\n language: effectiveRuntime\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `CodeSandbox execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: CodesandboxSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n\n try {\n // Connect to the sandbox client using sandbox.connect()\n const client = await sandbox.connect();\n\n // Build command with options\n let fullCommand = command;\n\n // Handle environment variables\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(v)}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n // Handle working directory\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n // Handle background execution\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n // Execute command using CodeSandbox client.commands.run()\n const output = await client.commands.run(fullCommand);\n\n return {\n stdout: output,\n stderr: '',\n exitCode: 0,\n durationMs: Date.now() - startTime\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime\n };\n }\n },\n\n getInfo: async (sandbox: CodesandboxSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'codesandbox',\n runtime: 'node', // CodeSandbox default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n cluster: sandbox.cluster,\n bootupType: sandbox.bootupType,\n isUpToDate: sandbox.isUpToDate\n }\n };\n },\n\n getUrl: async (sandbox: CodesandboxSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const protocol = options.protocol || 'https';\n // CodeSandbox provides URLs in the format: https://{sandbox-id}.{cluster}.csb.app:{port}\n // Use the actual CodeSandbox URL format\n return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;\n },\n\n // Filesystem operations using CodeSandbox client.fs API\n filesystem: {\n readFile: async (sandbox: CodesandboxSandbox, path: string): Promise<string> => {\n // Connect to the sandbox client and use client.fs.readTextFile()\n const client = await sandbox.connect();\n return await client.fs.readTextFile(path);\n },\n\n writeFile: async (sandbox: CodesandboxSandbox, path: string, content: string): Promise<void> => {\n // Connect to the sandbox client and use client.fs.writeTextFile()\n const client = await sandbox.connect();\n await client.fs.writeTextFile(path, content);\n },\n\n mkdir: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n // CodeSandbox doesn't have a direct mkdir API, use commands to create directory\n const client = await sandbox.connect();\n await client.commands.run(`mkdir -p \"${path}\"`);\n },\n\n readdir: async (sandbox: CodesandboxSandbox, path: string): Promise<FileEntry[]> => {\n // Connect to the sandbox client and use client.fs.readdir()\n const client = await sandbox.connect();\n const entries = await client.fs.readdir(path);\n\n return entries.map((entry: any) => ({\n name: entry.name,\n type: entry.isDirectory ? 'directory' as const : 'file' as const,\n size: entry.size || 0,\n modified: entry.lastModified ? new Date(entry.lastModified) : new Date()\n }));\n },\n\n exists: async (sandbox: CodesandboxSandbox, path: string): Promise<boolean> => {\n // CodeSandbox doesn't have a direct exists API, use ls command to check\n const client = await sandbox.connect();\n try {\n await client.commands.run(`ls \"${path}\"`);\n return true;\n } catch {\n return false;\n }\n },\n\n remove: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n // Connect to the sandbox client and use client.fs.remove()\n const client = await sandbox.connect();\n await client.fs.remove(path);\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: CodesandboxSandbox): CodesandboxSandbox => {\n return sandbox;\n },\n\n },\n\n snapshot: {\n create: async (config: CodesandboxConfig, sandboxId: string, options?: { name?: string }) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Resume the sandbox first, then hibernate to create a snapshot\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n\n // Hibernate creates a checkpoint/snapshot of the sandbox\n // Cast to any to avoid type issues with SDK version\n await (sandbox as any).hibernate();\n\n // The hibernated sandbox becomes a snapshot we can fork\n return {\n id: sandbox.id,\n provider: 'codesandbox',\n createdAt: new Date(),\n metadata: {\n name: options?.name,\n bootupType: sandbox.bootupType\n }\n };\n } catch (error) {\n throw new Error(\n `Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing snapshots. Use the dashboard to manage snapshots.`\n );\n },\n\n delete: async (config: CodesandboxConfig, snapshotId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`\n );\n }\n\n const sdk = new CodeSandbox(apiKey);\n\n try {\n // Shutdown the snapshot (hibernated sandbox)\n await sdk.sandboxes.shutdown(snapshotId);\n } catch (error) {\n // Ignore if not found\n }\n }\n },\n\n // Templates in CodeSandbox are handled via templateId on create\n template: {\n create: async (_config: CodesandboxConfig, _options: { name: string }) => {\n throw new Error(\n `CodeSandbox templates must be created via the CodeSandbox dashboard or CLI. Use templateId in sandbox.create() to specify a template.`\n );\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(\n `CodeSandbox provider does not support listing templates via API. Use the dashboard to manage templates.`\n );\n },\n\n delete: async (_config: CodesandboxConfig, _templateId: string) => {\n throw new Error(\n `CodeSandbox templates must be deleted via the CodeSandbox dashboard or CLI.`\n );\n }\n }\n }\n});\n"],"mappings":";AAMA,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB,sBAAsB;AAqBxC,IAAM,cAAc,eAAgE;AAAA,EACzF,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,OAAO,QAA2B,YAAmC;AAE3E,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAEhG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF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,MACF;AAAA,MAEA,QAAQ,OAAO,SAA4B,gBAAwB;AACjE,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Codesandbox Provider - Factory-based Implementation\n */\n\nimport { CodeSandbox } from '@codesandbox/sdk';\nimport type { Sandbox as CodesandboxSandbox } from '@codesandbox/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nimport type { CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\ntype HibernateCapableSandbox = CodesandboxSandbox & { hibernate: () => Promise<void>; };\n\nexport interface CodesandboxConfig {\n /** CodeSandbox API key - if not provided, will fallback to CSB_API_KEY environment variable */\n apiKey?: string;\n /** Template to use for new sandboxes */\n templateId?: string;\n /** Default runtime environment (e.g. 'node', 'python') */\n runtime?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\nexport const codesandbox = defineProvider<CodesandboxSandbox, CodesandboxConfig, any, any>({\n name: 'codesandbox',\n methods: {\n sandbox: {\n create: async (config: CodesandboxConfig, options?: CreateSandboxOptions) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) {\n throw new Error(`Missing CodeSandbox API key. Provide 'apiKey' in config or set CSB_API_KEY environment variable.`);\n }\n const sdk = new CodeSandbox(apiKey);\n try {\n let sandbox: CodesandboxSandbox;\n let sandboxId: string;\n if (options?.snapshotId) {\n sandbox = await sdk.sandboxes.resume(options.snapshotId);\n sandboxId = options.snapshotId;\n } else {\n const {\n timeout: _timeout, envs, name: _name, metadata: _metadata,\n templateId: optTemplateId, snapshotId: _snapshotId, sandboxId: _sandboxId,\n namespace: _namespace, directory: _directory, ...providerOptions\n } = options || {};\n const createOptions: any = { ...providerOptions };\n const templateId = optTemplateId || config.templateId;\n if (templateId) createOptions.id = templateId;\n if (envs && Object.keys(envs).length > 0) createOptions.envVars = envs;\n sandbox = await sdk.sandboxes.create(createOptions);\n sandboxId = sandbox.id;\n }\n return { sandbox, sandboxId };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(`CodeSandbox authentication failed. Please check your CSB_API_KEY environment variable.`);\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(`CodeSandbox quota exceeded. Please check your usage at https://codesandbox.io/dashboard`);\n }\n }\n throw new Error(`Failed to create CodeSandbox sandbox: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n getById: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try {\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n return { sandbox, sandboxId };\n } catch { return null; }\n },\n\n list: async (_config: CodesandboxConfig) => {\n throw new Error(`CodeSandbox provider does not support listing sandboxes.`);\n },\n\n destroy: async (config: CodesandboxConfig, sandboxId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try { await sdk.sandboxes.shutdown(sandboxId); } catch { /* ignore */ }\n try {\n await sdk.sandboxes.delete(sandboxId);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (!message.includes('not found') && !message.includes('404')) {\n throw new Error(`Failed to delete CodeSandbox sandbox \"${sandboxId}\": ${message}`);\n }\n }\n },\n\n runCommand: async (sandbox: CodesandboxSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const client = await sandbox.connect();\n let fullCommand = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env).map(([k, v]) => `${k}=\"${escapeShellArg(v)}\"`).join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n if (options?.cwd) fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n if (options?.background) fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n const output = await client.commands.run(fullCommand);\n return { stdout: output, stderr: '', exitCode: 0, durationMs: Date.now() - startTime };\n } catch (error) {\n return { stdout: '', stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };\n }\n },\n\n getInfo: async (sandbox: CodesandboxSandbox): Promise<SandboxInfo> => ({\n id: sandbox.id,\n provider: 'codesandbox',\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: { cluster: sandbox.cluster, bootupType: sandbox.bootupType, isUpToDate: sandbox.isUpToDate }\n }),\n\n getUrl: async (sandbox: CodesandboxSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const protocol = options.protocol || 'https';\n return `${protocol}://${sandbox.id}.${sandbox.cluster}.csb.app:${options.port}`;\n },\n\n filesystem: {\n readFile: async (sandbox: CodesandboxSandbox, path: string): Promise<string> => {\n const client = await sandbox.connect();\n return client.fs.readTextFile(path);\n },\n writeFile: async (sandbox: CodesandboxSandbox, path: string, content: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.fs.writeTextFile(path, content);\n },\n mkdir: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.commands.run(`mkdir -p \"${path}\"`);\n },\n readdir: async (sandbox: CodesandboxSandbox, path: string): Promise<FileEntry[]> => {\n const client = await sandbox.connect();\n const entries = await client.fs.readdir(path);\n return entries.map((entry: any) => ({\n name: entry.name,\n type: entry.isDirectory ? 'directory' as const : 'file' as const,\n size: entry.size || 0,\n modified: entry.lastModified ? new Date(entry.lastModified) : new Date()\n }));\n },\n exists: async (sandbox: CodesandboxSandbox, path: string): Promise<boolean> => {\n const client = await sandbox.connect();\n try { await client.commands.run(`ls \"${path}\"`); return true; } catch { return false; }\n },\n remove: async (sandbox: CodesandboxSandbox, path: string): Promise<void> => {\n const client = await sandbox.connect();\n await client.fs.remove(path);\n }\n },\n\n getInstance: (sandbox: CodesandboxSandbox): CodesandboxSandbox => sandbox,\n },\n\n snapshot: {\n create: async (config: CodesandboxConfig, sandboxId: string, options?: { name?: string }) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try {\n const sandbox = await sdk.sandboxes.resume(sandboxId);\n await (sandbox as HibernateCapableSandbox).hibernate();\n return { id: sandbox.id, provider: 'codesandbox', createdAt: new Date(), metadata: { name: options?.name, bootupType: sandbox.bootupType } };\n } catch (error) {\n throw new Error(`Failed to create CodeSandbox snapshot: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n list: async (_config: CodesandboxConfig) => { throw new Error(`CodeSandbox provider does not support listing snapshots.`); },\n delete: async (config: CodesandboxConfig, snapshotId: string) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.CSB_API_KEY) || '';\n if (!apiKey) throw new Error(`Missing CodeSandbox API key.`);\n const sdk = new CodeSandbox(apiKey);\n try { await sdk.sandboxes.shutdown(snapshotId); } catch { /* ignore */ }\n }\n },\n\n template: {\n create: async (_config: CodesandboxConfig, _options: { name: string }) => {\n throw new Error(`CodeSandbox templates must be created via the dashboard.`);\n },\n list: async (_config: CodesandboxConfig) => { throw new Error(`CodeSandbox provider does not support listing templates via API.`); },\n delete: async (_config: CodesandboxConfig, _templateId: string) => { throw new Error(`CodeSandbox templates must be deleted via the dashboard.`); }\n }\n }\n});\n"],"mappings":";AAIA,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB,sBAAsB;AAiBxC,IAAM,cAAc,eAAgE;AAAA,EACzF,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAA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AAM,IAAI,UAAU,OAAO,SAAS;AACpD,gBAAO,QAAoC,UAAU;AACrD,iBAAO,EAAE,IAAI,QAAQ,IAAI,UAAU,eAAe,WAAW,oBAAI,KAAK,GAAG,UAAU,EAAE,MAAM,SAAS,MAAM,YAAY,QAAQ,WAAW,EAAE;AAAA,QAC7I,SAAS,OAAO;AACd,gBAAM,IAAI,MAAM,0CAA0C,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,QACpH;AAAA,MACF;AAAA,MACA,MAAM,OAAO,YAA+B;AAAE,cAAM,IAAI,MAAM,0DAA0D;AAAA,MAAG;AAAA,MAC3H,QAAQ,OAAO,QAA2B,eAAuB;AAC/D,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,eAAgB;AAChG,YAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,8BAA8B;AAC3D,cAAM,MAAM,IAAI,YAAY,MAAM;AAClC,YAAI;AAAE,gBAAM,IAAI,UAAU,SAAS,UAAU;AAAA,QAAG,QAAQ;AAAA,QAAe;AAAA,MACzE;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,QAAQ,OAAO,SAA4B,aAA+B;AACxE,cAAM,IAAI,MAAM,0DAA0D;AAAA,MAC5E;AAAA,MACA,MAAM,OAAO,YAA+B;AAAE,cAAM,IAAI,MAAM,kEAAkE;AAAA,MAAG;AAAA,MACnI,QAAQ,OAAO,SAA4B,gBAAwB;AAAE,cAAM,IAAI,MAAM,0DAA0D;AAAA,MAAG;AAAA,IACpJ;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/codesandbox",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.46",
|
|
4
4
|
"description": "CodeSandbox provider for ComputeSDK - fast browser-compatible sandboxes with npm and Python support",
|
|
5
5
|
"author": "Garrison",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@codesandbox/sdk": "^2.4.2",
|
|
22
|
-
"@computesdk/provider": "
|
|
23
|
-
"computesdk": "
|
|
22
|
+
"@computesdk/provider": "2.0.0",
|
|
23
|
+
"computesdk": "4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"computesdk",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"tsup": "^8.0.0",
|
|
52
52
|
"typescript": "^5.0.0",
|
|
53
53
|
"vitest": "^1.0.0",
|
|
54
|
-
"@computesdk/test-utils": "
|
|
54
|
+
"@computesdk/test-utils": "2.0.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsup",
|