Skip to main content

objectiveai_sdk/cli/command/logs/functions/executions/response/
mod.rs

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