Skip to content

Commit f0262de

Browse files
refactor: rename userPrompt to userInput (#4702)
1 parent c664473 commit f0262de

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ describe('AtlasServiceMain', function () {
193193
});
194194
});
195195

196-
describe('getQueryFromUserPrompt', function () {
197-
it('makes a post request with the user prompt to the endpoint in the environment', async function () {
196+
describe('getQueryFromUserInput', function () {
197+
it('makes a post request with the user input to the endpoint in the environment', async function () {
198198
AtlasService['fetch'] = sandbox.stub().resolves({
199199
ok: true,
200200
json() {
@@ -204,8 +204,8 @@ describe('AtlasServiceMain', function () {
204204
},
205205
}) as any;
206206

207-
const res = await AtlasService.getQueryFromUserPrompt({
208-
userPrompt: 'test',
207+
const res = await AtlasService.getQueryFromUserInput({
208+
userInput: 'test',
209209
signal: new AbortController().signal,
210210
collectionName: 'jam',
211211
databaseName: 'peanut',
@@ -220,7 +220,7 @@ describe('AtlasServiceMain', function () {
220220
expect(AtlasService['fetch']).to.have.been.calledOnce;
221221
expect(args[0]).to.eq('http://example.com/ai/api/v1/mql-query');
222222
expect(args[1].body).to.eq(
223-
'{"userPrompt":"test","collectionName":"jam","databaseName":"peanut","schema":{"_id":{"types":[{"bsonType":"ObjectId"}]}},"sampleDocuments":[{"_id":1234}]}'
223+
'{"userInput":"test","collectionName":"jam","databaseName":"peanut","schema":{"_id":{"types":[{"bsonType":"ObjectId"}]}},"sampleDocuments":[{"_id":1234}]}'
224224
);
225225
expect(res).to.have.nested.property(
226226
'content.query.find.test',
@@ -232,27 +232,27 @@ describe('AtlasServiceMain', function () {
232232
const c = new AbortController();
233233
c.abort();
234234
try {
235-
await AtlasService.getQueryFromUserPrompt({
235+
await AtlasService.getQueryFromUserInput({
236236
signal: c.signal,
237-
userPrompt: 'test',
237+
userInput: 'test',
238238
collectionName: 'test',
239239
databaseName: 'peanut',
240240
});
241-
expect.fail('Expected getQueryFromUserPrompt to throw');
241+
expect.fail('Expected getQueryFromUserInput to throw');
242242
} catch (err) {
243243
expect(err).to.have.property('message', 'This operation was aborted');
244244
}
245245
});
246246

247247
it('throws if the request would be too much for the ai', async function () {
248248
try {
249-
await AtlasService.getQueryFromUserPrompt({
250-
userPrompt: 'test',
249+
await AtlasService.getQueryFromUserInput({
250+
userInput: 'test',
251251
collectionName: 'test',
252252
databaseName: 'peanut',
253253
sampleDocuments: [{ test: '4'.repeat(60000) }],
254254
});
255-
expect.fail('Expected getQueryFromUserPrompt to throw');
255+
expect.fail('Expected getQueryFromUserInput to throw');
256256
} catch (err) {
257257
expect(err).to.have.property(
258258
'message',
@@ -269,8 +269,8 @@ describe('AtlasServiceMain', function () {
269269
},
270270
}) as any;
271271

272-
await AtlasService.getQueryFromUserPrompt({
273-
userPrompt: 'test',
272+
await AtlasService.getQueryFromUserInput({
273+
userInput: 'test',
274274
collectionName: 'test.test',
275275
databaseName: 'peanut',
276276
sampleDocuments: [
@@ -287,7 +287,7 @@ describe('AtlasServiceMain', function () {
287287

288288
expect(AtlasService['fetch']).to.have.been.calledOnce;
289289
expect(args[1].body).to.eq(
290-
'{"userPrompt":"test","collectionName":"test.test","databaseName":"peanut","sampleDocuments":[{"a":"1"}]}'
290+
'{"userInput":"test","collectionName":"test.test","databaseName":"peanut","sampleDocuments":[{"a":"1"}]}'
291291
);
292292
});
293293

@@ -299,12 +299,12 @@ describe('AtlasServiceMain', function () {
299299
}) as any;
300300

301301
try {
302-
await AtlasService.getQueryFromUserPrompt({
303-
userPrompt: 'test',
302+
await AtlasService.getQueryFromUserInput({
303+
userInput: 'test',
304304
collectionName: 'test.test',
305305
databaseName: 'peanut',
306306
});
307-
expect.fail('Expected getQueryFromUserPrompt to throw');
307+
expect.fail('Expected getQueryFromUserInput to throw');
308308
} catch (err) {
309309
expect(err).to.have.property('message', '500 Internal Server Error');
310310
}
@@ -314,8 +314,8 @@ describe('AtlasServiceMain', function () {
314314
delete process.env.COMPASS_ATLAS_SERVICE_BASE_URL;
315315

316316
try {
317-
await AtlasService.getQueryFromUserPrompt({
318-
userPrompt: 'test',
317+
await AtlasService.getQueryFromUserInput({
318+
userInput: 'test',
319319
collectionName: 'test.test',
320320
databaseName: 'peanut',
321321
});
@@ -337,8 +337,8 @@ describe('AtlasServiceMain', function () {
337337
}) as any;
338338
AtlasService['oidcPluginSyncedFromLoggerState'] = 'expired';
339339
const [query] = await Promise.all([
340-
AtlasService.getQueryFromUserPrompt({
341-
userPrompt: 'test',
340+
AtlasService.getQueryFromUserInput({
341+
userInput: 'test',
342342
collectionName: 'test',
343343
databaseName: 'test',
344344
sampleDocuments: [],

packages/atlas-service/src/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class AtlasService {
147147
'introspect',
148148
'isAuthenticated',
149149
'signIn',
150-
'getQueryFromUserPrompt',
150+
'getQueryFromUserInput',
151151
]);
152152
this.attachOidcPluginLoggerEvents();
153153
log.info(
@@ -448,15 +448,15 @@ export class AtlasService {
448448
return res.json() as Promise<IntrospectInfo>;
449449
}
450450

451-
static async getQueryFromUserPrompt({
451+
static async getQueryFromUserInput({
452452
signal,
453-
userPrompt,
453+
userInput,
454454
collectionName,
455455
databaseName,
456456
schema,
457457
sampleDocuments,
458458
}: {
459-
userPrompt: string;
459+
userInput: string;
460460
collectionName: string;
461461
databaseName: string;
462462
schema?: SimplifiedSchema;
@@ -469,7 +469,7 @@ export class AtlasService {
469469
}
470470

471471
let msgBody = JSON.stringify({
472-
userPrompt,
472+
userInput,
473473
collectionName,
474474
databaseName,
475475
schema,
@@ -481,7 +481,7 @@ export class AtlasService {
481481
// If that fails we throw an error indicating this collection's
482482
// documents are too large to send to the ai.
483483
msgBody = JSON.stringify({
484-
userPrompt,
484+
userInput,
485485
collectionName,
486486
databaseName,
487487
schema,

packages/atlas-service/src/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ export class AtlasService {
1616
| 'introspect'
1717
| 'isAuthenticated'
1818
| 'signIn'
19-
| 'getQueryFromUserPrompt'
19+
| 'getQueryFromUserInput'
2020
>('AtlasService', [
2121
'getUserInfo',
2222
'introspect',
2323
'isAuthenticated',
2424
'signIn',
25-
'getQueryFromUserPrompt',
25+
'getQueryFromUserInput',
2626
]);
2727

2828
getUserInfo = this.ipc.getUserInfo;
2929
introspect = this.ipc.introspect;
3030
isAuthenticated = this.ipc.isAuthenticated;
31-
getQueryFromUserPrompt = this.ipc.getQueryFromUserPrompt;
31+
getQueryFromUserInput = this.ipc.getQueryFromUserInput;
3232

3333
async signIn(
3434
options: {

packages/compass-query-bar/src/stores/ai-query-reducer.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('aiQueryReducer', function () {
3434
describe('with a successful server response', function () {
3535
it('should succeed', async function () {
3636
const mockAtlasService = {
37-
getQueryFromUserPrompt: sandbox
37+
getQueryFromUserInput: sandbox
3838
.stub()
3939
.resolves({ content: { query: { _id: 1 } } }),
4040
};
@@ -56,19 +56,19 @@ describe('aiQueryReducer', function () {
5656

5757
await store.dispatch(runAIQuery('testing prompt'));
5858

59-
expect(mockAtlasService.getQueryFromUserPrompt).to.have.been.calledOnce;
59+
expect(mockAtlasService.getQueryFromUserInput).to.have.been.calledOnce;
6060
expect(
61-
mockAtlasService.getQueryFromUserPrompt.getCall(0)
62-
).to.have.nested.property('args[0].userPrompt', 'testing prompt');
61+
mockAtlasService.getQueryFromUserInput.getCall(0)
62+
).to.have.nested.property('args[0].userInput', 'testing prompt');
6363
expect(
64-
mockAtlasService.getQueryFromUserPrompt.getCall(0)
64+
mockAtlasService.getQueryFromUserInput.getCall(0)
6565
).to.have.nested.property('args[0].collectionName', 'collection');
6666
expect(
67-
mockAtlasService.getQueryFromUserPrompt.getCall(0)
67+
mockAtlasService.getQueryFromUserInput.getCall(0)
6868
).to.have.nested.property('args[0].databaseName', 'database');
6969
// Sample documents are currently disabled.
7070
expect(
71-
mockAtlasService.getQueryFromUserPrompt.getCall(0)
71+
mockAtlasService.getQueryFromUserInput.getCall(0)
7272
).to.not.have.nested.property('args[0].sampleDocuments');
7373

7474
expect(store.getState().aiQuery.aiQueryFetchId).to.equal(-1);
@@ -80,7 +80,7 @@ describe('aiQueryReducer', function () {
8080
describe('when there is an error', function () {
8181
it('sets the error on the store', async function () {
8282
const mockAtlasService = {
83-
getQueryFromUserPrompt: sandbox
83+
getQueryFromUserInput: sandbox
8484
.stub()
8585
.rejects(new Error('500 Internal Server Error')),
8686
};
@@ -99,7 +99,7 @@ describe('aiQueryReducer', function () {
9999
const authError = new Error('Unauthorized');
100100
(authError as any).statusCode = 401;
101101
const mockAtlasService = {
102-
getQueryFromUserPrompt: sandbox.stub().rejects(authError),
102+
getQueryFromUserInput: sandbox.stub().rejects(authError),
103103
};
104104
const store = createStore({ atlasService: mockAtlasService as any });
105105
await store.dispatch(runAIQuery('testing prompt') as any);

packages/compass-query-bar/src/stores/ai-query-reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function logFailed(errorMessage: string) {
107107
}
108108

109109
export const runAIQuery = (
110-
userPrompt: string
110+
userInput: string
111111
): QueryBarThunkAction<
112112
Promise<void>,
113113
AIQueryStartedAction | AIQueryFailedAction | AIQuerySucceededAction
@@ -151,9 +151,9 @@ export const runAIQuery = (
151151

152152
const { collection: collectionName, database: databaseName } =
153153
toNS(namespace);
154-
jsonResponse = await atlasService.getQueryFromUserPrompt({
154+
jsonResponse = await atlasService.getQueryFromUserInput({
155155
signal: abortController.signal,
156-
userPrompt,
156+
userInput,
157157
collectionName,
158158
databaseName,
159159
schema,

0 commit comments

Comments
 (0)