Skip to content

Commit 8770414

Browse files
authored
fix(compass-assistant): also send the system context after the chat was cleared COMPASS-10182 (#7659)
also send the system context after the chat was cleared;
1 parent bd5736a commit 8770414

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/compass-assistant/src/compass-assistant-provider.spec.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ describe('CompassAssistantProvider', function () {
431431
});
432432
}
433433

434-
const contextMessages = mockChat.messages.filter(
434+
let contextMessages = mockChat.messages.filter(
435435
(message) => message.metadata?.isSystemContext
436436
);
437437

@@ -456,6 +456,30 @@ describe('CompassAssistantProvider', function () {
456456
],
457457
},
458458
]);
459+
460+
// if we clear the chat it will send the context again next time
461+
sendMessageSpy.resetHistory();
462+
mockChat.messages = [];
463+
464+
userEvent.type(
465+
screen.getByPlaceholderText('Ask a question'),
466+
'How about now?'
467+
);
468+
userEvent.click(screen.getByLabelText('Send message'));
469+
470+
await waitFor(() => {
471+
expect(sendMessageSpy.callCount).to.equal(1);
472+
expect(sendMessageSpy.getCall(0).args[0]).to.deep.include({
473+
text: 'How about now?',
474+
});
475+
476+
expect(screen.getByText('How about now?')).to.exist;
477+
});
478+
479+
contextMessages = mockChat.messages.filter(
480+
(message) => message.metadata?.isSystemContext
481+
);
482+
expect(contextMessages).to.have.lengthOf(1);
459483
});
460484

461485
it('will not send new messages if the user does not opt in', async function () {

packages/compass-assistant/src/compass-assistant-provider.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,15 @@ export const AssistantProvider: React.FunctionComponent<
258258
? contextPrompt.parts[0].text
259259
: '';
260260

261+
const hasSystemContextMessage = chat.messages.some((message) => {
262+
return message.metadata?.isSystemContext;
263+
});
264+
261265
const shouldSendContextPrompt =
262266
message?.metadata?.sendContext &&
263267
(!lastContextPromptRef.current ||
264-
lastContextPromptRef.current !== contextPromptText);
268+
lastContextPromptRef.current !== contextPromptText ||
269+
!hasSystemContextMessage);
265270
if (shouldSendContextPrompt) {
266271
lastContextPromptRef.current = contextPromptText;
267272
chat.messages = [...chat.messages, contextPrompt];

0 commit comments

Comments
 (0)