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>,
#[serde(flatten)]
pub base: crate::cli::command::RequestBase,
}
#[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"),
);
}
self.base.push_flags(&mut argv);
argv
}
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)
}
}
#[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 = "TagActive")]
TagActive(TagActiveResponseItem),
#[schemars(title = "TagSpawned")]
TagSpawned(TagSpawnedResponseItem),
#[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.TagActiveResponseItem")]
pub struct TagActiveResponseItem {
pub r#type: TagActiveType,
pub agent_tag: String,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.TagActiveType")]
pub enum TagActiveType {
#[serde(rename = "TagActive")]
TagActive,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.TagSpawnedResponseItem")]
pub struct TagSpawnedResponseItem {
pub r#type: TagSpawnedType,
pub agent_tag: String,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.queue.deliver.TagSpawnedType")]
pub enum TagSpawnedType {
#[serde(rename = "TagSpawned")]
TagSpawned,
}
#[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>,
#[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 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,
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;