use crate::cli::command::CommandRequest;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.logs.subscribe.Request")]
pub struct Request {
pub path_type: Path,
pub targets: Vec<Target>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub kinds: Option<KindFilter>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub after_id: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub limit: Option<i64>,
#[serde(flatten)]
pub base: crate::cli::command::RequestBase,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.logs.subscribe.KindFilter")]
pub struct KindFilter {
pub request: bool,
pub assistant: bool,
pub tool: bool,
}
impl KindFilter {
pub fn from_flags(request: bool, assistant: bool, tool: bool) -> Option<Self> {
if request || assistant || tool {
Some(Self { request, assistant, tool })
} else {
None
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.logs.subscribe.Path")]
pub enum Path {
#[serde(rename = "agents/logs/subscribe")]
AgentsLogsSubscribe,
}
impl CommandRequest for Request {
fn request_base(&self) -> &crate::cli::command::RequestBase {
&self.base
}
fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
Some(&mut self.base)
}
}
pub use super::list::Target;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.agents.logs.subscribe.ResponseItem")]
pub enum ResponseItem {
#[schemars(title = "Item")]
Item(super::list::ResponseItem),
#[schemars(title = "AgentsInactive")]
AgentsInactive(AgentsInactiveTag),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.logs.subscribe.AgentsInactiveTag")]
pub enum AgentsInactiveTag {
#[serde(rename = "agents_inactive")]
AgentsInactive,
}
#[derive(clap::Args)]
pub struct Args {
#[arg(long = "target", required = true)]
pub targets: Vec<String>,
#[arg(long)]
pub request: bool,
#[arg(long)]
pub assistant: bool,
#[arg(long)]
pub tool: bool,
#[arg(long)]
pub after_id: Option<i64>,
#[arg(long)]
pub limit: Option<i64>,
#[command(flatten)]
pub base: crate::cli::command::RequestBaseArgs,
}
#[derive(clap::Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct Command {
#[command(flatten)]
pub args: Args,
#[command(subcommand)]
pub schema: Option<Schema>,
}
#[derive(clap::Subcommand)]
pub enum Schema {
RequestSchema(request_schema::Args),
ResponseSchema(response_schema::Args),
}
impl TryFrom<Args> for Request {
type Error = crate::cli::command::FromArgsError;
fn try_from(args: Args) -> Result<Self, Self::Error> {
let targets = args
.targets
.iter()
.map(|s| {
s.parse::<Target>().map_err(|msg| {
crate::cli::command::FromArgsError::path_parse("target", msg)
})
})
.collect::<Result<Vec<_>, _>>()?;
let kinds = KindFilter::from_flags(args.request, args.assistant, args.tool);
Ok(Self {
path_type: Path::AgentsLogsSubscribe,
targets,
kinds,
after_id: args.after_id,
limit: args.limit,
base: args.base.into(),
})
}
}
#[cfg(feature = "cli-executor")]
pub async fn execute<E: crate::cli::command::CommandExecutor>(
executor: &E,
mut request: Request,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<E::Stream<ResponseItem>, E::Error> {
request.base.clear_transform();
executor.execute(request, agent_arguments).await
}
#[cfg(feature = "cli-executor")]
pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
executor: &E,
mut request: Request,
transform: crate::cli::command::Transform,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<E::Stream<serde_json::Value>, E::Error> {
request.base.set_transform(transform);
executor.execute(request, agent_arguments).await
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for ResponseItem {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
}
}
pub mod request_schema;
pub mod response_schema;