@@ -68,6 +68,10 @@ const UIStrings = {
6868 *@description AI assistance UI text creating selecting a history entry.
6969 */
7070 history : 'History' ,
71+ /**
72+ *@description AI assistance UI text clearing the current chat session.
73+ */
74+ clearChat : 'Clear chat' ,
7175} ;
7276
7377/*
@@ -105,7 +109,8 @@ function selectedElementFilter(maybeNode: SDK.DOMModel.DOMNode|null): SDK.DOMMod
105109// TODO(ergunsh): Use the WidgetElement instead of separately creating the toolbar.
106110function createToolbar (
107111 target : HTMLElement ,
108- { onHistoryClick, onNewAgentClick} : { onHistoryClick : ( event : Event ) => void , onNewAgentClick : ( ) => void } ) : void {
112+ { onHistoryClick, onNewAgentClick, onDeleteClick} :
113+ { onHistoryClick : ( event : Event ) => void , onNewAgentClick : ( ) => void , onDeleteClick : ( ) => void } ) : void {
109114 const toolbarContainer = target . createChild ( 'div' , 'freestyler-toolbar-container' ) ;
110115 const leftToolbar = new UI . Toolbar . Toolbar ( 'freestyler-left-toolbar' , toolbarContainer ) ;
111116 const rightToolbar = new UI . Toolbar . Toolbar ( 'freestyler-right-toolbar' , toolbarContainer ) ;
@@ -121,6 +126,10 @@ function createToolbar(
121126 onHistoryClick ( event . data ) ;
122127 } ) ;
123128 leftToolbar . appendToolbarItem ( historyButton ) ;
129+ const deleteButton =
130+ new UI . Toolbar . ToolbarButton ( i18nString ( UIStrings . clearChat ) , 'bin' , undefined , 'freestyler.delete' ) ;
131+ deleteButton . addEventListener ( UI . Toolbar . ToolbarButton . Events . CLICK , onDeleteClick ) ;
132+ leftToolbar . appendToolbarItem ( deleteButton ) ;
124133
125134 const link = UI . XLink . XLink . create (
126135 AI_ASSISTANCE_SEND_FEEDBACK , i18nString ( UIStrings . sendFeedback ) , undefined , undefined ,
@@ -187,9 +196,11 @@ export class FreestylerPanel extends UI.Panel.Panel {
187196 super ( FreestylerPanel . panelName ) ;
188197 this . #freestylerEnabledSetting = this . #getAiAssistanceEnabledSetting( ) ;
189198
190- createToolbar (
191- this . contentElement ,
192- { onNewAgentClick : this . #clearMessages. bind ( this ) , onHistoryClick : this . #onHistoryClicked. bind ( this ) } ) ;
199+ createToolbar ( this . contentElement , {
200+ onNewAgentClick : this . #clearMessages. bind ( this ) ,
201+ onHistoryClick : this . #onHistoryClicked. bind ( this ) ,
202+ onDeleteClick : this . #onDeleteClicked. bind ( this ) ,
203+ } ) ;
193204 this . #toggleSearchElementAction =
194205 UI . ActionRegistry . ActionRegistry . instance ( ) . getAction ( 'elements.toggle-element-search' ) ;
195206 this . #aidaClient = aidaClient ;
@@ -520,6 +531,7 @@ export class FreestylerPanel extends UI.Panel.Panel {
520531 }
521532 }
522533 }
534+
523535 #onHistoryClicked( event : Event ) : void {
524536 const contextMenu = new UI . ContextMenu . ContextMenu ( event ) ;
525537
@@ -543,6 +555,34 @@ export class FreestylerPanel extends UI.Panel.Panel {
543555 void contextMenu . show ( ) ;
544556 }
545557
558+ #onDeleteClicked( ) : void {
559+ if ( ! this . #viewProps. agentType ) {
560+ return ;
561+ }
562+
563+ switch ( this . #viewProps. agentType ) {
564+ case AgentType . FREESTYLER :
565+ this . #agents. delete ( this . #freestylerAgent) ;
566+ this . #freestylerAgent = this . #createFreestylerAgent( ) ;
567+ break ;
568+ case AgentType . DRJONES_FILE :
569+ this . #agents. delete ( this . #drJonesFileAgent) ;
570+ this . #drJonesFileAgent = this . #createDrJonesFileAgent( ) ;
571+ break ;
572+ case AgentType . DRJONES_NETWORK_REQUEST :
573+ this . #agents. delete ( this . #drJonesNetworkAgent) ;
574+ this . #drJonesNetworkAgent = this . #createDrJonesNetworkAgent( ) ;
575+ break ;
576+ case AgentType . DRJONES_PERFORMANCE :
577+ this . #agents. delete ( this . #drJonesPerformanceAgent) ;
578+ this . #drJonesPerformanceAgent = this . #createDrJonesPerformanceAgent( ) ;
579+ break ;
580+ }
581+ this . #viewProps. messages = [ ] ;
582+ this . #viewProps. agentType = undefined ;
583+ this . doUpdate ( ) ;
584+ }
585+
546586 async #switchAgent( agent : AiAgent < unknown > ) : Promise < void > {
547587 switch ( agent . type ) {
548588 case AgentType . FREESTYLER :
0 commit comments