Skip to main content

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

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