Skip to content

Commit ed77ee4

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
RPP: add default suggestions for each Insight
Bug: 405925760 Change-Id: I12b70506b58bf684fc55162d6be99df4012b6a41 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6397060 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Nancy Li <nancyly@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Nancy Li <nancyly@chromium.org>
1 parent c029e35 commit ed77ee4

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

‎front_end/models/ai_assistance/agents/PerformanceInsightsAgent.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import * as Host from '../../../core/host/host.js';
66
import * as i18n from '../../../core/i18n/i18n.js';
7+
import * as Platform from '../../../core/platform/platform.js';
78
import * as TimelineUtils from '../../../panels/timeline/utils/utils.js';
89
import * as PanelUtils from '../../../panels/utils/utils.js';
910
import type * as Lit from '../../../ui/lit/lit.js';
@@ -111,6 +112,70 @@ export class InsightContext extends ConversationContext<TimelineUtils.InsightAIC
111112
override getTitle(): string|ReturnType<typeof Lit.Directives.until> {
112113
return `Insight: ${this.#insight.title()}`;
113114
}
115+
116+
/**
117+
* Presents the default suggestions that are shown when the user first clicks
118+
* "Ask AI" on an Insight.
119+
*/
120+
override getSuggestions(): [string, ...string[]] {
121+
switch (this.#insight.insight.insightKey) {
122+
case 'CLSCulprits':
123+
return [
124+
'How can I improve my CLS score',
125+
'How can I prevent layout shifts on this page?',
126+
];
127+
case 'DocumentLatency':
128+
return [
129+
'How do I decrease the initial loading time of my page?',
130+
'Did anything slow down the request for this document?',
131+
132+
];
133+
case 'DOMSize':
134+
return ['How can I reduce the size of my DOM?'];
135+
case 'DuplicatedJavaScript':
136+
return ['How do I deduplicate the identified scripts in my bundle?'];
137+
case 'FontDisplay':
138+
return ['How can I update my CSS to avoid layout shifts caused by incorrect `font-display` properties?'];
139+
case 'ForcedReflow':
140+
return ['How can I avoid layout thrashing?', 'What is forced reflow and why is it problematic?'];
141+
case 'ImageDelivery':
142+
return ['What should I do to improve and optimize the time taken to fetch and display images on the page?'];
143+
case 'InteractionToNextPaint':
144+
return [
145+
'Help me optimize my INP score', 'Help me understand why a large INP score is problematic',
146+
'What was the biggest contributor to my longest interaction duration time?'
147+
];
148+
case 'LCPDiscovery':
149+
return [
150+
'Help me optimize my LCP score', 'What can I do to reduce my LCP discovery time?',
151+
'Why is LCP discovery time important?'
152+
];
153+
case 'LCPPhases':
154+
return [
155+
'Help me optimize my LCP score', 'Which LCP phase was most problematic?',
156+
'What can I do to reduce the LCP time for this page load?'
157+
];
158+
case 'NetworkDependencyTree':
159+
return ['How do I optimize my network dependency tree?'];
160+
case 'RenderBlocking':
161+
return [
162+
'Show me the render blocking requests, listed by impact',
163+
'How can I reduce the number of render blocking requests?'
164+
];
165+
case 'SlowCSSSelector':
166+
return ['How can I optimize my CSS to increase the performance of CSS selectors?'];
167+
case 'ThirdParties':
168+
return ['Which third parties are having the largest impact on my page performance?'];
169+
case 'Cache':
170+
return ['What caching strategies can I apply to improve my page performance?'];
171+
case 'Viewport':
172+
return ['How do I make sure my page is optimized for mobile viewing?'];
173+
case 'ModernHTTP':
174+
return ['Is my site being served using the recommended HTTP best practices?'];
175+
default:
176+
Platform.assertNever(this.#insight.insight.insightKey, 'Unknown insight key');
177+
}
178+
}
114179
}
115180

116181
export class PerformanceInsightsAgent extends AiAgent<TimelineUtils.InsightAIContext.ActiveInsight> {

‎front_end/panels/ai_assistance/AiAssistancePanel.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ describeWithMockConnection('AI Assistance Panel', () => {
238238
{
239239
flavor: TimelineUtils.InsightAIContext.ActiveInsight,
240240
createContext: () => {
241-
return new AiAssistanceModel.InsightContext(
241+
const context = new AiAssistanceModel.InsightContext(
242242
sinon.createStubInstance(TimelineUtils.InsightAIContext.ActiveInsight));
243+
sinon.stub(AiAssistanceModel.InsightContext.prototype, 'getSuggestions').returns(['test suggestion']);
244+
return context;
243245
},
244246
action: 'drjones.performance-insight-context'
245247
},

0 commit comments

Comments
 (0)