@b3os/sdk 0.2.2 → 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 (80) 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 +438 -11
  14. package/dist/cjs/generated/ns/agents.js +598 -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/listeners.d.ts +6 -2
  20. package/dist/cjs/generated/ns/listeners.js +6 -2
  21. package/dist/cjs/generated/ns/listeners.js.map +1 -1
  22. package/dist/cjs/generated/ns/routines.d.ts +11 -0
  23. package/dist/cjs/generated/ns/routines.js +11 -0
  24. package/dist/cjs/generated/ns/routines.js.map +1 -1
  25. package/dist/cjs/generated/ns/sandboxes.d.ts +140 -1
  26. package/dist/cjs/generated/ns/sandboxes.js +190 -1
  27. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  28. package/dist/cjs/generated/ns/vision.d.ts +55 -1
  29. package/dist/cjs/generated/ns/vision.js +94 -1
  30. package/dist/cjs/generated/ns/vision.js.map +1 -1
  31. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  32. package/dist/cjs/generated/ns/workspaces.js +410 -0
  33. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  34. package/dist/cjs/generated/types.d.ts +2230 -72
  35. package/dist/esm/core/util.d.ts +1 -1
  36. package/dist/esm/core/util.js +1 -1
  37. package/dist/esm/generated/client.d.ts +5 -0
  38. package/dist/esm/generated/client.js +9 -0
  39. package/dist/esm/generated/client.js.map +1 -1
  40. package/dist/esm/generated/errors.d.ts +1 -1
  41. package/dist/esm/generated/errors.js +45 -0
  42. package/dist/esm/generated/errors.js.map +1 -1
  43. package/dist/esm/generated/ids.d.ts +28 -0
  44. package/dist/esm/generated/ids.js +7 -0
  45. package/dist/esm/generated/ids.js.map +1 -1
  46. package/dist/esm/generated/ns/agents.d.ts +438 -11
  47. package/dist/esm/generated/ns/agents.js +598 -11
  48. package/dist/esm/generated/ns/agents.js.map +1 -1
  49. package/dist/esm/generated/ns/images.d.ts +84 -3
  50. package/dist/esm/generated/ns/images.js +126 -2
  51. package/dist/esm/generated/ns/images.js.map +1 -1
  52. package/dist/esm/generated/ns/listeners.d.ts +6 -2
  53. package/dist/esm/generated/ns/listeners.js +6 -2
  54. package/dist/esm/generated/ns/listeners.js.map +1 -1
  55. package/dist/esm/generated/ns/routines.d.ts +11 -0
  56. package/dist/esm/generated/ns/routines.js +11 -0
  57. package/dist/esm/generated/ns/routines.js.map +1 -1
  58. package/dist/esm/generated/ns/sandboxes.d.ts +140 -1
  59. package/dist/esm/generated/ns/sandboxes.js +190 -1
  60. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  61. package/dist/esm/generated/ns/vision.d.ts +55 -1
  62. package/dist/esm/generated/ns/vision.js +94 -1
  63. package/dist/esm/generated/ns/vision.js.map +1 -1
  64. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  65. package/dist/esm/generated/ns/workspaces.js +406 -0
  66. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  67. package/dist/esm/generated/types.d.ts +2230 -72
  68. package/package.json +1 -1
  69. package/src/core/util.ts +1 -1
  70. package/src/generated/client.ts +10 -0
  71. package/src/generated/errors.ts +90 -0
  72. package/src/generated/ids.ts +7 -0
  73. package/src/generated/ns/agents.ts +652 -11
  74. package/src/generated/ns/images.ts +131 -3
  75. package/src/generated/ns/listeners.ts +6 -2
  76. package/src/generated/ns/routines.ts +11 -0
  77. package/src/generated/ns/sandboxes.ts +203 -1
  78. package/src/generated/ns/vision.ts +101 -1
  79. package/src/generated/ns/workspaces.ts +448 -0
  80. package/src/generated/types.ts +2416 -48
@@ -34,6 +34,11 @@ export type Scope =
34
34
  | "routines:run"
35
35
  | "listeners:read"
36
36
  | "listeners:write"
37
+ | "workspaces:read"
38
+ | "workspaces:write"
39
+ | "workspaces:run"
40
+ | "workspaces:rules:write"
41
+ | "workspaces:subjects:assert"
37
42
  | "actions:read"
38
43
  | "actions:write"
39
44
  | "actions:run"
@@ -55,6 +60,7 @@ export type Scope =
55
60
  | "agents:*"
56
61
  | "routines:*"
57
62
  | "listeners:*"
63
+ | "workspaces:*"
58
64
  | "actions:*"
59
65
  | "infer:*"
60
66
  | "vault:*"
@@ -139,6 +145,18 @@ export interface Problem {
139
145
  limit?: LimitRef;
140
146
  /** The object's current status, for state conflicts such as `sandbox_not_running`. */
141
147
  current_status?: string;
148
+ /** The branch's head now (`head_moved`). */
149
+ current_head?: string;
150
+ /** The workspace paths the code is about (`path_not_writable`, `append_only_violation`), at most 100. */
151
+ paths?: string[];
152
+ /** Every path a merge could not combine (`merge_conflict`), with the blob IDs of the three sides. */
153
+ conflicts?: {
154
+ path: string;
155
+ kind: "content" | "binary" | "delete_modify" | "add_add" | "type";
156
+ base: string | null;
157
+ ours: string | null;
158
+ theirs: string | null;
159
+ }[];
142
160
  /** The sandbox that holds a lease's key now, or null when none does (`lease_holder_changed`). */
143
161
  holder?: string | null;
144
162
  /** The head of the linked branch now (`manifest_changed`). */
@@ -630,7 +648,7 @@ export type ScrapeRequest = {
630
648
  * `hosts` list the proxy's host (needs `vault:run`).
631
649
  * A URL with a username or password is refused (`400 invalid_request`): put them in a connection. This node
632
650
  * takes `http://` proxies only; plain HTTP means the username and password cross the network to your proxy
633
- * unencrypted. Batches, crawls, sessions and the Firecrawl surface do not take `proxy` yet.
651
+ * unencrypted. Batches, crawls and the Firecrawl surface do not take `proxy` yet; sessions take it with `stealth` only.
634
652
  */
635
653
  export type ProxyOption =
636
654
  | "none"
@@ -1146,8 +1164,130 @@ export interface SessionCreateRequest {
1146
1164
  * @default false
1147
1165
  */
1148
1166
  thumbnails?: boolean;
1167
+ /**
1168
+ * `microvm`: the session's browser runs in a microVM of its own (2 vCPU, 2 GiB, full Chrome with its own sandbox, a fresh random seed, machine ID and clock), or the create is refused with `503 capacity_unavailable` and `Retry-After: 1` when the node has none ready. `process`: the node's browser pool. Without it, the node decides (`process` on every node today).
1169
+ */
1170
+ isolation?: SessionIsolation;
1171
+ stealth?: StealthOption;
1172
+ /**
1173
+ * Where a stealth session leaves from (`vision.proxy`); only with `stealth`, else `400 invalid_request`.
1174
+ * `none` (the default): the node's own address, and the session carries the `exit_direct` warning. A
1175
+ * proxy URL or `{url, connection}`: your own proxy, as on a scrape, kept for the whole session (one exit,
1176
+ * never rotated). `auto` and `residential` answer `422 option_not_allowed` with `bound_by: catalog`: stealth
1177
+ * sessions never use the residential network.
1178
+ */
1179
+ proxy?: ProxyOption;
1180
+ }
1181
+
1182
+ /**
1183
+ * A stealth session (`vision.stealth`, needs the flag for your organization and the stealth terms accepted by
1184
+ * an owner; else `422 option_not_allowed` with `bound_by: org`). The browser runs headful in a microVM of its
1185
+ * own, keeps one consistent identity (screen, window, fonts, input style), and takes its time zone and locale
1186
+ * from where its exit is. `true` is `{}`; `false` or no member is an ordinary session. It implies `isolation:
1187
+ * microvm` (`process` is `400`), runs engine `chrome` (`headless-shell` is `400`), and sets the window, locale
1188
+ * and time zone itself (`viewport`, `locale`, `timezone`, `user_agent` and `block_resources` are `400`).
1189
+ */
1190
+ export type StealthOption =
1191
+ | boolean
1192
+ | {
1193
+ /**
1194
+ * An identity to reuse. Omitted: the profile's identity when `profile` names one that has one, else a new identity.
1195
+ */
1196
+ identity?: string;
1197
+ /**
1198
+ * The identity's home region, a country (`US`) or a country and a subdivision (`us-ny`). Omitted: the identity's, else where the exit is. The time zone and locale always follow where the exit actually is; a session whose exit is elsewhere carries the `exit_region_changed` warning.
1199
+ */
1200
+ region?: string;
1201
+ /**
1202
+ * Act steps (click, hover, type, key, and scroll without a target) send their input through the browser's own screen, shaped like a person's: pointer paths, key presses with their timing, wheel scrolling. Slower: a click takes hundreds of milliseconds. `false`: the default session's input.
1203
+ * @default true
1204
+ */
1205
+ humanize?: boolean;
1206
+ };
1207
+
1208
+ /** What a stealth session's browser presents and where it leaves from. */
1209
+ export interface SessionStealth {
1210
+ identity: string;
1211
+ persona: {
1212
+ os: "linux";
1213
+ browser: "chrome";
1214
+ /** The running browser's major version. */
1215
+ major: number;
1216
+ screen: string;
1217
+ locale: string;
1218
+ timezone: string;
1219
+ };
1220
+ exit: {
1221
+ /** `byo`: your proxy. `direct`: the node's address. */
1222
+ class: "byo" | "direct";
1223
+ /** Where the exit is (ISO 3166-1 alpha-2), as measured when the session started. */
1224
+ country?: string;
1225
+ region?: string;
1226
+ };
1227
+ /** The stealth engine's stage (1 today). */
1228
+ stage: number;
1229
+ /**
1230
+ * What undoes part of stealth and B3OS cannot fix on its side: `exit_direct` (the node's address, a datacenter range), `exit_region_changed` (the exit is outside the identity's home region), `client_runtime_enable` (a CDP client enabled the `Runtime` domain on a page, which pages can observe).
1231
+ */
1232
+ warnings: string[];
1233
+ }
1234
+
1235
+ export interface StealthAudit {
1236
+ object: "stealth_audit";
1237
+ session_id: string;
1238
+ /**
1239
+ * In order. Every line has `t` (RFC 3339) and `kind`: `open`, `connection`, `navigation`, `challenge`, `refused`, `warning`, `act` or `close`, and the members of its kind.
1240
+ */
1241
+ lines: {
1242
+ t: string;
1243
+ kind: string;
1244
+ [key: string]: unknown;
1245
+ }[];
1149
1246
  }
1150
1247
 
1248
+ /**
1249
+ * A stealth identity: what a stealth session's browser presents (drawn once and kept, so every session that uses it presents the same), its home region, and how it was used. It holds no cookies and no secret.
1250
+ */
1251
+ export interface StealthIdentity {
1252
+ id: string;
1253
+ object: "stealth_identity";
1254
+ state: "active" | "retired";
1255
+ persona: {
1256
+ /** The persona catalog's version it was drawn from. */
1257
+ catalog: number;
1258
+ os: "linux";
1259
+ browser: "chrome";
1260
+ /** The screen in CSS pixels. */
1261
+ screen: string;
1262
+ device_scale_factor: number;
1263
+ window: {
1264
+ x: number;
1265
+ y: number;
1266
+ width: number;
1267
+ height: number;
1268
+ maximized: boolean;
1269
+ };
1270
+ /** The font families its browser sees. */
1271
+ fonts: string[];
1272
+ };
1273
+ /** `us` or `us-ny`; `null` until a session names one or its first exit sets it. */
1274
+ home_region: string | null;
1275
+ /** Stealth sessions that used it. */
1276
+ sessions: number;
1277
+ created_at: string;
1278
+ last_used_at: string | null;
1279
+ retired_at: string | null;
1280
+ }
1281
+
1282
+ export type StealthIdentityList = Omit<ListEnvelope, "data"> & {
1283
+ data: StealthIdentity[];
1284
+ };
1285
+
1286
+ /**
1287
+ * Where a session's browser runs: `process`, a browser of the node's pool (one browser per session, never shared); `microvm`, a microVM of its own.
1288
+ */
1289
+ export type SessionIsolation = "process" | "microvm";
1290
+
1151
1291
  export interface SessionTimeline {
1152
1292
  object: "session_timeline";
1153
1293
  session_id: string;
@@ -1253,12 +1393,17 @@ export interface BrowserSession {
1253
1393
  * Why the session closed; `null` while it is active. `deleted`: `DELETE`. `expired`: its timeout.
1254
1394
  * `browser_exited`: its browser stopped under it. `node_restart`: the node stopped or restarted while the
1255
1395
  * session was open; browser time is billed up to the stop and not after it (nothing when the node did not
1256
- * stop cleanly, since it cannot tell when the browser stopped). Closed sessions stay readable for 7 days.
1396
+ * stop cleanly, since it cannot tell when the browser stopped). `stealth_revoked`: a stealth session whose
1397
+ * organization lost the `vision.stealth` flag or its acceptance of the stealth terms. Closed sessions stay
1398
+ * readable for 7 days.
1257
1399
  */
1258
- closed_reason?: "deleted" | "expired" | "browser_exited" | "node_restart" | null;
1400
+ closed_reason?: "deleted" | "expired" | "browser_exited" | "node_restart" | "stealth_revoked" | null;
1259
1401
  timeout_s: number;
1260
1402
  viewport: Viewport;
1261
1403
  browser: BrowserEngine;
1404
+ isolation: SessionIsolation;
1405
+ /** Present on stealth sessions only. */
1406
+ stealth?: SessionStealth;
1262
1407
  /** The loaded profile, or `null`. */
1263
1408
  profile: null | SessionProfileRef;
1264
1409
  /** WebSocket URL of the session's CDP endpoint. */
@@ -1605,6 +1750,10 @@ export interface Profile {
1605
1750
  * Whether GET /v1/vision/profiles/{id}/state exports the state. True when the current state was uploaded; false when a B3OS browser session saved it: such state still loads into the organization's sessions, scrapes and render jobs, but the state route answers 403 profile_not_exportable. The flag governs that route only: a session's CDP client with vision:profiles:export reads the cookies of a profile the session loaded, and scripts in its pages read what the page's own scripts can. An upload makes a profile exportable again.
1606
1751
  */
1607
1752
  exportable: boolean;
1753
+ /**
1754
+ * The stealth identity bound to this profile: a stealth session that loaded the profile with persist_profile saved it here, and later stealth sessions that load the profile use it unless they name another. Absent on a profile no stealth session saved.
1755
+ */
1756
+ identity?: string;
1608
1757
  /** Owning org. Returned to the owner only; tenancy is checked on every access. */
1609
1758
  org?: string;
1610
1759
  project?: string;
@@ -4221,7 +4370,7 @@ export type RenderBackgroundPackList = Omit<ListEnvelope, "data"> & {
4221
4370
  };
4222
4371
 
4223
4372
  /**
4224
- * `running` → `paused` ↔ `running` → `stopped`. `failed` means the microVM crashed; its usage is final. `hibernated` is an agent instance's microVM written to the node's disk with no process left (only agent instances, `/v1/agents`): its memory snapshot, which a message to its instance or a request to its port restores in place, or its disk alone (dormant), which a message to its instance boots. It is never listed.
4373
+ * `running` → `paused` ↔ `running` → `stopped`. `failed` means the microVM crashed; its usage is final. `hibernated` is a microVM written to the node's disk with no process left. For an agent instance (`/v1/agents`), never listed: its memory snapshot, which a message to its instance or a request to its port restores in place, or its disk alone (dormant), which a message to its instance boots. For a project's service that holds a lease, listed, with `restore`: its microVM ended without anyone asking (a node restart or release, a lost VM), and the node boots it again in place from its kept disk, with the same ID, volume and lease; a request to its port answers 503 `sandbox_restoring` meanwhile.
4225
4374
  */
4226
4375
  export type SandboxStatus = "running" | "paused" | "stopped" | "failed" | "hibernated";
4227
4376
 
@@ -4332,7 +4481,8 @@ export interface EgressPolicy {
4332
4481
  export interface SandboxCreateRequest {
4333
4482
  /**
4334
4483
  * Template name or `tpl_` ID: a node template (`GET /v1/sandboxes/templates`) or one of your project's
4335
- * image templates (an image's `template`). Ignored when `snapshot` is set.
4484
+ * image templates (an image's `template`, or its `name`; a name of an image that is not `ready` answers
4485
+ * `409 image_not_ready`). Node templates are looked up first. Ignored when `snapshot` is set.
4336
4486
  * @default "base"
4337
4487
  */
4338
4488
  template?: string;
@@ -4425,6 +4575,17 @@ export interface SandboxCreateRequest {
4425
4575
  * volume is free for the next sandbox once the microVM has exited.
4426
4576
  */
4427
4577
  volumes?: VolumeAttach[];
4578
+ /**
4579
+ * A workspace branch to mount (`POST /v1/workspaces`), at most one in this beta. Behind the `workspaces.api`
4580
+ * flag: `403 feature_not_enabled` while it is off for your organization. The branch's head is mounted at
4581
+ * `path` as a copy-on-write folder: the base files are shared and read-only underneath, and what the sandbox
4582
+ * writes there is the branch's change set, kept on the sandbox's disk until it is committed. Commands see
4583
+ * `B3OS_WORKSPACE_ID`, `B3OS_BRANCH_ID` and `B3OS_WORKSPACE_PATH`. Holding a protected branch (`main`) needs
4584
+ * `workspaces:write`, any other branch `workspaces:run`. A branch with no commit yet is `422
4585
+ * workspace_invalid` (reason `empty`). In this beta a sandbox with a workspace cannot be snapshotted (`409
4586
+ * conflict`), and `snapshot` and `forkable: true` are refused with it (`400 invalid_request`).
4587
+ */
4588
+ workspaces?: SandboxWorkspaceAttach[];
4428
4589
  owner?: SandboxOwner;
4429
4590
  metadata?: Metadata;
4430
4591
  }
@@ -4440,6 +4601,37 @@ export interface VolumeAttach {
4440
4601
  owner?: string;
4441
4602
  }
4442
4603
 
4604
+ export interface SandboxWorkspaceAttach {
4605
+ /** The workspace's `ws_` ID. */
4606
+ workspace: string;
4607
+ /**
4608
+ * An open branch's `br_` ID or name, or `new` (a new ephemeral branch from `from`).
4609
+ * @default "new"
4610
+ */
4611
+ branch?: string;
4612
+ /**
4613
+ * Where a new branch starts: a branch name or ID, or a `cmt_` commit ID; `main` when unset. Only with a new
4614
+ * branch (`400 invalid_request` otherwise).
4615
+ */
4616
+ from?: string;
4617
+ /**
4618
+ * Where the branch appears in the sandbox: absolute, and not a system folder or under one (the rules of a
4619
+ * volume mount's `path`); never overlapping a volume mount.
4620
+ * @default "/workspace"
4621
+ */
4622
+ path?: string;
4623
+ }
4624
+
4625
+ export interface SandboxWorkspace {
4626
+ workspace_id: string;
4627
+ branch_id: string;
4628
+ /** `ephemeral/<branch_id>` for a branch the create made. */
4629
+ branch_name: string;
4630
+ /** The commit the sandbox's base files are (the branch's head when the sandbox was created). */
4631
+ commit_id: string;
4632
+ path: string;
4633
+ }
4634
+
4443
4635
  export interface VolumeMount {
4444
4636
  /**
4445
4637
  * Where the folder appears in the sandbox: absolute, not `/`, not a system folder or under one (`/proc`,
@@ -4672,6 +4864,7 @@ export interface Sandbox {
4672
4864
  * running and renews its `expires_at` itself. `null` when it never held one. Always sent by this node.
4673
4865
  */
4674
4866
  lease?: null | SandboxLease;
4867
+ restore?: SandboxRestore;
4675
4868
  /**
4676
4869
  * The processes the node supervises (an exec with `background: true` and `restart`), oldest first; empty
4677
4870
  * when there are none. Always sent by this node.
@@ -4679,6 +4872,8 @@ export interface Sandbox {
4679
4872
  supervised?: SupervisedProcess[];
4680
4873
  /** The volume the sandbox holds and where it is mounted; empty when none. Always sent by this node. */
4681
4874
  volumes?: SandboxVolume[];
4875
+ /** The workspace branch the sandbox holds and where it is mounted; present only when it holds one. */
4876
+ workspaces?: SandboxWorkspace[];
4682
4877
  options: SandboxOptions;
4683
4878
  owner?: SandboxOwner;
4684
4879
  /**
@@ -4727,6 +4922,13 @@ export interface LeaseRequest {
4727
4922
  * that already holds `key` answers 200 whatever this says.
4728
4923
  */
4729
4924
  expect_holder?: string | null;
4925
+ /**
4926
+ * The order the node boots the project's services again in place after it loses their microVMs (a node
4927
+ * restart or release): higher first, and a service waits up to 2 minutes while one of its project with a
4928
+ * higher priority is not running and ready yet, so a database comes back before the app that uses it.
4929
+ * Default 0. Sent again with the same `key`, it changes only the priority.
4930
+ */
4931
+ restore_priority?: number;
4730
4932
  }
4731
4933
 
4732
4934
  /** A sandbox's lease, held or ended. */
@@ -4743,6 +4945,49 @@ export interface SandboxLease {
4743
4945
  * one then stops within `sandboxes.lease_term`), or the sandbox's `stop_reason`.
4744
4946
  */
4745
4947
  end_reason: "released" | "replaced" | "deleted" | "timeout" | "failed" | "budget" | "revoked" | null;
4948
+ /** The lease's restore priority (`PUT …/lease`); 0 by default. */
4949
+ restore_priority?: number;
4950
+ }
4951
+
4952
+ /**
4953
+ * Present only for a project's service the node kept through the loss of its microVM: one that holds a lease
4954
+ * (`PUT …/lease`; not an agent instance, not started by another sandbox, no workspace, and `secrets` only as
4955
+ * connection references, which its boot reveals again while the edge says their creator still may). When its
4956
+ * microVM ends without anyone asking (a node restart or release, a VM lost while the node runs, a VM gone when
4957
+ * the node starts), the node keeps its disk and boots it again in place: the same ID (so its addresses need no
4958
+ * switch), its disk, its volume, its lease and its supervised processes, which start again. Boots back off 0,
4959
+ * 10, 60, 300 and 900 s; a boot whose VM is lost again within 10 minutes counts as failed; after 5 in a row the
4960
+ * node gives up and the sandbox ends `failed`. While it has no VM it bills no compute.
4961
+ */
4962
+ export interface SandboxRestore {
4963
+ /** Why its last microVM ended. */
4964
+ cause: "node_stop" | "vm_lost" | "vm_gone_at_start";
4965
+ /**
4966
+ * `clean`: the disk was copied after TERM to its supervised processes, its volume's release and a sync;
4967
+ * `crash`: copied while the guest ran or after its VM died, so writes the guest had not synced may be
4968
+ * missing (as after a power cut).
4969
+ */
4970
+ consistency: "clean" | "crash";
4971
+ state: "waiting" | "booting" | "booted" | "gave_up";
4972
+ /** When its last microVM ended. */
4973
+ since: string;
4974
+ /** Boots begun since its last run of 10 minutes. */
4975
+ attempts: number;
4976
+ /** When the next boot may begin; `null` while it boots, once booted, and once given up. */
4977
+ next_at: string | null;
4978
+ booted_at: string | null;
4979
+ /** When the node gave up booting it (the sandbox ended `failed`). */
4980
+ gave_up_at: string | null;
4981
+ /** Why the last boot failed, or why the node gave up. */
4982
+ last_error: string | null;
4983
+ /**
4984
+ * For a service with `secrets` (connection references), why the node did not reveal them again:
4985
+ * `restore_grant_revoked`, the edge said the principal that revealed them at its create no longer may (its
4986
+ * key revoked or expired, its user removed, its scopes cut, its application unlinked; the sandbox ends
4987
+ * `stopped`, `revoked`); `restore_grant_unknown`, the edge could not say, through every boot of the backoff
4988
+ * (it ends `failed`). The node never keeps a secret's value, only its reference.
4989
+ */
4990
+ reason?: "restore_grant_revoked" | "restore_grant_unknown" | null;
4746
4991
  }
4747
4992
 
4748
4993
  /** A background process the node starts again when it exits (an exec with `restart`). */
@@ -5088,6 +5333,239 @@ export type SnapshotList = Omit<ListEnvelope, "data"> & {
5088
5333
  data: Snapshot[];
5089
5334
  };
5090
5335
 
5336
+ /** How many more sandboxes of one shape would be created now, and the limits behind the count. */
5337
+ export interface SandboxCapacity {
5338
+ object: "sandbox_capacity";
5339
+ /** The template's name. */
5340
+ template: string;
5341
+ vcpu: number;
5342
+ memory_mib: number;
5343
+ /**
5344
+ * Creates of this shape that would pass now; the least of `org`, `desktops` (desktop templates only) and `node.room`.
5345
+ */
5346
+ room: number;
5347
+ /** The limit that refuses the next create when `room` is 0; `null` while a create would pass. */
5348
+ binding: "org_concurrency" | "desktops" | "node" | null;
5349
+ org: CapacityCount;
5350
+ desktops: CapacityCount;
5351
+ node: {
5352
+ /** Sandboxes of this shape waiting warm in the node's pool. */
5353
+ parked: number;
5354
+ /**
5355
+ * Sandboxes of this shape the memory left under the node's microVM memory limit holds, or 0 while the node's disk store is too full; `null` when the node cannot read the limit.
5356
+ */
5357
+ room: number | null;
5358
+ };
5359
+ /** When `room` is 0, how long to wait before trying again. */
5360
+ retry_after_s?: number;
5361
+ }
5362
+
5363
+ /**
5364
+ * Your organization's live sandboxes against one limit (`sandboxes.concurrent` or `sandboxes.desktops_concurrent`).
5365
+ */
5366
+ export interface CapacityCount {
5367
+ /** Running and paused sandboxes, and creates in flight. */
5368
+ running: number;
5369
+ limit: number;
5370
+ }
5371
+
5372
+ export interface Computer {
5373
+ object: "computer";
5374
+ display: {
5375
+ width: number;
5376
+ height: number;
5377
+ };
5378
+ cursor: ComputerPoint;
5379
+ /**
5380
+ * Who controls the desktop's input: `agent` (the computer-use operations) or `human` (a person who took over, which is not built yet). Always `agent` for now.
5381
+ */
5382
+ controller: "agent" | "human";
5383
+ }
5384
+
5385
+ /** A position on the screen, in pixels from the top left. */
5386
+ export interface ComputerPoint {
5387
+ x: number;
5388
+ y: number;
5389
+ }
5390
+
5391
+ export interface ComputerScreenshotOptions {
5392
+ /** @default "jpeg" */
5393
+ format?: "png" | "jpeg";
5394
+ /**
5395
+ * JPEG quality.
5396
+ * @default 80
5397
+ */
5398
+ quality?: number;
5399
+ }
5400
+
5401
+ /** Before the screenshot, wait until the screen has not changed for `quiet_ms`, at most `max_ms`. */
5402
+ export interface ComputerSettle {
5403
+ /** @default 80 */
5404
+ quiet_ms?: number;
5405
+ /** @default 1000 */
5406
+ max_ms?: number;
5407
+ }
5408
+
5409
+ export interface ComputerActRequest {
5410
+ /** Run in order. Their `wait` actions add up to at most 30,000 ms. */
5411
+ actions: ComputerAction[];
5412
+ /** A screenshot after the actions; `null` or left out for none. */
5413
+ screenshot?: ComputerScreenshotOptions | null;
5414
+ /** Wait for the screen to settle before the screenshot; `null` or left out for no wait. */
5415
+ settle?: ComputerSettle | null;
5416
+ }
5417
+
5418
+ /** One mouse or keyboard action; `action` selects it. */
5419
+ export type ComputerAction =
5420
+ | ComputerClick
5421
+ | ComputerMove
5422
+ | ComputerMouseDown
5423
+ | ComputerMouseUp
5424
+ | ComputerDrag
5425
+ | ComputerScroll
5426
+ | ComputerType
5427
+ | ComputerKey
5428
+ | ComputerKeyDown
5429
+ | ComputerKeyUp
5430
+ | ComputerWait
5431
+ | ComputerCursorPosition;
5432
+
5433
+ /** Pixels from the left (`x`) or the top (`y`); within the screen. */
5434
+ export type ComputerCoordinate = number;
5435
+
5436
+ export type ComputerButton = "left" | "right" | "middle";
5437
+
5438
+ /**
5439
+ * Click at `x`, `y` (both or neither; neither clicks at the pointer). `count` 2 is a double click, 3 a triple click.
5440
+ */
5441
+ export interface ComputerClick {
5442
+ action: "click";
5443
+ x?: ComputerCoordinate;
5444
+ y?: ComputerCoordinate;
5445
+ button?: ComputerButton;
5446
+ /** @default 1 */
5447
+ count?: number;
5448
+ }
5449
+
5450
+ /** Move the pointer. */
5451
+ export interface ComputerMove {
5452
+ action: "move";
5453
+ x: ComputerCoordinate;
5454
+ y: ComputerCoordinate;
5455
+ }
5456
+
5457
+ /** Press a button, at `x`, `y` or at the pointer, and hold it. */
5458
+ export interface ComputerMouseDown {
5459
+ action: "mouse_down";
5460
+ x?: ComputerCoordinate;
5461
+ y?: ComputerCoordinate;
5462
+ button?: ComputerButton;
5463
+ }
5464
+
5465
+ /** Release a button, at `x`, `y` or at the pointer. */
5466
+ export interface ComputerMouseUp {
5467
+ action: "mouse_up";
5468
+ x?: ComputerCoordinate;
5469
+ y?: ComputerCoordinate;
5470
+ button?: ComputerButton;
5471
+ }
5472
+
5473
+ /**
5474
+ * Press the button at the first point, move through the others and release at the last. The button is released if the drag fails part way.
5475
+ */
5476
+ export interface ComputerDrag {
5477
+ action: "drag";
5478
+ /** `[[x, y], ...]`, 2 to 64 points. */
5479
+ path: ComputerCoordinate[][];
5480
+ button?: ComputerButton;
5481
+ }
5482
+
5483
+ /** Turn the wheel `amount` clicks, at `x`, `y` or at the pointer. */
5484
+ export interface ComputerScroll {
5485
+ action: "scroll";
5486
+ x?: ComputerCoordinate;
5487
+ y?: ComputerCoordinate;
5488
+ direction: "up" | "down" | "left" | "right";
5489
+ /** @default 1 */
5490
+ amount?: number;
5491
+ }
5492
+
5493
+ /** Type the text, as a keyboard would (newline and tab included). The node logs its length only. */
5494
+ export interface ComputerType {
5495
+ action: "type";
5496
+ /** At most 8,192 bytes of UTF-8; no control characters other than newline, carriage return and tab. */
5497
+ text: string;
5498
+ }
5499
+
5500
+ /** Press and release a key or a chord of xdotool key names joined by `+`. */
5501
+ export interface ComputerKey {
5502
+ action: "key";
5503
+ keys: string;
5504
+ }
5505
+
5506
+ /** Press one key and hold it until `key_up` (or the end of a batch that fails). */
5507
+ export interface ComputerKeyDown {
5508
+ action: "key_down";
5509
+ key: string;
5510
+ }
5511
+
5512
+ /** Release a held key. */
5513
+ export interface ComputerKeyUp {
5514
+ action: "key_up";
5515
+ key: string;
5516
+ }
5517
+
5518
+ /** Wait */
5519
+ export interface ComputerWait {
5520
+ action: "wait";
5521
+ ms: number;
5522
+ }
5523
+
5524
+ /** Sends no input; the answer's `cursor` is the pointer's position. */
5525
+ export interface ComputerCursorPosition {
5526
+ action: "cursor_position";
5527
+ }
5528
+
5529
+ export interface ComputerActResult {
5530
+ object: "computer_actions";
5531
+ /** One per action, in order. */
5532
+ results: ComputerActionResult[];
5533
+ /** Where the pointer is after the actions; `null` when the X server went away during the batch. */
5534
+ cursor: ComputerPoint | null;
5535
+ /** The screenshot asked for; `null` when none was asked for or it could not be taken. */
5536
+ screenshot: ScreenshotData | null;
5537
+ /** How long the settle waited, ms; `null` without `settle`. */
5538
+ settled_ms: number | null;
5539
+ /** `quiet`: the screen stayed still for `quiet_ms`; `deadline`: `max_ms` passed first. */
5540
+ settled_by: "quiet" | "deadline" | null;
5541
+ /** Time inside the sandbox, ms. */
5542
+ timing: {
5543
+ act_ms: number;
5544
+ settle_ms: number;
5545
+ capture_ms: number;
5546
+ encode_ms: number;
5547
+ };
5548
+ }
5549
+
5550
+ export interface ComputerActionResult {
5551
+ ok: boolean;
5552
+ /**
5553
+ * Whether the action's input reached the X server. `delivered_unverified`: sent and synced; what the
5554
+ * application did with it is not checked. `delivery_uncertain`: part of it may have been sent.
5555
+ * `not_delivered`: nothing was sent (the action failed before its input, was skipped, or sends no input:
5556
+ * `wait`, `cursor_position`). `unknown`: the X server went away after the input was sent.
5557
+ */
5558
+ delivery: "delivered_verified" | "delivered_unverified" | "delivery_uncertain" | "not_delivered" | "unknown";
5559
+ /**
5560
+ * Whether sending the action again is safe. `safe`: nothing was sent, or the action does the same thing
5561
+ * twice (`move`, `wait`, `cursor_position`). `unsafe`: its input landed and a second send repeats it.
5562
+ * `unknown`: whether its input landed cannot be told.
5563
+ */
5564
+ retry: "safe" | "unsafe" | "unknown";
5565
+ /** Why the action failed; `null` when it did not. */
5566
+ error: string | null;
5567
+ }
5568
+
5091
5569
  export interface Template {
5092
5570
  id: string;
5093
5571
  object: "template";
@@ -5097,9 +5575,10 @@ export interface Template {
5097
5575
  runtimes: string[];
5098
5576
  /**
5099
5577
  * `cdp`: Chrome runs in the template's snapshot with DevTools on `127.0.0.1:9222` inside the sandbox; declare
5100
- * port 9222 to reach it through a port preview.
5578
+ * port 9222 to reach it through a port preview. `computer`: the sandbox has a screen, a mouse and a keyboard
5579
+ * that `/v1/sandboxes/{sandbox_id}/computer` reads and drives (the `desktop` template).
5101
5580
  */
5102
- capabilities: Array<"exec" | "files" | "pty" | "run_code" | "cdp">;
5581
+ capabilities: Array<"exec" | "files" | "pty" | "run_code" | "cdp" | "computer">;
5103
5582
  defaults: {
5104
5583
  vcpu: number;
5105
5584
  memory_mib: number;
@@ -5116,8 +5595,8 @@ export interface Template {
5116
5595
  }[];
5117
5596
  /**
5118
5597
  * `node`: one of the node's templates, the same for everyone. `project`: an imported image's template,
5119
- * which only its project sees and can start sandboxes from. An image template's `name` is its `tpl_` ID and
5120
- * it has one size (`size_classes` holds only the image's).
5598
+ * which only its project sees and can start sandboxes from. An image template's `name` is its image's
5599
+ * `name` when it has one, else its `tpl_` ID, and it has one size (`size_classes` holds only the image's).
5121
5600
  */
5122
5601
  owner: "node" | "project";
5123
5602
  /** The image this template was imported from (`owner: project`); `null` for node templates. */
@@ -5131,6 +5610,41 @@ export interface Template {
5131
5610
  agent_sha256?: string;
5132
5611
  }
5133
5612
 
5613
+ /**
5614
+ * Exactly one of `image` (an import) and `build` (a Dockerfile build); the rest as `POST /v1/images` takes it.
5615
+ */
5616
+ export type TemplateCreateRequest = {
5617
+ name?: ImageName;
5618
+ /** An image reference, as `ref` of `POST /v1/images` (`python:3.11-slim`); a private one needs `auth`. */
5619
+ image?: string;
5620
+ build?: ImageBuild;
5621
+ auth?: ImageRegistryAuth;
5622
+ warmup?: ImageWarmup;
5623
+ /** The size every sandbox from the template has. Default 1, at most your plan's `sandboxes.vcpu_max`. */
5624
+ vcpu?: number;
5625
+ /**
5626
+ * The memory every sandbox from the template has. Default 1024, at most your plan's `sandboxes.memory_max`.
5627
+ */
5628
+ memory_mib?: number;
5629
+ };
5630
+
5631
+ /**
5632
+ * A template made by `POST /v1/sandboxes/templates`: its image's template, from the image's start. Once the image is `ready`, `GET /v1/sandboxes/templates/{template}` returns the whole template.
5633
+ */
5634
+ export interface TemplateCreated {
5635
+ id: string;
5636
+ object: "template";
5637
+ /** The image's name, else `null` (then the template is started by its ID). */
5638
+ name: null | ImageName;
5639
+ status: ImageStatus;
5640
+ /** The image (`GET /v1/images/{image_id}?wait=30` until it is `ready`). */
5641
+ image: string;
5642
+ /** The image's flattened root file system, once stored. */
5643
+ rootfs_sha256: string | null;
5644
+ /** The image's key; the same request in this project answers this template. */
5645
+ key: string;
5646
+ }
5647
+
5134
5648
  export type TemplateList = Omit<ListEnvelope, "data"> & {
5135
5649
  data: Template[];
5136
5650
  };
@@ -5296,7 +5810,7 @@ export type SwarmEvent = JobEvent & {
5296
5810
  };
5297
5811
 
5298
5812
  /**
5299
- * `queued` (accepted, waiting for the queue), `pulling` (layers streaming into the unpacking microVM),
5813
+ * `queued` (accepted, waiting for the queue), `building` (a Dockerfile build running in its microVM), `pulling` (layers streaming into the unpacking microVM),
5300
5814
  * `flattening` (the last byte sent; waiting for the unpacker and the store), `warming` (the first boot, the
5301
5815
  * warm-up and the warm snapshot), `ready`. `rebuilding`: a node release changed the guest agent, kernel or
5302
5816
  * hypervisor, and the warm snapshot is being taken again (creates answer `409 image_not_ready` until it is
@@ -5305,6 +5819,7 @@ export type SwarmEvent = JobEvent & {
5305
5819
  */
5306
5820
  export type ImageStatus =
5307
5821
  | "queued"
5822
+ | "building"
5308
5823
  | "pulling"
5309
5824
  | "flattening"
5310
5825
  | "warming"
@@ -5322,14 +5837,35 @@ export interface ImageWarmup {
5322
5837
  commands: string[][];
5323
5838
  }
5324
5839
 
5325
- export interface ImageImportRequest {
5840
+ /**
5841
+ * The project's name for the image (`images.build`): `name[:tag]`, at most 64 characters in all, each part of
5842
+ * lowercase letters, digits, `.`, `_` and `-` and starting with a letter or a digit, the name not starting
5843
+ * with `tpl_`. The whole string is the name (`app` and `app:latest` are two names). `POST /v1/sandboxes
5844
+ * {"template": "<name>"}` starts from it in this project only; another project's name answers `404
5845
+ * template_not_found`. Unique among the project's images, never a node template's name (`base` nor
5846
+ * `base:v1`), and part of the image's key.
5847
+ */
5848
+ export type ImageName = string;
5849
+
5850
+ /**
5851
+ * An application, as its b3os.yaml `name` (`images.build`): on a request, the application asking for the image,
5852
+ * which then holds it (`held_by`) instead of keeping it until it is deleted (`kept`).
5853
+ */
5854
+ export type ImageAppName = string;
5855
+
5856
+ /** Exactly one of `ref` (an import) and `build` (a Dockerfile build). */
5857
+ export type ImageImportRequest = {
5326
5858
  /**
5327
5859
  * An image reference: `[registry/]repository[:tag|@sha256:digest]`. Without a registry it is Docker Hub
5328
5860
  * (`python:3.11-slim` is `registry-1.docker.io/library/python:3.11-slim`); without a tag or digest it is
5329
5861
  * `latest`. A tag is resolved to its digest once, when the import is accepted; the image keeps that digest.
5330
- * Public images only (no credentials).
5862
+ * A private image needs `auth`.
5331
5863
  */
5332
- ref: string;
5864
+ ref?: string;
5865
+ build?: ImageBuild;
5866
+ name?: ImageName;
5867
+ auth?: ImageRegistryAuth;
5868
+ app?: ImageAppName;
5333
5869
  warmup?: ImageWarmup;
5334
5870
  /** The size every sandbox from the image has. Default 1, at most your plan's `sandboxes.vcpu_max`. */
5335
5871
  vcpu?: number;
@@ -5337,6 +5873,72 @@ export interface ImageImportRequest {
5337
5873
  * The memory every sandbox from the image has. Default 1024, at most your plan's `sandboxes.memory_max`.
5338
5874
  */
5339
5875
  memory_mib?: number;
5876
+ };
5877
+
5878
+ /**
5879
+ * A private registry's credential, from the vault (with the `images.build` flag; an import only, not a build).
5880
+ * `connection` names a connection of this project of type `basic`: `username`, and the password or an access
5881
+ * token in `password` (a Docker Hub or GitHub personal access token with read access to the image). Its
5882
+ * `hosts` must list the registry and the registry's token service: `registry-1.docker.io` and `auth.docker.io`
5883
+ * (or `*.docker.io`) for Docker Hub, `ghcr.io` for GHCR.
5884
+ *
5885
+ * The node reads the connection when the import is accepted, as your credential (it needs `vault:run`), keeps
5886
+ * it in memory for that one import, and sends it only in the Basic `Authorization` header of the token request
5887
+ * the registry's `WWW-Authenticate: Bearer` challenge names, over https, to a host the connection lists. It is
5888
+ * never logged, never put into an error, the image or its key, and never reaches a microVM; the tokens it earns
5889
+ * are used by that import only. Registries that only take Basic credentials on every request (no token
5890
+ * service) are not supported yet.
5891
+ *
5892
+ * The key does not name the connection: the same image pulled with another of the project's connections is the
5893
+ * same image.
5894
+ */
5895
+ export interface ImageRegistryAuth {
5896
+ /** A `basic` connection of this project, bound to the registry's hosts. */
5897
+ connection: string;
5898
+ }
5899
+
5900
+ export interface ImageContext {
5901
+ object: "image_context";
5902
+ sha256: string;
5903
+ bytes: number;
5904
+ /** When the tar goes, unless it is uploaded again or a build names it first. */
5905
+ expires_at: string;
5906
+ }
5907
+
5908
+ export interface ImageContextPart {
5909
+ /** A tar this project uploaded with `PUT /v1/images/contexts/{sha256}` (kept 24 hours). */
5910
+ sha256: string;
5911
+ /**
5912
+ * The folder of the build context the tar is unpacked into, relative (no `..`, no leading `/`); empty for the context's root.
5913
+ * @default ""
5914
+ */
5915
+ at?: string;
5916
+ }
5917
+
5918
+ /**
5919
+ * A Dockerfile build. The context is one or more uploaded tars, unpacked in order inside the build microVM
5920
+ * (never on the host); the Dockerfile is a file of the context. The build runs BuildKit's Dockerfile frontend
5921
+ * as root inside a microVM of its own, with the public internet through B3OS's egress guard and no secrets,
5922
+ * for `linux/amd64`, within 1,800 seconds; the result is flattened and becomes a template as an import does.
5923
+ * The same request in the same project (the same context bytes, Dockerfile path, arguments and target) answers
5924
+ * the image it already built; a base image tag that moved since is not pulled again unless `no_cache` is set.
5925
+ */
5926
+ export interface ImageBuild {
5927
+ context: ImageContextPart[];
5928
+ /**
5929
+ * The Dockerfile's path in the context, relative.
5930
+ * @default "Dockerfile"
5931
+ */
5932
+ dockerfile?: string;
5933
+ /** Build arguments (`ARG`). Part of the key; not secret (they are in the image's history). */
5934
+ args?: Record<string, string>;
5935
+ /** The stage to build (`--target`), else the last. */
5936
+ target?: string | null;
5937
+ /**
5938
+ * Build again even when this project already has the image of this request.
5939
+ * @default false
5940
+ */
5941
+ no_cache?: boolean;
5340
5942
  }
5341
5943
 
5342
5944
  /**
@@ -5371,13 +5973,15 @@ export interface ImagePackage {
5371
5973
 
5372
5974
  /**
5373
5975
  * Milliseconds each finished stage took (`null` until it finishes): `resolve` (the reference to a digest,
5374
- * before the answer), `queue` (waiting for a slot), `pull_flatten` (pulling and unpacking, which overlap),
5976
+ * before the answer; `null` for a build), `queue` (waiting for a slot), `build` (a Dockerfile build, `null` for an
5977
+ * import), `pull_flatten` (pulling and unpacking, which overlap; for a build, unpacking its result),
5375
5978
  * `adopt` (checking and storing the file system), `golden` (the first boot, warm-up and warm snapshot), and
5376
5979
  * `total`.
5377
5980
  */
5378
5981
  export interface ImageStagesMs {
5379
5982
  resolve: number | null;
5380
5983
  queue: number | null;
5984
+ build: number | null;
5381
5985
  pull_flatten: number | null;
5382
5986
  adopt: number | null;
5383
5987
  golden: number | null;
@@ -5387,19 +5991,41 @@ export interface ImageStagesMs {
5387
5991
  export interface ImageError {
5388
5992
  /** `import_failed`. */
5389
5993
  code: string;
5390
- stage: "resolve" | "pull" | "flatten" | "adopt" | "golden" | "rebuild" | "interrupted";
5994
+ stage: "resolve" | "build" | "pull" | "flatten" | "adopt" | "golden" | "rebuild" | "interrupted";
5391
5995
  detail: string;
5392
5996
  /** The last 4 KiB of the unpacker's or the warm-up's output, when there was any. */
5393
5997
  output: string | null;
5394
5998
  }
5395
5999
 
6000
+ export interface ImageBuildSource {
6001
+ context: {
6002
+ sha256: string;
6003
+ at: string;
6004
+ bytes: number;
6005
+ }[];
6006
+ dockerfile: string;
6007
+ args: Record<string, string>;
6008
+ target: string | null;
6009
+ /** The base images the build pulled, by reference and digest, once it ran. */
6010
+ base_images: {
6011
+ ref: string;
6012
+ digest: string;
6013
+ }[];
6014
+ }
6015
+
5396
6016
  export interface Image {
5397
6017
  id: string;
5398
6018
  object: "image";
5399
- /** The reference as given. */
5400
- ref: string;
5401
- /** The `linux/amd64` image manifest's digest. */
5402
- digest: string;
6019
+ /** The reference as given; `null` for a build. */
6020
+ ref: string | null;
6021
+ /** The build request, for an image built from a Dockerfile; `null` for an import. */
6022
+ build: null | ImageBuildSource;
6023
+ /** The project's name for the image (`images.build`), else `null`. */
6024
+ name: null | ImageName;
6025
+ /**
6026
+ * The `linux/amd64` image manifest's digest: the imported one, or for a build the one BuildKit produced (`null` until the build finishes).
6027
+ */
6028
+ digest: string | null;
5403
6029
  /** The index (multi-platform list) the manifest was picked from, when the reference named one. */
5404
6030
  index_digest: string | null;
5405
6031
  platform: "linux/amd64";
@@ -5419,7 +6045,9 @@ export interface Image {
5419
6045
  vcpu: number;
5420
6046
  memory_mib: number;
5421
6047
  };
5422
- /** The import key (sha256); an import with the same key in this project returns this image. */
6048
+ /**
6049
+ * The import key (sha256), over the image's source, warm-up, size, name and the node's build inputs; an import with the same key in this project returns this image.
6050
+ */
5423
6051
  key: string;
5424
6052
  stages_ms: ImageStagesMs;
5425
6053
  /** Compressed layer bytes pulled from the registry. */
@@ -5437,6 +6065,47 @@ export interface Image {
5437
6065
  error: null | ImageError;
5438
6066
  created_at: string;
5439
6067
  ready_at: string | null;
6068
+ /**
6069
+ * The applications (b3os.yaml `name`) that hold the image: each asked for it with `app`, or runs a sandbox from it. Empty for an image only ever asked for without `app`.
6070
+ */
6071
+ held_by: ImageAppName[];
6072
+ /**
6073
+ * Asked for without `app` at least once (an import, a template, an E2B build, or any image from before holds): kept until you delete it. An image that is not kept goes once no application holds it and nothing uses it.
6074
+ */
6075
+ kept: boolean;
6076
+ }
6077
+
6078
+ /** An application's hold on an image, released (`POST /v1/images/{image_id}/release`). */
6079
+ export interface ImageRelease {
6080
+ object: "image_release";
6081
+ image: string;
6082
+ app: ImageAppName;
6083
+ /** The image is gone (deleted as `DELETE /v1/images/{image_id}` deletes it). */
6084
+ removed: boolean;
6085
+ /** The applications that still hold it. */
6086
+ held_by: ImageAppName[];
6087
+ /** It is kept until deleted (asked for without `app` at least once), so it stays. */
6088
+ kept: boolean;
6089
+ /**
6090
+ * A running, paused or hibernated sandbox, or a snapshot, uses its template, so it stays; once nothing does and nothing holds or keeps it, the node removes it.
6091
+ */
6092
+ in_use: boolean;
6093
+ }
6094
+
6095
+ export interface ImageReleaseRequest {
6096
+ app: ImageAppName;
6097
+ }
6098
+
6099
+ /** Lines of an image's build log. */
6100
+ export interface ImageLog {
6101
+ object: "image_log";
6102
+ /** The image ID (`img_…`). */
6103
+ image: string;
6104
+ status: ImageStatus;
6105
+ /** The log's lines from `offset`, without their line ends. */
6106
+ lines: string[];
6107
+ /** The `offset` of the next read. */
6108
+ next_offset: number;
5440
6109
  }
5441
6110
 
5442
6111
  export type ImageList = Omit<ListEnvelope, "data"> & {
@@ -5446,7 +6115,11 @@ export type ImageList = Omit<ListEnvelope, "data"> & {
5446
6115
  /** An instance's key, stored and shown as written, so never a credential or a personal detail. */
5447
6116
  export type AgentInstanceKey = string;
5448
6117
 
5449
- /** Lowercase letters, digits and `-`, starting with a letter. `sessions` is reserved. */
6118
+ /**
6119
+ * Lowercase letters, digits and `-`, starting with a letter. `sessions`, `harnesses`, `grants`, `self` and
6120
+ * `recipes` are reserved: they are path segments under `/v1/agents`, or will be (`recipes`, for shared harness
6121
+ * definitions).
6122
+ */
5450
6123
  export type AgentName = string;
5451
6124
 
5452
6125
  /**
@@ -5525,28 +6198,1189 @@ export interface AgentTurns {
5525
6198
  redeliver?: boolean;
5526
6199
  }
5527
6200
 
5528
- export interface AgentCreateRequest {
5529
- name: AgentName;
5530
- source?: AgentSource;
5531
- entry: AgentEntry;
5532
- /** Environment variables of the harness. Returned as given; put credentials in `secrets`. */
5533
- env?: Record<string, string>;
5534
- /**
5535
- * Environment variables never returned or logged, as a sandbox's `secrets`: code in the instance can read
5536
- * them. A memory snapshot holds them, so the node keeps an instance's snapshots to itself: they are never
5537
- * listed or restorable through the API.
5538
- */
6201
+ /**
6202
+ * Which harness. The open-source ones come first: `opencode` (MIT; its server takes steers, queued prompts and
6203
+ * permission answers, with a TUI that attaches to the same server), `codex` (OpenAI's Codex CLI, Apache-2.0)
6204
+ * and `pi` (Earendil's pi coding agent, MIT); then `claude-code` (Anthropic's Claude Code). Each is driven by a
6205
+ * driver built into the shim, and what each takes (providers, sign-ins, a model the node serves, modes, lists)
6206
+ * is its entry in `GET /v1/agents/harnesses`, which lists the ones this node runs. Or `acp`, a harness your
6207
+ * organization brings that speaks the Agent Client Protocol over stdio, named in the block's `acp` (planned,
6208
+ * after prepared snapshots, for your organization's own use; refused with `422 harness_capability_unsupported`
6209
+ * until the shim serves it).
6210
+ */
6211
+ export type AgentHarnessKindName = "opencode" | "codex" | "pi" | "claude-code" | "acp";
6212
+
6213
+ /**
6214
+ * A coding agent people already use, run unmodified as the agent's harness (planned: not served on the beta
6215
+ * node yet; research/harnesses-design.md). The instance's entry is B3OS's shim, `b3os-harness serve`, which owns
6216
+ * the harness process, delivers turns into it, turns its hooks and stream into `harness.*` events, answers its
6217
+ * permission prompts and serves its terminal. What the node and the shim say to each other inside the instance
6218
+ * (the environment, `/run/b3os/harness.json`, the headers and the shim's routes) is
6219
+ * packages/spec/sidecars/harness.md.
6220
+ *
6221
+ * The block is a recipe: write it once, and deploy it as many agents and instances as you need. Its members are
6222
+ * settled at three times:
6223
+ *
6224
+ * - At prepare, what has to be fetched: `skills` and `plugins` from `git`, `npm` or `artifact`, and `mcp`
6225
+ * servers run from an npm package. The node installs them, with the harness at `version`, into a snapshot of
6226
+ * the `harness` template that it builds once per prepare key and shares across the project
6227
+ * (`Agent.harness_prepared`), so each instance starts with them in place. The key covers only that fetched
6228
+ * set, the kind, the version, the template and the shim, so editing any other member builds nothing again.
6229
+ * Until prepared snapshots ship, those sources answer `422 harness_setup_needs_prepare`.
6230
+ * - When an instance starts, what the shim writes and sets up: `instructions`, `settings`, `mcp` entries,
6231
+ * `skills` and `plugins` given as `text`, `files` or `builtin`, `files`, `mode`, `terminal`, and each
6232
+ * credential profile's directory.
6233
+ * - At each turn: `model`, `permissions`, `hooks` and the turn's credential profile.
6234
+ *
6235
+ * Until they are served on this node, three members are refused when the definition is written, even when
6236
+ * empty (`[]` or `{}`), with `422 harness_capability_unsupported`: `repo`, `context` and `acp` (`kind: acp`
6237
+ * with it). The node never stores them, so neither a stored block nor `/run/b3os/harness.json` carries them.
6238
+ * A vault connection outside a credential profile reaches the instance as a `B3OS_CONN_<N>` secret (below): a
6239
+ * remote `mcp` server's `connection` and a stdio server's `{connection}` `env` values. `repo.connection` waits
6240
+ * for `repo`. A `${...}` or `{env:...}` in a server's `url`, `command` or `env`, which Claude Code and opencode
6241
+ * would expand from the harness's environment, is `400 invalid_request`: name a connection instead.
6242
+ *
6243
+ * B3OS's own tools are default entries of the block's lists, not a switch. `mcp` starts with `b3os`, B3OS's MCP
6244
+ * server inside the instance (`{builtin: b3os, toolsets: [browser, vision, render, sandboxes, actions, infer]}`,
6245
+ * at `B3OS_MCP_URL`), and `skills` starts with `b3os`, the skill that says how to use them (`{builtin: b3os}`);
6246
+ * `GET /v1/agents/harnesses` lists both (`checks.defaults`). Your `mcp` and `skills` maps are a JSON merge patch
6247
+ * (RFC 7396) over those defaults, the rule the shim applies: an entry under a new name is added, an entry set
6248
+ * to `null` is removed, and an entry under a default's name is merged into the default member by member (a
6249
+ * member set to `null` is removed, an array replaces the default's whole). So `"mcp": {"b3os": {"toolsets":
6250
+ * ["vision"]}}` keeps only the page tools without restating `builtin`, and `"mcp": {"b3os": null}, "skills":
6251
+ * {"b3os": null}` leaves the harness its own tools only. `plugins` has no default. The grant the node fills in
6252
+ * comes with the merged `b3os` MCP entry: the scopes its toolsets need, scoped to the instance
6253
+ * (`AgentHarnessMcpBuiltin`); without that entry the filled `api` carries no B3OS MCP tool scopes (only
6254
+ * `infer:run` if a `node` profile is present, and nothing otherwise). A model the node serves is reached
6255
+ * through the `model` or a `node` profile you pick, not through these entries. Every node carries the
6256
+ * defaults; a toolset a node does not serve is left out of the server's tools. A default is added only where
6257
+ * the kind takes its list (the kind's `setup` in `GET /v1/agents/harnesses`), and both default entries are
6258
+ * builtins of the `harness` template, so they change no prepare key.
6259
+ *
6260
+ * The stored block keeps `mcp` and `skills` as you wrote them, never merged: your own entries and patches, a
6261
+ * removed default kept as `null`, `{}` when you gave none. So a block that is read and sent back changes
6262
+ * nothing, and the shim, which merges once at start, sees the same maps you wrote. The merged lists are those
6263
+ * maps merged over `checks.defaults`, and the filled `api` shows the grant they bring.
6264
+ *
6265
+ * The node fills the rest of the definition from this block: `source.template` (the `harness` template, which
6266
+ * pins each harness's versions) and `source.snapshot` (the revision's prepared snapshot, once prepared
6267
+ * snapshots ship and it is built), `entry` (`b3os-harness serve --config /run/b3os/harness.json` on port 7801,
6268
+ * ready when that port answers, `max_restarts` 5), `secrets` (beside your own: each `key` profile's
6269
+ * credentials, as `B3OS_PROFILE_<NAME>__<VAR>`, and the secret of every other connection the block names, as
6270
+ * `B3OS_CONN_<N>`, which the file maps to its member: `repo`, a remote `mcp` server's `connection`, a stdio
6271
+ * server's `{connection}` values), `api` (the scopes that come with the `b3os` MCP entry, plus `infer:run`
6272
+ * when a `node` profile is present, and nothing without either), `egress` and `turns.timeout_s` (3,600
6273
+ * seconds, the most a turn may take). The shim writes each connection's secret where its member says (the
6274
+ * instance's git credentials, the harness's MCP config, as a variable the config refers to) and keeps every
6275
+ * `B3OS_*` variable out of the harness's processes and its terminal except the ones B3OS gives every sandbox
6276
+ * (`B3OS_API_URL`, `B3OS_SANDBOX_ID`, `B3OS_PROJECT`, `B3OS_PORT_BASE_PATH`, `B3OS_MCP_URL`, `B3OS_MODEL`,
6277
+ * `B3OS_WORKSPACE_ID`, `B3OS_BRANCH_ID`, `B3OS_WORKSPACE_PATH`): the profiles' values, the connections' secrets,
6278
+ * the shim's token, the flags and the instance's id never reach it. Set `api`,
6279
+ * `egress` or `turns` yourself to use your own instead. `source.vcpu`, `memory_mib` and `disk_gib` apply as
6280
+ * for any agent. `source.template`, `source.snapshot` and `entry` cannot be set beside `harness`, and neither
6281
+ * can an `env` or `secrets` name that starts with `B3OS_` (the node's and the shim's own) or that the kind's
6282
+ * shim sets or removes (`checks.kinds.<kind>.env_owned`) (`400 invalid_request`).
6283
+ *
6284
+ * `/run/b3os/harness.json` is this block as the node stored it, with exactly these changes and nothing else: it
6285
+ * leaves out `hooks.webhook` and `hooks.decide.url` (both calls leave from the node, so neither URL nor a
6286
+ * secret enters the instance) and every vault `connection` (a profile's values arrive as
6287
+ * `B3OS_PROFILE_<NAME>__<VAR>`, any other connection's as `B3OS_CONN_<N>`); each `node` profile gains
6288
+ * `base_url`, the node's infer inside the instance (`http://127.0.0.1:7700/v1/infer`); and `connections` maps
6289
+ * each member a secret goes to (`mcp.<name>`, `mcp.<name>.env.<VAR>`, and `repo` once it is served) to its
6290
+ * variable. It never holds a credential. packages/spec/sidecars/harness.md
6291
+ * lists every member and which the shim reads.
6292
+ *
6293
+ * The filled `egress` is an allowlist of exactly the hosts the block reaches from the instance: each `key` and
6294
+ * `signin` profile's provider hosts, from the kind's `auth.hosts` in `GET /v1/agents/harnesses` (a `{region}`
6295
+ * in one filled from the profile's `region`); each profile's `base_url` host; the `repo` host; and each remote
6296
+ * `mcp` server's host. A profile whose provider has no hosts in the catalog is `422
6297
+ * harness_capability_unsupported`. Your own `egress` must let the same hosts through (`public`, or an
6298
+ * `allowlist` that matches each one); one it does not is `400 invalid_request`, naming the host. B3OS itself is
6299
+ * reached inside the instance at `http://127.0.0.1:7700`, outside `egress`, and the `hooks.webhook` and
6300
+ * `hooks.decide` calls leave from the node, so neither host goes in the list. The hosts a stdio `mcp` server
6301
+ * reaches are not known to the node: list them in your own `egress`.
6302
+ *
6303
+ * No harness agent takes a plan's token. A name in `AgentHarnessPlanEnv` in `env`, `secrets`, an `mcp` server's
6304
+ * `env` or a `settings` `env` entry is `400 invalid_request`. A value holding a plan's token (`sk-ant-oat` or
6305
+ * `sk-ant-ort`) is `400 harness_plan_credential` wherever it is: any string in the stored definition (`env`,
6306
+ * `secrets`, this block's members, argv such as an `mcp` server's or `acp`'s `command`, `settings`, and every
6307
+ * skill, plugin and file), and the resolved value of every connection the definition names (each profile's,
6308
+ * `repo`'s, a remote `mcp` server's and a stdio server's `{connection}` values). The node checks when the
6309
+ * definition is written and again each time it makes an instance, so a connection changed later is refused
6310
+ * then.
6311
+ *
6312
+ * The block is part of the revision, as the rest of the definition is: a `PATCH` makes a new revision, and
6313
+ * `upgrade: on_wake` moves sleeping instances to it. A harness cannot change its own definition (`agents:write`
6314
+ * is granted only when named exactly), and what the recipe installs is read-only to the harness.
6315
+ */
6316
+ export interface AgentHarness {
6317
+ /**
6318
+ * Which harness. Default: `opencode`, which is open source and reaches the providers its catalog entry's
6319
+ * `auth.key` lists (Anthropic, OpenAI and OpenRouter, and through OpenRouter many others). Its driver was
6320
+ * checked live against opencode 2.4.2 and a real provider on 2026-11-28: `openai/gpt-4o-mini` through
6321
+ * OpenRouter, three turns, one of them running a shell tool, each reporting its usage and cost.
6322
+ */
6323
+ kind?: AgentHarnessKindName;
6324
+ /**
6325
+ * The harness's version, one of the kind's `versions` in `GET /v1/agents/harnesses`. Default: its
6326
+ * `default_version`. A version this node does not run is `422 harness_version_unavailable`.
6327
+ */
6328
+ version?: string;
6329
+ acp?: AgentHarnessAcp;
6330
+ auth?: AgentHarnessAuth;
6331
+ /**
6332
+ * The model, as the harness names it (opencode's `openrouter/openai/gpt-4o-mini`, Claude Code's
6333
+ * `claude-opus-5-5`), or a model the node's infer serves (`GET /v1/infer/models`), which the harness then
6334
+ * reaches on the node with no key, for a kind whose catalog entry has `auth.node: true`. A profile's own
6335
+ * `model` wins for that profile's turns. Default: the harness's own default.
6336
+ */
6337
+ model?: string;
6338
+ /**
6339
+ * What the harness may do without asking. `auto`: the microVM is the sandbox, so the harness runs in its
6340
+ * most autonomous mode (every tool allowed in opencode and pi, Codex's full access with approvals off,
6341
+ * Claude Code's `bypassPermissions`). `ask`: every permission prompt becomes `harness.permission.requested`
6342
+ * and the turn waits for `POST /v1/agents/{agent}/instances/{key}/decisions`; one nobody answers is denied
6343
+ * at the turn's timeout. `plan`: read-only tools only; every write is denied, and
6344
+ * `hooks.decide` is never called. In `auto` and `ask`, `hooks.decide` answers before a person.
6345
+ * @default "auto"
6346
+ */
6347
+ permissions?: "auto" | "ask" | "plan";
6348
+ /**
6349
+ * How the shim drives the harness. `api`: headless and structured (opencode's server, Codex's app-server,
6350
+ * pi's RPC mode, Claude Code's stream-json); the terminal holds a shell in the workspace. `terminal`: the
6351
+ * harness's own TUI holds the terminal and turns are pasted into it, so a person can type turns of their
6352
+ * own there. In `terminal` mode the events come from the harness's hooks, so a kind may report less there
6353
+ * (Claude Code's TUI sends no `harness.message`). The kind's `modes` in `GET /v1/agents/harnesses` lists
6354
+ * what it takes (`422 harness_capability_unsupported` otherwise), with these limits:
6355
+ *
6356
+ * - Codex and pi run in `api` only. pi's RPC process and its TUI cannot share one session file yet.
6357
+ * - opencode in `terminal` takes no `hooks.decide` outside `permissions: plan`: its TUI answers permission
6358
+ * prompts itself, and an "always" answered there would keep the webhook from seeing that tool again. The
6359
+ * kind's `capabilities.decide_modes` lists the modes where `hooks.decide` answers.
6360
+ * @default "api"
6361
+ */
6362
+ mode?: "api" | "terminal";
6363
+ /**
6364
+ * The repository cloned into the workspace. Not served yet: refused at write, even empty, with `422
6365
+ * harness_capability_unsupported` until the harness's shim clones it.
6366
+ */
6367
+ repo?: AgentHarnessRepo;
6368
+ /**
6369
+ * Appended to the harness's own system prompt, as written, when a harness session starts. Yours, so never
6370
+ * quoted.
6371
+ */
6372
+ instructions?: string;
6373
+ /**
6374
+ * Text added, as written, at each harness session's start (`session_start`) or before each turn
6375
+ * (`turn_start`); a resumed session does not get `session_start` again.
6376
+ * - `api` mode: it goes before the turn's own text in its prompt.
6377
+ * - `terminal` mode: it goes through the TUI's own hooks (Claude Code's SessionStart and UserPromptSubmit
6378
+ * `additionalContext`). A kind whose TUI the shim cannot reach is refused it there (`422
6379
+ * harness_capability_unsupported`); today that is opencode.
6380
+ *
6381
+ * Not served on the beta node yet: refused at write, even as `[]`, with `422 harness_capability_unsupported`.
6382
+ */
6383
+ context?: AgentHarnessContext[];
6384
+ /**
6385
+ * Skills (folders with a `SKILL.md`), by name, put where the harness reads them: Claude Code's skills
6386
+ * directory of each profile, Codex's extra skill roots. It starts with `b3os`, the builtin skill for B3OS's
6387
+ * tools; this map is a JSON merge patch over that default (`AgentHarness`): a new name is added and `null`
6388
+ * removes an entry. `b3os` takes only `{builtin: b3os}` or `null`. Stored as written. A kind whose `setup`
6389
+ * in `GET /v1/agents/harnesses` does not list `skills` gets no default, and a skill of yours there answers
6390
+ * `422 harness_capability_unsupported`.
6391
+ */
6392
+ skills?: Record<string, AgentHarnessSetupItem | null>;
6393
+ /**
6394
+ * Plugins, by name, in the kind's own plugin format: a Claude Code plugin directory (loaded with
6395
+ * `--plugin-dir`), a Codex plugin (installed from a local marketplace at prepare). There is no default
6396
+ * plugin. With `permissions: ask`, a
6397
+ * plugin whose hooks can answer a permission prompt (Claude Code's `PreToolUse` or `PermissionRequest`) is
6398
+ * `400 invalid_request`, since a person is the gate there; with `hooks.decide` it is allowed, because the
6399
+ * shim's own hook still runs on every tool and a deny wins. A kind whose `setup` does not list `plugins`
6400
+ * answers `422 harness_capability_unsupported`.
6401
+ */
6402
+ plugins?: Record<string, AgentHarnessSetupItem>;
6403
+ /**
6404
+ * MCP servers for the harness, by name, written into its own MCP config when the instance starts:
6405
+ * opencode's `mcp`, each profile's Codex `config.toml`, Claude Code's `--mcp-config` file (with
6406
+ * `--strict-mcp-config`, so a repository's own `.mcp.json` is not read), or an ACP harness's session. Each
6407
+ * is remote (`url`) or run in the instance (`command`). It starts with `b3os`, B3OS's own server
6408
+ * (`AgentHarnessMcpBuiltin`), which brings the instance's grant; this map is a JSON merge patch over that
6409
+ * default (`AgentHarness`): a new name is added, `null` removes an entry, and `"b3os": {"toolsets": [...]}`
6410
+ * narrows the default's toolsets without restating `builtin`. Stored as written. A kind whose `setup` does
6411
+ * not list `mcp` gets no default, and a server of yours there answers `422 harness_capability_unsupported`.
6412
+ */
6413
+ mcp?: {
6414
+ b3os?: AgentHarnessMcpBuiltin | null;
6415
+ [key: string]: unknown;
6416
+ };
6417
+ settings?: AgentHarnessSettings;
6418
+ /**
6419
+ * Files written into the workspace before the first harness session, after the repository is cloned
6420
+ * (`CLAUDE.md`, `AGENTS.md`). A file already at the path is replaced. Skills and plugins go in `skills` and
6421
+ * `plugins`.
6422
+ */
6423
+ files?: AgentHarnessFile[];
6424
+ hooks?: AgentHarnessHooks;
6425
+ terminal?: AgentHarnessTerminal;
6426
+ }
6427
+
6428
+ /**
6429
+ * A harness your organization brings, for `kind: acp` only (planned: it needs prepared snapshots, and it is for
6430
+ * your organization's own use). It speaks the Agent Client Protocol over stdio: the shim starts `command` as the
6431
+ * harness's user, opens a session with the block's `mcp` servers, sends each turn as a prompt and each cancel as
6432
+ * an interrupt, and answers the harness's permission requests through the same rules, `hooks.decide` and people
6433
+ * as any harness, allowing or rejecting each call once. The package is installed at prepare. An ACP harness
6434
+ * takes `key` and `node` profiles only, never `signin`; it is steered only when it implements B3OS's optional
6435
+ * `_b3os/steer` method (`422 harness_capability_unsupported` otherwise); and `hooks.decide` on
6436
+ * `harness.tool.requested` is refused, because the node cannot check that every tool call reaches a permission
6437
+ * request. With any other `kind` it is `400 invalid_request`.
6438
+ */
6439
+ export interface AgentHarnessAcp {
6440
+ npm: AgentHarnessNpmSource;
6441
+ /** The command that starts the harness in ACP mode, from the installed package. */
6442
+ command: string[];
6443
+ /** The environment variables the harness reads a `key` profile's key from. */
6444
+ key_env?: string[];
6445
+ }
6446
+
6447
+ /**
6448
+ * How the harness reaches its model: named credential profiles, so plans, subscriptions and API keys sit side by
6449
+ * side and each turn uses one of them. B3OS never collects, stores, reads or routes a plan's token: no member
6450
+ * takes one, a harness agent's `env`, `secrets`, `mcp` `env` and `settings` `env` refuse the variables a
6451
+ * harness reads one from (`AgentHarnessPlanEnv`), and a value holding one, in the definition or in a connection
6452
+ * it names, is `400 harness_plan_credential` (`AgentHarness`).
6453
+ *
6454
+ * - `{connection}` is shorthand for one `key` profile named `default`.
6455
+ * - Left out, with a `model` the node's infer serves, it is one `node` profile named `default`, for a kind
6456
+ * whose catalog entry has `auth.node: true` (`422 harness_capability_unsupported` for another); left out
6457
+ * with any other model, `400 invalid_request`.
6458
+ * - `{default, profiles}`: up to 8 named profiles (`AgentHarnessAuthProfile`). `default` is the profile a turn
6459
+ * uses when neither its message nor its conversation names one, and is required with more than one profile.
6460
+ *
6461
+ * The node stores the expanded form, so a read always shows `{default, profiles}`.
6462
+ *
6463
+ * A turn's profile is its message's `profile`, else the one its conversation used last, else `default`. A
6464
+ * caller only picks among the definition's profiles and never sends a credential with a turn. Profiles switch
6465
+ * between turns only, and a switch to another account starts without the provider's prompt cache. Each profile
6466
+ * has its own directory in the instance, so two sign-ins never share a file, and the harness's sessions are
6467
+ * shared across them, so a conversation goes on under another profile.
6468
+ *
6469
+ * A profile's `fallback` names the profile a conversation moves to when this one reaches a usage limit or is
6470
+ * refused. A fallback never moves into a `signin` profile, so a plan is only ever chosen by name, and it never
6471
+ * moves back by itself: `harness.auth.limited` carries `resets_at`, and you move back by naming the profile.
6472
+ * Errors the harness retries itself (a rate limit of the moment, a 5xx, an overload) never trigger one. Until a
6473
+ * kind's limit signal is checked against its pinned version, no fallback fires for it.
6474
+ */
6475
+ export type AgentHarnessAuth = AgentHarnessAuthConnection | AgentHarnessAuthProfiles;
6476
+
6477
+ /** Shorthand for `{default: default, profiles: {default: {type: key, connection}}}`. */
6478
+ export interface AgentHarnessAuthConnection {
6479
+ connection: string;
6480
+ }
6481
+
6482
+ export interface AgentHarnessAuthProfiles {
6483
+ default?: AgentHarnessProfileName;
6484
+ /**
6485
+ * The profiles by name. A `default` that names none of them, a `fallback` whose `to` names none of them or
6486
+ * a `signin` profile, and a cycle of fallbacks are `400 invalid_request`.
6487
+ */
6488
+ profiles: Record<string, AgentHarnessAuthProfile>;
6489
+ }
6490
+
6491
+ /**
6492
+ * A credential profile's name: 1 to 32 lowercase letters, digits and single `_`s, starting with a letter and
6493
+ * not ending with `_`. It goes into an environment variable's name, `B3OS_PROFILE_<NAME>__<VAR>`, where the
6494
+ * first `__` ends the name, so no two profiles and variables share one.
6495
+ */
6496
+ export type AgentHarnessProfileName = string;
6497
+
6498
+ /**
6499
+ * One credential: `key` (an API key or a cloud provider's credentials from your vault), `signin` (a person's own
6500
+ * plan, signed in inside their own instance) or `node` (a model the node serves). The kind's `auth` in
6501
+ * `GET /v1/agents/harnesses` says which it takes.
6502
+ */
6503
+ export type AgentHarnessAuthProfile = AgentHarnessAuthKey | AgentHarnessAuthSignin | AgentHarnessAuthNode;
6504
+
6505
+ /**
6506
+ * An API key, or a cloud provider's credentials, from a vault connection. The node puts its values in the
6507
+ * shim's environment as `B3OS_PROFILE_<NAME>__<VAR>`, and the shim gives them, under the names the harness reads
6508
+ * (the kind's `auth.key`), to this profile's harness processes only; opencode's one server holds every `key`
6509
+ * profile's. Until egress credential injection ships, code in the instance can read the key, as with an agent's
6510
+ * `secrets`; it needs `vault:run` and `vault:connections:reveal`. The provider bills the key's owner.
6511
+ */
6512
+ export interface AgentHarnessAuthKey {
6513
+ type: "key";
6514
+ connection: string;
6515
+ provider?: AgentHarnessKeyProvider;
6516
+ /**
6517
+ * For `anthropic_compatible` and `openai_compatible` only: the gateway the harness sends to. Its host
6518
+ * joins the filled `egress`.
6519
+ */
6520
+ base_url?: string;
6521
+ /** The cloud region, for `bedrock` and `vertex`. */
6522
+ region?: string;
6523
+ /** The model for this profile's turns, when it is not the block's `model`. */
6524
+ model?: string;
6525
+ /** A name for people (the console, the CLI, events). */
6526
+ label?: string;
6527
+ fallback?: AgentHarnessAuthFallback;
6528
+ }
6529
+
6530
+ /**
6531
+ * A person's own plan (a Claude or ChatGPT subscription), which that person signs in to inside their own
6532
+ * instance with the harness's own login, in the sign-in window (`GET …/terminal?window=signin:<profile>`). The
6533
+ * harness writes its credential file in this profile's directory, as it would on a laptop. B3OS never asks for
6534
+ * the token, never reads, stores or copies the file, and has no member to take one; the shim checks only that
6535
+ * the file exists, and asks the harness what it is signed in as (`harness.auth.ready`).
6536
+ *
6537
+ * A `signin` profile makes the agent personal (`Agent.owner`), whatever the provider: a person makes it, not a
6538
+ * key, and only its owner drives it, so one person uses each plan. Forks and children never carry a sign-in.
6539
+ * It needs a `provider` the kind's `auth.signin` lists (`422 harness_signin_unsupported`), and it is served
6540
+ * only on an instance made from the revision's prepared snapshot, which holds no other harness that could read
6541
+ * the file. A ChatGPT plan (`openai`) needs no flag. A Claude plan (`anthropic`) needs the
6542
+ * `agents.claude_plan_signin` flag, off by default and turned on per organization (`403
6543
+ * harness_claude_plan_signin_disabled` without it). The provider's terms for personal plans apply, and they
6544
+ * assume one person's ordinary use.
6545
+ *
6546
+ * Not served yet. Personal agents wait on two prerequisites, and until both land the node refuses every
6547
+ * `signin` profile with `403 harness_personal_agent`, whatever its provider and flag:
6548
+ *
6549
+ * - Harness agent VMs closed to the generic sandboxes API. Today any caller holding `sandboxes:run` in the
6550
+ * project can reach an agent's microVM by its `sandbox_id` (`GET /v1/sandboxes/{sandbox_id}`, exec, files,
6551
+ * logs and ports), and so read a sign-in's credential file and the shim's token. A personal agent's VMs (and,
6552
+ * once the node can, every harness agent's) answer those routes as a sandbox that does not exist, and
6553
+ * `AgentInstance.sandbox_id` is `null` for them.
6554
+ * - A person in the node's principal. A node token carries the organization, the project, the key, its scopes
6555
+ * and the request ID, and no person, so the node cannot tell an owner from anyone else in the project. The
6556
+ * edge's node tokens for dashboard sessions and CLI tokens gain the person (`usr`) and their organization
6557
+ * role, the claims workspaces asks for too.
6558
+ *
6559
+ * After both, a `signin` profile still waits for prepared snapshots (`422 harness_setup_needs_prepare` until
6560
+ * they ship).
6561
+ */
6562
+ export interface AgentHarnessAuthSignin {
6563
+ type: "signin";
6564
+ /**
6565
+ * `openai` (a ChatGPT plan) or `anthropic` (a Claude plan, behind `agents.claude_plan_signin`). The kind's
6566
+ * `auth.signin` in `GET /v1/agents/harnesses` lists which it signs in to: today Codex `openai` and Claude
6567
+ * Code `anthropic`, and opencode and pi none until their logins are checked on their pinned versions.
6568
+ */
6569
+ provider: "anthropic" | "openai";
6570
+ /** The model for this profile's turns, when it is not the block's `model`. */
6571
+ model?: string;
6572
+ /** A name for people (the console, the CLI, events). */
6573
+ label?: string;
6574
+ fallback?: AgentHarnessAuthFallback;
6575
+ }
6576
+
6577
+ /**
6578
+ * A model the node's infer serves (`GET /v1/infer/models`), reached inside the instance with no key, at the
6579
+ * `base_url` the node gives the shim (`http://127.0.0.1:7700/v1/infer`). It adds `infer:run` to the instance's
6580
+ * grant, and infer bills its tokens to your organization. Only for a kind whose catalog entry has `auth.node:
6581
+ * true` (`422 harness_capability_unsupported` otherwise): today Codex and Claude Code.
6582
+ */
6583
+ export interface AgentHarnessAuthNode {
6584
+ type: "node";
6585
+ model: string;
6586
+ /** A name for people (the console, the CLI, events). */
6587
+ label?: string;
6588
+ fallback?: AgentHarnessAuthFallback;
6589
+ }
6590
+
6591
+ /**
6592
+ * Whose API a `key` profile's credentials are for. Default: the connection's provider; the stored profile always
6593
+ * names it. Only a provider the kind's `auth.key` lists, with its hosts in `auth.hosts` (`422
6594
+ * harness_capability_unsupported` otherwise).
6595
+ */
6596
+ export type AgentHarnessKeyProvider =
6597
+ | "anthropic"
6598
+ | "openai"
6599
+ | "bedrock"
6600
+ | "vertex"
6601
+ | "foundry"
6602
+ | "azure_openai"
6603
+ | "openrouter"
6604
+ | "openai_compatible"
6605
+ | "anthropic_compatible";
6606
+
6607
+ /**
6608
+ * Where a conversation goes when this profile stops. The turn that stopped ends `harness.turn.failed`
6609
+ * (`error.code` `limit_reached` or `auth_required`), the shim marks the profile limited until its `resets_at`
6610
+ * (or until it checks again at the next turn) and sends `harness.auth.limited`, and the conversation moves to
6611
+ * `to` (`harness.auth.switched`). A chain follows each profile's own `fallback`. When every profile is limited,
6612
+ * the turn fails `no_profile_ready` with the earliest `resets_at`.
6613
+ */
6614
+ export interface AgentHarnessAuthFallback {
6615
+ to: AgentHarnessProfileName;
6616
+ /**
6617
+ * `limit`: a usage limit was reached or the credits ran out. `auth`: the credential was refused or expired.
6618
+ */
6619
+ on: Array<"limit" | "auth">;
6620
+ /**
6621
+ * `next_turn` (the default, chosen): the conversation's next turn runs on `to`. `continue`: the shim starts
6622
+ * one turn on `to` at once, with a fixed line ("Continue the task; the previous turn stopped at a usage
6623
+ * limit") and `source: fallback`. The prompt that stopped is never sent again, since its tools may have run.
6624
+ * @default "next_turn"
6625
+ */
6626
+ resume?: "next_turn" | "continue";
6627
+ }
6628
+
6629
+ /**
6630
+ * A skill or a plugin, under its name in `skills` or `plugins`: exactly one source. `text`, `files` and `builtin`
6631
+ * are written when the instance starts. `git`, `npm` and `artifact` are fetched once, at prepare, into the
6632
+ * revision's prepared snapshot, and are pinned so a revision never changes under you: a git `ref` is resolved to a
6633
+ * `commit` when the definition is written, an npm `version` is exact (`422 harness_setup_unpinned` otherwise) and
6634
+ * its integrity is recorded, and an artifact is checked by its `sha256`.
6635
+ */
6636
+ export type AgentHarnessSetupItem = {
6637
+ /** A skill's one file, its `SKILL.md`. Not for a plugin. */
6638
+ text?: string;
6639
+ /** The item's files, each relative to the item's folder. */
6640
+ files?: AgentHarnessFile[];
6641
+ git?: AgentHarnessGitSource;
6642
+ npm?: AgentHarnessNpmSource;
6643
+ artifact?: AgentHarnessArtifactSource;
6644
+ /**
6645
+ * One of B3's own items, shipped in the `harness` template. `b3os` is the skill for B3OS's tools, and the
6646
+ * default entry of `skills`; only under the name `b3os`, and only in `skills`.
6647
+ */
6648
+ builtin?: "b3os";
6649
+ };
6650
+
6651
+ /**
6652
+ * A folder of a public Git repository, fetched at prepare (the build has no access to your vault). Give `ref` or
6653
+ * `commit`: the node resolves a `ref` once, when the definition is written, and stores the `commit` beside it.
6654
+ * That lookup leaves from the node through the egress guard, as a webhook delivery does (private and loopback
6655
+ * addresses refused), and counts as your egress; a `ref` it cannot resolve is `400 invalid_request`, naming
6656
+ * the member, never quoting what the server answered.
6657
+ */
6658
+ export interface AgentHarnessGitSource {
6659
+ url: string;
6660
+ /** A branch or tag. */
6661
+ ref?: string;
6662
+ commit?: string;
6663
+ /** The item's folder in the repository. Default, its root. */
6664
+ path?: string;
6665
+ }
6666
+
6667
+ /**
6668
+ * An npm package, installed at prepare with its install scripts off. `version` is an exact version; a range or
6669
+ * a tag is `422 harness_setup_unpinned`. The node records the package's `integrity` when the definition is
6670
+ * written, looking it up through the egress guard, and checks it at prepare.
6671
+ */
6672
+ export interface AgentHarnessNpmSource {
6673
+ package: string;
6674
+ version: string;
6675
+ /** The package's `sha512-` integrity, set by the node. */
6676
+ integrity?: string;
6677
+ }
6678
+
6679
+ /**
6680
+ * A bundle of the item's folder in your project's artifact store, checked by `sha256` at prepare. Uploading one
6681
+ * needs a public artifact upload route, which is planned.
6682
+ */
6683
+ export interface AgentHarnessArtifactSource {
6684
+ id: string;
6685
+ sha256: string;
6686
+ }
6687
+
6688
+ /**
6689
+ * The harness's own settings, under the block's own `kind` (another kind's key is `400 invalid_request`),
6690
+ * merged under the settings the shim writes when the instance starts: opencode's config, each profile's Codex
6691
+ * `config.toml`, pi's `settings.json`, Claude Code's `--settings` file. A key the shim owns (the kind's
6692
+ * `settings_refused`: its hooks, permissions, login method, providers, MCP servers, and the plugins and plugin
6693
+ * marketplaces it turns on) is `400 invalid_request`, naming the key, and so is an `env` entry (Claude Code's
6694
+ * `env`) named in `AgentHarnessPlanEnv`, like one of the kind's key variables or `B3OS_*`, and a plan's token in
6695
+ * any value. MCP servers go in `mcp` and plugins in `plugins`, where they are pinned and checked.
6696
+ */
6697
+ export interface AgentHarnessSettings {
6698
+ opencode?: Record<string, unknown>;
6699
+ codex?: Record<string, unknown>;
6700
+ pi?: Record<string, unknown>;
6701
+ "claude-code"?: Record<string, unknown>;
6702
+ }
6703
+
6704
+ /** The repository cloned into the workspace at the instance's first start, before its first turn. */
6705
+ export interface AgentHarnessRepo {
6706
+ /** An `https://` Git URL. */
6707
+ url: string;
6708
+ /** The branch, tag or commit to check out. Default, the repository's default branch. */
6709
+ ref?: string;
6710
+ /**
6711
+ * A vault connection with a token for a private repository. The node delivers its secret as a
6712
+ * `B3OS_CONN_<N>` variable, and the harness's shim clones inside the instance and writes the token into the
6713
+ * instance's git credentials, so the harness can fetch and push with it and code in the instance can read
6714
+ * it; it needs `vault:run` and `vault:connections:reveal`. Refused with the rest of `repo` (`422
6715
+ * harness_capability_unsupported`) until the shim clones it.
6716
+ */
6717
+ connection?: string;
6718
+ }
6719
+
6720
+ export interface AgentHarnessContext {
6721
+ at: "session_start" | "turn_start";
6722
+ text: string;
6723
+ }
6724
+
6725
+ export interface AgentHarnessMcpRemote {
6726
+ /**
6727
+ * The server's `https://` URL (streamable HTTP or SSE). Reached through the instance's `egress`, which the
6728
+ * node fills with its host.
6729
+ */
6730
+ url: string;
6731
+ /**
6732
+ * A vault connection whose token the harness sends to this server as `Authorization: Bearer <token>`. The
6733
+ * node delivers its secret as a `B3OS_CONN_<N>` variable, and the shim writes the harness's MCP config to
6734
+ * send it (as a variable the config refers to, never the value: opencode's `{env:...}`, Claude Code's
6735
+ * `${...}`, Codex's `bearer_token_env_var`), so code in the instance can read it. It needs `vault:run` and
6736
+ * `vault:connections:reveal`, and a connection whose type has a credential field (`api_key`, `bearer` or
6737
+ * `oauth2`; another is `400 invalid_request`). A connection bound to `hosts` is `422
6738
+ * connection_host_bound` (B3OS adds such a credential only at the egress proxy, never inside a VM), and one
6739
+ * holding a plan's token is `400 harness_plan_credential`.
6740
+ */
6741
+ connection?: string;
6742
+ }
6743
+
6744
+ /**
6745
+ * A server the harness starts in the instance, as the harness's user, over stdio. With `npm`, the package is
6746
+ * installed at prepare and its commands are on the server's `PATH`; until prepared snapshots ship that answers
6747
+ * `422 harness_setup_needs_prepare`.
6748
+ */
6749
+ export interface AgentHarnessMcpStdio {
6750
+ command: string[];
6751
+ npm?: AgentHarnessNpmSource;
6752
+ /**
6753
+ * The server's environment. A `{connection}` value is a vault connection's secret, delivered as a
6754
+ * `B3OS_CONN_<N>` variable and set in the server's environment by the shim, so code in the instance can read
6755
+ * it; it needs `vault:run` and `vault:connections:reveal`. `field` names the secret field, and is required
6756
+ * for a connection type with no credential field of its own (`400 invalid_request`). A connection bound to
6757
+ * `hosts` is `422 connection_host_bound`.
6758
+ */
6759
+ env?: Record<
6760
+ string,
6761
+ | string
6762
+ | {
6763
+ connection: string;
6764
+ /** Which secret field of the connection, as a sandbox's `secrets` takes it. */
6765
+ field?: string;
6766
+ }
6767
+ >;
6768
+ }
6769
+
6770
+ /**
6771
+ * B3OS's own MCP server inside the instance, at the instance's local address (`B3OS_MCP_URL`): the `mcp.b3os`
6772
+ * entry, and only that one. The default is `{builtin: b3os}` with all six toolsets; what you write under `b3os`
6773
+ * is merged into it as a JSON merge patch, so `{toolsets: [vision]}` narrows it and `builtin` need not be
6774
+ * restated. It brings the instance's B3OS MCP grant: the node fills `api` with the scopes the merged entry's
6775
+ * `toolsets` need, scoped to the instance, unless the definition sets `api` itself. A definition without this
6776
+ * entry gets no filled B3OS MCP scopes (only `infer:run` when it declares a `node` profile, and nothing
6777
+ * otherwise). The server lists the tools of each toolset this node serves, so a node without one lists fewer
6778
+ * tools.
6779
+ */
6780
+ export interface AgentHarnessMcpBuiltin {
6781
+ /** `b3os`: B3OS's own server, the default's; may be left out. */
6782
+ builtin?: "b3os";
6783
+ /**
6784
+ * Which of B3OS's tools the server lists, and so which scopes the filled grant holds. Default: all six.
6785
+ * `browser` (the `browser_*` tools; `vision:run` and `vision:write`), `vision` (web pages: `vision_scrape`
6786
+ * and the like; `vision:run`), `render` (screenshots and videos; `render:run`), `sandboxes` (code in
6787
+ * other sandboxes; `sandboxes:run`), `actions` (the pack actions the grant's actions rule allows;
6788
+ * `actions:read` and `actions:run`) and `infer` (the node's models; `infer:run`).
6789
+ */
6790
+ toolsets?: Array<"browser" | "vision" | "render" | "sandboxes" | "actions" | "infer">;
6791
+ }
6792
+
6793
+ export interface AgentHarnessFile {
6794
+ /**
6795
+ * Relative to the workspace, or, in a skill's or plugin's `files`, to the item's folder. A path with a `..`
6796
+ * segment is `400 invalid_request`.
6797
+ */
6798
+ path: string;
6799
+ text: string;
6800
+ }
6801
+
6802
+ /** Where the harness's events go beyond its session's stream, and who answers its questions. */
6803
+ export interface AgentHarnessHooks {
6804
+ webhook?: AgentHarnessWebhook;
6805
+ decide?: AgentHarnessDecide;
6806
+ /**
6807
+ * Add each event's native payload (`native.payload`: the harness's own hook or stream record), after the
6808
+ * redaction listeners use. Off by default, because a native payload can hold a tool's whole input.
6809
+ * @default false
6810
+ */
6811
+ include_native?: boolean;
6812
+ }
6813
+
6814
+ /** An event type (`harness.turn.completed`), a family (`harness.turn.*`) or `*` for every type. */
6815
+ export type AgentHarnessEventPattern = string;
6816
+
6817
+ /**
6818
+ * Where the agents product sends this agent's `harness.*` events, from every instance and every way a turn
6819
+ * came: each event `events` selects is a `POST` of a `WebhookEvent` (`agentsDeliverHarnessEvent`), signed with
6820
+ * `B3OS-Signature` and the URL's secret (`POST /v1/webhooks/secret`), retried with backoff for 24 hours, in
6821
+ * order per session. Delivery goes through the egress guard.
6822
+ */
6823
+ export interface AgentHarnessWebhook {
6824
+ /** An `https://` URL. */
6825
+ url: string;
6826
+ /**
6827
+ * Default: every type but `harness.message`, which carries each piece of streamed text as its own event; name
6828
+ * it, or `*`, to get it too.
6829
+ */
6830
+ events?: AgentHarnessEventPattern[];
6831
+ }
6832
+
6833
+ /**
6834
+ * A webhook that answers the harness's questions while the turn waits (`agentsDecideHarnessEvent`): before a
6835
+ * tool runs (`harness.tool.requested`), when the harness asks for permission (`harness.permission.requested`),
6836
+ * or as a turn starts (`harness.turn.started`, to add context). The harness's shim hands each question to the
6837
+ * node (`POST /v1/agents/self/decide`), and the node makes the call: signed as a webhook delivery is, through
6838
+ * the egress guard (private and loopback addresses refused), so the URL's secret never enters the instance and
6839
+ * its host need not be in the instance's `egress`. The turn waits up to `timeout_ms` for `{decision: allow |
6840
+ * deny | ask, reason?, context?}`. It fails closed: no answer in time, a status other than 2xx, or a body
6841
+ * without a `decision` is `deny`, unless `on_timeout` is `allow`. `ask` hands the question to a person. The
6842
+ * definition's own rules come first, and in `permissions: plan` the webhook is never called: the harness's
6843
+ * read-only mode and the rules answer every question there.
6844
+ */
6845
+ export interface AgentHarnessDecide {
6846
+ /** An `https://` URL. */
6847
+ url: string;
6848
+ /** @default ["harness.tool.requested"] */
6849
+ events?: Array<"harness.tool.requested" | "harness.permission.requested" | "harness.turn.started">;
6850
+ /**
6851
+ * How long the turn waits for the answer.
6852
+ * @default 3000
6853
+ */
6854
+ timeout_ms?: number;
6855
+ /**
6856
+ * The decision when the webhook does not answer in time, fails, or answers without a decision.
6857
+ * @default "deny"
6858
+ */
6859
+ on_timeout?: "deny" | "allow";
6860
+ }
6861
+
6862
+ export interface AgentHarnessTerminal {
6863
+ /**
6864
+ * Record the terminal as asciicast v3 files on the instance's disk (`…/terminal/recordings`). Off by default:
6865
+ * a recording keeps whatever the terminal showed, codes and keys printed in it included.
6866
+ * @default false
6867
+ */
6868
+ record?: boolean;
6869
+ }
6870
+
6871
+ /**
6872
+ * The type of a harness event, the same for every harness. Each is what the instance reports about itself, not
6873
+ * something the node observed. What each carries in `data`:
6874
+ *
6875
+ * - `harness.session.started`: `native_session` (the harness's own session ID), `resumed`, `model`, `auth`
6876
+ * (`profile`, `type`, `provider`) and `withheld` (the names of the variables the shim kept from the harness,
6877
+ * never their values). `harness.session.ended`: `reason`.
6878
+ * - `harness.turn.started`: `source`, `profile`, `chars`, `prompt` (the first 4,000 characters). `source` is
6879
+ * where the turn came from, set from the message's `initiator` and never from its body: `api` (a key, a
6880
+ * person or a sandbox), `routine`, `listener`, `instance` (another agent instance), `terminal` (typed in the
6881
+ * terminal), `steer`, or `fallback` (the turn a profile's `fallback` with `resume: continue` starts).
6882
+ * - `harness.message`: `role`, `text`, `delta` (`true` while the text streams).
6883
+ * - `harness.tool.requested`: `tool`, `call_id`, `summary`, `parent` (the subagent's call, when one ran it).
6884
+ * `harness.tool.completed`: `tool`, `call_id`, `ok`, `duration_ms`.
6885
+ * - `harness.permission.requested`: `request` (the `dec_` ID `POST …/decisions` answers), `kind`, `tool`,
6886
+ * `summary`, `reason`. `harness.permission.resolved`: `request`, or `call_id` for a call the definition's
6887
+ * rules or `hooks.decide` answered without asking; `decision`, `by` (`rules`, `decide`, `person`, `timeout`
6888
+ * or `withdrawn`, when the turn ended first) and `reason`.
6889
+ * - `harness.subagent.started`: `agent_id`, `kind`, `model`. `harness.subagent.completed`: `agent_id`.
6890
+ * - `harness.compacted`: nothing.
6891
+ * - `harness.turn.completed`: `result`, `usage` (`AgentHarnessUsage`), `cost_usd` and `list_price_usd` (as on a
6892
+ * usage row), `timing` (`model_ms`, `tool_ms`, `wall_ms`), `steps` and `files` (the workspace paths the turn
6893
+ * changed, when the harness reports them). `harness.turn.failed`: `error` (`code`, `detail`; `limit_reached`,
6894
+ * `auth_required` and `no_profile_ready` carry `profile` and `resets_at` when known), `timing`, `usage`.
6895
+ * `harness.turn.interrupted`: `timing`, `usage`.
6896
+ * - `harness.terminal.attached` and `harness.terminal.detached`: `role`, `viewer`, `viewers` (how many remain).
6897
+ * - `harness.auth.required`: `profile`, `reason` (`signed_out`, `expired`, `refused` or `missing`), `detail`.
6898
+ * - `harness.auth.ready`: `profile`, `type`, `provider` and `plan` (what the harness says it is signed in as,
6899
+ * when it says).
6900
+ * - `harness.auth.limited`: `profile`, `limit` (`usage`, `credits` or `rate`), `resets_at` and `used_percent`
6901
+ * when the harness reports them, `detail`.
6902
+ * - `harness.auth.switched`: `from`, `to`, `why` (`requested` or `fallback`), `billed_to`.
6903
+ * - `harness.auth.removed`: `profile`, `cli`, `reason`: `signed_out` (the owner signed out), or
6904
+ * `signin_not_personal` (a harness's credential file where no sign-in belongs, removed without being read).
6905
+ */
6906
+ export type AgentHarnessEventType =
6907
+ | "harness.session.started"
6908
+ | "harness.session.ended"
6909
+ | "harness.turn.started"
6910
+ | "harness.message"
6911
+ | "harness.tool.requested"
6912
+ | "harness.tool.completed"
6913
+ | "harness.permission.requested"
6914
+ | "harness.permission.resolved"
6915
+ | "harness.subagent.started"
6916
+ | "harness.subagent.completed"
6917
+ | "harness.compacted"
6918
+ | "harness.turn.completed"
6919
+ | "harness.turn.failed"
6920
+ | "harness.turn.interrupted"
6921
+ | "harness.terminal.attached"
6922
+ | "harness.terminal.detached"
6923
+ | "harness.auth.required"
6924
+ | "harness.auth.ready"
6925
+ | "harness.auth.limited"
6926
+ | "harness.auth.switched"
6927
+ | "harness.auth.removed";
6928
+
6929
+ /** A turn's token use, one row per model, as the harness reported it. */
6930
+ export interface AgentHarnessUsage {
6931
+ models: AgentHarnessUsageRow[];
6932
+ [key: string]: unknown;
6933
+ }
6934
+
6935
+ /**
6936
+ * One model's tokens in a turn, and who pays for them. `cost_usd` is there only when `billed_to` is `key` or
6937
+ * `node`; for a plan's turn, the figure the harness reports goes in `list_price_usd`, so a sum of `cost_usd`
6938
+ * never counts a plan's turns as spend.
6939
+ */
6940
+ export interface AgentHarnessUsageRow {
6941
+ model: string;
6942
+ input: number;
6943
+ cacheRead: number;
6944
+ cacheWrite: number;
6945
+ output: number;
6946
+ reasoning?: number;
6947
+ profile: AgentHarnessProfileName;
6948
+ /** `key`: the key's owner, through the provider. `plan`: a person's plan. `node`: infer on the node. */
6949
+ billed_to: "key" | "plan" | "node";
6950
+ /** What the harness or infer reports this row cost, for `key` and `node` only. */
6951
+ cost_usd?: number;
6952
+ /** For `plan` only, what the harness reports the tokens would cost at list price; not a charge. */
6953
+ list_price_usd?: number;
6954
+ }
6955
+
6956
+ /**
6957
+ * One event of a harness, in the product-event envelope (ARCHITECTURE 4.12). The harness's shim writes `id`,
6958
+ * `type`, `time`, `harness`, `conversation`, `data` and `native`. The node sets `seq`, `org`, `project`,
6959
+ * `instance` and, for an event of a delivered turn, `session_id` and `subject` (from the session) as it writes
6960
+ * the event to the instance's log, replacing whatever the shim sent on a delivery's answer. The shim numbers
6961
+ * the events of its own streams too, but that number orders them only within one run of the shim and starts
6962
+ * again when the shim restarts; a self event carries none (`AgentSelfEvent`).
6963
+ */
6964
+ export interface AgentHarnessEvent {
6965
+ /** Unique per event; deduplicate on it. */
6966
+ id: string;
6967
+ /**
6968
+ * The event's place in its instance's event log, set by the node and growing across restarts of the
6969
+ * harness's shim. The SSE `id` of `GET …/stream`.
6970
+ */
6971
+ seq: number;
6972
+ type: AgentHarnessEventType;
6973
+ time: string;
6974
+ harness: AgentHarnessKindName;
6975
+ org?: string;
6976
+ project?: string;
6977
+ instance?: string;
6978
+ /** The agent session, for an event of a turn sent as a message. */
6979
+ session_id?: string;
6980
+ /** The harness session the event belongs to (the message's `conversation`). */
6981
+ conversation?: string;
6982
+ /** The end user the turn is for, for an event of a delivered turn (the session's `subject`). */
6983
+ subject?: string;
6984
+ /** What happened; `AgentHarnessEventType` lists the members of each type. */
6985
+ data: {
6986
+ usage?: AgentHarnessUsage;
6987
+ [key: string]: unknown;
6988
+ };
6989
+ /** The harness event this one came from. `payload` only with `hooks.include_native`. */
6990
+ native?: {
6991
+ harness: AgentHarnessKindName;
6992
+ event: string;
6993
+ payload?: unknown;
6994
+ };
6995
+ }
6996
+
6997
+ /**
6998
+ * One harness this node runs, as its driver declares it (`b3os-harness catalog --json`, printed by the shim
6999
+ * and served as printed). A feature not yet checked against the kind's pinned version is left out, and a
7000
+ * definition that uses it is refused.
7001
+ */
7002
+ export interface AgentHarnessKind {
7003
+ object: "harness_kind";
7004
+ kind: AgentHarnessKindName;
7005
+ /** The harness's own name. */
7006
+ name: string;
7007
+ /**
7008
+ * `native`: a driver built into the shim and reviewed by B3. `acp`: the generic Agent Client Protocol
7009
+ * adapter, which runs the harness as its own process over stdio.
7010
+ */
7011
+ driver: "native" | "acp";
7012
+ /** The versions this node runs, newest first. */
7013
+ versions: string[];
7014
+ /** What a definition without `version` gets. */
7015
+ default_version: string;
7016
+ modes: Array<"api" | "terminal">;
7017
+ capabilities: AgentHarnessCapabilities;
7018
+ auth: AgentHarnessKindAuth;
7019
+ /** The lists of the `harness` block this kind takes; another is `422 harness_capability_unsupported`. */
7020
+ setup: Array<"skills" | "plugins" | "mcp" | "instructions" | "settings">;
7021
+ /**
7022
+ * The kind's own settings keys the shim owns (its hooks, permissions, login method, providers, MCP servers,
7023
+ * and the plugins and marketplaces it turns on), which a definition's `settings` may not set (`400
7024
+ * invalid_request`).
7025
+ */
7026
+ settings_refused: string[];
7027
+ /**
7028
+ * The environment variables this kind reads a plan's token from. No harness agent's `env` or `secrets` sets
7029
+ * these, or any other kind's (`400 invalid_request`).
7030
+ */
7031
+ plan_env: AgentHarnessPlanEnv[];
7032
+ }
7033
+
7034
+ /** What the kind's driver delivers; the shim's conformance test checks each one it declares. */
7035
+ export interface AgentHarnessCapabilities {
7036
+ /** A running turn takes more text (`POST …/steer`). */
7037
+ steer: boolean;
7038
+ /** A running turn stops with its usage so far, and the harness session stays open. */
7039
+ interrupt: boolean;
7040
+ /** A conversation continues its harness session after the shim or the instance restarts. */
7041
+ resume: boolean;
7042
+ /**
7043
+ * Which tool calls the shim sees before they run, and so which `hooks.decide` on `harness.tool.requested`
7044
+ * answers: `every_tool`, `asked` (only the calls the harness asks permission for), or `partial` (some calls
7045
+ * run without asking, such as Codex's read-only commands).
7046
+ */
7047
+ tool_gate: "every_tool" | "asked" | "partial";
7048
+ /**
7049
+ * The `mode`s in which `hooks.decide` answers. A definition with `hooks.decide` in another mode is `422
7050
+ * harness_capability_unsupported`, but in `permissions: plan`, where the webhook is never called. opencode
7051
+ * lists `api` only: in `terminal` its TUI answers permission prompts itself.
7052
+ */
7053
+ decide_modes: Array<"api" | "terminal">;
7054
+ /** Turns report their tokens per model. */
7055
+ usage: boolean;
7056
+ /** The harness's subagents show as `harness.subagent.*` events. */
7057
+ subagent_events: boolean;
7058
+ }
7059
+
7060
+ /** The credential profiles the kind takes (`AgentHarnessAuthProfile`). */
7061
+ export interface AgentHarnessKindAuth {
7062
+ /** Each `key` provider the kind takes, with the environment variables a profile of it sets. */
7063
+ key: Record<string, string[]>;
7064
+ /**
7065
+ * The plans a person may sign in to in a `signin` profile; empty when the kind takes none. `anthropic`
7066
+ * also needs `agents.claude_plan_signin`.
7067
+ */
7068
+ signin: Array<"anthropic" | "openai">;
7069
+ /** A `node` profile (a model the node's infer serves) works with this kind. */
7070
+ node: boolean;
7071
+ /**
7072
+ * The hosts a profile of each provider reaches from the instance at the kind's pinned version, measured on
7073
+ * the pin with the kind's own switches for the CLI's other traffic set (telemetry, update checks, a plugin
7074
+ * sync). The node puts them in the filled `egress` and checks your own `egress` against them
7075
+ * (`AgentHarness`).
7076
+ * - `key`: what a turn on each `auth.key` provider reaches: its model API, and a model catalog the kind
7077
+ * fetches for it. A `*_compatible` provider lists none; its `base_url` host stands for them.
7078
+ * - `signin`: each `auth.signin` provider's login, token and model API hosts.
7079
+ *
7080
+ * Exact hosts or `*.` wildcards. A `{region}` label is filled from the profile's `region`, which a profile
7081
+ * of that provider then needs (`400 invalid_request` without one). A profile whose provider is not listed
7082
+ * here is refused (`422 harness_capability_unsupported`).
7083
+ */
7084
+ hosts: {
7085
+ key: Record<string, string[]>;
7086
+ signin: Record<string, string[]>;
7087
+ };
7088
+ }
7089
+
7090
+ /**
7091
+ * An environment variable a harness reads a plan's token from, or that changes where it signs in:
7092
+ * `CLAUDE_CODE_OAUTH_TOKEN` and `CLAUDE_CODE_OAUTH_REFRESH_TOKEN` (Claude Code 2.1.332; `claude auth login`
7093
+ * signs in from the refresh token);
7094
+ * Claude Code 2.1.332's session and bridge tokens (`CLAUDE_CODE_SESSIONS_OAUTH_TOKEN`, `CLAUDE_BRIDGE_OAUTH_TOKEN`,
7095
+ * `CLAUDE_CODE_SESSION_ACCESS_TOKEN`), the forms that read a token from a descriptor or a file, which a value
7096
+ * check cannot see (`CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR`, `CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR`,
7097
+ * `CLAUDE_SESSION_INGRESS_TOKEN_FILE`, `CLAUDE_CODE_HOST_CREDS_FILE`), an account credential
7098
+ * (`CLAUDE_TRUSTED_DEVICE_TOKEN`) and the OAuth endpoint overrides (`CLAUDE_CODE_CUSTOM_OAUTH_URL`,
7099
+ * `CLAUDE_LOCAL_OAUTH_API_BASE`, `USE_LOCAL_OAUTH`, `USE_STAGING_OAUTH`), all read from the binary's strings;
7100
+ * `ANTHROPIC_OAUTH_TOKEN` (pi), and `CODEX_ACCESS_TOKEN` (Codex 0.164.0: `codex login --with-access-token`
7101
+ * reads an access token from it; refused until it is checked whether that token is a ChatGPT plan's). An agent
7102
+ * with a `harness` block never takes one of these names in `env` or `secrets`, in an `mcp` server's `env`, or
7103
+ * in a `settings` `env` entry, whatever its `kind`, since the `harness` template holds every harness: `400
7104
+ * invalid_request`. Names alone do not hold the line, because pi sends any Anthropic key whose value holds
7105
+ * `sk-ant-oat` as a plan login: a value holding `sk-ant-oat` or `sk-ant-ort` is `400 harness_plan_credential`
7106
+ * anywhere in the definition and in the resolved value of every connection it names (`AgentHarness`), and the
7107
+ * shim drops every variable whose value holds one from the harness's environment and the terminal's. B3OS
7108
+ * never stores a plan's token.
7109
+ */
7110
+ export type AgentHarnessPlanEnv =
7111
+ | "CLAUDE_CODE_OAUTH_TOKEN"
7112
+ | "CLAUDE_CODE_OAUTH_REFRESH_TOKEN"
7113
+ | "ANTHROPIC_OAUTH_TOKEN"
7114
+ | "CODEX_ACCESS_TOKEN"
7115
+ | "CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR"
7116
+ | "CLAUDE_CODE_SESSIONS_OAUTH_TOKEN"
7117
+ | "CLAUDE_BRIDGE_OAUTH_TOKEN"
7118
+ | "CLAUDE_CODE_SESSION_ACCESS_TOKEN"
7119
+ | "CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR"
7120
+ | "CLAUDE_SESSION_INGRESS_TOKEN_FILE"
7121
+ | "CLAUDE_CODE_HOST_CREDS_FILE"
7122
+ | "CLAUDE_TRUSTED_DEVICE_TOKEN"
7123
+ | "CLAUDE_CODE_CUSTOM_OAUTH_URL"
7124
+ | "CLAUDE_LOCAL_OAUTH_API_BASE"
7125
+ | "USE_LOCAL_OAUTH"
7126
+ | "USE_STAGING_OAUTH";
7127
+
7128
+ /**
7129
+ * The catalog as the shim prints it (`b3os-harness catalog --json`): the kinds in `data`, open-source first,
7130
+ * and `checks`. The node stores it with the `harness` template's build and serves it unchanged.
7131
+ */
7132
+ export type AgentHarnessKindList = Omit<ListEnvelope, "data"> & {
7133
+ data: AgentHarnessKind[];
7134
+ checks: AgentHarnessCatalogChecks;
7135
+ };
7136
+
7137
+ /**
7138
+ * What the shim refuses or removes at start beyond each kind's entry, so the node refuses the same at write:
7139
+ * per kind (`kinds`), the rules for profile names, the plan-token names and value, the workspace paths `files`
7140
+ * may not write, the default `mcp` and `skills` entries, each B3OS toolset's scopes and the flag each gated
7141
+ * sign-in needs.
7142
+ */
7143
+ export interface AgentHarnessCatalogChecks {
7144
+ kinds: Record<string, AgentHarnessKindChecks>;
7145
+ profiles: {
7146
+ /** The most profiles a definition holds. */
7147
+ max: number;
7148
+ /** The pattern a profile's name matches (an ECMAScript regular expression). */
7149
+ name: string;
7150
+ };
7151
+ /** Every kind's plan variables, refused as names on every harness agent. */
7152
+ plan_env: AgentHarnessPlanEnv[];
7153
+ /** The pattern of a plan's token, refused as a value anywhere (an ECMAScript regular expression). */
7154
+ plan_value: string;
7155
+ /** Workspace paths (a file, or a directory ending in `/`) no definition's `files` writes. */
7156
+ files_refused: string[];
7157
+ /**
7158
+ * The entries every definition's `mcp` and `skills` start with. A definition's maps are a JSON merge patch
7159
+ * (RFC 7396) over them (`AgentHarness`); a kind whose `setup` does not list a list gets none.
7160
+ */
7161
+ defaults: {
7162
+ mcp: Record<string, AgentHarnessMcpBuiltin>;
7163
+ skills: Record<string, AgentHarnessSetupItem>;
7164
+ };
7165
+ /** Each B3OS toolset's scopes; the filled grant is the merged `mcp.b3os` entry's toolsets' scopes. */
7166
+ b3os_toolsets: Record<string, string[]>;
7167
+ /** The flag a sign-in to each listed provider needs; a provider not listed, and every key, needs none. */
7168
+ signin_flags: Record<string, string>;
7169
+ }
7170
+
7171
+ /** What the shim enforces for one kind beyond its catalog entry. */
7172
+ export interface AgentHarnessKindChecks {
7173
+ /**
7174
+ * Per `key` provider, the variables the node delivers as `B3OS_PROFILE_<NAME>__<VAR>`; the `optional` ones
7175
+ * may be left out (`AWS_SESSION_TOKEN`).
7176
+ */
7177
+ deliver: Record<
7178
+ string,
7179
+ {
7180
+ env: string[];
7181
+ optional: string[];
7182
+ }
7183
+ >;
7184
+ /** The providers whose profile needs an `https://` `base_url`; any other provider's refuses one. */
7185
+ base_url: AgentHarnessKeyProvider[];
7186
+ /** The providers whose profile takes a `region`. */
7187
+ region: AgentHarnessKeyProvider[];
7188
+ /**
7189
+ * Every variable the shim sets or removes in the kind's processes; a definition's `env` or `secrets` naming one is refused.
7190
+ */
7191
+ env_owned: string[];
7192
+ /** The CLI's config-directory variable, which the shim sets to each profile's directory. */
7193
+ dir_env: string;
7194
+ /** Lists the kind takes only from a prepared snapshot; refused until prepared snapshots ship. */
7195
+ prepare_only: Array<"skills" | "plugins" | "mcp" | "instructions" | "settings">;
7196
+ /**
7197
+ * For a kind that has one, the only keys its `settings.<kind>` takes, checked on its pinned version; any other
7198
+ * key is refused, as is any in its `settings_refused`. Absent: every key not refused is taken.
7199
+ */
7200
+ settings_allowed?: string[];
7201
+ /**
7202
+ * When true, a definition with more than one `key` profile gives each one a model on the profile's own
7203
+ * provider (the profile's `model`, else the block's); one that has none is refused at write. The kind runs
7204
+ * every key profile in one process, each on its own model (opencode), so such a profile would run nothing.
7205
+ */
7206
+ key_profiles_need_model?: boolean;
7207
+ /** The limit and auth signals the driver reads from the CLI. */
7208
+ signals: Record<string, "limit" | "auth">;
7209
+ /** The signals seen live on the kind's pinned version; only these move a profile's `fallback`. */
7210
+ checked: string[];
7211
+ }
7212
+
7213
+ export interface AgentSteerRequest {
7214
+ /** What the harness reads at its next step. Yours, so never quoted. */
7215
+ text: string;
7216
+ }
7217
+
7218
+ export interface AgentDecisionRequest {
7219
+ /** The `request` of the `harness.permission.requested` event, unique per instance. */
7220
+ request: string;
7221
+ decision: "allow" | "deny";
7222
+ /** Shown to the harness with the decision. */
7223
+ reason?: string;
7224
+ }
7225
+
7226
+ export interface AgentDecision {
7227
+ object: "agent_decision";
7228
+ instance_id: string;
7229
+ /**
7230
+ * The session whose turn asked, or `null` for a turn that is not a session (typed in the terminal or
7231
+ * started inside the instance).
7232
+ */
7233
+ session_id: string | null;
7234
+ request: string;
7235
+ decision: "allow" | "deny";
7236
+ reason: string | null;
7237
+ by: AgentSessionInitiator;
7238
+ decided_at: string;
7239
+ }
7240
+
7241
+ /**
7242
+ * `watch`: the live view and the terminal, view-only. `control`: also input, when nobody else holds it.
7243
+ */
7244
+ export type AgentGrantRole = "watch" | "control";
7245
+
7246
+ export interface AgentGrantCreateRequest {
7247
+ /** @default "watch" */
7248
+ role?: AgentGrantRole;
7249
+ /**
7250
+ * How long the link works. Chosen for the beta.
7251
+ * @default 900
7252
+ */
7253
+ ttl_s?: number;
7254
+ /**
7255
+ * How many times the link may be redeemed: each page load is one, and so is each reconnect of its terminal
7256
+ * or event stream. Default, any number until it expires.
7257
+ */
7258
+ uses?: number;
7259
+ }
7260
+
7261
+ export interface AgentGrant {
7262
+ id: string;
7263
+ object: "agent_grant";
7264
+ agent_id: string;
7265
+ key: AgentInstanceKey;
7266
+ role: AgentGrantRole;
7267
+ /** The grant's secret, in the create answer only (`null` everywhere else). Treat it as a password. */
7268
+ token: string | null;
7269
+ /** The share page with the token in its fragment, in the create answer only. */
7270
+ url: string | null;
7271
+ expires_at: string;
7272
+ uses: number | null;
7273
+ uses_left: number | null;
7274
+ created_by: AgentSessionInitiator;
7275
+ created_at: string;
7276
+ }
7277
+
7278
+ export type AgentGrantList = Omit<ListEnvelope, "data"> & {
7279
+ data: AgentGrant[];
7280
+ };
7281
+
7282
+ export interface AgentTerminalRecording {
7283
+ id: string;
7284
+ object: "terminal_recording";
7285
+ /** The harness session whose terminal it recorded. */
7286
+ conversation: string;
7287
+ format: "asciicast-v3";
7288
+ bytes: number;
7289
+ started_at: string;
7290
+ /** The last write; a recording still being written keeps growing. */
7291
+ updated_at: string;
7292
+ }
7293
+
7294
+ export type AgentTerminalRecordingList = Omit<ListEnvelope, "data"> & {
7295
+ data: AgentTerminalRecording[];
7296
+ };
7297
+
7298
+ export interface AgentSelfEventsRequest {
7299
+ events: AgentSelfEvent[];
7300
+ }
7301
+
7302
+ /**
7303
+ * A harness event as the shim records it from inside the instance: an `AgentHarnessEvent` without the members
7304
+ * the node sets (`seq`, `org`, `project`, `instance`, `session_id`, `subject`), which a self event never
7305
+ * carries (`400 invalid_request`): the node assigns the log's `seq` as it writes the event.
7306
+ */
7307
+ export interface AgentSelfEvent {
7308
+ id: string;
7309
+ type: AgentHarnessEventType;
7310
+ time: string;
7311
+ harness: AgentHarnessKindName;
7312
+ conversation?: string;
7313
+ data: {
7314
+ usage?: AgentHarnessUsage;
7315
+ [key: string]: unknown;
7316
+ };
7317
+ native?: {
7318
+ harness: AgentHarnessKindName;
7319
+ event: string;
7320
+ payload?: unknown;
7321
+ };
7322
+ }
7323
+
7324
+ /** A question for the definition's `hooks.decide` webhook, from the harness's shim. */
7325
+ export interface AgentSelfDecideRequest {
7326
+ type: "harness.tool.requested" | "harness.permission.requested" | "harness.turn.started";
7327
+ /**
7328
+ * The session the turn was delivered as (the delivery's `session`), when the question belongs to one. The
7329
+ * node keeps it only when it is the session the instance runs now.
7330
+ */
7331
+ session?: string;
7332
+ conversation?: string;
7333
+ /** `tool`, `input` (the tool's arguments), `summary` and `call_id`; a turn's `prompt`. */
7334
+ data: Record<string, unknown>;
7335
+ }
7336
+
7337
+ export interface AgentSelfDecision {
7338
+ object: "agent_self_decision";
7339
+ /** `ask` hands the question to a person (`harness.permission.requested`). */
7340
+ decision: "allow" | "deny" | "ask";
7341
+ reason?: string;
7342
+ /** Added to what the model sees next, quoted as information. */
7343
+ context?: string;
7344
+ /**
7345
+ * `true` when the webhook did not answer in time, failed or answered without a `decision`, and `decision` is
7346
+ * the definition's `on_timeout`.
7347
+ */
7348
+ fallback: boolean;
7349
+ }
7350
+
7351
+ export interface AgentSelfEventsResult {
7352
+ object: "agent_self_events";
7353
+ accepted: number;
7354
+ /** Events whose `id` the instance had already recorded; not written again. */
7355
+ duplicates: number;
7356
+ }
7357
+
7358
+ /** Set exactly one of `entry` (your own harness) and `harness` (a coding agent B3OS runs for you). */
7359
+ export type AgentCreateRequest = {
7360
+ name: AgentName;
7361
+ source?: AgentSource;
7362
+ entry?: AgentEntry;
7363
+ harness?: AgentHarness;
7364
+ /** Environment variables of the harness. Returned as given; put credentials in `secrets`. */
7365
+ env?: Record<string, string>;
7366
+ /**
7367
+ * Environment variables never returned or logged, as a sandbox's `secrets`: code in the instance can read
7368
+ * them. A memory snapshot holds them, so the node keeps an instance's snapshots to itself: they are never
7369
+ * listed or restorable through the API.
7370
+ */
5539
7371
  secrets?: Record<string, SecretValue>;
5540
7372
  api?: SandboxApiGrant;
5541
7373
  egress?: EgressPolicy;
5542
7374
  sleep?: AgentSleep;
5543
7375
  turns?: AgentTurns;
5544
7376
  metadata?: Metadata;
5545
- }
7377
+ };
5546
7378
 
7379
+ /** `entry` and `harness` never come together, and an agent keeps the one it was made with. */
5547
7380
  export interface AgentUpdateRequest {
5548
7381
  source?: AgentSource;
5549
7382
  entry?: AgentEntry;
7383
+ harness?: AgentHarness;
5550
7384
  env?: Record<string, string>;
5551
7385
  secrets?: Record<string, SecretValue>;
5552
7386
  api?: SandboxApiGrant;
@@ -5576,6 +7410,31 @@ export interface Agent {
5576
7410
  egress: EgressPolicy;
5577
7411
  sleep: AgentSleep;
5578
7412
  turns: AgentTurns;
7413
+ /**
7414
+ * Only on an agent made with a `harness` block (planned), as the node stored it: defaults filled in,
7415
+ * shorthands expanded, git refs resolved to commits, and `mcp` and `skills` as you wrote them, nulls
7416
+ * included, never merged with their default `b3os` entries (`AgentHarness`), so the block can be sent back
7417
+ * as it is.
7418
+ */
7419
+ harness?: AgentHarness;
7420
+ /**
7421
+ * The person a personal agent belongs to, or `null`. An agent with a `signin` profile is personal (planned):
7422
+ * its owner is the person who made it, and it never changes. Everything that drives it or reads what its
7423
+ * instances hold is the owner's alone, and so is changing it: messages, steer, cancel, decisions, making,
7424
+ * waking and putting to sleep its instances (an instance may also put itself to sleep from inside), its
7425
+ * sessions (read, listed or streamed: their results and `session.output` carry the turns), and its
7426
+ * instances' stream, terminal, tickets, grants and recordings. Anyone else, an organization admin included,
7427
+ * gets `403 harness_personal_agent`. The owner or an organization admin may delete it or one of its
7428
+ * instances, and list or revoke its grants. Every `agents:read` caller still sees the definition and each
7429
+ * instance's status and lifecycle events (`GET …/instances`, `GET …/instances/{key}/events`), which hold no
7430
+ * turn. Listeners never send it turns, and routines only when the owner made them. The owner shares a view with a `watch` grant;
7431
+ * `control` grants are refused. Forks and children of it run only on `key` and `node` profiles (`409
7432
+ * harness_profile_unavailable`), and nothing it signed in to is carried to another instance. Not served
7433
+ * yet: until the prerequisites `AgentHarnessAuthSignin` names land, the node makes no personal agent, so
7434
+ * `owner` is `null` on every agent.
7435
+ */
7436
+ owner?: null | AgentOwner;
7437
+ harness_prepared?: AgentHarnessPrepared;
5579
7438
  upgrade: "new_instances" | "on_wake";
5580
7439
  /** How many instances the agent has, in any state. */
5581
7440
  instances: number;
@@ -5584,6 +7443,35 @@ export interface Agent {
5584
7443
  metadata: Metadata;
5585
7444
  }
5586
7445
 
7446
+ export interface AgentOwner {
7447
+ kind: "user";
7448
+ id: string;
7449
+ }
7450
+
7451
+ /**
7452
+ * The revision's prepared snapshot (planned): the `harness` template with only this kind's harness at its
7453
+ * `version` and the recipe's fetched items installed, built once per `key` and shared by the project's agents
7454
+ * with the same key. The build runs in a `builder` sandbox with no secrets and no vault access, reaching only
7455
+ * the recipe's source hosts, and fails if any harness credential file exists in it. Messages wait while it
7456
+ * builds, and that time counts toward `turns.timeout_s`; a failed build fails them with
7457
+ * `harness_prepare_failed`. `upgrade: on_wake` moves instances only to a revision whose snapshot is `ready`.
7458
+ * It counts against your snapshot quota.
7459
+ */
7460
+ export interface AgentHarnessPrepared {
7461
+ /**
7462
+ * The prepare key: the SHA-256 of the template's ID and revision, the shim's version, the `kind`, the
7463
+ * `version` and the resolved sources of the fetched items. A change elsewhere in the block keeps it.
7464
+ */
7465
+ key: string;
7466
+ /** `none`: nothing is built for this revision yet. */
7467
+ status: "none" | "queued" | "building" | "ready" | "failed";
7468
+ /** The snapshot instances start from, once `ready`; also the filled `source.snapshot`. */
7469
+ snapshot: string | null;
7470
+ built_at: string | null;
7471
+ /** Why the last build failed, naming the step and the item. */
7472
+ error: null | Problem;
7473
+ }
7474
+
5587
7475
  export type AgentList = Omit<ListEnvelope, "data"> & {
5588
7476
  data: Agent[];
5589
7477
  };
@@ -5621,7 +7509,10 @@ export interface AgentInstance {
5621
7509
  key: AgentInstanceKey;
5622
7510
  revision: number;
5623
7511
  status: AgentInstanceStatus;
5624
- /** The instance's microVM, the same through every sleep tier; `null` before it was first made. */
7512
+ /**
7513
+ * The instance's microVM, the same through every sleep tier; `null` before it was first made. `null` too for
7514
+ * an instance of a personal agent (planned), whose microVM the generic sandboxes API does not reach.
7515
+ */
5625
7516
  sandbox_id: string | null;
5626
7517
  /** Host memory the instance holds now (0 when hibernated or dormant). */
5627
7518
  resident_mib: number;
@@ -5675,6 +7566,16 @@ export type AgentInstanceEventList = Omit<ListEnvelope, "data"> & {
5675
7566
  /**
5676
7567
  * Your message. Every member but the reserved ones (`type`, `conversation`, `subject`, `metadata`, `create`,
5677
7568
  * `webhook`) is yours, and reaches the harness as `message`, with `type`.
7569
+ *
7570
+ * A message to an agent with a `harness` block (planned) is closed instead. Besides the reserved members it takes
7571
+ * `text` (the prompt, a string of 1 to 262,144 characters, required), `context` (at most 16 `{text, source?}`
7572
+ * objects, each quoted as information), `profile` (one of the definition's credential profiles) and, from a
7573
+ * listener's actor sink (`type: listener.event`), `event`, quoted whole, in place of `text`. Any other member is
7574
+ * `400 invalid_request`, so a field the harness would not read is refused, not dropped. A listener's message
7575
+ * is `422 harness_capability_unsupported` until the harness's shim quotes its `event`.
7576
+ * `source`, `limits` and `parent` are reserved there for the run contract.
7577
+ * These members bind harness agents only: an agent with an `entry` keeps every member but the reserved ones as
7578
+ * its own.
5678
7579
  */
5679
7580
  export interface AgentMessageRequest {
5680
7581
  /**
@@ -5728,6 +7629,8 @@ export type AgentSessionList = Omit<ListEnvelope, "data"> & {
5728
7629
 
5729
7630
  /**
5730
7631
  * `session.waking` carries `woke_from`; `session.output` carries `data`, one event the harness streamed, as text.
7632
+ * For an agent with a `harness` block (planned), each `session.output`'s `data` is one `AgentHarnessEvent` as
7633
+ * JSON, as the node wrote it to the instance's event log (its `seq` is the log's, not this stream's).
5731
7634
  */
5732
7635
  export type AgentSessionEvent = JobEvent & {
5733
7636
  woke_from?: AgentWokeFrom;
@@ -5763,7 +7666,7 @@ export interface RoutineDefinition {
5763
7666
  */
5764
7667
  vars?: Record<string, unknown>;
5765
7668
  /**
5766
- * How runs start besides POST /v1/routines/{id}/runs. Triggers switch atomically when a new version is published. Action triggers are trigger subscriptions (tsub_): publishing a version creates or updates them, and a rollback or delete removes them (README, 'Pack triggers').
7669
+ * How runs start besides POST /v1/routines/{id}/runs. Triggers switch atomically when a new version is published. Action triggers are trigger subscriptions (tsub_): publishing a version creates or updates them, and a rollback or delete removes them (README, 'Pack triggers'). Listener triggers are listeners (lsn_): one the trigger declares is the routine's own (publishing creates it, and a version without the trigger or a delete removes it); one the trigger names by id or name is bound for as long as a version names it (README, 'Listener triggers').
5767
7670
  */
5768
7671
  triggers?: RoutineDefinitionTrigger[];
5769
7672
  defaults?: {
@@ -5983,15 +7886,19 @@ export type RoutineDefinitionCatchUp = "skip" | "latest" | "all";
5983
7886
  export type RoutineDefinitionOverlap = "skip" | "buffer_one" | "allow" | "cancel_running";
5984
7887
 
5985
7888
  /**
5986
- * trigger context by type. cron and interval: {type, id, occurrence_id, scheduled_at, fired_at}. webhook: {type, id, hook_id, delivery_id, received_at, method, headers (lowercase map), query (map), body (parsed JSON when the request is JSON, else string)}. action: {type, id, subscription_id, event_id, event_type, source, time, data (the pack trigger's event data, valid against its eventSchema)}. Runs started through the API: {type: api}; sub-routine runs: {type: routine, parent_run_id, parent_step_id}.
7889
+ * trigger context by type. cron and interval: {type, id, occurrence_id, scheduled_at, fired_at}. webhook: {type, id, hook_id, delivery_id, received_at, method, headers (lowercase map), query (map), body (parsed JSON when the request is JSON, else string)}. action: {type, id, subscription_id, event_id, event_type, source, time, data (the pack trigger's event data, valid against its eventSchema)}. listener: {type, id, listener_id, event_id, seq, dedupe_key, received_at, payload (the event as the listener kept it, after redact), trace_id (the run's trace, derived from the listener and the event)}. Runs started through the API: {type: api}; sub-routine runs: {type: routine, parent_run_id, parent_step_id}.
5987
7890
  */
5988
7891
  export type RoutineDefinitionTrigger = {
5989
- type: "cron" | "interval" | "webhook" | "action";
7892
+ type: "cron" | "interval" | "webhook" | "action" | "listener";
5990
7893
  id: RoutineDefinitionIdent;
5991
7894
  /** action only: the pack trigger to subscribe to. */
5992
7895
  uses?: RoutineDefinitionTriggerRef;
5993
7896
  /**
5994
- * cron, interval, webhook: the run input built from the event (context: trigger, vars), validated against inputs; absent: {} plus input defaults. action: the pack trigger's configuration, validated against its configSchema and evaluated once when the version is published (context: vars only); action runs start with {} plus input defaults and read the event from trigger.data.
7897
+ * listener only: an object declares the routine's own listener (listenerTrigger); a string names a listener that already exists in the project (listenerRef).
7898
+ */
7899
+ listener?: RoutineDefinitionListenerTrigger | RoutineDefinitionListenerRef;
7900
+ /**
7901
+ * cron, interval, webhook, listener: the run input built from the event (context: trigger, vars), validated against inputs; absent: {} plus input defaults. action: the pack trigger's configuration, validated against its configSchema and evaluated once when the version is published (context: vars only); action runs start with {} plus input defaults and read the event from trigger.data.
5995
7902
  */
5996
7903
  with?: RoutineDefinitionTemplateObject;
5997
7904
  /**
@@ -5999,7 +7906,7 @@ export type RoutineDefinitionTrigger = {
5999
7906
  */
6000
7907
  connections?: Record<string, RoutineDefinitionConnectionRef>;
6001
7908
  /**
6002
- * Start a run only when true (context: trigger, vars). A webhook delivery that does not match is acknowledged with 202 and starts nothing; an action event that does not match is dropped. Status functions are not available here.
7909
+ * Start a run only when true (context: trigger, vars). A webhook delivery that does not match is acknowledged with 202 and starts nothing; an action or listener event that does not match is dropped. Status functions are not available here.
6003
7910
  */
6004
7911
  if?: RoutineDefinitionCondition;
6005
7912
  /**
@@ -6029,6 +7936,31 @@ export type RoutineDefinitionTrigger = {
6029
7936
  dedupe?: RoutineDefinitionCelExpression;
6030
7937
  };
6031
7938
 
7939
+ /**
7940
+ * listener only: the listener the trigger holds, in the shape of POST /v1/listeners (listeners.yaml ListenerCreateRequest) without sink, name, ttl_s, expires_at and metadata: its sink is this routine and it lives as long as a version with this trigger is active. Publishing creates it (lsn_, owned by the routine, read-only in /v1/listeners) as the publishing key, which needs routines:run; the listeners product validates it, and a refusal fails the publish with routine_invalid pointing into this object. Taken as written: nothing in it is evaluated as a routine expression (an http_poll URL's ${{ cursor }} is the listener's own).
7941
+ */
7942
+ export interface RoutineDefinitionListenerTrigger {
7943
+ /** listeners.yaml ListenerSource: push, http_poll, sse, websocket, webhook or pack. */
7944
+ source: {
7945
+ type: "push" | "http_poll" | "sse" | "websocket" | "webhook" | "pack";
7946
+ };
7947
+ /** listeners.yaml ListenerDedupe. */
7948
+ dedupe?: Record<string, unknown>;
7949
+ /**
7950
+ * listeners.yaml ListenerFilter: a CEL filter over the event, or a model filter, applied before the event is kept.
7951
+ */
7952
+ filter?: Record<string, unknown>;
7953
+ /** listeners.yaml ListenerRedact: JSON pointers removed from each payload before it is kept. */
7954
+ redact?: string[];
7955
+ /** listeners.yaml ListenerBudgetRequest. */
7956
+ budget?: Record<string, unknown>;
7957
+ }
7958
+
7959
+ /**
7960
+ * listener only, behind the preview flag routines.named_listeners (with listeners.api): a listener that already exists in this project, by its id (lsn_...) or its name (among the listeners that have not ended; a name two of them share is refused). Publishing binds it: its sink becomes this routine and trigger (sink.bound in /v1/listeners), so its delivery, order and retries stay the listener's own. The publishing key needs listeners:read, and listeners:write when the listener's sink points anywhere else. A listener another trigger holds, one a routine made, or one that has ended is refused. A version without the trigger, a rollback to one, or deleting the routine unbinds it and pauses it (status_reason routine_unbound). Pausing the routine holds its deliveries until the sink's retry_for_s.
7961
+ */
7962
+ export type RoutineDefinitionListenerRef = string;
7963
+
6032
7964
  /**
6033
7965
  * webhook only: answer a provider's GET verification request, such as Meta's hub.challenge with hub.verify_token or Dropbox's challenge. GET /v1/routines/hooks/{hk_id}?<param>=<value>&<token_param>=<verify token> answers 200 text/plain with <value> and starts no run; a missing or wrong token answers 401 webhook_signature_invalid. <value> must be 1-1024 characters of A-Z a-z 0-9 and . _ ~ : + / = -. Without token_param and token_connection any caller gets the echo; the POST deliveries are verified by verify either way.
6034
7966
  */
@@ -6081,7 +8013,7 @@ export interface RoutineHook {
6081
8013
  export interface RoutineTrigger {
6082
8014
  /** The trigger's `id` in the definition. */
6083
8015
  id: string;
6084
- type: "cron" | "interval" | "webhook" | "action";
8016
+ type: "cron" | "interval" | "webhook" | "action" | "listener";
6085
8017
  status: "active" | "paused";
6086
8018
  /** Next scheduled fire (cron and interval), or `null`. */
6087
8019
  next_fire_at: string | null;
@@ -6091,6 +8023,10 @@ export interface RoutineTrigger {
6091
8023
  * The trigger subscription of an action trigger (`GET /v1/actions/subscriptions/{subscription_id}`), or `null`.
6092
8024
  */
6093
8025
  subscription_id: string | null;
8026
+ /**
8027
+ * The listener of a listener trigger (`GET /v1/listeners/{listener_id}`), or `null`. A listener the trigger declares is the routine's and read-only there; one it names stays its owner's, bound to this trigger (`sink.bound`).
8028
+ */
8029
+ listener_id: string | null;
6094
8030
  }
6095
8031
 
6096
8032
  export interface Routine {
@@ -6115,7 +8051,7 @@ export interface Routine {
6115
8051
  updated_at: string;
6116
8052
  metadata: Metadata;
6117
8053
  /**
6118
- * Present only when something about the active version needs attention. Today: a `product_unavailable` warning at `/triggers/<i>` for each action trigger whose subscription the actions product does not hold yet (it was not running, or answered 5xx or 429, when the version was published). The publish stands, the trigger starts no runs until it is subscribed, and routines retries the subscription every 10 seconds until the actions product takes it; the warning then goes away. A 4xx from the actions product fails the publish with `routine_invalid` instead.
8054
+ * Present only when something about the active version needs attention. Today: a `product_unavailable` warning at `/triggers/<i>` for each action trigger whose subscription the actions product does not hold yet (it was not running, or answered 5xx or 429, when the version was published). The publish stands, the trigger starts no runs until it is subscribed, and routines retries the subscription every 10 seconds until the actions product takes it; the warning then goes away. A 4xx from the actions product fails the publish with `routine_invalid` instead. For a listener trigger that names a listener, at `/triggers/<i>/listener`: `listener_not_found` when the listener was deleted or no longer feeds the trigger, and `listener_not_active` when it has ended or its owner paused it. The trigger starts no runs meanwhile; publish a version that names another listener, or resume it.
6119
8055
  */
6120
8056
  warnings?: Diagnostic[];
6121
8057
  }
@@ -6234,9 +8170,13 @@ export interface HookSecret {
6234
8170
 
6235
8171
  /** How the run started (the `trigger` context of its expressions). */
6236
8172
  export interface RunTrigger {
6237
- type: "api" | "cron" | "interval" | "webhook" | "action" | "routine" | "replay";
6238
- /** The trigger ID (cron, interval, webhook, action). */
8173
+ type: "api" | "cron" | "interval" | "webhook" | "action" | "listener" | "routine" | "replay";
8174
+ /**
8175
+ * The trigger ID (cron, interval, webhook, action, and listener triggers), or the listener (`lsn_`) of a listener whose sink names the routine.
8176
+ */
6239
8177
  id?: string;
8178
+ /** The listener that delivered the event (listener triggers). */
8179
+ listener_id?: string;
6240
8180
  /** Cron and interval occurrence, used to deduplicate fires. */
6241
8181
  occurrence_id?: string;
6242
8182
  scheduled_at?: string;
@@ -6244,8 +8184,12 @@ export interface RunTrigger {
6244
8184
  delivery_id?: string;
6245
8185
  /** The trigger subscription that delivered the event (action triggers). */
6246
8186
  subscription_id?: string;
6247
- /** The pack trigger event's ID (action triggers). */
8187
+ /** The pack trigger event's ID (action triggers), or the listener event's (`evt_`, listeners). */
6248
8188
  event_id?: string;
8189
+ /**
8190
+ * Listener runs. The run's trace (`GET /v1/traces/{trace_id}`), derived from the listener and the event, so a redelivery of the event lands in the same trace.
8191
+ */
8192
+ trace_id?: string;
6249
8193
  /** For sub-routine runs, the calling run; for replays, the source run. */
6250
8194
  parent_run_id?: string;
6251
8195
  parent_step_id?: string;
@@ -6684,8 +8628,8 @@ export interface RoutineSink {
6684
8628
  routine: string;
6685
8629
  /**
6686
8630
  * `run` starts a run of the routine's active version per event, with `trigger = {type: listener, id,
6687
- * event_id, seq, dedupe_key, received_at, payload}`; a redelivery of the same `dedupe_key` starts no
6688
- * second run. `event` sends the event to the routine's runs waiting with `wait: {event: <event>}`
8631
+ * event_id, seq, dedupe_key, received_at, payload, trace_id}`; a redelivery of the same `dedupe_key`
8632
+ * starts no second run. `event` sends the event to the routine's runs waiting with `wait: {event: <event>}`
6689
8633
  * (`routinesSendEvent`), with `data` = the payload.
6690
8634
  * @default "run"
6691
8635
  */
@@ -6703,6 +8647,25 @@ export interface RoutineSink {
6703
8647
  */
6704
8648
  retry_for_s?: number;
6705
8649
  batch?: ListenerBatch;
8650
+ /**
8651
+ * Set by routines on the listener of a routine's `type: listener` trigger: that trigger's ID. Routines
8652
+ * creates the listener when it publishes the version, as the publishing key, and removes it when a version
8653
+ * without the trigger is published or the routine is deleted. Each event starts a run with the trigger's
8654
+ * `if` and `with`, and `trigger = {type: listener, id: <trigger id>, listener_id, ...}`. Such a listener is
8655
+ * read-only here: PATCH and DELETE answer `409 listener_managed`. A request cannot set it. With `bound`,
8656
+ * the trigger names this listener instead (preview, `routines.named_listeners`): the listener is yours, and
8657
+ * only its sink is held.
8658
+ */
8659
+ trigger?: string;
8660
+ /**
8661
+ * True while a routine's `type: listener` trigger names this listener (by id or name) and its active
8662
+ * version is published: routines set `routine` and `trigger` when it bound the listener, keeping
8663
+ * `concurrency`, `retry_for_s` and `batch`. Every field but `sink` can still change; a PATCH of `sink`
8664
+ * answers `409 listener_bound`. A version without the trigger, or deleting the routine, clears it and
8665
+ * pauses the listener (`status_reason: routine_unbound`). While the routine is paused, deliveries are
8666
+ * retried until `retry_for_s`, then fail `routine_paused`. A request cannot set it.
8667
+ */
8668
+ bound?: boolean;
6706
8669
  }
6707
8670
 
6708
8671
  export interface WebhookSink {
@@ -6792,6 +8755,7 @@ export interface Listener {
6792
8755
  | "source_errors"
6793
8756
  | "owner_revoked"
6794
8757
  | "sandbox_ended"
8758
+ | "routine_unbound"
6795
8759
  | null;
6796
8760
  /** Why the source last failed, or why the listener ended `failed`. */
6797
8761
  error: {
@@ -6836,6 +8800,10 @@ export interface Listener {
6836
8800
  failed: number;
6837
8801
  skipped: number;
6838
8802
  reconnects: number;
8803
+ /**
8804
+ * Delivery attempts the sink answered with a retryable refusal (5xx, 429, a paused routine) and that were tried again. An event still refused at `retry_for_s` is counted in `failed`, with the refusal's code in its `delivery.last_error`.
8805
+ */
8806
+ retries?: number;
6839
8807
  last_event_at: string | null;
6840
8808
  };
6841
8809
  created_at: string;
@@ -6970,6 +8938,217 @@ export interface ListenerTestResult {
6970
8938
  event: ListenerEvent | null;
6971
8939
  }
6972
8940
 
8941
+ /**
8942
+ * One path rule. `path` is gitignore-style (`*` within a name, `**` across directories) and may use `{human}`,
8943
+ * `{initiator}` and `{agent}`, which bind to that principal's ID. `read` and `write` list selectors:
8944
+ * `agent:<id or name>`, `user:usr_…`, `role:owner|admin|member`, `subject:<id>`, `key:key_…`, `routine:rtn_…`,
8945
+ * `listener:lsn_…`, the bare roles `agent`, `human` and `initiator`, and `project`. A null list leaves that side
8946
+ * to the rules before it.
8947
+ */
8948
+ export interface WorkspaceRule {
8949
+ path: string;
8950
+ read?: string[] | null;
8951
+ write?: string[] | null;
8952
+ /**
8953
+ * A commit may only add bytes at the end of a matching file.
8954
+ * @default false
8955
+ */
8956
+ append_only?: boolean;
8957
+ }
8958
+
8959
+ export interface WorkspaceCreateRequest {
8960
+ /** Unique in the project. */
8961
+ name: string;
8962
+ rules?: WorkspaceRule[];
8963
+ metadata?: Metadata;
8964
+ }
8965
+
8966
+ export interface WorkspaceRulesRequest {
8967
+ rules: WorkspaceRule[];
8968
+ }
8969
+
8970
+ export interface Workspace {
8971
+ id: string;
8972
+ object: "workspace";
8973
+ name: string;
8974
+ status: "active" | "deleted";
8975
+ default_branch: string;
8976
+ /** The head commit of the default branch; null before the first commit. */
8977
+ head: string | null;
8978
+ rules: WorkspaceRule[];
8979
+ usage: {
8980
+ /** Unique content bytes stored, the unit of `workspaces.storage_gib_h`. */
8981
+ bytes: number;
8982
+ /** Files at the head of the default branch. */
8983
+ files: number;
8984
+ commits: number;
8985
+ open_branches: number;
8986
+ };
8987
+ created_at: string;
8988
+ updated_at: string;
8989
+ metadata: Metadata;
8990
+ }
8991
+
8992
+ export type WorkspaceList = Omit<ListEnvelope, "data"> & {
8993
+ data: Workspace[];
8994
+ };
8995
+
8996
+ export type BranchStatus = "open" | "merged" | "closed" | "expired";
8997
+
8998
+ export interface BranchCreateRequest {
8999
+ /**
9000
+ * A branch name or ID, or a commit ID, to start from.
9001
+ * @default "main"
9002
+ */
9003
+ from?: string;
9004
+ /** Unique among the workspace's open branches. Without one the branch is ephemeral. */
9005
+ name?: string;
9006
+ /** An ephemeral branch's lifetime; 604,800 (7 days) by default. */
9007
+ ttl_s?: number;
9008
+ metadata?: Metadata;
9009
+ }
9010
+
9011
+ export type PrincipalRef = {
9012
+ kind: "agent" | "routine" | "key" | "user" | "subject" | "sandbox" | "instance" | "routine_run" | "listener";
9013
+ id: string;
9014
+ } | null;
9015
+
9016
+ export interface Branch {
9017
+ id: string;
9018
+ object: "branch";
9019
+ workspace: string;
9020
+ name: string;
9021
+ kind: "named" | "ephemeral";
9022
+ /** Merging into it needs `workspaces:write` (`main` is protected). */
9023
+ protected: boolean;
9024
+ status: BranchStatus;
9025
+ /** The commit the branch started from; null for a branch of an empty workspace. */
9026
+ base: string | null;
9027
+ head: string | null;
9028
+ holder: PrincipalRef;
9029
+ expires_at: string | null;
9030
+ created_at: string;
9031
+ metadata: Metadata;
9032
+ }
9033
+
9034
+ export type BranchList = Omit<ListEnvelope, "data"> & {
9035
+ data: Branch[];
9036
+ };
9037
+
9038
+ /** One file to write (`content` as UTF-8 text or `content_base64` as bytes) or to delete. */
9039
+ export interface CommitFile {
9040
+ /** Absolute in the workspace (`/notes/today.md`); no `..`, no empty segment. */
9041
+ path: string;
9042
+ content?: string;
9043
+ content_base64?: string;
9044
+ /**
9045
+ * A regular file, an executable, or a symlink whose content is its target.
9046
+ * @default "100644"
9047
+ */
9048
+ mode?: "100644" | "100755" | "120000";
9049
+ delete?: boolean;
9050
+ }
9051
+
9052
+ export interface CommitRequest {
9053
+ message: string;
9054
+ /**
9055
+ * The files to write or delete. Required, except from inside the sandbox that holds the branch (its
9056
+ * `workspaces` member on create): there, without `files`, the commit is what the sandbox changed under the
9057
+ * branch's path.
9058
+ */
9059
+ files?: CommitFile[];
9060
+ /**
9061
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
9062
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
9063
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
9064
+ */
9065
+ subject?: string;
9066
+ if_head?: string;
9067
+ }
9068
+
9069
+ export interface Commit {
9070
+ id: string;
9071
+ object: "commit";
9072
+ workspace: string;
9073
+ /** The branch it was made on. */
9074
+ branch: string;
9075
+ parents: string[];
9076
+ /** The git tree ID of its content. */
9077
+ tree: string;
9078
+ /** Its git commit ID, the same after a push to a git remote. */
9079
+ git_sha: string;
9080
+ message: string;
9081
+ principals: {
9082
+ agent: PrincipalRef;
9083
+ human: PrincipalRef;
9084
+ initiator: PrincipalRef;
9085
+ };
9086
+ stats: {
9087
+ files_changed: number;
9088
+ /** New content bytes the commit stored. */
9089
+ bytes: number;
9090
+ };
9091
+ created_at: string;
9092
+ }
9093
+
9094
+ export type CommitList = Omit<ListEnvelope, "data"> & {
9095
+ data: Commit[];
9096
+ };
9097
+
9098
+ export interface MergeRequest {
9099
+ /**
9100
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
9101
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
9102
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
9103
+ */
9104
+ subject?: string;
9105
+ /**
9106
+ * The target branch, by name or ID.
9107
+ * @default "main"
9108
+ */
9109
+ into?: string;
9110
+ /** @default "three_way" */
9111
+ mode?: "three_way" | "paths";
9112
+ /** Merge only while the target's head is this commit. */
9113
+ if_head?: string;
9114
+ message?: string;
9115
+ }
9116
+
9117
+ export interface MergeResult {
9118
+ object: "workspace_merge";
9119
+ into: string;
9120
+ /** The target had not moved since the branch's base, so its head became the branch's head. */
9121
+ fast_forward: boolean;
9122
+ commit: Commit;
9123
+ }
9124
+
9125
+ export interface WorkspaceDiff {
9126
+ object: "workspace_diff";
9127
+ base: string;
9128
+ head: string;
9129
+ changes: {
9130
+ path: string;
9131
+ kind: "added" | "modified" | "deleted" | "type_changed";
9132
+ old_size: number | null;
9133
+ new_size: number | null;
9134
+ }[];
9135
+ /** More than 10,000 changes; narrow it with `path`. */
9136
+ truncated: boolean;
9137
+ }
9138
+
9139
+ export interface WorkspaceEntry {
9140
+ path: string;
9141
+ type: "file" | "dir" | "symlink";
9142
+ size: number | null;
9143
+ mode: string;
9144
+ /** The git blob ID; null for a directory. */
9145
+ blob: string | null;
9146
+ }
9147
+
9148
+ export type WorkspaceEntryList = Omit<ListEnvelope, "data"> & {
9149
+ data: WorkspaceEntry[];
9150
+ };
9151
+
6973
9152
  /**
6974
9153
  * One JSON-RPC 2.0 message of the Model Context Protocol (https://modelcontextprotocol.io): a request
6975
9154
  * (`method` and `id`), a notification (`method`, no `id`) or a response (`result` or `error`). Methods served:
@@ -9367,8 +11546,10 @@ export type ToolBlockList = Omit<ListEnvelope, "data"> & {
9367
11546
  data: ToolBlock[];
9368
11547
  };
9369
11548
 
9370
- /** An option's value; for an enum option, one of its values (`x-b3os-options`). */
9371
- export type SettingValue = string | number | boolean;
11549
+ /**
11550
+ * An option's value: for an enum option, one of its values; for an object option, an object of the members its catalog row names in `fields` (`x-b3os-options`), such as `platform.export_otlp`'s `{url, connection, header, content}`. An unset object option resolves to null.
11551
+ */
11552
+ export type SettingValue = string | number | boolean | Record<string, unknown> | null;
9372
11553
 
9373
11554
  export interface SettingRequest {
9374
11555
  value: SettingValue;
@@ -9503,6 +11684,14 @@ export interface RequestRecord {
9503
11684
  phases: RequestPhase[];
9504
11685
  /** The W3C trace ID from `traceparent`, when sent. */
9505
11686
  trace_id: string | null;
11687
+ /**
11688
+ * The span id the node gave this request (with `traceparent` sent): the parent id in the `traceparent` its
11689
+ * handler passes on, so a request it made (an MCP product tool's) names it in `parent_span_id`. Absent from
11690
+ * records written before node release 1127 and from requests the edge answered itself.
11691
+ */
11692
+ span_id?: string | null;
11693
+ /** The span id in the `traceparent` the request arrived with (its caller's span), when sent. */
11694
+ parent_span_id?: string | null;
9506
11695
  user_agent: string | null;
9507
11696
  source: RequestSource;
9508
11697
  action?: RequestAction;
@@ -9855,6 +12044,17 @@ export interface VisionListCrawlPagesParams {
9855
12044
  status?: "succeeded" | "failed";
9856
12045
  }
9857
12046
 
12047
+ /** Parameters of `listIdentities`. */
12048
+ export interface VisionListIdentitiesParams {
12049
+ /**
12050
+ * Page size, from 1 to 100.
12051
+ * @default 20
12052
+ */
12053
+ limit?: number;
12054
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12055
+ cursor?: string;
12056
+ }
12057
+
9858
12058
  /** Parameters of `listProfiles`. */
9859
12059
  export interface VisionListProfilesParams {
9860
12060
  /**
@@ -10026,6 +12226,19 @@ export interface SandboxesListSandboxesParams {
10026
12226
  metadata?: Record<string, string>;
10027
12227
  }
10028
12228
 
12229
+ /** Parameters of `getCapacity`. */
12230
+ export interface SandboxesGetCapacityParams {
12231
+ /**
12232
+ * Template name or `tpl_` ID.
12233
+ * @default "desktop"
12234
+ */
12235
+ template?: string;
12236
+ /** vCPUs of each sandbox; the template's default when left out. */
12237
+ vcpu?: number;
12238
+ /** Memory of each sandbox, MiB; the template's default when left out. */
12239
+ memory_mib?: number;
12240
+ }
12241
+
10029
12242
  /** Parameters of `listSnapshots`. */
10030
12243
  export interface SandboxesListSnapshotsParams {
10031
12244
  /**
@@ -10089,6 +12302,17 @@ export interface SandboxesListVolumesParams {
10089
12302
  status?: "available" | "attached" | "deleted";
10090
12303
  }
10091
12304
 
12305
+ /** Parameters of `computerScreenshot`. */
12306
+ export interface SandboxesComputerScreenshotParams {
12307
+ /** `png` or `jpeg`. Without it: the image type `Accept` names, else `jpeg`. */
12308
+ format?: "png" | "jpeg";
12309
+ /**
12310
+ * JPEG quality, 1 to 100.
12311
+ * @default 80
12312
+ */
12313
+ quality?: number;
12314
+ }
12315
+
10092
12316
  /** Parameters of `deleteFile`. */
10093
12317
  export interface SandboxesDeleteFileParams {
10094
12318
  /** Absolute path inside the sandbox. */
@@ -10191,6 +12415,20 @@ export interface ImagesGetImageParams {
10191
12415
  wait?: number;
10192
12416
  }
10193
12417
 
12418
+ /** Parameters of `getImageLogs`. */
12419
+ export interface ImagesGetImageLogsParams {
12420
+ /**
12421
+ * The first line to answer (0 is the first).
12422
+ * @default 0
12423
+ */
12424
+ offset?: number;
12425
+ /**
12426
+ * Hold the answer up to this many seconds until there are lines past `offset` or the image settles.
12427
+ * @default 0
12428
+ */
12429
+ wait?: number;
12430
+ }
12431
+
10194
12432
  /** Parameters of `listAgents`. */
10195
12433
  export interface AgentsListAgentsParams {
10196
12434
  /**
@@ -10226,6 +12464,53 @@ export interface AgentsListInstanceEventsParams {
10226
12464
  cursor?: string;
10227
12465
  }
10228
12466
 
12467
+ /** Parameters of `listGrants`. */
12468
+ export interface AgentsListGrantsParams {
12469
+ /**
12470
+ * Page size, from 1 to 100.
12471
+ * @default 20
12472
+ */
12473
+ limit?: number;
12474
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12475
+ cursor?: string;
12476
+ }
12477
+
12478
+ /** Parameters of `openTerminal`. */
12479
+ export interface AgentsOpenTerminalParams {
12480
+ /**
12481
+ * `view` (the default) or `control`, which also needs `agents:run`.
12482
+ * @default "view"
12483
+ */
12484
+ role?: "view" | "control";
12485
+ /** The byte offset to resume from, with `session`. Without it the socket starts at the current screen. */
12486
+ cursor?: number;
12487
+ /** The terminal (`pts_…`) the `cursor` belongs to, from the session frame of the socket you resume. */
12488
+ session?: string;
12489
+ /** Which harness session's terminal, when the instance has more than one. Default `default`. */
12490
+ conversation?: string;
12491
+ /**
12492
+ * `main` (the default): the harness's terminal. `signin:<profile>` and `signout:<profile>`: the sign-in
12493
+ * and sign-out windows for one of the definition's `signin` profiles, for a personal agent's owner only.
12494
+ * @default "main"
12495
+ */
12496
+ window?: string;
12497
+ /** The controller's width; ignored for a viewer. */
12498
+ cols?: number;
12499
+ /** The controller's height; ignored for a viewer. */
12500
+ rows?: number;
12501
+ }
12502
+
12503
+ /** Parameters of `listRecordings`. */
12504
+ export interface AgentsListRecordingsParams {
12505
+ /**
12506
+ * Page size, from 1 to 100.
12507
+ * @default 20
12508
+ */
12509
+ limit?: number;
12510
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12511
+ cursor?: string;
12512
+ }
12513
+
10229
12514
  /** Parameters of `listSessions`. */
10230
12515
  export interface AgentsListSessionsParams {
10231
12516
  /**
@@ -10332,6 +12617,89 @@ export interface ListenersListEventsParams {
10332
12617
  status?: ListenerEventStatus;
10333
12618
  }
10334
12619
 
12620
+ /** Parameters of `listWorkspaces`. */
12621
+ export interface WorkspacesListWorkspacesParams {
12622
+ /**
12623
+ * Page size, from 1 to 100.
12624
+ * @default 20
12625
+ */
12626
+ limit?: number;
12627
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12628
+ cursor?: string;
12629
+ }
12630
+
12631
+ /** Parameters of `listBranches`. */
12632
+ export interface WorkspacesListBranchesParams {
12633
+ /**
12634
+ * Page size, from 1 to 100.
12635
+ * @default 20
12636
+ */
12637
+ limit?: number;
12638
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12639
+ cursor?: string;
12640
+ /** Only the branch with this name. */
12641
+ name?: string;
12642
+ /** Only branches in this status. */
12643
+ status?: BranchStatus;
12644
+ }
12645
+
12646
+ /** Parameters of `listCommits`. */
12647
+ export interface WorkspacesListCommitsParams {
12648
+ /**
12649
+ * Page size, from 1 to 100.
12650
+ * @default 20
12651
+ */
12652
+ limit?: number;
12653
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
12654
+ cursor?: string;
12655
+ /** The branch whose history to list (`br_…`); `main` when absent. */
12656
+ branch_id?: string;
12657
+ }
12658
+
12659
+ /** Parameters of `diff`. */
12660
+ export interface WorkspacesDiffParams {
12661
+ /**
12662
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
12663
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
12664
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
12665
+ */
12666
+ subject?: string;
12667
+ /** A commit ID (`cmt_…`) or a branch name. */
12668
+ base: string;
12669
+ /** A commit ID (`cmt_…`) or a branch name. */
12670
+ head: string;
12671
+ /** Only paths under this directory. */
12672
+ path?: string;
12673
+ }
12674
+
12675
+ /** Parameters of `listFiles`. */
12676
+ export interface WorkspacesListFilesParams {
12677
+ /**
12678
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
12679
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
12680
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
12681
+ */
12682
+ subject?: string;
12683
+ /** A commit ID (`cmt_…`) or a branch name; `main` when absent. */
12684
+ ref?: string;
12685
+ /** The directory or file, absolute in the workspace; `/` when absent. */
12686
+ path?: string;
12687
+ }
12688
+
12689
+ /** Parameters of `readFile`. */
12690
+ export interface WorkspacesReadFileParams {
12691
+ /**
12692
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
12693
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
12694
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
12695
+ */
12696
+ subject?: string;
12697
+ /** A commit ID (`cmt_…`) or a branch name; `main` when absent. */
12698
+ ref?: string;
12699
+ /** The file, absolute in the workspace. */
12700
+ path: string;
12701
+ }
12702
+
10335
12703
  /** Parameters of `describe`. */
10336
12704
  export interface ActionsDescribeParams {
10337
12705
  /** `<namespace>/<name>/<action>@<version>`; the version may be exact (`1.0.0`) or a major (`1`). */