Skip to main content

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

1//! `laboratories delete` — remove a laboratory container (a podman
2//! `rm -f`), reclaiming its disk. Names the container per state
3//! (`--id`); `--client` is required (a required arg-group, matching
4//! `create`, leaving room to add `--server` later). The leaf echoes
5//! back the id it removed.
6
7use crate::cli::command::CommandRequest;
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[schemars(rename = "cli.command.laboratories.delete.Request")]
11pub struct Request {
12    pub path_type: Path,
13    pub kind: Kind,
14    pub id: String,
15    /// The EXACT machine id whose laboratory host owns the container.
16    /// Provided together with `machine_state` or not at all; neither ⇒
17    /// the current machine + the daemon's own state.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    #[schemars(extend("omitempty" = true))]
20    pub machine: Option<String>,
21    /// The state (on `machine`) whose laboratory host owns the
22    /// container. Paired with `machine` — both or neither.
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    #[schemars(extend("omitempty" = true))]
25    pub machine_state: Option<String>,
26    #[serde(flatten)]
27    pub base: crate::cli::command::RequestBase,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.laboratories.delete.Path")]
32pub enum Path {
33    #[serde(rename = "laboratories/delete")]
34    LaboratoriesDelete,
35}
36
37/// Which side of the conduit the laboratory serves. Only `Client`
38/// exists today; the tag-by-`by` shape leaves room to add `Server`
39/// later.
40#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
41#[serde(tag = "by", rename_all = "snake_case")]
42#[schemars(rename = "cli.command.laboratories.delete.Kind")]
43pub enum Kind {
44    // No variant-level `#[schemars(title = "...")]`: a single-variant enum
45    // collapses and hoists the variant title to the schema's top-level
46    // `title`, which the JS codegen then uses as the module path — a title
47    // of "Client" would clobber `src/client.ts`. Let `rename` drive it.
48    Client,
49}
50
51impl CommandRequest for Request {
52    fn request_base(&self) -> &crate::cli::command::RequestBase {
53        &self.base
54    }
55
56    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
57        Some(&mut self.base)
58    }
59}
60
61/// Echo of the removed laboratory.
62#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
63#[schemars(rename = "cli.command.laboratories.delete.Response")]
64pub struct Response {
65    pub id: String,
66}
67
68#[derive(clap::Args)]
69#[command(
70    group(clap::ArgGroup::new("side").required(true).args(["client"])),
71    group(clap::ArgGroup::new("id_required").required(true).args(["id"])),
72)]
73pub struct Args {
74    /// Delete a client-side laboratory (an MCP server the conduit dials).
75    /// Required (part of the `side` arg-group, which will gain `--server`).
76    #[arg(long)]
77    pub client: bool,
78    /// Laboratory id — names the per-state container.
79    #[arg(long)]
80    pub id: Option<String>,
81    /// The EXACT machine id whose host owns the container. Requires
82    /// `--machine-state`; neither ⇒ the current machine + the daemon's
83    /// own state.
84    #[arg(long, requires = "machine_state")]
85    pub machine: Option<String>,
86    /// The state (on `--machine`) whose host owns the container.
87    /// Requires `--machine` — both or neither.
88    #[arg(long, requires = "machine")]
89    pub machine_state: Option<String>,
90    #[command(flatten)]
91    pub base: crate::cli::command::RequestBaseArgs,
92}
93
94#[derive(clap::Args)]
95#[command(args_conflicts_with_subcommands = true)]
96pub struct Command {
97    #[command(flatten)]
98    pub args: Args,
99    #[command(subcommand)]
100    pub schema: Option<Schema>,
101}
102
103#[derive(clap::Subcommand)]
104pub enum Schema {
105    /// Emit the JSON Schema for this leaf's `Request` type and exit.
106    RequestSchema(request_schema::Args),
107    /// Emit the JSON Schema for this leaf's `Response` type and exit.
108    ResponseSchema(response_schema::Args),
109}
110
111impl TryFrom<Args> for Request {
112    type Error = crate::cli::command::FromArgsError;
113    fn try_from(args: Args) -> Result<Self, Self::Error> {
114        let id = args.id.ok_or_else(|| {
115            crate::cli::command::FromArgsError::path_parse("id", "--id is required".to_string())
116        })?;
117        if !args.client {
118            return Err(crate::cli::command::FromArgsError::path_parse(
119                "client",
120                "--client is required".to_string(),
121            ));
122        }
123        // Both-or-neither, re-validated beyond clap's mutual
124        // `requires` (which only runs for argv-built requests).
125        if args.machine.is_some() != args.machine_state.is_some() {
126            return Err(crate::cli::command::FromArgsError::path_parse(
127                "machine",
128                "--machine and --machine-state must be provided together".to_string(),
129            ));
130        }
131        Ok(Self {
132            path_type: Path::LaboratoriesDelete,
133            kind: Kind::Client,
134            id,
135            machine: args.machine,
136            machine_state: args.machine_state,
137            base: args.base.into(),
138        })
139    }
140}
141
142#[cfg(feature = "cli-executor")]
143pub async fn execute<E: crate::cli::command::CommandExecutor>(
144    executor: &E,
145    mut request: Request,
146    agent_arguments: Option<&crate::cli::command::AgentArguments>,
147) -> Result<Response, E::Error> {
148    request.base.clear_transform();
149    executor.execute_one(request, agent_arguments).await
150}
151
152#[cfg(feature = "cli-executor")]
153pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
154    executor: &E,
155    mut request: Request,
156    transform: crate::cli::command::Transform,
157    agent_arguments: Option<&crate::cli::command::AgentArguments>,
158) -> Result<serde_json::Value, E::Error> {
159    request.base.set_transform(transform);
160    executor.execute_one(request, agent_arguments).await
161}
162
163#[cfg(feature = "mcp")]
164impl crate::cli::command::CommandResponse for Response {
165    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
166        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
167    }
168}
169
170pub mod request_schema;
171
172pub mod response_schema;
173
174/// One `/listen` broadcast run of `laboratories delete`: the actual
175/// [`Request`], the producer's
176/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
177/// unary response future. See [`crate::cli::broadcast_listener`].
178#[cfg(feature = "cli-listener")]
179pub struct ListenerExecution {
180    pub request: Request,
181    pub agent_arguments: crate::cli::command::AgentArguments,
182    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
183}