Enhances session details with transcript viewer

Adds a transcript viewer component to display transcript content within the session details page.

This change introduces a new `TranscriptViewer` component that renders the transcript content if available. It also adds logic to fetch and store transcript content from the provided URL during session data refresh. The existing link-based transcript view is now used as a fallback when only the transcript URL is available. It also fixes an issue where session ID was not properly displayed.
This commit is contained in:
2025-05-22 05:44:09 +02:00
parent ac7cafd7b2
commit 8ce0b8be37
11 changed files with 620 additions and 14 deletions

View File

@ -11,6 +11,27 @@ interface SessionCreateData {
[key: string]: unknown;
}
/**
* Fetches transcript content from a URL
* @param url The URL to fetch the transcript from
* @returns The transcript content or null if fetching fails
*/
async function fetchTranscriptContent(url: string): Promise<string | null> {
try {
const response = await fetch(url);
if (!response.ok) {
process.stderr.write(
`Error fetching transcript: ${response.statusText}\n`
);
return null;
}
return await response.text();
} catch (error) {
process.stderr.write(`Failed to fetch transcript: ${error}\n`);
return null;
}
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
@ -86,6 +107,14 @@ export default async function handler(
? session.endTime
: new Date();
// Fetch transcript content if URL is available
let transcriptContent: string | null = null;
if (session.fullTranscriptUrl) {
transcriptContent = await fetchTranscriptContent(
session.fullTranscriptUrl
);
}
// Only include fields that are properly typed for Prisma
await prisma.session.create({
data: {
@ -107,6 +136,7 @@ export default async function handler(
? session.forwardedHr
: null,
fullTranscriptUrl: session.fullTranscriptUrl || null,
transcriptContent: transcriptContent, // Add the transcript content
avgResponseTime:
typeof session.avgResponseTime === "number"
? session.avgResponseTime