@b3os/sdk 0.2.2 → 0.2.4

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 (87) 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 +449 -11
  14. package/dist/cjs/generated/ns/agents.js +609 -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/keys.d.ts +12 -4
  20. package/dist/cjs/generated/ns/keys.js +12 -4
  21. package/dist/cjs/generated/ns/keys.js.map +1 -1
  22. package/dist/cjs/generated/ns/listeners.d.ts +6 -2
  23. package/dist/cjs/generated/ns/listeners.js +6 -2
  24. package/dist/cjs/generated/ns/listeners.js.map +1 -1
  25. package/dist/cjs/generated/ns/routines.d.ts +11 -0
  26. package/dist/cjs/generated/ns/routines.js +11 -0
  27. package/dist/cjs/generated/ns/routines.js.map +1 -1
  28. package/dist/cjs/generated/ns/sandboxes.d.ts +140 -1
  29. package/dist/cjs/generated/ns/sandboxes.js +190 -1
  30. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  31. package/dist/cjs/generated/ns/vision.d.ts +55 -1
  32. package/dist/cjs/generated/ns/vision.js +94 -1
  33. package/dist/cjs/generated/ns/vision.js.map +1 -1
  34. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  35. package/dist/cjs/generated/ns/workspaces.js +410 -0
  36. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  37. package/dist/cjs/generated/types.d.ts +2312 -90
  38. package/dist/esm/core/util.d.ts +1 -1
  39. package/dist/esm/core/util.js +1 -1
  40. package/dist/esm/generated/client.d.ts +5 -0
  41. package/dist/esm/generated/client.js +9 -0
  42. package/dist/esm/generated/client.js.map +1 -1
  43. package/dist/esm/generated/errors.d.ts +1 -1
  44. package/dist/esm/generated/errors.js +45 -0
  45. package/dist/esm/generated/errors.js.map +1 -1
  46. package/dist/esm/generated/ids.d.ts +28 -0
  47. package/dist/esm/generated/ids.js +7 -0
  48. package/dist/esm/generated/ids.js.map +1 -1
  49. package/dist/esm/generated/ns/agents.d.ts +449 -11
  50. package/dist/esm/generated/ns/agents.js +609 -11
  51. package/dist/esm/generated/ns/agents.js.map +1 -1
  52. package/dist/esm/generated/ns/images.d.ts +84 -3
  53. package/dist/esm/generated/ns/images.js +126 -2
  54. package/dist/esm/generated/ns/images.js.map +1 -1
  55. package/dist/esm/generated/ns/keys.d.ts +12 -4
  56. package/dist/esm/generated/ns/keys.js +12 -4
  57. package/dist/esm/generated/ns/keys.js.map +1 -1
  58. package/dist/esm/generated/ns/listeners.d.ts +6 -2
  59. package/dist/esm/generated/ns/listeners.js +6 -2
  60. package/dist/esm/generated/ns/listeners.js.map +1 -1
  61. package/dist/esm/generated/ns/routines.d.ts +11 -0
  62. package/dist/esm/generated/ns/routines.js +11 -0
  63. package/dist/esm/generated/ns/routines.js.map +1 -1
  64. package/dist/esm/generated/ns/sandboxes.d.ts +140 -1
  65. package/dist/esm/generated/ns/sandboxes.js +190 -1
  66. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  67. package/dist/esm/generated/ns/vision.d.ts +55 -1
  68. package/dist/esm/generated/ns/vision.js +94 -1
  69. package/dist/esm/generated/ns/vision.js.map +1 -1
  70. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  71. package/dist/esm/generated/ns/workspaces.js +406 -0
  72. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  73. package/dist/esm/generated/types.d.ts +2312 -90
  74. package/package.json +1 -1
  75. package/src/core/util.ts +1 -1
  76. package/src/generated/client.ts +10 -0
  77. package/src/generated/errors.ts +90 -0
  78. package/src/generated/ids.ts +7 -0
  79. package/src/generated/ns/agents.ts +663 -11
  80. package/src/generated/ns/images.ts +131 -3
  81. package/src/generated/ns/keys.ts +12 -4
  82. package/src/generated/ns/listeners.ts +6 -2
  83. package/src/generated/ns/routines.ts +11 -0
  84. package/src/generated/ns/sandboxes.ts +203 -1
  85. package/src/generated/ns/vision.ts +101 -1
  86. package/src/generated/ns/workspaces.ts +448 -0
  87. package/src/generated/types.ts +2488 -55
@@ -6,6 +6,7 @@ import { Namespace } from "../../core/namespace.ts";
6
6
  import type { Op } from "../../core/op.ts";
7
7
  import type { APIPromise, JobPromise, ListPromise } from "../../core/promise.ts";
8
8
  import type { EventStream } from "../../core/sse.ts";
9
+ import { openSocket, PtySession, ticketedUrl } from "../../core/ws.ts";
9
10
  import type * as T from "../types.ts";
10
11
 
11
12
  const listAgentsOp: Op = {
@@ -24,6 +25,32 @@ const createAgentOp: Op = {
24
25
  timeoutMs: 10000,
25
26
  scope: "agents:write",
26
27
  };
28
+ const listHarnessesOp: Op = {
29
+ id: "agentsListHarnesses",
30
+ method: "GET",
31
+ path: "/v1/agents/harnesses",
32
+ timeoutMs: 10000,
33
+ stretch: true,
34
+ scope: "agents:read",
35
+ };
36
+ const requestSelfDecisionOp: Op = {
37
+ id: "agentsRequestSelfDecision",
38
+ method: "POST",
39
+ path: "/v1/agents/self/decide",
40
+ body: "json",
41
+ timeoutMs: 12000,
42
+ stretch: true,
43
+ scope: "authenticated",
44
+ };
45
+ const recordSelfEventsOp: Op = {
46
+ id: "agentsRecordSelfEvents",
47
+ method: "POST",
48
+ path: "/v1/agents/self/events",
49
+ body: "json",
50
+ timeoutMs: 10000,
51
+ stretch: true,
52
+ scope: "authenticated",
53
+ };
27
54
  const getSessionOp: Op = {
28
55
  id: "agentsGetSession",
29
56
  method: "GET",
@@ -40,6 +67,16 @@ const cancelSessionOp: Op = {
40
67
  timeoutMs: 10000,
41
68
  scope: "agents:run",
42
69
  };
70
+ const sendDecisionOp: Op = {
71
+ id: "agentsSendDecision",
72
+ method: "POST",
73
+ path: "/v1/agents/sessions/{session_id}/decisions",
74
+ params: ["session_id"],
75
+ body: "json",
76
+ timeoutMs: 10000,
77
+ stretch: true,
78
+ scope: "agents:run",
79
+ };
43
80
  const streamSessionOp: Op = {
44
81
  id: "agentsStreamSession",
45
82
  method: "GET",
@@ -49,6 +86,16 @@ const streamSessionOp: Op = {
49
86
  timeoutMs: 3600000,
50
87
  scope: "agents:read",
51
88
  };
89
+ const steerSessionOp: Op = {
90
+ id: "agentsSteerSession",
91
+ method: "POST",
92
+ path: "/v1/agents/sessions/{session_id}/steer",
93
+ params: ["session_id"],
94
+ body: "json",
95
+ timeoutMs: 10000,
96
+ stretch: true,
97
+ scope: "agents:run",
98
+ };
52
99
  const deleteAgentOp: Op = {
53
100
  id: "agentsDeleteAgent",
54
101
  method: "DELETE",
@@ -107,6 +154,16 @@ const putInstanceOp: Op = {
107
154
  timeoutMs: 65000,
108
155
  scope: "agents:run",
109
156
  };
157
+ const sendInstanceDecisionOp: Op = {
158
+ id: "agentsSendInstanceDecision",
159
+ method: "POST",
160
+ path: "/v1/agents/{agent}/instances/{key}/decisions",
161
+ params: ["agent", "key"],
162
+ body: "json",
163
+ timeoutMs: 10000,
164
+ stretch: true,
165
+ scope: "agents:run",
166
+ };
110
167
  const listInstanceEventsOp: Op = {
111
168
  id: "agentsListInstanceEvents",
112
169
  method: "GET",
@@ -115,6 +172,34 @@ const listInstanceEventsOp: Op = {
115
172
  timeoutMs: 10000,
116
173
  scope: "agents:read",
117
174
  };
175
+ const listGrantsOp: Op = {
176
+ id: "agentsListGrants",
177
+ method: "GET",
178
+ path: "/v1/agents/{agent}/instances/{key}/grants",
179
+ params: ["agent", "key"],
180
+ timeoutMs: 10000,
181
+ stretch: true,
182
+ scope: "agents:read",
183
+ };
184
+ const createGrantOp: Op = {
185
+ id: "agentsCreateGrant",
186
+ method: "POST",
187
+ path: "/v1/agents/{agent}/instances/{key}/grants",
188
+ params: ["agent", "key"],
189
+ body: "json",
190
+ timeoutMs: 10000,
191
+ stretch: true,
192
+ scope: "agents:write",
193
+ };
194
+ const deleteGrantOp: Op = {
195
+ id: "agentsDeleteGrant",
196
+ method: "DELETE",
197
+ path: "/v1/agents/{agent}/instances/{key}/grants/{grant_id}",
198
+ params: ["agent", "key", "grant_id"],
199
+ timeoutMs: 10000,
200
+ stretch: true,
201
+ scope: "agents:write",
202
+ };
118
203
  const sleepInstanceOp: Op = {
119
204
  id: "agentsSleepInstance",
120
205
  method: "POST",
@@ -124,6 +209,53 @@ const sleepInstanceOp: Op = {
124
209
  timeoutMs: 30000,
125
210
  scope: "agents:run",
126
211
  };
212
+ const streamInstanceOp: Op = {
213
+ id: "agentsStreamInstance",
214
+ method: "GET",
215
+ path: "/v1/agents/{agent}/instances/{key}/stream",
216
+ params: ["agent", "key"],
217
+ stream: "sse",
218
+ timeoutMs: 3600000,
219
+ stretch: true,
220
+ scope: "agents:read",
221
+ };
222
+ const openTerminalOp: Op = {
223
+ id: "agentsOpenTerminal",
224
+ method: "GET",
225
+ path: "/v1/agents/{agent}/instances/{key}/terminal",
226
+ params: ["agent", "key"],
227
+ stream: "ws",
228
+ timeoutMs: 3600000,
229
+ stretch: true,
230
+ scope: "agents:read",
231
+ };
232
+ const listRecordingsOp: Op = {
233
+ id: "agentsListRecordings",
234
+ method: "GET",
235
+ path: "/v1/agents/{agent}/instances/{key}/terminal/recordings",
236
+ params: ["agent", "key"],
237
+ timeoutMs: 30000,
238
+ stretch: true,
239
+ scope: "agents:read",
240
+ };
241
+ const getRecordingOp: Op = {
242
+ id: "agentsGetRecording",
243
+ method: "GET",
244
+ path: "/v1/agents/{agent}/instances/{key}/terminal/recordings/{recording_id}",
245
+ params: ["agent", "key", "recording_id"],
246
+ timeoutMs: 65000,
247
+ stretch: true,
248
+ scope: "agents:read",
249
+ };
250
+ const createTicketOp: Op = {
251
+ id: "agentsCreateTicket",
252
+ method: "POST",
253
+ path: "/v1/agents/{agent}/instances/{key}/ticket",
254
+ params: ["agent", "key"],
255
+ timeoutMs: 5000,
256
+ stretch: true,
257
+ scope: "agents:read",
258
+ };
127
259
  const listSessionsOp: Op = {
128
260
  id: "agentsListSessions",
129
261
  method: "GET",
@@ -149,9 +281,14 @@ const sendMessageOp: Op = {
149
281
  export const agentsOps = {
150
282
  listAgents: listAgentsOp,
151
283
  createAgent: createAgentOp,
284
+ listHarnesses: listHarnessesOp,
285
+ requestSelfDecision: requestSelfDecisionOp,
286
+ recordSelfEvents: recordSelfEventsOp,
152
287
  getSession: getSessionOp,
153
288
  cancelSession: cancelSessionOp,
289
+ sendDecision: sendDecisionOp,
154
290
  streamSession: streamSessionOp,
291
+ steerSession: steerSessionOp,
155
292
  deleteAgent: deleteAgentOp,
156
293
  getAgent: getAgentOp,
157
294
  updateAgent: updateAgentOp,
@@ -159,9 +296,18 @@ export const agentsOps = {
159
296
  deleteInstance: deleteInstanceOp,
160
297
  getInstance: getInstanceOp,
161
298
  putInstance: putInstanceOp,
299
+ sendInstanceDecision: sendInstanceDecisionOp,
162
300
  listInstanceEvents: listInstanceEventsOp,
301
+ listGrants: listGrantsOp,
302
+ createGrant: createGrantOp,
303
+ deleteGrant: deleteGrantOp,
163
304
  sendMessage: sendMessageOp,
164
305
  sleepInstance: sleepInstanceOp,
306
+ streamInstance: streamInstanceOp,
307
+ openTerminal: openTerminalOp,
308
+ listRecordings: listRecordingsOp,
309
+ getRecording: getRecordingOp,
310
+ createTicket: createTicketOp,
165
311
  listSessions: listSessionsOp,
166
312
  } as const;
167
313
 
@@ -194,19 +340,129 @@ export class AgentsAPI extends Namespace {
194
340
  * disk, never its definition. Instances belong to the project: revoking the key that created the agent does
195
341
  * not stop them.
196
342
  *
343
+ * Set `harness` instead of `entry` to run a coding agent people already use (opencode, the default; Codex; pi;
344
+ * Claude Code), unmodified (`AgentHarness`; planned, not served on the beta node yet). The node checks the
345
+ * block against the kind's entry in `GET /v1/agents/harnesses`, then fills `entry`, `source.template`, each
346
+ * `key` profile's credentials in `secrets` (as `B3OS_PROFILE_<NAME>__<VAR>`), and `api`, `egress` and
347
+ * `turns.timeout_s` where you leave them out. A request with both `entry` and `harness`, or neither, is `400
348
+ * invalid_request`. Until they are served on this node, `repo`, `context` and `acp` are refused even when
349
+ * empty, and so is every vault connection outside a credential profile (`repo.connection`, a remote `mcp`
350
+ * server's `connection`, a stdio server's `{connection}` values): `422 harness_capability_unsupported`.
351
+ *
352
+ * An agent with a `signin` profile in `harness.auth` is personal: its `owner` is the person who creates it,
353
+ * from their own dashboard session or CLI token (an API key, a sandbox or an instance gets `403
354
+ * harness_personal_agent`), and it never changes. A ChatGPT plan's sign-in (`provider: openai`) needs no flag.
355
+ * A Claude plan's (`provider: anthropic`) needs the `agents.claude_plan_signin` flag (`403
356
+ * harness_claude_plan_signin_disabled` without it). The node knows no person yet, so until the prerequisites
357
+ * `AgentHarnessAuthSignin` names land, every `signin` profile is `403 harness_personal_agent`.
358
+ *
197
359
  * `POST /v1/agents` · scope `agents:write` · served by the node
198
360
  */
199
361
  createAgent(body: T.AgentCreateRequest, options?: RequestOptions): APIPromise<T.Agent> {
200
362
  return this._client._call<T.Agent>(createAgentOp, { body }, options);
201
363
  }
202
364
 
365
+ /**
366
+ * List the harnesses this node runs
367
+ *
368
+ * The harnesses a `harness` block may name (`kind`), the open-source ones first (opencode, the default `kind`,
369
+ * then Codex and pi; Claude Code last), each with the versions this node runs, newest first, and the one a
370
+ * definition without `version` gets. A version is pinned in the node's `harness` template; a new
371
+ * upstream release becomes a new template revision and a new entry here, and a definition moves to it only when
372
+ * a `PATCH` changes its `version`.
373
+ *
374
+ * This answer is the catalog the harness's shim prints (`b3os-harness catalog --json`), stored with the
375
+ * `harness` template's build and served as it was printed, nothing added or left out: the shim's drivers are
376
+ * the source of truth for what each kind takes, and the node checks definitions against this answer. Each entry
377
+ * in `data` is what the kind's driver declares about itself: `driver` (`native`, built into the shim, or `acp`,
378
+ * the generic Agent Client Protocol adapter), `capabilities`, the credential profiles the kind takes (`auth`:
379
+ * the `key` providers with the variables each sets, the `signin` providers, and whether a model the node serves
380
+ * works), the lists of the block it takes (`setup`), and the `settings` keys the shim owns
381
+ * (`settings_refused`). `plan_env` names the variables no harness agent may set (`AgentHarnessPlanEnv`).
382
+ * `checks` is what the node and the shim refuse beyond each entry (`AgentHarnessCatalogChecks`), among them the
383
+ * default `mcp` and `skills` entries every definition's maps merge over (`checks.defaults`), so a client can
384
+ * check a recipe, and show its merged lists, before it deploys it. A feature not yet checked against a kind's
385
+ * pinned version is left out, and a definition that uses it is refused (`422 harness_capability_unsupported`).
386
+ * A definition that moves to a new version builds that revision's prepared snapshot again, at most
387
+ * `agents.prepare_concurrent` builds of an organization at once (planned, with prepared snapshots).
388
+ * Planned: not served on the beta node yet.
389
+ *
390
+ * `GET /v1/agents/harnesses` · scope `agents:read` · served by the node
391
+ *
392
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
393
+ */
394
+ listHarnesses(options?: RequestOptions): APIPromise<T.AgentHarnessKindList> {
395
+ return this._client._call<T.AgentHarnessKindList>(listHarnessesOp, {}, options);
396
+ }
397
+
398
+ /**
399
+ * Ask the decide webhook from inside an instance
400
+ *
401
+ * How the harness's shim asks the definition's `hooks.decide` webhook a question while the turn waits, from
402
+ * inside the instance at `http://127.0.0.1:7700`. The node makes the call (`agentsDecideHarnessEvent`): it sets
403
+ * `harness`, `instance` and, when `session` is the session the instance runs now, `session_id` and `subject`
404
+ * from that session (any other `session` is dropped); it signs the call with `B3OS-Signature` and the URL's
405
+ * secret, sends it through the egress guard (private and loopback addresses refused), and answers with the
406
+ * decision. So the secret never enters the instance, and the decide host need not be in the instance's
407
+ * `egress`.
408
+ *
409
+ * The node applies the fail-closed rule itself and answers within `timeout_ms` (at most 10 seconds) plus its
410
+ * own overhead: no answer in time, a status other than 2xx, or a body without a `decision` answers
411
+ * `hooks.decide.on_timeout` (`deny` unless the definition sets `allow`) with `fallback: true`. The shim treats
412
+ * any answer other than `200`, and no answer, as `deny`. A question the definition does not send to the
413
+ * webhook is `400 invalid_request`: an agent without `hooks.decide`, a `type` its `events` does not select, and
414
+ * any question in `permissions: plan`, where the webhook is never called.
415
+ *
416
+ * Bound to the caller's own credential as `POST /v1/agents/self/events` is: the instance is the one whose
417
+ * token calls, and any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
418
+ * An instance asks at most `agents.self_decide_rate` questions a minute; past it the answer is `429
419
+ * rate_limited`, which the shim takes as `deny`, as it takes any answer but `200`. Planned: not served on the
420
+ * beta node yet.
421
+ *
422
+ * `POST /v1/agents/self/decide` · scope `authenticated` · served by the node
423
+ *
424
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
425
+ */
426
+ requestSelfDecision(body: T.AgentSelfDecideRequest, options?: RequestOptions): APIPromise<T.AgentSelfDecision> {
427
+ return this._client._call<T.AgentSelfDecision>(requestSelfDecisionOp, { body }, options);
428
+ }
429
+
430
+ /**
431
+ * Record harness events from inside an instance
432
+ *
433
+ * How the harness's shim records `harness.*` events that happened outside a delivered turn (a turn typed in the
434
+ * terminal or started inside the instance), from inside the instance at `http://127.0.0.1:7700`. The node writes them to the
435
+ * calling instance's event stream (`GET /v1/agents/{agent}/instances/{key}/stream`) and sends the ones the
436
+ * definition's `hooks.webhook` selects. Events of a delivered turn reach the session's stream as
437
+ * `session.output` instead and are not sent here.
438
+ *
439
+ * The route is bound to the caller's own credential: the node takes the instance from the token of the VM that
440
+ * calls. Each event is an `AgentSelfEvent`, which has none of the members the node owns: the node sets
441
+ * `instance`, `org` and `project` itself and assigns the log's own `seq`. An event with `seq`, `instance`,
442
+ * `org`, `project`, `session_id` or `subject` is `400 invalid_request`, and so is one whose `harness` is not the
443
+ * definition's kind; the whole request is refused and nothing in it is written. A self event never belongs to a
444
+ * session: the node never takes one as a session's result or as the answer to a question. No instance can write
445
+ * another's events. Any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
446
+ * An event whose `id` the instance already recorded is counted in `duplicates` and not written again. An
447
+ * instance records at most `agents.self_events_rate` events a minute; past it the request is `429
448
+ * rate_limited` with `Retry-After` and nothing in it is written. Planned: not served on the beta node yet.
449
+ *
450
+ * `POST /v1/agents/self/events` · scope `authenticated` · served by the node
451
+ *
452
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
453
+ */
454
+ recordSelfEvents(body: T.AgentSelfEventsRequest, options?: RequestOptions): APIPromise<T.AgentSelfEventsResult> {
455
+ return this._client._call<T.AgentSelfEventsResult>(recordSelfEventsOp, { body }, options);
456
+ }
457
+
203
458
  /**
204
459
  * Get an agent session
205
460
  *
206
461
  * One turn: its status and phase, who sent it (`initiator`), its conversation, how its instance woke
207
462
  * (`woke_from`), its trace and its timing. The message and the harness's answer are kept only for a session that
208
463
  * was answered `202` (so you can read the result here, for 24 hours) or when the project's
209
- * `platform.capture_content` setting is on. Sessions are kept 30 days after they end.
464
+ * `platform.capture_content` setting is on. Sessions are kept 30 days after they end. A session of a personal
465
+ * agent (`Agent.owner`, planned) is read only by the agent's owner (`403 harness_personal_agent`).
210
466
  *
211
467
  * `GET /v1/agents/sessions/{session_id}` · scope `agents:read` · served by the node
212
468
  */
@@ -218,7 +474,13 @@ export class AgentsAPI extends Namespace {
218
474
  * Cancel an agent session
219
475
  *
220
476
  * Cancels a turn. A queued session leaves the queue and is never delivered. A delivered one has its request into
221
- * the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged.
477
+ * the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged. For
478
+ * an agent with a `harness` block (planned), the node first asks the harness to interrupt the turn (opencode's
479
+ * session interrupt, Codex's `turn/interrupt`, pi's `abort`, Claude Code's `interrupt`), so the turn ends
480
+ * `harness.turn.interrupted` with its usage so far, and the harness session stays open for the next turn. The
481
+ * harness's shim also stops the turn when the node closes the delivery, so a cancel that arrives before the
482
+ * harness has started the turn still stops it. On a personal agent only the owner cancels (`403
483
+ * harness_personal_agent`).
222
484
  *
223
485
  * `POST /v1/agents/sessions/{session_id}/cancel` · scope `agents:run` · served by the node
224
486
  */
@@ -226,6 +488,38 @@ export class AgentsAPI extends Namespace {
226
488
  return this._client._call<T.AgentSession>(cancelSessionOp, { path: [sessionId] }, options);
227
489
  }
228
490
 
491
+ /**
492
+ * Answer a harness's permission request
493
+ *
494
+ * Answers a question the turn waits on: a `harness.permission.requested` event (the harness asked a person,
495
+ * with `permissions: ask`, or `hooks.decide` answered `ask`). `request` is that event's `request`. `allow` lets
496
+ * the tool run; `deny` refuses it, and the harness carries on with the refusal and `reason`. The answer is
497
+ * recorded as `harness.permission.resolved` with `by: person`. A question nobody answers is denied when the turn
498
+ * reaches its timeout (`by: timeout`), and one still open when its turn ends is withdrawn (`by: withdrawn`). This
499
+ * answer is for this one call, and B3OS never picks a harness's own "always allow": an answer that should cover
500
+ * the rest of a conversation is a rule B3OS keeps for that conversation (planned), never the harness's own.
501
+ *
502
+ * A question of a turn that is not a session (typed in the terminal or started inside the instance) has no
503
+ * session to answer it through: its event has no `session_id`. Answer those, or any question of the instance, with
504
+ * `POST /v1/agents/{agent}/instances/{key}/decisions`, which the live view uses for every question.
505
+ *
506
+ * Claude Code in `terminal` mode asks its own permission prompts in its TUI (with `permissions: ask`), and they
507
+ * are answered there, by whoever controls the terminal: such a `harness.permission.requested` carries no
508
+ * `request`, and no `…/decisions` route can answer it. `hooks.decide` still answers before the TUI asks.
509
+ *
510
+ * A question already answered (by you, another caller, the turn's end or its timeout), or one this session
511
+ * never asked, answers `404 decision_not_found`; an ended session answers `409 no_turn_running`. On a personal
512
+ * agent only the owner answers (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
513
+ * harness_required`). Planned: not served on the beta node yet.
514
+ *
515
+ * `POST /v1/agents/sessions/{session_id}/decisions` · scope `agents:run` · served by the node
516
+ *
517
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
518
+ */
519
+ sendDecision(sessionId: string, body: T.AgentDecisionRequest, options?: RequestOptions): APIPromise<T.AgentDecision> {
520
+ return this._client._call<T.AgentDecision>(sendDecisionOp, { path: [sessionId], body }, options);
521
+ }
522
+
229
523
  /**
230
524
  * Stream an agent session's events
231
525
  *
@@ -233,7 +527,9 @@ export class AgentsAPI extends Namespace {
233
527
  * to wake (with `woke_from`), `session.delivered` when the harness received it, `session.output` for each event
234
528
  * the harness streamed back (when it answered with `text/event-stream`), and the terminal `job.succeeded`,
235
529
  * `job.failed` or `job.canceled`, which carries the final session and ends the stream. Reconnect with
236
- * `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone.
530
+ * `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone. A
531
+ * session of a personal agent (`Agent.owner`, planned) is streamed only by the agent's owner, since its
532
+ * `session.output` carries the turn's `harness.*` events (`403 harness_personal_agent`).
237
533
  *
238
534
  * `GET /v1/agents/sessions/{session_id}/events` · scope `agents:read` · served by the node
239
535
  */
@@ -244,11 +540,34 @@ export class AgentsAPI extends Namespace {
244
540
  });
245
541
  }
246
542
 
543
+ /**
544
+ * Steer a running harness turn
545
+ *
546
+ * Adds `text` to the turn while it runs, past the instance's queue: the harness reads it at its next step
547
+ * (opencode as a `steer` prompt, Codex with `turn/steer`, pi with `steer`, Claude Code as a user message on its
548
+ * input). The session's stream shows it as `harness.turn.started` with `source: steer`. Only for an agent
549
+ * with a `harness` block (`409 harness_required` otherwise), and only while the session is delivered and
550
+ * running: a queued or ended session answers `409 no_turn_running`. A steer that arrives after delivery but
551
+ * before the harness has started the turn is held by the harness's shim and given to the turn as it starts. To
552
+ * start a new turn, send a message. A harness that refuses the text answers `502 harness_error`, and a kind
553
+ * whose driver cannot steer (`capabilities.steer: false` in `GET /v1/agents/harnesses`) answers `422
554
+ * harness_capability_unsupported`. On a personal agent only the owner steers (`403 harness_personal_agent`).
555
+ * Planned: not served on the beta node yet.
556
+ *
557
+ * `POST /v1/agents/sessions/{session_id}/steer` · scope `agents:run` · served by the node
558
+ *
559
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
560
+ */
561
+ steerSession(sessionId: string, body: T.AgentSteerRequest, options?: RequestOptions): APIPromise<T.AgentSession> {
562
+ return this._client._call<T.AgentSession>(steerSessionOp, { path: [sessionId], body }, options);
563
+ }
564
+
247
565
  /**
248
566
  * Delete an agent
249
567
  *
250
- * Deletes the agent and every instance of it: their microVMs, memory snapshots and disks. Their sessions stay
251
- * readable until they expire.
568
+ * Deletes the agent and every instance of it: their microVMs, memory snapshots and disks, with any sign-in
569
+ * made in them. Their sessions stay readable until they expire. A personal agent is deleted by its owner or an
570
+ * organization admin (`403 harness_personal_agent` for anyone else).
252
571
  *
253
572
  * `DELETE /v1/agents/{agent}` · scope `agents:write` · served by the node
254
573
  */
@@ -259,7 +578,11 @@ export class AgentsAPI extends Namespace {
259
578
  /**
260
579
  * Get an agent
261
580
  *
262
- * The agent, by name or `agt_` ID, with its current revision and how many instances it has.
581
+ * The agent, by name or `agt_` ID, with its current revision and how many instances it has. A harness agent
582
+ * (planned) also has its `harness` block as the node stored it (shorthands expanded, `mcp` and `skills` as
583
+ * written, so it can be sent back as it is; the merged lists are those maps over `checks.defaults` in `GET
584
+ * /v1/agents/harnesses`), its `owner`, the state of its revision's prepared snapshot (`harness_prepared`), and
585
+ * its `entry`, `source`, `api`, `egress` and `turns` show what the node filled in from it.
263
586
  *
264
587
  * `GET /v1/agents/{agent}` · scope `agents:read` · served by the node
265
588
  */
@@ -276,6 +599,18 @@ export class AgentsAPI extends Namespace {
276
599
  * earlier revision again from this one at its next wake, which ends its memory and disk. `name` cannot change.
277
600
  * The grant is checked again against your own scopes.
278
601
  *
602
+ * `harness` (planned) replaces the whole block, as `entry` does; a harness is pinned to the revision, so a new
603
+ * `version` reaches an instance only through `upgrade: on_wake`, and only once the new revision's prepared
604
+ * snapshot is ready. `on_wake` remakes the instance, so its sign-ins and its harness sessions end with its disk.
605
+ * A change to start-time members only (`instructions`, `settings`, `mcp` entries, `files`, `auth`, `model`,
606
+ * `permissions` and the like) keeps the revision's prepare key, so nothing is built again. An agent made with
607
+ * `entry` cannot take a `harness`, and a harness agent cannot take an `entry` (`400 invalid_request`): make
608
+ * another agent.
609
+ *
610
+ * Only the owner changes a personal agent (`403 harness_personal_agent`). Adding a `signin` profile to an agent
611
+ * that is not personal is `409 harness_signin_not_personal`: make a personal agent from the same block
612
+ * instead.
613
+ *
279
614
  * `PATCH /v1/agents/{agent}` · scope `agents:write` · served by the node
280
615
  */
281
616
  updateAgent(agent: string, body: T.AgentUpdateRequest, options?: RequestOptions): APIPromise<T.Agent> {
@@ -306,7 +641,9 @@ export class AgentsAPI extends Namespace {
306
641
  *
307
642
  * Deletes the instance: its microVM, its memory snapshot and its disk. Queued messages end `canceled` and are
308
643
  * never delivered. This and deleting the agent are the only ways an instance ends; idleness never does. The
309
- * next message to the key makes a new instance unless it sends `create: false`.
644
+ * next message to the key makes a new instance unless it sends `create: false`. An instance of a personal agent
645
+ * (`Agent.owner`, planned), with any sign-in made in it, is deleted by the agent's owner or an organization
646
+ * admin (`403 harness_personal_agent` for anyone else).
310
647
  *
311
648
  * `DELETE /v1/agents/{agent}/instances/{key}` · scope `agents:write` · served by the node
312
649
  */
@@ -336,7 +673,8 @@ export class AgentsAPI extends Namespace {
336
673
  * agent's current revision. Two requests for a new key at once make one instance.
337
674
  *
338
675
  * Each instance is its own microVM: instances of different keys never share one. The key is stored and shown as
339
- * written, so never use a credential or a personal detail as a key.
676
+ * written, so never use a credential or a personal detail as a key. Only the owner makes or wakes an instance
677
+ * of a personal agent (`403 harness_personal_agent`).
340
678
  *
341
679
  * `PUT /v1/agents/{agent}/instances/{key}` · scope `agents:run` · served by the node
342
680
  */
@@ -349,6 +687,39 @@ export class AgentsAPI extends Namespace {
349
687
  return this._client._call<T.AgentInstance>(putInstanceOp, { path: [agent, key], body }, options);
350
688
  }
351
689
 
690
+ /**
691
+ * Answer any permission request of an instance
692
+ *
693
+ * Answers a question the instance's harness waits on, whichever way its turn came: a message (a session), or a
694
+ * turn typed in the terminal or started inside the instance. The body, the answer and the errors are those of
695
+ * `POST /v1/agents/sessions/{session_id}/decisions`; `request` is unique per instance, so this route answers
696
+ * any question of the instance, a session's included. The live view answers every question here, since an event
697
+ * without `session_id` has no session to answer through. The answer is recorded as
698
+ * `harness.permission.resolved` with `by: person`.
699
+ *
700
+ * Claude Code's own permission prompts in `terminal` mode are answered in its TUI, not here (their
701
+ * `harness.permission.requested` carries no `request`).
702
+ *
703
+ * A question of a session is denied when its turn reaches its timeout; one of a turn without a session is denied
704
+ * after an hour (the most a turn may take). A question still open when its turn ends is withdrawn
705
+ * (`harness.permission.resolved` with `by: withdrawn`). A question already answered, or one the instance never
706
+ * asked, answers `404 decision_not_found`. On a personal agent only the owner answers (`403
707
+ * harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`). Planned: not
708
+ * served on the beta node yet.
709
+ *
710
+ * `POST /v1/agents/{agent}/instances/{key}/decisions` · scope `agents:run` · served by the node
711
+ *
712
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
713
+ */
714
+ sendInstanceDecision(
715
+ agent: string,
716
+ key: string,
717
+ body: T.AgentDecisionRequest,
718
+ options?: RequestOptions,
719
+ ): APIPromise<T.AgentDecision> {
720
+ return this._client._call<T.AgentDecision>(sendInstanceDecisionOp, { path: [agent, key], body }, options);
721
+ }
722
+
352
723
  /**
353
724
  * List an instance's lifecycle events
354
725
  *
@@ -373,6 +744,77 @@ export class AgentsAPI extends Namespace {
373
744
  );
374
745
  }
375
746
 
747
+ /**
748
+ * List an instance's grants
749
+ *
750
+ * The instance's grants that have not ended, newest first, without their tokens (`token` and `url` are
751
+ * `null`). A personal agent's grants are listed by its owner or an organization admin (`403
752
+ * harness_personal_agent` for anyone else). Planned: not served on the beta node yet.
753
+ *
754
+ * `GET /v1/agents/{agent}/instances/{key}/grants` · scope `agents:read` · served by the node
755
+ *
756
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
757
+ */
758
+ listGrants(
759
+ agent: string,
760
+ key: string,
761
+ params?: T.AgentsListGrantsParams,
762
+ options?: RequestOptions,
763
+ ): ListPromise<T.AgentGrantList, T.AgentGrant> {
764
+ return this._client._list<T.AgentGrantList, T.AgentGrant>(
765
+ listGrantsOp,
766
+ { path: [agent, key], query: params },
767
+ options,
768
+ );
769
+ }
770
+
771
+ /**
772
+ * Share an instance's terminal by link
773
+ *
774
+ * Mints a grant: a link that opens this instance's live view and terminal for whoever holds it, without a B3OS
775
+ * account. `watch` shows the event stream and the terminal, view-only; `control` also types into the terminal
776
+ * when nobody else holds control, and never takes it over. The link carries its token in the URL fragment
777
+ * (`#token=`), which browsers never send to a server, so it stays out of every log on the way; the share page
778
+ * redeems it (`agentsRedeemGrant`). `token` and `url` are in this answer only: B3OS keeps a hash of the token.
779
+ *
780
+ * A grant ends at `expires_at` (`ttl_s`, 900 seconds by default, at most 3,600), after `uses` redemptions when
781
+ * set, when it is revoked (`DELETE …/grants/{grant_id}`), or when the instance is deleted; revoking it closes
782
+ * the sockets opened with it. The share page redeems the link again each time it reconnects, and each
783
+ * redemption counts one of `uses`: leave `uses` out, or set it to cover the reconnects you expect. An instance
784
+ * has at most `agents.grants_max` grants that have not ended; one more is `422 limit_exceeded`. On a personal
785
+ * agent only the owner mints grants, and only `watch` ones (`403 harness_personal_agent`): a `watch` grant never
786
+ * shows the sign-in window. Only for an agent with a `harness` block (`409 harness_required`). Planned: not
787
+ * served on the beta node yet.
788
+ *
789
+ * `POST /v1/agents/{agent}/instances/{key}/grants` · scope `agents:write` · served by the node
790
+ *
791
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
792
+ */
793
+ createGrant(
794
+ agent: string,
795
+ key: string,
796
+ body: T.AgentGrantCreateRequest,
797
+ options?: RequestOptions,
798
+ ): APIPromise<T.AgentGrant> {
799
+ return this._client._call<T.AgentGrant>(createGrantOp, { path: [agent, key], body }, options);
800
+ }
801
+
802
+ /**
803
+ * Revoke a grant
804
+ *
805
+ * Ends the grant: its link stops working, and the terminal and event-stream sockets opened with it close.
806
+ * Revoking a grant that already ended answers `404 grant_not_found`. A personal agent's grants are revoked by its
807
+ * owner or an organization admin (`403 harness_personal_agent` for anyone else). Planned: not served on the beta
808
+ * node yet.
809
+ *
810
+ * `DELETE /v1/agents/{agent}/instances/{key}/grants/{grant_id}` · scope `agents:write` · served by the node
811
+ *
812
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
813
+ */
814
+ deleteGrant(agent: string, key: string, grantId: string, options?: RequestOptions): APIPromise<T.Deleted> {
815
+ return this._client._call<T.Deleted>(deleteGrantOp, { path: [agent, key, grantId] }, options);
816
+ }
817
+
376
818
  /**
377
819
  * Send a message to an instance
378
820
  *
@@ -407,6 +849,28 @@ export class AgentsAPI extends Namespace {
407
849
  * `Server-Timing` and the session's `timing` split the turn into `queue`, `wake` (`desc` names the tier),
408
850
  * `deliver` and `harness`.
409
851
  *
852
+ * For an agent with a `harness` block (planned), `text` is the prompt and `context` (optional) is added before
853
+ * the model sees it, quoted as information rather than an instruction. `conversation` names the harness's own
854
+ * session (an opencode session, a Codex thread, a pi session file, a Claude Code session): the first message of
855
+ * a new `conversation` starts a new harness session, and later ones continue it. `profile` picks one of the
856
+ * definition's credential profiles for this turn and the conversation's next ones (`harness.auth`); a name the
857
+ * definition does not have is `400 harness_profile_unknown`. A harness agent's message is closed: a member
858
+ * other than the reserved ones, `text`, `context`, `profile` and a listener's `event` is `400
859
+ * invalid_request`, so a field the harness would not read is refused rather than dropped. `text` is required,
860
+ * but in a listener's message (`type: listener.event`), which carries `event` instead and which the harness is
861
+ * to see quoted whole as information; until the harness's shim quotes it, a `listener.event` message to a
862
+ * harness agent is `422 harness_capability_unsupported`, and `event` in any other message is `400
863
+ * invalid_request`. Each
864
+ * `session.output` carries one `AgentHarnessEvent`, as the node wrote it to the instance's event log, and the
865
+ * turn's `result` is `harness.turn.completed`'s `result`. The session ends `succeeded` at
866
+ * `harness.turn.completed`, `canceled` at `harness.turn.interrupted`, and `failed` with `harness_error` at
867
+ * `harness.turn.failed` or when the harness's stream ends without one of the three, or with
868
+ * `harness_prepare_failed` when the revision's prepared snapshot could not be built.
869
+ *
870
+ * A personal agent (`Agent.owner`) takes messages only from its owner's own principals (their dashboard
871
+ * session, their CLI token, and routines they made); anyone else, and every listener, gets `403
872
+ * harness_personal_agent`.
873
+ *
410
874
  * `POST /v1/agents/{agent}/instances/{key}/messages` · scope `agents:run` · served by the node
411
875
  */
412
876
  sendMessage(
@@ -423,10 +887,15 @@ export class AgentsAPI extends Namespace {
423
887
  *
424
888
  * Sends the instance to a sleep tier now instead of waiting for its timers: `ram` pauses it, `snapshot` writes
425
889
  * its memory snapshot and frees its memory (an instance with a volume answers `409 volume_attached` and stays as
426
- * it was). A harness may call this on its own instance when it knows it is done
890
+ * it was). The snapshot's write takes longer the more memory the instance has (seconds to minutes for 4 GiB on
891
+ * a slow drive), and the call does not wait for all of it: it answers `200` with the instance `hibernated` when
892
+ * the write is done within about 2 seconds, else `202` with the instance `paused` and the write going on. It
893
+ * reads `hibernated` once the write is committed; a write that fails leaves it `paused`, and its timers try the
894
+ * snapshot again later. A harness may call this on its own instance when it knows it is done
427
895
  * (from inside, at `http://127.0.0.1:7700`); the pause then happens once its current turn ends. An instance with
428
896
  * a turn running or messages queued goes to sleep after them. Asleep already in that tier or a deeper one:
429
- * returned unchanged.
897
+ * returned unchanged. An instance of a personal agent (`Agent.owner`, planned) is put to sleep by the agent's
898
+ * owner or by itself, from inside (`403 harness_personal_agent` for anyone else).
430
899
  *
431
900
  * `POST /v1/agents/{agent}/instances/{key}/sleep` · scope `agents:run` · served by the node
432
901
  */
@@ -439,11 +908,194 @@ export class AgentsAPI extends Namespace {
439
908
  return this._client._call<T.AgentInstance>(sleepInstanceOp, { path: [agent, key], body }, options);
440
909
  }
441
910
 
911
+ /**
912
+ * Stream an instance's harness events
913
+ *
914
+ * Server-sent events: every `harness.*` event of the instance, whichever way its turn came (a message, a turn
915
+ * typed in the terminal or started inside the instance, a steer), as `AgentHarnessEvent`s. This is what the live view reads.
916
+ * Each event's SSE `id` is its `seq`, which the node assigns as it writes the event to the instance's log, so it
917
+ * keeps growing when the harness's shim restarts; reconnect with `Last-Event-ID` to resume after it. Events are
918
+ * kept 7 days for replay, as every product event is, and at most `agents.harness_event_log_mib` per instance,
919
+ * past which the oldest go first; a stream that resumes past what is kept starts from the oldest kept event.
920
+ * `harness.message` events with `delta: true` get a `seq` too, but are streamed and never kept. The node
921
+ * serves the stream from its own copy of the events, so opening it neither wakes the instance nor keeps it
922
+ * awake.
923
+ *
924
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
925
+ * grant's from `agentsRedeemGrant`). On a personal agent, only the owner and the owner's `watch` grants read
926
+ * it (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`).
927
+ * Planned: not served on the beta node yet.
928
+ *
929
+ * `GET /v1/agents/{agent}/instances/{key}/stream` · scope `agents:read` · served by the node
930
+ *
931
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
932
+ */
933
+ streamInstance(agent: string, key: string, options?: StreamOptions): EventStream<T.AgentHarnessEvent> {
934
+ return this._client._stream<T.AgentHarnessEvent>(streamInstanceOp, { path: [agent, key] }, options, {});
935
+ }
936
+
937
+ /**
938
+ * Open a harness's terminal
939
+ *
940
+ * Opens the harness's terminal over a WebSocket: the harness's own TUI in `terminal` mode, a shell in the
941
+ * workspace in `api` mode (the live view shows the events beside it). tmux in the instance holds the terminal,
942
+ * so it outlives every socket and a restart of the harness's shim. The node reaches it through the instance's
943
+ * port proxy. A socket opened with `role=control` wakes a sleeping instance and keeps it awake while it is open;
944
+ * when the last one closes and the harness is idle, the instance sleeps on its timers with the terminal paused in
945
+ * memory.
946
+ *
947
+ * A viewer's socket (`role=view`) never wakes the instance and never counts as activity, so an open viewer does
948
+ * not keep an instance running: it sleeps on its timers with viewers attached, and the node drops their sockets
949
+ * as it does. A viewer that opens while the instance sleeps gets `{"type": "sleeping", "status": "paused"}` (the
950
+ * instance's `status`), and the socket closes with code 1000 and reason `sleeping`. To watch again, open it once
951
+ * the instance is awake: its next turn's events show in the event stream (`agentsStreamInstance`), which neither
952
+ * wakes the instance nor keeps it awake.
953
+ *
954
+ * The wire is the sandbox terminal's (`sandboxesOpenPty`) with a cursor added. Binary frames carry terminal
955
+ * bytes both ways; input counts only from the controller. Text frames carry JSON. The server's first frame is
956
+ * `{"type": "session", "id": "pts_…", "resumed": true, "cursor": 1048576, "role": "view", "cols": 120, "rows":
957
+ * 40}`, then one binary frame with what the socket missed, then live output. The client sends `{"type":
958
+ * "resize", "cols", "rows"}` (controller only), `{"type": "control"}` to ask for control, `{"type": "release"}`,
959
+ * and `{"type": "end"}` (controller only: ends the terminal, and the TUI with it). The server sends `{"type":
960
+ * "role", "role", "reason"}` when this socket's role changes, `{"type": "size", "cols", "rows"}` to every viewer
961
+ * when the controller resizes the terminal (a viewer draws the controller's grid, which tmux draws for),
962
+ * `{"type": "error", "code": "controller_active"}` when another socket holds control, and `{"type": "exit",
963
+ * "code"}` before it closes.
964
+ *
965
+ * One controller, any number of viewers. `role=control` takes control when nobody holds it, and needs
966
+ * `agents:run` besides this operation's `agents:read`; when another socket holds it, this one opens as `view`
967
+ * (its first frame says so) and may ask for control later. A socket opened with `role=view` never takes control:
968
+ * it gets `{"type": "error", "code": "forbidden"}` when it asks. Only the agent's owners take control from the
969
+ * holder, with `{"type": "control", "takeover": true}`: a credential that holds `agents:write`, never a grant.
970
+ * The holder stays as a viewer and gets `{"type": "role", "role": "view", "reason": "taken over"}`.
971
+ *
972
+ * Reconnect where you left off: the terminal's output is kept in a 1 MiB ring indexed by byte offset. Send the
973
+ * `session` and the `cursor` (the session frame's `cursor` plus the bytes received since), and the socket
974
+ * replays the bytes it missed. Past the ring, or when the terminal was started again (another `session`), it
975
+ * draws the current screen and goes on live. A socket lasts at most an hour; reconnect with the cursor.
976
+ *
977
+ * Every attach and detach is a `harness.terminal.attached` or `harness.terminal.detached` event. With
978
+ * `harness.terminal.record`, the terminal is also written as a recording (`…/terminal/recordings`).
979
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
980
+ * grant's from `agentsRedeemGrant`) as `?ticket=` or the `b3os.ticket.<ticket>` subprotocol. Only for an agent
981
+ * with a `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
982
+ *
983
+ * The sign-in window (`window=signin:<profile>`) is where a personal agent's owner signs in to their own plan
984
+ * for a `signin` profile: the harness's own login runs there (`codex login --device-auth`, `claude auth login`;
985
+ * a kind signs in only to the plans its `auth.signin` in `GET /v1/agents/harnesses` lists), under that profile's
986
+ * directory, and writes the harness's own credential file in the instance. B3OS never reads that file, and the
987
+ * shim reports only that it exists (`harness.auth.ready`, with what the harness says about its plan). The
988
+ * sign-out window (`window=signout:<profile>`) runs the harness's own logout for the profile the same way, and
989
+ * `harness.auth.removed` (`reason: signed_out`) says when the file is gone. Either window opens only for the
990
+ * owner, on a `signin` profile of the definition (`403 harness_personal_agent` or `400 harness_profile_unknown`
991
+ * otherwise), and a sign-in to a Claude plan's profile (`provider: anthropic`) only with
992
+ * `agents.claude_plan_signin` on (`403 harness_claude_plan_signin_disabled`); a sign-out needs no flag. It is
993
+ * never sent to a viewer or a grant's socket, it is never recorded, and what it showed is dropped when it
994
+ * closes. On a personal agent the main window too is the owner's: others see it only through a `watch` grant,
995
+ * and `control` grants are refused. Until personal agents are served (`AgentHarnessAuthSignin` names what they
996
+ * wait on), no agent has a `signin` profile, so neither window opens.
997
+ *
998
+ * The node opens the shim's terminal with the shim's token in place of your credential, and says what it
999
+ * checked in headers only it may set (`x-b3os-window`, `x-b3os-takeover`), which it removes from every request
1000
+ * it forwards (packages/spec/sidecars/harness.md).
1001
+ *
1002
+ * `GET /v1/agents/{agent}/instances/{key}/terminal` · scope `agents:read` · served by the node
1003
+ *
1004
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
1005
+ */
1006
+ async openTerminal(
1007
+ agent: string,
1008
+ key: string,
1009
+ params?: T.AgentsOpenTerminalParams,
1010
+ options: RequestOptions = {},
1011
+ ): Promise<PtySession> {
1012
+ const { url, protocols } = await ticketedUrl(
1013
+ this._client,
1014
+ openTerminalOp,
1015
+ createTicketOp,
1016
+ { path: [agent, key], query: params },
1017
+ options,
1018
+ false,
1019
+ );
1020
+ return new PtySession(await openSocket(url, protocols, options.signal));
1021
+ }
1022
+
1023
+ /**
1024
+ * List an instance's terminal recordings
1025
+ *
1026
+ * The instance's terminal recordings, newest first. A terminal is recorded only when the definition sets
1027
+ * `harness.terminal.record: true`; it is off by default, because a recording keeps whatever the terminal showed,
1028
+ * codes and keys printed in it included. Each start of a conversation's terminal begins a new recording, an
1029
+ * asciicast v3 file on the instance's own disk with one header, with a marker (`m`) at each `harness.*` event
1030
+ * but `harness.message`, so a player can jump to a turn. One that reaches 64 MiB while it is written is closed
1031
+ * and the next one begins; a conversation keeps its current recording and the one before it. Deleting the
1032
+ * instance deletes them. The node reads them from the harness's shim through the instance's port, so reading
1033
+ * the list wakes the instance as a port request does. The sign-in window is never recorded. On a personal agent
1034
+ * only the owner reads them (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
1035
+ * harness_required`). Planned: not served on the beta node yet.
1036
+ *
1037
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings` · scope `agents:read` · served by the node
1038
+ *
1039
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
1040
+ */
1041
+ listRecordings(
1042
+ agent: string,
1043
+ key: string,
1044
+ params?: T.AgentsListRecordingsParams,
1045
+ options?: RequestOptions,
1046
+ ): ListPromise<T.AgentTerminalRecordingList, T.AgentTerminalRecording> {
1047
+ return this._client._list<T.AgentTerminalRecordingList, T.AgentTerminalRecording>(
1048
+ listRecordingsOp,
1049
+ { path: [agent, key], query: params },
1050
+ options,
1051
+ );
1052
+ }
1053
+
1054
+ /**
1055
+ * Download a terminal recording
1056
+ *
1057
+ * The recording as an asciicast v3 file (`application/x-asciicast`, one JSON value per line): a header, then
1058
+ * `[seconds since the previous event, code, data]` with codes `o` (output), `r` (resize, `"COLSxROWS"`), `m`
1059
+ * (a marker, the `harness.*` event's type) and `x` (exit status). Input is never recorded. asciinema 3 plays
1060
+ * it. Planned: not served on the beta node yet.
1061
+ *
1062
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings/{recording_id}` · scope `agents:read` · served by the node
1063
+ *
1064
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
1065
+ */
1066
+ getRecording(agent: string, key: string, recordingId: string, options?: RequestOptions): APIPromise<Uint8Array> {
1067
+ return this._client._call<Uint8Array>(getRecordingOp, { path: [agent, key, recordingId] }, options, "*/*", "bytes");
1068
+ }
1069
+
1070
+ /**
1071
+ * Create a stream ticket for an instance
1072
+ *
1073
+ * Returns a single-use ticket, valid for 30 seconds, that opens one stream of this instance without a bearer
1074
+ * header: its terminal (`GET …/terminal`) or its event stream (`GET …/stream`). Pass it as `?ticket=` or in
1075
+ * `Sec-WebSocket-Protocol: b3os.v1, b3os.ticket.<ticket>`. The stream runs with this caller's scopes, so a
1076
+ * terminal opened with it takes control only when the caller holds `agents:run`.
1077
+ *
1078
+ * The ticket's `resource` is this request's own path without `/ticket`, exactly as it was sent: the agent as you
1079
+ * named it (its name or its `agt_` ID) and the key percent-encoded as in the request. A ticket is matched
1080
+ * against the stream's path as sent, so open the stream with the same form: a ticket minted under the agent's
1081
+ * name does not open its stream under its ID. On a personal agent only the owner mints tickets (`403
1082
+ * harness_personal_agent`): others watch through a `watch` grant the owner shares. Only for an agent with a
1083
+ * `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
1084
+ *
1085
+ * `POST /v1/agents/{agent}/instances/{key}/ticket` · scope `agents:read` · served by the node
1086
+ *
1087
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
1088
+ */
1089
+ createTicket(agent: string, key: string, options?: RequestOptions): APIPromise<T.StreamTicket> {
1090
+ return this._client._call<T.StreamTicket>(createTicketOp, { path: [agent, key] }, options);
1091
+ }
1092
+
442
1093
  /**
443
1094
  * List an agent's sessions
444
1095
  *
445
1096
  * Lists the agent's sessions, newest first. Filter by instance `key`, by `conversation` (the ID you sent with the
446
- * message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`.
1097
+ * message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`. A personal agent's sessions
1098
+ * (`Agent.owner`, planned) are listed only for its owner (`403 harness_personal_agent`).
447
1099
  *
448
1100
  * `GET /v1/agents/{agent}/sessions` · scope `agents:read` · served by the node
449
1101
  */