@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
@@ -3,14 +3,20 @@ import { Namespace } from "../../core/namespace.ts";
3
3
  import type { Op } from "../../core/op.ts";
4
4
  import type { APIPromise, JobPromise, ListPromise } from "../../core/promise.ts";
5
5
  import type { EventStream } from "../../core/sse.ts";
6
+ import { PtySession } from "../../core/ws.ts";
6
7
  import type * as T from "../types.ts";
7
8
  /** Descriptors of every agents operation, keyed by method name (for tooling and custom clients). */
8
9
  export declare const agentsOps: {
9
10
  readonly listAgents: Op;
10
11
  readonly createAgent: Op;
12
+ readonly listHarnesses: Op;
13
+ readonly requestSelfDecision: Op;
14
+ readonly recordSelfEvents: Op;
11
15
  readonly getSession: Op;
12
16
  readonly cancelSession: Op;
17
+ readonly sendDecision: Op;
13
18
  readonly streamSession: Op;
19
+ readonly steerSession: Op;
14
20
  readonly deleteAgent: Op;
15
21
  readonly getAgent: Op;
16
22
  readonly updateAgent: Op;
@@ -18,9 +24,18 @@ export declare const agentsOps: {
18
24
  readonly deleteInstance: Op;
19
25
  readonly getInstance: Op;
20
26
  readonly putInstance: Op;
27
+ readonly sendInstanceDecision: Op;
21
28
  readonly listInstanceEvents: Op;
29
+ readonly listGrants: Op;
30
+ readonly createGrant: Op;
31
+ readonly deleteGrant: Op;
22
32
  readonly sendMessage: Op;
23
33
  readonly sleepInstance: Op;
34
+ readonly streamInstance: Op;
35
+ readonly openTerminal: Op;
36
+ readonly listRecordings: Op;
37
+ readonly getRecording: Op;
38
+ readonly createTicket: Op;
24
39
  readonly listSessions: Op;
25
40
  };
26
41
  /**
@@ -49,16 +64,117 @@ export declare class AgentsAPI extends Namespace {
49
64
  * disk, never its definition. Instances belong to the project: revoking the key that created the agent does
50
65
  * not stop them.
51
66
  *
67
+ * Set `harness` instead of `entry` to run a coding agent people already use (opencode, the default; Codex; pi;
68
+ * Claude Code), unmodified (`AgentHarness`; planned, not served on the beta node yet). The node checks the
69
+ * block against the kind's entry in `GET /v1/agents/harnesses`, then fills `entry`, `source.template`, each
70
+ * `key` profile's credentials in `secrets` (as `B3OS_PROFILE_<NAME>__<VAR>`), and `api`, `egress` and
71
+ * `turns.timeout_s` where you leave them out. A request with both `entry` and `harness`, or neither, is `400
72
+ * invalid_request`. Until they are served on this node, `repo`, `context` and `acp` are refused even when
73
+ * empty, and so is every vault connection outside a credential profile (`repo.connection`, a remote `mcp`
74
+ * server's `connection`, a stdio server's `{connection}` values): `422 harness_capability_unsupported`.
75
+ *
76
+ * An agent with a `signin` profile in `harness.auth` is personal: its `owner` is the person who creates it,
77
+ * from their own dashboard session or CLI token (an API key, a sandbox or an instance gets `403
78
+ * harness_personal_agent`), and it never changes. A ChatGPT plan's sign-in (`provider: openai`) needs no flag.
79
+ * A Claude plan's (`provider: anthropic`) needs the `agents.claude_plan_signin` flag (`403
80
+ * harness_claude_plan_signin_disabled` without it). The node knows no person yet, so until the prerequisites
81
+ * `AgentHarnessAuthSignin` names land, every `signin` profile is `403 harness_personal_agent`.
82
+ *
52
83
  * `POST /v1/agents` · scope `agents:write` · served by the node
53
84
  */
54
85
  createAgent(body: T.AgentCreateRequest, options?: RequestOptions): APIPromise<T.Agent>;
86
+ /**
87
+ * List the harnesses this node runs
88
+ *
89
+ * The harnesses a `harness` block may name (`kind`), the open-source ones first (opencode, the default `kind`,
90
+ * then Codex and pi; Claude Code last), each with the versions this node runs, newest first, and the one a
91
+ * definition without `version` gets. A version is pinned in the node's `harness` template; a new
92
+ * upstream release becomes a new template revision and a new entry here, and a definition moves to it only when
93
+ * a `PATCH` changes its `version`.
94
+ *
95
+ * This answer is the catalog the harness's shim prints (`b3os-harness catalog --json`), stored with the
96
+ * `harness` template's build and served as it was printed, nothing added or left out: the shim's drivers are
97
+ * the source of truth for what each kind takes, and the node checks definitions against this answer. Each entry
98
+ * in `data` is what the kind's driver declares about itself: `driver` (`native`, built into the shim, or `acp`,
99
+ * the generic Agent Client Protocol adapter), `capabilities`, the credential profiles the kind takes (`auth`:
100
+ * the `key` providers with the variables each sets, the `signin` providers, and whether a model the node serves
101
+ * works), the lists of the block it takes (`setup`), and the `settings` keys the shim owns
102
+ * (`settings_refused`). `plan_env` names the variables no harness agent may set (`AgentHarnessPlanEnv`).
103
+ * `checks` is what the node and the shim refuse beyond each entry (`AgentHarnessCatalogChecks`), among them the
104
+ * default `mcp` and `skills` entries every definition's maps merge over (`checks.defaults`), so a client can
105
+ * check a recipe, and show its merged lists, before it deploys it. A feature not yet checked against a kind's
106
+ * pinned version is left out, and a definition that uses it is refused (`422 harness_capability_unsupported`).
107
+ * A definition that moves to a new version builds that revision's prepared snapshot again, at most
108
+ * `agents.prepare_concurrent` builds of an organization at once (planned, with prepared snapshots).
109
+ * Planned: not served on the beta node yet.
110
+ *
111
+ * `GET /v1/agents/harnesses` · scope `agents:read` · served by the node
112
+ *
113
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
114
+ */
115
+ listHarnesses(options?: RequestOptions): APIPromise<T.AgentHarnessKindList>;
116
+ /**
117
+ * Ask the decide webhook from inside an instance
118
+ *
119
+ * How the harness's shim asks the definition's `hooks.decide` webhook a question while the turn waits, from
120
+ * inside the instance at `http://127.0.0.1:7700`. The node makes the call (`agentsDecideHarnessEvent`): it sets
121
+ * `harness`, `instance` and, when `session` is the session the instance runs now, `session_id` and `subject`
122
+ * from that session (any other `session` is dropped); it signs the call with `B3OS-Signature` and the URL's
123
+ * secret, sends it through the egress guard (private and loopback addresses refused), and answers with the
124
+ * decision. So the secret never enters the instance, and the decide host need not be in the instance's
125
+ * `egress`.
126
+ *
127
+ * The node applies the fail-closed rule itself and answers within `timeout_ms` (at most 10 seconds) plus its
128
+ * own overhead: no answer in time, a status other than 2xx, or a body without a `decision` answers
129
+ * `hooks.decide.on_timeout` (`deny` unless the definition sets `allow`) with `fallback: true`. The shim treats
130
+ * any answer other than `200`, and no answer, as `deny`. A question the definition does not send to the
131
+ * webhook is `400 invalid_request`: an agent without `hooks.decide`, a `type` its `events` does not select, and
132
+ * any question in `permissions: plan`, where the webhook is never called.
133
+ *
134
+ * Bound to the caller's own credential as `POST /v1/agents/self/events` is: the instance is the one whose
135
+ * token calls, and any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
136
+ * An instance asks at most `agents.self_decide_rate` questions a minute; past it the answer is `429
137
+ * rate_limited`, which the shim takes as `deny`, as it takes any answer but `200`. Planned: not served on the
138
+ * beta node yet.
139
+ *
140
+ * `POST /v1/agents/self/decide` · scope `authenticated` · served by the node
141
+ *
142
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
143
+ */
144
+ requestSelfDecision(body: T.AgentSelfDecideRequest, options?: RequestOptions): APIPromise<T.AgentSelfDecision>;
145
+ /**
146
+ * Record harness events from inside an instance
147
+ *
148
+ * How the harness's shim records `harness.*` events that happened outside a delivered turn (a turn typed in the
149
+ * terminal or started inside the instance), from inside the instance at `http://127.0.0.1:7700`. The node writes them to the
150
+ * calling instance's event stream (`GET /v1/agents/{agent}/instances/{key}/stream`) and sends the ones the
151
+ * definition's `hooks.webhook` selects. Events of a delivered turn reach the session's stream as
152
+ * `session.output` instead and are not sent here.
153
+ *
154
+ * The route is bound to the caller's own credential: the node takes the instance from the token of the VM that
155
+ * calls. Each event is an `AgentSelfEvent`, which has none of the members the node owns: the node sets
156
+ * `instance`, `org` and `project` itself and assigns the log's own `seq`. An event with `seq`, `instance`,
157
+ * `org`, `project`, `session_id` or `subject` is `400 invalid_request`, and so is one whose `harness` is not the
158
+ * definition's kind; the whole request is refused and nothing in it is written. A self event never belongs to a
159
+ * session: the node never takes one as a session's result or as the answer to a question. No instance can write
160
+ * another's events. Any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
161
+ * An event whose `id` the instance already recorded is counted in `duplicates` and not written again. An
162
+ * instance records at most `agents.self_events_rate` events a minute; past it the request is `429
163
+ * rate_limited` with `Retry-After` and nothing in it is written. Planned: not served on the beta node yet.
164
+ *
165
+ * `POST /v1/agents/self/events` · scope `authenticated` · served by the node
166
+ *
167
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
168
+ */
169
+ recordSelfEvents(body: T.AgentSelfEventsRequest, options?: RequestOptions): APIPromise<T.AgentSelfEventsResult>;
55
170
  /**
56
171
  * Get an agent session
57
172
  *
58
173
  * One turn: its status and phase, who sent it (`initiator`), its conversation, how its instance woke
59
174
  * (`woke_from`), its trace and its timing. The message and the harness's answer are kept only for a session that
60
175
  * was answered `202` (so you can read the result here, for 24 hours) or when the project's
61
- * `platform.capture_content` setting is on. Sessions are kept 30 days after they end.
176
+ * `platform.capture_content` setting is on. Sessions are kept 30 days after they end. A session of a personal
177
+ * agent (`Agent.owner`, planned) is read only by the agent's owner (`403 harness_personal_agent`).
62
178
  *
63
179
  * `GET /v1/agents/sessions/{session_id}` · scope `agents:read` · served by the node
64
180
  */
@@ -67,11 +183,46 @@ export declare class AgentsAPI extends Namespace {
67
183
  * Cancel an agent session
68
184
  *
69
185
  * Cancels a turn. A queued session leaves the queue and is never delivered. A delivered one has its request into
70
- * the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged.
186
+ * the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged. For
187
+ * an agent with a `harness` block (planned), the node first asks the harness to interrupt the turn (opencode's
188
+ * session interrupt, Codex's `turn/interrupt`, pi's `abort`, Claude Code's `interrupt`), so the turn ends
189
+ * `harness.turn.interrupted` with its usage so far, and the harness session stays open for the next turn. The
190
+ * harness's shim also stops the turn when the node closes the delivery, so a cancel that arrives before the
191
+ * harness has started the turn still stops it. On a personal agent only the owner cancels (`403
192
+ * harness_personal_agent`).
71
193
  *
72
194
  * `POST /v1/agents/sessions/{session_id}/cancel` · scope `agents:run` · served by the node
73
195
  */
74
196
  cancelSession(sessionId: string, options?: RequestOptions): APIPromise<T.AgentSession>;
197
+ /**
198
+ * Answer a harness's permission request
199
+ *
200
+ * Answers a question the turn waits on: a `harness.permission.requested` event (the harness asked a person,
201
+ * with `permissions: ask`, or `hooks.decide` answered `ask`). `request` is that event's `request`. `allow` lets
202
+ * the tool run; `deny` refuses it, and the harness carries on with the refusal and `reason`. The answer is
203
+ * recorded as `harness.permission.resolved` with `by: person`. A question nobody answers is denied when the turn
204
+ * reaches its timeout (`by: timeout`), and one still open when its turn ends is withdrawn (`by: withdrawn`). This
205
+ * answer is for this one call, and B3OS never picks a harness's own "always allow": an answer that should cover
206
+ * the rest of a conversation is a rule B3OS keeps for that conversation (planned), never the harness's own.
207
+ *
208
+ * A question of a turn that is not a session (typed in the terminal or started inside the instance) has no
209
+ * session to answer it through: its event has no `session_id`. Answer those, or any question of the instance, with
210
+ * `POST /v1/agents/{agent}/instances/{key}/decisions`, which the live view uses for every question.
211
+ *
212
+ * Claude Code in `terminal` mode asks its own permission prompts in its TUI (with `permissions: ask`), and they
213
+ * are answered there, by whoever controls the terminal: such a `harness.permission.requested` carries no
214
+ * `request`, and no `…/decisions` route can answer it. `hooks.decide` still answers before the TUI asks.
215
+ *
216
+ * A question already answered (by you, another caller, the turn's end or its timeout), or one this session
217
+ * never asked, answers `404 decision_not_found`; an ended session answers `409 no_turn_running`. On a personal
218
+ * agent only the owner answers (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
219
+ * harness_required`). Planned: not served on the beta node yet.
220
+ *
221
+ * `POST /v1/agents/sessions/{session_id}/decisions` · scope `agents:run` · served by the node
222
+ *
223
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
224
+ */
225
+ sendDecision(sessionId: string, body: T.AgentDecisionRequest, options?: RequestOptions): APIPromise<T.AgentDecision>;
75
226
  /**
76
227
  * Stream an agent session's events
77
228
  *
@@ -79,16 +230,38 @@ export declare class AgentsAPI extends Namespace {
79
230
  * to wake (with `woke_from`), `session.delivered` when the harness received it, `session.output` for each event
80
231
  * the harness streamed back (when it answered with `text/event-stream`), and the terminal `job.succeeded`,
81
232
  * `job.failed` or `job.canceled`, which carries the final session and ends the stream. Reconnect with
82
- * `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone.
233
+ * `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone. A
234
+ * session of a personal agent (`Agent.owner`, planned) is streamed only by the agent's owner, since its
235
+ * `session.output` carries the turn's `harness.*` events (`403 harness_personal_agent`).
83
236
  *
84
237
  * `GET /v1/agents/sessions/{session_id}/events` · scope `agents:read` · served by the node
85
238
  */
86
239
  streamSession(sessionId: string, options?: StreamOptions): EventStream<T.AgentSessionEvent>;
240
+ /**
241
+ * Steer a running harness turn
242
+ *
243
+ * Adds `text` to the turn while it runs, past the instance's queue: the harness reads it at its next step
244
+ * (opencode as a `steer` prompt, Codex with `turn/steer`, pi with `steer`, Claude Code as a user message on its
245
+ * input). The session's stream shows it as `harness.turn.started` with `source: steer`. Only for an agent
246
+ * with a `harness` block (`409 harness_required` otherwise), and only while the session is delivered and
247
+ * running: a queued or ended session answers `409 no_turn_running`. A steer that arrives after delivery but
248
+ * before the harness has started the turn is held by the harness's shim and given to the turn as it starts. To
249
+ * start a new turn, send a message. A harness that refuses the text answers `502 harness_error`, and a kind
250
+ * whose driver cannot steer (`capabilities.steer: false` in `GET /v1/agents/harnesses`) answers `422
251
+ * harness_capability_unsupported`. On a personal agent only the owner steers (`403 harness_personal_agent`).
252
+ * Planned: not served on the beta node yet.
253
+ *
254
+ * `POST /v1/agents/sessions/{session_id}/steer` · scope `agents:run` · served by the node
255
+ *
256
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
257
+ */
258
+ steerSession(sessionId: string, body: T.AgentSteerRequest, options?: RequestOptions): APIPromise<T.AgentSession>;
87
259
  /**
88
260
  * Delete an agent
89
261
  *
90
- * Deletes the agent and every instance of it: their microVMs, memory snapshots and disks. Their sessions stay
91
- * readable until they expire.
262
+ * Deletes the agent and every instance of it: their microVMs, memory snapshots and disks, with any sign-in
263
+ * made in them. Their sessions stay readable until they expire. A personal agent is deleted by its owner or an
264
+ * organization admin (`403 harness_personal_agent` for anyone else).
92
265
  *
93
266
  * `DELETE /v1/agents/{agent}` · scope `agents:write` · served by the node
94
267
  */
@@ -96,7 +269,11 @@ export declare class AgentsAPI extends Namespace {
96
269
  /**
97
270
  * Get an agent
98
271
  *
99
- * The agent, by name or `agt_` ID, with its current revision and how many instances it has.
272
+ * The agent, by name or `agt_` ID, with its current revision and how many instances it has. A harness agent
273
+ * (planned) also has its `harness` block as the node stored it (shorthands expanded, `mcp` and `skills` as
274
+ * written, so it can be sent back as it is; the merged lists are those maps over `checks.defaults` in `GET
275
+ * /v1/agents/harnesses`), its `owner`, the state of its revision's prepared snapshot (`harness_prepared`), and
276
+ * its `entry`, `source`, `api`, `egress` and `turns` show what the node filled in from it.
100
277
  *
101
278
  * `GET /v1/agents/{agent}` · scope `agents:read` · served by the node
102
279
  */
@@ -110,6 +287,18 @@ export declare class AgentsAPI extends Namespace {
110
287
  * earlier revision again from this one at its next wake, which ends its memory and disk. `name` cannot change.
111
288
  * The grant is checked again against your own scopes.
112
289
  *
290
+ * `harness` (planned) replaces the whole block, as `entry` does; a harness is pinned to the revision, so a new
291
+ * `version` reaches an instance only through `upgrade: on_wake`, and only once the new revision's prepared
292
+ * snapshot is ready. `on_wake` remakes the instance, so its sign-ins and its harness sessions end with its disk.
293
+ * A change to start-time members only (`instructions`, `settings`, `mcp` entries, `files`, `auth`, `model`,
294
+ * `permissions` and the like) keeps the revision's prepare key, so nothing is built again. An agent made with
295
+ * `entry` cannot take a `harness`, and a harness agent cannot take an `entry` (`400 invalid_request`): make
296
+ * another agent.
297
+ *
298
+ * Only the owner changes a personal agent (`403 harness_personal_agent`). Adding a `signin` profile to an agent
299
+ * that is not personal is `409 harness_signin_not_personal`: make a personal agent from the same block
300
+ * instead.
301
+ *
113
302
  * `PATCH /v1/agents/{agent}` · scope `agents:write` · served by the node
114
303
  */
115
304
  updateAgent(agent: string, body: T.AgentUpdateRequest, options?: RequestOptions): APIPromise<T.Agent>;
@@ -126,7 +315,9 @@ export declare class AgentsAPI extends Namespace {
126
315
  *
127
316
  * Deletes the instance: its microVM, its memory snapshot and its disk. Queued messages end `canceled` and are
128
317
  * never delivered. This and deleting the agent are the only ways an instance ends; idleness never does. The
129
- * next message to the key makes a new instance unless it sends `create: false`.
318
+ * next message to the key makes a new instance unless it sends `create: false`. An instance of a personal agent
319
+ * (`Agent.owner`, planned), with any sign-in made in it, is deleted by the agent's owner or an organization
320
+ * admin (`403 harness_personal_agent` for anyone else).
130
321
  *
131
322
  * `DELETE /v1/agents/{agent}/instances/{key}` · scope `agents:write` · served by the node
132
323
  */
@@ -150,11 +341,37 @@ export declare class AgentsAPI extends Namespace {
150
341
  * agent's current revision. Two requests for a new key at once make one instance.
151
342
  *
152
343
  * Each instance is its own microVM: instances of different keys never share one. The key is stored and shown as
153
- * written, so never use a credential or a personal detail as a key.
344
+ * written, so never use a credential or a personal detail as a key. Only the owner makes or wakes an instance
345
+ * of a personal agent (`403 harness_personal_agent`).
154
346
  *
155
347
  * `PUT /v1/agents/{agent}/instances/{key}` · scope `agents:run` · served by the node
156
348
  */
157
349
  putInstance(agent: string, key: string, body?: T.AgentInstancePutRequest, options?: RequestOptions): APIPromise<T.AgentInstance>;
350
+ /**
351
+ * Answer any permission request of an instance
352
+ *
353
+ * Answers a question the instance's harness waits on, whichever way its turn came: a message (a session), or a
354
+ * turn typed in the terminal or started inside the instance. The body, the answer and the errors are those of
355
+ * `POST /v1/agents/sessions/{session_id}/decisions`; `request` is unique per instance, so this route answers
356
+ * any question of the instance, a session's included. The live view answers every question here, since an event
357
+ * without `session_id` has no session to answer through. The answer is recorded as
358
+ * `harness.permission.resolved` with `by: person`.
359
+ *
360
+ * Claude Code's own permission prompts in `terminal` mode are answered in its TUI, not here (their
361
+ * `harness.permission.requested` carries no `request`).
362
+ *
363
+ * A question of a session is denied when its turn reaches its timeout; one of a turn without a session is denied
364
+ * after an hour (the most a turn may take). A question still open when its turn ends is withdrawn
365
+ * (`harness.permission.resolved` with `by: withdrawn`). A question already answered, or one the instance never
366
+ * asked, answers `404 decision_not_found`. On a personal agent only the owner answers (`403
367
+ * harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`). Planned: not
368
+ * served on the beta node yet.
369
+ *
370
+ * `POST /v1/agents/{agent}/instances/{key}/decisions` · scope `agents:run` · served by the node
371
+ *
372
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
373
+ */
374
+ sendInstanceDecision(agent: string, key: string, body: T.AgentDecisionRequest, options?: RequestOptions): APIPromise<T.AgentDecision>;
158
375
  /**
159
376
  * List an instance's lifecycle events
160
377
  *
@@ -167,6 +384,54 @@ export declare class AgentsAPI extends Namespace {
167
384
  * `GET /v1/agents/{agent}/instances/{key}/events` · scope `agents:read` · served by the node
168
385
  */
169
386
  listInstanceEvents(agent: string, key: string, params?: T.AgentsListInstanceEventsParams, options?: RequestOptions): ListPromise<T.AgentInstanceEventList, T.AgentInstanceEvent>;
387
+ /**
388
+ * List an instance's grants
389
+ *
390
+ * The instance's grants that have not ended, newest first, without their tokens (`token` and `url` are
391
+ * `null`). A personal agent's grants are listed by its owner or an organization admin (`403
392
+ * harness_personal_agent` for anyone else). Planned: not served on the beta node yet.
393
+ *
394
+ * `GET /v1/agents/{agent}/instances/{key}/grants` · scope `agents:read` · served by the node
395
+ *
396
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
397
+ */
398
+ listGrants(agent: string, key: string, params?: T.AgentsListGrantsParams, options?: RequestOptions): ListPromise<T.AgentGrantList, T.AgentGrant>;
399
+ /**
400
+ * Share an instance's terminal by link
401
+ *
402
+ * Mints a grant: a link that opens this instance's live view and terminal for whoever holds it, without a B3OS
403
+ * account. `watch` shows the event stream and the terminal, view-only; `control` also types into the terminal
404
+ * when nobody else holds control, and never takes it over. The link carries its token in the URL fragment
405
+ * (`#token=`), which browsers never send to a server, so it stays out of every log on the way; the share page
406
+ * redeems it (`agentsRedeemGrant`). `token` and `url` are in this answer only: B3OS keeps a hash of the token.
407
+ *
408
+ * A grant ends at `expires_at` (`ttl_s`, 900 seconds by default, at most 3,600), after `uses` redemptions when
409
+ * set, when it is revoked (`DELETE …/grants/{grant_id}`), or when the instance is deleted; revoking it closes
410
+ * the sockets opened with it. The share page redeems the link again each time it reconnects, and each
411
+ * redemption counts one of `uses`: leave `uses` out, or set it to cover the reconnects you expect. An instance
412
+ * has at most `agents.grants_max` grants that have not ended; one more is `422 limit_exceeded`. On a personal
413
+ * agent only the owner mints grants, and only `watch` ones (`403 harness_personal_agent`): a `watch` grant never
414
+ * shows the sign-in window. Only for an agent with a `harness` block (`409 harness_required`). Planned: not
415
+ * served on the beta node yet.
416
+ *
417
+ * `POST /v1/agents/{agent}/instances/{key}/grants` · scope `agents:write` · served by the node
418
+ *
419
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
420
+ */
421
+ createGrant(agent: string, key: string, body: T.AgentGrantCreateRequest, options?: RequestOptions): APIPromise<T.AgentGrant>;
422
+ /**
423
+ * Revoke a grant
424
+ *
425
+ * Ends the grant: its link stops working, and the terminal and event-stream sockets opened with it close.
426
+ * Revoking a grant that already ended answers `404 grant_not_found`. A personal agent's grants are revoked by its
427
+ * owner or an organization admin (`403 harness_personal_agent` for anyone else). Planned: not served on the beta
428
+ * node yet.
429
+ *
430
+ * `DELETE /v1/agents/{agent}/instances/{key}/grants/{grant_id}` · scope `agents:write` · served by the node
431
+ *
432
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
433
+ */
434
+ deleteGrant(agent: string, key: string, grantId: string, options?: RequestOptions): APIPromise<T.Deleted>;
170
435
  /**
171
436
  * Send a message to an instance
172
437
  *
@@ -201,6 +466,28 @@ export declare class AgentsAPI extends Namespace {
201
466
  * `Server-Timing` and the session's `timing` split the turn into `queue`, `wake` (`desc` names the tier),
202
467
  * `deliver` and `harness`.
203
468
  *
469
+ * For an agent with a `harness` block (planned), `text` is the prompt and `context` (optional) is added before
470
+ * the model sees it, quoted as information rather than an instruction. `conversation` names the harness's own
471
+ * session (an opencode session, a Codex thread, a pi session file, a Claude Code session): the first message of
472
+ * a new `conversation` starts a new harness session, and later ones continue it. `profile` picks one of the
473
+ * definition's credential profiles for this turn and the conversation's next ones (`harness.auth`); a name the
474
+ * definition does not have is `400 harness_profile_unknown`. A harness agent's message is closed: a member
475
+ * other than the reserved ones, `text`, `context`, `profile` and a listener's `event` is `400
476
+ * invalid_request`, so a field the harness would not read is refused rather than dropped. `text` is required,
477
+ * but in a listener's message (`type: listener.event`), which carries `event` instead and which the harness is
478
+ * to see quoted whole as information; until the harness's shim quotes it, a `listener.event` message to a
479
+ * harness agent is `422 harness_capability_unsupported`, and `event` in any other message is `400
480
+ * invalid_request`. Each
481
+ * `session.output` carries one `AgentHarnessEvent`, as the node wrote it to the instance's event log, and the
482
+ * turn's `result` is `harness.turn.completed`'s `result`. The session ends `succeeded` at
483
+ * `harness.turn.completed`, `canceled` at `harness.turn.interrupted`, and `failed` with `harness_error` at
484
+ * `harness.turn.failed` or when the harness's stream ends without one of the three, or with
485
+ * `harness_prepare_failed` when the revision's prepared snapshot could not be built.
486
+ *
487
+ * A personal agent (`Agent.owner`) takes messages only from its owner's own principals (their dashboard
488
+ * session, their CLI token, and routines they made); anyone else, and every listener, gets `403
489
+ * harness_personal_agent`.
490
+ *
204
491
  * `POST /v1/agents/{agent}/instances/{key}/messages` · scope `agents:run` · served by the node
205
492
  */
206
493
  sendMessage(agent: string, key: string, body: T.AgentMessageRequest, options?: RequestOptions): JobPromise<T.AgentSession, T.AgentSessionEvent>;
@@ -209,19 +496,159 @@ export declare class AgentsAPI extends Namespace {
209
496
  *
210
497
  * Sends the instance to a sleep tier now instead of waiting for its timers: `ram` pauses it, `snapshot` writes
211
498
  * its memory snapshot and frees its memory (an instance with a volume answers `409 volume_attached` and stays as
212
- * it was). A harness may call this on its own instance when it knows it is done
499
+ * it was). The snapshot's write takes longer the more memory the instance has (seconds to minutes for 4 GiB on
500
+ * a slow drive), and the call does not wait for all of it: it answers `200` with the instance `hibernated` when
501
+ * the write is done within about 2 seconds, else `202` with the instance `paused` and the write going on. It
502
+ * reads `hibernated` once the write is committed; a write that fails leaves it `paused`, and its timers try the
503
+ * snapshot again later. A harness may call this on its own instance when it knows it is done
213
504
  * (from inside, at `http://127.0.0.1:7700`); the pause then happens once its current turn ends. An instance with
214
505
  * a turn running or messages queued goes to sleep after them. Asleep already in that tier or a deeper one:
215
- * returned unchanged.
506
+ * returned unchanged. An instance of a personal agent (`Agent.owner`, planned) is put to sleep by the agent's
507
+ * owner or by itself, from inside (`403 harness_personal_agent` for anyone else).
216
508
  *
217
509
  * `POST /v1/agents/{agent}/instances/{key}/sleep` · scope `agents:run` · served by the node
218
510
  */
219
511
  sleepInstance(agent: string, key: string, body?: T.AgentInstanceSleepRequest, options?: RequestOptions): APIPromise<T.AgentInstance>;
512
+ /**
513
+ * Stream an instance's harness events
514
+ *
515
+ * Server-sent events: every `harness.*` event of the instance, whichever way its turn came (a message, a turn
516
+ * typed in the terminal or started inside the instance, a steer), as `AgentHarnessEvent`s. This is what the live view reads.
517
+ * Each event's SSE `id` is its `seq`, which the node assigns as it writes the event to the instance's log, so it
518
+ * keeps growing when the harness's shim restarts; reconnect with `Last-Event-ID` to resume after it. Events are
519
+ * kept 7 days for replay, as every product event is, and at most `agents.harness_event_log_mib` per instance,
520
+ * past which the oldest go first; a stream that resumes past what is kept starts from the oldest kept event.
521
+ * `harness.message` events with `delta: true` get a `seq` too, but are streamed and never kept. The node
522
+ * serves the stream from its own copy of the events, so opening it neither wakes the instance nor keeps it
523
+ * awake.
524
+ *
525
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
526
+ * grant's from `agentsRedeemGrant`). On a personal agent, only the owner and the owner's `watch` grants read
527
+ * it (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`).
528
+ * Planned: not served on the beta node yet.
529
+ *
530
+ * `GET /v1/agents/{agent}/instances/{key}/stream` · scope `agents:read` · served by the node
531
+ *
532
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
533
+ */
534
+ streamInstance(agent: string, key: string, options?: StreamOptions): EventStream<T.AgentHarnessEvent>;
535
+ /**
536
+ * Open a harness's terminal
537
+ *
538
+ * Opens the harness's terminal over a WebSocket: the harness's own TUI in `terminal` mode, a shell in the
539
+ * workspace in `api` mode (the live view shows the events beside it). tmux in the instance holds the terminal,
540
+ * so it outlives every socket and a restart of the harness's shim. The node reaches it through the instance's
541
+ * port proxy: opening it wakes a sleeping instance, and an open socket keeps the instance awake. When the last
542
+ * socket closes and the harness is idle, the instance sleeps on its timers with the terminal paused in memory.
543
+ *
544
+ * The wire is the sandbox terminal's (`sandboxesOpenPty`) with a cursor added. Binary frames carry terminal
545
+ * bytes both ways; input counts only from the controller. Text frames carry JSON. The server's first frame is
546
+ * `{"type": "session", "id": "pts_…", "resumed": true, "cursor": 1048576, "role": "view", "cols": 120, "rows":
547
+ * 40}`, then one binary frame with what the socket missed, then live output. The client sends `{"type":
548
+ * "resize", "cols", "rows"}` (controller only), `{"type": "control"}` to ask for control, `{"type": "release"}`,
549
+ * and `{"type": "end"}` (controller only: ends the terminal, and the TUI with it). The server sends `{"type":
550
+ * "role", "role", "reason"}` when this socket's role changes, `{"type": "error", "code": "controller_active"}`
551
+ * when another socket holds control, and `{"type": "exit", "code"}` before it closes.
552
+ *
553
+ * One controller, any number of viewers. `role=control` takes control when nobody holds it, and needs
554
+ * `agents:run` besides this operation's `agents:read`; when another socket holds it, this one opens as `view`
555
+ * (its first frame says so). Only the agent's owners take control from the holder, with `{"type": "control",
556
+ * "takeover": true}`: a credential that holds `agents:write`, never a grant. The holder stays as a viewer and
557
+ * gets `{"type": "role", "role": "view", "reason": "taken over"}`.
558
+ *
559
+ * Reconnect where you left off: the terminal's output is kept in a 1 MiB ring indexed by byte offset. Send the
560
+ * `session` and the `cursor` (the session frame's `cursor` plus the bytes received since), and the socket
561
+ * replays the bytes it missed. Past the ring, or when the terminal was started again (another `session`), it
562
+ * draws the current screen and goes on live. A socket lasts at most an hour; reconnect with the cursor.
563
+ *
564
+ * Every attach and detach is a `harness.terminal.attached` or `harness.terminal.detached` event. With
565
+ * `harness.terminal.record`, the terminal is also written as a recording (`…/terminal/recordings`).
566
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
567
+ * grant's from `agentsRedeemGrant`) as `?ticket=` or the `b3os.ticket.<ticket>` subprotocol. Only for an agent
568
+ * with a `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
569
+ *
570
+ * The sign-in window (`window=signin:<profile>`) is where a personal agent's owner signs in to their own plan
571
+ * for a `signin` profile: the harness's own login runs there (`codex login --device-auth`, `claude auth login`;
572
+ * a kind signs in only to the plans its `auth.signin` in `GET /v1/agents/harnesses` lists), under that profile's
573
+ * directory, and writes the harness's own credential file in the instance. B3OS never reads that file, and the
574
+ * shim reports only that it exists (`harness.auth.ready`, with what the harness says about its plan). The
575
+ * sign-out window (`window=signout:<profile>`) runs the harness's own logout for the profile the same way, and
576
+ * `harness.auth.removed` (`reason: signed_out`) says when the file is gone. Either window opens only for the
577
+ * owner, on a `signin` profile of the definition (`403 harness_personal_agent` or `400 harness_profile_unknown`
578
+ * otherwise), and a sign-in to a Claude plan's profile (`provider: anthropic`) only with
579
+ * `agents.claude_plan_signin` on (`403 harness_claude_plan_signin_disabled`); a sign-out needs no flag. It is
580
+ * never sent to a viewer or a grant's socket, it is never recorded, and what it showed is dropped when it
581
+ * closes. On a personal agent the main window too is the owner's: others see it only through a `watch` grant,
582
+ * and `control` grants are refused. Until personal agents are served (`AgentHarnessAuthSignin` names what they
583
+ * wait on), no agent has a `signin` profile, so neither window opens.
584
+ *
585
+ * The node opens the shim's terminal with the shim's token in place of your credential, and says what it
586
+ * checked in headers only it may set (`x-b3os-window`, `x-b3os-takeover`), which it removes from every request
587
+ * it forwards (packages/spec/sidecars/harness.md).
588
+ *
589
+ * `GET /v1/agents/{agent}/instances/{key}/terminal` · scope `agents:read` · served by the node
590
+ *
591
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
592
+ */
593
+ openTerminal(agent: string, key: string, params?: T.AgentsOpenTerminalParams, options?: RequestOptions): Promise<PtySession>;
594
+ /**
595
+ * List an instance's terminal recordings
596
+ *
597
+ * The instance's terminal recordings, newest first. A terminal is recorded only when the definition sets
598
+ * `harness.terminal.record: true`; it is off by default, because a recording keeps whatever the terminal showed,
599
+ * codes and keys printed in it included. Each start of a conversation's terminal begins a new recording, an
600
+ * asciicast v3 file on the instance's own disk with one header, with a marker (`m`) at each `harness.*` event
601
+ * but `harness.message`, so a player can jump to a turn. One that reaches 64 MiB while it is written is closed
602
+ * and the next one begins; a conversation keeps its current recording and the one before it. Deleting the
603
+ * instance deletes them. The node reads them from the harness's shim through the instance's port, so reading
604
+ * the list wakes the instance as a port request does. The sign-in window is never recorded. On a personal agent
605
+ * only the owner reads them (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
606
+ * harness_required`). Planned: not served on the beta node yet.
607
+ *
608
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings` · scope `agents:read` · served by the node
609
+ *
610
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
611
+ */
612
+ listRecordings(agent: string, key: string, params?: T.AgentsListRecordingsParams, options?: RequestOptions): ListPromise<T.AgentTerminalRecordingList, T.AgentTerminalRecording>;
613
+ /**
614
+ * Download a terminal recording
615
+ *
616
+ * The recording as an asciicast v3 file (`application/x-asciicast`, one JSON value per line): a header, then
617
+ * `[seconds since the previous event, code, data]` with codes `o` (output), `r` (resize, `"COLSxROWS"`), `m`
618
+ * (a marker, the `harness.*` event's type) and `x` (exit status). Input is never recorded. asciinema 3 plays
619
+ * it. Planned: not served on the beta node yet.
620
+ *
621
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings/{recording_id}` · scope `agents:read` · served by the node
622
+ *
623
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
624
+ */
625
+ getRecording(agent: string, key: string, recordingId: string, options?: RequestOptions): APIPromise<Uint8Array>;
626
+ /**
627
+ * Create a stream ticket for an instance
628
+ *
629
+ * Returns a single-use ticket, valid for 30 seconds, that opens one stream of this instance without a bearer
630
+ * header: its terminal (`GET …/terminal`) or its event stream (`GET …/stream`). Pass it as `?ticket=` or in
631
+ * `Sec-WebSocket-Protocol: b3os.v1, b3os.ticket.<ticket>`. The stream runs with this caller's scopes, so a
632
+ * terminal opened with it takes control only when the caller holds `agents:run`.
633
+ *
634
+ * The ticket's `resource` is this request's own path without `/ticket`, exactly as it was sent: the agent as you
635
+ * named it (its name or its `agt_` ID) and the key percent-encoded as in the request. A ticket is matched
636
+ * against the stream's path as sent, so open the stream with the same form: a ticket minted under the agent's
637
+ * name does not open its stream under its ID. On a personal agent only the owner mints tickets (`403
638
+ * harness_personal_agent`): others watch through a `watch` grant the owner shares. Only for an agent with a
639
+ * `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
640
+ *
641
+ * `POST /v1/agents/{agent}/instances/{key}/ticket` · scope `agents:read` · served by the node
642
+ *
643
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
644
+ */
645
+ createTicket(agent: string, key: string, options?: RequestOptions): APIPromise<T.StreamTicket>;
220
646
  /**
221
647
  * List an agent's sessions
222
648
  *
223
649
  * Lists the agent's sessions, newest first. Filter by instance `key`, by `conversation` (the ID you sent with the
224
- * message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`.
650
+ * message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`. A personal agent's sessions
651
+ * (`Agent.owner`, planned) are listed only for its owner (`403 harness_personal_agent`).
225
652
  *
226
653
  * `GET /v1/agents/{agent}/sessions` · scope `agents:read` · served by the node
227
654
  */