Sid Gifari File Manager
🏠 Root
/
home
/
genremedia08
/
thepassage.overlookedtracks.com
/
wp-content9
/
plugins
/
echo-knowledge-base
/
js
/
ai
/
Editing: ai-chat-util.min.js
(function(){"use strict";const e="epkb_ai_chat_debug";const s="epkb_debug";function t(){const t=new URLSearchParams(window.location.search);if(t.get(s)==="1"){sessionStorage.setItem(e,"true");return true}return sessionStorage.getItem(e)==="true"}window.epkbEnableDebug=function(s=true){if(s){sessionStorage.setItem(e,"true");console.log("EPKB AI Chat debug mode enabled for this session. Refresh the page to see all debug messages.")}else{sessionStorage.removeItem(e);console.log("EPKB AI Chat debug mode disabled.")}};function r(e,s,t=null){const r=Date.now();const a=Math.random().toString(36).substring(2,11);const n=s?"user":"assistant";return{id:r,messageId:t||`msg_${n}_${r}_${a}`,text:e,isUser:s}}function a(e){const s=e.trim();if(!s){return{valid:false,error:"Empty message"}}if(s.length>2e3){return{valid:false,error:"Message too long",userMessage:"Your message is too long. Please limit it to 2000 characters."}}const t=s.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"");const r=Date.now();const a=Math.random().toString(36).substr(2,9);const n=`msg_user_${r}_${a}`;const o={id:r,messageId:n,text:t,isUser:true};return{valid:true,message:o,text:t,messageId:n}}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const s=Math.random()*16|0;const t=e==="x"?s:s&3|8;return t.toString(16)}))}function o(e){if(typeof marked==="undefined"||!marked||!marked.parse){console.warn("EPKB AI Chat: marked library not available for parsing");return e}try{const s={breaks:true,gfm:true,headerIds:false,mangle:false,sanitize:true};return marked.parse(e,s)}catch(s){console.error("EPKB AI Chat: Error parsing message with marked:",s);return e}}function i(e,s){if(e.status!==403&&e.status!==401){return false}const t=["rest_cookie_invalid_nonce","invalid_nonce","rest_missing_nonce"];return t.includes(s.code)}function c(e,s=null,t=false){const r={type:"unknown",message:"",code:"",userMessage:"",adminMessage:"",isRetryable:false,statusCode:null,context:{}};if(e.name==="AbortError"||e.message&&e.message.toLowerCase().includes("timeout")||e.message&&e.message.toLowerCase().includes("signal")){r.type="timeout";r.code="timeout_error";r.message="Request timed out";r.userMessage="The response is taking longer than expected. The system will retry automatically.";r.adminMessage="Request timeout: "+(e.message||"Unknown timeout error");r.isRetryable=true;r.finalMessage=t?r.adminMessage:r.userMessage;return r}if(s&&s.data){const e=s.data;r.code=e.error||e.code||"";r.message=e.message||"";r.userMessage=e.user_message||e.message||"";r.adminMessage=e.admin_message||e.message||"";r.type=e.error_type||"unknown";r.isRetryable=e.is_retryable||false;r.statusCode=s.status||s.statusCode||null;if(e.retry_after){r.context.retryAfter=e.retry_after}if(e.details){r.context={...r.context,...e.details}}if(!t){r.finalMessage=r.userMessage||"Unable to connect. Please refresh the page and try again."}else{r.finalMessage=r.adminMessage||r.userMessage||"An unexpected error occurred."}return r}if(e instanceof Error){r.message=e.message;r.code=e.code||"";if(e.name==="NetworkError"||e.message.includes("network")){r.type="network";r.userMessage="Network error. Please check your internet connection.";r.adminMessage="Network error: "+e.message;r.isRetryable=true}else{r.userMessage="Unable to connect. Please refresh the page and try again.";r.adminMessage="Client error: "+e.message}r.finalMessage=t?r.adminMessage:r.userMessage}return r}function l(){const e=window.epkbChatWidgetRoot||"epkb-ai-chat-widget-root";return document.getElementById(e)}function u(e){const s={"Content-Type":"application/json"};if(e){s["X-WP-Nonce"]=e}return s}function d(e,s=null,t=1e4,r=null){const a={method:e,credentials:"same-origin",headers:u(r)};if(s){a.body=JSON.stringify(s)}if(typeof AbortSignal!=="undefined"&&AbortSignal.timeout){a.signal=AbortSignal.timeout(t)}return a}async function g(e){if(!e){console.error("EPKB AI Chat: No response object provided to safeParseJSON");return{error:"no_response",message:"No response to parse",user_message:"Unable to process server response. Please refresh the page and try again.",admin_message:"Response object is null or undefined",is_retryable:false,error_type:"parse_error"}}if(e.bodyUsed){return{}}try{const s=await e.text();try{return JSON.parse(s)}catch(t){const r="Server returned non-JSON response";console.error("EPKB AI Chat: "+r,{status:e.status,statusText:e.statusText,responsePreview:s.substring(0,200)+(s.length>200?"...":"")});const a=s.trim().toLowerCase().startsWith("<!doctype")||s.trim().toLowerCase().startsWith("<html");return{error:"invalid_response_format",message:a?"Server returned an HTML page instead of expected JSON response":"Server returned invalid response format",user_message:"Unable to process server response. Please refresh the page and try again.",admin_message:r+": "+(a?"HTML page returned":"Non-JSON response"),is_retryable:false,error_type:"parse_error",raw_response:s.substring(0,500)}}}catch(e){console.error("EPKB AI Chat: Failed to read response",e);return{error:"response_read_error",message:"Failed to read server response",user_message:"Unable to process server response. Please refresh the page and try again.",admin_message:"Failed to read response: "+e.message,is_retryable:false,error_type:"parse_error"}}}function p(e){const{createElement:s}=e;return function(){return s("div",{className:"epkb-ai-chat-message"},s("div",{className:"epkb-ai-chat-typing"},s("div",{className:"epkb-ai-chat-typing-dot"}),s("div",{className:"epkb-ai-chat-typing-dot"}),s("div",{className:"epkb-ai-chat-typing-dot"})))}}function m(e){const{createElement:s}=e;return function(){return s("div",{className:"epkb-ai-chat-loading-skeleton"},s("div",{className:"epkb-ai-chat-skeleton-message epkb-ai-chat-skeleton-message--bot"},s("div",{className:"epkb-ai-chat-skeleton-line"}),s("div",{className:"epkb-ai-chat-skeleton-line epkb-ai-chat-skeleton-line--short"})),s("div",{className:"epkb-ai-chat-skeleton-message epkb-ai-chat-skeleton-message--user"},s("div",{className:"epkb-ai-chat-skeleton-line"})),s("div",{className:"epkb-ai-chat-skeleton-message epkb-ai-chat-skeleton-message--bot"},s("div",{className:"epkb-ai-chat-skeleton-line"}),s("div",{className:"epkb-ai-chat-skeleton-line"}),s("div",{className:"epkb-ai-chat-skeleton-line epkb-ai-chat-skeleton-line--short"})))}}function f(e){const{useEffect:s}=e;return function(e,t,r){s((()=>{if(!t)return;const s=s=>{if(s.key==="Tab"&&e.current){const t=e.current.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])');const r=t[0];const a=t[t.length-1];if(s.shiftKey&&document.activeElement===r){s.preventDefault();a.focus()}else if(!s.shiftKey&&document.activeElement===a){s.preventDefault();r.focus()}}if(s.key==="Escape"&&r){r()}};document.addEventListener("keydown",s);return()=>{document.removeEventListener("keydown",s)}}),[t,e,r])}}function b(e,s=false,t=null){if(!s){return e}const r='<button class="epkb-error-report-btn" style="display: none; margin-left: 10px; font-size: 12px; padding: 2px 8px; cursor: pointer;">Report Issue</button>';return e+" "+r}function h(e,s,t={}){console.error(`%c[EPKB ${e} Error]`,"color: #ff0000; font-weight: bold;",s);if(Object.keys(t).length>0){const e=Object.entries(t).map((([e,s])=>({Property:e,Value:typeof s==="object"?JSON.stringify(s):s})));console.table(e)}}function k(e){const{message:s,isAdmin:t=false,container:r,onReport:a=null,source:n="search"}=e;const o=window.jQuery;const i=o(r);i.empty();const c=s&&(s.includes("temporarily unavailable")||s.includes("API key")||s.includes("not configured"));const l={chat:{base:"epkb-ai-chat-error",message:"epkb-ai-chat-error__message",button:"epkb-ai-chat-error__report-btn"},search:{base:"epkb-ai-search-error__dropdown",message:"epkb-ai-search-error__message",button:"epkb-ai-search-error__report-btn"}};const u=l[n]||l.search;const d=c?" epkb-ai-error--service-unavailable":"";if(t&&a){i.html(`\n <div class="${u.base}${d}">\n <div class="${u.message}">${s}</div>\n <button class="${u.button}" type="button" style="display: none; margin-top: 10px; font-size: 12px; padding: 4px 12px; cursor: pointer; background: #007cba; color: white; border: none; border-radius: 3px;">\n Report Issue\n </button>\n </div>\n `);i.find("."+u.button).on("click",(()=>a(s)))}else{const e=n==="chat"?"epkb-ai-chat-error":"epkb-ai-search-error__user-message";i.html(`<div class="${e}${d}">${s}</div>`)}i.show()}function y(e,s,t={},r=""){const a=[`${e} Error Report`,"===================","",`Error: ${s}`,r?`Context: ${r}`:"",`Time: ${(new Date).toISOString()}`,`URL: ${window.location.href}`,`Browser: ${navigator.userAgent}`,""];if(t&&Object.keys(t).length>0){a.push("Details:",JSON.stringify(t,null,2))}return a.filter((e=>e!=="")).join("\n")}window.EPKBChatUtils={isDebugMode:t,createMessage:r,prepareMessage:a,generateIdempotencyKey:n,parseMessageFormatting:o,isInvalidNonceError:i,parseAIChatErrorResponse:c,parseErrorResponse:c,formatErrorMessage:b,logError:h,showErrorMessage:k,createErrorReport:y,getChatRootElement:l,createHeaders:u,createFetchOptions:d,safeParseJSON:g,TypingIndicator:p,LoadingSkeleton:m,useFocusTrap:f}})();
Save
Cancel