1
1
import { useCallback , useContext , useEffect , useRef } from "react" ;
2
2
import { IdeMessengerContext } from "../context/IdeMessenger" ;
3
3
4
- import { EDIT_MODE_STREAM_ID } from "core/edit/constants" ;
5
4
import { FromCoreProtocol } from "core/protocol" ;
6
5
import { useAppDispatch , useAppSelector } from "../redux/hooks" ;
7
6
import { setConfigLoading , setConfigResult } from "../redux/slices/configSlice" ;
8
- import {
9
- setLastNonEditSessionEmpty ,
10
- updateEditStateApplyState ,
11
- } from "../redux/slices/editState" ;
7
+ import { setLastNonEditSessionEmpty } from "../redux/slices/editState" ;
12
8
import { updateIndexingStatus } from "../redux/slices/indexingSlice" ;
13
9
import {
14
10
initializeProfilePreferences ,
@@ -17,27 +13,21 @@ import {
17
13
setSelectedProfile ,
18
14
} from "../redux/slices/profilesSlice" ;
19
15
import {
20
- acceptToolCall ,
21
16
addContextItemsAtIndex ,
22
17
setHasReasoningEnabled ,
23
18
setIsSessionMetadataLoading ,
24
- updateApplyState ,
25
19
} from "../redux/slices/sessionSlice" ;
26
20
import { setTTSActive } from "../redux/slices/uiSlice" ;
27
- import { exitEdit } from "../redux/thunks/edit" ;
28
- import { streamResponseAfterToolCall } from "../redux/thunks/streamResponseAfterToolCall" ;
29
21
30
- import { store } from "../redux/store" ;
31
22
import { cancelStream } from "../redux/thunks/cancelStream" ;
23
+ import { handleApplyStateUpdate } from "../redux/thunks/handleApplyStateUpdate" ;
32
24
import { refreshSessionMetadata } from "../redux/thunks/session" ;
33
25
import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols" ;
34
- import { findToolCallById , logToolUsage } from "../redux/util" ;
35
26
import {
36
27
setDocumentStylesFromLocalStorage ,
37
28
setDocumentStylesFromTheme ,
38
29
} from "../styles/theme" ;
39
30
import { isJetBrains } from "../util" ;
40
- import { logAgentModeEditOutcome } from "../util/editOutcomeLogger" ;
41
31
import { setLocalStorage } from "../util/localStorage" ;
42
32
import { migrateLocalStorage } from "../util/migrateLocalStorage" ;
43
33
import { useWebviewListener } from "./useWebviewListener" ;
@@ -51,9 +41,7 @@ function ParallelListeners() {
51
41
( store ) => store . profiles . selectedProfileId ,
52
42
) ;
53
43
const hasDoneInitialConfigLoad = useRef ( false ) ;
54
- const autoAcceptEditToolDiffs = useAppSelector (
55
- ( store ) => store . config . config . ui ?. autoAcceptEditToolDiffs ,
56
- ) ;
44
+
57
45
// Load symbols for chat on any session change
58
46
const sessionId = useAppSelector ( ( state ) => state . session . id ) ;
59
47
@@ -235,83 +223,9 @@ function ParallelListeners() {
235
223
useWebviewListener (
236
224
"updateApplyState" ,
237
225
async ( state ) => {
238
- if ( state . streamId === EDIT_MODE_STREAM_ID ) {
239
- dispatch ( updateEditStateApplyState ( state ) ) ;
240
-
241
- if ( state . status === "closed" ) {
242
- const toolCallState = findToolCallById (
243
- store . getState ( ) . session . history ,
244
- state . toolCallId ! ,
245
- ) ;
246
- if ( toolCallState ) {
247
- logToolUsage ( toolCallState , true , true , ideMessenger ) ;
248
- }
249
- void dispatch ( exitEdit ( { } ) ) ;
250
- }
251
- } else {
252
- // chat or agent
253
- dispatch ( updateApplyState ( state ) ) ;
254
-
255
- // Handle apply status updates - use toolCallId from event payload
256
- if ( state . toolCallId ) {
257
- if ( state . status === "done" && autoAcceptEditToolDiffs ) {
258
- ideMessenger . post ( "acceptDiff" , {
259
- streamId : state . streamId ,
260
- filepath : state . filepath ,
261
- } ) ;
262
- }
263
- if ( state . status === "closed" ) {
264
- // Find the tool call to check if it was canceled
265
- const toolCallState = findToolCallById (
266
- store . getState ( ) . session . history ,
267
- state . toolCallId ,
268
- ) ;
269
-
270
- if ( toolCallState ) {
271
- const accepted = toolCallState . status !== "canceled" ;
272
-
273
- logToolUsage ( toolCallState , accepted , true , ideMessenger ) ;
274
-
275
- // Log edit outcome for Agent Mode
276
- const applyState = store
277
- . getState ( )
278
- . session . codeBlockApplyStates . states . find (
279
- ( s ) => s . streamId === state . streamId ,
280
- ) ;
281
-
282
- if ( applyState ) {
283
- void logAgentModeEditOutcome (
284
- toolCallState ,
285
- applyState ,
286
- accepted ,
287
- ideMessenger ,
288
- ) ;
289
- }
290
-
291
- if ( accepted ) {
292
- dispatch (
293
- acceptToolCall ( {
294
- toolCallId : state . toolCallId ,
295
- } ) ,
296
- ) ;
297
- void dispatch (
298
- streamResponseAfterToolCall ( {
299
- toolCallId : state . toolCallId ,
300
- } ) ,
301
- ) ;
302
- }
303
- }
304
- // const output: ContextItem = {
305
- // name: "Edit tool output",
306
- // content: "Completed edit",
307
- // description: "",
308
- // };
309
- // dispatch(setToolCallOutput([]));
310
- }
311
- }
312
- }
226
+ void dispatch ( handleApplyStateUpdate ( state ) ) ;
313
227
} ,
314
- [ autoAcceptEditToolDiffs , ideMessenger ] ,
228
+ [ ] ,
315
229
) ;
316
230
317
231
useEffect ( ( ) => {
0 commit comments