objectiveai_sdk/cli/command/tools/get/
mod.rs1use 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 #[serde(flatten)]
13 pub base: crate::cli::command::RequestBase,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.tools.get.Path")]
18pub enum Path {
19 #[serde(rename = "tools/get")]
20 ToolsGet,
21}
22
23impl CommandRequest for Request {
24 fn into_command(&self) -> Vec<String> {
25 let mut argv = vec![
26 "tools".to_string(),
27 "get".to_string(),
28 "--owner".to_string(),
29 self.owner.clone(),
30 "--name".to_string(),
31 self.name.clone(),
32 "--version".to_string(),
33 self.version.clone(),
34 ];
35 self.base.push_flags(&mut argv);
36 argv
37 }
38
39 fn request_base(&self) -> &crate::cli::command::RequestBase {
40 &self.base
41 }
42
43 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
44 Some(&mut self.base)
45 }
46}
47
48#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
53#[schemars(rename = "cli.command.tools.get.Exec")]
54pub struct Exec {
55 pub windows: Vec<String>,
56 pub linux: Vec<String>,
57 pub macos: Vec<String>,
58}
59
60impl Exec {
61 pub fn is_empty(&self) -> bool {
62 self.windows.is_empty() && self.linux.is_empty() && self.macos.is_empty()
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
67#[schemars(rename = "cli.command.tools.get.ResponseManifest")]
68pub struct ResponseManifest {
69 pub name: String,
70 pub description: String,
71 pub version: String,
72 pub owner: String,
73 pub exec: Exec,
74 pub source: String,
75}
76
77impl ResponseManifest {
78 pub fn tool_name(&self) -> String {
84 format!(
85 "tool_{}_{}_{}",
86 self.owner,
87 self.name,
88 self.version.replace('.', "-")
89 )
90 }
91}
92
93pub type Response = Option<ResponseManifest>;
94
95#[derive(clap::Args)]
96pub struct Args {
97 #[arg(long)]
99 pub owner: String,
100 #[arg(long)]
102 pub name: String,
103 #[arg(long)]
105 pub version: String,
106 #[command(flatten)]
107 pub base: crate::cli::command::RequestBaseArgs,
108}
109
110#[derive(clap::Args)]
111#[command(args_conflicts_with_subcommands = true)]
112pub struct Command {
113 #[command(flatten)]
114 pub args: Args,
115 #[command(subcommand)]
116 pub schema: Option<Schema>,
117}
118
119#[derive(clap::Subcommand)]
120pub enum Schema {
121 RequestSchema(request_schema::Args),
123 ResponseSchema(response_schema::Args),
125}
126
127impl TryFrom<Args> for Request {
128 type Error = crate::cli::command::FromArgsError;
129 fn try_from(args: Args) -> Result<Self, Self::Error> {
130 Ok(Self {
131 path_type: Path::ToolsGet,
132 owner: args.owner,
133 name: args.name,
134 version: args.version,
135 base: args.base.into(),
136 })
137 }
138}
139
140#[cfg(feature = "cli-executor")]
141pub async fn execute<E: crate::cli::command::CommandExecutor>(
142 executor: &E,
143 mut request: Request,
144
145 agent_arguments: Option<&crate::cli::command::AgentArguments>,
146 ) -> Result<Response, E::Error> {
147 request.base.clear_transform();
148 executor.execute_one(request, agent_arguments).await
149}
150
151#[cfg(feature = "cli-executor")]
152pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
153 executor: &E,
154 mut request: Request,
155 transform: crate::cli::command::Transform,
156
157 agent_arguments: Option<&crate::cli::command::AgentArguments>,
158 ) -> Result<serde_json::Value, E::Error> {
159 request.base.set_transform(transform);
160 executor.execute_one(request, agent_arguments).await
161}
162
163#[cfg(feature = "mcp")]
164impl crate::cli::command::CommandResponse for ResponseManifest {
165 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
166 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
167 }
168}
169
170pub mod request_schema;
171
172
173pub mod response_schema;