Skip to content

Commit

Permalink
chore(atlas-service): remove unused ai enabled boolean (#6377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Oct 18, 2024
1 parent 5e7df67 commit 2901b38
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 57 deletions.
5 changes: 1 addition & 4 deletions packages/atlas-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,7 @@ export class CompassAuthService {

await throwIfNotOk(res);

const userInfo = (await res.json()) as AtlasUserInfo;

// TODO: Remove hadcoded `enabledAIFeature: true` when Atlas returns the actual value.
return { ...userInfo, enabledAIFeature: true };
return (await res.json()) as AtlasUserInfo;
})();
return this.currentUser;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/atlas-service/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type AtlasUserInfo = {
lastName: string;
primaryEmail: string;
login: string;
} & { enabledAIFeature: boolean };
};

export type IntrospectInfo = { active: boolean };

Expand Down
21 changes: 0 additions & 21 deletions packages/compass-generative-ai/src/atlas-ai-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { AtlasAiService } from './atlas-ai-service';
import type { PreferencesAccess } from 'compass-preferences-model';
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
import { createNoopLogger } from '@mongodb-js/compass-logging/provider';
import { AtlasAuthService } from '@mongodb-js/atlas-service/provider';
import { ObjectId } from 'mongodb';

const ATLAS_USER = {
enabledAIFeature: true,
firstName: 'John',
lastName: 'Doe',
login: 'johndoe',
Expand All @@ -23,24 +21,6 @@ const PREFERENCES_USER = {

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

class MockAtlasAuthService extends AtlasAuthService {
isAuthenticated() {
return Promise.resolve(true);
}
async getUserInfo() {
return Promise.resolve({} as any);
}
async signIn() {
return Promise.resolve({} as any);
}
async signOut() {
return Promise.resolve();
}
async getAuthHeaders() {
return Promise.resolve({});
}
}

class MockAtlasService {
getCurrentUser = () => Promise.resolve(ATLAS_USER);
adminApiEndpoint = (url: string, requestId?: string) =>
Expand Down Expand Up @@ -76,7 +56,6 @@ describe('AtlasAiService', function () {

atlasAiService = new AtlasAiService(
new MockAtlasService() as any,
new MockAtlasAuthService(),
preferences,
createNoopLogger()
);
Expand Down
17 changes: 3 additions & 14 deletions packages/compass-generative-ai/src/atlas-ai-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import {
type PreferencesAccess,
isAIFeatureEnabled,
} from 'compass-preferences-model/provider';
import type {
AtlasAuthService,
AtlasService,
} from '@mongodb-js/atlas-service/provider';
import type { AtlasService } from '@mongodb-js/atlas-service/provider';
import { AtlasServiceError } from '@mongodb-js/atlas-service/renderer';
import type { Document } from 'mongodb';
import type { Logger } from '@mongodb-js/compass-logging';
Expand Down Expand Up @@ -200,14 +197,13 @@ export class AtlasAiService {

constructor(
private atlasService: AtlasService,
private atlasAuthService: AtlasAuthService,
private preferences: PreferencesAccess,
private logger: Logger
) {
this.initPromise = this.setupAIAccess();
}

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

private async getAIFeatureEnablement(): Promise<AIFeatureEnablement> {
Expand Down Expand Up @@ -277,7 +266,7 @@ export class AtlasAiService {
validationFn: (res: any) => asserts res is T
): Promise<T> => {
await this.initPromise;
await this.throwIfAINotEnabled();
this.throwIfAINotEnabled();

const { signal, requestId, ...rest } = input;
const msgBody = buildQueryOrAggregationMessageBody(rest);
Expand Down
15 changes: 3 additions & 12 deletions packages/compass-generative-ai/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import React, { createContext, useContext, useMemo } from 'react';
import { AtlasAiService } from './atlas-ai-service';
import { preferencesLocator } from 'compass-preferences-model/provider';
import { useLogger } from '@mongodb-js/compass-logging/provider';
import {
atlasAuthServiceLocator,
atlasServiceLocator,
} from '@mongodb-js/atlas-service/provider';
import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider';
import {
createServiceLocator,
createServiceProvider,
Expand All @@ -17,17 +14,11 @@ export const AtlasAiServiceProvider: React.FC = createServiceProvider(
function AtlasAiServiceProvider({ children }) {
const logger = useLogger('ATLAS-AI-SERVICE');
const preferences = preferencesLocator();
const atlasAuthService = atlasAuthServiceLocator();
const atlasService = atlasServiceLocator();

const aiService = useMemo(() => {
return new AtlasAiService(
atlasService,
atlasAuthService,
preferences,
logger
);
}, [atlasAuthService, preferences, logger, atlasService]);
return new AtlasAiService(atlasService, preferences, logger);
}, [preferences, logger, atlasService]);

return (
<AtlasAiServiceContext.Provider value={aiService}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ describe('AtlasLoginSettings', function () {

it('should not reset sign in state if there is no sign in attempt in progress', async function () {
const atlasAuthService = {
signIn: sandbox
.stub()
.resolves({ login: 'user@mongodb.com', enabledAIFeature: false }),
signIn: sandbox.stub().resolves({ login: 'user@mongodb.com' }),
};

const { store } = renderAtlasLoginSettings(atlasAuthService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const atlasLoginEmailStyles = css({
export const AtlasLoginSettings: React.FunctionComponent<{
isSignInInProgress: boolean;
userLogin: string | null;
isAIFeatureEnabled: boolean;
onSignInClick(): void;
onSignOutClick(): void;
}> = ({ isSignInInProgress, userLogin, onSignInClick, onSignOutClick }) => {
Expand Down Expand Up @@ -174,7 +173,6 @@ export const ConnectedAtlasLoginSettings = connect(
return {
isSignInInProgress: state.atlasLogin.status === 'in-progress',
userLogin: state.atlasLogin.userInfo?.login ?? null,
isAIFeatureEnabled: Boolean(state.atlasLogin.userInfo?.enabledAIFeature),
};
},
{
Expand Down

0 comments on commit 2901b38

Please sign in to comment.