use crate::cli::command::CommandRequest;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.Request")]
pub struct Request {
pub path_type: Path,
pub dangerous_advanced: Option<RequestDangerousAdvanced>,
pub jq: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.Path")]
pub enum Path {
#[serde(rename = "agents/queue/deliver")]
AgentsQueueDeliver,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.RequestDangerousAdvanced")]
pub struct RequestDangerousAdvanced {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub stream_spawns: Option<bool>,
}
impl CommandRequest for Request {
fn into_command(&self) -> Vec<String> {
let mut argv = vec![
"agents".to_string(),
"queue".to_string(),
"deliver".to_string(),
];
if let Some(advanced) = &self.dangerous_advanced {
argv.push("--dangerous-advanced".to_string());
argv.push(
serde_json::to_string(advanced)
.expect("RequestDangerousAdvanced serializes"),
);
}
if let Some(jq) = &self.jq {
argv.push("--jq".to_string());
argv.push(jq.clone());
}
argv
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.agents.queue.deliver.ResponseItem")]
pub enum ResponseItem {
#[schemars(title = "Value")]
Value(ValueResponseItem),
#[schemars(title = "AgentActive")]
AgentActive(AgentActiveResponseItem),
#[schemars(title = "AgentSpawned")]
AgentSpawned(AgentSpawnedResponseItem),
#[schemars(title = "AllAgentsActive")]
AllAgentsActive(AllAgentsActive),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.ValueResponseItem")]
pub struct ValueResponseItem {
pub agent_instance_hierarchy: String,
#[schemars(with = "serde_json::Value")]
pub value: Box<crate::cli::command::ResponseItem>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.AgentActiveResponseItem")]
pub struct AgentActiveResponseItem {
pub r#type: AgentActiveType,
pub agent_instance_hierarchy: String,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.AgentActiveType")]
pub enum AgentActiveType {
#[serde(rename = "AgentActive")]
AgentActive,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.AgentSpawnedResponseItem")]
pub struct AgentSpawnedResponseItem {
pub r#type: AgentSpawnedType,
pub agent_instance_hierarchy: String,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.AgentSpawnedType")]
pub enum AgentSpawnedType {
#[serde(rename = "AgentSpawned")]
AgentSpawned,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.AllAgentsActive")]
pub enum AllAgentsActive {
AllAgentsActive,
}
#[derive(clap::Args)]
pub struct Args {
#[arg(long)]
pub dangerous_advanced: Option<String>,
#[arg(long)]
pub jq: Option<String>,
}
#[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 dangerous_advanced: Option<RequestDangerousAdvanced> =
if let Some(s) = args.dangerous_advanced {
let mut de = serde_json::Deserializer::from_str(&s);
let v = serde_path_to_error::deserialize(&mut de).map_err(|source| {
crate::cli::command::FromArgsError {
field: "dangerous_advanced",
source: source.into(),
}
})?;
Some(v)
} else {
None
};
Ok(Self {
path_type: Path::AgentsQueueDeliver,
dangerous_advanced,
jq: args.jq,
})
}
}
#[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.jq = None;
executor.execute(request, agent_arguments).await
}
#[cfg(feature = "cli-executor")]
pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
executor: &E,
mut request: Request,
jq: String,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<E::Stream<serde_json::Value>, E::Error> {
request.jq = Some(jq);
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;