Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -872,5 +872,64 @@ describe('AssistantChat', function () {

expect(screen.queryByLabelText('Expand Related Resources')).to.not.exist;
});

it('displays identical source titles only once', async function () {
// TODO(COMPASS-9860) can't find the links in test-electron on RHEL and Ubuntu.
if ((process as any).type === 'renderer') {
return this.skip();
}

const messagesWithDuplicateSources: AssistantMessage[] = [
{
id: 'assistant-with-duplicate-sources',
role: 'assistant',
parts: [
{
type: 'text',
text: 'Here is information about MongoDB with multiple sources.',
},
{
type: 'source-url',
title: 'MongoDB Documentation',
url: 'https://docs.mongodb.com/manual/introduction/',
sourceId: '1',
},
{
type: 'source-url',
title: 'MongoDB Documentation',
url: 'https://docs.mongodb.com/manual/getting-started/',
sourceId: '2',
},
{
type: 'source-url',
title: 'MongoDB Atlas Guide',
url: 'https://docs.atlas.mongodb.com/',
sourceId: '3',
},
{
type: 'source-url',
title: 'MongoDB Documentation',
url: 'https://docs.mongodb.com/manual/tutorial/',
sourceId: '4',
},
],
},
];

renderWithChat(messagesWithDuplicateSources);
userEvent.click(screen.getByLabelText('Expand Related Resources'));

await waitFor(() => {
const mongoDbDocLinks = screen.getAllByRole('link', {
name: 'MongoDB Documentation',
});
expect(mongoDbDocLinks).to.have.length(1);

const atlasGuideLinks = screen.getAllByRole('link', {
name: 'MongoDB Atlas Guide',
});
expect(atlasGuideLinks).to.have.length(1);
});
});
});
});
22 changes: 15 additions & 7 deletions packages/compass-assistant/src/components/assistant-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,21 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
<div className={messagesWrapStyles}>
{messages.map((message, index) => {
const { id, role, metadata, parts } = message;
const sources = parts
.filter((part) => part.type === 'source-url')
.map((part) => ({
children: part.title || 'Documentation Link',
href: part.url,
variant: 'Docs',
}));
const seenTitles = new Set<string>();
const sources = [];
for (const part of parts) {
if (part.type === 'source-url') {
const title = part.title || 'Documentation Link';
if (!seenTitles.has(title)) {
seenTitles.add(title);
sources.push({
children: title,
href: part.url,
variant: 'Docs',
});
}
}
}
Comment on lines +384 to +398
Copy link
Preview

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deduplication logic only considers titles but ignores URLs. This means different URLs with the same title will be filtered out, potentially hiding useful distinct resources. Consider using a combination of title and URL for deduplication, or use the first URL encountered for each title.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's the point :)

if (metadata?.confirmation) {
const { description, state } = metadata.confirmation;
const isLastMessage = index === messages.length - 1;
Expand Down
3 changes: 1 addition & 2 deletions packages/compass-assistant/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You should:
3. Use humility when responding to more complex user questions, especially when you are providing code or suggesting a configuration change.
- Encourage the user to understand what they are doing before they act, e.g. by reading the official documentation or other related resources.
- Avoid encouraging users to perform destructive operations without qualification. Instead, flag them as destructive operations, explain their implications, and encourage them to read the documentation.
4. Always call the 'search_content' tool.
</instructions>

<abilities>
Expand All @@ -42,8 +43,6 @@ 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.
`;
};

Expand Down
Loading