diff --git a/crates/extension_host/src/anthropic_migration.rs b/crates/extension_host/src/anthropic_migration.rs deleted file mode 100644 index 71d8cc07ac7c672eb84958b8a067c57233aae3e0..0000000000000000000000000000000000000000 --- a/crates/extension_host/src/anthropic_migration.rs +++ /dev/null @@ -1,124 +0,0 @@ -use credentials_provider::CredentialsProvider; -use gpui::App; - -const ANTHROPIC_EXTENSION_ID: &str = "anthropic"; -const ANTHROPIC_PROVIDER_ID: &str = "anthropic"; -const ANTHROPIC_DEFAULT_API_URL: &str = "https://api.anthropic.com"; - -/// Migrates Anthropic API credentials from the old built-in provider location -/// to the new extension-based location. -/// -/// This should only be called during auto-install of the extension. -pub fn migrate_anthropic_credentials_if_needed(extension_id: &str, cx: &mut App) { - if extension_id != ANTHROPIC_EXTENSION_ID { - return; - } - - let extension_credential_key = format!( - "extension-llm-{}:{}", - ANTHROPIC_EXTENSION_ID, ANTHROPIC_PROVIDER_ID - ); - - let credentials_provider = ::global(cx); - - cx.spawn(async move |cx| { - // Read from old location - let old_credential = credentials_provider - .read_credentials(ANTHROPIC_DEFAULT_API_URL, &cx) - .await - .ok() - .flatten(); - - let api_key = match old_credential { - Some((_, key_bytes)) => match String::from_utf8(key_bytes) { - Ok(key) if !key.is_empty() => key, - Ok(_) => { - log::debug!("Existing Anthropic API key is empty, nothing to migrate"); - return; - } - Err(_) => { - log::error!("Failed to decode Anthropic API key as UTF-8"); - return; - } - }, - None => { - log::debug!("No existing Anthropic API key found to migrate"); - return; - } - }; - - log::info!("Migrating existing Anthropic API key to Anthropic extension"); - - match credentials_provider - .write_credentials(&extension_credential_key, "Bearer", api_key.as_bytes(), &cx) - .await - { - Ok(()) => { - log::info!("Successfully migrated Anthropic API key to extension"); - } - Err(err) => { - log::error!("Failed to migrate Anthropic API key: {}", err); - } - } - }) - .detach(); -} - -#[cfg(test)] -mod tests { - use super::*; - use gpui::TestAppContext; - - #[gpui::test] - async fn test_migrates_credentials_from_old_location(cx: &mut TestAppContext) { - let api_key = "sk-ant-test-key-12345"; - - cx.write_credentials(ANTHROPIC_DEFAULT_API_URL, "Bearer", api_key.as_bytes()); - - cx.update(|cx| { - migrate_anthropic_credentials_if_needed(ANTHROPIC_EXTENSION_ID, cx); - }); - - cx.run_until_parked(); - - let migrated = cx.read_credentials("extension-llm-anthropic:anthropic"); - assert!(migrated.is_some(), "Credentials should have been migrated"); - let (username, password) = migrated.unwrap(); - assert_eq!(username, "Bearer"); - assert_eq!(String::from_utf8(password).unwrap(), api_key); - } - - #[gpui::test] - async fn test_no_migration_if_no_old_credentials(cx: &mut TestAppContext) { - cx.update(|cx| { - migrate_anthropic_credentials_if_needed(ANTHROPIC_EXTENSION_ID, cx); - }); - - cx.run_until_parked(); - - let credentials = cx.read_credentials("extension-llm-anthropic:anthropic"); - assert!( - credentials.is_none(), - "Should not create credentials if none existed" - ); - } - - #[gpui::test] - async fn test_skips_migration_for_other_extensions(cx: &mut TestAppContext) { - let api_key = "sk-ant-test-key"; - - cx.write_credentials(ANTHROPIC_DEFAULT_API_URL, "Bearer", api_key.as_bytes()); - - cx.update(|cx| { - migrate_anthropic_credentials_if_needed("some-other-extension", cx); - }); - - cx.run_until_parked(); - - let credentials = cx.read_credentials("extension-llm-anthropic:anthropic"); - assert!( - credentials.is_none(), - "Should not migrate for other extensions" - ); - } -} diff --git a/crates/extension_host/src/google_ai_migration.rs b/crates/extension_host/src/google_ai_migration.rs deleted file mode 100644 index 80f930ea91359b4d852c60f8f0b3d5d30ab6e372..0000000000000000000000000000000000000000 --- a/crates/extension_host/src/google_ai_migration.rs +++ /dev/null @@ -1,124 +0,0 @@ -use credentials_provider::CredentialsProvider; -use gpui::App; - -const GOOGLE_AI_EXTENSION_ID: &str = "google-ai"; -const GOOGLE_AI_PROVIDER_ID: &str = "google-ai"; -const GOOGLE_AI_DEFAULT_API_URL: &str = "https://generativelanguage.googleapis.com"; - -/// Migrates Google AI API credentials from the old built-in provider location -/// to the new extension-based location. -/// -/// This should only be called during auto-install of the extension. -pub fn migrate_google_ai_credentials_if_needed(extension_id: &str, cx: &mut App) { - if extension_id != GOOGLE_AI_EXTENSION_ID { - return; - } - - let extension_credential_key = format!( - "extension-llm-{}:{}", - GOOGLE_AI_EXTENSION_ID, GOOGLE_AI_PROVIDER_ID - ); - - let credentials_provider = ::global(cx); - - cx.spawn(async move |cx| { - // Read from old location - let old_credential = credentials_provider - .read_credentials(GOOGLE_AI_DEFAULT_API_URL, &cx) - .await - .ok() - .flatten(); - - let api_key = match old_credential { - Some((_, key_bytes)) => match String::from_utf8(key_bytes) { - Ok(key) if !key.is_empty() => key, - Ok(_) => { - log::debug!("Existing Google AI API key is empty, nothing to migrate"); - return; - } - Err(_) => { - log::error!("Failed to decode Google AI API key as UTF-8"); - return; - } - }, - None => { - log::debug!("No existing Google AI API key found to migrate"); - return; - } - }; - - log::info!("Migrating existing Google AI API key to Google AI extension"); - - match credentials_provider - .write_credentials(&extension_credential_key, "Bearer", api_key.as_bytes(), &cx) - .await - { - Ok(()) => { - log::info!("Successfully migrated Google AI API key to extension"); - } - Err(err) => { - log::error!("Failed to migrate Google AI API key: {}", err); - } - } - }) - .detach(); -} - -#[cfg(test)] -mod tests { - use super::*; - use gpui::TestAppContext; - - #[gpui::test] - async fn test_migrates_credentials_from_old_location(cx: &mut TestAppContext) { - let api_key = "AIzaSy-test-key-12345"; - - cx.write_credentials(GOOGLE_AI_DEFAULT_API_URL, "Bearer", api_key.as_bytes()); - - cx.update(|cx| { - migrate_google_ai_credentials_if_needed(GOOGLE_AI_EXTENSION_ID, cx); - }); - - cx.run_until_parked(); - - let migrated = cx.read_credentials("extension-llm-google-ai:google-ai"); - assert!(migrated.is_some(), "Credentials should have been migrated"); - let (username, password) = migrated.unwrap(); - assert_eq!(username, "Bearer"); - assert_eq!(String::from_utf8(password).unwrap(), api_key); - } - - #[gpui::test] - async fn test_no_migration_if_no_old_credentials(cx: &mut TestAppContext) { - cx.update(|cx| { - migrate_google_ai_credentials_if_needed(GOOGLE_AI_EXTENSION_ID, cx); - }); - - cx.run_until_parked(); - - let credentials = cx.read_credentials("extension-llm-google-ai:google-ai"); - assert!( - credentials.is_none(), - "Should not create credentials if none existed" - ); - } - - #[gpui::test] - async fn test_skips_migration_for_other_extensions(cx: &mut TestAppContext) { - let api_key = "AIzaSy-test-key"; - - cx.write_credentials(GOOGLE_AI_DEFAULT_API_URL, "Bearer", api_key.as_bytes()); - - cx.update(|cx| { - migrate_google_ai_credentials_if_needed("some-other-extension", cx); - }); - - cx.run_until_parked(); - - let credentials = cx.read_credentials("extension-llm-google-ai:google-ai"); - assert!( - credentials.is_none(), - "Should not migrate for other extensions" - ); - } -}