From 1b97cf369b7f7b0cebea49a5c4bdd8c02fc2b3d9 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 12 Feb 2025 16:10:02 -0800 Subject: [PATCH 1/2] new history items at index 0 --- gui/src/redux/slices/sessionSlice.ts | 6 +++--- gui/src/redux/thunks/streamResponse.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index fa6cfb03c..5ee87d44c 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( @@ -260,7 +260,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( From de3636ddaee279c40165ade0f48d071c1716eee8 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 12 Feb 2025 16:17:43 -0800 Subject: [PATCH 2/2] clear context items on resubmit --- gui/src/redux/slices/sessionSlice.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 5ee87d44c..101177b2a 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -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: {