@b3os/sdk 0.0.0-stage → 0.1.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 +202 -0
- package/README.md +233 -2
- package/dist/cjs/core/client.d.ts +165 -0
- package/dist/cjs/core/client.js +825 -0
- package/dist/cjs/core/client.js.map +1 -0
- package/dist/cjs/core/errors.d.ts +101 -0
- package/dist/cjs/core/errors.js +249 -0
- package/dist/cjs/core/errors.js.map +1 -0
- package/dist/cjs/core/index.d.ts +12 -0
- package/dist/cjs/core/index.js +42 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/core/jobs.d.ts +31 -0
- package/dist/cjs/core/jobs.js +72 -0
- package/dist/cjs/core/jobs.js.map +1 -0
- package/dist/cjs/core/namespace.d.ts +7 -0
- package/dist/cjs/core/namespace.js +13 -0
- package/dist/cjs/core/namespace.js.map +1 -0
- package/dist/cjs/core/op.d.ts +47 -0
- package/dist/cjs/core/op.js +5 -0
- package/dist/cjs/core/op.js.map +1 -0
- package/dist/cjs/core/promise.d.ts +106 -0
- package/dist/cjs/core/promise.js +200 -0
- package/dist/cjs/core/promise.js.map +1 -0
- package/dist/cjs/core/response.d.ts +54 -0
- package/dist/cjs/core/response.js +92 -0
- package/dist/cjs/core/response.js.map +1 -0
- package/dist/cjs/core/sse.d.ts +79 -0
- package/dist/cjs/core/sse.js +291 -0
- package/dist/cjs/core/sse.js.map +1 -0
- package/dist/cjs/core/timing.d.ts +20 -0
- package/dist/cjs/core/timing.js +96 -0
- package/dist/cjs/core/timing.js.map +1 -0
- package/dist/cjs/core/transport.d.ts +80 -0
- package/dist/cjs/core/transport.js +472 -0
- package/dist/cjs/core/transport.js.map +1 -0
- package/dist/cjs/core/util.d.ts +25 -0
- package/dist/cjs/core/util.js +142 -0
- package/dist/cjs/core/util.js.map +1 -0
- package/dist/cjs/core/ws.d.ts +52 -0
- package/dist/cjs/core/ws.js +181 -0
- package/dist/cjs/core/ws.js.map +1 -0
- package/dist/cjs/generated/client.d.ts +62 -0
- package/dist/cjs/generated/client.js +130 -0
- package/dist/cjs/generated/client.js.map +1 -0
- package/dist/cjs/generated/errors.d.ts +4 -0
- package/dist/cjs/generated/errors.js +160 -0
- package/dist/cjs/generated/errors.js.map +1 -0
- package/dist/cjs/generated/ids.d.ts +114 -0
- package/dist/cjs/generated/ids.js +47 -0
- package/dist/cjs/generated/ids.js.map +1 -0
- package/dist/cjs/generated/jobs.d.ts +10 -0
- package/dist/cjs/generated/jobs.js +24 -0
- package/dist/cjs/generated/jobs.js.map +1 -0
- package/dist/cjs/generated/ns/actions.d.ts +161 -0
- package/dist/cjs/generated/ns/actions.js +304 -0
- package/dist/cjs/generated/ns/actions.js.map +1 -0
- package/dist/cjs/generated/ns/infer.d.ts +190 -0
- package/dist/cjs/generated/ns/infer.js +253 -0
- package/dist/cjs/generated/ns/infer.js.map +1 -0
- package/dist/cjs/generated/ns/keys.d.ts +76 -0
- package/dist/cjs/generated/ns/keys.js +144 -0
- package/dist/cjs/generated/ns/keys.js.map +1 -0
- package/dist/cjs/generated/ns/limits.d.ts +22 -0
- package/dist/cjs/generated/ns/limits.js +32 -0
- package/dist/cjs/generated/ns/limits.js.map +1 -0
- package/dist/cjs/generated/ns/orgs.d.ts +38 -0
- package/dist/cjs/generated/ns/orgs.js +68 -0
- package/dist/cjs/generated/ns/orgs.js.map +1 -0
- package/dist/cjs/generated/ns/projects.d.ts +57 -0
- package/dist/cjs/generated/ns/projects.js +115 -0
- package/dist/cjs/generated/ns/projects.js.map +1 -0
- package/dist/cjs/generated/ns/render.d.ts +159 -0
- package/dist/cjs/generated/ns/render.js +299 -0
- package/dist/cjs/generated/ns/render.js.map +1 -0
- package/dist/cjs/generated/ns/requests.d.ts +36 -0
- package/dist/cjs/generated/ns/requests.js +54 -0
- package/dist/cjs/generated/ns/requests.js.map +1 -0
- package/dist/cjs/generated/ns/routines.d.ts +212 -0
- package/dist/cjs/generated/ns/routines.js +419 -0
- package/dist/cjs/generated/ns/routines.js.map +1 -0
- package/dist/cjs/generated/ns/sandboxes.d.ts +318 -0
- package/dist/cjs/generated/ns/sandboxes.js +549 -0
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -0
- package/dist/cjs/generated/ns/usage.d.ts +30 -0
- package/dist/cjs/generated/ns/usage.js +49 -0
- package/dist/cjs/generated/ns/usage.js.map +1 -0
- package/dist/cjs/generated/ns/vault.d.ts +69 -0
- package/dist/cjs/generated/ns/vault.js +122 -0
- package/dist/cjs/generated/ns/vault.js.map +1 -0
- package/dist/cjs/generated/ns/vision.d.ts +376 -0
- package/dist/cjs/generated/ns/vision.js +736 -0
- package/dist/cjs/generated/ns/vision.js.map +1 -0
- package/dist/cjs/generated/ns/webhooks.d.ts +50 -0
- package/dist/cjs/generated/ns/webhooks.js +91 -0
- package/dist/cjs/generated/ns/webhooks.js.map +1 -0
- package/dist/cjs/generated/types.d.ts +4613 -0
- package/dist/cjs/generated/types.js +4 -0
- package/dist/cjs/generated/types.js.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/webhooks.d.ts +19 -0
- package/dist/cjs/webhooks.js +85 -0
- package/dist/cjs/webhooks.js.map +1 -0
- package/dist/esm/core/client.d.ts +165 -0
- package/dist/esm/core/client.js +821 -0
- package/dist/esm/core/client.js.map +1 -0
- package/dist/esm/core/errors.d.ts +101 -0
- package/dist/esm/core/errors.js +239 -0
- package/dist/esm/core/errors.js.map +1 -0
- package/dist/esm/core/index.d.ts +12 -0
- package/dist/esm/core/index.js +15 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/jobs.d.ts +31 -0
- package/dist/esm/core/jobs.js +66 -0
- package/dist/esm/core/jobs.js.map +1 -0
- package/dist/esm/core/namespace.d.ts +7 -0
- package/dist/esm/core/namespace.js +9 -0
- package/dist/esm/core/namespace.js.map +1 -0
- package/dist/esm/core/op.d.ts +47 -0
- package/dist/esm/core/op.js +4 -0
- package/dist/esm/core/op.js.map +1 -0
- package/dist/esm/core/promise.d.ts +106 -0
- package/dist/esm/core/promise.js +193 -0
- package/dist/esm/core/promise.js.map +1 -0
- package/dist/esm/core/response.d.ts +54 -0
- package/dist/esm/core/response.js +86 -0
- package/dist/esm/core/response.js.map +1 -0
- package/dist/esm/core/sse.d.ts +79 -0
- package/dist/esm/core/sse.js +286 -0
- package/dist/esm/core/sse.js.map +1 -0
- package/dist/esm/core/timing.d.ts +20 -0
- package/dist/esm/core/timing.js +92 -0
- package/dist/esm/core/timing.js.map +1 -0
- package/dist/esm/core/transport.d.ts +80 -0
- package/dist/esm/core/transport.js +465 -0
- package/dist/esm/core/transport.js.map +1 -0
- package/dist/esm/core/util.d.ts +25 -0
- package/dist/esm/core/util.js +128 -0
- package/dist/esm/core/util.js.map +1 -0
- package/dist/esm/core/ws.d.ts +52 -0
- package/dist/esm/core/ws.js +175 -0
- package/dist/esm/core/ws.js.map +1 -0
- package/dist/esm/generated/client.d.ts +62 -0
- package/dist/esm/generated/client.js +126 -0
- package/dist/esm/generated/client.js.map +1 -0
- package/dist/esm/generated/errors.d.ts +4 -0
- package/dist/esm/generated/errors.js +157 -0
- package/dist/esm/generated/errors.js.map +1 -0
- package/dist/esm/generated/ids.d.ts +114 -0
- package/dist/esm/generated/ids.js +42 -0
- package/dist/esm/generated/ids.js.map +1 -0
- package/dist/esm/generated/jobs.d.ts +10 -0
- package/dist/esm/generated/jobs.js +21 -0
- package/dist/esm/generated/jobs.js.map +1 -0
- package/dist/esm/generated/ns/actions.d.ts +161 -0
- package/dist/esm/generated/ns/actions.js +300 -0
- package/dist/esm/generated/ns/actions.js.map +1 -0
- package/dist/esm/generated/ns/infer.d.ts +190 -0
- package/dist/esm/generated/ns/infer.js +249 -0
- package/dist/esm/generated/ns/infer.js.map +1 -0
- package/dist/esm/generated/ns/keys.d.ts +76 -0
- package/dist/esm/generated/ns/keys.js +140 -0
- package/dist/esm/generated/ns/keys.js.map +1 -0
- package/dist/esm/generated/ns/limits.d.ts +22 -0
- package/dist/esm/generated/ns/limits.js +28 -0
- package/dist/esm/generated/ns/limits.js.map +1 -0
- package/dist/esm/generated/ns/orgs.d.ts +38 -0
- package/dist/esm/generated/ns/orgs.js +64 -0
- package/dist/esm/generated/ns/orgs.js.map +1 -0
- package/dist/esm/generated/ns/projects.d.ts +57 -0
- package/dist/esm/generated/ns/projects.js +111 -0
- package/dist/esm/generated/ns/projects.js.map +1 -0
- package/dist/esm/generated/ns/render.d.ts +159 -0
- package/dist/esm/generated/ns/render.js +295 -0
- package/dist/esm/generated/ns/render.js.map +1 -0
- package/dist/esm/generated/ns/requests.d.ts +36 -0
- package/dist/esm/generated/ns/requests.js +50 -0
- package/dist/esm/generated/ns/requests.js.map +1 -0
- package/dist/esm/generated/ns/routines.d.ts +212 -0
- package/dist/esm/generated/ns/routines.js +415 -0
- package/dist/esm/generated/ns/routines.js.map +1 -0
- package/dist/esm/generated/ns/sandboxes.d.ts +318 -0
- package/dist/esm/generated/ns/sandboxes.js +545 -0
- package/dist/esm/generated/ns/sandboxes.js.map +1 -0
- package/dist/esm/generated/ns/usage.d.ts +30 -0
- package/dist/esm/generated/ns/usage.js +45 -0
- package/dist/esm/generated/ns/usage.js.map +1 -0
- package/dist/esm/generated/ns/vault.d.ts +69 -0
- package/dist/esm/generated/ns/vault.js +118 -0
- package/dist/esm/generated/ns/vault.js.map +1 -0
- package/dist/esm/generated/ns/vision.d.ts +376 -0
- package/dist/esm/generated/ns/vision.js +732 -0
- package/dist/esm/generated/ns/vision.js.map +1 -0
- package/dist/esm/generated/ns/webhooks.d.ts +50 -0
- package/dist/esm/generated/ns/webhooks.js +87 -0
- package/dist/esm/generated/ns/webhooks.js.map +1 -0
- package/dist/esm/generated/types.d.ts +4613 -0
- package/dist/esm/generated/types.js +3 -0
- package/dist/esm/generated/types.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/webhooks.d.ts +19 -0
- package/dist/esm/webhooks.js +79 -0
- package/dist/esm/webhooks.js.map +1 -0
- package/package.json +97 -3
- package/src/core/client.ts +1022 -0
- package/src/core/errors.ts +296 -0
- package/src/core/index.ts +45 -0
- package/src/core/jobs.ts +94 -0
- package/src/core/namespace.ts +10 -0
- package/src/core/op.ts +53 -0
- package/src/core/promise.ts +268 -0
- package/src/core/response.ts +115 -0
- package/src/core/sse.ts +305 -0
- package/src/core/timing.ts +106 -0
- package/src/core/transport.ts +489 -0
- package/src/core/util.ts +138 -0
- package/src/core/ws.ts +215 -0
- package/src/generated/client.ts +143 -0
- package/src/generated/errors.ts +313 -0
- package/src/generated/ids.ts +47 -0
- package/src/generated/jobs.ts +25 -0
- package/src/generated/ns/actions.ts +353 -0
- package/src/generated/ns/infer.ts +332 -0
- package/src/generated/ns/keys.ts +152 -0
- package/src/generated/ns/limits.ts +35 -0
- package/src/generated/ns/orgs.ts +77 -0
- package/src/generated/ns/projects.ts +122 -0
- package/src/generated/ns/render.ts +348 -0
- package/src/generated/ns/requests.ts +61 -0
- package/src/generated/ns/routines.ts +474 -0
- package/src/generated/ns/sandboxes.ts +671 -0
- package/src/generated/ns/usage.ts +56 -0
- package/src/generated/ns/vault.ts +136 -0
- package/src/generated/ns/vision.ts +836 -0
- package/src/generated/ns/webhooks.ts +100 -0
- package/src/generated/types.ts +5131 -0
- package/src/index.ts +30 -0
- package/src/webhooks.ts +100 -0
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
// Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
|
|
2
|
+
|
|
3
|
+
import type { BinaryInput, RequestOptions, StreamOptions } from "../../core/client.ts";
|
|
4
|
+
import { Namespace } from "../../core/namespace.ts";
|
|
5
|
+
import type { Op } from "../../core/op.ts";
|
|
6
|
+
import type { APIPromise, ListPromise } from "../../core/promise.ts";
|
|
7
|
+
import type { EventStream } from "../../core/sse.ts";
|
|
8
|
+
import { openSocket, PtySession, ticketedUrl } from "../../core/ws.ts";
|
|
9
|
+
import type * as T from "../types.ts";
|
|
10
|
+
|
|
11
|
+
const listSandboxesOp: Op = {
|
|
12
|
+
id: "sandboxesListSandboxes",
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: "/v1/sandboxes",
|
|
15
|
+
timeoutMs: 10000,
|
|
16
|
+
scope: "sandboxes:read",
|
|
17
|
+
};
|
|
18
|
+
const createSandboxOp: Op = {
|
|
19
|
+
id: "sandboxesCreateSandbox",
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/v1/sandboxes",
|
|
22
|
+
body: "json",
|
|
23
|
+
idem: true,
|
|
24
|
+
timeoutMs: 30000,
|
|
25
|
+
scope: "sandboxes:write",
|
|
26
|
+
};
|
|
27
|
+
const listSnapshotsOp: Op = {
|
|
28
|
+
id: "sandboxesListSnapshots",
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/v1/sandboxes/snapshots",
|
|
31
|
+
timeoutMs: 10000,
|
|
32
|
+
scope: "sandboxes:read",
|
|
33
|
+
};
|
|
34
|
+
const deleteSnapshotOp: Op = {
|
|
35
|
+
id: "sandboxesDeleteSnapshot",
|
|
36
|
+
method: "DELETE",
|
|
37
|
+
path: "/v1/sandboxes/snapshots/{snapshot_id}",
|
|
38
|
+
params: ["snapshot_id"],
|
|
39
|
+
timeoutMs: 10000,
|
|
40
|
+
scope: "sandboxes:write",
|
|
41
|
+
};
|
|
42
|
+
const getSnapshotOp: Op = {
|
|
43
|
+
id: "sandboxesGetSnapshot",
|
|
44
|
+
method: "GET",
|
|
45
|
+
path: "/v1/sandboxes/snapshots/{snapshot_id}",
|
|
46
|
+
params: ["snapshot_id"],
|
|
47
|
+
timeoutMs: 10000,
|
|
48
|
+
scope: "sandboxes:read",
|
|
49
|
+
};
|
|
50
|
+
const listTemplatesOp: Op = {
|
|
51
|
+
id: "sandboxesListTemplates",
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/v1/sandboxes/templates",
|
|
54
|
+
timeoutMs: 10000,
|
|
55
|
+
scope: "sandboxes:read",
|
|
56
|
+
};
|
|
57
|
+
const getTemplateOp: Op = {
|
|
58
|
+
id: "sandboxesGetTemplate",
|
|
59
|
+
method: "GET",
|
|
60
|
+
path: "/v1/sandboxes/templates/{template}",
|
|
61
|
+
params: ["template"],
|
|
62
|
+
timeoutMs: 10000,
|
|
63
|
+
scope: "sandboxes:read",
|
|
64
|
+
};
|
|
65
|
+
const deleteSandboxOp: Op = {
|
|
66
|
+
id: "sandboxesDeleteSandbox",
|
|
67
|
+
method: "DELETE",
|
|
68
|
+
path: "/v1/sandboxes/{sandbox_id}",
|
|
69
|
+
params: ["sandbox_id"],
|
|
70
|
+
timeoutMs: 15000,
|
|
71
|
+
scope: "sandboxes:write",
|
|
72
|
+
};
|
|
73
|
+
const getSandboxOp: Op = {
|
|
74
|
+
id: "sandboxesGetSandbox",
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: "/v1/sandboxes/{sandbox_id}",
|
|
77
|
+
params: ["sandbox_id"],
|
|
78
|
+
timeoutMs: 10000,
|
|
79
|
+
scope: "sandboxes:read",
|
|
80
|
+
};
|
|
81
|
+
const execOp: Op = {
|
|
82
|
+
id: "sandboxesExec",
|
|
83
|
+
method: "POST",
|
|
84
|
+
path: "/v1/sandboxes/{sandbox_id}/exec",
|
|
85
|
+
params: ["sandbox_id"],
|
|
86
|
+
body: "json",
|
|
87
|
+
stream: "sse",
|
|
88
|
+
timeoutMs: 3600000,
|
|
89
|
+
scope: "sandboxes:run",
|
|
90
|
+
};
|
|
91
|
+
const readFileOp: Op = {
|
|
92
|
+
id: "sandboxesReadFile",
|
|
93
|
+
method: "GET",
|
|
94
|
+
path: "/v1/sandboxes/{sandbox_id}/files",
|
|
95
|
+
params: ["sandbox_id"],
|
|
96
|
+
timeoutMs: 60000,
|
|
97
|
+
scope: "sandboxes:run",
|
|
98
|
+
};
|
|
99
|
+
const writeFileOp: Op = {
|
|
100
|
+
id: "sandboxesWriteFile",
|
|
101
|
+
method: "PUT",
|
|
102
|
+
path: "/v1/sandboxes/{sandbox_id}/files",
|
|
103
|
+
params: ["sandbox_id"],
|
|
104
|
+
body: "bytes",
|
|
105
|
+
contentType: "application/octet-stream",
|
|
106
|
+
timeoutMs: 60000,
|
|
107
|
+
scope: "sandboxes:run",
|
|
108
|
+
};
|
|
109
|
+
const forkSandboxOp: Op = {
|
|
110
|
+
id: "sandboxesForkSandbox",
|
|
111
|
+
method: "POST",
|
|
112
|
+
path: "/v1/sandboxes/{sandbox_id}/fork",
|
|
113
|
+
params: ["sandbox_id"],
|
|
114
|
+
body: "json",
|
|
115
|
+
idem: true,
|
|
116
|
+
timeoutMs: 30000,
|
|
117
|
+
stretch: true,
|
|
118
|
+
scope: "sandboxes:write",
|
|
119
|
+
};
|
|
120
|
+
const streamLogsOp: Op = {
|
|
121
|
+
id: "sandboxesStreamLogs",
|
|
122
|
+
method: "GET",
|
|
123
|
+
path: "/v1/sandboxes/{sandbox_id}/logs",
|
|
124
|
+
params: ["sandbox_id"],
|
|
125
|
+
stream: "sse",
|
|
126
|
+
timeoutMs: 3600000,
|
|
127
|
+
scope: "sandboxes:run",
|
|
128
|
+
};
|
|
129
|
+
const pauseSandboxOp: Op = {
|
|
130
|
+
id: "sandboxesPauseSandbox",
|
|
131
|
+
method: "POST",
|
|
132
|
+
path: "/v1/sandboxes/{sandbox_id}/pause",
|
|
133
|
+
params: ["sandbox_id"],
|
|
134
|
+
timeoutMs: 10000,
|
|
135
|
+
scope: "sandboxes:write",
|
|
136
|
+
};
|
|
137
|
+
const createPortUrlOp: Op = {
|
|
138
|
+
id: "sandboxesCreatePortUrl",
|
|
139
|
+
method: "POST",
|
|
140
|
+
path: "/v1/sandboxes/{sandbox_id}/ports/{port}/url",
|
|
141
|
+
params: ["sandbox_id", "port"],
|
|
142
|
+
body: "json",
|
|
143
|
+
timeoutMs: 5000,
|
|
144
|
+
scope: "sandboxes:run",
|
|
145
|
+
};
|
|
146
|
+
const listProcessesOp: Op = {
|
|
147
|
+
id: "sandboxesListProcesses",
|
|
148
|
+
method: "GET",
|
|
149
|
+
path: "/v1/sandboxes/{sandbox_id}/processes",
|
|
150
|
+
params: ["sandbox_id"],
|
|
151
|
+
timeoutMs: 10000,
|
|
152
|
+
scope: "sandboxes:run",
|
|
153
|
+
};
|
|
154
|
+
const killProcessOp: Op = {
|
|
155
|
+
id: "sandboxesKillProcess",
|
|
156
|
+
method: "POST",
|
|
157
|
+
path: "/v1/sandboxes/{sandbox_id}/processes/{pid}/kill",
|
|
158
|
+
params: ["sandbox_id", "pid"],
|
|
159
|
+
body: "json",
|
|
160
|
+
timeoutMs: 10000,
|
|
161
|
+
scope: "sandboxes:run",
|
|
162
|
+
};
|
|
163
|
+
const openPtyOp: Op = {
|
|
164
|
+
id: "sandboxesOpenPty",
|
|
165
|
+
method: "GET",
|
|
166
|
+
path: "/v1/sandboxes/{sandbox_id}/pty",
|
|
167
|
+
params: ["sandbox_id"],
|
|
168
|
+
stream: "ws",
|
|
169
|
+
timeoutMs: 3600000,
|
|
170
|
+
scope: "sandboxes:run",
|
|
171
|
+
};
|
|
172
|
+
const resumeSandboxOp: Op = {
|
|
173
|
+
id: "sandboxesResumeSandbox",
|
|
174
|
+
method: "POST",
|
|
175
|
+
path: "/v1/sandboxes/{sandbox_id}/resume",
|
|
176
|
+
params: ["sandbox_id"],
|
|
177
|
+
timeoutMs: 10000,
|
|
178
|
+
scope: "sandboxes:write",
|
|
179
|
+
};
|
|
180
|
+
const runCodeOp: Op = {
|
|
181
|
+
id: "sandboxesRunCode",
|
|
182
|
+
method: "POST",
|
|
183
|
+
path: "/v1/sandboxes/{sandbox_id}/run_code",
|
|
184
|
+
params: ["sandbox_id"],
|
|
185
|
+
body: "json",
|
|
186
|
+
timeoutMs: 65000,
|
|
187
|
+
scope: "sandboxes:run",
|
|
188
|
+
};
|
|
189
|
+
const createSnapshotOp: Op = {
|
|
190
|
+
id: "sandboxesCreateSnapshot",
|
|
191
|
+
method: "POST",
|
|
192
|
+
path: "/v1/sandboxes/{sandbox_id}/snapshot",
|
|
193
|
+
params: ["sandbox_id"],
|
|
194
|
+
body: "json",
|
|
195
|
+
idem: true,
|
|
196
|
+
timeoutMs: 65000,
|
|
197
|
+
scope: "sandboxes:write",
|
|
198
|
+
};
|
|
199
|
+
const createTicketOp: Op = {
|
|
200
|
+
id: "sandboxesCreateTicket",
|
|
201
|
+
method: "POST",
|
|
202
|
+
path: "/v1/sandboxes/{sandbox_id}/ticket",
|
|
203
|
+
params: ["sandbox_id"],
|
|
204
|
+
timeoutMs: 5000,
|
|
205
|
+
scope: "sandboxes:read",
|
|
206
|
+
};
|
|
207
|
+
const setTimeoutOp: Op = {
|
|
208
|
+
id: "sandboxesSetTimeout",
|
|
209
|
+
method: "POST",
|
|
210
|
+
path: "/v1/sandboxes/{sandbox_id}/timeout",
|
|
211
|
+
params: ["sandbox_id"],
|
|
212
|
+
body: "json",
|
|
213
|
+
timeoutMs: 10000,
|
|
214
|
+
scope: "sandboxes:write",
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** Descriptors of every sandboxes operation, keyed by method name (for tooling and custom clients). */
|
|
218
|
+
export const sandboxesOps = {
|
|
219
|
+
listSandboxes: listSandboxesOp,
|
|
220
|
+
createSandbox: createSandboxOp,
|
|
221
|
+
listSnapshots: listSnapshotsOp,
|
|
222
|
+
deleteSnapshot: deleteSnapshotOp,
|
|
223
|
+
getSnapshot: getSnapshotOp,
|
|
224
|
+
listTemplates: listTemplatesOp,
|
|
225
|
+
getTemplate: getTemplateOp,
|
|
226
|
+
deleteSandbox: deleteSandboxOp,
|
|
227
|
+
getSandbox: getSandboxOp,
|
|
228
|
+
exec: execOp,
|
|
229
|
+
readFile: readFileOp,
|
|
230
|
+
writeFile: writeFileOp,
|
|
231
|
+
forkSandbox: forkSandboxOp,
|
|
232
|
+
streamLogs: streamLogsOp,
|
|
233
|
+
pauseSandbox: pauseSandboxOp,
|
|
234
|
+
createPortUrl: createPortUrlOp,
|
|
235
|
+
listProcesses: listProcessesOp,
|
|
236
|
+
killProcess: killProcessOp,
|
|
237
|
+
openPty: openPtyOp,
|
|
238
|
+
resumeSandbox: resumeSandboxOp,
|
|
239
|
+
runCode: runCodeOp,
|
|
240
|
+
createSnapshot: createSnapshotOp,
|
|
241
|
+
createTicket: createTicketOp,
|
|
242
|
+
setTimeout: setTimeoutOp,
|
|
243
|
+
} as const;
|
|
244
|
+
|
|
245
|
+
/** Firecracker microVM sandboxes: exec, files, terminals, ports, snapshots (`/v1/sandboxes`). */
|
|
246
|
+
export class SandboxesAPI extends Namespace {
|
|
247
|
+
/**
|
|
248
|
+
* List sandboxes
|
|
249
|
+
*
|
|
250
|
+
* Lists sandboxes in this project, newest first, including stopped ones from the last 7 days.
|
|
251
|
+
*
|
|
252
|
+
* `GET /v1/sandboxes` · scope `sandboxes:read` · served by the node
|
|
253
|
+
*/
|
|
254
|
+
listSandboxes(
|
|
255
|
+
params?: T.SandboxesListSandboxesParams,
|
|
256
|
+
options?: RequestOptions,
|
|
257
|
+
): ListPromise<T.SandboxList, T.Sandbox> {
|
|
258
|
+
return this._client._list<T.SandboxList, T.Sandbox>(listSandboxesOp, { query: params }, options);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Create a sandbox
|
|
263
|
+
*
|
|
264
|
+
* Claims a pre-warmed microVM from the template's pool (or restores a snapshot), binds a fresh identity to it
|
|
265
|
+
* (new entropy, machine ID and clock) and returns it running. The sandbox stops when `timeout_s` passes unless
|
|
266
|
+
* you extend it, and `on_idle: pause` pauses it instead. It bills `sandboxes.vcpu_ms` (CPU used) and
|
|
267
|
+
* `sandboxes.gib_ms` (memory allocated) while running.
|
|
268
|
+
*
|
|
269
|
+
* `api` grants code inside the sandbox access to B3OS (`http://127.0.0.1:7700`) with scopes that must be a
|
|
270
|
+
* subset of yours; `sandboxes:write`, every `vault:*` and every `platform:*` scope are never granted unless named
|
|
271
|
+
* explicitly. `api.spend_cap_usd` may not exceed your own spend cap, and `null` means your cap applies; scopes
|
|
272
|
+
* or a cap beyond yours are refused with `403 forbidden`, `reason: scope_escalation`.
|
|
273
|
+
*
|
|
274
|
+
* Inside the sandbox the environment also has `B3OS_API_URL=http://127.0.0.1:7700`, `B3OS_SANDBOX_ID`,
|
|
275
|
+
* `B3OS_PROJECT` and `B3OS_PORT_BASE_PATH=/sbx/<host_id>`. `B3OS_PORT_BASE_PATH` is only the fixed start of
|
|
276
|
+
* every port preview path on `usercontent.b3os.org`, not a full base path: the full prefix of a request,
|
|
277
|
+
* `/sbx/<host_id>/<port>/<token>`, arrives with it in `X-Forwarded-Prefix` (`sandboxesProxyPortGet`).
|
|
278
|
+
*
|
|
279
|
+
* `timing` phases: `validate_ms`, then `claim_ms` and `resume_ms` for a pre-warmed microVM from the pool, or
|
|
280
|
+
* `restore_ms` when none was parked (a restore on demand, or from a snapshot), then `bind_ms` (the identity
|
|
281
|
+
* and environment reach the guest agent), and `total_ms`.
|
|
282
|
+
*
|
|
283
|
+
* A create that has started finishes even if the client disconnects before the response: the sandbox then
|
|
284
|
+
* runs (and is billed) until its timeout or a delete, and `GET /v1/sandboxes` lists it with the `metadata`
|
|
285
|
+
* it was created with. After a disconnect, look for it there before you retry: a retry is a new create, also
|
|
286
|
+
* with the same `Idempotency-Key`, because the key is released when the client goes away before the
|
|
287
|
+
* response. Fork, snapshot, pause and resume also finish after a disconnect.
|
|
288
|
+
*
|
|
289
|
+
* `POST /v1/sandboxes` · scope `sandboxes:write` · served by the node
|
|
290
|
+
*/
|
|
291
|
+
createSandbox(body?: T.SandboxCreateRequest, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
292
|
+
return this._client._call<T.Sandbox>(createSandboxOp, { body }, options);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* List snapshots
|
|
297
|
+
*
|
|
298
|
+
* Lists snapshots in this project, newest first.
|
|
299
|
+
*
|
|
300
|
+
* `GET /v1/sandboxes/snapshots` · scope `sandboxes:read` · served by the node
|
|
301
|
+
*/
|
|
302
|
+
listSnapshots(
|
|
303
|
+
params?: T.SandboxesListSnapshotsParams,
|
|
304
|
+
options?: RequestOptions,
|
|
305
|
+
): ListPromise<T.SnapshotList, T.Snapshot> {
|
|
306
|
+
return this._client._list<T.SnapshotList, T.Snapshot>(listSnapshotsOp, { query: params }, options);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Delete a snapshot
|
|
311
|
+
*
|
|
312
|
+
* Deletes the snapshot. Sandboxes already restored from it keep running.
|
|
313
|
+
*
|
|
314
|
+
* `DELETE /v1/sandboxes/snapshots/{snapshot_id}` · scope `sandboxes:write` · served by the node
|
|
315
|
+
*/
|
|
316
|
+
deleteSnapshot(snapshotId: string, options?: RequestOptions): APIPromise<T.Deleted> {
|
|
317
|
+
return this._client._call<T.Deleted>(deleteSnapshotOp, { path: [snapshotId] }, options);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Get a snapshot
|
|
322
|
+
*
|
|
323
|
+
* Returns a snapshot's metadata and status.
|
|
324
|
+
*
|
|
325
|
+
* `GET /v1/sandboxes/snapshots/{snapshot_id}` · scope `sandboxes:read` · served by the node
|
|
326
|
+
*/
|
|
327
|
+
getSnapshot(snapshotId: string, options?: RequestOptions): APIPromise<T.Snapshot> {
|
|
328
|
+
return this._client._call<T.Snapshot>(getSnapshotOp, { path: [snapshotId] }, options);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* List templates
|
|
333
|
+
*
|
|
334
|
+
* Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and on nodes that build it
|
|
335
|
+
* `browser`: Chrome already running in the snapshot, a VM-isolated browser with DevTools on port 9222) with their
|
|
336
|
+
* contents and defaults.
|
|
337
|
+
*
|
|
338
|
+
* `GET /v1/sandboxes/templates` · scope `sandboxes:read` · served by the node
|
|
339
|
+
*/
|
|
340
|
+
listTemplates(options?: RequestOptions): APIPromise<T.TemplateList> {
|
|
341
|
+
return this._client._call<T.TemplateList>(listTemplatesOp, {}, options);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get a template
|
|
346
|
+
*
|
|
347
|
+
* Returns one template by name (`base`) or ID (`tpl_…`).
|
|
348
|
+
*
|
|
349
|
+
* `GET /v1/sandboxes/templates/{template}` · scope `sandboxes:read` · served by the node
|
|
350
|
+
*/
|
|
351
|
+
getTemplate(template: string, options?: RequestOptions): APIPromise<T.Template> {
|
|
352
|
+
return this._client._call<T.Template>(getTemplateOp, { path: [template] }, options);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Delete a sandbox
|
|
357
|
+
*
|
|
358
|
+
* Stops the sandbox and destroys its memory and disk. Snapshots taken from it are kept. Returns the stopped sandbox with its final usage.
|
|
359
|
+
*
|
|
360
|
+
* `DELETE /v1/sandboxes/{sandbox_id}` · scope `sandboxes:write` · served by the node
|
|
361
|
+
*/
|
|
362
|
+
deleteSandbox(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
363
|
+
return this._client._call<T.Sandbox>(deleteSandboxOp, { path: [sandboxId] }, options);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Get a sandbox
|
|
368
|
+
*
|
|
369
|
+
* Returns the sandbox with its status, expiry, ports and usage so far.
|
|
370
|
+
*
|
|
371
|
+
* `GET /v1/sandboxes/{sandbox_id}` · scope `sandboxes:read` · served by the node
|
|
372
|
+
*/
|
|
373
|
+
getSandbox(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
374
|
+
return this._client._call<T.Sandbox>(getSandboxOp, { path: [sandboxId] }, options);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Run a command
|
|
379
|
+
*
|
|
380
|
+
* Runs a command in the sandbox. By default the response waits for it to exit (at most `timeout_ms`, up to 60
|
|
381
|
+
* seconds) and returns its exit code and output. With `?stream=true` (or `Accept: text/event-stream`) output
|
|
382
|
+
* arrives as `exec.stdout` and `exec.stderr` events while it runs, ending with `exec.exit`; streamed commands
|
|
383
|
+
* may run up to an hour. With `background: true` the response returns at once with the process, whose output
|
|
384
|
+
* you read from `GET /v1/sandboxes/{sandbox_id}/logs`.
|
|
385
|
+
*
|
|
386
|
+
* `cmd` as a string runs through `/bin/sh -c`; as an array it is executed directly. Output is UTF-8 (invalid
|
|
387
|
+
* bytes become U+FFFD) and each stream is capped at 1 MiB in a buffered response.
|
|
388
|
+
*
|
|
389
|
+
* `POST /v1/sandboxes/{sandbox_id}/exec` · scope `sandboxes:run` · served by the node
|
|
390
|
+
*/
|
|
391
|
+
exec(
|
|
392
|
+
sandboxId: string,
|
|
393
|
+
body: T.ExecRequest & { background: true },
|
|
394
|
+
options?: RequestOptions,
|
|
395
|
+
): APIPromise<T.SandboxProcess>;
|
|
396
|
+
exec(sandboxId: string, body: T.ExecRequest, options: StreamOptions & { stream: true }): EventStream<T.ExecEvent>;
|
|
397
|
+
exec(sandboxId: string, body: T.ExecRequest, options?: RequestOptions & { stream?: false }): APIPromise<T.ExecResult>;
|
|
398
|
+
exec(
|
|
399
|
+
sandboxId: string,
|
|
400
|
+
body: T.ExecRequest,
|
|
401
|
+
options: StreamOptions & { stream?: boolean } = {},
|
|
402
|
+
): APIPromise<T.ExecResult | T.SandboxProcess> | EventStream<T.ExecEvent> {
|
|
403
|
+
if (options.stream) {
|
|
404
|
+
return this._client._postStream<T.ExecEvent>(execOp, { path: [sandboxId], body }, options, {
|
|
405
|
+
terminal: (e) => e.type === "exec.exit",
|
|
406
|
+
extraQuery: { stream: "true" },
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return this._client._call<T.ExecResult | T.SandboxProcess>(execOp, { path: [sandboxId], body }, options);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Read a file or list a directory
|
|
414
|
+
*
|
|
415
|
+
* Returns the file at `path` as bytes. With `list=1` returns the directory's entries (or the single entry
|
|
416
|
+
* when `path` is a file) as JSON instead. Transfers are capped at 64 MiB.
|
|
417
|
+
*
|
|
418
|
+
* `GET /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
|
|
419
|
+
*/
|
|
420
|
+
readFile(
|
|
421
|
+
sandboxId: string,
|
|
422
|
+
params: T.SandboxesReadFileParams & { list: 1 },
|
|
423
|
+
options?: RequestOptions,
|
|
424
|
+
): APIPromise<T.FileEntryList>;
|
|
425
|
+
readFile(
|
|
426
|
+
sandboxId: string,
|
|
427
|
+
params: T.SandboxesReadFileParams & { list?: 0 },
|
|
428
|
+
options?: RequestOptions,
|
|
429
|
+
): APIPromise<Uint8Array>;
|
|
430
|
+
readFile(
|
|
431
|
+
sandboxId: string,
|
|
432
|
+
params: T.SandboxesReadFileParams,
|
|
433
|
+
options?: RequestOptions,
|
|
434
|
+
): APIPromise<Uint8Array | T.FileEntryList> {
|
|
435
|
+
return params.list === 1
|
|
436
|
+
? this._client._call<T.FileEntryList>(
|
|
437
|
+
readFileOp,
|
|
438
|
+
{ path: [sandboxId], query: params },
|
|
439
|
+
options,
|
|
440
|
+
"application/json",
|
|
441
|
+
"json",
|
|
442
|
+
)
|
|
443
|
+
: this._client._call<Uint8Array>(
|
|
444
|
+
readFileOp,
|
|
445
|
+
{ path: [sandboxId], query: params },
|
|
446
|
+
options,
|
|
447
|
+
"application/octet-stream",
|
|
448
|
+
"bytes",
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Write a file
|
|
454
|
+
*
|
|
455
|
+
* Writes the request body to `path`, replacing any existing file, creating parent directories with `mkdir=1`.
|
|
456
|
+
* Returns the file's entry. Up to 64 MiB per request.
|
|
457
|
+
*
|
|
458
|
+
* `PUT /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
|
|
459
|
+
*/
|
|
460
|
+
writeFile(
|
|
461
|
+
sandboxId: string,
|
|
462
|
+
params: T.SandboxesWriteFileParams,
|
|
463
|
+
data: BinaryInput,
|
|
464
|
+
options?: RequestOptions,
|
|
465
|
+
): APIPromise<T.FileEntry> {
|
|
466
|
+
return this._client._call<T.FileEntry>(writeFileOp, { path: [sandboxId], query: params, body: data }, options);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Fork a sandbox
|
|
471
|
+
*
|
|
472
|
+
* Creates `count` new running sandboxes that share the source's memory and disk copy-on-write, each with a fresh
|
|
473
|
+
* identity (its own id, entropy, machine ID and clock; the source's environment, secrets, files and running
|
|
474
|
+
* processes carry over). The source must have been created with `forkable: true` (forkable sandboxes are
|
|
475
|
+
* restored for themselves rather than claimed from a pool, and track the pages they change); forks are
|
|
476
|
+
* forkable too. The source pauses while its changed memory is written (`pause`, `base`, `snapshot`, `export`
|
|
477
|
+
* phases in `Server-Timing`), then runs on; like a snapshot this resets its open connections to the outside.
|
|
478
|
+
* Each fork counts against your sandbox concurrency.
|
|
479
|
+
*
|
|
480
|
+
* `POST /v1/sandboxes/{sandbox_id}/fork` · scope `sandboxes:write` · served by the node
|
|
481
|
+
*
|
|
482
|
+
* Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
|
|
483
|
+
*/
|
|
484
|
+
forkSandbox(sandboxId: string, body?: T.ForkRequest, options?: RequestOptions): APIPromise<T.SandboxList> {
|
|
485
|
+
return this._client._call<T.SandboxList>(forkSandboxOp, { path: [sandboxId], body }, options);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Stream process logs
|
|
490
|
+
*
|
|
491
|
+
* Server-sent events with the output of background processes: `log.stdout` and `log.stderr` per chunk and
|
|
492
|
+
* `process.exited` when one ends. Starts with up to 1 MiB of buffered output per process, then follows new
|
|
493
|
+
* output until the sandbox stops (or immediately ends with `follow=false`). Filter to one process with `pid`.
|
|
494
|
+
* Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`
|
|
495
|
+
* (`?ticket=`, for `EventSource`).
|
|
496
|
+
*
|
|
497
|
+
* `GET /v1/sandboxes/{sandbox_id}/logs` · scope `sandboxes:run` · served by the node
|
|
498
|
+
*/
|
|
499
|
+
streamLogs(
|
|
500
|
+
sandboxId: string,
|
|
501
|
+
params?: T.SandboxesStreamLogsParams,
|
|
502
|
+
options?: StreamOptions,
|
|
503
|
+
): EventStream<T.LogEvent> {
|
|
504
|
+
return this._client._stream<T.LogEvent>(streamLogsOp, { path: [sandboxId], query: params }, options, {
|
|
505
|
+
// With a pid filter the stream is over once that process exited.
|
|
506
|
+
terminal: params?.pid !== undefined ? (e) => e.type === "process.exited" : undefined,
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Pause a sandbox
|
|
512
|
+
*
|
|
513
|
+
* Freezes the sandbox's vCPUs and keeps its memory and disk on the node. A paused sandbox bills no CPU time
|
|
514
|
+
* and still counts allocated memory; it still expires at `expires_at`. Resume continues exactly where it
|
|
515
|
+
* stopped. Pausing a paused sandbox returns it unchanged.
|
|
516
|
+
*
|
|
517
|
+
* `POST /v1/sandboxes/{sandbox_id}/pause` · scope `sandboxes:write` · served by the node
|
|
518
|
+
*/
|
|
519
|
+
pauseSandbox(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
520
|
+
return this._client._call<T.Sandbox>(pauseSandboxOp, { path: [sandboxId] }, options);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Get a URL for a port
|
|
525
|
+
*
|
|
526
|
+
* Returns a URL that reaches `port` inside the sandbox:
|
|
527
|
+
* `https://usercontent.b3os.org/sbx/<host_id>/<port>/<token>/`. The token in the path is signed by the node and
|
|
528
|
+
* expires after `ttl_s` (10 minutes by default, at most 24 hours); anyone with the URL reaches the port until
|
|
529
|
+
* then, with no cookie or other credential. For a public port the response is the sandbox's long-lived URL
|
|
530
|
+
* (`ports[].url`) and `ttl_s` is ignored. The port must be declared in `ports` when the sandbox is created. The
|
|
531
|
+
* app sees the URL's base path in `X-Forwarded-Prefix` on every request (token format and forwarding:
|
|
532
|
+
* `sandboxesProxyPortGet`).
|
|
533
|
+
*
|
|
534
|
+
* `POST /v1/sandboxes/{sandbox_id}/ports/{port}/url` · scope `sandboxes:run` · served by the node
|
|
535
|
+
*/
|
|
536
|
+
createPortUrl(
|
|
537
|
+
sandboxId: string,
|
|
538
|
+
port: number,
|
|
539
|
+
body?: T.PortUrlRequest,
|
|
540
|
+
options?: RequestOptions,
|
|
541
|
+
): APIPromise<T.PortUrl> {
|
|
542
|
+
return this._client._call<T.PortUrl>(createPortUrlOp, { path: [sandboxId, port], body }, options);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* List background processes
|
|
547
|
+
*
|
|
548
|
+
* Lists processes started with `background: true`, running or exited, newest first.
|
|
549
|
+
*
|
|
550
|
+
* `GET /v1/sandboxes/{sandbox_id}/processes` · scope `sandboxes:run` · served by the node
|
|
551
|
+
*/
|
|
552
|
+
listProcesses(sandboxId: string, options?: RequestOptions): APIPromise<T.SandboxProcessList> {
|
|
553
|
+
return this._client._call<T.SandboxProcessList>(listProcessesOp, { path: [sandboxId] }, options);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Signal a background process
|
|
558
|
+
*
|
|
559
|
+
* Sends a signal (default `TERM`) to a background process and its process group, and returns the process.
|
|
560
|
+
*
|
|
561
|
+
* `POST /v1/sandboxes/{sandbox_id}/processes/{pid}/kill` · scope `sandboxes:run` · served by the node
|
|
562
|
+
*/
|
|
563
|
+
killProcess(
|
|
564
|
+
sandboxId: string,
|
|
565
|
+
pid: number,
|
|
566
|
+
body?: T.KillRequest,
|
|
567
|
+
options?: RequestOptions,
|
|
568
|
+
): APIPromise<T.SandboxProcess> {
|
|
569
|
+
return this._client._call<T.SandboxProcess>(killProcessOp, { path: [sandboxId, pid], body }, options);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Open a terminal
|
|
574
|
+
*
|
|
575
|
+
* Opens a WebSocket attached to a new pseudo-terminal running the user's login shell (or `cmd`). Binary frames
|
|
576
|
+
* carry terminal bytes in both directions. Text frames carry JSON control messages: send
|
|
577
|
+
* `{"type": "resize", "cols": 120, "rows": 40}`; the server sends `{"type": "exit", "code": 0}` before it closes.
|
|
578
|
+
* Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`.
|
|
579
|
+
*
|
|
580
|
+
* `GET /v1/sandboxes/{sandbox_id}/pty` · scope `sandboxes:run` · served by the node
|
|
581
|
+
*/
|
|
582
|
+
async openPty(
|
|
583
|
+
sandboxId: string,
|
|
584
|
+
params?: T.SandboxesOpenPtyParams,
|
|
585
|
+
options: RequestOptions = {},
|
|
586
|
+
): Promise<PtySession> {
|
|
587
|
+
const { url, protocols } = await ticketedUrl(
|
|
588
|
+
this._client,
|
|
589
|
+
openPtyOp,
|
|
590
|
+
createTicketOp,
|
|
591
|
+
{ path: [sandboxId], query: params },
|
|
592
|
+
options,
|
|
593
|
+
false,
|
|
594
|
+
);
|
|
595
|
+
return new PtySession(await openSocket(url, protocols, options.signal));
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Resume a sandbox
|
|
600
|
+
*
|
|
601
|
+
* Resumes a paused sandbox. Processes continue where they were, and the guest clock is corrected. Resuming a
|
|
602
|
+
* running sandbox returns it unchanged. A resumed sandbox is billed again (`sandboxes.gib_ms`), so a resume is
|
|
603
|
+
* admitted like a create (credits, spend cap).
|
|
604
|
+
*
|
|
605
|
+
* `POST /v1/sandboxes/{sandbox_id}/resume` · scope `sandboxes:write` · served by the node
|
|
606
|
+
*/
|
|
607
|
+
resumeSandbox(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
608
|
+
return this._client._call<T.Sandbox>(resumeSandboxOp, { path: [sandboxId] }, options);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Run code in a kernel
|
|
613
|
+
*
|
|
614
|
+
* Runs code in the sandbox's Jupyter kernel and returns its rich results (text, images, HTML, JSON), output
|
|
615
|
+
* and any error. State persists between calls, like cells in a notebook. Needs a sandbox created from the
|
|
616
|
+
* `code-interpreter` template.
|
|
617
|
+
*
|
|
618
|
+
* `POST /v1/sandboxes/{sandbox_id}/run_code` · scope `sandboxes:run` · served by the node
|
|
619
|
+
*/
|
|
620
|
+
runCode(sandboxId: string, body: T.RunCodeRequest, options?: RequestOptions): APIPromise<T.RunCodeResult> {
|
|
621
|
+
return this._client._call<T.RunCodeResult>(runCodeOp, { path: [sandboxId], body }, options);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Snapshot a sandbox
|
|
626
|
+
*
|
|
627
|
+
* Saves the sandbox's memory and disk as a snapshot you can create new sandboxes from. The sandbox keeps
|
|
628
|
+
* running (it pauses for the copy). New sandboxes restored from a snapshot get a fresh identity, so two of them
|
|
629
|
+
* never share random state. Writing the snapshot resets the sandbox's open connections to the outside (open
|
|
630
|
+
* PTY sessions, streaming execs and log streams, port preview connections, outbound TCP connections); new
|
|
631
|
+
* ones work as soon as the call returns.
|
|
632
|
+
*
|
|
633
|
+
* Snapshots are kept 7 days. An organization keeps at most `sandboxes.snapshots_max` snapshots (beta: 20)
|
|
634
|
+
* per node, counting at most `sandboxes.snapshot_storage_max` (beta: 40 GiB). Each snapshot counts its
|
|
635
|
+
* sandbox's memory plus its disk size: the memory is stored whole, and the disk copy comes to hold every
|
|
636
|
+
* block the sandbox rewrites after the snapshot. Past either limit the snapshot is refused with
|
|
637
|
+
* `422 limit_exceeded` until you delete some. While the node's snapshot store is nearly full, snapshots and
|
|
638
|
+
* forks are refused with `503 capacity_unavailable`.
|
|
639
|
+
*
|
|
640
|
+
* `POST /v1/sandboxes/{sandbox_id}/snapshot` · scope `sandboxes:write` · served by the node
|
|
641
|
+
*/
|
|
642
|
+
createSnapshot(sandboxId: string, body?: T.SnapshotCreateRequest, options?: RequestOptions): APIPromise<T.Snapshot> {
|
|
643
|
+
return this._client._call<T.Snapshot>(createSnapshotOp, { path: [sandboxId], body }, options);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Create a stream ticket
|
|
648
|
+
*
|
|
649
|
+
* Returns a single-use ticket, valid for 30 seconds, that opens one stream under this sandbox (the terminal
|
|
650
|
+
* WebSocket or the logs event stream) without a bearer header. Pass it as `?ticket=` or in
|
|
651
|
+
* `Sec-WebSocket-Protocol: b3os.v1, b3os.ticket.<ticket>`. The stream runs with this caller's scopes.
|
|
652
|
+
*
|
|
653
|
+
* `POST /v1/sandboxes/{sandbox_id}/ticket` · scope `sandboxes:read` · served by the node
|
|
654
|
+
*/
|
|
655
|
+
createTicket(sandboxId: string, options?: RequestOptions): APIPromise<T.StreamTicket> {
|
|
656
|
+
return this._client._call<T.StreamTicket>(createTicketOp, { path: [sandboxId] }, options);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Extend a sandbox's timeout
|
|
661
|
+
*
|
|
662
|
+
* Sets the sandbox to expire `timeout_s` seconds from now (up to your plan's maximum lifetime). Works on running
|
|
663
|
+
* and paused sandboxes. A longer life is billed (`sandboxes.vcpu_ms`, `sandboxes.gib_ms`), so the call is
|
|
664
|
+
* admitted like a create (credits, spend cap).
|
|
665
|
+
*
|
|
666
|
+
* `POST /v1/sandboxes/{sandbox_id}/timeout` · scope `sandboxes:write` · served by the node
|
|
667
|
+
*/
|
|
668
|
+
setTimeout(sandboxId: string, body: T.TimeoutRequest, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
669
|
+
return this._client._call<T.Sandbox>(setTimeoutOp, { path: [sandboxId], body }, options);
|
|
670
|
+
}
|
|
671
|
+
}
|