Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
genai = "0.4"
base64 = "0.22"
rand = "0.8"
sha2 = "0.10"
spinoff = { version = "0.8.0", features = ["dots"] }
thiserror = "1.0"
indoc = "2.0.5"
Expand All @@ -41,6 +44,7 @@ tree-sitter-bash = "0.23"
once_cell = "1.20"
arboard = "3.4"
inquire = "0.7"
open = "5"

[profile.release]
lto = true
34 changes: 30 additions & 4 deletions src/command/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct ProviderOption {
id: &'static str,
display_name: &'static str,
env_var: &'static str,
needs_api_key: bool,
}

impl fmt::Display for ProviderOption {
Expand All @@ -22,46 +23,61 @@ const PROVIDERS: &[ProviderOption] = &[
id: "openai",
display_name: "OpenAI",
env_var: "OPENAI_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "groq",
display_name: "Groq",
env_var: "GROQ_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "claude",
display_name: "Claude (Anthropic)",
env_var: "ANTHROPIC_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "ollama",
display_name: "Ollama (local)",
env_var: "",
needs_api_key: false,
},
ProviderOption {
id: "openrouter",
display_name: "OpenRouter",
env_var: "OPENROUTER_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "deepseek",
display_name: "DeepSeek",
env_var: "DEEPSEEK_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "gemini",
display_name: "Gemini (Google)",
env_var: "GEMINI_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "xai",
display_name: "xAI (Grok)",
env_var: "XAI_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "vercel",
display_name: "Vercel AI Gateway",
env_var: "VERCEL_API_KEY",
needs_api_key: true,
},
ProviderOption {
id: "qwen",
display_name: "Qwen (OAuth)",
env_var: "",
needs_api_key: false,
},
];

Expand Down Expand Up @@ -97,10 +113,16 @@ impl ConfigureCommand {
}

fn get_api_key(provider: &ProviderOption) -> Result<Option<String>, LumenError> {
if provider.env_var.is_empty() {
println!(
"\n \x1b[2mOllama runs locally — no API key needed.\x1b[0m"
);
if !provider.needs_api_key {
if provider.id == "qwen" {
println!(
"\n \x1b[2mQwen OAuth will open a browser on first use to authorize your account.\x1b[0m"
);
} else {
println!(
"\n \x1b[2mOllama runs locally — no API key needed.\x1b[0m"
);
}
return Ok(None);
}

Expand Down Expand Up @@ -146,6 +168,10 @@ impl ConfigureCommand {

if let Some(key) = api_key {
config["api_key"] = json!(key);
} else if provider.id == "qwen" {
if let Some(obj) = config.as_object_mut() {
obj.remove("api_key");
}
}

let content = serde_json::to_string_pretty(&config)?;
Expand Down
6 changes: 4 additions & 2 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ impl LumenCommand {
pub async fn execute(&self, command_type: CommandType) -> Result<(), LumenError> {
match command_type {
CommandType::Explain { git_entity, query } => {
ExplainCommand { git_entity, query }.execute(&self.provider).await
ExplainCommand { git_entity, query }
.execute(&self.provider)
.await
}
CommandType::List => ListCommand.execute(&self.provider).await,
CommandType::Draft(context, draft_config) => {
DraftCommand {
git_entity: GitEntity::Diff(Diff::from_working_tree(true)?),
git_entity: GitEntity::Diff(Diff::from_working_tree(false)?),
draft_config,
context,
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum ProviderType {
Gemini,
Xai,
Vercel,
Qwen,
}

impl FromStr for ProviderType {
Expand All @@ -52,6 +53,7 @@ impl FromStr for ProviderType {
"gemini" => Ok(ProviderType::Gemini),
"xai" => Ok(ProviderType::Xai),
"vercel" => Ok(ProviderType::Vercel),
"qwen" => Ok(ProviderType::Qwen),
_ => Err(format!("Unknown provider: {}", s)),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod diff_ui;
mod error;
mod git_entity;
mod provider;
mod qwen_oauth;

#[tokio::main]
async fn main() {
Expand Down
Loading