🚸 persist current session and model

This commit is contained in:
Nate Sesti 2023-12-27 17:42:08 -05:00
parent 3aa5b68747
commit 89e68b4d39
6 changed files with 59 additions and 15 deletions

21
gui/package-lock.json generated
View file

@ -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",

View file

@ -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",

View file

@ -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) {

View file

@ -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(
<React.StrictMode>
<Provider store={store}>
{/* <PersistGate loading={null} persistor={persistor}> */}
<CustomPostHogProvider>
<App />
</CustomPostHogProvider>
{/* </PersistGate> */}
<PersistGate loading={null} persistor={persistor}>
<CustomPostHogProvider>
<App />
</CustomPostHogProvider>
</PersistGate>
</Provider>
</React.StrictMode>
);

View file

@ -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 {

View file

@ -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);