Merge pull request #4120 from continuedev/dallin/chat-bugs

Message Resubmission bugs
This commit is contained in:
Nate Sesti 2025-02-13 07:49:53 -08:00 • committed by GitHub
commit 79070a5548
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

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

View file

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