( event: ActionEvent, conversationId: string, queryClient: QueryClient, )
| 16 | * @param queryClient - The TanStack Query client instance |
| 17 | */ |
| 18 | export const handleActionEventCacheInvalidation = ( |
| 19 | event: ActionEvent, |
| 20 | conversationId: string, |
| 21 | queryClient: QueryClient, |
| 22 | ) => { |
| 23 | const { action } = event; |
| 24 | |
| 25 | // Invalidate file_changes cache for file-related actions |
| 26 | if ( |
| 27 | action.kind === "StrReplaceEditorAction" || |
| 28 | action.kind === "FileEditorAction" || |
| 29 | action.kind === "ExecuteBashAction" |
| 30 | ) { |
| 31 | queryClient.invalidateQueries( |
| 32 | { |
| 33 | queryKey: ["file_changes", conversationId], |
| 34 | }, |
| 35 | { cancelRefetch: false }, |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | // Invalidate specific file diff cache for file modifications |
| 40 | if ( |
| 41 | (action.kind === "StrReplaceEditorAction" || |
| 42 | action.kind === "FileEditorAction") && |
| 43 | action.path |
| 44 | ) { |
| 45 | const strippedPath = stripWorkspacePrefix(action.path); |
| 46 | queryClient.invalidateQueries({ |
| 47 | queryKey: ["file_diff", conversationId, strippedPath], |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | // When the agent autonomously swaps the LLM via SwitchLLMTool, refresh the |
| 52 | // conversation so SwitchProfileButton / ChatInputModel pick up the new |
| 53 | // `llm_model`, and drop any previously-set optimistic profile name (it |
| 54 | // would now misrepresent the agent's choice). |
| 55 | if (event.tool_name === "SwitchLLMTool") { |
| 56 | queryClient.invalidateQueries({ |
| 57 | queryKey: ["user", "conversation", conversationId], |
| 58 | }); |
| 59 | useModelStore.getState().clearActiveProfile(conversationId); |
| 60 | } |
| 61 | }; |
no test coverage detected