objectiveai-sdk 2.2.16

ObjectiveAI SDK, definitions, and utilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
//! The `/laboratory` channel's OWN request/response vocabulary.
//!
//! The daemon↔host channel and the API↔client reverse channel are
//! NAIVE to each other: neither imports the other's payloads, and the
//! CLI daemon's conduit is the one place an API-side op is translated
//! into a host-side op (and the response back). The only types both
//! channels share are the provider-neutral MCP domain models
//! (`crate::mcp::tool` / `resource` / `initialize_result`) — genuine
//! data, not channel vocabulary. Everything else here, down to the
//! [`JsonRpcResult`] envelope, is a deliberate local definition.
//!
//! What the vocabulary deliberately does NOT carry (the reverse
//! channel needs these, the host does not):
//! - `mcp_kind` — reverse-channel routing metadata; the conduit
//!   re-attaches it when translating a response back.
//! - `machine` / `machine_state` — daemon-side routing; by the time a
//!   frame reaches a host, the host IS the (machine, state).
//! - per-payload `laboratory_id` — the [`ChannelRequest`](super::ChannelRequest)
//!   envelope's `laboratory_id` addresses the lab.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Daemon → host: every op the `/laboratory` channel can carry.
/// Container-scoped ops (everything except `Create` / `Delete` /
/// `LocalTransfer`) demux by the envelope's `laboratory_id`.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.RequestPayload")]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RequestPayload {
    /// Open (or reuse) the per-response MCP connection into the
    /// laboratory container. The host dials fresh — no params.
    #[schemars(title = "Initialize")]
    Initialize,
    /// Tear down the per-response MCP connection.
    #[schemars(title = "SessionTerminate")]
    SessionTerminate,
    #[schemars(title = "ToolsList")]
    ToolsList(crate::mcp::tool::ListToolsRequest),
    #[schemars(title = "ToolsCall")]
    ToolsCall(crate::mcp::tool::CallToolRequestParams),
    #[schemars(title = "ResourcesList")]
    ResourcesList(crate::mcp::resource::ListResourcesRequest),
    #[schemars(title = "ResourcesRead")]
    ResourcesRead(crate::mcp::resource::ReadResourceRequestParams),
    /// Drop every per-response connection for `response_id` on this
    /// laboratory — the host-side half of the conduit's own drop.
    #[schemars(title = "Drop")]
    Drop(DropRequest),
    /// Whether the daemon currently holds ≥1 live filetree subscriber
    /// for the envelope's laboratory (edge-triggered: sent on the
    /// 0→1 and 1→0 transitions, and replayed as `on: true` when the
    /// host reconnects while subscribers exist). Drives the host's
    /// container lifecycle: `on` lazily starts the container (and its
    /// filetree pump); `off` makes it a stop candidate once the lab
    /// also has no MCP connections. Defaults to off — a host that
    /// never receives this treats the lab as unwatched.
    #[schemars(title = "Filetree")]
    Filetree(FiletreeRequest),
    /// Begin streaming a tar export OUT of the laboratory: the host
    /// opens the container's `/export` and parks the byte stream under
    /// a fresh `transfer_id`; the requester then PULLS chunks with
    /// [`RequestPayload::ExportRead`].
    #[schemars(title = "ExportBegin")]
    ExportBegin(ExportBeginRequest),
    /// Pull the next chunk of a parked export. `eof: true` on the
    /// reply means the stream completed and the entry is gone (the
    /// final reply's `data` may still be non-empty).
    #[schemars(title = "ExportRead")]
    ExportRead(TransferIdRequest),
    /// Drop a parked export early (requester-side failure).
    #[schemars(title = "ExportAbort")]
    ExportAbort(TransferIdRequest),
    /// Begin streaming a tar import INTO the laboratory: the host
    /// opens the container's `/import` with a channel-backed body and
    /// parks the sender under a fresh `transfer_id`.
    #[schemars(title = "ImportBegin")]
    ImportBegin(ImportBeginRequest),
    /// Push one chunk into a parked import body.
    #[schemars(title = "ImportWrite")]
    ImportWrite(ImportWriteRequest),
    /// Close a parked import and await the unpack; replies with the
    /// total bytes fed.
    #[schemars(title = "ImportEnd")]
    ImportEnd(TransferIdRequest),
    /// Drop a parked import early — the truncated tar fails the
    /// unpack, so nothing partial is kept silently.
    #[schemars(title = "ImportAbort")]
    ImportAbort(TransferIdRequest),
    /// Create a laboratory on this host (podman create + MCP binary
    /// injection, container NOT started). Host-level: no envelope
    /// `laboratory_id`.
    #[schemars(title = "Create")]
    Create(CreateRequest),
    /// Create an EPHEMERAL agent laboratory AND establish its single
    /// MCP connection, atomically: ensure the content-addressed agent
    /// image, `rm -f` any stale container for the id, create + start
    /// the container, connect using THIS request's envelope headers
    /// (they carry the FULL originating header set — the agent
    /// arguments the in-container MCP requires; unlike `Create`, which
    /// rides with an empty map). Succeeds only when BOTH the container
    /// and the connection exist; the reply carries identity AND the
    /// initialize result. Exactly ONE connection, ever — the
    /// laboratory's lifetime IS that connection's, and the container
    /// evaporates (`rm -f`, zero grace) the moment it ends. Host-level:
    /// no envelope `laboratory_id` — the HOST derives the id
    /// (`{derived_id}-{response_id}`, see
    /// [`crate::agent::laboratories::ephemeral_id`]).
    ///
    /// NOTE for the daemon phase: the image ensure runs a pull/build
    /// inline, which can exceed the standard RPC forward timeout —
    /// classify this op with the timeout-free transfer family.
    #[schemars(title = "AgentEphemeralCreate")]
    AgentEphemeralCreate(AgentEphemeralCreateRequest),
    /// The PLUGIN twin of [`RequestPayload::AgentEphemeralCreate`]:
    /// ensure the plugin image (git fetch at the version tag + `podman
    /// build` — timeout-free family, same note as above), then the
    /// same atomic create + start + connect with this request's
    /// headers. The HOST derives the id
    /// (`oai-plugin-{owner}-{name}-{version}-{response_id}`).
    #[schemars(title = "PluginEphemeralCreate")]
    PluginEphemeralCreate(PluginEphemeralCreateRequest),
    /// DEVELOPMENT mode: drop a plugin's local image so the next
    /// [`RequestPayload::PluginEphemeralCreate`] has to rebuild it.
    ///
    /// Rebuilds are EXPLICIT — the image-exists fast path is kept for
    /// registered plugins too — so this is the thing that makes an
    /// edit take effect. Host-level: it addresses an IMAGE, never the
    /// envelope's laboratory. Takes the same build lock the build
    /// takes, so it can never land mid-build.
    #[schemars(title = "PluginImageReset")]
    PluginImageReset(PluginImageResetRequest),
    /// Delete a laboratory from this host (podman rm). Host-level.
    #[schemars(title = "Delete")]
    Delete(DeleteRequest),
    /// Transfer a path between TWO laboratories that both live on
    /// THIS host: the host pipes the source's export stream straight
    /// into the destination's import — no chunk staging anywhere.
    /// Host-level: it addresses two labs, never the envelope's one.
    #[schemars(title = "LocalTransfer")]
    LocalTransfer(LocalTransferRequest),
    /// Build a plugin's VIEWER extension: fetch the repo at the
    /// version's git tag, run the baked builder image over the
    /// checkout in a BUILD laboratory, and park the resulting
    /// `bundle.tar.gz` for [`RequestPayload::BuildRead`]. Runs to
    /// completion — the container is created, waited on, and removed
    /// within this one request (timeout-free family: a cold build
    /// pulls a base image and installs a dependency tree). Host-level:
    /// the HOST derives the laboratory id.
    #[schemars(title = "BuildCreate")]
    BuildCreate(BuildCreateRequest),
    /// Drain the next chunk of a parked build artifact — the
    /// [`RequestPayload::ExportRead`] shape for a host-side FILE
    /// rather than a container's export stream (a build container
    /// serves no HTTP: it has no injected MCP binary and is gone by
    /// the time this runs). Host-level.
    #[schemars(title = "BuildRead")]
    BuildRead(TransferIdRequest),
    /// Discard a parked build artifact without draining it.
    /// Host-level.
    #[schemars(title = "BuildAbort")]
    BuildAbort(TransferIdRequest),
}

/// Host → daemon: the reply vocabulary, 1:1 with [`RequestPayload`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ResponsePayload")]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ResponsePayload {
    #[schemars(title = "Initialize")]
    Initialize(JsonRpcResult<InitializeReply>),
    #[schemars(title = "SessionTerminate")]
    SessionTerminate(JsonRpcResult<()>),
    #[schemars(title = "ToolsList")]
    ToolsList(JsonRpcResult<crate::mcp::tool::ListToolsResult>),
    #[schemars(title = "ToolsCall")]
    ToolsCall(JsonRpcResult<crate::mcp::tool::CallToolResult>),
    #[schemars(title = "ResourcesList")]
    ResourcesList(JsonRpcResult<crate::mcp::resource::ListResourcesResult>),
    #[schemars(title = "ResourcesRead")]
    ResourcesRead(JsonRpcResult<crate::mcp::resource::ReadResourceResult>),
    /// Infallible — reports whether a bucket was present and removed.
    #[schemars(title = "Drop")]
    Drop(DropResult),
    #[schemars(title = "Filetree")]
    Filetree(JsonRpcResult<TransferAck>),
    #[schemars(title = "ExportBegin")]
    ExportBegin(JsonRpcResult<TransferBeginResult>),
    #[schemars(title = "ExportRead")]
    ExportRead(JsonRpcResult<ExportChunk>),
    #[schemars(title = "ExportAbort")]
    ExportAbort(JsonRpcResult<TransferAck>),
    #[schemars(title = "ImportBegin")]
    ImportBegin(JsonRpcResult<TransferBeginResult>),
    #[schemars(title = "ImportWrite")]
    ImportWrite(JsonRpcResult<TransferAck>),
    #[schemars(title = "ImportEnd")]
    ImportEnd(JsonRpcResult<ImportEndResult>),
    #[schemars(title = "ImportAbort")]
    ImportAbort(JsonRpcResult<TransferAck>),
    #[schemars(title = "Create")]
    Create(JsonRpcResult<super::Identify>),
    #[schemars(title = "AgentEphemeralCreate")]
    AgentEphemeralCreate(JsonRpcResult<EphemeralCreated>),
    #[schemars(title = "PluginEphemeralCreate")]
    PluginEphemeralCreate(JsonRpcResult<EphemeralCreated>),
    #[schemars(title = "PluginImageReset")]
    PluginImageReset(JsonRpcResult<PluginImageResetResult>),
    #[schemars(title = "Delete")]
    Delete(JsonRpcResult<TransferAck>),
    #[schemars(title = "LocalTransfer")]
    LocalTransfer(JsonRpcResult<LocalTransferResult>),
    #[schemars(title = "BuildCreate")]
    BuildCreate(JsonRpcResult<BuildCreated>),
    #[schemars(title = "BuildRead")]
    BuildRead(JsonRpcResult<ExportChunk>),
    #[schemars(title = "BuildAbort")]
    BuildAbort(JsonRpcResult<TransferAck>),
}

/// JSON-RPC result/error shape for this channel's typed methods —
/// the host channel's OWN envelope, deliberately not shared with the
/// reverse channel's twin.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.JsonRpcResult.{R}", bound = "R: JsonSchema")]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum JsonRpcResult<R> {
    /// Method returned a typed result.
    #[schemars(title = "Ok")]
    Ok { result: R },
    /// Method returned a JSON-RPC error envelope.
    #[schemars(title = "Err")]
    Err {
        code: i64,
        message: String,
        #[serde(default, skip_serializing_if = "Option::is_none")]
        #[schemars(extend("omitempty" = true))]
        data: Option<serde_json::Value>,
    },
}

/// Successful payload for [`ResponsePayload::Initialize`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.InitializeReply")]
pub struct InitializeReply {
    /// The container upstream's native `Mcp-Session-Id`.
    pub mcp_session_id: String,
    /// The container's verbatim `InitializeResult`.
    pub result: crate::mcp::initialize_result::InitializeResult,
}

/// Parameters for [`RequestPayload::Drop`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.DropRequest")]
pub struct DropRequest {
    pub response_id: String,
}

/// Payload for [`ResponsePayload::Drop`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.DropResult")]
pub struct DropResult {
    pub dropped: bool,
}

/// Parameters for [`RequestPayload::Filetree`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.FiletreeRequest")]
pub struct FiletreeRequest {
    /// `true` ⇒ the daemon holds ≥1 live filetree subscriber for this
    /// laboratory; `false` ⇒ it holds none.
    pub on: bool,
}

/// Parameters for [`RequestPayload::ExportBegin`]. `path` exports
/// cp-style (a directory is archived under its basename).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ExportBeginRequest")]
pub struct ExportBeginRequest {
    pub path: String,
}

/// Parameters for [`RequestPayload::ImportBegin`]. The tar unpacks
/// into `path` (created if missing).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ImportBeginRequest")]
pub struct ImportBeginRequest {
    pub path: String,
}

/// Parameters for every transfer op addressed purely by its parked
/// `transfer_id` (read / end / both aborts).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.TransferIdRequest")]
pub struct TransferIdRequest {
    pub transfer_id: String,
}

/// Parameters for [`RequestPayload::ImportWrite`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ImportWriteRequest")]
pub struct ImportWriteRequest {
    pub transfer_id: String,
    /// RAW tar bytes. Never in the JSON header — rides OUT OF BAND in
    /// the binary wire frame (`crate::binary_frame`); serde skips it.
    #[serde(skip)]
    pub data: Vec<u8>,
}

/// Successful payload for the two `*Begin` transfer replies.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.TransferBeginResult")]
pub struct TransferBeginResult {
    pub transfer_id: String,
}

/// Successful payload for [`ResponsePayload::ExportRead`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ExportChunk")]
pub struct ExportChunk {
    /// RAW tar bytes; may be non-empty on the final chunk. Never in
    /// the JSON header — rides OUT OF BAND in the binary wire frame
    /// (`crate::binary_frame`); serde skips it.
    #[serde(skip)]
    pub data: Vec<u8>,
    /// `true` ⇒ the export completed and its parked entry is gone.
    pub eof: bool,
}

/// Empty ack for the fire-and-forget-shaped replies.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.TransferAck")]
pub struct TransferAck {}

/// Successful payload for [`ResponsePayload::ImportEnd`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.ImportEndResult")]
pub struct ImportEndResult {
    pub bytes: u64,
}

/// Successful payload for [`ResponsePayload::LocalTransfer`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.LocalTransferResult")]
pub struct LocalTransferResult {
    pub bytes: u64,
}

/// Parameters for [`RequestPayload::Create`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.CreateRequest")]
pub struct CreateRequest {
    pub id: String,
    /// The base image, always split — the joined reference string is
    /// constructed only inside the host's podman internals.
    pub image: crate::laboratories::LaboratoryImage,
    /// `[host, container]` bind-mount pairs.
    pub mounts: Vec<[String; 2]>,
    /// `[key, value]` environment pairs.
    pub env: Vec<[String; 2]>,
    pub cwd: String,
    /// For agent laboratories: the full id of the agent the
    /// laboratory derives from. `Some` ⇔ the id is under the reserved
    /// `oai-agent-` prefix (the host enforces both directions).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[schemars(extend("omitempty" = true))]
    pub agent_full_id: Option<String>,
}

/// Parameters for [`RequestPayload::AgentEphemeralCreate`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.AgentEphemeralCreateRequest")]
pub struct AgentEphemeralCreateRequest {
    /// The agent-completion response id this laboratory serves — bare
    /// base62, unique per completion. Becomes the laboratory id's
    /// suffix and the container label's `response_id`.
    pub response_id: String,
    /// The full id of the agent the laboratory derives from.
    pub agent_full_id: String,
    /// The agent-embedded laboratory spec (image, env, cwd) — the
    /// host re-derives the content-addressed image key from
    /// `(agent_full_id, laboratory)`.
    pub laboratory: crate::agent::Laboratory,
}

/// Parameters for [`RequestPayload::PluginEphemeralCreate`] — the
/// plugin's coordinate trio (`agent::plugin::prepare` already
/// lowercases owner/name; the host re-lowercases them defensively —
/// the version passes through untouched: it is required `v`-prefixed
/// at the declaration layer and git tags are case-sensitive) plus the
/// response id the laboratory serves.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.PluginEphemeralCreateRequest")]
pub struct PluginEphemeralCreateRequest {
    /// The agent-completion response id this laboratory serves.
    pub response_id: String,
    /// GitHub `<owner>` segment.
    pub owner: String,
    /// Repository segment.
    pub name: String,
    /// Plugin version — IS the repo's git tag (Go-modules style,
    /// `v`-prefixed), byte-for-byte; the tag must exist.
    pub version: String,
    /// The plugin's Postgres compartment ROLE, resolved (and
    /// provisioned) daemon-side before the create is forwarded. The
    /// host builds `OBJECTIVEAI_POSTGRES_URL` from this + its own
    /// tunnel-listener address (it never sees the daemon's own DB
    /// address).
    pub db_role: String,
    /// The compartment role's password (random, stored daemon-side).
    pub db_password: String,
    /// The application database name.
    pub db_database: String,
    /// DEVELOPMENT mode: an ABSOLUTE host directory that stands in for
    /// the git checkout, from `development plugins mcp create`.
    ///
    /// `Some` ⇒ the host fetches nothing and deletes nothing (the tree
    /// is the developer's), builds the image straight out of that
    /// directory, and binds the manifest's `mcp.development.caches` as
    /// build volumes. The daemon only forwards a registered plugin to
    /// the LOCAL host, so this path is always one the host can see.
    ///
    /// Optional + defaulted so frames from daemons predating this
    /// field still parse.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[schemars(extend("omitempty" = true))]
    pub development: Option<String>,
}

/// Parameters for [`RequestPayload::PluginImageReset`] — the
/// coordinate trio, exactly as [`PluginEphemeralCreateRequest`] takes
/// it.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.PluginImageResetRequest")]
pub struct PluginImageResetRequest {
    pub owner: String,
    pub name: String,
    pub version: String,
    /// Also delete the plugin's development CACHE directories.
    ///
    /// OFF by default, and that default is the point: reset is the
    /// per-edit verb, and the caches are the only reason the rebuild
    /// it triggers is fast. Wiping them every time would leave no way
    /// to ask for a fast rebuild. Turn it on for the rarer case — a
    /// corrupted cache, a changed toolchain, disk pressure.
    #[serde(default)]
    pub caches: bool,
}

/// Successful payload for [`ResponsePayload::PluginImageReset`].
///
/// Both fields are informational. Resetting a plugin that was never
/// built is a SUCCESS with `removed: false` — the point of the command
/// is that the next run rebuilds, and that is already true.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.PluginImageResetResult")]
pub struct PluginImageResetResult {
    /// Whether an image was actually removed.
    pub removed: bool,
    /// How many cache directories were deleted — always 0 unless
    /// [`PluginImageResetRequest::caches`] was set.
    pub caches_removed: u32,
}

/// Successful payload for BOTH ephemeral-create replies: the created
/// laboratory's identity (`response_id` Some, `running` true) AND its
/// single MCP connection's initialize result — one round trip, both
/// or neither.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.EphemeralCreated")]
pub struct EphemeralCreated {
    pub identify: super::Identify,
    pub reply: InitializeReply,
}

/// Parameters for [`RequestPayload::BuildCreate`] — the plugin's
/// coordinate trio, exactly as [`PluginEphemeralCreateRequest`] takes
/// it (owner/name lowercased defensively host-side; the version passes
/// through untouched — it IS the git tag, byte-for-byte).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.BuildCreateRequest")]
pub struct BuildCreateRequest {
    /// GitHub `<owner>` segment.
    pub owner: String,
    /// Repository segment.
    pub name: String,
    /// Plugin version — IS the repo's git tag; the tag must exist.
    pub version: String,
}

/// Successful payload for [`ResponsePayload::BuildCreate`]: the build
/// SUCCEEDED and its artifact is parked. Nothing is streamed before
/// this lands — a failed build never produces a truncated archive.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.BuildCreated")]
pub struct BuildCreated {
    /// The commit the version's tag resolved to — the daemon's
    /// `X-OBJECTIVEAI-SHA`.
    pub commit_sha: String,
    /// Drain handle for [`RequestPayload::BuildRead`].
    pub transfer_id: String,
    /// The artifact's total size in bytes.
    pub bytes: u64,
}

/// The JSON-RPC error code [`RequestPayload::BuildCreate`] answers
/// with when the plugin's git TAG does not exist — the one build
/// failure that is the caller's fault rather than the plugin's, and
/// the daemon's `404`. Every other failure uses the generic internal
/// code and becomes a `500`. A code (not a message substring) carries
/// it: the old route sniffed `"not found in"` out of an error string,
/// which is exactly the kind of coupling this replaces.
pub const BUILD_TAG_NOT_FOUND_CODE: i64 = -32004;

/// The code [`RequestPayload::PluginEphemeralCreate`] answers with
/// when a DEVELOPMENT registration's source is unusable — the
/// directory is missing, is not a directory, holds no
/// `objectiveai.json`, or its manifest does not validate.
///
/// Distinct from the generic internal code because it is not an
/// internal fault: it is the developer's own registration, and the
/// answer is "fix or remove it" rather than a 500. Same reasoning as
/// [`BUILD_TAG_NOT_FOUND_CODE`] — a code, never a message substring.
pub const PLUGIN_DEVELOPMENT_SOURCE_CODE: i64 = -32005;

/// Parameters for [`RequestPayload::Delete`].
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.DeleteRequest")]
pub struct DeleteRequest {
    pub id: String,
}

/// Parameters for [`RequestPayload::LocalTransfer`] — both endpoints
/// live on the receiving host, so raw ids + paths are the whole
/// address.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "laboratories.daemon.LocalTransferRequest")]
pub struct LocalTransferRequest {
    pub source_id: String,
    pub source_path: String,
    pub destination_id: String,
    pub destination_path: String,
}