11import { useCallback , useContext , useEffect , useRef } from "react" ;
22import { IdeMessengerContext } from "../context/IdeMessenger" ;
33
4- import { EDIT_MODE_STREAM_ID } from "core/edit/constants" ;
54import { FromCoreProtocol } from "core/protocol" ;
65import { useAppDispatch , useAppSelector } from "../redux/hooks" ;
76import { setConfigLoading , setConfigResult } from "../redux/slices/configSlice" ;
8- import {
9- setLastNonEditSessionEmpty ,
10- updateEditStateApplyState ,
11- } from "../redux/slices/editState" ;
7+ import { setLastNonEditSessionEmpty } from "../redux/slices/editState" ;
128import { updateIndexingStatus } from "../redux/slices/indexingSlice" ;
139import {
1410 initializeProfilePreferences ,
@@ -17,27 +13,21 @@ import {
1713 setSelectedProfile ,
1814} from "../redux/slices/profilesSlice" ;
1915import {
20- acceptToolCall ,
2116 addContextItemsAtIndex ,
2217 setHasReasoningEnabled ,
2318 setIsSessionMetadataLoading ,
24- updateApplyState ,
2519} from "../redux/slices/sessionSlice" ;
2620import { setTTSActive } from "../redux/slices/uiSlice" ;
27- import { exitEdit } from "../redux/thunks/edit" ;
28- import { streamResponseAfterToolCall } from "../redux/thunks/streamResponseAfterToolCall" ;
2921
30- import { store } from "../redux/store" ;
3122import { cancelStream } from "../redux/thunks/cancelStream" ;
23+ import { handleApplyStateUpdate } from "../redux/thunks/handleApplyStateUpdate" ;
3224import { refreshSessionMetadata } from "../redux/thunks/session" ;
3325import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols" ;
34- import { findToolCallById , logToolUsage } from "../redux/util" ;
3526import {
3627 setDocumentStylesFromLocalStorage ,
3728 setDocumentStylesFromTheme ,
3829} from "../styles/theme" ;
3930import { isJetBrains } from "../util" ;
40- import { logAgentModeEditOutcome } from "../util/editOutcomeLogger" ;
4131import { setLocalStorage } from "../util/localStorage" ;
4232import { migrateLocalStorage } from "../util/migrateLocalStorage" ;
4333import { useWebviewListener } from "./useWebviewListener" ;
@@ -51,9 +41,7 @@ function ParallelListeners() {
5141 ( store ) => store . profiles . selectedProfileId ,
5242 ) ;
5343 const hasDoneInitialConfigLoad = useRef ( false ) ;
54- const autoAcceptEditToolDiffs = useAppSelector (
55- ( store ) => store . config . config . ui ?. autoAcceptEditToolDiffs ,
56- ) ;
44+
5745 // Load symbols for chat on any session change
5846 const sessionId = useAppSelector ( ( state ) => state . session . id ) ;
5947
@@ -235,83 +223,9 @@ function ParallelListeners() {
235223 useWebviewListener (
236224 "updateApplyState" ,
237225 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 ) ) ;
313227 } ,
314- [ autoAcceptEditToolDiffs , ideMessenger ] ,
228+ [ ] ,
315229 ) ;
316230
317231 useEffect ( ( ) => {
0 commit comments