Skip to content

Commit e59f673

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Add experimental workspace agent
Not intended to be used outside of internal tester groups and not enabled by default. Bug: 385082492 Change-Id: I705dd9ee48fe6ccec3b373a2d9fbc76ea45e6551 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6097889 Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent e73fae1 commit e59f673

File tree

10 files changed

+489
-1
lines changed

10 files changed

+489
-1
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ grd_files_debug_sources = [
11611161
"front_end/panels/ai_assistance/agents/AiAgent.js",
11621162
"front_end/panels/ai_assistance/agents/FileAgent.js",
11631163
"front_end/panels/ai_assistance/agents/NetworkAgent.js",
1164+
"front_end/panels/ai_assistance/agents/PatchAgent.js",
11641165
"front_end/panels/ai_assistance/agents/PerformanceAgent.js",
11651166
"front_end/panels/ai_assistance/agents/StylingAgent.js",
11661167
"front_end/panels/ai_assistance/aiAssistancePanel.css.js",

front_end/core/host/AidaClient.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export enum ClientFeature {
123123
CHROME_PERFORMANCE_AGENT = 8,
124124
// Chrome AI Assistance File Agent.
125125
CHROME_FILE_AGENT = 9,
126+
// Chrome AI Patch Agent.
127+
CHROME_PATCH_AGENT = 12,
126128
}
127129

128130
export enum UserTier {

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Host from '../../core/host/host.js';
66
import * as i18n from '../../core/i18n/i18n.js';
77
import type * as Platform from '../../core/platform/platform.js';
88
import * as SDK from '../../core/sdk/sdk.js';
9+
import * as Persistence from '../../models/persistence/persistence.js';
910
import * as Workspace from '../../models/workspace/workspace.js';
1011
import * as UI from '../../ui/legacy/legacy.js';
1112
import * as LitHtml from '../../ui/lit-html/lit-html.js';
@@ -34,6 +35,7 @@ import {
3435
NetworkAgent,
3536
RequestContext,
3637
} from './agents/NetworkAgent.js';
38+
import {PatchAgent, ProjectContext} from './agents/PatchAgent.js';
3739
import {CallTreeContext, PerformanceAgent} from './agents/PerformanceAgent.js';
3840
import {NodeContext, StylingAgent} from './agents/StylingAgent.js';
3941
import styles from './aiAssistancePanel.css.js';
@@ -158,6 +160,13 @@ function createFileContext(file: Workspace.UISourceCode.UISourceCode|null): File
158160
return new FileContext(file);
159161
}
160162

163+
function createProjectContext(project: Persistence.FileSystemWorkspaceBinding.FileSystem|null): ProjectContext|null {
164+
if (!project) {
165+
return null;
166+
}
167+
return new ProjectContext(project);
168+
}
169+
161170
function createRequestContext(request: SDK.NetworkRequest.NetworkRequest|null): RequestContext|null {
162171
if (!request) {
163172
return null;
@@ -196,6 +205,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
196205
#currentAgent?: AiAgent<unknown>;
197206

198207
#previousSameOriginContext?: ConversationContext<unknown>;
208+
#project: ProjectContext|null = null;
199209
#selectedFile: FileContext|null = null;
200210
#selectedElement: NodeContext|null = null;
201211
#selectedCallTree: CallTreeContext|null = null;
@@ -330,6 +340,10 @@ export class AiAssistancePanel extends UI.Panel.Panel {
330340
agent = new PerformanceAgent(options);
331341
break;
332342
}
343+
case AgentType.PATCH: {
344+
agent = new PatchAgent(options);
345+
break;
346+
}
333347
}
334348

335349
if (history) {
@@ -421,6 +435,8 @@ export class AiAssistancePanel extends UI.Panel.Panel {
421435
this.#selectedCallTree =
422436
createCallTreeContext(UI.Context.Context.instance().flavor(TimelineUtils.AICallTree.AICallTree)),
423437
this.#selectedFile = createFileContext(UI.Context.Context.instance().flavor(Workspace.UISourceCode.UISourceCode)),
438+
this.#project =
439+
createProjectContext(UI.Context.Context.instance().flavor(Persistence.FileSystemWorkspaceBinding.FileSystem)),
424440
this.#viewProps = {
425441
...this.#viewProps,
426442
agentType: this.#currentAgent?.type,
@@ -441,6 +457,8 @@ export class AiAssistancePanel extends UI.Panel.Panel {
441457
TimelineUtils.AICallTree.AICallTree, this.#handleTraceEntryNodeFlavorChange);
442458
UI.Context.Context.instance().addFlavorChangeListener(
443459
Workspace.UISourceCode.UISourceCode, this.#handleUISourceCodeFlavorChange);
460+
UI.Context.Context.instance().addFlavorChangeListener(
461+
Persistence.FileSystemWorkspaceBinding.FileSystem, this.#handlePersistenceFileSystemChange);
444462
UI.Context.Context.instance().addFlavorChangeListener(
445463
ElementsPanel.ElementsPanel.ElementsPanel, this.#selectDefaultAgentIfNeeded, this);
446464
UI.Context.Context.instance().addFlavorChangeListener(
@@ -566,6 +584,19 @@ export class AiAssistancePanel extends UI.Panel.Panel {
566584
this.#updateAgentState(this.#currentAgent);
567585
};
568586

587+
#handlePersistenceFileSystemChange =
588+
(ev: Common.EventTarget.EventTargetEvent<Persistence.FileSystemWorkspaceBinding.FileSystem>): void => {
589+
const newProject = ev.data;
590+
if (!newProject) {
591+
return;
592+
}
593+
if (this.#project?.getItem() === newProject) {
594+
return;
595+
}
596+
this.#project = new ProjectContext(ev.data as Workspace.Workspace.Project);
597+
this.#updateAgentState(this.#currentAgent);
598+
};
599+
569600
#handleAiAssistanceEnabledSettingChanged = (): void => {
570601
const nextChatUiState = this.#getChatUiState();
571602
if (this.#viewProps.state === nextChatUiState) {
@@ -627,6 +658,11 @@ export class AiAssistancePanel extends UI.Panel.Panel {
627658

628659
let targetAgentType: AgentType|undefined;
629660
switch (actionId) {
661+
case 'ai-assistance.filesystem': {
662+
// TODO: metrics if needed.
663+
targetAgentType = AgentType.PATCH;
664+
break;
665+
}
630666
case 'freestyler.elements-floating-button': {
631667
Host.userMetrics.actionTaken(Host.UserMetrics.Action.AiAssistanceOpenedFromElementsPanelFloatingButton);
632668
targetAgentType = AgentType.STYLING;
@@ -806,6 +842,9 @@ export class AiAssistancePanel extends UI.Panel.Panel {
806842
case AgentType.PERFORMANCE:
807843
context = this.#selectedCallTree;
808844
break;
845+
case AgentType.PATCH:
846+
context = this.#project;
847+
break;
809848
}
810849
return context;
811850
}
@@ -966,7 +1005,8 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
9661005
case 'drjones.network-panel-context':
9671006
case 'drjones.performance-panel-context':
9681007
case 'drjones.sources-floating-button':
969-
case 'drjones.sources-panel-context': {
1008+
case 'drjones.sources-panel-context':
1009+
case 'ai-assistance.filesystem': {
9701010
void (async () => {
9711011
const view = UI.ViewManager.ViewManager.instance().view(
9721012
AiAssistancePanel.panelName,

front_end/panels/ai_assistance/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ devtools_module("ai_assistance") {
2626
"agents/AiAgent.ts",
2727
"agents/FileAgent.ts",
2828
"agents/NetworkAgent.ts",
29+
"agents/PatchAgent.ts",
2930
"agents/PerformanceAgent.ts",
3031
"agents/StylingAgent.ts",
3132
"components/ChatView.ts",
@@ -40,6 +41,7 @@ devtools_module("ai_assistance") {
4041
"../../core/root:bundle",
4142
"../../models/bindings:bundle",
4243
"../../models/logs:bundle",
44+
"../../models/text_utils:bundle",
4345
"../../models/trace:bundle",
4446
"../../models/workspace:bundle",
4547
"../../panels/elements:bundle",

front_end/panels/ai_assistance/agents/AiAgent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const enum AgentType {
118118
FILE = 'drjones-file',
119119
NETWORK = 'drjones-network-request',
120120
PERFORMANCE = 'drjones-performance',
121+
PATCH = 'patch',
121122
}
122123

123124
export interface SerializedAgent {

0 commit comments

Comments
 (0)