objectiveai_sdk/cli/command/channels/close/
mod.rs1use crate::cli::command::CommandRequest;
9
10#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[schemars(rename = "cli.command.channels.close.Request")]
12pub struct Request {
13 pub path_type: Path,
14 pub channel_id: String,
16 pub secret: String,
18 #[serde(flatten)]
19 pub base: crate::cli::command::RequestBase,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
23#[schemars(rename = "cli.command.channels.close.Path")]
24pub enum Path {
25 #[serde(rename = "channels/close")]
26 ChannelsClose,
27}
28
29impl CommandRequest for Request {
30 fn request_base(&self) -> &crate::cli::command::RequestBase {
31 &self.base
32 }
33
34 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
35 Some(&mut self.base)
36 }
37}
38
39#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
41#[schemars(rename = "cli.command.channels.close.Response")]
42pub struct Response {
43 pub channel_id: String,
44}
45
46#[derive(clap::Args)]
47#[command(group(clap::ArgGroup::new("channel_id_required").required(true).args(["channel_id"])))]
48#[command(group(clap::ArgGroup::new("secret_required").required(true).args(["secret"])))]
49pub struct Args {
50 #[arg(long)]
52 pub channel_id: Option<String>,
53 #[arg(long)]
55 pub secret: Option<String>,
56 #[command(flatten)]
57 pub base: crate::cli::command::RequestBaseArgs,
58}
59
60#[derive(clap::Args)]
61#[command(args_conflicts_with_subcommands = true)]
62pub struct Command {
63 #[command(flatten)]
64 pub args: Args,
65 #[command(subcommand)]
66 pub schema: Option<Schema>,
67}
68
69#[derive(clap::Subcommand)]
70pub enum Schema {
71 RequestSchema(request_schema::Args),
73 ResponseSchema(response_schema::Args),
75}
76
77impl TryFrom<Args> for Request {
78 type Error = crate::cli::command::FromArgsError;
79 fn try_from(args: Args) -> Result<Self, Self::Error> {
80 let channel_id = args.channel_id.ok_or_else(|| {
81 crate::cli::command::FromArgsError::path_parse(
82 "channel_id",
83 "--channel-id is required".to_string(),
84 )
85 })?;
86 let secret = args.secret.ok_or_else(|| {
87 crate::cli::command::FromArgsError::path_parse(
88 "secret",
89 "--secret is required".to_string(),
90 )
91 })?;
92 Ok(Self {
93 path_type: Path::ChannelsClose,
94 channel_id,
95 secret,
96 base: args.base.into(),
97 })
98 }
99}
100
101#[cfg(feature = "mcp")]
102impl crate::cli::command::CommandResponse for Response {
103 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
104 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
105 }
106}
107
108#[cfg(feature = "cli-executor")]
109pub async fn execute<E: crate::cli::command::CommandExecutor>(
110 executor: &E,
111 mut request: Request,
112 identity: Option<&crate::identity::Identity>,
113) -> Result<Response, E::Error> {
114 request.base.clear_transform();
115 executor.execute_one(request, identity).await
116}
117
118#[cfg(feature = "cli-executor")]
119pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
120 executor: &E,
121 mut request: Request,
122 transform: crate::cli::command::Transform,
123 identity: Option<&crate::identity::Identity>,
124) -> Result<serde_json::Value, E::Error> {
125 request.base.set_transform(transform);
126 executor.execute_one(request, identity).await
127}
128
129pub mod request_schema;
130
131pub mod response_schema;
132
133#[cfg(all(feature = "cli", feature = "daemon"))]
136pub struct ListenerExecution {
137 pub request: Request,
138 pub identity: crate::identity::Identity,
139 pub response: crate::daemon::command_listener::UnaryResponse<Response>,
140}