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 into_command(&self) -> Vec<String> {
111        match self {
112            Request::Add(inner) => inner.into_command(),
113            Request::AddRequestSchema(inner) => inner.into_command(),
114            Request::AddResponseSchema(inner) => inner.into_command(),
115            Request::Del(inner) => inner.into_command(),
116            Request::DelRequestSchema(inner) => inner.into_command(),
117            Request::DelResponseSchema(inner) => inner.into_command(),
118            Request::Get(inner) => inner.into_command(),
119            Request::GetRequestSchema(inner) => inner.into_command(),
120            Request::GetResponseSchema(inner) => inner.into_command(),
121        }
122    }
123
124    fn request_base(&self) -> &crate::cli::command::RequestBase {
125        match self {
126            Request::Add(inner) => inner.request_base(),
127            Request::AddRequestSchema(inner) => inner.request_base(),
128            Request::AddResponseSchema(inner) => inner.request_base(),
129            Request::Del(inner) => inner.request_base(),
130            Request::DelRequestSchema(inner) => inner.request_base(),
131            Request::DelResponseSchema(inner) => inner.request_base(),
132            Request::Get(inner) => inner.request_base(),
133            Request::GetRequestSchema(inner) => inner.request_base(),
134            Request::GetResponseSchema(inner) => inner.request_base(),
135        }
136    }
137
138    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
139        match self {
140            Request::Add(inner) => inner.request_base_mut(),
141            Request::AddRequestSchema(inner) => inner.request_base_mut(),
142            Request::AddResponseSchema(inner) => inner.request_base_mut(),
143            Request::Del(inner) => inner.request_base_mut(),
144            Request::DelRequestSchema(inner) => inner.request_base_mut(),
145            Request::DelResponseSchema(inner) => inner.request_base_mut(),
146            Request::Get(inner) => inner.request_base_mut(),
147            Request::GetRequestSchema(inner) => inner.request_base_mut(),
148            Request::GetResponseSchema(inner) => inner.request_base_mut(),
149        }
150    }
151}
152
153#[cfg(feature = "cli-executor")]
154pub async fn execute<E: crate::cli::command::CommandExecutor>(
155    executor: &E,
156    request: Request,
157
158        agent_arguments: Option<&crate::cli::command::AgentArguments>,
159    ) -> Result<
160    std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
161    E::Error,
162> {
163    use futures::StreamExt;
164    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
165        match request {
166            Request::Add(req) => {
167                let value = add::execute(executor, req, agent_arguments).await?;
168                Box::pin(crate::cli::command::StreamOnce::new(Ok(
169                    Response::Add(value),
170                )))
171            }
172            Request::AddRequestSchema(req) => {
173                let value = add::request_schema::execute(executor, req, agent_arguments).await?;
174                Box::pin(crate::cli::command::StreamOnce::new(Ok(
175                    Response::AddRequestSchema(value),
176                )))
177            }
178            Request::AddResponseSchema(req) => {
179                let value = add::response_schema::execute(executor, req, agent_arguments).await?;
180                Box::pin(crate::cli::command::StreamOnce::new(Ok(
181                    Response::AddResponseSchema(value),
182                )))
183            }
184            Request::Del(req) => {
185                let value = del::execute(executor, req, agent_arguments).await?;
186                Box::pin(crate::cli::command::StreamOnce::new(Ok(
187                    Response::Del(value),
188                )))
189            }
190            Request::DelRequestSchema(req) => {
191                let value = del::request_schema::execute(executor, req, agent_arguments).await?;
192                Box::pin(crate::cli::command::StreamOnce::new(Ok(
193                    Response::DelRequestSchema(value),
194                )))
195            }
196            Request::DelResponseSchema(req) => {
197                let value = del::response_schema::execute(executor, req, agent_arguments).await?;
198                Box::pin(crate::cli::command::StreamOnce::new(Ok(
199                    Response::DelResponseSchema(value),
200                )))
201            }
202            Request::Get(req) => {
203                let value = get::execute(executor, req, agent_arguments).await?;
204                Box::pin(crate::cli::command::StreamOnce::new(Ok(
205                    Response::Get(value),
206                )))
207            }
208            Request::GetRequestSchema(req) => {
209                let value = get::request_schema::execute(executor, req, agent_arguments).await?;
210                Box::pin(crate::cli::command::StreamOnce::new(Ok(
211                    Response::GetRequestSchema(value),
212                )))
213            }
214            Request::GetResponseSchema(req) => {
215                let value = get::response_schema::execute(executor, req, agent_arguments).await?;
216                Box::pin(crate::cli::command::StreamOnce::new(Ok(
217                    Response::GetResponseSchema(value),
218                )))
219            }
220        };
221    Ok(stream)
222}
223
224#[cfg(feature = "cli-executor")]
225pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
226    executor: &E,
227    request: Request,
228    transform: crate::cli::command::Transform,
229
230        agent_arguments: Option<&crate::cli::command::AgentArguments>,
231    ) -> Result<
232    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
233    E::Error,
234> {
235    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
236        match request {
237            Request::Add(req) => {
238                let value = add::execute_transform(executor, req, transform, agent_arguments).await?;
239                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
240            }
241            Request::AddRequestSchema(req) => {
242                let value = add::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
243                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
244            }
245            Request::AddResponseSchema(req) => {
246                let value = add::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
247                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
248            }
249            Request::Del(req) => {
250                let value = del::execute_transform(executor, req, transform, agent_arguments).await?;
251                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
252            }
253            Request::DelRequestSchema(req) => {
254                let value = del::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
255                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
256            }
257            Request::DelResponseSchema(req) => {
258                let value = del::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
259                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
260            }
261            Request::Get(req) => {
262                let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
263                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
264            }
265            Request::GetRequestSchema(req) => {
266                let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
267                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
268            }
269            Request::GetResponseSchema(req) => {
270                let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
271                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
272            }
273        };
274    Ok(stream)
275}