Skip to main content

objectiveai_sdk/cli/command/functions/executions/create/
mod.rs

1pub mod standard;
2pub mod swiss_system;
3
4/// CLI-surface form for the `--function-inline` argument: either a fully
5/// resolved inline-or-remote spec, or a bare favorite name that the CLI
6/// resolves to one of those at handler time. Untagged: an inline function
7/// object or remote-path object lands on `Resolved`; a bare JSON string
8/// lands on `Favorite`.
9#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[serde(untagged)]
11#[schemars(rename = "cli.command.functions.executions.create.FunctionSpec")]
12pub enum FunctionSpec {
13    #[schemars(title = "Resolved")]
14    Resolved(crate::functions::FullInlineFunctionOrRemoteCommitOptional),
15    #[schemars(title = "Favorite")]
16    Favorite(String),
17}
18
19/// CLI-surface form for the `--profile-inline` argument: either a fully
20/// resolved inline-or-remote spec, or a bare favorite name that the CLI
21/// resolves to one of those at handler time. Untagged: an inline profile
22/// object or remote-path object lands on `Resolved`; a bare JSON string
23/// lands on `Favorite`.
24#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
25#[serde(untagged)]
26#[schemars(rename = "cli.command.functions.executions.create.ProfileSpec")]
27pub enum ProfileSpec {
28    #[schemars(title = "Resolved")]
29    Resolved(crate::functions::InlineProfileOrRemoteCommitOptional),
30    #[schemars(title = "Favorite")]
31    Favorite(String),
32}
33
34#[derive(clap::Subcommand)]
35pub enum Command {
36    Standard(standard::Command),
37    SwissSystem(swiss_system::Command),
38}
39
40#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
41#[serde(untagged)]
42#[schemars(rename = "cli.command.functions.executions.create.Request")]
43pub enum Request {
44    #[schemars(title = "Standard")]
45    Standard(standard::Request),
46    #[schemars(title = "StandardRequestSchema")]
47    StandardRequestSchema(standard::request_schema::Request),
48    #[schemars(title = "StandardResponseSchema")]
49    StandardResponseSchema(standard::response_schema::Request),
50    #[schemars(title = "SwissSystem")]
51    SwissSystem(swiss_system::Request),
52    #[schemars(title = "SwissSystemRequestSchema")]
53    SwissSystemRequestSchema(swiss_system::request_schema::Request),
54    #[schemars(title = "SwissSystemResponseSchema")]
55    SwissSystemResponseSchema(swiss_system::response_schema::Request),
56}
57
58// Exempt from json-schema coverage: tier aggregate (see the root
59// `ResponseItem` in command.rs - TS7056).
60#[objectiveai_sdk_macros::json_schema_ignore]
61#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
62#[schemars(rename = "cli.command.functions.executions.create.ResponseItem")]
63#[serde(untagged)]
64pub enum ResponseItem {
65    #[schemars(title = "Standard")]
66    Standard(standard::ResponseItem),
67    #[schemars(title = "StandardRequestSchema")]
68    StandardRequestSchema(standard::request_schema::Response),
69    #[schemars(title = "StandardResponseSchema")]
70    StandardResponseSchema(standard::response_schema::Response),
71    #[schemars(title = "SwissSystem")]
72    SwissSystem(swiss_system::ResponseItem),
73    #[schemars(title = "SwissSystemRequestSchema")]
74    SwissSystemRequestSchema(swiss_system::request_schema::Response),
75    #[schemars(title = "SwissSystemResponseSchema")]
76    SwissSystemResponseSchema(swiss_system::response_schema::Response),
77}
78
79#[cfg(feature = "mcp")]
80impl crate::cli::command::CommandResponse for ResponseItem {
81    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
82        match self {
83            ResponseItem::Standard(v) => v.into_mcp(),
84            ResponseItem::StandardRequestSchema(v) => v.into_mcp(),
85            ResponseItem::StandardResponseSchema(v) => v.into_mcp(),
86            ResponseItem::SwissSystem(v) => v.into_mcp(),
87            ResponseItem::SwissSystemRequestSchema(v) => v.into_mcp(),
88            ResponseItem::SwissSystemResponseSchema(v) => v.into_mcp(),
89        }
90    }
91}
92
93impl TryFrom<Command> for Request {
94    type Error = crate::cli::command::FromArgsError;
95    fn try_from(command: Command) -> Result<Self, Self::Error> {
96        match command {
97            Command::Standard(cmd) => match cmd.schema {
98                None => Ok(Request::Standard(standard::Request::try_from(cmd.args)?)),
99                Some(standard::Schema::RequestSchema(args)) =>
100                    Ok(Request::StandardRequestSchema(standard::request_schema::Request::try_from(args)?)),
101                Some(standard::Schema::ResponseSchema(args)) =>
102                    Ok(Request::StandardResponseSchema(standard::response_schema::Request::try_from(args)?)),
103            },
104            Command::SwissSystem(cmd) => match cmd.schema {
105                None => Ok(Request::SwissSystem(swiss_system::Request::try_from(cmd.args)?)),
106                Some(swiss_system::Schema::RequestSchema(args)) =>
107                    Ok(Request::SwissSystemRequestSchema(swiss_system::request_schema::Request::try_from(args)?)),
108                Some(swiss_system::Schema::ResponseSchema(args)) =>
109                    Ok(Request::SwissSystemResponseSchema(swiss_system::response_schema::Request::try_from(args)?)),
110            },
111        }
112    }
113}
114
115impl crate::cli::command::CommandRequest for Request {
116    fn into_command(&self) -> Vec<String> {
117        match self {
118            Request::Standard(inner) => inner.into_command(),
119            Request::StandardRequestSchema(inner) => inner.into_command(),
120            Request::StandardResponseSchema(inner) => inner.into_command(),
121            Request::SwissSystem(inner) => inner.into_command(),
122            Request::SwissSystemRequestSchema(inner) => inner.into_command(),
123            Request::SwissSystemResponseSchema(inner) => inner.into_command(),
124        }
125    }
126}
127
128#[cfg(feature = "cli-executor")]
129pub async fn execute<E: crate::cli::command::CommandExecutor>(
130    executor: &E,
131    request: Request,
132
133        agent_arguments: Option<&crate::cli::command::AgentArguments>,
134    ) -> Result<
135    std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
136    E::Error,
137> {
138    use futures::StreamExt;
139    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>> =
140        match request {
141            Request::Standard(req) => {
142                let want_streaming = req
143                    .dangerous_advanced
144                    .as_ref()
145                    .and_then(|a| a.stream)
146                    .unwrap_or(false);
147                if want_streaming {
148                    let inner = standard::execute_streaming(executor, req, agent_arguments).await?;
149                    Box::pin(inner.map(|r| r.map(ResponseItem::Standard)))
150                } else {
151                    let value = standard::execute(executor, req, agent_arguments).await?;
152                    Box::pin(crate::cli::command::StreamOnce::new(Ok(
153                        ResponseItem::Standard(standard::ResponseItem::Id(value)),
154                    )))
155                }
156            }
157            Request::StandardRequestSchema(req) => {
158                let value = standard::request_schema::execute(executor, req, agent_arguments).await?;
159                Box::pin(crate::cli::command::StreamOnce::new(Ok(
160                    ResponseItem::StandardRequestSchema(value),
161                )))
162            }
163            Request::StandardResponseSchema(req) => {
164                let value = standard::response_schema::execute(executor, req, agent_arguments).await?;
165                Box::pin(crate::cli::command::StreamOnce::new(Ok(
166                    ResponseItem::StandardResponseSchema(value),
167                )))
168            }
169            Request::SwissSystem(req) => {
170                let want_streaming = req
171                    .dangerous_advanced
172                    .as_ref()
173                    .and_then(|a| a.stream)
174                    .unwrap_or(false);
175                if want_streaming {
176                    let inner = swiss_system::execute_streaming(executor, req, agent_arguments).await?;
177                    Box::pin(inner.map(|r| r.map(ResponseItem::SwissSystem)))
178                } else {
179                    let value = swiss_system::execute(executor, req, agent_arguments).await?;
180                    Box::pin(crate::cli::command::StreamOnce::new(Ok(
181                        ResponseItem::SwissSystem(swiss_system::ResponseItem::Id(value)),
182                    )))
183                }
184            }
185            Request::SwissSystemRequestSchema(req) => {
186                let value = swiss_system::request_schema::execute(executor, req, agent_arguments).await?;
187                Box::pin(crate::cli::command::StreamOnce::new(Ok(
188                    ResponseItem::SwissSystemRequestSchema(value),
189                )))
190            }
191            Request::SwissSystemResponseSchema(req) => {
192                let value = swiss_system::response_schema::execute(executor, req, agent_arguments).await?;
193                Box::pin(crate::cli::command::StreamOnce::new(Ok(
194                    ResponseItem::SwissSystemResponseSchema(value),
195                )))
196            }
197        };
198    Ok(stream)
199}
200
201#[cfg(feature = "cli-executor")]
202pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
203    executor: &E,
204    request: Request,
205    jq: String,
206
207        agent_arguments: Option<&crate::cli::command::AgentArguments>,
208    ) -> Result<
209    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
210    E::Error,
211> {
212    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
213        match request {
214            Request::Standard(req) => {
215                let want_streaming = req
216                    .dangerous_advanced
217                    .as_ref()
218                    .and_then(|a| a.stream)
219                    .unwrap_or(false);
220                if want_streaming {
221                    let inner = standard::execute_streaming_jq(executor, req, jq, agent_arguments).await?;
222                    Box::pin(inner)
223                } else {
224                    let value = standard::execute_jq(executor, req, jq, agent_arguments).await?;
225                    Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
226                }
227            }
228            Request::StandardRequestSchema(req) => {
229                let value = standard::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
230                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
231            }
232            Request::StandardResponseSchema(req) => {
233                let value = standard::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
234                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
235            }
236            Request::SwissSystem(req) => {
237                let want_streaming = req
238                    .dangerous_advanced
239                    .as_ref()
240                    .and_then(|a| a.stream)
241                    .unwrap_or(false);
242                if want_streaming {
243                    let inner = swiss_system::execute_streaming_jq(executor, req, jq, agent_arguments).await?;
244                    Box::pin(inner)
245                } else {
246                    let value = swiss_system::execute_jq(executor, req, jq, agent_arguments).await?;
247                    Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
248                }
249            }
250            Request::SwissSystemRequestSchema(req) => {
251                let value = swiss_system::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
252                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
253            }
254            Request::SwissSystemResponseSchema(req) => {
255                let value = swiss_system::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
256                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
257            }
258        };
259    Ok(stream)
260}