objectiveai_sdk/cli/command/agents/publish/
mod.rs1use crate::agent::RemoteAgentBaseWithFallbacks;
4use crate::cli::command::CommandRequest;
5
6#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
7#[schemars(rename = "cli.command.agents.publish.Request")]
8pub struct Request {
9 pub path_type: Path,
10 pub repository: String,
11 pub body: RequestBody,
12 pub message: RequestPublishMessage,
13 pub overwrite: bool,
14 #[serde(flatten)]
15 pub base: crate::cli::command::RequestBase,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[schemars(rename = "cli.command.agents.publish.Path")]
20pub enum Path {
21 #[serde(rename = "agents/publish")]
22 AgentsPublish,
23}
24
25#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
26#[schemars(rename = "cli.command.agents.publish.RequestBody")]
27pub enum RequestBody {
28 #[schemars(title = "Inline")]
29 Inline(RemoteAgentBaseWithFallbacks),
30 #[schemars(title = "File")]
31 File(std::path::PathBuf),
32 #[schemars(title = "PythonInline")]
33 PythonInline(String),
34 #[schemars(title = "PythonFile")]
35 PythonFile(std::path::PathBuf),
36}
37
38#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
39#[schemars(rename = "cli.command.agents.publish.RequestPublishMessage")]
40pub enum RequestPublishMessage {
41 #[schemars(title = "Inline")]
42 Inline(String),
43 #[schemars(title = "File")]
44 File(std::path::PathBuf),
45}
46
47impl RequestBody {
48 fn push_flags(&self, out: &mut Vec<String>) {
49 match self {
50 RequestBody::Inline(v) => {
51 out.push("--body-inline".to_string());
52 out.push(serde_json::to_string(v).expect("body serializes"));
53 }
54 RequestBody::File(p) => {
55 out.push("--body-file".to_string());
56 out.push(p.to_string_lossy().into_owned());
57 }
58 RequestBody::PythonInline(code) => {
59 out.push("--body-python-inline".to_string());
60 out.push(code.clone());
61 }
62 RequestBody::PythonFile(p) => {
63 out.push("--body-python-file".to_string());
64 out.push(p.to_string_lossy().into_owned());
65 }
66 }
67 }
68}
69
70impl RequestPublishMessage {
71 fn push_flags(&self, out: &mut Vec<String>) {
72 match self {
73 RequestPublishMessage::Inline(s) => {
74 out.push("--message-inline".to_string());
75 out.push(s.clone());
76 }
77 RequestPublishMessage::File(p) => {
78 out.push("--message-file".to_string());
79 out.push(p.to_string_lossy().into_owned());
80 }
81 }
82 }
83}
84
85impl CommandRequest for Request {
86 fn into_command(&self) -> Vec<String> {
87 let mut argv = vec![
88 "agents".to_string(),
89 "publish".to_string(),
90 "--repository".to_string(),
91 self.repository.clone(),
92 ];
93 self.body.push_flags(&mut argv);
94 self.message.push_flags(&mut argv);
95 if self.overwrite {
96 argv.push("--overwrite".to_string());
97 }
98 self.base.push_flags(&mut argv);
99 argv
100 }
101
102 fn request_base(&self) -> &crate::cli::command::RequestBase {
103 &self.base
104 }
105
106 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
107 Some(&mut self.base)
108 }
109}
110
111#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
112#[schemars(rename = "cli.command.agents.publish.Response")]
113pub struct Response {
114 pub sha: String,
115}
116
117#[derive(clap::Args)]
118pub struct Args {
119 #[arg(long)]
121 pub repository: String,
122 #[command(flatten)]
123 pub body: BodyArgs,
124 #[command(flatten)]
125 pub message: PublishMessageArgs,
126 #[arg(long)]
128 pub overwrite: bool,
129 #[command(flatten)]
130 pub base: crate::cli::command::RequestBaseArgs,
131}
132
133#[derive(clap::Args)]
134#[group(required = true, multiple = false)]
135pub struct BodyArgs {
136 #[arg(long)]
138 pub body_inline: Option<String>,
139 #[arg(long)]
141 pub body_file: Option<std::path::PathBuf>,
142 #[arg(long)]
144 pub body_python_inline: Option<String>,
145 #[arg(long)]
147 pub body_python_file: Option<std::path::PathBuf>,
148}
149
150#[derive(clap::Args)]
151#[group(required = true, multiple = false)]
152pub struct PublishMessageArgs {
153 #[arg(long)]
155 pub message_inline: Option<String>,
156 #[arg(long)]
158 pub message_file: Option<std::path::PathBuf>,
159}
160
161#[derive(clap::Args)]
162#[command(args_conflicts_with_subcommands = true)]
163pub struct Command {
164 #[command(flatten)]
165 pub args: Args,
166 #[command(subcommand)]
167 pub schema: Option<Schema>,
168}
169
170#[derive(clap::Subcommand)]
171pub enum Schema {
172 RequestSchema(request_schema::Args),
174 ResponseSchema(response_schema::Args),
176}
177
178impl TryFrom<Args> for Request {
179 type Error = crate::cli::command::FromArgsError;
180 fn try_from(args: Args) -> Result<Self, Self::Error> {
181 let body = if let Some(s) = args.body.body_inline {
182 let mut de = serde_json::Deserializer::from_str(&s);
183 let v = serde_path_to_error::deserialize(&mut de).map_err(|source| {
184 crate::cli::command::FromArgsError {
185 field: "body_inline",
186 source: source.into(),
187 }
188 })?;
189 RequestBody::Inline(v)
190 } else if let Some(p) = args.body.body_file {
191 RequestBody::File(p)
192 } else if let Some(s) = args.body.body_python_inline {
193 RequestBody::PythonInline(s)
194 } else {
195 RequestBody::PythonFile(args.body.body_python_file.unwrap())
196 };
197 let message = if let Some(s) = args.message.message_inline {
198 RequestPublishMessage::Inline(s)
199 } else {
200 RequestPublishMessage::File(args.message.message_file.unwrap())
201 };
202 Ok(Self { path_type: Path::AgentsPublish,
203 repository: args.repository,
204 body,
205 message,
206 overwrite: args.overwrite,
207 base: args.base.into(),
208 })
209 }
210}
211
212#[cfg(feature = "cli-executor")]
213pub async fn execute<E: crate::cli::command::CommandExecutor>(
214 executor: &E,
215 mut request: Request,
216
217 agent_arguments: Option<&crate::cli::command::AgentArguments>,
218 ) -> Result<Response, E::Error> {
219 request.base.clear_transform();
220 executor.execute_one(request, agent_arguments).await
221}
222
223#[cfg(feature = "cli-executor")]
224pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
225 executor: &E,
226 mut request: Request,
227 transform: crate::cli::command::Transform,
228
229 agent_arguments: Option<&crate::cli::command::AgentArguments>,
230 ) -> Result<serde_json::Value, E::Error> {
231 request.base.set_transform(transform);
232 executor.execute_one(request, agent_arguments).await
233}
234
235#[cfg(feature = "mcp")]
236impl crate::cli::command::CommandResponse for Response {
237 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
238 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
239 }
240}
241
242pub mod request_schema;
243
244
245pub mod response_schema;