Skip to content

Commit 353bbb1

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Freestyler] Clear current History entry
Clears the current conversation and goes to empty state. Bug: 351752761 Change-Id: Id16ba333f85576c939ea48e01e975b10fd1768b0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5979947 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent 49c32cb commit 353bbb1

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

front_end/panels/freestyler/FreestylerPanel.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,35 @@ describeWithEnvironment('FreestylerPanel', () => {
701701
]);
702702
});
703703
});
704+
705+
it('should have empty state after clear chat', async () => {
706+
panel = new Freestyler.FreestylerPanel(mockView, {
707+
aidaClient: getTestAidaClient(),
708+
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,
709+
syncInfo: getTestSyncInfo(),
710+
});
711+
panel.handleAction('freestyler.elements-floating-button');
712+
(mockView.lastCall.args.at(0) as Freestyler.Props).onTextSubmit('test');
713+
await drainMicroTasks();
714+
715+
assert.deepEqual(mockView.lastCall.args.at(0).messages, [
716+
{
717+
entity: 'user',
718+
text: 'test',
719+
},
720+
{
721+
answer: 'test',
722+
entity: 'model',
723+
rpcId: undefined,
724+
suggestions: undefined,
725+
steps: [],
726+
},
727+
]);
728+
const toolbar = panel.contentElement.querySelector('.freestyler-left-toolbar');
729+
const button = toolbar!.shadowRoot!.querySelector('devtools-button[aria-label=\'Clear chat\']');
730+
assert.instanceOf(button, HTMLElement);
731+
dispatchClickEvent(button);
732+
assert.deepEqual(mockView.lastCall.args.at(0).messages, []);
733+
assert.deepEqual(mockView.lastCall.args.at(0).agentType, undefined);
734+
});
704735
});

front_end/panels/freestyler/FreestylerPanel.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
106110
function 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:

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ export const knownContextValues = new Set([
13981398
'frames-per-issue',
13991399
'freestyler',
14001400
'freestyler.accordion',
1401+
'freestyler.delete',
14011402
'freestyler.dogfood-info',
14021403
'freestyler.element-panel-context',
14031404
'freestyler.elements-floating-button',

0 commit comments

Comments
 (0)