Skip to main content

objectiveai_sdk/cli/command/laboratories/config/addresses/add/
mod.rs

1//! `laboratories config addresses add` — async handler stub.
2
3use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.laboratories.config.addresses.add.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11    /// The daemon `http://` address the laboratory host should connect to.
12    pub key: String,
13    /// The signature to present at that address. Empty ⇒ dial
14    /// unauthenticated (the address's daemon must be open). Always
15    /// sent explicitly — NO serde default: empty-string schema
16    /// defaults are banned (the json-schema builder asserts it), and
17    /// the CLI fills `""` itself when `--value` is omitted.
18    pub value: String,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.laboratories.config.addresses.add.Path")]
23pub enum Path {
24    #[serde(rename = "laboratories/config/addresses/add")]
25    LaboratoriesConfigAddressesAdd,
26}
27
28impl CommandRequest for Request {
29    fn request_base(&self) -> &crate::cli::command::RequestBase {
30        &self.base
31    }
32
33    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
34        Some(&mut self.base)
35    }
36}
37
38pub type Response = crate::cli::command::Ok;
39
40#[derive(clap::Args)]
41#[command(group(clap::ArgGroup::new("key_required").required(true).args(["key"])))]
42pub struct Args {
43    #[command(flatten)]
44    pub base: crate::cli::command::RequestBaseArgs,
45    /// Entry key (a daemon `http://` address).
46    #[arg(long)]
47    pub key: Option<String>,
48    /// Entry value (the signature to present at that address).
49    /// Omitted ⇒ dial unauthenticated.
50    #[arg(long)]
51    pub value: Option<String>,
52}
53
54#[derive(clap::Args)]
55#[command(args_conflicts_with_subcommands = true)]
56pub struct Command {
57    #[command(flatten)]
58    pub args: Args,
59    #[command(subcommand)]
60    pub schema: Option<Schema>,
61}
62
63#[derive(clap::Subcommand)]
64pub enum Schema {
65    /// Emit the JSON Schema for this leaf's `Request` type and exit.
66    RequestSchema(request_schema::Args),
67    /// Emit the JSON Schema for this leaf's `Response` type and exit.
68    ResponseSchema(response_schema::Args),
69}
70
71impl TryFrom<Args> for Request {
72    type Error = crate::cli::command::FromArgsError;
73    fn try_from(args: Args) -> Result<Self, Self::Error> {
74        Ok(Self {
75            base: args.base.into(), path_type: Path::LaboratoriesConfigAddressesAdd,
76            key: args.key.ok_or_else(|| {
77                crate::cli::command::FromArgsError::path_parse(
78                    "key",
79                    "--key is required".to_string(),
80                )
81            })?,
82            // Optional: an address without a signature dials
83            // unauthenticated.
84            value: args.value.unwrap_or_default(),
85        })
86    }
87}
88
89#[cfg(feature = "cli-executor")]
90pub async fn execute<E: crate::cli::command::CommandExecutor>(
91    executor: &E,
92    request: Request,
93
94        agent_arguments: Option<&crate::cli::command::AgentArguments>,
95    ) -> Result<Response, E::Error> {
96    executor.execute_one(request, agent_arguments).await
97}
98
99pub mod request_schema;
100
101pub mod response_schema;
102
103#[cfg(feature = "cli-executor")]
104pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
105    executor: &E,
106    request: Request,
107    _transform: crate::cli::command::Transform,
108
109        agent_arguments: Option<&crate::cli::command::AgentArguments>,
110    ) -> Result<serde_json::Value, E::Error> {
111    let resp: Response = executor.execute_one(request, agent_arguments).await?;
112    Ok(serde_json::to_value(resp).expect("Response serializes"))
113}
114
115/// One `/listen` broadcast run of `laboratories config addresses add`: the actual
116/// [`Request`], the producer's
117/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
118/// unary response future. See [`crate::cli::broadcast_listener`].
119#[cfg(feature = "cli-listener")]
120pub struct ListenerExecution {
121    pub request: Request,
122    pub agent_arguments: crate::cli::command::AgentArguments,
123    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
124}