Skip to content

Commit 2901b38

Browse files
authored
chore(atlas-service): remove unused ai enabled boolean (#6377)
1 parent 5e7df67 commit 2901b38

File tree

7 files changed

+9
-57
lines changed

7 files changed

+9
-57
lines changed

packages/atlas-service/src/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ export class CompassAuthService {
376376

377377
await throwIfNotOk(res);
378378

379-
const userInfo = (await res.json()) as AtlasUserInfo;
380-
381-
// TODO: Remove hadcoded `enabledAIFeature: true` when Atlas returns the actual value.
382-
return { ...userInfo, enabledAIFeature: true };
379+
return (await res.json()) as AtlasUserInfo;
383380
})();
384381
return this.currentUser;
385382
}

packages/atlas-service/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type AtlasUserInfo = {
99
lastName: string;
1010
primaryEmail: string;
1111
login: string;
12-
} & { enabledAIFeature: boolean };
12+
};
1313

1414
export type IntrospectInfo = { active: boolean };
1515

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import { AtlasAiService } from './atlas-ai-service';
44
import type { PreferencesAccess } from 'compass-preferences-model';
55
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
66
import { createNoopLogger } from '@mongodb-js/compass-logging/provider';
7-
import { AtlasAuthService } from '@mongodb-js/atlas-service/provider';
87
import { ObjectId } from 'mongodb';
98

109
const ATLAS_USER = {
11-
enabledAIFeature: true,
1210
firstName: 'John',
1311
lastName: 'Doe',
1412
login: 'johndoe',
@@ -23,24 +21,6 @@ const PREFERENCES_USER = {
2321

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

26-
class MockAtlasAuthService extends AtlasAuthService {
27-
isAuthenticated() {
28-
return Promise.resolve(true);
29-
}
30-
async getUserInfo() {
31-
return Promise.resolve({} as any);
32-
}
33-
async signIn() {
34-
return Promise.resolve({} as any);
35-
}
36-
async signOut() {
37-
return Promise.resolve();
38-
}
39-
async getAuthHeaders() {
40-
return Promise.resolve({});
41-
}
42-
}
43-
4424
class MockAtlasService {
4525
getCurrentUser = () => Promise.resolve(ATLAS_USER);
4626
adminApiEndpoint = (url: string, requestId?: string) =>
@@ -76,7 +56,6 @@ describe('AtlasAiService', function () {
7656

7757
atlasAiService = new AtlasAiService(
7858
new MockAtlasService() as any,
79-
new MockAtlasAuthService(),
8059
preferences,
8160
createNoopLogger()
8261
);

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import {
33
type PreferencesAccess,
44
isAIFeatureEnabled,
55
} from 'compass-preferences-model/provider';
6-
import type {
7-
AtlasAuthService,
8-
AtlasService,
9-
} from '@mongodb-js/atlas-service/provider';
6+
import type { AtlasService } from '@mongodb-js/atlas-service/provider';
107
import { AtlasServiceError } from '@mongodb-js/atlas-service/renderer';
118
import type { Document } from 'mongodb';
129
import type { Logger } from '@mongodb-js/compass-logging';
@@ -200,14 +197,13 @@ export class AtlasAiService {
200197

201198
constructor(
202199
private atlasService: AtlasService,
203-
private atlasAuthService: AtlasAuthService,
204200
private preferences: PreferencesAccess,
205201
private logger: Logger
206202
) {
207203
this.initPromise = this.setupAIAccess();
208204
}
209205

210-
private async throwIfAINotEnabled() {
206+
private throwIfAINotEnabled() {
211207
if (process.env.COMPASS_E2E_SKIP_ATLAS_SIGNIN === 'true') {
212208
return;
213209
}
@@ -216,13 +212,6 @@ export class AtlasAiService {
216212
"Compass' AI functionality is not currently enabled. Please try again later."
217213
);
218214
}
219-
// Only throw if we actually have userInfo / logged in. Otherwise allow
220-
// request to fall through so that we can get a proper network error
221-
if (
222-
(await this.atlasAuthService.getUserInfo()).enabledAIFeature === false
223-
) {
224-
throw new Error("Can't use AI before accepting terms and conditions");
225-
}
226215
}
227216

228217
private async getAIFeatureEnablement(): Promise<AIFeatureEnablement> {
@@ -277,7 +266,7 @@ export class AtlasAiService {
277266
validationFn: (res: any) => asserts res is T
278267
): Promise<T> => {
279268
await this.initPromise;
280-
await this.throwIfAINotEnabled();
269+
this.throwIfAINotEnabled();
281270

282271
const { signal, requestId, ...rest } = input;
283272
const msgBody = buildQueryOrAggregationMessageBody(rest);

packages/compass-generative-ai/src/provider.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import React, { createContext, useContext, useMemo } from 'react';
22
import { AtlasAiService } from './atlas-ai-service';
33
import { preferencesLocator } from 'compass-preferences-model/provider';
44
import { useLogger } from '@mongodb-js/compass-logging/provider';
5-
import {
6-
atlasAuthServiceLocator,
7-
atlasServiceLocator,
8-
} from '@mongodb-js/atlas-service/provider';
5+
import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider';
96
import {
107
createServiceLocator,
118
createServiceProvider,
@@ -17,17 +14,11 @@ export const AtlasAiServiceProvider: React.FC = createServiceProvider(
1714
function AtlasAiServiceProvider({ children }) {
1815
const logger = useLogger('ATLAS-AI-SERVICE');
1916
const preferences = preferencesLocator();
20-
const atlasAuthService = atlasAuthServiceLocator();
2117
const atlasService = atlasServiceLocator();
2218

2319
const aiService = useMemo(() => {
24-
return new AtlasAiService(
25-
atlasService,
26-
atlasAuthService,
27-
preferences,
28-
logger
29-
);
30-
}, [atlasAuthService, preferences, logger, atlasService]);
20+
return new AtlasAiService(atlasService, preferences, logger);
21+
}, [preferences, logger, atlasService]);
3122

3223
return (
3324
<AtlasAiServiceContext.Provider value={aiService}>

packages/compass-settings/src/components/settings/atlas-login.spec.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ describe('AtlasLoginSettings', function () {
205205

206206
it('should not reset sign in state if there is no sign in attempt in progress', async function () {
207207
const atlasAuthService = {
208-
signIn: sandbox
209-
.stub()
210-
.resolves({ login: '[email protected]', enabledAIFeature: false }),
208+
signIn: sandbox.stub().resolves({ login: '[email protected]' }),
211209
};
212210

213211
const { store } = renderAtlasLoginSettings(atlasAuthService);

packages/compass-settings/src/components/settings/atlas-login.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const atlasLoginEmailStyles = css({
7070
export const AtlasLoginSettings: React.FunctionComponent<{
7171
isSignInInProgress: boolean;
7272
userLogin: string | null;
73-
isAIFeatureEnabled: boolean;
7473
onSignInClick(): void;
7574
onSignOutClick(): void;
7675
}> = ({ isSignInInProgress, userLogin, onSignInClick, onSignOutClick }) => {
@@ -174,7 +173,6 @@ export const ConnectedAtlasLoginSettings = connect(
174173
return {
175174
isSignInInProgress: state.atlasLogin.status === 'in-progress',
176175
userLogin: state.atlasLogin.userInfo?.login ?? null,
177-
isAIFeatureEnabled: Boolean(state.atlasLogin.userInfo?.enabledAIFeature),
178176
};
179177
},
180178
{

0 commit comments

Comments
 (0)