pub mod get;
pub mod list;
pub mod me;
pub mod message;
pub mod publish;
pub mod read;
pub mod spawn;
#[derive(clap::Subcommand)]
pub enum Command {
Get(get::Command),
List {
#[command(subcommand)]
command: list::Command,
},
Me(me::Command),
Message(message::Command),
Publish(publish::Command),
Read {
#[command(subcommand)]
command: read::Command,
},
Spawn(spawn::Command),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.agents.Request")]
pub enum Request {
#[schemars(title = "Get")]
Get(get::Request),
#[schemars(title = "GetRequestSchema")]
GetRequestSchema(get::request_schema::Request),
#[schemars(title = "GetResponseSchema")]
GetResponseSchema(get::response_schema::Request),
#[schemars(title = "List")]
List(list::Request),
#[schemars(title = "Me")]
Me(me::Request),
#[schemars(title = "MeRequestSchema")]
MeRequestSchema(me::request_schema::Request),
#[schemars(title = "MeResponseSchema")]
MeResponseSchema(me::response_schema::Request),
#[schemars(title = "Message")]
Message(message::Request),
#[schemars(title = "MessageRequestSchema")]
MessageRequestSchema(message::request_schema::Request),
#[schemars(title = "MessageResponseSchema")]
MessageResponseSchema(message::response_schema::Request),
#[schemars(title = "Publish")]
Publish(publish::Request),
#[schemars(title = "PublishRequestSchema")]
PublishRequestSchema(publish::request_schema::Request),
#[schemars(title = "PublishResponseSchema")]
PublishResponseSchema(publish::response_schema::Request),
#[schemars(title = "Read")]
Read(read::Request),
#[schemars(title = "Spawn")]
Spawn(spawn::Request),
#[schemars(title = "SpawnRequestSchema")]
SpawnRequestSchema(spawn::request_schema::Request),
#[schemars(title = "SpawnResponseSchema")]
SpawnResponseSchema(spawn::response_schema::Request),
}
#[objectiveai_sdk_macros::json_schema_ignore]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.agents.ResponseItem")]
#[serde(untagged)]
pub enum ResponseItem {
#[schemars(title = "Get")]
Get(get::Response),
#[schemars(title = "GetRequestSchema")]
GetRequestSchema(get::request_schema::Response),
#[schemars(title = "GetResponseSchema")]
GetResponseSchema(get::response_schema::Response),
#[schemars(title = "List")]
List(list::ResponseItem),
#[schemars(title = "Me")]
Me(me::Response),
#[schemars(title = "MeRequestSchema")]
MeRequestSchema(me::request_schema::Response),
#[schemars(title = "MeResponseSchema")]
MeResponseSchema(me::response_schema::Response),
#[schemars(title = "Message")]
Message(message::Response),
#[schemars(title = "MessageRequestSchema")]
MessageRequestSchema(message::request_schema::Response),
#[schemars(title = "MessageResponseSchema")]
MessageResponseSchema(message::response_schema::Response),
#[schemars(title = "Publish")]
Publish(publish::Response),
#[schemars(title = "PublishRequestSchema")]
PublishRequestSchema(publish::request_schema::Response),
#[schemars(title = "PublishResponseSchema")]
PublishResponseSchema(publish::response_schema::Response),
#[schemars(title = "Read")]
Read(read::ResponseItem),
#[schemars(title = "Spawn")]
Spawn(spawn::ResponseItem),
#[schemars(title = "SpawnRequestSchema")]
SpawnRequestSchema(spawn::request_schema::Response),
#[schemars(title = "SpawnResponseSchema")]
SpawnResponseSchema(spawn::response_schema::Response),
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for ResponseItem {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
match self {
ResponseItem::Get(v) => v.into_mcp(),
ResponseItem::GetRequestSchema(v) => v.into_mcp(),
ResponseItem::GetResponseSchema(v) => v.into_mcp(),
ResponseItem::List(v) => v.into_mcp(),
ResponseItem::Me(v) => v.into_mcp(),
ResponseItem::MeRequestSchema(v) => v.into_mcp(),
ResponseItem::MeResponseSchema(v) => v.into_mcp(),
ResponseItem::Message(v) => v.into_mcp(),
ResponseItem::MessageRequestSchema(v) => v.into_mcp(),
ResponseItem::MessageResponseSchema(v) => v.into_mcp(),
ResponseItem::Publish(v) => v.into_mcp(),
ResponseItem::PublishRequestSchema(v) => v.into_mcp(),
ResponseItem::PublishResponseSchema(v) => v.into_mcp(),
ResponseItem::Read(v) => v.into_mcp(),
ResponseItem::Spawn(v) => v.into_mcp(),
ResponseItem::SpawnRequestSchema(v) => v.into_mcp(),
ResponseItem::SpawnResponseSchema(v) => v.into_mcp(),
}
}
}
impl TryFrom<Command> for Request {
type Error = crate::cli::command::FromArgsError;
fn try_from(command: Command) -> Result<Self, Self::Error> {
match command {
Command::Get(cmd) => match cmd.schema {
None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
Some(get::Schema::RequestSchema(args)) =>
Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
Some(get::Schema::ResponseSchema(args)) =>
Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
},
Command::List { command } =>
Ok(Request::List(list::Request::try_from(command)?)),
Command::Me(cmd) => match cmd.schema {
None => Ok(Request::Me(me::Request::try_from(cmd.args)?)),
Some(me::Schema::RequestSchema(args)) =>
Ok(Request::MeRequestSchema(me::request_schema::Request::try_from(args)?)),
Some(me::Schema::ResponseSchema(args)) =>
Ok(Request::MeResponseSchema(me::response_schema::Request::try_from(args)?)),
},
Command::Message(cmd) => match cmd.schema {
None => Ok(Request::Message(message::Request::try_from(cmd.args)?)),
Some(message::Schema::RequestSchema(args)) =>
Ok(Request::MessageRequestSchema(message::request_schema::Request::try_from(args)?)),
Some(message::Schema::ResponseSchema(args)) =>
Ok(Request::MessageResponseSchema(message::response_schema::Request::try_from(args)?)),
},
Command::Publish(cmd) => match cmd.schema {
None => Ok(Request::Publish(publish::Request::try_from(cmd.args)?)),
Some(publish::Schema::RequestSchema(args)) =>
Ok(Request::PublishRequestSchema(publish::request_schema::Request::try_from(args)?)),
Some(publish::Schema::ResponseSchema(args)) =>
Ok(Request::PublishResponseSchema(publish::response_schema::Request::try_from(args)?)),
},
Command::Read { command } =>
Ok(Request::Read(read::Request::try_from(command)?)),
Command::Spawn(cmd) => match cmd.schema {
None => Ok(Request::Spawn(spawn::Request::try_from(cmd.args)?)),
Some(spawn::Schema::RequestSchema(args)) =>
Ok(Request::SpawnRequestSchema(spawn::request_schema::Request::try_from(args)?)),
Some(spawn::Schema::ResponseSchema(args)) =>
Ok(Request::SpawnResponseSchema(spawn::response_schema::Request::try_from(args)?)),
},
}
}
}
impl crate::cli::command::CommandRequest for Request {
fn into_command(&self) -> Vec<String> {
match self {
Request::Get(inner) => inner.into_command(),
Request::GetRequestSchema(inner) => inner.into_command(),
Request::GetResponseSchema(inner) => inner.into_command(),
Request::List(inner) => inner.into_command(),
Request::Me(inner) => inner.into_command(),
Request::MeRequestSchema(inner) => inner.into_command(),
Request::MeResponseSchema(inner) => inner.into_command(),
Request::Message(inner) => inner.into_command(),
Request::MessageRequestSchema(inner) => inner.into_command(),
Request::MessageResponseSchema(inner) => inner.into_command(),
Request::Publish(inner) => inner.into_command(),
Request::PublishRequestSchema(inner) => inner.into_command(),
Request::PublishResponseSchema(inner) => inner.into_command(),
Request::Read(inner) => inner.into_command(),
Request::Spawn(inner) => inner.into_command(),
Request::SpawnRequestSchema(inner) => inner.into_command(),
Request::SpawnResponseSchema(inner) => inner.into_command(),
}
}
}
#[cfg(feature = "cli-executor")]
pub async fn execute<E: crate::cli::command::CommandExecutor>(
executor: &E,
request: Request,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<
std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
E::Error,
> {
use futures::StreamExt;
let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>> =
match request {
Request::Get(req) => {
let value = get::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::Get(value),
)))
}
Request::GetRequestSchema(req) => {
let value = get::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::GetRequestSchema(value),
)))
}
Request::GetResponseSchema(req) => {
let value = get::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::GetResponseSchema(value),
)))
}
Request::List(req) => {
let inner = list::execute(executor, req, agent_arguments).await?;
Box::pin(inner.map(|r| r.map(ResponseItem::List)))
}
Request::Me(req) => {
let value = me::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::Me(value),
)))
}
Request::MeRequestSchema(req) => {
let value = me::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::MeRequestSchema(value),
)))
}
Request::MeResponseSchema(req) => {
let value = me::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::MeResponseSchema(value),
)))
}
Request::Message(req) => {
let value = message::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::Message(value),
)))
}
Request::MessageRequestSchema(req) => {
let value = message::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::MessageRequestSchema(value),
)))
}
Request::MessageResponseSchema(req) => {
let value = message::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::MessageResponseSchema(value),
)))
}
Request::Publish(req) => {
let value = publish::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::Publish(value),
)))
}
Request::PublishRequestSchema(req) => {
let value = publish::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::PublishRequestSchema(value),
)))
}
Request::PublishResponseSchema(req) => {
let value = publish::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::PublishResponseSchema(value),
)))
}
Request::Read(req) => {
let inner = read::execute(executor, req, agent_arguments).await?;
Box::pin(inner.map(|r| r.map(ResponseItem::Read)))
}
Request::Spawn(req) => {
let want_streaming = req
.dangerous_advanced
.as_ref()
.and_then(|a| a.stream)
.unwrap_or(false);
if want_streaming {
let inner = spawn::execute_streaming(executor, req, agent_arguments).await?;
Box::pin(inner.map(|r| r.map(ResponseItem::Spawn)))
} else {
let value = spawn::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::Spawn(spawn::ResponseItem::Id(value)),
)))
}
}
Request::SpawnRequestSchema(req) => {
let value = spawn::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::SpawnRequestSchema(value),
)))
}
Request::SpawnResponseSchema(req) => {
let value = spawn::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
ResponseItem::SpawnResponseSchema(value),
)))
}
};
Ok(stream)
}
#[cfg(feature = "cli-executor")]
pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
executor: &E,
request: Request,
jq: String,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<
std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
E::Error,
> {
let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
match request {
Request::Get(req) => {
let value = get::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::GetRequestSchema(req) => {
let value = get::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::GetResponseSchema(req) => {
let value = get::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::List(req) => {
let inner = list::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(inner)
}
Request::Me(req) => {
let value = me::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::MeRequestSchema(req) => {
let value = me::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::MeResponseSchema(req) => {
let value = me::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::Message(req) => {
let value = message::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::MessageRequestSchema(req) => {
let value = message::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::MessageResponseSchema(req) => {
let value = message::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::Publish(req) => {
let value = publish::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::PublishRequestSchema(req) => {
let value = publish::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::PublishResponseSchema(req) => {
let value = publish::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::Read(req) => {
let inner = read::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(inner)
}
Request::Spawn(req) => {
let want_streaming = req
.dangerous_advanced
.as_ref()
.and_then(|a| a.stream)
.unwrap_or(false);
if want_streaming {
let inner = spawn::execute_streaming_jq(executor, req, jq, agent_arguments).await?;
Box::pin(inner)
} else {
let value = spawn::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
}
Request::SpawnRequestSchema(req) => {
let value = spawn::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::SpawnResponseSchema(req) => {
let value = spawn::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
};
Ok(stream)
}