@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
@@ -8,7 +8,7 @@ export type Metadata = Record<string, string>;
8
8
  * for every scope. The build generates `enum` from the catalog, the same list as `dist/scopes.json` plus
9
9
  * `<product>:*` and `*`.
10
10
  */
11
- export type Scope = "vision:read" | "vision:write" | "vision:run" | "vision:profiles:use" | "vision:profiles:export" | "render:read" | "render:write" | "render:run" | "sandboxes:read" | "sandboxes:write" | "sandboxes:run" | "agents:read" | "agents:write" | "agents:run" | "routines:read" | "routines:write" | "routines:run" | "listeners:read" | "listeners:write" | "actions:read" | "actions:write" | "actions:run" | "actions:tools:publish" | "infer:read" | "infer:write" | "infer:run" | "vault:read" | "vault:write" | "vault:run" | "vault:connections:reveal" | "platform:read" | "platform:write" | "platform:content:read" | "settings:write" | "vision:*" | "render:*" | "sandboxes:*" | "agents:*" | "routines:*" | "listeners:*" | "actions:*" | "infer:*" | "vault:*" | "platform:*" | "settings:*" | "*";
11
+ export type Scope = "vision:read" | "vision:write" | "vision:run" | "vision:profiles:use" | "vision:profiles:export" | "render:read" | "render:write" | "render:run" | "sandboxes:read" | "sandboxes:write" | "sandboxes:run" | "agents:read" | "agents:write" | "agents:run" | "routines:read" | "routines:write" | "routines:run" | "listeners:read" | "listeners:write" | "workspaces:read" | "workspaces:write" | "workspaces:run" | "workspaces:rules:write" | "workspaces:subjects:assert" | "actions:read" | "actions:write" | "actions:run" | "actions:tools:publish" | "infer:read" | "infer:write" | "infer:run" | "vault:read" | "vault:write" | "vault:run" | "vault:connections:reveal" | "platform:read" | "platform:write" | "platform:content:read" | "settings:write" | "vision:*" | "render:*" | "sandboxes:*" | "agents:*" | "routines:*" | "listeners:*" | "workspaces:*" | "actions:*" | "infer:*" | "vault:*" | "platform:*" | "settings:*" | "*";
12
12
  /**
13
13
  * Server-side phase durations in milliseconds with microsecond resolution: the same phases as the
14
14
  * `Server-Timing` header, keyed `<phase>_ms`. `total_ms` is always present. Phase names are product-specific
@@ -82,6 +82,18 @@ export interface Problem {
82
82
  limit?: LimitRef;
83
83
  /** The object's current status, for state conflicts such as `sandbox_not_running`. */
84
84
  current_status?: string;
85
+ /** The branch's head now (`head_moved`). */
86
+ current_head?: string;
87
+ /** The workspace paths the code is about (`path_not_writable`, `append_only_violation`), at most 100. */
88
+ paths?: string[];
89
+ /** Every path a merge could not combine (`merge_conflict`), with the blob IDs of the three sides. */
90
+ conflicts?: {
91
+ path: string;
92
+ kind: "content" | "binary" | "delete_modify" | "add_add" | "type";
93
+ base: string | null;
94
+ ours: string | null;
95
+ theirs: string | null;
96
+ }[];
85
97
  /** The sandbox that holds a lease's key now, or null when none does (`lease_holder_changed`). */
86
98
  holder?: string | null;
87
99
  /** The head of the linked branch now (`manifest_changed`). */
@@ -548,7 +560,7 @@ export type ScrapeRequest = {
548
560
  * `hosts` list the proxy's host (needs `vault:run`).
549
561
  * A URL with a username or password is refused (`400 invalid_request`): put them in a connection. This node
550
562
  * takes `http://` proxies only; plain HTTP means the username and password cross the network to your proxy
551
- * unencrypted. Batches, crawls, sessions and the Firecrawl surface do not take `proxy` yet.
563
+ * unencrypted. Batches, crawls and the Firecrawl surface do not take `proxy` yet; sessions take it with `stealth` only.
552
564
  */
553
565
  export type ProxyOption = "none" | "auto" | "residential" | string | {
554
566
  /** Your proxy's URL, `http://host:port`. */
@@ -1015,7 +1027,121 @@ export interface SessionCreateRequest {
1015
1027
  * @default false
1016
1028
  */
1017
1029
  thumbnails?: boolean;
1030
+ /**
1031
+ * `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).
1032
+ */
1033
+ isolation?: SessionIsolation;
1034
+ stealth?: StealthOption;
1035
+ /**
1036
+ * Where a stealth session leaves from (`vision.proxy`); only with `stealth`, else `400 invalid_request`.
1037
+ * `none` (the default): the node's own address, and the session carries the `exit_direct` warning. A
1038
+ * proxy URL or `{url, connection}`: your own proxy, as on a scrape, kept for the whole session (one exit,
1039
+ * never rotated). `auto` and `residential` answer `422 option_not_allowed` with `bound_by: catalog`: stealth
1040
+ * sessions never use the residential network.
1041
+ */
1042
+ proxy?: ProxyOption;
1043
+ }
1044
+ /**
1045
+ * A stealth session (`vision.stealth`, needs the flag for your organization and the stealth terms accepted by
1046
+ * an owner; else `422 option_not_allowed` with `bound_by: org`). The browser runs headful in a microVM of its
1047
+ * own, keeps one consistent identity (screen, window, fonts, input style), and takes its time zone and locale
1048
+ * from where its exit is. `true` is `{}`; `false` or no member is an ordinary session. It implies `isolation:
1049
+ * microvm` (`process` is `400`), runs engine `chrome` (`headless-shell` is `400`), and sets the window, locale
1050
+ * and time zone itself (`viewport`, `locale`, `timezone`, `user_agent` and `block_resources` are `400`).
1051
+ */
1052
+ export type StealthOption = boolean | {
1053
+ /**
1054
+ * An identity to reuse. Omitted: the profile's identity when `profile` names one that has one, else a new identity.
1055
+ */
1056
+ identity?: string;
1057
+ /**
1058
+ * 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.
1059
+ */
1060
+ region?: string;
1061
+ /**
1062
+ * 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.
1063
+ * @default true
1064
+ */
1065
+ humanize?: boolean;
1066
+ };
1067
+ /** What a stealth session's browser presents and where it leaves from. */
1068
+ export interface SessionStealth {
1069
+ identity: string;
1070
+ persona: {
1071
+ os: "linux";
1072
+ browser: "chrome";
1073
+ /** The running browser's major version. */
1074
+ major: number;
1075
+ screen: string;
1076
+ locale: string;
1077
+ timezone: string;
1078
+ };
1079
+ exit: {
1080
+ /** `byo`: your proxy. `direct`: the node's address. */
1081
+ class: "byo" | "direct";
1082
+ /** Where the exit is (ISO 3166-1 alpha-2), as measured when the session started. */
1083
+ country?: string;
1084
+ region?: string;
1085
+ };
1086
+ /** The stealth engine's stage (1 today). */
1087
+ stage: number;
1088
+ /**
1089
+ * 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).
1090
+ */
1091
+ warnings: string[];
1092
+ }
1093
+ export interface StealthAudit {
1094
+ object: "stealth_audit";
1095
+ session_id: string;
1096
+ /**
1097
+ * 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.
1098
+ */
1099
+ lines: {
1100
+ t: string;
1101
+ kind: string;
1102
+ [key: string]: unknown;
1103
+ }[];
1104
+ }
1105
+ /**
1106
+ * 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.
1107
+ */
1108
+ export interface StealthIdentity {
1109
+ id: string;
1110
+ object: "stealth_identity";
1111
+ state: "active" | "retired";
1112
+ persona: {
1113
+ /** The persona catalog's version it was drawn from. */
1114
+ catalog: number;
1115
+ os: "linux";
1116
+ browser: "chrome";
1117
+ /** The screen in CSS pixels. */
1118
+ screen: string;
1119
+ device_scale_factor: number;
1120
+ window: {
1121
+ x: number;
1122
+ y: number;
1123
+ width: number;
1124
+ height: number;
1125
+ maximized: boolean;
1126
+ };
1127
+ /** The font families its browser sees. */
1128
+ fonts: string[];
1129
+ };
1130
+ /** `us` or `us-ny`; `null` until a session names one or its first exit sets it. */
1131
+ home_region: string | null;
1132
+ /** Stealth sessions that used it. */
1133
+ sessions: number;
1134
+ created_at: string;
1135
+ last_used_at: string | null;
1136
+ retired_at: string | null;
1018
1137
  }
1138
+ export type StealthIdentityList = Omit<ListEnvelope, "data"> & {
1139
+ data: StealthIdentity[];
1140
+ };
1141
+ /**
1142
+ * 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.
1143
+ */
1144
+ export type SessionIsolation = "process" | "microvm";
1019
1145
  export interface SessionTimeline {
1020
1146
  object: "session_timeline";
1021
1147
  session_id: string;
@@ -1103,12 +1229,17 @@ export interface BrowserSession {
1103
1229
  * Why the session closed; `null` while it is active. `deleted`: `DELETE`. `expired`: its timeout.
1104
1230
  * `browser_exited`: its browser stopped under it. `node_restart`: the node stopped or restarted while the
1105
1231
  * session was open; browser time is billed up to the stop and not after it (nothing when the node did not
1106
- * stop cleanly, since it cannot tell when the browser stopped). Closed sessions stay readable for 7 days.
1232
+ * stop cleanly, since it cannot tell when the browser stopped). `stealth_revoked`: a stealth session whose
1233
+ * organization lost the `vision.stealth` flag or its acceptance of the stealth terms. Closed sessions stay
1234
+ * readable for 7 days.
1107
1235
  */
1108
- closed_reason?: "deleted" | "expired" | "browser_exited" | "node_restart" | null;
1236
+ closed_reason?: "deleted" | "expired" | "browser_exited" | "node_restart" | "stealth_revoked" | null;
1109
1237
  timeout_s: number;
1110
1238
  viewport: Viewport;
1111
1239
  browser: BrowserEngine;
1240
+ isolation: SessionIsolation;
1241
+ /** Present on stealth sessions only. */
1242
+ stealth?: SessionStealth;
1112
1243
  /** The loaded profile, or `null`. */
1113
1244
  profile: null | SessionProfileRef;
1114
1245
  /** WebSocket URL of the session's CDP endpoint. */
@@ -1399,6 +1530,10 @@ export interface Profile {
1399
1530
  * 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.
1400
1531
  */
1401
1532
  exportable: boolean;
1533
+ /**
1534
+ * 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.
1535
+ */
1536
+ identity?: string;
1402
1537
  /** Owning org. Returned to the owner only; tenancy is checked on every access. */
1403
1538
  org?: string;
1404
1539
  project?: string;
@@ -3851,7 +3986,7 @@ export type RenderBackgroundPackList = Omit<ListEnvelope, "data"> & {
3851
3986
  data: RenderBackgroundPack[];
3852
3987
  };
3853
3988
  /**
3854
- * `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.
3989
+ * `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.
3855
3990
  */
3856
3991
  export type SandboxStatus = "running" | "paused" | "stopped" | "failed" | "hibernated";
3857
3992
  /**
@@ -3954,7 +4089,8 @@ export interface EgressPolicy {
3954
4089
  export interface SandboxCreateRequest {
3955
4090
  /**
3956
4091
  * Template name or `tpl_` ID: a node template (`GET /v1/sandboxes/templates`) or one of your project's
3957
- * image templates (an image's `template`). Ignored when `snapshot` is set.
4092
+ * image templates (an image's `template`, or its `name`; a name of an image that is not `ready` answers
4093
+ * `409 image_not_ready`). Node templates are looked up first. Ignored when `snapshot` is set.
3958
4094
  * @default "base"
3959
4095
  */
3960
4096
  template?: string;
@@ -4047,6 +4183,17 @@ export interface SandboxCreateRequest {
4047
4183
  * volume is free for the next sandbox once the microVM has exited.
4048
4184
  */
4049
4185
  volumes?: VolumeAttach[];
4186
+ /**
4187
+ * A workspace branch to mount (`POST /v1/workspaces`), at most one in this beta. Behind the `workspaces.api`
4188
+ * flag: `403 feature_not_enabled` while it is off for your organization. The branch's head is mounted at
4189
+ * `path` as a copy-on-write folder: the base files are shared and read-only underneath, and what the sandbox
4190
+ * writes there is the branch's change set, kept on the sandbox's disk until it is committed. Commands see
4191
+ * `B3OS_WORKSPACE_ID`, `B3OS_BRANCH_ID` and `B3OS_WORKSPACE_PATH`. Holding a protected branch (`main`) needs
4192
+ * `workspaces:write`, any other branch `workspaces:run`. A branch with no commit yet is `422
4193
+ * workspace_invalid` (reason `empty`). In this beta a sandbox with a workspace cannot be snapshotted (`409
4194
+ * conflict`), and `snapshot` and `forkable: true` are refused with it (`400 invalid_request`).
4195
+ */
4196
+ workspaces?: SandboxWorkspaceAttach[];
4050
4197
  owner?: SandboxOwner;
4051
4198
  metadata?: Metadata;
4052
4199
  }
@@ -4060,6 +4207,35 @@ export interface VolumeAttach {
4060
4207
  */
4061
4208
  owner?: string;
4062
4209
  }
4210
+ export interface SandboxWorkspaceAttach {
4211
+ /** The workspace's `ws_` ID. */
4212
+ workspace: string;
4213
+ /**
4214
+ * An open branch's `br_` ID or name, or `new` (a new ephemeral branch from `from`).
4215
+ * @default "new"
4216
+ */
4217
+ branch?: string;
4218
+ /**
4219
+ * Where a new branch starts: a branch name or ID, or a `cmt_` commit ID; `main` when unset. Only with a new
4220
+ * branch (`400 invalid_request` otherwise).
4221
+ */
4222
+ from?: string;
4223
+ /**
4224
+ * Where the branch appears in the sandbox: absolute, and not a system folder or under one (the rules of a
4225
+ * volume mount's `path`); never overlapping a volume mount.
4226
+ * @default "/workspace"
4227
+ */
4228
+ path?: string;
4229
+ }
4230
+ export interface SandboxWorkspace {
4231
+ workspace_id: string;
4232
+ branch_id: string;
4233
+ /** `ephemeral/<branch_id>` for a branch the create made. */
4234
+ branch_name: string;
4235
+ /** The commit the sandbox's base files are (the branch's head when the sandbox was created). */
4236
+ commit_id: string;
4237
+ path: string;
4238
+ }
4063
4239
  export interface VolumeMount {
4064
4240
  /**
4065
4241
  * Where the folder appears in the sandbox: absolute, not `/`, not a system folder or under one (`/proc`,
@@ -4279,6 +4455,7 @@ export interface Sandbox {
4279
4455
  * running and renews its `expires_at` itself. `null` when it never held one. Always sent by this node.
4280
4456
  */
4281
4457
  lease?: null | SandboxLease;
4458
+ restore?: SandboxRestore;
4282
4459
  /**
4283
4460
  * The processes the node supervises (an exec with `background: true` and `restart`), oldest first; empty
4284
4461
  * when there are none. Always sent by this node.
@@ -4286,6 +4463,8 @@ export interface Sandbox {
4286
4463
  supervised?: SupervisedProcess[];
4287
4464
  /** The volume the sandbox holds and where it is mounted; empty when none. Always sent by this node. */
4288
4465
  volumes?: SandboxVolume[];
4466
+ /** The workspace branch the sandbox holds and where it is mounted; present only when it holds one. */
4467
+ workspaces?: SandboxWorkspace[];
4289
4468
  options: SandboxOptions;
4290
4469
  owner?: SandboxOwner;
4291
4470
  /**
@@ -4331,6 +4510,13 @@ export interface LeaseRequest {
4331
4510
  * that already holds `key` answers 200 whatever this says.
4332
4511
  */
4333
4512
  expect_holder?: string | null;
4513
+ /**
4514
+ * The order the node boots the project's services again in place after it loses their microVMs (a node
4515
+ * restart or release): higher first, and a service waits up to 2 minutes while one of its project with a
4516
+ * higher priority is not running and ready yet, so a database comes back before the app that uses it.
4517
+ * Default 0. Sent again with the same `key`, it changes only the priority.
4518
+ */
4519
+ restore_priority?: number;
4334
4520
  }
4335
4521
  /** A sandbox's lease, held or ended. */
4336
4522
  export interface SandboxLease {
@@ -4346,6 +4532,48 @@ export interface SandboxLease {
4346
4532
  * one then stops within `sandboxes.lease_term`), or the sandbox's `stop_reason`.
4347
4533
  */
4348
4534
  end_reason: "released" | "replaced" | "deleted" | "timeout" | "failed" | "budget" | "revoked" | null;
4535
+ /** The lease's restore priority (`PUT …/lease`); 0 by default. */
4536
+ restore_priority?: number;
4537
+ }
4538
+ /**
4539
+ * Present only for a project's service the node kept through the loss of its microVM: one that holds a lease
4540
+ * (`PUT …/lease`; not an agent instance, not started by another sandbox, no workspace, and `secrets` only as
4541
+ * connection references, which its boot reveals again while the edge says their creator still may). When its
4542
+ * microVM ends without anyone asking (a node restart or release, a VM lost while the node runs, a VM gone when
4543
+ * the node starts), the node keeps its disk and boots it again in place: the same ID (so its addresses need no
4544
+ * switch), its disk, its volume, its lease and its supervised processes, which start again. Boots back off 0,
4545
+ * 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
4546
+ * node gives up and the sandbox ends `failed`. While it has no VM it bills no compute.
4547
+ */
4548
+ export interface SandboxRestore {
4549
+ /** Why its last microVM ended. */
4550
+ cause: "node_stop" | "vm_lost" | "vm_gone_at_start";
4551
+ /**
4552
+ * `clean`: the disk was copied after TERM to its supervised processes, its volume's release and a sync;
4553
+ * `crash`: copied while the guest ran or after its VM died, so writes the guest had not synced may be
4554
+ * missing (as after a power cut).
4555
+ */
4556
+ consistency: "clean" | "crash";
4557
+ state: "waiting" | "booting" | "booted" | "gave_up";
4558
+ /** When its last microVM ended. */
4559
+ since: string;
4560
+ /** Boots begun since its last run of 10 minutes. */
4561
+ attempts: number;
4562
+ /** When the next boot may begin; `null` while it boots, once booted, and once given up. */
4563
+ next_at: string | null;
4564
+ booted_at: string | null;
4565
+ /** When the node gave up booting it (the sandbox ended `failed`). */
4566
+ gave_up_at: string | null;
4567
+ /** Why the last boot failed, or why the node gave up. */
4568
+ last_error: string | null;
4569
+ /**
4570
+ * For a service with `secrets` (connection references), why the node did not reveal them again:
4571
+ * `restore_grant_revoked`, the edge said the principal that revealed them at its create no longer may (its
4572
+ * key revoked or expired, its user removed, its scopes cut, its application unlinked; the sandbox ends
4573
+ * `stopped`, `revoked`); `restore_grant_unknown`, the edge could not say, through every boot of the backoff
4574
+ * (it ends `failed`). The node never keeps a secret's value, only its reference.
4575
+ */
4576
+ reason?: "restore_grant_revoked" | "restore_grant_unknown" | null;
4349
4577
  }
4350
4578
  /** A background process the node starts again when it exits (an exec with `restart`). */
4351
4579
  export interface SupervisedProcess {
@@ -4666,6 +4894,203 @@ export interface Snapshot {
4666
4894
  export type SnapshotList = Omit<ListEnvelope, "data"> & {
4667
4895
  data: Snapshot[];
4668
4896
  };
4897
+ /** How many more sandboxes of one shape would be created now, and the limits behind the count. */
4898
+ export interface SandboxCapacity {
4899
+ object: "sandbox_capacity";
4900
+ /** The template's name. */
4901
+ template: string;
4902
+ vcpu: number;
4903
+ memory_mib: number;
4904
+ /**
4905
+ * Creates of this shape that would pass now; the least of `org`, `desktops` (desktop templates only) and `node.room`.
4906
+ */
4907
+ room: number;
4908
+ /** The limit that refuses the next create when `room` is 0; `null` while a create would pass. */
4909
+ binding: "org_concurrency" | "desktops" | "node" | null;
4910
+ org: CapacityCount;
4911
+ desktops: CapacityCount;
4912
+ node: {
4913
+ /** Sandboxes of this shape waiting warm in the node's pool. */
4914
+ parked: number;
4915
+ /**
4916
+ * 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.
4917
+ */
4918
+ room: number | null;
4919
+ };
4920
+ /** When `room` is 0, how long to wait before trying again. */
4921
+ retry_after_s?: number;
4922
+ }
4923
+ /**
4924
+ * Your organization's live sandboxes against one limit (`sandboxes.concurrent` or `sandboxes.desktops_concurrent`).
4925
+ */
4926
+ export interface CapacityCount {
4927
+ /** Running and paused sandboxes, and creates in flight. */
4928
+ running: number;
4929
+ limit: number;
4930
+ }
4931
+ export interface Computer {
4932
+ object: "computer";
4933
+ display: {
4934
+ width: number;
4935
+ height: number;
4936
+ };
4937
+ cursor: ComputerPoint;
4938
+ /**
4939
+ * 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.
4940
+ */
4941
+ controller: "agent" | "human";
4942
+ }
4943
+ /** A position on the screen, in pixels from the top left. */
4944
+ export interface ComputerPoint {
4945
+ x: number;
4946
+ y: number;
4947
+ }
4948
+ export interface ComputerScreenshotOptions {
4949
+ /** @default "jpeg" */
4950
+ format?: "png" | "jpeg";
4951
+ /**
4952
+ * JPEG quality.
4953
+ * @default 80
4954
+ */
4955
+ quality?: number;
4956
+ }
4957
+ /** Before the screenshot, wait until the screen has not changed for `quiet_ms`, at most `max_ms`. */
4958
+ export interface ComputerSettle {
4959
+ /** @default 80 */
4960
+ quiet_ms?: number;
4961
+ /** @default 1000 */
4962
+ max_ms?: number;
4963
+ }
4964
+ export interface ComputerActRequest {
4965
+ /** Run in order. Their `wait` actions add up to at most 30,000 ms. */
4966
+ actions: ComputerAction[];
4967
+ /** A screenshot after the actions; `null` or left out for none. */
4968
+ screenshot?: ComputerScreenshotOptions | null;
4969
+ /** Wait for the screen to settle before the screenshot; `null` or left out for no wait. */
4970
+ settle?: ComputerSettle | null;
4971
+ }
4972
+ /** One mouse or keyboard action; `action` selects it. */
4973
+ export type ComputerAction = ComputerClick | ComputerMove | ComputerMouseDown | ComputerMouseUp | ComputerDrag | ComputerScroll | ComputerType | ComputerKey | ComputerKeyDown | ComputerKeyUp | ComputerWait | ComputerCursorPosition;
4974
+ /** Pixels from the left (`x`) or the top (`y`); within the screen. */
4975
+ export type ComputerCoordinate = number;
4976
+ export type ComputerButton = "left" | "right" | "middle";
4977
+ /**
4978
+ * Click at `x`, `y` (both or neither; neither clicks at the pointer). `count` 2 is a double click, 3 a triple click.
4979
+ */
4980
+ export interface ComputerClick {
4981
+ action: "click";
4982
+ x?: ComputerCoordinate;
4983
+ y?: ComputerCoordinate;
4984
+ button?: ComputerButton;
4985
+ /** @default 1 */
4986
+ count?: number;
4987
+ }
4988
+ /** Move the pointer. */
4989
+ export interface ComputerMove {
4990
+ action: "move";
4991
+ x: ComputerCoordinate;
4992
+ y: ComputerCoordinate;
4993
+ }
4994
+ /** Press a button, at `x`, `y` or at the pointer, and hold it. */
4995
+ export interface ComputerMouseDown {
4996
+ action: "mouse_down";
4997
+ x?: ComputerCoordinate;
4998
+ y?: ComputerCoordinate;
4999
+ button?: ComputerButton;
5000
+ }
5001
+ /** Release a button, at `x`, `y` or at the pointer. */
5002
+ export interface ComputerMouseUp {
5003
+ action: "mouse_up";
5004
+ x?: ComputerCoordinate;
5005
+ y?: ComputerCoordinate;
5006
+ button?: ComputerButton;
5007
+ }
5008
+ /**
5009
+ * 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.
5010
+ */
5011
+ export interface ComputerDrag {
5012
+ action: "drag";
5013
+ /** `[[x, y], ...]`, 2 to 64 points. */
5014
+ path: ComputerCoordinate[][];
5015
+ button?: ComputerButton;
5016
+ }
5017
+ /** Turn the wheel `amount` clicks, at `x`, `y` or at the pointer. */
5018
+ export interface ComputerScroll {
5019
+ action: "scroll";
5020
+ x?: ComputerCoordinate;
5021
+ y?: ComputerCoordinate;
5022
+ direction: "up" | "down" | "left" | "right";
5023
+ /** @default 1 */
5024
+ amount?: number;
5025
+ }
5026
+ /** Type the text, as a keyboard would (newline and tab included). The node logs its length only. */
5027
+ export interface ComputerType {
5028
+ action: "type";
5029
+ /** At most 8,192 bytes of UTF-8; no control characters other than newline, carriage return and tab. */
5030
+ text: string;
5031
+ }
5032
+ /** Press and release a key or a chord of xdotool key names joined by `+`. */
5033
+ export interface ComputerKey {
5034
+ action: "key";
5035
+ keys: string;
5036
+ }
5037
+ /** Press one key and hold it until `key_up` (or the end of a batch that fails). */
5038
+ export interface ComputerKeyDown {
5039
+ action: "key_down";
5040
+ key: string;
5041
+ }
5042
+ /** Release a held key. */
5043
+ export interface ComputerKeyUp {
5044
+ action: "key_up";
5045
+ key: string;
5046
+ }
5047
+ /** Wait */
5048
+ export interface ComputerWait {
5049
+ action: "wait";
5050
+ ms: number;
5051
+ }
5052
+ /** Sends no input; the answer's `cursor` is the pointer's position. */
5053
+ export interface ComputerCursorPosition {
5054
+ action: "cursor_position";
5055
+ }
5056
+ export interface ComputerActResult {
5057
+ object: "computer_actions";
5058
+ /** One per action, in order. */
5059
+ results: ComputerActionResult[];
5060
+ /** Where the pointer is after the actions; `null` when the X server went away during the batch. */
5061
+ cursor: ComputerPoint | null;
5062
+ /** The screenshot asked for; `null` when none was asked for or it could not be taken. */
5063
+ screenshot: ScreenshotData | null;
5064
+ /** How long the settle waited, ms; `null` without `settle`. */
5065
+ settled_ms: number | null;
5066
+ /** `quiet`: the screen stayed still for `quiet_ms`; `deadline`: `max_ms` passed first. */
5067
+ settled_by: "quiet" | "deadline" | null;
5068
+ /** Time inside the sandbox, ms. */
5069
+ timing: {
5070
+ act_ms: number;
5071
+ settle_ms: number;
5072
+ capture_ms: number;
5073
+ encode_ms: number;
5074
+ };
5075
+ }
5076
+ export interface ComputerActionResult {
5077
+ ok: boolean;
5078
+ /**
5079
+ * Whether the action's input reached the X server. `delivered_unverified`: sent and synced; what the
5080
+ * application did with it is not checked. `delivery_uncertain`: part of it may have been sent.
5081
+ * `not_delivered`: nothing was sent (the action failed before its input, was skipped, or sends no input:
5082
+ * `wait`, `cursor_position`). `unknown`: the X server went away after the input was sent.
5083
+ */
5084
+ delivery: "delivered_verified" | "delivered_unverified" | "delivery_uncertain" | "not_delivered" | "unknown";
5085
+ /**
5086
+ * Whether sending the action again is safe. `safe`: nothing was sent, or the action does the same thing
5087
+ * twice (`move`, `wait`, `cursor_position`). `unsafe`: its input landed and a second send repeats it.
5088
+ * `unknown`: whether its input landed cannot be told.
5089
+ */
5090
+ retry: "safe" | "unsafe" | "unknown";
5091
+ /** Why the action failed; `null` when it did not. */
5092
+ error: string | null;
5093
+ }
4669
5094
  export interface Template {
4670
5095
  id: string;
4671
5096
  object: "template";
@@ -4675,9 +5100,10 @@ export interface Template {
4675
5100
  runtimes: string[];
4676
5101
  /**
4677
5102
  * `cdp`: Chrome runs in the template's snapshot with DevTools on `127.0.0.1:9222` inside the sandbox; declare
4678
- * port 9222 to reach it through a port preview.
5103
+ * port 9222 to reach it through a port preview. `computer`: the sandbox has a screen, a mouse and a keyboard
5104
+ * that `/v1/sandboxes/{sandbox_id}/computer` reads and drives (the `desktop` template).
4679
5105
  */
4680
- capabilities: Array<"exec" | "files" | "pty" | "run_code" | "cdp">;
5106
+ capabilities: Array<"exec" | "files" | "pty" | "run_code" | "cdp" | "computer">;
4681
5107
  defaults: {
4682
5108
  vcpu: number;
4683
5109
  memory_mib: number;
@@ -4694,8 +5120,8 @@ export interface Template {
4694
5120
  }[];
4695
5121
  /**
4696
5122
  * `node`: one of the node's templates, the same for everyone. `project`: an imported image's template,
4697
- * which only its project sees and can start sandboxes from. An image template's `name` is its `tpl_` ID and
4698
- * it has one size (`size_classes` holds only the image's).
5123
+ * which only its project sees and can start sandboxes from. An image template's `name` is its image's
5124
+ * `name` when it has one, else its `tpl_` ID, and it has one size (`size_classes` holds only the image's).
4699
5125
  */
4700
5126
  owner: "node" | "project";
4701
5127
  /** The image this template was imported from (`owner: project`); `null` for node templates. */
@@ -4708,6 +5134,39 @@ export interface Template {
4708
5134
  */
4709
5135
  agent_sha256?: string;
4710
5136
  }
5137
+ /**
5138
+ * Exactly one of `image` (an import) and `build` (a Dockerfile build); the rest as `POST /v1/images` takes it.
5139
+ */
5140
+ export type TemplateCreateRequest = {
5141
+ name?: ImageName;
5142
+ /** An image reference, as `ref` of `POST /v1/images` (`python:3.11-slim`); a private one needs `auth`. */
5143
+ image?: string;
5144
+ build?: ImageBuild;
5145
+ auth?: ImageRegistryAuth;
5146
+ warmup?: ImageWarmup;
5147
+ /** The size every sandbox from the template has. Default 1, at most your plan's `sandboxes.vcpu_max`. */
5148
+ vcpu?: number;
5149
+ /**
5150
+ * The memory every sandbox from the template has. Default 1024, at most your plan's `sandboxes.memory_max`.
5151
+ */
5152
+ memory_mib?: number;
5153
+ };
5154
+ /**
5155
+ * 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.
5156
+ */
5157
+ export interface TemplateCreated {
5158
+ id: string;
5159
+ object: "template";
5160
+ /** The image's name, else `null` (then the template is started by its ID). */
5161
+ name: null | ImageName;
5162
+ status: ImageStatus;
5163
+ /** The image (`GET /v1/images/{image_id}?wait=30` until it is `ready`). */
5164
+ image: string;
5165
+ /** The image's flattened root file system, once stored. */
5166
+ rootfs_sha256: string | null;
5167
+ /** The image's key; the same request in this project answers this template. */
5168
+ key: string;
5169
+ }
4711
5170
  export type TemplateList = Omit<ListEnvelope, "data"> & {
4712
5171
  data: Template[];
4713
5172
  };
@@ -4864,14 +5323,14 @@ export type SwarmEvent = JobEvent & {
4864
5323
  }[];
4865
5324
  };
4866
5325
  /**
4867
- * `queued` (accepted, waiting for the queue), `pulling` (layers streaming into the unpacking microVM),
5326
+ * `queued` (accepted, waiting for the queue), `building` (a Dockerfile build running in its microVM), `pulling` (layers streaming into the unpacking microVM),
4868
5327
  * `flattening` (the last byte sent; waiting for the unpacker and the store), `warming` (the first boot, the
4869
5328
  * warm-up and the warm snapshot), `ready`. `rebuilding`: a node release changed the guest agent, kernel or
4870
5329
  * hypervisor, and the warm snapshot is being taken again (creates answer `409 image_not_ready` until it is
4871
5330
  * `ready`). `failed`: see `error`. `evicted`: the node's image cache was full and this image, unused, was
4872
5331
  * removed; import it again with the same request.
4873
5332
  */
4874
- export type ImageStatus = "queued" | "pulling" | "flattening" | "warming" | "ready" | "rebuilding" | "failed" | "evicted";
5333
+ export type ImageStatus = "queued" | "building" | "pulling" | "flattening" | "warming" | "ready" | "rebuilding" | "failed" | "evicted";
4875
5334
  export interface ImageWarmup {
4876
5335
  /**
4877
5336
  * Commands run once, in order, in the image's first boot before its warm snapshot is taken: each an
@@ -4880,14 +5339,33 @@ export interface ImageWarmup {
4880
5339
  */
4881
5340
  commands: string[][];
4882
5341
  }
4883
- export interface ImageImportRequest {
5342
+ /**
5343
+ * The project's name for the image (`images.build`): `name[:tag]`, at most 64 characters in all, each part of
5344
+ * lowercase letters, digits, `.`, `_` and `-` and starting with a letter or a digit, the name not starting
5345
+ * with `tpl_`. The whole string is the name (`app` and `app:latest` are two names). `POST /v1/sandboxes
5346
+ * {"template": "<name>"}` starts from it in this project only; another project's name answers `404
5347
+ * template_not_found`. Unique among the project's images, never a node template's name (`base` nor
5348
+ * `base:v1`), and part of the image's key.
5349
+ */
5350
+ export type ImageName = string;
5351
+ /**
5352
+ * An application, as its b3os.yaml `name` (`images.build`): on a request, the application asking for the image,
5353
+ * which then holds it (`held_by`) instead of keeping it until it is deleted (`kept`).
5354
+ */
5355
+ export type ImageAppName = string;
5356
+ /** Exactly one of `ref` (an import) and `build` (a Dockerfile build). */
5357
+ export type ImageImportRequest = {
4884
5358
  /**
4885
5359
  * An image reference: `[registry/]repository[:tag|@sha256:digest]`. Without a registry it is Docker Hub
4886
5360
  * (`python:3.11-slim` is `registry-1.docker.io/library/python:3.11-slim`); without a tag or digest it is
4887
5361
  * `latest`. A tag is resolved to its digest once, when the import is accepted; the image keeps that digest.
4888
- * Public images only (no credentials).
5362
+ * A private image needs `auth`.
4889
5363
  */
4890
- ref: string;
5364
+ ref?: string;
5365
+ build?: ImageBuild;
5366
+ name?: ImageName;
5367
+ auth?: ImageRegistryAuth;
5368
+ app?: ImageAppName;
4891
5369
  warmup?: ImageWarmup;
4892
5370
  /** The size every sandbox from the image has. Default 1, at most your plan's `sandboxes.vcpu_max`. */
4893
5371
  vcpu?: number;
@@ -4895,6 +5373,68 @@ export interface ImageImportRequest {
4895
5373
  * The memory every sandbox from the image has. Default 1024, at most your plan's `sandboxes.memory_max`.
4896
5374
  */
4897
5375
  memory_mib?: number;
5376
+ };
5377
+ /**
5378
+ * A private registry's credential, from the vault (with the `images.build` flag; an import only, not a build).
5379
+ * `connection` names a connection of this project of type `basic`: `username`, and the password or an access
5380
+ * token in `password` (a Docker Hub or GitHub personal access token with read access to the image). Its
5381
+ * `hosts` must list the registry and the registry's token service: `registry-1.docker.io` and `auth.docker.io`
5382
+ * (or `*.docker.io`) for Docker Hub, `ghcr.io` for GHCR.
5383
+ *
5384
+ * The node reads the connection when the import is accepted, as your credential (it needs `vault:run`), keeps
5385
+ * it in memory for that one import, and sends it only in the Basic `Authorization` header of the token request
5386
+ * the registry's `WWW-Authenticate: Bearer` challenge names, over https, to a host the connection lists. It is
5387
+ * never logged, never put into an error, the image or its key, and never reaches a microVM; the tokens it earns
5388
+ * are used by that import only. Registries that only take Basic credentials on every request (no token
5389
+ * service) are not supported yet.
5390
+ *
5391
+ * The key does not name the connection: the same image pulled with another of the project's connections is the
5392
+ * same image.
5393
+ */
5394
+ export interface ImageRegistryAuth {
5395
+ /** A `basic` connection of this project, bound to the registry's hosts. */
5396
+ connection: string;
5397
+ }
5398
+ export interface ImageContext {
5399
+ object: "image_context";
5400
+ sha256: string;
5401
+ bytes: number;
5402
+ /** When the tar goes, unless it is uploaded again or a build names it first. */
5403
+ expires_at: string;
5404
+ }
5405
+ export interface ImageContextPart {
5406
+ /** A tar this project uploaded with `PUT /v1/images/contexts/{sha256}` (kept 24 hours). */
5407
+ sha256: string;
5408
+ /**
5409
+ * The folder of the build context the tar is unpacked into, relative (no `..`, no leading `/`); empty for the context's root.
5410
+ * @default ""
5411
+ */
5412
+ at?: string;
5413
+ }
5414
+ /**
5415
+ * A Dockerfile build. The context is one or more uploaded tars, unpacked in order inside the build microVM
5416
+ * (never on the host); the Dockerfile is a file of the context. The build runs BuildKit's Dockerfile frontend
5417
+ * as root inside a microVM of its own, with the public internet through B3OS's egress guard and no secrets,
5418
+ * for `linux/amd64`, within 1,800 seconds; the result is flattened and becomes a template as an import does.
5419
+ * The same request in the same project (the same context bytes, Dockerfile path, arguments and target) answers
5420
+ * the image it already built; a base image tag that moved since is not pulled again unless `no_cache` is set.
5421
+ */
5422
+ export interface ImageBuild {
5423
+ context: ImageContextPart[];
5424
+ /**
5425
+ * The Dockerfile's path in the context, relative.
5426
+ * @default "Dockerfile"
5427
+ */
5428
+ dockerfile?: string;
5429
+ /** Build arguments (`ARG`). Part of the key; not secret (they are in the image's history). */
5430
+ args?: Record<string, string>;
5431
+ /** The stage to build (`--target`), else the last. */
5432
+ target?: string | null;
5433
+ /**
5434
+ * Build again even when this project already has the image of this request.
5435
+ * @default false
5436
+ */
5437
+ no_cache?: boolean;
4898
5438
  }
4899
5439
  /**
4900
5440
  * What the image's own configuration says, read when it was imported. `user`, `env` and `workdir` apply to every
@@ -4926,13 +5466,15 @@ export interface ImagePackage {
4926
5466
  }
4927
5467
  /**
4928
5468
  * Milliseconds each finished stage took (`null` until it finishes): `resolve` (the reference to a digest,
4929
- * before the answer), `queue` (waiting for a slot), `pull_flatten` (pulling and unpacking, which overlap),
5469
+ * before the answer; `null` for a build), `queue` (waiting for a slot), `build` (a Dockerfile build, `null` for an
5470
+ * import), `pull_flatten` (pulling and unpacking, which overlap; for a build, unpacking its result),
4930
5471
  * `adopt` (checking and storing the file system), `golden` (the first boot, warm-up and warm snapshot), and
4931
5472
  * `total`.
4932
5473
  */
4933
5474
  export interface ImageStagesMs {
4934
5475
  resolve: number | null;
4935
5476
  queue: number | null;
5477
+ build: number | null;
4936
5478
  pull_flatten: number | null;
4937
5479
  adopt: number | null;
4938
5480
  golden: number | null;
@@ -4941,18 +5483,39 @@ export interface ImageStagesMs {
4941
5483
  export interface ImageError {
4942
5484
  /** `import_failed`. */
4943
5485
  code: string;
4944
- stage: "resolve" | "pull" | "flatten" | "adopt" | "golden" | "rebuild" | "interrupted";
5486
+ stage: "resolve" | "build" | "pull" | "flatten" | "adopt" | "golden" | "rebuild" | "interrupted";
4945
5487
  detail: string;
4946
5488
  /** The last 4 KiB of the unpacker's or the warm-up's output, when there was any. */
4947
5489
  output: string | null;
4948
5490
  }
5491
+ export interface ImageBuildSource {
5492
+ context: {
5493
+ sha256: string;
5494
+ at: string;
5495
+ bytes: number;
5496
+ }[];
5497
+ dockerfile: string;
5498
+ args: Record<string, string>;
5499
+ target: string | null;
5500
+ /** The base images the build pulled, by reference and digest, once it ran. */
5501
+ base_images: {
5502
+ ref: string;
5503
+ digest: string;
5504
+ }[];
5505
+ }
4949
5506
  export interface Image {
4950
5507
  id: string;
4951
5508
  object: "image";
4952
- /** The reference as given. */
4953
- ref: string;
4954
- /** The `linux/amd64` image manifest's digest. */
4955
- digest: string;
5509
+ /** The reference as given; `null` for a build. */
5510
+ ref: string | null;
5511
+ /** The build request, for an image built from a Dockerfile; `null` for an import. */
5512
+ build: null | ImageBuildSource;
5513
+ /** The project's name for the image (`images.build`), else `null`. */
5514
+ name: null | ImageName;
5515
+ /**
5516
+ * The `linux/amd64` image manifest's digest: the imported one, or for a build the one BuildKit produced (`null` until the build finishes).
5517
+ */
5518
+ digest: string | null;
4956
5519
  /** The index (multi-platform list) the manifest was picked from, when the reference named one. */
4957
5520
  index_digest: string | null;
4958
5521
  platform: "linux/amd64";
@@ -4972,7 +5535,9 @@ export interface Image {
4972
5535
  vcpu: number;
4973
5536
  memory_mib: number;
4974
5537
  };
4975
- /** The import key (sha256); an import with the same key in this project returns this image. */
5538
+ /**
5539
+ * 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.
5540
+ */
4976
5541
  key: string;
4977
5542
  stages_ms: ImageStagesMs;
4978
5543
  /** Compressed layer bytes pulled from the registry. */
@@ -4990,13 +5555,55 @@ export interface Image {
4990
5555
  error: null | ImageError;
4991
5556
  created_at: string;
4992
5557
  ready_at: string | null;
5558
+ /**
5559
+ * 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`.
5560
+ */
5561
+ held_by: ImageAppName[];
5562
+ /**
5563
+ * 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.
5564
+ */
5565
+ kept: boolean;
5566
+ }
5567
+ /** An application's hold on an image, released (`POST /v1/images/{image_id}/release`). */
5568
+ export interface ImageRelease {
5569
+ object: "image_release";
5570
+ image: string;
5571
+ app: ImageAppName;
5572
+ /** The image is gone (deleted as `DELETE /v1/images/{image_id}` deletes it). */
5573
+ removed: boolean;
5574
+ /** The applications that still hold it. */
5575
+ held_by: ImageAppName[];
5576
+ /** It is kept until deleted (asked for without `app` at least once), so it stays. */
5577
+ kept: boolean;
5578
+ /**
5579
+ * 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.
5580
+ */
5581
+ in_use: boolean;
5582
+ }
5583
+ export interface ImageReleaseRequest {
5584
+ app: ImageAppName;
5585
+ }
5586
+ /** Lines of an image's build log. */
5587
+ export interface ImageLog {
5588
+ object: "image_log";
5589
+ /** The image ID (`img_…`). */
5590
+ image: string;
5591
+ status: ImageStatus;
5592
+ /** The log's lines from `offset`, without their line ends. */
5593
+ lines: string[];
5594
+ /** The `offset` of the next read. */
5595
+ next_offset: number;
4993
5596
  }
4994
5597
  export type ImageList = Omit<ListEnvelope, "data"> & {
4995
5598
  data: Image[];
4996
5599
  };
4997
5600
  /** An instance's key, stored and shown as written, so never a credential or a personal detail. */
4998
5601
  export type AgentInstanceKey = string;
4999
- /** Lowercase letters, digits and `-`, starting with a letter. `sessions` is reserved. */
5602
+ /**
5603
+ * Lowercase letters, digits and `-`, starting with a letter. `sessions`, `harnesses`, `grants`, `self` and
5604
+ * `recipes` are reserved: they are path segments under `/v1/agents`, or will be (`recipes`, for shared harness
5605
+ * definitions).
5606
+ */
5000
5607
  export type AgentName = string;
5001
5608
  /**
5002
5609
  * What each instance starts from: a template (node templates, or one of your project's image templates) at a
@@ -5070,44 +5677,1098 @@ export interface AgentTurns {
5070
5677
  */
5071
5678
  redeliver?: boolean;
5072
5679
  }
5073
- export interface AgentCreateRequest {
5074
- name: AgentName;
5075
- source?: AgentSource;
5076
- entry: AgentEntry;
5077
- /** Environment variables of the harness. Returned as given; put credentials in `secrets`. */
5078
- env?: Record<string, string>;
5680
+ /**
5681
+ * Which harness. The open-source ones come first: `opencode` (MIT; its server takes steers, queued prompts and
5682
+ * permission answers, with a TUI that attaches to the same server), `codex` (OpenAI's Codex CLI, Apache-2.0)
5683
+ * and `pi` (Earendil's pi coding agent, MIT); then `claude-code` (Anthropic's Claude Code). Each is driven by a
5684
+ * driver built into the shim, and what each takes (providers, sign-ins, a model the node serves, modes, lists)
5685
+ * is its entry in `GET /v1/agents/harnesses`, which lists the ones this node runs. Or `acp`, a harness your
5686
+ * organization brings that speaks the Agent Client Protocol over stdio, named in the block's `acp` (planned,
5687
+ * after prepared snapshots, for your organization's own use; refused with `422 harness_capability_unsupported`
5688
+ * until the shim serves it).
5689
+ */
5690
+ export type AgentHarnessKindName = "opencode" | "codex" | "pi" | "claude-code" | "acp";
5691
+ /**
5692
+ * A coding agent people already use, run unmodified as the agent's harness (planned: not served on the beta
5693
+ * node yet; research/harnesses-design.md). The instance's entry is B3OS's shim, `b3os-harness serve`, which owns
5694
+ * the harness process, delivers turns into it, turns its hooks and stream into `harness.*` events, answers its
5695
+ * permission prompts and serves its terminal. What the node and the shim say to each other inside the instance
5696
+ * (the environment, `/run/b3os/harness.json`, the headers and the shim's routes) is
5697
+ * packages/spec/sidecars/harness.md.
5698
+ *
5699
+ * The block is a recipe: write it once, and deploy it as many agents and instances as you need. Its members are
5700
+ * settled at three times:
5701
+ *
5702
+ * - At prepare, what has to be fetched: `skills` and `plugins` from `git`, `npm` or `artifact`, and `mcp`
5703
+ * servers run from an npm package. The node installs them, with the harness at `version`, into a snapshot of
5704
+ * the `harness` template that it builds once per prepare key and shares across the project
5705
+ * (`Agent.harness_prepared`), so each instance starts with them in place. The key covers only that fetched
5706
+ * set, the kind, the version, the template and the shim, so editing any other member builds nothing again.
5707
+ * Until prepared snapshots ship, those sources answer `422 harness_setup_needs_prepare`.
5708
+ * - When an instance starts, what the shim writes and sets up: `instructions`, `settings`, `mcp` entries,
5709
+ * `skills` and `plugins` given as `text`, `files` or `builtin`, `files`, `mode`, `terminal`, and each
5710
+ * credential profile's directory.
5711
+ * - At each turn: `model`, `permissions`, `hooks` and the turn's credential profile.
5712
+ *
5713
+ * Until they are served on this node, three members are refused when the definition is written, even when
5714
+ * empty (`[]` or `{}`), with `422 harness_capability_unsupported`: `repo`, `context` and `acp` (`kind: acp`
5715
+ * with it). The node never stores them, so neither a stored block nor `/run/b3os/harness.json` carries them.
5716
+ * A vault connection outside a credential profile reaches the instance as a `B3OS_CONN_<N>` secret (below): a
5717
+ * remote `mcp` server's `connection` and a stdio server's `{connection}` `env` values. `repo.connection` waits
5718
+ * for `repo`. A `${...}` or `{env:...}` in a server's `url`, `command` or `env`, which Claude Code and opencode
5719
+ * would expand from the harness's environment, is `400 invalid_request`: name a connection instead.
5720
+ *
5721
+ * B3OS's own tools are default entries of the block's lists, not a switch. `mcp` starts with `b3os`, B3OS's MCP
5722
+ * server inside the instance (`{builtin: b3os, toolsets: [browser, vision, render, sandboxes, actions, infer]}`,
5723
+ * at `B3OS_MCP_URL`), and `skills` starts with `b3os`, the skill that says how to use them (`{builtin: b3os}`);
5724
+ * `GET /v1/agents/harnesses` lists both (`checks.defaults`). Your `mcp` and `skills` maps are a JSON merge patch
5725
+ * (RFC 7396) over those defaults, the rule the shim applies: an entry under a new name is added, an entry set
5726
+ * to `null` is removed, and an entry under a default's name is merged into the default member by member (a
5727
+ * member set to `null` is removed, an array replaces the default's whole). So `"mcp": {"b3os": {"toolsets":
5728
+ * ["vision"]}}` keeps only the page tools without restating `builtin`, and `"mcp": {"b3os": null}, "skills":
5729
+ * {"b3os": null}` leaves the harness its own tools only. `plugins` has no default. The grant the node fills in
5730
+ * comes with the merged `b3os` MCP entry: the scopes its toolsets need, scoped to the instance
5731
+ * (`AgentHarnessMcpBuiltin`); without that entry the filled `api` carries no B3OS MCP tool scopes (only
5732
+ * `infer:run` if a `node` profile is present, and nothing otherwise). A model the node serves is reached
5733
+ * through the `model` or a `node` profile you pick, not through these entries. Every node carries the
5734
+ * defaults; a toolset a node does not serve is left out of the server's tools. A default is added only where
5735
+ * the kind takes its list (the kind's `setup` in `GET /v1/agents/harnesses`), and both default entries are
5736
+ * builtins of the `harness` template, so they change no prepare key.
5737
+ *
5738
+ * The stored block keeps `mcp` and `skills` as you wrote them, never merged: your own entries and patches, a
5739
+ * removed default kept as `null`, `{}` when you gave none. So a block that is read and sent back changes
5740
+ * nothing, and the shim, which merges once at start, sees the same maps you wrote. The merged lists are those
5741
+ * maps merged over `checks.defaults`, and the filled `api` shows the grant they bring.
5742
+ *
5743
+ * The node fills the rest of the definition from this block: `source.template` (the `harness` template, which
5744
+ * pins each harness's versions) and `source.snapshot` (the revision's prepared snapshot, once prepared
5745
+ * snapshots ship and it is built), `entry` (`b3os-harness serve --config /run/b3os/harness.json` on port 7801,
5746
+ * ready when that port answers, `max_restarts` 5), `secrets` (beside your own: each `key` profile's
5747
+ * credentials, as `B3OS_PROFILE_<NAME>__<VAR>`, and the secret of every other connection the block names, as
5748
+ * `B3OS_CONN_<N>`, which the file maps to its member: `repo`, a remote `mcp` server's `connection`, a stdio
5749
+ * server's `{connection}` values), `api` (the scopes that come with the `b3os` MCP entry, plus `infer:run`
5750
+ * when a `node` profile is present, and nothing without either), `egress` and `turns.timeout_s` (3,600
5751
+ * seconds, the most a turn may take). The shim writes each connection's secret where its member says (the
5752
+ * instance's git credentials, the harness's MCP config, as a variable the config refers to) and keeps every
5753
+ * `B3OS_*` variable out of the harness's processes and its terminal except the ones B3OS gives every sandbox
5754
+ * (`B3OS_API_URL`, `B3OS_SANDBOX_ID`, `B3OS_PROJECT`, `B3OS_PORT_BASE_PATH`, `B3OS_MCP_URL`, `B3OS_MODEL`,
5755
+ * `B3OS_WORKSPACE_ID`, `B3OS_BRANCH_ID`, `B3OS_WORKSPACE_PATH`): the profiles' values, the connections' secrets,
5756
+ * the shim's token, the flags and the instance's id never reach it. Set `api`,
5757
+ * `egress` or `turns` yourself to use your own instead. `source.vcpu`, `memory_mib` and `disk_gib` apply as
5758
+ * for any agent. `source.template`, `source.snapshot` and `entry` cannot be set beside `harness`, and neither
5759
+ * can an `env` or `secrets` name that starts with `B3OS_` (the node's and the shim's own) or that the kind's
5760
+ * shim sets or removes (`checks.kinds.<kind>.env_owned`) (`400 invalid_request`).
5761
+ *
5762
+ * `/run/b3os/harness.json` is this block as the node stored it, with exactly these changes and nothing else: it
5763
+ * leaves out `hooks.webhook` and `hooks.decide.url` (both calls leave from the node, so neither URL nor a
5764
+ * secret enters the instance) and every vault `connection` (a profile's values arrive as
5765
+ * `B3OS_PROFILE_<NAME>__<VAR>`, any other connection's as `B3OS_CONN_<N>`); each `node` profile gains
5766
+ * `base_url`, the node's infer inside the instance (`http://127.0.0.1:7700/v1/infer`); and `connections` maps
5767
+ * each member a secret goes to (`mcp.<name>`, `mcp.<name>.env.<VAR>`, and `repo` once it is served) to its
5768
+ * variable. It never holds a credential. packages/spec/sidecars/harness.md
5769
+ * lists every member and which the shim reads.
5770
+ *
5771
+ * The filled `egress` is an allowlist of exactly the hosts the block reaches from the instance: each `key` and
5772
+ * `signin` profile's provider hosts, from the kind's `auth.hosts` in `GET /v1/agents/harnesses` (a `{region}`
5773
+ * in one filled from the profile's `region`); each profile's `base_url` host; the `repo` host; and each remote
5774
+ * `mcp` server's host. A profile whose provider has no hosts in the catalog is `422
5775
+ * harness_capability_unsupported`. Your own `egress` must let the same hosts through (`public`, or an
5776
+ * `allowlist` that matches each one); one it does not is `400 invalid_request`, naming the host. B3OS itself is
5777
+ * reached inside the instance at `http://127.0.0.1:7700`, outside `egress`, and the `hooks.webhook` and
5778
+ * `hooks.decide` calls leave from the node, so neither host goes in the list. The hosts a stdio `mcp` server
5779
+ * reaches are not known to the node: list them in your own `egress`.
5780
+ *
5781
+ * No harness agent takes a plan's token. A name in `AgentHarnessPlanEnv` in `env`, `secrets`, an `mcp` server's
5782
+ * `env` or a `settings` `env` entry is `400 invalid_request`. A value holding a plan's token (`sk-ant-oat` or
5783
+ * `sk-ant-ort`) is `400 harness_plan_credential` wherever it is: any string in the stored definition (`env`,
5784
+ * `secrets`, this block's members, argv such as an `mcp` server's or `acp`'s `command`, `settings`, and every
5785
+ * skill, plugin and file), and the resolved value of every connection the definition names (each profile's,
5786
+ * `repo`'s, a remote `mcp` server's and a stdio server's `{connection}` values). The node checks when the
5787
+ * definition is written and again each time it makes an instance, so a connection changed later is refused
5788
+ * then.
5789
+ *
5790
+ * The block is part of the revision, as the rest of the definition is: a `PATCH` makes a new revision, and
5791
+ * `upgrade: on_wake` moves sleeping instances to it. A harness cannot change its own definition (`agents:write`
5792
+ * is granted only when named exactly), and what the recipe installs is read-only to the harness.
5793
+ */
5794
+ export interface AgentHarness {
5079
5795
  /**
5080
- * Environment variables never returned or logged, as a sandbox's `secrets`: code in the instance can read
5081
- * them. A memory snapshot holds them, so the node keeps an instance's snapshots to itself: they are never
5082
- * listed or restorable through the API.
5796
+ * Which harness. Default: `opencode`, which is open source and reaches the providers its catalog entry's
5797
+ * `auth.key` lists (Anthropic, OpenAI and OpenRouter, and through OpenRouter many others). Its driver was
5798
+ * checked live against opencode 2.4.2 and a real provider on 2026-11-28: `openai/gpt-4o-mini` through
5799
+ * OpenRouter, three turns, one of them running a shell tool, each reporting its usage and cost.
5083
5800
  */
5084
- secrets?: Record<string, SecretValue>;
5085
- api?: SandboxApiGrant;
5086
- egress?: EgressPolicy;
5087
- sleep?: AgentSleep;
5088
- turns?: AgentTurns;
5089
- metadata?: Metadata;
5090
- }
5091
- export interface AgentUpdateRequest {
5092
- source?: AgentSource;
5093
- entry?: AgentEntry;
5094
- env?: Record<string, string>;
5095
- secrets?: Record<string, SecretValue>;
5096
- api?: SandboxApiGrant;
5097
- egress?: EgressPolicy;
5098
- sleep?: AgentSleep;
5099
- turns?: AgentTurns;
5801
+ kind?: AgentHarnessKindName;
5100
5802
  /**
5101
- * What happens to instances of earlier revisions: `new_instances` leaves them as they are; `on_wake` makes a
5102
- * sleeping one again from this revision at its next wake, which ends its memory and disk.
5103
- * @default "new_instances"
5803
+ * The harness's version, one of the kind's `versions` in `GET /v1/agents/harnesses`. Default: its
5804
+ * `default_version`. A version this node does not run is `422 harness_version_unavailable`.
5104
5805
  */
5105
- upgrade?: "new_instances" | "on_wake";
5106
- metadata?: Metadata;
5806
+ version?: string;
5807
+ acp?: AgentHarnessAcp;
5808
+ auth?: AgentHarnessAuth;
5809
+ /**
5810
+ * The model, as the harness names it (opencode's `openrouter/openai/gpt-4o-mini`, Claude Code's
5811
+ * `claude-opus-5-5`), or a model the node's infer serves (`GET /v1/infer/models`), which the harness then
5812
+ * reaches on the node with no key, for a kind whose catalog entry has `auth.node: true`. A profile's own
5813
+ * `model` wins for that profile's turns. Default: the harness's own default.
5814
+ */
5815
+ model?: string;
5816
+ /**
5817
+ * What the harness may do without asking. `auto`: the microVM is the sandbox, so the harness runs in its
5818
+ * most autonomous mode (every tool allowed in opencode and pi, Codex's full access with approvals off,
5819
+ * Claude Code's `bypassPermissions`). `ask`: every permission prompt becomes `harness.permission.requested`
5820
+ * and the turn waits for `POST /v1/agents/{agent}/instances/{key}/decisions`; one nobody answers is denied
5821
+ * at the turn's timeout. `plan`: read-only tools only; every write is denied, and
5822
+ * `hooks.decide` is never called. In `auto` and `ask`, `hooks.decide` answers before a person.
5823
+ * @default "auto"
5824
+ */
5825
+ permissions?: "auto" | "ask" | "plan";
5826
+ /**
5827
+ * How the shim drives the harness. `api`: headless and structured (opencode's server, Codex's app-server,
5828
+ * pi's RPC mode, Claude Code's stream-json); the terminal holds a shell in the workspace. `terminal`: the
5829
+ * harness's own TUI holds the terminal and turns are pasted into it, so a person can type turns of their
5830
+ * own there. In `terminal` mode the events come from the harness's hooks, so a kind may report less there
5831
+ * (Claude Code's TUI sends no `harness.message`). The kind's `modes` in `GET /v1/agents/harnesses` lists
5832
+ * what it takes (`422 harness_capability_unsupported` otherwise), with these limits:
5833
+ *
5834
+ * - Codex and pi run in `api` only. pi's RPC process and its TUI cannot share one session file yet.
5835
+ * - opencode in `terminal` takes no `hooks.decide` outside `permissions: plan`: its TUI answers permission
5836
+ * prompts itself, and an "always" answered there would keep the webhook from seeing that tool again. The
5837
+ * kind's `capabilities.decide_modes` lists the modes where `hooks.decide` answers.
5838
+ * @default "api"
5839
+ */
5840
+ mode?: "api" | "terminal";
5841
+ /**
5842
+ * The repository cloned into the workspace. Not served yet: refused at write, even empty, with `422
5843
+ * harness_capability_unsupported` until the harness's shim clones it.
5844
+ */
5845
+ repo?: AgentHarnessRepo;
5846
+ /**
5847
+ * Appended to the harness's own system prompt, as written, when a harness session starts. Yours, so never
5848
+ * quoted.
5849
+ */
5850
+ instructions?: string;
5851
+ /**
5852
+ * Text added, as written, at each harness session's start (`session_start`) or before each turn
5853
+ * (`turn_start`); a resumed session does not get `session_start` again.
5854
+ * - `api` mode: it goes before the turn's own text in its prompt.
5855
+ * - `terminal` mode: it goes through the TUI's own hooks (Claude Code's SessionStart and UserPromptSubmit
5856
+ * `additionalContext`). A kind whose TUI the shim cannot reach is refused it there (`422
5857
+ * harness_capability_unsupported`); today that is opencode.
5858
+ *
5859
+ * Not served on the beta node yet: refused at write, even as `[]`, with `422 harness_capability_unsupported`.
5860
+ */
5861
+ context?: AgentHarnessContext[];
5862
+ /**
5863
+ * Skills (folders with a `SKILL.md`), by name, put where the harness reads them: Claude Code's skills
5864
+ * directory of each profile, Codex's extra skill roots. It starts with `b3os`, the builtin skill for B3OS's
5865
+ * tools; this map is a JSON merge patch over that default (`AgentHarness`): a new name is added and `null`
5866
+ * removes an entry. `b3os` takes only `{builtin: b3os}` or `null`. Stored as written. A kind whose `setup`
5867
+ * in `GET /v1/agents/harnesses` does not list `skills` gets no default, and a skill of yours there answers
5868
+ * `422 harness_capability_unsupported`.
5869
+ */
5870
+ skills?: Record<string, AgentHarnessSetupItem | null>;
5871
+ /**
5872
+ * Plugins, by name, in the kind's own plugin format: a Claude Code plugin directory (loaded with
5873
+ * `--plugin-dir`), a Codex plugin (installed from a local marketplace at prepare). There is no default
5874
+ * plugin. With `permissions: ask`, a
5875
+ * plugin whose hooks can answer a permission prompt (Claude Code's `PreToolUse` or `PermissionRequest`) is
5876
+ * `400 invalid_request`, since a person is the gate there; with `hooks.decide` it is allowed, because the
5877
+ * shim's own hook still runs on every tool and a deny wins. A kind whose `setup` does not list `plugins`
5878
+ * answers `422 harness_capability_unsupported`.
5879
+ */
5880
+ plugins?: Record<string, AgentHarnessSetupItem>;
5881
+ /**
5882
+ * MCP servers for the harness, by name, written into its own MCP config when the instance starts:
5883
+ * opencode's `mcp`, each profile's Codex `config.toml`, Claude Code's `--mcp-config` file (with
5884
+ * `--strict-mcp-config`, so a repository's own `.mcp.json` is not read), or an ACP harness's session. Each
5885
+ * is remote (`url`) or run in the instance (`command`). It starts with `b3os`, B3OS's own server
5886
+ * (`AgentHarnessMcpBuiltin`), which brings the instance's grant; this map is a JSON merge patch over that
5887
+ * default (`AgentHarness`): a new name is added, `null` removes an entry, and `"b3os": {"toolsets": [...]}`
5888
+ * narrows the default's toolsets without restating `builtin`. Stored as written. A kind whose `setup` does
5889
+ * not list `mcp` gets no default, and a server of yours there answers `422 harness_capability_unsupported`.
5890
+ */
5891
+ mcp?: {
5892
+ b3os?: AgentHarnessMcpBuiltin | null;
5893
+ [key: string]: unknown;
5894
+ };
5895
+ settings?: AgentHarnessSettings;
5896
+ /**
5897
+ * Files written into the workspace before the first harness session, after the repository is cloned
5898
+ * (`CLAUDE.md`, `AGENTS.md`). A file already at the path is replaced. Skills and plugins go in `skills` and
5899
+ * `plugins`.
5900
+ */
5901
+ files?: AgentHarnessFile[];
5902
+ hooks?: AgentHarnessHooks;
5903
+ terminal?: AgentHarnessTerminal;
5904
+ }
5905
+ /**
5906
+ * A harness your organization brings, for `kind: acp` only (planned: it needs prepared snapshots, and it is for
5907
+ * your organization's own use). It speaks the Agent Client Protocol over stdio: the shim starts `command` as the
5908
+ * harness's user, opens a session with the block's `mcp` servers, sends each turn as a prompt and each cancel as
5909
+ * an interrupt, and answers the harness's permission requests through the same rules, `hooks.decide` and people
5910
+ * as any harness, allowing or rejecting each call once. The package is installed at prepare. An ACP harness
5911
+ * takes `key` and `node` profiles only, never `signin`; it is steered only when it implements B3OS's optional
5912
+ * `_b3os/steer` method (`422 harness_capability_unsupported` otherwise); and `hooks.decide` on
5913
+ * `harness.tool.requested` is refused, because the node cannot check that every tool call reaches a permission
5914
+ * request. With any other `kind` it is `400 invalid_request`.
5915
+ */
5916
+ export interface AgentHarnessAcp {
5917
+ npm: AgentHarnessNpmSource;
5918
+ /** The command that starts the harness in ACP mode, from the installed package. */
5919
+ command: string[];
5920
+ /** The environment variables the harness reads a `key` profile's key from. */
5921
+ key_env?: string[];
5107
5922
  }
5108
- export interface Agent {
5109
- id: string;
5110
- object: "agent";
5923
+ /**
5924
+ * How the harness reaches its model: named credential profiles, so plans, subscriptions and API keys sit side by
5925
+ * side and each turn uses one of them. B3OS never collects, stores, reads or routes a plan's token: no member
5926
+ * takes one, a harness agent's `env`, `secrets`, `mcp` `env` and `settings` `env` refuse the variables a
5927
+ * harness reads one from (`AgentHarnessPlanEnv`), and a value holding one, in the definition or in a connection
5928
+ * it names, is `400 harness_plan_credential` (`AgentHarness`).
5929
+ *
5930
+ * - `{connection}` is shorthand for one `key` profile named `default`.
5931
+ * - Left out, with a `model` the node's infer serves, it is one `node` profile named `default`, for a kind
5932
+ * whose catalog entry has `auth.node: true` (`422 harness_capability_unsupported` for another); left out
5933
+ * with any other model, `400 invalid_request`.
5934
+ * - `{default, profiles}`: up to 8 named profiles (`AgentHarnessAuthProfile`). `default` is the profile a turn
5935
+ * uses when neither its message nor its conversation names one, and is required with more than one profile.
5936
+ *
5937
+ * The node stores the expanded form, so a read always shows `{default, profiles}`.
5938
+ *
5939
+ * A turn's profile is its message's `profile`, else the one its conversation used last, else `default`. A
5940
+ * caller only picks among the definition's profiles and never sends a credential with a turn. Profiles switch
5941
+ * between turns only, and a switch to another account starts without the provider's prompt cache. Each profile
5942
+ * has its own directory in the instance, so two sign-ins never share a file, and the harness's sessions are
5943
+ * shared across them, so a conversation goes on under another profile.
5944
+ *
5945
+ * A profile's `fallback` names the profile a conversation moves to when this one reaches a usage limit or is
5946
+ * refused. A fallback never moves into a `signin` profile, so a plan is only ever chosen by name, and it never
5947
+ * moves back by itself: `harness.auth.limited` carries `resets_at`, and you move back by naming the profile.
5948
+ * Errors the harness retries itself (a rate limit of the moment, a 5xx, an overload) never trigger one. Until a
5949
+ * kind's limit signal is checked against its pinned version, no fallback fires for it.
5950
+ */
5951
+ export type AgentHarnessAuth = AgentHarnessAuthConnection | AgentHarnessAuthProfiles;
5952
+ /** Shorthand for `{default: default, profiles: {default: {type: key, connection}}}`. */
5953
+ export interface AgentHarnessAuthConnection {
5954
+ connection: string;
5955
+ }
5956
+ export interface AgentHarnessAuthProfiles {
5957
+ default?: AgentHarnessProfileName;
5958
+ /**
5959
+ * The profiles by name. A `default` that names none of them, a `fallback` whose `to` names none of them or
5960
+ * a `signin` profile, and a cycle of fallbacks are `400 invalid_request`.
5961
+ */
5962
+ profiles: Record<string, AgentHarnessAuthProfile>;
5963
+ }
5964
+ /**
5965
+ * A credential profile's name: 1 to 32 lowercase letters, digits and single `_`s, starting with a letter and
5966
+ * not ending with `_`. It goes into an environment variable's name, `B3OS_PROFILE_<NAME>__<VAR>`, where the
5967
+ * first `__` ends the name, so no two profiles and variables share one.
5968
+ */
5969
+ export type AgentHarnessProfileName = string;
5970
+ /**
5971
+ * One credential: `key` (an API key or a cloud provider's credentials from your vault), `signin` (a person's own
5972
+ * plan, signed in inside their own instance) or `node` (a model the node serves). The kind's `auth` in
5973
+ * `GET /v1/agents/harnesses` says which it takes.
5974
+ */
5975
+ export type AgentHarnessAuthProfile = AgentHarnessAuthKey | AgentHarnessAuthSignin | AgentHarnessAuthNode;
5976
+ /**
5977
+ * An API key, or a cloud provider's credentials, from a vault connection. The node puts its values in the
5978
+ * shim's environment as `B3OS_PROFILE_<NAME>__<VAR>`, and the shim gives them, under the names the harness reads
5979
+ * (the kind's `auth.key`), to this profile's harness processes only; opencode's one server holds every `key`
5980
+ * profile's. Until egress credential injection ships, code in the instance can read the key, as with an agent's
5981
+ * `secrets`; it needs `vault:run` and `vault:connections:reveal`. The provider bills the key's owner.
5982
+ */
5983
+ export interface AgentHarnessAuthKey {
5984
+ type: "key";
5985
+ connection: string;
5986
+ provider?: AgentHarnessKeyProvider;
5987
+ /**
5988
+ * For `anthropic_compatible` and `openai_compatible` only: the gateway the harness sends to. Its host
5989
+ * joins the filled `egress`.
5990
+ */
5991
+ base_url?: string;
5992
+ /** The cloud region, for `bedrock` and `vertex`. */
5993
+ region?: string;
5994
+ /** The model for this profile's turns, when it is not the block's `model`. */
5995
+ model?: string;
5996
+ /** A name for people (the console, the CLI, events). */
5997
+ label?: string;
5998
+ fallback?: AgentHarnessAuthFallback;
5999
+ }
6000
+ /**
6001
+ * A person's own plan (a Claude or ChatGPT subscription), which that person signs in to inside their own
6002
+ * instance with the harness's own login, in the sign-in window (`GET …/terminal?window=signin:<profile>`). The
6003
+ * harness writes its credential file in this profile's directory, as it would on a laptop. B3OS never asks for
6004
+ * the token, never reads, stores or copies the file, and has no member to take one; the shim checks only that
6005
+ * the file exists, and asks the harness what it is signed in as (`harness.auth.ready`).
6006
+ *
6007
+ * A `signin` profile makes the agent personal (`Agent.owner`), whatever the provider: a person makes it, not a
6008
+ * key, and only its owner drives it, so one person uses each plan. Forks and children never carry a sign-in.
6009
+ * It needs a `provider` the kind's `auth.signin` lists (`422 harness_signin_unsupported`), and it is served
6010
+ * only on an instance made from the revision's prepared snapshot, which holds no other harness that could read
6011
+ * the file. A ChatGPT plan (`openai`) needs no flag. A Claude plan (`anthropic`) needs the
6012
+ * `agents.claude_plan_signin` flag, off by default and turned on per organization (`403
6013
+ * harness_claude_plan_signin_disabled` without it). The provider's terms for personal plans apply, and they
6014
+ * assume one person's ordinary use.
6015
+ *
6016
+ * Not served yet. Personal agents wait on two prerequisites, and until both land the node refuses every
6017
+ * `signin` profile with `403 harness_personal_agent`, whatever its provider and flag:
6018
+ *
6019
+ * - Harness agent VMs closed to the generic sandboxes API. Today any caller holding `sandboxes:run` in the
6020
+ * project can reach an agent's microVM by its `sandbox_id` (`GET /v1/sandboxes/{sandbox_id}`, exec, files,
6021
+ * logs and ports), and so read a sign-in's credential file and the shim's token. A personal agent's VMs (and,
6022
+ * once the node can, every harness agent's) answer those routes as a sandbox that does not exist, and
6023
+ * `AgentInstance.sandbox_id` is `null` for them.
6024
+ * - A person in the node's principal. A node token carries the organization, the project, the key, its scopes
6025
+ * and the request ID, and no person, so the node cannot tell an owner from anyone else in the project. The
6026
+ * edge's node tokens for dashboard sessions and CLI tokens gain the person (`usr`) and their organization
6027
+ * role, the claims workspaces asks for too.
6028
+ *
6029
+ * After both, a `signin` profile still waits for prepared snapshots (`422 harness_setup_needs_prepare` until
6030
+ * they ship).
6031
+ */
6032
+ export interface AgentHarnessAuthSignin {
6033
+ type: "signin";
6034
+ /**
6035
+ * `openai` (a ChatGPT plan) or `anthropic` (a Claude plan, behind `agents.claude_plan_signin`). The kind's
6036
+ * `auth.signin` in `GET /v1/agents/harnesses` lists which it signs in to: today Codex `openai` and Claude
6037
+ * Code `anthropic`, and opencode and pi none until their logins are checked on their pinned versions.
6038
+ */
6039
+ provider: "anthropic" | "openai";
6040
+ /** The model for this profile's turns, when it is not the block's `model`. */
6041
+ model?: string;
6042
+ /** A name for people (the console, the CLI, events). */
6043
+ label?: string;
6044
+ fallback?: AgentHarnessAuthFallback;
6045
+ }
6046
+ /**
6047
+ * A model the node's infer serves (`GET /v1/infer/models`), reached inside the instance with no key, at the
6048
+ * `base_url` the node gives the shim (`http://127.0.0.1:7700/v1/infer`). It adds `infer:run` to the instance's
6049
+ * grant, and infer bills its tokens to your organization. Only for a kind whose catalog entry has `auth.node:
6050
+ * true` (`422 harness_capability_unsupported` otherwise): today Codex and Claude Code.
6051
+ */
6052
+ export interface AgentHarnessAuthNode {
6053
+ type: "node";
6054
+ model: string;
6055
+ /** A name for people (the console, the CLI, events). */
6056
+ label?: string;
6057
+ fallback?: AgentHarnessAuthFallback;
6058
+ }
6059
+ /**
6060
+ * Whose API a `key` profile's credentials are for. Default: the connection's provider; the stored profile always
6061
+ * names it. Only a provider the kind's `auth.key` lists, with its hosts in `auth.hosts` (`422
6062
+ * harness_capability_unsupported` otherwise).
6063
+ */
6064
+ export type AgentHarnessKeyProvider = "anthropic" | "openai" | "bedrock" | "vertex" | "foundry" | "azure_openai" | "openrouter" | "openai_compatible" | "anthropic_compatible";
6065
+ /**
6066
+ * Where a conversation goes when this profile stops. The turn that stopped ends `harness.turn.failed`
6067
+ * (`error.code` `limit_reached` or `auth_required`), the shim marks the profile limited until its `resets_at`
6068
+ * (or until it checks again at the next turn) and sends `harness.auth.limited`, and the conversation moves to
6069
+ * `to` (`harness.auth.switched`). A chain follows each profile's own `fallback`. When every profile is limited,
6070
+ * the turn fails `no_profile_ready` with the earliest `resets_at`.
6071
+ */
6072
+ export interface AgentHarnessAuthFallback {
6073
+ to: AgentHarnessProfileName;
6074
+ /**
6075
+ * `limit`: a usage limit was reached or the credits ran out. `auth`: the credential was refused or expired.
6076
+ */
6077
+ on: Array<"limit" | "auth">;
6078
+ /**
6079
+ * `next_turn` (the default, chosen): the conversation's next turn runs on `to`. `continue`: the shim starts
6080
+ * one turn on `to` at once, with a fixed line ("Continue the task; the previous turn stopped at a usage
6081
+ * limit") and `source: fallback`. The prompt that stopped is never sent again, since its tools may have run.
6082
+ * @default "next_turn"
6083
+ */
6084
+ resume?: "next_turn" | "continue";
6085
+ }
6086
+ /**
6087
+ * A skill or a plugin, under its name in `skills` or `plugins`: exactly one source. `text`, `files` and `builtin`
6088
+ * are written when the instance starts. `git`, `npm` and `artifact` are fetched once, at prepare, into the
6089
+ * revision's prepared snapshot, and are pinned so a revision never changes under you: a git `ref` is resolved to a
6090
+ * `commit` when the definition is written, an npm `version` is exact (`422 harness_setup_unpinned` otherwise) and
6091
+ * its integrity is recorded, and an artifact is checked by its `sha256`.
6092
+ */
6093
+ export type AgentHarnessSetupItem = {
6094
+ /** A skill's one file, its `SKILL.md`. Not for a plugin. */
6095
+ text?: string;
6096
+ /** The item's files, each relative to the item's folder. */
6097
+ files?: AgentHarnessFile[];
6098
+ git?: AgentHarnessGitSource;
6099
+ npm?: AgentHarnessNpmSource;
6100
+ artifact?: AgentHarnessArtifactSource;
6101
+ /**
6102
+ * One of B3's own items, shipped in the `harness` template. `b3os` is the skill for B3OS's tools, and the
6103
+ * default entry of `skills`; only under the name `b3os`, and only in `skills`.
6104
+ */
6105
+ builtin?: "b3os";
6106
+ };
6107
+ /**
6108
+ * A folder of a public Git repository, fetched at prepare (the build has no access to your vault). Give `ref` or
6109
+ * `commit`: the node resolves a `ref` once, when the definition is written, and stores the `commit` beside it.
6110
+ * That lookup leaves from the node through the egress guard, as a webhook delivery does (private and loopback
6111
+ * addresses refused), and counts as your egress; a `ref` it cannot resolve is `400 invalid_request`, naming
6112
+ * the member, never quoting what the server answered.
6113
+ */
6114
+ export interface AgentHarnessGitSource {
6115
+ url: string;
6116
+ /** A branch or tag. */
6117
+ ref?: string;
6118
+ commit?: string;
6119
+ /** The item's folder in the repository. Default, its root. */
6120
+ path?: string;
6121
+ }
6122
+ /**
6123
+ * An npm package, installed at prepare with its install scripts off. `version` is an exact version; a range or
6124
+ * a tag is `422 harness_setup_unpinned`. The node records the package's `integrity` when the definition is
6125
+ * written, looking it up through the egress guard, and checks it at prepare.
6126
+ */
6127
+ export interface AgentHarnessNpmSource {
6128
+ package: string;
6129
+ version: string;
6130
+ /** The package's `sha512-` integrity, set by the node. */
6131
+ integrity?: string;
6132
+ }
6133
+ /**
6134
+ * A bundle of the item's folder in your project's artifact store, checked by `sha256` at prepare. Uploading one
6135
+ * needs a public artifact upload route, which is planned.
6136
+ */
6137
+ export interface AgentHarnessArtifactSource {
6138
+ id: string;
6139
+ sha256: string;
6140
+ }
6141
+ /**
6142
+ * The harness's own settings, under the block's own `kind` (another kind's key is `400 invalid_request`),
6143
+ * merged under the settings the shim writes when the instance starts: opencode's config, each profile's Codex
6144
+ * `config.toml`, pi's `settings.json`, Claude Code's `--settings` file. A key the shim owns (the kind's
6145
+ * `settings_refused`: its hooks, permissions, login method, providers, MCP servers, and the plugins and plugin
6146
+ * marketplaces it turns on) is `400 invalid_request`, naming the key, and so is an `env` entry (Claude Code's
6147
+ * `env`) named in `AgentHarnessPlanEnv`, like one of the kind's key variables or `B3OS_*`, and a plan's token in
6148
+ * any value. MCP servers go in `mcp` and plugins in `plugins`, where they are pinned and checked.
6149
+ */
6150
+ export interface AgentHarnessSettings {
6151
+ opencode?: Record<string, unknown>;
6152
+ codex?: Record<string, unknown>;
6153
+ pi?: Record<string, unknown>;
6154
+ "claude-code"?: Record<string, unknown>;
6155
+ }
6156
+ /** The repository cloned into the workspace at the instance's first start, before its first turn. */
6157
+ export interface AgentHarnessRepo {
6158
+ /** An `https://` Git URL. */
6159
+ url: string;
6160
+ /** The branch, tag or commit to check out. Default, the repository's default branch. */
6161
+ ref?: string;
6162
+ /**
6163
+ * A vault connection with a token for a private repository. The node delivers its secret as a
6164
+ * `B3OS_CONN_<N>` variable, and the harness's shim clones inside the instance and writes the token into the
6165
+ * instance's git credentials, so the harness can fetch and push with it and code in the instance can read
6166
+ * it; it needs `vault:run` and `vault:connections:reveal`. Refused with the rest of `repo` (`422
6167
+ * harness_capability_unsupported`) until the shim clones it.
6168
+ */
6169
+ connection?: string;
6170
+ }
6171
+ export interface AgentHarnessContext {
6172
+ at: "session_start" | "turn_start";
6173
+ text: string;
6174
+ }
6175
+ export interface AgentHarnessMcpRemote {
6176
+ /**
6177
+ * The server's `https://` URL (streamable HTTP or SSE). Reached through the instance's `egress`, which the
6178
+ * node fills with its host.
6179
+ */
6180
+ url: string;
6181
+ /**
6182
+ * A vault connection whose token the harness sends to this server as `Authorization: Bearer <token>`. The
6183
+ * node delivers its secret as a `B3OS_CONN_<N>` variable, and the shim writes the harness's MCP config to
6184
+ * send it (as a variable the config refers to, never the value: opencode's `{env:...}`, Claude Code's
6185
+ * `${...}`, Codex's `bearer_token_env_var`), so code in the instance can read it. It needs `vault:run` and
6186
+ * `vault:connections:reveal`, and a connection whose type has a credential field (`api_key`, `bearer` or
6187
+ * `oauth2`; another is `400 invalid_request`). A connection bound to `hosts` is `422
6188
+ * connection_host_bound` (B3OS adds such a credential only at the egress proxy, never inside a VM), and one
6189
+ * holding a plan's token is `400 harness_plan_credential`.
6190
+ */
6191
+ connection?: string;
6192
+ }
6193
+ /**
6194
+ * A server the harness starts in the instance, as the harness's user, over stdio. With `npm`, the package is
6195
+ * installed at prepare and its commands are on the server's `PATH`; until prepared snapshots ship that answers
6196
+ * `422 harness_setup_needs_prepare`.
6197
+ */
6198
+ export interface AgentHarnessMcpStdio {
6199
+ command: string[];
6200
+ npm?: AgentHarnessNpmSource;
6201
+ /**
6202
+ * The server's environment. A `{connection}` value is a vault connection's secret, delivered as a
6203
+ * `B3OS_CONN_<N>` variable and set in the server's environment by the shim, so code in the instance can read
6204
+ * it; it needs `vault:run` and `vault:connections:reveal`. `field` names the secret field, and is required
6205
+ * for a connection type with no credential field of its own (`400 invalid_request`). A connection bound to
6206
+ * `hosts` is `422 connection_host_bound`.
6207
+ */
6208
+ env?: Record<string, string | {
6209
+ connection: string;
6210
+ /** Which secret field of the connection, as a sandbox's `secrets` takes it. */
6211
+ field?: string;
6212
+ }>;
6213
+ }
6214
+ /**
6215
+ * B3OS's own MCP server inside the instance, at the instance's local address (`B3OS_MCP_URL`): the `mcp.b3os`
6216
+ * entry, and only that one. The default is `{builtin: b3os}` with all six toolsets; what you write under `b3os`
6217
+ * is merged into it as a JSON merge patch, so `{toolsets: [vision]}` narrows it and `builtin` need not be
6218
+ * restated. It brings the instance's B3OS MCP grant: the node fills `api` with the scopes the merged entry's
6219
+ * `toolsets` need, scoped to the instance, unless the definition sets `api` itself. A definition without this
6220
+ * entry gets no filled B3OS MCP scopes (only `infer:run` when it declares a `node` profile, and nothing
6221
+ * otherwise). The server lists the tools of each toolset this node serves, so a node without one lists fewer
6222
+ * tools.
6223
+ */
6224
+ export interface AgentHarnessMcpBuiltin {
6225
+ /** `b3os`: B3OS's own server, the default's; may be left out. */
6226
+ builtin?: "b3os";
6227
+ /**
6228
+ * Which of B3OS's tools the server lists, and so which scopes the filled grant holds. Default: all six.
6229
+ * `browser` (the `browser_*` tools; `vision:run` and `vision:write`), `vision` (web pages: `vision_scrape`
6230
+ * and the like; `vision:run`), `render` (screenshots and videos; `render:run`), `sandboxes` (code in
6231
+ * other sandboxes; `sandboxes:run`), `actions` (the pack actions the grant's actions rule allows;
6232
+ * `actions:read` and `actions:run`) and `infer` (the node's models; `infer:run`).
6233
+ */
6234
+ toolsets?: Array<"browser" | "vision" | "render" | "sandboxes" | "actions" | "infer">;
6235
+ }
6236
+ export interface AgentHarnessFile {
6237
+ /**
6238
+ * Relative to the workspace, or, in a skill's or plugin's `files`, to the item's folder. A path with a `..`
6239
+ * segment is `400 invalid_request`.
6240
+ */
6241
+ path: string;
6242
+ text: string;
6243
+ }
6244
+ /** Where the harness's events go beyond its session's stream, and who answers its questions. */
6245
+ export interface AgentHarnessHooks {
6246
+ webhook?: AgentHarnessWebhook;
6247
+ decide?: AgentHarnessDecide;
6248
+ /**
6249
+ * Add each event's native payload (`native.payload`: the harness's own hook or stream record), after the
6250
+ * redaction listeners use. Off by default, because a native payload can hold a tool's whole input.
6251
+ * @default false
6252
+ */
6253
+ include_native?: boolean;
6254
+ }
6255
+ /** An event type (`harness.turn.completed`), a family (`harness.turn.*`) or `*` for every type. */
6256
+ export type AgentHarnessEventPattern = string;
6257
+ /**
6258
+ * Where the agents product sends this agent's `harness.*` events, from every instance and every way a turn
6259
+ * came: each event `events` selects is a `POST` of a `WebhookEvent` (`agentsDeliverHarnessEvent`), signed with
6260
+ * `B3OS-Signature` and the URL's secret (`POST /v1/webhooks/secret`), retried with backoff for 24 hours, in
6261
+ * order per session. Delivery goes through the egress guard.
6262
+ */
6263
+ export interface AgentHarnessWebhook {
6264
+ /** An `https://` URL. */
6265
+ url: string;
6266
+ /**
6267
+ * Default: every type but `harness.message`, which carries each piece of streamed text as its own event; name
6268
+ * it, or `*`, to get it too.
6269
+ */
6270
+ events?: AgentHarnessEventPattern[];
6271
+ }
6272
+ /**
6273
+ * A webhook that answers the harness's questions while the turn waits (`agentsDecideHarnessEvent`): before a
6274
+ * tool runs (`harness.tool.requested`), when the harness asks for permission (`harness.permission.requested`),
6275
+ * or as a turn starts (`harness.turn.started`, to add context). The harness's shim hands each question to the
6276
+ * node (`POST /v1/agents/self/decide`), and the node makes the call: signed as a webhook delivery is, through
6277
+ * the egress guard (private and loopback addresses refused), so the URL's secret never enters the instance and
6278
+ * its host need not be in the instance's `egress`. The turn waits up to `timeout_ms` for `{decision: allow |
6279
+ * deny | ask, reason?, context?}`. It fails closed: no answer in time, a status other than 2xx, or a body
6280
+ * without a `decision` is `deny`, unless `on_timeout` is `allow`. `ask` hands the question to a person. The
6281
+ * definition's own rules come first, and in `permissions: plan` the webhook is never called: the harness's
6282
+ * read-only mode and the rules answer every question there.
6283
+ */
6284
+ export interface AgentHarnessDecide {
6285
+ /** An `https://` URL. */
6286
+ url: string;
6287
+ /** @default ["harness.tool.requested"] */
6288
+ events?: Array<"harness.tool.requested" | "harness.permission.requested" | "harness.turn.started">;
6289
+ /**
6290
+ * How long the turn waits for the answer.
6291
+ * @default 3000
6292
+ */
6293
+ timeout_ms?: number;
6294
+ /**
6295
+ * The decision when the webhook does not answer in time, fails, or answers without a decision.
6296
+ * @default "deny"
6297
+ */
6298
+ on_timeout?: "deny" | "allow";
6299
+ }
6300
+ export interface AgentHarnessTerminal {
6301
+ /**
6302
+ * Record the terminal as asciicast v3 files on the instance's disk (`…/terminal/recordings`). Off by default:
6303
+ * a recording keeps whatever the terminal showed, codes and keys printed in it included.
6304
+ * @default false
6305
+ */
6306
+ record?: boolean;
6307
+ }
6308
+ /**
6309
+ * The type of a harness event, the same for every harness. Each is what the instance reports about itself, not
6310
+ * something the node observed. What each carries in `data`:
6311
+ *
6312
+ * - `harness.session.started`: `native_session` (the harness's own session ID), `resumed`, `model`, `auth`
6313
+ * (`profile`, `type`, `provider`) and `withheld` (the names of the variables the shim kept from the harness,
6314
+ * never their values). `harness.session.ended`: `reason`.
6315
+ * - `harness.turn.started`: `source`, `profile`, `chars`, `prompt` (the first 4,000 characters). `source` is
6316
+ * where the turn came from, set from the message's `initiator` and never from its body: `api` (a key, a
6317
+ * person or a sandbox), `routine`, `listener`, `instance` (another agent instance), `terminal` (typed in the
6318
+ * terminal), `steer`, or `fallback` (the turn a profile's `fallback` with `resume: continue` starts).
6319
+ * - `harness.message`: `role`, `text`, `delta` (`true` while the text streams).
6320
+ * - `harness.tool.requested`: `tool`, `call_id`, `summary`, `parent` (the subagent's call, when one ran it).
6321
+ * `harness.tool.completed`: `tool`, `call_id`, `ok`, `duration_ms`.
6322
+ * - `harness.permission.requested`: `request` (the `dec_` ID `POST …/decisions` answers), `kind`, `tool`,
6323
+ * `summary`, `reason`. `harness.permission.resolved`: `request`, or `call_id` for a call the definition's
6324
+ * rules or `hooks.decide` answered without asking; `decision`, `by` (`rules`, `decide`, `person`, `timeout`
6325
+ * or `withdrawn`, when the turn ended first) and `reason`.
6326
+ * - `harness.subagent.started`: `agent_id`, `kind`, `model`. `harness.subagent.completed`: `agent_id`.
6327
+ * - `harness.compacted`: nothing.
6328
+ * - `harness.turn.completed`: `result`, `usage` (`AgentHarnessUsage`), `cost_usd` and `list_price_usd` (as on a
6329
+ * usage row), `timing` (`model_ms`, `tool_ms`, `wall_ms`), `steps` and `files` (the workspace paths the turn
6330
+ * changed, when the harness reports them). `harness.turn.failed`: `error` (`code`, `detail`; `limit_reached`,
6331
+ * `auth_required` and `no_profile_ready` carry `profile` and `resets_at` when known), `timing`, `usage`.
6332
+ * `harness.turn.interrupted`: `timing`, `usage`.
6333
+ * - `harness.terminal.attached` and `harness.terminal.detached`: `role`, `viewer`, `viewers` (how many remain).
6334
+ * - `harness.auth.required`: `profile`, `reason` (`signed_out`, `expired`, `refused` or `missing`), `detail`.
6335
+ * - `harness.auth.ready`: `profile`, `type`, `provider` and `plan` (what the harness says it is signed in as,
6336
+ * when it says).
6337
+ * - `harness.auth.limited`: `profile`, `limit` (`usage`, `credits` or `rate`), `resets_at` and `used_percent`
6338
+ * when the harness reports them, `detail`.
6339
+ * - `harness.auth.switched`: `from`, `to`, `why` (`requested` or `fallback`), `billed_to`.
6340
+ * - `harness.auth.removed`: `profile`, `cli`, `reason`: `signed_out` (the owner signed out), or
6341
+ * `signin_not_personal` (a harness's credential file where no sign-in belongs, removed without being read).
6342
+ */
6343
+ export type AgentHarnessEventType = "harness.session.started" | "harness.session.ended" | "harness.turn.started" | "harness.message" | "harness.tool.requested" | "harness.tool.completed" | "harness.permission.requested" | "harness.permission.resolved" | "harness.subagent.started" | "harness.subagent.completed" | "harness.compacted" | "harness.turn.completed" | "harness.turn.failed" | "harness.turn.interrupted" | "harness.terminal.attached" | "harness.terminal.detached" | "harness.auth.required" | "harness.auth.ready" | "harness.auth.limited" | "harness.auth.switched" | "harness.auth.removed";
6344
+ /** A turn's token use, one row per model, as the harness reported it. */
6345
+ export interface AgentHarnessUsage {
6346
+ models: AgentHarnessUsageRow[];
6347
+ [key: string]: unknown;
6348
+ }
6349
+ /**
6350
+ * One model's tokens in a turn, and who pays for them. `cost_usd` is there only when `billed_to` is `key` or
6351
+ * `node`; for a plan's turn, the figure the harness reports goes in `list_price_usd`, so a sum of `cost_usd`
6352
+ * never counts a plan's turns as spend.
6353
+ */
6354
+ export interface AgentHarnessUsageRow {
6355
+ model: string;
6356
+ input: number;
6357
+ cacheRead: number;
6358
+ cacheWrite: number;
6359
+ output: number;
6360
+ reasoning?: number;
6361
+ profile: AgentHarnessProfileName;
6362
+ /** `key`: the key's owner, through the provider. `plan`: a person's plan. `node`: infer on the node. */
6363
+ billed_to: "key" | "plan" | "node";
6364
+ /** What the harness or infer reports this row cost, for `key` and `node` only. */
6365
+ cost_usd?: number;
6366
+ /** For `plan` only, what the harness reports the tokens would cost at list price; not a charge. */
6367
+ list_price_usd?: number;
6368
+ }
6369
+ /**
6370
+ * One event of a harness, in the product-event envelope (ARCHITECTURE 4.12). The harness's shim writes `id`,
6371
+ * `type`, `time`, `harness`, `conversation`, `data` and `native`. The node sets `seq`, `org`, `project`,
6372
+ * `instance` and, for an event of a delivered turn, `session_id` and `subject` (from the session) as it writes
6373
+ * the event to the instance's log, replacing whatever the shim sent on a delivery's answer. The shim numbers
6374
+ * the events of its own streams too, but that number orders them only within one run of the shim and starts
6375
+ * again when the shim restarts; a self event carries none (`AgentSelfEvent`).
6376
+ */
6377
+ export interface AgentHarnessEvent {
6378
+ /** Unique per event; deduplicate on it. */
6379
+ id: string;
6380
+ /**
6381
+ * The event's place in its instance's event log, set by the node and growing across restarts of the
6382
+ * harness's shim. The SSE `id` of `GET …/stream`.
6383
+ */
6384
+ seq: number;
6385
+ type: AgentHarnessEventType;
6386
+ time: string;
6387
+ harness: AgentHarnessKindName;
6388
+ org?: string;
6389
+ project?: string;
6390
+ instance?: string;
6391
+ /** The agent session, for an event of a turn sent as a message. */
6392
+ session_id?: string;
6393
+ /** The harness session the event belongs to (the message's `conversation`). */
6394
+ conversation?: string;
6395
+ /** The end user the turn is for, for an event of a delivered turn (the session's `subject`). */
6396
+ subject?: string;
6397
+ /** What happened; `AgentHarnessEventType` lists the members of each type. */
6398
+ data: {
6399
+ usage?: AgentHarnessUsage;
6400
+ [key: string]: unknown;
6401
+ };
6402
+ /** The harness event this one came from. `payload` only with `hooks.include_native`. */
6403
+ native?: {
6404
+ harness: AgentHarnessKindName;
6405
+ event: string;
6406
+ payload?: unknown;
6407
+ };
6408
+ }
6409
+ /**
6410
+ * One harness this node runs, as its driver declares it (`b3os-harness catalog --json`, printed by the shim
6411
+ * and served as printed). A feature not yet checked against the kind's pinned version is left out, and a
6412
+ * definition that uses it is refused.
6413
+ */
6414
+ export interface AgentHarnessKind {
6415
+ object: "harness_kind";
6416
+ kind: AgentHarnessKindName;
6417
+ /** The harness's own name. */
6418
+ name: string;
6419
+ /**
6420
+ * `native`: a driver built into the shim and reviewed by B3. `acp`: the generic Agent Client Protocol
6421
+ * adapter, which runs the harness as its own process over stdio.
6422
+ */
6423
+ driver: "native" | "acp";
6424
+ /** The versions this node runs, newest first. */
6425
+ versions: string[];
6426
+ /** What a definition without `version` gets. */
6427
+ default_version: string;
6428
+ modes: Array<"api" | "terminal">;
6429
+ capabilities: AgentHarnessCapabilities;
6430
+ auth: AgentHarnessKindAuth;
6431
+ /** The lists of the `harness` block this kind takes; another is `422 harness_capability_unsupported`. */
6432
+ setup: Array<"skills" | "plugins" | "mcp" | "instructions" | "settings">;
6433
+ /**
6434
+ * The kind's own settings keys the shim owns (its hooks, permissions, login method, providers, MCP servers,
6435
+ * and the plugins and marketplaces it turns on), which a definition's `settings` may not set (`400
6436
+ * invalid_request`).
6437
+ */
6438
+ settings_refused: string[];
6439
+ /**
6440
+ * The environment variables this kind reads a plan's token from. No harness agent's `env` or `secrets` sets
6441
+ * these, or any other kind's (`400 invalid_request`).
6442
+ */
6443
+ plan_env: AgentHarnessPlanEnv[];
6444
+ }
6445
+ /** What the kind's driver delivers; the shim's conformance test checks each one it declares. */
6446
+ export interface AgentHarnessCapabilities {
6447
+ /** A running turn takes more text (`POST …/steer`). */
6448
+ steer: boolean;
6449
+ /** A running turn stops with its usage so far, and the harness session stays open. */
6450
+ interrupt: boolean;
6451
+ /** A conversation continues its harness session after the shim or the instance restarts. */
6452
+ resume: boolean;
6453
+ /**
6454
+ * Which tool calls the shim sees before they run, and so which `hooks.decide` on `harness.tool.requested`
6455
+ * answers: `every_tool`, `asked` (only the calls the harness asks permission for), or `partial` (some calls
6456
+ * run without asking, such as Codex's read-only commands).
6457
+ */
6458
+ tool_gate: "every_tool" | "asked" | "partial";
6459
+ /**
6460
+ * The `mode`s in which `hooks.decide` answers. A definition with `hooks.decide` in another mode is `422
6461
+ * harness_capability_unsupported`, but in `permissions: plan`, where the webhook is never called. opencode
6462
+ * lists `api` only: in `terminal` its TUI answers permission prompts itself.
6463
+ */
6464
+ decide_modes: Array<"api" | "terminal">;
6465
+ /** Turns report their tokens per model. */
6466
+ usage: boolean;
6467
+ /** The harness's subagents show as `harness.subagent.*` events. */
6468
+ subagent_events: boolean;
6469
+ }
6470
+ /** The credential profiles the kind takes (`AgentHarnessAuthProfile`). */
6471
+ export interface AgentHarnessKindAuth {
6472
+ /** Each `key` provider the kind takes, with the environment variables a profile of it sets. */
6473
+ key: Record<string, string[]>;
6474
+ /**
6475
+ * The plans a person may sign in to in a `signin` profile; empty when the kind takes none. `anthropic`
6476
+ * also needs `agents.claude_plan_signin`.
6477
+ */
6478
+ signin: Array<"anthropic" | "openai">;
6479
+ /** A `node` profile (a model the node's infer serves) works with this kind. */
6480
+ node: boolean;
6481
+ /**
6482
+ * The hosts a profile of each provider reaches from the instance at the kind's pinned version, measured on
6483
+ * the pin with the kind's own switches for the CLI's other traffic set (telemetry, update checks, a plugin
6484
+ * sync). The node puts them in the filled `egress` and checks your own `egress` against them
6485
+ * (`AgentHarness`).
6486
+ * - `key`: what a turn on each `auth.key` provider reaches: its model API, and a model catalog the kind
6487
+ * fetches for it. A `*_compatible` provider lists none; its `base_url` host stands for them.
6488
+ * - `signin`: each `auth.signin` provider's login, token and model API hosts.
6489
+ *
6490
+ * Exact hosts or `*.` wildcards. A `{region}` label is filled from the profile's `region`, which a profile
6491
+ * of that provider then needs (`400 invalid_request` without one). A profile whose provider is not listed
6492
+ * here is refused (`422 harness_capability_unsupported`).
6493
+ */
6494
+ hosts: {
6495
+ key: Record<string, string[]>;
6496
+ signin: Record<string, string[]>;
6497
+ };
6498
+ }
6499
+ /**
6500
+ * An environment variable a harness reads a plan's token from, or that changes where it signs in:
6501
+ * `CLAUDE_CODE_OAUTH_TOKEN` and `CLAUDE_CODE_OAUTH_REFRESH_TOKEN` (Claude Code 2.1.332; `claude auth login`
6502
+ * signs in from the refresh token);
6503
+ * Claude Code 2.1.332's session and bridge tokens (`CLAUDE_CODE_SESSIONS_OAUTH_TOKEN`, `CLAUDE_BRIDGE_OAUTH_TOKEN`,
6504
+ * `CLAUDE_CODE_SESSION_ACCESS_TOKEN`), the forms that read a token from a descriptor or a file, which a value
6505
+ * check cannot see (`CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR`, `CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR`,
6506
+ * `CLAUDE_SESSION_INGRESS_TOKEN_FILE`, `CLAUDE_CODE_HOST_CREDS_FILE`), an account credential
6507
+ * (`CLAUDE_TRUSTED_DEVICE_TOKEN`) and the OAuth endpoint overrides (`CLAUDE_CODE_CUSTOM_OAUTH_URL`,
6508
+ * `CLAUDE_LOCAL_OAUTH_API_BASE`, `USE_LOCAL_OAUTH`, `USE_STAGING_OAUTH`), all read from the binary's strings;
6509
+ * `ANTHROPIC_OAUTH_TOKEN` (pi), and `CODEX_ACCESS_TOKEN` (Codex 0.164.0: `codex login --with-access-token`
6510
+ * reads an access token from it; refused until it is checked whether that token is a ChatGPT plan's). An agent
6511
+ * with a `harness` block never takes one of these names in `env` or `secrets`, in an `mcp` server's `env`, or
6512
+ * in a `settings` `env` entry, whatever its `kind`, since the `harness` template holds every harness: `400
6513
+ * invalid_request`. Names alone do not hold the line, because pi sends any Anthropic key whose value holds
6514
+ * `sk-ant-oat` as a plan login: a value holding `sk-ant-oat` or `sk-ant-ort` is `400 harness_plan_credential`
6515
+ * anywhere in the definition and in the resolved value of every connection it names (`AgentHarness`), and the
6516
+ * shim drops every variable whose value holds one from the harness's environment and the terminal's. B3OS
6517
+ * never stores a plan's token.
6518
+ */
6519
+ export type AgentHarnessPlanEnv = "CLAUDE_CODE_OAUTH_TOKEN" | "CLAUDE_CODE_OAUTH_REFRESH_TOKEN" | "ANTHROPIC_OAUTH_TOKEN" | "CODEX_ACCESS_TOKEN" | "CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR" | "CLAUDE_CODE_SESSIONS_OAUTH_TOKEN" | "CLAUDE_BRIDGE_OAUTH_TOKEN" | "CLAUDE_CODE_SESSION_ACCESS_TOKEN" | "CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR" | "CLAUDE_SESSION_INGRESS_TOKEN_FILE" | "CLAUDE_CODE_HOST_CREDS_FILE" | "CLAUDE_TRUSTED_DEVICE_TOKEN" | "CLAUDE_CODE_CUSTOM_OAUTH_URL" | "CLAUDE_LOCAL_OAUTH_API_BASE" | "USE_LOCAL_OAUTH" | "USE_STAGING_OAUTH";
6520
+ /**
6521
+ * The catalog as the shim prints it (`b3os-harness catalog --json`): the kinds in `data`, open-source first,
6522
+ * and `checks`. The node stores it with the `harness` template's build and serves it unchanged.
6523
+ */
6524
+ export type AgentHarnessKindList = Omit<ListEnvelope, "data"> & {
6525
+ data: AgentHarnessKind[];
6526
+ checks: AgentHarnessCatalogChecks;
6527
+ };
6528
+ /**
6529
+ * What the shim refuses or removes at start beyond each kind's entry, so the node refuses the same at write:
6530
+ * per kind (`kinds`), the rules for profile names, the plan-token names and value, the workspace paths `files`
6531
+ * may not write, the default `mcp` and `skills` entries, each B3OS toolset's scopes and the flag each gated
6532
+ * sign-in needs.
6533
+ */
6534
+ export interface AgentHarnessCatalogChecks {
6535
+ kinds: Record<string, AgentHarnessKindChecks>;
6536
+ profiles: {
6537
+ /** The most profiles a definition holds. */
6538
+ max: number;
6539
+ /** The pattern a profile's name matches (an ECMAScript regular expression). */
6540
+ name: string;
6541
+ };
6542
+ /** Every kind's plan variables, refused as names on every harness agent. */
6543
+ plan_env: AgentHarnessPlanEnv[];
6544
+ /** The pattern of a plan's token, refused as a value anywhere (an ECMAScript regular expression). */
6545
+ plan_value: string;
6546
+ /** Workspace paths (a file, or a directory ending in `/`) no definition's `files` writes. */
6547
+ files_refused: string[];
6548
+ /**
6549
+ * The entries every definition's `mcp` and `skills` start with. A definition's maps are a JSON merge patch
6550
+ * (RFC 7396) over them (`AgentHarness`); a kind whose `setup` does not list a list gets none.
6551
+ */
6552
+ defaults: {
6553
+ mcp: Record<string, AgentHarnessMcpBuiltin>;
6554
+ skills: Record<string, AgentHarnessSetupItem>;
6555
+ };
6556
+ /** Each B3OS toolset's scopes; the filled grant is the merged `mcp.b3os` entry's toolsets' scopes. */
6557
+ b3os_toolsets: Record<string, string[]>;
6558
+ /** The flag a sign-in to each listed provider needs; a provider not listed, and every key, needs none. */
6559
+ signin_flags: Record<string, string>;
6560
+ }
6561
+ /** What the shim enforces for one kind beyond its catalog entry. */
6562
+ export interface AgentHarnessKindChecks {
6563
+ /**
6564
+ * Per `key` provider, the variables the node delivers as `B3OS_PROFILE_<NAME>__<VAR>`; the `optional` ones
6565
+ * may be left out (`AWS_SESSION_TOKEN`).
6566
+ */
6567
+ deliver: Record<string, {
6568
+ env: string[];
6569
+ optional: string[];
6570
+ }>;
6571
+ /** The providers whose profile needs an `https://` `base_url`; any other provider's refuses one. */
6572
+ base_url: AgentHarnessKeyProvider[];
6573
+ /** The providers whose profile takes a `region`. */
6574
+ region: AgentHarnessKeyProvider[];
6575
+ /**
6576
+ * Every variable the shim sets or removes in the kind's processes; a definition's `env` or `secrets` naming one is refused.
6577
+ */
6578
+ env_owned: string[];
6579
+ /** The CLI's config-directory variable, which the shim sets to each profile's directory. */
6580
+ dir_env: string;
6581
+ /** Lists the kind takes only from a prepared snapshot; refused until prepared snapshots ship. */
6582
+ prepare_only: Array<"skills" | "plugins" | "mcp" | "instructions" | "settings">;
6583
+ /**
6584
+ * For a kind that has one, the only keys its `settings.<kind>` takes, checked on its pinned version; any other
6585
+ * key is refused, as is any in its `settings_refused`. Absent: every key not refused is taken.
6586
+ */
6587
+ settings_allowed?: string[];
6588
+ /**
6589
+ * When true, a definition with more than one `key` profile gives each one a model on the profile's own
6590
+ * provider (the profile's `model`, else the block's); one that has none is refused at write. The kind runs
6591
+ * every key profile in one process, each on its own model (opencode), so such a profile would run nothing.
6592
+ */
6593
+ key_profiles_need_model?: boolean;
6594
+ /** The limit and auth signals the driver reads from the CLI. */
6595
+ signals: Record<string, "limit" | "auth">;
6596
+ /** The signals seen live on the kind's pinned version; only these move a profile's `fallback`. */
6597
+ checked: string[];
6598
+ }
6599
+ export interface AgentSteerRequest {
6600
+ /** What the harness reads at its next step. Yours, so never quoted. */
6601
+ text: string;
6602
+ }
6603
+ export interface AgentDecisionRequest {
6604
+ /** The `request` of the `harness.permission.requested` event, unique per instance. */
6605
+ request: string;
6606
+ decision: "allow" | "deny";
6607
+ /** Shown to the harness with the decision. */
6608
+ reason?: string;
6609
+ }
6610
+ export interface AgentDecision {
6611
+ object: "agent_decision";
6612
+ instance_id: string;
6613
+ /**
6614
+ * The session whose turn asked, or `null` for a turn that is not a session (typed in the terminal or
6615
+ * started inside the instance).
6616
+ */
6617
+ session_id: string | null;
6618
+ request: string;
6619
+ decision: "allow" | "deny";
6620
+ reason: string | null;
6621
+ by: AgentSessionInitiator;
6622
+ decided_at: string;
6623
+ }
6624
+ /**
6625
+ * `watch`: the live view and the terminal, view-only. `control`: also input, when nobody else holds it.
6626
+ */
6627
+ export type AgentGrantRole = "watch" | "control";
6628
+ export interface AgentGrantCreateRequest {
6629
+ /** @default "watch" */
6630
+ role?: AgentGrantRole;
6631
+ /**
6632
+ * How long the link works. Chosen for the beta.
6633
+ * @default 900
6634
+ */
6635
+ ttl_s?: number;
6636
+ /**
6637
+ * How many times the link may be redeemed: each page load is one, and so is each reconnect of its terminal
6638
+ * or event stream. Default, any number until it expires.
6639
+ */
6640
+ uses?: number;
6641
+ }
6642
+ export interface AgentGrant {
6643
+ id: string;
6644
+ object: "agent_grant";
6645
+ agent_id: string;
6646
+ key: AgentInstanceKey;
6647
+ role: AgentGrantRole;
6648
+ /** The grant's secret, in the create answer only (`null` everywhere else). Treat it as a password. */
6649
+ token: string | null;
6650
+ /** The share page with the token in its fragment, in the create answer only. */
6651
+ url: string | null;
6652
+ expires_at: string;
6653
+ uses: number | null;
6654
+ uses_left: number | null;
6655
+ created_by: AgentSessionInitiator;
6656
+ created_at: string;
6657
+ }
6658
+ export type AgentGrantList = Omit<ListEnvelope, "data"> & {
6659
+ data: AgentGrant[];
6660
+ };
6661
+ export interface AgentTerminalRecording {
6662
+ id: string;
6663
+ object: "terminal_recording";
6664
+ /** The harness session whose terminal it recorded. */
6665
+ conversation: string;
6666
+ format: "asciicast-v3";
6667
+ bytes: number;
6668
+ started_at: string;
6669
+ /** The last write; a recording still being written keeps growing. */
6670
+ updated_at: string;
6671
+ }
6672
+ export type AgentTerminalRecordingList = Omit<ListEnvelope, "data"> & {
6673
+ data: AgentTerminalRecording[];
6674
+ };
6675
+ export interface AgentSelfEventsRequest {
6676
+ events: AgentSelfEvent[];
6677
+ }
6678
+ /**
6679
+ * A harness event as the shim records it from inside the instance: an `AgentHarnessEvent` without the members
6680
+ * the node sets (`seq`, `org`, `project`, `instance`, `session_id`, `subject`), which a self event never
6681
+ * carries (`400 invalid_request`): the node assigns the log's `seq` as it writes the event.
6682
+ */
6683
+ export interface AgentSelfEvent {
6684
+ id: string;
6685
+ type: AgentHarnessEventType;
6686
+ time: string;
6687
+ harness: AgentHarnessKindName;
6688
+ conversation?: string;
6689
+ data: {
6690
+ usage?: AgentHarnessUsage;
6691
+ [key: string]: unknown;
6692
+ };
6693
+ native?: {
6694
+ harness: AgentHarnessKindName;
6695
+ event: string;
6696
+ payload?: unknown;
6697
+ };
6698
+ }
6699
+ /** A question for the definition's `hooks.decide` webhook, from the harness's shim. */
6700
+ export interface AgentSelfDecideRequest {
6701
+ type: "harness.tool.requested" | "harness.permission.requested" | "harness.turn.started";
6702
+ /**
6703
+ * The session the turn was delivered as (the delivery's `session`), when the question belongs to one. The
6704
+ * node keeps it only when it is the session the instance runs now.
6705
+ */
6706
+ session?: string;
6707
+ conversation?: string;
6708
+ /** `tool`, `input` (the tool's arguments), `summary` and `call_id`; a turn's `prompt`. */
6709
+ data: Record<string, unknown>;
6710
+ }
6711
+ export interface AgentSelfDecision {
6712
+ object: "agent_self_decision";
6713
+ /** `ask` hands the question to a person (`harness.permission.requested`). */
6714
+ decision: "allow" | "deny" | "ask";
6715
+ reason?: string;
6716
+ /** Added to what the model sees next, quoted as information. */
6717
+ context?: string;
6718
+ /**
6719
+ * `true` when the webhook did not answer in time, failed or answered without a `decision`, and `decision` is
6720
+ * the definition's `on_timeout`.
6721
+ */
6722
+ fallback: boolean;
6723
+ }
6724
+ export interface AgentSelfEventsResult {
6725
+ object: "agent_self_events";
6726
+ accepted: number;
6727
+ /** Events whose `id` the instance had already recorded; not written again. */
6728
+ duplicates: number;
6729
+ }
6730
+ /** Set exactly one of `entry` (your own harness) and `harness` (a coding agent B3OS runs for you). */
6731
+ export type AgentCreateRequest = {
6732
+ name: AgentName;
6733
+ source?: AgentSource;
6734
+ entry?: AgentEntry;
6735
+ harness?: AgentHarness;
6736
+ /** Environment variables of the harness. Returned as given; put credentials in `secrets`. */
6737
+ env?: Record<string, string>;
6738
+ /**
6739
+ * Environment variables never returned or logged, as a sandbox's `secrets`: code in the instance can read
6740
+ * them. A memory snapshot holds them, so the node keeps an instance's snapshots to itself: they are never
6741
+ * listed or restorable through the API.
6742
+ */
6743
+ secrets?: Record<string, SecretValue>;
6744
+ api?: SandboxApiGrant;
6745
+ egress?: EgressPolicy;
6746
+ sleep?: AgentSleep;
6747
+ turns?: AgentTurns;
6748
+ metadata?: Metadata;
6749
+ };
6750
+ /** `entry` and `harness` never come together, and an agent keeps the one it was made with. */
6751
+ export interface AgentUpdateRequest {
6752
+ source?: AgentSource;
6753
+ entry?: AgentEntry;
6754
+ harness?: AgentHarness;
6755
+ env?: Record<string, string>;
6756
+ secrets?: Record<string, SecretValue>;
6757
+ api?: SandboxApiGrant;
6758
+ egress?: EgressPolicy;
6759
+ sleep?: AgentSleep;
6760
+ turns?: AgentTurns;
6761
+ /**
6762
+ * What happens to instances of earlier revisions: `new_instances` leaves them as they are; `on_wake` makes a
6763
+ * sleeping one again from this revision at its next wake, which ends its memory and disk.
6764
+ * @default "new_instances"
6765
+ */
6766
+ upgrade?: "new_instances" | "on_wake";
6767
+ metadata?: Metadata;
6768
+ }
6769
+ export interface Agent {
6770
+ id: string;
6771
+ object: "agent";
5111
6772
  name: AgentName;
5112
6773
  /** Grows by one with each update. Each instance keeps the revision it was made from. */
5113
6774
  revision: number;
@@ -5119,6 +6780,31 @@ export interface Agent {
5119
6780
  egress: EgressPolicy;
5120
6781
  sleep: AgentSleep;
5121
6782
  turns: AgentTurns;
6783
+ /**
6784
+ * Only on an agent made with a `harness` block (planned), as the node stored it: defaults filled in,
6785
+ * shorthands expanded, git refs resolved to commits, and `mcp` and `skills` as you wrote them, nulls
6786
+ * included, never merged with their default `b3os` entries (`AgentHarness`), so the block can be sent back
6787
+ * as it is.
6788
+ */
6789
+ harness?: AgentHarness;
6790
+ /**
6791
+ * The person a personal agent belongs to, or `null`. An agent with a `signin` profile is personal (planned):
6792
+ * its owner is the person who made it, and it never changes. Everything that drives it or reads what its
6793
+ * instances hold is the owner's alone, and so is changing it: messages, steer, cancel, decisions, making,
6794
+ * waking and putting to sleep its instances (an instance may also put itself to sleep from inside), its
6795
+ * sessions (read, listed or streamed: their results and `session.output` carry the turns), and its
6796
+ * instances' stream, terminal, tickets, grants and recordings. Anyone else, an organization admin included,
6797
+ * gets `403 harness_personal_agent`. The owner or an organization admin may delete it or one of its
6798
+ * instances, and list or revoke its grants. Every `agents:read` caller still sees the definition and each
6799
+ * instance's status and lifecycle events (`GET …/instances`, `GET …/instances/{key}/events`), which hold no
6800
+ * turn. Listeners never send it turns, and routines only when the owner made them. The owner shares a view with a `watch` grant;
6801
+ * `control` grants are refused. Forks and children of it run only on `key` and `node` profiles (`409
6802
+ * harness_profile_unavailable`), and nothing it signed in to is carried to another instance. Not served
6803
+ * yet: until the prerequisites `AgentHarnessAuthSignin` names land, the node makes no personal agent, so
6804
+ * `owner` is `null` on every agent.
6805
+ */
6806
+ owner?: null | AgentOwner;
6807
+ harness_prepared?: AgentHarnessPrepared;
5122
6808
  upgrade: "new_instances" | "on_wake";
5123
6809
  /** How many instances the agent has, in any state. */
5124
6810
  instances: number;
@@ -5126,6 +6812,33 @@ export interface Agent {
5126
6812
  updated_at: string;
5127
6813
  metadata: Metadata;
5128
6814
  }
6815
+ export interface AgentOwner {
6816
+ kind: "user";
6817
+ id: string;
6818
+ }
6819
+ /**
6820
+ * The revision's prepared snapshot (planned): the `harness` template with only this kind's harness at its
6821
+ * `version` and the recipe's fetched items installed, built once per `key` and shared by the project's agents
6822
+ * with the same key. The build runs in a `builder` sandbox with no secrets and no vault access, reaching only
6823
+ * the recipe's source hosts, and fails if any harness credential file exists in it. Messages wait while it
6824
+ * builds, and that time counts toward `turns.timeout_s`; a failed build fails them with
6825
+ * `harness_prepare_failed`. `upgrade: on_wake` moves instances only to a revision whose snapshot is `ready`.
6826
+ * It counts against your snapshot quota.
6827
+ */
6828
+ export interface AgentHarnessPrepared {
6829
+ /**
6830
+ * The prepare key: the SHA-256 of the template's ID and revision, the shim's version, the `kind`, the
6831
+ * `version` and the resolved sources of the fetched items. A change elsewhere in the block keeps it.
6832
+ */
6833
+ key: string;
6834
+ /** `none`: nothing is built for this revision yet. */
6835
+ status: "none" | "queued" | "building" | "ready" | "failed";
6836
+ /** The snapshot instances start from, once `ready`; also the filled `source.snapshot`. */
6837
+ snapshot: string | null;
6838
+ built_at: string | null;
6839
+ /** Why the last build failed, naming the step and the item. */
6840
+ error: null | Problem;
6841
+ }
5129
6842
  export type AgentList = Omit<ListEnvelope, "data"> & {
5130
6843
  data: Agent[];
5131
6844
  };
@@ -5159,7 +6872,10 @@ export interface AgentInstance {
5159
6872
  key: AgentInstanceKey;
5160
6873
  revision: number;
5161
6874
  status: AgentInstanceStatus;
5162
- /** The instance's microVM, the same through every sleep tier; `null` before it was first made. */
6875
+ /**
6876
+ * The instance's microVM, the same through every sleep tier; `null` before it was first made. `null` too for
6877
+ * an instance of a personal agent (planned), whose microVM the generic sandboxes API does not reach.
6878
+ */
5163
6879
  sandbox_id: string | null;
5164
6880
  /** Host memory the instance holds now (0 when hibernated or dormant). */
5165
6881
  resident_mib: number;
@@ -5200,6 +6916,16 @@ export type AgentInstanceEventList = Omit<ListEnvelope, "data"> & {
5200
6916
  /**
5201
6917
  * Your message. Every member but the reserved ones (`type`, `conversation`, `subject`, `metadata`, `create`,
5202
6918
  * `webhook`) is yours, and reaches the harness as `message`, with `type`.
6919
+ *
6920
+ * A message to an agent with a `harness` block (planned) is closed instead. Besides the reserved members it takes
6921
+ * `text` (the prompt, a string of 1 to 262,144 characters, required), `context` (at most 16 `{text, source?}`
6922
+ * objects, each quoted as information), `profile` (one of the definition's credential profiles) and, from a
6923
+ * listener's actor sink (`type: listener.event`), `event`, quoted whole, in place of `text`. Any other member is
6924
+ * `400 invalid_request`, so a field the harness would not read is refused, not dropped. A listener's message
6925
+ * is `422 harness_capability_unsupported` until the harness's shim quotes its `event`.
6926
+ * `source`, `limits` and `parent` are reserved there for the run contract.
6927
+ * These members bind harness agents only: an agent with an `entry` keeps every member but the reserved ones as
6928
+ * its own.
5203
6929
  */
5204
6930
  export interface AgentMessageRequest {
5205
6931
  /**
@@ -5249,6 +6975,8 @@ export type AgentSessionList = Omit<ListEnvelope, "data"> & {
5249
6975
  };
5250
6976
  /**
5251
6977
  * `session.waking` carries `woke_from`; `session.output` carries `data`, one event the harness streamed, as text.
6978
+ * For an agent with a `harness` block (planned), each `session.output`'s `data` is one `AgentHarnessEvent` as
6979
+ * JSON, as the node wrote it to the instance's event log (its `seq` is the log's, not this stream's).
5252
6980
  */
5253
6981
  export type AgentSessionEvent = JobEvent & {
5254
6982
  woke_from?: AgentWokeFrom;
@@ -5283,7 +7011,7 @@ export interface RoutineDefinition {
5283
7011
  */
5284
7012
  vars?: Record<string, unknown>;
5285
7013
  /**
5286
- * 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').
7014
+ * 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').
5287
7015
  */
5288
7016
  triggers?: RoutineDefinitionTrigger[];
5289
7017
  defaults?: {
@@ -5484,15 +7212,19 @@ export type RoutineDefinitionCatchUp = "skip" | "latest" | "all";
5484
7212
  */
5485
7213
  export type RoutineDefinitionOverlap = "skip" | "buffer_one" | "allow" | "cancel_running";
5486
7214
  /**
5487
- * 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}.
7215
+ * 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}.
5488
7216
  */
5489
7217
  export type RoutineDefinitionTrigger = {
5490
- type: "cron" | "interval" | "webhook" | "action";
7218
+ type: "cron" | "interval" | "webhook" | "action" | "listener";
5491
7219
  id: RoutineDefinitionIdent;
5492
7220
  /** action only: the pack trigger to subscribe to. */
5493
7221
  uses?: RoutineDefinitionTriggerRef;
5494
7222
  /**
5495
- * 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.
7223
+ * listener only: an object declares the routine's own listener (listenerTrigger); a string names a listener that already exists in the project (listenerRef).
7224
+ */
7225
+ listener?: RoutineDefinitionListenerTrigger | RoutineDefinitionListenerRef;
7226
+ /**
7227
+ * 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.
5496
7228
  */
5497
7229
  with?: RoutineDefinitionTemplateObject;
5498
7230
  /**
@@ -5500,7 +7232,7 @@ export type RoutineDefinitionTrigger = {
5500
7232
  */
5501
7233
  connections?: Record<string, RoutineDefinitionConnectionRef>;
5502
7234
  /**
5503
- * 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.
7235
+ * 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.
5504
7236
  */
5505
7237
  if?: RoutineDefinitionCondition;
5506
7238
  /**
@@ -5529,6 +7261,29 @@ export type RoutineDefinitionTrigger = {
5529
7261
  */
5530
7262
  dedupe?: RoutineDefinitionCelExpression;
5531
7263
  };
7264
+ /**
7265
+ * 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).
7266
+ */
7267
+ export interface RoutineDefinitionListenerTrigger {
7268
+ /** listeners.yaml ListenerSource: push, http_poll, sse, websocket, webhook or pack. */
7269
+ source: {
7270
+ type: "push" | "http_poll" | "sse" | "websocket" | "webhook" | "pack";
7271
+ };
7272
+ /** listeners.yaml ListenerDedupe. */
7273
+ dedupe?: Record<string, unknown>;
7274
+ /**
7275
+ * listeners.yaml ListenerFilter: a CEL filter over the event, or a model filter, applied before the event is kept.
7276
+ */
7277
+ filter?: Record<string, unknown>;
7278
+ /** listeners.yaml ListenerRedact: JSON pointers removed from each payload before it is kept. */
7279
+ redact?: string[];
7280
+ /** listeners.yaml ListenerBudgetRequest. */
7281
+ budget?: Record<string, unknown>;
7282
+ }
7283
+ /**
7284
+ * 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.
7285
+ */
7286
+ export type RoutineDefinitionListenerRef = string;
5532
7287
  /**
5533
7288
  * 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.
5534
7289
  */
@@ -5577,7 +7332,7 @@ export interface RoutineHook {
5577
7332
  export interface RoutineTrigger {
5578
7333
  /** The trigger's `id` in the definition. */
5579
7334
  id: string;
5580
- type: "cron" | "interval" | "webhook" | "action";
7335
+ type: "cron" | "interval" | "webhook" | "action" | "listener";
5581
7336
  status: "active" | "paused";
5582
7337
  /** Next scheduled fire (cron and interval), or `null`. */
5583
7338
  next_fire_at: string | null;
@@ -5587,6 +7342,10 @@ export interface RoutineTrigger {
5587
7342
  * The trigger subscription of an action trigger (`GET /v1/actions/subscriptions/{subscription_id}`), or `null`.
5588
7343
  */
5589
7344
  subscription_id: string | null;
7345
+ /**
7346
+ * 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`).
7347
+ */
7348
+ listener_id: string | null;
5590
7349
  }
5591
7350
  export interface Routine {
5592
7351
  id: string;
@@ -5610,7 +7369,7 @@ export interface Routine {
5610
7369
  updated_at: string;
5611
7370
  metadata: Metadata;
5612
7371
  /**
5613
- * 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.
7372
+ * 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.
5614
7373
  */
5615
7374
  warnings?: Diagnostic[];
5616
7375
  }
@@ -5714,9 +7473,13 @@ export interface HookSecret {
5714
7473
  }
5715
7474
  /** How the run started (the `trigger` context of its expressions). */
5716
7475
  export interface RunTrigger {
5717
- type: "api" | "cron" | "interval" | "webhook" | "action" | "routine" | "replay";
5718
- /** The trigger ID (cron, interval, webhook, action). */
7476
+ type: "api" | "cron" | "interval" | "webhook" | "action" | "listener" | "routine" | "replay";
7477
+ /**
7478
+ * The trigger ID (cron, interval, webhook, action, and listener triggers), or the listener (`lsn_`) of a listener whose sink names the routine.
7479
+ */
5719
7480
  id?: string;
7481
+ /** The listener that delivered the event (listener triggers). */
7482
+ listener_id?: string;
5720
7483
  /** Cron and interval occurrence, used to deduplicate fires. */
5721
7484
  occurrence_id?: string;
5722
7485
  scheduled_at?: string;
@@ -5724,8 +7487,12 @@ export interface RunTrigger {
5724
7487
  delivery_id?: string;
5725
7488
  /** The trigger subscription that delivered the event (action triggers). */
5726
7489
  subscription_id?: string;
5727
- /** The pack trigger event's ID (action triggers). */
7490
+ /** The pack trigger event's ID (action triggers), or the listener event's (`evt_`, listeners). */
5728
7491
  event_id?: string;
7492
+ /**
7493
+ * 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.
7494
+ */
7495
+ trace_id?: string;
5729
7496
  /** For sub-routine runs, the calling run; for replays, the source run. */
5730
7497
  parent_run_id?: string;
5731
7498
  parent_step_id?: string;
@@ -6136,8 +7903,8 @@ export interface RoutineSink {
6136
7903
  routine: string;
6137
7904
  /**
6138
7905
  * `run` starts a run of the routine's active version per event, with `trigger = {type: listener, id,
6139
- * event_id, seq, dedupe_key, received_at, payload}`; a redelivery of the same `dedupe_key` starts no
6140
- * second run. `event` sends the event to the routine's runs waiting with `wait: {event: <event>}`
7906
+ * event_id, seq, dedupe_key, received_at, payload, trace_id}`; a redelivery of the same `dedupe_key`
7907
+ * starts no second run. `event` sends the event to the routine's runs waiting with `wait: {event: <event>}`
6141
7908
  * (`routinesSendEvent`), with `data` = the payload.
6142
7909
  * @default "run"
6143
7910
  */
@@ -6155,6 +7922,25 @@ export interface RoutineSink {
6155
7922
  */
6156
7923
  retry_for_s?: number;
6157
7924
  batch?: ListenerBatch;
7925
+ /**
7926
+ * Set by routines on the listener of a routine's `type: listener` trigger: that trigger's ID. Routines
7927
+ * creates the listener when it publishes the version, as the publishing key, and removes it when a version
7928
+ * without the trigger is published or the routine is deleted. Each event starts a run with the trigger's
7929
+ * `if` and `with`, and `trigger = {type: listener, id: <trigger id>, listener_id, ...}`. Such a listener is
7930
+ * read-only here: PATCH and DELETE answer `409 listener_managed`. A request cannot set it. With `bound`,
7931
+ * the trigger names this listener instead (preview, `routines.named_listeners`): the listener is yours, and
7932
+ * only its sink is held.
7933
+ */
7934
+ trigger?: string;
7935
+ /**
7936
+ * True while a routine's `type: listener` trigger names this listener (by id or name) and its active
7937
+ * version is published: routines set `routine` and `trigger` when it bound the listener, keeping
7938
+ * `concurrency`, `retry_for_s` and `batch`. Every field but `sink` can still change; a PATCH of `sink`
7939
+ * answers `409 listener_bound`. A version without the trigger, or deleting the routine, clears it and
7940
+ * pauses the listener (`status_reason: routine_unbound`). While the routine is paused, deliveries are
7941
+ * retried until `retry_for_s`, then fail `routine_paused`. A request cannot set it.
7942
+ */
7943
+ bound?: boolean;
6158
7944
  }
6159
7945
  export interface WebhookSink {
6160
7946
  type: "webhook";
@@ -6228,7 +8014,7 @@ export interface Listener {
6228
8014
  object: "listener";
6229
8015
  name: string | null;
6230
8016
  status: ListenerStatus;
6231
- status_reason: "user" | "budget" | "auth" | "egress_denied" | "source_errors" | "owner_revoked" | "sandbox_ended" | null;
8017
+ status_reason: "user" | "budget" | "auth" | "egress_denied" | "source_errors" | "owner_revoked" | "sandbox_ended" | "routine_unbound" | null;
6232
8018
  /** Why the source last failed, or why the listener ended `failed`. */
6233
8019
  error: {
6234
8020
  code: string;
@@ -6272,6 +8058,10 @@ export interface Listener {
6272
8058
  failed: number;
6273
8059
  skipped: number;
6274
8060
  reconnects: number;
8061
+ /**
8062
+ * 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`.
8063
+ */
8064
+ retries?: number;
6275
8065
  last_event_at: string | null;
6276
8066
  };
6277
8067
  created_at: string;
@@ -6396,6 +8186,198 @@ export interface ListenerTestResult {
6396
8186
  /** With `deliver: true` and a kept event, the event as written to the log. */
6397
8187
  event: ListenerEvent | null;
6398
8188
  }
8189
+ /**
8190
+ * One path rule. `path` is gitignore-style (`*` within a name, `**` across directories) and may use `{human}`,
8191
+ * `{initiator}` and `{agent}`, which bind to that principal's ID. `read` and `write` list selectors:
8192
+ * `agent:<id or name>`, `user:usr_…`, `role:owner|admin|member`, `subject:<id>`, `key:key_…`, `routine:rtn_…`,
8193
+ * `listener:lsn_…`, the bare roles `agent`, `human` and `initiator`, and `project`. A null list leaves that side
8194
+ * to the rules before it.
8195
+ */
8196
+ export interface WorkspaceRule {
8197
+ path: string;
8198
+ read?: string[] | null;
8199
+ write?: string[] | null;
8200
+ /**
8201
+ * A commit may only add bytes at the end of a matching file.
8202
+ * @default false
8203
+ */
8204
+ append_only?: boolean;
8205
+ }
8206
+ export interface WorkspaceCreateRequest {
8207
+ /** Unique in the project. */
8208
+ name: string;
8209
+ rules?: WorkspaceRule[];
8210
+ metadata?: Metadata;
8211
+ }
8212
+ export interface WorkspaceRulesRequest {
8213
+ rules: WorkspaceRule[];
8214
+ }
8215
+ export interface Workspace {
8216
+ id: string;
8217
+ object: "workspace";
8218
+ name: string;
8219
+ status: "active" | "deleted";
8220
+ default_branch: string;
8221
+ /** The head commit of the default branch; null before the first commit. */
8222
+ head: string | null;
8223
+ rules: WorkspaceRule[];
8224
+ usage: {
8225
+ /** Unique content bytes stored, the unit of `workspaces.storage_gib_h`. */
8226
+ bytes: number;
8227
+ /** Files at the head of the default branch. */
8228
+ files: number;
8229
+ commits: number;
8230
+ open_branches: number;
8231
+ };
8232
+ created_at: string;
8233
+ updated_at: string;
8234
+ metadata: Metadata;
8235
+ }
8236
+ export type WorkspaceList = Omit<ListEnvelope, "data"> & {
8237
+ data: Workspace[];
8238
+ };
8239
+ export type BranchStatus = "open" | "merged" | "closed" | "expired";
8240
+ export interface BranchCreateRequest {
8241
+ /**
8242
+ * A branch name or ID, or a commit ID, to start from.
8243
+ * @default "main"
8244
+ */
8245
+ from?: string;
8246
+ /** Unique among the workspace's open branches. Without one the branch is ephemeral. */
8247
+ name?: string;
8248
+ /** An ephemeral branch's lifetime; 604,800 (7 days) by default. */
8249
+ ttl_s?: number;
8250
+ metadata?: Metadata;
8251
+ }
8252
+ export type PrincipalRef = {
8253
+ kind: "agent" | "routine" | "key" | "user" | "subject" | "sandbox" | "instance" | "routine_run" | "listener";
8254
+ id: string;
8255
+ } | null;
8256
+ export interface Branch {
8257
+ id: string;
8258
+ object: "branch";
8259
+ workspace: string;
8260
+ name: string;
8261
+ kind: "named" | "ephemeral";
8262
+ /** Merging into it needs `workspaces:write` (`main` is protected). */
8263
+ protected: boolean;
8264
+ status: BranchStatus;
8265
+ /** The commit the branch started from; null for a branch of an empty workspace. */
8266
+ base: string | null;
8267
+ head: string | null;
8268
+ holder: PrincipalRef;
8269
+ expires_at: string | null;
8270
+ created_at: string;
8271
+ metadata: Metadata;
8272
+ }
8273
+ export type BranchList = Omit<ListEnvelope, "data"> & {
8274
+ data: Branch[];
8275
+ };
8276
+ /** One file to write (`content` as UTF-8 text or `content_base64` as bytes) or to delete. */
8277
+ export interface CommitFile {
8278
+ /** Absolute in the workspace (`/notes/today.md`); no `..`, no empty segment. */
8279
+ path: string;
8280
+ content?: string;
8281
+ content_base64?: string;
8282
+ /**
8283
+ * A regular file, an executable, or a symlink whose content is its target.
8284
+ * @default "100644"
8285
+ */
8286
+ mode?: "100644" | "100755" | "120000";
8287
+ delete?: boolean;
8288
+ }
8289
+ export interface CommitRequest {
8290
+ message: string;
8291
+ /**
8292
+ * The files to write or delete. Required, except from inside the sandbox that holds the branch (its
8293
+ * `workspaces` member on create): there, without `files`, the commit is what the sandbox changed under the
8294
+ * branch's path.
8295
+ */
8296
+ files?: CommitFile[];
8297
+ /**
8298
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
8299
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
8300
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
8301
+ */
8302
+ subject?: string;
8303
+ if_head?: string;
8304
+ }
8305
+ export interface Commit {
8306
+ id: string;
8307
+ object: "commit";
8308
+ workspace: string;
8309
+ /** The branch it was made on. */
8310
+ branch: string;
8311
+ parents: string[];
8312
+ /** The git tree ID of its content. */
8313
+ tree: string;
8314
+ /** Its git commit ID, the same after a push to a git remote. */
8315
+ git_sha: string;
8316
+ message: string;
8317
+ principals: {
8318
+ agent: PrincipalRef;
8319
+ human: PrincipalRef;
8320
+ initiator: PrincipalRef;
8321
+ };
8322
+ stats: {
8323
+ files_changed: number;
8324
+ /** New content bytes the commit stored. */
8325
+ bytes: number;
8326
+ };
8327
+ created_at: string;
8328
+ }
8329
+ export type CommitList = Omit<ListEnvelope, "data"> & {
8330
+ data: Commit[];
8331
+ };
8332
+ export interface MergeRequest {
8333
+ /**
8334
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
8335
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
8336
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
8337
+ */
8338
+ subject?: string;
8339
+ /**
8340
+ * The target branch, by name or ID.
8341
+ * @default "main"
8342
+ */
8343
+ into?: string;
8344
+ /** @default "three_way" */
8345
+ mode?: "three_way" | "paths";
8346
+ /** Merge only while the target's head is this commit. */
8347
+ if_head?: string;
8348
+ message?: string;
8349
+ }
8350
+ export interface MergeResult {
8351
+ object: "workspace_merge";
8352
+ into: string;
8353
+ /** The target had not moved since the branch's base, so its head became the branch's head. */
8354
+ fast_forward: boolean;
8355
+ commit: Commit;
8356
+ }
8357
+ export interface WorkspaceDiff {
8358
+ object: "workspace_diff";
8359
+ base: string;
8360
+ head: string;
8361
+ changes: {
8362
+ path: string;
8363
+ kind: "added" | "modified" | "deleted" | "type_changed";
8364
+ old_size: number | null;
8365
+ new_size: number | null;
8366
+ }[];
8367
+ /** More than 10,000 changes; narrow it with `path`. */
8368
+ truncated: boolean;
8369
+ }
8370
+ export interface WorkspaceEntry {
8371
+ path: string;
8372
+ type: "file" | "dir" | "symlink";
8373
+ size: number | null;
8374
+ mode: string;
8375
+ /** The git blob ID; null for a directory. */
8376
+ blob: string | null;
8377
+ }
8378
+ export type WorkspaceEntryList = Omit<ListEnvelope, "data"> & {
8379
+ data: WorkspaceEntry[];
8380
+ };
6399
8381
  /**
6400
8382
  * One JSON-RPC 2.0 message of the Model Context Protocol (https://modelcontextprotocol.io): a request
6401
8383
  * (`method` and `id`), a notification (`method`, no `id`) or a response (`result` or `error`). Methods served:
@@ -8600,8 +10582,10 @@ export interface ToolBlock {
8600
10582
  export type ToolBlockList = Omit<ListEnvelope, "data"> & {
8601
10583
  data: ToolBlock[];
8602
10584
  };
8603
- /** An option's value; for an enum option, one of its values (`x-b3os-options`). */
8604
- export type SettingValue = string | number | boolean;
10585
+ /**
10586
+ * 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.
10587
+ */
10588
+ export type SettingValue = string | number | boolean | Record<string, unknown> | null;
8605
10589
  export interface SettingRequest {
8606
10590
  value: SettingValue;
8607
10591
  }
@@ -8716,6 +10700,14 @@ export interface RequestRecord {
8716
10700
  phases: RequestPhase[];
8717
10701
  /** The W3C trace ID from `traceparent`, when sent. */
8718
10702
  trace_id: string | null;
10703
+ /**
10704
+ * The span id the node gave this request (with `traceparent` sent): the parent id in the `traceparent` its
10705
+ * handler passes on, so a request it made (an MCP product tool's) names it in `parent_span_id`. Absent from
10706
+ * records written before node release 1127 and from requests the edge answered itself.
10707
+ */
10708
+ span_id?: string | null;
10709
+ /** The span id in the `traceparent` the request arrived with (its caller's span), when sent. */
10710
+ parent_span_id?: string | null;
8719
10711
  user_agent: string | null;
8720
10712
  source: RequestSource;
8721
10713
  action?: RequestAction;
@@ -9019,6 +11011,16 @@ export interface VisionListCrawlPagesParams {
9019
11011
  /** Only pages that succeeded, or only pages that failed. */
9020
11012
  status?: "succeeded" | "failed";
9021
11013
  }
11014
+ /** Parameters of `listIdentities`. */
11015
+ export interface VisionListIdentitiesParams {
11016
+ /**
11017
+ * Page size, from 1 to 100.
11018
+ * @default 20
11019
+ */
11020
+ limit?: number;
11021
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11022
+ cursor?: string;
11023
+ }
9022
11024
  /** Parameters of `listProfiles`. */
9023
11025
  export interface VisionListProfilesParams {
9024
11026
  /**
@@ -9180,6 +11182,18 @@ export interface SandboxesListSandboxesParams {
9180
11182
  */
9181
11183
  metadata?: Record<string, string>;
9182
11184
  }
11185
+ /** Parameters of `getCapacity`. */
11186
+ export interface SandboxesGetCapacityParams {
11187
+ /**
11188
+ * Template name or `tpl_` ID.
11189
+ * @default "desktop"
11190
+ */
11191
+ template?: string;
11192
+ /** vCPUs of each sandbox; the template's default when left out. */
11193
+ vcpu?: number;
11194
+ /** Memory of each sandbox, MiB; the template's default when left out. */
11195
+ memory_mib?: number;
11196
+ }
9183
11197
  /** Parameters of `listSnapshots`. */
9184
11198
  export interface SandboxesListSnapshotsParams {
9185
11199
  /**
@@ -9238,6 +11252,16 @@ export interface SandboxesListVolumesParams {
9238
11252
  /** Only volumes in this status. */
9239
11253
  status?: "available" | "attached" | "deleted";
9240
11254
  }
11255
+ /** Parameters of `computerScreenshot`. */
11256
+ export interface SandboxesComputerScreenshotParams {
11257
+ /** `png` or `jpeg`. Without it: the image type `Accept` names, else `jpeg`. */
11258
+ format?: "png" | "jpeg";
11259
+ /**
11260
+ * JPEG quality, 1 to 100.
11261
+ * @default 80
11262
+ */
11263
+ quality?: number;
11264
+ }
9241
11265
  /** Parameters of `deleteFile`. */
9242
11266
  export interface SandboxesDeleteFileParams {
9243
11267
  /** Absolute path inside the sandbox. */
@@ -9332,6 +11356,19 @@ export interface ImagesGetImageParams {
9332
11356
  */
9333
11357
  wait?: number;
9334
11358
  }
11359
+ /** Parameters of `getImageLogs`. */
11360
+ export interface ImagesGetImageLogsParams {
11361
+ /**
11362
+ * The first line to answer (0 is the first).
11363
+ * @default 0
11364
+ */
11365
+ offset?: number;
11366
+ /**
11367
+ * Hold the answer up to this many seconds until there are lines past `offset` or the image settles.
11368
+ * @default 0
11369
+ */
11370
+ wait?: number;
11371
+ }
9335
11372
  /** Parameters of `listAgents`. */
9336
11373
  export interface AgentsListAgentsParams {
9337
11374
  /**
@@ -9364,6 +11401,50 @@ export interface AgentsListInstanceEventsParams {
9364
11401
  /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
9365
11402
  cursor?: string;
9366
11403
  }
11404
+ /** Parameters of `listGrants`. */
11405
+ export interface AgentsListGrantsParams {
11406
+ /**
11407
+ * Page size, from 1 to 100.
11408
+ * @default 20
11409
+ */
11410
+ limit?: number;
11411
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11412
+ cursor?: string;
11413
+ }
11414
+ /** Parameters of `openTerminal`. */
11415
+ export interface AgentsOpenTerminalParams {
11416
+ /**
11417
+ * `view` (the default) or `control`, which also needs `agents:run`.
11418
+ * @default "view"
11419
+ */
11420
+ role?: "view" | "control";
11421
+ /** The byte offset to resume from, with `session`. Without it the socket starts at the current screen. */
11422
+ cursor?: number;
11423
+ /** The terminal (`pts_…`) the `cursor` belongs to, from the session frame of the socket you resume. */
11424
+ session?: string;
11425
+ /** Which harness session's terminal, when the instance has more than one. Default `default`. */
11426
+ conversation?: string;
11427
+ /**
11428
+ * `main` (the default): the harness's terminal. `signin:<profile>` and `signout:<profile>`: the sign-in
11429
+ * and sign-out windows for one of the definition's `signin` profiles, for a personal agent's owner only.
11430
+ * @default "main"
11431
+ */
11432
+ window?: string;
11433
+ /** The controller's width; ignored for a viewer. */
11434
+ cols?: number;
11435
+ /** The controller's height; ignored for a viewer. */
11436
+ rows?: number;
11437
+ }
11438
+ /** Parameters of `listRecordings`. */
11439
+ export interface AgentsListRecordingsParams {
11440
+ /**
11441
+ * Page size, from 1 to 100.
11442
+ * @default 20
11443
+ */
11444
+ limit?: number;
11445
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11446
+ cursor?: string;
11447
+ }
9367
11448
  /** Parameters of `listSessions`. */
9368
11449
  export interface AgentsListSessionsParams {
9369
11450
  /**
@@ -9461,6 +11542,83 @@ export interface ListenersListEventsParams {
9461
11542
  /** Only events in this status. */
9462
11543
  status?: ListenerEventStatus;
9463
11544
  }
11545
+ /** Parameters of `listWorkspaces`. */
11546
+ export interface WorkspacesListWorkspacesParams {
11547
+ /**
11548
+ * Page size, from 1 to 100.
11549
+ * @default 20
11550
+ */
11551
+ limit?: number;
11552
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11553
+ cursor?: string;
11554
+ }
11555
+ /** Parameters of `listBranches`. */
11556
+ export interface WorkspacesListBranchesParams {
11557
+ /**
11558
+ * Page size, from 1 to 100.
11559
+ * @default 20
11560
+ */
11561
+ limit?: number;
11562
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11563
+ cursor?: string;
11564
+ /** Only the branch with this name. */
11565
+ name?: string;
11566
+ /** Only branches in this status. */
11567
+ status?: BranchStatus;
11568
+ }
11569
+ /** Parameters of `listCommits`. */
11570
+ export interface WorkspacesListCommitsParams {
11571
+ /**
11572
+ * Page size, from 1 to 100.
11573
+ * @default 20
11574
+ */
11575
+ limit?: number;
11576
+ /** Opaque cursor from the previous page's `next_cursor`. Omit it for the first page. */
11577
+ cursor?: string;
11578
+ /** The branch whose history to list (`br_…`); `main` when absent. */
11579
+ branch_id?: string;
11580
+ }
11581
+ /** Parameters of `diff`. */
11582
+ export interface WorkspacesDiffParams {
11583
+ /**
11584
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
11585
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
11586
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
11587
+ */
11588
+ subject?: string;
11589
+ /** A commit ID (`cmt_…`) or a branch name. */
11590
+ base: string;
11591
+ /** A commit ID (`cmt_…`) or a branch name. */
11592
+ head: string;
11593
+ /** Only paths under this directory. */
11594
+ path?: string;
11595
+ }
11596
+ /** Parameters of `listFiles`. */
11597
+ export interface WorkspacesListFilesParams {
11598
+ /**
11599
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
11600
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
11601
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
11602
+ */
11603
+ subject?: string;
11604
+ /** A commit ID (`cmt_…`) or a branch name; `main` when absent. */
11605
+ ref?: string;
11606
+ /** The directory or file, absolute in the workspace; `/` when absent. */
11607
+ path?: string;
11608
+ }
11609
+ /** Parameters of `readFile`. */
11610
+ export interface WorkspacesReadFileParams {
11611
+ /**
11612
+ * The end user this call works for: the `human` principal the workspace's rules check. Only a credential holding
11613
+ * `workspaces:subjects:assert` may name one (`403 forbidden`, reason `scope`), never a sandbox's own credential
11614
+ * (reason `sandbox`). 1 to 200 letters, digits or `._:@-`.
11615
+ */
11616
+ subject?: string;
11617
+ /** A commit ID (`cmt_…`) or a branch name; `main` when absent. */
11618
+ ref?: string;
11619
+ /** The file, absolute in the workspace. */
11620
+ path: string;
11621
+ }
9464
11622
  /** Parameters of `describe`. */
9465
11623
  export interface ActionsDescribeParams {
9466
11624
  /** `<namespace>/<name>/<action>@<version>`; the version may be exact (`1.0.0`) or a major (`1`). */