fix(citations): improve citation link rendering and copy behavior

- Use citation.title for display text in CitationLink to ensure correct
  titles show during streaming (instead of generic "Source" text)
- Render all external links as CitationLink badges for consistent styling
  during streaming output
- Add removeAllCitations when copying message content to clipboard
- Simplify citations_format prompt for cleaner AI output

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LofiSu
2026-02-04 16:34:12 +08:00
parent 644229f968
commit 2debcf421c
3 changed files with 26 additions and 26 deletions

View File

@@ -21,6 +21,7 @@ import {
buildCitationMap,
isCitationsBlockIncomplete,
parseCitations,
removeAllCitations,
} from "@/core/citations";
import {
extractContentFromMessage,
@@ -62,11 +63,11 @@ export function MessageListItem({
>
<div className="flex gap-1">
<CopyButton
clipboardData={
clipboardData={removeAllCitations(
extractContentFromMessage(message) ??
extractReasoningContentFromMessage(message) ??
""
}
)}
/>
</div>
</MessageToolbar>
@@ -76,19 +77,25 @@ export function MessageListItem({
/**
* Custom link component that handles citations and external links
* All external links (http/https) are rendered as CitationLink badges
* to ensure consistent styling during streaming
*/
function MessageLink({
href,
children,
citationMap,
...props
}: React.AnchorHTMLAttributes<HTMLAnchorElement> & {
citationMap: Map<string, Citation>;
}) {
if (!href) return <span>{children}</span>;
const citation = citationMap.get(href);
if (citation) {
// Check if it's an external link (http/https)
const isExternalLink = href.startsWith("http://") || href.startsWith("https://");
// All external links use CitationLink for consistent styling during streaming
if (isExternalLink) {
return (
<CitationLink citation={citation} href={href}>
{children}
@@ -96,13 +103,11 @@ function MessageLink({
);
}
// Internal/anchor links use simple anchor tag
return (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="text-primary underline underline-offset-2 hover:no-underline"
{...props}
>
{children}
</a>