Skip to content

Commit 8677208

Browse files
committed
fix: tests
1 parent 62120df commit 8677208

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

gui/src/pages/gui/Chat.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import { cancelStream } from "../../redux/thunks/cancelStream";
4949
import { EmptyChatBody } from "./EmptyChatBody";
5050
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
5151
import { useAutoScroll } from "./useAutoScroll";
52+
import { useStore } from "react-redux";
53+
import { RootState } from "../../redux/store";
5254

5355
// Helper function to find the index of the latest conversation summary
5456
function findLatestSummaryIndex(history: ChatHistoryItem[]): number {
@@ -98,13 +100,11 @@ function fallbackRender({ error, resetErrorBoundary }: any) {
98100
export function Chat() {
99101
const dispatch = useAppDispatch();
100102
const ideMessenger = useContext(IdeMessengerContext);
103+
const reduxStore = useStore<RootState>();
101104
const onboardingCard = useOnboardingCard();
102105
const showSessionTabs = useAppSelector(
103106
(store) => store.config.config.ui?.showSessionTabs,
104107
);
105-
const selectedModels = useAppSelector(
106-
(store) => store.config?.config.selectedModelByRole,
107-
);
108108
const isStreaming = useAppSelector((state) => state.session.isStreaming);
109109
const [stepsOpen] = useState<(boolean | undefined)[]>([]);
110110
const mainTextInputRef = useRef<HTMLInputElement>(null);
@@ -115,7 +115,6 @@ export function Chat() {
115115
(state) => state.config.config.ui?.showChatScrollbar,
116116
);
117117
const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit);
118-
const mode = useAppSelector((store) => store.session.mode);
119118
const isInEdit = useAppSelector((store) => store.session.isInEdit);
120119

121120
const lastSessionId = useAppSelector((state) => state.session.lastSessionId);
@@ -152,18 +151,23 @@ export function Chat() {
152151
isStreaming,
153152
);
154153

155-
const pendingToolCalls = useAppSelector(selectPendingToolCalls);
156-
const pendingApplyStates = useAppSelector(selectDoneApplyStates);
157-
158154
const sendInput = useCallback(
159155
(
160156
editorState: JSONContent,
161157
modifiers: InputModifiers,
162158
index?: number,
163159
editorToClearOnSend?: Editor,
164160
) => {
161+
const stateSnapshot = reduxStore.getState();
162+
const latestPendingToolCalls = selectPendingToolCalls(stateSnapshot);
163+
const latestPendingApplyStates = selectDoneApplyStates(stateSnapshot);
164+
const isCurrentlyInEdit = stateSnapshot.session.isInEdit;
165+
const codeToEditSnapshot = stateSnapshot.editModeState.codeToEdit;
166+
const selectedModelByRole =
167+
stateSnapshot.config.config.selectedModelByRole;
168+
165169
// Cancel all pending tool calls
166-
pendingToolCalls.forEach((toolCallState) => {
170+
latestPendingToolCalls.forEach((toolCallState) => {
167171
dispatch(
168172
cancelToolCall({
169173
toolCallId: toolCallState.toolCallId,
@@ -172,19 +176,20 @@ export function Chat() {
172176
});
173177

174178
// Reject all pending apply states
175-
pendingApplyStates.forEach((applyState) => {
179+
latestPendingApplyStates.forEach((applyState) => {
176180
if (applyState.status !== "closed") {
177181
ideMessenger.post("rejectDiff", applyState);
178182
}
179183
});
180-
const model = isInEdit
181-
? (selectedModels?.edit ?? selectedModels?.chat)
182-
: selectedModels?.chat;
184+
const model = isCurrentlyInEdit
185+
? selectedModelByRole.edit ?? selectedModelByRole.chat
186+
: selectedModelByRole.chat;
187+
183188
if (!model) {
184189
return;
185190
}
186191

187-
if (isInEdit && codeToEdit.length === 0) {
192+
if (isCurrentlyInEdit && codeToEditSnapshot.length === 0) {
188193
return;
189194
}
190195

@@ -212,11 +217,11 @@ export function Chat() {
212217
// }
213218
// }
214219

215-
if (isInEdit) {
220+
if (isCurrentlyInEdit) {
216221
void dispatch(
217222
streamEditThunk({
218223
editorState,
219-
codeToEdit,
224+
codeToEdit: codeToEditSnapshot,
220225
}),
221226
);
222227
} else {
@@ -227,15 +232,7 @@ export function Chat() {
227232
}
228233
}
229234
},
230-
[
231-
history,
232-
selectedModels,
233-
mode,
234-
isInEdit,
235-
codeToEdit,
236-
pendingToolCalls,
237-
pendingApplyStates,
238-
],
235+
[dispatch, ideMessenger, reduxStore],
239236
);
240237

241238
useWebviewListener(

packages/openai-adapters/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)