From 89e68b4d392928df70479be71bc9bee61fe2192f Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 27 Dec 2023 17:42:08 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20persist=20current=20session=20an?= =?UTF-8?q?d=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/package-lock.json | 21 ++++++++++++++ gui/package.json | 1 + gui/src/components/mainInput/TipTapEditor.tsx | 6 +++- gui/src/main.tsx | 13 +++++---- gui/src/redux/slices/stateSlice.ts | 4 +++ gui/src/redux/store.ts | 29 ++++++++++++++----- 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/gui/package-lock.json b/gui/package-lock.json index 7b3a6eaf8..eddc1266e 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -38,6 +38,7 @@ "react-syntax-highlighter": "^15.5.0", "react-tooltip": "^5.18.0", "redux-persist": "^6.0.0", + "redux-persist-transform-filter": "^0.0.22", "seti-file-icons": "^0.0.8", "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", @@ -4977,6 +4978,18 @@ "redux": ">4.0.0" } }, + "node_modules/redux-persist-transform-filter": { + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/redux-persist-transform-filter/-/redux-persist-transform-filter-0.0.22.tgz", + "integrity": "sha512-XtGN7UQ8w7b3qaxQfdYY1UmuYULqIIemD47IWxIyM8AOF48I6C74m9XxA7gQoC2nIi+rz4URi9Mye4fIbHhZPQ==", + "dependencies": { + "lodash": "^4.17.21" + }, + "peerDependencies": { + "redux": ">3.0.0", + "redux-persist": "^3.4.0 || ^4 || ^5 || ^6" + } + }, "node_modules/redux-thunk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.4.2.tgz", @@ -9391,6 +9404,14 @@ "integrity": "sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==", "requires": {} }, + "redux-persist-transform-filter": { + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/redux-persist-transform-filter/-/redux-persist-transform-filter-0.0.22.tgz", + "integrity": "sha512-XtGN7UQ8w7b3qaxQfdYY1UmuYULqIIemD47IWxIyM8AOF48I6C74m9XxA7gQoC2nIi+rz4URi9Mye4fIbHhZPQ==", + "requires": { + "lodash": "^4.17.21" + } + }, "redux-thunk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.4.2.tgz", diff --git a/gui/package.json b/gui/package.json index 25783bbe4..7d6cb128e 100644 --- a/gui/package.json +++ b/gui/package.json @@ -39,6 +39,7 @@ "react-syntax-highlighter": "^15.5.0", "react-tooltip": "^5.18.0", "redux-persist": "^6.0.0", + "redux-persist-transform-filter": "^0.0.22", "seti-file-icons": "^0.0.8", "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 989a8e73f..e397997d4 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -222,7 +222,11 @@ function TipTapEditor(props: TipTapEditorProps) { // Search for slashcommand type for (const p of json.content) { - if (p.type !== "paragraph") { + if ( + p.type !== "paragraph" || + !p.content || + typeof p.content === "string" + ) { continue; } for (const node of p.content) { diff --git a/gui/src/main.tsx b/gui/src/main.tsx index 1688d937e..2e7514cd0 100644 --- a/gui/src/main.tsx +++ b/gui/src/main.tsx @@ -3,9 +3,10 @@ import ReactDOM from "react-dom/client"; import { Provider } from "react-redux"; import App from "./App"; import "./index.css"; -import { store } from "./redux/store"; +import { persistor, store } from "./redux/store"; import { proxyFetch } from "core/util"; +import { PersistGate } from "redux-persist/integration/react"; import CustomPostHogProvider from "./hooks/CustomPostHogProvider"; (window as any)._fetch = window.fetch; @@ -14,11 +15,11 @@ window.fetch = proxyFetch; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - {/* */} - - - - {/* */} + + + + + ); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 762c6eead..0a7866da8 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -116,6 +116,10 @@ export const stateSlice = createSlice({ }; }, addLogs: (state, { payload }: { payload: [string, string][] }) => { + if (state.history.length === 0) { + return; + } + if (state.history[state.history.length - 1].promptLogs) { state.history[state.history.length - 1].promptLogs.push(...payload); } else { diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 9412ce406..a62b93a43 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -12,7 +12,9 @@ import { ContinueConfig, SlashCommandDescription, } from "core"; -import { createTransform } from "redux-persist"; +import { createTransform, persistReducer, persistStore } from "redux-persist"; +import { createFilter } from "redux-persist-transform-filter"; +import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2"; import storage from "redux-persist/lib/storage"; export interface ChatMessage { @@ -77,23 +79,34 @@ const windowIDTransform = (windowID) => } ); +const saveSubsetFilters = [ + createFilter("state", [ + "history", + "contextItems", + "sessionId", + "defaultModelTitle", + ]), +]; + const persistConfig = { key: "root", storage, - // transforms: [ - // windowIDTransform((window as any).windowId || "undefinedWindowId"), - // ], + transforms: [ + ...saveSubsetFilters, + // windowIDTransform((window as any).windowId || "undefinedWindowId"), + ], + stateReconciler: autoMergeLevel2, }; -// const persistedReducer = persistReducer(persistConfig, rootReducer); +const persistedReducer = persistReducer(persistConfig, rootReducer); export const store = configureStore({ - // reducer: persistedReducer, - reducer: rootReducer, + reducer: persistedReducer, + // reducer: rootReducer, middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false, }), }); -// export const persistor = persistStore(store); +export const persistor = persistStore(store);