Skip to main content

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

1pub mod request;
2pub mod response;
3
4#[derive(clap::Subcommand)]
5pub enum Command {
6    Request {
7        #[command(subcommand)]
8        command: request::Command,
9    },
10    Response {
11        #[command(subcommand)]
12        command: response::Command,
13    },
14}
15
16#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[serde(untagged)]
18#[schemars(rename = "cli.command.logs.agents.completions.Request")]
19pub enum Request {
20    #[schemars(title = "Request")]
21    Request(request::Request),
22    #[schemars(title = "Response")]
23    Response(response::Request),
24}
25
26// Exempt from json-schema coverage: tier aggregate (see the root
27// `ResponseItem` in command.rs - TS7056).
28#[objectiveai_sdk_macros::json_schema_ignore]
29#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
30#[schemars(rename = "cli.command.logs.agents.completions.ResponseItem")]
31#[serde(untagged)]
32pub enum ResponseItem {
33    #[schemars(title = "Request")]
34    Request(request::Response),
35    #[schemars(title = "Response")]
36    Response(response::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::Request(v) => v.into_mcp(),
44            ResponseItem::Response(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::Request { command } =>
54                Ok(Request::Request(request::Request::try_from(command)?)),
55            Command::Response { command } =>
56                Ok(Request::Response(response::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::Request(inner) => inner.into_command(),
65            Request::Response(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::Request(req) => {
84                let inner = request::execute(executor, req, agent_arguments).await?;
85                Box::pin(inner.map(|r| r.map(ResponseItem::Request)))
86            }
87            Request::Response(req) => {
88                let inner = response::execute(executor, req, agent_arguments).await?;
89                Box::pin(inner.map(|r| r.map(ResponseItem::Response)))
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::Request(req) => {
109                let inner = request::execute_jq(executor, req, jq, agent_arguments).await?;
110                Box::pin(inner)
111            }
112            Request::Response(req) => {
113                let inner = response::execute_jq(executor, req, jq, agent_arguments).await?;
114                Box::pin(inner)
115            }
116        };
117    Ok(stream)
118}