From d4487755bf8ce89c49d5505608d4bb2bf5fdf488 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 24 Nov 2025 22:40:04 +0800 Subject: [PATCH] feat(backend): add unified deeplink import command Add a new unified command handler for importing all resource types via deeplinks, replacing the legacy provider-only import command. Changes: - Add import_from_deeplink_unified command supporting all resource types - Keep import_from_deeplink for backward compatibility (now marked legacy) - Route imports based on request.resource field (provider/prompt/mcp/skill) - Return typed ImportResult with resource-specific data Return types: - Provider: { type: "provider", id: string } - Prompt: { type: "prompt", id: string } - MCP: { type: "mcp", importedCount, importedIds, failed } - Skill: { type: "skill", key: string } The unified handler simplifies frontend logic by providing consistent return types and error handling across all resource types. --- src-tauri/src/commands/deeplink.rs | 58 +++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands/deeplink.rs b/src-tauri/src/commands/deeplink.rs index 755f773b9..0ef03e41e 100644 --- a/src-tauri/src/commands/deeplink.rs +++ b/src-tauri/src/commands/deeplink.rs @@ -1,4 +1,7 @@ -use crate::deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest}; +use crate::deeplink::{ + import_mcp_from_deeplink, import_prompt_from_deeplink, import_provider_from_deeplink, + import_skill_from_deeplink, parse_deeplink_url, DeepLinkImportRequest, +}; use crate::store::AppState; use tauri::State; @@ -15,18 +18,18 @@ pub fn parse_deeplink(url: String) -> Result { pub fn merge_deeplink_config( request: DeepLinkImportRequest, ) -> Result { - log::info!("Merging config for deep link request: {}", request.name); + log::info!("Merging config for deep link request: {:?}", request.name); crate::deeplink::parse_and_merge_config(&request).map_err(|e| e.to_string()) } -/// Import a provider from a deep link request (after user confirmation) +/// Import a provider from a deep link request (legacy, kept for compatibility) #[tauri::command] pub fn import_from_deeplink( state: State, request: DeepLinkImportRequest, ) -> Result { log::info!( - "Importing provider from deep link: {} for app {}", + "Importing provider from deep link: {:?} for app {:?}", request.name, request.app ); @@ -37,3 +40,50 @@ pub fn import_from_deeplink( Ok(provider_id) } + +/// Import resource from a deep link request (unified handler) +#[tauri::command] +pub async fn import_from_deeplink_unified( + state: State<'_, AppState>, + request: DeepLinkImportRequest, +) -> Result { + log::info!("Importing {} resource from deep link", request.resource); + + match request.resource.as_str() { + "provider" => { + let provider_id = + import_provider_from_deeplink(&state, request).map_err(|e| e.to_string())?; + Ok(serde_json::json!({ + "type": "provider", + "id": provider_id + })) + } + "prompt" => { + let prompt_id = + import_prompt_from_deeplink(&state, request).map_err(|e| e.to_string())?; + Ok(serde_json::json!({ + "type": "prompt", + "id": prompt_id + })) + } + "mcp" => { + let result = import_mcp_from_deeplink(&state, request).map_err(|e| e.to_string())?; + // Add type field to the result + Ok(serde_json::json!({ + "type": "mcp", + "importedCount": result.imported_count, + "importedIds": result.imported_ids, + "failed": result.failed + })) + } + "skill" => { + let skill_key = + import_skill_from_deeplink(&state, request).map_err(|e| e.to_string())?; + Ok(serde_json::json!({ + "type": "skill", + "key": skill_key + })) + } + _ => Err(format!("Unsupported resource type: {}", request.resource)), + } +}