pub mod addresses;
pub mod local;
#[derive(clap::Subcommand)]
pub enum Command {
Addresses {
#[command(subcommand)]
command: addresses::Command,
},
Local {
#[command(subcommand)]
command: local::Command,
},
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.laboratories.config.Request")]
pub enum Request {
#[schemars(title = "Addresses")]
Addresses(addresses::Request),
#[schemars(title = "Local")]
Local(local::Request),
}
#[objectiveai_sdk_macros::json_schema_ignore]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.laboratories.config.Response")]
#[serde(untagged)]
pub enum Response {
#[schemars(title = "Addresses")]
Addresses(addresses::Response),
#[schemars(title = "Local")]
Local(local::Response),
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for Response {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
match self {
Response::Addresses(v) => v.into_mcp(),
Response::Local(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::Addresses { command } => {
Ok(Request::Addresses(addresses::Request::try_from(command)?))
}
Command::Local { command } => {
Ok(Request::Local(local::Request::try_from(command)?))
}
}
}
}
impl crate::cli::command::CommandRequest for Request {
fn request_base(&self) -> &crate::cli::command::RequestBase {
match self {
Request::Addresses(inner) => inner.request_base(),
Request::Local(inner) => inner.request_base(),
}
}
fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
match self {
Request::Addresses(inner) => inner.request_base_mut(),
Request::Local(inner) => inner.request_base_mut(),
}
}
}
#[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<Response, E::Error>> + Send>>,
E::Error,
> {
use futures::StreamExt;
let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
match request {
Request::Addresses(req) => {
let inner = addresses::execute(executor, req, agent_arguments).await?;
Box::pin(inner.map(|r| r.map(Response::Addresses)))
}
Request::Local(req) => {
let inner = local::execute(executor, req, agent_arguments).await?;
Box::pin(inner.map(|r| r.map(Response::Local)))
}
};
Ok(stream)
}
#[cfg(feature = "cli-executor")]
pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
executor: &E,
request: Request,
transform: crate::cli::command::Transform,
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::Addresses(req) => {
let inner = addresses::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(inner)
}
Request::Local(req) => {
let inner = local::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(inner)
}
};
Ok(stream)
}
#[cfg(feature = "cli-listener")]
pub enum ListenerExecution {
Addresses(addresses::ListenerExecution),
Local(local::ListenerExecution),
}