|
4 | 4 |
|
5 | 5 | import * as Host from '../../../core/host/host.js'; |
6 | 6 | import * as i18n from '../../../core/i18n/i18n.js'; |
| 7 | +import * as Platform from '../../../core/platform/platform.js'; |
7 | 8 | import * as TimelineUtils from '../../../panels/timeline/utils/utils.js'; |
8 | 9 | import * as PanelUtils from '../../../panels/utils/utils.js'; |
9 | 10 | import type * as Lit from '../../../ui/lit/lit.js'; |
@@ -111,6 +112,70 @@ export class InsightContext extends ConversationContext<TimelineUtils.InsightAIC |
111 | 112 | override getTitle(): string|ReturnType<typeof Lit.Directives.until> { |
112 | 113 | return `Insight: ${this.#insight.title()}`; |
113 | 114 | } |
| 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 | + } |
114 | 179 | } |
115 | 180 |
|
116 | 181 | export class PerformanceInsightsAgent extends AiAgent<TimelineUtils.InsightAIContext.ActiveInsight> { |
|
0 commit comments