Skip to main content

objectiveai_sdk/cli/command/functions/inventions/recursive/create/
mod.rs

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