Skip to main content

objectiveai_sdk/cli/command/config/
mod.rs

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