@snf/access-qa-bot 3.1.0-rc.2 → 3.1.0-rc.3

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 @@ var AccessQABot=function(En){"use strict";var $t,q,Io,xt,To,Qo,Mo,Oo,tr,nr,rr,No
35
35
  background-color: #0000001a !important;
36
36
  opacity: 1 !important;
37
37
  }
38
- `),N.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(n),style:Object.assign(Object.assign({},i),r)},"Log In"))},Td=()=>N.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"},N.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"},N.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),N.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Pe=[];for(let e=0;e<256;++e)Pe.push((e+256).toString(16).slice(1));let yo;const Qd=new Uint8Array(16);var zs={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function js(e,t,n){var o;if(zs.randomUUID&&!e)return zs.randomUUID();const r=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");yo=crypto.getRandomValues.bind(crypto)}return yo(Qd)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(i,s=0){return(Pe[i[s+0]]+Pe[i[s+1]]+Pe[i[s+2]]+Pe[i[s+3]]+"-"+Pe[i[s+4]]+Pe[i[s+5]]+"-"+Pe[i[s+6]]+Pe[i[s+7]]+"-"+Pe[i[s+8]]+Pe[i[s+9]]+"-"+Pe[i[s+10]]+Pe[i[s+11]]+Pe[i[s+12]]+Pe[i[s+13]]+Pe[i[s+14]]+Pe[i[s+15]]).toLowerCase()}(r)}function Xn(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Md="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",Od="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",Nd="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",Ld="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",Rd="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",Hd=()=>{Xn()&&console.log("%c QA Bot Core %c v".concat("0.2.14"," "),Ld,Rd)},Vn=function(e){if(Xn()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Session]%c ".concat(e),Md,"",...n)}},at=function(e){if(Xn()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[History]%c ".concat(e),Od,"",...n)}},Ud=(e,t)=>{Xn()&&console.log("%c[Message]%c ".concat(e),Nd,"",t)},Fd=function(){console.warn(...arguments)},St=function(){console.error(...arguments)},Ws="qa_bot_session_messages",qs=()=>"qa_bot_session_".concat(js()),mn=()=>{try{const e=localStorage.getItem(Ws);return e?JSON.parse(e):{}}catch{return{}}},zd=(e,t,n,r,o)=>{const i=mn();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},at("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void at("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r});const s={id:t,content:n,sender:r,type:o,timestamp:Date.now()};i[e].messages.push(s),at("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r,totalInSession:i[e].messages.length});const A=i[e].messages,a=A.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=A.find(c=>{var u;return c.sender.toLowerCase()==="user"&&((u=c.content)===null||u===void 0?void 0:u.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const u=()=>Object.values(l).reduce((d,p)=>d+p.messages.length,0);for(;u()>100&&Object.keys(l).length>1;){const d=(c=Object.entries(l).sort((p,h)=>{let[,m]=p,[,f]=h;return new Date(m.startedAt).getTime()-new Date(f.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!d)break;delete l[d]}localStorage.setItem(Ws,JSON.stringify(l))})(i),at("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},Gs=e=>{var t,n;return(n=(t=mn()[e])===null||t===void 0?void 0:t.messages.length)!==null&&n!==void 0?n:0},jd=e=>{const t=mn()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},Ys=Ye(void 0),Wd=e=>{let{children:t,getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}=e;return N.createElement(Ys.Provider,{value:{getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}},t)},vo=()=>{const e=ze(Ys);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},qd=()=>{const[e,t]=J(!1),[n,r]=J([]),[o,i]=J(null),[s,A]=J(0),a=Ae(null),l=Ae(null),{replaceMessages:c}=ln(),{toggleTextAreaDisabled:u}=ga(),{setSessionId:d,getSessionId:p}=vo();te(()=>{const m=f=>{a.current&&!a.current.contains(f.target)&&l.current&&!l.current.contains(f.target)&&t(!1)};return e&&document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[e]);const h=m=>{const f=p();if(at("RESTORE requested",{targetSession:m.slice(-12),currentSession:f==null?void 0:f.slice(-12)}),m===f)return at("RESTORE skipped - already on this session"),void t(!1);const v=(g=>{var x;return((x=mn()[g])===null||x===void 0?void 0:x.messages)||[]})(m).filter(g=>{var x;return(x=g.content)===null||x===void 0?void 0:x.trim()});at("Stored messages from our localStorage",{count:v.length,ids:v.map(g=>g.id.slice(-8))});const y=v.map(g=>({id:g.id,content:g.content,sender:g.sender.toUpperCase(),type:g.type||"string",timestamp:new Date(g.timestamp).toISOString()}));c(y),at("replaceMessages called",{count:y.length}),setTimeout(()=>{const g=document.querySelector(".rcb-chat-body-container");g&&g.querySelectorAll(".rcb-bot-message").forEach(x=>{var k;let E=x.innerHTML,C=!1;E.includes("](")&&(E=E.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),C=!0),E.includes("&lt;a href=")&&(E=E.replace(/&lt;a\s+href=["']([^"']+)["'][^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),C=!0),(E.includes("&lt;a ")||!((k=x.textContent)===null||k===void 0)&&k.includes("<a href="))&&(x.textContent||"").includes("<a href=")&&(E=E.replace(/&lt;a\s+href="([^"]+)"[^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),C=!0),C&&(x.innerHTML=E)})},50),d(m),at("Session ID updated",{newSession:m.slice(-12)}),u(!1),at("Chat input enabled after restore"),t(!1)};return N.createElement("div",{style:{position:"relative"}},N.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(r((()=>{const m=mn();return Object.entries(m).map(f=>{let[v,y]=f;return Object.assign({sessionId:v},y)}).sort((f,v)=>new Date(v.startedAt).getTime()-new Date(f.startedAt).getTime())})()),l.current)){const m=l.current.closest(".rcb-chat-window");if(m){const f=m.getBoundingClientRect(),v=l.current.getBoundingClientRect();i(f.width+3),A(f.right-v.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"},N.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"},N.createElement("circle",{cx:"12",cy:"12",r:"10"}),N.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&N.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:s?"-".concat(s,"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}},n.length===0?N.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):n.map(m=>N.createElement("button",{key:m.sessionId,role:"menuitem",onClick:()=>h(m.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:f=>{f.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"}},N.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},m.preview||"New conversation"),N.createElement("span",{style:{fontSize:"12px",color:"#888"}},(f=>{const v=new Date(f),y=new Date().getTime()-v.getTime(),g=Math.floor(y/864e5);return g===0?v.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):g===1?"Yesterday":g<7?v.toLocaleDateString([],{weekday:"short"}):v.toLocaleDateString([],{month:"short",day:"numeric"})})(m.startedAt))))))};function bo(){return bo=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},bo.apply(null,arguments)}const Xs=({width:e=24,height:t=24,color:n="currentColor",children:r,...o})=>N.createElement("svg",bo({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),r),Gd=e=>N.createElement(Xs,e,N.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"})),Vs=Ye(null),Yd=e=>{let{trackEvent:t,children:n}=e;const r=Ae(t);return r.current=t,N.createElement(Vs.Provider,{value:{trackEvent:o=>r.current(o)}},n)},Xd=()=>{const{restartFlow:e}=Ln(),{setTextAreaValue:t}=ga(),{messages:n}=ln(),{getSessionId:r,resetSession:o,clearResettingFlag:i}=vo(),{trackEvent:s}=ze(Vs)||{trackEvent:()=>{}};return N.createElement("button",{onClick:async()=>{const A=r(),a=A?Gs(A):0;s({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:A=>{A.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:A=>{A.target.style.backgroundColor="var(--primaryColor, #107180)"}},N.createElement(Gd,{width:16,height:16}),"New Chat")};function wo(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(wo).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return wo(t.children)}return""}const Vd=()=>{const{getSessionId:e}=vo(),t=W(n=>{var r;const o=(r=n.data)===null||r===void 0?void 0:r.message;if(!(o!=null&&o.id))return;const i=o.sender,s=o.type||"string";let A;if(A=typeof o.content=="string"?o.content:wo(o.content),Ud("TRACKED",{id:o.id,sender:i,content:A.substring(0,50)+(A.length>50?"...":"")}),A.includes("rcb-options-container")||!A.trim())return;const a=e();zd(a,o.id,A,i,s)},[e]);return te(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},Kd=()=>(te(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const s=document.activeElement;if(s&&(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.contentEditable==="true"||s.classList.contains("rcb-chat-input-textarea")))return;const A=document.querySelector(".rcb-chat-window");if(!A)return;const 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){const u=a[a.length-1].querySelector(".rcb-checkbox-container");if(u&&u.offsetParent!==null){const d=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")),p=u.querySelector(".rcb-checkbox-next-button");if(d.length>0){const h=[...d];return p&&h.push(p),void((m,f)=>{m.preventDefault();let v=-1;for(let g=0;g<f.length;g++)if(f[g]===document.activeElement||f[g].contains(document.activeElement)){v=g;break}v===-1&&(v=0);let y=v;switch(m.key){case"ArrowDown":case"ArrowRight":y=v<f.length-1?v+1:0;break;case"ArrowUp":case"ArrowLeft":y=v>0?v-1:f.length-1;break;case"Home":y=0;break;case"End":y=f.length-1;break;case"Enter":case" ":{const g=f[v],x=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void g.dispatchEvent(x)}default:return}f[y].focus(),f[y].setAttribute("tabindex","0"),f[y].classList.add("keyboard-focused"),f.forEach((g,x)=>{x!==y&&(g.setAttribute("tabindex","-1"),g.classList.remove("keyboard-focused"))})})(i,h)}}}let l=[];if(a.length>0){const u=a[a.length-1],d=Array.from(u.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(d.length>0){const p=d[d.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(u=>u===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let u;i.preventDefault(),u=c<l.length-1?c+1:0,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"ArrowUp":case"ArrowLeft":{let u;i.preventDefault(),u=c>0?c-1:l.length-1,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const u=document.activeElement;if(u.classList.contains("rcb-checkbox-row-container")||u.closest(".rcb-checkbox-row-container")){const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.querySelector(".rcb-checkbox-label"),h=p?p.textContent:u.textContent||"checkbox",m=u.querySelector(".rcb-checkbox-mark"),f=m&&m.style.backgroundColor?"checked":"unchecked";t(`${h} ${f}`)}else{const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.textContent||u.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((u,d)=>{d!==0&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const u=l.length-1;l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus()}}},t=i=>{const s=document.createElement("div");s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true"),s.className="sr-only",s.textContent=i,document.body.appendChild(s),setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},1e3)},n=(i=null)=>{let s=i;if(s||(s=document.querySelector(".rcb-chat-window"),s||(s=document.querySelector('[class*="rcb-chat"]')),s||(s=document.querySelector(".qa-bot"))),!s)return;const A=s.closest(".embedded-qa-bot")!==null,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)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(d=>d.offsetParent!==null);let u=[];if(c.length>0){const d=c[c.length-1];u=Array.from(d.querySelectorAll(".rcb-options"))}if(u.length===0){let d=l.querySelector(".rcb-checkbox-container");if(!d&&s&&(d=s.querySelector(".rcb-checkbox-container")),d&&d.offsetParent!==null){const p=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")).filter(h=>h.offsetParent!==null&&h.style.display!=="none");if(p.length>0){const h=d.querySelector(".rcb-checkbox-next-button"),m=[...p];if(h&&h.offsetParent!==null&&m.push(h),m.forEach((f,v)=>{f.setAttribute("tabindex",v===0?"0":"-1"),v===0?f.classList.add("keyboard-focused"):f.classList.remove("keyboard-focused")}),p.length>1){d.querySelectorAll(".keyboard-nav-hint").forEach(v=>v.remove());const f=document.createElement("div");f.className="keyboard-nav-hint",f.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",f.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(f,d.firstChild)}return void setTimeout(()=>{m[0]&&m[0].offsetParent!==null&&!A&&m[0].focus()},150)}}}if(u.length>0){if(u.forEach((d,p)=>{const h=p===0?"0":"-1";d.setAttribute("tabindex",h),d.setAttribute("role","option"),d.setAttribute("aria-posinset",p+1),d.setAttribute("aria-setsize",u.length),p===0?d.classList.add("keyboard-focused"):d.classList.remove("keyboard-focused")}),u.length>1){const d=c.length>0?c[c.length-1]:null;if(d){d.querySelectorAll(".keyboard-nav-hint").forEach(h=>h.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;",d.insertBefore(p,d.firstChild)}}else{const d=c.length>0?c[c.length-1]:null;d&&d.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{u[0]&&u[0].offsetParent!==null&&!A&&(u[0].focus(),u.length>1&&t(`${u.length} options available. Use arrow keys to navigate.`))},200)}},r=new MutationObserver(i=>{i.forEach(s=>{var A,a;if(s.type==="childList"){const l=Array.from(s.addedNodes),c=l.some(d=>{var p,h,m,f;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-options-container"))||((h=d.classList)==null?void 0:h.contains("rcb-options"))||((m=d.querySelector)==null?void 0:m.call(d,".rcb-options-container"))||((f=d.querySelector)==null?void 0:f.call(d,".rcb-options")))}),u=l.some(d=>{var p,h;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((h=d.querySelector)==null?void 0:h.call(d,".rcb-checkbox-container")))});if(c||u){let d=s.target;for(;d&&!((A=d.classList)!=null&&A.contains("qa-bot"))&&!((a=d.classList)!=null&&a.contains("rcb-chat-window"));)d=d.parentElement;(d||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(()=>n(d),100)}}})});r.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),n();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const s=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,A=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(s){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&n(i)}if(A){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&n(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),r.disconnect(),clearInterval(o)}},[]),null),$d="#1a5b6e",Jd="#107180",Zd="Arial, sans-serif",Ks="Q&A Bot",ep="/chat-icon.svg",tp="Type your question here...",np="Select an option to continue",rp=!1,op="Ask me a question!",$s="/login",ip={general:{showHeader:!0,showFooter:!0},tooltip:{mode:"CLOSE"},chatInput:{disabled:!1,characterLimit:1e3,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}},xo=Ie((e,t)=>{var n,r;const{apiKey:o,qaEndpoint:i,ratingEndpoint:s,welcomeMessage:A,open:a,onOpenChange:l,isLoggedIn:c,allowAnonAccess:u=!1,actingUser:d,primaryColor:p,secondaryColor:h,botName:m,logo:f,placeholder:v,errorMessage:y,embedded:g,footerText:x,footerLink:k,tooltipText:E,loginUrl:C,customFlow:T,onAnalyticsEvent:D}=e,P=Ae("bot_".concat(Math.random().toString(36).substr(2,9)));te(()=>{Hd()},[]);const S=Ae(null);S.current===null&&(S.current=qs(),Vn("CREATED",S.current));const B=Ae(!1),R=Ae({getSessionId:()=>S.current,isResetting:()=>B.current}),[L,Q]=J(c);te(()=>{Q(c)},[c]);const z=g!==void 0?g:rp,M=W(F=>{var H;D&&D(Object.assign(Object.assign({},F),{timestamp:Date.now(),sessionId:(H=S.current)!==null&&H!==void 0?H:void 0,pageUrl:typeof window<"u"?window.location.href:void 0,isEmbedded:z}))},[D,z]),U=be(()=>{const F=Object.assign({},ip);F.general=Object.assign(Object.assign({},F.general),{primaryColor:p||$d,secondaryColor:h||Jd,fontFamily:Zd,embedded:z});const H=L===!1?[N.createElement(Fs,{key:"login-button",loginUrl:C||$s,isHeaderButton:!0})]:[N.createElement(qd,{key:"history-button"}),N.createElement(Td,{key:"user-icon"})];F.header={title:N.createElement("span",{style:{fontSize:14,fontWeight:500}},m||Ks),showAvatar:!0,avatar:f||ep,buttons:[...H,ye.CLOSE_CHAT_BUTTON]},F.chatInput=Object.assign(Object.assign({},F.chatInput),{disabled:!1,enabledPlaceholderText:v||tp,disabledPlaceholderText:y||np}),F.tooltip=Object.assign(Object.assign({},F.tooltip),{text:E||op});const Y=x?k?N.createElement("a",{href:k,target:"_blank",rel:"noopener noreferrer",key:"footer-link"},x):N.createElement("span",{key:"footer-text"},x):null;return F.footer={text:Y,buttons:[N.createElement(Xd,{key:"new-chat-button"})]},F.event={rcbPreInjectMessage:!0,rcbPostInjectMessage:!0,rcbUserSubmitText:!0,rcbChangePath:!0,rcbToggleChatWindow:!0},F},[p,h,m,f,v,y,z,E,L,C,x,k]),b=Ae(null),re=function(F){let H=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return be(()=>{const Y=(ee,oe)=>{if(F.current){const ce=getComputedStyle(F.current).getPropertyValue(ee);if(ce&&ce.trim()!=="")return ce.trim();if(F.current.parentElement){const pe=getComputedStyle(F.current.parentElement).getPropertyValue(ee);if(pe&&pe.trim()!=="")return pe.trim()}}return oe};return{primaryColor:Y("--primaryColor",H.primaryColor),secondaryColor:Y("--secondaryColor",H.secondaryColor),fontFamily:Y("--fontFamily",H.fontFamily)}},[F,H])}(b,U.general);((F,H)=>{te(()=>{H.current&&(F?H.current.classList.add("bot-logged-in"):H.current.classList.remove("bot-logged-in"))},[F,H])})(L!==!1,b),(F=>{let{settings:H,themeColors:Y}=F;te(()=>{Y&&(Object.entries(Y).forEach(ee=>{let[oe,ce]=ee;ce&&document.documentElement.style.setProperty("--".concat(oe),ce)}),Y.primaryColor&&document.documentElement.style.setProperty("--rcb-header-background",Y.primaryColor),Y.secondaryColor&&document.documentElement.style.setProperty("--rcb-header-background-hover",Y.secondaryColor))},[Y]),te(()=>{var ee,oe,ce;!((ee=H.header)===null||ee===void 0)&&ee.title&&typeof H.header.title=="string"&&(H.header.title=N.createElement("div",{key:"header-title"},N.createElement("h1",{className:"sr-only"},H.header.title),N.createElement("span",{"aria-hidden":"true"},H.header.title))),!((oe=H.general)===null||oe===void 0)&&oe.embedded&&H.chatWindow&&(H.chatWindow.defaultOpen=!0),H.device={desktopEnabled:!0,mobileEnabled:!0,applyMobileOptimizations:!1},H.chatHistory={disabled:!1},H.chatButton=Object.assign(Object.assign({},H.chatButton),{icon:(ce=H.header)===null||ce===void 0?void 0:ce.avatar}),H.event={rcbToggleChatWindow:!0}},[H])})({settings:U,themeColors:re});const w=be(()=>{const F=(Y=>{let{endpoint:ee,ratingEndpoint:oe,apiKey:ce,sessionId:pe,isResetting:ve=()=>!1,isLoggedIn:Ve,allowAnonAccess:Tt=!1,loginUrl:Qt="/login",actingUser:st,trackEvent:Ne}=Y;if(Ve===!1&&!Tt)return Ne==null||Ne({type:"chatbot_login_prompt_shown"}),{qa_loop:{message:"To ask questions, please log in first.",component:N.createElement(Fs,{loginUrl:Qt}),chatDisabled:!0,path:"qa_loop"}};let Ke=null,er=!1;if(!ee)throw new Error("Q&A endpoint is required");return{qa_loop:{message:async ut=>{const{userInput:At}=ut;if(ve&&ve()||!At||At.trim()==="")return null;if(At==="👍 Helpful"||At==="👎 Not helpful"){if(oe&&Ke)try{const ke=At==="👍 Helpful",Ge={"Content-Type":"application/json"};ce&&(Ge["X-API-KEY"]=ce);const $e=pe();$e&&(Ge["X-Session-ID"]=$e,Ge["X-Query-ID"]=Ke),await fetch(oe,{method:"POST",headers:Ge,body:JSON.stringify({sessionId:$e,queryId:Ke,rating:ke?1:0})}),Ne==null||Ne({type:"chatbot_rating_sent",queryId:Ke,rating:ke?"helpful":"not_helpful"})}catch(ke){St("Error sending feedback:",ke)}return"Thanks for the feedback! Feel free to ask another question."}try{const ke=js();Ke=ke,Ne==null||Ne({type:"chatbot_question_sent",queryId:ke,questionLength:At.length});const Ge={"Content-Type":"application/json"};ce&&(Ge["X-API-KEY"]=ce);const $e=pe();$e&&(Ge["X-Session-ID"]=$e,Ge["X-Query-ID"]=ke),st&&(Ge["X-Acting-User"]=st);const bn={query:At,session_id:$e,question_id:ke};st&&(bn.acting_user=st),Vn("SENT to API",{session_id:$e,question_id:ke,acting_user:st||"(not set)"});const So=Date.now(),wn=await fetch(ee,{method:"POST",headers:Ge,body:JSON.stringify(bn)}),Bo=Date.now()-So;if(!wn.ok)throw new Error("API returned ".concat(wn.status));const Mt=await wn.json(),xn=Mt.response||Mt.answer||Mt.text||Mt.message;if(!xn)throw new Error("Invalid response format from API");const I=(le=>{if(!le||typeof le!="string")return le;let ae=le.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return ae=ae.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),_e=>{let Qe=_e,Se="";const wt=Qe.match(/([.,;:!?]+)$/);return wt&&(Se=wt[1],Qe=Qe.slice(0,-Se.length)),"[".concat(Qe,"](").concat(Qe,")").concat(Se)}),ae})(xn),G=function(le){const{confidence:ae,tools_used:_e,metadata:Qe}=le;if(!(ae||_e&&_e.length!==0))return"";const Se=[];return ae&&Se.push("• Confidence: ".concat(ae)),_e&&_e.length>0&&Se.push("• Tools used: ".concat(_e.join(", "))),Qe!=null&&Qe.agent&&Se.push("• Agent: ".concat(Qe.agent)),`---
38
+ `),N.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(n),style:Object.assign(Object.assign({},i),r)},"Log In"))},Td=()=>N.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"},N.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"},N.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),N.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Pe=[];for(let e=0;e<256;++e)Pe.push((e+256).toString(16).slice(1));let yo;const Qd=new Uint8Array(16);var zs={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function js(e,t,n){var o;if(zs.randomUUID&&!e)return zs.randomUUID();const r=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");yo=crypto.getRandomValues.bind(crypto)}return yo(Qd)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(i,s=0){return(Pe[i[s+0]]+Pe[i[s+1]]+Pe[i[s+2]]+Pe[i[s+3]]+"-"+Pe[i[s+4]]+Pe[i[s+5]]+"-"+Pe[i[s+6]]+Pe[i[s+7]]+"-"+Pe[i[s+8]]+Pe[i[s+9]]+"-"+Pe[i[s+10]]+Pe[i[s+11]]+Pe[i[s+12]]+Pe[i[s+13]]+Pe[i[s+14]]+Pe[i[s+15]]).toLowerCase()}(r)}function Xn(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Md="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",Od="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",Nd="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",Ld="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",Rd="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",Hd=()=>{Xn()&&console.log("%c QA Bot Core %c v".concat("0.2.17"," "),Ld,Rd)},Vn=function(e){if(Xn()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Session]%c ".concat(e),Md,"",...n)}},at=function(e){if(Xn()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[History]%c ".concat(e),Od,"",...n)}},Ud=(e,t)=>{Xn()&&console.log("%c[Message]%c ".concat(e),Nd,"",t)},Fd=function(){console.warn(...arguments)},St=function(){console.error(...arguments)},Ws="qa_bot_session_messages",qs=()=>"qa_bot_session_".concat(js()),mn=()=>{try{const e=localStorage.getItem(Ws);return e?JSON.parse(e):{}}catch{return{}}},zd=(e,t,n,r,o)=>{const i=mn();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},at("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void at("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r});const s={id:t,content:n,sender:r,type:o,timestamp:Date.now()};i[e].messages.push(s),at("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r,totalInSession:i[e].messages.length});const A=i[e].messages,a=A.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=A.find(c=>{var u;return c.sender.toLowerCase()==="user"&&((u=c.content)===null||u===void 0?void 0:u.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const u=()=>Object.values(l).reduce((d,p)=>d+p.messages.length,0);for(;u()>100&&Object.keys(l).length>1;){const d=(c=Object.entries(l).sort((p,h)=>{let[,m]=p,[,f]=h;return new Date(m.startedAt).getTime()-new Date(f.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!d)break;delete l[d]}localStorage.setItem(Ws,JSON.stringify(l))})(i),at("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},Gs=e=>{var t,n;return(n=(t=mn()[e])===null||t===void 0?void 0:t.messages.length)!==null&&n!==void 0?n:0},jd=e=>{const t=mn()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},Ys=Ye(void 0),Wd=e=>{let{children:t,getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}=e;return N.createElement(Ys.Provider,{value:{getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}},t)},vo=()=>{const e=ze(Ys);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},qd=()=>{const[e,t]=J(!1),[n,r]=J([]),[o,i]=J(null),[s,A]=J(0),a=Ae(null),l=Ae(null),{replaceMessages:c}=ln(),{toggleTextAreaDisabled:u}=ga(),{setSessionId:d,getSessionId:p}=vo();te(()=>{const m=f=>{a.current&&!a.current.contains(f.target)&&l.current&&!l.current.contains(f.target)&&t(!1)};return e&&document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[e]);const h=m=>{const f=p();if(at("RESTORE requested",{targetSession:m.slice(-12),currentSession:f==null?void 0:f.slice(-12)}),m===f)return at("RESTORE skipped - already on this session"),void t(!1);const v=(g=>{var x;return((x=mn()[g])===null||x===void 0?void 0:x.messages)||[]})(m).filter(g=>{var x;return(x=g.content)===null||x===void 0?void 0:x.trim()});at("Stored messages from our localStorage",{count:v.length,ids:v.map(g=>g.id.slice(-8))});const y=v.map(g=>({id:g.id,content:g.content,sender:g.sender.toUpperCase(),type:g.type||"string",timestamp:new Date(g.timestamp).toISOString()}));c(y),at("replaceMessages called",{count:y.length}),setTimeout(()=>{const g=document.querySelector(".rcb-chat-body-container");g&&g.querySelectorAll(".rcb-bot-message").forEach(x=>{var k;let E=x.innerHTML,C=!1;E.includes("](")&&(E=E.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),C=!0),E.includes("&lt;a href=")&&(E=E.replace(/&lt;a\s+href=["']([^"']+)["'][^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),C=!0),(E.includes("&lt;a ")||!((k=x.textContent)===null||k===void 0)&&k.includes("<a href="))&&(x.textContent||"").includes("<a href=")&&(E=E.replace(/&lt;a\s+href="([^"]+)"[^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),C=!0),C&&(x.innerHTML=E)})},50),d(m),at("Session ID updated",{newSession:m.slice(-12)}),u(!1),at("Chat input enabled after restore"),t(!1)};return N.createElement("div",{style:{position:"relative"}},N.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(r((()=>{const m=mn();return Object.entries(m).map(f=>{let[v,y]=f;return Object.assign({sessionId:v},y)}).sort((f,v)=>new Date(v.startedAt).getTime()-new Date(f.startedAt).getTime())})()),l.current)){const m=l.current.closest(".rcb-chat-window");if(m){const f=m.getBoundingClientRect(),v=l.current.getBoundingClientRect();i(f.width+3),A(f.right-v.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"},N.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"},N.createElement("circle",{cx:"12",cy:"12",r:"10"}),N.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&N.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:s?"-".concat(s,"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}},n.length===0?N.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):n.map(m=>N.createElement("button",{key:m.sessionId,role:"menuitem",onClick:()=>h(m.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:f=>{f.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"}},N.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},m.preview||"New conversation"),N.createElement("span",{style:{fontSize:"12px",color:"#888"}},(f=>{const v=new Date(f),y=new Date().getTime()-v.getTime(),g=Math.floor(y/864e5);return g===0?v.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):g===1?"Yesterday":g<7?v.toLocaleDateString([],{weekday:"short"}):v.toLocaleDateString([],{month:"short",day:"numeric"})})(m.startedAt))))))};function bo(){return bo=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},bo.apply(null,arguments)}const Xs=({width:e=24,height:t=24,color:n="currentColor",children:r,...o})=>N.createElement("svg",bo({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),r),Gd=e=>N.createElement(Xs,e,N.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"})),Vs=Ye(null),Yd=e=>{let{trackEvent:t,children:n}=e;const r=Ae(t);return r.current=t,N.createElement(Vs.Provider,{value:{trackEvent:o=>r.current(o)}},n)},Xd=()=>{const{restartFlow:e}=Ln(),{setTextAreaValue:t}=ga(),{messages:n}=ln(),{getSessionId:r,resetSession:o,clearResettingFlag:i}=vo(),{trackEvent:s}=ze(Vs)||{trackEvent:()=>{}};return N.createElement("button",{onClick:async()=>{const A=r(),a=A?Gs(A):0;s({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:A=>{A.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:A=>{A.target.style.backgroundColor="var(--primaryColor, #107180)"}},N.createElement(Gd,{width:16,height:16}),"New Chat")};function wo(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(wo).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return wo(t.children)}return""}const Vd=()=>{const{getSessionId:e}=vo(),t=W(n=>{var r;const o=(r=n.data)===null||r===void 0?void 0:r.message;if(!(o!=null&&o.id))return;const i=o.sender,s=o.type||"string";let A;if(A=typeof o.content=="string"?o.content:wo(o.content),Ud("TRACKED",{id:o.id,sender:i,content:A.substring(0,50)+(A.length>50?"...":"")}),A.includes("rcb-options-container")||!A.trim())return;const a=e();zd(a,o.id,A,i,s)},[e]);return te(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},Kd=()=>(te(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const s=document.activeElement;if(s&&(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.contentEditable==="true"||s.classList.contains("rcb-chat-input-textarea")))return;const A=document.querySelector(".rcb-chat-window");if(!A)return;const 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){const u=a[a.length-1].querySelector(".rcb-checkbox-container");if(u&&u.offsetParent!==null){const d=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")),p=u.querySelector(".rcb-checkbox-next-button");if(d.length>0){const h=[...d];return p&&h.push(p),void((m,f)=>{m.preventDefault();let v=-1;for(let g=0;g<f.length;g++)if(f[g]===document.activeElement||f[g].contains(document.activeElement)){v=g;break}v===-1&&(v=0);let y=v;switch(m.key){case"ArrowDown":case"ArrowRight":y=v<f.length-1?v+1:0;break;case"ArrowUp":case"ArrowLeft":y=v>0?v-1:f.length-1;break;case"Home":y=0;break;case"End":y=f.length-1;break;case"Enter":case" ":{const g=f[v],x=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void g.dispatchEvent(x)}default:return}f[y].focus(),f[y].setAttribute("tabindex","0"),f[y].classList.add("keyboard-focused"),f.forEach((g,x)=>{x!==y&&(g.setAttribute("tabindex","-1"),g.classList.remove("keyboard-focused"))})})(i,h)}}}let l=[];if(a.length>0){const u=a[a.length-1],d=Array.from(u.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(d.length>0){const p=d[d.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(u=>u===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let u;i.preventDefault(),u=c<l.length-1?c+1:0,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"ArrowUp":case"ArrowLeft":{let u;i.preventDefault(),u=c>0?c-1:l.length-1,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const u=document.activeElement;if(u.classList.contains("rcb-checkbox-row-container")||u.closest(".rcb-checkbox-row-container")){const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.querySelector(".rcb-checkbox-label"),h=p?p.textContent:u.textContent||"checkbox",m=u.querySelector(".rcb-checkbox-mark"),f=m&&m.style.backgroundColor?"checked":"unchecked";t(`${h} ${f}`)}else{const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.textContent||u.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((u,d)=>{d!==0&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const u=l.length-1;l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus()}}},t=i=>{const s=document.createElement("div");s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true"),s.className="sr-only",s.textContent=i,document.body.appendChild(s),setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},1e3)},n=(i=null)=>{let s=i;if(s||(s=document.querySelector(".rcb-chat-window"),s||(s=document.querySelector('[class*="rcb-chat"]')),s||(s=document.querySelector(".qa-bot"))),!s)return;const A=s.closest(".embedded-qa-bot")!==null,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)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(d=>d.offsetParent!==null);let u=[];if(c.length>0){const d=c[c.length-1];u=Array.from(d.querySelectorAll(".rcb-options"))}if(u.length===0){let d=l.querySelector(".rcb-checkbox-container");if(!d&&s&&(d=s.querySelector(".rcb-checkbox-container")),d&&d.offsetParent!==null){const p=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")).filter(h=>h.offsetParent!==null&&h.style.display!=="none");if(p.length>0){const h=d.querySelector(".rcb-checkbox-next-button"),m=[...p];if(h&&h.offsetParent!==null&&m.push(h),m.forEach((f,v)=>{f.setAttribute("tabindex",v===0?"0":"-1"),v===0?f.classList.add("keyboard-focused"):f.classList.remove("keyboard-focused")}),p.length>1){d.querySelectorAll(".keyboard-nav-hint").forEach(v=>v.remove());const f=document.createElement("div");f.className="keyboard-nav-hint",f.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",f.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(f,d.firstChild)}return void setTimeout(()=>{m[0]&&m[0].offsetParent!==null&&!A&&m[0].focus()},150)}}}if(u.length>0){if(u.forEach((d,p)=>{const h=p===0?"0":"-1";d.setAttribute("tabindex",h),d.setAttribute("role","option"),d.setAttribute("aria-posinset",p+1),d.setAttribute("aria-setsize",u.length),p===0?d.classList.add("keyboard-focused"):d.classList.remove("keyboard-focused")}),u.length>1){const d=c.length>0?c[c.length-1]:null;if(d){d.querySelectorAll(".keyboard-nav-hint").forEach(h=>h.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;",d.insertBefore(p,d.firstChild)}}else{const d=c.length>0?c[c.length-1]:null;d&&d.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{u[0]&&u[0].offsetParent!==null&&!A&&(u[0].focus(),u.length>1&&t(`${u.length} options available. Use arrow keys to navigate.`))},200)}},r=new MutationObserver(i=>{i.forEach(s=>{var A,a;if(s.type==="childList"){const l=Array.from(s.addedNodes),c=l.some(d=>{var p,h,m,f;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-options-container"))||((h=d.classList)==null?void 0:h.contains("rcb-options"))||((m=d.querySelector)==null?void 0:m.call(d,".rcb-options-container"))||((f=d.querySelector)==null?void 0:f.call(d,".rcb-options")))}),u=l.some(d=>{var p,h;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((h=d.querySelector)==null?void 0:h.call(d,".rcb-checkbox-container")))});if(c||u){let d=s.target;for(;d&&!((A=d.classList)!=null&&A.contains("qa-bot"))&&!((a=d.classList)!=null&&a.contains("rcb-chat-window"));)d=d.parentElement;(d||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(()=>n(d),100)}}})});r.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),n();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const s=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,A=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(s){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&n(i)}if(A){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&n(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),r.disconnect(),clearInterval(o)}},[]),null),$d="#1a5b6e",Jd="#107180",Zd="Arial, sans-serif",Ks="Q&A Bot",ep="/chat-icon.svg",tp="Type your question here...",np="Select an option to continue",rp=!1,op="Ask me a question!",$s="/login",ip={general:{showHeader:!0,showFooter:!0},tooltip:{mode:"CLOSE"},chatInput:{disabled:!1,characterLimit:1e3,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}},xo=Ie((e,t)=>{var n,r;const{apiKey:o,qaEndpoint:i,ratingEndpoint:s,welcomeMessage:A,open:a,onOpenChange:l,isLoggedIn:c,allowAnonAccess:u=!1,actingUser:d,primaryColor:p,secondaryColor:h,botName:m,logo:f,placeholder:v,errorMessage:y,embedded:g,footerText:x,footerLink:k,tooltipText:E,loginUrl:C,customFlow:T,onAnalyticsEvent:D}=e,P=Ae("bot_".concat(Math.random().toString(36).substr(2,9)));te(()=>{Hd()},[]);const S=Ae(null);S.current===null&&(S.current=qs(),Vn("CREATED",S.current));const B=Ae(!1),R=Ae({getSessionId:()=>S.current,isResetting:()=>B.current}),[L,Q]=J(c);te(()=>{Q(c)},[c]);const z=g!==void 0?g:rp,M=W(F=>{var H;D&&D(Object.assign(Object.assign({},F),{timestamp:Date.now(),sessionId:(H=S.current)!==null&&H!==void 0?H:void 0,pageUrl:typeof window<"u"?window.location.href:void 0,isEmbedded:z}))},[D,z]),U=be(()=>{const F=Object.assign({},ip);F.general=Object.assign(Object.assign({},F.general),{primaryColor:p||$d,secondaryColor:h||Jd,fontFamily:Zd,embedded:z});const H=L===!1?[N.createElement(Fs,{key:"login-button",loginUrl:C||$s,isHeaderButton:!0})]:[N.createElement(qd,{key:"history-button"}),N.createElement(Td,{key:"user-icon"})];F.header={title:N.createElement("span",{style:{fontSize:14,fontWeight:500}},m||Ks),showAvatar:!0,avatar:f||ep,buttons:[...H,ye.CLOSE_CHAT_BUTTON]},F.chatInput=Object.assign(Object.assign({},F.chatInput),{disabled:!1,enabledPlaceholderText:v||tp,disabledPlaceholderText:y||np}),F.tooltip=Object.assign(Object.assign({},F.tooltip),{text:E||op});const Y=x?k?N.createElement("a",{href:k,target:"_blank",rel:"noopener noreferrer",key:"footer-link"},x):N.createElement("span",{key:"footer-text"},x):null;return F.footer={text:Y,buttons:[N.createElement(Xd,{key:"new-chat-button"})]},F.event={rcbPreInjectMessage:!0,rcbPostInjectMessage:!0,rcbUserSubmitText:!0,rcbChangePath:!0,rcbToggleChatWindow:!0},F},[p,h,m,f,v,y,z,E,L,C,x,k]),b=Ae(null),re=function(F){let H=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return be(()=>{const Y=(ee,oe)=>{if(F.current){const ce=getComputedStyle(F.current).getPropertyValue(ee);if(ce&&ce.trim()!=="")return ce.trim();if(F.current.parentElement){const pe=getComputedStyle(F.current.parentElement).getPropertyValue(ee);if(pe&&pe.trim()!=="")return pe.trim()}}return oe};return{primaryColor:Y("--primaryColor",H.primaryColor),secondaryColor:Y("--secondaryColor",H.secondaryColor),fontFamily:Y("--fontFamily",H.fontFamily)}},[F,H])}(b,U.general);((F,H)=>{te(()=>{H.current&&(F?H.current.classList.add("bot-logged-in"):H.current.classList.remove("bot-logged-in"))},[F,H])})(L!==!1,b),(F=>{let{settings:H,themeColors:Y}=F;te(()=>{Y&&(Object.entries(Y).forEach(ee=>{let[oe,ce]=ee;ce&&document.documentElement.style.setProperty("--".concat(oe),ce)}),Y.primaryColor&&document.documentElement.style.setProperty("--rcb-header-background",Y.primaryColor),Y.secondaryColor&&document.documentElement.style.setProperty("--rcb-header-background-hover",Y.secondaryColor))},[Y]),te(()=>{var ee,oe,ce;!((ee=H.header)===null||ee===void 0)&&ee.title&&typeof H.header.title=="string"&&(H.header.title=N.createElement("div",{key:"header-title"},N.createElement("h1",{className:"sr-only"},H.header.title),N.createElement("span",{"aria-hidden":"true"},H.header.title))),!((oe=H.general)===null||oe===void 0)&&oe.embedded&&H.chatWindow&&(H.chatWindow.defaultOpen=!0),H.device={desktopEnabled:!0,mobileEnabled:!0,applyMobileOptimizations:!1},H.chatHistory={disabled:!1},H.chatButton=Object.assign(Object.assign({},H.chatButton),{icon:(ce=H.header)===null||ce===void 0?void 0:ce.avatar}),H.event={rcbToggleChatWindow:!0}},[H])})({settings:U,themeColors:re});const w=be(()=>{const F=(Y=>{let{endpoint:ee,ratingEndpoint:oe,apiKey:ce,sessionId:pe,isResetting:ve=()=>!1,isLoggedIn:Ve,allowAnonAccess:Tt=!1,loginUrl:Qt="/login",actingUser:st,trackEvent:Ne}=Y;if(Ve===!1&&!Tt)return Ne==null||Ne({type:"chatbot_login_prompt_shown"}),{qa_loop:{message:"To ask questions, please log in first.",component:N.createElement(Fs,{loginUrl:Qt}),chatDisabled:!0,path:"qa_loop"}};let Ke=null,er=!1;if(!ee)throw new Error("Q&A endpoint is required");return{qa_loop:{message:async ut=>{const{userInput:At}=ut;if(ve&&ve()||!At||At.trim()==="")return null;if(At==="👍 Helpful"||At==="👎 Not helpful"){if(oe&&Ke)try{const ke=At==="👍 Helpful",Ge={"Content-Type":"application/json"};ce&&(Ge["X-API-KEY"]=ce);const $e=pe();$e&&(Ge["X-Session-ID"]=$e,Ge["X-Query-ID"]=Ke),await fetch(oe,{method:"POST",headers:Ge,body:JSON.stringify({sessionId:$e,queryId:Ke,rating:ke?1:0})}),Ne==null||Ne({type:"chatbot_rating_sent",queryId:Ke,rating:ke?"helpful":"not_helpful"})}catch(ke){St("Error sending feedback:",ke)}return"Thanks for the feedback! Feel free to ask another question."}try{const ke=js();Ke=ke,Ne==null||Ne({type:"chatbot_question_sent",queryId:ke,questionLength:At.length});const Ge={"Content-Type":"application/json"};ce&&(Ge["X-API-KEY"]=ce);const $e=pe();$e&&(Ge["X-Session-ID"]=$e,Ge["X-Query-ID"]=ke),st&&(Ge["X-Acting-User"]=st);const bn={query:At,session_id:$e,question_id:ke};st&&(bn.acting_user=st),Vn("SENT to API",{session_id:$e,question_id:ke,acting_user:st||"(not set)"});const So=Date.now(),wn=await fetch(ee,{method:"POST",headers:Ge,body:JSON.stringify(bn)}),Bo=Date.now()-So;if(!wn.ok)throw new Error("API returned ".concat(wn.status));const Mt=await wn.json(),xn=Mt.response||Mt.answer||Mt.text||Mt.message;if(!xn)throw new Error("Invalid response format from API");const I=(le=>{if(!le||typeof le!="string")return le;let ae=le.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return ae=ae.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),_e=>{let Qe=_e,Se="";const wt=Qe.match(/([.,;:!?]+)$/);return wt&&(Se=wt[1],Qe=Qe.slice(0,-Se.length)),"[".concat(Qe,"](").concat(Qe,")").concat(Se)}),ae})(xn),G=function(le){const{confidence:ae,tools_used:_e,metadata:Qe}=le;if(!(ae||_e&&_e.length!==0))return"";const Se=[];return ae&&Se.push("• Confidence: ".concat(ae)),_e&&_e.length>0&&Se.push("• Tools used: ".concat(_e.join(", "))),Qe!=null&&Qe.agent&&Se.push("• Agent: ".concat(Qe.agent)),`---
39
39
  `.concat(Se.join(`
40
40
  `))}(Mt),K=G?"".concat(I,`
41
41