55import '../../ui/components/spinners/spinners.js' ;
66import '../../ui/components/tooltips/tooltips.js' ;
77
8+ import * as Host from '../../core/host/host.js' ;
89import * as i18n from '../../core/i18n/i18n.js' ;
910import * as Root from '../../core/root/root.js' ;
1011import * as UI from '../../ui/legacy/legacy.js' ;
@@ -47,6 +48,7 @@ const lockedString = i18n.i18n.lockedString;
4748export interface ViewInput {
4849 disclaimerTooltipId ?: string ;
4950 noLogging : boolean ;
51+ aidaAvailability ?: Host . AidaClient . AidaAccessPreconditions ;
5052 onManageInSettingsTooltipClick : ( ) => void ;
5153}
5254
@@ -57,13 +59,12 @@ export interface ViewOutput {
5759
5860export type View = ( input : ViewInput , output : ViewOutput , target : HTMLElement ) => void ;
5961
60- export const DEFAULT_SUMMARY_TOOLBAR_VIEW : View =
61- ( input , output , target ) => {
62- if ( ! input . disclaimerTooltipId ) {
63- render ( nothing , target ) ;
64- return ;
65- }
66- // clang-format off
62+ export const DEFAULT_SUMMARY_TOOLBAR_VIEW : View = ( input , output , target ) => {
63+ if ( input . aidaAvailability !== Host . AidaClient . AidaAccessPreconditions . AVAILABLE || ! input . disclaimerTooltipId ) {
64+ render ( nothing , target ) ;
65+ return ;
66+ }
67+ // clang-format off
6768 render (
6869 html `
6970 < style > ${ styles } </ style >
@@ -114,8 +115,8 @@ export const DEFAULT_SUMMARY_TOOLBAR_VIEW: View =
114115 > ${ lockedString ( UIStringsNotTranslate . manageInSettings ) } </ span > </ div > </ devtools-tooltip >
115116 </ div >
116117 ` , target ) ;
117- // clang-format on
118- } ;
118+ // clang-format on
119+ } ;
119120
120121const MINIMUM_LOADING_STATE_TIMEOUT = 1000 ;
121122
@@ -129,11 +130,15 @@ export class AiCodeCompletionDisclaimer extends UI.Widget.Widget {
129130 #loadingStartTime = 0 ;
130131 #spinnerLoadingTimeout: number | undefined ;
131132
133+ #aidaAvailability?: Host . AidaClient . AidaAccessPreconditions ;
134+ #boundOnAidaAvailabilityChange: ( ) => Promise < void > ;
135+
132136 constructor ( element ?: HTMLElement , view : View = DEFAULT_SUMMARY_TOOLBAR_VIEW ) {
133137 super ( element ) ;
134138 this . markAsExternallyManaged ( ) ;
135139 this . #noLogging = Root . Runtime . hostConfig . aidaAvailability ?. enterprisePolicyValue ===
136140 Root . Runtime . GenAiEnterprisePolicyValue . ALLOW_WITHOUT_LOGGING ;
141+ this . #boundOnAidaAvailabilityChange = this . #onAidaAvailabilityChange. bind ( this ) ;
137142 this . #view = view ;
138143 }
139144
@@ -169,6 +174,14 @@ export class AiCodeCompletionDisclaimer extends UI.Widget.Widget {
169174 }
170175 }
171176
177+ async #onAidaAvailabilityChange( ) : Promise < void > {
178+ const currentAidaAvailability = await Host . AidaClient . AidaClient . checkAccessPreconditions ( ) ;
179+ if ( currentAidaAvailability !== this . #aidaAvailability) {
180+ this . #aidaAvailability = currentAidaAvailability ;
181+ this . requestUpdate ( ) ;
182+ }
183+ }
184+
172185 #onManageInSettingsTooltipClick( ) : void {
173186 this . #viewOutput. hideTooltip ?.( ) ;
174187 void UI . ViewManager . ViewManager . instance ( ) . showView ( 'chrome-ai' ) ;
@@ -179,8 +192,22 @@ export class AiCodeCompletionDisclaimer extends UI.Widget.Widget {
179192 {
180193 disclaimerTooltipId : this . #disclaimerTooltipId,
181194 noLogging : this . #noLogging,
195+ aidaAvailability : this . #aidaAvailability,
182196 onManageInSettingsTooltipClick : this . #onManageInSettingsTooltipClick. bind ( this ) ,
183197 } ,
184198 this . #viewOutput, this . contentElement ) ;
185199 }
200+
201+ override wasShown ( ) : void {
202+ super . wasShown ( ) ;
203+ Host . AidaClient . HostConfigTracker . instance ( ) . addEventListener (
204+ Host . AidaClient . Events . AIDA_AVAILABILITY_CHANGED , this . #boundOnAidaAvailabilityChange) ;
205+ void this . #onAidaAvailabilityChange( ) ;
206+ }
207+
208+ override willHide ( ) : void {
209+ super . willHide ( ) ;
210+ Host . AidaClient . HostConfigTracker . instance ( ) . removeEventListener (
211+ Host . AidaClient . Events . AIDA_AVAILABILITY_CHANGED , this . #boundOnAidaAvailabilityChange) ;
212+ }
186213}
0 commit comments