objectiveai_sdk/cli/command/agents/logs/subscribe/
mod.rs1use crate::cli::command::CommandRequest;
16
17#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
18#[schemars(rename = "cli.command.agents.logs.subscribe.Request")]
19pub struct Request {
20 pub path_type: Path,
21 pub targets: Vec<Target>,
22 #[serde(default, skip_serializing_if = "Option::is_none")]
25 #[schemars(extend("omitempty" = true))]
26 pub kinds: Option<KindFilter>,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
29 #[schemars(extend("omitempty" = true))]
30 pub after_id: Option<i64>,
31 #[serde(default, skip_serializing_if = "Option::is_none")]
33 #[schemars(extend("omitempty" = true))]
34 pub limit: Option<i64>,
35 #[serde(flatten)]
36 pub base: crate::cli::command::RequestBase,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
43#[schemars(rename = "cli.command.agents.logs.subscribe.KindFilter")]
44pub struct KindFilter {
45 pub request: bool,
53 pub assistant: bool,
56 pub tool: bool,
59}
60
61impl KindFilter {
62 pub fn from_flags(request: bool, assistant: bool, tool: bool) -> Option<Self> {
65 if request || assistant || tool {
66 Some(Self { request, assistant, tool })
67 } else {
68 None
69 }
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
74#[schemars(rename = "cli.command.agents.logs.subscribe.Path")]
75pub enum Path {
76 #[serde(rename = "agents/logs/subscribe")]
77 AgentsLogsSubscribe,
78}
79
80impl CommandRequest for Request {
81 fn request_base(&self) -> &crate::cli::command::RequestBase {
82 &self.base
83 }
84
85 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
86 Some(&mut self.base)
87 }
88}
89
90pub use super::list::Target;
94
95#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
101#[serde(untagged)]
102#[schemars(rename = "cli.command.agents.logs.subscribe.ResponseItem")]
103pub enum ResponseItem {
104 #[schemars(title = "Item")]
105 Item(super::list::ResponseItem),
106 #[schemars(title = "AgentsInactive")]
107 AgentsInactive(AgentsInactiveTag),
108}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
115#[schemars(rename = "cli.command.agents.logs.subscribe.AgentsInactiveTag")]
116pub enum AgentsInactiveTag {
117 #[serde(rename = "agents_inactive")]
118 AgentsInactive,
119}
120
121#[derive(clap::Args)]
122pub struct Args {
123 #[arg(long = "target", required = true)]
129 pub targets: Vec<String>,
130 #[arg(long)]
133 pub request: bool,
134 #[arg(long)]
136 pub assistant: bool,
137 #[arg(long)]
139 pub tool: bool,
140 #[arg(long)]
142 pub after_id: Option<i64>,
143 #[arg(long)]
145 pub limit: Option<i64>,
146 #[command(flatten)]
147 pub base: crate::cli::command::RequestBaseArgs,
148}
149
150#[derive(clap::Args)]
151#[command(args_conflicts_with_subcommands = true)]
152pub struct Command {
153 #[command(flatten)]
154 pub args: Args,
155 #[command(subcommand)]
156 pub schema: Option<Schema>,
157}
158
159#[derive(clap::Subcommand)]
160pub enum Schema {
161 RequestSchema(request_schema::Args),
163 ResponseSchema(response_schema::Args),
165}
166
167impl TryFrom<Args> for Request {
168 type Error = crate::cli::command::FromArgsError;
169 fn try_from(args: Args) -> Result<Self, Self::Error> {
170 let targets = args
171 .targets
172 .iter()
173 .map(|s| {
174 s.parse::<Target>().map_err(|msg| {
175 crate::cli::command::FromArgsError::path_parse("target", msg)
176 })
177 })
178 .collect::<Result<Vec<_>, _>>()?;
179 let kinds = KindFilter::from_flags(args.request, args.assistant, args.tool);
180 Ok(Self {
181 path_type: Path::AgentsLogsSubscribe,
182 targets,
183 kinds,
184 after_id: args.after_id,
185 limit: args.limit,
186 base: args.base.into(),
187 })
188 }
189}
190
191#[cfg(feature = "cli-executor")]
192pub async fn execute<E: crate::cli::command::CommandExecutor>(
193 executor: &E,
194 mut request: Request,
195
196 agent_arguments: Option<&crate::cli::command::AgentArguments>,
197 ) -> Result<E::Stream<ResponseItem>, E::Error> {
198 request.base.clear_transform();
199 executor.execute(request, agent_arguments).await
200}
201
202#[cfg(feature = "cli-executor")]
203pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
204 executor: &E,
205 mut request: Request,
206 transform: crate::cli::command::Transform,
207
208 agent_arguments: Option<&crate::cli::command::AgentArguments>,
209 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
210 request.base.set_transform(transform);
211 executor.execute(request, agent_arguments).await
212}
213
214#[cfg(feature = "mcp")]
215impl crate::cli::command::CommandResponse for ResponseItem {
216 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
217 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
218 }
219}
220
221pub mod request_schema;
222
223
224pub mod response_schema;