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<super::create::Mount>,
44    pub env: Vec<super::create::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    /// The machine whose laboratory host serves this laboratory.
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    #[schemars(extend("omitempty" = true))]
60    pub machine: Option<crate::machine::MachineIdentity>,
61    /// The state (on that machine) the serving host serves —
62    /// laboratory ids are only unique per (machine, state).
63    #[serde(default, skip_serializing_if = "Option::is_none")]
64    #[schemars(extend("omitempty" = true))]
65    pub machine_state: Option<String>,
66    /// Whether the laboratory's CONTAINER is running right now (the
67    /// lifecycle starts and stops containers on demand). Defaulted so
68    /// older daemons' items parse (as not-running).
69    #[serde(default)]
70    pub running: bool,
71}
72
73#[derive(clap::Args)]
74#[command(group(clap::ArgGroup::new("side").required(true).args(["client"])))]
75pub struct Args {
76    /// List client-side laboratories (MCP servers the conduit dials).
77    /// Required (part of the `side` arg-group, which will gain `--server`).
78    #[arg(long)]
79    pub client: bool,
80    #[command(flatten)]
81    pub base: crate::cli::command::RequestBaseArgs,
82}
83
84#[derive(clap::Args)]
85#[command(args_conflicts_with_subcommands = true)]
86pub struct Command {
87    #[command(flatten)]
88    pub args: Args,
89    #[command(subcommand)]
90    pub schema: Option<Schema>,
91}
92
93#[derive(clap::Subcommand)]
94pub enum Schema {
95    /// Emit the JSON Schema for this leaf's `Request` type and exit.
96    RequestSchema(request_schema::Args),
97    /// Emit the JSON Schema for this leaf's `ResponseItem` type and exit.
98    ResponseSchema(response_schema::Args),
99}
100
101impl TryFrom<Args> for Request {
102    type Error = crate::cli::command::FromArgsError;
103    fn try_from(args: Args) -> Result<Self, Self::Error> {
104        if !args.client {
105            return Err(crate::cli::command::FromArgsError::path_parse(
106                "client",
107                "--client is required".to_string(),
108            ));
109        }
110        Ok(Self {
111            path_type: Path::LaboratoriesList,
112            kind: super::create::Kind::Client,
113            base: args.base.into(),
114        })
115    }
116}
117
118#[cfg(feature = "cli-executor")]
119pub async fn execute<E: crate::cli::command::CommandExecutor>(
120    executor: &E,
121    mut request: Request,
122    agent_arguments: Option<&crate::cli::command::AgentArguments>,
123) -> Result<E::Stream<ResponseItem>, E::Error> {
124    request.base.clear_transform();
125    executor.execute(request, agent_arguments).await
126}
127
128#[cfg(feature = "cli-executor")]
129pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
130    executor: &E,
131    mut request: Request,
132    transform: crate::cli::command::Transform,
133    agent_arguments: Option<&crate::cli::command::AgentArguments>,
134) -> Result<E::Stream<serde_json::Value>, E::Error> {
135    request.base.set_transform(transform);
136    executor.execute(request, agent_arguments).await
137}
138
139#[cfg(feature = "mcp")]
140impl crate::cli::command::CommandResponse for ResponseItem {
141    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
142        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
143    }
144}
145
146pub mod request_schema;
147
148pub mod response_schema;
149
150/// One `/listen` broadcast run of `laboratories list`: the actual
151/// [`Request`], the producer's
152/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
153/// response-item stream. See [`crate::cli::broadcast_listener`].
154#[cfg(feature = "cli-listener")]
155pub struct ListenerExecution {
156    pub request: Request,
157    pub agent_arguments: crate::cli::command::AgentArguments,
158    pub response: crate::cli::broadcast_listener::ResponseItemStream<ResponseItem>,
159}