Skip to main content

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

1//! `agents queue read pending` — stream every pending (i.e.
2//! `active = TRUE`) `message_queue` row for the resolved targets,
3//! coalesced into parts-grouped `ResponseItem` blocks. Symmetric
4//! with `agents logs read all`'s `ClientNotification` shape — same
5//! `Target` input, same per-part type tag, same `id` shape (an i64
6//! you pass to the matching `read id` verb to drill into the body).
7
8use crate::cli::command::CommandRequest;
9
10#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[schemars(rename = "cli.command.agents.queue.list.Request")]
12pub struct Request {
13    pub path_type: Path,
14    pub targets: Vec<Target>,
15    /// Skip rows with `message_queue_contents.id <= after_id`. Use
16    /// the highest `id` from a previous page to paginate forward.
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    #[schemars(extend("omitempty" = true))]
19    pub after_id: Option<i64>,
20    /// Cap on rows scanned per target. `None` = unlimited.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    #[schemars(extend("omitempty" = true))]
23    pub limit: Option<i64>,
24    #[serde(flatten)]
25    pub base: crate::cli::command::RequestBase,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
29#[schemars(rename = "cli.command.agents.queue.list.Path")]
30pub enum Path {
31    #[serde(rename = "agents/queue/list")]
32    AgentsQueueList,
33}
34
35impl CommandRequest for Request {
36    fn request_base(&self) -> &crate::cli::command::RequestBase {
37        &self.base
38    }
39
40    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
41        Some(&mut self.base)
42    }
43}
44
45// Share `Target` + `ClientNotificationPartType` with
46// `agents logs read all` — same per-target input shape, same
47// per-part 5-variant kind discriminator. `agents queue read pending`
48// is the pre-execution mirror of logs read all's
49// `ClientNotification` block.
50pub use super::super::logs::list::{
51    ClientNotificationPartType as QueuePartType, Target,
52};
53
54/// One row inside a `ResponseItem` block — a
55/// `message_queue_contents` entry. The `id` is the
56/// `message_queue_contents.id`, which you pass to
57/// `agents queue read id <n>` to drill into the body.
58/// `enqueued_at` is on the enclosing block, not here
59/// (one block = one `message_queue` parent row, sharing one
60/// `enqueued_at`).
61#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
62#[schemars(rename = "cli.command.agents.queue.list.QueuePart")]
63pub struct QueuePart {
64    pub id: i64,
65    pub r#type: QueuePartType,
66}
67
68/// One pending `message_queue` row, with its content rows
69/// grouped as `parts`. Two variants — direct AIH target or tag
70/// target — both flat (no nested `LookupState`).
71#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
72#[serde(tag = "by", rename_all = "snake_case")]
73#[schemars(rename = "cli.command.agents.queue.list.ResponseItem")]
74pub enum ResponseItem {
75    #[schemars(title = "AgentInstanceHierarchy")]
76    AgentInstanceHierarchy {
77        /// `message_queue.id` — the row-level id this block
78        /// represents. Pass to `agents queue delete <id>` to
79        /// soft-flip the entire row (all parts) in one call.
80        /// Distinct from each `QueuePart.id` (which is a
81        /// `message_queue_contents.id` for drilling into one
82        /// content slot via `agents queue read id`).
83        delete_id: i64,
84        agent_instance_hierarchy: String,
85        /// AIH of the caller who enqueued — from
86        /// `message_queue.sender_*`.
87        sender_agent_instance_hierarchy: String,
88        /// `message_queue.enqueued_at`. One block = one parent
89        /// `message_queue` row, so this is well-defined
90        /// block-level.
91        enqueued_at: String,
92        /// Idempotency token, if the row was enqueued with `--key`.
93        #[serde(default, skip_serializing_if = "Option::is_none")]
94        #[schemars(extend("omitempty" = true))]
95        key: Option<String>,
96        parts: Vec<QueuePart>,
97    },
98    #[schemars(title = "Tag")]
99    Tag {
100        /// `message_queue.id`. Pass to `agents queue delete <id>`.
101        delete_id: i64,
102        agent_tag: String,
103        sender_agent_instance_hierarchy: String,
104        enqueued_at: String,
105        #[serde(default, skip_serializing_if = "Option::is_none")]
106        #[schemars(extend("omitempty" = true))]
107        key: Option<String>,
108        parts: Vec<QueuePart>,
109    },
110}
111
112#[derive(clap::Args)]
113pub struct Args {
114    /// List pending (undelivered) queued prompts. Required: today
115    /// `list` only supports the pending view, so the flag must be
116    /// given explicitly (leaves room for future list modes).
117    #[arg(long, required = true)]
118    pub pending: bool,
119    /// One or more `--target instance=L[,parent=P]` entries.
120    /// `parent` defaults to the cli's own
121    /// `Config.agent_instance_hierarchy` when omitted on an
122    /// individual target. Also accepts `--target tag=T` and
123    /// `--target me` (the caller's own AIH).
124    #[arg(long = "target", required = true)]
125    pub targets: Vec<String>,
126    /// Skip rows with `message_queue_contents.id <= after_id`.
127    #[arg(long)]
128    pub after_id: Option<i64>,
129    /// Cap on rows scanned per target.
130    #[arg(long)]
131    pub limit: Option<i64>,
132    #[command(flatten)]
133    pub base: crate::cli::command::RequestBaseArgs,
134}
135
136#[derive(clap::Args)]
137#[command(args_conflicts_with_subcommands = true)]
138pub struct Command {
139    #[command(flatten)]
140    pub args: Args,
141    #[command(subcommand)]
142    pub schema: Option<Schema>,
143}
144
145#[derive(clap::Subcommand)]
146pub enum Schema {
147    /// Emit the JSON Schema for this leaf's `Request` type and exit.
148    RequestSchema(request_schema::Args),
149    /// Emit the JSON Schema for this leaf's `Response` type and exit.
150    ResponseSchema(response_schema::Args),
151}
152
153impl TryFrom<Args> for Request {
154    type Error = crate::cli::command::FromArgsError;
155    fn try_from(args: Args) -> Result<Self, Self::Error> {
156        let targets = args
157            .targets
158            .iter()
159            .map(|s| {
160                s.parse::<Target>().map_err(|msg| {
161                    crate::cli::command::FromArgsError::path_parse("target", msg)
162                })
163            })
164            .collect::<Result<Vec<_>, _>>()?;
165        Ok(Self {
166            path_type: Path::AgentsQueueList,
167            targets,
168            after_id: args.after_id,
169            limit: args.limit,
170            base: args.base.into(),
171        })
172    }
173}
174
175#[cfg(feature = "cli-executor")]
176pub async fn execute<E: crate::cli::command::CommandExecutor>(
177    executor: &E,
178    mut request: Request,
179    agent_arguments: Option<&crate::cli::command::AgentArguments>,
180) -> Result<E::Stream<ResponseItem>, E::Error> {
181    request.base.clear_transform();
182    executor.execute(request, agent_arguments).await
183}
184
185#[cfg(feature = "cli-executor")]
186pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
187    executor: &E,
188    mut request: Request,
189    transform: crate::cli::command::Transform,
190    agent_arguments: Option<&crate::cli::command::AgentArguments>,
191) -> Result<E::Stream<serde_json::Value>, E::Error> {
192    request.base.set_transform(transform);
193    executor.execute(request, agent_arguments).await
194}
195
196#[cfg(feature = "mcp")]
197impl crate::cli::command::CommandResponse for ResponseItem {
198    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
199        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
200    }
201}
202
203pub mod request_schema;
204
205pub mod response_schema;