@computesdk/superserve 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 computesdk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # @computesdk/superserve
2
+
3
+ Superserve provides sandbox infrastructure to run code in isolated cloud
4
+ environments powered by Firecracker MicroVMs.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install computesdk @computesdk/superserve
10
+ ```
11
+
12
+ ## Setup
13
+
14
+ 1. Get your Superserve API key from [console.superserve.ai](https://console.superserve.ai).
15
+ 2. Set the environment variable:
16
+
17
+ ```bash
18
+ export SUPERSERVE_API_KEY=your_api_key_here
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import { compute } from 'computesdk';
25
+ import { superserve } from '@computesdk/superserve';
26
+
27
+ compute.setConfig({
28
+ provider: superserve({ apiKey: process.env.SUPERSERVE_API_KEY }),
29
+ });
30
+
31
+ const sandbox = await compute.sandbox.create();
32
+
33
+ const result = await sandbox.runCommand('node -v');
34
+ console.log(result.stdout);
35
+
36
+ await sandbox.destroy();
37
+ ```
38
+
39
+ Or call the provider factory directly:
40
+
41
+ ```typescript
42
+ import { superserve } from '@computesdk/superserve';
43
+
44
+ const provider = superserve({ apiKey: process.env.SUPERSERVE_API_KEY });
45
+ const { sandbox } = await provider.sandbox.create();
46
+ ```
47
+
48
+ ## Configuration
49
+
50
+ ```typescript
51
+ superserve({
52
+ apiKey: string, // optional, falls back to SUPERSERVE_API_KEY
53
+ baseUrl: string, // optional, falls back to SUPERSERVE_BASE_URL,
54
+ // then 'https://api.superserve.ai'
55
+ timeout: number, // optional default sandbox idle timeout (ms)
56
+ })
57
+ ```
58
+
59
+ ## Features
60
+
61
+ | Feature | Supported |
62
+ |---|---|
63
+ | Sandbox lifecycle (create / connect / list / destroy) | ✅ |
64
+ | Command execution with cwd, env, and timeout | ✅ |
65
+ | Filesystem (read, write, mkdir, readdir, exists, remove) | ✅ |
66
+ | Templates (boot from named template) | ✅ |
67
+ | Pause / resume (in-place state preservation) | ✅ via `@superserve/sdk` |
68
+ | Snapshots as forkable resources | ❌ Use templates instead |
69
+ | Arbitrary port forwarding (`getUrl`) | ❌ Run a reverse-proxy inside the sandbox |
70
+ | Template build (`template.create`) | ❌ Use `@superserve/sdk` `Template.create` |
71
+
72
+ ## API Reference
73
+
74
+ ### `sandbox.create(options?)`
75
+
76
+ Boots a new microVM. Common options:
77
+
78
+ ```typescript
79
+ await compute.sandbox.create({
80
+ templateId: 'superserve/python-3.11', // optional, defaults to superserve/base
81
+ timeout: 60_000, // idle timeout in ms
82
+ envs: { API_KEY: 'value' },
83
+ name: 'my-sandbox',
84
+ metadata: { source: 'ci' },
85
+ });
86
+ ```
87
+
88
+ Curated templates include `superserve/base`, `superserve/python-3.11`,
89
+ `superserve/node-22`, and others — see the
90
+ [Superserve docs](https://docs.superserve.ai) for the full list.
91
+
92
+ ### `sandbox.runCommand(command, options?)`
93
+
94
+ ```typescript
95
+ const result = await sandbox.runCommand('npm install', {
96
+ cwd: '/app',
97
+ env: { NODE_ENV: 'production' },
98
+ timeout: 120_000,
99
+ });
100
+
101
+ console.log(result.exitCode);
102
+ console.log(result.stdout);
103
+ console.log(result.stderr);
104
+ ```
105
+
106
+ ### `sandbox.filesystem`
107
+
108
+ ```typescript
109
+ await sandbox.filesystem.writeFile('/app/config.json', '{"key":"value"}');
110
+ const text = await sandbox.filesystem.readFile('/app/config.json');
111
+ await sandbox.filesystem.mkdir('/app/data');
112
+ const entries = await sandbox.filesystem.readdir('/app');
113
+ const present = await sandbox.filesystem.exists('/app/config.json');
114
+ await sandbox.filesystem.remove('/app/config.json');
115
+ ```
116
+
117
+ `readFile` and `writeFile` go directly to the per-sandbox data plane.
118
+ `mkdir`, `readdir`, `exists`, and `remove` are implemented via shell
119
+ fallbacks against `sandbox.runCommand` until the data plane exposes
120
+ native filesystem operations.
121
+
122
+ ### `sandbox.getInfo()` / `sandbox.destroy()`
123
+
124
+ ```typescript
125
+ const info = await sandbox.getInfo();
126
+ console.log(info.id, info.status);
127
+
128
+ await sandbox.destroy();
129
+ ```
130
+
131
+ Status mapping: Superserve's `paused` state is reported as ComputeSDK's
132
+ `stopped`, `failed` as `error`, and `active` / `resuming` as `running`.
133
+
134
+ ### `provider.sandbox.list()` and `getById(id)`
135
+
136
+ ```typescript
137
+ const items = await provider.sandbox.list(); // read-only, no side effects
138
+ const { sandbox } = await provider.sandbox.getById(items[0].sandboxId);
139
+ ```
140
+
141
+ `list()` is read-only — it returns `SandboxInfo` stubs without opening a
142
+ session. To actually operate on a listed entry, call `getById(id)`.
143
+
144
+ Note that `getById()` issues `POST /activate` on the sandbox, which
145
+ **auto-resumes paused sandboxes** and rotates their access token. If you
146
+ only need read-only metadata, prefer iterating the result of `list()`
147
+ directly.
148
+
149
+ ### Templates
150
+
151
+ ```typescript
152
+ const templates = await provider.template.list();
153
+ ```
154
+
155
+ To **create** a template, use `@superserve/sdk` directly — templates
156
+ require a build spec (`from` + `steps`), which the ComputeSDK
157
+ `template.create({ name })` shape doesn't carry.
158
+
159
+ ## Error Handling
160
+
161
+ Common errors and how to recover:
162
+
163
+ ```typescript
164
+ try {
165
+ const sandbox = await compute.sandbox.create();
166
+ } catch (error) {
167
+ const msg = error instanceof Error ? error.message : String(error);
168
+
169
+ if (msg.includes('authentication')) {
170
+ // Bad or missing SUPERSERVE_API_KEY
171
+ } else if (msg.includes('quota') || msg.includes('limit')) {
172
+ // Team has hit its concurrent-sandbox cap
173
+ } else {
174
+ // Network or transient platform error — safe to retry with backoff
175
+ }
176
+ }
177
+ ```
178
+
179
+ Authentication failures are normalized into a single user-facing message
180
+ regardless of underlying cause (HTTP 401, missing key, `AuthenticationError`
181
+ from the SDK).
182
+
183
+ ## Examples
184
+
185
+ A runnable example lives in [`examples/basic`](../../examples/basic):
186
+
187
+ ```bash
188
+ cd examples/basic
189
+ export SUPERSERVE_API_KEY=your_key
190
+ pnpm superserve
191
+ ```
192
+
193
+ ## Learn more
194
+
195
+ - [Superserve docs](https://docs.superserve.ai)
196
+ - [`@superserve/sdk`](https://www.npmjs.com/package/@superserve/sdk)
197
+ - [ComputeSDK](https://github.com/computesdk/computesdk)
198
+
199
+ ## License
200
+
201
+ MIT
@@ -0,0 +1,15 @@
1
+ import * as _computesdk_provider from '@computesdk/provider';
2
+ import { Sandbox } from '@superserve/sdk';
3
+ export { Sandbox as SuperserveSandbox } from '@superserve/sdk';
4
+
5
+ interface SuperserveConfig {
6
+ /** Superserve API key. Falls back to `SUPERSERVE_API_KEY` env var. */
7
+ apiKey?: string;
8
+ /** API base URL. Falls back to `SUPERSERVE_BASE_URL` env var, then `https://api.superserve.ai`. */
9
+ baseUrl?: string;
10
+ /** Default sandbox idle timeout in milliseconds. */
11
+ timeout?: number;
12
+ }
13
+ declare const superserve: (config: SuperserveConfig) => _computesdk_provider.Provider<Sandbox, any, any>;
14
+
15
+ export { type SuperserveConfig, superserve };
@@ -0,0 +1,15 @@
1
+ import * as _computesdk_provider from '@computesdk/provider';
2
+ import { Sandbox } from '@superserve/sdk';
3
+ export { Sandbox as SuperserveSandbox } from '@superserve/sdk';
4
+
5
+ interface SuperserveConfig {
6
+ /** Superserve API key. Falls back to `SUPERSERVE_API_KEY` env var. */
7
+ apiKey?: string;
8
+ /** API base URL. Falls back to `SUPERSERVE_BASE_URL` env var, then `https://api.superserve.ai`. */
9
+ baseUrl?: string;
10
+ /** Default sandbox idle timeout in milliseconds. */
11
+ timeout?: number;
12
+ }
13
+ declare const superserve: (config: SuperserveConfig) => _computesdk_provider.Provider<Sandbox, any, any>;
14
+
15
+ export { type SuperserveConfig, superserve };
package/dist/index.js ADDED
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ superserve: () => superserve
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_node_crypto = require("crypto");
27
+ var import_sdk = require("@superserve/sdk");
28
+ var import_provider = require("@computesdk/provider");
29
+ var DEFAULT_TIMEOUT_MS = 3e5;
30
+ function resolveApiKey(config) {
31
+ const apiKey = config.apiKey || process.env.SUPERSERVE_API_KEY;
32
+ if (!apiKey) {
33
+ throw new Error(
34
+ `Missing Superserve API key. Provide 'apiKey' in config or set SUPERSERVE_API_KEY environment variable.`
35
+ );
36
+ }
37
+ return apiKey;
38
+ }
39
+ function resolveBaseUrl(config) {
40
+ return config.baseUrl || process.env.SUPERSERVE_BASE_URL || void 0;
41
+ }
42
+ function generateSandboxName() {
43
+ return `cs-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`;
44
+ }
45
+ function rethrowFriendly(error, fallbackPrefix) {
46
+ if (error instanceof import_sdk.AuthenticationError) {
47
+ throw new Error(
48
+ `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`
49
+ );
50
+ }
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ const lower = message.toLowerCase();
53
+ if (lower.includes("unauthorized") || lower.includes("401") || lower.includes("api key")) {
54
+ throw new Error(
55
+ `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`
56
+ );
57
+ }
58
+ if (lower.includes("quota") || lower.includes("limit") || lower.includes("429")) {
59
+ throw new Error(`Superserve quota or rate limit reached: ${message}`);
60
+ }
61
+ throw new Error(`${fallbackPrefix}: ${message}`);
62
+ }
63
+ var superserve = (0, import_provider.defineProvider)({
64
+ name: "superserve",
65
+ methods: {
66
+ sandbox: {
67
+ create: async (config, options) => {
68
+ const apiKey = resolveApiKey(config);
69
+ const baseUrl = resolveBaseUrl(config);
70
+ const {
71
+ timeout: requestedTimeoutMs,
72
+ envs,
73
+ name,
74
+ metadata,
75
+ templateId,
76
+ // Superserve has no snapshot resource — `snapshotId` is dropped here
77
+ // intentionally; use `templateId` (a Superserve template UUID or name)
78
+ // instead. See `snapshot` block below for context.
79
+ snapshotId: _snapshotId,
80
+ namespace: _namespace,
81
+ directory: _directory,
82
+ ...providerOptions
83
+ } = options || {};
84
+ const ttMs = requestedTimeoutMs ?? config.timeout;
85
+ const timeoutSeconds = ttMs !== void 0 ? Math.max(1, Math.ceil(ttMs / 1e3)) : void 0;
86
+ try {
87
+ const sandbox = await import_sdk.Sandbox.create({
88
+ apiKey,
89
+ baseUrl,
90
+ name: name ?? generateSandboxName(),
91
+ ...templateId ? { fromTemplate: templateId } : {},
92
+ ...timeoutSeconds !== void 0 ? { timeoutSeconds } : {},
93
+ ...metadata ? { metadata } : {},
94
+ ...envs ? { envVars: envs } : {},
95
+ ...providerOptions
96
+ });
97
+ return { sandbox, sandboxId: sandbox.id };
98
+ } catch (error) {
99
+ rethrowFriendly(error, "Failed to create Superserve sandbox");
100
+ }
101
+ },
102
+ getById: async (config, sandboxId) => {
103
+ const apiKey = resolveApiKey(config);
104
+ const baseUrl = resolveBaseUrl(config);
105
+ try {
106
+ const sandbox = await import_sdk.Sandbox.connect(sandboxId, { apiKey, baseUrl });
107
+ return { sandbox, sandboxId: sandbox.id };
108
+ } catch {
109
+ return null;
110
+ }
111
+ },
112
+ list: async (config) => {
113
+ const apiKey = resolveApiKey(config);
114
+ const baseUrl = resolveBaseUrl(config);
115
+ try {
116
+ const infos = await import_sdk.Sandbox.list({ apiKey, baseUrl });
117
+ return infos.map((info) => ({
118
+ sandbox: info,
119
+ sandboxId: info.id
120
+ }));
121
+ } catch {
122
+ return [];
123
+ }
124
+ },
125
+ destroy: async (config, sandboxId) => {
126
+ const apiKey = resolveApiKey(config);
127
+ const baseUrl = resolveBaseUrl(config);
128
+ try {
129
+ await import_sdk.Sandbox.killById(sandboxId, { apiKey, baseUrl });
130
+ } catch {
131
+ }
132
+ },
133
+ runCommand: async (sandbox, command, options) => {
134
+ const startTime = Date.now();
135
+ try {
136
+ let fullCommand = command;
137
+ if (options?.background) {
138
+ fullCommand = `nohup sh -c "${(0, import_provider.escapeShellArg)(fullCommand)}" > /dev/null 2>&1 &`;
139
+ }
140
+ const result = await sandbox.commands.run(fullCommand, {
141
+ cwd: options?.cwd,
142
+ env: options?.env,
143
+ timeoutMs: options?.timeout
144
+ });
145
+ return {
146
+ stdout: result.stdout,
147
+ stderr: result.stderr,
148
+ exitCode: result.exitCode,
149
+ durationMs: Date.now() - startTime
150
+ };
151
+ } catch (error) {
152
+ return {
153
+ stdout: "",
154
+ stderr: error instanceof Error ? error.message : String(error),
155
+ exitCode: 127,
156
+ durationMs: Date.now() - startTime
157
+ };
158
+ }
159
+ },
160
+ getInfo: async (sandbox) => {
161
+ const info = await sandbox.getInfo();
162
+ const status = info.status === "paused" ? "stopped" : info.status === "failed" ? "error" : "running";
163
+ return {
164
+ id: info.id,
165
+ provider: "superserve",
166
+ status,
167
+ createdAt: info.createdAt,
168
+ timeout: info.timeoutSeconds ? info.timeoutSeconds * 1e3 : DEFAULT_TIMEOUT_MS,
169
+ metadata: info.metadata
170
+ };
171
+ },
172
+ getUrl: async (_sandbox, _options) => {
173
+ throw new Error(
174
+ "Superserve does not currently support arbitrary port forwarding via getUrl(). Use sandbox.commands.run() to interact with services running inside the sandbox."
175
+ );
176
+ },
177
+ filesystem: {
178
+ readFile: async (sandbox, path) => {
179
+ return sandbox.files.readText(path);
180
+ },
181
+ writeFile: async (sandbox, path, content) => {
182
+ await sandbox.files.write(path, content);
183
+ },
184
+ mkdir: async (sandbox, path) => {
185
+ const result = await sandbox.commands.run(`mkdir -p "${(0, import_provider.escapeShellArg)(path)}"`);
186
+ if (result.exitCode !== 0) {
187
+ throw new Error(`mkdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);
188
+ }
189
+ },
190
+ readdir: async (sandbox, path) => {
191
+ const cmd = [
192
+ `cd "${(0, import_provider.escapeShellArg)(path)}" || exit 2`,
193
+ `find . -mindepth 1 -maxdepth 1 -printf '%y\\t%s\\t%T@\\t%f\\n' 2>/dev/null`
194
+ ].join(" && ");
195
+ const result = await sandbox.commands.run(cmd);
196
+ if (result.exitCode === 2) {
197
+ throw new Error(`readdir: directory not found: ${path}`);
198
+ }
199
+ if (result.exitCode !== 0) {
200
+ throw new Error(`readdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);
201
+ }
202
+ const entries = [];
203
+ for (const line of result.stdout.split("\n")) {
204
+ if (!line) continue;
205
+ const [type, sizeStr, mtimeStr, ...nameParts] = line.split(" ");
206
+ const name = nameParts.join(" ");
207
+ if (!name) continue;
208
+ const size = Number.parseInt(sizeStr, 10);
209
+ const mtime = Number.parseFloat(mtimeStr);
210
+ entries.push({
211
+ name,
212
+ type: type === "d" ? "directory" : "file",
213
+ size: Number.isFinite(size) ? size : 0,
214
+ modified: Number.isFinite(mtime) ? new Date(mtime * 1e3) : /* @__PURE__ */ new Date()
215
+ });
216
+ }
217
+ return entries;
218
+ },
219
+ exists: async (sandbox, path) => {
220
+ const result = await sandbox.commands.run(`test -e "${(0, import_provider.escapeShellArg)(path)}"`);
221
+ return result.exitCode === 0;
222
+ },
223
+ remove: async (sandbox, path) => {
224
+ const result = await sandbox.commands.run(`rm -rf "${(0, import_provider.escapeShellArg)(path)}"`);
225
+ if (result.exitCode !== 0) {
226
+ throw new Error(`remove failed: ${result.stderr || `exit code ${result.exitCode}`}`);
227
+ }
228
+ }
229
+ },
230
+ getInstance: (sandbox) => sandbox
231
+ },
232
+ // Superserve has no standalone snapshot resource — pause/resume is 1:1
233
+ // and not forkable. Templates are the closest analog (wired below).
234
+ snapshot: {
235
+ create: async (_config, _sandboxId, _options) => {
236
+ throw new Error(
237
+ "Superserve does not expose snapshots as a separate resource. Use Template.create() with a build spec for reusable base images, or sandbox.pause() / sandbox.resume() for in-place state preservation."
238
+ );
239
+ },
240
+ list: async (_config) => {
241
+ return [];
242
+ },
243
+ delete: async (_config, _snapshotId) => {
244
+ }
245
+ },
246
+ template: {
247
+ create: async (_config, _options) => {
248
+ throw new Error(
249
+ "Templates require a build spec. Use the @superserve/sdk Template.create() API directly with `from` and `steps`, or define templates via the Superserve console."
250
+ );
251
+ },
252
+ list: async (config) => {
253
+ const apiKey = resolveApiKey(config);
254
+ const baseUrl = resolveBaseUrl(config);
255
+ try {
256
+ const infos = await import_sdk.Template.list({ apiKey, baseUrl });
257
+ return infos.map((info) => ({
258
+ id: info.id,
259
+ name: info.name,
260
+ createdAt: info.createdAt,
261
+ metadata: { status: info.status, vcpu: info.vcpu, memoryMib: info.memoryMib }
262
+ }));
263
+ } catch {
264
+ return [];
265
+ }
266
+ },
267
+ delete: async (config, templateId) => {
268
+ const apiKey = resolveApiKey(config);
269
+ const baseUrl = resolveBaseUrl(config);
270
+ try {
271
+ await import_sdk.Template.deleteById(templateId, { apiKey, baseUrl });
272
+ } catch {
273
+ }
274
+ }
275
+ }
276
+ }
277
+ });
278
+ // Annotate the CommonJS export names for ESM import in node:
279
+ 0 && (module.exports = {
280
+ superserve
281
+ });
282
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Superserve Provider - Factory-based Implementation\n *\n * Wraps `@superserve/sdk` to expose the ComputeSDK provider interface.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport {\n AuthenticationError,\n Sandbox as SuperserveSandbox,\n Template as SuperserveTemplate,\n} from '@superserve/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nconst DEFAULT_TIMEOUT_MS = 300_000;\n\nimport type {\n CommandResult,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n SandboxInfo,\n} from '@computesdk/provider';\n\nexport interface SuperserveConfig {\n /** Superserve API key. Falls back to `SUPERSERVE_API_KEY` env var. */\n apiKey?: string;\n /** API base URL. Falls back to `SUPERSERVE_BASE_URL` env var, then `https://api.superserve.ai`. */\n baseUrl?: string;\n /** Default sandbox idle timeout in milliseconds. */\n timeout?: number;\n}\n\nfunction resolveApiKey(config: SuperserveConfig): string {\n const apiKey = config.apiKey || process.env.SUPERSERVE_API_KEY;\n if (!apiKey) {\n throw new Error(\n `Missing Superserve API key. Provide 'apiKey' in config or set SUPERSERVE_API_KEY environment variable.`,\n );\n }\n return apiKey;\n}\n\nfunction resolveBaseUrl(config: SuperserveConfig): string | undefined {\n // Returns undefined when unset on purpose: the SDK then applies its own\n // resolution (SUPERSERVE_BASE_URL env var, then its https://api.superserve.ai\n // default), so we don't duplicate that constant and risk it drifting.\n return config.baseUrl || process.env.SUPERSERVE_BASE_URL || undefined;\n}\n\nfunction generateSandboxName(): string {\n return `cs-${randomUUID().slice(0, 8)}`;\n}\n\nfunction rethrowFriendly(error: unknown, fallbackPrefix: string): never {\n if (error instanceof AuthenticationError) {\n throw new Error(\n `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`,\n );\n }\n const message = error instanceof Error ? error.message : String(error);\n const lower = message.toLowerCase();\n if (lower.includes('unauthorized') || lower.includes('401') || lower.includes('api key')) {\n throw new Error(\n `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`,\n );\n }\n if (lower.includes('quota') || lower.includes('limit') || lower.includes('429')) {\n throw new Error(`Superserve quota or rate limit reached: ${message}`);\n }\n throw new Error(`${fallbackPrefix}: ${message}`);\n}\n\nexport const superserve = defineProvider<SuperserveSandbox, SuperserveConfig>({\n name: 'superserve',\n methods: {\n sandbox: {\n create: async (config: SuperserveConfig, options?: CreateSandboxOptions) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n\n const {\n timeout: requestedTimeoutMs,\n envs,\n name,\n metadata,\n templateId,\n // Superserve has no snapshot resource — `snapshotId` is dropped here\n // intentionally; use `templateId` (a Superserve template UUID or name)\n // instead. See `snapshot` block below for context.\n snapshotId: _snapshotId,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const ttMs = requestedTimeoutMs ?? config.timeout;\n const timeoutSeconds = ttMs !== undefined ? Math.max(1, Math.ceil(ttMs / 1000)) : undefined;\n\n try {\n const sandbox = await SuperserveSandbox.create({\n apiKey,\n baseUrl,\n name: name ?? generateSandboxName(),\n ...(templateId ? { fromTemplate: templateId } : {}),\n ...(timeoutSeconds !== undefined ? { timeoutSeconds } : {}),\n ...(metadata ? { metadata: metadata as Record<string, string> } : {}),\n ...(envs ? { envVars: envs } : {}),\n ...providerOptions,\n });\n return { sandbox, sandboxId: sandbox.id };\n } catch (error) {\n rethrowFriendly(error, 'Failed to create Superserve sandbox');\n }\n },\n\n getById: async (config: SuperserveConfig, sandboxId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const sandbox = await SuperserveSandbox.connect(sandboxId, { apiKey, baseUrl });\n return { sandbox, sandboxId: sandbox.id };\n } catch {\n return null;\n }\n },\n\n list: async (config: SuperserveConfig) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const infos = await SuperserveSandbox.list({ apiKey, baseUrl });\n // No per-item connect() — that would POST /activate and resume paused sandboxes.\n return infos.map((info) => ({\n sandbox: info as unknown as SuperserveSandbox,\n sandboxId: info.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: SuperserveConfig, sandboxId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n await SuperserveSandbox.killById(sandboxId, { apiKey, baseUrl });\n } catch {\n /* already destroyed */\n }\n },\n\n runCommand: async (\n sandbox: SuperserveSandbox,\n command: string,\n options?: RunCommandOptions,\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n let fullCommand = command;\n if (options?.background) {\n // Run the whole command under `sh -c` so the trailing `&` backgrounds\n // the entire command (not just its last statement), and escape it so\n // the user's command can't break out of the nohup wrapper.\n fullCommand = `nohup sh -c \"${escapeShellArg(fullCommand)}\" > /dev/null 2>&1 &`;\n }\n const result = await sandbox.commands.run(fullCommand, {\n cwd: options?.cwd,\n env: options?.env,\n timeoutMs: options?.timeout,\n });\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n getInfo: async (sandbox: SuperserveSandbox): Promise<SandboxInfo> => {\n const info = await sandbox.getInfo();\n const status: SandboxInfo['status'] =\n info.status === 'paused' ? 'stopped' :\n info.status === 'failed' ? 'error' :\n 'running';\n return {\n id: info.id,\n provider: 'superserve',\n status,\n createdAt: info.createdAt,\n timeout: info.timeoutSeconds ? info.timeoutSeconds * 1000 : DEFAULT_TIMEOUT_MS,\n metadata: info.metadata,\n };\n },\n\n getUrl: async (_sandbox: SuperserveSandbox, _options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n 'Superserve does not currently support arbitrary port forwarding via getUrl(). ' +\n 'Use sandbox.commands.run() to interact with services running inside the sandbox.',\n );\n },\n\n filesystem: {\n readFile: async (sandbox: SuperserveSandbox, path: string): Promise<string> => {\n return sandbox.files.readText(path);\n },\n\n writeFile: async (sandbox: SuperserveSandbox, path: string, content: string): Promise<void> => {\n await sandbox.files.write(path, content);\n },\n\n mkdir: async (sandbox: SuperserveSandbox, path: string): Promise<void> => {\n const result = await sandbox.commands.run(`mkdir -p \"${escapeShellArg(path)}\"`);\n if (result.exitCode !== 0) {\n throw new Error(`mkdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n },\n\n readdir: async (sandbox: SuperserveSandbox, path: string): Promise<FileEntry[]> => {\n // find -printf format: <type>\\t<size>\\t<mtime-epoch>\\t<name>\n const cmd = [\n `cd \"${escapeShellArg(path)}\" || exit 2`,\n `find . -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n' 2>/dev/null`,\n ].join(' && ');\n const result = await sandbox.commands.run(cmd);\n if (result.exitCode === 2) {\n throw new Error(`readdir: directory not found: ${path}`);\n }\n if (result.exitCode !== 0) {\n throw new Error(`readdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n const entries: FileEntry[] = [];\n for (const line of result.stdout.split('\\n')) {\n if (!line) continue;\n const [type, sizeStr, mtimeStr, ...nameParts] = line.split('\\t');\n const name = nameParts.join('\\t');\n if (!name) continue;\n const size = Number.parseInt(sizeStr, 10);\n const mtime = Number.parseFloat(mtimeStr);\n entries.push({\n name,\n type: type === 'd' ? 'directory' : 'file',\n size: Number.isFinite(size) ? size : 0,\n modified: Number.isFinite(mtime) ? new Date(mtime * 1000) : new Date(),\n });\n }\n return entries;\n },\n\n exists: async (sandbox: SuperserveSandbox, path: string): Promise<boolean> => {\n const result = await sandbox.commands.run(`test -e \"${escapeShellArg(path)}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: SuperserveSandbox, path: string): Promise<void> => {\n const result = await sandbox.commands.run(`rm -rf \"${escapeShellArg(path)}\"`);\n if (result.exitCode !== 0) {\n throw new Error(`remove failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n },\n },\n\n getInstance: (sandbox: SuperserveSandbox): SuperserveSandbox => sandbox,\n },\n\n // Superserve has no standalone snapshot resource — pause/resume is 1:1\n // and not forkable. Templates are the closest analog (wired below).\n snapshot: {\n create: async (_config: SuperserveConfig, _sandboxId: string, _options?: { name?: string }) => {\n throw new Error(\n 'Superserve does not expose snapshots as a separate resource. ' +\n 'Use Template.create() with a build spec for reusable base images, ' +\n 'or sandbox.pause() / sandbox.resume() for in-place state preservation.',\n );\n },\n list: async (_config: SuperserveConfig) => {\n return [];\n },\n delete: async (_config: SuperserveConfig, _snapshotId: string) => {\n /* no-op: snapshots are not a separate resource */\n },\n },\n\n template: {\n create: async (_config: SuperserveConfig, _options: { name: string }) => {\n throw new Error(\n 'Templates require a build spec. Use the @superserve/sdk Template.create() ' +\n 'API directly with `from` and `steps`, or define templates via the Superserve console.',\n );\n },\n list: async (config: SuperserveConfig) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const infos = await SuperserveTemplate.list({ apiKey, baseUrl });\n return infos.map((info) => ({\n id: info.id,\n name: info.name,\n createdAt: info.createdAt,\n metadata: { status: info.status, vcpu: info.vcpu, memoryMib: info.memoryMib },\n }));\n } catch {\n return [];\n }\n },\n delete: async (config: SuperserveConfig, templateId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n await SuperserveTemplate.deleteById(templateId, { apiKey, baseUrl });\n } catch {\n /* already deleted */\n }\n },\n },\n },\n});\n\nexport type { Sandbox as SuperserveSandbox } from '@superserve/sdk';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,yBAA2B;AAC3B,iBAIO;AACP,sBAA+C;AAE/C,IAAM,qBAAqB;AAmB3B,SAAS,cAAc,QAAkC;AACvD,QAAM,SAAS,OAAO,UAAU,QAAQ,IAAI;AAC5C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,eAAe,QAA8C;AAIpE,SAAO,OAAO,WAAW,QAAQ,IAAI,uBAAuB;AAC9D;AAEA,SAAS,sBAA8B;AACrC,SAAO,UAAM,+BAAW,EAAE,MAAM,GAAG,CAAC,CAAC;AACvC;AAEA,SAAS,gBAAgB,OAAgB,gBAA+B;AACtE,MAAI,iBAAiB,gCAAqB;AACxC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,QAAM,QAAQ,QAAQ,YAAY;AAClC,MAAI,MAAM,SAAS,cAAc,KAAK,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,SAAS,GAAG;AACxF,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,MAAM,SAAS,OAAO,KAAK,MAAM,SAAS,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG;AAC/E,UAAM,IAAI,MAAM,2CAA2C,OAAO,EAAE;AAAA,EACtE;AACA,QAAM,IAAI,MAAM,GAAG,cAAc,KAAK,OAAO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YAA8B;AACzC,eAAO,CAAC;AAAA,MACV;AAAA,MACA,QAAQ,OAAO,SAA2B,gBAAwB;AAAA,MAElE;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,QAAQ,OAAO,SAA2B,aAA+B;AACvE,cAAM,IAAI;AAAA,UACR;AAAA,QAEF;AAAA,MACF;AAAA,MACA,MAAM,OAAO,WAA6B;AACxC,cAAM,SAAS,cAAc,MAAM;AACnC,cAAM,UAAU,eAAe,MAAM;AACrC,YAAI;AACF,gBAAM,QAAQ,MAAM,WAAAC,SAAmB,KAAK,EAAE,QAAQ,QAAQ,CAAC;AAC/D,iBAAO,MAAM,IAAI,CAAC,UAAU;AAAA,YAC1B,IAAI,KAAK;AAAA,YACT,MAAM,KAAK;AAAA,YACX,WAAW,KAAK;AAAA,YAChB,UAAU,EAAE,QAAQ,KAAK,QAAQ,MAAM,KAAK,MAAM,WAAW,KAAK,UAAU;AAAA,UAC9E,EAAE;AAAA,QACJ,QAAQ;AACN,iBAAO,CAAC;AAAA,QACV;AAAA,MACF;AAAA,MACA,QAAQ,OAAO,QAA0B,eAAuB;AAC9D,cAAM,SAAS,cAAc,MAAM;AACnC,cAAM,UAAU,eAAe,MAAM;AACrC,YAAI;AACF,gBAAM,WAAAA,SAAmB,WAAW,YAAY,EAAE,QAAQ,QAAQ,CAAC;AAAA,QACrE,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":["SuperserveSandbox","SuperserveTemplate"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,261 @@
1
+ // src/index.ts
2
+ import { randomUUID } from "crypto";
3
+ import {
4
+ AuthenticationError,
5
+ Sandbox as SuperserveSandbox,
6
+ Template as SuperserveTemplate
7
+ } from "@superserve/sdk";
8
+ import { defineProvider, escapeShellArg } from "@computesdk/provider";
9
+ var DEFAULT_TIMEOUT_MS = 3e5;
10
+ function resolveApiKey(config) {
11
+ const apiKey = config.apiKey || process.env.SUPERSERVE_API_KEY;
12
+ if (!apiKey) {
13
+ throw new Error(
14
+ `Missing Superserve API key. Provide 'apiKey' in config or set SUPERSERVE_API_KEY environment variable.`
15
+ );
16
+ }
17
+ return apiKey;
18
+ }
19
+ function resolveBaseUrl(config) {
20
+ return config.baseUrl || process.env.SUPERSERVE_BASE_URL || void 0;
21
+ }
22
+ function generateSandboxName() {
23
+ return `cs-${randomUUID().slice(0, 8)}`;
24
+ }
25
+ function rethrowFriendly(error, fallbackPrefix) {
26
+ if (error instanceof AuthenticationError) {
27
+ throw new Error(
28
+ `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`
29
+ );
30
+ }
31
+ const message = error instanceof Error ? error.message : String(error);
32
+ const lower = message.toLowerCase();
33
+ if (lower.includes("unauthorized") || lower.includes("401") || lower.includes("api key")) {
34
+ throw new Error(
35
+ `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`
36
+ );
37
+ }
38
+ if (lower.includes("quota") || lower.includes("limit") || lower.includes("429")) {
39
+ throw new Error(`Superserve quota or rate limit reached: ${message}`);
40
+ }
41
+ throw new Error(`${fallbackPrefix}: ${message}`);
42
+ }
43
+ var superserve = defineProvider({
44
+ name: "superserve",
45
+ methods: {
46
+ sandbox: {
47
+ create: async (config, options) => {
48
+ const apiKey = resolveApiKey(config);
49
+ const baseUrl = resolveBaseUrl(config);
50
+ const {
51
+ timeout: requestedTimeoutMs,
52
+ envs,
53
+ name,
54
+ metadata,
55
+ templateId,
56
+ // Superserve has no snapshot resource — `snapshotId` is dropped here
57
+ // intentionally; use `templateId` (a Superserve template UUID or name)
58
+ // instead. See `snapshot` block below for context.
59
+ snapshotId: _snapshotId,
60
+ namespace: _namespace,
61
+ directory: _directory,
62
+ ...providerOptions
63
+ } = options || {};
64
+ const ttMs = requestedTimeoutMs ?? config.timeout;
65
+ const timeoutSeconds = ttMs !== void 0 ? Math.max(1, Math.ceil(ttMs / 1e3)) : void 0;
66
+ try {
67
+ const sandbox = await SuperserveSandbox.create({
68
+ apiKey,
69
+ baseUrl,
70
+ name: name ?? generateSandboxName(),
71
+ ...templateId ? { fromTemplate: templateId } : {},
72
+ ...timeoutSeconds !== void 0 ? { timeoutSeconds } : {},
73
+ ...metadata ? { metadata } : {},
74
+ ...envs ? { envVars: envs } : {},
75
+ ...providerOptions
76
+ });
77
+ return { sandbox, sandboxId: sandbox.id };
78
+ } catch (error) {
79
+ rethrowFriendly(error, "Failed to create Superserve sandbox");
80
+ }
81
+ },
82
+ getById: async (config, sandboxId) => {
83
+ const apiKey = resolveApiKey(config);
84
+ const baseUrl = resolveBaseUrl(config);
85
+ try {
86
+ const sandbox = await SuperserveSandbox.connect(sandboxId, { apiKey, baseUrl });
87
+ return { sandbox, sandboxId: sandbox.id };
88
+ } catch {
89
+ return null;
90
+ }
91
+ },
92
+ list: async (config) => {
93
+ const apiKey = resolveApiKey(config);
94
+ const baseUrl = resolveBaseUrl(config);
95
+ try {
96
+ const infos = await SuperserveSandbox.list({ apiKey, baseUrl });
97
+ return infos.map((info) => ({
98
+ sandbox: info,
99
+ sandboxId: info.id
100
+ }));
101
+ } catch {
102
+ return [];
103
+ }
104
+ },
105
+ destroy: async (config, sandboxId) => {
106
+ const apiKey = resolveApiKey(config);
107
+ const baseUrl = resolveBaseUrl(config);
108
+ try {
109
+ await SuperserveSandbox.killById(sandboxId, { apiKey, baseUrl });
110
+ } catch {
111
+ }
112
+ },
113
+ runCommand: async (sandbox, command, options) => {
114
+ const startTime = Date.now();
115
+ try {
116
+ let fullCommand = command;
117
+ if (options?.background) {
118
+ fullCommand = `nohup sh -c "${escapeShellArg(fullCommand)}" > /dev/null 2>&1 &`;
119
+ }
120
+ const result = await sandbox.commands.run(fullCommand, {
121
+ cwd: options?.cwd,
122
+ env: options?.env,
123
+ timeoutMs: options?.timeout
124
+ });
125
+ return {
126
+ stdout: result.stdout,
127
+ stderr: result.stderr,
128
+ exitCode: result.exitCode,
129
+ durationMs: Date.now() - startTime
130
+ };
131
+ } catch (error) {
132
+ return {
133
+ stdout: "",
134
+ stderr: error instanceof Error ? error.message : String(error),
135
+ exitCode: 127,
136
+ durationMs: Date.now() - startTime
137
+ };
138
+ }
139
+ },
140
+ getInfo: async (sandbox) => {
141
+ const info = await sandbox.getInfo();
142
+ const status = info.status === "paused" ? "stopped" : info.status === "failed" ? "error" : "running";
143
+ return {
144
+ id: info.id,
145
+ provider: "superserve",
146
+ status,
147
+ createdAt: info.createdAt,
148
+ timeout: info.timeoutSeconds ? info.timeoutSeconds * 1e3 : DEFAULT_TIMEOUT_MS,
149
+ metadata: info.metadata
150
+ };
151
+ },
152
+ getUrl: async (_sandbox, _options) => {
153
+ throw new Error(
154
+ "Superserve does not currently support arbitrary port forwarding via getUrl(). Use sandbox.commands.run() to interact with services running inside the sandbox."
155
+ );
156
+ },
157
+ filesystem: {
158
+ readFile: async (sandbox, path) => {
159
+ return sandbox.files.readText(path);
160
+ },
161
+ writeFile: async (sandbox, path, content) => {
162
+ await sandbox.files.write(path, content);
163
+ },
164
+ mkdir: async (sandbox, path) => {
165
+ const result = await sandbox.commands.run(`mkdir -p "${escapeShellArg(path)}"`);
166
+ if (result.exitCode !== 0) {
167
+ throw new Error(`mkdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);
168
+ }
169
+ },
170
+ readdir: async (sandbox, path) => {
171
+ const cmd = [
172
+ `cd "${escapeShellArg(path)}" || exit 2`,
173
+ `find . -mindepth 1 -maxdepth 1 -printf '%y\\t%s\\t%T@\\t%f\\n' 2>/dev/null`
174
+ ].join(" && ");
175
+ const result = await sandbox.commands.run(cmd);
176
+ if (result.exitCode === 2) {
177
+ throw new Error(`readdir: directory not found: ${path}`);
178
+ }
179
+ if (result.exitCode !== 0) {
180
+ throw new Error(`readdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);
181
+ }
182
+ const entries = [];
183
+ for (const line of result.stdout.split("\n")) {
184
+ if (!line) continue;
185
+ const [type, sizeStr, mtimeStr, ...nameParts] = line.split(" ");
186
+ const name = nameParts.join(" ");
187
+ if (!name) continue;
188
+ const size = Number.parseInt(sizeStr, 10);
189
+ const mtime = Number.parseFloat(mtimeStr);
190
+ entries.push({
191
+ name,
192
+ type: type === "d" ? "directory" : "file",
193
+ size: Number.isFinite(size) ? size : 0,
194
+ modified: Number.isFinite(mtime) ? new Date(mtime * 1e3) : /* @__PURE__ */ new Date()
195
+ });
196
+ }
197
+ return entries;
198
+ },
199
+ exists: async (sandbox, path) => {
200
+ const result = await sandbox.commands.run(`test -e "${escapeShellArg(path)}"`);
201
+ return result.exitCode === 0;
202
+ },
203
+ remove: async (sandbox, path) => {
204
+ const result = await sandbox.commands.run(`rm -rf "${escapeShellArg(path)}"`);
205
+ if (result.exitCode !== 0) {
206
+ throw new Error(`remove failed: ${result.stderr || `exit code ${result.exitCode}`}`);
207
+ }
208
+ }
209
+ },
210
+ getInstance: (sandbox) => sandbox
211
+ },
212
+ // Superserve has no standalone snapshot resource — pause/resume is 1:1
213
+ // and not forkable. Templates are the closest analog (wired below).
214
+ snapshot: {
215
+ create: async (_config, _sandboxId, _options) => {
216
+ throw new Error(
217
+ "Superserve does not expose snapshots as a separate resource. Use Template.create() with a build spec for reusable base images, or sandbox.pause() / sandbox.resume() for in-place state preservation."
218
+ );
219
+ },
220
+ list: async (_config) => {
221
+ return [];
222
+ },
223
+ delete: async (_config, _snapshotId) => {
224
+ }
225
+ },
226
+ template: {
227
+ create: async (_config, _options) => {
228
+ throw new Error(
229
+ "Templates require a build spec. Use the @superserve/sdk Template.create() API directly with `from` and `steps`, or define templates via the Superserve console."
230
+ );
231
+ },
232
+ list: async (config) => {
233
+ const apiKey = resolveApiKey(config);
234
+ const baseUrl = resolveBaseUrl(config);
235
+ try {
236
+ const infos = await SuperserveTemplate.list({ apiKey, baseUrl });
237
+ return infos.map((info) => ({
238
+ id: info.id,
239
+ name: info.name,
240
+ createdAt: info.createdAt,
241
+ metadata: { status: info.status, vcpu: info.vcpu, memoryMib: info.memoryMib }
242
+ }));
243
+ } catch {
244
+ return [];
245
+ }
246
+ },
247
+ delete: async (config, templateId) => {
248
+ const apiKey = resolveApiKey(config);
249
+ const baseUrl = resolveBaseUrl(config);
250
+ try {
251
+ await SuperserveTemplate.deleteById(templateId, { apiKey, baseUrl });
252
+ } catch {
253
+ }
254
+ }
255
+ }
256
+ }
257
+ });
258
+ export {
259
+ superserve
260
+ };
261
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Superserve Provider - Factory-based Implementation\n *\n * Wraps `@superserve/sdk` to expose the ComputeSDK provider interface.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport {\n AuthenticationError,\n Sandbox as SuperserveSandbox,\n Template as SuperserveTemplate,\n} from '@superserve/sdk';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\n\nconst DEFAULT_TIMEOUT_MS = 300_000;\n\nimport type {\n CommandResult,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n SandboxInfo,\n} from '@computesdk/provider';\n\nexport interface SuperserveConfig {\n /** Superserve API key. Falls back to `SUPERSERVE_API_KEY` env var. */\n apiKey?: string;\n /** API base URL. Falls back to `SUPERSERVE_BASE_URL` env var, then `https://api.superserve.ai`. */\n baseUrl?: string;\n /** Default sandbox idle timeout in milliseconds. */\n timeout?: number;\n}\n\nfunction resolveApiKey(config: SuperserveConfig): string {\n const apiKey = config.apiKey || process.env.SUPERSERVE_API_KEY;\n if (!apiKey) {\n throw new Error(\n `Missing Superserve API key. Provide 'apiKey' in config or set SUPERSERVE_API_KEY environment variable.`,\n );\n }\n return apiKey;\n}\n\nfunction resolveBaseUrl(config: SuperserveConfig): string | undefined {\n // Returns undefined when unset on purpose: the SDK then applies its own\n // resolution (SUPERSERVE_BASE_URL env var, then its https://api.superserve.ai\n // default), so we don't duplicate that constant and risk it drifting.\n return config.baseUrl || process.env.SUPERSERVE_BASE_URL || undefined;\n}\n\nfunction generateSandboxName(): string {\n return `cs-${randomUUID().slice(0, 8)}`;\n}\n\nfunction rethrowFriendly(error: unknown, fallbackPrefix: string): never {\n if (error instanceof AuthenticationError) {\n throw new Error(\n `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`,\n );\n }\n const message = error instanceof Error ? error.message : String(error);\n const lower = message.toLowerCase();\n if (lower.includes('unauthorized') || lower.includes('401') || lower.includes('api key')) {\n throw new Error(\n `Superserve authentication failed. Please check your SUPERSERVE_API_KEY environment variable.`,\n );\n }\n if (lower.includes('quota') || lower.includes('limit') || lower.includes('429')) {\n throw new Error(`Superserve quota or rate limit reached: ${message}`);\n }\n throw new Error(`${fallbackPrefix}: ${message}`);\n}\n\nexport const superserve = defineProvider<SuperserveSandbox, SuperserveConfig>({\n name: 'superserve',\n methods: {\n sandbox: {\n create: async (config: SuperserveConfig, options?: CreateSandboxOptions) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n\n const {\n timeout: requestedTimeoutMs,\n envs,\n name,\n metadata,\n templateId,\n // Superserve has no snapshot resource — `snapshotId` is dropped here\n // intentionally; use `templateId` (a Superserve template UUID or name)\n // instead. See `snapshot` block below for context.\n snapshotId: _snapshotId,\n namespace: _namespace,\n directory: _directory,\n ...providerOptions\n } = options || {};\n\n const ttMs = requestedTimeoutMs ?? config.timeout;\n const timeoutSeconds = ttMs !== undefined ? Math.max(1, Math.ceil(ttMs / 1000)) : undefined;\n\n try {\n const sandbox = await SuperserveSandbox.create({\n apiKey,\n baseUrl,\n name: name ?? generateSandboxName(),\n ...(templateId ? { fromTemplate: templateId } : {}),\n ...(timeoutSeconds !== undefined ? { timeoutSeconds } : {}),\n ...(metadata ? { metadata: metadata as Record<string, string> } : {}),\n ...(envs ? { envVars: envs } : {}),\n ...providerOptions,\n });\n return { sandbox, sandboxId: sandbox.id };\n } catch (error) {\n rethrowFriendly(error, 'Failed to create Superserve sandbox');\n }\n },\n\n getById: async (config: SuperserveConfig, sandboxId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const sandbox = await SuperserveSandbox.connect(sandboxId, { apiKey, baseUrl });\n return { sandbox, sandboxId: sandbox.id };\n } catch {\n return null;\n }\n },\n\n list: async (config: SuperserveConfig) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const infos = await SuperserveSandbox.list({ apiKey, baseUrl });\n // No per-item connect() — that would POST /activate and resume paused sandboxes.\n return infos.map((info) => ({\n sandbox: info as unknown as SuperserveSandbox,\n sandboxId: info.id,\n }));\n } catch {\n return [];\n }\n },\n\n destroy: async (config: SuperserveConfig, sandboxId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n await SuperserveSandbox.killById(sandboxId, { apiKey, baseUrl });\n } catch {\n /* already destroyed */\n }\n },\n\n runCommand: async (\n sandbox: SuperserveSandbox,\n command: string,\n options?: RunCommandOptions,\n ): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n let fullCommand = command;\n if (options?.background) {\n // Run the whole command under `sh -c` so the trailing `&` backgrounds\n // the entire command (not just its last statement), and escape it so\n // the user's command can't break out of the nohup wrapper.\n fullCommand = `nohup sh -c \"${escapeShellArg(fullCommand)}\" > /dev/null 2>&1 &`;\n }\n const result = await sandbox.commands.run(fullCommand, {\n cwd: options?.cwd,\n env: options?.env,\n timeoutMs: options?.timeout,\n });\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n getInfo: async (sandbox: SuperserveSandbox): Promise<SandboxInfo> => {\n const info = await sandbox.getInfo();\n const status: SandboxInfo['status'] =\n info.status === 'paused' ? 'stopped' :\n info.status === 'failed' ? 'error' :\n 'running';\n return {\n id: info.id,\n provider: 'superserve',\n status,\n createdAt: info.createdAt,\n timeout: info.timeoutSeconds ? info.timeoutSeconds * 1000 : DEFAULT_TIMEOUT_MS,\n metadata: info.metadata,\n };\n },\n\n getUrl: async (_sandbox: SuperserveSandbox, _options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n 'Superserve does not currently support arbitrary port forwarding via getUrl(). ' +\n 'Use sandbox.commands.run() to interact with services running inside the sandbox.',\n );\n },\n\n filesystem: {\n readFile: async (sandbox: SuperserveSandbox, path: string): Promise<string> => {\n return sandbox.files.readText(path);\n },\n\n writeFile: async (sandbox: SuperserveSandbox, path: string, content: string): Promise<void> => {\n await sandbox.files.write(path, content);\n },\n\n mkdir: async (sandbox: SuperserveSandbox, path: string): Promise<void> => {\n const result = await sandbox.commands.run(`mkdir -p \"${escapeShellArg(path)}\"`);\n if (result.exitCode !== 0) {\n throw new Error(`mkdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n },\n\n readdir: async (sandbox: SuperserveSandbox, path: string): Promise<FileEntry[]> => {\n // find -printf format: <type>\\t<size>\\t<mtime-epoch>\\t<name>\n const cmd = [\n `cd \"${escapeShellArg(path)}\" || exit 2`,\n `find . -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n' 2>/dev/null`,\n ].join(' && ');\n const result = await sandbox.commands.run(cmd);\n if (result.exitCode === 2) {\n throw new Error(`readdir: directory not found: ${path}`);\n }\n if (result.exitCode !== 0) {\n throw new Error(`readdir failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n const entries: FileEntry[] = [];\n for (const line of result.stdout.split('\\n')) {\n if (!line) continue;\n const [type, sizeStr, mtimeStr, ...nameParts] = line.split('\\t');\n const name = nameParts.join('\\t');\n if (!name) continue;\n const size = Number.parseInt(sizeStr, 10);\n const mtime = Number.parseFloat(mtimeStr);\n entries.push({\n name,\n type: type === 'd' ? 'directory' : 'file',\n size: Number.isFinite(size) ? size : 0,\n modified: Number.isFinite(mtime) ? new Date(mtime * 1000) : new Date(),\n });\n }\n return entries;\n },\n\n exists: async (sandbox: SuperserveSandbox, path: string): Promise<boolean> => {\n const result = await sandbox.commands.run(`test -e \"${escapeShellArg(path)}\"`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: SuperserveSandbox, path: string): Promise<void> => {\n const result = await sandbox.commands.run(`rm -rf \"${escapeShellArg(path)}\"`);\n if (result.exitCode !== 0) {\n throw new Error(`remove failed: ${result.stderr || `exit code ${result.exitCode}`}`);\n }\n },\n },\n\n getInstance: (sandbox: SuperserveSandbox): SuperserveSandbox => sandbox,\n },\n\n // Superserve has no standalone snapshot resource — pause/resume is 1:1\n // and not forkable. Templates are the closest analog (wired below).\n snapshot: {\n create: async (_config: SuperserveConfig, _sandboxId: string, _options?: { name?: string }) => {\n throw new Error(\n 'Superserve does not expose snapshots as a separate resource. ' +\n 'Use Template.create() with a build spec for reusable base images, ' +\n 'or sandbox.pause() / sandbox.resume() for in-place state preservation.',\n );\n },\n list: async (_config: SuperserveConfig) => {\n return [];\n },\n delete: async (_config: SuperserveConfig, _snapshotId: string) => {\n /* no-op: snapshots are not a separate resource */\n },\n },\n\n template: {\n create: async (_config: SuperserveConfig, _options: { name: string }) => {\n throw new Error(\n 'Templates require a build spec. Use the @superserve/sdk Template.create() ' +\n 'API directly with `from` and `steps`, or define templates via the Superserve console.',\n );\n },\n list: async (config: SuperserveConfig) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n const infos = await SuperserveTemplate.list({ apiKey, baseUrl });\n return infos.map((info) => ({\n id: info.id,\n name: info.name,\n createdAt: info.createdAt,\n metadata: { status: info.status, vcpu: info.vcpu, memoryMib: info.memoryMib },\n }));\n } catch {\n return [];\n }\n },\n delete: async (config: SuperserveConfig, templateId: string) => {\n const apiKey = resolveApiKey(config);\n const baseUrl = resolveBaseUrl(config);\n try {\n await SuperserveTemplate.deleteById(templateId, { apiKey, baseUrl });\n } catch {\n /* already deleted */\n }\n },\n },\n },\n});\n\nexport type { Sandbox as SuperserveSandbox } from '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AM;AACnC,cAAM,UAAU,eAAe,MAAM;AACrC,YAAI;AACF,gBAAM,QAAQ,MAAM,mBAAmB,KAAK,EAAE,QAAQ,QAAQ,CAAC;AAC/D,iBAAO,MAAM,IAAI,CAAC,UAAU;AAAA,YAC1B,IAAI,KAAK;AAAA,YACT,MAAM,KAAK;AAAA,YACX,WAAW,KAAK;AAAA,YAChB,UAAU,EAAE,QAAQ,KAAK,QAAQ,MAAM,KAAK,MAAM,WAAW,KAAK,UAAU;AAAA,UAC9E,EAAE;AAAA,QACJ,QAAQ;AACN,iBAAO,CAAC;AAAA,QACV;AAAA,MACF;AAAA,MACA,QAAQ,OAAO,QAA0B,eAAuB;AAC9D,cAAM,SAAS,cAAc,MAAM;AACnC,cAAM,UAAU,eAAe,MAAM;AACrC,YAAI;AACF,gBAAM,mBAAmB,WAAW,YAAY,EAAE,QAAQ,QAAQ,CAAC;AAAA,QACrE,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@computesdk/superserve",
3
+ "version": "0.2.0",
4
+ "description": "Superserve provides sandbox infrastructure to run code in isolated cloud environments powered by Firecracker MicroVMs",
5
+ "author": "Superserve",
6
+ "license": "MIT",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@superserve/sdk": "^0.7.6",
22
+ "@computesdk/provider": "2.1.3",
23
+ "computesdk": "4.1.3"
24
+ },
25
+ "keywords": [
26
+ "computesdk",
27
+ "superserve",
28
+ "sandbox",
29
+ "firecracker",
30
+ "microvm",
31
+ "code-execution",
32
+ "cloud",
33
+ "compute",
34
+ "provider"
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/computesdk/computesdk.git",
39
+ "directory": "packages/superserve"
40
+ },
41
+ "homepage": "https://superserve.ai",
42
+ "bugs": {
43
+ "url": "https://github.com/computesdk/computesdk/issues"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.0.0",
47
+ "@vitest/coverage-v8": "^1.0.0",
48
+ "eslint": "^8.37.0",
49
+ "rimraf": "^5.0.0",
50
+ "tsup": "^8.0.0",
51
+ "typescript": "^5.0.0",
52
+ "vitest": "^1.0.0",
53
+ "@computesdk/test-utils": "2.0.0"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup",
57
+ "clean": "rimraf dist",
58
+ "dev": "tsup --watch",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest watch",
61
+ "test:coverage": "vitest run --coverage",
62
+ "typecheck": "tsc --noEmit",
63
+ "lint": "eslint"
64
+ }
65
+ }