objectiveai_sdk/cli/command/plugins/get/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.plugins.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.plugins.get.Path")]
18pub enum Path {
19 #[serde(rename = "plugins/get")]
20 PluginsGet,
21}
22
23impl CommandRequest for Request {
24 fn request_base(&self) -> &crate::cli::command::RequestBase {
25 &self.base
26 }
27
28 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
29 Some(&mut self.base)
30 }
31}
32
33pub type Response = Option<ResponseManifest>;
34
35#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
36#[schemars(rename = "cli.command.plugins.get.ResponseManifest")]
37pub struct ResponseManifest {
38 pub owner: String,
39 pub name: String,
40 pub version: String,
41 pub description: String,
42 pub exec: crate::cli::command::tools::get::Exec,
47 #[serde(default, skip_serializing_if = "Option::is_none")]
48 #[schemars(extend("omitempty" = true))]
49 pub viewer_url: Option<String>,
50 #[serde(default, skip_serializing_if = "Vec::is_empty")]
51 pub viewer_routes: Vec<ResponseViewerRoute>,
52 #[serde(default, skip_serializing_if = "Vec::is_empty")]
53 pub mcp_servers: Vec<ResponseMcpServer>,
54}
55
56impl ResponseManifest {
57 pub fn tool_name(&self) -> String {
63 format!(
64 "plugin_{}_{}_{}",
65 self.owner,
66 self.name,
67 self.version.replace('.', "-")
68 )
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
73#[schemars(rename = "cli.command.plugins.get.ResponseViewerRoute")]
74pub struct ResponseViewerRoute {
75 pub path: String,
76 pub method: ResponseHttpMethod,
77 pub r#type: String,
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
81#[serde(rename_all = "UPPERCASE")]
82#[schemars(rename = "cli.command.plugins.get.ResponseHttpMethod")]
83pub enum ResponseHttpMethod {
84 Get,
85 Post,
86 Put,
87 Patch,
88 Delete,
89}
90
91#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
92#[schemars(rename = "cli.command.plugins.get.ResponseMcpServer")]
93pub struct ResponseMcpServer {
94 pub name: String,
95 pub authorization: bool,
96}
97
98#[derive(clap::Args)]
99#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
100#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
101#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
102pub struct Args {
103 #[arg(long)]
105 pub owner: Option<String>,
106 #[arg(long)]
108 pub name: Option<String>,
109 #[arg(long)]
111 pub version: Option<String>,
112 #[command(flatten)]
113 pub base: crate::cli::command::RequestBaseArgs,
114}
115
116#[derive(clap::Args)]
117#[command(args_conflicts_with_subcommands = true)]
118pub struct Command {
119 #[command(flatten)]
120 pub args: Args,
121 #[command(subcommand)]
122 pub schema: Option<Schema>,
123}
124
125#[derive(clap::Subcommand)]
126pub enum Schema {
127 RequestSchema(request_schema::Args),
129 ResponseSchema(response_schema::Args),
131}
132
133impl TryFrom<Args> for Request {
134 type Error = crate::cli::command::FromArgsError;
135 fn try_from(args: Args) -> Result<Self, Self::Error> {
136 Ok(Self {
137 path_type: Path::PluginsGet,
138 owner: args.owner.ok_or_else(|| {
139 crate::cli::command::FromArgsError::path_parse(
140 "owner",
141 "--owner is required".to_string(),
142 )
143 })?,
144 name: args.name.ok_or_else(|| {
145 crate::cli::command::FromArgsError::path_parse(
146 "name",
147 "--name is required".to_string(),
148 )
149 })?,
150 version: args.version.ok_or_else(|| {
151 crate::cli::command::FromArgsError::path_parse(
152 "version",
153 "--version is required".to_string(),
154 )
155 })?,
156 base: args.base.into(),
157 })
158 }
159}
160
161#[cfg(feature = "cli-executor")]
162pub async fn execute<E: crate::cli::command::CommandExecutor>(
163 executor: &E,
164 mut request: Request,
165
166 agent_arguments: Option<&crate::cli::command::AgentArguments>,
167 ) -> Result<Response, E::Error> {
168 request.base.clear_transform();
169 executor.execute_one(request, agent_arguments).await
170}
171
172#[cfg(feature = "cli-executor")]
173pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
174 executor: &E,
175 mut request: Request,
176 transform: crate::cli::command::Transform,
177
178 agent_arguments: Option<&crate::cli::command::AgentArguments>,
179 ) -> Result<serde_json::Value, E::Error> {
180 request.base.set_transform(transform);
181 executor.execute_one(request, agent_arguments).await
182}
183
184#[cfg(feature = "mcp")]
185impl crate::cli::command::CommandResponse for ResponseManifest {
186 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
187 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
188 }
189}
190
191pub mod request_schema;
192
193
194pub mod response_schema;