Skip to content
Merged
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
87 changes: 56 additions & 31 deletions packages/atlas-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ export class AtlasService {
log.info(mongoLogId(1_001_000_218), 'AtlasService', 'Starting sign in');

try {
const userInfo = await this.getUserInfo({ signal });
log.info(
mongoLogId(1_001_000_219),
'AtlasService',
'Signed in successfully'
);
const userInfo = await this.getUserInfo({ signal });
track('Atlas Sign In Success', getTrackingUserInfo(userInfo));
return userInfo;
} catch (err) {
Expand Down Expand Up @@ -544,11 +544,17 @@ export class AtlasService {
throwIfNetworkTrafficDisabled();

const userId = (await this.getActiveCompassUser()).id;
const url = `${this.config.atlasApiUnauthBaseUrl}/ai/api/v1/hello/${userId}`;

const res = await this.fetch(
`${this.config.atlasApiUnauthBaseUrl}/ai/api/v1/hello/${userId}`
log.info(
mongoLogId(1_001_000_227),
'AtlasService',
'Fetching if the AI feature is enabled via hello endpoint',
{ userId, url }
);

const res = await this.fetch(url);

await throwIfNotOk(res);

const body = await res.json();
Expand All @@ -559,12 +565,6 @@ export class AtlasService {
}

static async setupAIAccess(): Promise<void> {
log.info(
mongoLogId(1_001_000_227),
'AtlasService',
'Fetching if the AI feature is enabled'
);

try {
throwIfNetworkTrafficDisabled();

Expand All @@ -579,6 +579,7 @@ export class AtlasService {
'Fetched if the AI feature is enabled',
{
enabled: isAIFeatureEnabled,
featureResponse,
}
);

Expand Down Expand Up @@ -644,18 +645,30 @@ export class AtlasService {
}

const token = await this.maybeGetToken({ signal });
const url = `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-aggregation`;

const res = await this.fetch(
`${this.config.atlasApiBaseUrl}/ai/api/v1/mql-aggregation`,
{
signal: signal as NodeFetchAbortSignal | undefined,
method: 'POST',
headers: {
Authorization: `Bearer ${token ?? ''}`,
'Content-Type': 'application/json',
},
body: msgBody,
}
log.info(
mongoLogId(1_001_000_247),
'AtlasService',
'Running aggregation generation request',
{ url, body: msgBody }
);

const res = await this.fetch(url, {
signal: signal as NodeFetchAbortSignal | undefined,
method: 'POST',
headers: {
Authorization: `Bearer ${token ?? ''}`,
'Content-Type': 'application/json',
},
body: msgBody,
});

log.info(
mongoLogId(1_001_000_248),
'AtlasService',
'Received aggregation generation response',
{ status: res.status, statusText: res.statusText }
);

await throwIfNotOk(res);
Expand Down Expand Up @@ -713,18 +726,30 @@ export class AtlasService {
}

const token = await this.maybeGetToken({ signal });
const url = `${this.config.atlasApiBaseUrl}/ai/api/v1/mql-query`;

const res = await this.fetch(
`${this.config.atlasApiBaseUrl}/ai/api/v1/mql-query`,
{
signal: signal as NodeFetchAbortSignal | undefined,
method: 'POST',
headers: {
Authorization: `Bearer ${token ?? ''}`,
'Content-Type': 'application/json',
},
body: msgBody,
}
log.info(
mongoLogId(1_001_000_249),
'AtlasService',
'Running query generation request',
{ url, body: msgBody }
);

const res = await this.fetch(url, {
signal: signal as NodeFetchAbortSignal | undefined,
method: 'POST',
headers: {
Authorization: `Bearer ${token ?? ''}`,
'Content-Type': 'application/json',
},
body: msgBody,
});

log.info(
mongoLogId(1_001_000_250),
'AtlasService',
'Received query generation response',
{ status: res.status, statusText: res.statusText }
);

await throwIfNotOk(res);
Expand Down