Skip to main content

objectiveai_sdk/cli/command/functions/profiles/publish/
mod.rs

1//! `functions profiles publish` — async handler stub.
2
3use 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    #[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.functions.profiles.publish.Path")]
20pub enum Path {
21    #[serde(rename = "functions/profiles/publish")]
22    FunctionsProfilesPublish,
23}
24
25#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
26#[schemars(rename = "cli.command.functions.profiles.publish.RequestBody")]
27pub enum RequestBody {
28    #[schemars(title = "Inline")]
29    Inline(RemoteProfile),
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.functions.profiles.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 request_base(&self) -> &crate::cli::command::RequestBase {
87        &self.base
88    }
89
90    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
91        Some(&mut self.base)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
96#[schemars(rename = "cli.command.functions.profiles.publish.Response")]
97pub struct Response {
98    pub sha: String,
99}
100
101#[derive(clap::Args)]
102#[command(group(clap::ArgGroup::new("repository_required").required(true).args(["repository"])))]
103#[group(id = "body", required = true, multiple = false)]
104#[group(id = "message", required = true, multiple = false)]
105pub struct Args {
106    /// Repository name.
107    #[arg(long)]
108    pub repository: Option<String>,
109    /// Inline JSON body.
110    #[arg(long, group = "body")]
111    pub body_inline: Option<String>,
112    /// Path to a JSON file.
113    #[arg(long, group = "body")]
114    pub body_file: Option<std::path::PathBuf>,
115    /// Inline Python that produces the JSON body.
116    #[arg(long, group = "body")]
117    pub body_python_inline: Option<String>,
118    /// Path to a Python file that produces the JSON body.
119    #[arg(long, group = "body")]
120    pub body_python_file: Option<std::path::PathBuf>,
121    /// Inline commit message.
122    #[arg(long, group = "message")]
123    pub message_inline: Option<String>,
124    /// Path to a file containing the commit message.
125    #[arg(long, group = "message")]
126    pub message_file: Option<std::path::PathBuf>,
127    /// Overwrite if the entry already exists.
128    #[arg(long)]
129    pub overwrite: bool,
130    #[command(flatten)]
131    pub base: crate::cli::command::RequestBaseArgs,
132}
133
134#[derive(clap::Args)]
135#[command(args_conflicts_with_subcommands = true)]
136pub struct Command {
137    #[command(flatten)]
138    pub args: Args,
139    #[command(subcommand)]
140    pub schema: Option<Schema>,
141}
142
143#[derive(clap::Subcommand)]
144pub enum Schema {
145    /// Emit the JSON Schema for this leaf's `Request` type and exit.
146    RequestSchema(request_schema::Args),
147    /// Emit the JSON Schema for this leaf's `Response` type and exit.
148    ResponseSchema(response_schema::Args),
149}
150
151impl TryFrom<Args> for Request {
152    type Error = crate::cli::command::FromArgsError;
153    fn try_from(args: Args) -> Result<Self, Self::Error> {
154        let body = if let Some(s) = args.body_inline {
155            let mut de = serde_json::Deserializer::from_str(&s);
156            let v = serde_path_to_error::deserialize(&mut de).map_err(|source| {
157                crate::cli::command::FromArgsError {
158                    field: "body_inline",
159                    source: source.into(),
160                }
161            })?;
162            RequestBody::Inline(v)
163        } else if let Some(p) = args.body_file {
164            RequestBody::File(p)
165        } else if let Some(s) = args.body_python_inline {
166            RequestBody::PythonInline(s)
167        } else {
168            RequestBody::PythonFile(args.body_python_file.unwrap())
169        };
170        let message = if let Some(s) = args.message_inline {
171            RequestPublishMessage::Inline(s)
172        } else {
173            RequestPublishMessage::File(args.message_file.unwrap())
174        };
175        Ok(Self { path_type: Path::FunctionsProfilesPublish,
176            repository: args.repository.ok_or_else(|| {
177                crate::cli::command::FromArgsError::path_parse(
178                    "repository",
179                    "--repository is required".to_string(),
180                )
181            })?,
182            body,
183            message,
184            overwrite: args.overwrite,
185            base: args.base.into(),
186        })
187    }
188}
189
190#[cfg(feature = "cli-executor")]
191pub async fn execute<E: crate::cli::command::CommandExecutor>(
192    executor: &E,
193    mut request: Request,
194
195        agent_arguments: Option<&crate::cli::command::AgentArguments>,
196    ) -> Result<Response, E::Error> {
197    request.base.clear_transform();
198    executor.execute_one(request, agent_arguments).await
199}
200
201#[cfg(feature = "cli-executor")]
202pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
203    executor: &E,
204    mut request: Request,
205    transform: crate::cli::command::Transform,
206
207        agent_arguments: Option<&crate::cli::command::AgentArguments>,
208    ) -> Result<serde_json::Value, E::Error> {
209    request.base.set_transform(transform);
210    executor.execute_one(request, agent_arguments).await
211}
212
213#[cfg(feature = "mcp")]
214impl crate::cli::command::CommandResponse for Response {
215    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
216        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
217    }
218}
219
220pub mod request_schema;
221
222
223pub mod response_schema;