Skip to content

Commit ef56a52

Browse files
Kateryna Prokopenkodevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
Do not regenerate prompt summary when only timestamp changes
Bug: 502891604 Change-Id: I04637039ec69f534de56c49e3e826fd3276fd421 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7761678 Auto-Submit: Kateryna Prokopenko <kprokopenko@chromium.org> Commit-Queue: Kateryna Prokopenko <kprokopenko@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
1 parent fd82caf commit ef56a52

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

front_end/panels/ai_assistance/components/ChatView.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,39 @@ describeWithEnvironment('ChatView', () => {
9999
assert.exists(sideEffect);
100100
});
101101
});
102+
103+
describe('Caching', () => {
104+
it('should cache the summary and not regenerate it if only the timestamp changes', async () => {
105+
const generateSummaryStub = sinon.stub().resolves('Summary');
106+
let capturedExportClick: (() => void)|undefined;
107+
const customView = (input: AiAssistancePanel.ChatWidgetInput) => {
108+
capturedExportClick = input.exportForAgentsClick;
109+
};
110+
111+
const props = getProp({
112+
generateConversationSummary: generateSummaryStub,
113+
conversationMarkdown: '# Conversation\n\n**Export Timestamp (UTC):** 2026-04-15T10:00:00.000Z\n\n---\nContent',
114+
});
115+
116+
const chat = new AiAssistancePanel.ChatView(props, customView);
117+
renderElementIntoDOM(chat);
118+
119+
assert.exists(capturedExportClick);
120+
121+
// Trigger export first time
122+
await capturedExportClick!();
123+
sinon.assert.callCount(generateSummaryStub, 1);
124+
125+
// Update props with a new timestamp but same content
126+
chat.props = getProp({
127+
generateConversationSummary: generateSummaryStub,
128+
conversationMarkdown: '# Conversation\n\n**Export Timestamp (UTC):** 2026-04-15T11:00:00.000Z\n\n---\nContent',
129+
});
130+
131+
// Trigger export second time
132+
await capturedExportClick!();
133+
// Should still be 1 because of cache
134+
sinon.assert.callCount(generateSummaryStub, 1);
135+
});
136+
});
102137
});

front_end/panels/ai_assistance/components/ChatView.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface Props {
9696
};
9797
}
9898

99-
interface ChatWidgetInput extends Props {
99+
export interface ChatWidgetInput extends Props {
100100
handleScroll: (ev: Event) => void;
101101
handleSuggestionClick: (title: string) => void;
102102
handleMessageContainerRef: (el: Element|undefined) => void;
@@ -367,12 +367,13 @@ export class ChatView extends HTMLElement {
367367
};
368368

369369
async #getSummary(): Promise<string> {
370-
if (this.#cachedSummary?.markdown === this.#props.conversationMarkdown) {
370+
const cacheKey = this.#props.conversationMarkdown.replace(/\*\*Export Timestamp \(UTC\):\*\* .*\n\n/, '');
371+
if (this.#cachedSummary?.markdown === cacheKey) {
371372
return this.#cachedSummary.summary;
372373
}
373374
try {
374375
const summary = await this.#props.generateConversationSummary(this.#props.conversationMarkdown);
375-
this.#cachedSummary = {markdown: this.#props.conversationMarkdown, summary};
376+
this.#cachedSummary = {markdown: cacheKey, summary};
376377
return summary;
377378
} catch (err) {
378379
console.error(err);

0 commit comments

Comments
 (0)