Skip to main content

objectiveai_sdk/cli/command/functions/
mod.rs

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