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