mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
refactor: Replace hardcoded localStorage key with constant
This commit is contained in:
@ -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 { 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 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 { generateBasicAppFirstTimeRule, generateRule } from '@/service/debug'
|
||||||
import { useGenerateRuleTemplate } from '@/service/use-apps'
|
import { useGenerateRuleTemplate } from '@/service/use-apps'
|
||||||
import IdeaOutput from './idea-output'
|
import IdeaOutput from './idea-output'
|
||||||
@ -83,8 +84,8 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
|
|||||||
onFinished,
|
onFinished,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model
|
||||||
: null
|
: null
|
||||||
const [model, setModel] = React.useState<Model>(localModel || {
|
const [model, setModel] = React.useState<Model>(localModel || {
|
||||||
name: '',
|
name: '',
|
||||||
@ -178,8 +179,8 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultModel) {
|
if (defaultModel) {
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') || '')
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '')
|
||||||
: null
|
: null
|
||||||
if (localModel) {
|
if (localModel) {
|
||||||
setModel(localModel)
|
setModel(localModel)
|
||||||
@ -209,7 +210,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
|
|||||||
mode: newValue.mode as ModelModeType,
|
mode: newValue.mode as ModelModeType,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
||||||
@ -218,7 +219,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
|
|||||||
completion_params: newParams as CompletionParams,
|
completion_params: newParams as CompletionParams,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const onGenerate = async () => {
|
const onGenerate = async () => {
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import Toast from '@/app/components/base/toast'
|
|||||||
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
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 { 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 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 { generateRule } from '@/service/debug'
|
||||||
import { useGenerateRuleTemplate } from '@/service/use-apps'
|
import { useGenerateRuleTemplate } from '@/service/use-apps'
|
||||||
import { languageMap } from '../../../../workflow/nodes/_base/components/editor/code-editor/index'
|
import { languageMap } from '../../../../workflow/nodes/_base/components/editor/code-editor/index'
|
||||||
@ -53,8 +54,8 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
|
|||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model
|
||||||
: null
|
: null
|
||||||
const [model, setModel] = React.useState<Model>(localModel || {
|
const [model, setModel] = React.useState<Model>(localModel || {
|
||||||
name: '',
|
name: '',
|
||||||
@ -106,7 +107,7 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
|
|||||||
mode: newValue.mode as ModelModeType,
|
mode: newValue.mode as ModelModeType,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
||||||
@ -115,7 +116,7 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
|
|||||||
completion_params: newParams as CompletionParams,
|
completion_params: newParams as CompletionParams,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const onGenerate = async () => {
|
const onGenerate = async () => {
|
||||||
@ -166,8 +167,8 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultModel) {
|
if (defaultModel) {
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') || '')
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '')
|
||||||
: null
|
: null
|
||||||
if (localModel) {
|
if (localModel) {
|
||||||
setModel({
|
setModel({
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
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 { 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 useTheme from '@/hooks/use-theme'
|
||||||
import { useGenerateStructuredOutputRules } from '@/service/use-common'
|
import { useGenerateStructuredOutputRules } from '@/service/use-common'
|
||||||
import { ModelModeType, Theme } from '@/types/app'
|
import { ModelModeType, Theme } from '@/types/app'
|
||||||
@ -36,8 +37,8 @@ const JsonSchemaGenerator: FC<JsonSchemaGeneratorProps> = ({
|
|||||||
onApply,
|
onApply,
|
||||||
crossAxisOffset,
|
crossAxisOffset,
|
||||||
}) => {
|
}) => {
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) as string) as Model
|
||||||
: null
|
: null
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [view, setView] = useState(GeneratorView.promptEditor)
|
const [view, setView] = useState(GeneratorView.promptEditor)
|
||||||
@ -60,8 +61,8 @@ const JsonSchemaGenerator: FC<JsonSchemaGeneratorProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultModel) {
|
if (defaultModel) {
|
||||||
const localModel = localStorage.getItem('auto-gen-model')
|
const localModel = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
? JSON.parse(localStorage.getItem('auto-gen-model') || '')
|
? JSON.parse(localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL) || '')
|
||||||
: null
|
: null
|
||||||
if (localModel) {
|
if (localModel) {
|
||||||
setModel(localModel)
|
setModel(localModel)
|
||||||
@ -95,7 +96,7 @@ const JsonSchemaGenerator: FC<JsonSchemaGeneratorProps> = ({
|
|||||||
mode: newValue.mode as ModelModeType,
|
mode: newValue.mode as ModelModeType,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
||||||
@ -104,7 +105,7 @@ const JsonSchemaGenerator: FC<JsonSchemaGeneratorProps> = ({
|
|||||||
completion_params: newParams as CompletionParams,
|
completion_params: newParams as CompletionParams,
|
||||||
}
|
}
|
||||||
setModel(newModel)
|
setModel(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model, setModel])
|
}, [model, setModel])
|
||||||
|
|
||||||
const { mutateAsync: generateStructuredOutputRules, isPending: isGenerating } = useGenerateStructuredOutputRules()
|
const { mutateAsync: generateStructuredOutputRules, isPending: isGenerating } = useGenerateStructuredOutputRules()
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/com
|
|||||||
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
|
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
|
||||||
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
|
import { STORAGE_KEYS } from '@/config/storage-keys'
|
||||||
import { useGetLanguage } from '@/context/i18n'
|
import { useGetLanguage } from '@/context/i18n'
|
||||||
import { languages } from '@/i18n-config/language'
|
import { languages } from '@/i18n-config/language'
|
||||||
import { fetchContextGenerateSuggestedQuestions, generateContext } from '@/service/debug'
|
import { fetchContextGenerateSuggestedQuestions, generateContext } from '@/service/debug'
|
||||||
@ -271,7 +272,7 @@ const useContextGenerate = ({
|
|||||||
const [inputValue, setInputValue] = useState('')
|
const [inputValue, setInputValue] = useState('')
|
||||||
const [isGenerating, { setTrue: setGeneratingTrue, setFalse: setGeneratingFalse }] = useBoolean(false)
|
const [isGenerating, { setTrue: setGeneratingTrue, setFalse: setGeneratingFalse }] = useBoolean(false)
|
||||||
const [modelOverride, setModelOverride] = useState<Model | null>(() => {
|
const [modelOverride, setModelOverride] = useState<Model | null>(() => {
|
||||||
const stored = localStorage.getItem('auto-gen-model')
|
const stored = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
|
||||||
if (!stored)
|
if (!stored)
|
||||||
return null
|
return null
|
||||||
const parsed = JSON.parse(stored) as Model
|
const parsed = JSON.parse(stored) as Model
|
||||||
@ -327,7 +328,7 @@ const useContextGenerate = ({
|
|||||||
mode: newValue.mode as ModelModeType,
|
mode: newValue.mode as ModelModeType,
|
||||||
}
|
}
|
||||||
setModelOverride(newModel)
|
setModelOverride(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model])
|
}, [model])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
|
||||||
@ -336,7 +337,7 @@ const useContextGenerate = ({
|
|||||||
completion_params: newParams as CompletionParams,
|
completion_params: newParams as CompletionParams,
|
||||||
}
|
}
|
||||||
setModelOverride(newModel)
|
setModelOverride(newModel)
|
||||||
localStorage.setItem('auto-gen-model', JSON.stringify(newModel))
|
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
|
||||||
}, [model])
|
}, [model])
|
||||||
|
|
||||||
const promptMessageCount = promptMessages?.length ?? 0
|
const promptMessageCount = promptMessages?.length ?? 0
|
||||||
|
|||||||
@ -2,4 +2,7 @@ export const STORAGE_KEYS = {
|
|||||||
SKILL: {
|
SKILL: {
|
||||||
SIDEBAR_WIDTH: 'skill-sidebar-width',
|
SIDEBAR_WIDTH: 'skill-sidebar-width',
|
||||||
},
|
},
|
||||||
|
GENERATOR: {
|
||||||
|
AUTO_GEN_MODEL: 'auto-gen-model',
|
||||||
|
},
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
Reference in New Issue
Block a user