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.
This commit is contained in:
Jason
2026-02-27 11:50:38 +08:00
parent 3bd0a7c02c
commit b2b20dadd7
3 changed files with 21 additions and 29 deletions

View File

@@ -448,18 +448,7 @@ pub fn run() {
Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"), Err(e) => log::warn!("✗ Failed to read skills migration flag: {e}"),
} }
// 2. OpenCode 供应商导入(累加式模式,需特殊处理 // 2. OMO 配置导入(当数据库中无 OMO provider 时,从本地文件导入
// 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 时,从本地文件导入)
{ {
let has_omo = app_state let has_omo = app_state
.db .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 服务器配置(表空时触发) // 3. 导入 MCP 服务器配置(表空时触发)
if app_state.db.is_mcp_table_empty().unwrap_or(false) { if app_state.db.is_mcp_table_empty().unwrap_or(false) {
log::info!("MCP table empty, importing from live configurations..."); log::info!("MCP table empty, importing from live configurations...");

View File

@@ -179,7 +179,17 @@ export function ProviderList({
// Import current live config as default provider // Import current live config as default provider
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const importMutation = useMutation({ const importMutation = useMutation({
mutationFn: () => providersApi.importDefault(appId), mutationFn: async (): Promise<boolean> => {
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) => { onSuccess: (imported) => {
if (imported) { if (imported) {
queryClient.invalidateQueries({ queryKey: ["providers", appId] }); 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) { if (sortedProviders.length === 0) {
return ( return (
<ProviderEmptyState <ProviderEmptyState
onCreate={onCreate} onCreate={onCreate}
onImport={showImportButton ? () => importMutation.mutate() : undefined} onImport={() => importMutation.mutate()}
/> />
); );
} }

View File

@@ -110,6 +110,14 @@ export const providersApi = {
async getOpenClawLiveProviderIds(): Promise<string[]> { async getOpenClawLiveProviderIds(): Promise<string[]> {
return await invoke("get_openclaw_live_provider_ids"); return await invoke("get_openclaw_live_provider_ids");
}, },
/**
* 从 OpenClaw live 配置导入供应商到数据库
* OpenClaw 特有功能:由于累加模式,用户可能已在 openclaw.json 中配置供应商
*/
async importOpenClawFromLive(): Promise<number> {
return await invoke("import_openclaw_providers_from_live");
},
}; };
// ============================================================================ // ============================================================================