Skip to content

Commit 5e9bca5

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Clean up code
Bug: none Change-Id: I96e4e831937e4e8ecda8e3fd220d5cbff256f54f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6352461 Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent ce37d1d commit 5e9bca5

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
887887

888888
describe('auto agent selection for panels', () => {
889889
const tests: Array<{
890-
panel: {new (...args: any[]): UI.Panel.Panel},
890+
panel: Platform.Constructor.Constructor<UI.Panel.Panel>,
891891
expectedConversationType: AiAssistance.ConversationType,
892892
featureFlagName: string,
893893
}> =

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,11 @@ export class AiAssistancePanel extends UI.Panel.Panel {
824824
}
825825

826826
#getChangeSummary(): string|undefined {
827-
return (isAiAssistancePatchingEnabled() && this.#conversationAgent && !this.#conversation?.isReadOnly) ?
828-
this.#changeManager.formatChangesForPatching(this.#conversationAgent.id, /* includeSourceLocation= */ true) :
829-
undefined;
827+
if (!isAiAssistancePatchingEnabled() || !this.#conversationAgent || this.#conversation?.isReadOnly) {
828+
return;
829+
}
830+
831+
return this.#changeManager.formatChangesForPatching(this.#conversationAgent.id, /* includeSourceLocation= */ true);
830832
}
831833

832834
override async performUpdate(): Promise<void> {

front_end/panels/ai_assistance/ChangeManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ChangeManager {
4141
this.#stylesheetChanges.clear();
4242
const firstFailed = results.find(result => result.status === 'rejected');
4343
if (firstFailed) {
44-
throw new Error(firstFailed.reason);
44+
console.error(firstFailed.reason);
4545
}
4646
}
4747

@@ -60,7 +60,7 @@ export class ChangeManager {
6060
} else {
6161
changes.push(change);
6262
}
63-
const content = this.formatChangesForInspectoStylesheet(changes);
63+
const content = this.#formatChangesForInspectorStylesheet(changes);
6464
await cssModel.setStyleSheetText(stylesheetId, content, true);
6565
this.#stylesheetChanges.set(stylesheetId, changes);
6666
return content;
@@ -74,7 +74,7 @@ export class ChangeManager {
7474
.join('\n\n');
7575
}
7676

77-
formatChangesForInspectoStylesheet(changes: Change[]): string {
77+
#formatChangesForInspectorStylesheet(changes: Change[]): string {
7878
return changes
7979
.map(change => {
8080
return `.${change.className} {

front_end/panels/ai_assistance/agents/StylingAgent.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
429429

430430
#execJs: typeof executeJsCode;
431431

432-
changes: ChangeManager;
433-
createExtensionScope: CreateExtensionScopeFunction;
432+
#changes: ChangeManager;
433+
#createExtensionScope: CreateExtensionScopeFunction;
434434

435435
constructor(opts: AgentOptions) {
436436
super({
@@ -439,14 +439,17 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
439439
confirmSideEffectForTest: opts.confirmSideEffectForTest,
440440
});
441441

442-
this.changes = opts.changeManager || new ChangeManager();
442+
this.#changes = opts.changeManager || new ChangeManager();
443443
this.#execJs = opts.execJs ?? executeJsCode;
444-
this.createExtensionScope = opts.createExtensionScope ?? ((changes: ChangeManager) => {
445-
return new ExtensionScope(changes, this.id);
446-
});
444+
this.#createExtensionScope = opts.createExtensionScope ?? ((changes: ChangeManager) => {
445+
return new ExtensionScope(changes, this.id);
446+
});
447447
SDK.TargetManager.TargetManager.instance().addModelListener(
448-
SDK.ResourceTreeModel.ResourceTreeModel, SDK.ResourceTreeModel.Events.PrimaryPageChanged,
449-
this.onPrimaryPageChanged, this);
448+
SDK.ResourceTreeModel.ResourceTreeModel,
449+
SDK.ResourceTreeModel.Events.PrimaryPageChanged,
450+
this.onPrimaryPageChanged,
451+
this,
452+
);
450453

451454
this.declareFunction<{
452455
title: string,
@@ -500,7 +503,7 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
500503
}
501504

502505
onPrimaryPageChanged(): void {
503-
void this.changes.clear();
506+
void this.#changes.clear();
504507
}
505508

506509
protected override emulateFunctionCall(aidaResponse: Host.AidaClient.AidaResponse):
@@ -697,7 +700,7 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
697700
};
698701
}
699702

700-
const scope = this.createExtensionScope(this.changes);
703+
const scope = this.#createExtensionScope(this.#changes);
701704
await scope.install();
702705
try {
703706
let throwOnSideEffect = true;

0 commit comments

Comments
 (0)