@b3os/sdk 0.2.1 → 0.2.3

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 (146) 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 +18 -0
  5. package/dist/cjs/generated/client.js +34 -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 +120 -0
  9. package/dist/cjs/generated/errors.js.map +1 -1
  10. package/dist/cjs/generated/ids.d.ts +89 -0
  11. package/dist/cjs/generated/ids.js +22 -0
  12. package/dist/cjs/generated/ids.js.map +1 -1
  13. package/dist/cjs/generated/jobs.js +4 -0
  14. package/dist/cjs/generated/jobs.js.map +1 -1
  15. package/dist/cjs/generated/ns/actions.d.ts +267 -33
  16. package/dist/cjs/generated/ns/actions.js +375 -33
  17. package/dist/cjs/generated/ns/actions.js.map +1 -1
  18. package/dist/cjs/generated/ns/agents.d.ts +656 -0
  19. package/dist/cjs/generated/ns/agents.js +989 -0
  20. package/dist/cjs/generated/ns/agents.js.map +1 -0
  21. package/dist/cjs/generated/ns/images.d.ts +162 -0
  22. package/dist/cjs/generated/ns/images.js +246 -0
  23. package/dist/cjs/generated/ns/images.js.map +1 -0
  24. package/dist/cjs/generated/ns/infer.d.ts +71 -3
  25. package/dist/cjs/generated/ns/infer.js +98 -3
  26. package/dist/cjs/generated/ns/infer.js.map +1 -1
  27. package/dist/cjs/generated/ns/keys.d.ts +3 -1
  28. package/dist/cjs/generated/ns/keys.js +3 -1
  29. package/dist/cjs/generated/ns/keys.js.map +1 -1
  30. package/dist/cjs/generated/ns/listeners.d.ts +163 -0
  31. package/dist/cjs/generated/ns/listeners.js +268 -0
  32. package/dist/cjs/generated/ns/listeners.js.map +1 -0
  33. package/dist/cjs/generated/ns/orgs.d.ts +10 -0
  34. package/dist/cjs/generated/ns/orgs.js +26 -1
  35. package/dist/cjs/generated/ns/orgs.js.map +1 -1
  36. package/dist/cjs/generated/ns/projects.d.ts +32 -0
  37. package/dist/cjs/generated/ns/projects.js +66 -0
  38. package/dist/cjs/generated/ns/projects.js.map +1 -1
  39. package/dist/cjs/generated/ns/render.d.ts +192 -21
  40. package/dist/cjs/generated/ns/render.js +267 -24
  41. package/dist/cjs/generated/ns/render.js.map +1 -1
  42. package/dist/cjs/generated/ns/requests.d.ts +3 -1
  43. package/dist/cjs/generated/ns/requests.js +3 -1
  44. package/dist/cjs/generated/ns/requests.js.map +1 -1
  45. package/dist/cjs/generated/ns/routines.d.ts +22 -4
  46. package/dist/cjs/generated/ns/routines.js +22 -4
  47. package/dist/cjs/generated/ns/routines.js.map +1 -1
  48. package/dist/cjs/generated/ns/sandboxes.d.ts +431 -7
  49. package/dist/cjs/generated/ns/sandboxes.js +633 -6
  50. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  51. package/dist/cjs/generated/ns/usage.d.ts +1 -1
  52. package/dist/cjs/generated/ns/usage.js +1 -1
  53. package/dist/cjs/generated/ns/vision.d.ts +113 -17
  54. package/dist/cjs/generated/ns/vision.js +152 -21
  55. package/dist/cjs/generated/ns/vision.js.map +1 -1
  56. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  57. package/dist/cjs/generated/ns/workspaces.js +410 -0
  58. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  59. package/dist/cjs/generated/types.d.ts +5259 -605
  60. package/dist/cjs/helpers/sandboxes.d.ts +20 -1
  61. package/dist/cjs/helpers/sandboxes.js +13 -1
  62. package/dist/cjs/helpers/sandboxes.js.map +1 -1
  63. package/dist/esm/core/util.d.ts +1 -1
  64. package/dist/esm/core/util.js +1 -1
  65. package/dist/esm/generated/client.d.ts +18 -0
  66. package/dist/esm/generated/client.js +34 -0
  67. package/dist/esm/generated/client.js.map +1 -1
  68. package/dist/esm/generated/errors.d.ts +1 -1
  69. package/dist/esm/generated/errors.js +120 -0
  70. package/dist/esm/generated/errors.js.map +1 -1
  71. package/dist/esm/generated/ids.d.ts +89 -0
  72. package/dist/esm/generated/ids.js +22 -0
  73. package/dist/esm/generated/ids.js.map +1 -1
  74. package/dist/esm/generated/jobs.js +4 -0
  75. package/dist/esm/generated/jobs.js.map +1 -1
  76. package/dist/esm/generated/ns/actions.d.ts +267 -33
  77. package/dist/esm/generated/ns/actions.js +375 -33
  78. package/dist/esm/generated/ns/actions.js.map +1 -1
  79. package/dist/esm/generated/ns/agents.d.ts +656 -0
  80. package/dist/esm/generated/ns/agents.js +985 -0
  81. package/dist/esm/generated/ns/agents.js.map +1 -0
  82. package/dist/esm/generated/ns/images.d.ts +162 -0
  83. package/dist/esm/generated/ns/images.js +242 -0
  84. package/dist/esm/generated/ns/images.js.map +1 -0
  85. package/dist/esm/generated/ns/infer.d.ts +71 -3
  86. package/dist/esm/generated/ns/infer.js +98 -3
  87. package/dist/esm/generated/ns/infer.js.map +1 -1
  88. package/dist/esm/generated/ns/keys.d.ts +3 -1
  89. package/dist/esm/generated/ns/keys.js +3 -1
  90. package/dist/esm/generated/ns/keys.js.map +1 -1
  91. package/dist/esm/generated/ns/listeners.d.ts +163 -0
  92. package/dist/esm/generated/ns/listeners.js +264 -0
  93. package/dist/esm/generated/ns/listeners.js.map +1 -0
  94. package/dist/esm/generated/ns/orgs.d.ts +10 -0
  95. package/dist/esm/generated/ns/orgs.js +26 -1
  96. package/dist/esm/generated/ns/orgs.js.map +1 -1
  97. package/dist/esm/generated/ns/projects.d.ts +32 -0
  98. package/dist/esm/generated/ns/projects.js +66 -0
  99. package/dist/esm/generated/ns/projects.js.map +1 -1
  100. package/dist/esm/generated/ns/render.d.ts +192 -21
  101. package/dist/esm/generated/ns/render.js +267 -24
  102. package/dist/esm/generated/ns/render.js.map +1 -1
  103. package/dist/esm/generated/ns/requests.d.ts +3 -1
  104. package/dist/esm/generated/ns/requests.js +3 -1
  105. package/dist/esm/generated/ns/requests.js.map +1 -1
  106. package/dist/esm/generated/ns/routines.d.ts +22 -4
  107. package/dist/esm/generated/ns/routines.js +22 -4
  108. package/dist/esm/generated/ns/routines.js.map +1 -1
  109. package/dist/esm/generated/ns/sandboxes.d.ts +431 -7
  110. package/dist/esm/generated/ns/sandboxes.js +633 -6
  111. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  112. package/dist/esm/generated/ns/usage.d.ts +1 -1
  113. package/dist/esm/generated/ns/usage.js +1 -1
  114. package/dist/esm/generated/ns/vision.d.ts +113 -17
  115. package/dist/esm/generated/ns/vision.js +152 -21
  116. package/dist/esm/generated/ns/vision.js.map +1 -1
  117. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  118. package/dist/esm/generated/ns/workspaces.js +406 -0
  119. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  120. package/dist/esm/generated/types.d.ts +5259 -605
  121. package/dist/esm/helpers/sandboxes.d.ts +20 -1
  122. package/dist/esm/helpers/sandboxes.js +13 -1
  123. package/dist/esm/helpers/sandboxes.js.map +1 -1
  124. package/package.json +1 -1
  125. package/src/core/util.ts +1 -1
  126. package/src/generated/client.ts +38 -0
  127. package/src/generated/errors.ts +240 -0
  128. package/src/generated/ids.ts +22 -0
  129. package/src/generated/jobs.ts +4 -0
  130. package/src/generated/ns/actions.ts +403 -33
  131. package/src/generated/ns/agents.ts +1102 -0
  132. package/src/generated/ns/images.ts +256 -0
  133. package/src/generated/ns/infer.ts +100 -3
  134. package/src/generated/ns/keys.ts +3 -1
  135. package/src/generated/ns/listeners.ts +300 -0
  136. package/src/generated/ns/orgs.ts +27 -1
  137. package/src/generated/ns/projects.ts +74 -0
  138. package/src/generated/ns/render.ts +277 -24
  139. package/src/generated/ns/requests.ts +3 -1
  140. package/src/generated/ns/routines.ts +22 -4
  141. package/src/generated/ns/sandboxes.ts +694 -7
  142. package/src/generated/ns/usage.ts +1 -1
  143. package/src/generated/ns/vision.ts +159 -21
  144. package/src/generated/ns/workspaces.ts +448 -0
  145. package/src/generated/types.ts +5684 -601
  146. package/src/helpers/sandboxes.ts +31 -2
@@ -0,0 +1,256 @@
1
+ // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
+
3
+ import type { BinaryInput, RequestOptions } from "../../core/client.ts";
4
+ import { Namespace } from "../../core/namespace.ts";
5
+ import type { Op } from "../../core/op.ts";
6
+ import type { APIPromise } from "../../core/promise.ts";
7
+ import type * as T from "../types.ts";
8
+
9
+ const listImagesOp: Op = {
10
+ id: "imagesListImages",
11
+ method: "GET",
12
+ path: "/v1/images",
13
+ timeoutMs: 10000,
14
+ scope: "sandboxes:read",
15
+ };
16
+ const importImageOp: Op = {
17
+ id: "imagesImportImage",
18
+ method: "POST",
19
+ path: "/v1/images",
20
+ body: "json",
21
+ timeoutMs: 30000,
22
+ scope: "sandboxes:write",
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
+ };
42
+ const deleteImageOp: Op = {
43
+ id: "imagesDeleteImage",
44
+ method: "DELETE",
45
+ path: "/v1/images/{image_id}",
46
+ params: ["image_id"],
47
+ timeoutMs: 30000,
48
+ scope: "sandboxes:write",
49
+ };
50
+ const getImageOp: Op = {
51
+ id: "imagesGetImage",
52
+ method: "GET",
53
+ path: "/v1/images/{image_id}",
54
+ params: ["image_id"],
55
+ timeoutMs: 35000,
56
+ scope: "sandboxes:read",
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
+ };
75
+
76
+ /** Descriptors of every images operation, keyed by method name (for tooling and custom clients). */
77
+ export const imagesOps = {
78
+ listImages: listImagesOp,
79
+ importImage: importImageOp,
80
+ getContext: getContextOp,
81
+ putContext: putContextOp,
82
+ deleteImage: deleteImageOp,
83
+ getImage: getImageOp,
84
+ getImageLogs: getImageLogsOp,
85
+ releaseImage: releaseImageOp,
86
+ } as const;
87
+
88
+ /** Public OCI images imported as templates for your project's sandboxes (`/v1/images`). */
89
+ export class ImagesAPI extends Namespace {
90
+ /**
91
+ * List images
92
+ *
93
+ * Lists this project's images, newest first, in every status (an `evicted` or `failed` image stays listed
94
+ * until it is deleted). Other projects' images are never listed.
95
+ *
96
+ * `GET /v1/images` · scope `sandboxes:read` · served by the node
97
+ */
98
+ listImages(options?: RequestOptions): APIPromise<T.ImageList> {
99
+ return this._client._call<T.ImageList>(listImagesOp, {}, options);
100
+ }
101
+
102
+ /**
103
+ * Import an image
104
+ *
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
108
+ * answer (a tag to its digest with one manifest `HEAD`), so the answer names the exact image: `202` with a new
109
+ * image (`status: queued`), or `200` with the project's existing image when one with the same key exists,
110
+ * ready or still importing. The key covers the project, the image's digest, the warm-up, the size and the
111
+ * node's own build inputs (guest agent, kernel, the unpacker), so the same request after a node release can be
112
+ * a new image. Watch it with `GET /v1/images/{image_id}?wait=30` until `ready` (or `failed`), then create
113
+ * sandboxes with `POST /v1/sandboxes {"image": "img_…"}`.
114
+ *
115
+ * The import runs whether or not the client stays connected. It holds `images.rootfs_max` of your
116
+ * organization's snapshot storage while it runs and then counts as one snapshot, its root file system plus its
117
+ * warm snapshot's memory, against `sandboxes.snapshots_max` and `sandboxes.snapshot_storage_max`. An
118
+ * organization runs one import at a time and a node two; more wait in the queue (`queued`). The CPU the import
119
+ * uses (the unpacking microVM and the warm-up boot) is recorded as `images.import_vcpu_ms`.
120
+ *
121
+ * `warmup.commands` run in order, each as an argument list (no shell unless you name one), as root, with no
122
+ * network, at most 300 seconds in all; what they read is in the page cache of every sandbox restored from the
123
+ * snapshot. The image's `USER`, `ENV` and `WORKDIR` apply to every command your sandboxes run. Clones of one
124
+ * warm snapshot share the in-process random state of anything the warm-up left running, within your project
125
+ * only; the kernel's random pool is reseeded for each.
126
+ *
127
+ * `size` (`vcpu`, `memory_mib`) is fixed at import: every sandbox from the image has it, and a create that asks
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
135
+ * `404 feature_not_enabled`; without an image store on the node, a full store or the node's disk under its
136
+ * floor, `503 capacity_unavailable`.
137
+ *
138
+ * A `failed` image whose warm snapshot could not be rebuilt (`error.stage: rebuild`) keeps its root file
139
+ * system, and the node tries it again at its next start. The same request imports it again under its ID and
140
+ * replaces that file system, except while a running or paused sandbox, or a snapshot taken from one, uses the
141
+ * image's template: then the answer is `409 image_in_use`.
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
+ *
163
+ * `POST /v1/images` · scope `sandboxes:write` · served by the node
164
+ */
165
+ importImage(body: T.ImageImportRequest, options?: RequestOptions): APIPromise<T.Image> {
166
+ return this._client._call<T.Image>(importImageOp, { body }, options);
167
+ }
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
+
197
+ /**
198
+ * Delete an image
199
+ *
200
+ * Deletes the image, its template, its warm snapshot and its root file system. An import in progress is
201
+ * cancelled and leaves nothing behind. While a running or paused sandbox, or a snapshot taken from one, uses
202
+ * the image's template the answer is `409 image_in_use`.
203
+ *
204
+ * `DELETE /v1/images/{image_id}` · scope `sandboxes:write` · served by the node
205
+ */
206
+ deleteImage(imageId: string, options?: RequestOptions): APIPromise<T.Deleted> {
207
+ return this._client._call<T.Deleted>(deleteImageOp, { path: [imageId] }, options);
208
+ }
209
+
210
+ /**
211
+ * Get an image
212
+ *
213
+ * Returns one of this project's images. With `wait` (seconds, at most 30) the answer is held until the image is
214
+ * `ready`, `failed` or `evicted`, or the time passes, whichever is first; it then returns the image as it is.
215
+ * `stages_ms` times each stage the import has finished; `error` says why a `failed` image failed, with the
216
+ * last 4 KiB of output.
217
+ *
218
+ * `GET /v1/images/{image_id}` · scope `sandboxes:read` · served by the node
219
+ */
220
+ getImage(imageId: string, params?: T.ImagesGetImageParams, options?: RequestOptions): APIPromise<T.Image> {
221
+ return this._client._call<T.Image>(getImageOp, { path: [imageId], query: params }, options);
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
+ }
256
+ }
@@ -29,6 +29,7 @@ const createChatCompletionOp: Op = {
29
29
  id: "inferCreateChatCompletion",
30
30
  method: "POST",
31
31
  path: "/v1/infer/chat/completions",
32
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
32
33
  body: "json",
33
34
  stream: "sse",
34
35
  timeoutMs: 600000,
@@ -63,10 +64,21 @@ const getModelOp: Op = {
63
64
  errorFormat: "openai",
64
65
  scope: "infer:read",
65
66
  };
67
+ const createRerankOp: Op = {
68
+ id: "inferCreateRerank",
69
+ method: "POST",
70
+ path: "/v1/infer/rerank",
71
+ body: "json",
72
+ timeoutMs: 65000,
73
+ errorFormat: "openai",
74
+ stretch: true,
75
+ scope: "infer:run",
76
+ };
66
77
  const createResponseOp: Op = {
67
78
  id: "inferCreateResponse",
68
79
  method: "POST",
69
80
  path: "/v1/infer/responses",
81
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
70
82
  body: "json",
71
83
  stream: "sse",
72
84
  timeoutMs: 600000,
@@ -77,6 +89,7 @@ const createMessageOp: Op = {
77
89
  id: "inferCreateMessage",
78
90
  method: "POST",
79
91
  path: "/v1/infer/v1/messages",
92
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
80
93
  body: "json",
81
94
  stream: "sse",
82
95
  timeoutMs: 600000,
@@ -92,6 +105,16 @@ const countMessageTokensOp: Op = {
92
105
  errorFormat: "anthropic",
93
106
  scope: "infer:run",
94
107
  };
108
+ const createRerankV2Op: Op = {
109
+ id: "inferCreateRerankV2",
110
+ method: "POST",
111
+ path: "/v1/infer/v2/rerank",
112
+ body: "json",
113
+ timeoutMs: 65000,
114
+ errorFormat: "openai",
115
+ stretch: true,
116
+ scope: "infer:run",
117
+ };
95
118
 
96
119
  /** Descriptors of every infer operation, keyed by method name (for tooling and custom clients). */
97
120
  export const inferOps = {
@@ -101,9 +124,11 @@ export const inferOps = {
101
124
  createEmbeddings: createEmbeddingsOp,
102
125
  listModels: listModelsOp,
103
126
  getModel: getModelOp,
127
+ createRerank: createRerankOp,
104
128
  createResponse: createResponseOp,
105
129
  createMessage: createMessageOp,
106
130
  countMessageTokens: countMessageTokensOp,
131
+ createRerankV2: createRerankV2Op,
107
132
  } as const;
108
133
 
109
134
  /** Models on the node: OpenAI-compatible chat, embeddings and speech (`/v1/infer`). */
@@ -273,8 +298,33 @@ export class InferAPI extends Namespace {
273
298
  /**
274
299
  * Create embeddings
275
300
  *
276
- * The OpenAI Embeddings API, for embedding models the node serves (`b3os.kind` is `embedding`). Other models
277
- * return `404 model_not_available`; the beta node serves no embedding model yet. Bills input tokens.
301
+ * The OpenAI Embeddings API, for embedding models the node serves (`b3os.kind` is `embedding` in
302
+ * `GET /v1/infer/models`). Other models return `404 model_not_available`; the beta node serves no embedding
303
+ * model yet. An embedding model has no alias: name its own ID, so stored vectors always come from the model
304
+ * that made them.
305
+ *
306
+ * `input` is a string or 1 to 2,048 strings, none of them empty (`400 invalid_request` pointing at it). Arrays
307
+ * of token IDs are `400 unsupported_parameter`: the node reads text only, and token IDs from another tokenizer
308
+ * would give wrong vectors (LangChain's `OpenAIEmbeddings` sends them unless it is created with
309
+ * `check_embedding_ctx_length=False`). An input may have as many tokens as the model's `context_length`,
310
+ * query prompt included; a longer one is `400 context_length_exceeded` pointing at it, unless `truncate` is
311
+ * `end`, which cuts it at the end to fit.
312
+ *
313
+ * `encoding_format` is `float` (the default) or `base64` (little-endian float32, what the OpenAI SDKs ask for
314
+ * by default); both carry the same numbers. Every vector has length 1. `dimensions` shortens the vectors, from
315
+ * the model's `b3os.min_dimensions` to its `b3os.dimensions` values (`400 unsupported_parameter` outside it):
316
+ * the node cuts each vector and scales it back to length 1. `user` is accepted and ignored.
317
+ *
318
+ * B3OS extensions: `input_type: "query"` puts the model's query prompt before each input, for text you search
319
+ * with (`document`, the default, embeds the input as it is), and `instruction` replaces the task the prompt
320
+ * describes (with `input_type: "query"` only, at most 512 characters). The prompt's tokens are billed with the
321
+ * input. The node sends a large request to the model in parts of at most 8,192 tokens and answers in input
322
+ * order.
323
+ *
324
+ * Bills `infer.embed_tokens`, the tokens the model read; a request that fails is not billed. Requests are
325
+ * admitted against your organization's per-minute token and request limits on the model, and against 8
326
+ * embedding and rerank requests in flight per organization (`429 concurrency_limited`, limit
327
+ * `infer.pool.concurrent`). Embeddings are never kept by the model call log. No streaming.
278
328
  *
279
329
  * `POST /v1/infer/embeddings` · scope `infer:run` · served by the node
280
330
  *
@@ -291,7 +341,8 @@ export class InferAPI extends Namespace {
291
341
  * quantization, whether it supports tools, JSON Schema output and image input, the largest accepted request,
292
342
  * and your per-model token and request limits. Chat models are listed while the node's model runtime is
293
343
  * configured (one that is restarting is still listed; requests get `503` with `Retry-After`); speech models
294
- * while the voice service answers.
344
+ * while the voice service answers. Embedding and rerank models, where a node serves them, are listed the same
345
+ * way, each with its own engine.
295
346
  *
296
347
  * `GET /v1/infer/models` · scope `infer:read` · served by the node
297
348
  */
@@ -310,6 +361,37 @@ export class InferAPI extends Namespace {
310
361
  return this._client._call<T.Model>(getModelOp, { path: [model] }, options);
311
362
  }
312
363
 
364
+ /**
365
+ * Rerank documents
366
+ *
367
+ * Ranks documents by how well they answer a query, in the shape of Cohere's v2 rerank API, for rerank models
368
+ * the node serves (`b3os.kind` is `rerank` in `GET /v1/infer/models`). Other models return
369
+ * `404 model_not_available`; the beta node serves no rerank model yet. The same operation answers at
370
+ * `POST /v1/infer/v2/rerank`, so Cohere's SDK works with its base URL set to
371
+ * `https://beta-api.b3os.org/v1/infer`.
372
+ *
373
+ * `documents` holds 1 to 1,000 strings or `{text}` objects, none of them empty. `query` may have 2,048 tokens
374
+ * (`400 context_length_exceeded` past it). Each document is cut at the end to `max_tokens_per_doc` tokens
375
+ * (default 4,096, at most 8,000), and further where the query and the document together would pass the
376
+ * model's `context_length`. `results` lists the `top_n` best documents (default: all of them), highest
377
+ * `relevance_score` (0 to 1) first, each with its `index` in `documents`; with `return_documents: true` each
378
+ * also carries its document as sent. B3OS extension: `instruction` replaces the task the model's query prompt
379
+ * describes (at most 512 characters). The node sends a large request to the model in parts of at most 8,192
380
+ * tokens.
381
+ *
382
+ * Bills `infer.rerank_tokens`, the tokens of every query and document pair the model read
383
+ * (`usage.total_tokens`, also in `meta.billed_units.input_tokens`); a request that fails is not billed. Limits
384
+ * as for embeddings: per-minute tokens and requests on the model, and 8 embedding and rerank requests in
385
+ * flight per organization. Rerank calls are never kept by the model call log. No streaming.
386
+ *
387
+ * `POST /v1/infer/rerank` · scope `infer:run` · served by the node
388
+ *
389
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
390
+ */
391
+ createRerank(body: T.RerankRequest, options?: RequestOptions): APIPromise<T.RerankList> {
392
+ return this._client._call<T.RerankList>(createRerankOp, { body }, options);
393
+ }
394
+
313
395
  /**
314
396
  * Create a response (OpenAI Responses API)
315
397
  *
@@ -497,4 +579,19 @@ export class InferAPI extends Namespace {
497
579
  ): APIPromise<T.AnthropicCountTokens> {
498
580
  return this._client._call<T.AnthropicCountTokens>(countMessageTokensOp, { body }, options);
499
581
  }
582
+
583
+ /**
584
+ * Rerank documents at Cohere's path
585
+ *
586
+ * `POST /v1/infer/rerank` at the path Cohere's v2 SDK calls (`<base URL>/v2/rerank`), so
587
+ * `cohere.ClientV2(base_url="https://beta-api.b3os.org/v1/infer")` works unchanged. The request, the answer,
588
+ * the limits and the meter are those of `POST /v1/infer/rerank`.
589
+ *
590
+ * `POST /v1/infer/v2/rerank` · scope `infer:run` · served by the node
591
+ *
592
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
593
+ */
594
+ createRerankV2(body: T.RerankRequest, options?: RequestOptions): APIPromise<T.RerankList> {
595
+ return this._client._call<T.RerankList>(createRerankV2Op, { body }, options);
596
+ }
500
597
  }
@@ -99,7 +99,9 @@ export class KeysAPI extends Namespace {
99
99
  *
100
100
  * Creates a key in your project (or `project`, in the same organization). `scopes` and `spend_cap_usd` may not
101
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.
102
+ * expiry (`forbidden`, reason `scope_escalation`). The response is the only time `secret` is returned. An
103
+ * organization holds at most `platform.keys.max` active API keys (1,000 in the beta; revoked and expired ones are
104
+ * not counted, nor CLI tokens); a create past it is 422 `limit_exceeded`.
103
105
  *
104
106
  * `POST /v1/keys` · scope `platform:write` · served by beta-api.b3os.org
105
107
  */