Skip to main content

objectiveai_sdk/cli/command/config/
mod.rs

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