objectiveai_sdk/cli/command/logs/agents/completions/request/messages/
mod.rs1pub mod audio;
2pub mod file;
3pub mod image;
4pub mod text;
5pub mod video;
6
7#[derive(clap::Subcommand)]
8pub enum Command {
9 Audio {
10 #[command(subcommand)]
11 command: audio::Command,
12 },
13 File {
14 #[command(subcommand)]
15 command: file::Command,
16 },
17 Image {
18 #[command(subcommand)]
19 command: image::Command,
20 },
21 Text {
22 #[command(subcommand)]
23 command: text::Command,
24 },
25 Video {
26 #[command(subcommand)]
27 command: video::Command,
28 },
29}
30
31#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[serde(untagged)]
33#[schemars(rename = "cli.command.logs.agents.completions.request.messages.Request")]
34pub enum Request {
35 #[schemars(title = "Audio")]
36 Audio(audio::Request),
37 #[schemars(title = "File")]
38 File(file::Request),
39 #[schemars(title = "Image")]
40 Image(image::Request),
41 #[schemars(title = "Text")]
42 Text(text::Request),
43 #[schemars(title = "Video")]
44 Video(video::Request),
45}
46
47#[objectiveai_sdk_macros::json_schema_ignore]
50#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
51#[schemars(rename = "cli.command.logs.agents.completions.request.messages.Response")]
52#[serde(untagged)]
53pub enum Response {
54 #[schemars(title = "Audio")]
55 Audio(audio::Response),
56 #[schemars(title = "File")]
57 File(file::Response),
58 #[schemars(title = "Image")]
59 Image(image::Response),
60 #[schemars(title = "Text")]
61 Text(text::Response),
62 #[schemars(title = "Video")]
63 Video(video::Response),
64}
65
66#[cfg(feature = "mcp")]
67impl crate::cli::command::CommandResponse for Response {
68 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
69 match self {
70 Response::Audio(v) => v.into_mcp(),
71 Response::File(v) => v.into_mcp(),
72 Response::Image(v) => v.into_mcp(),
73 Response::Text(v) => v.into_mcp(),
74 Response::Video(v) => v.into_mcp(),
75 }
76 }
77}
78
79impl TryFrom<Command> for Request {
80 type Error = crate::cli::command::FromArgsError;
81 fn try_from(command: Command) -> Result<Self, Self::Error> {
82 match command {
83 Command::Audio { command } =>
84 Ok(Request::Audio(audio::Request::try_from(command)?)),
85 Command::File { command } =>
86 Ok(Request::File(file::Request::try_from(command)?)),
87 Command::Image { command } =>
88 Ok(Request::Image(image::Request::try_from(command)?)),
89 Command::Text { command } =>
90 Ok(Request::Text(text::Request::try_from(command)?)),
91 Command::Video { command } =>
92 Ok(Request::Video(video::Request::try_from(command)?)),
93 }
94 }
95}
96
97impl crate::cli::command::CommandRequest for Request {
98 fn into_command(&self) -> Vec<String> {
99 match self {
100 Request::Audio(inner) => inner.into_command(),
101 Request::File(inner) => inner.into_command(),
102 Request::Image(inner) => inner.into_command(),
103 Request::Text(inner) => inner.into_command(),
104 Request::Video(inner) => inner.into_command(),
105 }
106 }
107}
108
109#[cfg(feature = "cli-executor")]
110pub async fn execute<E: crate::cli::command::CommandExecutor>(
111 executor: &E,
112 request: Request,
113
114 agent_arguments: Option<&crate::cli::command::AgentArguments>,
115 ) -> Result<
116 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
117 E::Error,
118> {
119 use futures::StreamExt;
120 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
121 match request {
122 Request::Audio(req) => {
123 let inner = audio::execute(executor, req, agent_arguments).await?;
124 Box::pin(inner.map(|r| r.map(Response::Audio)))
125 }
126 Request::File(req) => {
127 let inner = file::execute(executor, req, agent_arguments).await?;
128 Box::pin(inner.map(|r| r.map(Response::File)))
129 }
130 Request::Image(req) => {
131 let inner = image::execute(executor, req, agent_arguments).await?;
132 Box::pin(inner.map(|r| r.map(Response::Image)))
133 }
134 Request::Text(req) => {
135 let inner = text::execute(executor, req, agent_arguments).await?;
136 Box::pin(inner.map(|r| r.map(Response::Text)))
137 }
138 Request::Video(req) => {
139 let inner = video::execute(executor, req, agent_arguments).await?;
140 Box::pin(inner.map(|r| r.map(Response::Video)))
141 }
142 };
143 Ok(stream)
144}
145
146#[cfg(feature = "cli-executor")]
147pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
148 executor: &E,
149 request: Request,
150 jq: String,
151
152 agent_arguments: Option<&crate::cli::command::AgentArguments>,
153 ) -> Result<
154 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
155 E::Error,
156> {
157 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
158 match request {
159 Request::Audio(req) => {
160 let inner = audio::execute_jq(executor, req, jq, agent_arguments).await?;
161 Box::pin(inner)
162 }
163 Request::File(req) => {
164 let inner = file::execute_jq(executor, req, jq, agent_arguments).await?;
165 Box::pin(inner)
166 }
167 Request::Image(req) => {
168 let inner = image::execute_jq(executor, req, jq, agent_arguments).await?;
169 Box::pin(inner)
170 }
171 Request::Text(req) => {
172 let inner = text::execute_jq(executor, req, jq, agent_arguments).await?;
173 Box::pin(inner)
174 }
175 Request::Video(req) => {
176 let inner = video::execute_jq(executor, req, jq, agent_arguments).await?;
177 Box::pin(inner)
178 }
179 };
180 Ok(stream)
181}