Skip to content

Commit 4febfae

Browse files
authored
feat(compass-generative-ai): don't require Atlas login, use the unauthenticated NLQ endpoints COMPASS-9688 (#7191)
* Don't require Atlas login, use the unauthenticated NLQ endpoints. * released, then * update expected endpoints in tests * skip the atlas login tests for now
1 parent 98d3a96 commit 4febfae

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

packages/compass-e2e-tests/tests/atlas-login.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function getTestBrowserShellCommand() {
3636
)}`;
3737
}
3838

39-
describe('Atlas Login', function () {
39+
// TODO: remove these when we remove atlas login
40+
describe.skip('Atlas Login', function () {
4041
let compass: Compass;
4142
let browser: CompassBrowser;
4243
let oidcMockProvider: OIDCMockProvider;
@@ -281,7 +282,8 @@ describe('Atlas Login', function () {
281282
);
282283
});
283284

284-
it('should not show AI input if sign in flow was not finished', async function () {
285+
// TODO: remove once we remove atlas login
286+
it.skip('should not show AI input if sign in flow was not finished', async function () {
285287
getTokenPayload = () => {
286288
return new Promise(() => {});
287289
};
@@ -314,7 +316,8 @@ describe('Atlas Login', function () {
314316
);
315317
});
316318

317-
it('should not show AI input if sign in flow was not finished', async function () {
319+
// TODO: remove once we remove atlas login
320+
it.skip('should not show AI input if sign in flow was not finished', async function () {
318321
getTokenPayload = () => {
319322
return new Promise(() => {});
320323
};

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ describe('AtlasAiService', function () {
8686
{
8787
apiURLPreset: 'admin-api',
8888
expectedEndpoints: {
89-
'mql-aggregation': `http://example.com/ai/api/v1/mql-aggregation?request_id=abc`,
90-
'mql-query': `http://example.com/ai/api/v1/mql-query?request_id=abc`,
89+
'mql-aggregation': `http://example.com/unauth/ai/api/v1/mql-aggregation?request_id=abc`,
90+
'mql-query': `http://example.com/unauth/ai/api/v1/mql-query?request_id=abc`,
9191
},
9292
},
9393
{
@@ -333,13 +333,6 @@ describe('AtlasAiService', function () {
333333
// Reset preferences
334334
await preferences.savePreferences({
335335
optInGenAIFeatures: false,
336-
enableUnauthenticatedGenAI: true,
337-
});
338-
});
339-
340-
afterEach(async function () {
341-
await preferences.savePreferences({
342-
enableUnauthenticatedGenAI: false,
343336
});
344337
});
345338

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import { EJSON } from 'bson';
1212
import { z } from 'zod';
1313
import { getStore } from './store/atlas-ai-store';
1414
import { optIntoGenAIWithModalPrompt } from './store/atlas-optin-reducer';
15-
import { signIntoAtlasWithModalPrompt } from './store/atlas-signin-reducer';
1615
import {
1716
AtlasAiServiceInvalidInputError,
1817
AtlasAiServiceApiResponseParseError,
1918
} from './atlas-ai-errors';
20-
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
2119

2220
type GenerativeAiInput = {
2321
userInput: string;
@@ -203,9 +201,11 @@ const aiURLConfig = {
203201
// There are two different sets of endpoints we use for our requests.
204202
// Down the line we'd like to only use the admin api, however,
205203
// we cannot currently call that from the Atlas UI. Pending CLOUDP-251201
204+
// NOTE: The unauthenticated endpoints are also rate limited by IP address
205+
// rather than by logged in user.
206206
'admin-api': {
207-
aggregation: 'ai/api/v1/mql-aggregation',
208-
query: 'ai/api/v1/mql-query',
207+
aggregation: 'unauth/ai/api/v1/mql-aggregation',
208+
query: 'unauth/ai/api/v1/mql-query',
209209
},
210210
cloud: {
211211
aggregation: (groupId: string) => `ai/v1/groups/${groupId}/mql-aggregation`,
@@ -341,21 +341,12 @@ export class AtlasAiService {
341341
}
342342

343343
async ensureAiFeatureAccess({ signal }: { signal?: AbortSignal } = {}) {
344-
if (this.preferences.getPreferences().enableUnauthenticatedGenAI) {
345-
return getStore().dispatch(
346-
optIntoGenAIWithModalPrompt({ signal, isCloudOptIn: false })
347-
);
348-
}
349-
350-
// When the ai feature is attempted to be opened we make sure
351-
// the user is signed into Atlas and opted in.
352-
353-
if (this.apiURLPreset === 'cloud') {
354-
return getStore().dispatch(
355-
optIntoGenAIWithModalPrompt({ signal, isCloudOptIn: true })
356-
);
357-
}
358-
return getStore().dispatch(signIntoAtlasWithModalPrompt({ signal }));
344+
return getStore().dispatch(
345+
optIntoGenAIWithModalPrompt({
346+
signal,
347+
isCloudOptIn: this.apiURLPreset === 'cloud',
348+
})
349+
);
359350
}
360351

361352
private getQueryOrAggregationFromUserInput = async <T>(
@@ -502,7 +493,7 @@ export class AtlasAiService {
502493
} catch (err) {
503494
const errorMessage = err instanceof Error ? err.stack : String(err);
504495
this.logger.log.error(
505-
mongoLogId(1_001_000_311),
496+
this.logger.mongoLogId(1_001_000_311),
506497
'AtlasAiService',
507498
'Failed to parse mock data schema response with expected schema',
508499
{

packages/compass-preferences-model/src/feature-flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const featureFlags: Required<{
153153
},
154154

155155
enableUnauthenticatedGenAI: {
156-
stage: 'development',
156+
stage: 'released',
157157
description: {
158158
short: 'Enable GenAI for unauthenticated users',
159159
},

0 commit comments

Comments
 (0)