pub mod commands;
use clap::Parser;
#[derive(Parser, Debug)]
#[clap(author = "Orual", version, about = "Letta REST API client")]
pub struct Args {
#[arg(
short = 'u',
long,
env = "LETTA_BASE_URL",
default_value = "http://localhost:8283"
)]
pub base_url: String,
#[arg(short = 'k', long, env = "LETTA_API_KEY")]
pub api_key: Option<String>,
#[arg(short = 'v', long)]
pub verbose: bool,
#[command(subcommand)]
pub command: Command,
}
#[derive(Parser, Debug)]
pub enum Command {
#[command(subcommand)]
Agent(commands::agent::AgentCommand),
#[command(subcommand)]
Message(commands::message::MessageCommand),
#[command(subcommand)]
Memory(commands::memory::MemoryCommand),
#[command(subcommand)]
Tools(commands::tools::ToolsCommand),
#[command(subcommand)]
Sources(commands::sources::SourcesCommand),
Health,
}
pub async fn run() -> miette::Result<()> {
miette::set_hook(Box::new(|_| {
Box::new(
miette::MietteHandlerOpts::new()
.terminal_links(true)
.unicode(true)
.context_lines(3)
.tab_width(4)
.build(),
)
}))?;
miette::set_panic_hook();
let args = Args::parse();
if args.verbose {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
}
let mut config = crate::ClientConfig::new(&args.base_url)?;
if let Some(api_key) = args.api_key {
config = config.auth(crate::auth::AuthConfig::bearer(api_key));
}
let client = crate::LettaClient::new(config)?;
match args.command {
Command::Agent(agent_cmd) => commands::agent::handle(agent_cmd, &client).await?,
Command::Message(message_cmd) => commands::message::handle(message_cmd, &client).await?,
Command::Memory(memory_cmd) => commands::memory::handle(memory_cmd, &client).await?,
Command::Tools(tools_cmd) => commands::tools::handle(tools_cmd, &client).await?,
Command::Sources(sources_cmd) => commands::sources::handle(sources_cmd, &client).await?,
Command::Health => {
println!("Checking health...");
commands::check_health(&client).await?;
}
}
Ok(())
}