Skip to main content

objectiveai_cli/command/agents/queue/
delete.rs

1//! `agents queue delete` — bare-naked handler. Atomically
2//! drops one queued message by its `message_queue.id` and returns the
3//! deleted row's metadata + reconstructed content body. Cascade on
4//! `message_queue_contents.message_queue_id` sweeps every per-kind content row
5//! inside the same transaction.
6
7use objectiveai_sdk::cli::command::agents::queue::delete::{Request, Response};
8
9use crate::context::Context;
10use crate::db;
11use crate::error::Error;
12
13pub async fn execute(ctx: &Context, request: Request) -> Result<Response, Error> {
14    use db::message_queue::DeleteOutcome;
15
16    let outcome = db::message_queue::delete_by_id(
17        ctx.db_client().await?,
18        request.id,
19        &ctx.config.agent_instance_hierarchy,
20    )
21    .await?;
22    let item = match outcome {
23        DeleteOutcome::Deleted(item) => item,
24        DeleteOutcome::NotFound => {
25            return Err(Error::Filesystem(crate::filesystem::Error::NotFound(
26                format!("message-queue prompt id {}", request.id),
27            )));
28        }
29        DeleteOutcome::Unauthorized {
30            sender_agent_instance_hierarchy,
31        } => {
32            return Err(Error::QueueDeleteUnauthorized {
33                id: request.id,
34                sender_agent_instance_hierarchy,
35                caller_agent_instance_hierarchy: ctx
36                    .config
37                    .agent_instance_hierarchy
38                    .clone(),
39            });
40        }
41    };
42    Ok(Response {
43        id: request.id,
44        agent_instance_hierarchy: item.agent_instance_hierarchy,
45        agent_tag: item.agent_tag,
46        key: item.key,
47        enqueued_at: item.enqueued_at,
48        content: item.content,
49    })
50}
51
52pub mod request_schema {
53    use objectiveai_sdk::cli::command::agents::queue::delete as sdk;
54    use objectiveai_sdk::cli::command::agents::queue::delete::request_schema::{
55        Request, Response,
56    };
57
58    use crate::context::Context;
59    use crate::error::Error;
60
61    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
62        Ok(objectiveai_sdk::cli::command::ResponseSchema(
63            schemars::schema_for!(sdk::Request),
64        ))
65    }
66}
67
68pub mod response_schema {
69    use objectiveai_sdk::cli::command::agents::queue::delete as sdk;
70    use objectiveai_sdk::cli::command::agents::queue::delete::response_schema::{
71        Request, Response,
72    };
73
74    use crate::context::Context;
75    use crate::error::Error;
76
77    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
78        Ok(objectiveai_sdk::cli::command::ResponseSchema(
79            schemars::schema_for!(sdk::Response),
80        ))
81    }
82}