Skip to main content

objectiveai_sdk/cli/command/api/config/mcp_authorization/
mod.rs

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