objectiveai_sdk/cli/command/channels/publish/
mod.rs1use crate::cli::command::CommandRequest;
8
9#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[schemars(rename = "cli.command.channels.publish.Request")]
11pub struct Request {
12 pub path_type: Path,
13 pub key: String,
16 pub details: serde_json::Value,
18 pub message: String,
21 #[serde(flatten)]
22 pub base: crate::cli::command::RequestBase,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
26#[schemars(rename = "cli.command.channels.publish.Path")]
27pub enum Path {
28 #[serde(rename = "channels/publish")]
29 ChannelsPublish,
30}
31
32impl CommandRequest for Request {
33 fn request_base(&self) -> &crate::cli::command::RequestBase {
34 &self.base
35 }
36
37 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
38 Some(&mut self.base)
39 }
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
45#[schemars(rename = "cli.command.channels.publish.Response")]
46pub struct Response {
47 pub channel_id: String,
48 pub secret: String,
51}
52
53#[derive(clap::Args)]
54#[command(group(clap::ArgGroup::new("key_required").required(true).args(["key"])))]
55#[command(group(clap::ArgGroup::new("details_required").required(true).args(["details"])))]
56#[command(group(clap::ArgGroup::new("message_required").required(true).args(["message"])))]
57pub struct Args {
58 #[arg(long)]
60 pub key: Option<String>,
61 #[arg(long)]
63 pub details: Option<String>,
64 #[arg(long)]
67 pub message: Option<String>,
68 #[command(flatten)]
69 pub base: crate::cli::command::RequestBaseArgs,
70}
71
72#[derive(clap::Args)]
73#[command(args_conflicts_with_subcommands = true)]
74pub struct Command {
75 #[command(flatten)]
76 pub args: Args,
77 #[command(subcommand)]
78 pub schema: Option<Schema>,
79}
80
81#[derive(clap::Subcommand)]
82pub enum Schema {
83 RequestSchema(request_schema::Args),
85 ResponseSchema(response_schema::Args),
87}
88
89impl TryFrom<Args> for Request {
90 type Error = crate::cli::command::FromArgsError;
91 fn try_from(args: Args) -> Result<Self, Self::Error> {
92 let key = args.key.ok_or_else(|| {
93 crate::cli::command::FromArgsError::path_parse("key", "--key is required".to_string())
94 })?;
95 let details_raw = args.details.ok_or_else(|| {
96 crate::cli::command::FromArgsError::path_parse(
97 "details",
98 "--details is required".to_string(),
99 )
100 })?;
101 let mut de = serde_json::Deserializer::from_str(&details_raw);
102 let details = serde_path_to_error::deserialize(&mut de)
103 .map_err(|e| crate::cli::command::FromArgsError::json("details", e))?;
104 let message_raw = args.message.ok_or_else(|| {
105 crate::cli::command::FromArgsError::path_parse(
106 "message",
107 "--message is required".to_string(),
108 )
109 })?;
110 let mut de = serde_json::Deserializer::from_str(&message_raw);
111 let message = serde_path_to_error::deserialize(&mut de)
112 .map_err(|e| crate::cli::command::FromArgsError::json("message", e))?;
113 Ok(Self {
114 path_type: Path::ChannelsPublish,
115 key,
116 details,
117 message,
118 base: args.base.into(),
119 })
120 }
121}
122
123#[cfg(feature = "mcp")]
124impl crate::cli::command::CommandResponse for Response {
125 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
126 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
127 }
128}
129
130#[cfg(feature = "cli-executor")]
131pub async fn execute<E: crate::cli::command::CommandExecutor>(
132 executor: &E,
133 mut request: Request,
134 identity: Option<&crate::identity::Identity>,
135) -> Result<Response, E::Error> {
136 request.base.clear_transform();
137 executor.execute_one(request, identity).await
138}
139
140#[cfg(feature = "cli-executor")]
141pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
142 executor: &E,
143 mut request: Request,
144 transform: crate::cli::command::Transform,
145 identity: Option<&crate::identity::Identity>,
146) -> Result<serde_json::Value, E::Error> {
147 request.base.set_transform(transform);
148 executor.execute_one(request, identity).await
149}
150
151pub mod request_schema;
152
153pub mod response_schema;
154
155#[cfg(all(feature = "cli", feature = "daemon"))]
158pub struct ListenerExecution {
159 pub request: Request,
160 pub identity: crate::identity::Identity,
161 pub response: crate::daemon::command_listener::UnaryResponse<Response>,
162}