diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 510733da93f..2d3413327c0 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -22,7 +22,10 @@ import { setTTSActive } from "../redux/slices/uiSlice"; import { modelSupportsReasoning } from "core/llm/autodetect"; import { cancelStream } from "../redux/thunks/cancelStream"; import { handleApplyStateUpdate } from "../redux/thunks/handleApplyStateUpdate"; -import { refreshSessionMetadata } from "../redux/thunks/session"; +import { + loadLastSession, + refreshSessionMetadata, +} from "../redux/thunks/session"; import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols"; import { setDocumentStylesFromLocalStorage, @@ -240,6 +243,10 @@ function ParallelListeners() { migrateLocalStorage(dispatch); }, []); + useEffect(() => { + void dispatch(loadLastSession()); + }, []); + return <>; } diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 08ca69498ea..f7e9c308dc0 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -43,14 +43,14 @@ import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; import { ToolCallDiv } from "./ToolCallDiv"; +import { useStore } from "react-redux"; import { FatalErrorIndicator } from "../../components/config/FatalErrorNotice"; import InlineErrorMessage from "../../components/mainInput/InlineErrorMessage"; +import { RootState } from "../../redux/store"; import { cancelStream } from "../../redux/thunks/cancelStream"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { useAutoScroll } from "./useAutoScroll"; -import { useStore } from "react-redux"; -import { RootState } from "../../redux/store"; // Helper function to find the index of the latest conversation summary function findLatestSummaryIndex(history: ChatHistoryItem[]): number { @@ -431,11 +431,7 @@ export function Chat() { {history.length === 0 && lastSessionId && !isInEdit && ( { - await dispatch( - loadLastSession({ - saveCurrentSession: true, - }), - ); + await dispatch(loadLastSession()); }} className="flex items-center gap-2" > diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 0bd38f1fd0d..8ffb22dc2cb 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -4,7 +4,6 @@ import { ThunkDispatch, UnknownAction, } from "@reduxjs/toolkit"; -import { createLogger } from "redux-logger"; import { createMigrate, MigrationManifest, @@ -35,9 +34,7 @@ const rootReducer = combineReducers({ const saveSubsetFilters = [ createFilter("session", [ - "history", "id", - "lastSessionId", "title", // Persist edit mode in case closes in middle @@ -73,7 +70,6 @@ const migrations: MigrationManifest = { defaultModelTitle: oldState?.state?.defaultModelTitle ?? undefined, }, session: { - history: oldState?.state?.history ?? [], id: oldState?.state?.sessionId ?? "", }, tabs: { @@ -108,13 +104,6 @@ const persistedReducer = persistReducer>( export function setupStore(options: { ideMessenger?: IIdeMessenger }) { const ideMessenger = options.ideMessenger ?? new IdeMessenger(); - const logger = createLogger({ - // Customize logger options if needed - collapsed: true, // Collapse console groups by default - timestamp: false, // Remove timestamps from log - diff: true, // Show diff between states - }); - return configureStore({ // persistedReducer causes type errors with async thunks reducer: persistedReducer as unknown as typeof rootReducer, diff --git a/gui/src/redux/thunks/edit.ts b/gui/src/redux/thunks/edit.ts index 700d49d5587..c2192ab9e7c 100644 --- a/gui/src/redux/thunks/edit.ts +++ b/gui/src/redux/thunks/edit.ts @@ -109,11 +109,7 @@ export const exitEdit = createAsyncThunk< if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { dispatch(newSession()); } else { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); + await dispatch(loadLastSession()); } dispatch(setMode(state.editModeState.returnToMode)); diff --git a/gui/src/redux/thunks/session.ts b/gui/src/redux/thunks/session.ts index c2fe35c36e3..5fadfb68583 100644 --- a/gui/src/redux/thunks/session.ts +++ b/gui/src/redux/thunks/session.ts @@ -1,5 +1,5 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; -import { ChatMessage, Session, BaseSessionMetadata } from "core"; +import { BaseSessionMetadata, ChatMessage, Session } from "core"; import { RemoteSessionMetadata } from "core/control-plane/client"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { renderChatMessage } from "core/util/messageContent"; @@ -67,11 +67,7 @@ export const deleteSession = createAsyncThunk( dispatch(deleteSessionMetadata(id)); // optimistic const state = getState(); if (id === state.session.id) { - await dispatch( - loadLastSession({ - saveCurrentSession: false, - }), - ); + await dispatch(loadLastSession()); } const result = await extra.ideMessenger.request("history/delete", { id }); if (result.status === "error") { @@ -146,20 +142,17 @@ export const loadRemoteSession = createAsyncThunk< }, ); -export const loadLastSession = createAsyncThunk< - void, - { - saveCurrentSession: boolean; - }, - ThunkApiType ->( +export const loadLastSession = createAsyncThunk( "session/loadLast", - async ({ saveCurrentSession }, { extra, dispatch, getState }) => { - const state = getState(); - - if (state.session.id && saveCurrentSession) { + async (_, { extra, dispatch, getState }) => { + let lastSessionId = getState().session.lastSessionId; + + const lastSessionResult = await extra.ideMessenger.request("history/list", { + limit: 1, + }); + if (lastSessionResult.status === "success") { + lastSessionId = lastSessionResult.content.at(0)?.sessionId; } - const lastSessionId = getState().session.lastSessionId; if (!lastSessionId) { dispatch(newSession());