From b2b20dadd76398e77ca2ec5a5c91e8d30df4d432 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 27 Feb 2026 11:50:38 +0800 Subject: [PATCH] fix: add import button for OpenCode/OpenClaw empty state and remove auto-import on startup Previously OpenCode and OpenClaw auto-imported providers from live config on app startup, which could confuse users. Now they follow the same pattern as Claude/Codex/Gemini: manual import via the empty state button. --- src-tauri/src/lib.rs | 24 +---------------------- src/components/providers/ProviderList.tsx | 18 +++++++++++------ src/lib/api/providers.ts | 8 ++++++++ 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1ba9229da..b0330ec5c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -448,18 +448,7 @@ pub fn run() { Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"), } - // 2. OpenCode 供应商导入(累加式模式,需特殊处理) - // OpenCode 与其他应用不同:配置文件中可同时存在多个供应商 - // 需要遍历 provider 字段下的每个供应商并导入 - match crate::services::provider::import_opencode_providers_from_live(&app_state) { - Ok(count) if count > 0 => { - log::info!("✓ Imported {count} OpenCode provider(s) from live config"); - } - Ok(_) => log::debug!("○ No OpenCode providers found to import"), - Err(e) => log::warn!("○ Failed to import OpenCode providers: {e}"), - } - - // 2.2 OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入) + // 2. OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入) { let has_omo = app_state .db @@ -510,17 +499,6 @@ pub fn run() { } } - // 2.4 OpenClaw 供应商导入(累加式模式,需特殊处理) - // OpenClaw 与 OpenCode 类似:配置文件中可同时存在多个供应商 - // 需要遍历 models.providers 字段下的每个供应商并导入 - match crate::services::provider::import_openclaw_providers_from_live(&app_state) { - Ok(count) if count > 0 => { - log::info!("✓ Imported {count} OpenClaw provider(s) from live config"); - } - Ok(_) => log::debug!("○ No OpenClaw providers found to import"), - Err(e) => log::warn!("○ Failed to import OpenClaw providers: {e}"), - } - // 3. 导入 MCP 服务器配置(表空时触发) if app_state.db.is_mcp_table_empty().unwrap_or(false) { log::info!("MCP table empty, importing from live configurations..."); diff --git a/src/components/providers/ProviderList.tsx b/src/components/providers/ProviderList.tsx index 259120142..2063fd595 100644 --- a/src/components/providers/ProviderList.tsx +++ b/src/components/providers/ProviderList.tsx @@ -179,7 +179,17 @@ export function ProviderList({ // Import current live config as default provider const queryClient = useQueryClient(); const importMutation = useMutation({ - mutationFn: () => providersApi.importDefault(appId), + mutationFn: async (): Promise => { + if (appId === "opencode") { + const count = await providersApi.importOpenCodeFromLive(); + return count > 0; + } + if (appId === "openclaw") { + const count = await providersApi.importOpenClawFromLive(); + return count > 0; + } + return providersApi.importDefault(appId); + }, onSuccess: (imported) => { if (imported) { queryClient.invalidateQueries({ queryKey: ["providers", appId] }); @@ -245,15 +255,11 @@ export function ProviderList({ ); } - // Only show import button for standard apps (not additive-mode apps like OpenCode/OpenClaw) - const showImportButton = - appId === "claude" || appId === "codex" || appId === "gemini"; - if (sortedProviders.length === 0) { return ( importMutation.mutate() : undefined} + onImport={() => importMutation.mutate()} /> ); } diff --git a/src/lib/api/providers.ts b/src/lib/api/providers.ts index b0a51a9e5..47a950630 100644 --- a/src/lib/api/providers.ts +++ b/src/lib/api/providers.ts @@ -110,6 +110,14 @@ export const providersApi = { async getOpenClawLiveProviderIds(): Promise { return await invoke("get_openclaw_live_provider_ids"); }, + + /** + * 从 OpenClaw live 配置导入供应商到数据库 + * OpenClaw 特有功能:由于累加模式,用户可能已在 openclaw.json 中配置供应商 + */ + async importOpenClawFromLive(): Promise { + return await invoke("import_openclaw_providers_from_live"); + }, }; // ============================================================================