@@ -49,6 +49,8 @@ import { cancelStream } from "../../redux/thunks/cancelStream";
49
49
import { EmptyChatBody } from "./EmptyChatBody" ;
50
50
import { ExploreDialogWatcher } from "./ExploreDialogWatcher" ;
51
51
import { useAutoScroll } from "./useAutoScroll" ;
52
+ import { useStore } from "react-redux" ;
53
+ import { RootState } from "../../redux/store" ;
52
54
53
55
// Helper function to find the index of the latest conversation summary
54
56
function findLatestSummaryIndex ( history : ChatHistoryItem [ ] ) : number {
@@ -98,13 +100,11 @@ function fallbackRender({ error, resetErrorBoundary }: any) {
98
100
export function Chat ( ) {
99
101
const dispatch = useAppDispatch ( ) ;
100
102
const ideMessenger = useContext ( IdeMessengerContext ) ;
103
+ const reduxStore = useStore < RootState > ( ) ;
101
104
const onboardingCard = useOnboardingCard ( ) ;
102
105
const showSessionTabs = useAppSelector (
103
106
( store ) => store . config . config . ui ?. showSessionTabs ,
104
107
) ;
105
- const selectedModels = useAppSelector (
106
- ( store ) => store . config ?. config . selectedModelByRole ,
107
- ) ;
108
108
const isStreaming = useAppSelector ( ( state ) => state . session . isStreaming ) ;
109
109
const [ stepsOpen ] = useState < ( boolean | undefined ) [ ] > ( [ ] ) ;
110
110
const mainTextInputRef = useRef < HTMLInputElement > ( null ) ;
@@ -115,7 +115,6 @@ export function Chat() {
115
115
( state ) => state . config . config . ui ?. showChatScrollbar ,
116
116
) ;
117
117
const codeToEdit = useAppSelector ( ( state ) => state . editModeState . codeToEdit ) ;
118
- const mode = useAppSelector ( ( store ) => store . session . mode ) ;
119
118
const isInEdit = useAppSelector ( ( store ) => store . session . isInEdit ) ;
120
119
121
120
const lastSessionId = useAppSelector ( ( state ) => state . session . lastSessionId ) ;
@@ -152,18 +151,23 @@ export function Chat() {
152
151
isStreaming ,
153
152
) ;
154
153
155
- const pendingToolCalls = useAppSelector ( selectPendingToolCalls ) ;
156
- const pendingApplyStates = useAppSelector ( selectDoneApplyStates ) ;
157
-
158
154
const sendInput = useCallback (
159
155
(
160
156
editorState : JSONContent ,
161
157
modifiers : InputModifiers ,
162
158
index ?: number ,
163
159
editorToClearOnSend ?: Editor ,
164
160
) => {
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
+
165
169
// Cancel all pending tool calls
166
- pendingToolCalls . forEach ( ( toolCallState ) => {
170
+ latestPendingToolCalls . forEach ( ( toolCallState ) => {
167
171
dispatch (
168
172
cancelToolCall ( {
169
173
toolCallId : toolCallState . toolCallId ,
@@ -172,19 +176,20 @@ export function Chat() {
172
176
} ) ;
173
177
174
178
// Reject all pending apply states
175
- pendingApplyStates . forEach ( ( applyState ) => {
179
+ latestPendingApplyStates . forEach ( ( applyState ) => {
176
180
if ( applyState . status !== "closed" ) {
177
181
ideMessenger . post ( "rejectDiff" , applyState ) ;
178
182
}
179
183
} ) ;
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
+
183
188
if ( ! model ) {
184
189
return ;
185
190
}
186
191
187
- if ( isInEdit && codeToEdit . length === 0 ) {
192
+ if ( isCurrentlyInEdit && codeToEditSnapshot . length === 0 ) {
188
193
return ;
189
194
}
190
195
@@ -212,11 +217,11 @@ export function Chat() {
212
217
// }
213
218
// }
214
219
215
- if ( isInEdit ) {
220
+ if ( isCurrentlyInEdit ) {
216
221
void dispatch (
217
222
streamEditThunk ( {
218
223
editorState,
219
- codeToEdit,
224
+ codeToEdit : codeToEditSnapshot ,
220
225
} ) ,
221
226
) ;
222
227
} else {
@@ -227,15 +232,7 @@ export function Chat() {
227
232
}
228
233
}
229
234
} ,
230
- [
231
- history ,
232
- selectedModels ,
233
- mode ,
234
- isInEdit ,
235
- codeToEdit ,
236
- pendingToolCalls ,
237
- pendingApplyStates ,
238
- ] ,
235
+ [ dispatch , ideMessenger , reduxStore ] ,
239
236
) ;
240
237
241
238
useWebviewListener (
0 commit comments