Skip to main content

objectiveai_sdk/cli/command/config/swarms/favorites/
mod.rs

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