objectiveai_sdk/cli/command/logs/functions/
mod.rs1pub mod executions;
2pub mod inventions;
3
4#[derive(clap::Subcommand)]
5pub enum Command {
6 Executions {
7 #[command(subcommand)]
8 command: executions::Command,
9 },
10 Inventions {
11 #[command(subcommand)]
12 command: inventions::Command,
13 },
14}
15
16#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[serde(untagged)]
18#[schemars(rename = "cli.command.logs.functions.Request")]
19pub enum Request {
20 #[schemars(title = "Executions")]
21 Executions(executions::Request),
22 #[schemars(title = "Inventions")]
23 Inventions(inventions::Request),
24}
25
26#[objectiveai_sdk_macros::json_schema_ignore]
29#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
30#[schemars(rename = "cli.command.logs.functions.ResponseItem")]
31#[serde(untagged)]
32pub enum ResponseItem {
33 #[schemars(title = "Executions")]
34 Executions(executions::ResponseItem),
35 #[schemars(title = "Inventions")]
36 Inventions(inventions::ResponseItem),
37}
38
39#[cfg(feature = "mcp")]
40impl crate::cli::command::CommandResponse for ResponseItem {
41 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
42 match self {
43 ResponseItem::Executions(v) => v.into_mcp(),
44 ResponseItem::Inventions(v) => v.into_mcp(),
45 }
46 }
47}
48
49impl TryFrom<Command> for Request {
50 type Error = crate::cli::command::FromArgsError;
51 fn try_from(command: Command) -> Result<Self, Self::Error> {
52 match command {
53 Command::Executions { command } =>
54 Ok(Request::Executions(executions::Request::try_from(command)?)),
55 Command::Inventions { command } =>
56 Ok(Request::Inventions(inventions::Request::try_from(command)?)),
57 }
58 }
59}
60
61impl crate::cli::command::CommandRequest for Request {
62 fn into_command(&self) -> Vec<String> {
63 match self {
64 Request::Executions(inner) => inner.into_command(),
65 Request::Inventions(inner) => inner.into_command(),
66 }
67 }
68}
69
70#[cfg(feature = "cli-executor")]
71pub async fn execute<E: crate::cli::command::CommandExecutor>(
72 executor: &E,
73 request: Request,
74
75 agent_arguments: Option<&crate::cli::command::AgentArguments>,
76 ) -> Result<
77 std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
78 E::Error,
79> {
80 use futures::StreamExt;
81 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>> =
82 match request {
83 Request::Executions(req) => {
84 let inner = executions::execute(executor, req, agent_arguments).await?;
85 Box::pin(inner.map(|r| r.map(ResponseItem::Executions)))
86 }
87 Request::Inventions(req) => {
88 let inner = inventions::execute(executor, req, agent_arguments).await?;
89 Box::pin(inner.map(|r| r.map(ResponseItem::Inventions)))
90 }
91 };
92 Ok(stream)
93}
94
95#[cfg(feature = "cli-executor")]
96pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
97 executor: &E,
98 request: Request,
99 jq: String,
100
101 agent_arguments: Option<&crate::cli::command::AgentArguments>,
102 ) -> Result<
103 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
104 E::Error,
105> {
106 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
107 match request {
108 Request::Executions(req) => {
109 let inner = executions::execute_jq(executor, req, jq, agent_arguments).await?;
110 Box::pin(inner)
111 }
112 Request::Inventions(req) => {
113 let inner = inventions::execute_jq(executor, req, jq, agent_arguments).await?;
114 Box::pin(inner)
115 }
116 };
117 Ok(stream)
118}