@computesdk/codesandbox 1.5.59 → 1.5.61
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 +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ const compute = codesandbox({
|
|
|
28
28
|
timeout: 600000 // 10 minutes
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const sandbox = await compute.
|
|
31
|
+
const sandbox = await compute.instances.create();
|
|
32
32
|
|
|
33
33
|
const result = await sandbox.runCommand('node -e "console.log(\"Hello from CodeSandbox!\")"');
|
|
34
34
|
console.log(result.stdout);
|
|
@@ -143,10 +143,10 @@ const info = await sandbox.getInfo();
|
|
|
143
143
|
console.log(info.id, info.provider, info.status);
|
|
144
144
|
|
|
145
145
|
// Resume existing sandbox
|
|
146
|
-
const existing = await compute.
|
|
146
|
+
const existing = await compute.instances.getById('sandbox-id');
|
|
147
147
|
|
|
148
148
|
// Hibernate sandbox (saves state)
|
|
149
|
-
await compute.
|
|
149
|
+
await compute.instances.destroy('sandbox-id'); // Actually hibernates
|
|
150
150
|
|
|
151
151
|
// Note: CodeSandbox doesn't support listing all sandboxes
|
|
152
152
|
// Each sandbox is managed individually
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_provider = require("@computesdk/provider");
|
|
|
28
28
|
var codesandbox = (0, import_provider.defineProvider)({
|
|
29
29
|
name: "codesandbox",
|
|
30
30
|
methods: {
|
|
31
|
-
|
|
31
|
+
instances: {
|
|
32
32
|
create: async (config, options) => {
|
|
33
33
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
34
34
|
if (!apiKey) {
|
|
@@ -61,7 +61,7 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
61
61
|
sandbox = await sdk.sandboxes.create(createOptions);
|
|
62
62
|
sandboxId = sandbox.id;
|
|
63
63
|
}
|
|
64
|
-
return { sandbox, sandboxId };
|
|
64
|
+
return { instance: sandbox, instanceId: sandboxId };
|
|
65
65
|
} catch (error) {
|
|
66
66
|
if (error instanceof Error) {
|
|
67
67
|
if (error.message.includes("unauthorized") || error.message.includes("API key")) {
|
|
@@ -80,7 +80,7 @@ var codesandbox = (0, import_provider.defineProvider)({
|
|
|
80
80
|
const sdk = new import_sdk.CodeSandbox(apiKey);
|
|
81
81
|
try {
|
|
82
82
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
83
|
-
return { sandbox, sandboxId };
|
|
83
|
+
return { instance: sandbox, instanceId: sandboxId };
|
|
84
84
|
} catch {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,YAAY;AAAA,cAAe,YAAY;AAAA,cAAa,WAAW;AAAA,cAC/D,WAAW;AAAA,cAAY,WAAW;AAAA,cAAY,GAAG;AAAA,YACnD,IAAI,WAAW,CAAC;AAChB,kBAAM,gBAAqB,EAAE,GAAG,gBAAgB;AAChD,kBAAM,aAAa,iBAAiB,OAAO;AAC3C,gBAAI,WAAY,eAAc,KAAK;AACnC,gBAAI,QAAQ,OAAO,KAAK,IAAI,EAAE,SAAS,EAAG,eAAc,UAAU;AAClE,sBAAU,MAAM,IAAI,UAAU,OAAO,aAAa;AAClD,wBAAY,QAAQ;AAAA,UACtB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5E;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":[]}
|
|
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, InstanceInfo, CreateInstanceOptions, 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 instances: {\n create: async (config: CodesandboxConfig, options?: CreateInstanceOptions) => {\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 { instance: sandbox, instanceId: 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 { instance: sandbox, instanceId: 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<InstanceInfo> => ({\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;AAE5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
|
|
4
4
|
var codesandbox = defineProvider({
|
|
5
5
|
name: "codesandbox",
|
|
6
6
|
methods: {
|
|
7
|
-
|
|
7
|
+
instances: {
|
|
8
8
|
create: async (config, options) => {
|
|
9
9
|
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.CSB_API_KEY || "";
|
|
10
10
|
if (!apiKey) {
|
|
@@ -37,7 +37,7 @@ var codesandbox = defineProvider({
|
|
|
37
37
|
sandbox = await sdk.sandboxes.create(createOptions);
|
|
38
38
|
sandboxId = sandbox.id;
|
|
39
39
|
}
|
|
40
|
-
return { sandbox, sandboxId };
|
|
40
|
+
return { instance: sandbox, instanceId: sandboxId };
|
|
41
41
|
} catch (error) {
|
|
42
42
|
if (error instanceof Error) {
|
|
43
43
|
if (error.message.includes("unauthorized") || error.message.includes("API key")) {
|
|
@@ -56,7 +56,7 @@ var codesandbox = defineProvider({
|
|
|
56
56
|
const sdk = new CodeSandbox(apiKey);
|
|
57
57
|
try {
|
|
58
58
|
const sandbox = await sdk.sandboxes.resume(sandboxId);
|
|
59
|
-
return { sandbox, sandboxId };
|
|
59
|
+
return { instance: sandbox, instanceId: sandboxId };
|
|
60
60
|
} catch {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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,YAAY,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,YAAY;AAAA,cAAe,YAAY;AAAA,cAAa,WAAW;AAAA,cAC/D,WAAW;AAAA,cAAY,WAAW;AAAA,cAAY,GAAG;AAAA,YACnD,IAAI,WAAW,CAAC;AAChB,kBAAM,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AAM,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":[]}
|
|
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, InstanceInfo, CreateInstanceOptions, 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 instances: {\n create: async (config: CodesandboxConfig, options?: CreateInstanceOptions) => {\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 { instance: sandbox, instanceId: 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 { instance: sandbox, instanceId: 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<InstanceInfo> => ({\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,WAAW;AAAA,MACT,QAAQ,OAAO,QAA2B,YAAoC;AAC5E,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,YAAY,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,YAAY;AAAA,cAAe,YAAY;AAAA,cAAa,WAAW;AAAA,cAC/D,WAAW;AAAA,cAAY,WAAW;AAAA,cAAY,GAAG;AAAA,YACnD,IAAI,WAAW,CAAC;AAChB,kBAAM,gBAAqB,EAAE,GAAG,gBAAgB;AAChD,kBAAM,aAAa,iBAAiB,OAAO;AAC3C,gBAAI,WAAY,eAAc,KAAK;AACnC,gBAAI,QAAQ,OAAO,KAAK,IAAI,EAAE,SAAS,EAAG,eAAc,UAAU;AAClE,sBAAU,MAAM,IAAI,UAAU,OAAO,aAAa;AAClD,wBAAY,QAAQ;AAAA,UACtB;AACA,iBAAO,EAAE,UAAU,SAAS,YAAY,UAAU;AAAA,QACpD,SAAS,OAAO;AACd,cAAI,iBAAiB,OAAO;AAC1B,gBAAI,MAAM,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AAO,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.61",
|
|
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": "2.1.
|
|
23
|
-
"computesdk": "4.1.
|
|
22
|
+
"@computesdk/provider": "2.1.14",
|
|
23
|
+
"computesdk": "4.1.12"
|
|
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": "2.0.
|
|
54
|
+
"@computesdk/test-utils": "2.0.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsup",
|