Skip to main content

objectiveai_sdk/cli/command/logs/
mod.rs

1pub mod agents;
2pub mod clear;
3pub mod functions;
4pub mod vector;
5
6#[derive(clap::Subcommand)]
7pub enum Command {
8    Agents {
9        #[command(subcommand)]
10        command: agents::Command,
11    },
12    Clear(clear::Command),
13    Functions {
14        #[command(subcommand)]
15        command: functions::Command,
16    },
17    Vector {
18        #[command(subcommand)]
19        command: vector::Command,
20    },
21}
22
23#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
24#[serde(untagged)]
25#[schemars(rename = "cli.command.logs.Request")]
26pub enum Request {
27    #[schemars(title = "Agents")]
28    Agents(agents::Request),
29    #[schemars(title = "Clear")]
30    Clear(clear::Request),
31    #[schemars(title = "ClearRequestSchema")]
32    ClearRequestSchema(clear::request_schema::Request),
33    #[schemars(title = "ClearResponseSchema")]
34    ClearResponseSchema(clear::response_schema::Request),
35    #[schemars(title = "Functions")]
36    Functions(functions::Request),
37    #[schemars(title = "Vector")]
38    Vector(vector::Request),
39}
40
41// Exempt from json-schema coverage — see the root `ResponseItem`
42// in command.rs for the rationale (TS7056 aggregate).
43#[objectiveai_sdk_macros::json_schema_ignore]
44#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
45#[schemars(rename = "cli.command.logs.ResponseItem")]
46#[serde(untagged)]
47pub enum ResponseItem {
48    #[schemars(title = "Agents")]
49    Agents(agents::ResponseItem),
50    #[schemars(title = "Clear")]
51    Clear(clear::Response),
52    #[schemars(title = "ClearRequestSchema")]
53    ClearRequestSchema(clear::request_schema::Response),
54    #[schemars(title = "ClearResponseSchema")]
55    ClearResponseSchema(clear::response_schema::Response),
56    #[schemars(title = "Functions")]
57    Functions(functions::ResponseItem),
58    #[schemars(title = "Vector")]
59    Vector(vector::ResponseItem),
60}
61
62#[cfg(feature = "mcp")]
63impl crate::cli::command::CommandResponse for ResponseItem {
64    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
65        match self {
66            ResponseItem::Agents(v) => v.into_mcp(),
67            ResponseItem::Clear(v) => v.into_mcp(),
68            ResponseItem::ClearRequestSchema(v) => v.into_mcp(),
69            ResponseItem::ClearResponseSchema(v) => v.into_mcp(),
70            ResponseItem::Functions(v) => v.into_mcp(),
71            ResponseItem::Vector(v) => v.into_mcp(),
72        }
73    }
74}
75
76impl TryFrom<Command> for Request {
77    type Error = crate::cli::command::FromArgsError;
78    fn try_from(command: Command) -> Result<Self, Self::Error> {
79        match command {
80            Command::Agents { command } =>
81                Ok(Request::Agents(agents::Request::try_from(command)?)),
82            Command::Clear(cmd) => match cmd.schema {
83                None => Ok(Request::Clear(clear::Request::try_from(cmd.args)?)),
84                Some(clear::Schema::RequestSchema(args)) =>
85                    Ok(Request::ClearRequestSchema(clear::request_schema::Request::try_from(args)?)),
86                Some(clear::Schema::ResponseSchema(args)) =>
87                    Ok(Request::ClearResponseSchema(clear::response_schema::Request::try_from(args)?)),
88            },
89            Command::Functions { command } =>
90                Ok(Request::Functions(functions::Request::try_from(command)?)),
91            Command::Vector { command } =>
92                Ok(Request::Vector(vector::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::Agents(inner) => inner.into_command(),
101            Request::Clear(inner) => inner.into_command(),
102            Request::ClearRequestSchema(inner) => inner.into_command(),
103            Request::ClearResponseSchema(inner) => inner.into_command(),
104            Request::Functions(inner) => inner.into_command(),
105            Request::Vector(inner) => inner.into_command(),
106        }
107    }
108}
109
110#[cfg(feature = "cli-executor")]
111pub async fn execute<E: crate::cli::command::CommandExecutor>(
112    executor: &E,
113    request: Request,
114
115        agent_arguments: Option<&crate::cli::command::AgentArguments>,
116    ) -> Result<
117    std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
118    E::Error,
119> {
120    use futures::StreamExt;
121    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>> =
122        match request {
123            Request::Agents(req) => {
124                let inner = agents::execute(executor, req, agent_arguments).await?;
125                Box::pin(inner.map(|r| r.map(ResponseItem::Agents)))
126            }
127            Request::Clear(req) => {
128                let value = clear::execute(executor, req, agent_arguments).await?;
129                Box::pin(crate::cli::command::StreamOnce::new(Ok(
130                    ResponseItem::Clear(value),
131                )))
132            }
133            Request::ClearRequestSchema(req) => {
134                let value = clear::request_schema::execute(executor, req, agent_arguments).await?;
135                Box::pin(crate::cli::command::StreamOnce::new(Ok(
136                    ResponseItem::ClearRequestSchema(value),
137                )))
138            }
139            Request::ClearResponseSchema(req) => {
140                let value = clear::response_schema::execute(executor, req, agent_arguments).await?;
141                Box::pin(crate::cli::command::StreamOnce::new(Ok(
142                    ResponseItem::ClearResponseSchema(value),
143                )))
144            }
145            Request::Functions(req) => {
146                let inner = functions::execute(executor, req, agent_arguments).await?;
147                Box::pin(inner.map(|r| r.map(ResponseItem::Functions)))
148            }
149            Request::Vector(req) => {
150                let inner = vector::execute(executor, req, agent_arguments).await?;
151                Box::pin(inner.map(|r| r.map(ResponseItem::Vector)))
152            }
153        };
154    Ok(stream)
155}
156
157#[cfg(feature = "cli-executor")]
158pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
159    executor: &E,
160    request: Request,
161    jq: String,
162
163        agent_arguments: Option<&crate::cli::command::AgentArguments>,
164    ) -> Result<
165    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
166    E::Error,
167> {
168    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
169        match request {
170            Request::Agents(req) => {
171                let inner = agents::execute_jq(executor, req, jq, agent_arguments).await?;
172                Box::pin(inner)
173            }
174            Request::Clear(req) => {
175                let value = clear::execute_jq(executor, req, jq, agent_arguments).await?;
176                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
177            }
178            Request::ClearRequestSchema(req) => {
179                let value = clear::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
180                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
181            }
182            Request::ClearResponseSchema(req) => {
183                let value = clear::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
184                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
185            }
186            Request::Functions(req) => {
187                let inner = functions::execute_jq(executor, req, jq, agent_arguments).await?;
188                Box::pin(inner)
189            }
190            Request::Vector(req) => {
191                let inner = vector::execute_jq(executor, req, jq, agent_arguments).await?;
192                Box::pin(inner)
193            }
194        };
195    Ok(stream)
196}