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    pub jq: Option<String>,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
21#[schemars(rename = "cli.command.agents.queue.delete.Path")]
22pub enum Path {
23    #[serde(rename = "agents/queue/delete")]
24    AgentsQueueDelete,
25}
26
27impl CommandRequest for Request {
28    fn into_command(&self) -> Vec<String> {
29        let mut argv = vec![
30            "agents".to_string(),
31            "queue".to_string(),
32            "delete".to_string(),
33            self.id.to_string(),
34        ];
35        if let Some(jq) = &self.jq {
36            argv.push("--jq".to_string());
37            argv.push(jq.clone());
38        }
39        argv
40    }
41}
42
43/// What was deleted. Carries every column of the original
44/// `prompts` row so the caller can confirm the drop:
45/// exactly one of `agent_instance_hierarchy` / `agent_tag` is set
46/// (matching the original target), `enqueued_at` is the original
47/// unix-seconds timestamp, and `content` is the reconstructed
48/// `RichContent` body.
49#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
50#[schemars(rename = "cli.command.agents.queue.delete.Response")]
51pub struct Response {
52    pub id: i64,
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    #[schemars(extend("omitempty" = true))]
55    pub agent_instance_hierarchy: Option<String>,
56    #[serde(default, skip_serializing_if = "Option::is_none")]
57    #[schemars(extend("omitempty" = true))]
58    pub agent_tag: Option<String>,
59    /// Idempotency token, if the dropped row had one.
60    #[serde(default, skip_serializing_if = "Option::is_none")]
61    #[schemars(extend("omitempty" = true))]
62    pub key: Option<String>,
63    pub enqueued_at: i64,
64    pub content: crate::agent::completions::message::RichContent,
65}
66
67#[derive(clap::Args)]
68pub struct Args {
69    /// Row id of the queued prompt to delete (as surfaced by
70    /// `agents queue list`).
71    pub id: i64,
72    /// jq filter applied to the JSON output.
73    #[arg(long)]
74    pub jq: Option<String>,
75}
76
77#[derive(clap::Args)]
78#[command(args_conflicts_with_subcommands = true)]
79pub struct Command {
80    #[command(flatten)]
81    pub args: Args,
82    #[command(subcommand)]
83    pub schema: Option<Schema>,
84}
85
86#[derive(clap::Subcommand)]
87pub enum Schema {
88    /// Emit the JSON Schema for this leaf's `Request` type and exit.
89    RequestSchema(request_schema::Args),
90    /// Emit the JSON Schema for this leaf's `Response` type and exit.
91    ResponseSchema(response_schema::Args),
92}
93
94impl TryFrom<Args> for Request {
95    type Error = crate::cli::command::FromArgsError;
96    fn try_from(args: Args) -> Result<Self, Self::Error> {
97        Ok(Self {
98            path_type: Path::AgentsQueueDelete,
99            id: args.id,
100            jq: args.jq,
101        })
102    }
103}
104
105#[cfg(feature = "cli-executor")]
106pub async fn execute<E: crate::cli::command::CommandExecutor>(
107    executor: &E,
108    mut request: Request,
109    agent_arguments: Option<&crate::cli::command::AgentArguments>,
110) -> Result<Response, E::Error> {
111    request.jq = None;
112    executor.execute_one(request, agent_arguments).await
113}
114
115#[cfg(feature = "cli-executor")]
116pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
117    executor: &E,
118    mut request: Request,
119    jq: String,
120    agent_arguments: Option<&crate::cli::command::AgentArguments>,
121) -> Result<serde_json::Value, E::Error> {
122    request.jq = Some(jq);
123    executor.execute_one(request, agent_arguments).await
124}
125
126#[cfg(feature = "mcp")]
127impl crate::cli::command::CommandResponse for Response {
128    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
129        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
130    }
131}
132
133pub mod request_schema;
134
135pub mod response_schema;