Skip to main content

objectiveai_sdk/cli/command/tools/get/
mod.rs

1//! `tools get` — async handler stub.
2
3use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.tools.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub name: String,
10    pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.tools.get.Path")]
15pub enum Path {
16    #[serde(rename = "tools/get")]
17    ToolsGet,
18}
19
20impl CommandRequest for Request {
21    fn into_command(&self) -> Vec<String> {
22        let mut argv = vec!["tools".to_string(), "get".to_string(), self.name.clone()];
23        if let Some(jq) = &self.jq {
24            argv.push("--jq".to_string());
25            argv.push(jq.clone());
26        }
27        argv
28    }
29}
30
31#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.tools.get.ResponseManifest")]
33pub struct ResponseManifest {
34    pub name: String,
35    pub description: String,
36    pub version: String,
37    pub owner: String,
38    pub exec: String,
39    pub source: String,
40}
41
42pub type Response = Option<ResponseManifest>;
43
44#[derive(clap::Args)]
45pub struct Args {
46    /// Plugin/tool name.
47    pub name: String,
48    /// jq filter applied to the JSON output.
49    #[arg(long)]
50    pub jq: Option<String>,
51}
52
53#[derive(clap::Args)]
54#[command(args_conflicts_with_subcommands = true)]
55pub struct Command {
56    #[command(flatten)]
57    pub args: Args,
58    #[command(subcommand)]
59    pub schema: Option<Schema>,
60}
61
62#[derive(clap::Subcommand)]
63pub enum Schema {
64    /// Emit the JSON Schema for this leaf's `Request` type and exit.
65    RequestSchema(request_schema::Args),
66    /// Emit the JSON Schema for this leaf's `Response` type and exit.
67    ResponseSchema(response_schema::Args),
68}
69
70impl TryFrom<Args> for Request {
71    type Error = crate::cli::command::FromArgsError;
72    fn try_from(args: Args) -> Result<Self, Self::Error> {
73        Ok(Self { path_type: Path::ToolsGet,
74            name: args.name,
75            jq: args.jq,
76        })
77    }
78}
79
80#[cfg(feature = "cli-executor")]
81pub async fn execute<E: crate::cli::command::CommandExecutor>(
82    executor: &E,
83    mut request: Request,
84
85        agent_arguments: Option<&crate::cli::command::AgentArguments>,
86    ) -> Result<Response, E::Error> {
87    request.jq = None;
88    executor.execute_one(request, agent_arguments).await
89}
90
91#[cfg(feature = "cli-executor")]
92pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
93    executor: &E,
94    mut request: Request,
95    jq: String,
96
97        agent_arguments: Option<&crate::cli::command::AgentArguments>,
98    ) -> Result<serde_json::Value, E::Error> {
99    request.jq = Some(jq);
100    executor.execute_one(request, agent_arguments).await
101}
102
103#[cfg(feature = "mcp")]
104impl crate::cli::command::CommandResponse for ResponseManifest {
105    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
106        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
107    }
108}
109
110pub mod request_schema;
111
112
113pub mod response_schema;