diff --git a/src-tauri/src/commands/omo.rs b/src-tauri/src/commands/omo.rs index d976e8b94..628cc2853 100644 --- a/src-tauri/src/commands/omo.rs +++ b/src-tauri/src/commands/omo.rs @@ -36,19 +36,6 @@ pub async fn disable_current_omo(state: State<'_, AppState>) -> Result<(), Strin Ok(()) } -#[tauri::command] -pub async fn get_omo_provider_count(state: State<'_, AppState>) -> Result { - let providers = state - .db - .get_all_providers("opencode") - .map_err(|e| e.to_string())?; - let count = providers - .values() - .filter(|p| p.category.as_deref() == Some("omo")) - .count(); - Ok(count) -} - // ── OMO Slim commands ─────────────────────────────────────── #[tauri::command] @@ -84,16 +71,3 @@ pub async fn disable_current_omo_slim(state: State<'_, AppState>) -> Result<(), OmoService::delete_config_file(&SLIM).map_err(|e| e.to_string())?; Ok(()) } - -#[tauri::command] -pub async fn get_omo_slim_provider_count(state: State<'_, AppState>) -> Result { - let providers = state - .db - .get_all_providers("opencode") - .map_err(|e| e.to_string())?; - let count = providers - .values() - .filter(|p| p.category.as_deref() == Some("omo-slim")) - .count(); - Ok(count) -} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2ed14d9f9..879fe81ee 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1035,11 +1035,9 @@ pub fn run() { commands::set_window_theme, commands::read_omo_local_file, commands::get_current_omo_provider_id, - commands::get_omo_provider_count, commands::disable_current_omo, commands::read_omo_slim_local_file, commands::get_current_omo_slim_provider_id, - commands::get_omo_slim_provider_count, commands::disable_current_omo_slim, // Workspace files (OpenClaw) commands::read_workspace_file, diff --git a/src-tauri/src/services/provider/mod.rs b/src-tauri/src/services/provider/mod.rs index 17aa759a6..59f4b8536 100644 --- a/src-tauri/src/services/provider/mod.rs +++ b/src-tauri/src/services/provider/mod.rs @@ -260,18 +260,6 @@ impl ProviderService { state .db .is_omo_provider_current(app_type.as_str(), id, "omo")?; - let omo_count = state - .db - .get_all_providers(app_type.as_str())? - .values() - .filter(|p| p.category.as_deref() == Some("omo")) - .count(); - - if omo_count <= 1 && was_current { - return Err(AppError::Message( - "无法删除当前启用的最后一个 OMO 配置,请先停用".to_string(), - )); - } state.db.delete_provider(app_type.as_str(), id)?; if was_current { @@ -287,18 +275,6 @@ impl ProviderService { state .db .is_omo_provider_current(app_type.as_str(), id, "omo-slim")?; - let slim_count = state - .db - .get_all_providers(app_type.as_str())? - .values() - .filter(|p| p.category.as_deref() == Some("omo-slim")) - .count(); - - if slim_count <= 1 && was_current { - return Err(AppError::Message( - "无法删除当前启用的最后一个 OMO Slim 配置,请先停用".to_string(), - )); - } state.db.delete_provider(app_type.as_str(), id)?; if was_current { diff --git a/src/components/providers/ProviderActions.tsx b/src/components/providers/ProviderActions.tsx index 1394fa69f..90bd60991 100644 --- a/src/components/providers/ProviderActions.tsx +++ b/src/components/providers/ProviderActions.tsx @@ -24,7 +24,6 @@ interface ProviderActionsProps { isTesting?: boolean; isProxyTakeover?: boolean; isOmo?: boolean; - isLastOmo?: boolean; onSwitch: () => void; onEdit: () => void; onDuplicate: () => void; @@ -49,7 +48,6 @@ export function ProviderActions({ isTesting: _isTesting, // Hidden: stream check feature disabled isProxyTakeover = false, isOmo = false, - isLastOmo = false, onSwitch, onEdit, onDuplicate, @@ -192,11 +190,7 @@ export function ProviderActions({ const buttonState = getMainButtonState(); - const canDelete = isOmo - ? !(isLastOmo && isCurrent) - : isAdditiveMode - ? true - : !isCurrent; + const canDelete = isOmo || isAdditiveMode ? true : !isCurrent; return (
diff --git a/src/components/providers/ProviderCard.tsx b/src/components/providers/ProviderCard.tsx index 6590cd14c..96d8b4607 100644 --- a/src/components/providers/ProviderCard.tsx +++ b/src/components/providers/ProviderCard.tsx @@ -28,9 +28,7 @@ interface ProviderCardProps { appId: AppId; isInConfig?: boolean; // OpenCode: 是否已添加到 opencode.json isOmo?: boolean; - isLastOmo?: boolean; isOmoSlim?: boolean; - isLastOmoSlim?: boolean; onSwitch: (provider: Provider) => void; onEdit: (provider: Provider) => void; onDelete: (provider: Provider) => void; @@ -94,9 +92,7 @@ export function ProviderCard({ appId, isInConfig = true, isOmo = false, - isLastOmo = false, isOmoSlim = false, - isLastOmoSlim = false, onSwitch, onEdit, onDelete, @@ -125,7 +121,6 @@ export function ProviderCard({ // OMO and OMO Slim share the same card behavior const isAnyOmo = isOmo || isOmoSlim; - const isLastAnyOmo = isOmo ? isLastOmo : isLastOmoSlim; const handleDisableAnyOmo = isOmoSlim ? onDisableOmoSlim : onDisableOmo; const { data: health } = useProviderHealth(provider.id, appId); @@ -390,7 +385,6 @@ export function ProviderCard({ isTesting={isTesting} isProxyTakeover={isProxyTakeover} isOmo={isAnyOmo} - isLastOmo={isLastAnyOmo} onSwitch={() => onSwitch(provider)} onEdit={() => onEdit(provider)} onDuplicate={() => onDuplicate(provider)} diff --git a/src/components/providers/ProviderList.tsx b/src/components/providers/ProviderList.tsx index 928bdbcf4..259120142 100644 --- a/src/components/providers/ProviderList.tsx +++ b/src/components/providers/ProviderList.tsx @@ -36,9 +36,7 @@ import { } from "@/lib/query/failover"; import { useCurrentOmoProviderId, - useOmoProviderCount, useCurrentOmoSlimProviderId, - useOmoSlimProviderCount, } from "@/lib/query/omo"; import { useCallback } from "react"; import { Input } from "@/components/ui/input"; @@ -142,9 +140,7 @@ export function ProviderList({ const isOpenCode = appId === "opencode"; const { data: currentOmoId } = useCurrentOmoProviderId(isOpenCode); - const { data: omoProviderCount } = useOmoProviderCount(isOpenCode); const { data: currentOmoSlimId } = useCurrentOmoSlimProviderId(isOpenCode); - const { data: omoSlimProviderCount } = useOmoSlimProviderCount(isOpenCode); const getFailoverPriority = useCallback( (providerId: string): number | undefined => { @@ -293,15 +289,7 @@ export function ProviderList({ appId={appId} isInConfig={isProviderInConfig(provider.id)} isOmo={isOmo} - isLastOmo={ - isOmo && (omoProviderCount ?? 0) <= 1 && isOmoCurrent - } isOmoSlim={isOmoSlim} - isLastOmoSlim={ - isOmoSlim && - (omoSlimProviderCount ?? 0) <= 1 && - isOmoSlimCurrent - } onSwitch={onSwitch} onEdit={onEdit} onDelete={onDelete} @@ -420,9 +408,7 @@ interface SortableProviderCardProps { appId: AppId; isInConfig: boolean; isOmo: boolean; - isLastOmo: boolean; isOmoSlim: boolean; - isLastOmoSlim: boolean; onSwitch: (provider: Provider) => void; onEdit: (provider: Provider) => void; onDelete: (provider: Provider) => void; @@ -453,9 +439,7 @@ function SortableProviderCard({ appId, isInConfig, isOmo, - isLastOmo, isOmoSlim, - isLastOmoSlim, onSwitch, onEdit, onDelete, @@ -500,9 +484,7 @@ function SortableProviderCard({ appId={appId} isInConfig={isInConfig} isOmo={isOmo} - isLastOmo={isLastOmo} isOmoSlim={isOmoSlim} - isLastOmoSlim={isLastOmoSlim} onSwitch={onSwitch} onEdit={onEdit} onDelete={onDelete} diff --git a/src/lib/api/omo.ts b/src/lib/api/omo.ts index f79dedfc6..9df562c35 100644 --- a/src/lib/api/omo.ts +++ b/src/lib/api/omo.ts @@ -5,7 +5,6 @@ export const omoApi = { readLocalFile: (): Promise => invoke("read_omo_local_file"), getCurrentOmoProviderId: (): Promise => invoke("get_current_omo_provider_id"), - getOmoProviderCount: (): Promise => invoke("get_omo_provider_count"), disableCurrentOmo: (): Promise => invoke("disable_current_omo"), }; @@ -14,7 +13,5 @@ export const omoSlimApi = { invoke("read_omo_slim_local_file"), getCurrentProviderId: (): Promise => invoke("get_current_omo_slim_provider_id"), - getProviderCount: (): Promise => - invoke("get_omo_slim_provider_count"), disableCurrent: (): Promise => invoke("disable_current_omo_slim"), }; diff --git a/src/lib/query/omo.ts b/src/lib/query/omo.ts index c760a4371..6d84b9c87 100644 --- a/src/lib/query/omo.ts +++ b/src/lib/query/omo.ts @@ -7,7 +7,6 @@ function createOmoQueryKeys(prefix: string) { return { all: [prefix] as const, currentProviderId: () => [prefix, "current-provider-id"] as const, - providerCount: () => [prefix, "provider-count"] as const, }; } @@ -20,7 +19,6 @@ function createOmoQueryHooks( function invalidateAll(queryClient: ReturnType) { queryClient.invalidateQueries({ queryKey: ["providers"] }); queryClient.invalidateQueries({ queryKey: keys.currentProviderId() }); - queryClient.invalidateQueries({ queryKey: keys.providerCount() }); } function useCurrentProviderId(enabled = true) { @@ -34,17 +32,6 @@ function createOmoQueryHooks( }); } - function useProviderCount(enabled = true) { - return useQuery({ - queryKey: keys.providerCount(), - queryFn: - "getOmoProviderCount" in api - ? (api as typeof omoApi).getOmoProviderCount - : (api as typeof omoSlimApi).getProviderCount, - enabled, - }); - } - function useReadLocalFile() { return useMutation({ mutationFn: () => api.readLocalFile(), @@ -65,7 +52,6 @@ function createOmoQueryHooks( return { keys, useCurrentProviderId, - useProviderCount, useReadLocalFile, useDisableCurrent, }; @@ -82,11 +68,9 @@ export const omoKeys = omoHooks.keys; export const omoSlimKeys = omoSlimHooks.keys; export const useCurrentOmoProviderId = omoHooks.useCurrentProviderId; -export const useOmoProviderCount = omoHooks.useProviderCount; export const useReadOmoLocalFile = omoHooks.useReadLocalFile; export const useDisableCurrentOmo = omoHooks.useDisableCurrent; export const useCurrentOmoSlimProviderId = omoSlimHooks.useCurrentProviderId; -export const useOmoSlimProviderCount = omoSlimHooks.useProviderCount; export const useReadOmoSlimLocalFile = omoSlimHooks.useReadLocalFile; export const useDisableCurrentOmoSlim = omoSlimHooks.useDisableCurrent;