Skip to main content

objectiveai_cli/command/laboratories/
list.rs

1//! `laboratories list` — stream the laboratory containers created in this
2//! state by reading them back from podman (the source of truth). Read-only.
3//! Only client-side laboratories are supported today.
4
5use std::pin::Pin;
6
7use futures::Stream;
8use objectiveai_sdk::cli::command::laboratories::create::{EnvVar, Kind, Mount};
9use objectiveai_sdk::cli::command::laboratories::list::{Request, ResponseItem};
10
11use crate::context::Context;
12use crate::error::Error;
13use crate::podman::laboratory;
14
15type ItemStream = Pin<Box<dyn Stream<Item = Result<ResponseItem, Error>> + Send>>;
16
17pub async fn execute(ctx: &Context, request: Request) -> Result<ItemStream, Error> {
18    // Only `Client` exists today; the match stays exhaustive so adding
19    // `Server` later forces a decision here.
20    match request.kind {
21        Kind::Client => {}
22    }
23
24    let labs = laboratory::list(ctx).await;
25    let stream = async_stream::stream! {
26        match labs {
27            Ok(labs) => {
28                for lab in labs {
29                    yield Ok(ResponseItem {
30                        id: lab.id,
31                        image: lab.image,
32                        mounts: lab
33                            .mounts
34                            .into_iter()
35                            .map(|m| Mount {
36                                host: m.host,
37                                container: m.container,
38                            })
39                            .collect(),
40                        env: lab
41                            .env
42                            .into_iter()
43                            .map(|(key, value)| EnvVar { key, value })
44                            .collect(),
45                        cwd: lab.cwd,
46                    });
47                }
48            }
49            Err(e) => yield Err(e),
50        }
51    };
52    Ok(Box::pin(stream))
53}
54
55pub mod request_schema {
56    use objectiveai_sdk::cli::command::laboratories::list as sdk;
57    use objectiveai_sdk::cli::command::laboratories::list::request_schema::{Request, Response};
58
59    use crate::context::Context;
60    use crate::error::Error;
61
62    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
63        Ok(objectiveai_sdk::cli::command::ResponseSchema(
64            schemars::schema_for!(sdk::Request),
65        ))
66    }
67}
68
69pub mod response_schema {
70    use objectiveai_sdk::cli::command::laboratories::list as sdk;
71    use objectiveai_sdk::cli::command::laboratories::list::response_schema::{Request, Response};
72
73    use crate::context::Context;
74    use crate::error::Error;
75
76    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
77        Ok(objectiveai_sdk::cli::command::ResponseSchema(
78            schemars::schema_for!(sdk::ResponseItem),
79        ))
80    }
81}