@@ -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
101110const 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
0 commit comments