"use client"; import { FileText, ExternalLink, Star, Database, Globe } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; interface SourceReference { title: string; filename?: string; page?: number; score?: number; preview: string; url?: string; source_type?: "web" | "rag"; } interface SourceReferencesProps { sources: SourceReference[]; maxSources?: number; } export default function SourceReferences({ sources, maxSources = 5 }: SourceReferencesProps) { if (!sources || sources.length === 0) { return null; } const displaySources = sources.slice(0, maxSources); const ragSources = displaySources.filter(s => s.source_type !== "web"); const webSources = displaySources.filter(s => s.source_type === "web"); return (
{ragSources.length > 0 && (
知识库来源 ({ragSources.length})
{ragSources.map((source, index) => (
{source.title} {source.score != null && source.score > 0 && source.score < 1 && (
{(source.score * 100).toFixed(1)}%
)}
{source.filename} {source.page && ` • 第 ${source.page} 页`}

{source.preview}

))}
)} {webSources.length > 0 && (
网络来源 ({webSources.length})
{webSources.map((source, index) => ( {source.title}

{source.preview}

{source.url && ( )}
))}
)} {sources.length > maxSources && (
还有 {sources.length - maxSources} 个相关来源
)}
); }