@b3os/sdk 0.2.0 → 0.2.2
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.
- package/dist/cjs/core/sse.d.ts +2 -0
- package/dist/cjs/core/sse.js +17 -5
- package/dist/cjs/core/sse.js.map +1 -1
- package/dist/cjs/core/util.d.ts +1 -1
- package/dist/cjs/core/util.js +1 -1
- package/dist/cjs/generated/client.d.ts +13 -0
- package/dist/cjs/generated/client.js +25 -0
- package/dist/cjs/generated/client.js.map +1 -1
- package/dist/cjs/generated/errors.d.ts +1 -1
- package/dist/cjs/generated/errors.js +95 -0
- package/dist/cjs/generated/errors.js.map +1 -1
- package/dist/cjs/generated/ids.d.ts +61 -0
- package/dist/cjs/generated/ids.js +15 -0
- package/dist/cjs/generated/ids.js.map +1 -1
- package/dist/cjs/generated/jobs.js +4 -0
- package/dist/cjs/generated/jobs.js.map +1 -1
- package/dist/cjs/generated/ns/actions.d.ts +303 -4
- package/dist/cjs/generated/ns/actions.js +446 -4
- package/dist/cjs/generated/ns/actions.js.map +1 -1
- package/dist/cjs/generated/ns/agents.d.ts +229 -0
- package/dist/cjs/generated/ns/agents.js +402 -0
- package/dist/cjs/generated/ns/agents.js.map +1 -0
- package/dist/cjs/generated/ns/images.d.ts +81 -0
- package/dist/cjs/generated/ns/images.js +122 -0
- package/dist/cjs/generated/ns/images.js.map +1 -0
- package/dist/cjs/generated/ns/infer.d.ts +71 -3
- package/dist/cjs/generated/ns/infer.js +98 -3
- package/dist/cjs/generated/ns/infer.js.map +1 -1
- package/dist/cjs/generated/ns/keys.d.ts +3 -1
- package/dist/cjs/generated/ns/keys.js +3 -1
- package/dist/cjs/generated/ns/keys.js.map +1 -1
- package/dist/cjs/generated/ns/listeners.d.ts +159 -0
- package/dist/cjs/generated/ns/listeners.js +264 -0
- package/dist/cjs/generated/ns/listeners.js.map +1 -0
- package/dist/cjs/generated/ns/orgs.d.ts +10 -0
- package/dist/cjs/generated/ns/orgs.js +26 -1
- package/dist/cjs/generated/ns/orgs.js.map +1 -1
- package/dist/cjs/generated/ns/projects.d.ts +32 -0
- package/dist/cjs/generated/ns/projects.js +66 -0
- package/dist/cjs/generated/ns/projects.js.map +1 -1
- package/dist/cjs/generated/ns/render.d.ts +192 -21
- package/dist/cjs/generated/ns/render.js +267 -24
- package/dist/cjs/generated/ns/render.js.map +1 -1
- package/dist/cjs/generated/ns/requests.d.ts +3 -1
- package/dist/cjs/generated/ns/requests.js +3 -1
- package/dist/cjs/generated/ns/requests.js.map +1 -1
- package/dist/cjs/generated/ns/routines.d.ts +11 -4
- package/dist/cjs/generated/ns/routines.js +11 -4
- package/dist/cjs/generated/ns/routines.js.map +1 -1
- package/dist/cjs/generated/ns/sandboxes.d.ts +292 -7
- package/dist/cjs/generated/ns/sandboxes.js +444 -6
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
- package/dist/cjs/generated/ns/usage.d.ts +1 -1
- package/dist/cjs/generated/ns/usage.js +1 -1
- package/dist/cjs/generated/ns/vision.d.ts +59 -17
- package/dist/cjs/generated/ns/vision.js +59 -21
- package/dist/cjs/generated/ns/vision.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +2787 -85
- package/dist/cjs/helpers/sandboxes.d.ts +46 -3
- package/dist/cjs/helpers/sandboxes.js +127 -14
- package/dist/cjs/helpers/sandboxes.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/core/sse.d.ts +2 -0
- package/dist/esm/core/sse.js +17 -5
- package/dist/esm/core/sse.js.map +1 -1
- package/dist/esm/core/util.d.ts +1 -1
- package/dist/esm/core/util.js +1 -1
- package/dist/esm/generated/client.d.ts +13 -0
- package/dist/esm/generated/client.js +25 -0
- package/dist/esm/generated/client.js.map +1 -1
- package/dist/esm/generated/errors.d.ts +1 -1
- package/dist/esm/generated/errors.js +95 -0
- package/dist/esm/generated/errors.js.map +1 -1
- package/dist/esm/generated/ids.d.ts +61 -0
- package/dist/esm/generated/ids.js +15 -0
- package/dist/esm/generated/ids.js.map +1 -1
- package/dist/esm/generated/jobs.js +4 -0
- package/dist/esm/generated/jobs.js.map +1 -1
- package/dist/esm/generated/ns/actions.d.ts +303 -4
- package/dist/esm/generated/ns/actions.js +446 -4
- package/dist/esm/generated/ns/actions.js.map +1 -1
- package/dist/esm/generated/ns/agents.d.ts +229 -0
- package/dist/esm/generated/ns/agents.js +398 -0
- package/dist/esm/generated/ns/agents.js.map +1 -0
- package/dist/esm/generated/ns/images.d.ts +81 -0
- package/dist/esm/generated/ns/images.js +118 -0
- package/dist/esm/generated/ns/images.js.map +1 -0
- package/dist/esm/generated/ns/infer.d.ts +71 -3
- package/dist/esm/generated/ns/infer.js +98 -3
- package/dist/esm/generated/ns/infer.js.map +1 -1
- package/dist/esm/generated/ns/keys.d.ts +3 -1
- package/dist/esm/generated/ns/keys.js +3 -1
- package/dist/esm/generated/ns/keys.js.map +1 -1
- package/dist/esm/generated/ns/listeners.d.ts +159 -0
- package/dist/esm/generated/ns/listeners.js +260 -0
- package/dist/esm/generated/ns/listeners.js.map +1 -0
- package/dist/esm/generated/ns/orgs.d.ts +10 -0
- package/dist/esm/generated/ns/orgs.js +26 -1
- package/dist/esm/generated/ns/orgs.js.map +1 -1
- package/dist/esm/generated/ns/projects.d.ts +32 -0
- package/dist/esm/generated/ns/projects.js +66 -0
- package/dist/esm/generated/ns/projects.js.map +1 -1
- package/dist/esm/generated/ns/render.d.ts +192 -21
- package/dist/esm/generated/ns/render.js +267 -24
- package/dist/esm/generated/ns/render.js.map +1 -1
- package/dist/esm/generated/ns/requests.d.ts +3 -1
- package/dist/esm/generated/ns/requests.js +3 -1
- package/dist/esm/generated/ns/requests.js.map +1 -1
- package/dist/esm/generated/ns/routines.d.ts +11 -4
- package/dist/esm/generated/ns/routines.js +11 -4
- package/dist/esm/generated/ns/routines.js.map +1 -1
- package/dist/esm/generated/ns/sandboxes.d.ts +292 -7
- package/dist/esm/generated/ns/sandboxes.js +444 -6
- package/dist/esm/generated/ns/sandboxes.js.map +1 -1
- package/dist/esm/generated/ns/usage.d.ts +1 -1
- package/dist/esm/generated/ns/usage.js +1 -1
- package/dist/esm/generated/ns/vision.d.ts +59 -17
- package/dist/esm/generated/ns/vision.js +59 -21
- package/dist/esm/generated/ns/vision.js.map +1 -1
- package/dist/esm/generated/types.d.ts +2787 -85
- package/dist/esm/helpers/sandboxes.d.ts +46 -3
- package/dist/esm/helpers/sandboxes.js +126 -13
- package/dist/esm/helpers/sandboxes.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/sse.ts +17 -5
- package/src/core/util.ts +1 -1
- package/src/generated/client.ts +28 -0
- package/src/generated/errors.ts +190 -0
- package/src/generated/ids.ts +15 -0
- package/src/generated/jobs.ts +4 -0
- package/src/generated/ns/actions.ts +483 -4
- package/src/generated/ns/agents.ts +461 -0
- package/src/generated/ns/images.ts +128 -0
- package/src/generated/ns/infer.ts +100 -3
- package/src/generated/ns/keys.ts +3 -1
- package/src/generated/ns/listeners.ts +296 -0
- package/src/generated/ns/orgs.ts +27 -1
- package/src/generated/ns/projects.ts +74 -0
- package/src/generated/ns/render.ts +277 -24
- package/src/generated/ns/requests.ts +3 -1
- package/src/generated/ns/routines.ts +11 -4
- package/src/generated/ns/sandboxes.ts +492 -7
- package/src/generated/ns/usage.ts +1 -1
- package/src/generated/ns/vision.ts +59 -21
- package/src/generated/types.ts +3511 -575
- package/src/helpers/sandboxes.ts +167 -14
- package/src/index.ts +1 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
// Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
|
|
2
|
+
|
|
3
|
+
import type { RequestOptions, StreamOptions } from "../../core/client.ts";
|
|
4
|
+
import { isTerminalJobEvent } from "../../core/jobs.ts";
|
|
5
|
+
import { Namespace } from "../../core/namespace.ts";
|
|
6
|
+
import type { Op } from "../../core/op.ts";
|
|
7
|
+
import type { APIPromise, JobPromise, ListPromise } from "../../core/promise.ts";
|
|
8
|
+
import type { EventStream } from "../../core/sse.ts";
|
|
9
|
+
import type * as T from "../types.ts";
|
|
10
|
+
|
|
11
|
+
const listAgentsOp: Op = {
|
|
12
|
+
id: "agentsListAgents",
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: "/v1/agents",
|
|
15
|
+
timeoutMs: 10000,
|
|
16
|
+
scope: "agents:read",
|
|
17
|
+
};
|
|
18
|
+
const createAgentOp: Op = {
|
|
19
|
+
id: "agentsCreateAgent",
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/v1/agents",
|
|
22
|
+
body: "json",
|
|
23
|
+
idem: true,
|
|
24
|
+
timeoutMs: 10000,
|
|
25
|
+
scope: "agents:write",
|
|
26
|
+
};
|
|
27
|
+
const getSessionOp: Op = {
|
|
28
|
+
id: "agentsGetSession",
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/v1/agents/sessions/{session_id}",
|
|
31
|
+
params: ["session_id"],
|
|
32
|
+
timeoutMs: 10000,
|
|
33
|
+
scope: "agents:read",
|
|
34
|
+
};
|
|
35
|
+
const cancelSessionOp: Op = {
|
|
36
|
+
id: "agentsCancelSession",
|
|
37
|
+
method: "POST",
|
|
38
|
+
path: "/v1/agents/sessions/{session_id}/cancel",
|
|
39
|
+
params: ["session_id"],
|
|
40
|
+
timeoutMs: 10000,
|
|
41
|
+
scope: "agents:run",
|
|
42
|
+
};
|
|
43
|
+
const streamSessionOp: Op = {
|
|
44
|
+
id: "agentsStreamSession",
|
|
45
|
+
method: "GET",
|
|
46
|
+
path: "/v1/agents/sessions/{session_id}/events",
|
|
47
|
+
params: ["session_id"],
|
|
48
|
+
stream: "sse",
|
|
49
|
+
timeoutMs: 3600000,
|
|
50
|
+
scope: "agents:read",
|
|
51
|
+
};
|
|
52
|
+
const deleteAgentOp: Op = {
|
|
53
|
+
id: "agentsDeleteAgent",
|
|
54
|
+
method: "DELETE",
|
|
55
|
+
path: "/v1/agents/{agent}",
|
|
56
|
+
params: ["agent"],
|
|
57
|
+
timeoutMs: 30000,
|
|
58
|
+
scope: "agents:write",
|
|
59
|
+
};
|
|
60
|
+
const getAgentOp: Op = {
|
|
61
|
+
id: "agentsGetAgent",
|
|
62
|
+
method: "GET",
|
|
63
|
+
path: "/v1/agents/{agent}",
|
|
64
|
+
params: ["agent"],
|
|
65
|
+
timeoutMs: 10000,
|
|
66
|
+
scope: "agents:read",
|
|
67
|
+
};
|
|
68
|
+
const updateAgentOp: Op = {
|
|
69
|
+
id: "agentsUpdateAgent",
|
|
70
|
+
method: "PATCH",
|
|
71
|
+
path: "/v1/agents/{agent}",
|
|
72
|
+
params: ["agent"],
|
|
73
|
+
body: "json",
|
|
74
|
+
timeoutMs: 10000,
|
|
75
|
+
scope: "agents:write",
|
|
76
|
+
};
|
|
77
|
+
const listInstancesOp: Op = {
|
|
78
|
+
id: "agentsListInstances",
|
|
79
|
+
method: "GET",
|
|
80
|
+
path: "/v1/agents/{agent}/instances",
|
|
81
|
+
params: ["agent"],
|
|
82
|
+
timeoutMs: 10000,
|
|
83
|
+
scope: "agents:read",
|
|
84
|
+
};
|
|
85
|
+
const deleteInstanceOp: Op = {
|
|
86
|
+
id: "agentsDeleteInstance",
|
|
87
|
+
method: "DELETE",
|
|
88
|
+
path: "/v1/agents/{agent}/instances/{key}",
|
|
89
|
+
params: ["agent", "key"],
|
|
90
|
+
timeoutMs: 30000,
|
|
91
|
+
scope: "agents:write",
|
|
92
|
+
};
|
|
93
|
+
const getInstanceOp: Op = {
|
|
94
|
+
id: "agentsGetInstance",
|
|
95
|
+
method: "GET",
|
|
96
|
+
path: "/v1/agents/{agent}/instances/{key}",
|
|
97
|
+
params: ["agent", "key"],
|
|
98
|
+
timeoutMs: 10000,
|
|
99
|
+
scope: "agents:read",
|
|
100
|
+
};
|
|
101
|
+
const putInstanceOp: Op = {
|
|
102
|
+
id: "agentsPutInstance",
|
|
103
|
+
method: "PUT",
|
|
104
|
+
path: "/v1/agents/{agent}/instances/{key}",
|
|
105
|
+
params: ["agent", "key"],
|
|
106
|
+
body: "json",
|
|
107
|
+
timeoutMs: 65000,
|
|
108
|
+
scope: "agents:run",
|
|
109
|
+
};
|
|
110
|
+
const listInstanceEventsOp: Op = {
|
|
111
|
+
id: "agentsListInstanceEvents",
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: "/v1/agents/{agent}/instances/{key}/events",
|
|
114
|
+
params: ["agent", "key"],
|
|
115
|
+
timeoutMs: 10000,
|
|
116
|
+
scope: "agents:read",
|
|
117
|
+
};
|
|
118
|
+
const sleepInstanceOp: Op = {
|
|
119
|
+
id: "agentsSleepInstance",
|
|
120
|
+
method: "POST",
|
|
121
|
+
path: "/v1/agents/{agent}/instances/{key}/sleep",
|
|
122
|
+
params: ["agent", "key"],
|
|
123
|
+
body: "json",
|
|
124
|
+
timeoutMs: 30000,
|
|
125
|
+
scope: "agents:run",
|
|
126
|
+
};
|
|
127
|
+
const listSessionsOp: Op = {
|
|
128
|
+
id: "agentsListSessions",
|
|
129
|
+
method: "GET",
|
|
130
|
+
path: "/v1/agents/{agent}/sessions",
|
|
131
|
+
params: ["agent"],
|
|
132
|
+
timeoutMs: 10000,
|
|
133
|
+
scope: "agents:read",
|
|
134
|
+
};
|
|
135
|
+
const sendMessageOp: Op = {
|
|
136
|
+
id: "agentsSendMessage",
|
|
137
|
+
method: "POST",
|
|
138
|
+
path: "/v1/agents/{agent}/instances/{key}/messages",
|
|
139
|
+
params: ["agent", "key"],
|
|
140
|
+
body: "json",
|
|
141
|
+
idem: true,
|
|
142
|
+
stream: "sse",
|
|
143
|
+
timeoutMs: 3600000,
|
|
144
|
+
scope: "agents:run",
|
|
145
|
+
job: { get: getSessionOp, events: streamSessionOp, cancel: cancelSessionOp },
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/** Descriptors of every agents operation, keyed by method name (for tooling and custom clients). */
|
|
149
|
+
export const agentsOps = {
|
|
150
|
+
listAgents: listAgentsOp,
|
|
151
|
+
createAgent: createAgentOp,
|
|
152
|
+
getSession: getSessionOp,
|
|
153
|
+
cancelSession: cancelSessionOp,
|
|
154
|
+
streamSession: streamSessionOp,
|
|
155
|
+
deleteAgent: deleteAgentOp,
|
|
156
|
+
getAgent: getAgentOp,
|
|
157
|
+
updateAgent: updateAgentOp,
|
|
158
|
+
listInstances: listInstancesOp,
|
|
159
|
+
deleteInstance: deleteInstanceOp,
|
|
160
|
+
getInstance: getInstanceOp,
|
|
161
|
+
putInstance: putInstanceOp,
|
|
162
|
+
listInstanceEvents: listInstanceEventsOp,
|
|
163
|
+
sendMessage: sendMessageOp,
|
|
164
|
+
sleepInstance: sleepInstanceOp,
|
|
165
|
+
listSessions: listSessionsOp,
|
|
166
|
+
} as const;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Actors: agent definitions, keyed instances (one microVM per key) and agent sessions; a message wakes its instance (`/v1/agents`).
|
|
170
|
+
*/
|
|
171
|
+
export class AgentsAPI extends Namespace {
|
|
172
|
+
/**
|
|
173
|
+
* List agents
|
|
174
|
+
*
|
|
175
|
+
* Lists the project's agents, newest first.
|
|
176
|
+
*
|
|
177
|
+
* `GET /v1/agents` · scope `agents:read` · served by the node
|
|
178
|
+
*/
|
|
179
|
+
listAgents(params?: T.AgentsListAgentsParams, options?: RequestOptions): ListPromise<T.AgentList, T.Agent> {
|
|
180
|
+
return this._client._list<T.AgentList, T.Agent>(listAgentsOp, { query: params }, options);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Create an agent
|
|
185
|
+
*
|
|
186
|
+
* Creates an agent: the definition every instance of it starts from. Nothing starts until the first message to
|
|
187
|
+
* a key (or `PUT /v1/agents/{agent}/instances/{key}`). `name` is unique in the project and is how the other
|
|
188
|
+
* operations name the agent (its `agt_` ID works too).
|
|
189
|
+
*
|
|
190
|
+
* `entry` is the harness: `command` runs in each instance, and the node delivers each message as a `POST` to
|
|
191
|
+
* `entry.port` and `entry.path` inside it. `api` is the grant each instance runs with, at most your own scopes:
|
|
192
|
+
* its `scopes`, its vault `connections` and its actions rule, whose packs it calls as MCP tools at
|
|
193
|
+
* `B3OS_MCP_URL`. `agents:write` is granted only when named exactly, so a harness changes its own memory and
|
|
194
|
+
* disk, never its definition. Instances belong to the project: revoking the key that created the agent does
|
|
195
|
+
* not stop them.
|
|
196
|
+
*
|
|
197
|
+
* `POST /v1/agents` · scope `agents:write` · served by the node
|
|
198
|
+
*/
|
|
199
|
+
createAgent(body: T.AgentCreateRequest, options?: RequestOptions): APIPromise<T.Agent> {
|
|
200
|
+
return this._client._call<T.Agent>(createAgentOp, { body }, options);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get an agent session
|
|
205
|
+
*
|
|
206
|
+
* One turn: its status and phase, who sent it (`initiator`), its conversation, how its instance woke
|
|
207
|
+
* (`woke_from`), its trace and its timing. The message and the harness's answer are kept only for a session that
|
|
208
|
+
* was answered `202` (so you can read the result here, for 24 hours) or when the project's
|
|
209
|
+
* `platform.capture_content` setting is on. Sessions are kept 30 days after they end.
|
|
210
|
+
*
|
|
211
|
+
* `GET /v1/agents/sessions/{session_id}` · scope `agents:read` · served by the node
|
|
212
|
+
*/
|
|
213
|
+
getSession(sessionId: string, options?: RequestOptions): APIPromise<T.AgentSession> {
|
|
214
|
+
return this._client._call<T.AgentSession>(getSessionOp, { path: [sessionId] }, options);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Cancel an agent session
|
|
219
|
+
*
|
|
220
|
+
* Cancels a turn. A queued session leaves the queue and is never delivered. A delivered one has its request into
|
|
221
|
+
* the harness closed; what the harness already did stands. Cancelling an ended session returns it unchanged.
|
|
222
|
+
*
|
|
223
|
+
* `POST /v1/agents/sessions/{session_id}/cancel` · scope `agents:run` · served by the node
|
|
224
|
+
*/
|
|
225
|
+
cancelSession(sessionId: string, options?: RequestOptions): APIPromise<T.AgentSession> {
|
|
226
|
+
return this._client._call<T.AgentSession>(cancelSessionOp, { path: [sessionId] }, options);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Stream an agent session's events
|
|
231
|
+
*
|
|
232
|
+
* Server-sent events for one turn: `job.queued` when it was accepted, `session.waking` when its instance began
|
|
233
|
+
* to wake (with `woke_from`), `session.delivered` when the harness received it, `session.output` for each event
|
|
234
|
+
* the harness streamed back (when it answered with `text/event-stream`), and the terminal `job.succeeded`,
|
|
235
|
+
* `job.failed` or `job.canceled`, which carries the final session and ends the stream. Reconnect with
|
|
236
|
+
* `Last-Event-ID` to resume while the session runs; a session that ended sends its terminal event alone.
|
|
237
|
+
*
|
|
238
|
+
* `GET /v1/agents/sessions/{session_id}/events` · scope `agents:read` · served by the node
|
|
239
|
+
*/
|
|
240
|
+
streamSession(sessionId: string, options?: StreamOptions): EventStream<T.AgentSessionEvent> {
|
|
241
|
+
return this._client._stream<T.AgentSessionEvent>(streamSessionOp, { path: [sessionId] }, options, {
|
|
242
|
+
terminal: isTerminalJobEvent,
|
|
243
|
+
reconnectOnEnd: true,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Delete an agent
|
|
249
|
+
*
|
|
250
|
+
* Deletes the agent and every instance of it: their microVMs, memory snapshots and disks. Their sessions stay
|
|
251
|
+
* readable until they expire.
|
|
252
|
+
*
|
|
253
|
+
* `DELETE /v1/agents/{agent}` · scope `agents:write` · served by the node
|
|
254
|
+
*/
|
|
255
|
+
deleteAgent(agent: string, options?: RequestOptions): APIPromise<T.Deleted> {
|
|
256
|
+
return this._client._call<T.Deleted>(deleteAgentOp, { path: [agent] }, options);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Get an agent
|
|
261
|
+
*
|
|
262
|
+
* The agent, by name or `agt_` ID, with its current revision and how many instances it has.
|
|
263
|
+
*
|
|
264
|
+
* `GET /v1/agents/{agent}` · scope `agents:read` · served by the node
|
|
265
|
+
*/
|
|
266
|
+
getAgent(agent: string, options?: RequestOptions): APIPromise<T.Agent> {
|
|
267
|
+
return this._client._call<T.Agent>(getAgentOp, { path: [agent] }, options);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Update an agent
|
|
272
|
+
*
|
|
273
|
+
* Changes the definition and makes a new revision. `upgrade` says what happens to instances of earlier
|
|
274
|
+
* revisions: `new_instances` (the default) leaves them on the revision they were made from, so their memory
|
|
275
|
+
* and disk stay as they are, and only new instances take the change; `on_wake` makes a sleeping instance of an
|
|
276
|
+
* earlier revision again from this one at its next wake, which ends its memory and disk. `name` cannot change.
|
|
277
|
+
* The grant is checked again against your own scopes.
|
|
278
|
+
*
|
|
279
|
+
* `PATCH /v1/agents/{agent}` · scope `agents:write` · served by the node
|
|
280
|
+
*/
|
|
281
|
+
updateAgent(agent: string, body: T.AgentUpdateRequest, options?: RequestOptions): APIPromise<T.Agent> {
|
|
282
|
+
return this._client._call<T.Agent>(updateAgentOp, { path: [agent], body }, options);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* List an agent's instances
|
|
287
|
+
*
|
|
288
|
+
* Lists the agent's instances, most recently messaged first. Filter by `status`.
|
|
289
|
+
*
|
|
290
|
+
* `GET /v1/agents/{agent}/instances` · scope `agents:read` · served by the node
|
|
291
|
+
*/
|
|
292
|
+
listInstances(
|
|
293
|
+
agent: string,
|
|
294
|
+
params?: T.AgentsListInstancesParams,
|
|
295
|
+
options?: RequestOptions,
|
|
296
|
+
): ListPromise<T.AgentInstanceList, T.AgentInstance> {
|
|
297
|
+
return this._client._list<T.AgentInstanceList, T.AgentInstance>(
|
|
298
|
+
listInstancesOp,
|
|
299
|
+
{ path: [agent], query: params },
|
|
300
|
+
options,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Delete an instance
|
|
306
|
+
*
|
|
307
|
+
* Deletes the instance: its microVM, its memory snapshot and its disk. Queued messages end `canceled` and are
|
|
308
|
+
* never delivered. This and deleting the agent are the only ways an instance ends; idleness never does. The
|
|
309
|
+
* next message to the key makes a new instance unless it sends `create: false`.
|
|
310
|
+
*
|
|
311
|
+
* `DELETE /v1/agents/{agent}/instances/{key}` · scope `agents:write` · served by the node
|
|
312
|
+
*/
|
|
313
|
+
deleteInstance(agent: string, key: string, options?: RequestOptions): APIPromise<T.Deleted> {
|
|
314
|
+
return this._client._call<T.Deleted>(deleteInstanceOp, { path: [agent, key] }, options);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Get an instance
|
|
319
|
+
*
|
|
320
|
+
* The instance for `key`: its status (`running`, `paused` in memory, `hibernated` as a memory snapshot,
|
|
321
|
+
* `dormant` on its disk alone), the host memory it holds now (`resident_mib`), the disk it holds on the node
|
|
322
|
+
* (`storage_bytes`), how many messages wait in its queue, and when it last got a message and went to sleep.
|
|
323
|
+
*
|
|
324
|
+
* `GET /v1/agents/{agent}/instances/{key}` · scope `agents:read` · served by the node
|
|
325
|
+
*/
|
|
326
|
+
getInstance(agent: string, key: string, options?: RequestOptions): APIPromise<T.AgentInstance> {
|
|
327
|
+
return this._client._call<T.AgentInstance>(getInstanceOp, { path: [agent, key] }, options);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Get or create an instance
|
|
332
|
+
*
|
|
333
|
+
* The instance for `key`, made if it does not exist: `201` when this request made it (its microVM started and
|
|
334
|
+
* its harness passed readiness), `200` when it existed. An existing instance is not woken unless `wake: true`.
|
|
335
|
+
* `replace: true` deletes an existing instance (its memory, snapshot and disk) and makes it again from the
|
|
336
|
+
* agent's current revision. Two requests for a new key at once make one instance.
|
|
337
|
+
*
|
|
338
|
+
* Each instance is its own microVM: instances of different keys never share one. The key is stored and shown as
|
|
339
|
+
* written, so never use a credential or a personal detail as a key.
|
|
340
|
+
*
|
|
341
|
+
* `PUT /v1/agents/{agent}/instances/{key}` · scope `agents:run` · served by the node
|
|
342
|
+
*/
|
|
343
|
+
putInstance(
|
|
344
|
+
agent: string,
|
|
345
|
+
key: string,
|
|
346
|
+
body?: T.AgentInstancePutRequest,
|
|
347
|
+
options?: RequestOptions,
|
|
348
|
+
): APIPromise<T.AgentInstance> {
|
|
349
|
+
return this._client._call<T.AgentInstance>(putInstanceOp, { path: [agent, key], body }, options);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* List an instance's lifecycle events
|
|
354
|
+
*
|
|
355
|
+
* What happened to the instance, newest first: `instance.created`, `instance.paused`, `instance.hibernated`,
|
|
356
|
+
* `instance.dormant`, `instance.woke` (with `woke_from`), `instance.failed`, `instance.recovered` (with
|
|
357
|
+
* `woke_from`: from its memory snapshot, which takes memory and disk back to the snapshot's time together,
|
|
358
|
+
* from its disk, with memory lost, or `new`, when its disk was gone too) and `instance.upgraded`. The last 200
|
|
359
|
+
* are kept.
|
|
360
|
+
*
|
|
361
|
+
* `GET /v1/agents/{agent}/instances/{key}/events` · scope `agents:read` · served by the node
|
|
362
|
+
*/
|
|
363
|
+
listInstanceEvents(
|
|
364
|
+
agent: string,
|
|
365
|
+
key: string,
|
|
366
|
+
params?: T.AgentsListInstanceEventsParams,
|
|
367
|
+
options?: RequestOptions,
|
|
368
|
+
): ListPromise<T.AgentInstanceEventList, T.AgentInstanceEvent> {
|
|
369
|
+
return this._client._list<T.AgentInstanceEventList, T.AgentInstanceEvent>(
|
|
370
|
+
listInstanceEventsOp,
|
|
371
|
+
{ path: [agent, key], query: params },
|
|
372
|
+
options,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Send a message to an instance
|
|
378
|
+
*
|
|
379
|
+
* Sends one message to the instance for `key` and starts a session (one turn). The instance is made if it does
|
|
380
|
+
* not exist, unless `create: false`; a sleeping one is woken, from memory, from its memory snapshot or from its
|
|
381
|
+
* disk (`woke_from`). Nobody calls resume.
|
|
382
|
+
*
|
|
383
|
+
* The message is written to disk before any answer. With `?wait=0` (the default) the answer is `202` with the
|
|
384
|
+
* session `queued` right after that write, before the instance wakes or the turn runs: from then on the message
|
|
385
|
+
* is not lost when the node's daemon restarts. With `?wait=N` the answer waits up to N seconds for the turn;
|
|
386
|
+
* with `Accept: text/event-stream` it streams the session's events, the harness's own streamed events among
|
|
387
|
+
* them (`session.output`). A `200` carries the harness's answer as `result` (its JSON body, or its text).
|
|
388
|
+
*
|
|
389
|
+
* An instance runs one turn at a time. A message that arrives during a turn waits in the instance's queue, in
|
|
390
|
+
* order, up to the agent's `turns.queue_max`; past it the answer is `429 instance_busy` with `Retry-After`, and
|
|
391
|
+
* nothing was queued. Retry with the same `Idempotency-Key`: a retry within 24 hours returns the first answer
|
|
392
|
+
* and never queues the message twice.
|
|
393
|
+
*
|
|
394
|
+
* The node delivers the message as a `POST` to the agent's `entry.port` and `entry.path` inside the instance,
|
|
395
|
+
* with the JSON body `{session, message, conversation, subject, initiator}` and the headers `traceparent`,
|
|
396
|
+
* `baggage` and `x-b3os-session`. `message` is your request body without the reserved members. A 2xx answer
|
|
397
|
+
* ends the session `succeeded`; any other ends it `failed` with `harness_error`. A message is delivered into
|
|
398
|
+
* the harness at most once: if the node restarts while the harness has it, the session ends `failed` with
|
|
399
|
+
* `session_interrupted`, unless the agent sets `turns.redeliver: true`.
|
|
400
|
+
*
|
|
401
|
+
* `conversation` and `subject` are taken from the body, else from the `b3os.conversation` and `b3os.subject`
|
|
402
|
+
* baggage that `b3.traces.turn` sends. `initiator` (the key, dashboard user, sandbox, instance, routine run or
|
|
403
|
+
* listener that sent the message) is taken from the credential, never from the body. A message whose key is
|
|
404
|
+
* revoked before it is delivered ends `failed` with `credential_revoked`. Code in an instance cannot message
|
|
405
|
+
* that same instance (`409 instance_self_message`).
|
|
406
|
+
*
|
|
407
|
+
* `Server-Timing` and the session's `timing` split the turn into `queue`, `wake` (`desc` names the tier),
|
|
408
|
+
* `deliver` and `harness`.
|
|
409
|
+
*
|
|
410
|
+
* `POST /v1/agents/{agent}/instances/{key}/messages` · scope `agents:run` · served by the node
|
|
411
|
+
*/
|
|
412
|
+
sendMessage(
|
|
413
|
+
agent: string,
|
|
414
|
+
key: string,
|
|
415
|
+
body: T.AgentMessageRequest,
|
|
416
|
+
options?: RequestOptions,
|
|
417
|
+
): JobPromise<T.AgentSession, T.AgentSessionEvent> {
|
|
418
|
+
return this._client._job<T.AgentSession, T.AgentSessionEvent>(sendMessageOp, { path: [agent, key], body }, options);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Put an instance to sleep now
|
|
423
|
+
*
|
|
424
|
+
* Sends the instance to a sleep tier now instead of waiting for its timers: `ram` pauses it, `snapshot` writes
|
|
425
|
+
* its memory snapshot and frees its memory (an instance with a volume answers `409 volume_attached` and stays as
|
|
426
|
+
* it was). A harness may call this on its own instance when it knows it is done
|
|
427
|
+
* (from inside, at `http://127.0.0.1:7700`); the pause then happens once its current turn ends. An instance with
|
|
428
|
+
* a turn running or messages queued goes to sleep after them. Asleep already in that tier or a deeper one:
|
|
429
|
+
* returned unchanged.
|
|
430
|
+
*
|
|
431
|
+
* `POST /v1/agents/{agent}/instances/{key}/sleep` · scope `agents:run` · served by the node
|
|
432
|
+
*/
|
|
433
|
+
sleepInstance(
|
|
434
|
+
agent: string,
|
|
435
|
+
key: string,
|
|
436
|
+
body?: T.AgentInstanceSleepRequest,
|
|
437
|
+
options?: RequestOptions,
|
|
438
|
+
): APIPromise<T.AgentInstance> {
|
|
439
|
+
return this._client._call<T.AgentInstance>(sleepInstanceOp, { path: [agent, key], body }, options);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* List an agent's sessions
|
|
444
|
+
*
|
|
445
|
+
* Lists the agent's sessions, newest first. Filter by instance `key`, by `conversation` (the ID you sent with the
|
|
446
|
+
* message, or the `b3os.conversation` baggage of `b3.traces.turn`) or by `status`.
|
|
447
|
+
*
|
|
448
|
+
* `GET /v1/agents/{agent}/sessions` · scope `agents:read` · served by the node
|
|
449
|
+
*/
|
|
450
|
+
listSessions(
|
|
451
|
+
agent: string,
|
|
452
|
+
params?: T.AgentsListSessionsParams,
|
|
453
|
+
options?: RequestOptions,
|
|
454
|
+
): ListPromise<T.AgentSessionList, T.AgentSession> {
|
|
455
|
+
return this._client._list<T.AgentSessionList, T.AgentSession>(
|
|
456
|
+
listSessionsOp,
|
|
457
|
+
{ path: [agent], query: params },
|
|
458
|
+
options,
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
|
|
2
|
+
|
|
3
|
+
import type { RequestOptions } from "../../core/client.ts";
|
|
4
|
+
import { Namespace } from "../../core/namespace.ts";
|
|
5
|
+
import type { Op } from "../../core/op.ts";
|
|
6
|
+
import type { APIPromise } from "../../core/promise.ts";
|
|
7
|
+
import type * as T from "../types.ts";
|
|
8
|
+
|
|
9
|
+
const listImagesOp: Op = {
|
|
10
|
+
id: "imagesListImages",
|
|
11
|
+
method: "GET",
|
|
12
|
+
path: "/v1/images",
|
|
13
|
+
timeoutMs: 10000,
|
|
14
|
+
scope: "sandboxes:read",
|
|
15
|
+
};
|
|
16
|
+
const importImageOp: Op = {
|
|
17
|
+
id: "imagesImportImage",
|
|
18
|
+
method: "POST",
|
|
19
|
+
path: "/v1/images",
|
|
20
|
+
body: "json",
|
|
21
|
+
timeoutMs: 30000,
|
|
22
|
+
scope: "sandboxes:write",
|
|
23
|
+
};
|
|
24
|
+
const deleteImageOp: Op = {
|
|
25
|
+
id: "imagesDeleteImage",
|
|
26
|
+
method: "DELETE",
|
|
27
|
+
path: "/v1/images/{image_id}",
|
|
28
|
+
params: ["image_id"],
|
|
29
|
+
timeoutMs: 30000,
|
|
30
|
+
scope: "sandboxes:write",
|
|
31
|
+
};
|
|
32
|
+
const getImageOp: Op = {
|
|
33
|
+
id: "imagesGetImage",
|
|
34
|
+
method: "GET",
|
|
35
|
+
path: "/v1/images/{image_id}",
|
|
36
|
+
params: ["image_id"],
|
|
37
|
+
timeoutMs: 35000,
|
|
38
|
+
scope: "sandboxes:read",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Descriptors of every images operation, keyed by method name (for tooling and custom clients). */
|
|
42
|
+
export const imagesOps = {
|
|
43
|
+
listImages: listImagesOp,
|
|
44
|
+
importImage: importImageOp,
|
|
45
|
+
deleteImage: deleteImageOp,
|
|
46
|
+
getImage: getImageOp,
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
/** Public OCI images imported as templates for your project's sandboxes (`/v1/images`). */
|
|
50
|
+
export class ImagesAPI extends Namespace {
|
|
51
|
+
/**
|
|
52
|
+
* List images
|
|
53
|
+
*
|
|
54
|
+
* Lists this project's images, newest first, in every status (an `evicted` or `failed` image stays listed
|
|
55
|
+
* until it is deleted). Other projects' images are never listed.
|
|
56
|
+
*
|
|
57
|
+
* `GET /v1/images` · scope `sandboxes:read` · served by the node
|
|
58
|
+
*/
|
|
59
|
+
listImages(options?: RequestOptions): APIPromise<T.ImageList> {
|
|
60
|
+
return this._client._call<T.ImageList>(listImagesOp, {}, options);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Import an image
|
|
65
|
+
*
|
|
66
|
+
* Imports a public OCI image as a template for this project's sandboxes. The reference is resolved before the
|
|
67
|
+
* answer (a tag to its digest with one manifest `HEAD`), so the answer names the exact image: `202` with a new
|
|
68
|
+
* image (`status: queued`), or `200` with the project's existing image when one with the same key exists,
|
|
69
|
+
* ready or still importing. The key covers the project, the image's digest, the warm-up, the size and the
|
|
70
|
+
* node's own build inputs (guest agent, kernel, the unpacker), so the same request after a node release can be
|
|
71
|
+
* a new image. Watch it with `GET /v1/images/{image_id}?wait=30` until `ready` (or `failed`), then create
|
|
72
|
+
* sandboxes with `POST /v1/sandboxes {"image": "img_…"}`.
|
|
73
|
+
*
|
|
74
|
+
* The import runs whether or not the client stays connected. It holds `images.rootfs_max` of your
|
|
75
|
+
* organization's snapshot storage while it runs and then counts as one snapshot, its root file system plus its
|
|
76
|
+
* warm snapshot's memory, against `sandboxes.snapshots_max` and `sandboxes.snapshot_storage_max`. An
|
|
77
|
+
* organization runs one import at a time and a node two; more wait in the queue (`queued`). The CPU the import
|
|
78
|
+
* uses (the unpacking microVM and the warm-up boot) is recorded as `images.import_vcpu_ms`.
|
|
79
|
+
*
|
|
80
|
+
* `warmup.commands` run in order, each as an argument list (no shell unless you name one), as root, with no
|
|
81
|
+
* network, at most 300 seconds in all; what they read is in the page cache of every sandbox restored from the
|
|
82
|
+
* snapshot. The image's `USER`, `ENV` and `WORKDIR` apply to every command your sandboxes run. Clones of one
|
|
83
|
+
* warm snapshot share the in-process random state of anything the warm-up left running, within your project
|
|
84
|
+
* only; the kernel's random pool is reseeded for each.
|
|
85
|
+
*
|
|
86
|
+
* `size` (`vcpu`, `memory_mib`) is fixed at import: every sandbox from the image has it, and a create that asks
|
|
87
|
+
* for another size answers `400 invalid_request`. Without the flag on for your organization the answer is
|
|
88
|
+
* `404 feature_not_enabled`; without an image store on the node, a full store or the node's disk under its
|
|
89
|
+
* floor, `503 capacity_unavailable`.
|
|
90
|
+
*
|
|
91
|
+
* A `failed` image whose warm snapshot could not be rebuilt (`error.stage: rebuild`) keeps its root file
|
|
92
|
+
* system, and the node tries it again at its next start. The same request imports it again under its ID and
|
|
93
|
+
* replaces that file system, except while a running or paused sandbox, or a snapshot taken from one, uses the
|
|
94
|
+
* image's template: then the answer is `409 image_in_use`.
|
|
95
|
+
*
|
|
96
|
+
* `POST /v1/images` · scope `sandboxes:write` · served by the node
|
|
97
|
+
*/
|
|
98
|
+
importImage(body: T.ImageImportRequest, options?: RequestOptions): APIPromise<T.Image> {
|
|
99
|
+
return this._client._call<T.Image>(importImageOp, { body }, options);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Delete an image
|
|
104
|
+
*
|
|
105
|
+
* Deletes the image, its template, its warm snapshot and its root file system. An import in progress is
|
|
106
|
+
* cancelled and leaves nothing behind. While a running or paused sandbox, or a snapshot taken from one, uses
|
|
107
|
+
* the image's template the answer is `409 image_in_use`.
|
|
108
|
+
*
|
|
109
|
+
* `DELETE /v1/images/{image_id}` · scope `sandboxes:write` · served by the node
|
|
110
|
+
*/
|
|
111
|
+
deleteImage(imageId: string, options?: RequestOptions): APIPromise<T.Deleted> {
|
|
112
|
+
return this._client._call<T.Deleted>(deleteImageOp, { path: [imageId] }, options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get an image
|
|
117
|
+
*
|
|
118
|
+
* Returns one of this project's images. With `wait` (seconds, at most 30) the answer is held until the image is
|
|
119
|
+
* `ready`, `failed` or `evicted`, or the time passes, whichever is first; it then returns the image as it is.
|
|
120
|
+
* `stages_ms` times each stage the import has finished; `error` says why a `failed` image failed, with the
|
|
121
|
+
* last 4 KiB of output.
|
|
122
|
+
*
|
|
123
|
+
* `GET /v1/images/{image_id}` · scope `sandboxes:read` · served by the node
|
|
124
|
+
*/
|
|
125
|
+
getImage(imageId: string, params?: T.ImagesGetImageParams, options?: RequestOptions): APIPromise<T.Image> {
|
|
126
|
+
return this._client._call<T.Image>(getImageOp, { path: [imageId], query: params }, options);
|
|
127
|
+
}
|
|
128
|
+
}
|