{"version":3,"file":"index.d8705ee6.js","sources":["../../../../../../node_modules/uuid/dist/esm-browser/rng.js","../../../../../../node_modules/uuid/dist/esm-browser/stringify.js","../../../../../../node_modules/uuid/dist/esm-browser/native.js","../../../../../../node_modules/uuid/dist/esm-browser/v4.js","../../../../../../src/lib/utils/index.ts"],"sourcesContent":["// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nlet getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","import { v4 as uuidv4 } from 'uuid';\nimport sha256 from 'js-sha256';\n\n//////////////////////////\n// Helper functions\n//////////////////////////\n\nexport const sanitizeResponseContent = (content: string) => {\n\treturn content\n\t\t.replace(/<\\|[a-z]*$/, '')\n\t\t.replace(/<\\|[a-z]+\\|$/, '')\n\t\t.replace(/<$/, '')\n\t\t.replaceAll(/<\\|[a-z]+\\|>/g, ' ')\n\t\t.replaceAll('<', '<')\n\t\t.replaceAll('>', '>')\n\t\t.trim();\n};\n\nexport const revertSanitizedResponseContent = (content: string) => {\n\treturn content.replaceAll('<', '<').replaceAll('>', '>');\n};\n\nexport const capitalizeFirstLetter = (string) => {\n\treturn string.charAt(0).toUpperCase() + string.slice(1);\n};\n\nexport const splitStream = (splitOn) => {\n\tlet buffer = '';\n\treturn new TransformStream({\n\t\ttransform(chunk, controller) {\n\t\t\tbuffer += chunk;\n\t\t\tconst parts = buffer.split(splitOn);\n\t\t\tparts.slice(0, -1).forEach((part) => controller.enqueue(part));\n\t\t\tbuffer = parts[parts.length - 1];\n\t\t},\n\t\tflush(controller) {\n\t\t\tif (buffer) controller.enqueue(buffer);\n\t\t}\n\t});\n};\n\nexport const convertMessagesToHistory = (messages) => {\n\tconst history = {\n\t\tmessages: {},\n\t\tcurrentId: null\n\t};\n\n\tlet parentMessageId = null;\n\tlet messageId = null;\n\n\tfor (const message of messages) {\n\t\tmessageId = uuidv4();\n\n\t\tif (parentMessageId !== null) {\n\t\t\thistory.messages[parentMessageId].childrenIds = [\n\t\t\t\t...history.messages[parentMessageId].childrenIds,\n\t\t\t\tmessageId\n\t\t\t];\n\t\t}\n\n\t\thistory.messages[messageId] = {\n\t\t\t...message,\n\t\t\tid: messageId,\n\t\t\tparentId: parentMessageId,\n\t\t\tchildrenIds: []\n\t\t};\n\n\t\tparentMessageId = messageId;\n\t}\n\n\thistory.currentId = messageId;\n\treturn history;\n};\n\nexport const getGravatarURL = (email) => {\n\t// Trim leading and trailing whitespace from\n\t// an email address and force all characters\n\t// to lower case\n\tconst address = String(email).trim().toLowerCase();\n\n\t// Create a SHA256 hash of the final string\n\tconst hash = sha256(address);\n\n\t// Grab the actual image URL\n\treturn `https://www.gravatar.com/avatar/${hash}`;\n};\n\nexport const canvasPixelTest = () => {\n\t// Test a 1x1 pixel to potentially identify browser/plugin fingerprint blocking or spoofing\n\t// Inspiration: https://github.com/kkapsner/CanvasBlocker/blob/master/test/detectionTest.js\n\tconst canvas = document.createElement('canvas');\n\tconst ctx = canvas.getContext('2d');\n\tcanvas.height = 1;\n\tcanvas.width = 1;\n\tconst imageData = new ImageData(canvas.width, canvas.height);\n\tconst pixelValues = imageData.data;\n\n\t// Generate RGB test data\n\tfor (let i = 0; i < imageData.data.length; i += 1) {\n\t\tif (i % 4 !== 3) {\n\t\t\tpixelValues[i] = Math.floor(256 * Math.random());\n\t\t} else {\n\t\t\tpixelValues[i] = 255;\n\t\t}\n\t}\n\n\tctx.putImageData(imageData, 0, 0);\n\tconst p = ctx.getImageData(0, 0, canvas.width, canvas.height).data;\n\n\t// Read RGB data and fail if unmatched\n\tfor (let i = 0; i < p.length; i += 1) {\n\t\tif (p[i] !== pixelValues[i]) {\n\t\t\tconsole.log(\n\t\t\t\t'canvasPixelTest: Wrong canvas pixel RGB value detected:',\n\t\t\t\tp[i],\n\t\t\t\t'at:',\n\t\t\t\ti,\n\t\t\t\t'expected:',\n\t\t\t\tpixelValues[i]\n\t\t\t);\n\t\t\tconsole.log('canvasPixelTest: Canvas blocking or spoofing is likely');\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n};\n\nexport const generateInitialsImage = (name) => {\n\tconst canvas = document.createElement('canvas');\n\tconst ctx = canvas.getContext('2d');\n\tcanvas.width = 100;\n\tcanvas.height = 100;\n\n\tif (!canvasPixelTest()) {\n\t\tconsole.log(\n\t\t\t'generateInitialsImage: failed pixel test, fingerprint evasion is likely. Using default image.'\n\t\t);\n\t\treturn '/user.png';\n\t}\n\n\tctx.fillStyle = '#F39C12';\n\tctx.fillRect(0, 0, canvas.width, canvas.height);\n\n\tctx.fillStyle = '#FFFFFF';\n\tctx.font = '40px Helvetica';\n\tctx.textAlign = 'center';\n\tctx.textBaseline = 'middle';\n\n\tconst sanitizedName = name.trim();\n\tconst initials =\n\t\tsanitizedName.length > 0\n\t\t\t? sanitizedName[0] +\n\t\t\t (sanitizedName.split(' ').length > 1\n\t\t\t\t\t? sanitizedName[sanitizedName.lastIndexOf(' ') + 1]\n\t\t\t\t\t: '')\n\t\t\t: '';\n\n\tctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2);\n\n\treturn canvas.toDataURL();\n};\n\nexport const copyToClipboard = async (text) => {\n\tlet result = false;\n\tif (!navigator.clipboard) {\n\t\tconst textArea = document.createElement('textarea');\n\t\ttextArea.value = text;\n\n\t\t// Avoid scrolling to bottom\n\t\ttextArea.style.top = '0';\n\t\ttextArea.style.left = '0';\n\t\ttextArea.style.position = 'fixed';\n\n\t\tdocument.body.appendChild(textArea);\n\t\ttextArea.focus();\n\t\ttextArea.select();\n\n\t\ttry {\n\t\t\tconst successful = document.execCommand('copy');\n\t\t\tconst msg = successful ? 'successful' : 'unsuccessful';\n\t\t\tconsole.log('Fallback: Copying text command was ' + msg);\n\t\t\tresult = true;\n\t\t} catch (err) {\n\t\t\tconsole.error('Fallback: Oops, unable to copy', err);\n\t\t}\n\n\t\tdocument.body.removeChild(textArea);\n\t\treturn result;\n\t}\n\n\tresult = await navigator.clipboard\n\t\t.writeText(text)\n\t\t.then(() => {\n\t\t\tconsole.log('Async: Copying to clipboard was successful!');\n\t\t\treturn true;\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error('Async: Could not copy text: ', error);\n\t\t\treturn false;\n\t\t});\n\n\treturn result;\n};\n\nexport const compareVersion = (latest, current) => {\n\treturn current === '0.0.0'\n\t\t? false\n\t\t: current.localeCompare(latest, undefined, {\n\t\t\t\tnumeric: true,\n\t\t\t\tsensitivity: 'case',\n\t\t\t\tcaseFirst: 'upper'\n\t\t }) < 0;\n};\n\nexport const findWordIndices = (text) => {\n\tconst regex = /\\[([^\\]]+)\\]/g;\n\tconst matches = [];\n\tlet match;\n\n\twhile ((match = regex.exec(text)) !== null) {\n\t\tmatches.push({\n\t\t\tword: match[1],\n\t\t\tstartIndex: match.index,\n\t\t\tendIndex: regex.lastIndex - 1\n\t\t});\n\t}\n\n\treturn matches;\n};\n\nexport const removeFirstHashWord = (inputString) => {\n\t// Split the string into an array of words\n\tconst words = inputString.split(' ');\n\n\t// Find the index of the first word that starts with #\n\tconst index = words.findIndex((word) => word.startsWith('#'));\n\n\t// Remove the first word with #\n\tif (index !== -1) {\n\t\twords.splice(index, 1);\n\t}\n\n\t// Join the remaining words back into a string\n\tconst resultString = words.join(' ');\n\n\treturn resultString;\n};\n\nexport const transformFileName = (fileName) => {\n\t// Convert to lowercase\n\tconst lowerCaseFileName = fileName.toLowerCase();\n\n\t// Remove special characters using regular expression\n\tconst sanitizedFileName = lowerCaseFileName.replace(/[^\\w\\s]/g, '');\n\n\t// Replace spaces with dashes\n\tconst finalFileName = sanitizedFileName.replace(/\\s+/g, '-');\n\n\treturn finalFileName;\n};\n\nexport const calculateSHA256 = async (file) => {\n\t// Create a FileReader to read the file asynchronously\n\tconst reader = new FileReader();\n\n\t// Define a promise to handle the file reading\n\tconst readFile = new Promise((resolve, reject) => {\n\t\treader.onload = () => resolve(reader.result);\n\t\treader.onerror = reject;\n\t});\n\n\t// Read the file as an ArrayBuffer\n\treader.readAsArrayBuffer(file);\n\n\ttry {\n\t\t// Wait for the FileReader to finish reading the file\n\t\tconst buffer = await readFile;\n\n\t\t// Convert the ArrayBuffer to a Uint8Array\n\t\tconst uint8Array = new Uint8Array(buffer);\n\n\t\t// Calculate the SHA-256 hash using Web Crypto API\n\t\tconst hashBuffer = await crypto.subtle.digest('SHA-256', uint8Array);\n\n\t\t// Convert the hash to a hexadecimal string\n\t\tconst hashArray = Array.from(new Uint8Array(hashBuffer));\n\t\tconst hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('');\n\n\t\treturn `${hashHex}`;\n\t} catch (error) {\n\t\tconsole.error('Error calculating SHA-256 hash:', error);\n\t\tthrow error;\n\t}\n};\n\nexport const getImportOrigin = (_chats) => {\n\t// Check what external service chat imports are from\n\tif ('mapping' in _chats[0]) {\n\t\treturn 'openai';\n\t}\n\treturn 'webui';\n};\n\nexport const getUserPosition = async (raw = false) => {\n\t// Get the user's location using the Geolocation API\n\tconst position = await new Promise((resolve, reject) => {\n\t\tnavigator.geolocation.getCurrentPosition(resolve, reject);\n\t}).catch((error) => {\n\t\tconsole.error('Error getting user location:', error);\n\t\tthrow error;\n\t});\n\n\tif (!position) {\n\t\treturn 'Location not available';\n\t}\n\n\t// Extract the latitude and longitude from the position\n\tconst { latitude, longitude } = position.coords;\n\n\tif (raw) {\n\t\treturn { latitude, longitude };\n\t} else {\n\t\treturn `${latitude.toFixed(3)}, ${longitude.toFixed(3)} (lat, long)`;\n\t}\n};\n\nconst convertOpenAIMessages = (convo) => {\n\t// Parse OpenAI chat messages and create chat dictionary for creating new chats\n\tconst mapping = convo['mapping'];\n\tconst messages = [];\n\tlet currentId = '';\n\tlet lastId = null;\n\n\tfor (let message_id in mapping) {\n\t\tconst message = mapping[message_id];\n\t\tcurrentId = message_id;\n\t\ttry {\n\t\t\tif (\n\t\t\t\tmessages.length == 0 &&\n\t\t\t\t(message['message'] == null ||\n\t\t\t\t\t(message['message']['content']['parts']?.[0] == '' &&\n\t\t\t\t\t\tmessage['message']['content']['text'] == null))\n\t\t\t) {\n\t\t\t\t// Skip chat messages with no content\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tconst new_chat = {\n\t\t\t\t\tid: message_id,\n\t\t\t\t\tparentId: lastId,\n\t\t\t\t\tchildrenIds: message['children'] || [],\n\t\t\t\t\trole: message['message']?.['author']?.['role'] !== 'user' ? 'assistant' : 'user',\n\t\t\t\t\tcontent:\n\t\t\t\t\t\tmessage['message']?.['content']?.['parts']?.[0] ||\n\t\t\t\t\t\tmessage['message']?.['content']?.['text'] ||\n\t\t\t\t\t\t'',\n\t\t\t\t\tmodel: 'gpt-3.5-turbo',\n\t\t\t\t\tdone: true,\n\t\t\t\t\tcontext: null\n\t\t\t\t};\n\t\t\t\tmessages.push(new_chat);\n\t\t\t\tlastId = currentId;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.log('Error with', message, '\\nError:', error);\n\t\t}\n\t}\n\n\tlet history = {};\n\tmessages.forEach((obj) => (history[obj.id] = obj));\n\n\tconst chat = {\n\t\thistory: {\n\t\t\tcurrentId: currentId,\n\t\t\tmessages: history // Need to convert this to not a list and instead a json object\n\t\t},\n\t\tmodels: ['gpt-3.5-turbo'],\n\t\tmessages: messages,\n\t\toptions: {},\n\t\ttimestamp: convo['create_time'],\n\t\ttitle: convo['title'] ?? 'New Chat'\n\t};\n\treturn chat;\n};\n\nconst validateChat = (chat) => {\n\t// Because ChatGPT sometimes has features we can't use like DALL-E or migh have corrupted messages, need to validate\n\tconst messages = chat.messages;\n\n\t// Check if messages array is empty\n\tif (messages.length === 0) {\n\t\treturn false;\n\t}\n\n\t// Last message's children should be an empty array\n\tconst lastMessage = messages[messages.length - 1];\n\tif (lastMessage.childrenIds.length !== 0) {\n\t\treturn false;\n\t}\n\n\t// First message's parent should be null\n\tconst firstMessage = messages[0];\n\tif (firstMessage.parentId !== null) {\n\t\treturn false;\n\t}\n\n\t// Every message's content should be a string\n\tfor (let message of messages) {\n\t\tif (typeof message.content !== 'string') {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n};\n\nexport const convertOpenAIChats = (_chats) => {\n\t// Create a list of dictionaries with each conversation from import\n\tconst chats = [];\n\tlet failed = 0;\n\tfor (let convo of _chats) {\n\t\tconst chat = convertOpenAIMessages(convo);\n\n\t\tif (validateChat(chat)) {\n\t\t\tchats.push({\n\t\t\t\tid: convo['id'],\n\t\t\t\tuser_id: '',\n\t\t\t\ttitle: convo['title'],\n\t\t\t\tchat: chat,\n\t\t\t\ttimestamp: convo['timestamp']\n\t\t\t});\n\t\t} else {\n\t\t\tfailed++;\n\t\t}\n\t}\n\tconsole.log(failed, 'Conversations could not be imported');\n\treturn chats;\n};\n\nexport const isValidHttpUrl = (string) => {\n\tlet url;\n\n\ttry {\n\t\turl = new URL(string);\n\t} catch (_) {\n\t\treturn false;\n\t}\n\n\treturn url.protocol === 'http:' || url.protocol === 'https:';\n};\n\nexport const removeEmojis = (str) => {\n\t// Regular expression to match emojis\n\tconst emojiRegex = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|\\uD83C[\\uDC00-\\uDFFF]|\\uD83D[\\uDC00-\\uDE4F]/g;\n\n\t// Replace emojis with an empty string\n\treturn str.replace(emojiRegex, '');\n};\n\nexport const extractSentences = (text) => {\n\t// Split the paragraph into sentences based on common punctuation marks\n\tconst sentences = text.split(/(?<=[.!?])\\s+/);\n\n\treturn sentences\n\t\t.map((sentence) => removeEmojis(sentence.trim()))\n\t\t.filter((sentence) => sentence !== '');\n};\n\nexport const extractSentencesForAudio = (text) => {\n\treturn extractSentences(text).reduce((mergedTexts, currentText) => {\n\t\tconst lastIndex = mergedTexts.length - 1;\n\t\tif (lastIndex >= 0) {\n\t\t\tconst previousText = mergedTexts[lastIndex];\n\t\t\tconst wordCount = previousText.split(/\\s+/).length;\n\t\t\tif (wordCount < 2) {\n\t\t\t\tmergedTexts[lastIndex] = previousText + ' ' + currentText;\n\t\t\t} else {\n\t\t\t\tmergedTexts.push(currentText);\n\t\t\t}\n\t\t} else {\n\t\t\tmergedTexts.push(currentText);\n\t\t}\n\t\treturn mergedTexts;\n\t}, []);\n};\n\nexport const blobToFile = (blob, fileName) => {\n\t// Create a new File object from the Blob\n\tconst file = new File([blob], fileName, { type: blob.type });\n\treturn file;\n};\n\n/**\n * @param {string} template - The template string containing placeholders.\n * @returns {string} The template string with the placeholders replaced by the prompt.\n */\nexport const promptTemplate = (\n\ttemplate: string,\n\tuser_name?: string,\n\tuser_location?: string\n): string => {\n\t// Get the current date\n\tconst currentDate = new Date();\n\n\t// Format the date to YYYY-MM-DD\n\tconst formattedDate =\n\t\tcurrentDate.getFullYear() +\n\t\t'-' +\n\t\tString(currentDate.getMonth() + 1).padStart(2, '0') +\n\t\t'-' +\n\t\tString(currentDate.getDate()).padStart(2, '0');\n\n\t// Format the time to HH:MM:SS AM/PM\n\tconst currentTime = currentDate.toLocaleTimeString('en-US', {\n\t\thour: 'numeric',\n\t\tminute: 'numeric',\n\t\tsecond: 'numeric',\n\t\thour12: true\n\t});\n\n\t// Replace {{CURRENT_DATETIME}} in the template with the formatted datetime\n\ttemplate = template.replace('{{CURRENT_DATETIME}}', `${formattedDate} ${currentTime}`);\n\n\t// Replace {{CURRENT_DATE}} in the template with the formatted date\n\ttemplate = template.replace('{{CURRENT_DATE}}', formattedDate);\n\n\t// Replace {{CURRENT_TIME}} in the template with the formatted time\n\ttemplate = template.replace('{{CURRENT_TIME}}', currentTime);\n\n\tif (user_name) {\n\t\t// Replace {{USER_NAME}} in the template with the user's name\n\t\ttemplate = template.replace('{{USER_NAME}}', user_name);\n\t}\n\n\tif (user_location) {\n\t\t// Replace {{USER_LOCATION}} in the template with the current location\n\t\ttemplate = template.replace('{{USER_LOCATION}}', user_location);\n\t}\n\n\treturn template;\n};\n\n/**\n * This function is used to replace placeholders in a template string with the provided prompt.\n * The placeholders can be in the following formats:\n * - `{{prompt}}`: This will be replaced with the entire prompt.\n * - `{{prompt:start:}}`: This will be replaced with the first characters of the prompt.\n * - `{{prompt:end:}}`: This will be replaced with the last characters of the prompt.\n * - `{{prompt:middletruncate:}}`: This will be replaced with the prompt truncated to characters, with '...' in the middle.\n *\n * @param {string} template - The template string containing placeholders.\n * @param {string} prompt - The string to replace the placeholders with.\n * @returns {string} The template string with the placeholders replaced by the prompt.\n */\nexport const titleGenerationTemplate = (template: string, prompt: string): string => {\n\ttemplate = template.replace(\n\t\t/{{prompt}}|{{prompt:start:(\\d+)}}|{{prompt:end:(\\d+)}}|{{prompt:middletruncate:(\\d+)}}/g,\n\t\t(match, startLength, endLength, middleLength) => {\n\t\t\tif (match === '{{prompt}}') {\n\t\t\t\treturn prompt;\n\t\t\t} else if (match.startsWith('{{prompt:start:')) {\n\t\t\t\treturn prompt.substring(0, startLength);\n\t\t\t} else if (match.startsWith('{{prompt:end:')) {\n\t\t\t\treturn prompt.slice(-endLength);\n\t\t\t} else if (match.startsWith('{{prompt:middletruncate:')) {\n\t\t\t\tif (prompt.length <= middleLength) {\n\t\t\t\t\treturn prompt;\n\t\t\t\t}\n\t\t\t\tconst start = prompt.slice(0, Math.ceil(middleLength / 2));\n\t\t\t\tconst end = prompt.slice(-Math.floor(middleLength / 2));\n\t\t\t\treturn `${start}...${end}`;\n\t\t\t}\n\t\t\treturn '';\n\t\t}\n\t);\n\n\ttemplate = promptTemplate(template);\n\n\treturn template;\n};\n\nexport const approximateToHumanReadable = (nanoseconds: number) => {\n\tconst seconds = Math.floor((nanoseconds / 1e9) % 60);\n\tconst minutes = Math.floor((nanoseconds / 6e10) % 60);\n\tconst hours = Math.floor((nanoseconds / 3.6e12) % 24);\n\n\tconst results: string[] = [];\n\n\tif (seconds >= 0) {\n\t\tresults.push(`${seconds}s`);\n\t}\n\n\tif (minutes > 0) {\n\t\tresults.push(`${minutes}m`);\n\t}\n\n\tif (hours > 0) {\n\t\tresults.push(`${hours}h`);\n\t}\n\n\treturn results.reverse().join(' ');\n};\n\nexport const getTimeRange = (timestamp) => {\n\tconst now = new Date();\n\tconst date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds\n\n\t// Calculate the difference in milliseconds\n\tconst diffTime = now.getTime() - date.getTime();\n\tconst diffDays = diffTime / (1000 * 3600 * 24);\n\n\tconst nowDate = now.getDate();\n\tconst nowMonth = now.getMonth();\n\tconst nowYear = now.getFullYear();\n\n\tconst dateDate = date.getDate();\n\tconst dateMonth = date.getMonth();\n\tconst dateYear = date.getFullYear();\n\n\tif (nowYear === dateYear && nowMonth === dateMonth && nowDate === dateDate) {\n\t\treturn 'Today';\n\t} else if (nowYear === dateYear && nowMonth === dateMonth && nowDate - dateDate === 1) {\n\t\treturn 'Yesterday';\n\t} else if (diffDays <= 7) {\n\t\treturn 'Previous 7 days';\n\t} else if (diffDays <= 30) {\n\t\treturn 'Previous 30 days';\n\t} else if (nowYear === dateYear) {\n\t\treturn date.toLocaleString('default', { month: 'long' });\n\t} else {\n\t\treturn date.getFullYear().toString();\n\t}\n};\n"],"names":["getRandomValues","rnds8","rng","byteToHex","i","unsafeStringify","arr","offset","randomUUID","native","v4","options","buf","rnds","sanitizeResponseContent","content","revertSanitizedResponseContent","splitStream","splitOn","buffer","chunk","controller","parts","part","convertMessagesToHistory","messages","history","parentMessageId","messageId","message","uuidv4","canvasPixelTest","canvas","ctx","imageData","pixelValues","p","generateInitialsImage","name","sanitizedName","initials","copyToClipboard","text","result","textArea","msg","err","error","compareVersion","latest","current","findWordIndices","regex","matches","match","removeFirstHashWord","inputString","words","index","word","transformFileName","fileName","getImportOrigin","_chats","getUserPosition","raw","position","resolve","reject","latitude","longitude","convertOpenAIMessages","convo","mapping","currentId","lastId","message_id","_a","new_chat","_c","_b","_f","_e","_d","_h","_g","obj","validateChat","chat","convertOpenAIChats","chats","failed","isValidHttpUrl","string","url","removeEmojis","str","emojiRegex","extractSentences","sentence","extractSentencesForAudio","mergedTexts","currentText","lastIndex","previousText","blobToFile","blob","promptTemplate","template","user_name","user_location","currentDate","formattedDate","currentTime","approximateToHumanReadable","nanoseconds","seconds","minutes","hours","results","getTimeRange","timestamp","now","date","diffDays","nowDate","nowMonth","nowYear","dateDate","dateMonth","dateYear"],"mappings":"6BAGA,IAAIA,EACJ,MAAMC,EAAQ,IAAI,WAAW,EAAE,EAChB,SAASC,GAAM,CAE5B,GAAI,CAACF,IAEHA,EAAkB,OAAO,OAAW,KAAe,OAAO,iBAAmB,OAAO,gBAAgB,KAAK,MAAM,EAE3G,CAACA,GACH,MAAM,IAAI,MAAM,0GAA0G,EAI9H,OAAOA,EAAgBC,CAAK,CAC9B,CCXA,MAAME,EAAY,CAAA,EAElB,QAASC,EAAI,EAAGA,EAAI,IAAK,EAAEA,EACzBD,EAAU,MAAMC,EAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,EAG3C,SAASC,EAAgBC,EAAKC,EAAS,EAAG,CAG/C,OAAOJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAIJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAIJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAIJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAI,IAAMJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAIJ,EAAUG,EAAIC,EAAS,CAAC,CAAC,EAAI,IAAMJ,EAAUG,EAAIC,EAAS,CAAC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