"use client"; import { useState } from "react"; import ReactMarkdown from "react-markdown"; import rehypeRaw from "rehype-raw"; // Import rehype-raw interface TranscriptViewerProps { transcriptContent: string; transcriptUrl?: string | null; } /** * Format the transcript content into a more readable format with styling */ function formatTranscript(content: string): React.ReactNode[] { if (!content.trim()) { return [

No transcript content available.

]; } // Split the transcript by lines const lines = content.split("\n"); const elements: React.ReactNode[] = []; let currentSpeaker: string | null = null; let currentMessages: string[] = []; // Process each line lines.forEach((line) => { const trimmedLine = line.trim(); if (!trimmedLine) { // Empty line, ignore return; } // Check if this is a new speaker line if (line.startsWith("User:") || line.startsWith("Assistant:")) { // If we have accumulated messages for a previous speaker, add them if (currentSpeaker && currentMessages.length > 0) { elements.push(
{currentMessages.map((msg, i) => ( // Use ReactMarkdown to render each message part ( ), }} > {msg} ))}
); currentMessages = []; } // Set the new current speaker currentSpeaker = trimmedLine.startsWith("User:") ? "User" : "Assistant"; // Add the content after "User:" or "Assistant:" const messageContent = trimmedLine .substring(trimmedLine.indexOf(":") + 1) .trim(); if (messageContent) { currentMessages.push(messageContent); } } else if (currentSpeaker) { // This is a continuation of the current speaker's message currentMessages.push(trimmedLine); } }); // Add any remaining messages if (currentSpeaker && currentMessages.length > 0) { elements.push(
{currentMessages.map((msg, i) => ( // Use ReactMarkdown to render each message part ( ), }} > {msg} ))}
); } return elements; } /** * Component to display a chat transcript */ export default function TranscriptViewer({ transcriptContent, transcriptUrl, }: TranscriptViewerProps) { const [showRaw, setShowRaw] = useState(false); const formattedElements = formatTranscript(transcriptContent); return (

Session Transcript

{transcriptUrl && ( View Full Raw )}
{showRaw ? (
          {transcriptContent}
        
) : (
{formattedElements.length > 0 ? ( formattedElements ) : (

No transcript content available.

)}
)}
); }