Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -311,7 +311,7 @@ const SandboxExtraConnectionOptionsContext = React.createContext<
* non-Atlas deployment
* @internal
*/
export const SandboxConnectionStorageProviver = ({
export const SandboxConnectionStorageProvider = ({
value,
extraConnectionOptions,
children,
Expand Down
Loading