Spaces:
Configuration error
Configuration error
Download frontend/src/hooks/mutation/use-save-settings.ts from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/hooks/mutation/use-save-settings.ts
- Command line
-
hf download hf://spaces/flyingdarkdev/README/frontend/src/hooks/mutation/use-save-settings.ts
-
curl -L -o use-save-settings.ts https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/hooks/mutation/use-save-settings.ts
1.94 kB
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | |
| import { DEFAULT_SETTINGS } from "#/services/settings"; | |
| import OpenHands from "#/api/open-hands"; | |
| import { PostSettings, PostApiSettings } from "#/types/settings"; | |
| import { useSettings } from "../query/use-settings"; | |
| const saveSettingsMutationFn = async ( | |
| settings: Partial<PostSettings> | null, | |
| ) => { | |
| // If settings is null, we're resetting | |
| if (settings === null) { | |
| await OpenHands.resetSettings(); | |
| return; | |
| } | |
| const apiSettings: Partial<PostApiSettings> = { | |
| llm_model: settings.LLM_MODEL, | |
| llm_base_url: settings.LLM_BASE_URL, | |
| agent: settings.AGENT || DEFAULT_SETTINGS.AGENT, | |
| language: settings.LANGUAGE || DEFAULT_SETTINGS.LANGUAGE, | |
| confirmation_mode: settings.CONFIRMATION_MODE, | |
| security_analyzer: settings.SECURITY_ANALYZER, | |
| llm_api_key: | |
| settings.LLM_API_KEY === "" | |
| ? "" | |
| : settings.LLM_API_KEY?.trim() || undefined, | |
| remote_runtime_resource_factor: settings.REMOTE_RUNTIME_RESOURCE_FACTOR, | |
| provider_tokens: settings.provider_tokens, | |
| enable_default_condenser: settings.ENABLE_DEFAULT_CONDENSER, | |
| enable_sound_notifications: settings.ENABLE_SOUND_NOTIFICATIONS, | |
| user_consents_to_analytics: settings.user_consents_to_analytics, | |
| }; | |
| await OpenHands.saveSettings(apiSettings); | |
| }; | |
| export const useSaveSettings = () => { | |
| const queryClient = useQueryClient(); | |
| const { data: currentSettings } = useSettings(); | |
| return useMutation({ | |
| mutationFn: async (settings: Partial<PostSettings> | null) => { | |
| if (settings === null) { | |
| await saveSettingsMutationFn(null); | |
| return; | |
| } | |
| const newSettings = { ...currentSettings, ...settings }; | |
| await saveSettingsMutationFn(newSettings); | |
| }, | |
| onSuccess: async () => { | |
| await queryClient.invalidateQueries({ queryKey: ["settings"] }); | |
| }, | |
| meta: { | |
| disableToast: true, | |
| }, | |
| }); | |
| }; | |