feat: migrate state from v1 to v2

This commit is contained in:
Yidadaa
2023-04-27 02:00:22 +08:00
parent 401c1364be
commit 30040a0366
8 changed files with 85 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { StoreKey } from "../constant";
export enum SubmitKey {
Enter = "Enter",
@@ -112,8 +113,6 @@ export const ModalConfigValidator = {
},
};
const CONFIG_KEY = "app-config";
export const useAppConfig = create<ChatConfigStore>()(
persist(
(set, get) => ({
@@ -130,7 +129,18 @@ export const useAppConfig = create<ChatConfigStore>()(
},
}),
{
name: CONFIG_KEY,
name: StoreKey.Config,
version: 2,
migrate(persistedState, version) {
if (version === 2) return persistedState as any;
const state = persistedState as ChatConfig;
state.modelConfig.sendMemory = true;
state.modelConfig.historyMessageCount = 4;
state.modelConfig.compressMessageLengthThreshold = 1000;
return state;
},
},
),
);