Skip to content

Commit 4dadfb0

Browse files
authored
chore(generative-ai): use telemetryAtlasUserId in feature enablement check COMPASS-8571 (#6527)
1 parent 51c6a37 commit 4dadfb0

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ const ATLAS_USER = {
1515
sub: '123',
1616
};
1717

18-
const PREFERENCES_USER = {
19-
id: '1234',
20-
createdAt: new Date(),
21-
};
22-
2318
const BASE_URL = 'http://example.com';
2419

2520
const mockConnectionInfo: ConnectionInfo = {
@@ -68,7 +63,9 @@ describe('AtlasAiService', function () {
6863
beforeEach(async function () {
6964
sandbox = Sinon.createSandbox();
7065
preferences = await createSandboxFromDefaultPreferences();
71-
preferences['getPreferencesUser'] = () => PREFERENCES_USER;
66+
await preferences.savePreferences({
67+
telemetryAtlasUserId: '1234',
68+
});
7269
});
7370

7471
afterEach(function () {

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AtlasServiceError } from '@mongodb-js/atlas-service/renderer';
88
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
99
import type { Document } from 'mongodb';
1010
import type { Logger } from '@mongodb-js/compass-logging';
11-
import { EJSON } from 'bson';
11+
import { EJSON, UUID } from 'bson';
1212
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';
1313
import { getStore } from './store/atlas-ai-store';
1414
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
@@ -245,7 +245,8 @@ export class AtlasAiService {
245245
if (urlId === 'user-access') {
246246
return this.atlasService.cloudEndpoint(
247247
aiURLConfig[this.apiURLPreset][urlId](
248-
this.preferences.getPreferencesUser().id
248+
this.preferences.getPreferences().telemetryAtlasUserId ??
249+
new UUID().toString()
249250
)
250251
);
251252
}
@@ -264,7 +265,10 @@ export class AtlasAiService {
264265
const urlConfig = aiURLConfig[this.apiURLPreset][urlId];
265266
const urlPath =
266267
typeof urlConfig === 'function'
267-
? urlConfig(this.preferences.getPreferencesUser().id)
268+
? urlConfig(
269+
this.preferences.getPreferences().telemetryAtlasUserId ??
270+
new UUID().toString()
271+
)
268272
: urlConfig;
269273

270274
return this.atlasService.adminApiEndpoint(urlPath);

packages/compass-web/sandbox/index.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useLayoutEffect } from 'react';
22
import ReactDOM from 'react-dom';
33
import { resetGlobalCSS, css, Body } from '@mongodb-js/compass-components';
44
import { CompassWeb } from '../src/index';
5-
import { SandboxConnectionStorageProviver } from '../src/connection-storage';
5+
import { SandboxConnectionStorageProvider } from '../src/connection-storage';
66
import { sandboxLogger } from './sandbox-logger';
77
import { sandboxTelemetry } from './sandbox-telemetry';
88
import { useAtlasProxySignIn } from './sandbox-atlas-sign-in';
@@ -41,6 +41,9 @@ const App = () => {
4141
? 'web-sandbox-atlas-dev'
4242
: 'web-sandbox-atlas';
4343

44+
const overrideGenAIEnablement =
45+
process.env.COMPASS_WEB_GEN_AI_ENABLEMENT === 'true';
46+
4447
useLayoutEffect(() => {
4548
getMetaEl('csrf-token').setAttribute('content', csrfToken ?? '');
4649
getMetaEl('csrf-time').setAttribute('content', csrfTime ?? '');
@@ -53,7 +56,7 @@ const App = () => {
5356
const isAtlas = status === 'signed-in';
5457

5558
return (
56-
<SandboxConnectionStorageProviver
59+
<SandboxConnectionStorageProvider
5760
value={isAtlas ? null : sandboxConnectionStorage}
5861
extraConnectionOptions={
5962
isAtlas
@@ -77,13 +80,18 @@ const App = () => {
7780
enableCreatingNewConnections: !isAtlas,
7881
enableGlobalWrites: isAtlas,
7982
enableRollingIndexes: isAtlas,
83+
enableGenAIFeaturesAtlasProject: isAtlas && overrideGenAIEnablement,
84+
enableGenAISampleDocumentPassingOnAtlasProject:
85+
isAtlas && overrideGenAIEnablement,
86+
enableGenAIFeaturesAtlasOrg: isAtlas && overrideGenAIEnablement,
87+
optInDataExplorerGenAIFeatures: isAtlas && overrideGenAIEnablement,
8088
}}
8189
onTrack={sandboxTelemetry.track}
8290
onDebug={sandboxLogger.debug}
8391
onLog={sandboxLogger.log}
8492
></CompassWeb>
8593
</Body>
86-
</SandboxConnectionStorageProviver>
94+
</SandboxConnectionStorageProvider>
8795
);
8896
};
8997

packages/compass-web/src/connection-storage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const SandboxExtraConnectionOptionsContext = React.createContext<
317317
* non-Atlas deployment
318318
* @internal
319319
*/
320-
export const SandboxConnectionStorageProviver = ({
320+
export const SandboxConnectionStorageProvider = ({
321321
value,
322322
extraConnectionOptions,
323323
children,

0 commit comments

Comments
 (0)