objectiveai_sdk/cli/command/config/api/mcp_authorization/
mod.rs1pub 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.config.api.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#[objectiveai_sdk_macros::json_schema_ignore]
39#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
40#[schemars(rename = "cli.command.config.api.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
125#[cfg(feature = "cli-executor")]
126pub async fn execute<E: crate::cli::command::CommandExecutor>(
127 executor: &E,
128 request: Request,
129
130 agent_arguments: Option<&crate::cli::command::AgentArguments>,
131 ) -> Result<
132 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
133 E::Error,
134> {
135 use futures::StreamExt;
136 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
137 match request {
138 Request::Add(req) => {
139 let value = add::execute(executor, req, agent_arguments).await?;
140 Box::pin(crate::cli::command::StreamOnce::new(Ok(
141 Response::Add(value),
142 )))
143 }
144 Request::AddRequestSchema(req) => {
145 let value = add::request_schema::execute(executor, req, agent_arguments).await?;
146 Box::pin(crate::cli::command::StreamOnce::new(Ok(
147 Response::AddRequestSchema(value),
148 )))
149 }
150 Request::AddResponseSchema(req) => {
151 let value = add::response_schema::execute(executor, req, agent_arguments).await?;
152 Box::pin(crate::cli::command::StreamOnce::new(Ok(
153 Response::AddResponseSchema(value),
154 )))
155 }
156 Request::Del(req) => {
157 let value = del::execute(executor, req, agent_arguments).await?;
158 Box::pin(crate::cli::command::StreamOnce::new(Ok(
159 Response::Del(value),
160 )))
161 }
162 Request::DelRequestSchema(req) => {
163 let value = del::request_schema::execute(executor, req, agent_arguments).await?;
164 Box::pin(crate::cli::command::StreamOnce::new(Ok(
165 Response::DelRequestSchema(value),
166 )))
167 }
168 Request::DelResponseSchema(req) => {
169 let value = del::response_schema::execute(executor, req, agent_arguments).await?;
170 Box::pin(crate::cli::command::StreamOnce::new(Ok(
171 Response::DelResponseSchema(value),
172 )))
173 }
174 Request::Get(req) => {
175 let value = get::execute(executor, req, agent_arguments).await?;
176 Box::pin(crate::cli::command::StreamOnce::new(Ok(
177 Response::Get(value),
178 )))
179 }
180 Request::GetRequestSchema(req) => {
181 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
182 Box::pin(crate::cli::command::StreamOnce::new(Ok(
183 Response::GetRequestSchema(value),
184 )))
185 }
186 Request::GetResponseSchema(req) => {
187 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
188 Box::pin(crate::cli::command::StreamOnce::new(Ok(
189 Response::GetResponseSchema(value),
190 )))
191 }
192 };
193 Ok(stream)
194}
195
196#[cfg(feature = "cli-executor")]
197pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
198 executor: &E,
199 request: Request,
200 jq: String,
201
202 agent_arguments: Option<&crate::cli::command::AgentArguments>,
203 ) -> Result<
204 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
205 E::Error,
206> {
207 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
208 match request {
209 Request::Add(req) => {
210 let value = add::execute_jq(executor, req, jq, agent_arguments).await?;
211 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
212 }
213 Request::AddRequestSchema(req) => {
214 let value = add::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
215 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
216 }
217 Request::AddResponseSchema(req) => {
218 let value = add::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
219 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
220 }
221 Request::Del(req) => {
222 let value = del::execute_jq(executor, req, jq, agent_arguments).await?;
223 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
224 }
225 Request::DelRequestSchema(req) => {
226 let value = del::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
227 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
228 }
229 Request::DelResponseSchema(req) => {
230 let value = del::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
231 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
232 }
233 Request::Get(req) => {
234 let value = get::execute_jq(executor, req, jq, agent_arguments).await?;
235 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
236 }
237 Request::GetRequestSchema(req) => {
238 let value = get::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
239 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
240 }
241 Request::GetResponseSchema(req) => {
242 let value = get::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
243 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
244 }
245 };
246 Ok(stream)
247}