Skip to content

Commit b127066

Browse files
authored
fix: show empty docs msg, schema set msg content correctly (#851)
1 parent 2cf7a18 commit b127066

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

src/participant/participant.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,12 @@ export default class ParticipantController {
792792
// TODO: Remove this when the issue is fixed.
793793
messagesWithNamespace.messages[
794794
messagesWithNamespace.messages.length - 1
795-
].content =
795+
// eslint-disable-next-line new-cap
796+
] = vscode.LanguageModelChatMessage.User(
796797
messagesWithNamespace.messages[
797798
messagesWithNamespace.messages.length - 1
798-
].content.trim() || 'see previous messages';
799+
].content.trim() || 'see previous messages'
800+
);
799801

800802
const responseContentWithNamespace = await this.getChatResponseContent({
801803
modelInput: messagesWithNamespace,
@@ -1359,13 +1361,7 @@ export default class ParticipantController {
13591361
token,
13601362
});
13611363

1362-
this._streamResponseReference({
1363-
reference: {
1364-
url: MONGODB_DOCS_LINK,
1365-
title: 'View MongoDB documentation',
1366-
},
1367-
stream,
1368-
});
1364+
this._streamGenericDocsLink(stream);
13691365

13701366
this._telemetryService.trackCopilotParticipantResponse({
13711367
command: 'docs/copilot',
@@ -1390,6 +1386,16 @@ export default class ParticipantController {
13901386
stream.markdown(link);
13911387
}
13921388

1389+
_streamGenericDocsLink(stream: vscode.ChatResponseStream): void {
1390+
this._streamResponseReference({
1391+
reference: {
1392+
url: MONGODB_DOCS_LINK,
1393+
title: 'View MongoDB documentation',
1394+
},
1395+
stream,
1396+
});
1397+
}
1398+
13931399
async handleDocsRequest(
13941400
...args: [
13951401
vscode.ChatRequest,
@@ -1400,6 +1406,12 @@ export default class ParticipantController {
14001406
): Promise<ChatResult> {
14011407
const [request, context, stream, token] = args;
14021408

1409+
if (Prompts.isPromptEmpty(request)) {
1410+
stream.markdown(Prompts.generic.getEmptyRequestResponse());
1411+
this._streamGenericDocsLink(stream);
1412+
return emptyRequestChatResult(context.history);
1413+
}
1414+
14031415
const chatId = ChatMetadataStore.getChatIdFromHistoryOrNewChatId(
14041416
context.history
14051417
);

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,52 @@ suite('Participant Controller Test Suite', function () {
13831383
'What is the name of the database you would like to run against?'
13841384
);
13851385
});
1386+
1387+
test('with history, and a blank prompt, it sets a message so it does not cause model error (VSCODE-626)', async function () {
1388+
const chatRequestMock = {
1389+
prompt: '',
1390+
command: 'schema',
1391+
references: [],
1392+
};
1393+
chatContextStub = {
1394+
history: [
1395+
Object.assign(Object.create(vscode.ChatRequestTurn.prototype), {
1396+
prompt:
1397+
'how do I make a find request vs favorite_fruits.pineapple?',
1398+
command: 'query',
1399+
references: [],
1400+
participant: CHAT_PARTICIPANT_ID,
1401+
}),
1402+
Object.assign(
1403+
Object.create(vscode.ChatResponseTurn.prototype),
1404+
{
1405+
participant: CHAT_PARTICIPANT_ID,
1406+
response: [
1407+
{
1408+
value: 'some code',
1409+
},
1410+
],
1411+
command: 'query',
1412+
result: {
1413+
metadata: {
1414+
intent: 'query',
1415+
chatId: 'abc',
1416+
},
1417+
},
1418+
}
1419+
),
1420+
],
1421+
};
1422+
await invokeChatHandler(chatRequestMock);
1423+
1424+
expect(sendRequestStub.calledOnce).to.be.true;
1425+
expect(sendRequestStub.firstCall.args[0][0].content).to.include(
1426+
'Parse all user messages to find a database name and a collection name.'
1427+
);
1428+
expect(sendRequestStub.firstCall.args[0][3].content).to.include(
1429+
'see previous messages'
1430+
);
1431+
});
13861432
});
13871433

13881434
suite(
@@ -1549,7 +1595,26 @@ Schema:
15491595

15501596
afterEach(function () {
15511597
global.fetch = initialFetch;
1552-
sinon.restore();
1598+
});
1599+
1600+
test('shows a message and docs link on empty prompt', async function () {
1601+
fetchStub = sinon.stub().resolves();
1602+
global.fetch = fetchStub;
1603+
const chatRequestMock = {
1604+
prompt: '',
1605+
command: 'docs',
1606+
references: [],
1607+
};
1608+
const res = await invokeChatHandler(chatRequestMock);
1609+
expect(fetchStub).to.not.have.been.called;
1610+
expect(sendRequestStub).to.have.not.been.called;
1611+
expect(res?.metadata.intent).to.equal('emptyRequest');
1612+
const defaultEmptyMsg = chatStreamStub.markdown.getCall(0).args[0];
1613+
expect(defaultEmptyMsg).to.include(
1614+
'Ask anything about MongoDB, from writing queries to questions a'
1615+
);
1616+
const referenceMsg = chatStreamStub.markdown.getCall(1).args[0];
1617+
expect(referenceMsg.value).to.include('View MongoDB documentation');
15531618
});
15541619

15551620
test('uses docs chatbot result if available', async function () {

0 commit comments

Comments
 (0)