dxt.ts
1 import { defineStore } from 'pinia' 2 import { ref, toRaw } from 'vue' 3 import type { userConfigValue } from '@/types/mcp' 4 import { useI18n } from 'vue-i18n' 5 6 export const validateNumberRange = (min: number | undefined, max: number | undefined) => { 7 const minNum = min ?? '-∞' 8 const maxNum = max ?? '+∞' 9 const { t } = useI18n() 10 return t('dxt.number-range', { min: minNum, max: maxNum }) 11 } 12 13 export const useDxtStore = defineStore( 14 'dxtStore', 15 () => { 16 const configValues = ref<Record<string, Record<string, userConfigValue>>>({}) 17 18 const updateConfigAttribute = (name: string, key: string, value: userConfigValue) => { 19 if (!configValues.value[name]) { 20 configValues.value[name] = {} 21 } 22 configValues.value[name][key] = value 23 } 24 25 const getConfig = (name: string) => { 26 return toRaw(configValues.value[name]) ?? null 27 } 28 29 const getConfigAttribute = (name: string, key: string) => { 30 return configValues.value[name]?.[key] ?? null 31 } 32 33 return { configValues, getConfig, updateConfigAttribute, getConfigAttribute } 34 }, 35 { 36 persist: true 37 } 38 )