From 00fc336962c9d9395d0bca0067e5be0d2afc76cf Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 17 Dec 2024 10:16:54 -0500 Subject: [PATCH] fix(preferences): don't derive enableGenAIFeatures from org, allow disabling it COMPASS-8680 (#6563) --- .../src/preferences-schema.ts | 20 +------------------ .../src/preferences.spec.ts | 5 +---- .../compass-preferences-model/src/utils.ts | 15 ++++++++++++-- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 2cf49d575b9..7c9e45bd0d3 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -472,10 +472,7 @@ export const storedUserPreferencesProps: Required<{ short: 'Enable AI Features', long: 'Allow the use of AI features in Compass which make requests to 3rd party services.', }, - deriveValue: deriveValueFromOtherPreferencesAsLogicalAnd( - 'enableGenAIFeatures', - ['enableGenAIFeaturesAtlasOrg', 'networkTraffic'] - ), + deriveValue: deriveNetworkTrafficOptionState('enableGenAIFeatures'), validator: z.boolean().default(true), type: 'boolean', }, @@ -1072,21 +1069,6 @@ function deriveNetworkTrafficOptionState( }); } -/** Helper for deriving value/state for preferences from other preferences */ -function deriveValueFromOtherPreferencesAsLogicalAnd< - K extends keyof AllPreferences ->(property: K, preferencesToDeriveFrom: K[]): DeriveValueFunction { - return (v, s) => ({ - value: v(property) && preferencesToDeriveFrom.every((p) => v(p)), - state: - s(property) ?? - (preferencesToDeriveFrom.every((p) => v(p)) - ? preferencesToDeriveFrom.map((p) => s(p)).filter(Boolean)?.[0] ?? - 'derived' - : undefined), - }); -} - /** Helper for defining how to derive value/state for feature-restricting preferences */ function deriveFeatureRestrictingOptionsState( property: K diff --git a/packages/compass-preferences-model/src/preferences.spec.ts b/packages/compass-preferences-model/src/preferences.spec.ts index d8cd53a8e48..e43da91cc8c 100644 --- a/packages/compass-preferences-model/src/preferences.spec.ts +++ b/packages/compass-preferences-model/src/preferences.spec.ts @@ -132,7 +132,6 @@ describe('Preferences class', function () { expect(states).to.deep.equal({ trackUsageStatistics: 'set-global', enableMaps: 'set-cli', - enableGenAIFeatures: 'derived', ...expectedReleasedFeatureFlagsStates, }); }); @@ -164,6 +163,7 @@ describe('Preferences class', function () { enableDevTools: 'set-global', networkTraffic: 'set-global', trackUsageStatistics: 'set-global', + enableGenAIFeatures: 'set-global', enableMaps: 'set-cli', enableShell: 'set-cli', readOnly: 'set-global', @@ -185,7 +185,6 @@ describe('Preferences class', function () { expect(states).to.deep.equal({ readOnly: 'set-global', - enableGenAIFeatures: 'derived', ...expectedReleasedFeatureFlagsStates, }); }); @@ -296,7 +295,6 @@ describe('Preferences class', function () { expect(mainPreferencesStates).to.deep.equal({ trackUsageStatistics: 'set-global', - enableGenAIFeatures: 'derived', enableMaps: 'set-cli', ...expectedReleasedFeatureFlagsStates, }); @@ -304,7 +302,6 @@ describe('Preferences class', function () { const sandboxPreferencesStates = sandbox.getPreferenceStates(); expect(sandboxPreferencesStates).to.deep.equal({ enableDevTools: 'derived', - enableGenAIFeatures: 'derived', trackUsageStatistics: 'set-global', enableMaps: 'set-cli', enableShell: 'derived', diff --git a/packages/compass-preferences-model/src/utils.ts b/packages/compass-preferences-model/src/utils.ts index 287593f05d3..136e406127a 100644 --- a/packages/compass-preferences-model/src/utils.ts +++ b/packages/compass-preferences-model/src/utils.ts @@ -30,25 +30,36 @@ export function getActiveUser( export function isAIFeatureEnabled( preferences: Pick< AllPreferences, - 'enableGenAIFeatures' | 'cloudFeatureRolloutAccess' + | 'enableGenAIFeatures' + | 'cloudFeatureRolloutAccess' + | 'enableGenAIFeaturesAtlasOrg' > ) { const { // a "kill switch" property from configuration file to be able to disable // feature in global config enableGenAIFeatures, + enableGenAIFeaturesAtlasOrg, // based on mms backend rollout response cloudFeatureRolloutAccess, } = preferences; - return enableGenAIFeatures && !!cloudFeatureRolloutAccess?.GEN_AI_COMPASS; + return ( + enableGenAIFeatures && + enableGenAIFeaturesAtlasOrg && + !!cloudFeatureRolloutAccess?.GEN_AI_COMPASS + ); } export function useIsAIFeatureEnabled() { const enableGenAIFeatures = usePreference('enableGenAIFeatures'); + const enableGenAIFeaturesAtlasOrg = usePreference( + 'enableGenAIFeaturesAtlasOrg' + ); const cloudFeatureRolloutAccess = usePreference('cloudFeatureRolloutAccess'); return isAIFeatureEnabled({ enableGenAIFeatures, + enableGenAIFeaturesAtlasOrg, cloudFeatureRolloutAccess, }); }