@temps-sdk/sandbox 0.0.0-alpha.0 → 0.0.1-beta.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/README.md +66 -1
- package/dist/client.d.ts +67 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +232 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +12 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +59 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -4
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
1
|
# @temps-sdk/sandbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed TypeScript/JavaScript client for the Temps Sandboxes API.
|
|
4
|
+
|
|
5
|
+
Drop-in compatible with the `@vercel/sandbox` shape — switch providers by
|
|
6
|
+
changing the import and base URL.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bun add @temps-sdk/sandbox
|
|
12
|
+
# or
|
|
13
|
+
npm install @temps-sdk/sandbox
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { Sandbox } from '@temps-sdk/sandbox';
|
|
20
|
+
|
|
21
|
+
// Reads TEMPS_API_URL and TEMPS_API_TOKEN from the environment when omitted.
|
|
22
|
+
const sandbox = await Sandbox.create({
|
|
23
|
+
name: 'my-sandbox',
|
|
24
|
+
timeoutSecs: 7200,
|
|
25
|
+
source: {
|
|
26
|
+
type: 'git',
|
|
27
|
+
url: 'https://github.com/example/repo.git',
|
|
28
|
+
revision: 'main',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const { exitCode, stdout } = await sandbox.exec(['node', '--version']);
|
|
33
|
+
console.log(stdout);
|
|
34
|
+
|
|
35
|
+
// Preview a dev server running inside the sandbox.
|
|
36
|
+
const url = sandbox.domain(3000); // https://sbx-abc-3000.preview.example.com
|
|
37
|
+
|
|
38
|
+
await sandbox.stop();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
- `Sandbox.create(opts)` — create a new sandbox, optionally seeded from a git repo or tarball.
|
|
44
|
+
Pass `node` (a worker node name, id, or `'control-plane'`) to choose where it runs;
|
|
45
|
+
omit it to let Temps place it. `sandbox.info.nodeName` reports where it landed.
|
|
46
|
+
- `Sandbox.get(id, config)` — rehydrate an existing sandbox by ID.
|
|
47
|
+
- `Sandbox.list(config)` — paginate the caller's sandboxes.
|
|
48
|
+
- `sandbox.exec(cmd, opts?)` — synchronous exec; returns stdout/stderr/exitCode.
|
|
49
|
+
- `sandbox.execDetached(cmd, opts?)` — background job; poll `jobStatus(jobId)`.
|
|
50
|
+
- `sandbox.writeFile({ path, contents, mode? })` — write UTF-8 or binary content.
|
|
51
|
+
- `sandbox.readFile(path)` — read as `Uint8Array`.
|
|
52
|
+
- `sandbox.stat(path)` / `sandbox.mkdir(path)` — filesystem helpers.
|
|
53
|
+
- `sandbox.domain(port)` — build a preview URL for a port exposed inside.
|
|
54
|
+
- `sandbox.pause()` / `resume()` / `restart()` / `stop()` / `destroy()` — lifecycle.
|
|
55
|
+
- `sandbox.extendTimeout(extraSecs)` — push back the idle expiry.
|
|
56
|
+
|
|
57
|
+
All errors are instances of `SandboxError`; the `detail` field carries the
|
|
58
|
+
RFC 7807 problem description from the server.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
| Option | Env var | Required |
|
|
63
|
+
| ------------- | ----------------- | -------- |
|
|
64
|
+
| `apiUrl` | `TEMPS_API_URL` | yes |
|
|
65
|
+
| `apiToken` | `TEMPS_API_TOKEN` | yes |
|
|
66
|
+
| `fetch` | — | no |
|
|
67
|
+
|
|
68
|
+
Create a personal access token under **API Keys** in the Temps dashboard.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { SandboxError } from './errors.js';
|
|
2
|
+
import type { CreateSandboxOptions, ExecOptions, ExecResult, JobHandle, JobState, ListSandboxesOptions, ListSandboxesPage, SandboxConfig, SandboxEvent, SandboxSummary, StatInfo, WriteFileOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A live sandbox. Instances are returned by {@link Sandbox.create} and
|
|
5
|
+
* {@link Sandbox.get}; they hold both the server-assigned ID and the
|
|
6
|
+
* client config needed to make follow-up calls.
|
|
7
|
+
*
|
|
8
|
+
* The shape intentionally mirrors `@vercel/sandbox` — switching providers
|
|
9
|
+
* should require only swapping the import and base URL.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Sandbox {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
private summary;
|
|
14
|
+
private readonly cfg;
|
|
15
|
+
private constructor();
|
|
16
|
+
/** Current metadata snapshot. Call {@link refresh} to reload from the server. */
|
|
17
|
+
get info(): SandboxSummary;
|
|
18
|
+
/** Provision a new sandbox. */
|
|
19
|
+
static create(config?: SandboxConfig & CreateSandboxOptions): Promise<Sandbox>;
|
|
20
|
+
/** Fetch an existing sandbox by ID. */
|
|
21
|
+
static get(id: string, config?: SandboxConfig): Promise<Sandbox>;
|
|
22
|
+
/** Page through the caller's sandboxes. */
|
|
23
|
+
static list(config?: SandboxConfig & ListSandboxesOptions): Promise<ListSandboxesPage>;
|
|
24
|
+
refresh(): Promise<SandboxSummary>;
|
|
25
|
+
/**
|
|
26
|
+
* Run a command synchronously. Blocks until the process exits; stdout
|
|
27
|
+
* and stderr are buffered and returned together. For long-running
|
|
28
|
+
* processes use {@link execDetached} and stream the job instead.
|
|
29
|
+
*/
|
|
30
|
+
exec(cmd: string[], options?: Omit<ExecOptions, 'cmd'>): Promise<ExecResult>;
|
|
31
|
+
/** Start a background job. Returns a handle — poll with {@link jobStatus}. */
|
|
32
|
+
execDetached(cmd: string[], options?: Omit<ExecOptions, 'cmd'>): Promise<JobHandle>;
|
|
33
|
+
jobStatus(jobId: string): Promise<JobState>;
|
|
34
|
+
killJob(jobId: string, signal?: string): Promise<void>;
|
|
35
|
+
writeFile(opts: WriteFileOptions): Promise<void>;
|
|
36
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
37
|
+
mkdir(path: string): Promise<void>;
|
|
38
|
+
stat(path: string): Promise<StatInfo>;
|
|
39
|
+
/**
|
|
40
|
+
* Build a public preview URL for a port exposed inside the sandbox.
|
|
41
|
+
* Returns `null` if this install doesn't have preview URLs configured
|
|
42
|
+
* (the template is empty). Matches `@vercel/sandbox`'s `domain(port)`.
|
|
43
|
+
*/
|
|
44
|
+
domain(port: number): string | null;
|
|
45
|
+
extendTimeout(extraSecs: number): Promise<void>;
|
|
46
|
+
pause(): Promise<void>;
|
|
47
|
+
resume(): Promise<void>;
|
|
48
|
+
restart(): Promise<void>;
|
|
49
|
+
/** Stop the container but keep the row (can `resume` later). */
|
|
50
|
+
stop(): Promise<void>;
|
|
51
|
+
/** Stop **and** delete the sandbox. Irreversible. */
|
|
52
|
+
destroy(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Grow the root disk to `diskSizeMb` (Firecracker only; grow-only). The
|
|
55
|
+
* sandbox restarts briefly to apply it — the filesystem is preserved.
|
|
56
|
+
* Returns the refreshed summary.
|
|
57
|
+
*/
|
|
58
|
+
resize(diskSizeMb: number): Promise<SandboxSummary>;
|
|
59
|
+
/**
|
|
60
|
+
* The operations timeline for this sandbox (lifecycle events only —
|
|
61
|
+
* create/stop/resume/restart/extend/resize/preview-password/destroy —
|
|
62
|
+
* never shell activity), newest first.
|
|
63
|
+
*/
|
|
64
|
+
events(limit?: number): Promise<SandboxEvent[]>;
|
|
65
|
+
}
|
|
66
|
+
export { SandboxError };
|
|
67
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,YAAY,EAEZ,cAAc,EACd,QAAQ,EACR,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAgIpB;;;;;;;GAOG;AACH,qBAAa,OAAO;IAClB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAiB;IAErC,OAAO;IAMP,iFAAiF;IACjF,IAAI,IAAI,IAAI,cAAc,CAEzB;IAED,+BAA+B;WAClB,MAAM,CACjB,MAAM,GAAE,aAAa,GAAG,oBAAyB,GAChD,OAAO,CAAC,OAAO,CAAC;IAYnB,uCAAuC;WAC1B,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU1E,2CAA2C;WAC9B,IAAI,CACf,MAAM,GAAE,aAAa,GAAG,oBAAyB,GAChD,OAAO,CAAC,iBAAiB,CAAC;IAoBvB,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC;IAUxC;;;;OAIG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IActF,8EAA8E;IACxE,YAAY,CAChB,GAAG,EAAE,MAAM,EAA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
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
import { SandboxError } from './errors.js';
|
|
4
|
+
import { request, resolveConfig } from './http.js';
|
|
5
|
+
function toSummary(w) {
|
|
6
|
+
return {
|
|
7
|
+
id: w.id,
|
|
8
|
+
name: w.name,
|
|
9
|
+
status: w.status,
|
|
10
|
+
image: w.image,
|
|
11
|
+
workDir: w.cwd,
|
|
12
|
+
backend: w.backend ?? undefined,
|
|
13
|
+
diskSizeMb: w.disk_size_mb ?? undefined,
|
|
14
|
+
createdAt: new Date(w.createdAt).toISOString(),
|
|
15
|
+
expiresAt: new Date(w.createdAt + w.timeout).toISOString(),
|
|
16
|
+
previewUrlTemplate: w.preview_url_template,
|
|
17
|
+
previewPasswordHint: w.preview_password_hint,
|
|
18
|
+
nodeName: w.node_name,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function toCreateBody(opts) {
|
|
22
|
+
return {
|
|
23
|
+
name: opts.name,
|
|
24
|
+
image: opts.image,
|
|
25
|
+
timeout_secs: opts.timeoutSecs,
|
|
26
|
+
env: opts.env,
|
|
27
|
+
cpu_limit: opts.cpuLimit,
|
|
28
|
+
memory_limit_mb: opts.memoryLimitMb,
|
|
29
|
+
pids_limit: opts.pidsLimit,
|
|
30
|
+
source: opts.source ? toSourceBody(opts.source) : undefined,
|
|
31
|
+
preview_password: opts.previewPassword,
|
|
32
|
+
backend: opts.backend,
|
|
33
|
+
node: opts.node,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function toSourceBody(src) {
|
|
37
|
+
if (src.type === 'git') {
|
|
38
|
+
return {
|
|
39
|
+
type: 'git',
|
|
40
|
+
url: src.url,
|
|
41
|
+
revision: src.revision,
|
|
42
|
+
depth: src.depth,
|
|
43
|
+
username: src.username,
|
|
44
|
+
password: src.password,
|
|
45
|
+
git_connection_id: src.gitConnectionId,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { type: 'tarball', url: src.url };
|
|
49
|
+
}
|
|
50
|
+
function toBase64(contents) {
|
|
51
|
+
const bytes = typeof contents === 'string'
|
|
52
|
+
? new TextEncoder().encode(contents)
|
|
53
|
+
: contents;
|
|
54
|
+
if (typeof Buffer !== 'undefined')
|
|
55
|
+
return Buffer.from(bytes).toString('base64');
|
|
56
|
+
// Browser fallback
|
|
57
|
+
let binary = '';
|
|
58
|
+
for (const b of bytes)
|
|
59
|
+
binary += String.fromCharCode(b);
|
|
60
|
+
return btoa(binary);
|
|
61
|
+
}
|
|
62
|
+
function fromBase64(b64) {
|
|
63
|
+
if (typeof Buffer !== 'undefined')
|
|
64
|
+
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
65
|
+
const binary = atob(b64);
|
|
66
|
+
const out = new Uint8Array(binary.length);
|
|
67
|
+
for (let i = 0; i < binary.length; i++)
|
|
68
|
+
out[i] = binary.charCodeAt(i);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A live sandbox. Instances are returned by {@link Sandbox.create} and
|
|
73
|
+
* {@link Sandbox.get}; they hold both the server-assigned ID and the
|
|
74
|
+
* client config needed to make follow-up calls.
|
|
75
|
+
*
|
|
76
|
+
* The shape intentionally mirrors `@vercel/sandbox` — switching providers
|
|
77
|
+
* should require only swapping the import and base URL.
|
|
78
|
+
*/
|
|
79
|
+
export class Sandbox {
|
|
80
|
+
id;
|
|
81
|
+
summary;
|
|
82
|
+
cfg;
|
|
83
|
+
constructor(summary, cfg) {
|
|
84
|
+
this.id = summary.id;
|
|
85
|
+
this.summary = summary;
|
|
86
|
+
this.cfg = cfg;
|
|
87
|
+
}
|
|
88
|
+
/** Current metadata snapshot. Call {@link refresh} to reload from the server. */
|
|
89
|
+
get info() {
|
|
90
|
+
return this.summary;
|
|
91
|
+
}
|
|
92
|
+
/** Provision a new sandbox. */
|
|
93
|
+
static async create(config = {}) {
|
|
94
|
+
const { apiUrl, apiToken, fetch, ...opts } = config;
|
|
95
|
+
const cfg = resolveConfig({ apiUrl, apiToken, fetch });
|
|
96
|
+
const wire = await request(cfg, 'POST', '/v1/sandboxes', toCreateBody(opts));
|
|
97
|
+
return new Sandbox(toSummary(wire.sandbox), cfg);
|
|
98
|
+
}
|
|
99
|
+
/** Fetch an existing sandbox by ID. */
|
|
100
|
+
static async get(id, config = {}) {
|
|
101
|
+
const cfg = resolveConfig(config);
|
|
102
|
+
const wire = await request(cfg, 'GET', `/v1/sandboxes/${id}`);
|
|
103
|
+
return new Sandbox(toSummary(wire.sandbox), cfg);
|
|
104
|
+
}
|
|
105
|
+
/** Page through the caller's sandboxes. */
|
|
106
|
+
static async list(config = {}) {
|
|
107
|
+
const { apiUrl, apiToken, fetch, page, pageSize } = config;
|
|
108
|
+
const cfg = resolveConfig({ apiUrl, apiToken, fetch });
|
|
109
|
+
const wire = await request(cfg, 'GET', '/v1/sandboxes', undefined, { page, page_size: pageSize });
|
|
110
|
+
return {
|
|
111
|
+
items: wire.sandboxes.map(toSummary),
|
|
112
|
+
total: wire.pagination.count,
|
|
113
|
+
page: page ?? 1,
|
|
114
|
+
pageSize: pageSize ?? 20,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// ── Instance methods ──
|
|
118
|
+
async refresh() {
|
|
119
|
+
const wire = await request(this.cfg, 'GET', `/v1/sandboxes/${this.id}`);
|
|
120
|
+
this.summary = toSummary(wire.sandbox);
|
|
121
|
+
return this.summary;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Run a command synchronously. Blocks until the process exits; stdout
|
|
125
|
+
* and stderr are buffered and returned together. For long-running
|
|
126
|
+
* processes use {@link execDetached} and stream the job instead.
|
|
127
|
+
*/
|
|
128
|
+
async exec(cmd, options = {}) {
|
|
129
|
+
const wire = await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/exec`, { cmd, env: options.env, cwd: options.cwd });
|
|
130
|
+
return {
|
|
131
|
+
exitCode: wire.exit_code,
|
|
132
|
+
stdout: wire.stdout,
|
|
133
|
+
stderr: wire.stderr,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Start a background job. Returns a handle — poll with {@link jobStatus}. */
|
|
137
|
+
async execDetached(cmd, options = {}) {
|
|
138
|
+
const wire = await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/exec-detached`, { cmd, env: options.env, cwd: options.cwd });
|
|
139
|
+
return { jobId: wire.job_id };
|
|
140
|
+
}
|
|
141
|
+
async jobStatus(jobId) {
|
|
142
|
+
const wire = await request(this.cfg, 'GET', `/v1/sandboxes/${this.id}/jobs/${jobId}`);
|
|
143
|
+
return {
|
|
144
|
+
status: wire.status,
|
|
145
|
+
exitCode: wire.exit_code,
|
|
146
|
+
reason: wire.reason,
|
|
147
|
+
stdout: wire.stdout,
|
|
148
|
+
stderr: wire.stderr,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async killJob(jobId, signal) {
|
|
152
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/jobs/${jobId}/kill`, signal ? { signal } : undefined);
|
|
153
|
+
}
|
|
154
|
+
async writeFile(opts) {
|
|
155
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/fs/write`, {
|
|
156
|
+
path: opts.path,
|
|
157
|
+
contents_b64: toBase64(opts.contents),
|
|
158
|
+
mode: opts.mode,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async readFile(path) {
|
|
162
|
+
const wire = await request(this.cfg, 'GET', `/v1/sandboxes/${this.id}/fs/read`, undefined, { path });
|
|
163
|
+
return fromBase64(wire.contents_b64);
|
|
164
|
+
}
|
|
165
|
+
async mkdir(path) {
|
|
166
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/fs/mkdir`, {
|
|
167
|
+
path,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async stat(path) {
|
|
171
|
+
const wire = await request(this.cfg, 'GET', `/v1/sandboxes/${this.id}/fs/stat`, undefined, { path });
|
|
172
|
+
return {
|
|
173
|
+
path: wire.path,
|
|
174
|
+
exists: wire.exists,
|
|
175
|
+
isDir: wire.is_dir,
|
|
176
|
+
isFile: wire.is_file,
|
|
177
|
+
size: wire.size,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Build a public preview URL for a port exposed inside the sandbox.
|
|
182
|
+
* Returns `null` if this install doesn't have preview URLs configured
|
|
183
|
+
* (the template is empty). Matches `@vercel/sandbox`'s `domain(port)`.
|
|
184
|
+
*/
|
|
185
|
+
domain(port) {
|
|
186
|
+
const tpl = this.summary.previewUrlTemplate;
|
|
187
|
+
if (!tpl)
|
|
188
|
+
return null;
|
|
189
|
+
return tpl.replace('{port}', String(port));
|
|
190
|
+
}
|
|
191
|
+
async extendTimeout(extraSecs) {
|
|
192
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/extend-timeout`, { extra_secs: extraSecs });
|
|
193
|
+
}
|
|
194
|
+
async pause() {
|
|
195
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/pause`);
|
|
196
|
+
}
|
|
197
|
+
async resume() {
|
|
198
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/resume`);
|
|
199
|
+
}
|
|
200
|
+
async restart() {
|
|
201
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/restart`);
|
|
202
|
+
}
|
|
203
|
+
/** Stop the container but keep the row (can `resume` later). */
|
|
204
|
+
async stop() {
|
|
205
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/stop`);
|
|
206
|
+
}
|
|
207
|
+
/** Stop **and** delete the sandbox. Irreversible. */
|
|
208
|
+
async destroy() {
|
|
209
|
+
await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/destroy`);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Grow the root disk to `diskSizeMb` (Firecracker only; grow-only). The
|
|
213
|
+
* sandbox restarts briefly to apply it — the filesystem is preserved.
|
|
214
|
+
* Returns the refreshed summary.
|
|
215
|
+
*/
|
|
216
|
+
async resize(diskSizeMb) {
|
|
217
|
+
const wire = await request(this.cfg, 'POST', `/v1/sandboxes/${this.id}/resize`, { disk_size_mb: diskSizeMb });
|
|
218
|
+
this.summary = toSummary(wire.sandbox);
|
|
219
|
+
return this.summary;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The operations timeline for this sandbox (lifecycle events only —
|
|
223
|
+
* create/stop/resume/restart/extend/resize/preview-password/destroy —
|
|
224
|
+
* never shell activity), newest first.
|
|
225
|
+
*/
|
|
226
|
+
async events(limit) {
|
|
227
|
+
const wire = await request(this.cfg, 'GET', `/v1/sandboxes/${this.id}/events`, undefined, limit ? { limit } : undefined);
|
|
228
|
+
return wire.events;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export { SandboxError };
|
|
232
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAC;AA0ExE,SAAS,SAAS,CAAC,CAAmB;IACpC,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,OAAO,EAAE,CAAC,CAAC,GAAG;QACd,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,SAAS;QAC/B,UAAU,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;QACvC,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;QAC9C,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS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,EAAE,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface ProblemDetails {
|
|
2
|
+
type?: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
detail?: string;
|
|
5
|
+
instance?: string;
|
|
6
|
+
status?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class SandboxError extends Error {
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
readonly title?: string;
|
|
12
|
+
readonly detail?: string;
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
code?: string;
|
|
15
|
+
status?: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
detail?: string;
|
|
18
|
+
});
|
|
19
|
+
static fromResponse(response: Response, body?: ProblemDetails | {
|
|
20
|
+
error?: {
|
|
21
|
+
message: string;
|
|
22
|
+
code?: string;
|
|
23
|
+
};
|
|
24
|
+
}): SandboxError;
|
|
25
|
+
static missingConfig(field: 'apiUrl' | 'apiToken'): SandboxError;
|
|
26
|
+
static networkError(originalError: Error): SandboxError;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAcH,MAAM,CAAC,YAAY,CACjB,QAAQ,EAAE,QAAQ,EAClB,IAAI,CAAC,EAAE,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACrE,YAAY;IAsBf,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY;IAQhE,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,KAAK,GAAG,YAAY;CAKxD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024-2026 Temps Contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
export class SandboxError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
status;
|
|
6
|
+
title;
|
|
7
|
+
detail;
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'SandboxError';
|
|
11
|
+
this.code = options?.code;
|
|
12
|
+
this.status = options?.status;
|
|
13
|
+
this.title = options?.title;
|
|
14
|
+
this.detail = options?.detail;
|
|
15
|
+
if (Error.captureStackTrace) {
|
|
16
|
+
Error.captureStackTrace(this, SandboxError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static fromResponse(response, body) {
|
|
20
|
+
if (body && typeof body === 'object' && ('title' in body || 'detail' in body)) {
|
|
21
|
+
const pd = body;
|
|
22
|
+
const message = pd.detail ??
|
|
23
|
+
pd.title ??
|
|
24
|
+
`Sandbox request failed with status ${response.status}`;
|
|
25
|
+
return new SandboxError(message, {
|
|
26
|
+
code: pd.type,
|
|
27
|
+
status: response.status,
|
|
28
|
+
title: pd.title,
|
|
29
|
+
detail: pd.detail,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const legacy = body;
|
|
33
|
+
return new SandboxError(legacy?.error?.message ??
|
|
34
|
+
`Sandbox request failed with status ${response.status}`, { code: legacy?.error?.code, status: response.status });
|
|
35
|
+
}
|
|
36
|
+
static missingConfig(field) {
|
|
37
|
+
const envVar = field === 'apiUrl' ? 'TEMPS_API_URL' : 'TEMPS_API_TOKEN';
|
|
38
|
+
return new SandboxError(`Missing required configuration: ${field}. Set ${envVar} or pass it in the config.`, { code: 'MISSING_CONFIG' });
|
|
39
|
+
}
|
|
40
|
+
static networkError(originalError) {
|
|
41
|
+
return new SandboxError(`Network error: ${originalError.message}`, {
|
|
42
|
+
code: 'NETWORK_ERROR',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAe7C,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrB,IAAI,CAAU;IACd,MAAM,CAAU;IAChB,KAAK,CAAU;IACf,MAAM,CAAU;IAEhC,YACE,OAAe,EACf,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAE9B,IAAI,KAAK,CAAC,iBAAiB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C,kBAAkB,aAAa,CAAC,OAAO,EAAE,EAAE;YACjE,IAAI,EAAE,eAAe;SACtB,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ResolvedConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
apiToken: string;
|
|
4
|
+
fetch: typeof fetch;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveConfig(cfg?: {
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
apiToken?: string;
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
}): ResolvedConfig;
|
|
11
|
+
export declare function request<T>(cfg: ResolvedConfig, method: string, path: string, body?: unknown, query?: Record<string, string | number | undefined>): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,wBAAgB,aAAa,CAC3B,GAAG,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GACrE,cAAc,CAehB;AAED,wBAAsB,OAAO,CAAC,CAAC,EAC7B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,GAClD,OAAO,CAAC,CAAC,CAAC,CAsCZ"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024-2026 Temps Contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
import { SandboxError } from './errors.js';
|
|
4
|
+
export function resolveConfig(cfg = {}) {
|
|
5
|
+
const env = typeof process !== 'undefined' && process.env ? process.env : {};
|
|
6
|
+
const apiUrl = cfg.apiUrl ?? env.TEMPS_API_URL;
|
|
7
|
+
const apiToken = cfg.apiToken ?? env.TEMPS_API_TOKEN;
|
|
8
|
+
if (!apiUrl)
|
|
9
|
+
throw SandboxError.missingConfig('apiUrl');
|
|
10
|
+
if (!apiToken)
|
|
11
|
+
throw SandboxError.missingConfig('apiToken');
|
|
12
|
+
const fetchImpl = cfg.fetch ?? globalThis.fetch;
|
|
13
|
+
if (!fetchImpl) {
|
|
14
|
+
throw new SandboxError('No fetch implementation available. Pass `fetch` in config or run on Node 18+.', { code: 'NO_FETCH' });
|
|
15
|
+
}
|
|
16
|
+
return { apiUrl: apiUrl.replace(/\/$/, ''), apiToken, fetch: fetchImpl };
|
|
17
|
+
}
|
|
18
|
+
export async function request(cfg, method, path, body, query) {
|
|
19
|
+
const url = new URL(cfg.apiUrl + path);
|
|
20
|
+
if (query) {
|
|
21
|
+
for (const [k, v] of Object.entries(query)) {
|
|
22
|
+
if (v !== undefined)
|
|
23
|
+
url.searchParams.set(k, String(v));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const headers = {
|
|
27
|
+
Authorization: `Bearer ${cfg.apiToken}`,
|
|
28
|
+
Accept: 'application/json',
|
|
29
|
+
};
|
|
30
|
+
if (body !== undefined)
|
|
31
|
+
headers['Content-Type'] = 'application/json';
|
|
32
|
+
let response;
|
|
33
|
+
try {
|
|
34
|
+
response = await cfg.fetch(url.toString(), {
|
|
35
|
+
method,
|
|
36
|
+
headers,
|
|
37
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
throw SandboxError.networkError(e);
|
|
42
|
+
}
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
// RFC 7807 uses application/problem+json; be lenient and try to
|
|
45
|
+
// parse whatever we got before giving up on a generic message.
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = await response.json();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
parsed = undefined;
|
|
52
|
+
}
|
|
53
|
+
throw SandboxError.fromResponse(response, parsed);
|
|
54
|
+
}
|
|
55
|
+
if (response.status === 204)
|
|
56
|
+
return undefined;
|
|
57
|
+
return (await response.json());
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAY3C,MAAM,UAAU,aAAa,CAC3B,MAAoE,EAAE;IAEtE,MAAM,GAAG,GACP,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,aAAa,CAAC;IAC/C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,eAAe,CAAC;IACrD,IAAI,CAAC,MAAM;QAAE,MAAM,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxD,IAAI,CAAC,QAAQ;QAAE,MAAM,YAAY,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC;IAChD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,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,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,gEAAgE;QAChE,+DAA+D;QAC/D,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,YAAY,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAe,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,SAAc,CAAC;IACnD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;AACtC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Sandbox, SandboxError } from './client.js';
|
|
2
|
+
export type { CreateSandboxOptions, ExecOptions, ExecResult, JobHandle, JobState, JobStatus, ListSandboxesOptions, ListSandboxesPage, SandboxConfig, SandboxEvent, SandboxSource, SandboxSummary, StatInfo, WriteFileOptions, } from './types.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAE7C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export interface SandboxConfig {
|
|
2
|
+
/** Base URL of the Temps control plane (e.g. https://temps.example.com). */
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
/** Personal access token: `temps_pat_...`. */
|
|
5
|
+
apiToken?: string;
|
|
6
|
+
/** Optional fetch override (tests, custom transports). */
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export type SandboxSource = {
|
|
10
|
+
type: 'git';
|
|
11
|
+
url: string;
|
|
12
|
+
revision?: string;
|
|
13
|
+
depth?: number;
|
|
14
|
+
username?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
gitConnectionId?: number;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'tarball';
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
|
+
export interface CreateSandboxOptions {
|
|
22
|
+
/** Friendly label surfaced in the UI and `list` output. */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** Docker image override. Omit to use the platform default. */
|
|
25
|
+
image?: string;
|
|
26
|
+
/** Idle timeout in seconds. Clamped server-side to [60, 86400]. */
|
|
27
|
+
timeoutSecs?: number;
|
|
28
|
+
/** Extra env vars baked into the container on create. */
|
|
29
|
+
env?: Record<string, string>;
|
|
30
|
+
cpuLimit?: number;
|
|
31
|
+
memoryLimitMb?: number;
|
|
32
|
+
pidsLimit?: number;
|
|
33
|
+
/** Seed initial contents from a git repo or tarball. */
|
|
34
|
+
source?: SandboxSource;
|
|
35
|
+
/** Optional plaintext password for preview URLs (8–256 chars). */
|
|
36
|
+
previewPassword?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Isolation backend: 'docker' (default), 'firecracker' (hardware-
|
|
39
|
+
* virtualized microVM; requires a host provisioned with
|
|
40
|
+
* `temps firecracker setup`) or 'microsandbox' (experimental libkrun
|
|
41
|
+
* microVM; requires `temps microsandbox setup`). Requesting an
|
|
42
|
+
* unavailable backend fails rather than silently downgrading isolation.
|
|
43
|
+
*/
|
|
44
|
+
backend?: 'docker' | 'firecracker' | 'microsandbox';
|
|
45
|
+
/**
|
|
46
|
+
* Node to run the sandbox on: a worker node name, a node id, or
|
|
47
|
+
* `'control-plane'`. Omit it to let Temps place the sandbox on an allowed
|
|
48
|
+
* node. A node that isn't allowed or isn't online fails the request
|
|
49
|
+
* rather than falling back to another one. Some features (terminal,
|
|
50
|
+
* snapshots, preview URLs, disk resize, volumes) are not available yet on
|
|
51
|
+
* worker nodes.
|
|
52
|
+
*/
|
|
53
|
+
node?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SandboxSummary {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
status: string;
|
|
59
|
+
image: string | null;
|
|
60
|
+
workDir: string;
|
|
61
|
+
/** Isolation backend the sandbox runs on ('docker' | 'firecracker' | 'microsandbox'). */
|
|
62
|
+
backend?: string;
|
|
63
|
+
/** Root disk size in MB (Firecracker). */
|
|
64
|
+
diskSizeMb?: number;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
expiresAt: string;
|
|
67
|
+
/**
|
|
68
|
+
* URL template with a literal `{port}` placeholder. Use `sandbox.domain(port)`
|
|
69
|
+
* to get a concrete URL rather than reading this directly.
|
|
70
|
+
*/
|
|
71
|
+
previewUrlTemplate: string;
|
|
72
|
+
previewPasswordHint?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Name of the node hosting the sandbox; `'control-plane'` for the control
|
|
75
|
+
* plane. Absent on servers without multi-node sandboxes.
|
|
76
|
+
*/
|
|
77
|
+
nodeName?: string;
|
|
78
|
+
}
|
|
79
|
+
/** One entry in a sandbox's operations timeline. */
|
|
80
|
+
export interface SandboxEvent {
|
|
81
|
+
/**
|
|
82
|
+
* Machine-readable operation: 'created' | 'stopped' | 'resumed' |
|
|
83
|
+
* 'restarted' | 'timeout_extended' | 'resized' | 'preview_password_set' |
|
|
84
|
+
* 'preview_password_cleared' | 'source_seeded' | 'destroyed'.
|
|
85
|
+
*/
|
|
86
|
+
event_type: string;
|
|
87
|
+
/** Optional structured context; shape depends on `event_type`. */
|
|
88
|
+
detail?: Record<string, unknown> | null;
|
|
89
|
+
/** Event time, Unix epoch milliseconds. */
|
|
90
|
+
at: number;
|
|
91
|
+
}
|
|
92
|
+
export interface ExecOptions {
|
|
93
|
+
/** Argv array. First element is the program; the rest are args. */
|
|
94
|
+
cmd: string[];
|
|
95
|
+
env?: Record<string, string>;
|
|
96
|
+
cwd?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface ExecResult {
|
|
99
|
+
exitCode: number;
|
|
100
|
+
stdout: string;
|
|
101
|
+
stderr: string;
|
|
102
|
+
}
|
|
103
|
+
export interface JobHandle {
|
|
104
|
+
/** Opaque job ID used to poll status or stream logs. */
|
|
105
|
+
jobId: string;
|
|
106
|
+
}
|
|
107
|
+
export type JobStatus = 'running' | 'exited' | 'failed';
|
|
108
|
+
export interface JobState {
|
|
109
|
+
status: JobStatus;
|
|
110
|
+
exitCode: number | null;
|
|
111
|
+
reason: string | null;
|
|
112
|
+
stdout: string;
|
|
113
|
+
stderr: string;
|
|
114
|
+
}
|
|
115
|
+
export interface WriteFileOptions {
|
|
116
|
+
/** Absolute path inside the sandbox (must start with `/`). */
|
|
117
|
+
path: string;
|
|
118
|
+
/** File contents. Strings are UTF-8 encoded; Uint8Array is used as-is. */
|
|
119
|
+
contents: string | Uint8Array;
|
|
120
|
+
/** Unix mode (e.g. 0o755). Defaults to 0o644. */
|
|
121
|
+
mode?: number;
|
|
122
|
+
}
|
|
123
|
+
export interface StatInfo {
|
|
124
|
+
path: string;
|
|
125
|
+
exists: boolean;
|
|
126
|
+
isDir: boolean;
|
|
127
|
+
isFile: boolean;
|
|
128
|
+
size: number;
|
|
129
|
+
}
|
|
130
|
+
export interface ListSandboxesPage {
|
|
131
|
+
items: SandboxSummary[];
|
|
132
|
+
total: number;
|
|
133
|
+
page: number;
|
|
134
|
+
pageSize: number;
|
|
135
|
+
}
|
|
136
|
+
export interface ListSandboxesOptions {
|
|
137
|
+
page?: number;
|
|
138
|
+
pageSize?: number;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GACrB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEN,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDA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,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExD,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAC9B,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temps-sdk/sandbox",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
|
+
"description": "Sandbox SDK for the Temps platform",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json",
|
|
16
|
+
"test": "vitest",
|
|
17
|
+
"test:run": "vitest run",
|
|
18
|
+
"test:coverage": "vitest run --coverage",
|
|
19
|
+
"clean": "rm -rf dist"
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"temps",
|
|
31
|
+
"sandbox",
|
|
32
|
+
"docker",
|
|
33
|
+
"exec",
|
|
34
|
+
"vercel-sandbox"
|
|
35
|
+
],
|
|
36
|
+
"author": "",
|
|
5
37
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
41
|
+
"typescript": "^5.5.4",
|
|
42
|
+
"vitest": "^4.1.0"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/gotempsh/temps.git",
|
|
47
|
+
"directory": "sdks/node/packages/sandbox"
|
|
48
|
+
}
|
|
8
49
|
}
|