Skip to main content

objectiveai_sdk/cli/command/laboratories/config/local/
mod.rs

1pub mod get;
2pub mod set;
3
4#[derive(clap::Subcommand)]
5pub enum Command {
6    Get(get::Command),
7    Set(set::Command),
8}
9
10#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[serde(untagged)]
12#[schemars(rename = "cli.command.laboratories.config.local.Request")]
13pub enum Request {
14    #[schemars(title = "Get")]
15    Get(get::Request),
16    #[schemars(title = "GetRequestSchema")]
17    GetRequestSchema(get::request_schema::Request),
18    #[schemars(title = "GetResponseSchema")]
19    GetResponseSchema(get::response_schema::Request),
20    #[schemars(title = "Set")]
21    Set(set::Request),
22    #[schemars(title = "SetRequestSchema")]
23    SetRequestSchema(set::request_schema::Request),
24    #[schemars(title = "SetResponseSchema")]
25    SetResponseSchema(set::response_schema::Request),
26}
27
28// Exempt from json-schema coverage: tier aggregate (see the root
29// `ResponseItem` in command.rs - TS7056).
30#[objectiveai_sdk_macros::json_schema_ignore]
31#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.laboratories.config.local.Response")]
33#[serde(untagged)]
34pub enum Response {
35    #[schemars(title = "Get")]
36    Get(get::Response),
37    #[schemars(title = "GetRequestSchema")]
38    GetRequestSchema(get::request_schema::Response),
39    #[schemars(title = "GetResponseSchema")]
40    GetResponseSchema(get::response_schema::Response),
41    #[schemars(title = "Set")]
42    Set(set::Response),
43    #[schemars(title = "SetRequestSchema")]
44    SetRequestSchema(set::request_schema::Response),
45    #[schemars(title = "SetResponseSchema")]
46    SetResponseSchema(set::response_schema::Response),
47}
48
49#[cfg(feature = "mcp")]
50impl crate::cli::command::CommandResponse for Response {
51    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
52        match self {
53            Response::Get(v) => v.into_mcp(),
54            Response::GetRequestSchema(v) => v.into_mcp(),
55            Response::GetResponseSchema(v) => v.into_mcp(),
56            Response::Set(v) => v.into_mcp(),
57            Response::SetRequestSchema(v) => v.into_mcp(),
58            Response::SetResponseSchema(v) => v.into_mcp(),
59        }
60    }
61}
62
63impl TryFrom<Command> for Request {
64    type Error = crate::cli::command::FromArgsError;
65    fn try_from(command: Command) -> Result<Self, Self::Error> {
66        match command {
67            Command::Get(cmd) => match cmd.schema {
68                None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
69                Some(get::Schema::RequestSchema(args)) =>
70                    Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
71                Some(get::Schema::ResponseSchema(args)) =>
72                    Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
73            },
74            Command::Set(cmd) => match cmd.schema {
75                None => Ok(Request::Set(set::Request::try_from(cmd.args)?)),
76                Some(set::Schema::RequestSchema(args)) =>
77                    Ok(Request::SetRequestSchema(set::request_schema::Request::try_from(args)?)),
78                Some(set::Schema::ResponseSchema(args)) =>
79                    Ok(Request::SetResponseSchema(set::response_schema::Request::try_from(args)?)),
80            },
81        }
82    }
83}
84
85impl crate::cli::command::CommandRequest for Request {
86    fn request_base(&self) -> &crate::cli::command::RequestBase {
87        match self {
88            Request::Get(inner) => inner.request_base(),
89            Request::GetRequestSchema(inner) => inner.request_base(),
90            Request::GetResponseSchema(inner) => inner.request_base(),
91            Request::Set(inner) => inner.request_base(),
92            Request::SetRequestSchema(inner) => inner.request_base(),
93            Request::SetResponseSchema(inner) => inner.request_base(),
94        }
95    }
96
97    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
98        match self {
99            Request::Get(inner) => inner.request_base_mut(),
100            Request::GetRequestSchema(inner) => inner.request_base_mut(),
101            Request::GetResponseSchema(inner) => inner.request_base_mut(),
102            Request::Set(inner) => inner.request_base_mut(),
103            Request::SetRequestSchema(inner) => inner.request_base_mut(),
104            Request::SetResponseSchema(inner) => inner.request_base_mut(),
105        }
106    }
107}
108
109#[cfg(feature = "cli-executor")]
110pub async fn execute<E: crate::cli::command::CommandExecutor>(
111    executor: &E,
112    request: Request,
113
114        agent_arguments: Option<&crate::cli::command::AgentArguments>,
115    ) -> Result<
116    std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
117    E::Error,
118> {
119    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
120        match request {
121            Request::Get(req) => {
122                let value = get::execute(executor, req, agent_arguments).await?;
123                Box::pin(crate::cli::command::StreamOnce::new(Ok(
124                    Response::Get(value),
125                )))
126            }
127            Request::GetRequestSchema(req) => {
128                let value = get::request_schema::execute(executor, req, agent_arguments).await?;
129                Box::pin(crate::cli::command::StreamOnce::new(Ok(
130                    Response::GetRequestSchema(value),
131                )))
132            }
133            Request::GetResponseSchema(req) => {
134                let value = get::response_schema::execute(executor, req, agent_arguments).await?;
135                Box::pin(crate::cli::command::StreamOnce::new(Ok(
136                    Response::GetResponseSchema(value),
137                )))
138            }
139            Request::Set(req) => {
140                let value = set::execute(executor, req, agent_arguments).await?;
141                Box::pin(crate::cli::command::StreamOnce::new(Ok(
142                    Response::Set(value),
143                )))
144            }
145            Request::SetRequestSchema(req) => {
146                let value = set::request_schema::execute(executor, req, agent_arguments).await?;
147                Box::pin(crate::cli::command::StreamOnce::new(Ok(
148                    Response::SetRequestSchema(value),
149                )))
150            }
151            Request::SetResponseSchema(req) => {
152                let value = set::response_schema::execute(executor, req, agent_arguments).await?;
153                Box::pin(crate::cli::command::StreamOnce::new(Ok(
154                    Response::SetResponseSchema(value),
155                )))
156            }
157        };
158    Ok(stream)
159}
160
161#[cfg(feature = "cli-executor")]
162pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
163    executor: &E,
164    request: Request,
165    transform: crate::cli::command::Transform,
166
167        agent_arguments: Option<&crate::cli::command::AgentArguments>,
168    ) -> Result<
169    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
170    E::Error,
171> {
172    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
173        match request {
174            Request::Get(req) => {
175                let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
176                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
177            }
178            Request::GetRequestSchema(req) => {
179                let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
180                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
181            }
182            Request::GetResponseSchema(req) => {
183                let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
184                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
185            }
186            Request::Set(req) => {
187                let value = set::execute_transform(executor, req, transform, agent_arguments).await?;
188                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
189            }
190            Request::SetRequestSchema(req) => {
191                let value = set::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
192                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
193            }
194            Request::SetResponseSchema(req) => {
195                let value = set::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
196                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
197            }
198        };
199    Ok(stream)
200}
201
202/// `/listen` mirror of [`Request`]: one variant per child, wrapping
203/// its `ListenerExecution`. See [`crate::cli::broadcast_listener`].
204#[cfg(feature = "cli-listener")]
205pub enum ListenerExecution {
206    Get(get::ListenerExecution),
207    GetRequestSchema(get::request_schema::ListenerExecution),
208    GetResponseSchema(get::response_schema::ListenerExecution),
209    Set(set::ListenerExecution),
210    SetRequestSchema(set::request_schema::ListenerExecution),
211    SetResponseSchema(set::response_schema::ListenerExecution),
212}