Skip to content

Commit 957012d

Browse files
committed
chore: fix up message role and deconstructing
1 parent 6df0be8 commit 957012d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/compass-assistant/src/components/assistant-chat.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ describe('AssistantChat', function () {
342342
expect(messagesContainer.scrollTop).to.equal(0);
343343
});
344344

345-
it('does not scroll to bottom when new message is added by assistant', async function () {
345+
it('does not scroll to bottom when new message is added by assistant', function () {
346346
const { chat } = renderWithChat(mockMessages);
347347

348348
const messagesContainer = screen.getByTestId('assistant-chat-messages');

packages/compass-assistant/src/components/assistant-chat.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
205205
const darkMode = useDarkMode();
206206
const messagesContainerRef = useRef<HTMLDivElement>(null);
207207
const previousLastMessageId = useRef<string | undefined>(undefined);
208-
const { id: lastMessageId, role: lastMessageIsUser } =
209-
chat.messages[chat.messages.length - 1];
208+
const { id: lastMessageId, role: lastMessageRole } =
209+
chat.messages[chat.messages.length - 1] ?? {};
210210

211211
const { ensureOptInAndSend } = useContext(AssistantActionsContext);
212212
const { messages, status, error, clearError, setMessages } = useChat({
@@ -231,12 +231,12 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
231231
lastMessageId &&
232232
previousLastMessageId.current !== undefined &&
233233
lastMessageId !== previousLastMessageId.current &&
234-
lastMessageIsUser
234+
lastMessageRole === 'user'
235235
) {
236236
scrollToBottom();
237237
}
238238
previousLastMessageId.current = lastMessageId;
239-
}, [lastMessageId, lastMessageIsUser, scrollToBottom]);
239+
}, [lastMessageId, lastMessageRole, scrollToBottom]);
240240

241241
useEffect(() => {
242242
const hasExistingNonGenuineWarning = chat.messages.some(

0 commit comments

Comments
 (0)