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 owner: String,
10    pub name: String,
11    pub version: String,
12    pub jq: Option<String>,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
16#[schemars(rename = "cli.command.tools.get.Path")]
17pub enum Path {
18    #[serde(rename = "tools/get")]
19    ToolsGet,
20}
21
22impl CommandRequest for Request {
23    fn into_command(&self) -> Vec<String> {
24        let mut argv = vec![
25            "tools".to_string(),
26            "get".to_string(),
27            "--owner".to_string(),
28            self.owner.clone(),
29            "--name".to_string(),
30            self.name.clone(),
31            "--version".to_string(),
32            self.version.clone(),
33        ];
34        if let Some(jq) = &self.jq {
35            argv.push("--jq".to_string());
36            argv.push(jq.clone());
37        }
38        argv
39    }
40}
41
42/// Per-OS exec command for a tool. The current platform's vector is
43/// the program plus its leading arguments; the caller's `--args` are
44/// appended, and the result runs with CWD = the tool's version folder
45/// (where `objectiveai.json` lives).
46#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
47#[schemars(rename = "cli.command.tools.get.Exec")]
48pub struct Exec {
49    pub windows: Vec<String>,
50    pub linux: Vec<String>,
51    pub macos: Vec<String>,
52}
53
54#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
55#[schemars(rename = "cli.command.tools.get.ResponseManifest")]
56pub struct ResponseManifest {
57    pub name: String,
58    pub description: String,
59    pub version: String,
60    pub owner: String,
61    pub exec: Exec,
62    pub source: String,
63}
64
65pub type Response = Option<ResponseManifest>;
66
67#[derive(clap::Args)]
68pub struct Args {
69    /// Tool owner (GitHub `<owner>` segment). Required.
70    #[arg(long)]
71    pub owner: String,
72    /// Tool name (repository segment). Required.
73    #[arg(long)]
74    pub name: String,
75    /// Tool version. Required.
76    #[arg(long)]
77    pub version: String,
78    /// jq filter applied to the JSON output.
79    #[arg(long)]
80    pub jq: Option<String>,
81}
82
83#[derive(clap::Args)]
84#[command(args_conflicts_with_subcommands = true)]
85pub struct Command {
86    #[command(flatten)]
87    pub args: Args,
88    #[command(subcommand)]
89    pub schema: Option<Schema>,
90}
91
92#[derive(clap::Subcommand)]
93pub enum Schema {
94    /// Emit the JSON Schema for this leaf's `Request` type and exit.
95    RequestSchema(request_schema::Args),
96    /// Emit the JSON Schema for this leaf's `Response` type and exit.
97    ResponseSchema(response_schema::Args),
98}
99
100impl TryFrom<Args> for Request {
101    type Error = crate::cli::command::FromArgsError;
102    fn try_from(args: Args) -> Result<Self, Self::Error> {
103        Ok(Self {
104            path_type: Path::ToolsGet,
105            owner: args.owner,
106            name: args.name,
107            version: args.version,
108            jq: args.jq,
109        })
110    }
111}
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute<E: crate::cli::command::CommandExecutor>(
115    executor: &E,
116    mut request: Request,
117
118        agent_arguments: Option<&crate::cli::command::AgentArguments>,
119    ) -> Result<Response, E::Error> {
120    request.jq = None;
121    executor.execute_one(request, agent_arguments).await
122}
123
124#[cfg(feature = "cli-executor")]
125pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
126    executor: &E,
127    mut request: Request,
128    jq: String,
129
130        agent_arguments: Option<&crate::cli::command::AgentArguments>,
131    ) -> Result<serde_json::Value, E::Error> {
132    request.jq = Some(jq);
133    executor.execute_one(request, agent_arguments).await
134}
135
136#[cfg(feature = "mcp")]
137impl crate::cli::command::CommandResponse for ResponseManifest {
138    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
139        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
140    }
141}
142
143pub mod request_schema;
144
145
146pub mod response_schema;