diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index fa85427e5..7027ac54c 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -3,6 +3,8 @@ import { JSONContent } from "@tiptap/react"; import { ChatHistoryItem, ChatMessage, + Checkpoint, + ContextItemId, ContextItemWithId, IndexingStatus, PersistedSessionInfo, @@ -12,13 +14,13 @@ import { BrowserSerializedContinueConfig } from "core/config/load"; import { ConfigValidationError } from "core/config/validation"; import { stripImages } from "core/llm/images"; import { v4 as uuidv4, v4 } from "uuid"; +import { ApplyState } from "core/protocol/ideWebview"; // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. type ChatHistoryItemWithMessageId = ChatHistoryItem & { message: ChatMessage & { id: string }; }; - type State = { history: ChatHistoryItemWithMessageId[]; ttsActive: boolean; @@ -31,8 +33,12 @@ type State = { mainEditorContent?: JSONContent; selectedProfileId: string; configError: ConfigValidationError[] | undefined; - isInMultifileEdit: boolean; - indexingStatuses: { [id: string]: IndexingStatus }; + checkpoints: Checkpoint[]; + curCheckpointIndex: number; + isMultifileEdit: boolean; + applyStates: ApplyState[]; + nextCodeBlockToApplyIndex: number; + indexingStatuses: Record; }; const initialState: State = { @@ -59,7 +65,11 @@ const initialState: State = { sessionId: v4(), defaultModelTitle: "GPT-4", selectedProfileId: "local", - isInMultifileEdit: false, + checkpoints: [], + isMultifileEdit: false, + curCheckpointIndex: 0, + nextCodeBlockToApplyIndex: 0, + applyStates: [], indexingStatuses: {}, }; @@ -187,6 +197,7 @@ export const stateSlice = createSlice({ }); state.active = true; + state.curCheckpointIndex = state.curCheckpointIndex + 1; }, setMessageAtIndex: ( state, @@ -253,12 +264,15 @@ export const stateSlice = createSlice({ state.history = payload.history as any; state.title = payload.title; state.sessionId = payload.sessionId; + state.checkpoints = payload.checkpoints; + state.curCheckpointIndex = 0; } else { state.history = []; state.active = false; state.title = "New Session"; state.sessionId = v4(); - state.isInMultifileEdit = false; + state.checkpoints = []; + state.curCheckpointIndex = 0; } }, addHighlightedCode: ( @@ -311,17 +325,51 @@ export const stateSlice = createSlice({ selectedProfileId: payload, }; }, - setIsInMultifileEdit: (state, action: PayloadAction) => { - state.isInMultifileEdit = action.payload; + + setIsInMultifileEdit: (state, { payload }: PayloadAction) => { + state.isMultifileEdit = payload; }, - updateIndexingStatus: (state, action: PayloadAction) => { - console.log("update indexing status"); + setCurCheckpointIndex: (state, { payload }: PayloadAction) => { + state.curCheckpointIndex = payload; + }, + updateCurCheckpoint: ( + state, + { payload }: PayloadAction<{ filepath: string; content: string }>, + ) => { + state.checkpoints[state.curCheckpointIndex] = { + ...state.checkpoints[state.curCheckpointIndex], + [payload.filepath]: payload.content, + }; + }, + updateApplyState: (state, { payload }: PayloadAction) => { + const index = state.applyStates.findIndex( + (applyState) => applyState.streamId === payload.streamId, + ); + + const curApplyState = state.applyStates[index]; + + if (index === -1) { + state.applyStates.push(payload); + } else { + curApplyState.status = payload.status ?? curApplyState.status; + curApplyState.numDiffs = payload.numDiffs ?? curApplyState.numDiffs; + curApplyState.filepath = payload.filepath ?? curApplyState.filepath; + } + if (payload.status === "done") { + state.nextCodeBlockToApplyIndex++; + } + }, + resetNextCodeBlockToApplyIndex: (state) => { + state.nextCodeBlockToApplyIndex = 0; + }, + updateIndexingStatus: ( + state, + { payload }: PayloadAction, + ) => { state.indexingStatuses = { ...state.indexingStatuses, - [action.payload.id]: action.payload, + [payload.id]: payload, }; - // consider only overwriting the one that changed - // depends on how watching }, }, }); @@ -348,6 +396,10 @@ export const { deleteMessage, setIsGatheringContext, setIsInMultifileEdit, + updateCurCheckpoint, + setCurCheckpointIndex, + resetNextCodeBlockToApplyIndex, + updateApplyState, updateIndexingStatus, } = stateSlice.actions;