objectiveai_sdk/cli/command/plugins/run/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.plugins.run.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub owner: String,
10 pub name: String,
11 pub version: String,
12 pub args: Vec<String>,
13 #[serde(flatten)]
14 pub base: crate::cli::command::RequestBase,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
18#[schemars(rename = "cli.command.plugins.run.Path")]
19pub enum Path {
20 #[serde(rename = "plugins/run")]
21 PluginsRun,
22}
23
24impl CommandRequest for Request {
25 fn into_command(&self) -> Vec<String> {
26 let mut argv = vec!["plugins".to_string(), "run".to_string()];
27 argv.push("--owner".to_string());
28 argv.push(self.owner.clone());
29 argv.push("--name".to_string());
30 argv.push(self.name.clone());
31 argv.push("--version".to_string());
32 argv.push(self.version.clone());
33 self.base.push_flags(&mut argv);
34 if !self.args.is_empty() {
35 argv.push("--args".to_string());
36 argv.push(serde_json::to_string(&self.args).expect("Vec<String> serializes"));
37 }
38 argv
39 }
40
41 fn request_base(&self) -> &crate::cli::command::RequestBase {
42 &self.base
43 }
44
45 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
46 Some(&mut self.base)
47 }
48}
49
50#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
51#[serde(untagged)]
52#[schemars(rename = "cli.command.plugins.run.ResponseItem")]
53pub enum ResponseItem {
54 #[schemars(title = "Mcp")]
55 Mcp(Mcp),
56 #[schemars(title = "Error")]
61 Error(crate::cli::Error),
62 #[schemars(title = "Notification")]
63 Notification(serde_json::Value),
64}
65
66#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
77#[schemars(rename = "cli.command.plugins.run.Mcp")]
78pub struct Mcp {
79 pub r#type: McpType,
80 pub url: String,
81}
82
83#[derive(
86 Debug,
87 Clone,
88 Copy,
89 PartialEq,
90 Eq,
91 serde::Serialize,
92 serde::Deserialize,
93 schemars::JsonSchema,
94)]
95#[serde(rename_all = "snake_case")]
96#[schemars(rename = "cli.command.plugins.run.McpType")]
97pub enum McpType {
98 Mcp,
99}
100
101#[derive(clap::Args)]
102pub struct Args {
103 #[arg(long)]
105 pub owner: String,
106 #[arg(long)]
108 pub name: String,
109 #[arg(long)]
111 pub version: String,
112 #[arg(long)]
115 pub args: Option<String>,
116 #[command(flatten)]
117 pub base: crate::cli::command::RequestBaseArgs,
118}
119
120#[derive(clap::Args)]
121#[command(args_conflicts_with_subcommands = true)]
122pub struct Command {
123 #[command(flatten)]
124 pub args: Args,
125 #[command(subcommand)]
126 pub schema: Option<Schema>,
127}
128
129#[derive(clap::Subcommand)]
130pub enum Schema {
131 RequestSchema(request_schema::Args),
133 ResponseSchema(response_schema::Args),
135}
136
137impl TryFrom<Args> for Request {
138 type Error = crate::cli::command::FromArgsError;
139 fn try_from(args: Args) -> Result<Self, Self::Error> {
140 let parsed_args: Vec<String> = match args.args {
141 Some(s) => {
142 let mut de = serde_json::Deserializer::from_str(&s);
143 serde_path_to_error::deserialize(&mut de).map_err(|source| {
144 crate::cli::command::FromArgsError {
145 field: "args",
146 source: source.into(),
147 }
148 })?
149 }
150 None => Vec::new(),
151 };
152 Ok(Self {
153 path_type: Path::PluginsRun,
154 owner: args.owner,
155 name: args.name,
156 version: args.version,
157 args: parsed_args,
158 base: args.base.into(),
159 })
160 }
161}
162
163#[cfg(feature = "cli-executor")]
164pub async fn execute<E: crate::cli::command::CommandExecutor>(
165 executor: &E,
166 mut request: Request,
167
168 agent_arguments: Option<&crate::cli::command::AgentArguments>,
169 ) -> Result<E::Stream<ResponseItem>, E::Error> {
170 request.base.clear_transform();
171 executor.execute(request, agent_arguments).await
172}
173
174#[cfg(feature = "cli-executor")]
175pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
176 executor: &E,
177 mut request: Request,
178 transform: crate::cli::command::Transform,
179
180 agent_arguments: Option<&crate::cli::command::AgentArguments>,
181 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
182 request.base.set_transform(transform);
183 executor.execute(request, agent_arguments).await
184}
185
186#[cfg(feature = "mcp")]
187impl crate::cli::command::CommandResponse for ResponseItem {
188 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
189 use crate::agent::completions::message::RichContentPart;
190 use crate::cli::command::McpResponseItem;
191 match self {
192 ResponseItem::Mcp(m) => {
193 McpResponseItem::JSONL(serde_json::to_value(m).unwrap())
194 }
195 ResponseItem::Error(e) => e.into_mcp(),
196 ResponseItem::Notification(value) => {
197 if let serde_json::Value::String(s) = &value
201 && let Some((mime, payload)) = crate::data_url::parse_data_url(s)
202 {
203 let part = RichContentPart::from_blob(
204 mime,
205 payload.to_string(),
206 None,
207 );
208 return McpResponseItem::Media(part.into());
209 }
210 McpResponseItem::JSONL(value)
211 }
212 }
213 }
214}
215
216pub mod request_schema;
217
218
219pub mod response_schema;