pub mod get;
pub mod set;
#[derive(clap::Subcommand)]
pub enum Command {
Get(get::Command),
Set(set::Command),
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.api.config.github_authorization.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 = "Set")]
Set(set::Request),
#[schemars(title = "SetRequestSchema")]
SetRequestSchema(set::request_schema::Request),
#[schemars(title = "SetResponseSchema")]
SetResponseSchema(set::response_schema::Request),
}
#[objectiveai_sdk_macros::json_schema_ignore]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.api.config.github_authorization.Response")]
#[serde(untagged)]
pub enum Response {
#[schemars(title = "Get")]
Get(get::Response),
#[schemars(title = "GetRequestSchema")]
GetRequestSchema(get::request_schema::Response),
#[schemars(title = "GetResponseSchema")]
GetResponseSchema(get::response_schema::Response),
#[schemars(title = "Set")]
Set(set::Response),
#[schemars(title = "SetRequestSchema")]
SetRequestSchema(set::request_schema::Response),
#[schemars(title = "SetResponseSchema")]
SetResponseSchema(set::response_schema::Response),
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for Response {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
match self {
Response::Get(v) => v.into_mcp(),
Response::GetRequestSchema(v) => v.into_mcp(),
Response::GetResponseSchema(v) => v.into_mcp(),
Response::Set(v) => v.into_mcp(),
Response::SetRequestSchema(v) => v.into_mcp(),
Response::SetResponseSchema(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::Set(cmd) => match cmd.schema {
None => Ok(Request::Set(set::Request::try_from(cmd.args)?)),
Some(set::Schema::RequestSchema(args)) =>
Ok(Request::SetRequestSchema(set::request_schema::Request::try_from(args)?)),
Some(set::Schema::ResponseSchema(args)) =>
Ok(Request::SetResponseSchema(set::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::Set(inner) => inner.into_command(),
Request::SetRequestSchema(inner) => inner.into_command(),
Request::SetResponseSchema(inner) => inner.into_command(),
}
}
fn request_base(&self) -> &crate::cli::command::RequestBase {
match self {
Request::Get(inner) => inner.request_base(),
Request::GetRequestSchema(inner) => inner.request_base(),
Request::GetResponseSchema(inner) => inner.request_base(),
Request::Set(inner) => inner.request_base(),
Request::SetRequestSchema(inner) => inner.request_base(),
Request::SetResponseSchema(inner) => inner.request_base(),
}
}
fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
match self {
Request::Get(inner) => inner.request_base_mut(),
Request::GetRequestSchema(inner) => inner.request_base_mut(),
Request::GetResponseSchema(inner) => inner.request_base_mut(),
Request::Set(inner) => inner.request_base_mut(),
Request::SetRequestSchema(inner) => inner.request_base_mut(),
Request::SetResponseSchema(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::Get(req) => {
let value = get::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::Get(value),
)))
}
Request::GetRequestSchema(req) => {
let value = get::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::GetRequestSchema(value),
)))
}
Request::GetResponseSchema(req) => {
let value = get::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::GetResponseSchema(value),
)))
}
Request::Set(req) => {
let value = set::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::Set(value),
)))
}
Request::SetRequestSchema(req) => {
let value = set::request_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::SetRequestSchema(value),
)))
}
Request::SetResponseSchema(req) => {
let value = set::response_schema::execute(executor, req, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(
Response::SetResponseSchema(value),
)))
}
};
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::Get(req) => {
let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::GetRequestSchema(req) => {
let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::GetResponseSchema(req) => {
let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::Set(req) => {
let value = set::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::SetRequestSchema(req) => {
let value = set::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
Request::SetResponseSchema(req) => {
let value = set::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
}
};
Ok(stream)
}