@b3os/sdk 0.1.3 → 0.2.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.
Files changed (80) hide show
  1. package/README.md +4 -3
  2. package/dist/cjs/core/client.d.ts +21 -2
  3. package/dist/cjs/core/client.js +26 -1
  4. package/dist/cjs/core/client.js.map +1 -1
  5. package/dist/cjs/core/handle.d.ts +5 -0
  6. package/dist/cjs/core/handle.js +13 -2
  7. package/dist/cjs/core/handle.js.map +1 -1
  8. package/dist/cjs/core/index.d.ts +2 -0
  9. package/dist/cjs/core/index.js +7 -1
  10. package/dist/cjs/core/index.js.map +1 -1
  11. package/dist/cjs/core/traces-api.d.ts +42 -0
  12. package/dist/cjs/core/traces-api.js +54 -0
  13. package/dist/cjs/core/traces-api.js.map +1 -0
  14. package/dist/cjs/core/traces.d.ts +120 -0
  15. package/dist/cjs/core/traces.js +306 -0
  16. package/dist/cjs/core/traces.js.map +1 -0
  17. package/dist/cjs/core/util.d.ts +1 -1
  18. package/dist/cjs/core/util.js +1 -1
  19. package/dist/cjs/generated/errors.d.ts +1 -1
  20. package/dist/cjs/generated/errors.js +12 -0
  21. package/dist/cjs/generated/errors.js.map +1 -1
  22. package/dist/cjs/generated/ids.d.ts +12 -0
  23. package/dist/cjs/generated/ids.js +3 -0
  24. package/dist/cjs/generated/ids.js.map +1 -1
  25. package/dist/cjs/generated/ns/keys.d.ts +2 -1
  26. package/dist/cjs/generated/ns/keys.js +2 -1
  27. package/dist/cjs/generated/ns/keys.js.map +1 -1
  28. package/dist/cjs/generated/ns/render.d.ts +22 -2
  29. package/dist/cjs/generated/ns/render.js +13 -2
  30. package/dist/cjs/generated/ns/render.js.map +1 -1
  31. package/dist/cjs/generated/ns/sandboxes.d.ts +29 -0
  32. package/dist/cjs/generated/ns/sandboxes.js +49 -0
  33. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  34. package/dist/cjs/generated/types.d.ts +820 -53
  35. package/dist/esm/core/client.d.ts +21 -2
  36. package/dist/esm/core/client.js +27 -2
  37. package/dist/esm/core/client.js.map +1 -1
  38. package/dist/esm/core/handle.d.ts +5 -0
  39. package/dist/esm/core/handle.js +13 -2
  40. package/dist/esm/core/handle.js.map +1 -1
  41. package/dist/esm/core/index.d.ts +2 -0
  42. package/dist/esm/core/index.js +2 -0
  43. package/dist/esm/core/index.js.map +1 -1
  44. package/dist/esm/core/traces-api.d.ts +42 -0
  45. package/dist/esm/core/traces-api.js +50 -0
  46. package/dist/esm/core/traces-api.js.map +1 -0
  47. package/dist/esm/core/traces.d.ts +120 -0
  48. package/dist/esm/core/traces.js +295 -0
  49. package/dist/esm/core/traces.js.map +1 -0
  50. package/dist/esm/core/util.d.ts +1 -1
  51. package/dist/esm/core/util.js +1 -1
  52. package/dist/esm/generated/errors.d.ts +1 -1
  53. package/dist/esm/generated/errors.js +12 -0
  54. package/dist/esm/generated/errors.js.map +1 -1
  55. package/dist/esm/generated/ids.d.ts +12 -0
  56. package/dist/esm/generated/ids.js +3 -0
  57. package/dist/esm/generated/ids.js.map +1 -1
  58. package/dist/esm/generated/ns/keys.d.ts +2 -1
  59. package/dist/esm/generated/ns/keys.js +2 -1
  60. package/dist/esm/generated/ns/keys.js.map +1 -1
  61. package/dist/esm/generated/ns/render.d.ts +22 -2
  62. package/dist/esm/generated/ns/render.js +13 -2
  63. package/dist/esm/generated/ns/render.js.map +1 -1
  64. package/dist/esm/generated/ns/sandboxes.d.ts +29 -0
  65. package/dist/esm/generated/ns/sandboxes.js +49 -0
  66. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  67. package/dist/esm/generated/types.d.ts +820 -53
  68. package/package.json +1 -1
  69. package/src/core/client.ts +36 -4
  70. package/src/core/handle.ts +12 -2
  71. package/src/core/index.ts +10 -0
  72. package/src/core/traces-api.ts +80 -0
  73. package/src/core/traces.ts +375 -0
  74. package/src/core/util.ts +1 -1
  75. package/src/generated/errors.ts +24 -0
  76. package/src/generated/ids.ts +3 -0
  77. package/src/generated/ns/keys.ts +2 -1
  78. package/src/generated/ns/render.ts +22 -2
  79. package/src/generated/ns/sandboxes.ts +59 -0
  80. package/src/generated/types.ts +825 -52
@@ -76,6 +76,16 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
76
76
  turnstile_required: [400, 0, "Turnstile token required"],
77
77
  turnstile_failed: [403, 0, "Turnstile check failed"],
78
78
  turnstile_unavailable: [503, 1, "Turnstile unavailable"],
79
+ github_app_not_configured: [503, 0, "GitHub App not configured"],
80
+ github_installation_not_found: [404, 0, "GitHub installation not found"],
81
+ github_repository_not_accessible: [404, 0, "GitHub repository not accessible"],
82
+ repository_link_not_found: [404, 0, "Repository link not found"],
83
+ eval_run_not_found: [404, 0, "Eval run not found"],
84
+ alert_destination_not_found: [404, 0, "Alert destination not found"],
85
+ trace_not_found: [404, 0, "Trace not found"],
86
+ deploy_not_found: [404, 0, "Deploy not found"],
87
+ deploy_not_rollbackable: [409, 0, "Deploy cannot be rolled back to"],
88
+ deploy_not_updatable: [409, 0, "Deploy cannot change this way"],
79
89
  authorization_pending: [400, 1, "Authorization pending"],
80
90
  slow_down: [400, 1, "Slow down"],
81
91
  access_denied: [400, 0, "Access denied"],
@@ -114,6 +124,7 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
114
124
  capture_failed: [502, 1, "Capture failed"],
115
125
  script_invalid: [422, 0, "Invalid video script"],
116
126
  script_step_failed: [422, 0, "Script step failed"],
127
+ profile_expired: [422, 0, "Profile no longer signs in"],
117
128
  restyle_unavailable: [409, 0, "Restyle not available"],
118
129
  background_unavailable: [503, 1, "Background unavailable"],
119
130
  style_invalid: [422, 0, "Invalid style"],
@@ -130,6 +141,7 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
130
141
  guest_outdated: [409, 0, "Sandbox agent predates the operation"],
131
142
  file_too_large: [413, 0, "File too large"],
132
143
  port_not_exposed: [404, 0, "Port not exposed"],
144
+ upstream_first_byte_timeout: [504, 0, "Upstream first byte timeout"],
133
145
  process_not_found: [404, 0, "Process not found"],
134
146
  kernel_unavailable: [409, 0, "Code kernel unavailable"],
135
147
  language_unsupported: [422, 0, "Language not supported"],
@@ -261,6 +273,16 @@ export type B3OSServerErrorCode =
261
273
  | "turnstile_required"
262
274
  | "turnstile_failed"
263
275
  | "turnstile_unavailable"
276
+ | "github_app_not_configured"
277
+ | "github_installation_not_found"
278
+ | "github_repository_not_accessible"
279
+ | "repository_link_not_found"
280
+ | "eval_run_not_found"
281
+ | "alert_destination_not_found"
282
+ | "trace_not_found"
283
+ | "deploy_not_found"
284
+ | "deploy_not_rollbackable"
285
+ | "deploy_not_updatable"
264
286
  | "authorization_pending"
265
287
  | "slow_down"
266
288
  | "access_denied"
@@ -299,6 +321,7 @@ export type B3OSServerErrorCode =
299
321
  | "capture_failed"
300
322
  | "script_invalid"
301
323
  | "script_step_failed"
324
+ | "profile_expired"
302
325
  | "restyle_unavailable"
303
326
  | "background_unavailable"
304
327
  | "style_invalid"
@@ -315,6 +338,7 @@ export type B3OSServerErrorCode =
315
338
  | "guest_outdated"
316
339
  | "file_too_large"
317
340
  | "port_not_exposed"
341
+ | "upstream_first_byte_timeout"
318
342
  | "process_not_found"
319
343
  | "kernel_unavailable"
320
344
  | "language_unsupported"
@@ -31,6 +31,9 @@ export const ID_PREFIXES = {
31
31
  tkt: { object: "stream_ticket", product: "platform", secret: true },
32
32
  evt: { object: "event", product: "platform" },
33
33
  usr: { object: "user", product: "platform" },
34
+ dep: { object: "deploy", product: "platform" },
35
+ evr: { object: "eval_run", product: "platform" },
36
+ alt: { object: "alert", product: "platform" },
34
37
  } as const;
35
38
 
36
39
  export type IdPrefix = keyof typeof ID_PREFIXES;
@@ -125,7 +125,8 @@ export class KeysAPI extends Namespace {
125
125
  * Describe the calling credential
126
126
  *
127
127
  * Returns who is calling: the key or CLI token (or dashboard session, or sandbox), its organization and
128
- * project, scopes, spend cap and expiry. Any valid credential may call it, whatever its scopes.
128
+ * project, scopes, spend cap, what it has spent this billing period and expiry. Any valid credential may call
129
+ * it, whatever its scopes, so a key without `platform:read` can still see how much of its cap is used.
129
130
  *
130
131
  * `GET /v1/keys/current` · scope `authenticated` · served by beta-api.b3os.org
131
132
  */
@@ -204,11 +204,13 @@ export class RenderAPI extends Namespace {
204
204
  *
205
205
  * - `css`: drawn by the compositor from CSS gradient layers (no image file), recolorable through `tokens`.
206
206
  * - `procedural`: the `studio` pack, our own soft meshes computed by the compositor (no image file, no
207
- * tokens); the ones tagged `auto` are the set the `auto` background preset picks from.
207
+ * tokens); the ones tagged `auto` are the set a screenshot's `auto` background (and anything's `studio`)
208
+ * picks from.
208
209
  * - `image`: a lossless WebP from ScreenFramed's curated library (decisions T9 and T10: Sean's grants as owner
209
210
  * of the library), up to 3840 px on the long edge, with its measured tone in `image` (theme, luminance, hue,
210
211
  * detail; how `"auto"` matches a page). `image.coverage` is `full-bleed` for backgrounds; the `gradients`
211
- * group holds transparent shapes (`cutout`) drawn over a matte.
212
+ * group holds transparent shapes (`cutout`) drawn over a matte. The images tagged `video` are the set a video's
213
+ * `auto` background picks from.
212
214
  *
213
215
  * Rows are in `ref` order, paged by `limit` and `cursor`. A ref whose bytes equal an earlier one's still
214
216
  * resolves but is not listed. Public: no API key, rate limited per client address, and answered from the
@@ -289,6 +291,15 @@ export class RenderAPI extends Namespace {
289
291
  * `final_url` and `page_state` say what the site answered, and `warnings` what a caller should know: an error
290
292
  * status, a main area that stayed blank, a page taken before its load event, overlays or a wall left in place.
291
293
  *
294
+ * `profile` names a vision profile (ID or name) of the key's project: its cookies and storage load into the
295
+ * page's own browser context before the page loads, so the capture shows the page signed in. It needs
296
+ * `vision:profiles:use` (403 without it, 404 `profile_not_found` for a profile the project does not have),
297
+ * and the answer's `source.profile` is the profile's `prof_` ID. Render writes the state into no answer,
298
+ * stored record or log line, but the image shows whatever the signed-in page shows: treat it and its link as
299
+ * private. A page that is still signed out after the profile loads (a sign-in form, a 401 or 403, a move to a
300
+ * sign-in page, or a sign-in wall) fails with 422 `profile_expired` and bills nothing: sign in again and save
301
+ * the profile.
302
+ *
292
303
  * `POST /v1/render/screenshots` · scope `render:run` · served by the node
293
304
  */
294
305
  createScreenshot(
@@ -354,6 +365,15 @@ export class RenderAPI extends Namespace {
354
365
  * (H.264, BT.709), GIF, poster and captions. Artifacts appear as they finish (`video.artifact` events, poster
355
366
  * first). Bills `render.video_s` per second of output.
356
367
  *
368
+ * `source.profile` names a vision profile (ID or name) of the key's project, found when the video is made
369
+ * (403 without `vision:profiles:use`, 404 `profile_not_found`). When the job runs, its state loads into the
370
+ * probe's browser context and every capture segment's, so the whole video is recorded signed in; the video,
371
+ * its timeline and its events name the profile by its `prof_` ID only, but the video shows whatever the
372
+ * signed-in pages show: treat it and its links as private. A page that opens still signed out (a sign-in form,
373
+ * a 401 or 403, or a move to a sign-in page) ends the job with `profile_expired` before any step runs, and
374
+ * nothing is billed. A recording made with a
375
+ * profile is reused (`recording.reuse`) only by videos with the same revision of the same profile.
376
+ *
357
377
  * `POST /v1/render/videos` · scope `render:run` · served by the node
358
378
  */
359
379
  createVideo(body: T.VideoCreateRequest, options?: RequestOptions): JobPromise<T.Video, T.VideoEvent> {
@@ -248,6 +248,14 @@ const waitReadyOp: Op = {
248
248
  timeoutMs: 65000,
249
249
  scope: "sandboxes:run",
250
250
  };
251
+ const listRequestsOp: Op = {
252
+ id: "sandboxesListRequests",
253
+ method: "GET",
254
+ path: "/v1/sandboxes/{sandbox_id}/requests",
255
+ params: ["sandbox_id"],
256
+ timeoutMs: 15000,
257
+ scope: "sandboxes:read",
258
+ };
251
259
  const resumeSandboxOp: Op = {
252
260
  id: "sandboxesResumeSandbox",
253
261
  method: "POST",
@@ -275,6 +283,14 @@ const createSnapshotOp: Op = {
275
283
  timeoutMs: 65000,
276
284
  scope: "sandboxes:write",
277
285
  };
286
+ const getStatsOp: Op = {
287
+ id: "sandboxesGetStats",
288
+ method: "GET",
289
+ path: "/v1/sandboxes/{sandbox_id}/stats",
290
+ params: ["sandbox_id"],
291
+ timeoutMs: 10000,
292
+ scope: "sandboxes:read",
293
+ };
278
294
  const createTicketOp: Op = {
279
295
  id: "sandboxesCreateTicket",
280
296
  method: "POST",
@@ -320,9 +336,11 @@ export const sandboxesOps = {
320
336
  killProcess: killProcessOp,
321
337
  openPty: openPtyOp,
322
338
  waitReady: waitReadyOp,
339
+ listRequests: listRequestsOp,
323
340
  resumeSandbox: resumeSandboxOp,
324
341
  runCode: runCodeOp,
325
342
  createSnapshot: createSnapshotOp,
343
+ getStats: getStatsOp,
326
344
  createTicket: createTicketOp,
327
345
  setTimeout: setTimeoutOp,
328
346
  } as const;
@@ -917,6 +935,31 @@ export class SandboxesAPI extends Namespace {
917
935
  return this._client._call<T.ReadinessResult>(waitReadyOp, { path: [sandboxId], body }, options);
918
936
  }
919
937
 
938
+ /**
939
+ * List the requests a sandbox made
940
+ *
941
+ * Lists the requests code inside this sandbox made to B3OS in the last 7 days (its model calls, scrapes,
942
+ * searches and calls to other sandboxes), newest first, from the node's request log. These are the records
943
+ * `GET /v1/requests?sandbox_id=` lists, for a caller that may read the sandbox: it needs only `sandboxes:read`,
944
+ * not `platform:read`, and never returns another sandbox's records. It takes the same paging and the
945
+ * `product`, `operation_id`, `status`, `trace_id` and `since` filters; any other query parameter is
946
+ * `400 invalid_request`. Requests made to the sandbox's public ports are not listed. A sandbox stopped more
947
+ * than 7 days ago is not found.
948
+ *
949
+ * `GET /v1/sandboxes/{sandbox_id}/requests` · scope `sandboxes:read` · served by the node
950
+ */
951
+ listRequests(
952
+ sandboxId: string,
953
+ params?: T.SandboxesListRequestsParams,
954
+ options?: RequestOptions,
955
+ ): ListPromise<T.RequestRecordList, T.RequestRecord> {
956
+ return this._client._list<T.RequestRecordList, T.RequestRecord>(
957
+ listRequestsOp,
958
+ { path: [sandboxId], query: params },
959
+ options,
960
+ );
961
+ }
962
+
920
963
  /**
921
964
  * Resume a sandbox
922
965
  *
@@ -976,6 +1019,22 @@ export class SandboxesAPI extends Namespace {
976
1019
  return this._client._call<T.Snapshot>(createSnapshotOp, { path: [sandboxId], body }, options);
977
1020
  }
978
1021
 
1022
+ /**
1023
+ * Read what a sandbox uses now
1024
+ *
1025
+ * CPU, memory, disk and process counts of a running sandbox, read now and run no command in it. `cpu.percent`
1026
+ * is the share of all the sandbox's vCPUs that was busy over the last `cpu.interval_ms`: since your previous
1027
+ * stats read of this sandbox when that was 1 second to 5 minutes ago, else over 250 ms. Memory is the guest
1028
+ * kernel's own count (`MemTotal` and `MemAvailable`). `disk` (the root filesystem) and `processes.total` are
1029
+ * null in a sandbox whose image predates them. Poll it no faster than every 2 seconds. A paused or stopped
1030
+ * sandbox answers `409 sandbox_not_running`.
1031
+ *
1032
+ * `GET /v1/sandboxes/{sandbox_id}/stats` · scope `sandboxes:read` · served by the node
1033
+ */
1034
+ getStats(sandboxId: string, options?: RequestOptions): APIPromise<T.SandboxStats> {
1035
+ return this._client._call<T.SandboxStats>(getStatsOp, { path: [sandboxId] }, options);
1036
+ }
1037
+
979
1038
  /**
980
1039
  * Create a stream ticket
981
1040
  *