Skip to content

Commit ec23136

Browse files
Natallia HarshunovaDevtools-frontend LUCI CQ
authored andcommitted
Clear historical conversation when disabling ai feature
Historical conversations are now cleared immediately when the "AI Assistance" feature is disabled in settings. This provides a more predictable user experience. A corresponding test has been added to verify this behavior. Change-Id: I145d05c55c5388c5fbd8d012e7b9d02713c605a5 Fixed: 419212081 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6712173 Reviewed-by: Alex Rudenko <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Auto-Submit: Natallia Harshunova <[email protected]>
1 parent dce7254 commit ec23136

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

front_end/models/ai_assistance/AiHistoryStorage.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ describe('AiHistoryStorage', () => {
334334
await storage.upsertImage(serializedImage1);
335335
await storage.upsertImage(serializedImage2);
336336
await storage.upsertHistoryEntry(agent4);
337+
const historyDeletedPromise = storage.once('AiHistoryDeleted' as AiAssistance.Events.HISTORY_DELETED);
337338
await storage.deleteAll();
338339
assert.deepEqual(
339340
storage.getHistory(),
@@ -343,6 +344,7 @@ describe('AiHistoryStorage', () => {
343344
storage.getImageHistory(),
344345
[],
345346
);
347+
await historyDeletedPromise;
346348
});
347349

348350
it('should limit the amount of stored images', async () => {

front_end/models/ai_assistance/AiHistoryStorage.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,22 @@ let instance: AiHistoryStorage|null = null;
129129

130130
const DEFAULT_MAX_STORAGE_SIZE = 50 * 1024 * 1024;
131131

132-
export class AiHistoryStorage {
132+
export const enum Events {
133+
HISTORY_DELETED = 'AiHistoryDeleted',
134+
}
135+
136+
export interface EventTypes {
137+
[Events.HISTORY_DELETED]: void;
138+
}
139+
140+
export class AiHistoryStorage extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
133141
#historySetting: Common.Settings.Setting<SerializedConversation[]>;
134142
#imageHistorySettings: Common.Settings.Setting<SerializedImage[]>;
135143
#mutex = new Common.Mutex.Mutex();
136144
#maxStorageSize: number;
137145

138146
constructor(maxStorageSize = DEFAULT_MAX_STORAGE_SIZE) {
147+
super();
139148
this.#historySetting = Common.Settings.Settings.instance().createSetting('ai-assistance-history-entries', []);
140149
this.#imageHistorySettings = Common.Settings.Settings.instance().createSetting(
141150
'ai-assistance-history-images',
@@ -229,6 +238,7 @@ export class AiHistoryStorage {
229238
this.#imageHistorySettings.set([]);
230239
} finally {
231240
release();
241+
this.dispatchEventToListeners(Events.HISTORY_DELETED);
232242
}
233243
}
234244

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,30 @@ describeWithMockConnection('AI Assistance Panel', () => {
716716
const menuAfterDelete = openHistoryContextMenu(view.input, 'User question to Freestyler?');
717717
assert.isUndefined(menuAfterDelete.id);
718718
});
719+
720+
it('should clear the list of previous conversations when all history is deleted', async () => {
721+
const {panel, view} = await createAiAssistancePanel({aidaClient: mockAidaClient([[{explanation: 'test'}]])});
722+
panel.handleAction('freestyler.elements-floating-button');
723+
(await view.nextInput).onTextSubmit('test');
724+
await view.nextInput;
725+
726+
let {contextMenu} = openHistoryContextMenu(view.input, 'test');
727+
assert.isDefined(findMenuItemWithLabel(contextMenu.defaultSection(), 'test'));
728+
contextMenu.discard();
729+
730+
await AiAssistanceModel.AiHistoryStorage.instance().deleteAll();
731+
732+
const newViewInput = await view.nextInput;
733+
({contextMenu} = openHistoryContextMenu(newViewInput, 'test'));
734+
735+
const defaultSectionItems = contextMenu.defaultSection().items;
736+
assert.lengthOf(defaultSectionItems, 1, 'Default section should have one item');
737+
738+
const placeholderItem = defaultSectionItems[0];
739+
assert.strictEqual(placeholderItem.buildDescriptor().label, 'No past conversations');
740+
assert.isFalse(placeholderItem.isEnabled(), 'Placeholder item should be disabled');
741+
});
742+
719743
});
720744

721745
describe('empty state', () => {

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ export class AiAssistancePanel extends UI.Panel.Panel {
533533
this.#toggleSearchElementAction =
534534
UI.ActionRegistry.ActionRegistry.instance().getAction('elements.toggle-element-search');
535535
}
536+
AiAssistanceModel.AiHistoryStorage.instance().addEventListener(
537+
AiAssistanceModel.Events.HISTORY_DELETED, this.#onHistoryDeleted, this);
536538
}
537539

538540
#getChatUiState(): ChatViewState {
@@ -1247,17 +1249,16 @@ export class AiAssistancePanel extends UI.Panel.Panel {
12471249
contextMenu.footerSection().appendItem(
12481250
i18nString(UIStrings.clearChatHistory),
12491251
() => {
1250-
this.#clearHistory();
1252+
void AiAssistanceModel.AiHistoryStorage.instance().deleteAll();
12511253
},
12521254
{
12531255
disabled: historyEmpty,
12541256
},
12551257
);
12561258
}
12571259

1258-
#clearHistory(): void {
1260+
#onHistoryDeleted(): void {
12591261
this.#historicalConversations = [];
1260-
void AiAssistanceModel.AiHistoryStorage.instance().deleteAll();
12611262
this.#updateConversationState();
12621263
}
12631264

0 commit comments

Comments
 (0)