objectiveai_sdk/cli/command/agents/queue/read/
mod.rs1use crate::cli::command::CommandRequest;
9
10pub mod id;
11pub mod pending;
12
13#[derive(clap::Subcommand)]
14pub enum Command {
15 Id(id::Command),
17 Pending(pending::Command),
19}
20
21#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[serde(untagged)]
23#[schemars(rename = "cli.command.agents.queue.read.Request")]
24pub enum Request {
25 #[schemars(title = "Id")]
26 Id(id::Request),
27 #[schemars(title = "IdRequestSchema")]
28 IdRequestSchema(id::request_schema::Request),
29 #[schemars(title = "IdResponseSchema")]
30 IdResponseSchema(id::response_schema::Request),
31 #[schemars(title = "Pending")]
32 Pending(pending::Request),
33 #[schemars(title = "PendingRequestSchema")]
34 PendingRequestSchema(pending::request_schema::Request),
35 #[schemars(title = "PendingResponseSchema")]
36 PendingResponseSchema(pending::response_schema::Request),
37}
38
39#[objectiveai_sdk_macros::json_schema_ignore]
42#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
43#[schemars(rename = "cli.command.agents.queue.read.ResponseItem")]
44#[serde(untagged)]
45pub enum ResponseItem {
46 #[schemars(title = "Id")]
47 Id(id::Response),
48 #[schemars(title = "IdRequestSchema")]
49 IdRequestSchema(id::request_schema::Response),
50 #[schemars(title = "IdResponseSchema")]
51 IdResponseSchema(id::response_schema::Response),
52 #[schemars(title = "Pending")]
53 Pending(pending::ResponseItem),
54 #[schemars(title = "PendingRequestSchema")]
55 PendingRequestSchema(pending::request_schema::Response),
56 #[schemars(title = "PendingResponseSchema")]
57 PendingResponseSchema(pending::response_schema::Response),
58}
59
60#[cfg(feature = "mcp")]
61impl crate::cli::command::CommandResponse for ResponseItem {
62 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
63 match self {
64 ResponseItem::Id(v) => v.into_mcp(),
65 ResponseItem::IdRequestSchema(v) => v.into_mcp(),
66 ResponseItem::IdResponseSchema(v) => v.into_mcp(),
67 ResponseItem::Pending(v) => v.into_mcp(),
68 ResponseItem::PendingRequestSchema(v) => v.into_mcp(),
69 ResponseItem::PendingResponseSchema(v) => v.into_mcp(),
70 }
71 }
72}
73
74impl TryFrom<Command> for Request {
75 type Error = crate::cli::command::FromArgsError;
76 fn try_from(command: Command) -> Result<Self, Self::Error> {
77 match command {
78 Command::Id(cmd) => match cmd.schema {
79 None => Ok(Request::Id(id::Request::try_from(cmd.args)?)),
80 Some(id::Schema::RequestSchema(args)) => Ok(
81 Request::IdRequestSchema(id::request_schema::Request::try_from(args)?),
82 ),
83 Some(id::Schema::ResponseSchema(args)) => Ok(
84 Request::IdResponseSchema(id::response_schema::Request::try_from(args)?),
85 ),
86 },
87 Command::Pending(cmd) => match cmd.schema {
88 None => Ok(Request::Pending(pending::Request::try_from(cmd.args)?)),
89 Some(pending::Schema::RequestSchema(args)) => Ok(Request::PendingRequestSchema(
90 pending::request_schema::Request::try_from(args)?,
91 )),
92 Some(pending::Schema::ResponseSchema(args)) => Ok(Request::PendingResponseSchema(
93 pending::response_schema::Request::try_from(args)?,
94 )),
95 },
96 }
97 }
98}
99
100impl CommandRequest for Request {
101 fn into_command(&self) -> Vec<String> {
102 match self {
103 Request::Id(inner) => inner.into_command(),
104 Request::IdRequestSchema(inner) => inner.into_command(),
105 Request::IdResponseSchema(inner) => inner.into_command(),
106 Request::Pending(inner) => inner.into_command(),
107 Request::PendingRequestSchema(inner) => inner.into_command(),
108 Request::PendingResponseSchema(inner) => inner.into_command(),
109 }
110 }
111}
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute<E: crate::cli::command::CommandExecutor>(
115 executor: &E,
116 request: Request,
117 agent_arguments: Option<&crate::cli::command::AgentArguments>,
118) -> Result<
119 std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
120 E::Error,
121> {
122 use futures::StreamExt;
123 let stream: std::pin::Pin<
124 Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>,
125 > = match request {
126 Request::Id(req) => {
127 let value = id::execute(executor, req, agent_arguments).await?;
128 Box::pin(crate::cli::command::StreamOnce::new(Ok(ResponseItem::Id(value))))
129 }
130 Request::IdRequestSchema(req) => {
131 let value =
132 id::request_schema::execute(executor, req, agent_arguments).await?;
133 Box::pin(crate::cli::command::StreamOnce::new(Ok(
134 ResponseItem::IdRequestSchema(value),
135 )))
136 }
137 Request::IdResponseSchema(req) => {
138 let value =
139 id::response_schema::execute(executor, req, agent_arguments).await?;
140 Box::pin(crate::cli::command::StreamOnce::new(Ok(
141 ResponseItem::IdResponseSchema(value),
142 )))
143 }
144 Request::Pending(req) => {
145 let inner = pending::execute(executor, req, agent_arguments).await?;
146 Box::pin(inner.map(|r| r.map(ResponseItem::Pending)))
147 }
148 Request::PendingRequestSchema(req) => {
149 let value =
150 pending::request_schema::execute(executor, req, agent_arguments).await?;
151 Box::pin(crate::cli::command::StreamOnce::new(Ok(
152 ResponseItem::PendingRequestSchema(value),
153 )))
154 }
155 Request::PendingResponseSchema(req) => {
156 let value =
157 pending::response_schema::execute(executor, req, agent_arguments).await?;
158 Box::pin(crate::cli::command::StreamOnce::new(Ok(
159 ResponseItem::PendingResponseSchema(value),
160 )))
161 }
162 };
163 Ok(stream)
164}
165
166#[cfg(feature = "cli-executor")]
167pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
168 executor: &E,
169 request: Request,
170 jq: String,
171 agent_arguments: Option<&crate::cli::command::AgentArguments>,
172) -> Result<
173 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
174 E::Error,
175> {
176 let stream: std::pin::Pin<
177 Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>,
178 > = match request {
179 Request::Id(req) => {
180 let value = id::execute_jq(executor, req, jq, agent_arguments).await?;
181 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
182 }
183 Request::IdRequestSchema(req) => {
184 let value =
185 id::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
186 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
187 }
188 Request::IdResponseSchema(req) => {
189 let value =
190 id::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
191 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
192 }
193 Request::Pending(req) => {
194 let inner = pending::execute_jq(executor, req, jq, agent_arguments).await?;
195 Box::pin(inner)
196 }
197 Request::PendingRequestSchema(req) => {
198 let value =
199 pending::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
200 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
201 }
202 Request::PendingResponseSchema(req) => {
203 let value =
204 pending::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
205 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
206 }
207 };
208 Ok(stream)
209}