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 name: String,
10 pub args: Vec<String>,
11 pub jq: Option<String>,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.plugins.run.Path")]
16pub enum Path {
17 #[serde(rename = "plugins/run")]
18 PluginsRun,
19}
20
21impl CommandRequest for Request {
22 fn into_command(&self) -> Vec<String> {
23 let mut argv = vec!["plugins".to_string(), "run".to_string()];
24 if let Some(jq) = &self.jq {
25 argv.push("--jq".to_string());
26 argv.push(jq.clone());
27 }
28 argv.push(self.name.clone());
29 argv.extend(self.args.iter().cloned());
30 argv
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
35#[serde(untagged)]
36#[schemars(rename = "cli.command.plugins.run.ResponseItem")]
37pub enum ResponseItem {
38 #[schemars(title = "Mcp")]
39 Mcp(Mcp),
40 #[schemars(title = "Error")]
45 Error(crate::cli::Error),
46 #[schemars(title = "Notification")]
47 Notification(serde_json::Value),
48}
49
50#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
61#[schemars(rename = "cli.command.plugins.run.Mcp")]
62pub struct Mcp {
63 pub r#type: McpType,
64 pub url: String,
65}
66
67#[derive(
70 Debug,
71 Clone,
72 Copy,
73 PartialEq,
74 Eq,
75 serde::Serialize,
76 serde::Deserialize,
77 schemars::JsonSchema,
78)]
79#[serde(rename_all = "snake_case")]
80#[schemars(rename = "cli.command.plugins.run.McpType")]
81pub enum McpType {
82 Mcp,
83}
84
85#[derive(clap::Args)]
86pub struct Args {
87 pub name: String,
89 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
91 pub args: Vec<String>,
92 #[arg(long)]
94 pub jq: Option<String>,
95}
96
97#[derive(clap::Args)]
98#[command(args_conflicts_with_subcommands = true)]
99pub struct Command {
100 #[command(flatten)]
101 pub args: Args,
102 #[command(subcommand)]
103 pub schema: Option<Schema>,
104}
105
106#[derive(clap::Subcommand)]
107pub enum Schema {
108 RequestSchema(request_schema::Args),
110 ResponseSchema(response_schema::Args),
112}
113
114impl TryFrom<Args> for Request {
115 type Error = crate::cli::command::FromArgsError;
116 fn try_from(args: Args) -> Result<Self, Self::Error> {
117 Ok(Self { path_type: Path::PluginsRun,
118 name: args.name,
119 args: args.args,
120 jq: args.jq,
121 })
122 }
123}
124
125#[cfg(feature = "cli-executor")]
126pub async fn execute<E: crate::cli::command::CommandExecutor>(
127 executor: &E,
128 mut request: Request,
129
130 agent_arguments: Option<&crate::cli::command::AgentArguments>,
131 ) -> Result<E::Stream<ResponseItem>, E::Error> {
132 request.jq = None;
133 executor.execute(request, agent_arguments).await
134}
135
136#[cfg(feature = "cli-executor")]
137pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
138 executor: &E,
139 mut request: Request,
140 jq: String,
141
142 agent_arguments: Option<&crate::cli::command::AgentArguments>,
143 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
144 request.jq = Some(jq);
145 executor.execute(request, agent_arguments).await
146}
147
148#[cfg(feature = "mcp")]
149impl crate::cli::command::CommandResponse for ResponseItem {
150 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
151 use crate::agent::completions::message::RichContentPart;
152 use crate::cli::command::McpResponseItem;
153 match self {
154 ResponseItem::Mcp(m) => {
155 McpResponseItem::JSONL(serde_json::to_value(m).unwrap())
156 }
157 ResponseItem::Error(e) => e.into_mcp(),
158 ResponseItem::Notification(value) => {
159 if let serde_json::Value::String(s) = &value
163 && let Some((mime, payload)) = crate::data_url::parse_data_url(s)
164 {
165 let part = RichContentPart::from_blob(
166 mime,
167 payload.to_string(),
168 None,
169 );
170 return McpResponseItem::Media(part.into());
171 }
172 McpResponseItem::JSONL(value)
173 }
174 }
175 }
176}
177
178pub mod request_schema;
179
180
181pub mod response_schema;