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.
This commit is contained in:
Jason
2026-04-19 09:32:43 +08:00
parent 5056978d80
commit 828ec2ce07
6 changed files with 86 additions and 45 deletions
+19 -1
View File
@@ -1,4 +1,9 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
useMutation,
useQuery,
useQueryClient,
type QueryClient,
} from "@tanstack/react-query";
import { hermesApi } from "@/lib/api/hermes";
import { providersApi } from "@/lib/api/providers";
import type {
@@ -20,6 +25,19 @@ export const hermesKeys = {
health: ["hermes", "health"] as const,
};
/**
* Invalidate all Hermes caches that may change when a provider is
* added/updated/deleted/switched. Runs invalidations in parallel so the
* caller doesn't await three sequential refetches.
*/
export function invalidateHermesProviderCaches(queryClient: QueryClient) {
return Promise.all([
queryClient.invalidateQueries({ queryKey: hermesKeys.liveProviderIds }),
queryClient.invalidateQueries({ queryKey: hermesKeys.modelConfig }),
queryClient.invalidateQueries({ queryKey: hermesKeys.health }),
]);
}
// ============================================================
// Query hooks
// ============================================================