@b3os/sdk 0.2.2 → 0.2.4

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.
Files changed (87) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/core/util.d.ts +1 -1
  3. package/dist/cjs/core/util.js +1 -1
  4. package/dist/cjs/generated/client.d.ts +5 -0
  5. package/dist/cjs/generated/client.js +9 -0
  6. package/dist/cjs/generated/client.js.map +1 -1
  7. package/dist/cjs/generated/errors.d.ts +1 -1
  8. package/dist/cjs/generated/errors.js +45 -0
  9. package/dist/cjs/generated/errors.js.map +1 -1
  10. package/dist/cjs/generated/ids.d.ts +28 -0
  11. package/dist/cjs/generated/ids.js +7 -0
  12. package/dist/cjs/generated/ids.js.map +1 -1
  13. package/dist/cjs/generated/ns/agents.d.ts +449 -11
  14. package/dist/cjs/generated/ns/agents.js +609 -11
  15. package/dist/cjs/generated/ns/agents.js.map +1 -1
  16. package/dist/cjs/generated/ns/images.d.ts +84 -3
  17. package/dist/cjs/generated/ns/images.js +126 -2
  18. package/dist/cjs/generated/ns/images.js.map +1 -1
  19. package/dist/cjs/generated/ns/keys.d.ts +12 -4
  20. package/dist/cjs/generated/ns/keys.js +12 -4
  21. package/dist/cjs/generated/ns/keys.js.map +1 -1
  22. package/dist/cjs/generated/ns/listeners.d.ts +6 -2
  23. package/dist/cjs/generated/ns/listeners.js +6 -2
  24. package/dist/cjs/generated/ns/listeners.js.map +1 -1
  25. package/dist/cjs/generated/ns/routines.d.ts +11 -0
  26. package/dist/cjs/generated/ns/routines.js +11 -0
  27. package/dist/cjs/generated/ns/routines.js.map +1 -1
  28. package/dist/cjs/generated/ns/sandboxes.d.ts +140 -1
  29. package/dist/cjs/generated/ns/sandboxes.js +190 -1
  30. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  31. package/dist/cjs/generated/ns/vision.d.ts +55 -1
  32. package/dist/cjs/generated/ns/vision.js +94 -1
  33. package/dist/cjs/generated/ns/vision.js.map +1 -1
  34. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  35. package/dist/cjs/generated/ns/workspaces.js +410 -0
  36. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  37. package/dist/cjs/generated/types.d.ts +2312 -90
  38. package/dist/esm/core/util.d.ts +1 -1
  39. package/dist/esm/core/util.js +1 -1
  40. package/dist/esm/generated/client.d.ts +5 -0
  41. package/dist/esm/generated/client.js +9 -0
  42. package/dist/esm/generated/client.js.map +1 -1
  43. package/dist/esm/generated/errors.d.ts +1 -1
  44. package/dist/esm/generated/errors.js +45 -0
  45. package/dist/esm/generated/errors.js.map +1 -1
  46. package/dist/esm/generated/ids.d.ts +28 -0
  47. package/dist/esm/generated/ids.js +7 -0
  48. package/dist/esm/generated/ids.js.map +1 -1
  49. package/dist/esm/generated/ns/agents.d.ts +449 -11
  50. package/dist/esm/generated/ns/agents.js +609 -11
  51. package/dist/esm/generated/ns/agents.js.map +1 -1
  52. package/dist/esm/generated/ns/images.d.ts +84 -3
  53. package/dist/esm/generated/ns/images.js +126 -2
  54. package/dist/esm/generated/ns/images.js.map +1 -1
  55. package/dist/esm/generated/ns/keys.d.ts +12 -4
  56. package/dist/esm/generated/ns/keys.js +12 -4
  57. package/dist/esm/generated/ns/keys.js.map +1 -1
  58. package/dist/esm/generated/ns/listeners.d.ts +6 -2
  59. package/dist/esm/generated/ns/listeners.js +6 -2
  60. package/dist/esm/generated/ns/listeners.js.map +1 -1
  61. package/dist/esm/generated/ns/routines.d.ts +11 -0
  62. package/dist/esm/generated/ns/routines.js +11 -0
  63. package/dist/esm/generated/ns/routines.js.map +1 -1
  64. package/dist/esm/generated/ns/sandboxes.d.ts +140 -1
  65. package/dist/esm/generated/ns/sandboxes.js +190 -1
  66. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  67. package/dist/esm/generated/ns/vision.d.ts +55 -1
  68. package/dist/esm/generated/ns/vision.js +94 -1
  69. package/dist/esm/generated/ns/vision.js.map +1 -1
  70. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  71. package/dist/esm/generated/ns/workspaces.js +406 -0
  72. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  73. package/dist/esm/generated/types.d.ts +2312 -90
  74. package/package.json +1 -1
  75. package/src/core/util.ts +1 -1
  76. package/src/generated/client.ts +10 -0
  77. package/src/generated/errors.ts +90 -0
  78. package/src/generated/ids.ts +7 -0
  79. package/src/generated/ns/agents.ts +663 -11
  80. package/src/generated/ns/images.ts +131 -3
  81. package/src/generated/ns/keys.ts +12 -4
  82. package/src/generated/ns/listeners.ts +6 -2
  83. package/src/generated/ns/routines.ts +11 -0
  84. package/src/generated/ns/sandboxes.ts +203 -1
  85. package/src/generated/ns/vision.ts +101 -1
  86. package/src/generated/ns/workspaces.ts +448 -0
  87. package/src/generated/types.ts +2488 -55
@@ -1,6 +1,6 @@
1
1
  // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
2
 
3
- import type { RequestOptions } from "../../core/client.ts";
3
+ import type { BinaryInput, RequestOptions } from "../../core/client.ts";
4
4
  import { Namespace } from "../../core/namespace.ts";
5
5
  import type { Op } from "../../core/op.ts";
6
6
  import type { APIPromise } from "../../core/promise.ts";
@@ -21,6 +21,24 @@ const importImageOp: Op = {
21
21
  timeoutMs: 30000,
22
22
  scope: "sandboxes:write",
23
23
  };
24
+ const getContextOp: Op = {
25
+ id: "imagesGetContext",
26
+ method: "GET",
27
+ path: "/v1/images/contexts/{sha256}",
28
+ params: ["sha256"],
29
+ timeoutMs: 10000,
30
+ scope: "sandboxes:read",
31
+ };
32
+ const putContextOp: Op = {
33
+ id: "imagesPutContext",
34
+ method: "PUT",
35
+ path: "/v1/images/contexts/{sha256}",
36
+ params: ["sha256"],
37
+ body: "bytes",
38
+ contentType: "application/octet-stream",
39
+ timeoutMs: 60000,
40
+ scope: "sandboxes:write",
41
+ };
24
42
  const deleteImageOp: Op = {
25
43
  id: "imagesDeleteImage",
26
44
  method: "DELETE",
@@ -37,13 +55,34 @@ const getImageOp: Op = {
37
55
  timeoutMs: 35000,
38
56
  scope: "sandboxes:read",
39
57
  };
58
+ const getImageLogsOp: Op = {
59
+ id: "imagesGetImageLogs",
60
+ method: "GET",
61
+ path: "/v1/images/{image_id}/logs",
62
+ params: ["image_id"],
63
+ timeoutMs: 35000,
64
+ scope: "sandboxes:read",
65
+ };
66
+ const releaseImageOp: Op = {
67
+ id: "imagesReleaseImage",
68
+ method: "POST",
69
+ path: "/v1/images/{image_id}/release",
70
+ params: ["image_id"],
71
+ body: "json",
72
+ timeoutMs: 30000,
73
+ scope: "sandboxes:write",
74
+ };
40
75
 
41
76
  /** Descriptors of every images operation, keyed by method name (for tooling and custom clients). */
42
77
  export const imagesOps = {
43
78
  listImages: listImagesOp,
44
79
  importImage: importImageOp,
80
+ getContext: getContextOp,
81
+ putContext: putContextOp,
45
82
  deleteImage: deleteImageOp,
46
83
  getImage: getImageOp,
84
+ getImageLogs: getImageLogsOp,
85
+ releaseImage: releaseImageOp,
47
86
  } as const;
48
87
 
49
88
  /** Public OCI images imported as templates for your project's sandboxes (`/v1/images`). */
@@ -63,7 +102,9 @@ export class ImagesAPI extends Namespace {
63
102
  /**
64
103
  * Import an image
65
104
  *
66
- * Imports a public OCI image as a template for this project's sandboxes. The reference is resolved before the
105
+ * Imports a public OCI image, or builds one from a Dockerfile (`build`, with the `images.build` flag), as a
106
+ * template for this project's sandboxes. A build skips the resolve: it is queued, then `building` in a microVM
107
+ * of its own, and from the unpacking on it goes as an import does. The reference is resolved before the
67
108
  * answer (a tag to its digest with one manifest `HEAD`), so the answer names the exact image: `202` with a new
68
109
  * image (`status: queued`), or `200` with the project's existing image when one with the same key exists,
69
110
  * ready or still importing. The key covers the project, the image's digest, the warm-up, the size and the
@@ -84,7 +125,13 @@ export class ImagesAPI extends Namespace {
84
125
  * only; the kernel's random pool is reseeded for each.
85
126
  *
86
127
  * `size` (`vcpu`, `memory_mib`) is fixed at import: every sandbox from the image has it, and a create that asks
87
- * for another size answers `400 invalid_request`. Without the flag on for your organization the answer is
128
+ * for another size answers `400 invalid_request`.
129
+ *
130
+ * A private image (`images.build`) names a registry connection in `auth` (see `ImageRegistryAuth`); using it
131
+ * also needs `vault:run`. A connection of another project, or one this credential may not use, answers `404
132
+ * connection_not_found`; one that is not a registry connection for the image's registry, `422
133
+ * image_auth_invalid`; a credential the registry's token service refuses, `422 image_refused` with `reason:
134
+ * credentials`. While the flag is off, `auth` answers `400 invalid_request`. Without the flag on for your organization the answer is
88
135
  * `404 feature_not_enabled`; without an image store on the node, a full store or the node's disk under its
89
136
  * floor, `503 capacity_unavailable`.
90
137
  *
@@ -93,12 +140,60 @@ export class ImagesAPI extends Namespace {
93
140
  * replaces that file system, except while a running or paused sandbox, or a snapshot taken from one, uses the
94
141
  * image's template: then the answer is `409 image_in_use`.
95
142
  *
143
+ * `name` (with the `images.build` flag; without it the answer is `404 feature_not_enabled`) gives the image a
144
+ * name in this project, which a create resolves inside the project only: `POST /v1/sandboxes {"template":
145
+ * "py:3.11"}`. A name is unique among the project's images (`409 image_name_taken` while another image, of any
146
+ * status, has it; delete that one first) and is never a node template's (`422 image_name_reserved` for `base`,
147
+ * `base:v1` and the like). The name is part of the key: the same image under another name, or without one, is
148
+ * another image.
149
+ *
150
+ * `app` (with the `images.build` flag) asks for the image on behalf of an application, the `name` of its
151
+ * b3os.yaml: `b3os apply` sends it for `build.image` and `build.dockerfile`. The application then holds the
152
+ * image (`held_by`), new or existing: the same request from two applications is one image with two holds. An
153
+ * image asked for without `app`, even once, is `kept`: it stays until you delete it, as every image did before
154
+ * holds. An image that is not kept goes once no application holds it and no running, paused or hibernated
155
+ * sandbox and no snapshot uses its template. An application's hold ends when `b3os app down` releases it
156
+ * (`POST /v1/images/{image_id}/release`), or by itself once none of the application's sandboxes (running, or
157
+ * stopped and still listed, for 7 days) runs from the image and the application has not asked for it for
158
+ * `[images] hold_h` (7 days): a rollback can start every generation still listed from its image. When an
159
+ * import does not fit the node's image store, images that are not kept, that no sandbox or snapshot uses and
160
+ * that no application asked for in the last hour go first, least recently used first; a rollback to one of
161
+ * them imports it again by digest, or builds it again from its commit.
162
+ *
96
163
  * `POST /v1/images` · scope `sandboxes:write` · served by the node
97
164
  */
98
165
  importImage(body: T.ImageImportRequest, options?: RequestOptions): APIPromise<T.Image> {
99
166
  return this._client._call<T.Image>(importImageOp, { body }, options);
100
167
  }
101
168
 
169
+ /**
170
+ * Check a build context tar
171
+ *
172
+ * This project's tar with this sha256 and when it expires, or `404 image_context_not_found` when it was never uploaded or has expired. A client checks before it uploads.
173
+ *
174
+ * `GET /v1/images/contexts/{sha256}` · scope `sandboxes:read` · served by the node
175
+ */
176
+ getContext(sha256: string, options?: RequestOptions): APIPromise<T.ImageContext> {
177
+ return this._client._call<T.ImageContext>(getContextOp, { path: [sha256] }, options);
178
+ }
179
+
180
+ /**
181
+ * Upload a build context tar
182
+ *
183
+ * Stores the body, a tar (plain or gzip), as a build context of this project under its sha256, for
184
+ * `POST /v1/images {"build": {"context": [{"sha256": "…"}]}}`. The body's sha256 must be the one in the path
185
+ * (`400` otherwise). A tar is at most 100 MiB: split a larger context into more tars (they are unpacked in
186
+ * order, each at its `at`). It is kept 24 hours after its last upload or the last build that named it, and
187
+ * only this project can use it. Your organization's stored tars count against `images.contexts_bytes`
188
+ * (`422 limit_exceeded`). The node never unpacks a tar: only the build microVM does. Uploading the same tar
189
+ * again answers `200` and keeps it another 24 hours.
190
+ *
191
+ * `PUT /v1/images/contexts/{sha256}` · scope `sandboxes:write` · served by the node
192
+ */
193
+ putContext(sha256: string, data: BinaryInput, options?: RequestOptions): APIPromise<T.ImageContext> {
194
+ return this._client._call<T.ImageContext>(putContextOp, { path: [sha256], body: data }, options);
195
+ }
196
+
102
197
  /**
103
198
  * Delete an image
104
199
  *
@@ -125,4 +220,37 @@ export class ImagesAPI extends Namespace {
125
220
  getImage(imageId: string, params?: T.ImagesGetImageParams, options?: RequestOptions): APIPromise<T.Image> {
126
221
  return this._client._call<T.Image>(getImageOp, { path: [imageId], query: params }, options);
127
222
  }
223
+
224
+ /**
225
+ * Read an image's build log
226
+ *
227
+ * The build log of one of this project's images (a Dockerfile build's output, its last 1 MiB), as lines from
228
+ * `offset` (0 is the first), at most 1,000 per answer. `next_offset` is where the next read starts. The log is
229
+ * kept when the build microVM ends, so a build still running has no lines yet, and an import has none. With
230
+ * `wait` (seconds, at most 30) the answer is held until there are lines past `offset` or the image is `ready`,
231
+ * `failed` or `evicted`, whichever is first. To follow a build, read again from `next_offset` until `status`
232
+ * is one of those and no lines come.
233
+ *
234
+ * `GET /v1/images/{image_id}/logs` · scope `sandboxes:read` · served by the node
235
+ */
236
+ getImageLogs(imageId: string, params?: T.ImagesGetImageLogsParams, options?: RequestOptions): APIPromise<T.ImageLog> {
237
+ return this._client._call<T.ImageLog>(getImageLogsOp, { path: [imageId], query: params }, options);
238
+ }
239
+
240
+ /**
241
+ * Release an application's hold on an image
242
+ *
243
+ * Ends `app`'s hold on the image (`held_by`), as `b3os app down` does for each image the application holds. The
244
+ * image is then removed now, as `DELETE /v1/images/{image_id}` removes it, when it is not `kept`, no other
245
+ * application holds it and no running, paused or hibernated sandbox and no snapshot uses its template
246
+ * (`removed: true`). Otherwise it stays, and the answer says why: `held_by`, `kept` or `in_use`. An image that
247
+ * stays only because something uses it goes once nothing does. Releasing a hold the application does not have
248
+ * changes nothing. An import still in progress for another holder answers `409 conflict`; release it once it
249
+ * is ready or failed.
250
+ *
251
+ * `POST /v1/images/{image_id}/release` · scope `sandboxes:write` · served by the node
252
+ */
253
+ releaseImage(imageId: string, body: T.ImageReleaseRequest, options?: RequestOptions): APIPromise<T.ImageRelease> {
254
+ return this._client._call<T.ImageRelease>(releaseImageOp, { path: [imageId], body }, options);
255
+ }
128
256
  }
@@ -98,8 +98,15 @@ export class KeysAPI extends Namespace {
98
98
  * Create an API key
99
99
  *
100
100
  * Creates a key in your project (or `project`, in the same organization). `scopes` and `spend_cap_usd` may not
101
- * exceed the caller's own, and when the caller expires, `expires_at` must be set and no later than the caller's
102
- * expiry (`forbidden`, reason `scope_escalation`). The response is the only time `secret` is returned. An
101
+ * exceed the caller's own (`forbidden`, reason `scope_escalation`). The key's expiry is its own, whatever happens
102
+ * to the credential that made it later, and depends on that credential:
103
+ * - a CLI token (`b3os login`): `expires_at` defaults to 90 days from now and may be at most 365 days away, never
104
+ * `null`, so a key made from a 30-day login can outlive it;
105
+ * - an API key that expires: `expires_at` must be set and no later than that key's expiry;
106
+ * - a dashboard session or an API key that does not expire: any `expires_at`; left out or `null`, the key never
107
+ * expires.
108
+ *
109
+ * Past these, `forbidden`, reason `scope_escalation`. The response is the only time `secret` is returned. An
103
110
  * organization holds at most `platform.keys.max` active API keys (1,000 in the beta; revoked and expired ones are
104
111
  * not counted, nor CLI tokens); a create past it is 422 `limit_exceeded`.
105
112
  *
@@ -167,8 +174,9 @@ export class KeysAPI extends Namespace {
167
174
  * Update an API key
168
175
  *
169
176
  * Renames a key or changes its spend cap, expiry or metadata. Scopes cannot change; create a new key instead.
170
- * A caller with a spend cap or an expiry cannot set a larger cap or a later (or no) expiry than its own
171
- * (`forbidden`, reason `scope_escalation`).
177
+ * A caller with a spend cap cannot set a larger cap than its own. A CLI token may set an expiry up to 365 days
178
+ * from now, never `null`; an API key that expires cannot set a later (or no) expiry than its own (`forbidden`,
179
+ * reason `scope_escalation`).
172
180
  *
173
181
  * `PATCH /v1/keys/{key_id}` · scope `platform:write` · served by beta-api.b3os.org
174
182
  */
@@ -172,7 +172,10 @@ export class ListenersAPI extends Namespace {
172
172
  *
173
173
  * Closes the source and stops delivery at once; an event already handed to its sink is not recalled. The
174
174
  * event history stays readable for its 7 days through `GET /v1/listeners/{listener_id}/events` and is then
175
- * deleted.
175
+ * deleted. A routine's listener trigger's listener (`sink.trigger`) answers `409 listener_managed`: it goes
176
+ * when its routine publishes a version without the trigger, or is deleted. A listener a routine trigger names
177
+ * (`sink.bound`) is its owner's to delete; the trigger then starts nothing and the routine shows a
178
+ * `listener_not_found` warning.
176
179
  *
177
180
  * `DELETE /v1/listeners/{listener_id}` · scope `listeners:write` · served by the node
178
181
  */
@@ -201,7 +204,8 @@ export class ListenersAPI extends Namespace {
201
204
  * ends, or now if the PATCH raises the budget above what it used. The source cannot change: create a new
202
205
  * listener. A new filter or `redact` applies to events received after the answer. A listener that ended
203
206
  * (`failed`, `expired`, `revoked`) answers `409 listener_not_active`, except that a `failed` one can be
204
- * resumed with `paused: false`, which starts its source again.
207
+ * resumed with `paused: false`, which starts its source again. While a routine's trigger names the listener
208
+ * (`sink.bound`), a change of `sink` answers `409 listener_bound`; everything else can change.
205
209
  *
206
210
  * `PATCH /v1/listeners/{listener_id}` · scope `listeners:write` · served by the node
207
211
  */
@@ -499,6 +499,17 @@ export class RoutinesAPI extends Namespace {
499
499
  * fails with `routine_invalid` and an `errors[]` item at that trigger. A webhook trigger that names a vault
500
500
  * connection (`verify.secret`, `challenge.token_connection`) needs `vault:run` on top of `routines:write`
501
501
  * (403 `forbidden`, `required_scope: vault:run`), as a connection in a pack trigger does.
502
+ * Listener triggers (`type: listener`) are listeners: publishing creates one (`lsn_`, read-only at
503
+ * `GET /v1/listeners/{listener_id}`) per listener trigger as the publishing key, which needs `routines:run`;
504
+ * a trigger whose `listener` and publishing key are unchanged keeps its listener, and the listeners of
505
+ * listener triggers the new version drops or changes are removed. When the listeners product refuses one,
506
+ * the publish fails with `routine_invalid` and `errors[]` items under that trigger's `listener`; when this
507
+ * node runs no listeners product it fails with 503 `product_unavailable`, and nothing is published.
508
+ * A listener trigger whose `listener` is a string (preview, flag `routines.named_listeners`) names a listener
509
+ * that already exists in the project by id or name: the publishing key needs `listeners:read` (and
510
+ * `listeners:write` when the listener's sink points anywhere else), the listener is checked before anything is
511
+ * committed, and once the version is active its sink becomes this routine and trigger (`sink.bound`). A
512
+ * version without the trigger, or a delete, unbinds it and pauses it.
502
513
  *
503
514
  * `PUT /v1/routines/{routine}` · scope `routines:write` · served by the node
504
515
  */
@@ -48,6 +48,13 @@ const createSandboxOp: Op = {
48
48
  timeoutMs: 30000,
49
49
  scope: "sandboxes:write",
50
50
  };
51
+ const getCapacityOp: Op = {
52
+ id: "sandboxesGetCapacity",
53
+ method: "GET",
54
+ path: "/v1/sandboxes/capacity",
55
+ timeoutMs: 10000,
56
+ scope: "sandboxes:read",
57
+ };
51
58
  const listSnapshotsOp: Op = {
52
59
  id: "sandboxesListSnapshots",
53
60
  method: "GET",
@@ -118,6 +125,14 @@ const listTemplatesOp: Op = {
118
125
  timeoutMs: 10000,
119
126
  scope: "sandboxes:read",
120
127
  };
128
+ const createTemplateOp: Op = {
129
+ id: "sandboxesCreateTemplate",
130
+ method: "POST",
131
+ path: "/v1/sandboxes/templates",
132
+ body: "json",
133
+ timeoutMs: 30000,
134
+ scope: "sandboxes:write",
135
+ };
121
136
  const getTemplateOp: Op = {
122
137
  id: "sandboxesGetTemplate",
123
138
  method: "GET",
@@ -199,6 +214,31 @@ const getSandboxOp: Op = {
199
214
  timeoutMs: 10000,
200
215
  scope: "sandboxes:read",
201
216
  };
217
+ const getComputerOp: Op = {
218
+ id: "sandboxesGetComputer",
219
+ method: "GET",
220
+ path: "/v1/sandboxes/{sandbox_id}/computer",
221
+ params: ["sandbox_id"],
222
+ timeoutMs: 15000,
223
+ scope: "sandboxes:read",
224
+ };
225
+ const computerActOp: Op = {
226
+ id: "sandboxesComputerAct",
227
+ method: "POST",
228
+ path: "/v1/sandboxes/{sandbox_id}/computer/actions",
229
+ params: ["sandbox_id"],
230
+ body: "json",
231
+ timeoutMs: 65000,
232
+ scope: "sandboxes:run",
233
+ };
234
+ const computerScreenshotOp: Op = {
235
+ id: "sandboxesComputerScreenshot",
236
+ method: "GET",
237
+ path: "/v1/sandboxes/{sandbox_id}/computer/screenshot",
238
+ params: ["sandbox_id"],
239
+ timeoutMs: 15000,
240
+ scope: "sandboxes:read",
241
+ };
202
242
  const setEgressOp: Op = {
203
243
  id: "sandboxesSetEgress",
204
244
  method: "POST",
@@ -449,6 +489,7 @@ const createSwarmOp: Op = {
449
489
  export const sandboxesOps = {
450
490
  listSandboxes: listSandboxesOp,
451
491
  createSandbox: createSandboxOp,
492
+ getCapacity: getCapacityOp,
452
493
  listSnapshots: listSnapshotsOp,
453
494
  deleteSnapshot: deleteSnapshotOp,
454
495
  getSnapshot: getSnapshotOp,
@@ -459,6 +500,7 @@ export const sandboxesOps = {
459
500
  listSwarmChildren: listSwarmChildrenOp,
460
501
  swarmEvents: swarmEventsOp,
461
502
  listTemplates: listTemplatesOp,
503
+ createTemplate: createTemplateOp,
462
504
  getTemplate: getTemplateOp,
463
505
  listVolumes: listVolumesOp,
464
506
  createVolume: createVolumeOp,
@@ -469,6 +511,9 @@ export const sandboxesOps = {
469
511
  restoreVolume: restoreVolumeOp,
470
512
  deleteSandbox: deleteSandboxOp,
471
513
  getSandbox: getSandboxOp,
514
+ getComputer: getComputerOp,
515
+ computerAct: computerActOp,
516
+ computerScreenshot: computerScreenshotOp,
472
517
  setEgress: setEgressOp,
473
518
  exec: execOp,
474
519
  deleteFile: deleteFileOp,
@@ -610,6 +655,12 @@ export class SandboxesAPI extends Namespace {
610
655
  * create the concurrency limit allows); past it a create is refused with `422 limit_exceeded`. While the
611
656
  * node's disk store is nearly full, creates are refused with `503 capacity_unavailable` and `Retry-After`.
612
657
  *
658
+ * Desktops: a sandbox of a template with the `computer` capability (`desktop`) also counts against
659
+ * `sandboxes.desktops_concurrent`, its running and paused sandboxes of such templates (forks included); past it
660
+ * a create or fork is refused with `429 concurrency_limited` and `Retry-After`, as past `sandboxes.concurrent`.
661
+ * Its environment has `DISPLAY=:1` (the desktop's X server) unless `env` sets `DISPLAY`, so commands reach the
662
+ * screen. `GET /v1/sandboxes/capacity` says how many more would be created now.
663
+ *
613
664
  * Returns the sandbox object (`SandboxInfo`). `create()` sends the same request and returns a `Sandbox`
614
665
  * handle instead (`exec`, `files`, `ports`), which `await using` deletes when the scope ends.
615
666
  *
@@ -624,6 +675,36 @@ export class SandboxesAPI extends Namespace {
624
675
  );
625
676
  }
626
677
 
678
+ /**
679
+ * Check room for more sandboxes
680
+ *
681
+ * How many more sandboxes of one template and size your organization could create on this node now, and
682
+ * which limit refuses the next one. Call it before a wave of creates instead of meeting `429` or `503`
683
+ * answers. The default shape is the `desktop` template at its default size; name another with `template`,
684
+ * `vcpu` and `memory_mib`.
685
+ *
686
+ * `room` is the least of three counts. `org` is `sandboxes.concurrent`: your running and paused sandboxes
687
+ * (and creates in flight) against the limit; paused sandboxes count, so delete the ones you are done with
688
+ * rather than leave them paused. `desktops` is `sandboxes.desktops_concurrent`, the running and paused
689
+ * sandboxes of templates with the `computer` capability; it counts toward `room` only when the template has
690
+ * that capability. `node` is this node: `parked` is how many sandboxes of the shape wait warm in its pool
691
+ * (a create claims one without a restore), and `room` is how many sandboxes of the shape the memory left
692
+ * under the node's microVM memory limit holds, each counting its `memory_mib` plus the node's per-microVM
693
+ * overhead, or `0` while the node's disk store is too full for new sandboxes. `node.room` is `null` when the
694
+ * node cannot read that limit, and then it does not count toward `room`.
695
+ *
696
+ * `binding` names the limit that refuses the next create (`org_concurrency`, `desktops` or `node`) when
697
+ * `room` is `0`, with `retry_after_s`, and is `null` while a create would pass. The answer is a reading, not
698
+ * a reservation: another create can take the room first. `sandboxes.disk_total_max` is left out (its beta
699
+ * default never refuses a create the concurrency limit allows). Behind the `sandboxes.desktop` feature flag:
700
+ * until it is on for your organization the operation answers `404 feature_not_enabled`.
701
+ *
702
+ * `GET /v1/sandboxes/capacity` · scope `sandboxes:read` · served by the node
703
+ */
704
+ getCapacity(params?: T.SandboxesGetCapacityParams, options?: RequestOptions): APIPromise<T.SandboxCapacity> {
705
+ return this._client._call<T.SandboxCapacity>(getCapacityOp, { query: params }, options);
706
+ }
707
+
627
708
  /**
628
709
  * List snapshots
629
710
  *
@@ -792,10 +873,41 @@ export class SandboxesAPI extends Namespace {
792
873
  return this._client._call<T.TemplateList>(listTemplatesOp, {}, options);
793
874
  }
794
875
 
876
+ /**
877
+ * Create a template
878
+ *
879
+ * Makes a template for this project's sandboxes from a public OCI image (`image`, a reference) or from a
880
+ * Dockerfile build (`build`), with an optional `name` the project's creates start from:
881
+ * `POST /v1/sandboxes {"template": "py:3.11"}`. It takes the request `POST /v1/images` takes (with `image` in
882
+ * place of `ref`), and the template is that image's: one object, listed and deleted with `/v1/images`. The
883
+ * answer is the template's view: its `tpl_` ID (fixed from the start), `name`, `status` (the image's), `image`
884
+ * (the `img_` ID), `rootfs_sha256` once the image is flattened, and `key`. `202` for a new image, `200` for
885
+ * the project's image of the same request. Watch it with `GET /v1/images/{image_id}?wait=30` until `ready`;
886
+ * a create by name before then answers `409 image_not_ready`.
887
+ *
888
+ * A name is unique among the project's images (`409 image_name_taken`) and never a node template's
889
+ * (`422 image_name_reserved`). Another project's name answers `404 template_not_found`, as a template that
890
+ * does not exist. Behind the `images.build` flag (and `images.import`): until it is on for your organization
891
+ * the answer is `404 feature_not_enabled`. `503 product_unavailable` on a node without the images product.
892
+ *
893
+ * A private image names a registry connection in `auth`, as `POST /v1/images` does (`ImageRegistryAuth`): a
894
+ * vault connection of this project of type `basic` whose `hosts` list the registry and its token service.
895
+ * Using it also needs `vault:run` (`403` without it). Another project's connection, or one this credential may
896
+ * not use, answers `404 connection_not_found`; one that is not a registry connection for the image's registry,
897
+ * `422 image_auth_invalid`; a credential the registry refuses, `422 image_refused` with `reason: credentials`.
898
+ * The node reads the secret once, keeps it in memory for that one import and sends it only to the registry's
899
+ * token service: it is never logged, recorded or put in an error. A build takes no `auth`.
900
+ *
901
+ * `POST /v1/sandboxes/templates` · scope `sandboxes:write` · served by the node
902
+ */
903
+ createTemplate(body: T.TemplateCreateRequest, options?: RequestOptions): APIPromise<T.TemplateCreated> {
904
+ return this._client._call<T.TemplateCreated>(createTemplateOp, { body }, options);
905
+ }
906
+
795
907
  /**
796
908
  * Get a template
797
909
  *
798
- * Returns one template by name (`base`) or ID (`tpl_…`): a node template, or one of your project's image templates. Another project's image template answers `404 template_not_found`.
910
+ * Returns one template by name (`base`) or ID (`tpl_…`): a node template, or one of your project's image templates, by its ID or its image's `name`. Another project's image template answers `404 template_not_found`.
799
911
  *
800
912
  * `GET /v1/sandboxes/templates/{template}` · scope `sandboxes:read` · served by the node
801
913
  */
@@ -913,6 +1025,96 @@ export class SandboxesAPI extends Namespace {
913
1025
  return this._client._call<T.Sandbox>(getSandboxOp, { path: [sandboxId] }, options);
914
1026
  }
915
1027
 
1028
+ /**
1029
+ * Read a desktop's screen size and pointer
1030
+ *
1031
+ * The screen size and the pointer position of a sandbox made from a template with the `computer`
1032
+ * capability (`desktop`), and who controls its input. `controller` is always `agent` for now. A sandbox of
1033
+ * another template answers `409 computer_unavailable`.
1034
+ *
1035
+ * A paused sandbox is resumed first when your key also has `sandboxes:write` (the scope of
1036
+ * `POST /v1/sandboxes/{sandbox_id}/resume`); without it the answer is `409 sandbox_not_running`. A paused
1037
+ * sandbox past its `expires_at` is not resumed: extend it with `POST /v1/sandboxes/{sandbox_id}/timeout` first.
1038
+ * `503 desktop_unavailable` means the desktop's screen and input server in the sandbox did not answer; it is
1039
+ * restarted within a few seconds of stopping. Behind the `sandboxes.desktop` feature flag: until it is on for
1040
+ * your organization the operation answers `404 feature_not_enabled`.
1041
+ *
1042
+ * `GET /v1/sandboxes/{sandbox_id}/computer` · scope `sandboxes:read` · served by the node
1043
+ */
1044
+ getComputer(sandboxId: string, options?: RequestOptions): APIPromise<T.Computer> {
1045
+ return this._client._call<T.Computer>(getComputerOp, { path: [sandboxId] }, options);
1046
+ }
1047
+
1048
+ /**
1049
+ * Send mouse and keyboard actions to a desktop
1050
+ *
1051
+ * Runs 1 to 32 mouse and keyboard actions in order on a sandbox made from a template with the `computer`
1052
+ * capability (`desktop`), then optionally waits for the screen to settle and takes a screenshot, all in one
1053
+ * call. Action names follow Anthropic's computer-use actions, so a harness maps them one to one. Coordinates
1054
+ * are screen pixels from the top left (`GET /v1/sandboxes/{sandbox_id}/computer` gives the screen size); an
1055
+ * action without `x` and `y` acts at the pointer. `type` types up to 8,192 bytes of UTF-8 text (newline and
1056
+ * tab included, other control characters refused); `key` presses a chord of xdotool key names
1057
+ * (`ctrl+shift+t`, `Return`, `alt+F4`); `key_down` and `key_up` hold and release one key; `wait` waits; the
1058
+ * waits of one call add up to at most 30,000 ms.
1059
+ *
1060
+ * The whole batch is checked before any input is sent: a bad action answers `400 invalid_request` naming it
1061
+ * (`actions[2]`), and nothing ran. Then each action gets a result in `results`, in order: `delivery` says
1062
+ * whether its input reached the X server (`delivered_unverified`: sent and synced; what the application did
1063
+ * with it is not checked) and `retry` whether sending it again is safe (`unsafe` once a click, text or a key
1064
+ * landed). An action that fails stops the batch; the actions after it are `not_delivered` with `retry:
1065
+ * safe`. Held buttons and keys are released when a batch fails part way.
1066
+ *
1067
+ * `screenshot` adds a screenshot after the actions (`{format, quality}`, the same as the screenshot
1068
+ * operation's query; `null` or left out: none). `settle` waits before the screenshot until the screen has
1069
+ * not changed for `quiet_ms` (80 by default), at most `max_ms` (1,000 by default); `settled_by` says which
1070
+ * ended the wait. `cursor` is where the pointer ended, `null` when the desktop's X server went away during
1071
+ * the batch (then `screenshot` is `null` too). A failed screenshot after the actions also leaves `screenshot`
1072
+ * `null` with the results intact.
1073
+ *
1074
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1075
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1076
+ * another template answers `409 computer_unavailable`. A `503` or `504` after the batch was sent to the
1077
+ * sandbox says so in its detail: some actions may have run, so take a screenshot before you send them again.
1078
+ * The node logs each action's name, its coordinates and the batch's timing, never typed text (its length
1079
+ * only), keys or screenshots. Behind the `sandboxes.desktop` feature flag: until it is on for your
1080
+ * organization the operation answers `404 feature_not_enabled`.
1081
+ *
1082
+ * `POST /v1/sandboxes/{sandbox_id}/computer/actions` · scope `sandboxes:run` · served by the node
1083
+ */
1084
+ computerAct(
1085
+ sandboxId: string,
1086
+ body: T.ComputerActRequest,
1087
+ options?: RequestOptions,
1088
+ ): APIPromise<T.ComputerActResult> {
1089
+ return this._client._call<T.ComputerActResult>(computerActOp, { path: [sandboxId], body }, options);
1090
+ }
1091
+
1092
+ /**
1093
+ * Take a screenshot of a desktop
1094
+ *
1095
+ * Captures the whole screen of a sandbox made from a template with the `computer` capability (`desktop`).
1096
+ * With `Accept: image/png` or `image/jpeg` (or `image/*`, `*\/*`, or no `Accept`) the answer is the image
1097
+ * bytes; with `Accept: application/json` it is `{format, width, height, data_base64}`, the shape of a vision
1098
+ * screenshot. `format` is `jpeg` (at `quality`, 80 by default) unless the query or `Accept` asks for `png`;
1099
+ * `quality` applies to JPEG only. `Server-Timing` has `capture` and `encode` (the time inside the sandbox),
1100
+ * `desk` (the round trip to it) and `resume` when a paused sandbox was resumed first.
1101
+ *
1102
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1103
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1104
+ * another template answers `409 computer_unavailable`. Screenshots are never logged or stored by the node.
1105
+ * Behind the `sandboxes.desktop` feature flag: until it is on for your organization the operation answers
1106
+ * `404 feature_not_enabled`.
1107
+ *
1108
+ * `GET /v1/sandboxes/{sandbox_id}/computer/screenshot` · scope `sandboxes:read` · served by the node
1109
+ */
1110
+ computerScreenshot(
1111
+ sandboxId: string,
1112
+ params?: T.SandboxesComputerScreenshotParams,
1113
+ options?: RequestOptions,
1114
+ ): APIPromise<T.ScreenshotData> {
1115
+ return this._client._call<T.ScreenshotData>(computerScreenshotOp, { path: [sandboxId], query: params }, options);
1116
+ }
1117
+
916
1118
  /**
917
1119
  * Change a sandbox's egress policy
918
1120
  *