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