mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-18 03:54:46 +08:00
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:
@@ -309,6 +309,11 @@ export const CitationLink = ({
|
||||
children,
|
||||
}: CitationLinkProps) => {
|
||||
const domain = extractDomainFromUrl(href);
|
||||
|
||||
// Priority: citation.title > domain
|
||||
// When citation has title, use it for consistent display
|
||||
// This ensures correct title shows even during streaming when children might be generic
|
||||
const displayText = citation?.title || domain;
|
||||
|
||||
return (
|
||||
<InlineCitationCard>
|
||||
@@ -324,7 +329,7 @@ export const CitationLink = ({
|
||||
variant="secondary"
|
||||
className="hover:bg-secondary/80 mx-0.5 cursor-pointer gap-1 rounded-full px-2 py-0.5 text-xs font-normal"
|
||||
>
|
||||
{children ?? domain}
|
||||
{displayText}
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</Badge>
|
||||
</a>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user