@b3os/sdk 0.2.1 → 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 (146) 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 +18 -0
  5. package/dist/cjs/generated/client.js +34 -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 +120 -0
  9. package/dist/cjs/generated/errors.js.map +1 -1
  10. package/dist/cjs/generated/ids.d.ts +89 -0
  11. package/dist/cjs/generated/ids.js +22 -0
  12. package/dist/cjs/generated/ids.js.map +1 -1
  13. package/dist/cjs/generated/jobs.js +4 -0
  14. package/dist/cjs/generated/jobs.js.map +1 -1
  15. package/dist/cjs/generated/ns/actions.d.ts +267 -33
  16. package/dist/cjs/generated/ns/actions.js +375 -33
  17. package/dist/cjs/generated/ns/actions.js.map +1 -1
  18. package/dist/cjs/generated/ns/agents.d.ts +656 -0
  19. package/dist/cjs/generated/ns/agents.js +989 -0
  20. package/dist/cjs/generated/ns/agents.js.map +1 -0
  21. package/dist/cjs/generated/ns/images.d.ts +162 -0
  22. package/dist/cjs/generated/ns/images.js +246 -0
  23. package/dist/cjs/generated/ns/images.js.map +1 -0
  24. package/dist/cjs/generated/ns/infer.d.ts +71 -3
  25. package/dist/cjs/generated/ns/infer.js +98 -3
  26. package/dist/cjs/generated/ns/infer.js.map +1 -1
  27. package/dist/cjs/generated/ns/keys.d.ts +3 -1
  28. package/dist/cjs/generated/ns/keys.js +3 -1
  29. package/dist/cjs/generated/ns/keys.js.map +1 -1
  30. package/dist/cjs/generated/ns/listeners.d.ts +163 -0
  31. package/dist/cjs/generated/ns/listeners.js +268 -0
  32. package/dist/cjs/generated/ns/listeners.js.map +1 -0
  33. package/dist/cjs/generated/ns/orgs.d.ts +10 -0
  34. package/dist/cjs/generated/ns/orgs.js +26 -1
  35. package/dist/cjs/generated/ns/orgs.js.map +1 -1
  36. package/dist/cjs/generated/ns/projects.d.ts +32 -0
  37. package/dist/cjs/generated/ns/projects.js +66 -0
  38. package/dist/cjs/generated/ns/projects.js.map +1 -1
  39. package/dist/cjs/generated/ns/render.d.ts +192 -21
  40. package/dist/cjs/generated/ns/render.js +267 -24
  41. package/dist/cjs/generated/ns/render.js.map +1 -1
  42. package/dist/cjs/generated/ns/requests.d.ts +3 -1
  43. package/dist/cjs/generated/ns/requests.js +3 -1
  44. package/dist/cjs/generated/ns/requests.js.map +1 -1
  45. package/dist/cjs/generated/ns/routines.d.ts +22 -4
  46. package/dist/cjs/generated/ns/routines.js +22 -4
  47. package/dist/cjs/generated/ns/routines.js.map +1 -1
  48. package/dist/cjs/generated/ns/sandboxes.d.ts +431 -7
  49. package/dist/cjs/generated/ns/sandboxes.js +633 -6
  50. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  51. package/dist/cjs/generated/ns/usage.d.ts +1 -1
  52. package/dist/cjs/generated/ns/usage.js +1 -1
  53. package/dist/cjs/generated/ns/vision.d.ts +113 -17
  54. package/dist/cjs/generated/ns/vision.js +152 -21
  55. package/dist/cjs/generated/ns/vision.js.map +1 -1
  56. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  57. package/dist/cjs/generated/ns/workspaces.js +410 -0
  58. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  59. package/dist/cjs/generated/types.d.ts +5259 -605
  60. package/dist/cjs/helpers/sandboxes.d.ts +20 -1
  61. package/dist/cjs/helpers/sandboxes.js +13 -1
  62. package/dist/cjs/helpers/sandboxes.js.map +1 -1
  63. package/dist/esm/core/util.d.ts +1 -1
  64. package/dist/esm/core/util.js +1 -1
  65. package/dist/esm/generated/client.d.ts +18 -0
  66. package/dist/esm/generated/client.js +34 -0
  67. package/dist/esm/generated/client.js.map +1 -1
  68. package/dist/esm/generated/errors.d.ts +1 -1
  69. package/dist/esm/generated/errors.js +120 -0
  70. package/dist/esm/generated/errors.js.map +1 -1
  71. package/dist/esm/generated/ids.d.ts +89 -0
  72. package/dist/esm/generated/ids.js +22 -0
  73. package/dist/esm/generated/ids.js.map +1 -1
  74. package/dist/esm/generated/jobs.js +4 -0
  75. package/dist/esm/generated/jobs.js.map +1 -1
  76. package/dist/esm/generated/ns/actions.d.ts +267 -33
  77. package/dist/esm/generated/ns/actions.js +375 -33
  78. package/dist/esm/generated/ns/actions.js.map +1 -1
  79. package/dist/esm/generated/ns/agents.d.ts +656 -0
  80. package/dist/esm/generated/ns/agents.js +985 -0
  81. package/dist/esm/generated/ns/agents.js.map +1 -0
  82. package/dist/esm/generated/ns/images.d.ts +162 -0
  83. package/dist/esm/generated/ns/images.js +242 -0
  84. package/dist/esm/generated/ns/images.js.map +1 -0
  85. package/dist/esm/generated/ns/infer.d.ts +71 -3
  86. package/dist/esm/generated/ns/infer.js +98 -3
  87. package/dist/esm/generated/ns/infer.js.map +1 -1
  88. package/dist/esm/generated/ns/keys.d.ts +3 -1
  89. package/dist/esm/generated/ns/keys.js +3 -1
  90. package/dist/esm/generated/ns/keys.js.map +1 -1
  91. package/dist/esm/generated/ns/listeners.d.ts +163 -0
  92. package/dist/esm/generated/ns/listeners.js +264 -0
  93. package/dist/esm/generated/ns/listeners.js.map +1 -0
  94. package/dist/esm/generated/ns/orgs.d.ts +10 -0
  95. package/dist/esm/generated/ns/orgs.js +26 -1
  96. package/dist/esm/generated/ns/orgs.js.map +1 -1
  97. package/dist/esm/generated/ns/projects.d.ts +32 -0
  98. package/dist/esm/generated/ns/projects.js +66 -0
  99. package/dist/esm/generated/ns/projects.js.map +1 -1
  100. package/dist/esm/generated/ns/render.d.ts +192 -21
  101. package/dist/esm/generated/ns/render.js +267 -24
  102. package/dist/esm/generated/ns/render.js.map +1 -1
  103. package/dist/esm/generated/ns/requests.d.ts +3 -1
  104. package/dist/esm/generated/ns/requests.js +3 -1
  105. package/dist/esm/generated/ns/requests.js.map +1 -1
  106. package/dist/esm/generated/ns/routines.d.ts +22 -4
  107. package/dist/esm/generated/ns/routines.js +22 -4
  108. package/dist/esm/generated/ns/routines.js.map +1 -1
  109. package/dist/esm/generated/ns/sandboxes.d.ts +431 -7
  110. package/dist/esm/generated/ns/sandboxes.js +633 -6
  111. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  112. package/dist/esm/generated/ns/usage.d.ts +1 -1
  113. package/dist/esm/generated/ns/usage.js +1 -1
  114. package/dist/esm/generated/ns/vision.d.ts +113 -17
  115. package/dist/esm/generated/ns/vision.js +152 -21
  116. package/dist/esm/generated/ns/vision.js.map +1 -1
  117. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  118. package/dist/esm/generated/ns/workspaces.js +406 -0
  119. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  120. package/dist/esm/generated/types.d.ts +5259 -605
  121. package/dist/esm/helpers/sandboxes.d.ts +20 -1
  122. package/dist/esm/helpers/sandboxes.js +13 -1
  123. package/dist/esm/helpers/sandboxes.js.map +1 -1
  124. package/package.json +1 -1
  125. package/src/core/util.ts +1 -1
  126. package/src/generated/client.ts +38 -0
  127. package/src/generated/errors.ts +240 -0
  128. package/src/generated/ids.ts +22 -0
  129. package/src/generated/jobs.ts +4 -0
  130. package/src/generated/ns/actions.ts +403 -33
  131. package/src/generated/ns/agents.ts +1102 -0
  132. package/src/generated/ns/images.ts +256 -0
  133. package/src/generated/ns/infer.ts +100 -3
  134. package/src/generated/ns/keys.ts +3 -1
  135. package/src/generated/ns/listeners.ts +300 -0
  136. package/src/generated/ns/orgs.ts +27 -1
  137. package/src/generated/ns/projects.ts +74 -0
  138. package/src/generated/ns/render.ts +277 -24
  139. package/src/generated/ns/requests.ts +3 -1
  140. package/src/generated/ns/routines.ts +22 -4
  141. package/src/generated/ns/sandboxes.ts +694 -7
  142. package/src/generated/ns/usage.ts +1 -1
  143. package/src/generated/ns/vision.ts +159 -21
  144. package/src/generated/ns/workspaces.ts +448 -0
  145. package/src/generated/types.ts +5684 -601
  146. package/src/helpers/sandboxes.ts +31 -2
@@ -0,0 +1,985 @@
1
+ // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
+ import { isTerminalJobEvent } from "../../core/jobs.js";
3
+ import { Namespace } from "../../core/namespace.js";
4
+ import { openSocket, PtySession, ticketedUrl } from "../../core/ws.js";
5
+ const listAgentsOp = {
6
+ id: "agentsListAgents",
7
+ method: "GET",
8
+ path: "/v1/agents",
9
+ timeoutMs: 10000,
10
+ scope: "agents:read",
11
+ };
12
+ const createAgentOp = {
13
+ id: "agentsCreateAgent",
14
+ method: "POST",
15
+ path: "/v1/agents",
16
+ body: "json",
17
+ idem: true,
18
+ timeoutMs: 10000,
19
+ scope: "agents:write",
20
+ };
21
+ const listHarnessesOp = {
22
+ id: "agentsListHarnesses",
23
+ method: "GET",
24
+ path: "/v1/agents/harnesses",
25
+ timeoutMs: 10000,
26
+ stretch: true,
27
+ scope: "agents:read",
28
+ };
29
+ const requestSelfDecisionOp = {
30
+ id: "agentsRequestSelfDecision",
31
+ method: "POST",
32
+ path: "/v1/agents/self/decide",
33
+ body: "json",
34
+ timeoutMs: 12000,
35
+ stretch: true,
36
+ scope: "authenticated",
37
+ };
38
+ const recordSelfEventsOp = {
39
+ id: "agentsRecordSelfEvents",
40
+ method: "POST",
41
+ path: "/v1/agents/self/events",
42
+ body: "json",
43
+ timeoutMs: 10000,
44
+ stretch: true,
45
+ scope: "authenticated",
46
+ };
47
+ const getSessionOp = {
48
+ id: "agentsGetSession",
49
+ method: "GET",
50
+ path: "/v1/agents/sessions/{session_id}",
51
+ params: ["session_id"],
52
+ timeoutMs: 10000,
53
+ scope: "agents:read",
54
+ };
55
+ const cancelSessionOp = {
56
+ id: "agentsCancelSession",
57
+ method: "POST",
58
+ path: "/v1/agents/sessions/{session_id}/cancel",
59
+ params: ["session_id"],
60
+ timeoutMs: 10000,
61
+ scope: "agents:run",
62
+ };
63
+ const sendDecisionOp = {
64
+ id: "agentsSendDecision",
65
+ method: "POST",
66
+ path: "/v1/agents/sessions/{session_id}/decisions",
67
+ params: ["session_id"],
68
+ body: "json",
69
+ timeoutMs: 10000,
70
+ stretch: true,
71
+ scope: "agents:run",
72
+ };
73
+ const streamSessionOp = {
74
+ id: "agentsStreamSession",
75
+ method: "GET",
76
+ path: "/v1/agents/sessions/{session_id}/events",
77
+ params: ["session_id"],
78
+ stream: "sse",
79
+ timeoutMs: 3600000,
80
+ scope: "agents:read",
81
+ };
82
+ const steerSessionOp = {
83
+ id: "agentsSteerSession",
84
+ method: "POST",
85
+ path: "/v1/agents/sessions/{session_id}/steer",
86
+ params: ["session_id"],
87
+ body: "json",
88
+ timeoutMs: 10000,
89
+ stretch: true,
90
+ scope: "agents:run",
91
+ };
92
+ const deleteAgentOp = {
93
+ id: "agentsDeleteAgent",
94
+ method: "DELETE",
95
+ path: "/v1/agents/{agent}",
96
+ params: ["agent"],
97
+ timeoutMs: 30000,
98
+ scope: "agents:write",
99
+ };
100
+ const getAgentOp = {
101
+ id: "agentsGetAgent",
102
+ method: "GET",
103
+ path: "/v1/agents/{agent}",
104
+ params: ["agent"],
105
+ timeoutMs: 10000,
106
+ scope: "agents:read",
107
+ };
108
+ const updateAgentOp = {
109
+ id: "agentsUpdateAgent",
110
+ method: "PATCH",
111
+ path: "/v1/agents/{agent}",
112
+ params: ["agent"],
113
+ body: "json",
114
+ timeoutMs: 10000,
115
+ scope: "agents:write",
116
+ };
117
+ const listInstancesOp = {
118
+ id: "agentsListInstances",
119
+ method: "GET",
120
+ path: "/v1/agents/{agent}/instances",
121
+ params: ["agent"],
122
+ timeoutMs: 10000,
123
+ scope: "agents:read",
124
+ };
125
+ const deleteInstanceOp = {
126
+ id: "agentsDeleteInstance",
127
+ method: "DELETE",
128
+ path: "/v1/agents/{agent}/instances/{key}",
129
+ params: ["agent", "key"],
130
+ timeoutMs: 30000,
131
+ scope: "agents:write",
132
+ };
133
+ const getInstanceOp = {
134
+ id: "agentsGetInstance",
135
+ method: "GET",
136
+ path: "/v1/agents/{agent}/instances/{key}",
137
+ params: ["agent", "key"],
138
+ timeoutMs: 10000,
139
+ scope: "agents:read",
140
+ };
141
+ const putInstanceOp = {
142
+ id: "agentsPutInstance",
143
+ method: "PUT",
144
+ path: "/v1/agents/{agent}/instances/{key}",
145
+ params: ["agent", "key"],
146
+ body: "json",
147
+ timeoutMs: 65000,
148
+ scope: "agents:run",
149
+ };
150
+ const sendInstanceDecisionOp = {
151
+ id: "agentsSendInstanceDecision",
152
+ method: "POST",
153
+ path: "/v1/agents/{agent}/instances/{key}/decisions",
154
+ params: ["agent", "key"],
155
+ body: "json",
156
+ timeoutMs: 10000,
157
+ stretch: true,
158
+ scope: "agents:run",
159
+ };
160
+ const listInstanceEventsOp = {
161
+ id: "agentsListInstanceEvents",
162
+ method: "GET",
163
+ path: "/v1/agents/{agent}/instances/{key}/events",
164
+ params: ["agent", "key"],
165
+ timeoutMs: 10000,
166
+ scope: "agents:read",
167
+ };
168
+ const listGrantsOp = {
169
+ id: "agentsListGrants",
170
+ method: "GET",
171
+ path: "/v1/agents/{agent}/instances/{key}/grants",
172
+ params: ["agent", "key"],
173
+ timeoutMs: 10000,
174
+ stretch: true,
175
+ scope: "agents:read",
176
+ };
177
+ const createGrantOp = {
178
+ id: "agentsCreateGrant",
179
+ method: "POST",
180
+ path: "/v1/agents/{agent}/instances/{key}/grants",
181
+ params: ["agent", "key"],
182
+ body: "json",
183
+ timeoutMs: 10000,
184
+ stretch: true,
185
+ scope: "agents:write",
186
+ };
187
+ const deleteGrantOp = {
188
+ id: "agentsDeleteGrant",
189
+ method: "DELETE",
190
+ path: "/v1/agents/{agent}/instances/{key}/grants/{grant_id}",
191
+ params: ["agent", "key", "grant_id"],
192
+ timeoutMs: 10000,
193
+ stretch: true,
194
+ scope: "agents:write",
195
+ };
196
+ const sleepInstanceOp = {
197
+ id: "agentsSleepInstance",
198
+ method: "POST",
199
+ path: "/v1/agents/{agent}/instances/{key}/sleep",
200
+ params: ["agent", "key"],
201
+ body: "json",
202
+ timeoutMs: 30000,
203
+ scope: "agents:run",
204
+ };
205
+ const streamInstanceOp = {
206
+ id: "agentsStreamInstance",
207
+ method: "GET",
208
+ path: "/v1/agents/{agent}/instances/{key}/stream",
209
+ params: ["agent", "key"],
210
+ stream: "sse",
211
+ timeoutMs: 3600000,
212
+ stretch: true,
213
+ scope: "agents:read",
214
+ };
215
+ const openTerminalOp = {
216
+ id: "agentsOpenTerminal",
217
+ method: "GET",
218
+ path: "/v1/agents/{agent}/instances/{key}/terminal",
219
+ params: ["agent", "key"],
220
+ stream: "ws",
221
+ timeoutMs: 3600000,
222
+ stretch: true,
223
+ scope: "agents:read",
224
+ };
225
+ const listRecordingsOp = {
226
+ id: "agentsListRecordings",
227
+ method: "GET",
228
+ path: "/v1/agents/{agent}/instances/{key}/terminal/recordings",
229
+ params: ["agent", "key"],
230
+ timeoutMs: 30000,
231
+ stretch: true,
232
+ scope: "agents:read",
233
+ };
234
+ const getRecordingOp = {
235
+ id: "agentsGetRecording",
236
+ method: "GET",
237
+ path: "/v1/agents/{agent}/instances/{key}/terminal/recordings/{recording_id}",
238
+ params: ["agent", "key", "recording_id"],
239
+ timeoutMs: 65000,
240
+ stretch: true,
241
+ scope: "agents:read",
242
+ };
243
+ const createTicketOp = {
244
+ id: "agentsCreateTicket",
245
+ method: "POST",
246
+ path: "/v1/agents/{agent}/instances/{key}/ticket",
247
+ params: ["agent", "key"],
248
+ timeoutMs: 5000,
249
+ stretch: true,
250
+ scope: "agents:read",
251
+ };
252
+ const listSessionsOp = {
253
+ id: "agentsListSessions",
254
+ method: "GET",
255
+ path: "/v1/agents/{agent}/sessions",
256
+ params: ["agent"],
257
+ timeoutMs: 10000,
258
+ scope: "agents:read",
259
+ };
260
+ const sendMessageOp = {
261
+ id: "agentsSendMessage",
262
+ method: "POST",
263
+ path: "/v1/agents/{agent}/instances/{key}/messages",
264
+ params: ["agent", "key"],
265
+ body: "json",
266
+ idem: true,
267
+ stream: "sse",
268
+ timeoutMs: 3600000,
269
+ scope: "agents:run",
270
+ job: { get: getSessionOp, events: streamSessionOp, cancel: cancelSessionOp },
271
+ };
272
+ /** Descriptors of every agents operation, keyed by method name (for tooling and custom clients). */
273
+ export const agentsOps = {
274
+ listAgents: listAgentsOp,
275
+ createAgent: createAgentOp,
276
+ listHarnesses: listHarnessesOp,
277
+ requestSelfDecision: requestSelfDecisionOp,
278
+ recordSelfEvents: recordSelfEventsOp,
279
+ getSession: getSessionOp,
280
+ cancelSession: cancelSessionOp,
281
+ sendDecision: sendDecisionOp,
282
+ streamSession: streamSessionOp,
283
+ steerSession: steerSessionOp,
284
+ deleteAgent: deleteAgentOp,
285
+ getAgent: getAgentOp,
286
+ updateAgent: updateAgentOp,
287
+ listInstances: listInstancesOp,
288
+ deleteInstance: deleteInstanceOp,
289
+ getInstance: getInstanceOp,
290
+ putInstance: putInstanceOp,
291
+ sendInstanceDecision: sendInstanceDecisionOp,
292
+ listInstanceEvents: listInstanceEventsOp,
293
+ listGrants: listGrantsOp,
294
+ createGrant: createGrantOp,
295
+ deleteGrant: deleteGrantOp,
296
+ sendMessage: sendMessageOp,
297
+ sleepInstance: sleepInstanceOp,
298
+ streamInstance: streamInstanceOp,
299
+ openTerminal: openTerminalOp,
300
+ listRecordings: listRecordingsOp,
301
+ getRecording: getRecordingOp,
302
+ createTicket: createTicketOp,
303
+ listSessions: listSessionsOp,
304
+ };
305
+ /**
306
+ * Actors: agent definitions, keyed instances (one microVM per key) and agent sessions; a message wakes its instance (`/v1/agents`).
307
+ */
308
+ export class AgentsAPI extends Namespace {
309
+ /**
310
+ * List agents
311
+ *
312
+ * Lists the project's agents, newest first.
313
+ *
314
+ * `GET /v1/agents` · scope `agents:read` · served by the node
315
+ */
316
+ listAgents(params, options) {
317
+ return this._client._list(listAgentsOp, { query: params }, options);
318
+ }
319
+ /**
320
+ * Create an agent
321
+ *
322
+ * Creates an agent: the definition every instance of it starts from. Nothing starts until the first message to
323
+ * a key (or `PUT /v1/agents/{agent}/instances/{key}`). `name` is unique in the project and is how the other
324
+ * operations name the agent (its `agt_` ID works too).
325
+ *
326
+ * `entry` is the harness: `command` runs in each instance, and the node delivers each message as a `POST` to
327
+ * `entry.port` and `entry.path` inside it. `api` is the grant each instance runs with, at most your own scopes:
328
+ * its `scopes`, its vault `connections` and its actions rule, whose packs it calls as MCP tools at
329
+ * `B3OS_MCP_URL`. `agents:write` is granted only when named exactly, so a harness changes its own memory and
330
+ * disk, never its definition. Instances belong to the project: revoking the key that created the agent does
331
+ * not stop them.
332
+ *
333
+ * Set `harness` instead of `entry` to run a coding agent people already use (opencode, the default; Codex; pi;
334
+ * Claude Code), unmodified (`AgentHarness`; planned, not served on the beta node yet). The node checks the
335
+ * block against the kind's entry in `GET /v1/agents/harnesses`, then fills `entry`, `source.template`, each
336
+ * `key` profile's credentials in `secrets` (as `B3OS_PROFILE_<NAME>__<VAR>`), and `api`, `egress` and
337
+ * `turns.timeout_s` where you leave them out. A request with both `entry` and `harness`, or neither, is `400
338
+ * invalid_request`. Until they are served on this node, `repo`, `context` and `acp` are refused even when
339
+ * empty, and so is every vault connection outside a credential profile (`repo.connection`, a remote `mcp`
340
+ * server's `connection`, a stdio server's `{connection}` values): `422 harness_capability_unsupported`.
341
+ *
342
+ * An agent with a `signin` profile in `harness.auth` is personal: its `owner` is the person who creates it,
343
+ * from their own dashboard session or CLI token (an API key, a sandbox or an instance gets `403
344
+ * harness_personal_agent`), and it never changes. A ChatGPT plan's sign-in (`provider: openai`) needs no flag.
345
+ * A Claude plan's (`provider: anthropic`) needs the `agents.claude_plan_signin` flag (`403
346
+ * harness_claude_plan_signin_disabled` without it). The node knows no person yet, so until the prerequisites
347
+ * `AgentHarnessAuthSignin` names land, every `signin` profile is `403 harness_personal_agent`.
348
+ *
349
+ * `POST /v1/agents` · scope `agents:write` · served by the node
350
+ */
351
+ createAgent(body, options) {
352
+ return this._client._call(createAgentOp, { body }, options);
353
+ }
354
+ /**
355
+ * List the harnesses this node runs
356
+ *
357
+ * The harnesses a `harness` block may name (`kind`), the open-source ones first (opencode, the default `kind`,
358
+ * then Codex and pi; Claude Code last), each with the versions this node runs, newest first, and the one a
359
+ * definition without `version` gets. A version is pinned in the node's `harness` template; a new
360
+ * upstream release becomes a new template revision and a new entry here, and a definition moves to it only when
361
+ * a `PATCH` changes its `version`.
362
+ *
363
+ * This answer is the catalog the harness's shim prints (`b3os-harness catalog --json`), stored with the
364
+ * `harness` template's build and served as it was printed, nothing added or left out: the shim's drivers are
365
+ * the source of truth for what each kind takes, and the node checks definitions against this answer. Each entry
366
+ * in `data` is what the kind's driver declares about itself: `driver` (`native`, built into the shim, or `acp`,
367
+ * the generic Agent Client Protocol adapter), `capabilities`, the credential profiles the kind takes (`auth`:
368
+ * the `key` providers with the variables each sets, the `signin` providers, and whether a model the node serves
369
+ * works), the lists of the block it takes (`setup`), and the `settings` keys the shim owns
370
+ * (`settings_refused`). `plan_env` names the variables no harness agent may set (`AgentHarnessPlanEnv`).
371
+ * `checks` is what the node and the shim refuse beyond each entry (`AgentHarnessCatalogChecks`), among them the
372
+ * default `mcp` and `skills` entries every definition's maps merge over (`checks.defaults`), so a client can
373
+ * check a recipe, and show its merged lists, before it deploys it. A feature not yet checked against a kind's
374
+ * pinned version is left out, and a definition that uses it is refused (`422 harness_capability_unsupported`).
375
+ * A definition that moves to a new version builds that revision's prepared snapshot again, at most
376
+ * `agents.prepare_concurrent` builds of an organization at once (planned, with prepared snapshots).
377
+ * Planned: not served on the beta node yet.
378
+ *
379
+ * `GET /v1/agents/harnesses` · scope `agents:read` · served by the node
380
+ *
381
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
382
+ */
383
+ listHarnesses(options) {
384
+ return this._client._call(listHarnessesOp, {}, options);
385
+ }
386
+ /**
387
+ * Ask the decide webhook from inside an instance
388
+ *
389
+ * How the harness's shim asks the definition's `hooks.decide` webhook a question while the turn waits, from
390
+ * inside the instance at `http://127.0.0.1:7700`. The node makes the call (`agentsDecideHarnessEvent`): it sets
391
+ * `harness`, `instance` and, when `session` is the session the instance runs now, `session_id` and `subject`
392
+ * from that session (any other `session` is dropped); it signs the call with `B3OS-Signature` and the URL's
393
+ * secret, sends it through the egress guard (private and loopback addresses refused), and answers with the
394
+ * decision. So the secret never enters the instance, and the decide host need not be in the instance's
395
+ * `egress`.
396
+ *
397
+ * The node applies the fail-closed rule itself and answers within `timeout_ms` (at most 10 seconds) plus its
398
+ * own overhead: no answer in time, a status other than 2xx, or a body without a `decision` answers
399
+ * `hooks.decide.on_timeout` (`deny` unless the definition sets `allow`) with `fallback: true`. The shim treats
400
+ * any answer other than `200`, and no answer, as `deny`. A question the definition does not send to the
401
+ * webhook is `400 invalid_request`: an agent without `hooks.decide`, a `type` its `events` does not select, and
402
+ * any question in `permissions: plan`, where the webhook is never called.
403
+ *
404
+ * Bound to the caller's own credential as `POST /v1/agents/self/events` is: the instance is the one whose
405
+ * token calls, and any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
406
+ * An instance asks at most `agents.self_decide_rate` questions a minute; past it the answer is `429
407
+ * rate_limited`, which the shim takes as `deny`, as it takes any answer but `200`. Planned: not served on the
408
+ * beta node yet.
409
+ *
410
+ * `POST /v1/agents/self/decide` · scope `authenticated` · served by the node
411
+ *
412
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
413
+ */
414
+ requestSelfDecision(body, options) {
415
+ return this._client._call(requestSelfDecisionOp, { body }, options);
416
+ }
417
+ /**
418
+ * Record harness events from inside an instance
419
+ *
420
+ * How the harness's shim records `harness.*` events that happened outside a delivered turn (a turn typed in the
421
+ * terminal or started inside the instance), from inside the instance at `http://127.0.0.1:7700`. The node writes them to the
422
+ * calling instance's event stream (`GET /v1/agents/{agent}/instances/{key}/stream`) and sends the ones the
423
+ * definition's `hooks.webhook` selects. Events of a delivered turn reach the session's stream as
424
+ * `session.output` instead and are not sent here.
425
+ *
426
+ * The route is bound to the caller's own credential: the node takes the instance from the token of the VM that
427
+ * calls. Each event is an `AgentSelfEvent`, which has none of the members the node owns: the node sets
428
+ * `instance`, `org` and `project` itself and assigns the log's own `seq`. An event with `seq`, `instance`,
429
+ * `org`, `project`, `session_id` or `subject` is `400 invalid_request`, and so is one whose `harness` is not the
430
+ * definition's kind; the whole request is refused and nothing in it is written. A self event never belongs to a
431
+ * session: the node never takes one as a session's result or as the answer to a question. No instance can write
432
+ * another's events. Any other caller, an API key included, gets `403 forbidden` with `reason: instance_only`.
433
+ * An event whose `id` the instance already recorded is counted in `duplicates` and not written again. An
434
+ * instance records at most `agents.self_events_rate` events a minute; past it the request is `429
435
+ * rate_limited` with `Retry-After` and nothing in it is written. Planned: not served on the beta node yet.
436
+ *
437
+ * `POST /v1/agents/self/events` · scope `authenticated` · served by the node
438
+ *
439
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
440
+ */
441
+ recordSelfEvents(body, options) {
442
+ return this._client._call(recordSelfEventsOp, { body }, options);
443
+ }
444
+ /**
445
+ * Get an agent session
446
+ *
447
+ * One turn: its status and phase, who sent it (`initiator`), its conversation, how its instance woke
448
+ * (`woke_from`), its trace and its timing. The message and the harness's answer are kept only for a session that
449
+ * was answered `202` (so you can read the result here, for 24 hours) or when the project's
450
+ * `platform.capture_content` setting is on. Sessions are kept 30 days after they end. A session of a personal
451
+ * agent (`Agent.owner`, planned) is read only by the agent's owner (`403 harness_personal_agent`).
452
+ *
453
+ * `GET /v1/agents/sessions/{session_id}` · scope `agents:read` · served by the node
454
+ */
455
+ getSession(sessionId, options) {
456
+ return this._client._call(getSessionOp, { path: [sessionId] }, options);
457
+ }
458
+ /**
459
+ * Cancel an agent session
460
+ *
461
+ * Cancels a turn. A queued session leaves the queue and is never delivered. A delivered one has its request into
462
+ * the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged. For
463
+ * an agent with a `harness` block (planned), the node first asks the harness to interrupt the turn (opencode's
464
+ * session interrupt, Codex's `turn/interrupt`, pi's `abort`, Claude Code's `interrupt`), so the turn ends
465
+ * `harness.turn.interrupted` with its usage so far, and the harness session stays open for the next turn. The
466
+ * harness's shim also stops the turn when the node closes the delivery, so a cancel that arrives before the
467
+ * harness has started the turn still stops it. On a personal agent only the owner cancels (`403
468
+ * harness_personal_agent`).
469
+ *
470
+ * `POST /v1/agents/sessions/{session_id}/cancel` · scope `agents:run` · served by the node
471
+ */
472
+ cancelSession(sessionId, options) {
473
+ return this._client._call(cancelSessionOp, { path: [sessionId] }, options);
474
+ }
475
+ /**
476
+ * Answer a harness's permission request
477
+ *
478
+ * Answers a question the turn waits on: a `harness.permission.requested` event (the harness asked a person,
479
+ * with `permissions: ask`, or `hooks.decide` answered `ask`). `request` is that event's `request`. `allow` lets
480
+ * the tool run; `deny` refuses it, and the harness carries on with the refusal and `reason`. The answer is
481
+ * recorded as `harness.permission.resolved` with `by: person`. A question nobody answers is denied when the turn
482
+ * reaches its timeout (`by: timeout`), and one still open when its turn ends is withdrawn (`by: withdrawn`). This
483
+ * answer is for this one call, and B3OS never picks a harness's own "always allow": an answer that should cover
484
+ * the rest of a conversation is a rule B3OS keeps for that conversation (planned), never the harness's own.
485
+ *
486
+ * A question of a turn that is not a session (typed in the terminal or started inside the instance) has no
487
+ * session to answer it through: its event has no `session_id`. Answer those, or any question of the instance, with
488
+ * `POST /v1/agents/{agent}/instances/{key}/decisions`, which the live view uses for every question.
489
+ *
490
+ * Claude Code in `terminal` mode asks its own permission prompts in its TUI (with `permissions: ask`), and they
491
+ * are answered there, by whoever controls the terminal: such a `harness.permission.requested` carries no
492
+ * `request`, and no `…/decisions` route can answer it. `hooks.decide` still answers before the TUI asks.
493
+ *
494
+ * A question already answered (by you, another caller, the turn's end or its timeout), or one this session
495
+ * never asked, answers `404 decision_not_found`; an ended session answers `409 no_turn_running`. On a personal
496
+ * agent only the owner answers (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
497
+ * harness_required`). Planned: not served on the beta node yet.
498
+ *
499
+ * `POST /v1/agents/sessions/{session_id}/decisions` · scope `agents:run` · served by the node
500
+ *
501
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
502
+ */
503
+ sendDecision(sessionId, body, options) {
504
+ return this._client._call(sendDecisionOp, { path: [sessionId], body }, options);
505
+ }
506
+ /**
507
+ * Stream an agent session's events
508
+ *
509
+ * Server-sent events for one turn: `job.queued` when it was accepted, `session.waking` when its instance began
510
+ * to wake (with `woke_from`), `session.delivered` when the harness received it, `session.output` for each event
511
+ * the harness streamed back (when it answered with `text/event-stream`), and the terminal `job.succeeded`,
512
+ * `job.failed` or `job.canceled`, which carries the final session and ends the stream. Reconnect with
513
+ * `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone. A
514
+ * session of a personal agent (`Agent.owner`, planned) is streamed only by the agent's owner, since its
515
+ * `session.output` carries the turn's `harness.*` events (`403 harness_personal_agent`).
516
+ *
517
+ * `GET /v1/agents/sessions/{session_id}/events` · scope `agents:read` · served by the node
518
+ */
519
+ streamSession(sessionId, options) {
520
+ return this._client._stream(streamSessionOp, { path: [sessionId] }, options, {
521
+ terminal: isTerminalJobEvent,
522
+ reconnectOnEnd: true,
523
+ });
524
+ }
525
+ /**
526
+ * Steer a running harness turn
527
+ *
528
+ * Adds `text` to the turn while it runs, past the instance's queue: the harness reads it at its next step
529
+ * (opencode as a `steer` prompt, Codex with `turn/steer`, pi with `steer`, Claude Code as a user message on its
530
+ * input). The session's stream shows it as `harness.turn.started` with `source: steer`. Only for an agent
531
+ * with a `harness` block (`409 harness_required` otherwise), and only while the session is delivered and
532
+ * running: a queued or ended session answers `409 no_turn_running`. A steer that arrives after delivery but
533
+ * before the harness has started the turn is held by the harness's shim and given to the turn as it starts. To
534
+ * start a new turn, send a message. A harness that refuses the text answers `502 harness_error`, and a kind
535
+ * whose driver cannot steer (`capabilities.steer: false` in `GET /v1/agents/harnesses`) answers `422
536
+ * harness_capability_unsupported`. On a personal agent only the owner steers (`403 harness_personal_agent`).
537
+ * Planned: not served on the beta node yet.
538
+ *
539
+ * `POST /v1/agents/sessions/{session_id}/steer` · scope `agents:run` · served by the node
540
+ *
541
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
542
+ */
543
+ steerSession(sessionId, body, options) {
544
+ return this._client._call(steerSessionOp, { path: [sessionId], body }, options);
545
+ }
546
+ /**
547
+ * Delete an agent
548
+ *
549
+ * Deletes the agent and every instance of it: their microVMs, memory snapshots and disks, with any sign-in
550
+ * made in them. Their sessions stay readable until they expire. A personal agent is deleted by its owner or an
551
+ * organization admin (`403 harness_personal_agent` for anyone else).
552
+ *
553
+ * `DELETE /v1/agents/{agent}` · scope `agents:write` · served by the node
554
+ */
555
+ deleteAgent(agent, options) {
556
+ return this._client._call(deleteAgentOp, { path: [agent] }, options);
557
+ }
558
+ /**
559
+ * Get an agent
560
+ *
561
+ * The agent, by name or `agt_` ID, with its current revision and how many instances it has. A harness agent
562
+ * (planned) also has its `harness` block as the node stored it (shorthands expanded, `mcp` and `skills` as
563
+ * written, so it can be sent back as it is; the merged lists are those maps over `checks.defaults` in `GET
564
+ * /v1/agents/harnesses`), its `owner`, the state of its revision's prepared snapshot (`harness_prepared`), and
565
+ * its `entry`, `source`, `api`, `egress` and `turns` show what the node filled in from it.
566
+ *
567
+ * `GET /v1/agents/{agent}` · scope `agents:read` · served by the node
568
+ */
569
+ getAgent(agent, options) {
570
+ return this._client._call(getAgentOp, { path: [agent] }, options);
571
+ }
572
+ /**
573
+ * Update an agent
574
+ *
575
+ * Changes the definition and makes a new revision. `upgrade` says what happens to instances of earlier
576
+ * revisions: `new_instances` (the default) leaves them on the revision they were made from, so their memory
577
+ * and disk stay as they are, and only new instances take the change; `on_wake` makes a sleeping instance of an
578
+ * earlier revision again from this one at its next wake, which ends its memory and disk. `name` cannot change.
579
+ * The grant is checked again against your own scopes.
580
+ *
581
+ * `harness` (planned) replaces the whole block, as `entry` does; a harness is pinned to the revision, so a new
582
+ * `version` reaches an instance only through `upgrade: on_wake`, and only once the new revision's prepared
583
+ * snapshot is ready. `on_wake` remakes the instance, so its sign-ins and its harness sessions end with its disk.
584
+ * A change to start-time members only (`instructions`, `settings`, `mcp` entries, `files`, `auth`, `model`,
585
+ * `permissions` and the like) keeps the revision's prepare key, so nothing is built again. An agent made with
586
+ * `entry` cannot take a `harness`, and a harness agent cannot take an `entry` (`400 invalid_request`): make
587
+ * another agent.
588
+ *
589
+ * Only the owner changes a personal agent (`403 harness_personal_agent`). Adding a `signin` profile to an agent
590
+ * that is not personal is `409 harness_signin_not_personal`: make a personal agent from the same block
591
+ * instead.
592
+ *
593
+ * `PATCH /v1/agents/{agent}` · scope `agents:write` · served by the node
594
+ */
595
+ updateAgent(agent, body, options) {
596
+ return this._client._call(updateAgentOp, { path: [agent], body }, options);
597
+ }
598
+ /**
599
+ * List an agent's instances
600
+ *
601
+ * Lists the agent's instances, most recently messaged first. Filter by `status`.
602
+ *
603
+ * `GET /v1/agents/{agent}/instances` · scope `agents:read` · served by the node
604
+ */
605
+ listInstances(agent, params, options) {
606
+ return this._client._list(listInstancesOp, { path: [agent], query: params }, options);
607
+ }
608
+ /**
609
+ * Delete an instance
610
+ *
611
+ * Deletes the instance: its microVM, its memory snapshot and its disk. Queued messages end `canceled` and are
612
+ * never delivered. This and deleting the agent are the only ways an instance ends; idleness never does. The
613
+ * next message to the key makes a new instance unless it sends `create: false`. An instance of a personal agent
614
+ * (`Agent.owner`, planned), with any sign-in made in it, is deleted by the agent's owner or an organization
615
+ * admin (`403 harness_personal_agent` for anyone else).
616
+ *
617
+ * `DELETE /v1/agents/{agent}/instances/{key}` · scope `agents:write` · served by the node
618
+ */
619
+ deleteInstance(agent, key, options) {
620
+ return this._client._call(deleteInstanceOp, { path: [agent, key] }, options);
621
+ }
622
+ /**
623
+ * Get an instance
624
+ *
625
+ * The instance for `key`: its status (`running`, `paused` in memory, `hibernated` as a memory snapshot,
626
+ * `dormant` on its disk alone), the host memory it holds now (`resident_mib`), the disk it holds on the node
627
+ * (`storage_bytes`), how many messages wait in its queue, and when it last got a message and went to sleep.
628
+ *
629
+ * `GET /v1/agents/{agent}/instances/{key}` · scope `agents:read` · served by the node
630
+ */
631
+ getInstance(agent, key, options) {
632
+ return this._client._call(getInstanceOp, { path: [agent, key] }, options);
633
+ }
634
+ /**
635
+ * Get or create an instance
636
+ *
637
+ * The instance for `key`, made if it does not exist: `201` when this request made it (its microVM started and
638
+ * its harness passed readiness), `200` when it existed. An existing instance is not woken unless `wake: true`.
639
+ * `replace: true` deletes an existing instance (its memory, snapshot and disk) and makes it again from the
640
+ * agent's current revision. Two requests for a new key at once make one instance.
641
+ *
642
+ * Each instance is its own microVM: instances of different keys never share one. The key is stored and shown as
643
+ * written, so never use a credential or a personal detail as a key. Only the owner makes or wakes an instance
644
+ * of a personal agent (`403 harness_personal_agent`).
645
+ *
646
+ * `PUT /v1/agents/{agent}/instances/{key}` · scope `agents:run` · served by the node
647
+ */
648
+ putInstance(agent, key, body, options) {
649
+ return this._client._call(putInstanceOp, { path: [agent, key], body }, options);
650
+ }
651
+ /**
652
+ * Answer any permission request of an instance
653
+ *
654
+ * Answers a question the instance's harness waits on, whichever way its turn came: a message (a session), or a
655
+ * turn typed in the terminal or started inside the instance. The body, the answer and the errors are those of
656
+ * `POST /v1/agents/sessions/{session_id}/decisions`; `request` is unique per instance, so this route answers
657
+ * any question of the instance, a session's included. The live view answers every question here, since an event
658
+ * without `session_id` has no session to answer through. The answer is recorded as
659
+ * `harness.permission.resolved` with `by: person`.
660
+ *
661
+ * Claude Code's own permission prompts in `terminal` mode are answered in its TUI, not here (their
662
+ * `harness.permission.requested` carries no `request`).
663
+ *
664
+ * A question of a session is denied when its turn reaches its timeout; one of a turn without a session is denied
665
+ * after an hour (the most a turn may take). A question still open when its turn ends is withdrawn
666
+ * (`harness.permission.resolved` with `by: withdrawn`). A question already answered, or one the instance never
667
+ * asked, answers `404 decision_not_found`. On a personal agent only the owner answers (`403
668
+ * harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`). Planned: not
669
+ * served on the beta node yet.
670
+ *
671
+ * `POST /v1/agents/{agent}/instances/{key}/decisions` · scope `agents:run` · served by the node
672
+ *
673
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
674
+ */
675
+ sendInstanceDecision(agent, key, body, options) {
676
+ return this._client._call(sendInstanceDecisionOp, { path: [agent, key], body }, options);
677
+ }
678
+ /**
679
+ * List an instance's lifecycle events
680
+ *
681
+ * What happened to the instance, newest first: `instance.created`, `instance.paused`, `instance.hibernated`,
682
+ * `instance.dormant`, `instance.woke` (with `woke_from`), `instance.failed`, `instance.recovered` (with
683
+ * `woke_from`: from its memory snapshot, which takes memory and disk back to the snapshot's time together,
684
+ * from its disk, with memory lost, or `new`, when its disk was gone too) and `instance.upgraded`. The last 200
685
+ * are kept.
686
+ *
687
+ * `GET /v1/agents/{agent}/instances/{key}/events` · scope `agents:read` · served by the node
688
+ */
689
+ listInstanceEvents(agent, key, params, options) {
690
+ return this._client._list(listInstanceEventsOp, { path: [agent, key], query: params }, options);
691
+ }
692
+ /**
693
+ * List an instance's grants
694
+ *
695
+ * The instance's grants that have not ended, newest first, without their tokens (`token` and `url` are
696
+ * `null`). A personal agent's grants are listed by its owner or an organization admin (`403
697
+ * harness_personal_agent` for anyone else). Planned: not served on the beta node yet.
698
+ *
699
+ * `GET /v1/agents/{agent}/instances/{key}/grants` · scope `agents:read` · served by the node
700
+ *
701
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
702
+ */
703
+ listGrants(agent, key, params, options) {
704
+ return this._client._list(listGrantsOp, { path: [agent, key], query: params }, options);
705
+ }
706
+ /**
707
+ * Share an instance's terminal by link
708
+ *
709
+ * Mints a grant: a link that opens this instance's live view and terminal for whoever holds it, without a B3OS
710
+ * account. `watch` shows the event stream and the terminal, view-only; `control` also types into the terminal
711
+ * when nobody else holds control, and never takes it over. The link carries its token in the URL fragment
712
+ * (`#token=`), which browsers never send to a server, so it stays out of every log on the way; the share page
713
+ * redeems it (`agentsRedeemGrant`). `token` and `url` are in this answer only: B3OS keeps a hash of the token.
714
+ *
715
+ * A grant ends at `expires_at` (`ttl_s`, 900 seconds by default, at most 3,600), after `uses` redemptions when
716
+ * set, when it is revoked (`DELETE …/grants/{grant_id}`), or when the instance is deleted; revoking it closes
717
+ * the sockets opened with it. The share page redeems the link again each time it reconnects, and each
718
+ * redemption counts one of `uses`: leave `uses` out, or set it to cover the reconnects you expect. An instance
719
+ * has at most `agents.grants_max` grants that have not ended; one more is `422 limit_exceeded`. On a personal
720
+ * agent only the owner mints grants, and only `watch` ones (`403 harness_personal_agent`): a `watch` grant never
721
+ * shows the sign-in window. Only for an agent with a `harness` block (`409 harness_required`). Planned: not
722
+ * served on the beta node yet.
723
+ *
724
+ * `POST /v1/agents/{agent}/instances/{key}/grants` · scope `agents:write` · served by the node
725
+ *
726
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
727
+ */
728
+ createGrant(agent, key, body, options) {
729
+ return this._client._call(createGrantOp, { path: [agent, key], body }, options);
730
+ }
731
+ /**
732
+ * Revoke a grant
733
+ *
734
+ * Ends the grant: its link stops working, and the terminal and event-stream sockets opened with it close.
735
+ * Revoking a grant that already ended answers `404 grant_not_found`. A personal agent's grants are revoked by its
736
+ * owner or an organization admin (`403 harness_personal_agent` for anyone else). Planned: not served on the beta
737
+ * node yet.
738
+ *
739
+ * `DELETE /v1/agents/{agent}/instances/{key}/grants/{grant_id}` · scope `agents:write` · served by the node
740
+ *
741
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
742
+ */
743
+ deleteGrant(agent, key, grantId, options) {
744
+ return this._client._call(deleteGrantOp, { path: [agent, key, grantId] }, options);
745
+ }
746
+ /**
747
+ * Send a message to an instance
748
+ *
749
+ * Sends one message to the instance for `key` and starts a session (one turn). The instance is made if it does
750
+ * not exist, unless `create: false`; a sleeping one is woken, from memory, from its memory snapshot or from its
751
+ * disk (`woke_from`). Nobody calls resume.
752
+ *
753
+ * The message is written to disk before any answer. With `?wait=0` (the default) the answer is `202` with the
754
+ * session `queued` right after that write, before the instance wakes or the turn runs: from then on the message
755
+ * is not lost when the node's daemon restarts. With `?wait=N` the answer waits up to N seconds for the turn;
756
+ * with `Accept: text/event-stream` it streams the session's events, the harness's own streamed events among
757
+ * them (`session.output`). A `200` carries the harness's answer as `result` (its JSON body, or its text).
758
+ *
759
+ * An instance runs one turn at a time. A message that arrives during a turn waits in the instance's queue, in
760
+ * order, up to the agent's `turns.queue_max`; past it the answer is `429 instance_busy` with `Retry-After`, and
761
+ * nothing was queued. Retry with the same `Idempotency-Key`: a retry within 24 hours returns the first answer
762
+ * and never queues the message twice.
763
+ *
764
+ * The node delivers the message as a `POST` to the agent's `entry.port` and `entry.path` inside the instance,
765
+ * with the JSON body `{session, message, conversation, subject, initiator}` and the headers `traceparent`,
766
+ * `baggage` and `x-b3os-session`. `message` is your request body without the reserved members. A 2xx answer
767
+ * ends the session `succeeded`; any other ends it `failed` with `harness_error`. A message is delivered into
768
+ * the harness at most once: if the node restarts while the harness has it, the session ends `failed` with
769
+ * `session_interrupted`, unless the agent sets `turns.redeliver: true`.
770
+ *
771
+ * `conversation` and `subject` are taken from the body, else from the `b3os.conversation` and `b3os.subject`
772
+ * baggage that `b3.traces.turn` sends. `initiator` (the key, dashboard user, sandbox, instance, routine run or
773
+ * listener that sent the message) is taken from the credential, never from the body. A message whose key is
774
+ * revoked before it is delivered ends `failed` with `credential_revoked`. Code in an instance cannot message
775
+ * that same instance (`409 instance_self_message`).
776
+ *
777
+ * `Server-Timing` and the session's `timing` split the turn into `queue`, `wake` (`desc` names the tier),
778
+ * `deliver` and `harness`.
779
+ *
780
+ * For an agent with a `harness` block (planned), `text` is the prompt and `context` (optional) is added before
781
+ * the model sees it, quoted as information rather than an instruction. `conversation` names the harness's own
782
+ * session (an opencode session, a Codex thread, a pi session file, a Claude Code session): the first message of
783
+ * a new `conversation` starts a new harness session, and later ones continue it. `profile` picks one of the
784
+ * definition's credential profiles for this turn and the conversation's next ones (`harness.auth`); a name the
785
+ * definition does not have is `400 harness_profile_unknown`. A harness agent's message is closed: a member
786
+ * other than the reserved ones, `text`, `context`, `profile` and a listener's `event` is `400
787
+ * invalid_request`, so a field the harness would not read is refused rather than dropped. `text` is required,
788
+ * but in a listener's message (`type: listener.event`), which carries `event` instead and which the harness is
789
+ * to see quoted whole as information; until the harness's shim quotes it, a `listener.event` message to a
790
+ * harness agent is `422 harness_capability_unsupported`, and `event` in any other message is `400
791
+ * invalid_request`. Each
792
+ * `session.output` carries one `AgentHarnessEvent`, as the node wrote it to the instance's event log, and the
793
+ * turn's `result` is `harness.turn.completed`'s `result`. The session ends `succeeded` at
794
+ * `harness.turn.completed`, `canceled` at `harness.turn.interrupted`, and `failed` with `harness_error` at
795
+ * `harness.turn.failed` or when the harness's stream ends without one of the three, or with
796
+ * `harness_prepare_failed` when the revision's prepared snapshot could not be built.
797
+ *
798
+ * A personal agent (`Agent.owner`) takes messages only from its owner's own principals (their dashboard
799
+ * session, their CLI token, and routines they made); anyone else, and every listener, gets `403
800
+ * harness_personal_agent`.
801
+ *
802
+ * `POST /v1/agents/{agent}/instances/{key}/messages` · scope `agents:run` · served by the node
803
+ */
804
+ sendMessage(agent, key, body, options) {
805
+ return this._client._job(sendMessageOp, { path: [agent, key], body }, options);
806
+ }
807
+ /**
808
+ * Put an instance to sleep now
809
+ *
810
+ * Sends the instance to a sleep tier now instead of waiting for its timers: `ram` pauses it, `snapshot` writes
811
+ * its memory snapshot and frees its memory (an instance with a volume answers `409 volume_attached` and stays as
812
+ * it was). The snapshot's write takes longer the more memory the instance has (seconds to minutes for 4 GiB on
813
+ * a slow drive), and the call does not wait for all of it: it answers `200` with the instance `hibernated` when
814
+ * the write is done within about 2 seconds, else `202` with the instance `paused` and the write going on. It
815
+ * reads `hibernated` once the write is committed; a write that fails leaves it `paused`, and its timers try the
816
+ * snapshot again later. A harness may call this on its own instance when it knows it is done
817
+ * (from inside, at `http://127.0.0.1:7700`); the pause then happens once its current turn ends. An instance with
818
+ * a turn running or messages queued goes to sleep after them. Asleep already in that tier or a deeper one:
819
+ * returned unchanged. An instance of a personal agent (`Agent.owner`, planned) is put to sleep by the agent's
820
+ * owner or by itself, from inside (`403 harness_personal_agent` for anyone else).
821
+ *
822
+ * `POST /v1/agents/{agent}/instances/{key}/sleep` · scope `agents:run` · served by the node
823
+ */
824
+ sleepInstance(agent, key, body, options) {
825
+ return this._client._call(sleepInstanceOp, { path: [agent, key], body }, options);
826
+ }
827
+ /**
828
+ * Stream an instance's harness events
829
+ *
830
+ * Server-sent events: every `harness.*` event of the instance, whichever way its turn came (a message, a turn
831
+ * typed in the terminal or started inside the instance, a steer), as `AgentHarnessEvent`s. This is what the live view reads.
832
+ * Each event's SSE `id` is its `seq`, which the node assigns as it writes the event to the instance's log, so it
833
+ * keeps growing when the harness's shim restarts; reconnect with `Last-Event-ID` to resume after it. Events are
834
+ * kept 7 days for replay, as every product event is, and at most `agents.harness_event_log_mib` per instance,
835
+ * past which the oldest go first; a stream that resumes past what is kept starts from the oldest kept event.
836
+ * `harness.message` events with `delta: true` get a `seq` too, but are streamed and never kept. The node
837
+ * serves the stream from its own copy of the events, so opening it neither wakes the instance nor keeps it
838
+ * awake.
839
+ *
840
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
841
+ * grant's from `agentsRedeemGrant`). On a personal agent, only the owner and the owner's `watch` grants read
842
+ * it (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409 harness_required`).
843
+ * Planned: not served on the beta node yet.
844
+ *
845
+ * `GET /v1/agents/{agent}/instances/{key}/stream` · scope `agents:read` · served by the node
846
+ *
847
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
848
+ */
849
+ streamInstance(agent, key, options) {
850
+ return this._client._stream(streamInstanceOp, { path: [agent, key] }, options, {});
851
+ }
852
+ /**
853
+ * Open a harness's terminal
854
+ *
855
+ * Opens the harness's terminal over a WebSocket: the harness's own TUI in `terminal` mode, a shell in the
856
+ * workspace in `api` mode (the live view shows the events beside it). tmux in the instance holds the terminal,
857
+ * so it outlives every socket and a restart of the harness's shim. The node reaches it through the instance's
858
+ * port proxy: opening it wakes a sleeping instance, and an open socket keeps the instance awake. When the last
859
+ * socket closes and the harness is idle, the instance sleeps on its timers with the terminal paused in memory.
860
+ *
861
+ * The wire is the sandbox terminal's (`sandboxesOpenPty`) with a cursor added. Binary frames carry terminal
862
+ * bytes both ways; input counts only from the controller. Text frames carry JSON. The server's first frame is
863
+ * `{"type": "session", "id": "pts_…", "resumed": true, "cursor": 1048576, "role": "view", "cols": 120, "rows":
864
+ * 40}`, then one binary frame with what the socket missed, then live output. The client sends `{"type":
865
+ * "resize", "cols", "rows"}` (controller only), `{"type": "control"}` to ask for control, `{"type": "release"}`,
866
+ * and `{"type": "end"}` (controller only: ends the terminal, and the TUI with it). The server sends `{"type":
867
+ * "role", "role", "reason"}` when this socket's role changes, `{"type": "error", "code": "controller_active"}`
868
+ * when another socket holds control, and `{"type": "exit", "code"}` before it closes.
869
+ *
870
+ * One controller, any number of viewers. `role=control` takes control when nobody holds it, and needs
871
+ * `agents:run` besides this operation's `agents:read`; when another socket holds it, this one opens as `view`
872
+ * (its first frame says so). Only the agent's owners take control from the holder, with `{"type": "control",
873
+ * "takeover": true}`: a credential that holds `agents:write`, never a grant. The holder stays as a viewer and
874
+ * gets `{"type": "role", "role": "view", "reason": "taken over"}`.
875
+ *
876
+ * Reconnect where you left off: the terminal's output is kept in a 1 MiB ring indexed by byte offset. Send the
877
+ * `session` and the `cursor` (the session frame's `cursor` plus the bytes received since), and the socket
878
+ * replays the bytes it missed. Past the ring, or when the terminal was started again (another `session`), it
879
+ * draws the current screen and goes on live. A socket lasts at most an hour; reconnect with the cursor.
880
+ *
881
+ * Every attach and detach is a `harness.terminal.attached` or `harness.terminal.detached` event. With
882
+ * `harness.terminal.record`, the terminal is also written as a recording (`…/terminal/recordings`).
883
+ * Authenticate with the `Authorization` header, the dashboard session, or a ticket (`POST …/ticket`, or a
884
+ * grant's from `agentsRedeemGrant`) as `?ticket=` or the `b3os.ticket.<ticket>` subprotocol. Only for an agent
885
+ * with a `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
886
+ *
887
+ * The sign-in window (`window=signin:<profile>`) is where a personal agent's owner signs in to their own plan
888
+ * for a `signin` profile: the harness's own login runs there (`codex login --device-auth`, `claude auth login`;
889
+ * a kind signs in only to the plans its `auth.signin` in `GET /v1/agents/harnesses` lists), under that profile's
890
+ * directory, and writes the harness's own credential file in the instance. B3OS never reads that file, and the
891
+ * shim reports only that it exists (`harness.auth.ready`, with what the harness says about its plan). The
892
+ * sign-out window (`window=signout:<profile>`) runs the harness's own logout for the profile the same way, and
893
+ * `harness.auth.removed` (`reason: signed_out`) says when the file is gone. Either window opens only for the
894
+ * owner, on a `signin` profile of the definition (`403 harness_personal_agent` or `400 harness_profile_unknown`
895
+ * otherwise), and a sign-in to a Claude plan's profile (`provider: anthropic`) only with
896
+ * `agents.claude_plan_signin` on (`403 harness_claude_plan_signin_disabled`); a sign-out needs no flag. It is
897
+ * never sent to a viewer or a grant's socket, it is never recorded, and what it showed is dropped when it
898
+ * closes. On a personal agent the main window too is the owner's: others see it only through a `watch` grant,
899
+ * and `control` grants are refused. Until personal agents are served (`AgentHarnessAuthSignin` names what they
900
+ * wait on), no agent has a `signin` profile, so neither window opens.
901
+ *
902
+ * The node opens the shim's terminal with the shim's token in place of your credential, and says what it
903
+ * checked in headers only it may set (`x-b3os-window`, `x-b3os-takeover`), which it removes from every request
904
+ * it forwards (packages/spec/sidecars/harness.md).
905
+ *
906
+ * `GET /v1/agents/{agent}/instances/{key}/terminal` · scope `agents:read` · served by the node
907
+ *
908
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
909
+ */
910
+ async openTerminal(agent, key, params, options = {}) {
911
+ const { url, protocols } = await ticketedUrl(this._client, openTerminalOp, createTicketOp, { path: [agent, key], query: params }, options, false);
912
+ return new PtySession(await openSocket(url, protocols, options.signal));
913
+ }
914
+ /**
915
+ * List an instance's terminal recordings
916
+ *
917
+ * The instance's terminal recordings, newest first. A terminal is recorded only when the definition sets
918
+ * `harness.terminal.record: true`; it is off by default, because a recording keeps whatever the terminal showed,
919
+ * codes and keys printed in it included. Each start of a conversation's terminal begins a new recording, an
920
+ * asciicast v3 file on the instance's own disk with one header, with a marker (`m`) at each `harness.*` event
921
+ * but `harness.message`, so a player can jump to a turn. One that reaches 64 MiB while it is written is closed
922
+ * and the next one begins; a conversation keeps its current recording and the one before it. Deleting the
923
+ * instance deletes them. The node reads them from the harness's shim through the instance's port, so reading
924
+ * the list wakes the instance as a port request does. The sign-in window is never recorded. On a personal agent
925
+ * only the owner reads them (`403 harness_personal_agent`). Only for an agent with a `harness` block (`409
926
+ * harness_required`). Planned: not served on the beta node yet.
927
+ *
928
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings` · scope `agents:read` · served by the node
929
+ *
930
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
931
+ */
932
+ listRecordings(agent, key, params, options) {
933
+ return this._client._list(listRecordingsOp, { path: [agent, key], query: params }, options);
934
+ }
935
+ /**
936
+ * Download a terminal recording
937
+ *
938
+ * The recording as an asciicast v3 file (`application/x-asciicast`, one JSON value per line): a header, then
939
+ * `[seconds since the previous event, code, data]` with codes `o` (output), `r` (resize, `"COLSxROWS"`), `m`
940
+ * (a marker, the `harness.*` event's type) and `x` (exit status). Input is never recorded. asciinema 3 plays
941
+ * it. Planned: not served on the beta node yet.
942
+ *
943
+ * `GET /v1/agents/{agent}/instances/{key}/terminal/recordings/{recording_id}` · scope `agents:read` · served by the node
944
+ *
945
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
946
+ */
947
+ getRecording(agent, key, recordingId, options) {
948
+ return this._client._call(getRecordingOp, { path: [agent, key, recordingId] }, options, "*/*", "bytes");
949
+ }
950
+ /**
951
+ * Create a stream ticket for an instance
952
+ *
953
+ * Returns a single-use ticket, valid for 30 seconds, that opens one stream of this instance without a bearer
954
+ * header: its terminal (`GET …/terminal`) or its event stream (`GET …/stream`). Pass it as `?ticket=` or in
955
+ * `Sec-WebSocket-Protocol: b3os.v1, b3os.ticket.<ticket>`. The stream runs with this caller's scopes, so a
956
+ * terminal opened with it takes control only when the caller holds `agents:run`.
957
+ *
958
+ * The ticket's `resource` is this request's own path without `/ticket`, exactly as it was sent: the agent as you
959
+ * named it (its name or its `agt_` ID) and the key percent-encoded as in the request. A ticket is matched
960
+ * against the stream's path as sent, so open the stream with the same form: a ticket minted under the agent's
961
+ * name does not open its stream under its ID. On a personal agent only the owner mints tickets (`403
962
+ * harness_personal_agent`): others watch through a `watch` grant the owner shares. Only for an agent with a
963
+ * `harness` block (`409 harness_required`). Planned: not served on the beta node yet.
964
+ *
965
+ * `POST /v1/agents/{agent}/instances/{key}/ticket` · scope `agents:read` · served by the node
966
+ *
967
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
968
+ */
969
+ createTicket(agent, key, options) {
970
+ return this._client._call(createTicketOp, { path: [agent, key] }, options);
971
+ }
972
+ /**
973
+ * List an agent's sessions
974
+ *
975
+ * Lists the agent's sessions, newest first. Filter by instance `key`, by `conversation` (the ID you sent with the
976
+ * message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`. A personal agent's sessions
977
+ * (`Agent.owner`, planned) are listed only for its owner (`403 harness_personal_agent`).
978
+ *
979
+ * `GET /v1/agents/{agent}/sessions` · scope `agents:read` · served by the node
980
+ */
981
+ listSessions(agent, params, options) {
982
+ return this._client._list(listSessionsOp, { path: [agent], query: params }, options);
983
+ }
984
+ }
985
+ //# sourceMappingURL=agents.js.map