Skip to main content

objectiveai_sdk/cli/command/agents/queue/open/request_schema/
mod.rs

1use crate::cli::command::CommandRequest;
2
3#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
4#[schemars(rename = "cli.command.agents.queue.open.request_schema.Request")]
5pub struct Request {
6    pub path_type: Path,
7    #[serde(flatten)]
8    pub base: crate::cli::command::RequestBase,
9}
10
11#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
12#[schemars(rename = "cli.command.agents.queue.open.request_schema.Path")]
13pub enum Path {
14    #[serde(rename = "agents/queue/open/request_schema")]
15    AgentsQueueOpenRequestSchema,
16}
17
18#[derive(clap::Args)]
19pub struct Args {
20    #[command(flatten)]
21    pub base: crate::cli::command::RequestBaseArgs,
22}
23
24impl CommandRequest for Request {
25    fn request_base(&self) -> &crate::cli::command::RequestBase {
26        &self.base
27    }
28
29    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
30        Some(&mut self.base)
31    }
32}
33
34pub type Response = crate::cli::command::ResponseSchema;
35
36impl TryFrom<Args> for Request {
37    type Error = crate::cli::command::FromArgsError;
38    fn try_from(args: Args) -> Result<Self, Self::Error> {
39        Ok(Self {
40            path_type: Path::AgentsQueueOpenRequestSchema,
41            base: args.base.into(),
42        })
43    }
44}
45
46#[cfg(feature = "cli-executor")]
47pub async fn execute<E: crate::cli::command::CommandExecutor>(
48    executor: &E,
49    mut request: Request,
50    agent_arguments: Option<&crate::cli::command::AgentArguments>,
51) -> Result<Response, E::Error> {
52    request.base.clear_transform();
53    executor.execute_one(request, agent_arguments).await
54}
55
56#[cfg(feature = "cli-executor")]
57pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
58    executor: &E,
59    mut request: Request,
60    transform: crate::cli::command::Transform,
61    agent_arguments: Option<&crate::cli::command::AgentArguments>,
62) -> Result<serde_json::Value, E::Error> {
63    request.base.set_transform(transform);
64    executor.execute_one(request, agent_arguments).await
65}
66
67/// One `/listen` broadcast run of `agents queue open request_schema`: the actual
68/// [`Request`], the producer's
69/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
70/// unary response future. See [`crate::cli::websocket_listener`].
71#[cfg(feature = "cli-listener")]
72pub struct ListenerExecution {
73    pub request: Request,
74    pub agent_arguments: crate::cli::command::AgentArguments,
75    pub response: crate::cli::websocket_listener::UnaryResponse<Response>,
76}