Skip to content

Commit 76f0bec

Browse files
authored
chore(gen-ai): remove gen ai access check, default always on COMPASS-9117 (#6812)
1 parent 0a08432 commit 76f0bec

File tree

4 files changed

+12
-160
lines changed

4 files changed

+12
-160
lines changed

packages/atlas-service/src/main.spec.ts

-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ describe('CompassAuthServiceMain', function () {
3333
'http://example.com/v1/revoke?client_id=1234abcd': {
3434
ok: true,
3535
},
36-
'http://example.com/unauth/ai/api/v1/hello/': {
37-
ok: true,
38-
json() {
39-
return { features: {} };
40-
},
41-
},
4236
}[url];
4337
});
4438

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ describe('Collection ai query', function () {
121121

122122
// Check that the request was made with the correct parameters.
123123
const requests = getRequests();
124-
expect(requests.length).to.equal(2);
125-
const lastPathRegex = /[^/]*$/;
126-
const userId = lastPathRegex.exec(requests[0].req.url)?.[0];
127-
expect((userId?.match(/-/g) || []).length).to.equal(4); // Is uuid like.
124+
expect(requests.length).to.equal(1);
128125

129-
const queryRequest = requests[1];
126+
const queryRequest = requests[0];
130127
const queryURL = new URL(
131128
queryRequest.req.url,
132129
`http://${queryRequest.req.headers.host}`

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

+1-85
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ describe('AtlasAiService', function () {
7777
{
7878
apiURLPreset: 'admin-api',
7979
expectedEndpoints: {
80-
'user-access': 'http://example.com/unauth/ai/api/v1/hello/1234',
8180
'mql-aggregation': `http://example.com/ai/api/v1/mql-aggregation?request_id=abc`,
8281
'mql-query': `http://example.com/ai/api/v1/mql-query?request_id=abc`,
8382
},
8483
},
8584
{
8685
apiURLPreset: 'cloud',
8786
expectedEndpoints: {
88-
'user-access': '/cloud/ai/v1/hello/1234',
8987
'mql-aggregation':
9088
'/cloud/ai/v1/groups/testProject/mql-aggregation?request_id=abc',
9189
'mql-query': '/cloud/ai/v1/groups/testProject/mql-query?request_id=abc',
@@ -293,7 +291,7 @@ describe('AtlasAiService', function () {
293291
});
294292
});
295293

296-
it('should set the cloudFeatureRolloutAccess true when returned true', async function () {
294+
it('should set the cloudFeatureRolloutAccess true', async function () {
297295
const fetchStub = sandbox.stub().resolves(
298296
makeResponse({
299297
features: {
@@ -311,94 +309,12 @@ describe('AtlasAiService', function () {
311309

312310
await atlasAiService['setupAIAccess']();
313311

314-
const { args } = fetchStub.firstCall;
315-
316-
expect(fetchStub).to.have.been.calledOnce;
317-
318-
expect(args[0]).to.equal(expectedEndpoints['user-access']);
319-
320312
currentCloudFeatureRolloutAccess =
321313
preferences.getPreferences().cloudFeatureRolloutAccess;
322314
expect(currentCloudFeatureRolloutAccess).to.deep.equal({
323315
GEN_AI_COMPASS: true,
324316
});
325317
});
326-
327-
it('should set the cloudFeatureRolloutAccess false when returned false', async function () {
328-
const fetchStub = sandbox.stub().resolves(
329-
makeResponse({
330-
features: {
331-
GEN_AI_COMPASS: {
332-
enabled: false,
333-
},
334-
},
335-
})
336-
);
337-
global.fetch = fetchStub;
338-
339-
let currentCloudFeatureRolloutAccess =
340-
preferences.getPreferences().cloudFeatureRolloutAccess;
341-
expect(currentCloudFeatureRolloutAccess).to.equal(undefined);
342-
343-
await atlasAiService['setupAIAccess']();
344-
345-
const { args } = fetchStub.firstCall;
346-
347-
expect(fetchStub).to.have.been.calledOnce;
348-
expect(args[0]).to.equal(expectedEndpoints['user-access']);
349-
350-
currentCloudFeatureRolloutAccess =
351-
preferences.getPreferences().cloudFeatureRolloutAccess;
352-
expect(currentCloudFeatureRolloutAccess).to.deep.equal({
353-
GEN_AI_COMPASS: false,
354-
});
355-
});
356-
357-
it('should set the cloudFeatureRolloutAccess false when returned null', async function () {
358-
const fetchStub = sandbox.stub().resolves(
359-
makeResponse({
360-
features: null,
361-
})
362-
);
363-
global.fetch = fetchStub;
364-
365-
let currentCloudFeatureRolloutAccess =
366-
preferences.getPreferences().cloudFeatureRolloutAccess;
367-
expect(currentCloudFeatureRolloutAccess).to.equal(undefined);
368-
369-
await atlasAiService['setupAIAccess']();
370-
371-
const { args } = fetchStub.firstCall;
372-
373-
expect(fetchStub).to.have.been.calledOnce;
374-
expect(args[0]).to.equal(expectedEndpoints['user-access']);
375-
376-
currentCloudFeatureRolloutAccess =
377-
preferences.getPreferences().cloudFeatureRolloutAccess;
378-
expect(currentCloudFeatureRolloutAccess).to.deep.equal({
379-
GEN_AI_COMPASS: false,
380-
});
381-
});
382-
383-
it('should not set the cloudFeatureRolloutAccess false when returned false', async function () {
384-
const fetchStub = sandbox.stub().throws(new Error('error'));
385-
global.fetch = fetchStub;
386-
387-
let currentCloudFeatureRolloutAccess =
388-
preferences.getPreferences().cloudFeatureRolloutAccess;
389-
expect(currentCloudFeatureRolloutAccess).to.equal(undefined);
390-
391-
await atlasAiService['setupAIAccess']();
392-
393-
const { args } = fetchStub.firstCall;
394-
395-
expect(fetchStub).to.have.been.calledOnce;
396-
expect(args[0]).to.equal(expectedEndpoints['user-access']);
397-
398-
currentCloudFeatureRolloutAccess =
399-
preferences.getPreferences().cloudFeatureRolloutAccess;
400-
expect(currentCloudFeatureRolloutAccess).to.deep.equal(undefined);
401-
});
402318
});
403319
});
404320
}

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

+9-64
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, UUID } from 'bson';
11+
import { EJSON } 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';
@@ -198,17 +198,15 @@ const aiURLConfig = {
198198
// Down the line we'd like to only use the admin api, however,
199199
// we cannot currently call that from the Atlas UI. Pending CLOUDP-251201
200200
'admin-api': {
201-
'user-access': (userId: string) => `unauth/ai/api/v1/hello/${userId}`,
202201
aggregation: 'ai/api/v1/mql-aggregation',
203202
query: 'ai/api/v1/mql-query',
204203
},
205204
cloud: {
206-
'user-access': (userId: string) => `ai/v1/hello/${userId}`,
207205
aggregation: (groupId: string) => `ai/v1/groups/${groupId}/mql-aggregation`,
208206
query: (groupId: string) => `ai/v1/groups/${groupId}/mql-query`,
209207
},
210208
} as const;
211-
type AIEndpoint = 'user-access' | 'query' | 'aggregation';
209+
type AIEndpoint = 'query' | 'aggregation';
212210

213211
export class AtlasAiService {
214212
private initPromise: Promise<void> | null = null;
@@ -242,15 +240,6 @@ export class AtlasAiService {
242240
connectionInfo?: ConnectionInfo
243241
) {
244242
if (this.apiURLPreset === 'cloud') {
245-
if (urlId === 'user-access') {
246-
return this.atlasService.cloudEndpoint(
247-
aiURLConfig[this.apiURLPreset][urlId](
248-
this.preferences.getPreferences().telemetryAtlasUserId ??
249-
new UUID().toString()
250-
)
251-
);
252-
}
253-
254243
const atlasMetadata = connectionInfo?.atlasMetadata;
255244
if (!atlasMetadata) {
256245
throw new Error(
@@ -262,15 +251,7 @@ export class AtlasAiService {
262251
aiURLConfig[this.apiURLPreset][urlId](atlasMetadata.projectId)
263252
);
264253
}
265-
const urlConfig = aiURLConfig[this.apiURLPreset][urlId];
266-
const urlPath =
267-
typeof urlConfig === 'function'
268-
? urlConfig(
269-
this.preferences.getPreferences().telemetryAtlasUserId ??
270-
new UUID().toString()
271-
)
272-
: urlConfig;
273-
254+
const urlPath = aiURLConfig[this.apiURLPreset][urlId];
274255
return this.atlasService.adminApiEndpoint(urlPath);
275256
}
276257

@@ -285,50 +266,14 @@ export class AtlasAiService {
285266
}
286267
}
287268

288-
private async getAIFeatureEnablement(): Promise<AIFeatureEnablement> {
289-
const url = this.getUrlForEndpoint('user-access');
290-
291-
const res = await this.atlasService.fetch(url, {
292-
headers: {
293-
Accept: 'application/json',
269+
async setupAIAccess(): Promise<void> {
270+
// We default GEN_AI_ACCESS on for everyone. Down the line if/when
271+
// we add more features with partial rollout, we'll fetch access here.
272+
await this.preferences.savePreferences({
273+
cloudFeatureRolloutAccess: {
274+
GEN_AI_COMPASS: true,
294275
},
295276
});
296-
const body = await res.json();
297-
this.validateAIFeatureEnablementResponse(body);
298-
return body;
299-
}
300-
301-
async setupAIAccess(): Promise<void> {
302-
try {
303-
const featureResponse = await this.getAIFeatureEnablement();
304-
305-
const isAIFeatureEnabled =
306-
!!featureResponse?.features?.GEN_AI_COMPASS?.enabled;
307-
308-
this.logger.log.info(
309-
this.logger.mongoLogId(1_001_000_300),
310-
'AtlasAIService',
311-
'Fetched if the AI feature is enabled',
312-
{
313-
enabled: isAIFeatureEnabled,
314-
featureResponse,
315-
}
316-
);
317-
318-
await this.preferences.savePreferences({
319-
cloudFeatureRolloutAccess: {
320-
GEN_AI_COMPASS: isAIFeatureEnabled,
321-
},
322-
});
323-
} catch (err) {
324-
// Default to what's already in Compass when we can't fetch the preference.
325-
this.logger.log.error(
326-
this.logger.mongoLogId(1_001_000_302),
327-
'AtlasAIService',
328-
'Failed to load if the AI feature is enabled',
329-
{ error: (err as Error).stack }
330-
);
331-
}
332277
}
333278

334279
async ensureAiFeatureAccess({ signal }: { signal?: AbortSignal } = {}) {

0 commit comments

Comments
 (0)