import { v4 as uuidv4 } from 'uuid'; import sha256 from 'js-sha256'; import { WEBUI_BASE_URL } from '$lib/constants'; import { TTS_RESPONSE_SPLIT } from '$lib/types'; ////////////////////////// // Helper functions ////////////////////////// const convertLatexToSingleLine = (content) => { // Patterns to match multiline LaTeX blocks const patterns = [ /(\$\$\s[\s\S]*?\s\$\$)/g, // Match $$ ... $$ /(\\\[[\s\S]*?\\\])/g, // Match \[ ... \] /(\\begin\{[a-z]+\}[\s\S]*?\\end\{[a-z]+\})/g // Match \begin{...} ... \end{...} ]; patterns.forEach((pattern) => { content = content.replace(pattern, (match) => { return match.replace(/\s*\n\s*/g, ' ').trim(); }); }); return content; }; export const replaceTokens = (content, char, user) => { const charToken = /{{char}}/gi; const userToken = /{{user}}/gi; const videoIdToken = /{{VIDEO_FILE_ID_([a-f0-9-]+)}}/gi; // Regex to capture the video ID const htmlIdToken = /{{HTML_FILE_ID_([a-f0-9-]+)}}/gi; // Regex to capture the HTML ID // Replace {{char}} if char is provided if (char !== undefined && char !== null) { content = content.replace(charToken, char); } // Replace {{user}} if user is provided if (user !== undefined && user !== null) { content = content.replace(userToken, user); } // Replace video ID tags with corresponding