'use client'; import React from 'react'; import { RAGResponse } from '@/lib/types'; import { ExternalLink, FileText, MapPin } from 'lucide-react'; import RBACBlock from './RBACBlock'; import GuardrailBanner from './GuardrailBanner'; interface ChatMessageProps { type: 'user' | 'assistant' | 'system'; content: string; timestamp: Date; response?: RAGResponse; } export default function ChatMessage({ type, content, timestamp, response }: ChatMessageProps) { const formatTime = (date: Date) => { return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); }; if (type === 'system') { return (
{content}
); } const isUser = type === 'user'; return (
{/* User Message */} {isUser && (

{content}

{formatTime(timestamp)}

)} {/* Assistant Message */} {!isUser && response && (
{/* RBAC Denial Block */} {response.rbac_denied && ( <> )} {/* Guardrail Warnings */} {response.guardrail_flags && response.guardrail_flags.length > 0 && (
)} {/* Main Answer */} {!response.rbac_denied && (

{response.answer}

{/* Metadata Section */}
{/* Route Information */}
🔄

Semantic Route

{(response.route ?? '') .replace(/_/g, ' ') .replace(/route/i, '') .trim()}

{/* User Role & Access */}
👤

Your Access

{response.user_role} {(response.accessible_collections ?? []).map((collection) => ( {collection} ))}
{/* Sources */} {(response.sources ?? []).length > 0 && (

Sources ({(response.sources ?? []).length})

{(response.sources ?? []).map((source, idx) => (

{source.document}

{source.page_number && ( Page {source.page_number} )} {source.section_title && ( {source.section_title} )}
))}
)}
)}

{formatTime(timestamp)}

)}
); }