Skip to content

Commit e8d1aa5

Browse files
committed
chore(compass-preferences-model): use optInGenAIFeatures for Compass and DE
1 parent a9b2fa7 commit e8d1aa5

File tree

9 files changed

+35
-43
lines changed

9 files changed

+35
-43
lines changed

packages/compass-e2e-tests/tests/atlas-cloud/collection-ai-query.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Collection ai query', function () {
4949
true
5050
);
5151
await browser.setFeature('enableGenAIFeaturesAtlasOrg', true);
52-
await browser.setFeature('optInDataExplorerGenAIFeatures', true);
52+
await browser.setFeature('optInGenAIFeatures', true);
5353
});
5454

5555
describe('on the documents tab', function () {
@@ -170,7 +170,7 @@ describe('Collection ai query', function () {
170170
true
171171
);
172172
await browser.setFeature('enableGenAIFeaturesAtlasOrg', false);
173-
await browser.setFeature('optInDataExplorerGenAIFeatures', true);
173+
await browser.setFeature('optInGenAIFeatures', true);
174174
});
175175

176176
it('should not show the gen ai intro button', async function () {

packages/compass-generative-ai/src/atlas-ai-service.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
99
import type { Document } from 'mongodb';
1010
import type { Logger } from '@mongodb-js/compass-logging';
1111
import { EJSON } from 'bson';
12-
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';
1312
import { getStore } from './store/atlas-ai-store';
1413
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
1514

@@ -277,13 +276,7 @@ export class AtlasAiService {
277276
}
278277

279278
async ensureAiFeatureAccess({ signal }: { signal?: AbortSignal } = {}) {
280-
// When the ai feature is attempted to be opened we make sure
281-
// the user is signed into Atlas and opted in.
282-
283-
if (this.apiURLPreset === 'cloud') {
284-
return getStore().dispatch(optIntoGenAIWithModalPrompt({ signal }));
285-
}
286-
return getStore().dispatch(signIntoAtlasWithModalPrompt({ signal }));
279+
return getStore().dispatch(optIntoGenAIWithModalPrompt({ signal }));
287280
}
288281

289282
private getQueryOrAggregationFromUserInput = async <T>(
@@ -391,23 +384,25 @@ export class AtlasAiService {
391384
);
392385
}
393386

394-
// Performs a post request to atlas to set the user opt in preference to true.
395-
async optIntoGenAIFeaturesAtlas() {
396-
await this.atlasService.authenticatedFetch(
397-
this.atlasService.cloudEndpoint(
398-
'/settings/optInDataExplorerGenAIFeatures'
399-
),
400-
{
401-
method: 'POST',
402-
headers: {
403-
'Content-Type': 'application/x-www-form-urlencoded',
404-
Accept: 'application/json',
405-
},
406-
body: new URLSearchParams([['value', 'true']]),
407-
}
408-
);
387+
async optIntoGenAIFeatures() {
388+
if (this.apiURLPreset === 'cloud') {
389+
// Performs a post request to Atlas to set the user opt in preference to true.
390+
await this.atlasService.authenticatedFetch(
391+
this.atlasService.cloudEndpoint(
392+
'/settings/optInDataExplorerGenAIFeatures'
393+
),
394+
{
395+
method: 'POST',
396+
headers: {
397+
'Content-Type': 'application/x-www-form-urlencoded',
398+
Accept: 'application/json',
399+
},
400+
body: new URLSearchParams([['value', 'true']]),
401+
}
402+
);
403+
}
409404
await this.preferences.savePreferences({
410-
optInDataExplorerGenAIFeatures: true,
405+
optInGenAIFeatures: true,
411406
});
412407
}
413408

packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('atlasOptInReducer', function () {
2020
beforeEach(async function () {
2121
mockPreferences = await createSandboxFromDefaultPreferences();
2222
await mockPreferences.savePreferences({
23-
optInDataExplorerGenAIFeatures: false,
23+
optInGenAIFeatures: false,
2424
});
2525
});
2626

@@ -81,7 +81,7 @@ describe('atlasOptInReducer', function () {
8181
beforeEach(async function () {
8282
await mockPreferences.savePreferences({
8383
enableGenAIFeaturesAtlasProject: false,
84-
optInDataExplorerGenAIFeatures: true,
84+
optInGenAIFeatures: true,
8585
});
8686
});
8787

packages/compass-generative-ai/src/store/atlas-optin-reducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export const optIntoGenAIWithModalPrompt = ({
228228
const { state } = getState().optIn;
229229
if (
230230
(state === 'optin-success' ||
231-
preferences.getPreferences().optInDataExplorerGenAIFeatures) &&
231+
preferences.getPreferences().optInGenAIFeatures) &&
232232
preferences.getPreferences().enableGenAIFeaturesAtlasProject
233233
) {
234234
return Promise.resolve();
@@ -265,7 +265,7 @@ export const optIn = (): GenAIAtlasOptInThunkAction<Promise<void>> => {
265265

266266
try {
267267
throwIfAborted(signal);
268-
await atlasAiService.optIntoGenAIFeaturesAtlas();
268+
await atlasAiService.optIntoGenAIFeatures();
269269
dispatch(atlasAiServiceOptedIn());
270270
resolve();
271271
} catch (err) {

packages/compass-preferences-model/src/compass-web-preferences-access.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getActiveUser } from './utils';
77

88
const editablePreferences: (keyof UserPreferences)[] = [
99
// Value can change from false to true during allocation / checking
10-
'optInDataExplorerGenAIFeatures',
10+
'optInGenAIFeatures',
1111
'cloudFeatureRolloutAccess',
1212
// TODO(COMPASS-9353): Provide a standard for updating Compass preferences in web
1313
'enableIndexesGuidanceExp',

packages/compass-preferences-model/src/preferences-schema.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
8585
| 'web-sandbox-atlas-dev'
8686
| 'web-sandbox-atlas-qa'
8787
| 'web-sandbox-atlas';
88-
optInDataExplorerGenAIFeatures: boolean;
88+
optInGenAIFeatures: boolean;
8989
// Features that are enabled by default in Compass, but are disabled in Data
9090
// Explorer
9191
enableExplainPlan: boolean;
@@ -810,17 +810,16 @@ export const storedUserPreferencesProps: Required<{
810810
.default('atlas'),
811811
type: 'string',
812812
},
813-
optInDataExplorerGenAIFeatures: {
813+
optInGenAIFeatures: {
814814
ui: true,
815815
cli: false,
816816
global: false,
817817
description: {
818-
short: 'User Opt-in for Data Explorer Gen AI Features',
818+
short: 'User or Client Opt-in for Gen AI Features',
819819
},
820-
validator: z.boolean().default(true),
820+
validator: z.boolean().default(false),
821821
type: 'boolean',
822822
},
823-
824823
enableAtlasSearchIndexes: {
825824
ui: true,
826825
cli: true,

packages/compass-web/sandbox/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const App = () => {
4848
enableGenAIFeaturesAtlasProject,
4949
enableGenAISampleDocumentPassingOnAtlasProject,
5050
enableGenAIFeaturesAtlasOrg,
51-
optInDataExplorerGenAIFeatures,
51+
optInGenAIFeatures,
5252
} = projectParams ?? {};
5353

5454
const atlasServiceSandboxBackendVariant =
@@ -135,8 +135,7 @@ const App = () => {
135135
isAtlas && !!enableGenAISampleDocumentPassingOnAtlasProject,
136136
enableGenAIFeaturesAtlasOrg:
137137
isAtlas && !!enableGenAIFeaturesAtlasOrg,
138-
optInDataExplorerGenAIFeatures:
139-
isAtlas && !!optInDataExplorerGenAIFeatures,
138+
optInGenAIFeatures: isAtlas && !!optInGenAIFeatures,
140139
enableDataModeling: true,
141140
}}
142141
onTrack={sandboxTelemetry.track}

packages/compass-web/sandbox/sandbox-atlas-sign-in.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ProjectParams = {
1919
enableGenAIFeaturesAtlasProject: boolean;
2020
enableGenAISampleDocumentPassingOnAtlasProject: boolean;
2121
enableGenAIFeaturesAtlasOrg: boolean;
22-
optInDataExplorerGenAIFeatures: boolean;
22+
optInGenAIFeatures: boolean;
2323
};
2424

2525
type AtlasLoginReturnValue =
@@ -129,8 +129,7 @@ export function useAtlasProxySignIn(): AtlasLoginReturnValue {
129129
projectId,
130130
csrfToken,
131131
csrfTime,
132-
optInDataExplorerGenAIFeatures:
133-
isOptedIntoDataExplorerGenAIFeatures,
132+
optInGenAIFeatures: isOptedIntoDataExplorerGenAIFeatures,
134133
enableGenAIFeaturesAtlasOrg: genAIFeaturesEnabled,
135134
enableGenAISampleDocumentPassingOnAtlasProject:
136135
groupEnabledFeatureFlags.includes(

packages/compass-web/src/preferences.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function useCompassWebPreferences(
5555
enableShell: false,
5656
enableCreatingNewConnections: false,
5757
enableGlobalWrites: false,
58-
optInDataExplorerGenAIFeatures: false,
58+
optInGenAIFeatures: false,
5959
enableConnectInNewWindow: false,
6060
...initialPreferences,
6161
})

0 commit comments

Comments
 (0)