-
Notifications
You must be signed in to change notification settings - Fork 234
feat(compass-assistant): show related resources below messages if it exists COMPASS-9838 #7323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2a9422c
3f38951
ab74a2d
f660823
2ce150f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
screen, | ||
userEvent, | ||
waitFor, | ||
within, | ||
} from '@mongodb-js/testing-library-compass'; | ||
import { AssistantChat } from './assistant-chat'; | ||
import { expect } from 'chai'; | ||
|
@@ -30,6 +31,12 @@ describe('AssistantChat', function () { | |
type: 'text', | ||
text: 'Hello! How can I help you with MongoDB today?', | ||
}, | ||
{ | ||
type: 'source-url', | ||
title: 'MongoDB', | ||
url: 'https://en.wikipedia.org/wiki/MongoDB', | ||
sourceId: '1', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
@@ -471,16 +478,14 @@ describe('AssistantChat', function () { | |
); | ||
|
||
// First click thumbs down to potentially open feedback form | ||
const thumbsDownButton = assistantMessage.querySelector( | ||
'[aria-label="Thumbs Down Icon"]' | ||
) as HTMLElement; | ||
const thumbsDownButton = within(assistantMessage).getByLabelText( | ||
'Dislike this message' | ||
); | ||
|
||
userEvent.click(thumbsDownButton); | ||
|
||
// Look for feedback text area (the exact implementation depends on LeafyGreen) | ||
const feedbackTextArea = screen.getByTestId( | ||
'lg-chat-message_actions-feedback_textarea' | ||
); | ||
const feedbackTextArea = within(assistantMessage).getByRole('textbox'); | ||
|
||
userEvent.type(feedbackTextArea, 'This response was not helpful'); | ||
|
||
|
@@ -527,4 +532,33 @@ describe('AssistantChat', function () { | |
expect(screen.queryByLabelText('Thumbs Down Icon')).to.not.exist; | ||
}); | ||
}); | ||
|
||
describe('related sources', function () { | ||
it('displays related resources links for assistant messages that include them', async function () { | ||
renderWithChat(mockMessages); | ||
userEvent.click(screen.getByLabelText('Expand Related Resources')); | ||
|
||
// TODO(COMPASS-9860) can't find the links in test-electron on RHEL and Ubuntu. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 |
||
if ((process as any).type === 'renderer') { | ||
return this.skip(); | ||
} | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('link', { name: 'MongoDB' })).to.have.attribute( | ||
'href', | ||
'https://en.wikipedia.org/wiki/MongoDB' | ||
); | ||
}); | ||
}); | ||
|
||
it('does not display related resources section when there are no source-url parts', function () { | ||
const messages = mockMessages.map((message) => ({ | ||
...message, | ||
parts: message.parts.filter((part) => part.type !== 'source-url'), | ||
})); | ||
renderWithChat(messages); | ||
|
||
expect(screen.queryByLabelText('Expand Related Resources')).to.not.exist; | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import { | |
LgChatChatWindow, | ||
LgChatLeafygreenChatProvider, | ||
LgChatMessage, | ||
LgChatMessageActions, | ||
LgChatInputBar, | ||
spacing, | ||
css, | ||
|
@@ -26,7 +25,6 @@ const { DisclaimerText } = LgChatChatDisclaimer; | |
const { ChatWindow } = LgChatChatWindow; | ||
const { LeafyGreenChatProvider, Variant } = LgChatLeafygreenChatProvider; | ||
const { Message } = LgChatMessage; | ||
const { MessageActions } = LgChatMessageActions; | ||
const { InputBar } = LgChatInputBar; | ||
|
||
const GEN_AI_FAQ_LINK = 'https://www.mongodb.com/docs/generative-ai-faq/'; | ||
|
@@ -141,6 +139,12 @@ const errorBannerWrapperStyles = css({ | |
margin: spacing[400], | ||
}); | ||
|
||
const messagesWrapStyles = css({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: spacing[400], | ||
}); | ||
|
||
export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | ||
chat, | ||
hasNonGenuineConnections, | ||
|
@@ -185,6 +189,13 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | |
.map((part) => part.text) | ||
.join(''), | ||
isSender: message.role === 'user', | ||
sources: message.parts | ||
.filter((part) => part.type === 'source-url') | ||
.map((part) => ({ | ||
children: part.title || 'Documentation Link', | ||
href: part.url, | ||
variant: 'Docs', | ||
})), | ||
})); | ||
|
||
const handleMessageSend = useCallback( | ||
|
@@ -247,7 +258,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | |
data-testid="assistant-chat-messages" | ||
className={messageFeedFixesStyles} | ||
> | ||
<div> | ||
<div className={messagesWrapStyles}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by: I broke the spacing between messages in the recent PR where I fixed the scrolling in a way where it didn't in turn break text selection across messages. |
||
{lgMessages.map((messageFields) => ( | ||
<Message | ||
key={messageFields.id} | ||
|
@@ -256,11 +267,14 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | |
data-testid={`assistant-message-${messageFields.id}`} | ||
> | ||
{messageFields.isSender === false && ( | ||
<MessageActions | ||
<Message.Actions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by: MessageActions is deprecated. Just like MessageLinks. These are now on Message like Message.Actions and Message.Links. |
||
onRatingChange={handleFeedback} | ||
onSubmitFeedback={handleFeedback} | ||
/> | ||
)} | ||
{messageFields.sources.length > 0 && ( | ||
<Message.Links links={messageFields.sources} /> | ||
)} | ||
</Message> | ||
))} | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ You CANNOT: | |
2. Query MongoDB directly or execute code. | ||
3. Access the current state of the UI | ||
</inabilities> | ||
Always call the 'search_content' tool when asked a technical question that would benefit from getting relevant info from the documentation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Jedi mind trick of getting this thing to use the sources and therefore reliably return some. https://mongodb.github.io/chatbot/server/context-engineering#elicit-internal-retrieval-augmented-generation-tool-calls |
||
`; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent half an hour trying to figure out why it suddenly cannot find the textarea by textid even though it is there and the testid matches 🤷