Skip to main content

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

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