Skip to main content

objectiveai_sdk/cli/command/laboratories/list/
mod.rs

1//! `laboratories list` — stream the laboratory containers created in this
2//! state (podman containers the conduit dials as client-side MCP servers).
3//! Read-only; reads back from podman (the source of truth). `--client` is
4//! required (a required arg-group, leaving room to add `--server` later).
5//! Each item echoes a laboratory's spec: `{ id, image, mounts, env, cwd }`.
6
7use crate::cli::command::CommandRequest;
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[schemars(rename = "cli.command.laboratories.list.Request")]
11pub struct Request {
12    pub path_type: Path,
13    pub kind: super::create::Kind,
14    #[serde(flatten)]
15    pub base: crate::cli::command::RequestBase,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[schemars(rename = "cli.command.laboratories.list.Path")]
20pub enum Path {
21    #[serde(rename = "laboratories/list")]
22    LaboratoriesList,
23}
24
25impl CommandRequest for Request {
26    fn request_base(&self) -> &crate::cli::command::RequestBase {
27        &self.base
28    }
29
30    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
31        Some(&mut self.base)
32    }
33}
34
35/// One laboratory served by a connected laboratory HOST. There is no
36/// local-vs-remote split — machine identity is the only provenance,
37/// the same logic regardless of where the host runs.
38#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
39#[schemars(rename = "cli.command.laboratories.list.ResponseItem")]
40pub struct ResponseItem {
41    pub id: String,
42    pub image: crate::laboratories::LaboratoryImage,
43    pub mounts: Vec<crate::laboratories::Mount>,
44    pub env: Vec<crate::laboratories::EnvVar>,
45    pub cwd: String,
46    /// Unix seconds when the laboratory container was created, from
47    /// podman's container record. `None` when the host didn't report
48    /// it.
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    #[schemars(extend("omitempty" = true))]
51    pub created_at: Option<i64>,
52    /// For agent laboratories: the full id of the agent the
53    /// laboratory derives from. `None` for user-created laboratories.
54    #[serde(default, skip_serializing_if = "Option::is_none")]
55    #[schemars(extend("omitempty" = true))]
56    pub agent_full_id: Option<String>,
57    /// For plugin laboratories: the plugin's canonical coordinate
58    /// trio (owner/name lowercased, version verbatim — the repo's
59    /// `v`-prefixed git tag). `None` for every other laboratory.
60    #[serde(default, skip_serializing_if = "Option::is_none")]
61    #[schemars(extend("omitempty" = true))]
62    pub plugin: Option<Plugin>,
63    /// For EPHEMERAL laboratories (agent and plugin): the
64    /// agent-completion response id the laboratory serves — its
65    /// lifetime is that completion's single MCP connection. `None`
66    /// for regular laboratories.
67    #[serde(default, skip_serializing_if = "Option::is_none")]
68    #[schemars(extend("omitempty" = true))]
69    pub response_id: Option<String>,
70    /// The machine whose laboratory host serves this laboratory.
71    #[serde(default, skip_serializing_if = "Option::is_none")]
72    #[schemars(extend("omitempty" = true))]
73    pub machine: Option<crate::machine::MachineIdentity>,
74    /// The state (on that machine) the serving host serves —
75    /// laboratory ids are only unique per (machine, state).
76    #[serde(default, skip_serializing_if = "Option::is_none")]
77    #[schemars(extend("omitempty" = true))]
78    pub machine_state: Option<String>,
79    /// Whether the laboratory's CONTAINER is running right now (the
80    /// lifecycle starts and stops containers on demand). Defaulted so
81    /// older daemons' items parse (as not-running).
82    #[serde(default)]
83    pub running: bool,
84}
85
86/// A plugin laboratory's canonical coordinate trio, as carried by
87/// [`ResponseItem::plugin`] — a local wire-shape twin of the host
88/// channel's `laboratories.daemon.IdentifyPlugin` (that module is
89/// feature-gated behind `laboratory-daemon` and deliberately not
90/// imported here).
91#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
92#[schemars(rename = "cli.command.laboratories.list.Plugin")]
93pub struct Plugin {
94    pub owner: String,
95    pub name: String,
96    pub version: String,
97}
98
99#[derive(clap::Args)]
100#[command(group(clap::ArgGroup::new("side").required(true).args(["client"])))]
101pub struct Args {
102    /// List client-side laboratories (MCP servers the conduit dials).
103    /// Required (part of the `side` arg-group, which will gain `--server`).
104    #[arg(long)]
105    pub client: bool,
106    #[command(flatten)]
107    pub base: crate::cli::command::RequestBaseArgs,
108}
109
110#[derive(clap::Args)]
111#[command(args_conflicts_with_subcommands = true)]
112pub struct Command {
113    #[command(flatten)]
114    pub args: Args,
115    #[command(subcommand)]
116    pub schema: Option<Schema>,
117}
118
119#[derive(clap::Subcommand)]
120pub enum Schema {
121    /// Emit the JSON Schema for this leaf's `Request` type and exit.
122    RequestSchema(request_schema::Args),
123    /// Emit the JSON Schema for this leaf's `ResponseItem` type and exit.
124    ResponseSchema(response_schema::Args),
125}
126
127impl TryFrom<Args> for Request {
128    type Error = crate::cli::command::FromArgsError;
129    fn try_from(args: Args) -> Result<Self, Self::Error> {
130        if !args.client {
131            return Err(crate::cli::command::FromArgsError::path_parse(
132                "client",
133                "--client is required".to_string(),
134            ));
135        }
136        Ok(Self {
137            path_type: Path::LaboratoriesList,
138            kind: super::create::Kind::Client,
139            base: args.base.into(),
140        })
141    }
142}
143
144#[cfg(feature = "cli-executor")]
145pub async fn execute<E: crate::cli::command::CommandExecutor>(
146    executor: &E,
147    mut request: Request,
148    identity: Option<&crate::identity::Identity>,
149) -> Result<E::Stream<ResponseItem>, E::Error> {
150    request.base.clear_transform();
151    executor.execute(request, identity).await
152}
153
154#[cfg(feature = "cli-executor")]
155pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
156    executor: &E,
157    mut request: Request,
158    transform: crate::cli::command::Transform,
159    identity: Option<&crate::identity::Identity>,
160) -> Result<E::Stream<serde_json::Value>, E::Error> {
161    request.base.set_transform(transform);
162    executor.execute(request, identity).await
163}
164
165#[cfg(feature = "mcp")]
166impl crate::cli::command::CommandResponse for ResponseItem {
167    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
168        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
169    }
170}
171
172pub mod request_schema;
173
174pub mod response_schema;
175
176/// One `/listen` broadcast run of `laboratories list`: the actual
177/// [`Request`], the producer's
178/// [`Identity`](crate::identity::Identity), and the
179/// response-item stream. See [`crate::daemon::command_listener`].
180#[cfg(all(feature = "cli", feature = "daemon"))]
181pub struct ListenerExecution {
182    pub request: Request,
183    pub identity: crate::identity::Identity,
184    pub response: crate::daemon::command_listener::ResponseItemStream<ResponseItem>,
185}