{"version":3,"file":"widget.js","sources":["../../../scripts/site/widget/index.ts"],"sourcesContent":["/**\n* @summary Functionality for creating and display the assistant as a widget\n*/\n/*BASE CLASS*/\nclass AssistantBaseWidget {\n constructor(id, isDev) {\n this.id = id;\n //TODO: Will need to update url for prod\n this.mantaHost = \"https://manta.barnaclestudios.com\";\n if (isDev) {\n this.mantaHost = \"https://localhost:7034\";\n }\n this.stylePath = this.mantaHost + \"/css/manta/external/external-assistant.css\";\n this.iconPath = this.mantaHost + \"/vendor/boxicons/css/boxicons.min.css\";\n this.framePath = this.mantaHost + \"/assistants/chat/widget/\" + this.id;\n this.scriptFilePath = this.mantaHost + \"/scripts/site/widget.js\";\n this.scriptFuncPath = this.mantaHost + \"/scripts/site/widget.js\";\n }\n init() {\n let self = this;\n const style = this.fetchStyles(this.stylePath);\n const icon = this.fetchStyles(this.iconPath);\n document.head.appendChild(style);\n document.head.appendChild(icon);\n const mantaLoader = new WidgetLoader(\"#4c82f7\");\n document.body.appendChild(mantaLoader.loaderObject);\n //TODO: Check if everything is loaded and then show widget\n this.fetchBuildFrame().then(() => {\n self.showWidget();\n //let images = document.getElementById(self.id)?.getElementsByTagName(\"img\");\n //let imgArray: HTMLImageElement[] = [];\n //if (images != undefined) {\n // for (let i = 0; i < images.length; i++) {\n // imgArray.push(images[i]);\n // }\n // const imageLoadPromises = imgArray.map(img => {\n // return new Promise((resolve, reject) => {\n // img.onload = () => resolve(img);\n // img.onerror = () => reject(new Error(`Failed to load image: ${img.src}`));\n // });\n // });\n // Promise.all(imageLoadPromises).then(() => {\n // self.showWidget();\n // });\n //}\n });\n }\n fetchBuildFrame() {\n let self = this;\n return new Promise((resolve, reject) => {\n let xmlhttp = new XMLHttpRequest();\n let frame = document.createElement(\"div\");\n frame.id = this.id;\n frame.className = \"manta-ea-frame-wrapper\";\n frame.style.display = \"none\";\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n frame.innerHTML = xmlhttp.responseText;\n document.body.appendChild(frame);\n let parentElement = document.getElementById(\"manta-chat-frame\");\n WidgetHelpers.mantifyElements(parentElement);\n let chatUrl = self.mantaHost + \"/chat/ea/frame/\" + (parentElement?.getAttribute(\"data-bot-uid\") ?? \"\") + \"/\" + (parentElement?.getAttribute(\"data-external-bot-uid\") ?? \"\") + \"/\" + (parentElement?.getAttribute(\"data-conversation-uid\") ?? \"\");\n let ratingUrl = self.mantaHost + \"/assistants/chat/ratelog\";\n let resolveUrl = self.mantaHost + \"/assistants/chat/resolvelog\";\n let userTemplateUrl = self.mantaHost + \"/assistants/chat/usermessagetemplate?uid=\" + (parentElement?.getAttribute(\"data-bot-uid\") ?? \"\");\n let assistantTemplateUrl = self.mantaHost + \"/assistants/chat/responsemessagetemplate?uid=\" + (parentElement?.getAttribute(\"data-bot-uid\") ?? \"\");\n let assistantThemeUrl = self.mantaHost + \"/assistants/chat/assistanttheme?uid=\" + (parentElement?.getAttribute(\"data-bot-uid\") ?? \"\");\n let cw = new ChatWidget(\"manta-chat-frame\", chatUrl, ratingUrl, resolveUrl, userTemplateUrl, assistantTemplateUrl, assistantThemeUrl);\n cw.init().then(() => {\n resolve(true);\n });\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n reject(false);\n }\n else {\n console.log(xmlhttp.status);\n reject(false);\n }\n }\n };\n xmlhttp.open(\"GET\", self.framePath, true);\n xmlhttp.send();\n });\n }\n showWidget() {\n let self = this;\n let loader = document.getElementById(\"manta-frame-loader\");\n loader?.remove();\n let frame = document.getElementById(self.id);\n frame.style.display = \"block\";\n document.getElementById(\"manta-frame-bubble\")?.classList.remove(\"manta-d-none\");\n }\n fetchStyles(url) {\n let style = document.createElement(\"link\");\n style.rel = \"stylesheet\";\n style.media = \"screen\";\n style.href = url;\n return style;\n }\n fetchChatScript() {\n let chatScript = document.createElement(\"script\");\n chatScript.type = \"module\";\n chatScript.src = this.scriptFilePath;\n return chatScript;\n }\n buildLoader() {\n let div = document.createElement(\"div\");\n div.id = \"manta-frame-loader\";\n div.className = \"manta-frame-loader\";\n let inner = document.createElement(\"div\");\n inner.className = \"manta-frame-loader-inner\";\n let spinner = document.createElement(\"span\");\n spinner.classList.add(\"spinner-grow\");\n spinner.classList.add(\"text-info\");\n inner.appendChild(spinner);\n div.appendChild(inner);\n return div;\n }\n}\n/*ACTUAL CHAT WIDGET*/\nclass ChatWidget {\n constructor(parentId, chatUrl, ratingUrl, resolveUrl, userTemplateUrl, assistantTemplateUrl, assistantThemeUrl) {\n this.startDragging = (e) => {\n if (this.suggestedPrompts != null) {\n this.unbindAllSuggestionClickEvents();\n this.mouseDown = true;\n this.startX = e.pageX - this.suggestedPrompts.offsetLeft;\n this.scrollLeft = this.suggestedPrompts.scrollLeft;\n }\n };\n this.stopDragging = (e) => {\n this.mouseDown = false;\n };\n this.move = (e) => {\n e.preventDefault();\n if (!this.mouseDown) {\n return;\n }\n if (this.suggestedPrompts != null) {\n const x = e.pageX - this.suggestedPrompts.offsetLeft;\n const scroll = x - (this.startX ?? 0);\n this.suggestedPrompts.scrollLeft = (this.scrollLeft ?? 0) - scroll;\n }\n };\n this.startDrag = () => {\n this.mouseDrag = true;\n };\n this.stopDrag = () => {\n this.mouseDrag = false;\n };\n this.bindAllSuggestionClickEvents = () => {\n let self = this;\n let suggestions = document.querySelectorAll('.manta-chat-suggested-prompt-item');\n this.suggestionHandlers = [];\n suggestions.forEach((s) => {\n self.suggestionHandlers[s.id] = () => self.bindSingleSuggestionClickEvent(s);\n s.addEventListener(\"click\", self.suggestionHandlers[s.id]);\n console.log(self.suggestionHandlers);\n });\n };\n this.parentId = parentId;\n this.chatUrl = chatUrl;\n this.ratingUrl = ratingUrl;\n this.resolveUrl = resolveUrl;\n this.parent = document.getElementById(this.parentId);\n this.chatSendBtn = document.getElementById(\"chat-send\");\n this.chatFrame = document.getElementById(\"manta-chat-frame\");\n this.chatHistory = document.getElementById(\"chat-history\");\n this.chatHistoryInner = document.getElementById(\"chat-history-inner\");\n this.suggestedPrompts = document.getElementById(\"chat-suggested-prompts\");\n this.promptLeftBtn = document.getElementById(\"chat-suggested-prompts-btn-l\");\n this.promptRightBtn = document.getElementById(\"chat-suggested-prompts-btn-r\");\n this.chatPrompt = document.getElementById(\"chat-prompt\");\n this.chatForm = document.getElementById(\"chat-form\");\n this.chatClose = document.getElementById(\"manta-chat-close\");\n this.bubble = document.getElementById(\"manta-frame-bubble\");\n this.welcomeScreen = document.getElementById(\"assistant-chat-welcome-screen\");\n this.mouseDown = false;\n this.mouseDrag = false;\n this.suggestionHandlers = [];\n this.userMessageTemplateUrl = userTemplateUrl;\n this.assistantMessageTemplateUrl = assistantTemplateUrl;\n this.assistantThemeUrl = assistantThemeUrl;\n this.userMessageTemplate = null;\n this.assistantMessageTemplate = null;\n this.assistantTheme = null;\n }\n async init() {\n let self = this;\n return new Promise((resolve, reject) => {\n self.getUserResponseTemplate().then(() => {\n self.getAssistantResponseTemplate().then(() => {\n self.getAssistantTheme().then(() => {\n self.bindEvents();\n self.bindSuggestionSlider();\n resolve(true);\n });\n });\n });\n });\n }\n bindEvents() {\n let self = this;\n this.chatForm?.addEventListener(\"submit\", (e) => {\n e.preventDefault();\n });\n this.chatSendBtn?.addEventListener(\"click\", (e) => {\n this.submitChat();\n });\n this.chatPrompt?.addEventListener(\"keypress\", (e) => {\n if (e.keyCode == 13 || e.which == 13) {\n this.submitChat();\n }\n });\n this.chatClose?.addEventListener(\"click\", (e) => {\n this.toggleOpenClose();\n });\n this.bubble?.addEventListener(\"click\", (e) => {\n this.toggleOpenClose();\n });\n this.promptLeftBtn?.addEventListener(\"click\", (e) => {\n this.scrollSuggestionsLeft();\n });\n this.promptRightBtn?.addEventListener(\"click\", (e) => {\n this.scrollSuggestionsRight();\n });\n if (document.querySelectorAll(\".manta-welcome-screen-initial-selection\").length > 0) {\n let els = document.querySelectorAll(\".manta-welcome-screen-initial-selection\");\n for (let i = 0; i < els.length; i++) {\n els[i].addEventListener(\"click\", (e) => {\n let target = e.currentTarget;\n self.chatPrompt?.setAttribute(\"value\", target.dataset.selectionText);\n self.submitChat();\n });\n }\n }\n }\n async getUserResponseTemplate() {\n let self = this;\n return new Promise((resolve, reject) => {\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n let parser = new DOMParser();\n let responseDOM = parser.parseFromString(xmlhttp.responseText, \"text/html\");\n let responseDiv = document.createElement(\"div\");\n responseDiv.appendChild(responseDOM.documentElement.getElementsByClassName(\"user-submitted-item\")[0]);\n WidgetHelpers.mantifyElements(responseDiv);\n let responseTemplate = responseDiv.getElementsByClassName(\"manta-user-submitted-item\")[0];\n self.userMessageTemplate = responseTemplate;\n resolve(true);\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n reject(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n reject(xmlhttp.status);\n }\n }\n };\n xmlhttp.open(\"GET\", self.userMessageTemplateUrl, true);\n xmlhttp.send();\n });\n }\n async getAssistantResponseTemplate() {\n let self = this;\n return new Promise((resolve, reject) => {\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n let parser = new DOMParser();\n let responseDOM = parser.parseFromString(xmlhttp.responseText, \"text/html\");\n let responseDiv = document.createElement(\"div\");\n responseDiv.appendChild(responseDOM.documentElement.getElementsByClassName(\"chat-response-item\")[0]);\n WidgetHelpers.mantifyElements(responseDiv);\n let responseTemplate = responseDiv.getElementsByClassName(\"manta-chat-response-item\")[0];\n self.assistantMessageTemplate = responseTemplate;\n resolve(true);\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n reject(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n reject(xmlhttp.status);\n }\n }\n };\n xmlhttp.open(\"GET\", self.assistantMessageTemplateUrl, true);\n xmlhttp.send();\n });\n }\n async getAssistantTheme() {\n let self = this;\n return new Promise((resolve, reject) => {\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n let assistantTheme = JSON.parse(xmlhttp.responseText);\n self.assistantTheme = assistantTheme;\n resolve(true);\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n reject(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n reject(xmlhttp.status);\n }\n }\n };\n xmlhttp.open(\"GET\", self.assistantThemeUrl, true);\n xmlhttp.send();\n });\n }\n toggleOpenClose() {\n if (this.chatFrame?.classList.contains(\"open\")) {\n this.parent?.classList.add(\"manta-ea-frame-clear\");\n this.chatFrame?.classList.remove(\"open\");\n this.bubble?.classList.add(\"open\");\n }\n else {\n this.parent?.classList.remove(\"manta-ea-frame-clear\");\n this.chatFrame?.classList.add(\"open\");\n this.bubble?.classList.remove(\"open\");\n }\n }\n submitChat() {\n let self = this;\n if (self.chatPrompt?.value != \"\" && self.chatPrompt != null) {\n self.welcomeScreen?.classList.add(\"manta-d-none\");\n self.chatHistoryInner?.classList.remove(\"manta-d-none\");\n //STP: need to sanitize the input\n self.addUserItemToChat(self.chatPrompt?.value);\n self.toggleSubmitLoading(true);\n if (self.suggestedPrompts != null) {\n self.suggestedPrompts.innerHTML = \"\";\n }\n self.promptLeftBtn?.classList.add(\"manta-d-none\");\n self.promptRightBtn?.classList.add(\"manta-d-none\");\n setTimeout(function () {\n self.toggleTyping(true);\n if (self.chatHistory != null) {\n self.chatHistory.scrollTop = self.chatHistory.scrollHeight;\n }\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n let data = JSON.parse(xmlhttp.response);\n self.toggleTyping(false);\n self.addResponseItemToChat(data.message, data.allowRating, data.logUid, data.isResolved);\n if (data.suggestedQuestions.length > 0) {\n if (self.suggestedPrompts != null) {\n self.suggestedPrompts.style.overflowX = \"scroll\";\n }\n for (let i = 0; i < data.suggestedQuestions.length; ++i) {\n if (data.suggestedQuestions[i] != \"\") {\n self.addSuggestedPrompt(data.suggestedQuestions[i]);\n }\n }\n self.suggestedPrompts?.classList.add(\"manta-py-2\");\n self.bindAllSuggestionClickEvents();\n }\n else {\n if (self.suggestedPrompts != null) {\n self.suggestedPrompts.style.overflowX = \"auto\";\n }\n self.promptLeftBtn?.classList.add(\"manta-d-none\");\n self.promptRightBtn?.classList.add(\"manta-d-none\");\n self.suggestedPrompts?.classList.remove(\"manta-py-2\");\n }\n self.toggleSubmitLoading(false);\n if (self.chatHistory != null) {\n self.chatHistory.scrollTop = self.chatHistory.scrollHeight;\n }\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n }\n }\n };\n xmlhttp.open(\"POST\", self.chatUrl, true);\n xmlhttp.send(new FormData(self.chatForm));\n }, 500);\n }\n return false;\n }\n submitLogRating(posEl, negEl, logUid, rating) {\n let self = this;\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n if (negEl.classList.contains(\"manta-bg-danger\")) {\n negEl.classList.remove(\"manta-bg-danger\");\n negEl.classList.remove(\"manta-text-white\");\n }\n else {\n negEl.classList.add(\"manta-bg-danger\");\n negEl.classList.add(\"manta-text-white\");\n }\n //Commenting out incase we ever bring back thumbs up\n //switch (rating as unknown as string) {\n // case \"0\":\n // if (negEl.classList.contains(\"manta-bg-danger\")) {\n // posEl.classList.remove(\"manta-bg-primary\");\n // posEl.classList.remove(\"manta-text-white\");\n // negEl.classList.remove(\"manta-bg-danger\");\n // negEl.classList.remove(\"manta-text-white\");\n // }\n // else {\n // posEl.classList.remove(\"manta-bg-primary\");\n // posEl.classList.remove(\"manta-text-white\");\n // negEl.classList.add(\"manta-bg-danger\");\n // negEl.classList.add(\"manta-text-white\");\n // }\n // break;\n // case \"1\":\n // if (posEl.classList.contains(\"manta-bg-primary\")) {\n // posEl.classList.remove(\"manta-bg-primary\");\n // posEl.classList.remove(\"manta-text-white\");\n // negEl.classList.remove(\"manta-bg-danger\");\n // negEl.classList.remove(\"manta-text-white\");\n // }\n // else {\n // posEl.classList.add(\"manta-bg-primary\");\n // posEl.classList.add(\"manta-text-white\");\n // negEl.classList.remove(\"manta-bg-danger\");\n // negEl.classList.remove(\"manta-text-white\");\n // }\n // break;\n //}\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n }\n }\n };\n let formData = new FormData();\n formData.append(\"logUid\", logUid);\n formData.append(\"rating\", rating.toString());\n xmlhttp.open(\"POST\", self.ratingUrl, true);\n xmlhttp.send(formData);\n }\n submitResolveLog(el, logUid, markResolved) {\n let self = this;\n let xmlhttp = new XMLHttpRequest();\n xmlhttp.onreadystatechange = () => {\n if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4\n if (xmlhttp.status == 200) {\n let parent = WidgetHelpers.findAncestor(el, \"manta-chat-response-item\");\n if (parent != null) {\n parent.dataset.resolved = markResolved;\n }\n let newEl = el.cloneNode(true);\n el.parentNode?.replaceChild(newEl, el);\n newEl.addEventListener(\"click\", (e) => {\n self.submitResolveLog(newEl, logUid, !markResolved);\n });\n if (markResolved) {\n newEl.classList.add(\"manta-bg-success\");\n newEl.classList.add(\"manta-text-white\");\n }\n else {\n newEl.classList.remove(\"manta-bg-success\");\n newEl.classList.remove(\"manta-text-white\");\n }\n }\n else if (xmlhttp.status == 400) {\n console.log(\"400\");\n }\n else {\n console.log(xmlhttp.status);\n }\n }\n };\n let formData = new FormData();\n formData.append(\"logUid\", logUid);\n formData.append(\"markResolved\", markResolved);\n xmlhttp.open(\"POST\", self.resolveUrl, true);\n xmlhttp.send(formData);\n }\n wireCopy(textToCopy) {\n navigator.clipboard.writeText(textToCopy);\n }\n toggleSubmitLoading(isLoading) {\n if (isLoading) {\n let spinner = document.createElement(\"span\");\n spinner.classList.add(\"manta-spinner-grow\");\n spinner.classList.add(\"manta-spinner-grow-sm\");\n spinner.role = \"status\";\n spinner.ariaHidden = \"true\";\n if (this.chatSendBtn != null) {\n this.chatSendBtn.innerHTML = \"\";\n this.chatSendBtn.appendChild(spinner);\n this.chatSendBtn.disabled = true;\n }\n if (this.chatPrompt != null) {\n this.chatPrompt.readOnly = true;\n }\n }\n else {\n let icon = document.createElement(\"i\");\n icon.classList.add(\"bx\");\n icon.classList.add(\"bx-send\");\n if (this.chatSendBtn != null) {\n this.chatSendBtn.innerHTML = \"\";\n this.chatSendBtn.appendChild(icon);\n this.chatSendBtn.disabled = false;\n }\n if (this.chatPrompt != null) {\n this.chatPrompt.readOnly = false;\n this.chatPrompt.value = \"\";\n }\n }\n }\n scrollSuggestionsLeft() {\n let scrollAmount = this.suggestedPrompts?.getBoundingClientRect().width ?? 0;\n if (this.suggestedPrompts != undefined) {\n this.suggestedPrompts.scrollLeft -= scrollAmount;\n }\n }\n scrollSuggestionsRight() {\n let scrollAmount = this.suggestedPrompts?.getBoundingClientRect().width ?? 0;\n if (this.suggestedPrompts != undefined) {\n this.suggestedPrompts.scrollLeft += scrollAmount;\n }\n }\n bindSuggestionSlider() {\n let self = this;\n if (this.suggestedPrompts != null) {\n this.suggestedPrompts.addEventListener('mousemove', self.move, false);\n this.suggestedPrompts.addEventListener('mousedown', self.startDragging, false);\n this.suggestedPrompts.addEventListener('mousedown', self.stopDrag, false);\n this.suggestedPrompts.addEventListener('mousemove', self.startDrag, false);\n this.suggestedPrompts.addEventListener('mouseup', self.stopDragging, false);\n this.suggestedPrompts.addEventListener('mouseup', self.bindAllSuggestionClickEvents, false);\n this.suggestedPrompts.addEventListener('mouseleave', self.stopDragging, false);\n }\n }\n bindSingleSuggestionClickEvent(suggestion) {\n console.log(this.mouseDrag);\n if (this.chatPrompt != null && !this.mouseDrag) {\n let textDiv = suggestion.querySelector(\".manta-chat-suggested-prompt-item-text\");\n console.log(textDiv);\n console.log(textDiv.innerText);\n this.chatPrompt.value = textDiv.innerText;\n this.chatSendBtn?.click();\n }\n }\n unbindAllSuggestionClickEvents() {\n let self = this;\n let drops = document.querySelectorAll('.manta-chat-suggested-prompt-item');\n drops.forEach((drop) => {\n drop.removeEventListener('click', self.suggestionHandlers[drop.id]);\n });\n self.suggestionHandlers = [];\n console.log(self.suggestionHandlers);\n }\n addSuggestedPrompt(text) {\n let self = this;\n let prompt = document.createElement(\"div\");\n prompt.classList.add(\"manta-chat-suggested-prompt-item\");\n prompt.classList.add(\"manta-d-block\");\n prompt.classList.add(\"manta-badge\");\n prompt.classList.add(\"manta-fs-xs\");\n //prompt.classList.add(\"manta-my-2\");\n prompt.classList.add(\"manta-me-2\");\n prompt.classList.add(\"manta-rounded-pill\");\n prompt.classList.add(\"manta-cursor-pointer\");\n prompt.classList.add(\"manta-px-3\");\n prompt.classList.add(\"manta-py-1\");\n prompt.classList.add(\"manta-col-auto\");\n prompt.id = (\"manta-suggestion-\" + crypto.randomUUID());\n if (self.assistantTheme != null) {\n prompt.style.backgroundColor = self.assistantTheme?.assistantBubbleColor ?? \"\";\n prompt.style.color = self.assistantTheme?.assistantBubbleTextColor ?? \"\";\n }\n else {\n prompt.classList.add(\"manta-bg-faded-info\");\n prompt.classList.add(\"manta-text-primary\");\n }\n let promptInnerDiv = document.createElement(\"div\");\n promptInnerDiv.classList.add(\"manta-d-flex\");\n promptInnerDiv.classList.add(\"manta-w-100\");\n promptInnerDiv.classList.add(\"manta-h-100\");\n promptInnerDiv.classList.add(\"manta-align-items-center\");\n promptInnerDiv.classList.add(\"manta-justify-content-center\");\n let promptInnerInnerDiv = document.createElement(\"div\");\n promptInnerInnerDiv.classList.add(\"manta-chat-suggested-prompt-item-text\");\n promptInnerInnerDiv.textContent = text;\n promptInnerDiv.appendChild(promptInnerInnerDiv);\n prompt.appendChild(promptInnerDiv);\n this.suggestedPrompts?.appendChild(prompt);\n }\n addUserItemToChat(text) {\n let self = this;\n let userItem = self.userMessageTemplate?.cloneNode(true);\n let textDiv = userItem?.getElementsByClassName(\"manta-chat-response-bubble\")[0];\n textDiv.innerText = text;\n if (userItem != null) {\n this.chatHistoryInner?.appendChild(userItem);\n }\n }\n addResponseItemToChat(text, allowRating, logUid, isResolved) {\n let self = this;\n let responseItem = self.assistantMessageTemplate?.cloneNode(true);\n responseItem.dataset.logUid = logUid;\n responseItem.dataset.resolved = isResolved;\n let btnGroup = responseItem.getElementsByClassName(\"manta-log-btn-group\")[0];\n btnGroup.classList.remove(\"manta-d-none\");\n let likeBtns = responseItem.getElementsByClassName(\"manta-log-rating-btn\");\n let posEl = responseItem.querySelectorAll(\"[data-rating='1']\")[0];\n let negEl = responseItem.querySelectorAll(\"[data-rating='0']\")[0];\n for (let i = 0; i < likeBtns.length; i++) {\n likeBtns[i].addEventListener(\"click\", (e) => {\n let clickedEl = e.currentTarget;\n let rating = clickedEl.dataset.rating;\n self.submitLogRating(posEl, negEl, logUid, rating);\n });\n }\n let resolveBtn = responseItem.getElementsByClassName(\"manta-log-resolve-btn\")[0];\n if (resolveBtn != undefined && resolveBtn != null) {\n resolveBtn.addEventListener(\"click\", (e) => {\n self.submitResolveLog(resolveBtn, logUid, !isResolved);\n });\n }\n let copyBtn = responseItem.getElementsByClassName(\"manta-log-copy-btn\")[0];\n if (copyBtn != undefined && copyBtn != null) {\n copyBtn.addEventListener(\"click\", (e) => {\n self.wireCopy(text);\n });\n }\n let textDiv = responseItem?.getElementsByClassName(\"manta-chat-response-bubble\")[0];\n textDiv.innerHTML = text;\n if (responseItem != null) {\n this.chatHistoryInner?.appendChild(responseItem);\n }\n }\n toggleTyping(isTyping) {\n let self = this;\n if (isTyping) {\n let chatItem = self.assistantMessageTemplate?.cloneNode(true);\n chatItem.id = \"manta-typing\";\n let typing = document.createElement(\"div\");\n typing.classList.add(\"manta-typing\");\n typing.classList.add(\"manta-mx-2\");\n let dot = document.createElement(\"i\");\n dot.classList.add(\"manta-dot\");\n dot.classList.add(\"bx\");\n dot.classList.add(\"bxs-circle\");\n dot.classList.add(\"manta-fs-xs\");\n dot.classList.add(\"manta-me-1\");\n typing.appendChild(dot);\n typing.appendChild(dot.cloneNode(true));\n typing.appendChild(dot.cloneNode(true));\n chatItem?.getElementsByClassName(\"manta-chat-response-bubble\")[0].appendChild(typing);\n let btnGroup = chatItem.getElementsByClassName(\"manta-log-btn-group\")[0];\n btnGroup.classList.add(\"manta-d-none\");\n this.chatHistoryInner?.appendChild(chatItem);\n }\n else {\n document.getElementById(\"manta-typing\")?.remove();\n }\n }\n wireSuggestionScrolling() {\n const slider = this.suggestedPrompts;\n let isDown = false;\n let startX;\n let scrollLeft;\n if (slider != null) {\n slider.addEventListener('mousedown', (e) => {\n isDown = true;\n slider.classList.add('active');\n startX = e.pageX - slider.offsetLeft;\n scrollLeft = slider.scrollLeft;\n });\n slider.addEventListener('mouseleave', () => {\n isDown = false;\n slider.classList.remove('active');\n });\n slider.addEventListener('mouseup', () => {\n isDown = false;\n slider.classList.remove('active');\n });\n slider.addEventListener('mousemove', (e) => {\n if (!isDown)\n return;\n e.preventDefault();\n const x = e.pageX - slider.offsetLeft;\n const walk = (x - startX) * 3; //scroll-fast\n slider.scrollLeft = scrollLeft - walk;\n });\n }\n }\n getResponseBubbleDiv(text) {\n let index = text.indexOf(\"~~\");\n let parentDiv = document.createElement(\"div\");\n if (text.indexOf(\"~~\") >= 0) {\n let starterTextDiv = document.createElement(\"div\");\n starterTextDiv.innerText = text.substring(0, index);\n parentDiv.appendChild(starterTextDiv);\n let items = [];\n let match = text.match(/~~(.*?)~~/g);\n if (match != null) {\n items = match.map(function (match) {\n return match.slice(2, -2); // Remove ~~ from the matched string\n });\n }\n if (items.length > 0) {\n let divs = items.map(function (item) {\n let div = document.createElement(\"div\");\n div.textContent = item;\n return div;\n });\n for (let i = 0; i < divs.length; ++i) {\n parentDiv.appendChild(divs[i]);\n }\n }\n }\n else {\n parentDiv.innerText = text;\n }\n return parentDiv;\n }\n}\nclass WidgetHelpers {\n static mantifyElements(parentElement) {\n let self = this;\n if (parentElement != null) {\n let els = parentElement.getElementsByTagName(\"*\");\n for (let i = 0; i < els.length; i++) {\n let element = els[i];\n if (element != null) {\n self.mantifyClasses(element);\n }\n }\n }\n }\n static mantifyClasses(element) {\n let classesToAdd = [];\n let classesToRemove = [];\n for (let i = 0; i < element.classList.length; i++) {\n if (element.classList[i].indexOf(\"manta-\") == -1 && element.classList[i].indexOf(\"bx\") == -1) {\n classesToAdd.push(\"manta-\" + element.classList[i]);\n classesToRemove.push(element.classList[i]);\n }\n }\n for (let i = 0; i < classesToRemove.length; i++) {\n element.classList.remove(classesToRemove[i]);\n }\n for (let i = 0; i < classesToAdd.length; i++) {\n element.classList.add(classesToAdd[i]);\n }\n }\n static findAncestor(el, cls) {\n if (el != null) {\n while ((el = el.parentElement) && !el.classList.contains(cls))\n ;\n return el;\n }\n else {\n return null;\n }\n }\n}\nclass WidgetLoader {\n constructor(colorValue) {\n this.colorValue = colorValue;\n this.loaderTeamplateSVG = this.setTemplateSVG(colorValue);\n this.loaderObject = this.buildLoader();\n }\n setTemplateSVG(colorValue) {\n let svg = `\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n`;\n return svg;\n }\n buildLoader() {\n let div = document.createElement(\"div\");\n div.id = \"manta-frame-loader\";\n div.className = \"manta-frame-loader\";\n div.style.position = \"absolute\";\n div.style.bottom = \"0.5rem\";\n div.style.right = \"0.5rem\";\n let inner = document.createElement(\"div\");\n inner.className = \"manta-frame-loader-inner\";\n inner.innerHTML = this.loaderTeamplateSVG;\n div.appendChild(inner);\n return div;\n }\n}\nif (document.readyState !== 'loading') {\n let script = document.querySelector('script[data-id][data-name=\"MantaAssistant\"]') ?? new Element;\n let id = script.getAttribute('data-id') ?? \"\";\n let isDev = (script.getAttribute('data-is-dev') ?? \"\") == \"true\";\n let ea = new AssistantBaseWidget(id, isDev);\n ea.init();\n}\nelse {\n document.addEventListener('DOMContentLoaded', function () {\n let script = document.querySelector('script[data-id][data-name=\"MantaAssistant\"]') ?? new Element;\n let id = script.getAttribute('data-id') ?? \"\";\n let isDev = (script.getAttribute('data-is-dev') ?? \"\") == \"true\";\n let ea = new AssistantBaseWidget(id, isDev);\n ea.init();\n });\n}\nexport {};\n"],"names":["AssistantBaseWidget","constructor","id","isDev","this","mantaHost","stylePath","iconPath","framePath","scriptFilePath","scriptFuncPath","init","self","style","fetchStyles","icon","document","head","appendChild","mantaLoader","WidgetLoader","body","loaderObject","fetchBuildFrame","then","showWidget","Promise","resolve","reject","xmlhttp","XMLHttpRequest","frame","createElement","className","display","onreadystatechange","readyState","DONE","status","innerHTML","responseText","parentElement","getElementById","WidgetHelpers","mantifyElements","chatUrl","getAttribute","ratingUrl","resolveUrl","userTemplateUrl","assistantTemplateUrl","assistantThemeUrl","ChatWidget","console","log","open","send","loader","remove","classList","url","rel","media","href","fetchChatScript","chatScript","type","src","buildLoader","div","inner","spinner","add","parentId","startDragging","e","suggestedPrompts","unbindAllSuggestionClickEvents","mouseDown","startX","pageX","offsetLeft","scrollLeft","stopDragging","move","preventDefault","scroll","startDrag","mouseDrag","stopDrag","bindAllSuggestionClickEvents","suggestions","querySelectorAll","suggestionHandlers","forEach","s","bindSingleSuggestionClickEvent","addEventListener","parent","chatSendBtn","chatFrame","chatHistory","chatHistoryInner","promptLeftBtn","promptRightBtn","chatPrompt","chatForm","chatClose","bubble","welcomeScreen","userMessageTemplateUrl","assistantMessageTemplateUrl","userMessageTemplate","assistantMessageTemplate","assistantTheme","getUserResponseTemplate","getAssistantResponseTemplate","getAssistantTheme","bindEvents","bindSuggestionSlider","submitChat","keyCode","which","toggleOpenClose","scrollSuggestionsLeft","scrollSuggestionsRight","length","els","i","target","currentTarget","setAttribute","dataset","selectionText","responseDOM","DOMParser","parseFromString","responseDiv","documentElement","getElementsByClassName","responseTemplate","JSON","parse","contains","value","addUserItemToChat","toggleSubmitLoading","setTimeout","toggleTyping","scrollTop","scrollHeight","data","response","addResponseItemToChat","message","allowRating","logUid","isResolved","suggestedQuestions","overflowX","addSuggestedPrompt","FormData","submitLogRating","posEl","negEl","rating","formData","append","toString","submitResolveLog","el","markResolved","findAncestor","resolved","newEl","cloneNode","parentNode","replaceChild","wireCopy","textToCopy","navigator","clipboard","writeText","isLoading","role","ariaHidden","disabled","readOnly","scrollAmount","getBoundingClientRect","width","undefined","suggestion","textDiv","querySelector","innerText","click","drop","removeEventListener","text","prompt","crypto","randomUUID","backgroundColor","assistantBubbleColor","color","assistantBubbleTextColor","promptInnerDiv","promptInnerInnerDiv","textContent","userItem","responseItem","likeBtns","resolveBtn","copyBtn","isTyping","chatItem","typing","dot","wireSuggestionScrolling","slider","isDown","walk","getResponseBubbleDiv","index","indexOf","parentDiv","starterTextDiv","substring","items","match","map","slice","divs","item","getElementsByTagName","element","mantifyClasses","classesToAdd","classesToRemove","push","cls","colorValue","loaderTeamplateSVG","setTemplateSVG","position","bottom","right","script","Element"],"mappings":"AAIA,MAAMA,EACF,WAAAC,CAAYC,EAAIC,GACZC,KAAKF,GAAKA,EAEVE,KAAKC,UAAY,oCACbF,IACAC,KAAKC,UAAY,0BAErBD,KAAKE,UAAYF,KAAKC,UAAY,6CAClCD,KAAKG,SAAWH,KAAKC,UAAY,wCACjCD,KAAKI,UAAYJ,KAAKC,UAAY,2BAA6BD,KAAKF,GACpEE,KAAKK,eAAiBL,KAAKC,UAAY,0BACvCD,KAAKM,eAAiBN,KAAKC,UAAY,yBAC1C,CACD,IAAAM,GACI,IAAIC,EAAOR,KACX,MAAMS,EAAQT,KAAKU,YAAYV,KAAKE,WAC9BS,EAAOX,KAAKU,YAAYV,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