Skip to main content

objectiveai_sdk/cli/command/plugins/run/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.plugins.run.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.plugins.run.request_schema.Path")]
12pub enum Path {
13    #[serde(rename = "plugins/run/request_schema")]
14    PluginsRunRequestSchema,
15}
16#[derive(clap::Args)]
17pub struct Args {
18    #[arg(long)]
19    pub jq: Option<String>,
20}
21
22
23impl CommandRequest for Request {
24    fn into_command(&self) -> Vec<String> {
25        let mut argv: Vec<String> = vec!["plugins", "run", "request-schema"].into_iter().map(String::from).collect();
26        if let Some(jq) = &self.jq {
27            argv.push("--jq".to_string());
28            argv.push(jq.clone());
29        }
30        argv
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 { path_type: Path::PluginsRunRequestSchema, jq: args.jq })
40    }
41}
42
43#[cfg(feature = "cli-executor")]
44pub async fn execute<E: crate::cli::command::CommandExecutor>(
45    executor: &E,
46    mut request: Request,
47
48    agent_arguments: Option<&crate::cli::command::AgentArguments>,
49) -> Result<Response, E::Error> {
50    request.jq = None;
51    executor.execute_one(request, agent_arguments).await
52}
53
54#[cfg(feature = "cli-executor")]
55pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
56    executor: &E,
57    mut request: Request,
58    jq: String,
59
60    agent_arguments: Option<&crate::cli::command::AgentArguments>,
61) -> Result<serde_json::Value, E::Error> {
62    request.jq = Some(jq);
63    executor.execute_one(request, agent_arguments).await
64}