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 container, reconstructed from its `objectiveai.laboratory`
36/// label. Mirrors the `create` echo: `{ id, image, mounts, env, cwd }`.
37#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
38#[schemars(rename = "cli.command.laboratories.list.ResponseItem")]
39pub struct ResponseItem {
40    pub id: String,
41    pub image: String,
42    pub mounts: Vec<super::create::Mount>,
43    pub env: Vec<super::create::EnvVar>,
44    pub cwd: String,
45}
46
47#[derive(clap::Args)]
48#[command(group(clap::ArgGroup::new("side").required(true).args(["client"])))]
49pub struct Args {
50    /// List client-side laboratories (MCP servers the conduit dials).
51    /// Required (part of the `side` arg-group, which will gain `--server`).
52    #[arg(long)]
53    pub client: bool,
54    #[command(flatten)]
55    pub base: crate::cli::command::RequestBaseArgs,
56}
57
58#[derive(clap::Args)]
59#[command(args_conflicts_with_subcommands = true)]
60pub struct Command {
61    #[command(flatten)]
62    pub args: Args,
63    #[command(subcommand)]
64    pub schema: Option<Schema>,
65}
66
67#[derive(clap::Subcommand)]
68pub enum Schema {
69    /// Emit the JSON Schema for this leaf's `Request` type and exit.
70    RequestSchema(request_schema::Args),
71    /// Emit the JSON Schema for this leaf's `ResponseItem` type and exit.
72    ResponseSchema(response_schema::Args),
73}
74
75impl TryFrom<Args> for Request {
76    type Error = crate::cli::command::FromArgsError;
77    fn try_from(args: Args) -> Result<Self, Self::Error> {
78        if !args.client {
79            return Err(crate::cli::command::FromArgsError::path_parse(
80                "client",
81                "--client is required".to_string(),
82            ));
83        }
84        Ok(Self {
85            path_type: Path::LaboratoriesList,
86            kind: super::create::Kind::Client,
87            base: args.base.into(),
88        })
89    }
90}
91
92#[cfg(feature = "cli-executor")]
93pub async fn execute<E: crate::cli::command::CommandExecutor>(
94    executor: &E,
95    mut request: Request,
96    agent_arguments: Option<&crate::cli::command::AgentArguments>,
97) -> Result<E::Stream<ResponseItem>, E::Error> {
98    request.base.clear_transform();
99    executor.execute(request, agent_arguments).await
100}
101
102#[cfg(feature = "cli-executor")]
103pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
104    executor: &E,
105    mut request: Request,
106    transform: crate::cli::command::Transform,
107    agent_arguments: Option<&crate::cli::command::AgentArguments>,
108) -> Result<E::Stream<serde_json::Value>, E::Error> {
109    request.base.set_transform(transform);
110    executor.execute(request, agent_arguments).await
111}
112
113#[cfg(feature = "mcp")]
114impl crate::cli::command::CommandResponse for ResponseItem {
115    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
116        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
117    }
118}
119
120pub mod request_schema;
121
122pub mod response_schema;
123
124/// One `/listen` broadcast run of `laboratories list`: the actual
125/// [`Request`], the producer's
126/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
127/// response-item stream. See [`crate::cli::websocket_listener`].
128#[cfg(feature = "cli-listener")]
129pub struct ListenerExecution {
130    pub request: Request,
131    pub agent_arguments: crate::cli::command::AgentArguments,
132    pub response: crate::cli::websocket_listener::ResponseItemStream<ResponseItem>,
133}