@@ -314,30 +314,36 @@ export function renderAgentTypeButtons(
314314export function createAgentTypeSelectionHandler (
315315 element : HTMLElement ,
316316 textInputElement : HTMLTextAreaElement | undefined ,
317- onAgentTypeSelected : ( ( agentType : string ) => void ) | undefined ,
318- setSelectedAgentType : ( type : string ) => void
317+ onAgentTypeSelected : ( ( agentType : string | null ) => void ) | undefined ,
318+ setSelectedAgentType : ( type : string | null ) => void ,
319+ getCurrentSelectedType : ( ) => string | null
319320) : ( event : Event ) => void {
320321 return ( event : Event ) : void => {
321322 const button = event . currentTarget as HTMLButtonElement ;
322323 const agentType = button . dataset . agentType ;
323324 if ( agentType && onAgentTypeSelected ) {
325+ const currentSelected = getCurrentSelectedType ( ) ;
326+
324327 // Remove selected class from all agent type buttons
325- const allButtons = element . shadowRoot ?. querySelectorAll ( '.agent-type -button' ) ;
328+ const allButtons = element . shadowRoot ?. querySelectorAll ( '.prompt -button' ) ;
326329 allButtons ?. forEach ( btn => btn . classList . remove ( 'selected' ) ) ;
327330
328- // Add selected class to the clicked button
329- button . classList . add ( 'selected' ) ;
330-
331- // Update the selected agent type
332- setSelectedAgentType ( agentType ) ;
333-
334- // Call the handler passed via props
335- onAgentTypeSelected ( agentType ) ;
336-
337- // Focus the input after selecting an agent type
331+ // Check if we're clicking on the currently selected button (toggle off)
332+ if ( currentSelected === agentType ) {
333+ // Deselect - set to null and don't add selected class
334+ setSelectedAgentType ( null ) ;
335+ onAgentTypeSelected ( null ) ;
336+ console . log ( 'Deselected agent type, returning to default' ) ;
337+ } else {
338+ // Select new agent type - add selected class to clicked button
339+ button . classList . add ( 'selected' ) ;
340+ setSelectedAgentType ( agentType ) ;
341+ onAgentTypeSelected ( agentType ) ;
342+ console . log ( 'Selected agent type:' , agentType ) ;
343+ }
344+
345+ // Focus the input after selecting/deselecting an agent type
338346 textInputElement ?. focus ( ) ;
339-
340- console . log ( 'Selected agent type:' , agentType ) ;
341347 }
342348 } ;
343349}
0 commit comments