diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index fa6cfb03c..101177b2a 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -191,13 +191,13 @@ export const sessionSlice = createSlice({ { payload, }: PayloadAction<{ - index?: number; + index: number; editorState: JSONContent; }>, ) => { const { index, editorState } = payload; - if (typeof index === "number" && index < state.history.length) { + if (state.history.length && index < state.history.length) { // Resubmission - update input message, truncate history after resubmit with new empty response message if (index % 2 === 1) { console.warn( @@ -208,6 +208,7 @@ export const sessionSlice = createSlice({ historyItem.message.content = ""; // IMPORTANT - this is quickly updated by resolveEditorContent based on editor state prior to streaming historyItem.editorState = payload.editorState; + historyItem.contextItems = []; state.history = state.history.slice(0, index + 1).concat({ message: { @@ -260,7 +261,7 @@ export const sessionSlice = createSlice({ }>, ) => { const { index, updates } = payload; - if (!state.history[index]) { + if (index !== 0 && !state.history[index]) { console.error( `attempting to update history item at nonexistent index ${index}`, updates, diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index 1c191b662..e30fd63f7 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -74,13 +74,15 @@ export const streamResponseThunk = createAsyncThunk< const useTools = state.ui.useTools; const defaultModel = selectDefaultModel(state); const slashCommands = state.config.config.slashCommands || []; - const inputIndex = index ?? state.session.history.length; + const inputIndex = index ?? state.session.history.length; // Either given index or concat to end if (!defaultModel) { throw new Error("No chat model selected"); } - dispatch(submitEditorAndInitAtIndex({ index, editorState })); + dispatch( + submitEditorAndInitAtIndex({ index: inputIndex, editorState }), + ); resetStateForNewMessage(); const result = await dispatch(