Skip to content

Commit 14b70f5

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] list to patch suggestion sources
Fixed: 402034781 Change-Id: I72ccb053958bdfb62ab1ade3e879467734ddab79 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6349244 Auto-Submit: Alex Rudenko <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 0dd1042 commit 14b70f5

File tree

4 files changed

+80
-23
lines changed

4 files changed

+80
-23
lines changed

front_end/panels/ai_assistance/PatchWidget.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
createPatchWidget,
1111
createTestFilesystem,
1212
initializePersistenceImplForTests,
13+
mockAidaClient,
1314
} from '../../testing/AiAssistanceHelpers.js';
1415
import {updateHostConfig} from '../../testing/EnvironmentHelpers.js';
1516
import {describeWithMockConnection} from '../../testing/MockConnection.js';
@@ -57,6 +58,24 @@ describeWithMockConnection('PatchWidget', () => {
5758

5859
assert.isFalse(showFreDialogStub.called, 'Expected FreDialog to be not shown but it\'s shown');
5960
});
61+
62+
it('should show files uploaded', async () => {
63+
Common.Settings.moduleSetting('ai-assistance-patching-fre-completed').set(true);
64+
const {view, panel} = await createPatchWidget({
65+
aidaClient: mockAidaClient([
66+
[{explanation: '', functionCalls: [{name: 'updateFiles', args: {files: ['index.html']}}]}], [{
67+
explanation: 'done',
68+
}]
69+
]),
70+
});
71+
panel.changeSummary = 'body { background-color: red; }';
72+
73+
view.input.onApplyToWorkspace();
74+
75+
assert.strictEqual((await view.nextInput).sources, `Filenames in test.
76+
Files:
77+
* index.html`);
78+
});
6079
});
6180

6281
describe('workspace', () => {

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ const UIStringsNotTranslate = {
9696
*@description Third disclaimer item text for the fre dialog.
9797
*/
9898
freDisclaimerTextUseWithCaution: 'Use generated code snippets with caution',
99+
/**
100+
* @description Title of the link opening data that was used to
101+
* produce a code suggestion.
102+
*/
103+
viewUploadedFiles: 'View data sent to Google',
104+
/**
105+
* @description Text indicating that a link opens in a new tab (for a11y).
106+
*/
107+
opensInNewTab: '(opens in a new tab)',
99108
} as const;
100109

101110
const lockedString = i18n.i18n.lockedString;
@@ -106,6 +115,7 @@ export interface ViewInput {
106115
changeSummary?: string;
107116
patchSuggestion?: string;
108117
patchSuggestionLoading?: boolean;
118+
sources?: string;
109119
projectName?: string;
110120
savedToDisk?: boolean;
111121
projectPath: Platform.DevToolsPath.UrlString;
@@ -135,6 +145,7 @@ export class PatchWidget extends UI.Widget.Widget {
135145
#applyPatchAbortController?: AbortController;
136146
#project?: Workspace.Workspace.Project;
137147
#patchSuggestion?: string;
148+
#patchSources?: string;
138149
#patchSuggestionLoading?: boolean;
139150
#savedToDisk?: boolean;
140151
#workspaceDiff = WorkspaceDiff.WorkspaceDiff.workspaceDiff();
@@ -219,6 +230,13 @@ export class PatchWidget extends UI.Widget.Widget {
219230
})}>
220231
${lockedString(UIStringsNotTranslate.codeDisclaimer)}
221232
</x-link>
233+
${input.sources ? html`<x-link
234+
class="link sources-link"
235+
title="${UIStringsNotTranslate.viewUploadedFiles} ${UIStringsNotTranslate.opensInNewTab}"
236+
href="data:text/plain,${encodeURIComponent(input.sources)}"
237+
jslog=${VisualLogging.link('files-used-in-patching').track({click: true})}>
238+
${UIStringsNotTranslate.viewUploadedFiles}
239+
</x-link>`: nothing}
222240
<div class="save-or-discard-buttons">
223241
<devtools-button
224242
@click=${input.onDiscard}
@@ -333,25 +351,27 @@ export class PatchWidget extends UI.Widget.Widget {
333351
}
334352

335353
override performUpdate(): void {
336-
const viewInput = {
337-
workspaceDiff: this.#workspaceDiff,
338-
changeSummary: this.changeSummary,
339-
patchSuggestion: this.#patchSuggestion,
340-
patchSuggestionLoading: this.#patchSuggestionLoading,
341-
projectName: this.#project?.displayName(),
342-
projectPath: Persistence.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.fileSystemPath(
343-
(this.#project?.id() || '') as Platform.DevToolsPath.UrlString),
344-
savedToDisk: this.#savedToDisk,
345-
onLearnMoreTooltipClick: this.#onLearnMoreTooltipClick.bind(this),
346-
onApplyToWorkspace: this.#onApplyToWorkspace.bind(this),
347-
onCancel: () => {
348-
this.#applyPatchAbortController?.abort();
349-
},
350-
onDiscard: this.#onDiscard.bind(this),
351-
onSaveAll: this.#onSaveAll.bind(this),
352-
onChangeWorkspaceClick: this.#onChangeWorkspaceClick.bind(this),
353-
};
354-
this.#view(viewInput, this.#viewOutput, this.contentElement);
354+
this.#view(
355+
{
356+
workspaceDiff: this.#workspaceDiff,
357+
changeSummary: this.changeSummary,
358+
patchSuggestion: this.#patchSuggestion,
359+
patchSuggestionLoading: this.#patchSuggestionLoading,
360+
sources: this.#patchSources,
361+
projectName: this.#project?.displayName(),
362+
projectPath: Persistence.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.fileSystemPath(
363+
(this.#project?.id() || '') as Platform.DevToolsPath.UrlString),
364+
savedToDisk: this.#savedToDisk,
365+
onLearnMoreTooltipClick: this.#onLearnMoreTooltipClick.bind(this),
366+
onApplyToWorkspace: this.#onApplyToWorkspace.bind(this),
367+
onCancel: () => {
368+
this.#applyPatchAbortController?.abort();
369+
},
370+
onDiscard: this.#onDiscard.bind(this),
371+
onSaveAll: this.#onSaveAll.bind(this),
372+
onChangeWorkspaceClick: this.#onChangeWorkspaceClick.bind(this),
373+
},
374+
this.#viewOutput, this.contentElement);
355375
}
356376

357377
override wasShown(): void {
@@ -463,18 +483,22 @@ export class PatchWidget extends UI.Widget.Widget {
463483

464484
this.#patchSuggestionLoading = true;
465485
this.requestUpdate();
466-
const response = await this.#applyPatch(changeSummary);
486+
const {response, processedFiles} = await this.#applyPatch(changeSummary);
467487
// TODO: Handle error state
468488
if (response?.type === ResponseType.ANSWER) {
469489
this.#patchSuggestion = response.text;
470490
}
491+
this.#patchSources = `Filenames in ${this.#project?.displayName()}.
492+
Files:
493+
${processedFiles.map(filename => `* ${filename}`).join('\n')}`;
471494
this.#patchSuggestionLoading = false;
472495
this.requestUpdate();
473496
}
474497

475498
#onDiscard(): void {
476499
// TODO: Remove changes from the working copies as well.
477500
this.#patchSuggestion = undefined;
501+
this.#patchSources = undefined;
478502
this.requestUpdate();
479503
}
480504

@@ -484,7 +508,10 @@ export class PatchWidget extends UI.Widget.Widget {
484508
this.requestUpdate();
485509
}
486510

487-
async #applyPatch(changeSummary: string): Promise<ResponseData|undefined> {
511+
async #applyPatch(changeSummary: string): Promise<{
512+
response: ResponseData | undefined,
513+
processedFiles: string[],
514+
}> {
488515
if (!this.#project) {
489516
throw new Error('Project does not exist');
490517
}
@@ -494,8 +521,12 @@ export class PatchWidget extends UI.Widget.Widget {
494521
serverSideLoggingEnabled: false,
495522
project: this.#project,
496523
});
497-
const {responses} = await agent.applyChanges(changeSummary, {signal: this.#applyPatchAbortController.signal});
498-
return responses.at(-1);
524+
const {responses, processedFiles} =
525+
await agent.applyChanges(changeSummary, {signal: this.#applyPatchAbortController.signal});
526+
return {
527+
response: responses.at(-1),
528+
processedFiles,
529+
};
499530
}
500531
}
501532

front_end/panels/ai_assistance/components/chatView.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,17 @@ main {
848848
flex-direction: row;
849849
justify-content: space-between;
850850
margin: var(--sys-size-5) 0;
851+
gap: var(--sys-size-6);
851852

852853
.disclaimer-link {
853854
align-self: center;
854855
}
855856

857+
.sources-link {
858+
flex-grow: 1;
859+
align-self: center;
860+
}
861+
856862
.selected-folder {
857863
display: flex;
858864
align-items: center;

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ export const knownContextValues = new Set([
14451445
'fil',
14461446
'fileMappingEntries',
14471447
'fileSystemMapping',
1448+
'files-used-in-patching',
14481449
'fill',
14491450
'fill-opacity',
14501451
'fill-rule',

0 commit comments

Comments
 (0)