File size: 1,697 Bytes
750639c
1f5b714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { SourceReference } from '@/types/rag';
import { FileText, ExternalLink } from 'lucide-react';
import { useState } from 'react';
import { cn } from '@/lib/utils';

interface SourceListProps {
  sources: SourceReference[];
  onSourceClick: (path: string) => void;
}

export function SourceList({ sources, onSourceClick }: SourceListProps) {
  const [expanded, setExpanded] = useState(false);

  if (!sources || sources.length === 0) return null;

  const displayedSources = expanded ? sources : sources.slice(0, 3);
  const hasMore = sources.length > 3;

  return (
    <div className="mt-2 text-sm">
      <p className="text-xs font-semibold text-muted-foreground mb-1 flex items-center gap-1">
        <FileText className="h-3 w-3" />
        Sources
      </p>
      <div className="flex flex-wrap gap-2">
        {displayedSources.map((source, i) => (
          <button
            key={i}
            onClick={() => onSourceClick(source.path)}
            className={cn(
              "flex items-center gap-1 px-2 py-1 rounded-md border border-border bg-muted/50 hover:bg-muted transition-colors text-xs max-w-[200px]",
              "text-left truncate"
            )}
            title={source.title}
          >
            <span className="truncate">{source.title}</span>
            <ExternalLink className="h-3 w-3 opacity-50 flex-shrink-0" />
          </button>
        ))}
        {hasMore && !expanded && (
          <button
            onClick={() => setExpanded(true)}
            className="px-2 py-1 text-xs text-muted-foreground hover:text-foreground"
          >
            +{sources.length - 3} more
          </button>
        )}
      </div>
    </div>
  );
}