Skip to main content

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

1//! `agents queue delete` — manually drop one queued prompt
2//! by its `prompts.id` (the id surfaced by `agents queue
3//! list`). Returns the deleted row's metadata + content so callers
4//! can confirm exactly which item was dropped.
5//!
6//! Cascade on `prompt_contents.prompt_id` sweeps every per-kind
7//! content row inside the same transaction, so the delete is
8//! atomic.
9
10use crate::cli::command::CommandRequest;
11
12#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
13#[schemars(rename = "cli.command.agents.queue.delete.Request")]
14pub struct Request {
15    pub path_type: Path,
16    pub id: i64,
17    #[serde(flatten)]
18    pub base: crate::cli::command::RequestBase,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.agents.queue.delete.Path")]
23pub enum Path {
24    #[serde(rename = "agents/queue/delete")]
25    AgentsQueueDelete,
26}
27
28impl CommandRequest for Request {
29    fn request_base(&self) -> &crate::cli::command::RequestBase {
30        &self.base
31    }
32
33    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
34        Some(&mut self.base)
35    }
36}
37
38/// What was deleted. Carries every column of the original
39/// `prompts` row so the caller can confirm the drop:
40/// exactly one of `agent_instance_hierarchy` / `agent_tag` is set
41/// (matching the original target), `enqueued_at` is the original
42/// unix-seconds timestamp, and `content` is the reconstructed
43/// `RichContent` body.
44#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
45#[schemars(rename = "cli.command.agents.queue.delete.Response")]
46pub struct Response {
47    pub id: i64,
48    #[serde(default, skip_serializing_if = "Option::is_none")]
49    #[schemars(extend("omitempty" = true))]
50    pub agent_instance_hierarchy: Option<String>,
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    #[schemars(extend("omitempty" = true))]
53    pub agent_tag: Option<String>,
54    /// Idempotency token, if the dropped row had one.
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    #[schemars(extend("omitempty" = true))]
57    pub key: Option<String>,
58    /// RFC3339 timestamp the dropped row was enqueued at.
59    pub enqueued_at: String,
60    pub content: crate::agent::completions::message::RichContent,
61}
62
63#[derive(clap::Args)]
64#[command(group(clap::ArgGroup::new("id_required").required(true).args(["id"])))]
65pub struct Args {
66    /// Row id of the queued prompt to delete (as surfaced by
67    /// `agents queue list`).
68    #[arg(long)]
69    pub id: Option<i64>,
70    #[command(flatten)]
71    pub base: crate::cli::command::RequestBaseArgs,
72}
73
74#[derive(clap::Args)]
75#[command(args_conflicts_with_subcommands = true)]
76pub struct Command {
77    #[command(flatten)]
78    pub args: Args,
79    #[command(subcommand)]
80    pub schema: Option<Schema>,
81}
82
83#[derive(clap::Subcommand)]
84pub enum Schema {
85    /// Emit the JSON Schema for this leaf's `Request` type and exit.
86    RequestSchema(request_schema::Args),
87    /// Emit the JSON Schema for this leaf's `Response` type and exit.
88    ResponseSchema(response_schema::Args),
89}
90
91impl TryFrom<Args> for Request {
92    type Error = crate::cli::command::FromArgsError;
93    fn try_from(args: Args) -> Result<Self, Self::Error> {
94        Ok(Self {
95            path_type: Path::AgentsQueueDelete,
96            id: args.id.ok_or_else(|| {
97                crate::cli::command::FromArgsError::path_parse(
98                    "id",
99                    "--id is required".to_string(),
100                )
101            })?,
102            base: args.base.into(),
103        })
104    }
105}
106
107#[cfg(feature = "cli-executor")]
108pub async fn execute<E: crate::cli::command::CommandExecutor>(
109    executor: &E,
110    mut request: Request,
111    agent_arguments: Option<&crate::cli::command::AgentArguments>,
112) -> Result<Response, E::Error> {
113    request.base.clear_transform();
114    executor.execute_one(request, agent_arguments).await
115}
116
117#[cfg(feature = "cli-executor")]
118pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
119    executor: &E,
120    mut request: Request,
121    transform: crate::cli::command::Transform,
122    agent_arguments: Option<&crate::cli::command::AgentArguments>,
123) -> Result<serde_json::Value, E::Error> {
124    request.base.set_transform(transform);
125    executor.execute_one(request, agent_arguments).await
126}
127
128#[cfg(feature = "mcp")]
129impl crate::cli::command::CommandResponse for Response {
130    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
131        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
132    }
133}
134
135pub mod request_schema;
136
137pub mod response_schema;