Skip to content

Commit 59a467c

Browse files
authored
chore(chat): update docs chatbot request headers VSCODE-634 (#853)
1 parent bfa57d4 commit 59a467c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/participant/docsChatbotAIService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class DocsChatbotAIService {
6969
}): Promise<Response> {
7070
return fetch(uri, {
7171
headers: {
72-
origin: this._serverBaseUri,
72+
'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`,
7373
'User-Agent': `mongodb-vscode/${version}`,
7474
...headers,
7575
},

src/test/suite/participant/docsChatbotAIService.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import sinon from 'sinon';
44

55
import { DocsChatbotAIService } from '../../../participant/docsChatbotAIService';
66

7+
// eslint-disable-next-line @typescript-eslint/no-var-requires
8+
const { version } = require('../../../../package.json');
9+
710
suite('DocsChatbotAIService Test Suite', function () {
811
const initialFetch = global.fetch;
912
let docsChatbotAIService: DocsChatbotAIService;
@@ -138,4 +141,34 @@ suite('DocsChatbotAIService Test Suite', function () {
138141
});
139142
expect(rating).to.be.eql(true);
140143
});
144+
145+
test('has the correct headers', async () => {
146+
const fetchStub = sinon.stub().resolves({
147+
status: 200,
148+
ok: true,
149+
json: () => Promise.resolve(true),
150+
});
151+
global.fetch = fetchStub;
152+
expect(fetchStub.calledOnce).to.be.false;
153+
const signal = new AbortController().signal;
154+
await docsChatbotAIService.addMessage({
155+
conversationId: '650b4b260f975ef031016c8a',
156+
message: 'pineapple',
157+
signal,
158+
});
159+
expect(fetchStub.calledOnce).to.be.true;
160+
expect(fetchStub.firstCall.args[0]).to.equal(
161+
'https://knowledge.mongodb.com/api/v1/conversations/650b4b260f975ef031016c8a/messages'
162+
);
163+
expect(fetchStub.firstCall.args[1]).to.deep.equal({
164+
method: 'POST',
165+
body: '{"message":"pineapple"}',
166+
headers: {
167+
'Content-Type': 'application/json',
168+
'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`,
169+
'User-Agent': `mongodb-vscode/${version}`,
170+
},
171+
signal,
172+
});
173+
});
141174
});

0 commit comments

Comments
 (0)