Skip to main content

objectiveai_sdk/cli/command/agents/queue/read/
mod.rs

1//! `agents queue read` sub-tier. Two leaves:
2//!
3//! * `id <id>` — fetch one piece of queued content by
4//!   `prompt_contents.id`.
5//! * `pending [parent]` — stream queued prompts under `parent` (or
6//!   the cli's own position when omitted).
7
8use crate::cli::command::CommandRequest;
9
10pub mod id;
11pub mod pending;
12
13#[derive(clap::Subcommand)]
14pub enum Command {
15    /// Fetch one piece of queued content by `prompt_contents.id`.
16    Id(id::Command),
17    /// Stream queued prompts pending delivery under a parent.
18    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// Exempt from json-schema coverage: tier aggregate (see the root
40// `ResponseItem` in command.rs - TS7056).
41#[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    fn request_base(&self) -> &crate::cli::command::RequestBase {
113        match self {
114            Request::Id(inner) => inner.request_base(),
115            Request::IdRequestSchema(inner) => inner.request_base(),
116            Request::IdResponseSchema(inner) => inner.request_base(),
117            Request::Pending(inner) => inner.request_base(),
118            Request::PendingRequestSchema(inner) => inner.request_base(),
119            Request::PendingResponseSchema(inner) => inner.request_base(),
120        }
121    }
122
123    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
124        match self {
125            Request::Id(inner) => inner.request_base_mut(),
126            Request::IdRequestSchema(inner) => inner.request_base_mut(),
127            Request::IdResponseSchema(inner) => inner.request_base_mut(),
128            Request::Pending(inner) => inner.request_base_mut(),
129            Request::PendingRequestSchema(inner) => inner.request_base_mut(),
130            Request::PendingResponseSchema(inner) => inner.request_base_mut(),
131        }
132    }
133}
134
135#[cfg(feature = "cli-executor")]
136pub async fn execute<E: crate::cli::command::CommandExecutor>(
137    executor: &E,
138    request: Request,
139    agent_arguments: Option<&crate::cli::command::AgentArguments>,
140) -> Result<
141    std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
142    E::Error,
143> {
144    use futures::StreamExt;
145    let stream: std::pin::Pin<
146        Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>,
147    > = match request {
148        Request::Id(req) => {
149            let value = id::execute(executor, req, agent_arguments).await?;
150            Box::pin(crate::cli::command::StreamOnce::new(Ok(ResponseItem::Id(value))))
151        }
152        Request::IdRequestSchema(req) => {
153            let value =
154                id::request_schema::execute(executor, req, agent_arguments).await?;
155            Box::pin(crate::cli::command::StreamOnce::new(Ok(
156                ResponseItem::IdRequestSchema(value),
157            )))
158        }
159        Request::IdResponseSchema(req) => {
160            let value =
161                id::response_schema::execute(executor, req, agent_arguments).await?;
162            Box::pin(crate::cli::command::StreamOnce::new(Ok(
163                ResponseItem::IdResponseSchema(value),
164            )))
165        }
166        Request::Pending(req) => {
167            let inner = pending::execute(executor, req, agent_arguments).await?;
168            Box::pin(inner.map(|r| r.map(ResponseItem::Pending)))
169        }
170        Request::PendingRequestSchema(req) => {
171            let value =
172                pending::request_schema::execute(executor, req, agent_arguments).await?;
173            Box::pin(crate::cli::command::StreamOnce::new(Ok(
174                ResponseItem::PendingRequestSchema(value),
175            )))
176        }
177        Request::PendingResponseSchema(req) => {
178            let value =
179                pending::response_schema::execute(executor, req, agent_arguments).await?;
180            Box::pin(crate::cli::command::StreamOnce::new(Ok(
181                ResponseItem::PendingResponseSchema(value),
182            )))
183        }
184    };
185    Ok(stream)
186}
187
188#[cfg(feature = "cli-executor")]
189pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
190    executor: &E,
191    request: Request,
192    transform: crate::cli::command::Transform,
193    agent_arguments: Option<&crate::cli::command::AgentArguments>,
194) -> Result<
195    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
196    E::Error,
197> {
198    let stream: std::pin::Pin<
199        Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>,
200    > = match request {
201        Request::Id(req) => {
202            let value = id::execute_transform(executor, req, transform, agent_arguments).await?;
203            Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
204        }
205        Request::IdRequestSchema(req) => {
206            let value =
207                id::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
208            Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
209        }
210        Request::IdResponseSchema(req) => {
211            let value =
212                id::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
213            Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
214        }
215        Request::Pending(req) => {
216            let inner = pending::execute_transform(executor, req, transform, agent_arguments).await?;
217            Box::pin(inner)
218        }
219        Request::PendingRequestSchema(req) => {
220            let value =
221                pending::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
222            Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
223        }
224        Request::PendingResponseSchema(req) => {
225            let value =
226                pending::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
227            Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
228        }
229    };
230    Ok(stream)
231}