Skip to content

Commit cdbfa92

Browse files
fixing post request
1 parent ee684c7 commit cdbfa92

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

package-lock.json

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@
9595
"@types/react-dom": "^17.0.25",
9696
"react": "^17.0.2",
9797
"react-dom": "^17.0.2"
98+
},
99+
"dependencies": {
100+
"query-string": "^9.1.1"
98101
}
99102
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ 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';
15+
import type { StringifyOptions } from 'query-string';
16+
import queryString from 'query-string';
1517

1618
type GenerativeAiInput = {
1719
userInput: string;
@@ -28,6 +30,18 @@ type GenerativeAiInput = {
2830
const AI_MAX_REQUEST_SIZE = 5120000;
2931
const AI_MIN_SAMPLE_DOCUMENTS = 1;
3032

33+
// Usage: when sending a request of content type 'application/x-www-form-urlencoded'
34+
export const formParams = function formParams(
35+
params: Record<string, any>,
36+
{
37+
skipNull = true,
38+
arrayFormat = 'bracket',
39+
...options
40+
}: StringifyOptions = {}
41+
) {
42+
return queryString.stringify(params, { skipNull, arrayFormat, ...options });
43+
};
44+
3145
type AIAggregation = {
3246
content: {
3347
aggregation?: {
@@ -450,13 +464,13 @@ export class AtlasAiService {
450464
),
451465
{
452466
method: 'POST',
453-
body: JSON.stringify({
454-
value: true,
455-
}),
456467
headers: {
457-
'Content-Type': 'application/json',
468+
'Content-Type': 'application/x-www-form-urlencoded',
458469
Accept: 'application/json',
459470
},
471+
body: formParams({
472+
value: true,
473+
}),
460474
}
461475
);
462476
await this.preferences.savePreferences({

0 commit comments

Comments
 (0)