From 828ec2ce07fb5a0eb81ef7920631b4f39a558e2c Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 19 Apr 2026 09:32:43 +0800 Subject: [PATCH] fix(hermes): show active provider and wire add/enable/remove actions Switching a Hermes provider previously only fired a toast because the frontend treated Hermes as non-additive (unlike backend AppType::is_additive_mode, which lists OpenCode | OpenClaw | Hermes) and relied on the unused is_current DB flag for highlighting. Align the UI model with the backend: - Include Hermes in ProviderActions' isAdditiveMode so the main button switches between "Add" and "Remove". - Drive the "current" highlight from model.provider (via useHermesModelConfig) instead of the DB is_current field; model.provider is Hermes's real SSOT for the active provider. - Reuse OpenClaw's set-as-default button slot to expose an "Enable" action on Hermes that calls switchProvider, so providers already in config can be activated without re-adding. switch_normal + apply_switch_defaults already atomically update custom_providers and model.provider, so no backend change is needed. - Invalidate liveProviderIds + modelConfig + health in parallel after add/update/delete/switch via a new invalidateHermesProviderCaches helper, replacing four copies of three sequential awaits. --- src/App.tsx | 6 ++- src/components/providers/ProviderActions.tsx | 55 ++++++++++++-------- src/components/providers/ProviderCard.tsx | 6 ++- src/components/providers/ProviderList.tsx | 23 ++++++-- src/hooks/useHermes.ts | 20 ++++++- src/lib/query/mutations.ts | 21 ++------ 6 files changed, 86 insertions(+), 45 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b331aaea1..d1dee843f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1021,7 +1021,11 @@ function App() { } onCreate={() => setIsAddOpen(true)} onSetAsDefault={ - activeApp === "openclaw" ? setAsDefaultModel : undefined + activeApp === "openclaw" + ? setAsDefaultModel + : activeApp === "hermes" + ? switchProvider + : undefined } /> diff --git a/src/components/providers/ProviderActions.tsx b/src/components/providers/ProviderActions.tsx index 344a71da8..50872decf 100644 --- a/src/components/providers/ProviderActions.tsx +++ b/src/components/providers/ProviderActions.tsx @@ -70,9 +70,11 @@ export function ProviderActions({ const { t } = useTranslation(); const iconButtonClass = "h-8 w-8 p-1"; - // 累加模式应用(OpenCode 非 OMO 和 OpenClaw) + // 累加模式应用(OpenCode 非 OMO / OpenClaw / Hermes) const isAdditiveMode = - (appId === "opencode" && !isOmo) || appId === "openclaw"; + (appId === "opencode" && !isOmo) || + appId === "openclaw" || + appId === "hermes"; // 故障转移模式下的按钮逻辑(累加模式和 OMO 应用不支持故障转移) const isFailoverMode = @@ -207,25 +209,36 @@ export function ProviderActions({ return (
- {appId === "openclaw" && isInConfig && onSetAsDefault && ( - - )} + {(appId === "openclaw" || appId === "hermes") && + isInConfig && + onSetAsDefault && + (() => { + const activeLabel = + appId === "hermes" + ? t("provider.inUse", { defaultValue: "已在用" }) + : t("provider.isDefault", { defaultValue: "当前默认" }); + const inactiveLabel = + appId === "hermes" + ? t("provider.enable", { defaultValue: "启用" }) + : t("provider.setAsDefault", { defaultValue: "设为默认" }); + return ( + + ); + })()}