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
2 changes: 1 addition & 1 deletion interface/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ export const api = {
return response.json() as Promise<Types.ProviderUpdateResponse>;
},
testProviderModel: async (provider: string, apiKey: string, model: string) => {
const response = await fetch(`${getApiBase()}/providers/test`, {
const response = await fetch(`${getApiBase()}/providers/test-model`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ provider, api_key: apiKey, model }),
Expand Down
48 changes: 46 additions & 2 deletions src/api/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ fn build_test_llm_config(provider: &str, credential: &str) -> crate::config::Llm
let mut providers = HashMap::new();
if let Some(provider_config) = crate::config::default_provider_config(provider, credential) {
providers.insert(provider.to_string(), provider_config);
} else if provider == "github-copilot" {
// GitHub Copilot uses token exchange, so default_provider_config returns None.
// For testing, add a provider entry with the PAT as the api_key —
// LlmManager::get_copilot_token() will exchange it for a real Copilot token.
providers.insert(
provider.to_string(),
crate::config::ProviderConfig {
api_type: crate::config::ApiType::OpenAiChatCompletions,
base_url: crate::config::GITHUB_COPILOT_DEFAULT_BASE_URL.to_string(),
api_key: credential.to_string(),
name: Some("GitHub Copilot".to_string()),
use_bearer_auth: true,
extra_headers: vec![],
},
);
}

crate::config::LlmConfig {
Expand Down Expand Up @@ -431,6 +446,15 @@ pub(super) async fn get_providers(
env_set(env_var)
};

// Copilot: only check TOML key, not env var. The env var GITHUB_COPILOT_API_KEY
// is a fallback for config loading but shouldn't keep the provider visible in
// the settings UI after a remove — the env var can't be unset from the process.
let copilot_configured = doc
.get("llm")
.and_then(|llm| llm.get("github_copilot_key"))
.and_then(|val| val.as_str())
.is_some_and(|s| resolve_value(s).is_some());

(
has_value("anthropic_key", "ANTHROPIC_API_KEY"),
has_value("openai_key", "OPENAI_API_KEY"),
Expand All @@ -454,7 +478,7 @@ pub(super) async fn get_providers(
has_value("minimax_cn_key", "MINIMAX_CN_API_KEY"),
has_value("moonshot_key", "MOONSHOT_API_KEY"),
has_value("zai_coding_plan_key", "ZAI_CODING_PLAN_API_KEY"),
has_value("github_copilot_key", "GITHUB_COPILOT_API_KEY"),
copilot_configured,
)
} else {
(
Expand Down Expand Up @@ -794,7 +818,7 @@ pub(super) async fn openai_browser_oauth_status(
}

#[utoipa::path(
post,
put,
path = "/providers",
request_body = ProviderUpdateRequest,
responses(
Expand Down Expand Up @@ -1083,4 +1107,24 @@ mod tests {
assert_eq!(provider.base_url, "http://remote-ollama.local:11434");
assert_eq!(provider.api_key, "");
}

#[test]
fn build_test_llm_config_registers_github_copilot_provider() {
let config = build_test_llm_config("github-copilot", "ghp_test_pat_token");
let provider = config
.providers
.get("github-copilot")
.expect("github-copilot provider should be registered");

assert_eq!(
provider.base_url,
crate::config::GITHUB_COPILOT_DEFAULT_BASE_URL
);
assert_eq!(provider.api_key, "ghp_test_pat_token");
assert!(provider.use_bearer_auth);
assert_eq!(
config.github_copilot_key.as_deref(),
Some("ghp_test_pat_token")
);
}
}
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub use permissions::{
DiscordPermissions, MattermostPermissions, SignalPermissions, SlackPermissions,
TelegramPermissions, TwitchPermissions,
};
pub(crate) use providers::GITHUB_COPILOT_DEFAULT_BASE_URL;
pub(crate) use providers::default_provider_config;
pub use runtime::RuntimeConfig;
pub use types::*;
Expand Down
2 changes: 1 addition & 1 deletion src/config/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(super) const NVIDIA_PROVIDER_BASE_URL: &str = "https://integrate.api.nvidia.
pub(super) const FIREWORKS_PROVIDER_BASE_URL: &str = "https://api.fireworks.ai/inference";
pub(crate) const GEMINI_PROVIDER_BASE_URL: &str =
"https://generativelanguage.googleapis.com/v1beta/openai";
pub(super) const GITHUB_COPILOT_DEFAULT_BASE_URL: &str = "https://api.individual.githubcopilot.com";
pub(crate) const GITHUB_COPILOT_DEFAULT_BASE_URL: &str = "https://api.individual.githubcopilot.com";

/// App attribution headers sent with every OpenRouter API request.
/// See <https://openrouter.ai/docs/app-attribution>.
Expand Down
Loading