Skip to content

Commit

Permalink
chore(generative-ai): use telemetryAtlasUserId in feature enablement …
Browse files Browse the repository at this point in the history
…check COMPASS-8571 (#6527)
  • Loading branch information
Anemy authored Dec 9, 2024
1 parent 51c6a37 commit 4dadfb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
9 changes: 3 additions & 6 deletions packages/compass-generative-ai/src/atlas-ai-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const ATLAS_USER = {
sub: '123',
};

const PREFERENCES_USER = {
id: '1234',
createdAt: new Date(),
};

const BASE_URL = 'http://example.com';

const mockConnectionInfo: ConnectionInfo = {
Expand Down Expand Up @@ -68,7 +63,9 @@ describe('AtlasAiService', function () {
beforeEach(async function () {
sandbox = Sinon.createSandbox();
preferences = await createSandboxFromDefaultPreferences();
preferences['getPreferencesUser'] = () => PREFERENCES_USER;
await preferences.savePreferences({
telemetryAtlasUserId: '1234',
});
});

afterEach(function () {
Expand Down
10 changes: 7 additions & 3 deletions packages/compass-generative-ai/src/atlas-ai-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AtlasServiceError } from '@mongodb-js/atlas-service/renderer';
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
import type { Document } from 'mongodb';
import type { Logger } from '@mongodb-js/compass-logging';
import { EJSON } from 'bson';
import { EJSON, UUID } from 'bson';
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';
import { getStore } from './store/atlas-ai-store';
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
Expand Down Expand Up @@ -245,7 +245,8 @@ export class AtlasAiService {
if (urlId === 'user-access') {
return this.atlasService.cloudEndpoint(
aiURLConfig[this.apiURLPreset][urlId](
this.preferences.getPreferencesUser().id
this.preferences.getPreferences().telemetryAtlasUserId ??
new UUID().toString()
)
);
}
Expand All @@ -264,7 +265,10 @@ export class AtlasAiService {
const urlConfig = aiURLConfig[this.apiURLPreset][urlId];
const urlPath =
typeof urlConfig === 'function'
? urlConfig(this.preferences.getPreferencesUser().id)
? urlConfig(
this.preferences.getPreferences().telemetryAtlasUserId ??
new UUID().toString()
)
: urlConfig;

return this.atlasService.adminApiEndpoint(urlPath);
Expand Down
14 changes: 11 additions & 3 deletions packages/compass-web/sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useLayoutEffect } from 'react';
import ReactDOM from 'react-dom';
import { resetGlobalCSS, css, Body } from '@mongodb-js/compass-components';
import { CompassWeb } from '../src/index';
import { SandboxConnectionStorageProviver } from '../src/connection-storage';
import { SandboxConnectionStorageProvider } from '../src/connection-storage';
import { sandboxLogger } from './sandbox-logger';
import { sandboxTelemetry } from './sandbox-telemetry';
import { useAtlasProxySignIn } from './sandbox-atlas-sign-in';
Expand Down Expand Up @@ -41,6 +41,9 @@ const App = () => {
? 'web-sandbox-atlas-dev'
: 'web-sandbox-atlas';

const overrideGenAIEnablement =
process.env.COMPASS_WEB_GEN_AI_ENABLEMENT === 'true';

useLayoutEffect(() => {
getMetaEl('csrf-token').setAttribute('content', csrfToken ?? '');
getMetaEl('csrf-time').setAttribute('content', csrfTime ?? '');
Expand All @@ -53,7 +56,7 @@ const App = () => {
const isAtlas = status === 'signed-in';

return (
<SandboxConnectionStorageProviver
<SandboxConnectionStorageProvider
value={isAtlas ? null : sandboxConnectionStorage}
extraConnectionOptions={
isAtlas
Expand All @@ -77,13 +80,18 @@ const App = () => {
enableCreatingNewConnections: !isAtlas,
enableGlobalWrites: isAtlas,
enableRollingIndexes: isAtlas,
enableGenAIFeaturesAtlasProject: isAtlas && overrideGenAIEnablement,
enableGenAISampleDocumentPassingOnAtlasProject:
isAtlas && overrideGenAIEnablement,
enableGenAIFeaturesAtlasOrg: isAtlas && overrideGenAIEnablement,
optInDataExplorerGenAIFeatures: isAtlas && overrideGenAIEnablement,
}}
onTrack={sandboxTelemetry.track}
onDebug={sandboxLogger.debug}
onLog={sandboxLogger.log}
></CompassWeb>
</Body>
</SandboxConnectionStorageProviver>
</SandboxConnectionStorageProvider>
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const SandboxExtraConnectionOptionsContext = React.createContext<
* non-Atlas deployment
* @internal
*/
export const SandboxConnectionStorageProviver = ({
export const SandboxConnectionStorageProvider = ({
value,
extraConnectionOptions,
children,
Expand Down

0 comments on commit 4dadfb0

Please sign in to comment.