diff --git a/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx b/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx index f5ebaac3ca..28e8299710 100644 --- a/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx +++ b/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx @@ -30,6 +30,7 @@ import { ModelTypeEnum } from '@/app/components/header/account-setting/model-pro import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' +import { STORAGE_KEYS } from '@/config/storage-keys' import { generateBasicAppFirstTimeRule, generateRule } from '@/service/debug' import { useGenerateRuleTemplate } from '@/service/use-apps' import IdeaOutput from './idea-output' @@ -83,8 +84,8 @@ const GetAutomaticRes: FC = ({ onFinished, }) => { const { t } = useTranslation() - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model : null const [model, setModel] = React.useState(localModel || { name: '', @@ -178,8 +179,8 @@ const GetAutomaticRes: FC = ({ useEffect(() => { if (defaultModel) { - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') || '') + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '') : null if (localModel) { setModel(localModel) @@ -209,7 +210,7 @@ const GetAutomaticRes: FC = ({ mode: newValue.mode as ModelModeType, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const handleCompletionParamsChange = useCallback((newParams: FormValue) => { @@ -218,7 +219,7 @@ const GetAutomaticRes: FC = ({ completion_params: newParams as CompletionParams, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const onGenerate = async () => { diff --git a/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx b/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx index d47b5c15c3..35bf48732f 100644 --- a/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx +++ b/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx @@ -17,6 +17,7 @@ import Toast from '@/app/components/base/toast' import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' +import { STORAGE_KEYS } from '@/config/storage-keys' import { generateRule } from '@/service/debug' import { useGenerateRuleTemplate } from '@/service/use-apps' import { languageMap } from '../../../../workflow/nodes/_base/components/editor/code-editor/index' @@ -53,8 +54,8 @@ export const GetCodeGeneratorResModal: FC = ( }, ) => { const { t } = useTranslation() - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model : null const [model, setModel] = React.useState(localModel || { name: '', @@ -106,7 +107,7 @@ export const GetCodeGeneratorResModal: FC = ( mode: newValue.mode as ModelModeType, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const handleCompletionParamsChange = useCallback((newParams: FormValue) => { @@ -115,7 +116,7 @@ export const GetCodeGeneratorResModal: FC = ( completion_params: newParams as CompletionParams, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const onGenerate = async () => { @@ -166,8 +167,8 @@ export const GetCodeGeneratorResModal: FC = ( useEffect(() => { if (defaultModel) { - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') || '') + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '') : null if (localModel) { setModel({ diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/index.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/index.tsx index 6a34925275..ef91e98676 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/index.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/index.tsx @@ -12,6 +12,7 @@ import { import Toast from '@/app/components/base/toast' import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { STORAGE_KEYS } from '@/config/storage-keys' import useTheme from '@/hooks/use-theme' import { useGenerateStructuredOutputRules } from '@/service/use-common' import { ModelModeType, Theme } from '@/types/app' @@ -36,8 +37,8 @@ const JsonSchemaGenerator: FC = ({ onApply, crossAxisOffset, }) => { - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model : null const [open, setOpen] = useState(false) const [view, setView] = useState(GeneratorView.promptEditor) @@ -60,8 +61,8 @@ const JsonSchemaGenerator: FC = ({ useEffect(() => { if (defaultModel) { - const localModel = localStorage.getItem('auto-gen-model') - ? JSON.parse(localStorage.getItem('auto-gen-model') || '') + const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) + ? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '') : null if (localModel) { setModel(localModel) @@ -95,7 +96,7 @@ const JsonSchemaGenerator: FC = ({ mode: newValue.mode as ModelModeType, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const handleCompletionParamsChange = useCallback((newParams: FormValue) => { @@ -104,7 +105,7 @@ const JsonSchemaGenerator: FC = ({ completion_params: newParams as CompletionParams, } setModel(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model, setModel]) const { mutateAsync: generateStructuredOutputRules, isPending: isGenerating } = useGenerateStructuredOutputRules() diff --git a/web/app/components/workflow/nodes/tool/components/context-generate-modal/hooks/use-context-generate.ts b/web/app/components/workflow/nodes/tool/components/context-generate-modal/hooks/use-context-generate.ts index 94a612457f..045e2944fe 100644 --- a/web/app/components/workflow/nodes/tool/components/context-generate-modal/hooks/use-context-generate.ts +++ b/web/app/components/workflow/nodes/tool/components/context-generate-modal/hooks/use-context-generate.ts @@ -22,6 +22,7 @@ import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/com import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { useStore } from '@/app/components/workflow/store' +import { STORAGE_KEYS } from '@/config/storage-keys' import { useGetLanguage } from '@/context/i18n' import { languages } from '@/i18n-config/language' import { fetchContextGenerateSuggestedQuestions, generateContext } from '@/service/debug' @@ -271,7 +272,7 @@ const useContextGenerate = ({ const [inputValue, setInputValue] = useState('') const [isGenerating, { setTrue: setGeneratingTrue, setFalse: setGeneratingFalse }] = useBoolean(false) const [modelOverride, setModelOverride] = useState(() => { - const stored = localStorage.getItem('auto-gen-model') + const stored = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) if (!stored) return null const parsed = JSON.parse(stored) as Model @@ -327,7 +328,7 @@ const useContextGenerate = ({ mode: newValue.mode as ModelModeType, } setModelOverride(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model]) const handleCompletionParamsChange = useCallback((newParams: FormValue) => { @@ -336,7 +337,7 @@ const useContextGenerate = ({ completion_params: newParams as CompletionParams, } setModelOverride(newModel) - localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel)) }, [model]) const promptMessageCount = promptMessages?.length ?? 0 diff --git a/web/config/storage-keys.ts b/web/config/storage-keys.ts index 730b78da49..7958ea588c 100644 --- a/web/config/storage-keys.ts +++ b/web/config/storage-keys.ts @@ -2,4 +2,7 @@ export const STORAGE_KEYS = { SKILL: { SIDEBAR_WIDTH: 'skill-sidebar-width', }, + GENERATOR: { + AUTO_GEN_MODEL: 'auto-gen-model', + }, } as const