@computesdk/tangle 0.0.0-stage → 1.0.1
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 +21 -0
- package/README.md +64 -2
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +195 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +170 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -3
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
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @computesdk/tangle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Tangle Sandbox](https://sandbox.tangle.tools) provider for ComputeSDK: isolated Linux sandboxes with command execution, filesystem access and port URLs, built on the `@tangle-network/sandbox` SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Requires Node.js 20.19 or newer.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @computesdk/tangle
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
| Option | Environment variable | Default |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `apiKey` | `TANGLE_API_KEY` | required |
|
|
18
|
+
| `baseUrl` | `TANGLE_SANDBOX_BASE_URL` | `https://sandbox.tangle.tools` |
|
|
19
|
+
| `image` | | server default image |
|
|
20
|
+
| `cpu`, `memory` (MB), `disk` (GB) | | server default shape |
|
|
21
|
+
| `timeout` (ms) | | server default lifetime |
|
|
22
|
+
|
|
23
|
+
Per-create `image`, `templateId` (a saved Tangle template), `cpu`, `memory`, `disk`, `timeout`, `name`, `envs`, `metadata`, `ephemeral` and `idempotencyKey` override the defaults. `ephemeral: true` gives the sandbox a scratch home directory whose contents are lost when it restarts.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { tangle } from '@computesdk/tangle';
|
|
29
|
+
|
|
30
|
+
const compute = tangle({ apiKey: process.env.TANGLE_API_KEY });
|
|
31
|
+
|
|
32
|
+
const sandbox = await compute.instances.create({ image: 'node:22' });
|
|
33
|
+
try {
|
|
34
|
+
const result = await sandbox.runCommand('node --version');
|
|
35
|
+
console.log(result.stdout);
|
|
36
|
+
|
|
37
|
+
await sandbox.filesystem.writeFile('/tmp/hello.txt', 'Hello from Tangle');
|
|
38
|
+
console.log(await sandbox.filesystem.readFile('/tmp/hello.txt'));
|
|
39
|
+
|
|
40
|
+
console.log(await sandbox.getUrl({ port: 3000 }));
|
|
41
|
+
} finally {
|
|
42
|
+
await sandbox.destroy();
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Supported operations
|
|
47
|
+
|
|
48
|
+
- `instances.create`, `getById`, `list` (deleted sandboxes omitted), `destroy`
|
|
49
|
+
- `runCommand` with `cwd`, `env`, `timeout` and `background`; a foreground `timeout` defaults to 600000 ms (10 minutes), the runtime's maximum, and must be a whole number of ms from 100 to 600000; a background command has no limit unless `timeout` is set
|
|
50
|
+
- `filesystem`: `readFile`, `writeFile`, `mkdir`, `readdir`, `exists`, `remove`
|
|
51
|
+
- `getUrl`, through the SDK's port exposure
|
|
52
|
+
- `getInstance()` returns the native `SandboxInstance` for other SDK features
|
|
53
|
+
|
|
54
|
+
## Not supported
|
|
55
|
+
|
|
56
|
+
- `snapshotId` on create throws; use the native SDK for snapshots.
|
|
57
|
+
- `runtime` names throw; pick an image such as `node:22` or `python:3.12-slim`.
|
|
58
|
+
|
|
59
|
+
## Tests
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm --filter @computesdk/tangle test
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Without `TANGLE_API_KEY` the suite runs against ComputeSDK's mock sandbox. With it, every test creates and destroys a real sandbox.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import * as _computesdk_provider from '@computesdk/provider';
|
|
3
|
+
import { SandboxInstance } from '@tangle-network/sandbox';
|
|
4
|
+
|
|
5
|
+
interface TangleConfig {
|
|
6
|
+
/** API key; falls back to TANGLE_API_KEY. */
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/** Sandbox API endpoint; falls back to TANGLE_SANDBOX_BASE_URL, then https://sandbox.tangle.tools. */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Default environment ID or OCI image reference, e.g. `node:22`. */
|
|
11
|
+
image?: string;
|
|
12
|
+
/** Default CPU cores. */
|
|
13
|
+
cpu?: number;
|
|
14
|
+
/** Default memory in MB. */
|
|
15
|
+
memory?: number;
|
|
16
|
+
/** Default disk in GB. */
|
|
17
|
+
disk?: number;
|
|
18
|
+
/** Default maximum sandbox lifetime in milliseconds. */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
declare const tangle: (config: TangleConfig & _computesdk_provider.ProcessRuntimeOptions) => _computesdk_provider.Provider<SandboxInstance, any, any, computesdk.Volume> & {
|
|
22
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { type TangleConfig, tangle };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import * as _computesdk_provider from '@computesdk/provider';
|
|
3
|
+
import { SandboxInstance } from '@tangle-network/sandbox';
|
|
4
|
+
|
|
5
|
+
interface TangleConfig {
|
|
6
|
+
/** API key; falls back to TANGLE_API_KEY. */
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/** Sandbox API endpoint; falls back to TANGLE_SANDBOX_BASE_URL, then https://sandbox.tangle.tools. */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Default environment ID or OCI image reference, e.g. `node:22`. */
|
|
11
|
+
image?: string;
|
|
12
|
+
/** Default CPU cores. */
|
|
13
|
+
cpu?: number;
|
|
14
|
+
/** Default memory in MB. */
|
|
15
|
+
memory?: number;
|
|
16
|
+
/** Default disk in GB. */
|
|
17
|
+
disk?: number;
|
|
18
|
+
/** Default maximum sandbox lifetime in milliseconds. */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
declare const tangle: (config: TangleConfig & _computesdk_provider.ProcessRuntimeOptions) => _computesdk_provider.Provider<SandboxInstance, any, any, computesdk.Volume> & {
|
|
22
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { type TangleConfig, tangle };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
tangle: () => tangle
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
27
|
+
var import_sandbox = require("@tangle-network/sandbox");
|
|
28
|
+
var import_provider = require("@computesdk/provider");
|
|
29
|
+
var DEFAULT_BASE_URL = "https://sandbox.tangle.tools";
|
|
30
|
+
var EXEC_TIMEOUT_MS = 6e5;
|
|
31
|
+
var LISTED_STATUSES = ["pending", "provisioning", "running", "stopped", "failed", "expired"];
|
|
32
|
+
var ENDED = /* @__PURE__ */ new Set(["stopped", "expired", "deleted"]);
|
|
33
|
+
var NO_ROOM = /* @__PURE__ */ new Set(["CAPACITY_EXHAUSTED", "HOST_PRESSURE"]);
|
|
34
|
+
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
35
|
+
function client(config) {
|
|
36
|
+
const apiKey = (config.apiKey || env("TANGLE_API_KEY"))?.trim();
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
throw new Error("Missing Tangle API key: pass tangle({ apiKey }) or set TANGLE_API_KEY. Create one at https://sandbox.tangle.tools.");
|
|
39
|
+
}
|
|
40
|
+
return new import_sandbox.Sandbox({ apiKey, baseUrl: config.baseUrl || env("TANGLE_SANDBOX_BASE_URL") || DEFAULT_BASE_URL });
|
|
41
|
+
}
|
|
42
|
+
function createOptions(config, options) {
|
|
43
|
+
if (options.snapshotId !== void 0) {
|
|
44
|
+
throw new Error("The Tangle provider does not restore snapshots; use getInstance() for native snapshot APIs.");
|
|
45
|
+
}
|
|
46
|
+
if (options.runtime !== void 0) {
|
|
47
|
+
throw new Error('Tangle does not map runtime names; select an image such as "node:22" or "python:3.12-slim".');
|
|
48
|
+
}
|
|
49
|
+
const environment = options.image ?? (options.templateId === void 0 ? config.image : void 0);
|
|
50
|
+
const cpuCores = options.cpu ?? config.cpu;
|
|
51
|
+
const memoryMB = options.memory ?? config.memory;
|
|
52
|
+
const diskGB = options.disk ?? config.disk;
|
|
53
|
+
const timeout = options.timeout ?? config.timeout;
|
|
54
|
+
const idempotencyKey = typeof options.idempotencyKey === "string" ? options.idempotencyKey : (0, import_node_crypto.randomUUID)();
|
|
55
|
+
return {
|
|
56
|
+
name: options.name ?? `computesdk-${(0, import_node_crypto.createHash)("sha256").update(idempotencyKey).digest("hex").slice(0, 8)}`,
|
|
57
|
+
...environment !== void 0 ? { environment } : {},
|
|
58
|
+
...options.templateId !== void 0 ? { templateId: options.templateId } : {},
|
|
59
|
+
...cpuCores !== void 0 || memoryMB !== void 0 || diskGB !== void 0 ? { resources: { cpuCores, memoryMB, diskGB } } : {},
|
|
60
|
+
...timeout !== void 0 ? { maxLifetimeSeconds: Math.ceil(timeout / 1e3) } : {},
|
|
61
|
+
...options.ephemeral !== void 0 ? { ephemeral: options.ephemeral } : {},
|
|
62
|
+
...options.envs ? { env: options.envs } : {},
|
|
63
|
+
...options.metadata ? { metadata: options.metadata } : {},
|
|
64
|
+
idempotencyKey
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function remove(sdk, id) {
|
|
68
|
+
try {
|
|
69
|
+
await sdk.delete(id);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!(error instanceof import_sandbox.NotFoundError)) throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function discard(sdk, id, failure) {
|
|
75
|
+
await remove(sdk, id).catch((cleanup) => {
|
|
76
|
+
const message = `Tangle sandbox ${id} did not start (${String(failure)}) and was not deleted (${String(cleanup)}).`;
|
|
77
|
+
throw Object.assign(new Error(message), { cause: failure });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function outcomeUnknown(error) {
|
|
81
|
+
if (!(error instanceof import_sandbox.SandboxError)) return true;
|
|
82
|
+
if (error.allocationId !== void 0 || error.createFailureDisposition === "not-admitted" || NO_ROOM.has(error.code)) return false;
|
|
83
|
+
return !(error.status >= 400 && error.status < 500 && !error.retryable);
|
|
84
|
+
}
|
|
85
|
+
async function admit(sdk, request) {
|
|
86
|
+
try {
|
|
87
|
+
return await sdk.create(request);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (!outcomeUnknown(error)) throw error;
|
|
90
|
+
return sdk.create(request).catch((joined) => {
|
|
91
|
+
if (joined instanceof Error && !("cause" in joined)) Object.assign(joined, { cause: error });
|
|
92
|
+
throw joined;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function status(sandbox) {
|
|
97
|
+
switch (sandbox.status) {
|
|
98
|
+
case "pending":
|
|
99
|
+
case "provisioning":
|
|
100
|
+
case "running":
|
|
101
|
+
return "running";
|
|
102
|
+
case "failed":
|
|
103
|
+
return "error";
|
|
104
|
+
default:
|
|
105
|
+
return "stopped";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var tangle = (0, import_provider.defineProvider)({
|
|
109
|
+
name: "tangle",
|
|
110
|
+
methods: {
|
|
111
|
+
instances: {
|
|
112
|
+
create: async (config, options = {}) => {
|
|
113
|
+
const sdk = client(config);
|
|
114
|
+
const request = createOptions(config, options);
|
|
115
|
+
const owned = (receipt) => typeof options.idempotencyKey !== "string" || receipt?.outcome === "created";
|
|
116
|
+
let sandbox;
|
|
117
|
+
try {
|
|
118
|
+
sandbox = await admit(sdk, request);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof import_sandbox.SandboxError && error.allocationId !== void 0 && owned(error.createReceipt)) {
|
|
121
|
+
await discard(sdk, error.allocationId, error);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
if (ENDED.has(sandbox.status)) throw new Error(`Tangle sandbox ${sandbox.id} is ${sandbox.status}.`);
|
|
127
|
+
await sandbox.waitFor("running");
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (owned(sandbox.createReceipt())) await discard(sdk, sandbox.id, error);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
if (options.signal?.aborted && !owned(sandbox.createReceipt())) {
|
|
133
|
+
throw new Error(`Create aborted; Tangle sandbox ${sandbox.id} may belong to another create with this idempotencyKey, so it is left running.`);
|
|
134
|
+
}
|
|
135
|
+
return { instance: sandbox, instanceId: sandbox.id };
|
|
136
|
+
},
|
|
137
|
+
getById: async (config, instanceId) => {
|
|
138
|
+
const sandbox = await client(config).get(instanceId);
|
|
139
|
+
return sandbox && sandbox.status !== "deleted" ? { instance: sandbox, instanceId: sandbox.id } : null;
|
|
140
|
+
},
|
|
141
|
+
// Without a limit the API returns every match, so one request lists every sandbox not deleted.
|
|
142
|
+
list: async (config) => (await client(config).list({ status: LISTED_STATUSES })).map((sandbox) => ({ instance: sandbox, instanceId: sandbox.id })),
|
|
143
|
+
destroy: async (config, instanceId) => remove(client(config), instanceId),
|
|
144
|
+
runCommand: async (sandbox, command, options = {}) => {
|
|
145
|
+
const start = Date.now();
|
|
146
|
+
const script = options.cwd ? `cd "${(0, import_provider.escapeShellArg)(options.cwd)}" || exit $?
|
|
147
|
+
${command}` : command;
|
|
148
|
+
if (options.background) {
|
|
149
|
+
await sandbox.process.spawn(script, { env: options.env, timeoutMs: options.timeout ?? 0 });
|
|
150
|
+
return { stdout: "", stderr: "", exitCode: 0, durationMs: Date.now() - start };
|
|
151
|
+
}
|
|
152
|
+
const result = await sandbox.exec(script, { env: options.env, timeoutMs: options.timeout ?? EXEC_TIMEOUT_MS });
|
|
153
|
+
return { ...result, durationMs: Date.now() - start };
|
|
154
|
+
},
|
|
155
|
+
getInfo: async (sandbox) => {
|
|
156
|
+
await sandbox.refresh();
|
|
157
|
+
return {
|
|
158
|
+
id: sandbox.id,
|
|
159
|
+
provider: "tangle",
|
|
160
|
+
status: status(sandbox),
|
|
161
|
+
createdAt: sandbox.createdAt,
|
|
162
|
+
// Each start or resume begins a new lifetime interval.
|
|
163
|
+
timeout: sandbox.expiresAt ? Math.max(0, sandbox.expiresAt.getTime() - (sandbox.startedAt ?? sandbox.createdAt).getTime()) : 0,
|
|
164
|
+
metadata: { ...sandbox.metadata, name: sandbox.name, resources: sandbox.resources }
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
getUrl: async (sandbox, { port, protocol }) => {
|
|
168
|
+
const url = new URL(await sandbox.network.exposePort(port));
|
|
169
|
+
if (protocol) url.protocol = `${protocol}:`;
|
|
170
|
+
return url.toString();
|
|
171
|
+
},
|
|
172
|
+
getInstance: (sandbox) => sandbox,
|
|
173
|
+
filesystem: {
|
|
174
|
+
readFile: (sandbox, path) => sandbox.read(path),
|
|
175
|
+
writeFile: async (sandbox, path, content) => {
|
|
176
|
+
await sandbox.write(path, content);
|
|
177
|
+
},
|
|
178
|
+
mkdir: (sandbox, path) => sandbox.fs.mkdir(path, { recursive: true }),
|
|
179
|
+
readdir: async (sandbox, path) => (await sandbox.fs.list(path)).map((entry) => ({
|
|
180
|
+
name: entry.name,
|
|
181
|
+
type: entry.isDir ? "directory" : "file",
|
|
182
|
+
size: entry.size,
|
|
183
|
+
modified: entry.modTime
|
|
184
|
+
})),
|
|
185
|
+
exists: (sandbox, path) => sandbox.fs.exists(path),
|
|
186
|
+
remove: (sandbox, path) => sandbox.fs.delete(path, { recursive: true })
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
192
|
+
0 && (module.exports = {
|
|
193
|
+
tangle
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Tangle Sandbox provider for ComputeSDK, a thin adapter over @tangle-network/sandbox.\n */\n\nimport { createHash, randomUUID } from 'node:crypto';\nimport { NotFoundError, Sandbox, SandboxError, type CreateSandboxOptions, type SandboxInstance, type SandboxStatus } from '@tangle-network/sandbox';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nconst DEFAULT_BASE_URL = 'https://sandbox.tangle.tools';\n/** The most the runtime allows per command; the SDK accepts whole ms from 100 to 600000 and defaults to 30 s. */\nconst EXEC_TIMEOUT_MS = 600_000;\n/** Every status `getById` returns; `deleted` records are history. */\nconst LISTED_STATUSES: SandboxStatus[] = ['pending', 'provisioning', 'running', 'stopped', 'failed', 'expired'];\n/** Statuses a sandbox does not leave for `running` on its own. */\nconst ENDED = new Set<SandboxStatus>(['stopped', 'expired', 'deleted']);\n/** 503 codes the SDK gives up on when no host has room; such a refusal allocated nothing. */\nconst NO_ROOM = new Set<string>(['CAPACITY_EXHAUSTED', 'HOST_PRESSURE']);\n\nexport interface TangleConfig {\n /** API key; falls back to TANGLE_API_KEY. */\n apiKey?: string;\n /** Sandbox API endpoint; falls back to TANGLE_SANDBOX_BASE_URL, then https://sandbox.tangle.tools. */\n baseUrl?: string;\n /** Default environment ID or OCI image reference, e.g. `node:22`. */\n image?: string;\n /** Default CPU cores. */\n cpu?: number;\n /** Default memory in MB. */\n memory?: number;\n /** Default disk in GB. */\n disk?: number;\n /** Default maximum sandbox lifetime in milliseconds. */\n timeout?: number;\n}\n\nconst env = (name: string): string | undefined =>\n typeof process !== 'undefined' ? process.env?.[name] : undefined;\n\n/** Credentials are checked when a call needs them; constructing the SDK client does no I/O. */\nfunction client(config: TangleConfig): Sandbox {\n const apiKey = (config.apiKey || env('TANGLE_API_KEY'))?.trim();\n if (!apiKey) {\n throw new Error('Missing Tangle API key: pass tangle({ apiKey }) or set TANGLE_API_KEY. Create one at https://sandbox.tangle.tools.');\n }\n return new Sandbox({ apiKey, baseUrl: config.baseUrl || env('TANGLE_SANDBOX_BASE_URL') || DEFAULT_BASE_URL });\n}\n\nfunction createOptions(config: TangleConfig, options: CreateInstanceOptions): CreateSandboxOptions {\n if (options.snapshotId !== undefined) {\n throw new Error('The Tangle provider does not restore snapshots; use getInstance() for native snapshot APIs.');\n }\n if (options.runtime !== undefined) {\n throw new Error('Tangle does not map runtime names; select an image such as \"node:22\" or \"python:3.12-slim\".');\n }\n // A saved template brings its own image, so the configured default image does not override it.\n const environment = options.image ?? (options.templateId === undefined ? config.image : undefined);\n const cpuCores = options.cpu ?? config.cpu;\n const memoryMB = options.memory ?? config.memory;\n const diskGB = options.disk ?? config.disk;\n const timeout = options.timeout ?? config.timeout;\n // Always keyed, so a create whose outcome is unknown can be joined. The default name comes from the\n // key, so a create sent again with the same key carries the same body.\n const idempotencyKey = typeof options.idempotencyKey === 'string' ? options.idempotencyKey : randomUUID();\n return {\n name: options.name ?? `computesdk-${createHash('sha256').update(idempotencyKey).digest('hex').slice(0, 8)}`,\n ...(environment !== undefined ? { environment } : {}),\n ...(options.templateId !== undefined ? { templateId: options.templateId } : {}),\n ...(cpuCores !== undefined || memoryMB !== undefined || diskGB !== undefined\n ? { resources: { cpuCores, memoryMB, diskGB } } : {}),\n ...(timeout !== undefined ? { maxLifetimeSeconds: Math.ceil(timeout / 1000) } : {}),\n ...(options.ephemeral !== undefined ? { ephemeral: options.ephemeral } : {}),\n ...(options.envs ? { env: options.envs } : {}),\n ...(options.metadata ? { metadata: options.metadata } : {}),\n idempotencyKey,\n };\n}\n\n/** A sandbox that is already gone counts as deleted. */\nasync function remove(sdk: Sandbox, id: string): Promise<void> {\n try {\n await sdk.delete(id);\n } catch (error) {\n if (!(error instanceof NotFoundError)) throw error;\n }\n}\n\n/** Deletes a sandbox that did not start, keeping the start failure as the error. */\nasync function discard(sdk: Sandbox, id: string, failure: unknown): Promise<void> {\n await remove(sdk, id).catch((cleanup: unknown) => {\n const message = `Tangle sandbox ${id} did not start (${String(failure)}) and was not deleted (${String(cleanup)}).`;\n throw Object.assign(new Error(message), { cause: failure });\n });\n}\n\n/** Only a refusal shows a failed create left nothing behind; without a sandbox id, anything else is unknown. */\nfunction outcomeUnknown(error: unknown): boolean {\n if (!(error instanceof SandboxError)) return true;\n if (error.allocationId !== undefined || error.createFailureDisposition === 'not-admitted' || NO_ROOM.has(error.code)) return false;\n return !(error.status >= 400 && error.status < 500 && !error.retryable);\n}\n\n/** Sends the create once more when its outcome is unknown; the same idempotency key joins the first attempt. */\nasync function admit(sdk: Sandbox, request: CreateSandboxOptions): Promise<SandboxInstance> {\n try {\n return await sdk.create(request);\n } catch (error) {\n if (!outcomeUnknown(error)) throw error;\n return sdk.create(request).catch((joined: unknown) => {\n // Keep the first failure reachable when the second fails too, unless the second carries its own cause.\n if (joined instanceof Error && !('cause' in joined)) Object.assign(joined, { cause: error });\n throw joined;\n });\n }\n}\n\nfunction status(sandbox: SandboxInstance): InstanceInfo['status'] {\n switch (sandbox.status) {\n case 'pending':\n case 'provisioning':\n case 'running':\n return 'running';\n case 'failed':\n return 'error';\n default:\n return 'stopped';\n }\n}\n\nexport const tangle = defineProvider<SandboxInstance, TangleConfig>({\n name: 'tangle',\n methods: {\n instances: {\n create: async (config, options = {}) => {\n const sdk = client(config);\n const request = createOptions(config, options);\n // A rejected create returns no id, so the caller could never delete what it left behind. With a\n // caller's key the platform can return a sandbox another call allocated, so delete only one under\n // the provider's own key or one the platform says this call created.\n const owned = (receipt: { outcome: string } | null | undefined): boolean =>\n typeof options.idempotencyKey !== 'string' || receipt?.outcome === 'created';\n let sandbox: SandboxInstance;\n try {\n sandbox = await admit(sdk, request);\n } catch (error) {\n // The SDK names the sandbox a failed readiness wait leaves behind.\n if (error instanceof SandboxError && error.allocationId !== undefined && owned(error.createReceipt)) {\n await discard(sdk, error.allocationId, error);\n }\n throw error;\n }\n try {\n if (ENDED.has(sandbox.status)) throw new Error(`Tangle sandbox ${sandbox.id} is ${sandbox.status}.`);\n // create() waits only while pending or provisioning; this also waits for the filesystem.\n await sandbox.waitFor('running');\n } catch (error) {\n if (owned(sandbox.createReceipt())) await discard(sdk, sandbox.id, error);\n throw error;\n }\n // The factory destroys an instance whose create resolves after an abort, so keep one this call\n // did not create from reaching it.\n if (options.signal?.aborted && !owned(sandbox.createReceipt())) {\n throw new Error(`Create aborted; Tangle sandbox ${sandbox.id} may belong to another create with this idempotencyKey, so it is left running.`);\n }\n return { instance: sandbox, instanceId: sandbox.id };\n },\n\n getById: async (config, instanceId) => {\n const sandbox = await client(config).get(instanceId);\n return sandbox && sandbox.status !== 'deleted' ? { instance: sandbox, instanceId: sandbox.id } : null;\n },\n\n // Without a limit the API returns every match, so one request lists every sandbox not deleted.\n list: async (config) =>\n (await client(config).list({ status: LISTED_STATUSES })).map((sandbox) => ({ instance: sandbox, instanceId: sandbox.id })),\n\n destroy: async (config, instanceId) => remove(client(config), instanceId),\n\n runCommand: async (sandbox, command, options: RunCommandOptions = {}): Promise<CommandResult> => {\n const start = Date.now();\n // The runtime's cwd field only accepts paths inside the workspace, so change directory in the shell.\n const script = options.cwd ? `cd \"${escapeShellArg(options.cwd)}\" || exit $?\\n${command}` : command;\n if (options.background) {\n // 0 is no limit: a background command runs until it exits or the sandbox stops.\n await sandbox.process.spawn(script, { env: options.env, timeoutMs: options.timeout ?? 0 });\n return { stdout: '', stderr: '', exitCode: 0, durationMs: Date.now() - start };\n }\n const result = await sandbox.exec(script, { env: options.env, timeoutMs: options.timeout ?? EXEC_TIMEOUT_MS });\n return { ...result, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox): Promise<InstanceInfo> => {\n await sandbox.refresh();\n return {\n id: sandbox.id,\n provider: 'tangle',\n status: status(sandbox),\n createdAt: sandbox.createdAt,\n // Each start or resume begins a new lifetime interval.\n timeout: sandbox.expiresAt ? Math.max(0, sandbox.expiresAt.getTime() - (sandbox.startedAt ?? sandbox.createdAt).getTime()) : 0,\n metadata: { ...sandbox.metadata, name: sandbox.name, resources: sandbox.resources },\n };\n },\n\n getUrl: async (sandbox, { port, protocol }) => {\n const url = new URL(await sandbox.network.exposePort(port));\n if (protocol) url.protocol = `${protocol}:`;\n return url.toString();\n },\n\n getInstance: (sandbox) => sandbox,\n\n filesystem: {\n readFile: (sandbox, path) => sandbox.read(path),\n writeFile: async (sandbox, path, content) => { await sandbox.write(path, content); },\n mkdir: (sandbox, path) => sandbox.fs.mkdir(path, { recursive: true }),\n readdir: async (sandbox, path): Promise<FileEntry[]> => (await sandbox.fs.list(path)).map((entry) => ({\n name: entry.name,\n type: entry.isDir ? 'directory' : 'file',\n size: entry.size,\n modified: entry.modTime,\n })),\n exists: (sandbox, path) => sandbox.fs.exists(path),\n remove: (sandbox, path) => sandbox.fs.delete(path, { recursive: true }),\n },\n },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAAuC;AACvC,qBAA0H;AAC1H,sBAA+C;AAG/C,IAAM,mBAAmB;AAEzB,IAAM,kBAAkB;AAExB,IA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/dist/index.mjs
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createHash, randomUUID } from "crypto";
|
|
3
|
+
import { NotFoundError, Sandbox, SandboxError } from "@tangle-network/sandbox";
|
|
4
|
+
import { defineProvider, escapeShellArg } from "@computesdk/provider";
|
|
5
|
+
var DEFAULT_BASE_URL = "https://sandbox.tangle.tools";
|
|
6
|
+
var EXEC_TIMEOUT_MS = 6e5;
|
|
7
|
+
var LISTED_STATUSES = ["pending", "provisioning", "running", "stopped", "failed", "expired"];
|
|
8
|
+
var ENDED = /* @__PURE__ */ new Set(["stopped", "expired", "deleted"]);
|
|
9
|
+
var NO_ROOM = /* @__PURE__ */ new Set(["CAPACITY_EXHAUSTED", "HOST_PRESSURE"]);
|
|
10
|
+
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
11
|
+
function client(config) {
|
|
12
|
+
const apiKey = (config.apiKey || env("TANGLE_API_KEY"))?.trim();
|
|
13
|
+
if (!apiKey) {
|
|
14
|
+
throw new Error("Missing Tangle API key: pass tangle({ apiKey }) or set TANGLE_API_KEY. Create one at https://sandbox.tangle.tools.");
|
|
15
|
+
}
|
|
16
|
+
return new Sandbox({ apiKey, baseUrl: config.baseUrl || env("TANGLE_SANDBOX_BASE_URL") || DEFAULT_BASE_URL });
|
|
17
|
+
}
|
|
18
|
+
function createOptions(config, options) {
|
|
19
|
+
if (options.snapshotId !== void 0) {
|
|
20
|
+
throw new Error("The Tangle provider does not restore snapshots; use getInstance() for native snapshot APIs.");
|
|
21
|
+
}
|
|
22
|
+
if (options.runtime !== void 0) {
|
|
23
|
+
throw new Error('Tangle does not map runtime names; select an image such as "node:22" or "python:3.12-slim".');
|
|
24
|
+
}
|
|
25
|
+
const environment = options.image ?? (options.templateId === void 0 ? config.image : void 0);
|
|
26
|
+
const cpuCores = options.cpu ?? config.cpu;
|
|
27
|
+
const memoryMB = options.memory ?? config.memory;
|
|
28
|
+
const diskGB = options.disk ?? config.disk;
|
|
29
|
+
const timeout = options.timeout ?? config.timeout;
|
|
30
|
+
const idempotencyKey = typeof options.idempotencyKey === "string" ? options.idempotencyKey : randomUUID();
|
|
31
|
+
return {
|
|
32
|
+
name: options.name ?? `computesdk-${createHash("sha256").update(idempotencyKey).digest("hex").slice(0, 8)}`,
|
|
33
|
+
...environment !== void 0 ? { environment } : {},
|
|
34
|
+
...options.templateId !== void 0 ? { templateId: options.templateId } : {},
|
|
35
|
+
...cpuCores !== void 0 || memoryMB !== void 0 || diskGB !== void 0 ? { resources: { cpuCores, memoryMB, diskGB } } : {},
|
|
36
|
+
...timeout !== void 0 ? { maxLifetimeSeconds: Math.ceil(timeout / 1e3) } : {},
|
|
37
|
+
...options.ephemeral !== void 0 ? { ephemeral: options.ephemeral } : {},
|
|
38
|
+
...options.envs ? { env: options.envs } : {},
|
|
39
|
+
...options.metadata ? { metadata: options.metadata } : {},
|
|
40
|
+
idempotencyKey
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function remove(sdk, id) {
|
|
44
|
+
try {
|
|
45
|
+
await sdk.delete(id);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (!(error instanceof NotFoundError)) throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function discard(sdk, id, failure) {
|
|
51
|
+
await remove(sdk, id).catch((cleanup) => {
|
|
52
|
+
const message = `Tangle sandbox ${id} did not start (${String(failure)}) and was not deleted (${String(cleanup)}).`;
|
|
53
|
+
throw Object.assign(new Error(message), { cause: failure });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function outcomeUnknown(error) {
|
|
57
|
+
if (!(error instanceof SandboxError)) return true;
|
|
58
|
+
if (error.allocationId !== void 0 || error.createFailureDisposition === "not-admitted" || NO_ROOM.has(error.code)) return false;
|
|
59
|
+
return !(error.status >= 400 && error.status < 500 && !error.retryable);
|
|
60
|
+
}
|
|
61
|
+
async function admit(sdk, request) {
|
|
62
|
+
try {
|
|
63
|
+
return await sdk.create(request);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!outcomeUnknown(error)) throw error;
|
|
66
|
+
return sdk.create(request).catch((joined) => {
|
|
67
|
+
if (joined instanceof Error && !("cause" in joined)) Object.assign(joined, { cause: error });
|
|
68
|
+
throw joined;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function status(sandbox) {
|
|
73
|
+
switch (sandbox.status) {
|
|
74
|
+
case "pending":
|
|
75
|
+
case "provisioning":
|
|
76
|
+
case "running":
|
|
77
|
+
return "running";
|
|
78
|
+
case "failed":
|
|
79
|
+
return "error";
|
|
80
|
+
default:
|
|
81
|
+
return "stopped";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var tangle = defineProvider({
|
|
85
|
+
name: "tangle",
|
|
86
|
+
methods: {
|
|
87
|
+
instances: {
|
|
88
|
+
create: async (config, options = {}) => {
|
|
89
|
+
const sdk = client(config);
|
|
90
|
+
const request = createOptions(config, options);
|
|
91
|
+
const owned = (receipt) => typeof options.idempotencyKey !== "string" || receipt?.outcome === "created";
|
|
92
|
+
let sandbox;
|
|
93
|
+
try {
|
|
94
|
+
sandbox = await admit(sdk, request);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof SandboxError && error.allocationId !== void 0 && owned(error.createReceipt)) {
|
|
97
|
+
await discard(sdk, error.allocationId, error);
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
if (ENDED.has(sandbox.status)) throw new Error(`Tangle sandbox ${sandbox.id} is ${sandbox.status}.`);
|
|
103
|
+
await sandbox.waitFor("running");
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (owned(sandbox.createReceipt())) await discard(sdk, sandbox.id, error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
if (options.signal?.aborted && !owned(sandbox.createReceipt())) {
|
|
109
|
+
throw new Error(`Create aborted; Tangle sandbox ${sandbox.id} may belong to another create with this idempotencyKey, so it is left running.`);
|
|
110
|
+
}
|
|
111
|
+
return { instance: sandbox, instanceId: sandbox.id };
|
|
112
|
+
},
|
|
113
|
+
getById: async (config, instanceId) => {
|
|
114
|
+
const sandbox = await client(config).get(instanceId);
|
|
115
|
+
return sandbox && sandbox.status !== "deleted" ? { instance: sandbox, instanceId: sandbox.id } : null;
|
|
116
|
+
},
|
|
117
|
+
// Without a limit the API returns every match, so one request lists every sandbox not deleted.
|
|
118
|
+
list: async (config) => (await client(config).list({ status: LISTED_STATUSES })).map((sandbox) => ({ instance: sandbox, instanceId: sandbox.id })),
|
|
119
|
+
destroy: async (config, instanceId) => remove(client(config), instanceId),
|
|
120
|
+
runCommand: async (sandbox, command, options = {}) => {
|
|
121
|
+
const start = Date.now();
|
|
122
|
+
const script = options.cwd ? `cd "${escapeShellArg(options.cwd)}" || exit $?
|
|
123
|
+
${command}` : command;
|
|
124
|
+
if (options.background) {
|
|
125
|
+
await sandbox.process.spawn(script, { env: options.env, timeoutMs: options.timeout ?? 0 });
|
|
126
|
+
return { stdout: "", stderr: "", exitCode: 0, durationMs: Date.now() - start };
|
|
127
|
+
}
|
|
128
|
+
const result = await sandbox.exec(script, { env: options.env, timeoutMs: options.timeout ?? EXEC_TIMEOUT_MS });
|
|
129
|
+
return { ...result, durationMs: Date.now() - start };
|
|
130
|
+
},
|
|
131
|
+
getInfo: async (sandbox) => {
|
|
132
|
+
await sandbox.refresh();
|
|
133
|
+
return {
|
|
134
|
+
id: sandbox.id,
|
|
135
|
+
provider: "tangle",
|
|
136
|
+
status: status(sandbox),
|
|
137
|
+
createdAt: sandbox.createdAt,
|
|
138
|
+
// Each start or resume begins a new lifetime interval.
|
|
139
|
+
timeout: sandbox.expiresAt ? Math.max(0, sandbox.expiresAt.getTime() - (sandbox.startedAt ?? sandbox.createdAt).getTime()) : 0,
|
|
140
|
+
metadata: { ...sandbox.metadata, name: sandbox.name, resources: sandbox.resources }
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
getUrl: async (sandbox, { port, protocol }) => {
|
|
144
|
+
const url = new URL(await sandbox.network.exposePort(port));
|
|
145
|
+
if (protocol) url.protocol = `${protocol}:`;
|
|
146
|
+
return url.toString();
|
|
147
|
+
},
|
|
148
|
+
getInstance: (sandbox) => sandbox,
|
|
149
|
+
filesystem: {
|
|
150
|
+
readFile: (sandbox, path) => sandbox.read(path),
|
|
151
|
+
writeFile: async (sandbox, path, content) => {
|
|
152
|
+
await sandbox.write(path, content);
|
|
153
|
+
},
|
|
154
|
+
mkdir: (sandbox, path) => sandbox.fs.mkdir(path, { recursive: true }),
|
|
155
|
+
readdir: async (sandbox, path) => (await sandbox.fs.list(path)).map((entry) => ({
|
|
156
|
+
name: entry.name,
|
|
157
|
+
type: entry.isDir ? "directory" : "file",
|
|
158
|
+
size: entry.size,
|
|
159
|
+
modified: entry.modTime
|
|
160
|
+
})),
|
|
161
|
+
exists: (sandbox, path) => sandbox.fs.exists(path),
|
|
162
|
+
remove: (sandbox, path) => sandbox.fs.delete(path, { recursive: true })
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
export {
|
|
168
|
+
tangle
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Tangle Sandbox provider for ComputeSDK, a thin adapter over @tangle-network/sandbox.\n */\n\nimport { createHash, randomUUID } from 'node:crypto';\nimport { NotFoundError, Sandbox, SandboxError, type CreateSandboxOptions, type SandboxInstance, type SandboxStatus } from '@tangle-network/sandbox';\nimport { defineProvider, escapeShellArg } from '@computesdk/provider';\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nconst DEFAULT_BASE_URL = 'https://sandbox.tangle.tools';\n/** The most the runtime allows per command; the SDK accepts whole ms from 100 to 600000 and defaults to 30 s. */\nconst EXEC_TIMEOUT_MS = 600_000;\n/** Every status `getById` returns; `deleted` records are history. */\nconst LISTED_STATUSES: SandboxStatus[] = ['pending', 'provisioning', 'running', 'stopped', 'failed', 'expired'];\n/** Statuses a sandbox does not leave for `running` on its own. */\nconst ENDED = new Set<SandboxStatus>(['stopped', 'expired', 'deleted']);\n/** 503 codes the SDK gives up on when no host has room; such a refusal allocated nothing. */\nconst NO_ROOM = new Set<string>(['CAPACITY_EXHAUSTED', 'HOST_PRESSURE']);\n\nexport interface TangleConfig {\n /** API key; falls back to TANGLE_API_KEY. */\n apiKey?: string;\n /** Sandbox API endpoint; falls back to TANGLE_SANDBOX_BASE_URL, then https://sandbox.tangle.tools. */\n baseUrl?: string;\n /** Default environment ID or OCI image reference, e.g. `node:22`. */\n image?: string;\n /** Default CPU cores. */\n cpu?: number;\n /** Default memory in MB. */\n memory?: number;\n /** Default disk in GB. */\n disk?: number;\n /** Default maximum sandbox lifetime in milliseconds. */\n timeout?: number;\n}\n\nconst env = (name: string): string | undefined =>\n typeof process !== 'undefined' ? process.env?.[name] : undefined;\n\n/** Credentials are checked when a call needs them; constructing the SDK client does no I/O. */\nfunction client(config: TangleConfig): Sandbox {\n const apiKey = (config.apiKey || env('TANGLE_API_KEY'))?.trim();\n if (!apiKey) {\n throw new Error('Missing Tangle API key: pass tangle({ apiKey }) or set TANGLE_API_KEY. Create one at https://sandbox.tangle.tools.');\n }\n return new Sandbox({ apiKey, baseUrl: config.baseUrl || env('TANGLE_SANDBOX_BASE_URL') || DEFAULT_BASE_URL });\n}\n\nfunction createOptions(config: TangleConfig, options: CreateInstanceOptions): CreateSandboxOptions {\n if (options.snapshotId !== undefined) {\n throw new Error('The Tangle provider does not restore snapshots; use getInstance() for native snapshot APIs.');\n }\n if (options.runtime !== undefined) {\n throw new Error('Tangle does not map runtime names; select an image such as \"node:22\" or \"python:3.12-slim\".');\n }\n // A saved template brings its own image, so the configured default image does not override it.\n const environment = options.image ?? (options.templateId === undefined ? config.image : undefined);\n const cpuCores = options.cpu ?? config.cpu;\n const memoryMB = options.memory ?? config.memory;\n const diskGB = options.disk ?? config.disk;\n const timeout = options.timeout ?? config.timeout;\n // Always keyed, so a create whose outcome is unknown can be joined. The default name comes from the\n // key, so a create sent again with the same key carries the same body.\n const idempotencyKey = typeof options.idempotencyKey === 'string' ? options.idempotencyKey : randomUUID();\n return {\n name: options.name ?? `computesdk-${createHash('sha256').update(idempotencyKey).digest('hex').slice(0, 8)}`,\n ...(environment !== undefined ? { environment } : {}),\n ...(options.templateId !== undefined ? { templateId: options.templateId } : {}),\n ...(cpuCores !== undefined || memoryMB !== undefined || diskGB !== undefined\n ? { resources: { cpuCores, memoryMB, diskGB } } : {}),\n ...(timeout !== undefined ? { maxLifetimeSeconds: Math.ceil(timeout / 1000) } : {}),\n ...(options.ephemeral !== undefined ? { ephemeral: options.ephemeral } : {}),\n ...(options.envs ? { env: options.envs } : {}),\n ...(options.metadata ? { metadata: options.metadata } : {}),\n idempotencyKey,\n };\n}\n\n/** A sandbox that is already gone counts as deleted. */\nasync function remove(sdk: Sandbox, id: string): Promise<void> {\n try {\n await sdk.delete(id);\n } catch (error) {\n if (!(error instanceof NotFoundError)) throw error;\n }\n}\n\n/** Deletes a sandbox that did not start, keeping the start failure as the error. */\nasync function discard(sdk: Sandbox, id: string, failure: unknown): Promise<void> {\n await remove(sdk, id).catch((cleanup: unknown) => {\n const message = `Tangle sandbox ${id} did not start (${String(failure)}) and was not deleted (${String(cleanup)}).`;\n throw Object.assign(new Error(message), { cause: failure });\n });\n}\n\n/** Only a refusal shows a failed create left nothing behind; without a sandbox id, anything else is unknown. */\nfunction outcomeUnknown(error: unknown): boolean {\n if (!(error instanceof SandboxError)) return true;\n if (error.allocationId !== undefined || error.createFailureDisposition === 'not-admitted' || NO_ROOM.has(error.code)) return false;\n return !(error.status >= 400 && error.status < 500 && !error.retryable);\n}\n\n/** Sends the create once more when its outcome is unknown; the same idempotency key joins the first attempt. */\nasync function admit(sdk: Sandbox, request: CreateSandboxOptions): Promise<SandboxInstance> {\n try {\n return await sdk.create(request);\n } catch (error) {\n if (!outcomeUnknown(error)) throw error;\n return sdk.create(request).catch((joined: unknown) => {\n // Keep the first failure reachable when the second fails too, unless the second carries its own cause.\n if (joined instanceof Error && !('cause' in joined)) Object.assign(joined, { cause: error });\n throw joined;\n });\n }\n}\n\nfunction status(sandbox: SandboxInstance): InstanceInfo['status'] {\n switch (sandbox.status) {\n case 'pending':\n case 'provisioning':\n case 'running':\n return 'running';\n case 'failed':\n return 'error';\n default:\n return 'stopped';\n }\n}\n\nexport const tangle = defineProvider<SandboxInstance, TangleConfig>({\n name: 'tangle',\n methods: {\n instances: {\n create: async (config, options = {}) => {\n const sdk = client(config);\n const request = createOptions(config, options);\n // A rejected create returns no id, so the caller could never delete what it left behind. With a\n // caller's key the platform can return a sandbox another call allocated, so delete only one under\n // the provider's own key or one the platform says this call created.\n const owned = (receipt: { outcome: string } | null | undefined): boolean =>\n typeof options.idempotencyKey !== 'string' || receipt?.outcome === 'created';\n let sandbox: SandboxInstance;\n try {\n sandbox = await admit(sdk, request);\n } catch (error) {\n // The SDK names the sandbox a failed readiness wait leaves behind.\n if (error instanceof SandboxError && error.allocationId !== undefined && owned(error.createReceipt)) {\n await discard(sdk, error.allocationId, error);\n }\n throw error;\n }\n try {\n if (ENDED.has(sandbox.status)) throw new Error(`Tangle sandbox ${sandbox.id} is ${sandbox.status}.`);\n // create() waits only while pending or provisioning; this also waits for the filesystem.\n await sandbox.waitFor('running');\n } catch (error) {\n if (owned(sandbox.createReceipt())) await discard(sdk, sandbox.id, error);\n throw error;\n }\n // The factory destroys an instance whose create resolves after an abort, so keep one this call\n // did not create from reaching it.\n if (options.signal?.aborted && !owned(sandbox.createReceipt())) {\n throw new Error(`Create aborted; Tangle sandbox ${sandbox.id} may belong to another create with this idempotencyKey, so it is left running.`);\n }\n return { instance: sandbox, instanceId: sandbox.id };\n },\n\n getById: async (config, instanceId) => {\n const sandbox = await client(config).get(instanceId);\n return sandbox && sandbox.status !== 'deleted' ? { instance: sandbox, instanceId: sandbox.id } : null;\n },\n\n // Without a limit the API returns every match, so one request lists every sandbox not deleted.\n list: async (config) =>\n (await client(config).list({ status: LISTED_STATUSES })).map((sandbox) => ({ instance: sandbox, instanceId: sandbox.id })),\n\n destroy: async (config, instanceId) => remove(client(config), instanceId),\n\n runCommand: async (sandbox, command, options: RunCommandOptions = {}): Promise<CommandResult> => {\n const start = Date.now();\n // The runtime's cwd field only accepts paths inside the workspace, so change directory in the shell.\n const script = options.cwd ? `cd \"${escapeShellArg(options.cwd)}\" || exit $?\\n${command}` : command;\n if (options.background) {\n // 0 is no limit: a background command runs until it exits or the sandbox stops.\n await sandbox.process.spawn(script, { env: options.env, timeoutMs: options.timeout ?? 0 });\n return { stdout: '', stderr: '', exitCode: 0, durationMs: Date.now() - start };\n }\n const result = await sandbox.exec(script, { env: options.env, timeoutMs: options.timeout ?? EXEC_TIMEOUT_MS });\n return { ...result, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox): Promise<InstanceInfo> => {\n await sandbox.refresh();\n return {\n id: sandbox.id,\n provider: 'tangle',\n status: status(sandbox),\n createdAt: sandbox.createdAt,\n // Each start or resume begins a new lifetime interval.\n timeout: sandbox.expiresAt ? Math.max(0, sandbox.expiresAt.getTime() - (sandbox.startedAt ?? sandbox.createdAt).getTime()) : 0,\n metadata: { ...sandbox.metadata, name: sandbox.name, resources: sandbox.resources },\n };\n },\n\n getUrl: async (sandbox, { port, protocol }) => {\n const url = new URL(await sandbox.network.exposePort(port));\n if (protocol) url.protocol = `${protocol}:`;\n return url.toString();\n },\n\n getInstance: (sandbox) => sandbox,\n\n filesystem: {\n readFile: (sandbox, path) => sandbox.read(path),\n writeFile: async (sandbox, path, content) => { await sandbox.write(path, content); },\n mkdir: (sandbox, path) => sandbox.fs.mkdir(path, { recursive: true }),\n readdir: async (sandbox, path): Promise<FileEntry[]> => (await sandbox.fs.list(path)).map((entry) => ({\n name: entry.name,\n type: entry.isDir ? 'directory' : 'file',\n size: entry.size,\n modified: entry.modTime,\n })),\n exists: (sandbox, path) => sandbox.fs.exists(path),\n remove: (sandbox, path) => sandbox.fs.delete(path, { recursive: true }),\n },\n },\n },\n});\n"],"mappings":";AAIA,SAAS,YAAY,kBAAkB;AACvC,SAAS,eAAe,SAAS,oBAAyF;AAC1H,SAAS,gBAAgB,sBAAsB;AAG/C,IAAM,mBAAmB;AAEzB,IAAM,kBAAkB;AAExB,IAAM,kBAAmC,CAAC,WAAW,gBAAgB,WAAW,WAAW,UAAU,SAAS;AAE9G,IAAM,QAAQ,oBAAI,IAAmB,CAAC,WAAW,WAAW,SAAS,CAAC;AAEtE,IAAM,UAAU,oBAAI,IAAY,CAAC,sBAAsB,eAAe,CAAC;AAmBvE,IAAM,MAAM,CAAC,SACX,OAAO,YAAY,cAAc,QAAQ,MAAM,IAAI,IAAI;AAGzD,SAAS,OAAO,QAA+B;AAC7C,QAAM,UAAU,OAAO,UAAU,IAAI,gBAAgB,IAAI,KAAK;AAC9D,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,oHAAoH;AAAA,EACtI;AACA,SAAO,IAAI,QAAQ,EAAE,QAAQ,SAAS,OAAO,WAAW,IAAI,yBAAyB,KAAK,iBAAiB,CAAC;AAC9G;AAEA,SAAS,cAAc,QAAsB,SAAsD;AACjG,MAAI,QAAQ,eAAe,QAAW;AACpC,UAAM,IAAI,MAAM,6FAA6F;AAAA,EAC/G;AACA,MAAI,QAAQ,YAAY,QAAW;AACjC,UAAM,IAAI,MAAM,6FAA6F;AAAA,EAC/G;AAEA,QAAM,cAAc,QAAQ,UAAU,QAAQ,eAAe,SAAY,OAAO,QAAQ;AACxF,QAAM,WAAW,QAAQ,OAAO,OAAO;AACvC,QAAM,WAAW,QAAQ,UAAU,OAAO;AAC1C,QAAM,SAAS,QAAQ,QAAQ,OAAO;AACtC,QAAM,UAAU,QAAQ,WAAW,OAAO;AAG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AM;AAAA,UACZ,MAAM,MAAM,QAAQ,cAAc;AAAA,UAClC,MAAM,MAAM;AAAA,UACZ,UAAU,MAAM;AAAA,QAClB,EAAE;AAAA,QACF,QAAQ,CAAC,SAAS,SAAS,QAAQ,GAAG,OAAO,IAAI;AAAA,QACjD,QAAQ,CAAC,SAAS,SAAS,QAAQ,GAAG,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/tangle",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Tangle Sandbox provider for ComputeSDK - isolated Linux sandboxes with command execution and filesystem access",
|
|
5
|
+
"author": "Tangle",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.19.0"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@tangle-network/sandbox": "1.0.264",
|
|
25
|
+
"@computesdk/provider": "2.1.24",
|
|
26
|
+
"computesdk": "4.1.18"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
31
|
+
"eslint": "^8.37.0",
|
|
32
|
+
"rimraf": "^5.0.0",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.0.0",
|
|
35
|
+
"vitest": "^1.0.0",
|
|
36
|
+
"@computesdk/test-utils": "2.0.6"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"computesdk",
|
|
40
|
+
"tangle",
|
|
41
|
+
"sandbox",
|
|
42
|
+
"code-execution",
|
|
43
|
+
"provider"
|
|
44
|
+
],
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/computesdk/computesdk.git",
|
|
48
|
+
"directory": "packages/tangle"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://sandbox.tangle.tools",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/computesdk/computesdk/issues"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup",
|
|
56
|
+
"clean": "rimraf dist",
|
|
57
|
+
"dev": "tsup --watch",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest watch",
|
|
60
|
+
"test:coverage": "vitest run --coverage",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"lint": "eslint"
|
|
63
|
+
}
|
|
6
64
|
}
|