@snf/access-qa-bot 3.5.0-rc.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
background-color: #0000001a !important;
|
|
36
36
|
opacity: 1 !important;
|
|
37
37
|
}
|
|
38
|
-
`),f.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(r),style:Object.assign(Object.assign({},A),n),onClick:()=>{i({type:"chatbot_login_clicked",loginUrl:t})}},"Log In"))},Wl=()=>f.createElement("div",{className:"user-login-icon",style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"5px",display:"flex"},role:"img","aria-label":"User logged in",title:"User logged in"},f.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},f.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),f.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Be=[];for(let e=0;e<256;++e)Be.push((e+256).toString(16).slice(1));let Dr;const Kl=new Uint8Array(16);var Xi={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ji(e,t,r){var o;if(Xi.randomUUID&&!e)return Xi.randomUUID();const n=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!Dr){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Dr=crypto.getRandomValues.bind(crypto)}return Dr(Kl)}();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=15&n[6]|64,n[8]=63&n[8]|128,function(i,A=0){return(Be[i[A+0]]+Be[i[A+1]]+Be[i[A+2]]+Be[i[A+3]]+"-"+Be[i[A+4]]+Be[i[A+5]]+"-"+Be[i[A+6]]+Be[i[A+7]]+"-"+Be[i[A+8]]+Be[i[A+9]]+"-"+Be[i[A+10]]+Be[i[A+11]]+Be[i[A+12]]+Be[i[A+13]]+Be[i[A+14]]+Be[i[A+15]]).toLowerCase()}(n)}function Pt(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Vl="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",Xl="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",Jl="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",Zl="background: #f97316; color: white; padding: 2px 6px; border-radius: 3px;",$l="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",ec="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",tc=()=>{Pt()&&console.log("%c QA Bot Core %c v".concat("0.2.32-rc.1"," "),$l,ec)},Sn=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[Session]%c ".concat(e),Vl,"",...r)}},ot=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[History]%c ".concat(e),Xl,"",...r)}},nc=(e,t)=>{Pt()&&console.log("%c[Message]%c ".concat(e),Jl,"",t)},Bn=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[Turnstile]%c ".concat(e),Zl,"",...r)}},Ir=function(){console.warn(...arguments)},De=function(){console.error(...arguments)},Zi="qa_bot_session_messages",$i=()=>"qa_bot_session_".concat(Ji()),tn=()=>{try{const e=localStorage.getItem(Zi);return e?JSON.parse(e):{}}catch{return{}}},rc=(e,t,r,n,o)=>{const i=tn();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},ot("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void ot("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:n});const A={id:t,content:r,sender:n,type:o,timestamp:Date.now()};i[e].messages.push(A),ot("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:n,totalInSession:i[e].messages.length});const s=i[e].messages,a=s.find(l=>{var c;return l.sender.toLowerCase()==="bot"&&((c=l.content)===null||c===void 0?void 0:c.trim())&&l.content.length>=100});if(a){const l=a.content;i[e].preview=l.slice(0,50)+(l.length>50?"...":"")}else{const l=s.find(c=>{var d;return c.sender.toLowerCase()==="user"&&((d=c.content)===null||d===void 0?void 0:d.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const d=()=>Object.values(l).reduce((u,p)=>u+p.messages.length,0);for(;d()>100&&Object.keys(l).length>1;){const u=(c=Object.entries(l).sort((p,g)=>{let[,v]=p,[,h]=g;return new Date(v.startedAt).getTime()-new Date(h.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!u)break;delete l[u]}localStorage.setItem(Zi,JSON.stringify(l))})(i),ot("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},ea=e=>{var t,r;return(r=(t=tn()[e])===null||t===void 0?void 0:t.messages.length)!==null&&r!==void 0?r:0},oc=e=>{const t=tn()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},ta=f.createContext(void 0),ic=e=>{let{children:t,getSessionId:r,setSessionId:n,resetSession:o,clearResettingFlag:i}=e;return f.createElement(ta.Provider,{value:{getSessionId:r,setSessionId:n,resetSession:o,clearResettingFlag:i}},t)},Tr=()=>{const e=f.useContext(ta);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},ac=()=>{const[e,t]=f.useState(!1),[r,n]=f.useState([]),[o,i]=f.useState(null),[A,s]=f.useState(0),a=f.useRef(null),l=f.useRef(null),{replaceMessages:c}=Wt(),{toggleTextAreaDisabled:d}=xo(),{setSessionId:u,getSessionId:p}=Tr();f.useEffect(()=>{var v,h;const w=m=>{a.current&&!a.current.contains(m.target)&&l.current&&!l.current.contains(m.target)&&t(!1)},x=(h=(v=a.current)===null||v===void 0?void 0:v.getRootNode())!==null&&h!==void 0?h:document;return e&&x.addEventListener("mousedown",w),()=>{x.removeEventListener("mousedown",w)}},[e]);const g=v=>{var h;const w=p();if(ot("RESTORE requested",{targetSession:v.slice(-12),currentSession:w==null?void 0:w.slice(-12)}),v===w)return ot("RESTORE skipped - already on this session"),void t(!1);const x=(P=>{var C;return((C=tn()[P])===null||C===void 0?void 0:C.messages)||[]})(v).filter(P=>{var C;return(C=P.content)===null||C===void 0?void 0:C.trim()});ot("Stored messages from our localStorage",{count:x.length,ids:x.map(P=>P.id.slice(-8))});const m=x.map(P=>({id:P.id,content:P.content,sender:P.sender.toUpperCase(),type:P.type||"string",timestamp:new Date(P.timestamp).toISOString()}));var k;u(v),ot("Session ID updated",{newSession:v.slice(-12)}),c(m),ot("replaceMessages called",{count:m.length}),k=(h=l.current)===null||h===void 0?void 0:h.getRootNode(),setTimeout(()=>{const P=(k||document).querySelector(".rcb-chat-body-container");P&&P.querySelectorAll(".rcb-bot-message").forEach(C=>{var S;let I=C.innerHTML,Q=!1;I.includes("](")&&(I=I.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),Q=!0),I.includes("<a href=")&&(I=I.replace(/<a\s+href=["']([^"']+)["'][^&]*>([^&]+)<\/a>/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),Q=!0),(I.includes("<a ")||!((S=C.textContent)===null||S===void 0)&&S.includes("<a href="))&&(C.textContent||"").includes("<a href=")&&(I=I.replace(/<a\s+href="([^"]+)"[^&]*>([^&]+)<\/a>/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),Q=!0),Q&&(C.innerHTML=I)})},50),d(!1),ot("Chat input enabled after restore"),t(!1)};return f.createElement("div",{style:{position:"relative"}},f.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(n((()=>{const v=tn();return Object.entries(v).map(h=>{let[w,x]=h;return Object.assign({sessionId:w},x)}).sort((h,w)=>new Date(w.startedAt).getTime()-new Date(h.startedAt).getTime())})()),l.current)){const v=l.current.closest(".rcb-chat-window");if(v){const h=v.getBoundingClientRect(),w=l.current.getBoundingClientRect();i(h.width+3),s(h.right-w.right-18+4)}}t(!e)},style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"18px",display:"flex",border:"none",cursor:"pointer",padding:0},"aria-label":"View chat history",title:"View chat history","aria-expanded":e,"aria-haspopup":"menu"},f.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},f.createElement("circle",{cx:"12",cy:"12",r:"10"}),f.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&f.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:A?"-".concat(A,"px"):"-18px",top:"100%",marginTop:"8px",width:o?"".concat(o,"px"):"550px",backgroundColor:"white",borderRadius:0,borderBottom:"3px solid var(--primaryColor, #1a5b6e)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",maxHeight:"250px",overflowY:"auto",zIndex:1e3}},r.length===0?f.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):r.map(v=>f.createElement("button",{key:v.sessionId,role:"menuitem",onClick:()=>g(v.sessionId),style:{width:"100%",padding:"10px 14px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",borderBottom:"1px solid #eee"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent"}},f.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},v.preview||"New conversation"),f.createElement("span",{style:{fontSize:"12px",color:"#888"}},(h=>{const w=new Date(h),x=new Date().getTime()-w.getTime(),m=Math.floor(x/864e5);return m===0?w.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):m===1?"Yesterday":m<7?w.toLocaleDateString([],{weekday:"short"}):w.toLocaleDateString([],{month:"short",day:"numeric"})})(v.startedAt))))))};function Qr(){return Qr=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Qr.apply(null,arguments)}const na=({width:e=24,height:t=24,color:r="currentColor",children:n,...o})=>f.createElement("svg",Qr({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),n),sc=e=>f.createElement(na,e,f.createElement("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})),Ac=()=>{const{restartFlow:e}=gn(),{setTextAreaValue:t}=xo(),{messages:r}=Wt(),{getSessionId:n,resetSession:o,clearResettingFlag:i}=Tr(),{trackEvent:A}=Ki();return f.createElement("button",{onClick:async()=>{const s=n(),a=s?ea(s):0;A({type:"chatbot_new_chat",previousMessageCount:a}),o(),await t(""),await e(),setTimeout(()=>{i()},100)},tabIndex:0,"aria-label":"New chat conversation",style:{backgroundColor:"var(--primaryColor, #107180)",border:"none",color:"#ffffff",fontSize:"14px",cursor:"pointer",padding:"8px 12px",borderRadius:"4px",transition:"all 0.2s ease",display:"flex",alignItems:"center",gap:"6px",fontWeight:"500"},onMouseEnter:s=>{s.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:s=>{s.target.style.backgroundColor="var(--primaryColor, #107180)"}},f.createElement(sc,{width:16,height:16}),"New Chat")};function Mr(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(Mr).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return Mr(t.children)}return""}const lc=()=>{const{getSessionId:e}=Tr(),t=f.useCallback(r=>{var n;const o=(n=r.data)===null||n===void 0?void 0:n.message;if(!(o!=null&&o.id))return;const i=o.sender,A=o.type||"string";let s;if(s=typeof o.content=="string"?o.content:Mr(o.content),nc("TRACKED",{id:o.id,sender:i,content:s.substring(0,50)+(s.length>50?"...":"")}),s.includes("rcb-options-container")||!s.trim())return;const a=e();rc(a,o.id,s,i,A)},[e]);return f.useEffect(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},cc=()=>(f.useEffect(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const A=document.activeElement;if(A&&(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.contentEditable==="true"||A.classList.contains("rcb-chat-input-textarea")))return;const s=document.querySelector(".rcb-chat-window");if(!s)return;const a=Array.from(s.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(d=>d.offsetParent!==null);if(a.length>0){const d=a[a.length-1].querySelector(".rcb-checkbox-container");if(d&&d.offsetParent!==null){const u=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")),p=d.querySelector(".rcb-checkbox-next-button");if(u.length>0){const g=[...u];return p&&g.push(p),void((v,h)=>{v.preventDefault();let w=-1;for(let m=0;m<h.length;m++)if(h[m]===document.activeElement||h[m].contains(document.activeElement)){w=m;break}w===-1&&(w=0);let x=w;switch(v.key){case"ArrowDown":case"ArrowRight":x=w<h.length-1?w+1:0;break;case"ArrowUp":case"ArrowLeft":x=w>0?w-1:h.length-1;break;case"Home":x=0;break;case"End":x=h.length-1;break;case"Enter":case" ":{const m=h[w],k=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void m.dispatchEvent(k)}default:return}h[x].focus(),h[x].setAttribute("tabindex","0"),h[x].classList.add("keyboard-focused"),h.forEach((m,k)=>{k!==x&&(m.setAttribute("tabindex","-1"),m.classList.remove("keyboard-focused"))})})(i,g)}}}let l=[];if(a.length>0){const d=a[a.length-1],u=Array.from(d.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(u.length>0){const p=u[u.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(d=>d===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let d;i.preventDefault(),d=c<l.length-1?c+1:0,l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus();break}case"ArrowUp":case"ArrowLeft":{let d;i.preventDefault(),d=c>0?c-1:l.length-1,l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const d=document.activeElement;if(d.classList.contains("rcb-checkbox-row-container")||d.closest(".rcb-checkbox-row-container")){const u=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});d.dispatchEvent(u);const p=d.querySelector(".rcb-checkbox-label"),g=p?p.textContent:d.textContent||"checkbox",v=d.querySelector(".rcb-checkbox-mark"),h=v&&v.style.backgroundColor?"checked":"unchecked";t(`${g} ${h}`)}else{const u=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});d.dispatchEvent(u);const p=d.textContent||d.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((d,u)=>{u!==0&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const d=l.length-1;l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus()}}},t=i=>{const A=document.createElement("div");A.setAttribute("aria-live","assertive"),A.setAttribute("aria-atomic","true"),A.className="sr-only",A.textContent=i,document.body.appendChild(A),setTimeout(()=>{document.body.contains(A)&&document.body.removeChild(A)},1e3)},r=(i=null)=>{let A=i;if(A||(A=document.querySelector(".rcb-chat-window"),A||(A=document.querySelector('[class*="rcb-chat"]')),A||(A=document.querySelector(".qa-bot"))),!A)return;const s=A.closest(".embedded-qa-bot")!==null,a=Array.from(A.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(u=>u.offsetParent!==null);if(a.length===0)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(u=>u.offsetParent!==null);let d=[];if(c.length>0){const u=c[c.length-1];d=Array.from(u.querySelectorAll(".rcb-options"))}if(d.length===0){let u=l.querySelector(".rcb-checkbox-container");if(!u&&A&&(u=A.querySelector(".rcb-checkbox-container")),u&&u.offsetParent!==null){const p=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")).filter(g=>g.offsetParent!==null&&g.style.display!=="none");if(p.length>0){const g=u.querySelector(".rcb-checkbox-next-button"),v=[...p];if(g&&g.offsetParent!==null&&v.push(g),v.forEach((h,w)=>{h.setAttribute("tabindex",w===0?"0":"-1"),w===0?h.classList.add("keyboard-focused"):h.classList.remove("keyboard-focused")}),p.length>1){u.querySelectorAll(".keyboard-nav-hint").forEach(w=>w.remove());const h=document.createElement("div");h.className="keyboard-nav-hint",h.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",h.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",u.insertBefore(h,u.firstChild)}return void setTimeout(()=>{v[0]&&v[0].offsetParent!==null&&!s&&v[0].focus()},150)}}}if(d.length>0){if(d.forEach((u,p)=>{const g=p===0?"0":"-1";u.setAttribute("tabindex",g),u.setAttribute("role","option"),u.setAttribute("aria-posinset",p+1),u.setAttribute("aria-setsize",d.length),p===0?u.classList.add("keyboard-focused"):u.classList.remove("keyboard-focused")}),d.length>1){const u=c.length>0?c[c.length-1]:null;if(u){u.querySelectorAll(".keyboard-nav-hint").forEach(g=>g.remove());const p=document.createElement("div");p.className="keyboard-nav-hint",p.textContent="Use arrow keys ↕ to navigate, Enter to select, or click any option",p.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",u.insertBefore(p,u.firstChild)}}else{const u=c.length>0?c[c.length-1]:null;u&&u.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{d[0]&&d[0].offsetParent!==null&&!s&&(d[0].focus(),d.length>1&&t(`${d.length} options available. Use arrow keys to navigate.`))},200)}},n=new MutationObserver(i=>{i.forEach(A=>{var s,a;if(A.type==="childList"){const l=Array.from(A.addedNodes),c=l.some(u=>{var p,g,v,h;return u.nodeType===Node.ELEMENT_NODE&&(((p=u.classList)==null?void 0:p.contains("rcb-options-container"))||((g=u.classList)==null?void 0:g.contains("rcb-options"))||((v=u.querySelector)==null?void 0:v.call(u,".rcb-options-container"))||((h=u.querySelector)==null?void 0:h.call(u,".rcb-options")))}),d=l.some(u=>{var p,g;return u.nodeType===Node.ELEMENT_NODE&&(((p=u.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((g=u.querySelector)==null?void 0:g.call(u,".rcb-checkbox-container")))});if(c||d){let u=A.target;for(;u&&!((s=u.classList)!=null&&s.contains("qa-bot"))&&!((a=u.classList)!=null&&a.contains("rcb-chat-window"));)u=u.parentElement;(u||document).querySelectorAll(".rcb-options[tabindex], .rcb-checkbox-row-container[tabindex], .rcb-checkbox-next-button[tabindex]").forEach(p=>{p.setAttribute("tabindex","-1"),p.classList.remove("keyboard-focused")}),setTimeout(()=>r(u),100)}}})});n.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),r();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const A=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,s=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(A){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&r(i)}if(s){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&r(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),n.disconnect(),clearInterval(o)}},[]),null);let ra=!1,Dn=null;function oa(){return ra?Promise.resolve():Dn||(Dn=new Promise((e,t)=>{const r=document.createElement("script");r.src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",r.async=!0,r.onload=()=>{ra=!0,Bn("Script loaded"),e()},r.onerror=()=>{Dn=null,t(new Error("Failed to load Turnstile script"))},document.head.appendChild(r)}),Dn)}const nn=e=>{if(!e||typeof e!="string")return e;let t=e.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return t=t.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),r=>{let n=r,o="";const i=n.match(/([.,;:!?]+)$/);return i&&(o=i[1],n=n.slice(0,-o.length)),"[".concat(n,"](").concat(n,")").concat(o)}),t},uc=e=>{let{siteKey:t,onVerify:r,onError:n}=e;const o=f.useRef(null),i=f.useRef(!1);return f.useEffect(()=>{!i.current&&o.current&&(i.current=!0,oa().then(()=>{const A=window.turnstile;if(!A||!o.current)return De("Turnstile API not available after script load"),void(n==null||n());A.render(o.current,{sitekey:t,callback:s=>{Bn("Visible challenge completed"),r(s)},"error-callback":()=>{De("Turnstile challenge failed"),n==null||n()},"expired-callback":()=>{De("Turnstile token expired"),n==null||n()}})}).catch(A=>{De("Failed to load Turnstile script:",A),n==null||n()}))},[t,r,n]),f.createElement("div",{style:{padding:"8px 16px"}},f.createElement("div",{ref:o,style:{borderRadius:"8px",overflow:"hidden"}}))};function ia(e){const{confidence:t,tools_used:r,metadata:n}=e;if(!(t||r&&r.length!==0))return"";const o=[];return t&&o.push("• Confidence: ".concat(t)),r&&r.length>0&&o.push("• Tools used: ".concat(r.join(", "))),n!=null&&n.agent&&o.push("• Agent: ".concat(n.agent)),`---
|
|
38
|
+
`),f.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(r),style:Object.assign(Object.assign({},A),n),onClick:()=>{i({type:"chatbot_login_clicked",loginUrl:t})}},"Log In"))},Wl=()=>f.createElement("div",{className:"user-login-icon",style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"5px",display:"flex"},role:"img","aria-label":"User logged in",title:"User logged in"},f.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},f.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),f.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Be=[];for(let e=0;e<256;++e)Be.push((e+256).toString(16).slice(1));let Dr;const Kl=new Uint8Array(16);var Xi={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ji(e,t,r){var o;if(Xi.randomUUID&&!e)return Xi.randomUUID();const n=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!Dr){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Dr=crypto.getRandomValues.bind(crypto)}return Dr(Kl)}();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=15&n[6]|64,n[8]=63&n[8]|128,function(i,A=0){return(Be[i[A+0]]+Be[i[A+1]]+Be[i[A+2]]+Be[i[A+3]]+"-"+Be[i[A+4]]+Be[i[A+5]]+"-"+Be[i[A+6]]+Be[i[A+7]]+"-"+Be[i[A+8]]+Be[i[A+9]]+"-"+Be[i[A+10]]+Be[i[A+11]]+Be[i[A+12]]+Be[i[A+13]]+Be[i[A+14]]+Be[i[A+15]]).toLowerCase()}(n)}function Pt(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Vl="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",Xl="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",Jl="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",Zl="background: #f97316; color: white; padding: 2px 6px; border-radius: 3px;",$l="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",ec="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",tc=()=>{Pt()&&console.log("%c QA Bot Core %c v".concat("0.2.32"," "),$l,ec)},Sn=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[Session]%c ".concat(e),Vl,"",...r)}},ot=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[History]%c ".concat(e),Xl,"",...r)}},nc=(e,t)=>{Pt()&&console.log("%c[Message]%c ".concat(e),Jl,"",t)},Bn=function(e){if(Pt()){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log("%c[Turnstile]%c ".concat(e),Zl,"",...r)}},Ir=function(){console.warn(...arguments)},De=function(){console.error(...arguments)},Zi="qa_bot_session_messages",$i=()=>"qa_bot_session_".concat(Ji()),tn=()=>{try{const e=localStorage.getItem(Zi);return e?JSON.parse(e):{}}catch{return{}}},rc=(e,t,r,n,o)=>{const i=tn();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},ot("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void ot("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:n});const A={id:t,content:r,sender:n,type:o,timestamp:Date.now()};i[e].messages.push(A),ot("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:n,totalInSession:i[e].messages.length});const s=i[e].messages,a=s.find(l=>{var c;return l.sender.toLowerCase()==="bot"&&((c=l.content)===null||c===void 0?void 0:c.trim())&&l.content.length>=100});if(a){const l=a.content;i[e].preview=l.slice(0,50)+(l.length>50?"...":"")}else{const l=s.find(c=>{var d;return c.sender.toLowerCase()==="user"&&((d=c.content)===null||d===void 0?void 0:d.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const d=()=>Object.values(l).reduce((u,p)=>u+p.messages.length,0);for(;d()>100&&Object.keys(l).length>1;){const u=(c=Object.entries(l).sort((p,g)=>{let[,v]=p,[,h]=g;return new Date(v.startedAt).getTime()-new Date(h.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!u)break;delete l[u]}localStorage.setItem(Zi,JSON.stringify(l))})(i),ot("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},ea=e=>{var t,r;return(r=(t=tn()[e])===null||t===void 0?void 0:t.messages.length)!==null&&r!==void 0?r:0},oc=e=>{const t=tn()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},ta=f.createContext(void 0),ic=e=>{let{children:t,getSessionId:r,setSessionId:n,resetSession:o,clearResettingFlag:i}=e;return f.createElement(ta.Provider,{value:{getSessionId:r,setSessionId:n,resetSession:o,clearResettingFlag:i}},t)},Tr=()=>{const e=f.useContext(ta);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},ac=()=>{const[e,t]=f.useState(!1),[r,n]=f.useState([]),[o,i]=f.useState(null),[A,s]=f.useState(0),a=f.useRef(null),l=f.useRef(null),{replaceMessages:c}=Wt(),{toggleTextAreaDisabled:d}=xo(),{setSessionId:u,getSessionId:p}=Tr();f.useEffect(()=>{var v,h;const w=m=>{a.current&&!a.current.contains(m.target)&&l.current&&!l.current.contains(m.target)&&t(!1)},x=(h=(v=a.current)===null||v===void 0?void 0:v.getRootNode())!==null&&h!==void 0?h:document;return e&&x.addEventListener("mousedown",w),()=>{x.removeEventListener("mousedown",w)}},[e]);const g=v=>{var h;const w=p();if(ot("RESTORE requested",{targetSession:v.slice(-12),currentSession:w==null?void 0:w.slice(-12)}),v===w)return ot("RESTORE skipped - already on this session"),void t(!1);const x=(P=>{var C;return((C=tn()[P])===null||C===void 0?void 0:C.messages)||[]})(v).filter(P=>{var C;return(C=P.content)===null||C===void 0?void 0:C.trim()});ot("Stored messages from our localStorage",{count:x.length,ids:x.map(P=>P.id.slice(-8))});const m=x.map(P=>({id:P.id,content:P.content,sender:P.sender.toUpperCase(),type:P.type||"string",timestamp:new Date(P.timestamp).toISOString()}));var k;u(v),ot("Session ID updated",{newSession:v.slice(-12)}),c(m),ot("replaceMessages called",{count:m.length}),k=(h=l.current)===null||h===void 0?void 0:h.getRootNode(),setTimeout(()=>{const P=(k||document).querySelector(".rcb-chat-body-container");P&&P.querySelectorAll(".rcb-bot-message").forEach(C=>{var S;let I=C.innerHTML,Q=!1;I.includes("](")&&(I=I.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),Q=!0),I.includes("<a href=")&&(I=I.replace(/<a\s+href=["']([^"']+)["'][^&]*>([^&]+)<\/a>/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),Q=!0),(I.includes("<a ")||!((S=C.textContent)===null||S===void 0)&&S.includes("<a href="))&&(C.textContent||"").includes("<a href=")&&(I=I.replace(/<a\s+href="([^"]+)"[^&]*>([^&]+)<\/a>/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),Q=!0),Q&&(C.innerHTML=I)})},50),d(!1),ot("Chat input enabled after restore"),t(!1)};return f.createElement("div",{style:{position:"relative"}},f.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(n((()=>{const v=tn();return Object.entries(v).map(h=>{let[w,x]=h;return Object.assign({sessionId:w},x)}).sort((h,w)=>new Date(w.startedAt).getTime()-new Date(h.startedAt).getTime())})()),l.current)){const v=l.current.closest(".rcb-chat-window");if(v){const h=v.getBoundingClientRect(),w=l.current.getBoundingClientRect();i(h.width+3),s(h.right-w.right-18+4)}}t(!e)},style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"18px",display:"flex",border:"none",cursor:"pointer",padding:0},"aria-label":"View chat history",title:"View chat history","aria-expanded":e,"aria-haspopup":"menu"},f.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},f.createElement("circle",{cx:"12",cy:"12",r:"10"}),f.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&f.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:A?"-".concat(A,"px"):"-18px",top:"100%",marginTop:"8px",width:o?"".concat(o,"px"):"550px",backgroundColor:"white",borderRadius:0,borderBottom:"3px solid var(--primaryColor, #1a5b6e)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",maxHeight:"250px",overflowY:"auto",zIndex:1e3}},r.length===0?f.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):r.map(v=>f.createElement("button",{key:v.sessionId,role:"menuitem",onClick:()=>g(v.sessionId),style:{width:"100%",padding:"10px 14px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",borderBottom:"1px solid #eee"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent"}},f.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},v.preview||"New conversation"),f.createElement("span",{style:{fontSize:"12px",color:"#888"}},(h=>{const w=new Date(h),x=new Date().getTime()-w.getTime(),m=Math.floor(x/864e5);return m===0?w.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):m===1?"Yesterday":m<7?w.toLocaleDateString([],{weekday:"short"}):w.toLocaleDateString([],{month:"short",day:"numeric"})})(v.startedAt))))))};function Qr(){return Qr=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Qr.apply(null,arguments)}const na=({width:e=24,height:t=24,color:r="currentColor",children:n,...o})=>f.createElement("svg",Qr({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),n),sc=e=>f.createElement(na,e,f.createElement("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})),Ac=()=>{const{restartFlow:e}=gn(),{setTextAreaValue:t}=xo(),{messages:r}=Wt(),{getSessionId:n,resetSession:o,clearResettingFlag:i}=Tr(),{trackEvent:A}=Ki();return f.createElement("button",{onClick:async()=>{const s=n(),a=s?ea(s):0;A({type:"chatbot_new_chat",previousMessageCount:a}),o(),await t(""),await e(),setTimeout(()=>{i()},100)},tabIndex:0,"aria-label":"New chat conversation",style:{backgroundColor:"var(--primaryColor, #107180)",border:"none",color:"#ffffff",fontSize:"14px",cursor:"pointer",padding:"8px 12px",borderRadius:"4px",transition:"all 0.2s ease",display:"flex",alignItems:"center",gap:"6px",fontWeight:"500"},onMouseEnter:s=>{s.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:s=>{s.target.style.backgroundColor="var(--primaryColor, #107180)"}},f.createElement(sc,{width:16,height:16}),"New Chat")};function Mr(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(Mr).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return Mr(t.children)}return""}const lc=()=>{const{getSessionId:e}=Tr(),t=f.useCallback(r=>{var n;const o=(n=r.data)===null||n===void 0?void 0:n.message;if(!(o!=null&&o.id))return;const i=o.sender,A=o.type||"string";let s;if(s=typeof o.content=="string"?o.content:Mr(o.content),nc("TRACKED",{id:o.id,sender:i,content:s.substring(0,50)+(s.length>50?"...":"")}),s.includes("rcb-options-container")||!s.trim())return;const a=e();rc(a,o.id,s,i,A)},[e]);return f.useEffect(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},cc=()=>(f.useEffect(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const A=document.activeElement;if(A&&(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.contentEditable==="true"||A.classList.contains("rcb-chat-input-textarea")))return;const s=document.querySelector(".rcb-chat-window");if(!s)return;const a=Array.from(s.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(d=>d.offsetParent!==null);if(a.length>0){const d=a[a.length-1].querySelector(".rcb-checkbox-container");if(d&&d.offsetParent!==null){const u=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")),p=d.querySelector(".rcb-checkbox-next-button");if(u.length>0){const g=[...u];return p&&g.push(p),void((v,h)=>{v.preventDefault();let w=-1;for(let m=0;m<h.length;m++)if(h[m]===document.activeElement||h[m].contains(document.activeElement)){w=m;break}w===-1&&(w=0);let x=w;switch(v.key){case"ArrowDown":case"ArrowRight":x=w<h.length-1?w+1:0;break;case"ArrowUp":case"ArrowLeft":x=w>0?w-1:h.length-1;break;case"Home":x=0;break;case"End":x=h.length-1;break;case"Enter":case" ":{const m=h[w],k=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void m.dispatchEvent(k)}default:return}h[x].focus(),h[x].setAttribute("tabindex","0"),h[x].classList.add("keyboard-focused"),h.forEach((m,k)=>{k!==x&&(m.setAttribute("tabindex","-1"),m.classList.remove("keyboard-focused"))})})(i,g)}}}let l=[];if(a.length>0){const d=a[a.length-1],u=Array.from(d.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(u.length>0){const p=u[u.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(d=>d===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let d;i.preventDefault(),d=c<l.length-1?c+1:0,l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus();break}case"ArrowUp":case"ArrowLeft":{let d;i.preventDefault(),d=c>0?c-1:l.length-1,l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const d=document.activeElement;if(d.classList.contains("rcb-checkbox-row-container")||d.closest(".rcb-checkbox-row-container")){const u=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});d.dispatchEvent(u);const p=d.querySelector(".rcb-checkbox-label"),g=p?p.textContent:d.textContent||"checkbox",v=d.querySelector(".rcb-checkbox-mark"),h=v&&v.style.backgroundColor?"checked":"unchecked";t(`${g} ${h}`)}else{const u=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});d.dispatchEvent(u);const p=d.textContent||d.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((d,u)=>{u!==0&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const d=l.length-1;l[d].setAttribute("tabindex","0"),l.forEach((u,p)=>{p!==d&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[d].classList.add("keyboard-focused"),l[d].focus()}}},t=i=>{const A=document.createElement("div");A.setAttribute("aria-live","assertive"),A.setAttribute("aria-atomic","true"),A.className="sr-only",A.textContent=i,document.body.appendChild(A),setTimeout(()=>{document.body.contains(A)&&document.body.removeChild(A)},1e3)},r=(i=null)=>{let A=i;if(A||(A=document.querySelector(".rcb-chat-window"),A||(A=document.querySelector('[class*="rcb-chat"]')),A||(A=document.querySelector(".qa-bot"))),!A)return;const s=A.closest(".embedded-qa-bot")!==null,a=Array.from(A.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(u=>u.offsetParent!==null);if(a.length===0)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(u=>u.offsetParent!==null);let d=[];if(c.length>0){const u=c[c.length-1];d=Array.from(u.querySelectorAll(".rcb-options"))}if(d.length===0){let u=l.querySelector(".rcb-checkbox-container");if(!u&&A&&(u=A.querySelector(".rcb-checkbox-container")),u&&u.offsetParent!==null){const p=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")).filter(g=>g.offsetParent!==null&&g.style.display!=="none");if(p.length>0){const g=u.querySelector(".rcb-checkbox-next-button"),v=[...p];if(g&&g.offsetParent!==null&&v.push(g),v.forEach((h,w)=>{h.setAttribute("tabindex",w===0?"0":"-1"),w===0?h.classList.add("keyboard-focused"):h.classList.remove("keyboard-focused")}),p.length>1){u.querySelectorAll(".keyboard-nav-hint").forEach(w=>w.remove());const h=document.createElement("div");h.className="keyboard-nav-hint",h.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",h.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",u.insertBefore(h,u.firstChild)}return void setTimeout(()=>{v[0]&&v[0].offsetParent!==null&&!s&&v[0].focus()},150)}}}if(d.length>0){if(d.forEach((u,p)=>{const g=p===0?"0":"-1";u.setAttribute("tabindex",g),u.setAttribute("role","option"),u.setAttribute("aria-posinset",p+1),u.setAttribute("aria-setsize",d.length),p===0?u.classList.add("keyboard-focused"):u.classList.remove("keyboard-focused")}),d.length>1){const u=c.length>0?c[c.length-1]:null;if(u){u.querySelectorAll(".keyboard-nav-hint").forEach(g=>g.remove());const p=document.createElement("div");p.className="keyboard-nav-hint",p.textContent="Use arrow keys ↕ to navigate, Enter to select, or click any option",p.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",u.insertBefore(p,u.firstChild)}}else{const u=c.length>0?c[c.length-1]:null;u&&u.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{d[0]&&d[0].offsetParent!==null&&!s&&(d[0].focus(),d.length>1&&t(`${d.length} options available. Use arrow keys to navigate.`))},200)}},n=new MutationObserver(i=>{i.forEach(A=>{var s,a;if(A.type==="childList"){const l=Array.from(A.addedNodes),c=l.some(u=>{var p,g,v,h;return u.nodeType===Node.ELEMENT_NODE&&(((p=u.classList)==null?void 0:p.contains("rcb-options-container"))||((g=u.classList)==null?void 0:g.contains("rcb-options"))||((v=u.querySelector)==null?void 0:v.call(u,".rcb-options-container"))||((h=u.querySelector)==null?void 0:h.call(u,".rcb-options")))}),d=l.some(u=>{var p,g;return u.nodeType===Node.ELEMENT_NODE&&(((p=u.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((g=u.querySelector)==null?void 0:g.call(u,".rcb-checkbox-container")))});if(c||d){let u=A.target;for(;u&&!((s=u.classList)!=null&&s.contains("qa-bot"))&&!((a=u.classList)!=null&&a.contains("rcb-chat-window"));)u=u.parentElement;(u||document).querySelectorAll(".rcb-options[tabindex], .rcb-checkbox-row-container[tabindex], .rcb-checkbox-next-button[tabindex]").forEach(p=>{p.setAttribute("tabindex","-1"),p.classList.remove("keyboard-focused")}),setTimeout(()=>r(u),100)}}})});n.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),r();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const A=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,s=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(A){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&r(i)}if(s){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&r(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),n.disconnect(),clearInterval(o)}},[]),null);let ra=!1,Dn=null;function oa(){return ra?Promise.resolve():Dn||(Dn=new Promise((e,t)=>{const r=document.createElement("script");r.src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",r.async=!0,r.onload=()=>{ra=!0,Bn("Script loaded"),e()},r.onerror=()=>{Dn=null,t(new Error("Failed to load Turnstile script"))},document.head.appendChild(r)}),Dn)}const nn=e=>{if(!e||typeof e!="string")return e;let t=e.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return t=t.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),r=>{let n=r,o="";const i=n.match(/([.,;:!?]+)$/);return i&&(o=i[1],n=n.slice(0,-o.length)),"[".concat(n,"](").concat(n,")").concat(o)}),t},uc=e=>{let{siteKey:t,onVerify:r,onError:n}=e;const o=f.useRef(null),i=f.useRef(!1);return f.useEffect(()=>{!i.current&&o.current&&(i.current=!0,oa().then(()=>{const A=window.turnstile;if(!A||!o.current)return De("Turnstile API not available after script load"),void(n==null||n());A.render(o.current,{sitekey:t,callback:s=>{Bn("Visible challenge completed"),r(s)},"error-callback":()=>{De("Turnstile challenge failed"),n==null||n()},"expired-callback":()=>{De("Turnstile token expired"),n==null||n()}})}).catch(A=>{De("Failed to load Turnstile script:",A),n==null||n()}))},[t,r,n]),f.createElement("div",{style:{padding:"8px 16px"}},f.createElement("div",{ref:o,style:{borderRadius:"8px",overflow:"hidden"}}))};function ia(e){const{confidence:t,tools_used:r,metadata:n}=e;if(!(t||r&&r.length!==0))return"";const o=[];return t&&o.push("• Confidence: ".concat(t)),r&&r.length>0&&o.push("• Tools used: ".concat(r.join(", "))),n!=null&&n.agent&&o.push("• Agent: ".concat(n.agent)),`---
|
|
39
39
|
`.concat(o.join(`
|
|
40
40
|
`))}function dc(e){let{getState:t,onResubmit:r,trackEvent:n,loginUrl:o}=e;const[i,A]=f.useState(!1),s=t();return f.useEffect(()=>{if(!s.siteKey)return;A(!1);const a=setTimeout(()=>{s.token||(A(!0),n==null||n({type:"chatbot_turnstile_error"}))},5e3);return()=>clearTimeout(a)},[s.siteKey]),s.siteKey?i?f.createElement("div",{style:{padding:"8px 16px",fontSize:"14px",lineHeight:"1.5"}},f.createElement("p",{style:{margin:0}},"I'm having trouble verifying your session. Please try"," ",f.createElement("a",{href:"",onClick:a=>{a.preventDefault(),window.location.reload()},style:{color:"var(--primaryColor, #107180)"}},"refreshing the page"),", or"," ",f.createElement("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primaryColor, #107180)",fontWeight:"bold"}},"log in")," ","to continue.")):f.createElement(uc,{siteKey:s.siteKey,onVerify:a=>{s.token=a,n==null||n({type:"chatbot_turnstile_completed"}),r(a)},onError:()=>{Ir("Turnstile widget error (may auto-recover)")}}):null}const pc="#1a5b6e",fc="#107180",hc="Arial, sans-serif",aa="Q&A Bot",gc="/chat-icon.svg",mc="Type your question here...",yc="Select an option to continue",bc=!1,vc="Ask me a question!",sa="/login",wc={general:{showHeader:!0,showFooter:!0},tooltip:{mode:"CLOSE"},chatInput:{disabled:!1,characterLimit:5e3,showCharacterCount:!1,allowNewline:!0,blockSpam:!1},chatWindow:{defaultOpen:!1,showScrollbar:!1},botBubble:{simulateStream:!0,streamSpeed:10,showAvatar:!1},userBubble:{showAvatar:!1},notification:{disabled:!0,showCount:!1},audio:{disabled:!0},emoji:{disabled:!0},fileAttachment:{disabled:!0}},Or=f.forwardRef((e,t)=>{var r,n,o;const{apiKey:i,qaEndpoint:A,ratingEndpoint:s,capabilitiesEndpoint:a,agentRatingEndpoint:l,welcomeMessage:c,open:d,onOpenChange:u,isLoggedIn:p,allowAnonAccess:g=!1,actingUser:v,primaryColor:h,secondaryColor:w,botName:x,logo:m,placeholder:k,errorMessage:P,embedded:C,footerText:S,footerLink:I,tooltipText:Q,loginUrl:D,turnstileSiteKey:_,resourceContext:B,customFlow:M,onAnalyticsEvent:F}=e,N=f.useRef("bot_".concat(Math.random().toString(36).substr(2,9)));f.useEffect(()=>{tc()},[]);const L=f.useRef(null);L.current===null&&(L.current=$i(),Sn("CREATED",L.current));const O=f.useRef(!1),U=f.useRef({getSessionId:()=>L.current,isResetting:()=>O.current}),b=function(j){const[Y,oe]=f.useState(null),[ne,ie]=f.useState("idle"),ce=f.useRef(null),Ae=f.useRef(null),Qe=f.useRef(!0),Le=f.useCallback(()=>{const Se=window.turnstile;if(Ae.current&&(Se!=null&&Se.remove)){try{Se.remove(Ae.current)}catch{}Ae.current=null}ce.current&&(ce.current.remove(),ce.current=null)},[]);return f.useEffect(()=>{if(Qe.current=!0,!j)return ie("idle"),void oe(null);ie("loading");const Se=document.createElement("div");return Se.style.position="fixed",Se.style.left="-9999px",Se.style.top="-9999px",Se.style.width="0",Se.style.height="0",Se.style.overflow="hidden",Se.setAttribute("aria-hidden","true"),document.body.appendChild(Se),ce.current=Se,oa().then(()=>{if(!Qe.current)return;const it=window.turnstile;if(!it||!ce.current)return De("Turnstile API not available for silent verification"),void ie("failed");const Ht=it.render(ce.current,{sitekey:j,execution:"render","refresh-expired":"auto",callback:me=>{Qe.current&&(Bn("Silent verification succeeded"),oe(me),ie("verified"))},"error-callback":()=>{Qe.current&&(De("Turnstile silent verification failed"),ie("failed"))},"expired-callback":()=>{Qe.current&&(Bn("Token expired, awaiting refresh"),oe(null),ie("loading"))}});Ae.current=Ht}).catch(it=>{Qe.current&&(De("Failed to load Turnstile script for silent verification:",it),ie("failed"))}),()=>{Qe.current=!1,Le()}},[j,Le]),{token:Y,status:ne}}(_),z=f.useRef(null);z.current=b.token;const[y,G]=f.useState(p);f.useEffect(()=>{G(p)},[p]);const Z=C!==void 0?C:bc,K=f.useCallback(j=>{var Y;F&&F(Object.assign(Object.assign({},j),{timestamp:Date.now(),sessionId:(Y=L.current)!==null&&Y!==void 0?Y:void 0,pageUrl:typeof window<"u"?window.location.href:void 0,isEmbedded:Z}))},[F,Z]),re=f.useMemo(()=>{const j=Object.assign({},wc);j.general=Object.assign(Object.assign({},j.general),{primaryColor:h||pc,secondaryColor:w||fc,fontFamily:hc,embedded:Z});const Y=y===!1?[f.createElement(Vi,{key:"login-button",loginUrl:D||sa,isHeaderButton:!0})]:[f.createElement(ac,{key:"history-button"}),f.createElement(Wl,{key:"user-icon"})];j.header={title:f.createElement("span",{style:{fontSize:14,fontWeight:500}},x||aa),showAvatar:!0,avatar:m||gc,buttons:[...Y,ye.CLOSE_CHAT_BUTTON]},j.chatInput=Object.assign(Object.assign({},j.chatInput),{disabled:!1,enabledPlaceholderText:k||mc,disabledPlaceholderText:P||yc}),j.tooltip=Object.assign(Object.assign({},j.tooltip),{text:Q||vc});const oe=S?I?f.createElement("a",{href:I,target:"_blank",rel:"noopener noreferrer",key:"footer-link"},S):f.createElement("span",{key:"footer-text"},S):null;return j.footer={text:oe,buttons:[f.createElement(Ac,{key:"new-chat-button"})]},j.chatWindow=Object.assign(Object.assign({},j.chatWindow),{defaultOpen:!!Z}),j.event={rcbPreInjectMessage:!0,rcbPostInjectMessage:!0,rcbUserSubmitText:!0,rcbChangePath:!0,rcbToggleChatWindow:!0},j},[h,w,x,m,k,P,Z,Q,y,D,S,I]),Pe=f.useRef(null),le=function(j){let Y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return f.useMemo(()=>{const oe=(ne,ie)=>{if(j.current){const ce=getComputedStyle(j.current).getPropertyValue(ne);if(ce&&ce.trim()!=="")return ce.trim();if(j.current.parentElement){const Ae=getComputedStyle(j.current.parentElement).getPropertyValue(ne);if(Ae&&Ae.trim()!=="")return Ae.trim()}}return ie};return{primaryColor:oe("--primaryColor",Y.primaryColor),secondaryColor:oe("--secondaryColor",Y.secondaryColor),fontFamily:oe("--fontFamily",Y.fontFamily)}},[j,Y])}(Pe,re.general);((j,Y)=>{f.useEffect(()=>{Y.current&&(j?Y.current.classList.add("bot-logged-in"):Y.current.classList.remove("bot-logged-in"))},[j,Y])})(y!==!1,Pe),(j=>{let{settings:Y,themeColors:oe}=j;f.useEffect(()=>{oe&&(Object.entries(oe).forEach(ne=>{let[ie,ce]=ne;ce&&document.documentElement.style.setProperty("--".concat(ie),ce)}),oe.primaryColor&&document.documentElement.style.setProperty("--rcb-header-background",oe.primaryColor),oe.secondaryColor&&document.documentElement.style.setProperty("--rcb-header-background-hover",oe.secondaryColor))},[oe]),f.useEffect(()=>{var ne,ie;!((ne=Y.header)===null||ne===void 0)&&ne.title&&typeof Y.header.title=="string"&&(Y.header.title=f.createElement("div",{key:"header-title"},f.createElement("h1",{className:"sr-only"},Y.header.title),f.createElement("span",{"aria-hidden":"true"},Y.header.title))),Y.device={desktopEnabled:!0,mobileEnabled:!0,applyMobileOptimizations:!1},Y.chatHistory={disabled:!0},Y.chatButton=Object.assign(Object.assign({},Y.chatButton),{icon:(ie=Y.header)===null||ie===void 0?void 0:ie.avatar}),Y.event=Object.assign(Object.assign({},Y.event),{rcbToggleChatWindow:!0})},[Y])})({settings:re,themeColors:le});const Ke=f.useMemo(()=>{const j=(oe=>{let{endpoint:ne,ratingEndpoint:ie,agentRatingEndpoint:ce,apiKey:Ae,sessionId:Qe,isResetting:Le=()=>!1,isLoggedIn:Se,allowAnonAccess:it=!1,loginUrl:Ht="/login",trackEvent:me,getTurnstileToken:an,resourceContext:Ut}=oe;if(Se===!1&&!it)return me==null||me({type:"chatbot_login_prompt_shown"}),{qa_loop:{message:"To ask questions, please log in first.",component:f.createElement(Vi,{loginUrl:Ht}),chatDisabled:!0,path:"qa_loop"}};let Ve=null,at=null,Bt=!1;const pe={siteKey:null,token:null,pendingQuery:null,needsChallenge:!1};let T=null;if(!ne)throw new Error("Q&A endpoint is required");return{qa_loop:{message:async R=>{var W;T=R.injectMessage.bind(R);const{userInput:te}=R;if(Le&&Le()||!te||te.trim()==="")return null;if(te==="👍 Helpful"||te==="👎 Not helpful"){if(Ve){const X=te==="👍 Helpful",he=at==="agent"?ce:ie;if(he)try{const be={"Content-Type":"application/json"};Ae&&(be["X-API-KEY"]=Ae);const fe=Qe();fe&&(be["X-Session-ID"]=fe,be["X-Query-ID"]=Ve),await fetch(he,{method:"POST",headers:be,credentials:"include",body:JSON.stringify(at==="agent"?{query_id:Ve,rating:X?"helpful":"not_helpful",session_id:fe}:{sessionId:fe,queryId:Ve,rating:X?1:0})}),me==null||me({type:"chatbot_rating_sent",queryId:Ve,rating:X?"helpful":"not_helpful"})}catch(be){De("Error sending feedback:",be)}}return"Thanks for the feedback!"}try{const X=Ji();Ve=X,me==null||me({type:"chatbot_question_sent",queryId:X,questionLength:te.length});const he={"Content-Type":"application/json"};Ae&&(he["X-API-KEY"]=Ae);const be=Qe();be&&(he["X-Session-ID"]=be,he["X-Query-ID"]=X);const fe={query:te,session_id:be,question_id:X};Ut&&(fe.resource_context=Ut);const qe=an==null?void 0:an();qe&&(fe.turnstile_token=qe),Sn("SENT to API",{session_id:be,question_id:X});const yt=Date.now(),ve=await fetch(ne,{method:"POST",headers:he,credentials:"include",body:JSON.stringify(fe)});if(!ve.ok)throw new Error("API returned ".concat(ve.status));if((ve.headers.get("content-type")||"").includes("text/event-stream")){const _n=(W=ve.body)===null||W===void 0?void 0:W.getReader();if(!_n)throw new Error("Response body is not readable");const zr=new TextDecoder;let st="",ut="",vt=!1;try{for(;;){const{done:wt,value:At}=await _n.read();if(wt)break;st+=zr.decode(At,{stream:!0});let Rt=st.indexOf(`
|
|
41
41
|
|
|
@@ -292,5 +292,5 @@ Would you like to submit this security incident report?`},options:["Submit Secur
|
|
|
292
292
|
display: inline !important;
|
|
293
293
|
margin: 0 !important;
|
|
294
294
|
}
|
|
295
|
-
`;function Kc(e){if(!e)return;const t=e.getRootNode();if(!(t instanceof ShadowRoot)||t.getElementById(ca))return;const r=document.createElement("style");r.id=ca,r.textContent=Wc,t.appendChild(r)}const Fr=f.forwardRef((e,t)=>{const{apiKey:r=je.DEFAULT_API_KEY,isLoggedIn:n=!1,loginUrl:o=mt.LOGIN_URL,userEmail:i,userName:A,accessId:s,actingUser:a,ringEffect:l,defaultOpen:c,onClose:d,open:u,onOpenChange:p,embedded:g=!1,welcome:v,qaEndpoint:h,ratingEndpoint:w,agentEndpoint:x,resourceContext:m,onAnalyticsEvent:k}=e,P=f.useRef(null),C=f.useRef(null),[S,I]=f.useState({}),[Q,D]=f.useState(null),_=f.useMemo(()=>({email:i,name:A,accessId:s}),[i,A,s]);f.useEffect(()=>{Kc(C.current)},[]),f.useEffect(()=>{Ic({ticketForm:S,setTicketForm:I})},[S]);const B=x||je.AGENT_ENDPOINT,M=m?`${B}/capabilities?resource_context=${encodeURIComponent(m)}`:`${B}/capabilities`,F=`${B}/rating`;f.useEffect(()=>{B.includes("localhost")&&!window.location.hostname.includes("localhost")&&console.warn("[AccessQABot] VITE_AGENT_ENDPOINT not set — agent requests will go to localhost. Set VITE_AGENT_ENDPOINT in your environment."),je.ALLOW_ANON_ACCESS&&!je.TURNSTILE_SITE_KEY&&console.warn("[AccessQABot] Anonymous access is enabled without Turnstile. Set VITE_TURNSTILE_SITE_KEY for bot protection, or disable VITE_ALLOW_ANON_ACCESS.")},[B]),f.useEffect(()=>{let z=!1;async function y(){try{const G=await fetch(M,{credentials:"include"});if(!G.ok)throw new Error(`Capabilities API returned ${G.status}`);const Z=await G.json();z||D(Z)}catch(G){console.warn("Failed to fetch capabilities:",G),z||D({categories:[],is_authenticated:!1})}}return y(),()=>{z=!0}},[M,n]),f.useEffect(()=>{if(!n)return;let z=!1;const y=`${B}/capabilities/personalized`;async function G(){try{const Z=await fetch(y,{credentials:"include"});if(!Z.ok)return;const K=await Z.json();z||console.debug("Personalized context loaded:",K)}catch{}}return G(),()=>{z=!0}},[B,n]),f.useImperativeHandle(t,()=>({addMessage:z=>{var y,G;(G=(y=P.current)==null?void 0:y.addMessage)==null||G.call(y,z)}}));const N=v||mt.WELCOME_MESSAGE,L=f.useMemo(()=>Yc(),[]),O=f.useCallback(z=>{k&&k({...z,type:z.type,timestamp:z.timestamp??Date.now(),sessionId:z.sessionId??L})},[k,L]),U=f.useCallback(z=>{k&&k({...z,type:z.type,timestamp:typeof z.timestamp=="number"?z.timestamp:Date.now(),sessionId:typeof z.sessionId=="string"?z.sessionId:L})},[k,L]),b=f.useMemo(()=>{const z=Dc({welcome:N,trackEvent:O}),y=Uc({ticketForm:{},setTicketForm:I,userInfo:_,trackEvent:O}),G=zc({ticketForm:{},setTicketForm:I,userInfo:_,trackEvent:O}),Z=Gc({sessionId:L,apiKey:r,trackEvent:O}),K={...z,...y,...G,...Z};return Sc(K,{disableOnOptions:!0})},[N,_,L,r,n,O,Q]);return Q?E.jsx("div",{ref:C,children:E.jsx(Or,{ref:P,isLoggedIn:n,allowAnonAccess:je.ALLOW_ANON_ACCESS,actingUser:a,onAnalyticsEvent:U,apiKey:r,qaEndpoint:h||je.QA_ENDPOINT,ratingEndpoint:w||je.RATING_ENDPOINT,capabilitiesEndpoint:M,agentRatingEndpoint:F,botName:mt.BOT_NAME,logo:mt.LOGO,primaryColor:mt.PRIMARY_COLOR,secondaryColor:mt.SECONDARY_COLOR,welcomeMessage:N,tooltipText:mt.TOOLTIP,turnstileSiteKey:je.TURNSTILE_SITE_KEY||void 0,loginUrl:o,open:u,onOpenChange:p,embedded:g,footerText:"AI-powered · Privacy Notice",footerLink:"https://support.access-ci.org/tools/access-qa-tool/privacy",resourceContext:m,customFlow:b})}):E.jsx("div",{ref:C})});Fr.displayName="AccessQABot",He.API_CONFIG=je,He.AccessQABot=Fr,He.BOT_CONFIG=mt,He.QABot=Fr,Object.defineProperty(He,Symbol.toStringTag,{value:"Module"})});
|
|
295
|
+
`;function Kc(e){if(!e)return;const t=e.getRootNode();if(!(t instanceof ShadowRoot)||t.getElementById(ca))return;const r=document.createElement("style");r.id=ca,r.textContent=Wc,t.appendChild(r)}const Fr=f.forwardRef((e,t)=>{const{apiKey:r=je.DEFAULT_API_KEY,isLoggedIn:n=!1,loginUrl:o=mt.LOGIN_URL,userEmail:i,userName:A,accessId:s,actingUser:a,ringEffect:l,defaultOpen:c,onClose:d,open:u,onOpenChange:p,embedded:g=!1,welcome:v,qaEndpoint:h,ratingEndpoint:w,agentEndpoint:x,resourceContext:m,onAnalyticsEvent:k}=e,P=f.useRef(null),C=f.useRef(null),[S,I]=f.useState({}),[Q,D]=f.useState(null),_=f.useMemo(()=>({email:i,name:A,accessId:s}),[i,A,s]);f.useEffect(()=>{Kc(C.current)},[]),f.useEffect(()=>{Ic({ticketForm:S,setTicketForm:I})},[S]);const B=x||je.AGENT_ENDPOINT,M=m?`${B}/capabilities?resource_context=${encodeURIComponent(m)}`:`${B}/capabilities`,F=`${B}/rating`;f.useEffect(()=>{B.includes("localhost")&&!window.location.hostname.includes("localhost")&&console.warn("[AccessQABot] VITE_AGENT_ENDPOINT not set — agent requests will go to localhost. Set VITE_AGENT_ENDPOINT in your environment."),je.ALLOW_ANON_ACCESS&&!je.TURNSTILE_SITE_KEY&&console.warn("[AccessQABot] Anonymous access is enabled without Turnstile. Set VITE_TURNSTILE_SITE_KEY for bot protection, or disable VITE_ALLOW_ANON_ACCESS.")},[B]),f.useEffect(()=>{let z=!1;async function y(){try{const G=await fetch(M,{credentials:"include"});if(!G.ok)throw new Error(`Capabilities API returned ${G.status}`);const Z=await G.json();z||D(Z)}catch(G){console.warn("Failed to fetch capabilities:",G),z||D({categories:[],is_authenticated:!1})}}return y(),()=>{z=!0}},[M,n]),f.useEffect(()=>{if(!n)return;let z=!1;const y=`${B}/capabilities/personalized`;async function G(){try{const Z=await fetch(y,{credentials:"include"});if(!Z.ok)return;const K=await Z.json();z||console.debug("Personalized context loaded:",K)}catch{}}return G(),()=>{z=!0}},[B,n]),f.useImperativeHandle(t,()=>({addMessage:z=>{var y,G;(G=(y=P.current)==null?void 0:y.addMessage)==null||G.call(y,z)}}));const N=v||(Q==null?void 0:Q.welcome_message)||mt.WELCOME_MESSAGE,L=f.useMemo(()=>Yc(),[]),O=f.useCallback(z=>{k&&k({...z,type:z.type,timestamp:z.timestamp??Date.now(),sessionId:z.sessionId??L})},[k,L]),U=f.useCallback(z=>{k&&k({...z,type:z.type,timestamp:typeof z.timestamp=="number"?z.timestamp:Date.now(),sessionId:typeof z.sessionId=="string"?z.sessionId:L})},[k,L]),b=f.useMemo(()=>{const z=Dc({welcome:N,trackEvent:O}),y=Uc({ticketForm:{},setTicketForm:I,userInfo:_,trackEvent:O}),G=zc({ticketForm:{},setTicketForm:I,userInfo:_,trackEvent:O}),Z=Gc({sessionId:L,apiKey:r,trackEvent:O}),K={...z,...y,...G,...Z};return Sc(K,{disableOnOptions:!0})},[N,_,L,r,n,O,Q]);return Q?E.jsx("div",{ref:C,children:E.jsx(Or,{ref:P,isLoggedIn:n,allowAnonAccess:je.ALLOW_ANON_ACCESS,actingUser:a,onAnalyticsEvent:U,apiKey:r,qaEndpoint:h||je.QA_ENDPOINT,ratingEndpoint:w||je.RATING_ENDPOINT,capabilitiesEndpoint:M,agentRatingEndpoint:F,botName:mt.BOT_NAME,logo:mt.LOGO,primaryColor:mt.PRIMARY_COLOR,secondaryColor:mt.SECONDARY_COLOR,welcomeMessage:N,tooltipText:mt.TOOLTIP,turnstileSiteKey:je.TURNSTILE_SITE_KEY||void 0,loginUrl:o,open:u,onOpenChange:p,embedded:g,footerText:"AI-powered · Privacy Notice",footerLink:"https://support.access-ci.org/tools/access-qa-tool/privacy",resourceContext:m,customFlow:b})}):E.jsx("div",{ref:C})});Fr.displayName="AccessQABot",He.API_CONFIG=je,He.AccessQABot=Fr,He.BOT_CONFIG=mt,He.QABot=Fr,Object.defineProperty(He,Symbol.toStringTag,{value:"Module"})});
|
|
296
296
|
//# sourceMappingURL=access-qa-bot.umd.cjs.map
|