mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 07:26:50 +00:00
chore: 移除所有 Citations 相关逻辑,为后续重构做准备
- Backend: 删除 lead_agent / general_purpose 中的 citations_format 与引用相关 reminder;artifacts 下载不再对 markdown 做 citation 清洗,统一走 FileResponse,保留 Response 用于二进制 inline - Frontend: 删除 core/citations 模块、inline-citation、safe-citation-content;新增 MarkdownContent 仅做 Markdown 渲染;消息/artifact 预览与复制均使用原始 content - i18n: 移除 citations 命名空间(loadingCitations、loadingCitationsWithCount) - 技能与 demo: 措辞改为 references,demo 数据去掉 <citations> 块 - 文档: 更新 CLAUDE/AGENTS/README 描述,新增按文件 diff 的代码变更总结 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,289 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
HoverCard,
|
||||
HoverCardContent,
|
||||
HoverCardTrigger,
|
||||
} from "@/components/ui/hover-card";
|
||||
import {
|
||||
cn,
|
||||
externalLinkClass,
|
||||
externalLinkClassNoUnderline,
|
||||
} from "@/lib/utils";
|
||||
import { ExternalLinkIcon } from "lucide-react";
|
||||
import {
|
||||
type AnchorHTMLAttributes,
|
||||
type ComponentProps,
|
||||
type ImgHTMLAttributes,
|
||||
type ReactElement,
|
||||
type ReactNode,
|
||||
Children,
|
||||
} from "react";
|
||||
import type { Citation } from "@/core/citations";
|
||||
import {
|
||||
extractDomainFromUrl,
|
||||
isExternalUrl,
|
||||
syntheticCitationFromLink,
|
||||
} from "@/core/citations";
|
||||
import { Shimmer } from "./shimmer";
|
||||
import { useI18n } from "@/core/i18n/hooks";
|
||||
|
||||
type InlineCitationCardProps = ComponentProps<typeof HoverCard>;
|
||||
|
||||
const InlineCitationCard = (props: InlineCitationCardProps) => (
|
||||
<HoverCard closeDelay={0} openDelay={0} {...props} />
|
||||
);
|
||||
|
||||
const InlineCitationCardBody = ({
|
||||
className,
|
||||
...props
|
||||
}: ComponentProps<"div">) => (
|
||||
<HoverCardContent className={cn("relative w-80 p-0", className)} {...props} />
|
||||
);
|
||||
|
||||
const InlineCitationSource = ({
|
||||
title,
|
||||
url,
|
||||
description,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: ComponentProps<"div"> & {
|
||||
title?: string;
|
||||
url?: string;
|
||||
description?: string;
|
||||
}) => (
|
||||
<div className={cn("space-y-1", className)} {...props}>
|
||||
{title && (
|
||||
<h4 className="truncate font-medium text-sm leading-tight">{title}</h4>
|
||||
)}
|
||||
{url && (
|
||||
<p className="truncate break-all text-muted-foreground text-xs">{url}</p>
|
||||
)}
|
||||
{description && (
|
||||
<p className="line-clamp-3 text-muted-foreground text-sm leading-relaxed">
|
||||
{description}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* Shared CitationLink component that renders a citation as a hover card badge
|
||||
* Used across message-list-item, artifact-file-detail, and message-group
|
||||
*
|
||||
* When citation is provided, displays title and snippet from the citation.
|
||||
* When citation is omitted, falls back to displaying the domain name extracted from href.
|
||||
*/
|
||||
export type CitationLinkProps = {
|
||||
citation?: Citation;
|
||||
href: string;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const CitationLink = ({
|
||||
citation,
|
||||
href,
|
||||
children,
|
||||
}: CitationLinkProps) => {
|
||||
const domain = extractDomainFromUrl(href);
|
||||
|
||||
// Priority: citation.title > children (if meaningful) > domain
|
||||
// - citation.title: from parsed <citations> block, most accurate
|
||||
// - children: from markdown link text [Text](url), used when no citation data
|
||||
// - domain: fallback when both above are unavailable
|
||||
// Skip children if it's a generic placeholder like "Source"
|
||||
const childrenText = typeof children === "string" ? children : null;
|
||||
const isGenericText = childrenText === "Source" || childrenText === "来源";
|
||||
const displayText = citation?.title || (!isGenericText && childrenText) || domain;
|
||||
|
||||
return (
|
||||
<InlineCitationCard>
|
||||
<HoverCardTrigger asChild>
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Badge
|
||||
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"
|
||||
>
|
||||
{displayText}
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</Badge>
|
||||
</a>
|
||||
</HoverCardTrigger>
|
||||
<InlineCitationCardBody>
|
||||
<div className="p-3">
|
||||
<InlineCitationSource
|
||||
title={citation?.title || domain}
|
||||
url={href}
|
||||
description={citation?.snippet}
|
||||
/>
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary mt-2 inline-flex items-center gap-1 text-xs hover:underline"
|
||||
>
|
||||
Visit source
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</a>
|
||||
</div>
|
||||
</InlineCitationCardBody>
|
||||
</InlineCitationCard>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a link with optional citation badge. Use in markdown components (message + artifact).
|
||||
* - citationMap: URL -> Citation; links in map render as CitationLink.
|
||||
* - isHuman: when true, never render as CitationLink (plain link).
|
||||
* - isLoadingCitations: when true and not human, non-citation links use no-underline style.
|
||||
* - syntheticExternal: when true, external URLs not in citationMap render as CitationLink with synthetic citation.
|
||||
*/
|
||||
export type CitationAwareLinkProps = ComponentProps<"a"> & {
|
||||
citationMap: Map<string, Citation>;
|
||||
isHuman?: boolean;
|
||||
isLoadingCitations?: boolean;
|
||||
syntheticExternal?: boolean;
|
||||
};
|
||||
|
||||
export const CitationAwareLink = ({
|
||||
href,
|
||||
children,
|
||||
citationMap,
|
||||
isHuman = false,
|
||||
isLoadingCitations = false,
|
||||
syntheticExternal = false,
|
||||
className,
|
||||
...rest
|
||||
}: CitationAwareLinkProps) => {
|
||||
if (!href) return <span>{children}</span>;
|
||||
|
||||
const citation = citationMap.get(href);
|
||||
|
||||
if (citation && !isHuman) {
|
||||
return (
|
||||
<CitationLink citation={citation} href={href}>
|
||||
{children}
|
||||
</CitationLink>
|
||||
);
|
||||
}
|
||||
|
||||
if (syntheticExternal && isExternalUrl(href)) {
|
||||
const linkText =
|
||||
typeof children === "string"
|
||||
? children
|
||||
: String(Children.toArray(children).join("")).trim() || href;
|
||||
return (
|
||||
<CitationLink
|
||||
citation={syntheticCitationFromLink(href, linkText)}
|
||||
href={href}
|
||||
>
|
||||
{children}
|
||||
</CitationLink>
|
||||
);
|
||||
}
|
||||
|
||||
const noUnderline = !isHuman && isLoadingCitations;
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={cn(noUnderline ? externalLinkClassNoUnderline : externalLinkClass, className)}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for creating markdown components that render links as citations.
|
||||
* Used by message list (all modes: Flash/Thinking/Pro/Ultra), artifact preview, and CoT.
|
||||
*/
|
||||
export type CreateCitationMarkdownComponentsOptions = {
|
||||
citationMap: Map<string, Citation>;
|
||||
isHuman?: boolean;
|
||||
isLoadingCitations?: boolean;
|
||||
syntheticExternal?: boolean;
|
||||
/** Optional custom img component (e.g. MessageImage with threadId). Omit for artifact. */
|
||||
img?: (props: ImgHTMLAttributes<HTMLImageElement> & { threadId?: string; maxWidth?: string }) => ReactNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create markdown `components` (a, optional img) that use CitationAwareLink.
|
||||
* Reused across message-list-item (all modes), artifact-file-detail, and any CoT markdown.
|
||||
*/
|
||||
export function createCitationMarkdownComponents(
|
||||
options: CreateCitationMarkdownComponentsOptions,
|
||||
): {
|
||||
a: (props: AnchorHTMLAttributes<HTMLAnchorElement>) => ReactElement;
|
||||
img?: (props: ImgHTMLAttributes<HTMLImageElement> & { threadId?: string; maxWidth?: string }) => ReactNode;
|
||||
} {
|
||||
const {
|
||||
citationMap,
|
||||
isHuman = false,
|
||||
isLoadingCitations = false,
|
||||
syntheticExternal = false,
|
||||
img,
|
||||
} = options;
|
||||
const a = (props: AnchorHTMLAttributes<HTMLAnchorElement>) => (
|
||||
<CitationAwareLink
|
||||
{...props}
|
||||
citationMap={citationMap}
|
||||
isHuman={isHuman}
|
||||
isLoadingCitations={isLoadingCitations}
|
||||
syntheticExternal={syntheticExternal}
|
||||
/>
|
||||
);
|
||||
return img ? { a, img } : { a };
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared CitationsLoadingIndicator component
|
||||
* Used across message-list-item and message-group to show loading citations
|
||||
*/
|
||||
export type CitationsLoadingIndicatorProps = {
|
||||
citations: Citation[];
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const CitationsLoadingIndicator = ({
|
||||
citations,
|
||||
className,
|
||||
}: CitationsLoadingIndicatorProps) => {
|
||||
const { t } = useI18n();
|
||||
|
||||
return (
|
||||
<div className={cn("flex flex-col gap-2", className)}>
|
||||
<Shimmer duration={2.5} className="text-sm">
|
||||
{citations.length > 0
|
||||
? t.citations.loadingCitationsWithCount(citations.length)
|
||||
: t.citations.loadingCitations}
|
||||
</Shimmer>
|
||||
{citations.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{citations.map((citation) => (
|
||||
<Badge
|
||||
key={citation.id}
|
||||
variant="secondary"
|
||||
className="animate-fade-in gap-1 rounded-full px-2.5 py-1 text-xs font-normal"
|
||||
>
|
||||
<Shimmer duration={2} as="span">
|
||||
{citation.title || extractDomainFromUrl(citation.url)}
|
||||
</Shimmer>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user