Lifei/clean up old onboarding flow (#8099)
This commit is contained in:
@@ -387,7 +387,6 @@ derive_utoipa!(Icon as IconSchema);
|
||||
super::routes::status::diagnostics,
|
||||
super::routes::mcp_ui_proxy::mcp_ui_proxy,
|
||||
super::routes::config_management::backup_config,
|
||||
super::routes::config_management::detect_provider,
|
||||
super::routes::config_management::recover_config,
|
||||
super::routes::config_management::validate_config,
|
||||
super::routes::config_management::init_config,
|
||||
@@ -484,8 +483,6 @@ derive_utoipa!(Icon as IconSchema);
|
||||
components(schemas(
|
||||
super::routes::config_management::UpsertConfigQuery,
|
||||
super::routes::config_management::ConfigKeyQuery,
|
||||
super::routes::config_management::DetectProviderRequest,
|
||||
super::routes::config_management::DetectProviderResponse,
|
||||
super::routes::config_management::ConfigResponse,
|
||||
super::routes::config_management::ProvidersResponse,
|
||||
super::routes::config_management::ProviderDetails,
|
||||
|
||||
@@ -12,7 +12,6 @@ use goose::config::paths::Paths;
|
||||
use goose::config::ExtensionEntry;
|
||||
use goose::config::{Config, ConfigError};
|
||||
use goose::model::ModelConfig;
|
||||
use goose::providers::auto_detect::detect_provider_from_api_key;
|
||||
use goose::providers::base::{ProviderMetadata, ProviderType};
|
||||
use goose::providers::canonical::maybe_get_canonical_model;
|
||||
use goose::providers::catalog::{
|
||||
@@ -149,16 +148,6 @@ pub struct SlashCommandsResponse {
|
||||
pub commands: Vec<SlashCommand>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, ToSchema)]
|
||||
pub struct DetectProviderRequest {
|
||||
pub api_key: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct DetectProviderResponse {
|
||||
pub provider_name: String,
|
||||
pub models: Vec<String>,
|
||||
}
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/config/upsert",
|
||||
@@ -534,31 +523,6 @@ pub async fn upsert_permissions(
|
||||
Ok(Json("Permissions updated successfully".to_string()))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/config/detect-provider",
|
||||
request_body = DetectProviderRequest,
|
||||
responses(
|
||||
(status = 200, description = "Provider detected successfully", body = DetectProviderResponse),
|
||||
(status = 404, description = "No matching provider found"),
|
||||
)
|
||||
)]
|
||||
pub async fn detect_provider(
|
||||
Json(detect_request): Json<DetectProviderRequest>,
|
||||
) -> Result<Json<DetectProviderResponse>, ErrorResponse> {
|
||||
let api_key = detect_request.api_key.trim();
|
||||
|
||||
match detect_provider_from_api_key(api_key).await {
|
||||
Some((provider_name, models)) => Ok(Json(DetectProviderResponse {
|
||||
provider_name,
|
||||
models,
|
||||
})),
|
||||
None => Err(ErrorResponse::not_found(
|
||||
"Could not detect provider from the provided API key",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/config/backup",
|
||||
@@ -930,7 +894,6 @@ pub fn routes(state: Arc<AppState>) -> Router {
|
||||
"/config/providers/{name}/cleanup",
|
||||
post(cleanup_provider_cache),
|
||||
)
|
||||
.route("/config/detect-provider", post(detect_provider))
|
||||
.route("/config/slash_commands", get(get_slash_commands))
|
||||
.route(
|
||||
"/config/canonical-model-info",
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
use crate::model::ModelConfig;
|
||||
use crate::providers::retry::{retry_operation, RetryConfig};
|
||||
|
||||
pub async fn detect_provider_from_api_key(api_key: &str) -> Option<(String, Vec<String>)> {
|
||||
let provider_tests = vec![
|
||||
("anthropic", "ANTHROPIC_API_KEY"),
|
||||
("openai", "OPENAI_API_KEY"),
|
||||
("google", "GOOGLE_API_KEY"),
|
||||
("groq", "GROQ_API_KEY"),
|
||||
("xai", "XAI_API_KEY"),
|
||||
// Ollama and OpenRouter don't validate keys, so they would match any input
|
||||
];
|
||||
|
||||
let tasks: Vec<_> = provider_tests
|
||||
.into_iter()
|
||||
.map(|(provider_name, env_key)| {
|
||||
let api_key = api_key.to_string();
|
||||
tokio::spawn(async move {
|
||||
let original_value = std::env::var(env_key).ok();
|
||||
std::env::set_var(env_key, &api_key);
|
||||
|
||||
let result = match crate::providers::create(
|
||||
provider_name,
|
||||
ModelConfig::new_or_fail("default").with_canonical_limits(provider_name),
|
||||
Vec::new(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(provider) => {
|
||||
match retry_operation(&RetryConfig::default(), || async {
|
||||
provider.fetch_supported_models().await
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(models) if !models.is_empty() => {
|
||||
Some((provider_name.to_string(), models))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
match original_value {
|
||||
Some(val) => std::env::set_var(env_key, val),
|
||||
None => std::env::remove_var(env_key),
|
||||
}
|
||||
|
||||
result
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
for task in tasks {
|
||||
if let Ok(Some(result)) = task.await {
|
||||
return Some(result);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod anthropic;
|
||||
pub mod api_client;
|
||||
pub mod auto_detect;
|
||||
pub mod avian;
|
||||
pub mod azure;
|
||||
pub mod azureauth;
|
||||
|
||||
Reference in New Issue
Block a user