Skip to main content

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

1//! `plugins 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.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    /// Per-OS exec argv for the plugin's cli side, run with CWD =
43    /// `<plugin dir>/cli/` — the same shape tools use. Required (an
44    /// empty exec is a viewer-only plugin, which still round-trips as
45    /// an empty per-OS object).
46    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 mcp_servers: Vec<ResponseMcpServer>,
52}
53
54impl ResponseManifest {
55    /// LLM-visible MCP tool name for this plugin:
56    /// `plugin_{owner}_{name}_{version}`, with every `.` in the
57    /// version substituted to `-` so the result stays within the
58    /// Anthropic tool-name regex (`^[a-zA-Z0-9_-]{1,128}$`).
59    /// `objectiveai-mcp` advertises each plugin under this name.
60    pub fn tool_name(&self) -> String {
61        format!(
62            "plugin_{}_{}_{}",
63            self.owner,
64            self.name,
65            self.version.replace('.', "-")
66        )
67    }
68}
69
70#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
71#[schemars(rename = "cli.command.plugins.get.ResponseMcpServer")]
72pub struct ResponseMcpServer {
73    pub name: String,
74    pub authorization: bool,
75}
76
77#[derive(clap::Args)]
78#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
79#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
80#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
81pub struct Args {
82    /// Plugin owner (GitHub `<owner>` segment). Required.
83    #[arg(long)]
84    pub owner: Option<String>,
85    /// Plugin name (repository segment). Required.
86    #[arg(long)]
87    pub name: Option<String>,
88    /// Plugin version. Required.
89    #[arg(long)]
90    pub version: Option<String>,
91    #[command(flatten)]
92    pub base: crate::cli::command::RequestBaseArgs,
93}
94
95#[derive(clap::Args)]
96#[command(args_conflicts_with_subcommands = true)]
97pub struct Command {
98    #[command(flatten)]
99    pub args: Args,
100    #[command(subcommand)]
101    pub schema: Option<Schema>,
102}
103
104#[derive(clap::Subcommand)]
105pub enum Schema {
106    /// Emit the JSON Schema for this leaf's `Request` type and exit.
107    RequestSchema(request_schema::Args),
108    /// Emit the JSON Schema for this leaf's `Response` type and exit.
109    ResponseSchema(response_schema::Args),
110}
111
112impl TryFrom<Args> for Request {
113    type Error = crate::cli::command::FromArgsError;
114    fn try_from(args: Args) -> Result<Self, Self::Error> {
115        Ok(Self {
116            path_type: Path::PluginsGet,
117            owner: args.owner.ok_or_else(|| {
118                crate::cli::command::FromArgsError::path_parse(
119                    "owner",
120                    "--owner is required".to_string(),
121                )
122            })?,
123            name: args.name.ok_or_else(|| {
124                crate::cli::command::FromArgsError::path_parse(
125                    "name",
126                    "--name is required".to_string(),
127                )
128            })?,
129            version: args.version.ok_or_else(|| {
130                crate::cli::command::FromArgsError::path_parse(
131                    "version",
132                    "--version is required".to_string(),
133                )
134            })?,
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
172pub mod response_schema;
173
174/// One `/listen` broadcast run of `plugins get`: the actual
175/// [`Request`], the producer's
176/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
177/// unary response future. See [`crate::cli::websocket_listener`].
178#[cfg(feature = "cli-listener")]
179pub struct ListenerExecution {
180    pub request: Request,
181    pub agent_arguments: crate::cli::command::AgentArguments,
182    pub response: crate::cli::websocket_listener::UnaryResponse<Response>,
183}