1const m=document.getElementById("search-hero"),h=document.querySelector("#register-submit"),f=document.querySelector("#register-detail-submit"),p=document.getElementById("register-telefone");p.addEventListener("keypress",t=>t.target.value=g(t.target.value));p.addEventListener("change",t=>t.target.value=g(t.target.value));m.addEventListener("keypress",function(t){let n=m.value;t.key==="Enter"&&n&&e.sendMsg(n)});document.querySelectorAll(".mirela-quick-input").forEach(t=>{t.addEventListener("click",function(n){let o=n.srcElement.innerText;e.sendMsg(o),window.scrollTo(0,0)})});h.addEventListener("click",function(t){t.preventDefault(),e.registrarUsuario()});f.addEventListener("click",function(t){t.preventDefault(),e.detalharUsuario()});const g=t=>(t=t.replace(/\D/g,""),t=t.replace(/^(\d{2})(\d)/g,"($1) $2"),t=t.replace(/(\d)(\d{5})$/,"$1-$2"),t);var e={urlBase:"https://mirela.ai/",SERVER_KEY:"swTtiibxZMmO5CvU-TtVF8E6e2uYoCv1x-8ImZIHfq2B6Am3p0-A5cUvT7IOpqsqkWH",msgerChat:document.getElementById("chat-history"),msgerInput:document.getElementById("search-hero"),msgerLoadingMessage:document.getElementById("chat-loading-message"),registerNowPopup:document.getElementById("chat-popup"),registerNowDetailedPopup:document.getElementById("chat-popup-detail"),BOT_IMG:"assets/mirela-ai-1.jpg",PERSON_IMG:"",BOT_NAME:"Mirela IA",PERSON_NAME:"Você",client_initials:null,id_chat:null,id_user:null,init:function(){this.id_user=localStorage.getItem("uuid"),(typeof localStorage.getItem("msgCount")>"u"||localStorage.getItem("msgCount")===null)&&localStorage.setItem("msgCount","0"),this.msgCount=parseInt(localStorage.getItem("msgCount"));let n="Usuário".split(" "),o="";o=n[0][0].toUpperCase(),n.length>1&&(o+=n[1][0].toUpperCase()),this.client_initials=o,setTimeout(()=>{this.registerNowPopup.removeAttribute("hidden"),this.registerNowDetailedPopup.removeAttribute("hidden")},500)},exibirBanner:function(){e.objSuaEmpresa.removeClass("hidden"),e.obj.removeClass("hidden")},esconderBanner:function(){e.obj.addClass("hidden")},getHistory:function(){var t={id_chat:e.id_chat};fetch(e.urlBase+"api/get-history",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json","Server-Key":this.SERVER_KEY}}).then(n=>n.json()).then(n=>{if(typeof n.dados<"u")for(const o of n.dados)e.appendMessage(e.PERSON_NAME,e.PERSON_IMG,"right",o.human,"",e.client_initials),e.appendMessage(e.BOT_NAME,e.BOT_IMG,"left",o.ai,"","");else console.error("Houve um erro na execução do chat: o Histórico da conversa não foi recuperado.")}).catch(n=>console.error(n))},appendMessage:function(t,n,o,r,i,l,s=""){const d=` 2 <div class="msg ${o}-msg"> 3 <div class="msg-bubble"> 4 <div class="msg-info"> 5 <div class="msg-info-name">${t}</div> 6 <div class="msg-info-time">${e.formatDate(new Date)}</div> 7 </div> 8 <div class="msg-text" id="${i}" data-id="${s}">${r}</div> 9 </div> 10 </div> 11 `;e.msgerChat.innerHTML=e.msgerChat.innerHTML+d,e.msgerChat.scrollTop+=500},sendMsg:function(t){e.msgerChat.hasAttribute("hidden")&&e.animarTransicaoChat(t),e.msgerInput.value="",e.appendMessage(e.PERSON_NAME,e.PERSON_IMG,"right",t,"",e.client_initials),e.msgerLoadingMessage.removeAttribute("hidden"),e.id_chat==null&&(e.id_chat=e.uuidv4());var n={msg:t,id_chat:e.id_chat,id_user:e.id_user};e.msgerInput.value="",fetch(e.urlBase+"api/send-message",{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json","Server-Key":this.SERVER_KEY}}).then(o=>o.json()).then(o=>{if(o.status=="falha"){var r="",i=null;if(o.tipo.includes("EXCEEDED_LIMIT_")){switch(r="Desculpe, você excedeu o limite de mensagens permitido.",o.tipo){case"EXCEEDED_LIMIT_FREE":i=this.registerNowPopup;break;case"EXCEEDED_LIMIT_REGISTERED":i=this.registerNowDetailedPopup;break}setTimeout(()=>{ui.modal(i).show(),i.scrollIntoView({behavior:"smooth"})},1e3)}else o.tipo.includes("EXCEEDED_DAILY_LIMIT_")?r="Desculpe, você excedeu o limite de mensagens disponÃveis hoje, volte amanhã para continuar utilizando.":r="Desculpe, houve um erro no processamento da sua mensagem. Por favor, tente enviá-la novamente, e se isso persistir, tente mais tarde, estou notificando o nosso time de desenvolvedores. (2)";return e.enviarMensagemMirela(r),!0}(typeof e.id_user>"u"||e.id_user===null||e.id_user==="")&&e.storeIdUser(o.dados.id_user),e.eventStream(o.dados.id)}).catch(o=>{console.error(o);let r="Desculpe, houve um erro na elaboração da sua mensagem. Por favor, tente enviá-la novamente.";e.enviarMensagemMirela(r)})},animarTransicaoChat:function(t){const n=document.getElementById("secaoTopo"),o=document.querySelector("#secaoTopo div.uk-container"),r=document.querySelector("#secaoTopo div.uk-container > div"),i=document.getElementById("chat-history-wrapper"),l=document.getElementById("chat-history"),s=document.getElementById("mirelaAvatar"),d=document.querySelector('form[name="search-hero"]'),a=document.querySelector("h1"),u=s.parentElement;n.style.animationDuration="500ms",n.style.animationDelay="50ms",n.style.padding="0",n.style.height="calc(100vh - 65px)",r.style.margin="0px",r.style.padding="0px",r.style.height="90vh",r.style.display="flex",r.style.flexDirection="column",r.style.alignItems="stretch",r.style.justifyContent="space-around",o.style.height="85vh",o.style.padding="0px",
11i.style.flex="10",i.style.borderTop="1px solid rgba(255,255,255,0.15)",i.style.height="0px",l.style.height="calc(100% - 65px)",d.style.flex="1",s.style.height="48px",s.style.width="48px",s.parentElement.parentElement.style.width="auto",s.parentElement.style.width="auto",s.parentElement.style.padding="0",a.style.fontSize="26px",a.style.width="auto",a.style.paddingTop="10px",a.style.paddingBottom="10px",a.style.paddingRight="10px",a.style.margin="0px",a.style.flex="1",a.innerText=e.BOT_NAME,a.classList.add("avatar"),u.remove(),e.msgerChat.removeAttribute("hidden")},storeIdUser:function(t){console.log(`Storing id_user: ${t}`),localStorage.setItem("uuid",t),this.id_user=t},eventStream:function(t,n=""){var o=e.urlBase+`api/event-streamer/${t}/${encodeURIComponent(e.id_chat)}`;n!=""&&(o+="/"+encodeURIComponent(btoa(JSON.stringify(n))));let r=e.uuidv4(),i={nome:"",argumentos:""};const l=new EventSourcePolyfill(o,{headers:{"Content-Type":"application/json","Server-Key":this.SERVER_KEY,"User-Id":this.id_user}});return l.onmessage=function(s){let a=JSON.parse(s.data).choices[0];if(a.finish_reason==null)if(typeof a.delta.function_call>"u"){let u=a.delta.content;const c=document.getElementById(r);typeof c>"u"||c==null?u!==""&&e.appendMessage(e.BOT_NAME,e.BOT_IMG,"left",u,r,"",t):typeof u<"u"&&u!==null&&(c.innerHTML+=u.replace(/(?:\r\n|\r|\n)/g,"<br>"))}else typeof a.delta.function_call.name<"u"&&(i.nome=a.delta.function_call.name),i.argumentos+=a.delta.function_call.arguments;else{if(e.msgerLoadingMessage.setAttribute("hidden",!0),l.close(),i.nome!==""){let u=e[i.nome](i.argumentos);if(u!==null&&typeof u<"u"){let c={id_chat:e.id_chat,message_id:t,funcao:i.nome,retorno:u};return i={nome:"",argumentos:""},e.eventStream(t,c),null}}return null}},l.onerror=function(s){console.log(s),console.log(JSON.stringify(s)),l.close()},null},enviarEventStream:function(t){fetch(e.urlBase+`api/event-stream/${t}/${encodeURIComponent(e.id_chat)}`,{headers:{"Content-Type":"application/json","Server-Key":this.SERVER_KEY}}).then(n=>n.json()).then(n=>{var o,r;if(n.status=="falha"){console.error("Houve um erro no processamento da mensagem. Verifique o log do servidor.");let i="Desculpe, houve um erro na elaboração da sua mensagem. Por favor, tente enviá-la novamente.";return e.enviarMensagemMirela(i),null}if(typeof((r=(o=n.resposta)==null?void 0:o.result)==null?void 0:r.para)<"u"&&n.resposta.result.para=="frontend"){let i=e[n.resposta.function_name](n.resposta.result.parameters);if(i!==null&&typeof i<"u"){let l={id_chat:e.id_chat,message_id:t,funcao:n.resposta.function_name,retorno:JSON.stringify(i)};e.enviarEventoResposta(l)}else e.msgerLoadingMessage.setAttribute("hidden",!0);return null}else e.enviarMensagemMirela(n.ai,t)}).catch(n=>{console.error(n);let o="Desculpe, houve um erro na elaboração da sua mensagem. Por favor, tente enviá-la novamente.";e.enviarMensagemMirela(o)})},enviarEventoResposta:function(t){const n=new EventSourcePolyfill(e.urlBase+`api/send-function-response/${encodeURIComponent(btoa(JSON.stringify(t)))}`,{headers:{"Content-Type":"application/json","Server-Key":this.SERVER_KEY}});return n.onmessage=function(o){let r=JSON.parse(o.data);console.log(r)},n.onerror=function(o){console.log(o),console.log(JSON.stringify(o)),n.close()},null},enviarMensagemMirela:function(t,n=""){let o=e.uuidv4();this.appendMessage(e.BOT_NAME,e.BOT_IMG,"left","",o,"",n);const r=document.getElementById(o);return r.innerHTML+=t.replace(/(?:\r\n|\r|\n)/g,"<br>"),e.msgerLoadingMessage.setAttribute("hidden",!0),o},get:function(t,n=document){return n.querySelector(t)},formatDate:function(t){const n="0"+t.getHours(),o="0"+t.getMinutes();return`${n.slice(-2)}:${o.slice(-2)}`},random:function(t,n){return Math.floor(Math.random()*(n-t)+t)},uuidv4:function(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))},registrarUsuario:function(){let t=document.querySelector('#register-form input[name="nome"]').value,n=document.querySelector('#register-form input[name="email"]').value,o=document.querySelector('#register-form input[name="telefone"]').value,r=document.querySelector('#register-form select[name="tipo"]').value;var i={"Content-Type":"application/json","Server-Key":this.SERVER_KEY,"User-Id":this.id_user},l={nome:t,email:n,celularwhatsapp:o,tipo_usuario:r};fetch(e.urlBase+"api/register-user",{method:"POST",headers:i,body:JSON.stringify(l)}).then(s=>s.json()).then(s=>{console.log(s),s.status==="sucesso"?(ui.modal(e.registerNowPopup).hide(),alert("Cadastro realizado com sucesso, agora vocẽ pode continuar tirando dúvidas com a Mirela IA!")):alert(s.message)}
11).catch(s=>console.error(s))},detalharUsuario:function(){}};e.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.