Skip to content

Commit 7ce315a

Browse files
AlinaVarkkidevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[AI] Add support for legacy js, viewport, modern http and character set widgets
https://screenshot.googleplex.com/jkce8tWGWRCsReb https://screenshot.googleplex.com/BicWVy6LuCCAAmx Bug: 503296282 Change-Id: I259fb06391342e78af38483c7acf6528217001ee Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7806469 Auto-Submit: Alina Varkki <alinavarkki@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
1 parent 2e34b84 commit 7ce315a

4 files changed

Lines changed: 180 additions & 0 deletions

File tree

front_end/models/ai_assistance/agents/PerformanceAgent.test.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,122 @@ code
12471247
assert.strictEqual(widget?.data.insight, Trace.Insights.Types.InsightKeys.SLOW_CSS_SELECTOR);
12481248
assert.strictEqual(widget?.data.insightData, insightSet.model.SlowCSSSelector);
12491249
});
1250+
1251+
it('yields a PERF_INSIGHT widget for LegacyJavaScript', async function() {
1252+
insightSet.model.LegacyJavaScript = {
1253+
insightKey: 'LegacyJavaScript',
1254+
state: 'fail',
1255+
legacyJavaScriptResults: new Map(),
1256+
} as unknown as Trace.Insights.Types.InsightModels['LegacyJavaScript'];
1257+
1258+
const agent = createAgentForConversation({
1259+
aidaClient: mockAidaClient([
1260+
[{
1261+
explanation: '',
1262+
functionCalls: [
1263+
{name: 'getInsightDetails', args: {insightSetId: insightSet.id, insightName: 'LegacyJavaScript'}},
1264+
]
1265+
}],
1266+
[{explanation: 'done'}]
1267+
])
1268+
});
1269+
1270+
const responses = await Array.fromAsync(agent.run('test', {selected: context}));
1271+
const actions = responses.filter(r => r.type === AiAgent.ResponseType.ACTION);
1272+
assert.lengthOf(actions, 1);
1273+
assert.exists(actions[0].widgets);
1274+
const widget = actions[0].widgets?.find(w => w.name === 'PERF_INSIGHT');
1275+
assert.exists(widget);
1276+
assert.strictEqual(widget?.data.insight, Trace.Insights.Types.InsightKeys.LEGACY_JAVASCRIPT);
1277+
assert.strictEqual(widget?.data.insightData, insightSet.model.LegacyJavaScript);
1278+
});
1279+
1280+
it('yields a PERF_INSIGHT widget for Viewport', async function() {
1281+
insightSet.model.Viewport = {
1282+
insightKey: 'Viewport',
1283+
state: 'fail',
1284+
mobileOptimized: false,
1285+
} as unknown as Trace.Insights.Types.InsightModels['Viewport'];
1286+
1287+
const agent = createAgentForConversation({
1288+
aidaClient: mockAidaClient([
1289+
[{
1290+
explanation: '',
1291+
functionCalls: [
1292+
{name: 'getInsightDetails', args: {insightSetId: insightSet.id, insightName: 'Viewport'}},
1293+
]
1294+
}],
1295+
[{explanation: 'done'}]
1296+
])
1297+
});
1298+
1299+
const responses = await Array.fromAsync(agent.run('test', {selected: context}));
1300+
const actions = responses.filter(r => r.type === AiAgent.ResponseType.ACTION);
1301+
assert.lengthOf(actions, 1);
1302+
assert.exists(actions[0].widgets);
1303+
const widget = actions[0].widgets?.find(w => w.name === 'PERF_INSIGHT');
1304+
assert.exists(widget);
1305+
assert.strictEqual(widget?.data.insight, Trace.Insights.Types.InsightKeys.VIEWPORT);
1306+
assert.strictEqual(widget?.data.insightData, insightSet.model.Viewport);
1307+
});
1308+
1309+
it('yields a PERF_INSIGHT widget for ModernHTTP', async function() {
1310+
insightSet.model.ModernHTTP = {
1311+
insightKey: 'ModernHTTP',
1312+
state: 'fail',
1313+
http1Requests: [],
1314+
} as unknown as Trace.Insights.Types.InsightModels['ModernHTTP'];
1315+
1316+
const agent = createAgentForConversation({
1317+
aidaClient: mockAidaClient([
1318+
[{
1319+
explanation: '',
1320+
functionCalls: [
1321+
{name: 'getInsightDetails', args: {insightSetId: insightSet.id, insightName: 'ModernHTTP'}},
1322+
]
1323+
}],
1324+
[{explanation: 'done'}]
1325+
])
1326+
});
1327+
1328+
const responses = await Array.fromAsync(agent.run('test', {selected: context}));
1329+
const actions = responses.filter(r => r.type === AiAgent.ResponseType.ACTION);
1330+
assert.lengthOf(actions, 1);
1331+
assert.exists(actions[0].widgets);
1332+
const widget = actions[0].widgets?.find(w => w.name === 'PERF_INSIGHT');
1333+
assert.exists(widget);
1334+
assert.strictEqual(widget?.data.insight, Trace.Insights.Types.InsightKeys.MODERN_HTTP);
1335+
assert.strictEqual(widget?.data.insightData, insightSet.model.ModernHTTP);
1336+
});
1337+
1338+
it('yields a PERF_INSIGHT widget for CharacterSet', async function() {
1339+
insightSet.model.CharacterSet = {
1340+
insightKey: 'CharacterSet',
1341+
state: 'fail',
1342+
data: {hasHttpCharset: false, metaCharsetDisposition: 'missing'},
1343+
} as unknown as Trace.Insights.Types.InsightModels['CharacterSet'];
1344+
1345+
const agent = createAgentForConversation({
1346+
aidaClient: mockAidaClient([
1347+
[{
1348+
explanation: '',
1349+
functionCalls: [
1350+
{name: 'getInsightDetails', args: {insightSetId: insightSet.id, insightName: 'CharacterSet'}},
1351+
]
1352+
}],
1353+
[{explanation: 'done'}]
1354+
])
1355+
});
1356+
1357+
const responses = await Array.fromAsync(agent.run('test', {selected: context}));
1358+
const actions = responses.filter(r => r.type === AiAgent.ResponseType.ACTION);
1359+
assert.lengthOf(actions, 1);
1360+
assert.exists(actions[0].widgets);
1361+
const widget = actions[0].widgets?.find(w => w.name === 'PERF_INSIGHT');
1362+
assert.exists(widget);
1363+
assert.strictEqual(widget?.data.insight, Trace.Insights.Types.InsightKeys.CHARACTER_SET);
1364+
assert.strictEqual(widget?.data.insightData, insightSet.model.CharacterSet);
1365+
});
12501366
});
12511367

12521368
it('yields a BOTTOM_UP_TREE widget when getDetailedCallTree is called', async function() {

front_end/models/ai_assistance/agents/PerformanceAgent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ const SUPPORTED_INSIGHT_WIDGETS = new Set<Trace.Insights.Types.InsightKeys>([
238238
Trace.Insights.Types.InsightKeys.IMAGE_DELIVERY,
239239
Trace.Insights.Types.InsightKeys.FONT_DISPLAY,
240240
Trace.Insights.Types.InsightKeys.SLOW_CSS_SELECTOR,
241+
Trace.Insights.Types.InsightKeys.LEGACY_JAVASCRIPT,
242+
Trace.Insights.Types.InsightKeys.VIEWPORT,
243+
Trace.Insights.Types.InsightKeys.MODERN_HTTP,
244+
Trace.Insights.Types.InsightKeys.CHARACTER_SET,
241245
]);
242246

243247
export class PerformanceTraceContext extends ConversationContext<AgentFocus> {

front_end/panels/ai_assistance/components/ChatMessage.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,38 @@ const UIStringsNotTranslate = {
351351
* @description Title for the slow CSS selectors widget.
352352
*/
353353
slowCssSelector: 'Slow CSS selectors',
354+
/**
355+
* @description Accessible label for the reveal button in the legacy JavaScript widget.
356+
*/
357+
revealLegacyJavaScript: 'Reveal legacy JavaScript',
358+
/**
359+
* @description Title for the legacy JavaScript widget.
360+
*/
361+
legacyJavaScript: 'Legacy JavaScript',
362+
/**
363+
* @description Accessible label for the reveal button in the viewport optimization widget.
364+
*/
365+
revealViewport: 'Reveal viewport optimization',
366+
/**
367+
* @description Title for the viewport optimization widget.
368+
*/
369+
viewport: 'Viewport optimization',
370+
/**
371+
* @description Accessible label for the reveal button in the modern HTTP usage widget.
372+
*/
373+
revealModernHttp: 'Reveal modern HTTP usage',
374+
/**
375+
* @description Title for the modern HTTP usage widget.
376+
*/
377+
modernHttp: 'Modern HTTP usage',
378+
/**
379+
* @description Accessible label for the reveal button in the character set declaration widget.
380+
*/
381+
revealCharacterSet: 'Reveal character set declaration',
382+
/**
383+
* @description Title for the character set declaration widget.
384+
*/
385+
characterSet: 'Character set declaration',
354386
} as const;
355387

356388
export interface Step {
@@ -1124,6 +1156,30 @@ const INSIGHT_METADATA: Record<string, {
11241156
title: UIStringsNotTranslate.slowCssSelector,
11251157
jslog: 'slow-css-selector-widget',
11261158
},
1159+
[Trace.Insights.Types.InsightKeys.LEGACY_JAVASCRIPT]: {
1160+
component: TimelineInsights.LegacyJavaScript.LegacyJavaScript,
1161+
accessibleLabel: UIStringsNotTranslate.revealLegacyJavaScript,
1162+
title: UIStringsNotTranslate.legacyJavaScript,
1163+
jslog: 'legacy-javascript-widget',
1164+
},
1165+
[Trace.Insights.Types.InsightKeys.VIEWPORT]: {
1166+
component: TimelineInsights.Viewport.Viewport,
1167+
accessibleLabel: UIStringsNotTranslate.revealViewport,
1168+
title: UIStringsNotTranslate.viewport,
1169+
jslog: 'viewport-widget',
1170+
},
1171+
[Trace.Insights.Types.InsightKeys.MODERN_HTTP]: {
1172+
component: TimelineInsights.ModernHTTP.ModernHTTP,
1173+
accessibleLabel: UIStringsNotTranslate.revealModernHttp,
1174+
title: UIStringsNotTranslate.modernHttp,
1175+
jslog: 'modern-http-widget',
1176+
},
1177+
[Trace.Insights.Types.InsightKeys.CHARACTER_SET]: {
1178+
component: TimelineInsights.CharacterSet.CharacterSet,
1179+
accessibleLabel: UIStringsNotTranslate.revealCharacterSet,
1180+
title: UIStringsNotTranslate.characterSet,
1181+
jslog: 'character-set-widget',
1182+
},
11271183
};
11281184

11291185
function renderInsightWidget<T extends Trace.Insights.Types.InsightModel>(

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ export const knownContextValues = new Set([
745745
'changes',
746746
'changes.changes',
747747
'changes.reveal-source',
748+
'character-set-widget',
748749
'checkbox-item',
749750
'checked',
750751
'chevron-left',
@@ -2299,6 +2300,7 @@ export const knownContextValues = new Set([
22992300
'learn-more.origin-trials',
23002301
'leavepictureinpicture',
23012302
'left',
2303+
'legacy-javascript-widget',
23022304
'legend',
23032305
'length',
23042306
'length-popover',
@@ -2709,6 +2711,7 @@ export const knownContextValues = new Set([
27092711
'mobile-throttling',
27102712
'model',
27112713
'modern',
2714+
'modern-http-widget',
27122715
'monitoring-xhr-enabled',
27132716
'monspace',
27142717
'more',
@@ -4357,6 +4360,7 @@ export const knownContextValues = new Set([
43574360
'view-transition-group',
43584361
'view-transition-name',
43594362
'view-transition-scope',
4363+
'viewport-widget',
43604364
'views-location-override',
43614365
'virtual-authenticators',
43624366
'visibility',

0 commit comments

Comments
 (0)