Skip to main content

objectiveai_sdk/cli/command/agents/queue/deliver/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.deliver.request_schema.Request")]
5pub struct Request {
6    pub path_type: Path,
7    pub jq: Option<String>,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[schemars(rename = "cli.command.agents.queue.deliver.request_schema.Path")]
12pub enum Path {
13    #[serde(rename = "agents/queue/deliver/request_schema")]
14    AgentsQueueDeliverRequestSchema,
15}
16
17#[derive(clap::Args)]
18pub struct Args {
19    #[arg(long)]
20    pub jq: Option<String>,
21}
22
23impl CommandRequest for Request {
24    fn into_command(&self) -> Vec<String> {
25        let mut argv: Vec<String> =
26            vec!["agents", "queue", "deliver", "request-schema"]
27                .into_iter()
28                .map(String::from)
29                .collect();
30        if let Some(jq) = &self.jq {
31            argv.push("--jq".to_string());
32            argv.push(jq.clone());
33        }
34        argv
35    }
36}
37
38pub type Response = crate::cli::command::ResponseSchema;
39
40impl TryFrom<Args> for Request {
41    type Error = crate::cli::command::FromArgsError;
42    fn try_from(args: Args) -> Result<Self, Self::Error> {
43        Ok(Self {
44            path_type: Path::AgentsQueueDeliverRequestSchema,
45            jq: args.jq,
46        })
47    }
48}
49
50#[cfg(feature = "cli-executor")]
51pub async fn execute<E: crate::cli::command::CommandExecutor>(
52    executor: &E,
53    mut request: Request,
54    agent_arguments: Option<&crate::cli::command::AgentArguments>,
55) -> Result<Response, E::Error> {
56    request.jq = None;
57    executor.execute_one(request, agent_arguments).await
58}
59
60#[cfg(feature = "cli-executor")]
61pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
62    executor: &E,
63    mut request: Request,
64    jq: String,
65    agent_arguments: Option<&crate::cli::command::AgentArguments>,
66) -> Result<serde_json::Value, E::Error> {
67    request.jq = Some(jq);
68    executor.execute_one(request, agent_arguments).await
69}