use crate::cli::command::CommandRequest;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.functions.list.Request")]
pub struct Request {
pub path_type: Path,
pub source: RequestSource,
pub jq: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.functions.list.Path")]
pub enum Path {
#[serde(rename = "functions/list")]
FunctionsList,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema, clap::ValueEnum)]
#[clap(rename_all = "lowercase")]
#[schemars(rename = "cli.command.functions.list.RequestSource")]
pub enum RequestSource {
Filesystem,
Favorites,
Objectiveai,
Mock,
All,
}
impl RequestSource {
fn as_str(&self) -> &'static str {
match self {
RequestSource::Filesystem => "filesystem",
RequestSource::Favorites => "favorites",
RequestSource::Objectiveai => "objectiveai",
RequestSource::Mock => "mock",
RequestSource::All => "all",
}
}
}
impl CommandRequest for Request {
fn into_command(&self) -> Vec<String> {
let mut argv = vec!["functions".to_string(), "list".to_string(), "--source".to_string(), self.source.as_str().to_string()];
if let Some(jq) = &self.jq {
argv.push("--jq".to_string());
argv.push(jq.clone());
}
argv
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.functions.list.ResponseFavorite")]
pub struct ResponseFavorite {
pub name: String,
#[serde(flatten)]
pub path: crate::RemotePathCommitOptional,
pub note: String,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.functions.list.Response")]
pub struct Response {
pub items: Vec<ResponseItem>,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
#[schemars(rename = "cli.command.functions.list.ResponseItem")]
pub enum ResponseItem {
#[schemars(title = "Favorite")]
Favorite(ResponseFavorite),
#[schemars(title = "Item")]
Item(crate::RemotePath),
}
#[derive(clap::Args)]
pub struct Args {
#[arg(long, value_enum)]
pub source: RequestSource,
#[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> {
Ok(Self { path_type: Path::FunctionsList,
source: args.source,
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 Response {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
}
}
#[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;