@computesdk/runloop 1.3.49 → 1.3.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +44 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -25,22 +25,40 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
var import_api_client = require("@runloop/api-client");
|
|
27
27
|
var import_provider = require("@computesdk/provider");
|
|
28
|
+
var clientCache = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
function resolveApiKey(config) {
|
|
30
|
+
return config.apiKey || typeof process !== "undefined" && process.env?.RUNLOOP_API_KEY || "";
|
|
31
|
+
}
|
|
32
|
+
function getRunloopClient(config) {
|
|
33
|
+
const apiKey = resolveApiKey(config);
|
|
34
|
+
if (!apiKey) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const cached = clientCache.get(config);
|
|
40
|
+
if (cached) return cached;
|
|
41
|
+
const client = new import_api_client.RunloopSDK({
|
|
42
|
+
bearerToken: apiKey
|
|
43
|
+
});
|
|
44
|
+
clientCache.set(config, client);
|
|
45
|
+
return client;
|
|
46
|
+
}
|
|
47
|
+
function longPollOptions(timeoutMs) {
|
|
48
|
+
return timeoutMs ? { longPoll: { timeoutMs } } : void 0;
|
|
49
|
+
}
|
|
50
|
+
function optimisticTimeoutSeconds(timeoutMs) {
|
|
51
|
+
if (!timeoutMs) return 25;
|
|
52
|
+
return Math.max(1, Math.min(25, Math.ceil(timeoutMs / 1e3)));
|
|
53
|
+
}
|
|
28
54
|
var runloop = (0, import_provider.defineProvider)({
|
|
29
55
|
name: "runloop",
|
|
30
56
|
methods: {
|
|
31
57
|
sandbox: {
|
|
32
58
|
create: async (config, options) => {
|
|
33
|
-
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.RUNLOOP_API_KEY || "";
|
|
34
|
-
if (!apiKey) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
59
|
const timeout = config.timeout;
|
|
40
60
|
try {
|
|
41
|
-
const client =
|
|
42
|
-
bearerToken: apiKey
|
|
43
|
-
});
|
|
61
|
+
const client = getRunloopClient(config);
|
|
44
62
|
const {
|
|
45
63
|
timeout: optTimeout,
|
|
46
64
|
envs,
|
|
@@ -49,6 +67,7 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
49
67
|
templateId,
|
|
50
68
|
snapshotId,
|
|
51
69
|
sandboxId: optSandboxId,
|
|
70
|
+
ports: _ports,
|
|
52
71
|
namespace: _namespace,
|
|
53
72
|
directory: _directory,
|
|
54
73
|
...providerOptions
|
|
@@ -74,7 +93,8 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
const dbx = await client.api.devboxes.createAndAwaitRunning(
|
|
77
|
-
devboxParams
|
|
96
|
+
devboxParams,
|
|
97
|
+
longPollOptions(effectiveTimeout)
|
|
78
98
|
);
|
|
79
99
|
const runloopSandbox = {
|
|
80
100
|
...dbx,
|
|
@@ -91,9 +111,8 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
91
111
|
}
|
|
92
112
|
},
|
|
93
113
|
getById: async (config, sandboxId) => {
|
|
94
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
95
114
|
try {
|
|
96
|
-
const client =
|
|
115
|
+
const client = getRunloopClient(config);
|
|
97
116
|
const devbox = await client.api.devboxes.retrieve(sandboxId);
|
|
98
117
|
return {
|
|
99
118
|
sandbox: { ...devbox, client },
|
|
@@ -104,9 +123,8 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
104
123
|
}
|
|
105
124
|
},
|
|
106
125
|
list: async (config) => {
|
|
107
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
108
126
|
try {
|
|
109
|
-
const client =
|
|
127
|
+
const client = getRunloopClient(config);
|
|
110
128
|
const response = await client.api.devboxes.list();
|
|
111
129
|
const devboxes = response.devboxes || [];
|
|
112
130
|
return devboxes.map((devbox) => ({
|
|
@@ -118,9 +136,8 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
118
136
|
}
|
|
119
137
|
},
|
|
120
138
|
destroy: async (config, sandboxId) => {
|
|
121
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
122
139
|
try {
|
|
123
|
-
const client =
|
|
140
|
+
const client = getRunloopClient(config);
|
|
124
141
|
await client.api.devboxes.shutdown(sandboxId);
|
|
125
142
|
} catch {
|
|
126
143
|
}
|
|
@@ -142,8 +159,9 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
142
159
|
fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
143
160
|
}
|
|
144
161
|
const executionResult = await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {
|
|
145
|
-
command: fullCommand
|
|
146
|
-
|
|
162
|
+
command: fullCommand,
|
|
163
|
+
optimistic_timeout: optimisticTimeoutSeconds(options?.timeout)
|
|
164
|
+
}, longPollOptions(options?.timeout));
|
|
147
165
|
return {
|
|
148
166
|
stdout: executionResult.stdout || "",
|
|
149
167
|
stderr: executionResult.stderr || "",
|
|
@@ -191,9 +209,9 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
191
209
|
},
|
|
192
210
|
filesystem: {
|
|
193
211
|
readFile: async (sandbox, path, runCommand) => {
|
|
194
|
-
const result = await runCommand(sandbox, `
|
|
212
|
+
const result = await runCommand(sandbox, `test -f "${path}" && base64 < "${path}" | tr -d '\\n'`);
|
|
195
213
|
if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);
|
|
196
|
-
return result.stdout;
|
|
214
|
+
return Buffer.from(result.stdout, "base64").toString("utf8");
|
|
197
215
|
},
|
|
198
216
|
writeFile: async (sandbox, path, content, runCommand) => {
|
|
199
217
|
const encoded = Buffer.from(content).toString("base64");
|
|
@@ -233,50 +251,38 @@ var runloop = (0, import_provider.defineProvider)({
|
|
|
233
251
|
},
|
|
234
252
|
template: {
|
|
235
253
|
create: async (config, options) => {
|
|
236
|
-
const
|
|
237
|
-
if (!apiKey) throw new Error("Missing Runloop API key for blueprint template creation");
|
|
238
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
254
|
+
const client = getRunloopClient(config);
|
|
239
255
|
return client.api.blueprints.create(options);
|
|
240
256
|
},
|
|
241
257
|
list: async (config, options) => {
|
|
242
|
-
const
|
|
243
|
-
if (!apiKey) throw new Error("Missing Runloop API key for listing blueprint templates");
|
|
244
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
258
|
+
const client = getRunloopClient(config);
|
|
245
259
|
const listParams = {};
|
|
246
260
|
if (options?.limit) listParams.limit = options.limit;
|
|
247
261
|
const response = await client.api.blueprints.list(listParams);
|
|
248
262
|
return response.blueprints || [];
|
|
249
263
|
},
|
|
250
264
|
delete: async (config, blueprintId) => {
|
|
251
|
-
const
|
|
252
|
-
if (!apiKey) throw new Error("Missing Runloop API key for blueprint template deletion");
|
|
253
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
265
|
+
const client = getRunloopClient(config);
|
|
254
266
|
await client.api.blueprints.delete(blueprintId);
|
|
255
267
|
}
|
|
256
268
|
},
|
|
257
269
|
snapshot: {
|
|
258
270
|
create: async (config, sandboxId, options) => {
|
|
259
|
-
const
|
|
260
|
-
if (!apiKey) throw new Error("Missing Runloop API key for snapshot creation");
|
|
261
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
271
|
+
const client = getRunloopClient(config);
|
|
262
272
|
const snapshotParams = {};
|
|
263
273
|
if (options?.name) snapshotParams.name = options.name;
|
|
264
274
|
if (options?.metadata) snapshotParams.metadata = options.metadata;
|
|
265
275
|
return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);
|
|
266
276
|
},
|
|
267
277
|
list: async (config, options) => {
|
|
268
|
-
const
|
|
269
|
-
if (!apiKey) throw new Error("Missing Runloop API key for listing snapshots");
|
|
270
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
278
|
+
const client = getRunloopClient(config);
|
|
271
279
|
const listParams = {};
|
|
272
280
|
if (options?.limit) listParams.limit = options.limit;
|
|
273
281
|
const response = await client.api.devboxes.listDiskSnapshots(listParams);
|
|
274
282
|
return response.snapshots || [];
|
|
275
283
|
},
|
|
276
284
|
delete: async (config, snapshotId) => {
|
|
277
|
-
const
|
|
278
|
-
if (!apiKey) throw new Error("Missing Runloop API key for snapshot deletion");
|
|
279
|
-
const client = new import_api_client.RunloopSDK({ bearerToken: apiKey });
|
|
285
|
+
const client = getRunloopClient(config);
|
|
280
286
|
await client.api.devboxes.deleteDiskSnapshot(snapshotId);
|
|
281
287
|
}
|
|
282
288
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Runloop Provider - Factory-based Implementation\n *\n * Full-featured provider with filesystem support using the factory pattern.\n * Reduces ~400 lines of boilerplate to ~100 lines of core logic.\n */\n\nimport { RunloopSDK, type Runloop } from \"@runloop/api-client\";\nimport { defineProvider, escapeShellArg } from \"@computesdk/provider\";\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n RunCommandOptions,\n} from \"@computesdk/provider\";\nimport type {\n CreateSandboxOptions,\n FileEntry,\n} from \"computesdk\";\n\n// Define Runloop-specific types\ntype RunloopSnapshot = Runloop.DevboxSnapshotView;\ntype RunloopTemplate = Runloop.BlueprintView;\ntype RunloopSandbox = Runloop.DevboxView & { client: RunloopSDK };\n\ntype CommandRunner = (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n) => Promise<CommandResult>;\n\n/**\n * Runloop-specific configuration options\n */\nexport interface RunloopConfig {\n /** Runloop API key - if not provided, will fallback to RUNLOOP_API_KEY environment variable */\n apiKey?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Runloop-specific blueprint creation options\n */\nexport interface CreateBlueprintTemplateOptions {\n /** Name of the blueprint template */\n name: string;\n /** Custom Dockerfile content */\n dockerfile?: string;\n /** System setup commands to run during blueprint creation */\n systemSetupCommands?: string[];\n /** Launch commands to run when starting a devbox from this blueprint */\n launchCommands?: string[];\n /** File mounts as key-value pairs (path -> content) */\n fileMounts?: Record<string, string>;\n /** Code repository mounts */\n codeMounts?: Array<{\n repoName: string;\n repoOwner: string;\n token?: string;\n installCommand?: string;\n }>;\n /** Resource size for devboxes created from this blueprint */\n resourceSize?:\n | \"X_SMALL\"\n | \"SMALL\"\n | \"MEDIUM\"\n | \"LARGE\"\n | \"X_LARGE\"\n | \"XX_LARGE\"\n | \"CUSTOM_SIZE\";\n /** CPU architecture */\n architecture?: \"x86_64\" | \"arm64\";\n /** Custom CPU cores (requires CUSTOM_SIZE) */\n customCpuCores?: number;\n /** Custom memory in GB (requires CUSTOM_SIZE) */\n customMemoryGb?: number;\n /** Custom disk size (requires CUSTOM_SIZE) */\n customDiskSize?: number;\n /** Available ports for the devbox */\n availablePorts?: number[];\n /** Action to take when devbox is idle */\n afterIdle?: { action: string; timeSeconds: number };\n /** Keep alive time in seconds */\n keepAliveTimeSeconds?: number;\n}\n\n/**\n * Create a Runloop provider instance using the factory pattern\n */\nexport const runloop = defineProvider<\n RunloopSandbox,\n RunloopConfig,\n RunloopTemplate,\n RunloopSnapshot\n>({\n name: \"runloop\",\n methods: {\n sandbox: {\n create: async (config: RunloopConfig, options?: CreateSandboxOptions) => {\n const apiKey =\n config.apiKey ||\n (typeof process !== \"undefined\" && process.env?.RUNLOOP_API_KEY) ||\n \"\";\n\n if (!apiKey) {\n throw new Error(\n `Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`\n );\n }\n\n const timeout = config.timeout;\n\n try {\n const client = new RunloopSDK({\n bearerToken: apiKey,\n });\n\n const {\n timeout: optTimeout,\n envs,\n name,\n metadata,\n templateId,\n snapshotId,\n sandboxId: optSandboxId,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const effectiveTimeout = optTimeout ?? timeout;\n const keepAliveSeconds = effectiveTimeout\n ? Math.ceil(effectiveTimeout / 1000)\n : 1800;\n\n let devboxParams: Runloop.DevboxCreateParams = {\n launch_parameters: {\n keep_alive_time_seconds: keepAliveSeconds,\n },\n name: name || optSandboxId,\n metadata,\n environment_variables: envs,\n ...providerOptions,\n };\n\n // snapshotId is the canonical cross-provider field — map it directly to snapshot_id.\n // templateId is kept for backwards compatibility: bpt_ prefix → blueprint_id, snp_ prefix → snapshot_id.\n if (snapshotId) {\n devboxParams.snapshot_id = snapshotId;\n } else if (templateId) {\n if (templateId.startsWith(\"bpt_\")) {\n devboxParams.blueprint_id = templateId;\n } else if (templateId.startsWith(\"snp_\")) {\n devboxParams.snapshot_id = templateId;\n }\n }\n\n const dbx = await client.api.devboxes.createAndAwaitRunning(\n devboxParams,\n );\n\n const runloopSandbox: RunloopSandbox = {\n ...dbx,\n client: client\n };\n\n return {\n sandbox: runloopSandbox,\n sandboxId: dbx.id,\n };\n } catch (error) {\n throw new Error(\n `Failed to create Runloop devbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RunloopConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n const devbox = await client.api.devboxes.retrieve(sandboxId);\n return {\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId,\n };\n } catch {\n return null;\n }\n },\n\n list: async (config: RunloopConfig) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n const response = await client.api.devboxes.list();\n const devboxes = response.devboxes || [];\n\n return devboxes.map((devbox) => ({\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId: devbox.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: RunloopConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.devboxes.shutdown(sandboxId);\n } catch {\n // Devbox might already be destroyed or doesn't exist\n }\n },\n\n runCommand: async (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n let fullCommand = command;\n\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(String(v))}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n const executionResult =\n await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {\n command: fullCommand,\n });\n\n return {\n stdout: executionResult.stdout || \"\",\n stderr: executionResult.stderr || \"\",\n exitCode: executionResult.exit_status || 0,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Syntax error\")) {\n throw error;\n }\n throw new Error(\n `Runloop execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox): Promise<SandboxInfo> => {\n const devbox = sandbox;\n const keepAliveSecs = devbox.launch_parameters.keep_alive_time_seconds;\n\n return {\n id: devbox.id || \"runloop-unknown\",\n provider: \"runloop\",\n status: devbox.status as 'running' | 'stopped' | 'error',\n createdAt: new Date(devbox.create_time_ms || Date.now()),\n // keep_alive_time_seconds is in seconds; SandboxInfo.timeout is in milliseconds\n timeout: keepAliveSecs ? keepAliveSecs * 1000 : 300000,\n metadata: {\n runloopDevboxId: devbox.id,\n templateId: devbox.blueprint_id || devbox.snapshot_id,\n runtime: 'node',\n ...devbox.metadata,\n },\n };\n },\n\n getUrl: async (\n sandbox: RunloopSandbox,\n options: { port: number }\n ): Promise<string> => {\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n const tunnel = await client.api.devboxes.enableTunnel(devbox.id);\n return `https://${options.port}-${tunnel.tunnel_key}.tunnel.runloop.ai`;\n } catch (error) {\n throw new Error(\n `Failed to get Runloop URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n filesystem: {\n readFile: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<string> => {\n const result = await runCommand(sandbox, `cat \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);\n return result.stdout;\n },\n\n writeFile: async (sandbox: RunloopSandbox, path: string, content: string, runCommand: CommandRunner): Promise<void> => {\n const encoded = Buffer.from(content).toString('base64');\n const result = await runCommand(sandbox, `sh -c 'echo \"${encoded}\" | base64 -d > \"${path}\"'`);\n if (result.exitCode !== 0) throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n },\n\n mkdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `mkdir -p \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n\n readdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<FileEntry[]> => {\n const result = await runCommand(sandbox, `ls -la \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n\n const lines = (result.stdout || \"\")\n .split(\"\\n\")\n .filter((line: string) => line.trim() && !line.startsWith(\"total\"));\n\n return lines.map((line: string) => {\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith(\"d\");\n return {\n name,\n type: isDirectory ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4]) || 0,\n modified: new Date(),\n };\n });\n },\n\n exists: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<boolean> => {\n const result = await runCommand(sandbox, `test -e \"${path}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `rm -rf \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: RunloopSandbox): RunloopSandbox => sandbox,\n },\n\n template: {\n create: async (config: RunloopConfig, options: CreateBlueprintTemplateOptions | Runloop.BlueprintCreateParams) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for blueprint template creation\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n return client.api.blueprints.create(options);\n },\n\n list: async (config: RunloopConfig, options?: { limit?: number }) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for listing blueprint templates\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.blueprints.list(listParams);\n return response.blueprints || [];\n },\n\n delete: async (config: RunloopConfig, blueprintId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for blueprint template deletion\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.blueprints.delete(blueprintId);\n },\n },\n\n snapshot: {\n create: async (config: RunloopConfig, sandboxId: string, options?: CreateSnapshotOptions) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for snapshot creation\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const snapshotParams: any = {};\n if (options?.name) snapshotParams.name = options.name;\n if (options?.metadata) snapshotParams.metadata = options.metadata;\n return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);\n },\n\n list: async (config: RunloopConfig, options?: ListSnapshotsOptions) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for listing snapshots\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.devboxes.listDiskSnapshots(listParams);\n return response.snapshots || [];\n },\n\n delete: async (config: RunloopConfig, snapshotId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for snapshot deletion\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.devboxes.deleteDiskSnapshot(snapshotId);\n },\n },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,wBAAyC;AACzC,sBAA+C;AAmFxC,IAAM,cAAU,gCAKrB;AAAA,EACA,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAAuB,YAAmC;AACvE,cAAM,SACJ,OAAO,UACN,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAChD;AAEF,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,UAAU,OAAO;AAEvB,YAAI;AACF,gBAAM,SAAS,IAAI,6BAAW;AAAA,YAC5B,aAAa;AAAA,UACf,CAAC;AAED,gBAAM;AAAA,YACJ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cAAM,OAAO,IAAI,SAAS,mBAAmB,UAAU;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Runloop Provider - Factory-based Implementation\n *\n * Full-featured provider with filesystem support using the factory pattern.\n * Reduces ~400 lines of boilerplate to ~100 lines of core logic.\n */\n\nimport { RunloopSDK, type Runloop } from \"@runloop/api-client\";\nimport { defineProvider, escapeShellArg } from \"@computesdk/provider\";\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n RunCommandOptions,\n} from \"@computesdk/provider\";\nimport type {\n CreateSandboxOptions,\n FileEntry,\n} from \"computesdk\";\n\n// Define Runloop-specific types\ntype RunloopSnapshot = Runloop.DevboxSnapshotView;\ntype RunloopTemplate = Runloop.BlueprintView;\ntype RunloopSandbox = Runloop.DevboxView & { client: RunloopSDK };\ntype RunloopCreateWaitOptions = Parameters<RunloopSDK[\"api\"][\"devboxes\"][\"createAndAwaitRunning\"]>[1];\ntype RunloopExecuteWaitOptions = Parameters<RunloopSDK[\"api\"][\"devboxes\"][\"executeAndAwaitCompletion\"]>[2];\n\ntype CommandRunner = (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n) => Promise<CommandResult>;\n\n/**\n * Runloop-specific configuration options\n */\nexport interface RunloopConfig {\n /** Runloop API key - if not provided, will fallback to RUNLOOP_API_KEY environment variable */\n apiKey?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\nconst clientCache = new WeakMap<RunloopConfig, RunloopSDK>();\n\nfunction resolveApiKey(config: RunloopConfig): string {\n return (\n config.apiKey ||\n (typeof process !== \"undefined\" && process.env?.RUNLOOP_API_KEY) ||\n \"\"\n );\n}\n\nfunction getRunloopClient(config: RunloopConfig): RunloopSDK {\n const apiKey = resolveApiKey(config);\n if (!apiKey) {\n throw new Error(\n `Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`\n );\n }\n\n const cached = clientCache.get(config);\n if (cached) return cached;\n\n const client = new RunloopSDK({\n bearerToken: apiKey,\n });\n clientCache.set(config, client);\n return client;\n}\n\nfunction longPollOptions<TOptions>(timeoutMs?: number): TOptions | undefined {\n return timeoutMs ? ({ longPoll: { timeoutMs } } as TOptions) : undefined;\n}\n\nfunction optimisticTimeoutSeconds(timeoutMs?: number): number {\n if (!timeoutMs) return 25;\n return Math.max(1, Math.min(25, Math.ceil(timeoutMs / 1000)));\n}\n\n/**\n * Runloop-specific blueprint creation options\n */\nexport interface CreateBlueprintTemplateOptions {\n /** Name of the blueprint template */\n name: string;\n /** Custom Dockerfile content */\n dockerfile?: string;\n /** System setup commands to run during blueprint creation */\n systemSetupCommands?: string[];\n /** Launch commands to run when starting a devbox from this blueprint */\n launchCommands?: string[];\n /** File mounts as key-value pairs (path -> content) */\n fileMounts?: Record<string, string>;\n /** Code repository mounts */\n codeMounts?: Array<{\n repoName: string;\n repoOwner: string;\n token?: string;\n installCommand?: string;\n }>;\n /** Resource size for devboxes created from this blueprint */\n resourceSize?:\n | \"X_SMALL\"\n | \"SMALL\"\n | \"MEDIUM\"\n | \"LARGE\"\n | \"X_LARGE\"\n | \"XX_LARGE\"\n | \"CUSTOM_SIZE\";\n /** CPU architecture */\n architecture?: \"x86_64\" | \"arm64\";\n /** Custom CPU cores (requires CUSTOM_SIZE) */\n customCpuCores?: number;\n /** Custom memory in GB (requires CUSTOM_SIZE) */\n customMemoryGb?: number;\n /** Custom disk size (requires CUSTOM_SIZE) */\n customDiskSize?: number;\n /** Available ports for the devbox */\n availablePorts?: number[];\n /** Action to take when devbox is idle */\n afterIdle?: { action: string; timeSeconds: number };\n /** Keep alive time in seconds */\n keepAliveTimeSeconds?: number;\n}\n\n/**\n * Create a Runloop provider instance using the factory pattern\n */\nexport const runloop = defineProvider<\n RunloopSandbox,\n RunloopConfig,\n RunloopTemplate,\n RunloopSnapshot\n>({\n name: \"runloop\",\n methods: {\n sandbox: {\n create: async (config: RunloopConfig, options?: CreateSandboxOptions) => {\n const timeout = config.timeout;\n\n try {\n const client = getRunloopClient(config);\n\n const {\n timeout: optTimeout,\n envs,\n name,\n metadata,\n templateId,\n snapshotId,\n sandboxId: optSandboxId,\n ports: _ports,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const effectiveTimeout = optTimeout ?? timeout;\n const keepAliveSeconds = effectiveTimeout\n ? Math.ceil(effectiveTimeout / 1000)\n : 1800;\n\n let devboxParams: Runloop.DevboxCreateParams = {\n launch_parameters: {\n keep_alive_time_seconds: keepAliveSeconds,\n },\n name: name || optSandboxId,\n metadata,\n environment_variables: envs,\n ...providerOptions,\n };\n\n // snapshotId is the canonical cross-provider field — map it directly to snapshot_id.\n // templateId is kept for backwards compatibility: bpt_ prefix → blueprint_id, snp_ prefix → snapshot_id.\n if (snapshotId) {\n devboxParams.snapshot_id = snapshotId;\n } else if (templateId) {\n if (templateId.startsWith(\"bpt_\")) {\n devboxParams.blueprint_id = templateId;\n } else if (templateId.startsWith(\"snp_\")) {\n devboxParams.snapshot_id = templateId;\n }\n }\n\n const dbx = await client.api.devboxes.createAndAwaitRunning(\n devboxParams,\n longPollOptions<RunloopCreateWaitOptions>(effectiveTimeout),\n );\n\n const runloopSandbox: RunloopSandbox = {\n ...dbx,\n client: client\n };\n\n return {\n sandbox: runloopSandbox,\n sandboxId: dbx.id,\n };\n } catch (error) {\n throw new Error(\n `Failed to create Runloop devbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RunloopConfig, sandboxId: string) => {\n try {\n const client = getRunloopClient(config);\n const devbox = await client.api.devboxes.retrieve(sandboxId);\n return {\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId,\n };\n } catch {\n return null;\n }\n },\n\n list: async (config: RunloopConfig) => {\n try {\n const client = getRunloopClient(config);\n const response = await client.api.devboxes.list();\n const devboxes = response.devboxes || [];\n\n return devboxes.map((devbox) => ({\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId: devbox.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: RunloopConfig, sandboxId: string) => {\n try {\n const client = getRunloopClient(config);\n await client.api.devboxes.shutdown(sandboxId);\n } catch {\n // Devbox might already be destroyed or doesn't exist\n }\n },\n\n runCommand: async (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n let fullCommand = command;\n\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(String(v))}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n const executionResult =\n await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {\n command: fullCommand,\n optimistic_timeout: optimisticTimeoutSeconds(options?.timeout),\n }, longPollOptions<RunloopExecuteWaitOptions>(options?.timeout));\n\n return {\n stdout: executionResult.stdout || \"\",\n stderr: executionResult.stderr || \"\",\n exitCode: executionResult.exit_status || 0,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Syntax error\")) {\n throw error;\n }\n throw new Error(\n `Runloop execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox): Promise<SandboxInfo> => {\n const devbox = sandbox;\n const keepAliveSecs = devbox.launch_parameters.keep_alive_time_seconds;\n\n return {\n id: devbox.id || \"runloop-unknown\",\n provider: \"runloop\",\n status: devbox.status as 'running' | 'stopped' | 'error',\n createdAt: new Date(devbox.create_time_ms || Date.now()),\n // keep_alive_time_seconds is in seconds; SandboxInfo.timeout is in milliseconds\n timeout: keepAliveSecs ? keepAliveSecs * 1000 : 300000,\n metadata: {\n runloopDevboxId: devbox.id,\n templateId: devbox.blueprint_id || devbox.snapshot_id,\n runtime: 'node',\n ...devbox.metadata,\n },\n };\n },\n\n getUrl: async (\n sandbox: RunloopSandbox,\n options: { port: number }\n ): Promise<string> => {\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n const tunnel = await client.api.devboxes.enableTunnel(devbox.id);\n return `https://${options.port}-${tunnel.tunnel_key}.tunnel.runloop.ai`;\n } catch (error) {\n throw new Error(\n `Failed to get Runloop URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n filesystem: {\n readFile: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<string> => {\n const result = await runCommand(sandbox, `test -f \"${path}\" && base64 < \"${path}\" | tr -d '\\\\n'`);\n if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);\n return Buffer.from(result.stdout, 'base64').toString('utf8');\n },\n\n writeFile: async (sandbox: RunloopSandbox, path: string, content: string, runCommand: CommandRunner): Promise<void> => {\n const encoded = Buffer.from(content).toString('base64');\n const result = await runCommand(sandbox, `sh -c 'echo \"${encoded}\" | base64 -d > \"${path}\"'`);\n if (result.exitCode !== 0) throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n },\n\n mkdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `mkdir -p \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n\n readdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<FileEntry[]> => {\n const result = await runCommand(sandbox, `ls -la \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n\n const lines = (result.stdout || \"\")\n .split(\"\\n\")\n .filter((line: string) => line.trim() && !line.startsWith(\"total\"));\n\n return lines.map((line: string) => {\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith(\"d\");\n return {\n name,\n type: isDirectory ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4]) || 0,\n modified: new Date(),\n };\n });\n },\n\n exists: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<boolean> => {\n const result = await runCommand(sandbox, `test -e \"${path}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `rm -rf \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: RunloopSandbox): RunloopSandbox => sandbox,\n },\n\n template: {\n create: async (config: RunloopConfig, options: CreateBlueprintTemplateOptions | Runloop.BlueprintCreateParams) => {\n const client = getRunloopClient(config);\n return client.api.blueprints.create(options);\n },\n\n list: async (config: RunloopConfig, options?: { limit?: number }) => {\n const client = getRunloopClient(config);\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.blueprints.list(listParams);\n return response.blueprints || [];\n },\n\n delete: async (config: RunloopConfig, blueprintId: string) => {\n const client = getRunloopClient(config);\n await client.api.blueprints.delete(blueprintId);\n },\n },\n\n snapshot: {\n create: async (config: RunloopConfig, sandboxId: string, options?: CreateSnapshotOptions) => {\n const client = getRunloopClient(config);\n const snapshotParams: any = {};\n if (options?.name) snapshotParams.name = options.name;\n if (options?.metadata) snapshotParams.metadata = options.metadata;\n return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);\n },\n\n list: async (config: RunloopConfig, options?: ListSnapshotsOptions) => {\n const client = getRunloopClient(config);\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.devboxes.listDiskSnapshots(listParams);\n return response.snapshots || [];\n },\n\n delete: async (config: RunloopConfig, snapshotId: string) => {\n const client = getRunloopClient(config);\n await client.api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AAmC;AACrE,cAAM,SAAS,iBAAiB,MAAM;AACtC,cAAM,aAAkB,CAAC;AACzB,YAAI,SAAS,MAAO,YAAW,QAAQ,QAAQ;AAC/C,cAAM,WAAW,MAAM,OAAO,IAAI,SAAS,kBAAkB,UAAU;AACvE,eAAO,SAAS,aAAa,CAAC;AAAA,MAChC;AAAA,MAEA,QAAQ,OAAO,QAAuB,eAAuB;AAC3D,cAAM,SAAS,iBAAiB,MAAM;AACtC,cAAM,OAAO,IAAI,SAAS,mBAAmB,UAAU;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { RunloopSDK } from "@runloop/api-client";
|
|
3
3
|
import { defineProvider, escapeShellArg } from "@computesdk/provider";
|
|
4
|
+
var clientCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function resolveApiKey(config) {
|
|
6
|
+
return config.apiKey || typeof process !== "undefined" && process.env?.RUNLOOP_API_KEY || "";
|
|
7
|
+
}
|
|
8
|
+
function getRunloopClient(config) {
|
|
9
|
+
const apiKey = resolveApiKey(config);
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const cached = clientCache.get(config);
|
|
16
|
+
if (cached) return cached;
|
|
17
|
+
const client = new RunloopSDK({
|
|
18
|
+
bearerToken: apiKey
|
|
19
|
+
});
|
|
20
|
+
clientCache.set(config, client);
|
|
21
|
+
return client;
|
|
22
|
+
}
|
|
23
|
+
function longPollOptions(timeoutMs) {
|
|
24
|
+
return timeoutMs ? { longPoll: { timeoutMs } } : void 0;
|
|
25
|
+
}
|
|
26
|
+
function optimisticTimeoutSeconds(timeoutMs) {
|
|
27
|
+
if (!timeoutMs) return 25;
|
|
28
|
+
return Math.max(1, Math.min(25, Math.ceil(timeoutMs / 1e3)));
|
|
29
|
+
}
|
|
4
30
|
var runloop = defineProvider({
|
|
5
31
|
name: "runloop",
|
|
6
32
|
methods: {
|
|
7
33
|
sandbox: {
|
|
8
34
|
create: async (config, options) => {
|
|
9
|
-
const apiKey = config.apiKey || typeof process !== "undefined" && process.env?.RUNLOOP_API_KEY || "";
|
|
10
|
-
if (!apiKey) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
`Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
35
|
const timeout = config.timeout;
|
|
16
36
|
try {
|
|
17
|
-
const client =
|
|
18
|
-
bearerToken: apiKey
|
|
19
|
-
});
|
|
37
|
+
const client = getRunloopClient(config);
|
|
20
38
|
const {
|
|
21
39
|
timeout: optTimeout,
|
|
22
40
|
envs,
|
|
@@ -25,6 +43,7 @@ var runloop = defineProvider({
|
|
|
25
43
|
templateId,
|
|
26
44
|
snapshotId,
|
|
27
45
|
sandboxId: optSandboxId,
|
|
46
|
+
ports: _ports,
|
|
28
47
|
namespace: _namespace,
|
|
29
48
|
directory: _directory,
|
|
30
49
|
...providerOptions
|
|
@@ -50,7 +69,8 @@ var runloop = defineProvider({
|
|
|
50
69
|
}
|
|
51
70
|
}
|
|
52
71
|
const dbx = await client.api.devboxes.createAndAwaitRunning(
|
|
53
|
-
devboxParams
|
|
72
|
+
devboxParams,
|
|
73
|
+
longPollOptions(effectiveTimeout)
|
|
54
74
|
);
|
|
55
75
|
const runloopSandbox = {
|
|
56
76
|
...dbx,
|
|
@@ -67,9 +87,8 @@ var runloop = defineProvider({
|
|
|
67
87
|
}
|
|
68
88
|
},
|
|
69
89
|
getById: async (config, sandboxId) => {
|
|
70
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
71
90
|
try {
|
|
72
|
-
const client =
|
|
91
|
+
const client = getRunloopClient(config);
|
|
73
92
|
const devbox = await client.api.devboxes.retrieve(sandboxId);
|
|
74
93
|
return {
|
|
75
94
|
sandbox: { ...devbox, client },
|
|
@@ -80,9 +99,8 @@ var runloop = defineProvider({
|
|
|
80
99
|
}
|
|
81
100
|
},
|
|
82
101
|
list: async (config) => {
|
|
83
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
84
102
|
try {
|
|
85
|
-
const client =
|
|
103
|
+
const client = getRunloopClient(config);
|
|
86
104
|
const response = await client.api.devboxes.list();
|
|
87
105
|
const devboxes = response.devboxes || [];
|
|
88
106
|
return devboxes.map((devbox) => ({
|
|
@@ -94,9 +112,8 @@ var runloop = defineProvider({
|
|
|
94
112
|
}
|
|
95
113
|
},
|
|
96
114
|
destroy: async (config, sandboxId) => {
|
|
97
|
-
const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY;
|
|
98
115
|
try {
|
|
99
|
-
const client =
|
|
116
|
+
const client = getRunloopClient(config);
|
|
100
117
|
await client.api.devboxes.shutdown(sandboxId);
|
|
101
118
|
} catch {
|
|
102
119
|
}
|
|
@@ -118,8 +135,9 @@ var runloop = defineProvider({
|
|
|
118
135
|
fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;
|
|
119
136
|
}
|
|
120
137
|
const executionResult = await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {
|
|
121
|
-
command: fullCommand
|
|
122
|
-
|
|
138
|
+
command: fullCommand,
|
|
139
|
+
optimistic_timeout: optimisticTimeoutSeconds(options?.timeout)
|
|
140
|
+
}, longPollOptions(options?.timeout));
|
|
123
141
|
return {
|
|
124
142
|
stdout: executionResult.stdout || "",
|
|
125
143
|
stderr: executionResult.stderr || "",
|
|
@@ -167,9 +185,9 @@ var runloop = defineProvider({
|
|
|
167
185
|
},
|
|
168
186
|
filesystem: {
|
|
169
187
|
readFile: async (sandbox, path, runCommand) => {
|
|
170
|
-
const result = await runCommand(sandbox, `
|
|
188
|
+
const result = await runCommand(sandbox, `test -f "${path}" && base64 < "${path}" | tr -d '\\n'`);
|
|
171
189
|
if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);
|
|
172
|
-
return result.stdout;
|
|
190
|
+
return Buffer.from(result.stdout, "base64").toString("utf8");
|
|
173
191
|
},
|
|
174
192
|
writeFile: async (sandbox, path, content, runCommand) => {
|
|
175
193
|
const encoded = Buffer.from(content).toString("base64");
|
|
@@ -209,50 +227,38 @@ var runloop = defineProvider({
|
|
|
209
227
|
},
|
|
210
228
|
template: {
|
|
211
229
|
create: async (config, options) => {
|
|
212
|
-
const
|
|
213
|
-
if (!apiKey) throw new Error("Missing Runloop API key for blueprint template creation");
|
|
214
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
230
|
+
const client = getRunloopClient(config);
|
|
215
231
|
return client.api.blueprints.create(options);
|
|
216
232
|
},
|
|
217
233
|
list: async (config, options) => {
|
|
218
|
-
const
|
|
219
|
-
if (!apiKey) throw new Error("Missing Runloop API key for listing blueprint templates");
|
|
220
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
234
|
+
const client = getRunloopClient(config);
|
|
221
235
|
const listParams = {};
|
|
222
236
|
if (options?.limit) listParams.limit = options.limit;
|
|
223
237
|
const response = await client.api.blueprints.list(listParams);
|
|
224
238
|
return response.blueprints || [];
|
|
225
239
|
},
|
|
226
240
|
delete: async (config, blueprintId) => {
|
|
227
|
-
const
|
|
228
|
-
if (!apiKey) throw new Error("Missing Runloop API key for blueprint template deletion");
|
|
229
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
241
|
+
const client = getRunloopClient(config);
|
|
230
242
|
await client.api.blueprints.delete(blueprintId);
|
|
231
243
|
}
|
|
232
244
|
},
|
|
233
245
|
snapshot: {
|
|
234
246
|
create: async (config, sandboxId, options) => {
|
|
235
|
-
const
|
|
236
|
-
if (!apiKey) throw new Error("Missing Runloop API key for snapshot creation");
|
|
237
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
247
|
+
const client = getRunloopClient(config);
|
|
238
248
|
const snapshotParams = {};
|
|
239
249
|
if (options?.name) snapshotParams.name = options.name;
|
|
240
250
|
if (options?.metadata) snapshotParams.metadata = options.metadata;
|
|
241
251
|
return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);
|
|
242
252
|
},
|
|
243
253
|
list: async (config, options) => {
|
|
244
|
-
const
|
|
245
|
-
if (!apiKey) throw new Error("Missing Runloop API key for listing snapshots");
|
|
246
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
254
|
+
const client = getRunloopClient(config);
|
|
247
255
|
const listParams = {};
|
|
248
256
|
if (options?.limit) listParams.limit = options.limit;
|
|
249
257
|
const response = await client.api.devboxes.listDiskSnapshots(listParams);
|
|
250
258
|
return response.snapshots || [];
|
|
251
259
|
},
|
|
252
260
|
delete: async (config, snapshotId) => {
|
|
253
|
-
const
|
|
254
|
-
if (!apiKey) throw new Error("Missing Runloop API key for snapshot deletion");
|
|
255
|
-
const client = new RunloopSDK({ bearerToken: apiKey });
|
|
261
|
+
const client = getRunloopClient(config);
|
|
256
262
|
await client.api.devboxes.deleteDiskSnapshot(snapshotId);
|
|
257
263
|
}
|
|
258
264
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Runloop Provider - Factory-based Implementation\n *\n * Full-featured provider with filesystem support using the factory pattern.\n * Reduces ~400 lines of boilerplate to ~100 lines of core logic.\n */\n\nimport { RunloopSDK, type Runloop } from \"@runloop/api-client\";\nimport { defineProvider, escapeShellArg } from \"@computesdk/provider\";\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n RunCommandOptions,\n} from \"@computesdk/provider\";\nimport type {\n CreateSandboxOptions,\n FileEntry,\n} from \"computesdk\";\n\n// Define Runloop-specific types\ntype RunloopSnapshot = Runloop.DevboxSnapshotView;\ntype RunloopTemplate = Runloop.BlueprintView;\ntype RunloopSandbox = Runloop.DevboxView & { client: RunloopSDK };\n\ntype CommandRunner = (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n) => Promise<CommandResult>;\n\n/**\n * Runloop-specific configuration options\n */\nexport interface RunloopConfig {\n /** Runloop API key - if not provided, will fallback to RUNLOOP_API_KEY environment variable */\n apiKey?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Runloop-specific blueprint creation options\n */\nexport interface CreateBlueprintTemplateOptions {\n /** Name of the blueprint template */\n name: string;\n /** Custom Dockerfile content */\n dockerfile?: string;\n /** System setup commands to run during blueprint creation */\n systemSetupCommands?: string[];\n /** Launch commands to run when starting a devbox from this blueprint */\n launchCommands?: string[];\n /** File mounts as key-value pairs (path -> content) */\n fileMounts?: Record<string, string>;\n /** Code repository mounts */\n codeMounts?: Array<{\n repoName: string;\n repoOwner: string;\n token?: string;\n installCommand?: string;\n }>;\n /** Resource size for devboxes created from this blueprint */\n resourceSize?:\n | \"X_SMALL\"\n | \"SMALL\"\n | \"MEDIUM\"\n | \"LARGE\"\n | \"X_LARGE\"\n | \"XX_LARGE\"\n | \"CUSTOM_SIZE\";\n /** CPU architecture */\n architecture?: \"x86_64\" | \"arm64\";\n /** Custom CPU cores (requires CUSTOM_SIZE) */\n customCpuCores?: number;\n /** Custom memory in GB (requires CUSTOM_SIZE) */\n customMemoryGb?: number;\n /** Custom disk size (requires CUSTOM_SIZE) */\n customDiskSize?: number;\n /** Available ports for the devbox */\n availablePorts?: number[];\n /** Action to take when devbox is idle */\n afterIdle?: { action: string; timeSeconds: number };\n /** Keep alive time in seconds */\n keepAliveTimeSeconds?: number;\n}\n\n/**\n * Create a Runloop provider instance using the factory pattern\n */\nexport const runloop = defineProvider<\n RunloopSandbox,\n RunloopConfig,\n RunloopTemplate,\n RunloopSnapshot\n>({\n name: \"runloop\",\n methods: {\n sandbox: {\n create: async (config: RunloopConfig, options?: CreateSandboxOptions) => {\n const apiKey =\n config.apiKey ||\n (typeof process !== \"undefined\" && process.env?.RUNLOOP_API_KEY) ||\n \"\";\n\n if (!apiKey) {\n throw new Error(\n `Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`\n );\n }\n\n const timeout = config.timeout;\n\n try {\n const client = new RunloopSDK({\n bearerToken: apiKey,\n });\n\n const {\n timeout: optTimeout,\n envs,\n name,\n metadata,\n templateId,\n snapshotId,\n sandboxId: optSandboxId,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const effectiveTimeout = optTimeout ?? timeout;\n const keepAliveSeconds = effectiveTimeout\n ? Math.ceil(effectiveTimeout / 1000)\n : 1800;\n\n let devboxParams: Runloop.DevboxCreateParams = {\n launch_parameters: {\n keep_alive_time_seconds: keepAliveSeconds,\n },\n name: name || optSandboxId,\n metadata,\n environment_variables: envs,\n ...providerOptions,\n };\n\n // snapshotId is the canonical cross-provider field — map it directly to snapshot_id.\n // templateId is kept for backwards compatibility: bpt_ prefix → blueprint_id, snp_ prefix → snapshot_id.\n if (snapshotId) {\n devboxParams.snapshot_id = snapshotId;\n } else if (templateId) {\n if (templateId.startsWith(\"bpt_\")) {\n devboxParams.blueprint_id = templateId;\n } else if (templateId.startsWith(\"snp_\")) {\n devboxParams.snapshot_id = templateId;\n }\n }\n\n const dbx = await client.api.devboxes.createAndAwaitRunning(\n devboxParams,\n );\n\n const runloopSandbox: RunloopSandbox = {\n ...dbx,\n client: client\n };\n\n return {\n sandbox: runloopSandbox,\n sandboxId: dbx.id,\n };\n } catch (error) {\n throw new Error(\n `Failed to create Runloop devbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RunloopConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n const devbox = await client.api.devboxes.retrieve(sandboxId);\n return {\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId,\n };\n } catch {\n return null;\n }\n },\n\n list: async (config: RunloopConfig) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n const response = await client.api.devboxes.list();\n const devboxes = response.devboxes || [];\n\n return devboxes.map((devbox) => ({\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId: devbox.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: RunloopConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n\n try {\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.devboxes.shutdown(sandboxId);\n } catch {\n // Devbox might already be destroyed or doesn't exist\n }\n },\n\n runCommand: async (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n let fullCommand = command;\n\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(String(v))}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n const executionResult =\n await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {\n command: fullCommand,\n });\n\n return {\n stdout: executionResult.stdout || \"\",\n stderr: executionResult.stderr || \"\",\n exitCode: executionResult.exit_status || 0,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Syntax error\")) {\n throw error;\n }\n throw new Error(\n `Runloop execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox): Promise<SandboxInfo> => {\n const devbox = sandbox;\n const keepAliveSecs = devbox.launch_parameters.keep_alive_time_seconds;\n\n return {\n id: devbox.id || \"runloop-unknown\",\n provider: \"runloop\",\n status: devbox.status as 'running' | 'stopped' | 'error',\n createdAt: new Date(devbox.create_time_ms || Date.now()),\n // keep_alive_time_seconds is in seconds; SandboxInfo.timeout is in milliseconds\n timeout: keepAliveSecs ? keepAliveSecs * 1000 : 300000,\n metadata: {\n runloopDevboxId: devbox.id,\n templateId: devbox.blueprint_id || devbox.snapshot_id,\n runtime: 'node',\n ...devbox.metadata,\n },\n };\n },\n\n getUrl: async (\n sandbox: RunloopSandbox,\n options: { port: number }\n ): Promise<string> => {\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n const tunnel = await client.api.devboxes.enableTunnel(devbox.id);\n return `https://${options.port}-${tunnel.tunnel_key}.tunnel.runloop.ai`;\n } catch (error) {\n throw new Error(\n `Failed to get Runloop URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n filesystem: {\n readFile: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<string> => {\n const result = await runCommand(sandbox, `cat \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);\n return result.stdout;\n },\n\n writeFile: async (sandbox: RunloopSandbox, path: string, content: string, runCommand: CommandRunner): Promise<void> => {\n const encoded = Buffer.from(content).toString('base64');\n const result = await runCommand(sandbox, `sh -c 'echo \"${encoded}\" | base64 -d > \"${path}\"'`);\n if (result.exitCode !== 0) throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n },\n\n mkdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `mkdir -p \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n\n readdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<FileEntry[]> => {\n const result = await runCommand(sandbox, `ls -la \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n\n const lines = (result.stdout || \"\")\n .split(\"\\n\")\n .filter((line: string) => line.trim() && !line.startsWith(\"total\"));\n\n return lines.map((line: string) => {\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith(\"d\");\n return {\n name,\n type: isDirectory ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4]) || 0,\n modified: new Date(),\n };\n });\n },\n\n exists: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<boolean> => {\n const result = await runCommand(sandbox, `test -e \"${path}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `rm -rf \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: RunloopSandbox): RunloopSandbox => sandbox,\n },\n\n template: {\n create: async (config: RunloopConfig, options: CreateBlueprintTemplateOptions | Runloop.BlueprintCreateParams) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for blueprint template creation\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n return client.api.blueprints.create(options);\n },\n\n list: async (config: RunloopConfig, options?: { limit?: number }) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for listing blueprint templates\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.blueprints.list(listParams);\n return response.blueprints || [];\n },\n\n delete: async (config: RunloopConfig, blueprintId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for blueprint template deletion\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.blueprints.delete(blueprintId);\n },\n },\n\n snapshot: {\n create: async (config: RunloopConfig, sandboxId: string, options?: CreateSnapshotOptions) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for snapshot creation\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const snapshotParams: any = {};\n if (options?.name) snapshotParams.name = options.name;\n if (options?.metadata) snapshotParams.metadata = options.metadata;\n return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);\n },\n\n list: async (config: RunloopConfig, options?: ListSnapshotsOptions) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for listing snapshots\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.devboxes.listDiskSnapshots(listParams);\n return response.snapshots || [];\n },\n\n delete: async (config: RunloopConfig, snapshotId: string) => {\n const apiKey = config.apiKey || process.env.RUNLOOP_API_KEY!;\n if (!apiKey) throw new Error(\"Missing Runloop API key for snapshot deletion\");\n const client = new RunloopSDK({ bearerToken: apiKey });\n await client.api.devboxes.deleteDiskSnapshot(snapshotId);\n },\n },\n },\n});\n"],"mappings":";AAOA,SAAS,kBAAgC;AACzC,SAAS,gBAAgB,sBAAsB;AAmFxC,IAAM,UAAU,eAKrB;AAAA,EACA,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAAuB,YAAmC;AACvE,cAAM,SACJ,OAAO,UACN,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAChD;AAEF,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,UAAU,OAAO;AAEvB,YAAI;AACF,gBAAM,SAAS,IAAI,WAAW;AAAA,YAC5B,aAAa;AAAA,UACf,CAAC;AAED,gBAAM;AAAA,YACJ,SAAS;AAAA,Y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AmB,UAAU;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Runloop Provider - Factory-based Implementation\n *\n * Full-featured provider with filesystem support using the factory pattern.\n * Reduces ~400 lines of boilerplate to ~100 lines of core logic.\n */\n\nimport { RunloopSDK, type Runloop } from \"@runloop/api-client\";\nimport { defineProvider, escapeShellArg } from \"@computesdk/provider\";\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n RunCommandOptions,\n} from \"@computesdk/provider\";\nimport type {\n CreateSandboxOptions,\n FileEntry,\n} from \"computesdk\";\n\n// Define Runloop-specific types\ntype RunloopSnapshot = Runloop.DevboxSnapshotView;\ntype RunloopTemplate = Runloop.BlueprintView;\ntype RunloopSandbox = Runloop.DevboxView & { client: RunloopSDK };\ntype RunloopCreateWaitOptions = Parameters<RunloopSDK[\"api\"][\"devboxes\"][\"createAndAwaitRunning\"]>[1];\ntype RunloopExecuteWaitOptions = Parameters<RunloopSDK[\"api\"][\"devboxes\"][\"executeAndAwaitCompletion\"]>[2];\n\ntype CommandRunner = (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n) => Promise<CommandResult>;\n\n/**\n * Runloop-specific configuration options\n */\nexport interface RunloopConfig {\n /** Runloop API key - if not provided, will fallback to RUNLOOP_API_KEY environment variable */\n apiKey?: string;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\nconst clientCache = new WeakMap<RunloopConfig, RunloopSDK>();\n\nfunction resolveApiKey(config: RunloopConfig): string {\n return (\n config.apiKey ||\n (typeof process !== \"undefined\" && process.env?.RUNLOOP_API_KEY) ||\n \"\"\n );\n}\n\nfunction getRunloopClient(config: RunloopConfig): RunloopSDK {\n const apiKey = resolveApiKey(config);\n if (!apiKey) {\n throw new Error(\n `Missing Runloop API key. Provide 'apiKey' in config or set RUNLOOP_API_KEY environment variable. Get your API key from https://runloop.ai/`\n );\n }\n\n const cached = clientCache.get(config);\n if (cached) return cached;\n\n const client = new RunloopSDK({\n bearerToken: apiKey,\n });\n clientCache.set(config, client);\n return client;\n}\n\nfunction longPollOptions<TOptions>(timeoutMs?: number): TOptions | undefined {\n return timeoutMs ? ({ longPoll: { timeoutMs } } as TOptions) : undefined;\n}\n\nfunction optimisticTimeoutSeconds(timeoutMs?: number): number {\n if (!timeoutMs) return 25;\n return Math.max(1, Math.min(25, Math.ceil(timeoutMs / 1000)));\n}\n\n/**\n * Runloop-specific blueprint creation options\n */\nexport interface CreateBlueprintTemplateOptions {\n /** Name of the blueprint template */\n name: string;\n /** Custom Dockerfile content */\n dockerfile?: string;\n /** System setup commands to run during blueprint creation */\n systemSetupCommands?: string[];\n /** Launch commands to run when starting a devbox from this blueprint */\n launchCommands?: string[];\n /** File mounts as key-value pairs (path -> content) */\n fileMounts?: Record<string, string>;\n /** Code repository mounts */\n codeMounts?: Array<{\n repoName: string;\n repoOwner: string;\n token?: string;\n installCommand?: string;\n }>;\n /** Resource size for devboxes created from this blueprint */\n resourceSize?:\n | \"X_SMALL\"\n | \"SMALL\"\n | \"MEDIUM\"\n | \"LARGE\"\n | \"X_LARGE\"\n | \"XX_LARGE\"\n | \"CUSTOM_SIZE\";\n /** CPU architecture */\n architecture?: \"x86_64\" | \"arm64\";\n /** Custom CPU cores (requires CUSTOM_SIZE) */\n customCpuCores?: number;\n /** Custom memory in GB (requires CUSTOM_SIZE) */\n customMemoryGb?: number;\n /** Custom disk size (requires CUSTOM_SIZE) */\n customDiskSize?: number;\n /** Available ports for the devbox */\n availablePorts?: number[];\n /** Action to take when devbox is idle */\n afterIdle?: { action: string; timeSeconds: number };\n /** Keep alive time in seconds */\n keepAliveTimeSeconds?: number;\n}\n\n/**\n * Create a Runloop provider instance using the factory pattern\n */\nexport const runloop = defineProvider<\n RunloopSandbox,\n RunloopConfig,\n RunloopTemplate,\n RunloopSnapshot\n>({\n name: \"runloop\",\n methods: {\n sandbox: {\n create: async (config: RunloopConfig, options?: CreateSandboxOptions) => {\n const timeout = config.timeout;\n\n try {\n const client = getRunloopClient(config);\n\n const {\n timeout: optTimeout,\n envs,\n name,\n metadata,\n templateId,\n snapshotId,\n sandboxId: optSandboxId,\n ports: _ports,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const effectiveTimeout = optTimeout ?? timeout;\n const keepAliveSeconds = effectiveTimeout\n ? Math.ceil(effectiveTimeout / 1000)\n : 1800;\n\n let devboxParams: Runloop.DevboxCreateParams = {\n launch_parameters: {\n keep_alive_time_seconds: keepAliveSeconds,\n },\n name: name || optSandboxId,\n metadata,\n environment_variables: envs,\n ...providerOptions,\n };\n\n // snapshotId is the canonical cross-provider field — map it directly to snapshot_id.\n // templateId is kept for backwards compatibility: bpt_ prefix → blueprint_id, snp_ prefix → snapshot_id.\n if (snapshotId) {\n devboxParams.snapshot_id = snapshotId;\n } else if (templateId) {\n if (templateId.startsWith(\"bpt_\")) {\n devboxParams.blueprint_id = templateId;\n } else if (templateId.startsWith(\"snp_\")) {\n devboxParams.snapshot_id = templateId;\n }\n }\n\n const dbx = await client.api.devboxes.createAndAwaitRunning(\n devboxParams,\n longPollOptions<RunloopCreateWaitOptions>(effectiveTimeout),\n );\n\n const runloopSandbox: RunloopSandbox = {\n ...dbx,\n client: client\n };\n\n return {\n sandbox: runloopSandbox,\n sandboxId: dbx.id,\n };\n } catch (error) {\n throw new Error(\n `Failed to create Runloop devbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RunloopConfig, sandboxId: string) => {\n try {\n const client = getRunloopClient(config);\n const devbox = await client.api.devboxes.retrieve(sandboxId);\n return {\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId,\n };\n } catch {\n return null;\n }\n },\n\n list: async (config: RunloopConfig) => {\n try {\n const client = getRunloopClient(config);\n const response = await client.api.devboxes.list();\n const devboxes = response.devboxes || [];\n\n return devboxes.map((devbox) => ({\n sandbox: { ...devbox, client } as RunloopSandbox,\n sandboxId: devbox.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: RunloopConfig, sandboxId: string) => {\n try {\n const client = getRunloopClient(config);\n await client.api.devboxes.shutdown(sandboxId);\n } catch {\n // Devbox might already be destroyed or doesn't exist\n }\n },\n\n runCommand: async (\n sandbox: RunloopSandbox,\n command: string,\n options?: RunCommandOptions\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n let fullCommand = command;\n\n if (options?.env && Object.keys(options.env).length > 0) {\n const envPrefix = Object.entries(options.env)\n .map(([k, v]) => `${k}=\"${escapeShellArg(String(v))}\"`)\n .join(' ');\n fullCommand = `${envPrefix} ${fullCommand}`;\n }\n\n if (options?.cwd) {\n fullCommand = `cd \"${escapeShellArg(options.cwd)}\" && ${fullCommand}`;\n }\n\n if (options?.background) {\n fullCommand = `nohup ${fullCommand} > /dev/null 2>&1 &`;\n }\n\n const executionResult =\n await client.api.devboxes.executeAndAwaitCompletion(devbox.id, {\n command: fullCommand,\n optimistic_timeout: optimisticTimeoutSeconds(options?.timeout),\n }, longPollOptions<RunloopExecuteWaitOptions>(options?.timeout));\n\n return {\n stdout: executionResult.stdout || \"\",\n stderr: executionResult.stderr || \"\",\n exitCode: executionResult.exit_status || 0,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Syntax error\")) {\n throw error;\n }\n throw new Error(\n `Runloop execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox): Promise<SandboxInfo> => {\n const devbox = sandbox;\n const keepAliveSecs = devbox.launch_parameters.keep_alive_time_seconds;\n\n return {\n id: devbox.id || \"runloop-unknown\",\n provider: \"runloop\",\n status: devbox.status as 'running' | 'stopped' | 'error',\n createdAt: new Date(devbox.create_time_ms || Date.now()),\n // keep_alive_time_seconds is in seconds; SandboxInfo.timeout is in milliseconds\n timeout: keepAliveSecs ? keepAliveSecs * 1000 : 300000,\n metadata: {\n runloopDevboxId: devbox.id,\n templateId: devbox.blueprint_id || devbox.snapshot_id,\n runtime: 'node',\n ...devbox.metadata,\n },\n };\n },\n\n getUrl: async (\n sandbox: RunloopSandbox,\n options: { port: number }\n ): Promise<string> => {\n const devbox = sandbox;\n const client = sandbox.client;\n\n try {\n const tunnel = await client.api.devboxes.enableTunnel(devbox.id);\n return `https://${options.port}-${tunnel.tunnel_key}.tunnel.runloop.ai`;\n } catch (error) {\n throw new Error(\n `Failed to get Runloop URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n filesystem: {\n readFile: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<string> => {\n const result = await runCommand(sandbox, `test -f \"${path}\" && base64 < \"${path}\" | tr -d '\\\\n'`);\n if (result.exitCode !== 0) throw new Error(`File not found or unreadable: ${result.stderr}`);\n return Buffer.from(result.stdout, 'base64').toString('utf8');\n },\n\n writeFile: async (sandbox: RunloopSandbox, path: string, content: string, runCommand: CommandRunner): Promise<void> => {\n const encoded = Buffer.from(content).toString('base64');\n const result = await runCommand(sandbox, `sh -c 'echo \"${encoded}\" | base64 -d > \"${path}\"'`);\n if (result.exitCode !== 0) throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n },\n\n mkdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `mkdir -p \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n\n readdir: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<FileEntry[]> => {\n const result = await runCommand(sandbox, `ls -la \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n\n const lines = (result.stdout || \"\")\n .split(\"\\n\")\n .filter((line: string) => line.trim() && !line.startsWith(\"total\"));\n\n return lines.map((line: string) => {\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith(\"d\");\n return {\n name,\n type: isDirectory ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4]) || 0,\n modified: new Date(),\n };\n });\n },\n\n exists: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<boolean> => {\n const result = await runCommand(sandbox, `test -e \"${path}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: RunloopSandbox, path: string, runCommand: CommandRunner): Promise<void> => {\n const result = await runCommand(sandbox, `rm -rf \"${path}\"`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: RunloopSandbox): RunloopSandbox => sandbox,\n },\n\n template: {\n create: async (config: RunloopConfig, options: CreateBlueprintTemplateOptions | Runloop.BlueprintCreateParams) => {\n const client = getRunloopClient(config);\n return client.api.blueprints.create(options);\n },\n\n list: async (config: RunloopConfig, options?: { limit?: number }) => {\n const client = getRunloopClient(config);\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.blueprints.list(listParams);\n return response.blueprints || [];\n },\n\n delete: async (config: RunloopConfig, blueprintId: string) => {\n const client = getRunloopClient(config);\n await client.api.blueprints.delete(blueprintId);\n },\n },\n\n snapshot: {\n create: async (config: RunloopConfig, sandboxId: string, options?: CreateSnapshotOptions) => {\n const client = getRunloopClient(config);\n const snapshotParams: any = {};\n if (options?.name) snapshotParams.name = options.name;\n if (options?.metadata) snapshotParams.metadata = options.metadata;\n return client.api.devboxes.snapshotDisk(sandboxId, snapshotParams);\n },\n\n list: async (config: RunloopConfig, options?: ListSnapshotsOptions) => {\n const client = getRunloopClient(config);\n const listParams: any = {};\n if (options?.limit) listParams.limit = options.limit;\n const response = await client.api.devboxes.listDiskSnapshots(listParams);\n return response.snapshots || [];\n },\n\n delete: async (config: RunloopConfig, snapshotId: string) => {\n const client = getRunloopClient(config);\n await client.api.devboxes.deleteDiskSnapshot(snapshotId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ACzB,YAAI,SAAS,MAAO,YAAW,QAAQ,QAAQ;AAC/C,cAAM,WAAW,MAAM,OAAO,IAAI,SAAS,kBAAkB,UAAU;AACvE,eAAO,SAAS,aAAa,CAAC;AAAA,MAChC;AAAA,MAEA,QAAQ,OAAO,QAAuB,eAAuB;AAC3D,cAAM,SAAS,iBAAiB,MAAM;AACtC,cAAM,OAAO,IAAI,SAAS,mBAAmB,UAAU;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/runloop",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.51",
|
|
4
4
|
"description": "Runloop provider for ComputeSDK - AI-optimized code execution with built-in devtools and debugging",
|
|
5
5
|
"author": "Runloop",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@runloop/api-client": "^1.
|
|
22
|
-
"@computesdk/provider": "2.1.
|
|
23
|
-
"computesdk": "4.1.
|
|
21
|
+
"@runloop/api-client": "^1.21.0",
|
|
22
|
+
"@computesdk/provider": "2.1.3",
|
|
23
|
+
"computesdk": "4.1.3"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"computesdk",
|