mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
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:
@@ -8,7 +8,7 @@ import type { Provider, SessionMeta, Settings } from "@/types";
|
||||
import { extractErrorMessage } from "@/utils/errorUtils";
|
||||
import { generateUUID } from "@/utils/uuid";
|
||||
import { openclawKeys } from "@/hooks/useOpenClaw";
|
||||
import { hermesKeys } from "@/hooks/useHermes";
|
||||
import { invalidateHermesProviderCaches } from "@/hooks/useHermes";
|
||||
|
||||
export const useAddProviderMutation = (appId: AppId) => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -77,9 +77,7 @@ export const useAddProviderMutation = (appId: AppId) => {
|
||||
}
|
||||
|
||||
if (appId === "hermes") {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: hermesKeys.health,
|
||||
});
|
||||
await invalidateHermesProviderCaches(queryClient);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -135,9 +133,7 @@ export const useUpdateProviderMutation = (appId: AppId) => {
|
||||
});
|
||||
}
|
||||
if (appId === "hermes") {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: hermesKeys.health,
|
||||
});
|
||||
await invalidateHermesProviderCaches(queryClient);
|
||||
}
|
||||
toast.success(
|
||||
t("notifications.updateSuccess", {
|
||||
@@ -193,9 +189,7 @@ export const useDeleteProviderMutation = (appId: AppId) => {
|
||||
}
|
||||
|
||||
if (appId === "hermes") {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: hermesKeys.health,
|
||||
});
|
||||
await invalidateHermesProviderCaches(queryClient);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -263,12 +257,7 @@ export const useSwitchProviderMutation = (appId: AppId) => {
|
||||
});
|
||||
}
|
||||
if (appId === "hermes") {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: hermesKeys.liveProviderIds,
|
||||
});
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: hermesKeys.health,
|
||||
});
|
||||
await invalidateHermesProviderCaches(queryClient);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user