objectiveai_cli/command/agents/
enqueue.rs1use objectiveai_sdk::cli::command::agents::enqueue::{Request, Response};
14use objectiveai_sdk::cli::command::agents::selector::AgentSelector;
15
16use crate::context::Context;
17use crate::error::Error;
18
19pub async fn execute(ctx: &Context, request: Request) -> Result<Response, Error> {
20 let content = super::message::resolve_message(ctx, request.message).await?;
21 let (hier, tag) = match request.agent {
22 AgentSelector::Instance {
23 parent_agent_instance_hierarchy,
24 agent_instance,
25 } => {
26 let parent = parent_agent_instance_hierarchy
27 .as_deref()
28 .unwrap_or(&ctx.config.agent_instance_hierarchy);
29 (Some(format!("{parent}/{agent_instance}")), None)
30 }
31 AgentSelector::Tag { agent_tag } => {
32 match crate::db::tags::lookup(ctx.db_client().await?, &agent_tag).await? {
33 crate::db::tags::LookupState::Absent => {
34 return Err(Error::TagNotFound(agent_tag));
35 }
36 _ => (None, Some(agent_tag)),
37 }
38 }
39 AgentSelector::Ref { .. } => return Err(Error::EnqueueRefTarget),
40 };
41 let id = crate::db::message_queue::enqueue_with_content(
42 ctx.db_client().await?,
43 hier.clone(),
44 tag.clone(),
45 &ctx.config.agent_instance_hierarchy,
46 request.key,
47 content,
48 )
49 .await?;
50 Ok(Response {
51 id,
52 agent_instance_hierarchy: hier,
53 agent_tag: tag,
54 })
55}
56
57pub mod request_schema {
58 use objectiveai_sdk::cli::command::agents::enqueue as sdk;
59 use objectiveai_sdk::cli::command::agents::enqueue::request_schema::{Request, Response};
60
61 use crate::context::Context;
62 use crate::error::Error;
63
64 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
65 Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Request)))
66 }
67}
68
69pub mod response_schema {
70 use objectiveai_sdk::cli::command::agents::enqueue as sdk;
71 use objectiveai_sdk::cli::command::agents::enqueue::response_schema::{Request, Response};
72
73 use crate::context::Context;
74 use crate::error::Error;
75
76 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
77 Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Response)))
78 }
79}