Skip to content

Commit 33679f8

Browse files
jackfranklindevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
AI: let the AI choose which mode to run Lighthouse in
Fixed: 498942434 Change-Id: Ieea5870da1fa211901df4ecd40943a0bd1344fa9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7761792 Commit-Queue: Alina Varkki <alinavarkki@chromium.org> Reviewed-by: Alina Varkki <alinavarkki@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
1 parent e5d13a6 commit 33679f8

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

front_end/models/ai_assistance/agents/ContextSelectionAgent.snapshot.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,16 @@ Content:
107107
"type": 6,
108108
"description": "",
109109
"nullable": true,
110-
"required": [],
111-
"properties": {}
110+
"required": [
111+
"mode"
112+
],
113+
"properties": {
114+
"mode": {
115+
"type": 1,
116+
"description": "The mode to run Lighthouse in. Your ONLY options are \"navigation\" or \"snapshot\". You should determine this based on the user's question. If the user is asking specifically about accessibility, you can run in \"snapshot\" mode which avoids reloading the page. If the user asks for a full Lighthouse report, you should run in \"navigation\" mode which is the default. These are the only options you can pass.",
117+
"nullable": false
118+
}
119+
}
112120
}
113121
},
114122
{

front_end/models/ai_assistance/agents/ContextSelectionAgent.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as Logs from '../../logs/logs.js';
1212
import * as NetworkTimeCalculator from '../../network_time_calculator/network_time_calculator.js';
1313
import type * as Trace from '../../trace/trace.js';
1414
import * as Workspace from '../../workspace/workspace.js';
15+
import {debugLog} from '../debug.js';
1516

1617
import {AccessibilityContext} from './AccessibilityAgent.js';
1718
import {
@@ -306,29 +307,44 @@ export class ContextSelectionAgent extends AiAgent<never> {
306307
}
307308
});
308309

309-
this.declareFunction('runLighthouseAudits', {
310+
type LHSupportedRunMode = Extract<LHModel.RunTypes.RunMode, 'navigation'|'snapshot'>;
311+
const parseLighthouseMode = (mode?: string): LHSupportedRunMode => {
312+
return mode === 'snapshot' ? 'snapshot' : 'navigation';
313+
};
314+
315+
this.declareFunction<{mode: LHSupportedRunMode}>('runLighthouseAudits', {
310316
description:
311317
'Records a Lighthouse audit on the current page. Use this to debug accessibility, SEO, and best practices. (For performance metrics like LCP, use performanceRecordAndReload instead).',
312318
parameters: {
313319
type: Host.AidaClient.ParametersTypes.OBJECT,
314320
description: '',
315321
nullable: true,
316-
required: [],
317-
properties: {},
322+
required: ['mode'],
323+
properties: {
324+
mode: {
325+
type: Host.AidaClient.ParametersTypes.STRING,
326+
description:
327+
'The mode to run Lighthouse in. Your ONLY options are "navigation" or "snapshot". You should determine this based on the user\'s question. If the user is asking specifically about accessibility, you can run in "snapshot" mode which avoids reloading the page. If the user asks for a full Lighthouse report, you should run in "navigation" mode which is the default. These are the only options you can pass.',
328+
nullable: false,
329+
}
330+
},
318331
},
319-
displayInfoFromArgs: () => {
332+
displayInfoFromArgs: args => {
333+
const mode = parseLighthouseMode(args.mode);
320334
return {
321335
title: 'Auditing your page with Lighthouse',
322-
action: 'runLighthouseAudits()',
336+
action: `runLighthouseAudits(${mode})`,
323337
};
324338
},
325-
handler: async () => {
339+
handler: async params => {
326340
if (!this.#lighthouseRecording) {
327341
return {
328342
error: 'Lighthouse report is not available.',
329343
};
330344
}
331-
const result = await this.#lighthouseRecording();
345+
const mode = parseLighthouseMode(params.mode);
346+
debugLog(`Recording with Lighthouse; runMode=${mode}`);
347+
const result = await this.#lighthouseRecording({mode});
332348
if (!result) {
333349
return {error: 'Failed to generate Lighthouse report.'};
334350
}

0 commit comments

Comments
 (0)