@@ -8,6 +8,7 @@ import { MessageModes } from "core";
88import { isRecommendedAgentModel } from "core/llm/toolSupport" ;
99import { capitalize } from "lodash" ;
1010import { useCallback , useEffect , useMemo } from "react" ;
11+ import { useAuth } from "../../context/Auth" ;
1112import { useAppDispatch , useAppSelector } from "../../redux/hooks" ;
1213import { selectSelectedChatModel } from "../../redux/slices/configSlice" ;
1314import { setMode } from "../../redux/slices/sessionSlice" ;
@@ -21,6 +22,7 @@ export function ModeSelect() {
2122 const dispatch = useAppDispatch ( ) ;
2223 const mode = useAppSelector ( ( store ) => store . session . mode ) ;
2324 const selectedModel = useAppSelector ( selectSelectedChatModel ) ;
25+ const { selectedProfile } = useAuth ( ) ;
2426
2527 const isGoodAtAgentMode = useMemo ( ( ) => {
2628 if ( ! selectedModel ) {
@@ -29,6 +31,10 @@ export function ModeSelect() {
2931 return isRecommendedAgentModel ( selectedModel . model ) ;
3032 } , [ selectedModel ] ) ;
3133
34+ const isLocalAgent = useMemo ( ( ) => {
35+ return selectedProfile ?. profileType === "local" ;
36+ } , [ selectedProfile ] ) ;
37+
3238 const { mainEditor } = useMainEditor ( ) ;
3339 const metaKeyLabel = useMemo ( ( ) => {
3440 return getMetaKeyLabel ( ) ;
@@ -40,15 +46,16 @@ export function ModeSelect() {
4046 } else if ( mode === "plan" ) {
4147 dispatch ( setMode ( "agent" ) ) ;
4248 } else if ( mode === "agent" ) {
43- dispatch ( setMode ( "background" ) ) ;
49+ // Skip background mode if local agent is selected
50+ dispatch ( setMode ( isLocalAgent ? "chat" : "background" ) ) ;
4451 } else {
4552 dispatch ( setMode ( "chat" ) ) ;
4653 }
4754 // Only focus main editor if another one doesn't already have focus
4855 if ( ! document . activeElement ?. classList ?. contains ( "ProseMirror" ) ) {
4956 mainEditor ?. commands . focus ( ) ;
5057 }
51- } , [ mode , mainEditor ] ) ;
58+ } , [ mode , mainEditor , isLocalAgent ] ) ;
5259
5360 const selectMode = useCallback (
5461 ( newMode : MessageModes ) => {
@@ -75,6 +82,13 @@ export function ModeSelect() {
7582 return ( ) => document . removeEventListener ( "keydown" , handleKeyDown ) ;
7683 } , [ cycleMode ] ) ;
7784
85+ // Auto-switch from background mode when local agent is selected
86+ useEffect ( ( ) => {
87+ if ( mode === "background" && isLocalAgent ) {
88+ dispatch ( setMode ( "agent" ) ) ;
89+ }
90+ } , [ mode , isLocalAgent , dispatch ] ) ;
91+
7892 const notGreatAtAgent = (
7993 < >
8094 < ToolTip
@@ -173,19 +187,26 @@ export function ModeSelect() {
173187 />
174188 </ ListboxOption >
175189
176- < ListboxOption value = "background" className = { "gap-1" } >
190+ < ListboxOption
191+ value = "background"
192+ className = { "gap-1" }
193+ disabled = { isLocalAgent }
194+ >
177195 < div className = "flex flex-row items-center gap-1.5" >
178196 < ModeIcon mode = "background" />
179197 < span className = "" > Background</ span >
180198 < ToolTip
181199 style = { {
182200 zIndex : 200001 ,
183201 } }
184- content = "Trigger background agents"
202+ content = { "Background mode cannot be used with local agents." }
185203 >
186204 < InformationCircleIcon className = "h-2.5 w-2.5 flex-shrink-0" />
187205 </ ToolTip >
188206 </ div >
207+ { isLocalAgent && (
208+ < ExclamationTriangleIcon className = "text-warning h-2.5 w-2.5" />
209+ ) }
189210 < CheckIcon
190211 className = { `ml-auto h-3 w-3 ${ mode === "background" ? "" : "opacity-0" } ` }
191212 />
0 commit comments