@@ -10,7 +10,6 @@ import type * as Platform from '../../../core/platform/platform.js';
1010import * as SDK from '../../../core/sdk/sdk.js' ;
1111import * as Protocol from '../../../generated/protocol.js' ;
1212import * as AiAssistanceModel from '../../../models/ai_assistance/ai_assistance.js' ;
13- import * as Workspace from '../../../models/workspace/workspace.js' ;
1413import * as PanelsCommon from '../../../panels/common/common.js' ;
1514import * as PanelUtils from '../../../panels/utils/utils.js' ;
1615import * as Buttons from '../../../ui/components/buttons/buttons.js' ;
@@ -37,14 +36,6 @@ const UIStrings = {
3736 * @description The footer disclaimer that links to more information about the AI feature.
3837 */
3938 learnAbout : 'Learn about AI in DevTools' ,
40- /**
41- * @description Label added to the button that remove the currently selected context in AI Assistance panel.
42- */
43- removeContext : 'Remove from context' ,
44- /**
45- * @description Label added to the button that add selected context from the current panel in AI Assistance panel.
46- */
47- addContext : 'Add selected item as context' ,
4839} as const ;
4940
5041/*
@@ -91,6 +82,30 @@ const UIStringsNotTranslate = {
9182 * @description Message displayed in toast in case of any failures while uploading an image file as input.
9283 */
9384 uploadImageFailureMessage : 'Failed to upload image. Please try again.' ,
85+ /**
86+ * @description Label added to the button that add selected context from the current panel in AI Assistance panel.
87+ */
88+ addContext : 'Add item for context' ,
89+ /**
90+ * @description Label added to the button that remove the currently selected element in AI Assistance panel.
91+ */
92+ removeContextElement : 'Remove element from context' ,
93+ /**
94+ * @description Label added to the button that remove the currently selected context in AI Assistance panel.
95+ */
96+ removeContextRequest : 'Remove request from context' ,
97+ /**
98+ * @description Label added to the button that remove the currently selected context in AI Assistance panel.
99+ */
100+ removeContextFile : 'Remove file from context' ,
101+ /**
102+ * @description Label added to the button that remove the currently selected context in AI Assistance panel.
103+ */
104+ removeContextPerfInsight : 'Remove performance insight from context' ,
105+ /**
106+ * @description Label added to the button that remove the currently selected context in AI Assistance panel.
107+ */
108+ removeContext : 'Remove from context' ,
94109} as const ;
95110
96111const str_ = i18n . i18n . registerUIStrings ( 'panels/ai_assistance/components/ChatInput.ts' , UIStrings ) ;
@@ -148,6 +163,23 @@ export interface ViewInput {
148163
149164export type ViewOutput = undefined ;
150165
166+ function getContextRemoveLabel ( context : AiAssistanceModel . AiAgent . ConversationContext < unknown > ) :
167+ Platform . UIString . LocalizedString {
168+ if ( context instanceof AiAssistanceModel . FileAgent . FileContext ) {
169+ return lockedString ( UIStringsNotTranslate . removeContextFile ) ;
170+ }
171+ if ( context instanceof AiAssistanceModel . StylingAgent . NodeContext ) {
172+ return lockedString ( UIStringsNotTranslate . removeContextElement ) ;
173+ }
174+ if ( context instanceof AiAssistanceModel . NetworkAgent . RequestContext ) {
175+ return lockedString ( UIStringsNotTranslate . removeContextRequest ) ;
176+ }
177+ if ( context instanceof AiAssistanceModel . PerformanceAgent . PerformanceTraceContext ) {
178+ return lockedString ( UIStringsNotTranslate . removeContextPerfInsight ) ;
179+ }
180+ return lockedString ( UIStringsNotTranslate . removeContext ) ;
181+ }
182+
151183export const DEFAULT_VIEW = ( input : ViewInput , _output : ViewOutput , target : HTMLElement ) : void => {
152184 const chatInputContainerCls = Lit . Directives . classMap ( {
153185 'chat-input-container' : true ,
@@ -303,20 +335,20 @@ export const DEFAULT_VIEW = (input: ViewInput, _output: ViewOutput, target: HTML
303335 } }
304336 aria-description=${ i18nString ( UIStrings . revealContextDescription ) }
305337 >
306- ${ input . selectedContext . getItem ( ) instanceof SDK . NetworkRequest . NetworkRequest ?
307- PanelUtils . PanelUtils . getIconForNetworkRequest ( input . selectedContext . getItem ( ) as SDK . NetworkRequest . NetworkRequest ) :
308- input . selectedContext . getItem ( ) instanceof Workspace . UISourceCode . UISourceCode ?
309- PanelUtils . PanelUtils . getIconForSourceFile ( input . selectedContext . getItem ( ) as Workspace . UISourceCode . UISourceCode ) :
310- input . selectedContext . getItem ( ) instanceof AiAssistanceModel . AIContext . AgentFocus ?
338+ ${ input . selectedContext instanceof AiAssistanceModel . NetworkAgent . RequestContext ?
339+ PanelUtils . PanelUtils . getIconForNetworkRequest ( input . selectedContext . getItem ( ) ) :
340+ input . selectedContext instanceof AiAssistanceModel . FileAgent . FileContext ?
341+ PanelUtils . PanelUtils . getIconForSourceFile ( input . selectedContext . getItem ( ) ) :
342+ input . selectedContext instanceof AiAssistanceModel . PerformanceAgent . PerformanceTraceContext ?
311343 html `< devtools-icon name ="performance " title ="Performance "> </ devtools-icon > ` :
312344 Lit . nothing }
313345 < span class ="title ">
314- ${ input . selectedContext . getItem ( ) instanceof SDK . DOMModel . DOMNode ?
346+ ${ input . selectedContext instanceof AiAssistanceModel . StylingAgent . NodeContext ?
315347 html `
316348 < devtools-widget .widgetConfig =${ UI . Widget . widgetConfig ( PanelsCommon . DOMLinkifier . DOMNodeLink , {
317- node : input . selectedContext . getItem ( ) as SDK . DOMModel . DOMNode ,
349+ node : input . selectedContext . getItem ( ) ,
318350 options : {
319- hiddenClassList : ( input . selectedContext . getItem ( ) as SDK . DOMModel . DOMNode ) . classNames ( ) . filter (
351+ hiddenClassList : input . selectedContext . getItem ( ) . classNames ( ) . filter (
320352 className => className . startsWith ( AiAssistanceModel . Injected . AI_ASSISTANCE_CSS_CLASS_NAME ) ) ,
321353 disabled : input . isTextInputDisabled ,
322354 } ,
@@ -326,8 +358,8 @@ export const DEFAULT_VIEW = (input: ViewInput, _output: ViewOutput, target: HTML
326358 </ span >
327359 ${ input . onContextRemoved ? html `
328360 < devtools-button
329- title =${ i18nString ( UIStrings . removeContext ) }
330- aria-label =${ i18nString ( UIStrings . removeContext ) }
361+ title =${ getContextRemoveLabel ( input . selectedContext ) }
362+ aria-label =${ getContextRemoveLabel ( input . selectedContext ) }
331363 class="remove-context"
332364 .iconName=${ 'cross' }
333365 .size=${ Buttons . Button . Size . MICRO }
@@ -339,8 +371,8 @@ export const DEFAULT_VIEW = (input: ViewInput, _output: ViewOutput, target: HTML
339371 :
340372 input . onContextAdd ? html `
341373 < devtools-button
342- title =${ i18nString ( UIStrings . addContext ) }
343- aria-label =${ i18nString ( UIStrings . addContext ) }
374+ title =${ lockedString ( UIStringsNotTranslate . addContext ) }
375+ aria-label =${ lockedString ( UIStringsNotTranslate . addContext ) }
344376 class="add-context"
345377 .iconName=${ 'plus' }
346378 .size=${ Buttons . Button . Size . SMALL }
@@ -442,7 +474,7 @@ export const DEFAULT_VIEW = (input: ViewInput, _output: ViewOutput, target: HTML
442474 >
443475 ${ renderRelevantDataDisclaimer ( RELEVANT_DATA_LINK_FOOTER_ID ) }
444476 </ footer >
445- ` , target ) ;
477+ ` , target , ) ;
446478 // clang-format on
447479} ;
448480
@@ -454,7 +486,7 @@ export class ChatInput extends UI.Widget.Widget implements SDK.TargetManager.Obs
454486 blockedByCrossOrigin = false ;
455487 isTextInputDisabled = false ;
456488 inputPlaceholder = '' as Platform . UIString . LocalizedString ;
457- selectedContext = null as AiAssistanceModel . AiAgent . ConversationContext < unknown > | null ;
489+ selectedContext : AiAssistanceModel . AiAgent . ConversationContext < unknown > | null = null ;
458490 inspectElementToggled = false ;
459491 disclaimerText = '' ;
460492 conversationType = AiAssistanceModel . AiHistoryStorage . ConversationType . STYLING ;
0 commit comments