Skip to content

Commit 1d6b9bf

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Remove prototype integration with Sources
Bug: 393267670 Change-Id: I1bafb457fb109544caf3907c3ef9930a91ee9ac6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6233109 Reviewed-by: Nikolay Vitkov <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 77956db commit 1d6b9bf

File tree

5 files changed

+93
-61
lines changed

5 files changed

+93
-61
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as Host from '../../core/host/host.js';
99
import * as i18n from '../../core/i18n/i18n.js';
1010
import type * as Platform from '../../core/platform/platform.js';
1111
import * as SDK from '../../core/sdk/sdk.js';
12-
import * as Persistence from '../../models/persistence/persistence.js';
1312
import * as Workspace from '../../models/workspace/workspace.js';
1413
import * as UI from '../../ui/legacy/legacy.js';
1514
import * as Lit from '../../ui/lit/lit.js';
@@ -38,7 +37,6 @@ import {
3837
NetworkAgent,
3938
RequestContext,
4039
} from './agents/NetworkAgent.js';
41-
import {PatchAgent, ProjectContext} from './agents/PatchAgent.js';
4240
import {CallTreeContext, PerformanceAgent} from './agents/PerformanceAgent.js';
4341
import {NodeContext, StylingAgent, StylingAgentWithFunctionCalling} from './agents/StylingAgent.js';
4442
import aiAssistancePanelStyles from './aiAssistancePanel.css.js';
@@ -163,13 +161,6 @@ function createFileContext(file: Workspace.UISourceCode.UISourceCode|null): File
163161
return new FileContext(file);
164162
}
165163

166-
function createProjectContext(project: Persistence.FileSystemWorkspaceBinding.FileSystem|null): ProjectContext|null {
167-
if (!project) {
168-
return null;
169-
}
170-
return new ProjectContext(project);
171-
}
172-
173164
function createRequestContext(request: SDK.NetworkRequest.NetworkRequest|null): RequestContext|null {
174165
if (!request) {
175166
return null;
@@ -209,7 +200,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
209200
#currentAgent?: AiAgent<unknown>;
210201

211202
#previousSameOriginContext?: ConversationContext<unknown>;
212-
#project: ProjectContext|null = null;
213203
#selectedFile: FileContext|null = null;
214204
#selectedElement: NodeContext|null = null;
215205
#selectedCallTree: CallTreeContext|null = null;
@@ -356,8 +346,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
356346
break;
357347
}
358348
case AgentType.PATCH: {
359-
agent = new PatchAgent(options);
360-
break;
349+
throw new Error('AI Assistance does not support direct usage of the patch agent');
361350
}
362351
}
363352

@@ -451,8 +440,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
451440
this.#selectedCallTree =
452441
createCallTreeContext(UI.Context.Context.instance().flavor(TimelineUtils.AICallTree.AICallTree)),
453442
this.#selectedFile = createFileContext(UI.Context.Context.instance().flavor(Workspace.UISourceCode.UISourceCode)),
454-
this.#project =
455-
createProjectContext(UI.Context.Context.instance().flavor(Persistence.FileSystemWorkspaceBinding.FileSystem)),
456443
this.#viewProps = {
457444
...this.#viewProps,
458445
agentType: this.#currentAgent?.type,
@@ -473,8 +460,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
473460
TimelineUtils.AICallTree.AICallTree, this.#handleTraceEntryNodeFlavorChange);
474461
UI.Context.Context.instance().addFlavorChangeListener(
475462
Workspace.UISourceCode.UISourceCode, this.#handleUISourceCodeFlavorChange);
476-
UI.Context.Context.instance().addFlavorChangeListener(
477-
Persistence.FileSystemWorkspaceBinding.FileSystem, this.#handlePersistenceFileSystemChange);
478463
UI.Context.Context.instance().addFlavorChangeListener(
479464
ElementsPanel.ElementsPanel.ElementsPanel, this.#selectDefaultAgentIfNeeded, this);
480465
UI.Context.Context.instance().addFlavorChangeListener(
@@ -600,19 +585,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
600585
this.#updateAgentState(this.#currentAgent);
601586
};
602587

603-
#handlePersistenceFileSystemChange =
604-
(ev: Common.EventTarget.EventTargetEvent<Persistence.FileSystemWorkspaceBinding.FileSystem>): void => {
605-
const newProject = ev.data;
606-
if (!newProject) {
607-
return;
608-
}
609-
if (this.#project?.getItem() === newProject) {
610-
return;
611-
}
612-
this.#project = new ProjectContext(ev.data as Workspace.Workspace.Project);
613-
this.#updateAgentState(this.#currentAgent);
614-
};
615-
616588
#handleAiAssistanceEnabledSettingChanged = (): void => {
617589
const nextChatUiState = this.#getChatUiState();
618590
if (this.#viewProps.state === nextChatUiState) {
@@ -674,11 +646,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
674646

675647
let targetAgentType: AgentType|undefined;
676648
switch (actionId) {
677-
case 'ai-assistance.filesystem': {
678-
// TODO: metrics if needed.
679-
targetAgentType = AgentType.PATCH;
680-
break;
681-
}
682649
case 'freestyler.elements-floating-button': {
683650
Host.userMetrics.actionTaken(Host.UserMetrics.Action.AiAssistanceOpenedFromElementsPanelFloatingButton);
684651
targetAgentType = AgentType.STYLING;
@@ -856,8 +823,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
856823
context = this.#selectedCallTree;
857824
break;
858825
case AgentType.PATCH:
859-
context = this.#project;
860-
break;
826+
throw new Error('AI Assistance does not support direct usage of the patch agent');
861827
}
862828
return context;
863829
}
@@ -1035,8 +1001,7 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
10351001
case 'drjones.network-panel-context':
10361002
case 'drjones.performance-panel-context':
10371003
case 'drjones.sources-floating-button':
1038-
case 'drjones.sources-panel-context':
1039-
case 'ai-assistance.filesystem': {
1004+
case 'drjones.sources-panel-context': {
10401005
void (async () => {
10411006
const view = UI.ViewManager.ViewManager.instance().view(
10421007
AiAssistancePanel.panelName,

front_end/panels/ai_assistance/agents/PatchAgent.ts

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Use those functions to fulfill the user query.
2626
## Step-by-step instructions
2727
2828
- Think about what the user wants.
29-
- List all files in the project.
29+
- List all files in the project or search for relevant files.
3030
- Identify the files that are likely to be modified.
3131
- Retrieve the content of those files.
3232
- Rewrite the files according to the user query.
@@ -37,6 +37,19 @@ Use those functions to fulfill the user query.
3737
- Always prefer changing the true source files and not the build output.
3838
- The build output is usually in dist/, out/, build/ folders.
3939
- *CRITICAL* never make the same function call twice.
40+
- *CRITICAL* do not make any changes if not prompted.
41+
42+
Instead of using the writeFile function you can also produce the following diff format:
43+
44+
\`\`\`
45+
src/index.html
46+
<meta charset="utf-8">
47+
<title>Test</title>
48+
\`\`\`
49+
50+
First output the filename (example, src/index.html), then output the SEARCH block,
51+
followed by the REPLACE block.
52+
4053
`;
4154
/* clang-format on */
4255

@@ -134,6 +147,82 @@ export class PatchAgent extends AiAgent<Workspace.Workspace.Project> {
134147
},
135148
});
136149

150+
this.declareFunction<{
151+
query: string,
152+
caseSensitive: boolean,
153+
isRegex: boolean,
154+
}>('searchInFiles', {
155+
description:
156+
'Searches for a query in all files in the project. For each match it returns the positions of matches.',
157+
parameters: {
158+
type: Host.AidaClient.ParametersTypes.OBJECT,
159+
description: '',
160+
nullable: false,
161+
properties: {
162+
query: {
163+
type: Host.AidaClient.ParametersTypes.STRING,
164+
description: 'The query to search for matches in files',
165+
nullable: false,
166+
},
167+
caseSensitive: {
168+
type: Host.AidaClient.ParametersTypes.BOOLEAN,
169+
description: 'Whether the query is case sensitive or not',
170+
nullable: false,
171+
},
172+
isRegex: {
173+
type: Host.AidaClient.ParametersTypes.BOOLEAN,
174+
description: 'Whether the query is a regular expression or not',
175+
nullable: true,
176+
}
177+
},
178+
},
179+
handler: async params => {
180+
if (!this.#project) {
181+
return {
182+
error: 'No project available',
183+
};
184+
}
185+
const project = this.#project.getItem();
186+
const {map} = getFiles(project);
187+
const matches = [];
188+
for (const [filepath, file] of map.entries()) {
189+
const results = await project.searchInFileContent(file, params.query, params.caseSensitive, params.isRegex);
190+
for (const result of results) {
191+
matches.push({
192+
filepath,
193+
lineNumber: result.lineNumber,
194+
columnNumber: result.columnNumber,
195+
matchLength: result.matchLength
196+
});
197+
}
198+
}
199+
return {
200+
result: {
201+
matches,
202+
}
203+
};
204+
},
205+
});
206+
207+
this.declareFunction('changeFile', {
208+
description: 'returns a list of all files in the project.',
209+
parameters: {
210+
type: Host.AidaClient.ParametersTypes.OBJECT,
211+
description: '',
212+
nullable: true,
213+
properties: {
214+
filepath: {
215+
type: Host.AidaClient.ParametersTypes.STRING,
216+
description: 'A file path that identifies the file to get the content for',
217+
nullable: false,
218+
},
219+
},
220+
},
221+
handler: async () => {
222+
return {result: {}};
223+
},
224+
});
225+
137226
this.declareFunction<{filepath: string}>('readFile', {
138227
description: 'returns the complement content of a file',
139228
parameters: {

front_end/panels/ai_assistance/ai_assistance-meta.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,6 @@ UI.ActionRegistration.registerActionExtension({
236236
condition: config => isFileAgentFeatureAvailable(config) && !isPolicyRestricted(config),
237237
});
238238

239-
UI.ActionRegistration.registerActionExtension({
240-
actionId: 'ai-assistance.filesystem',
241-
contextTypes(): [] {
242-
return [];
243-
},
244-
category: UI.ActionRegistration.ActionCategory.GLOBAL,
245-
title: i18nLazyString(UIStrings.askAi),
246-
async loadActionDelegate() {
247-
const AiAssistance = await loadAiAssistanceModule();
248-
return new AiAssistance.ActionDelegate();
249-
},
250-
condition: _config => Boolean(window.localStorage.getItem('ai_assistance_experimental_patch_do_not_use')),
251-
});
252-
253239
UI.ActionRegistration.registerActionExtension({
254240
actionId: 'drjones.sources-panel-context',
255241
contextTypes() {

front_end/panels/sources/NavigatorView.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,13 +1122,6 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
11221122
project.remove();
11231123
}
11241124
}, {jslogContext: 'remove-folder-from-workspace'});
1125-
1126-
if (UI.ActionRegistry.ActionRegistry.instance().hasAction('ai-assistance.filesystem')) {
1127-
contextMenu.headerSection().appendAction(
1128-
'ai-assistance.filesystem',
1129-
);
1130-
UI.Context.Context.instance().setFlavor(Persistence.FileSystemWorkspaceBinding.FileSystem, project);
1131-
}
11321125
}
11331126
} else {
11341127
if (!(node instanceof NavigatorGroupTreeNode)) {

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ export const knownContextValues = new Set([
335335
'affected-sources',
336336
'ai-assistance-enabled',
337337
'ai-assistance-history-entries',
338-
'ai-assistance.filesystem',
339338
'ai_assistance',
340339
'align-content',
341340
'align-content-center',

0 commit comments

Comments
 (0)