mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
♻️ refactor: 重构 settings 相关类型
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { ThemeMode } from 'antd-style';
|
||||
import type { StateCreator } from 'zustand/vanilla';
|
||||
|
||||
import type { ConfigSettings } from '@/types/exportConfig';
|
||||
import type { GlobalSettings } from '@/types/settings';
|
||||
|
||||
import type { SidebarTabKey } from './initialState';
|
||||
import { DEFAULT_SETTINGS, GlobalSettingsState } from './initialState';
|
||||
import { DEFAULT_SETTINGS, SettingsState } from './initialState';
|
||||
import type { SettingsStore } from './store';
|
||||
|
||||
/**
|
||||
* 设置操作
|
||||
*/
|
||||
export interface SettingsAction {
|
||||
importSettings: (settings: GlobalSettings) => void;
|
||||
/**
|
||||
* 重置设置
|
||||
*/
|
||||
@@ -19,12 +20,12 @@ export interface SettingsAction {
|
||||
* 设置全局设置
|
||||
* @param settings - 全局设置
|
||||
*/
|
||||
setGlobalSettings: (settings: GlobalSettingsState) => void;
|
||||
setGlobalSettings: (settings: SettingsState) => void;
|
||||
/**
|
||||
* 设置部分配置设置
|
||||
* @param settings - 部分配置设置
|
||||
*/
|
||||
setSettings: (settings: Partial<ConfigSettings>) => void;
|
||||
setSettings: (settings: Partial<GlobalSettings>) => void;
|
||||
/**
|
||||
* 设置主题模式
|
||||
* @param themeMode - 主题模式
|
||||
@@ -43,6 +44,13 @@ export const createSettings: StateCreator<
|
||||
[],
|
||||
SettingsAction
|
||||
> = (set, get) => ({
|
||||
importSettings: (importSettings) => {
|
||||
const { setSettings } = get();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { OPENAI_API_KEY: _, password: __, ...settings } = importSettings;
|
||||
|
||||
setSettings(settings);
|
||||
},
|
||||
resetSettings: () => {
|
||||
set({ settings: DEFAULT_SETTINGS });
|
||||
},
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { ConfigSettings } from '@/types/exportConfig';
|
||||
import { LanguageModel } from '@/types/llm';
|
||||
import type { GlobalSettings } from '@/types/settings';
|
||||
|
||||
export type SidebarTabKey = 'chat' | 'market';
|
||||
export type SidebarTabKey = 'chat' | 'market' | 'setting';
|
||||
|
||||
export const DEFAULT_SETTINGS: ConfigSettings = {
|
||||
export const DEFAULT_SETTINGS: GlobalSettings = {
|
||||
OPENAI_API_KEY: '',
|
||||
avatar: '',
|
||||
compressThreshold: 24,
|
||||
@@ -26,15 +26,15 @@ export const DEFAULT_SETTINGS: ConfigSettings = {
|
||||
topP: 1,
|
||||
};
|
||||
|
||||
export interface GlobalSettingsState {
|
||||
export interface SettingsState {
|
||||
inputHeight: number;
|
||||
sessionExpandable?: boolean;
|
||||
sessionsWidth: number;
|
||||
settings: ConfigSettings;
|
||||
settings: GlobalSettings;
|
||||
sidebarKey: SidebarTabKey;
|
||||
}
|
||||
|
||||
export const initialState: GlobalSettingsState = {
|
||||
export const initialState: SettingsState = {
|
||||
inputHeight: 200,
|
||||
sessionExpandable: true,
|
||||
sessionsWidth: 320,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { StateCreator } from 'zustand/vanilla';
|
||||
|
||||
import { type SettingsAction, createSettings } from './action';
|
||||
import { type GlobalSettingsState, initialState } from './initialState';
|
||||
import { type SettingsState, initialState } from './initialState';
|
||||
|
||||
export type SettingsStore = SettingsAction & GlobalSettingsState;
|
||||
export type SettingsStore = SettingsAction & SettingsState;
|
||||
|
||||
export const createStore: StateCreator<SettingsStore, [['zustand/devtools', never]]> = (
|
||||
...parameters
|
||||
|
||||
@@ -1,40 +1,9 @@
|
||||
import type { NeutralColors, PrimaryColors } from '@lobehub/ui';
|
||||
import { ThemeMode } from 'antd-style';
|
||||
|
||||
import { LanguageModel } from '@/types/llm';
|
||||
|
||||
import { Locales } from './locale';
|
||||
|
||||
/**
|
||||
* 配置设置
|
||||
*/
|
||||
export interface ConfigSettings {
|
||||
OPENAI_API_KEY: string;
|
||||
avatar: string;
|
||||
compressThreshold: number;
|
||||
enableCompressThreshold: boolean;
|
||||
enableHistoryCount: boolean;
|
||||
enableMaxTokens: boolean;
|
||||
endpoint: string;
|
||||
fontSize: number;
|
||||
frequencyPenalty: number;
|
||||
historyCount: number;
|
||||
language: Locales;
|
||||
maxTokens: number;
|
||||
model: LanguageModel;
|
||||
neutralColor: NeutralColors | '';
|
||||
password: string;
|
||||
presencePenalty: number;
|
||||
primaryColor: PrimaryColors | '';
|
||||
temperature: number;
|
||||
themeMode: ThemeMode;
|
||||
topP: number;
|
||||
}
|
||||
|
||||
export type ConfigKeys = keyof ConfigSettings;
|
||||
import { LobeSessions } from '@/types/session';
|
||||
import { GlobalSettings } from '@/types/settings';
|
||||
|
||||
export interface ConfigState {
|
||||
settings: ConfigSettings;
|
||||
sessions: LobeSessions;
|
||||
settings: GlobalSettings;
|
||||
}
|
||||
|
||||
export interface ConfigFile {
|
||||
|
||||
32
src/types/settings.ts
Normal file
32
src/types/settings.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NeutralColors, PrimaryColors } from '@lobehub/ui';
|
||||
import { ThemeMode } from 'antd-style';
|
||||
|
||||
import { Locales } from '@/locales/resources';
|
||||
import { LanguageModel } from '@/types/llm';
|
||||
|
||||
/**
|
||||
* 配置设置
|
||||
*/
|
||||
export interface GlobalSettings {
|
||||
OPENAI_API_KEY: string;
|
||||
avatar: string;
|
||||
compressThreshold: number;
|
||||
enableCompressThreshold: boolean;
|
||||
enableHistoryCount: boolean;
|
||||
enableMaxTokens: boolean;
|
||||
endpoint: string;
|
||||
fontSize: number;
|
||||
frequencyPenalty: number;
|
||||
historyCount: number;
|
||||
language: Locales;
|
||||
maxTokens: number;
|
||||
model: LanguageModel;
|
||||
neutralColor: NeutralColors | '';
|
||||
password: string;
|
||||
presencePenalty: number;
|
||||
primaryColor: PrimaryColors | '';
|
||||
temperature: number;
|
||||
themeMode: ThemeMode;
|
||||
topP: number;
|
||||
}
|
||||
export type ConfigKeys = keyof GlobalSettings;
|
||||
Reference in New Issue
Block a user