import { useEffect, useRef } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSparkles, faMicrophone } from '@fortawesome/pro-duotone-svg-icons'; import { formatTimeFull } from '@/lib/format'; import { cx } from '@/utils/cx'; type TranscriptLine = { id: string; text: string; isFinal: boolean; timestamp: Date; }; type Suggestion = { id: string; text: string; timestamp: Date; }; type LiveTranscriptProps = { transcript: TranscriptLine[]; suggestions: Suggestion[]; connected: boolean; }; export const LiveTranscript = ({ transcript, suggestions, connected }: LiveTranscriptProps) => { const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [transcript.length, suggestions.length]); // Merge transcript and suggestions by timestamp const items = [ ...transcript.map(t => ({ ...t, kind: 'transcript' as const })), ...suggestions.map(s => ({ ...s, kind: 'suggestion' as const, isFinal: true })), ].sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()); return (
{/* Header */}
Live Assist
{/* Transcript body */}
{items.length === 0 && (

Listening to customer...

Transcript will appear here

)} {items.map(item => { if (item.kind === 'suggestion') { return (
AI Suggestion

{item.text}

); } return (
{formatTimeFull(item.timestamp.toISOString())} {item.text}
); })}
); };