Skip to main content

objectiveai_sdk/cli/command/logs/agents/completions/response/messages/
mod.rs

1pub mod audio;
2pub mod clear;
3pub mod file;
4pub mod get;
5pub mod image;
6pub mod logprobs;
7pub mod reasoning;
8pub mod refusal;
9pub mod subscribe;
10pub mod text;
11pub mod tool;
12pub mod tool_calls;
13pub mod video;
14
15#[derive(clap::Subcommand)]
16pub enum Command {
17    Audio {
18        #[command(subcommand)]
19        command: audio::Command,
20    },
21    Clear(clear::Command),
22    File {
23        #[command(subcommand)]
24        command: file::Command,
25    },
26    Get(get::Command),
27    Image {
28        #[command(subcommand)]
29        command: image::Command,
30    },
31    Logprobs {
32        #[command(subcommand)]
33        command: logprobs::Command,
34    },
35    Reasoning {
36        #[command(subcommand)]
37        command: reasoning::Command,
38    },
39    Refusal {
40        #[command(subcommand)]
41        command: refusal::Command,
42    },
43    Subscribe(subscribe::Command),
44    Text {
45        #[command(subcommand)]
46        command: text::Command,
47    },
48    Tool {
49        #[command(subcommand)]
50        command: tool::Command,
51    },
52    ToolCalls {
53        #[command(subcommand)]
54        command: tool_calls::Command,
55    },
56    Video {
57        #[command(subcommand)]
58        command: video::Command,
59    },
60}
61
62#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
63#[serde(untagged)]
64#[schemars(rename = "cli.command.logs.agents.completions.response.messages.Request")]
65pub enum Request {
66    #[schemars(title = "Audio")]
67    Audio(audio::Request),
68    #[schemars(title = "Clear")]
69    Clear(clear::Request),
70    #[schemars(title = "ClearRequestSchema")]
71    ClearRequestSchema(clear::request_schema::Request),
72    #[schemars(title = "ClearResponseSchema")]
73    ClearResponseSchema(clear::response_schema::Request),
74    #[schemars(title = "File")]
75    File(file::Request),
76    #[schemars(title = "Get")]
77    Get(get::Request),
78    #[schemars(title = "GetRequestSchema")]
79    GetRequestSchema(get::request_schema::Request),
80    #[schemars(title = "GetResponseSchema")]
81    GetResponseSchema(get::response_schema::Request),
82    #[schemars(title = "Image")]
83    Image(image::Request),
84    #[schemars(title = "Logprobs")]
85    Logprobs(logprobs::Request),
86    #[schemars(title = "Reasoning")]
87    Reasoning(reasoning::Request),
88    #[schemars(title = "Refusal")]
89    Refusal(refusal::Request),
90    #[schemars(title = "Subscribe")]
91    Subscribe(subscribe::Request),
92    #[schemars(title = "SubscribeRequestSchema")]
93    SubscribeRequestSchema(subscribe::request_schema::Request),
94    #[schemars(title = "SubscribeResponseSchema")]
95    SubscribeResponseSchema(subscribe::response_schema::Request),
96    #[schemars(title = "Text")]
97    Text(text::Request),
98    #[schemars(title = "Tool")]
99    Tool(tool::Request),
100    #[schemars(title = "ToolCalls")]
101    ToolCalls(tool_calls::Request),
102    #[schemars(title = "Video")]
103    Video(video::Request),
104}
105
106// Exempt from json-schema coverage: tier aggregate (see the root
107// `ResponseItem` in command.rs - TS7056).
108#[objectiveai_sdk_macros::json_schema_ignore]
109#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
110#[schemars(rename = "cli.command.logs.agents.completions.response.messages.Response")]
111#[serde(untagged)]
112pub enum Response {
113    #[schemars(title = "Audio")]
114    Audio(audio::Response),
115    #[schemars(title = "Clear")]
116    Clear(clear::Response),
117    #[schemars(title = "ClearRequestSchema")]
118    ClearRequestSchema(clear::request_schema::Response),
119    #[schemars(title = "ClearResponseSchema")]
120    ClearResponseSchema(clear::response_schema::Response),
121    #[schemars(title = "File")]
122    File(file::Response),
123    #[schemars(title = "Get")]
124    Get(get::Response),
125    #[schemars(title = "GetRequestSchema")]
126    GetRequestSchema(get::request_schema::Response),
127    #[schemars(title = "GetResponseSchema")]
128    GetResponseSchema(get::response_schema::Response),
129    #[schemars(title = "Image")]
130    Image(image::Response),
131    #[schemars(title = "Logprobs")]
132    Logprobs(logprobs::Response),
133    #[schemars(title = "Reasoning")]
134    Reasoning(reasoning::Response),
135    #[schemars(title = "Refusal")]
136    Refusal(refusal::Response),
137    #[schemars(title = "Subscribe")]
138    Subscribe(subscribe::Response),
139    #[schemars(title = "SubscribeRequestSchema")]
140    SubscribeRequestSchema(subscribe::request_schema::Response),
141    #[schemars(title = "SubscribeResponseSchema")]
142    SubscribeResponseSchema(subscribe::response_schema::Response),
143    #[schemars(title = "Text")]
144    Text(text::Response),
145    #[schemars(title = "Tool")]
146    Tool(tool::Response),
147    #[schemars(title = "ToolCalls")]
148    ToolCalls(tool_calls::Response),
149    #[schemars(title = "Video")]
150    Video(video::Response),
151}
152
153#[cfg(feature = "mcp")]
154impl crate::cli::command::CommandResponse for Response {
155    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
156        match self {
157            Response::Audio(v) => v.into_mcp(),
158            Response::Clear(v) => v.into_mcp(),
159            Response::ClearRequestSchema(v) => v.into_mcp(),
160            Response::ClearResponseSchema(v) => v.into_mcp(),
161            Response::File(v) => v.into_mcp(),
162            Response::Get(v) => v.into_mcp(),
163            Response::GetRequestSchema(v) => v.into_mcp(),
164            Response::GetResponseSchema(v) => v.into_mcp(),
165            Response::Image(v) => v.into_mcp(),
166            Response::Logprobs(v) => v.into_mcp(),
167            Response::Reasoning(v) => v.into_mcp(),
168            Response::Refusal(v) => v.into_mcp(),
169            Response::Subscribe(v) => v.into_mcp(),
170            Response::SubscribeRequestSchema(v) => v.into_mcp(),
171            Response::SubscribeResponseSchema(v) => v.into_mcp(),
172            Response::Text(v) => v.into_mcp(),
173            Response::Tool(v) => v.into_mcp(),
174            Response::ToolCalls(v) => v.into_mcp(),
175            Response::Video(v) => v.into_mcp(),
176        }
177    }
178}
179
180impl TryFrom<Command> for Request {
181    type Error = crate::cli::command::FromArgsError;
182    fn try_from(command: Command) -> Result<Self, Self::Error> {
183        match command {
184            Command::Audio { command } =>
185                Ok(Request::Audio(audio::Request::try_from(command)?)),
186            Command::Clear(cmd) => match cmd.schema {
187                None => Ok(Request::Clear(clear::Request::try_from(cmd.args)?)),
188                Some(clear::Schema::RequestSchema(args)) =>
189                    Ok(Request::ClearRequestSchema(clear::request_schema::Request::try_from(args)?)),
190                Some(clear::Schema::ResponseSchema(args)) =>
191                    Ok(Request::ClearResponseSchema(clear::response_schema::Request::try_from(args)?)),
192            },
193            Command::File { command } =>
194                Ok(Request::File(file::Request::try_from(command)?)),
195            Command::Get(cmd) => match cmd.schema {
196                None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
197                Some(get::Schema::RequestSchema(args)) =>
198                    Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
199                Some(get::Schema::ResponseSchema(args)) =>
200                    Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
201            },
202            Command::Image { command } =>
203                Ok(Request::Image(image::Request::try_from(command)?)),
204            Command::Logprobs { command } =>
205                Ok(Request::Logprobs(logprobs::Request::try_from(command)?)),
206            Command::Reasoning { command } =>
207                Ok(Request::Reasoning(reasoning::Request::try_from(command)?)),
208            Command::Refusal { command } =>
209                Ok(Request::Refusal(refusal::Request::try_from(command)?)),
210            Command::Subscribe(cmd) => match cmd.schema {
211                None => Ok(Request::Subscribe(subscribe::Request::try_from(cmd.args)?)),
212                Some(subscribe::Schema::RequestSchema(args)) =>
213                    Ok(Request::SubscribeRequestSchema(subscribe::request_schema::Request::try_from(args)?)),
214                Some(subscribe::Schema::ResponseSchema(args)) =>
215                    Ok(Request::SubscribeResponseSchema(subscribe::response_schema::Request::try_from(args)?)),
216            },
217            Command::Text { command } =>
218                Ok(Request::Text(text::Request::try_from(command)?)),
219            Command::Tool { command } =>
220                Ok(Request::Tool(tool::Request::try_from(command)?)),
221            Command::ToolCalls { command } =>
222                Ok(Request::ToolCalls(tool_calls::Request::try_from(command)?)),
223            Command::Video { command } =>
224                Ok(Request::Video(video::Request::try_from(command)?)),
225        }
226    }
227}
228
229impl crate::cli::command::CommandRequest for Request {
230    fn into_command(&self) -> Vec<String> {
231        match self {
232            Request::Audio(inner) => inner.into_command(),
233            Request::Clear(inner) => inner.into_command(),
234            Request::ClearRequestSchema(inner) => inner.into_command(),
235            Request::ClearResponseSchema(inner) => inner.into_command(),
236            Request::File(inner) => inner.into_command(),
237            Request::Get(inner) => inner.into_command(),
238            Request::GetRequestSchema(inner) => inner.into_command(),
239            Request::GetResponseSchema(inner) => inner.into_command(),
240            Request::Image(inner) => inner.into_command(),
241            Request::Logprobs(inner) => inner.into_command(),
242            Request::Reasoning(inner) => inner.into_command(),
243            Request::Refusal(inner) => inner.into_command(),
244            Request::Subscribe(inner) => inner.into_command(),
245            Request::SubscribeRequestSchema(inner) => inner.into_command(),
246            Request::SubscribeResponseSchema(inner) => inner.into_command(),
247            Request::Text(inner) => inner.into_command(),
248            Request::Tool(inner) => inner.into_command(),
249            Request::ToolCalls(inner) => inner.into_command(),
250            Request::Video(inner) => inner.into_command(),
251        }
252    }
253}
254
255#[cfg(feature = "cli-executor")]
256pub async fn execute<E: crate::cli::command::CommandExecutor>(
257    executor: &E,
258    request: Request,
259
260        agent_arguments: Option<&crate::cli::command::AgentArguments>,
261    ) -> Result<
262    std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
263    E::Error,
264> {
265    use futures::StreamExt;
266    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
267        match request {
268            Request::Audio(req) => {
269                let inner = audio::execute(executor, req, agent_arguments).await?;
270                Box::pin(inner.map(|r| r.map(Response::Audio)))
271            }
272            Request::Clear(req) => {
273                let value = clear::execute(executor, req, agent_arguments).await?;
274                Box::pin(crate::cli::command::StreamOnce::new(Ok(
275                    Response::Clear(value),
276                )))
277            }
278            Request::ClearRequestSchema(req) => {
279                let value = clear::request_schema::execute(executor, req, agent_arguments).await?;
280                Box::pin(crate::cli::command::StreamOnce::new(Ok(
281                    Response::ClearRequestSchema(value),
282                )))
283            }
284            Request::ClearResponseSchema(req) => {
285                let value = clear::response_schema::execute(executor, req, agent_arguments).await?;
286                Box::pin(crate::cli::command::StreamOnce::new(Ok(
287                    Response::ClearResponseSchema(value),
288                )))
289            }
290            Request::File(req) => {
291                let inner = file::execute(executor, req, agent_arguments).await?;
292                Box::pin(inner.map(|r| r.map(Response::File)))
293            }
294            Request::Get(req) => {
295                let value = get::execute(executor, req, agent_arguments).await?;
296                Box::pin(crate::cli::command::StreamOnce::new(Ok(
297                    Response::Get(value),
298                )))
299            }
300            Request::GetRequestSchema(req) => {
301                let value = get::request_schema::execute(executor, req, agent_arguments).await?;
302                Box::pin(crate::cli::command::StreamOnce::new(Ok(
303                    Response::GetRequestSchema(value),
304                )))
305            }
306            Request::GetResponseSchema(req) => {
307                let value = get::response_schema::execute(executor, req, agent_arguments).await?;
308                Box::pin(crate::cli::command::StreamOnce::new(Ok(
309                    Response::GetResponseSchema(value),
310                )))
311            }
312            Request::Image(req) => {
313                let inner = image::execute(executor, req, agent_arguments).await?;
314                Box::pin(inner.map(|r| r.map(Response::Image)))
315            }
316            Request::Logprobs(req) => {
317                let inner = logprobs::execute(executor, req, agent_arguments).await?;
318                Box::pin(inner.map(|r| r.map(Response::Logprobs)))
319            }
320            Request::Reasoning(req) => {
321                let inner = reasoning::execute(executor, req, agent_arguments).await?;
322                Box::pin(inner.map(|r| r.map(Response::Reasoning)))
323            }
324            Request::Refusal(req) => {
325                let inner = refusal::execute(executor, req, agent_arguments).await?;
326                Box::pin(inner.map(|r| r.map(Response::Refusal)))
327            }
328            Request::Subscribe(req) => {
329                let value = subscribe::execute(executor, req, agent_arguments).await?;
330                Box::pin(crate::cli::command::StreamOnce::new(Ok(
331                    Response::Subscribe(value),
332                )))
333            }
334            Request::SubscribeRequestSchema(req) => {
335                let value = subscribe::request_schema::execute(executor, req, agent_arguments).await?;
336                Box::pin(crate::cli::command::StreamOnce::new(Ok(
337                    Response::SubscribeRequestSchema(value),
338                )))
339            }
340            Request::SubscribeResponseSchema(req) => {
341                let value = subscribe::response_schema::execute(executor, req, agent_arguments).await?;
342                Box::pin(crate::cli::command::StreamOnce::new(Ok(
343                    Response::SubscribeResponseSchema(value),
344                )))
345            }
346            Request::Text(req) => {
347                let inner = text::execute(executor, req, agent_arguments).await?;
348                Box::pin(inner.map(|r| r.map(Response::Text)))
349            }
350            Request::Tool(req) => {
351                let inner = tool::execute(executor, req, agent_arguments).await?;
352                Box::pin(inner.map(|r| r.map(Response::Tool)))
353            }
354            Request::ToolCalls(req) => {
355                let inner = tool_calls::execute(executor, req, agent_arguments).await?;
356                Box::pin(inner.map(|r| r.map(Response::ToolCalls)))
357            }
358            Request::Video(req) => {
359                let inner = video::execute(executor, req, agent_arguments).await?;
360                Box::pin(inner.map(|r| r.map(Response::Video)))
361            }
362        };
363    Ok(stream)
364}
365
366#[cfg(feature = "cli-executor")]
367pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
368    executor: &E,
369    request: Request,
370    jq: String,
371
372        agent_arguments: Option<&crate::cli::command::AgentArguments>,
373    ) -> Result<
374    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
375    E::Error,
376> {
377    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
378        match request {
379            Request::Audio(req) => {
380                let inner = audio::execute_jq(executor, req, jq, agent_arguments).await?;
381                Box::pin(inner)
382            }
383            Request::Clear(req) => {
384                let value = clear::execute_jq(executor, req, jq, agent_arguments).await?;
385                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
386            }
387            Request::ClearRequestSchema(req) => {
388                let value = clear::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
389                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
390            }
391            Request::ClearResponseSchema(req) => {
392                let value = clear::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
393                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
394            }
395            Request::File(req) => {
396                let inner = file::execute_jq(executor, req, jq, agent_arguments).await?;
397                Box::pin(inner)
398            }
399            Request::Get(req) => {
400                let value = get::execute_jq(executor, req, jq, agent_arguments).await?;
401                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
402            }
403            Request::GetRequestSchema(req) => {
404                let value = get::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
405                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
406            }
407            Request::GetResponseSchema(req) => {
408                let value = get::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
409                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
410            }
411            Request::Image(req) => {
412                let inner = image::execute_jq(executor, req, jq, agent_arguments).await?;
413                Box::pin(inner)
414            }
415            Request::Logprobs(req) => {
416                let inner = logprobs::execute_jq(executor, req, jq, agent_arguments).await?;
417                Box::pin(inner)
418            }
419            Request::Reasoning(req) => {
420                let inner = reasoning::execute_jq(executor, req, jq, agent_arguments).await?;
421                Box::pin(inner)
422            }
423            Request::Refusal(req) => {
424                let inner = refusal::execute_jq(executor, req, jq, agent_arguments).await?;
425                Box::pin(inner)
426            }
427            Request::Subscribe(req) => {
428                let value = subscribe::execute_jq(executor, req, jq, agent_arguments).await?;
429                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
430            }
431            Request::SubscribeRequestSchema(req) => {
432                let value = subscribe::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
433                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
434            }
435            Request::SubscribeResponseSchema(req) => {
436                let value = subscribe::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
437                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
438            }
439            Request::Text(req) => {
440                let inner = text::execute_jq(executor, req, jq, agent_arguments).await?;
441                Box::pin(inner)
442            }
443            Request::Tool(req) => {
444                let inner = tool::execute_jq(executor, req, jq, agent_arguments).await?;
445                Box::pin(inner)
446            }
447            Request::ToolCalls(req) => {
448                let inner = tool_calls::execute_jq(executor, req, jq, agent_arguments).await?;
449                Box::pin(inner)
450            }
451            Request::Video(req) => {
452                let inner = video::execute_jq(executor, req, jq, agent_arguments).await?;
453                Box::pin(inner)
454            }
455        };
456    Ok(stream)
457}