From 25abe51817847eb6a8cdf524966b7f58f3ff0ff1 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Tue, 15 Oct 2024 15:25:20 -0400 Subject: [PATCH 01/13] limit increased and message improved for PROMPT_TOO_LONG --- packages/compass-generative-ai/src/atlas-ai-service.ts | 2 +- .../src/components/generative-ai-input.spec.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compass-generative-ai/src/atlas-ai-service.ts b/packages/compass-generative-ai/src/atlas-ai-service.ts index dbfa1fb23e8..49a8ccf2777 100644 --- a/packages/compass-generative-ai/src/atlas-ai-service.ts +++ b/packages/compass-generative-ai/src/atlas-ai-service.ts @@ -24,7 +24,7 @@ type GenerativeAiInput = { // The size/token validation happens on the server, however, we do // want to ensure we're not uploading massive documents (some folks have documents > 1mb). -const AI_MAX_REQUEST_SIZE = 100000; +const AI_MAX_REQUEST_SIZE = 5120000; const AI_MIN_SAMPLE_DOCUMENTS = 1; const USER_AI_URI = (userId: string) => `unauth/ai/api/v1/hello/${userId}`; const AGGREGATION_URI = 'ai/api/v1/mql-aggregation'; diff --git a/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx b/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx index 26c24067eb9..73c70624410 100644 --- a/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx +++ b/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx @@ -112,7 +112,7 @@ describe('GenerativeAIInput Component', function () { ], [ 'PROMPT_TOO_LONG', - 'Sorry, your collections have too many fields to process. Please try using this feature on a collection with smaller documents.', + 'Sorry, your prompt is too long and has exceeded the token limit. Please try using this feature with a shorter prompt.', ], [ 'TOO_MANY_REQUESTS', From 6d015ab06ffb50c8e830946d1b31a3f6139be42d Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Tue, 15 Oct 2024 15:43:58 -0400 Subject: [PATCH 02/13] updating prompt_too_long error msg --- .../src/components/generative-ai-input.spec.tsx | 2 +- .../src/components/generative-ai-input.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx b/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx index 73c70624410..7e5ff722a01 100644 --- a/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx +++ b/packages/compass-generative-ai/src/components/generative-ai-input.spec.tsx @@ -112,7 +112,7 @@ describe('GenerativeAIInput Component', function () { ], [ 'PROMPT_TOO_LONG', - 'Sorry, your prompt is too long and has exceeded the token limit. Please try using this feature with a shorter prompt.', + 'Sorry, your request is too large. Please use a smaller prompt or try using this feature on a collection with smaller documents.', ], [ 'TOO_MANY_REQUESTS', diff --git a/packages/compass-generative-ai/src/components/generative-ai-input.tsx b/packages/compass-generative-ai/src/components/generative-ai-input.tsx index 36274cd90d4..81670398118 100644 --- a/packages/compass-generative-ai/src/components/generative-ai-input.tsx +++ b/packages/compass-generative-ai/src/components/generative-ai-input.tsx @@ -569,7 +569,7 @@ const AIError = ({ // able to fix the issue on their own it cases where the schema is too big. return ( <> - Sorry, your collections have too many fields to process. Please try + Sorry, your request is too large. Please use a smaller prompt or try using this feature on a collection with smaller documents. ); From e0858410982da15841f5b5355b7bbe80fea063ef Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Tue, 15 Oct 2024 15:52:05 -0400 Subject: [PATCH 03/13] updating test --- packages/compass-generative-ai/src/atlas-ai-service.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compass-generative-ai/src/atlas-ai-service.spec.ts b/packages/compass-generative-ai/src/atlas-ai-service.spec.ts index d5c5b2a34cb..14894c420a4 100644 --- a/packages/compass-generative-ai/src/atlas-ai-service.spec.ts +++ b/packages/compass-generative-ai/src/atlas-ai-service.spec.ts @@ -204,7 +204,7 @@ describe('AtlasAiService', function () { userInput: 'test', collectionName: 'test', databaseName: 'peanut', - sampleDocuments: [{ test: '4'.repeat(600000) }], + sampleDocuments: [{ test: '4'.repeat(5120001) }], requestId: 'abc', signal: new AbortController().signal, }); @@ -231,7 +231,7 @@ describe('AtlasAiService', function () { { a: '1' }, { a: '2' }, { a: '3' }, - { a: '4'.repeat(500000) }, + { a: '4'.repeat(5120001) }, ], requestId: 'abc', signal: new AbortController().signal, From 26d955f1da5b92b4b84ec8670f9fa6f696eb403e Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 31 Oct 2024 16:35:59 -0400 Subject: [PATCH 04/13] initial ticket changes --- .../src/compass-web-preferences-access.ts | 75 ++++++++++++++++ .../src/preferences-schema.ts | 87 ++++++++++++++++++- .../compass-preferences-model/src/provider.ts | 1 + 3 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 packages/compass-preferences-model/src/compass-web-preferences-access.ts diff --git a/packages/compass-preferences-model/src/compass-web-preferences-access.ts b/packages/compass-preferences-model/src/compass-web-preferences-access.ts new file mode 100644 index 00000000000..9e4c87d5dc3 --- /dev/null +++ b/packages/compass-preferences-model/src/compass-web-preferences-access.ts @@ -0,0 +1,75 @@ +import { createNoopLogger } from '@mongodb-js/compass-logging/provider'; +import { Preferences, type PreferencesAccess } from './preferences'; +import type { UserPreferences } from './preferences-schema'; +import { type AllPreferences } from './preferences-schema'; +import { InMemoryStorage } from './preferences-in-memory-storage'; +import { getActiveUser } from './utils'; + +export class CompassWebPreferencesAccess implements PreferencesAccess { + private _preferences: Preferences; + constructor(preferencesOverrides?: Partial) { + this._preferences = new Preferences({ + logger: createNoopLogger(), + preferencesStorage: new InMemoryStorage(preferencesOverrides), + }); + } + + savePreferences(_attributes: Partial) { + if ( + Object.keys(_attributes).length === 1 && + 'optInDataExplorerGenAIFeatures' in _attributes + ) { + return Promise.resolve(this._preferences.savePreferences(_attributes)); + } + // do not save any attributes other than the optInDataExplorerGenAIFeatures setting + return Promise.resolve(this._preferences.getPreferences()); + } + + refreshPreferences() { + return Promise.resolve(this._preferences.getPreferences()); + } + + getPreferences() { + return this._preferences.getPreferences(); + } + + ensureDefaultConfigurableUserPreferences() { + return this._preferences.ensureDefaultConfigurableUserPreferences(); + } + + getConfigurableUserPreferences() { + return Promise.resolve(this._preferences.getConfigurableUserPreferences()); + } + + getPreferenceStates() { + return Promise.resolve(this._preferences.getPreferenceStates()); + } + + onPreferenceValueChanged( + preferenceName: K, + callback: (value: AllPreferences[K]) => void + ) { + return ( + this._preferences?.onPreferencesChanged?.( + (preferences: Partial) => { + if (Object.keys(preferences).includes(preferenceName)) { + return callback((preferences as AllPreferences)[preferenceName]); + } + } + ) ?? + (() => { + /* no fallback */ + }) + ); + } + + createSandbox() { + return Promise.resolve( + new CompassWebPreferencesAccess(this.getPreferences()) + ); + } + + getPreferencesUser() { + return getActiveUser(this); + } +} diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 60b5d900484..0241f44b48f 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -56,6 +56,7 @@ export type UserConfigurablePreferences = PermanentFeatureFlags & | 'web-sandbox-atlas-local' | 'web-sandbox-atlas-dev' | 'web-sandbox-atlas'; + optInDataExplorerGenAIFeatures: boolean; // Features that are enabled by default in Compass, but are disabled in Data // Explorer enableExplainPlan: boolean; @@ -115,7 +116,9 @@ export type NonUserPreferences = { export type AllPreferences = UserPreferences & CliOnlyPreferences & NonUserPreferences & - PermanentFeatureFlags; + PermanentFeatureFlags & + AtlasProjectPreferences & + AtlasOrgPreferences; // Types related to PreferenceDefinition type PostProcessFunction = ( @@ -210,6 +213,15 @@ export type StoredPreferencesValidator = ReturnType< export type StoredPreferences = z.output; +export type AtlasProjectPreferences = { + enableGenAIFeaturesAtlasProject?: boolean; + enableGenAISampleDocumentPassingOnAtlasProject?: boolean; +}; + +export type AtlasOrgPreferences = { + enableGenAIFeaturesAtlasOrg?: boolean; +}; + // Preference definitions const featureFlagsProps: Required<{ [K in keyof FeatureFlags]: PreferenceDefinition; @@ -461,7 +473,10 @@ 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: deriveNetworkTrafficOptionState('enableGenAIFeatures'), + deriveValue: deriveValueFromOtherPreferences('enableGenAIFeatures', [ + 'enableGenAIFeaturesAtlasOrg', + 'networkTraffic', + ]), validator: z.boolean().default(true), type: 'boolean', }, @@ -679,6 +694,16 @@ export const storedUserPreferencesProps: Required<{ .default('atlas'), type: 'string', }, + optInDataExplorerGenAIFeatures: { + ui: true, + cli: false, + global: false, + description: { + short: 'User Opt-in for Data Explorer Gen AI Features', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, enableAtlasSearchIndexes: { ui: true, @@ -1007,12 +1032,54 @@ const nonUserPreferences: Required<{ }, }; +const atlasProjectPreferencesProps: Required<{ + [K in keyof NonUserPreferences]: PreferenceDefinition; +}> = { + enableGenAIFeaturesAtlasProject: { + ui: true, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Features on Atlas Project Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, + enableGenAISampleDocumentPassingOnAtlasProject: { + ui: true, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Sample Document Passing on Atlas Project Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, +}; + +const atlasOrgPreferencesProps: Required<{ + [K in keyof NonUserPreferences]: PreferenceDefinition; +}> = { + enableGenAIFeaturesAtlasOrg: { + ui: true, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Features on Atlas Org Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, +}; + export const allPreferencesProps: Required<{ [K in keyof AllPreferences]: PreferenceDefinition; }> = { ...storedUserPreferencesProps, ...cliOnlyPreferencesProps, ...nonUserPreferences, + ...atlasProjectPreferencesProps, + ...atlasOrgPreferencesProps, }; /** Helper for defining how to derive value/state for networkTraffic-affected preferences */ @@ -1027,6 +1094,22 @@ function deriveNetworkTrafficOptionState( }); } +/** Helper for deriving value/state for preferences from other preferences */ +function deriveValueFromOtherPreferences( + 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/provider.ts b/packages/compass-preferences-model/src/provider.ts index b5f3bfc92dc..ef2fa77b65c 100644 --- a/packages/compass-preferences-model/src/provider.ts +++ b/packages/compass-preferences-model/src/provider.ts @@ -1,5 +1,6 @@ export * from './react'; export { ReadOnlyPreferenceAccess } from './read-only-preferences-access'; +export { CompassWebPreferencesAccess } from './compass-web-preferences-access'; export { useIsAIFeatureEnabled, isAIFeatureEnabled, From b4dbf9e7d11ae614fd6d77e527e63420f57d8830 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 31 Oct 2024 16:37:39 -0400 Subject: [PATCH 05/13] entrypoint changed --- packages/compass-web/src/entrypoint.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/compass-web/src/entrypoint.tsx b/packages/compass-web/src/entrypoint.tsx index e2103fe782b..9beb7d71343 100644 --- a/packages/compass-web/src/entrypoint.tsx +++ b/packages/compass-web/src/entrypoint.tsx @@ -39,7 +39,7 @@ import { } from '@mongodb-js/compass-databases-collections'; import { PreferencesProvider, - ReadOnlyPreferenceAccess, + CompassWebPreferencesAccess, } from 'compass-preferences-model/provider'; import type { AllPreferences } from 'compass-preferences-model/provider'; import FieldStorePlugin from '@mongodb-js/compass-field-store'; @@ -260,7 +260,7 @@ const CompassWeb = ({ }); const preferencesAccess = useRef( - new ReadOnlyPreferenceAccess({ + new CompassWebPreferencesAccess({ maxTimeMS: 10_000, enableExplainPlan: true, enableAggregationBuilderRunPipeline: true, @@ -277,6 +277,7 @@ const CompassWeb = ({ enableShell: false, enableCreatingNewConnections: false, enableGlobalWrites: false, + optInDataExplorerGenAIFeatures: false, ...initialPreferences, }) ); From d685195b17a9b5ce9c80f27faf0648a5f0959144 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Fri, 1 Nov 2024 10:57:11 -0400 Subject: [PATCH 06/13] prefProps for atlas org and atlas proj prefs --- .../src/preferences-schema.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 0241f44b48f..1103ebaa138 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -1033,10 +1033,10 @@ const nonUserPreferences: Required<{ }; const atlasProjectPreferencesProps: Required<{ - [K in keyof NonUserPreferences]: PreferenceDefinition; + [K in keyof AtlasProjectPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasProject: { - ui: true, + ui: false, cli: true, global: true, description: { @@ -1046,7 +1046,7 @@ const atlasProjectPreferencesProps: Required<{ type: 'boolean', }, enableGenAISampleDocumentPassingOnAtlasProject: { - ui: true, + ui: false, cli: true, global: true, description: { @@ -1058,10 +1058,10 @@ const atlasProjectPreferencesProps: Required<{ }; const atlasOrgPreferencesProps: Required<{ - [K in keyof NonUserPreferences]: PreferenceDefinition; + [K in keyof AtlasOrgPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasOrg: { - ui: true, + ui: false, cli: true, global: true, description: { From 89589314bdecb9f9049464eefb5b23c27e1e6bc4 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Mon, 4 Nov 2024 16:13:58 -0500 Subject: [PATCH 07/13] function name change --- .../src/preferences-schema.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 1103ebaa138..1811f08ea9e 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -473,10 +473,10 @@ 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: deriveValueFromOtherPreferences('enableGenAIFeatures', [ - 'enableGenAIFeaturesAtlasOrg', - 'networkTraffic', - ]), + deriveValue: deriveValueFromOtherPreferencesAsLogicalAnd( + 'enableGenAIFeatures', + ['enableGenAIFeaturesAtlasOrg', 'networkTraffic'] + ), validator: z.boolean().default(true), type: 'boolean', }, @@ -1095,12 +1095,11 @@ function deriveNetworkTrafficOptionState( } /** Helper for deriving value/state for preferences from other preferences */ -function deriveValueFromOtherPreferences( - property: K, - preferencesToDeriveFrom: K[] -): DeriveValueFunction { +function deriveValueFromOtherPreferencesAsLogicalAnd< + K extends keyof AllPreferences +>(property: K, preferencesToDeriveFrom: K[]): DeriveValueFunction { return (v, s) => ({ - value: v(property) && preferencesToDeriveFrom.every((p) => v(p)), + value: preferencesToDeriveFrom.every((p) => v(p)), state: s(property) ?? (preferencesToDeriveFrom.every((p) => v(p)) From 2b71ed3e59647933b07b59b133e22d214bcf8633 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Tue, 5 Nov 2024 14:36:13 -0500 Subject: [PATCH 08/13] fixing base values --- .../compass-preferences-model/src/preferences-schema.ts | 6 +++--- packages/compass-preferences-model/src/preferences.spec.ts | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 1811f08ea9e..ef220d549c5 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -1036,7 +1036,7 @@ const atlasProjectPreferencesProps: Required<{ [K in keyof AtlasProjectPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasProject: { - ui: false, + ui: true, cli: true, global: true, description: { @@ -1046,7 +1046,7 @@ const atlasProjectPreferencesProps: Required<{ type: 'boolean', }, enableGenAISampleDocumentPassingOnAtlasProject: { - ui: false, + ui: true, cli: true, global: true, description: { @@ -1061,7 +1061,7 @@ const atlasOrgPreferencesProps: Required<{ [K in keyof AtlasOrgPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasOrg: { - ui: false, + ui: true, cli: true, global: true, description: { diff --git a/packages/compass-preferences-model/src/preferences.spec.ts b/packages/compass-preferences-model/src/preferences.spec.ts index c1acb216973..36e8b8b68b9 100644 --- a/packages/compass-preferences-model/src/preferences.spec.ts +++ b/packages/compass-preferences-model/src/preferences.spec.ts @@ -163,7 +163,6 @@ 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', @@ -227,7 +226,6 @@ describe('Preferences class', function () { }, { networkTraffic: false, - enableGenAIFeatures: false, enableMaps: false, enableFeedbackPanel: false, trackUsageStatistics: false, From 2beda7876fb9cce8c5fb381c162a9c1d29605591 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Wed, 6 Nov 2024 15:12:18 -0500 Subject: [PATCH 09/13] changing ui default back --- .../compass-preferences-model/src/preferences-schema.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index ef220d549c5..1811f08ea9e 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -1036,7 +1036,7 @@ const atlasProjectPreferencesProps: Required<{ [K in keyof AtlasProjectPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasProject: { - ui: true, + ui: false, cli: true, global: true, description: { @@ -1046,7 +1046,7 @@ const atlasProjectPreferencesProps: Required<{ type: 'boolean', }, enableGenAISampleDocumentPassingOnAtlasProject: { - ui: true, + ui: false, cli: true, global: true, description: { @@ -1061,7 +1061,7 @@ const atlasOrgPreferencesProps: Required<{ [K in keyof AtlasOrgPreferences]: PreferenceDefinition; }> = { enableGenAIFeaturesAtlasOrg: { - ui: true, + ui: false, cli: true, global: true, description: { From 1182707e02de6022c10151065e82c5bdb042e2be Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 7 Nov 2024 10:22:02 -0500 Subject: [PATCH 10/13] comment nit --- .../src/compass-web-preferences-access.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-preferences-model/src/compass-web-preferences-access.ts b/packages/compass-preferences-model/src/compass-web-preferences-access.ts index 9e4c87d5dc3..abad3f2446d 100644 --- a/packages/compass-preferences-model/src/compass-web-preferences-access.ts +++ b/packages/compass-preferences-model/src/compass-web-preferences-access.ts @@ -15,13 +15,13 @@ export class CompassWebPreferencesAccess implements PreferencesAccess { } savePreferences(_attributes: Partial) { + // Only allow saving the optInDataExplorerGenAIFeatures preference. if ( Object.keys(_attributes).length === 1 && 'optInDataExplorerGenAIFeatures' in _attributes ) { return Promise.resolve(this._preferences.savePreferences(_attributes)); } - // do not save any attributes other than the optInDataExplorerGenAIFeatures setting return Promise.resolve(this._preferences.getPreferences()); } From 660100b78e5f695f4d5504d07dfe78fdd8f14cf9 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 7 Nov 2024 11:40:00 -0500 Subject: [PATCH 11/13] moving prop defs so defaults get set as part of userpreferences --- .../src/preferences-schema.ts | 88 ++++++++----------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/packages/compass-preferences-model/src/preferences-schema.ts b/packages/compass-preferences-model/src/preferences-schema.ts index 1811f08ea9e..53d49eb2052 100644 --- a/packages/compass-preferences-model/src/preferences-schema.ts +++ b/packages/compass-preferences-model/src/preferences-schema.ts @@ -93,7 +93,9 @@ export type InternalUserPreferences = { // UserPreferences contains all preferences stored to disk. export type UserPreferences = UserConfigurablePreferences & - InternalUserPreferences; + InternalUserPreferences & + AtlasOrgPreferences & + AtlasProjectPreferences; export type CliOnlyPreferences = { exportConnections?: string; @@ -116,9 +118,7 @@ export type NonUserPreferences = { export type AllPreferences = UserPreferences & CliOnlyPreferences & NonUserPreferences & - PermanentFeatureFlags & - AtlasProjectPreferences & - AtlasOrgPreferences; + PermanentFeatureFlags; // Types related to PreferenceDefinition type PostProcessFunction = ( @@ -214,12 +214,12 @@ export type StoredPreferencesValidator = ReturnType< export type StoredPreferences = z.output; export type AtlasProjectPreferences = { - enableGenAIFeaturesAtlasProject?: boolean; - enableGenAISampleDocumentPassingOnAtlasProject?: boolean; + enableGenAIFeaturesAtlasProject: boolean; + enableGenAISampleDocumentPassingOnAtlasProject: boolean; }; export type AtlasOrgPreferences = { - enableGenAIFeaturesAtlasOrg?: boolean; + enableGenAIFeaturesAtlasOrg: boolean; }; // Preference definitions @@ -886,6 +886,36 @@ export const storedUserPreferencesProps: Required<{ validator: z.boolean().default(false), type: 'boolean', }, + enableGenAIFeaturesAtlasProject: { + ui: false, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Features on Atlas Project Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, + enableGenAISampleDocumentPassingOnAtlasProject: { + ui: false, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Sample Document Passing on Atlas Project Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, + enableGenAIFeaturesAtlasOrg: { + ui: false, + cli: true, + global: true, + description: { + short: 'Enable Gen AI Features on Atlas Org Level', + }, + validator: z.boolean().default(true), + type: 'boolean', + }, ...allFeatureFlagsProps, }; @@ -1032,54 +1062,12 @@ const nonUserPreferences: Required<{ }, }; -const atlasProjectPreferencesProps: Required<{ - [K in keyof AtlasProjectPreferences]: PreferenceDefinition; -}> = { - enableGenAIFeaturesAtlasProject: { - ui: false, - cli: true, - global: true, - description: { - short: 'Enable Gen AI Features on Atlas Project Level', - }, - validator: z.boolean().default(true), - type: 'boolean', - }, - enableGenAISampleDocumentPassingOnAtlasProject: { - ui: false, - cli: true, - global: true, - description: { - short: 'Enable Gen AI Sample Document Passing on Atlas Project Level', - }, - validator: z.boolean().default(true), - type: 'boolean', - }, -}; - -const atlasOrgPreferencesProps: Required<{ - [K in keyof AtlasOrgPreferences]: PreferenceDefinition; -}> = { - enableGenAIFeaturesAtlasOrg: { - ui: false, - cli: true, - global: true, - description: { - short: 'Enable Gen AI Features on Atlas Org Level', - }, - validator: z.boolean().default(true), - type: 'boolean', - }, -}; - export const allPreferencesProps: Required<{ [K in keyof AllPreferences]: PreferenceDefinition; }> = { ...storedUserPreferencesProps, ...cliOnlyPreferencesProps, ...nonUserPreferences, - ...atlasProjectPreferencesProps, - ...atlasOrgPreferencesProps, }; /** Helper for defining how to derive value/state for networkTraffic-affected preferences */ @@ -1099,7 +1087,7 @@ function deriveValueFromOtherPreferencesAsLogicalAnd< K extends keyof AllPreferences >(property: K, preferencesToDeriveFrom: K[]): DeriveValueFunction { return (v, s) => ({ - value: preferencesToDeriveFrom.every((p) => v(p)), + value: v(property) && preferencesToDeriveFrom.every((p) => v(p)), state: s(property) ?? (preferencesToDeriveFrom.every((p) => v(p)) From 87d7ac31e44c497d199787d5422b3cd3938e1a22 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 7 Nov 2024 13:28:55 -0500 Subject: [PATCH 12/13] updating tests --- packages/compass-preferences-model/src/preferences.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/compass-preferences-model/src/preferences.spec.ts b/packages/compass-preferences-model/src/preferences.spec.ts index 36e8b8b68b9..456a718ea61 100644 --- a/packages/compass-preferences-model/src/preferences.spec.ts +++ b/packages/compass-preferences-model/src/preferences.spec.ts @@ -132,6 +132,7 @@ describe('Preferences class', function () { expect(states).to.deep.equal({ trackUsageStatistics: 'set-global', enableMaps: 'set-cli', + enableGenAIFeatures: 'derived', ...expectedReleasedFeatureFlagsStates, }); }); @@ -184,6 +185,7 @@ describe('Preferences class', function () { expect(states).to.deep.equal({ readOnly: 'set-global', + enableGenAIFeatures: 'derived', ...expectedReleasedFeatureFlagsStates, }); }); @@ -227,6 +229,7 @@ describe('Preferences class', function () { { networkTraffic: false, enableMaps: false, + enableGenAIFeatures: false, enableFeedbackPanel: false, trackUsageStatistics: false, autoUpdates: false, @@ -248,6 +251,7 @@ describe('Preferences class', function () { }, hardcoded: { networkTraffic: false, + enableGenAIFeatures: false, }, }); const result = preferences.getPreferences(); @@ -292,6 +296,7 @@ describe('Preferences class', function () { expect(mainPreferencesStates).to.deep.equal({ trackUsageStatistics: 'set-global', + enableGenAIFeatures: 'derived', enableMaps: 'set-cli', ...expectedReleasedFeatureFlagsStates, }); From cd614ceb8152b00196b11f41acd5eea6ad6afe99 Mon Sep 17 00:00:00 2001 From: Ruchitha Rajaghatta Date: Thu, 7 Nov 2024 13:36:44 -0500 Subject: [PATCH 13/13] updating tests --- packages/compass-preferences-model/src/preferences.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/compass-preferences-model/src/preferences.spec.ts b/packages/compass-preferences-model/src/preferences.spec.ts index 456a718ea61..d8cd53a8e48 100644 --- a/packages/compass-preferences-model/src/preferences.spec.ts +++ b/packages/compass-preferences-model/src/preferences.spec.ts @@ -304,6 +304,7 @@ 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',