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