Download src/hooks/mutation/use-set-plugin-enabled.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/mutation/use-set-plugin-enabled.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/hooks/mutation/use-set-plugin-enabled.ts
-
curl -L -o use-set-plugin-enabled.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/mutation/use-set-plugin-enabled.ts
1.24 kB
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | |
| import { useTranslation } from "react-i18next"; | |
| import PluginsManagementService from "#/api/plugins-management-service"; | |
| import { PLUGINS_QUERY_KEYS } from "#/hooks/query/query-keys"; | |
| import { I18nKey } from "#/i18n/declaration"; | |
| import { displayErrorToast } from "#/utils/custom-toast-handlers"; | |
| import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message"; | |
| /** | |
| * Enable or disable an installed plugin. Enabled installed plugins auto-load | |
| * into new conversations (via the SDK auto-load wiring), so the enabled flag is | |
| * the enforced source of truth — invalidate the installed list on success. | |
| */ | |
| export function useSetPluginEnabled() { | |
| const queryClient = useQueryClient(); | |
| const { t } = useTranslation("openhands"); | |
| return useMutation({ | |
| mutationFn: ({ name, enabled }: { name: string; enabled: boolean }) => | |
| PluginsManagementService.setPluginEnabled(name, enabled), | |
| onSuccess: () => { | |
| queryClient.invalidateQueries({ queryKey: PLUGINS_QUERY_KEYS.installed }); | |
| }, | |
| onError: (error) => { | |
| displayErrorToast( | |
| retrieveAxiosErrorMessage(error) || t(I18nKey.ERROR$GENERIC), | |
| ); | |
| }, | |
| }); | |
| } | |