objectiveai_sdk/cli/command/channels/logs/open/
mod.rs1use crate::cli::command::CommandRequest;
7
8pub use super::list::MessageKind;
9
10#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[schemars(rename = "cli.command.channels.logs.open.Request")]
12pub struct Request {
13 pub path_type: Path,
14 pub channel_id: String,
15 pub secret: String,
16 pub entry_id: i64,
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.logs.open.Path")]
24pub enum Path {
25 #[serde(rename = "channels/logs/open")]
26 ChannelsLogsOpen,
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, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
41#[serde(tag = "type", rename_all = "snake_case")]
42#[schemars(rename = "cli.command.channels.logs.open.Response")]
43pub enum Response {
44 #[schemars(title = "Entry")]
45 Entry {
46 id: i64,
47 timestamp: String,
48 kind: MessageKind,
49 sender_agent_instance_hierarchy: Option<String>,
51 #[serde(default, skip_serializing_if = "Option::is_none")]
53 #[schemars(extend("omitempty" = true))]
54 plugin_owner: Option<String>,
55 #[serde(default, skip_serializing_if = "Option::is_none")]
56 #[schemars(extend("omitempty" = true))]
57 plugin_name: Option<String>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 #[schemars(extend("omitempty" = true))]
60 plugin_version: Option<String>,
61 content: serde_json::Value,
62 },
63 #[schemars(title = "NotFound")]
64 NotFound,
65}
66
67#[derive(clap::Args)]
68#[command(group(clap::ArgGroup::new("channel_required").required(true).args(["id"])))]
69#[command(group(clap::ArgGroup::new("secret_required").required(true).args(["secret"])))]
70#[command(group(clap::ArgGroup::new("entry_required").required(true).args(["entry_id"])))]
71pub struct Args {
72 #[arg(long)]
74 pub id: Option<String>,
75 #[arg(long)]
77 pub secret: Option<String>,
78 #[arg(long)]
80 pub entry_id: Option<i64>,
81 #[command(flatten)]
82 pub base: crate::cli::command::RequestBaseArgs,
83}
84
85#[derive(clap::Args)]
86#[command(args_conflicts_with_subcommands = true)]
87pub struct Command {
88 #[command(flatten)]
89 pub args: Args,
90 #[command(subcommand)]
91 pub schema: Option<Schema>,
92}
93
94#[derive(clap::Subcommand)]
95pub enum Schema {
96 RequestSchema(request_schema::Args),
98 ResponseSchema(response_schema::Args),
100}
101
102impl TryFrom<Args> for Request {
103 type Error = crate::cli::command::FromArgsError;
104 fn try_from(args: Args) -> Result<Self, Self::Error> {
105 let channel_id = args.id.ok_or_else(|| {
106 crate::cli::command::FromArgsError::path_parse("id", "--id is required".to_string())
107 })?;
108 let secret = args.secret.ok_or_else(|| {
109 crate::cli::command::FromArgsError::path_parse(
110 "secret",
111 "--secret is required".to_string(),
112 )
113 })?;
114 let entry_id = args.entry_id.ok_or_else(|| {
115 crate::cli::command::FromArgsError::path_parse(
116 "entry_id",
117 "--entry-id is required".to_string(),
118 )
119 })?;
120 Ok(Self {
121 path_type: Path::ChannelsLogsOpen,
122 channel_id,
123 secret,
124 entry_id,
125 base: args.base.into(),
126 })
127 }
128}
129
130#[cfg(feature = "mcp")]
131impl crate::cli::command::CommandResponse for Response {
132 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
133 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
134 }
135}
136
137#[cfg(feature = "cli-executor")]
138pub async fn execute<E: crate::cli::command::CommandExecutor>(
139 executor: &E,
140 mut request: Request,
141 identity: Option<&crate::identity::Identity>,
142) -> Result<Response, E::Error> {
143 request.base.clear_transform();
144 executor.execute_one(request, identity).await
145}
146
147#[cfg(feature = "cli-executor")]
148pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
149 executor: &E,
150 mut request: Request,
151 transform: crate::cli::command::Transform,
152 identity: Option<&crate::identity::Identity>,
153) -> Result<serde_json::Value, E::Error> {
154 request.base.set_transform(transform);
155 executor.execute_one(request, identity).await
156}
157
158pub mod request_schema;
159
160pub mod response_schema;
161
162#[cfg(all(feature = "cli", feature = "daemon"))]
164pub struct ListenerExecution {
165 pub request: Request,
166 pub identity: crate::identity::Identity,
167 pub response: crate::daemon::command_listener::UnaryResponse<Response>,
168}