Skip to content

Commit cff61d4

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] clean up debug utils
Bug: none Change-Id: I60f1318c85ff9a3c80543c217ce0da20c6464824 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6243821 Reviewed-by: Nikolay Vitkov <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 3d40ccb commit cff61d4

File tree

10 files changed

+51
-70
lines changed

10 files changed

+51
-70
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ grd_files_debug_sources = [
11951195
"front_end/panels/ai_assistance/components/userActionRow.css.js",
11961196
"front_end/panels/ai_assistance/data_formatters/FileFormatter.js",
11971197
"front_end/panels/ai_assistance/data_formatters/NetworkRequestFormatter.js",
1198+
"front_end/panels/ai_assistance/debug.js",
11981199
"front_end/panels/animation/AnimationGroupPreviewUI.js",
11991200
"front_end/panels/animation/AnimationScreenshotPopover.js",
12001201
"front_end/panels/animation/AnimationTimeline.js",

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ describeWithEnvironment('FreestylerPanel', () => {
166166
});
167167

168168
describe('on rate click', () => {
169-
afterEach(() => {
170-
// @ts-expect-error global test variable
171-
setAiAssistanceServerSideLoggingEnabled(false);
172-
});
173-
174169
it('renders a button linking to settings', () => {
175170
const stub = sinon.stub(UI.ViewManager.ViewManager.instance(), 'showView');
176171

@@ -187,8 +182,6 @@ describeWithEnvironment('FreestylerPanel', () => {
187182
});
188183

189184
it('should allow logging if configured', () => {
190-
// @ts-expect-error global test variable
191-
setAiAssistanceServerSideLoggingEnabled(true);
192185
const stub = getGetHostConfigStub({
193186
aidaAvailability: {
194187
disallowLogging: false,

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,35 +1051,12 @@ function isAiAssistancePatchingEnabled(): boolean {
10511051
return Boolean(config.devToolsFreestyler?.patching);
10521052
}
10531053

1054-
function setAiAssistanceServerSideLoggingEnabled(enabled: boolean): void {
1055-
if (enabled) {
1056-
localStorage.setItem('aiAssistance_enableServerSideLogging', 'true');
1057-
} else {
1058-
localStorage.setItem('aiAssistance_enableServerSideLogging', 'false');
1059-
}
1060-
}
1061-
10621054
function isAiAssistanceServerSideLoggingEnabled(): boolean {
10631055
const config = Common.Settings.Settings.instance().getHostConfig();
1064-
if (config.aidaAvailability?.disallowLogging) {
1065-
return false;
1066-
}
1067-
return localStorage.getItem('aiAssistance_enableServerSideLogging') !== 'false';
1068-
}
1069-
1070-
function setAiAssistanceStylingWithFunctionCalling(enabled: boolean): void {
1071-
if (enabled) {
1072-
localStorage.setItem('aiAssistance_stylingFunctionCalling', 'true');
1073-
} else {
1074-
localStorage.setItem('aiAssistance_stylingFunctionCalling', 'false');
1075-
}
1056+
return !config.aidaAvailability?.disallowLogging;
10761057
}
10771058

10781059
function isAiAssistanceStylingWithFunctionCallingEnabled(): boolean {
1079-
return localStorage.getItem('aiAssistance_stylingFunctionCalling') === 'true';
1060+
const config = Common.Settings.Settings.instance().getHostConfig();
1061+
return Boolean(config.devToolsFreestyler?.functionCalling);
10801062
}
1081-
1082-
// @ts-ignore
1083-
globalThis.setAiAssistanceServerSideLoggingEnabled = setAiAssistanceServerSideLoggingEnabled;
1084-
// @ts-ignore
1085-
globalThis.setAiAssistanceStylingWithFunctionCalling = setAiAssistanceStylingWithFunctionCalling;

front_end/panels/ai_assistance/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ devtools_module("ai_assistance") {
3333
"components/UserActionRow.ts",
3434
"data_formatters/FileFormatter.ts",
3535
"data_formatters/NetworkRequestFormatter.ts",
36+
"debug.ts",
3637
]
3738

3839
deps = [

front_end/panels/ai_assistance/agents/AiAgent.ts

Lines changed: 3 additions & 25 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 type * as Lit from '../../../ui/lit/lit.js';
7+
import {debugLog, isDebugMode} from '../debug.js';
78

89
export const enum ResponseType {
910
CONTEXT = 'context',
@@ -494,7 +495,7 @@ export abstract class AiAgent<T> {
494495
}
495496

496497
if (isDebugMode()) {
497-
window.dispatchEvent(new CustomEvent('freestylerdone'));
498+
window.dispatchEvent(new CustomEvent('aiassistancedone'));
498499
}
499500
}
500501

@@ -640,7 +641,7 @@ export abstract class AiAgent<T> {
640641
response,
641642
aidaResponse,
642643
});
643-
localStorage.setItem('freestylerStructuredLog', JSON.stringify(this.#structuredLog));
644+
localStorage.setItem('aiAssistanceStructuredLog', JSON.stringify(this.#structuredLog));
644645
}
645646
}
646647

@@ -679,26 +680,3 @@ STOP`;
679680
};
680681
}
681682
}
682-
683-
export function isDebugMode(): boolean {
684-
return Boolean(localStorage.getItem('debugFreestylerEnabled'));
685-
}
686-
687-
export function debugLog(...log: unknown[]): void {
688-
if (!isDebugMode()) {
689-
return;
690-
}
691-
692-
// eslint-disable-next-line no-console
693-
console.log(...log);
694-
}
695-
696-
function setDebugFreestylerEnabled(enabled: boolean): void {
697-
if (enabled) {
698-
localStorage.setItem('debugFreestylerEnabled', 'true');
699-
} else {
700-
localStorage.removeItem('debugFreestylerEnabled');
701-
}
702-
}
703-
// @ts-ignore
704-
globalThis.setDebugFreestylerEnabled = setDebugFreestylerEnabled;

front_end/panels/ai_assistance/agents/StylingAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as UI from '../../../ui/legacy/legacy.js';
1212
import * as Lit from '../../../ui/lit/lit.js';
1313
import {linkifyNodeReference} from '../../elements/DOMLinkifier.js';
1414
import {AI_ASSISTANCE_CSS_CLASS_NAME, ChangeManager} from '../ChangeManager.js';
15+
import {debugLog} from '../debug.js';
1516
import {EvaluateAction, formatError, SideEffectError} from '../EvaluateAction.js';
1617
import {ExtensionScope, FREESTYLER_WORLD_NAME} from '../ExtensionScope.js';
1718

@@ -22,7 +23,6 @@ import {
2223
AiAgent,
2324
type ContextResponse,
2425
ConversationContext,
25-
debugLog,
2626
type FunctionCallHandlerResult,
2727
type ParsedAnswer,
2828
type ParsedResponse,

front_end/panels/ai_assistance/ai_assistance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export * from './debug.js';
56
export * from './agents/AiAgent.js';
67
export * from './agents/FileAgent.js';
78
export * from './agents/NetworkAgent.js';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/**
6+
* @fileoverview Local debugging utilities.
7+
*/
8+
9+
export function isDebugMode(): boolean {
10+
return Boolean(localStorage.getItem('debugAiAssistancePanelEnabled'));
11+
}
12+
13+
export function debugLog(...log: unknown[]): void {
14+
if (!isDebugMode()) {
15+
return;
16+
}
17+
18+
// eslint-disable-next-line no-console
19+
console.log(...log);
20+
}
21+
22+
function setDebugAiAssistanceEnabled(enabled: boolean): void {
23+
if (enabled) {
24+
localStorage.setItem('debugAiAssistancePanelEnabled', 'true');
25+
} else {
26+
localStorage.removeItem('debugAiAssistancePanelEnabled');
27+
}
28+
}
29+
// @ts-ignore
30+
globalThis.setDebugAiAssistanceEnabled = setDebugAiAssistanceEnabled;

scripts/ai_assistance/auto-run.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,12 @@ class Example {
462462
}
463463
const executionStartTime = performance.now();
464464
await this.#devtoolsPage.waitForFunction(() => {
465-
return 'setDebugFreestylerEnabled' in window;
465+
return 'setDebugAiAssistanceEnabled' in window;
466466
});
467467

468468
await this.#devtoolsPage.evaluate(() => {
469469
// @ts-ignore this is run in the DevTools page context where this function does exist.
470-
setDebugFreestylerEnabled(true);
470+
setDebugAiAssistanceEnabled(true);
471471
});
472472

473473
/** @type {Array<import('./types').IndividualPromptRequestResponse>} */
@@ -506,7 +506,7 @@ class Example {
506506

507507
const done = this.#devtoolsPage.evaluate(() => {
508508
return /** @type {Promise<void>} */ (new Promise(resolve => {
509-
window.addEventListener('freestylerdone', () => {
509+
window.addEventListener('aiassistancedone', () => {
510510
resolve();
511511
}, {
512512
once: true,
@@ -519,10 +519,10 @@ class Example {
519519
abort.abort();
520520

521521
const logs = await devtoolsPage.evaluate(() => {
522-
return localStorage.getItem('freestylerStructuredLog');
522+
return localStorage.getItem('aiAssistanceStructuredLog');
523523
});
524524
if (!logs) {
525-
throw new Error('No freestylerStructuredLog entries were found.');
525+
throw new Error('No aiAssistanceStructuredLog entries were found.');
526526
}
527527
/** @type {import('./types').IndividualPromptRequestResponse[]} */
528528
const results = JSON.parse(logs);

test/e2e/ai_assistance/ai_assistance_test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ describe('AI Assistance', function() {
125125
async function enableDebugModeForFreestyler(): Promise<void> {
126126
const {frontend} = getBrowserAndPages();
127127
await frontend.waitForFunction(() => {
128-
return 'setDebugFreestylerEnabled' in window;
128+
return 'setDebugAiAssistanceEnabled' in window;
129129
});
130130
await frontend.evaluate(() => {
131131
// @ts-ignore
132-
setDebugFreestylerEnabled(true);
132+
setDebugAiAssistanceEnabled(true);
133133
});
134134
}
135135

@@ -152,7 +152,7 @@ describe('AI Assistance', function() {
152152
const {frontend} = getBrowserAndPages();
153153
const done = frontend.evaluate(() => {
154154
return new Promise(resolve => {
155-
window.addEventListener('freestylerdone', resolve, {
155+
window.addEventListener('aiassistancedone', resolve, {
156156
once: true,
157157
});
158158
});
@@ -162,7 +162,7 @@ describe('AI Assistance', function() {
162162
if (waitForSideEffect) {
163163
await frontend.waitForSelector('aria/Continue');
164164
return JSON.parse(await frontend.evaluate((): string => {
165-
return localStorage.getItem('freestylerStructuredLog') as string;
165+
return localStorage.getItem('aiAssistanceStructuredLog') as string;
166166
})) as Array<Log>;
167167
}
168168

@@ -177,7 +177,7 @@ describe('AI Assistance', function() {
177177
await done;
178178
abort.abort();
179179
return JSON.parse(await frontend.evaluate((): string => {
180-
return localStorage.getItem('freestylerStructuredLog') as string;
180+
return localStorage.getItem('aiAssistanceStructuredLog') as string;
181181
})) as Array<Log>;
182182
}
183183

@@ -486,7 +486,7 @@ STOP`,
486486
const {frontend} = getBrowserAndPages();
487487
const done = frontend.evaluate(() => {
488488
return new Promise(resolve => {
489-
window.addEventListener('freestylerdone', resolve, {
489+
window.addEventListener('aiassistancedone', resolve, {
490490
once: true,
491491
});
492492
});

0 commit comments

Comments
 (0)