UNPKG

chrome-devtools-frontend

Version:
57 lines (53 loc) 2.64 kB
// Copyright 2025 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import * as Common from '../../core/common/common.js'; import * as Host from '../../core/host/host.js'; import * as i18n from '../../core/i18n/i18n.js'; import type * as Platform from '../../core/platform/platform.js'; import * as Root from '../../core/root/root.js'; const UIStrings = { /** * @description Message shown to the user if the age check is not successful. */ ageRestricted: 'This feature is only available to users who are 18 years of age or older.', /** * @description The error message when the user is not logged in into Chrome. */ notLoggedIn: 'This feature is only available when you sign into Chrome with your Google account.', /** * @description Message shown when the user is offline. */ offline: 'This feature is only available with an active internet connection.', /** *@description Text informing the user that AI assistance is not available in Incognito mode or Guest mode. */ notAvailableInIncognitoMode: 'AI assistance is not available in Incognito mode or Guest mode.', } as const; const str_ = i18n.i18n.registerUIStrings('models/ai_assistance/AiUtils.ts', UIStrings); const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); export function getDisabledReasons(aidaAvailability: Host.AidaClient.AidaAccessPreconditions): Platform.UIString.LocalizedString[] { const reasons: Platform.UIString.LocalizedString[] = []; if (Root.Runtime.hostConfig.isOffTheRecord) { reasons.push(i18nString(UIStrings.notAvailableInIncognitoMode)); } switch (aidaAvailability) { case Host.AidaClient.AidaAccessPreconditions.NO_ACCOUNT_EMAIL: case Host.AidaClient.AidaAccessPreconditions.SYNC_IS_PAUSED: reasons.push(i18nString(UIStrings.notLoggedIn)); break; // @ts-expect-error case Host.AidaClient.AidaAccessPreconditions.NO_INTERNET: // fallthrough reasons.push(i18nString(UIStrings.offline)); case Host.AidaClient.AidaAccessPreconditions.AVAILABLE: { // No age check if there is no logged in user. Age check would always fail in that case. if (Root.Runtime.hostConfig?.aidaAvailability?.blockedByAge === true) { reasons.push(i18nString(UIStrings.ageRestricted)); } } } // The `console-insights-enabled` setting and the `ai-assistance-enabled` setting both have the same `disabledReasons`. reasons.push(...Common.Settings.Settings.instance().moduleSetting('ai-assistance-enabled').disabledReasons()); return reasons; }