From c43ed729592d7d4aed588d1ab59fb3404ec6e07e Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 7 Oct 2024 15:15:02 -0400 Subject: [PATCH] chore(chat): update docs chatbot request headers --- src/participant/docsChatbotAIService.ts | 2 +- .../participant/docsChatbotAIService.test.ts | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/participant/docsChatbotAIService.ts b/src/participant/docsChatbotAIService.ts index 47858280f..d912f8e0f 100644 --- a/src/participant/docsChatbotAIService.ts +++ b/src/participant/docsChatbotAIService.ts @@ -69,7 +69,7 @@ export class DocsChatbotAIService { }): Promise { return fetch(uri, { headers: { - origin: this._serverBaseUri, + 'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`, 'User-Agent': `mongodb-vscode/${version}`, ...headers, }, diff --git a/src/test/suite/participant/docsChatbotAIService.test.ts b/src/test/suite/participant/docsChatbotAIService.test.ts index e0f97e7ff..a84d86c66 100644 --- a/src/test/suite/participant/docsChatbotAIService.test.ts +++ b/src/test/suite/participant/docsChatbotAIService.test.ts @@ -4,6 +4,9 @@ import sinon from 'sinon'; import { DocsChatbotAIService } from '../../../participant/docsChatbotAIService'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version } = require('../../../../package.json'); + suite('DocsChatbotAIService Test Suite', function () { const initialFetch = global.fetch; let docsChatbotAIService: DocsChatbotAIService; @@ -138,4 +141,34 @@ suite('DocsChatbotAIService Test Suite', function () { }); expect(rating).to.be.eql(true); }); + + test('has the correct headers', async () => { + const fetchStub = sinon.stub().resolves({ + status: 200, + ok: true, + json: () => Promise.resolve(true), + }); + global.fetch = fetchStub; + expect(fetchStub.calledOnce).to.be.false; + const signal = new AbortController().signal; + await docsChatbotAIService.addMessage({ + conversationId: '650b4b260f975ef031016c8a', + message: 'pineapple', + signal, + }); + expect(fetchStub.calledOnce).to.be.true; + expect(fetchStub.firstCall.args[0]).to.equal( + 'https://knowledge.mongodb.com/api/v1/conversations/650b4b260f975ef031016c8a/messages' + ); + expect(fetchStub.firstCall.args[1]).to.deep.equal({ + method: 'POST', + body: '{"message":"pineapple"}', + headers: { + 'Content-Type': 'application/json', + 'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`, + 'User-Agent': `mongodb-vscode/${version}`, + }, + signal, + }); + }); });