Skip to content

Commit 406149a

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
AI: fix selection of Performance agents
Bug: 394552594 Change-Id: Ia7908f4ab3ec58ddc1abd10f76a210cd070ed9b9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6257568 Commit-Queue: Jack Franklin <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Auto-Submit: Jack Franklin <[email protected]>
1 parent f763f31 commit 406149a

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,84 @@ describeWithEnvironment('FreestylerPanel', () => {
689689
assert.deepEqual(mockView.lastCall.args[0].agentType, AiAssistance.AgentType.STYLING);
690690
});
691691

692+
it('should select the performance insights agent if it is enabled', async () => {
693+
Object.assign(Root.Runtime.hostConfig, {
694+
devToolsAiAssistancePerformanceAgent: {
695+
enabled: true,
696+
insightsEnabled: true,
697+
},
698+
});
699+
panel = new AiAssistance.AiAssistancePanel(mockView, {
700+
aidaClient: mockAidaClient([[{explanation: 'test'}]]),
701+
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,
702+
syncInfo: getTestSyncInfo(),
703+
});
704+
panel.handleAction('freestyler.elements-floating-button');
705+
mockView.lastCall.args[0].onTextSubmit('test');
706+
await drainMicroTasks();
707+
UI.Context.Context.instance().setFlavor(
708+
TimelinePanel.TimelinePanel.TimelinePanel,
709+
sinon.createStubInstance(TimelinePanel.TimelinePanel.TimelinePanel));
710+
711+
assert.deepEqual(mockView.lastCall.args[0].messages, [
712+
{
713+
entity: AiAssistance.ChatMessageEntity.USER,
714+
text: 'test',
715+
},
716+
{
717+
answer: 'test',
718+
entity: AiAssistance.ChatMessageEntity.MODEL,
719+
rpcId: undefined,
720+
suggestions: undefined,
721+
steps: [],
722+
},
723+
]);
724+
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
725+
assert.instanceOf(button, HTMLElement);
726+
dispatchClickEvent(button);
727+
assert.deepEqual(mockView.lastCall.args[0].messages, []);
728+
assert.deepEqual(mockView.lastCall.args[0].agentType, AiAssistance.AgentType.PERFORMANCE_INSIGHT);
729+
});
730+
731+
it('should select the Dr Jones performance agent if insights are not enabled', async () => {
732+
Object.assign(Root.Runtime.hostConfig, {
733+
devToolsAiAssistancePerformanceAgent: {
734+
enabled: true,
735+
insightsEnabled: false,
736+
},
737+
});
738+
panel = new AiAssistance.AiAssistancePanel(mockView, {
739+
aidaClient: mockAidaClient([[{explanation: 'test'}]]),
740+
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,
741+
syncInfo: getTestSyncInfo(),
742+
});
743+
panel.handleAction('freestyler.elements-floating-button');
744+
mockView.lastCall.args[0].onTextSubmit('test');
745+
await drainMicroTasks();
746+
UI.Context.Context.instance().setFlavor(
747+
TimelinePanel.TimelinePanel.TimelinePanel,
748+
sinon.createStubInstance(TimelinePanel.TimelinePanel.TimelinePanel));
749+
750+
assert.deepEqual(mockView.lastCall.args[0].messages, [
751+
{
752+
entity: AiAssistance.ChatMessageEntity.USER,
753+
text: 'test',
754+
},
755+
{
756+
answer: 'test',
757+
entity: AiAssistance.ChatMessageEntity.MODEL,
758+
rpcId: undefined,
759+
suggestions: undefined,
760+
steps: [],
761+
},
762+
]);
763+
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
764+
assert.instanceOf(button, HTMLElement);
765+
dispatchClickEvent(button);
766+
assert.deepEqual(mockView.lastCall.args[0].messages, []);
767+
assert.deepEqual(mockView.lastCall.args[0].agentType, AiAssistance.AgentType.PERFORMANCE);
768+
});
769+
692770
it('should switch agents and restore history', async () => {
693771
panel = new AiAssistance.AiAssistancePanel(mockView, {
694772
aidaClient: mockAidaClient([[{explanation: 'test'}], [{explanation: 'test2'}]]),

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,12 @@ export class AiAssistancePanel extends UI.Panel.Panel {
442442
targetAgentType = AgentType.NETWORK;
443443
} else if (isSourcesPanelVisible && hostConfig.devToolsAiAssistanceFileAgent?.enabled) {
444444
targetAgentType = AgentType.FILE;
445-
} else if (isPerformancePanelVisible && hostConfig.devToolsAiAssistancePerformanceAgent?.enabled) {
446-
targetAgentType = AgentType.PERFORMANCE;
447445
} else if (
448446
isPerformancePanelVisible && hostConfig.devToolsAiAssistancePerformanceAgent?.enabled &&
449447
hostConfig.devToolsAiAssistancePerformanceAgent?.insightsEnabled) {
450448
targetAgentType = AgentType.PERFORMANCE_INSIGHT;
449+
} else if (isPerformancePanelVisible && hostConfig.devToolsAiAssistancePerformanceAgent?.enabled) {
450+
targetAgentType = AgentType.PERFORMANCE;
451451
}
452452

453453
const agent = targetAgentType ? this.#createAgent(targetAgentType) : undefined;

0 commit comments

Comments
 (0)