Spaces:
Running on Zero

File size: 4,837 Bytes
d53374c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use client';

import React from 'react';
import { RetrievedCitation } from '@/src/hooks/useVoiceRAG';
import { sounds } from '@/src/lib/soundEffects';
import {
  X,
  Layers,
  FileText,
  Languages,
  Database,
  CheckCircle2,
  Share2,
  ExternalLink
} from 'lucide-react';

interface SourcesDrawerProps {
  citation: RetrievedCitation | null;
  index: number;
  onClose: () => void;
}

export function SourcesDrawer({ citation, index, onClose }: SourcesDrawerProps) {
  if (!citation) return null;

  return (
    <div className="fixed inset-0 z-50 flex justify-end bg-black/60 backdrop-blur-xs animate-in fade-in duration-200">
      <div className="w-full max-w-lg bg-zinc-950 border-l border-zinc-800 h-full p-6 flex flex-col justify-between shadow-2xl overflow-y-auto space-y-5 animate-in slide-in-from-right duration-300">
        {/* Top Header */}
        <div className="flex items-center justify-between border-b border-zinc-850 pb-4">
          <div className="flex items-center gap-2">
            <div className="p-1.5 rounded-lg bg-emerald-500/10 border border-emerald-500/20 text-emerald-400">
              <Database className="w-4 h-4" />
            </div>
            <div>
              <h3 className="text-zinc-100 font-bold text-sm font-mono">
                MSMARCO-XI Document #{index + 1}
              </h3>
              <p className="text-[10px] text-zinc-500 font-mono">LanceDB IVF-PQ Vector Match</p>
            </div>
          </div>

          <button
            type="button"
            onClick={() => {
              sounds.playBlip();
              onClose();
            }}
            className="p-1.5 rounded-lg text-zinc-400 hover:text-zinc-100 hover:bg-zinc-900 transition-colors"
          >
            <X className="w-4 h-4" />
          </button>
        </div>

        {/* Content Body */}
        <div className="space-y-4 flex-1 font-mono text-xs text-zinc-300">
          {/* Metadata Grid */}
          <div className="grid grid-cols-2 gap-2 bg-zinc-900/60 p-3 rounded-xl border border-zinc-850">
            <div>
              <span className="text-[10px] text-zinc-500 block uppercase">Cosine Distance</span>
              <span className="text-emerald-400 font-bold text-sm">{citation.distance}</span>
            </div>
            <div>
              <span className="text-[10px] text-zinc-500 block uppercase">Chunk Strategy</span>
              <span className="text-zinc-300 font-semibold text-[11px] truncate block">
                {citation.chunk_strategy}
              </span>
            </div>
          </div>

          {/* Child Chunk */}
          <div className="space-y-1.5">
            <span className="text-[10px] uppercase font-bold text-emerald-400 flex items-center gap-1.5">
              <FileText className="w-3.5 h-3.5" />
              50-Word High-Precision Child Chunk:
            </span>
            <div className="bg-emerald-950/20 border border-emerald-800/30 p-3.5 rounded-xl text-emerald-200 leading-relaxed font-sans text-xs">
              "{citation.chunk_text}"
            </div>
          </div>

          {/* Full Parent Passage */}
          <div className="space-y-1.5">
            <span className="text-[10px] uppercase font-bold text-zinc-400 block">
              Full Parent MSMARCO-XI Grounding Passage:
            </span>
            <div className="bg-zinc-900/80 border border-zinc-850 p-3.5 rounded-xl text-zinc-300 leading-relaxed font-sans text-xs">
              {citation.parent_passage}
            </div>
          </div>

          {/* Hindi Translation Split */}
          {citation.translated_passage && (
            <div className="space-y-1.5">
              <span className="text-[10px] uppercase font-bold text-amber-400 flex items-center gap-1.5">
                <Languages className="w-3.5 h-3.5" />
                Hindi Translation Split:
              </span>
              <div className="bg-amber-950/15 border border-amber-800/30 p-3.5 rounded-xl text-amber-200 leading-relaxed font-sans text-xs">
                {citation.translated_passage}
              </div>
            </div>
          )}
        </div>

        {/* Footer */}
        <div className="pt-3 border-t border-zinc-850 flex items-center justify-between text-[11px] font-mono text-zinc-500">
          <span className="flex items-center gap-1 text-emerald-400">
            <CheckCircle2 className="w-3.5 h-3.5" /> Verified Grounded
          </span>
          <button
            type="button"
            onClick={() => {
              sounds.playBlip();
              onClose();
            }}
            className="px-4 py-2 rounded-xl bg-zinc-900 hover:bg-zinc-800 text-zinc-200 border border-zinc-800 transition-colors"
          >
            Close
          </button>
        </div>
      </div>
    </div>
  );
}