1(function(){"use strict";let l={backendUrl:"",realtimeUrl:"https://api.openai.com/v1/realtime/calls",model:"gpt-realtime-2",voice:"alloy",instructions:"You are a concise, friendly website guide.",maxVoiceConversationMs:9e5,voiceConversationLimitMessage:"Conversations are limited to 15 minutes, if you still have questions feel free to call the virtual sales agent again.",voiceSilencePromptMs:2e4,voiceSilenceCloseMs:1e4,voiceSilencePromptMessage:"Are you still there?",label:"Speak to sales",styleMode:"sales",greeting:"I'm your WriteText.ai assistant. Ask me anything \u2014 in any language. Go ahead, I'm listening.",chatGreeting:"Hi! I'm your WriteText.ai assistant. Ask me anything, in any language. How can I help?",greetingRate:1.05,replyRate:.95,brandName:"WriteText.ai",phoneIconUrl:"phone.svg",debugLogs:!1,showLogPane:!1,consoleDebugLogs:!1,verboseEventLogs:!1};const qt={sales:{headerTitle:"Ask WriteText.ai",selectHeading:'Get answers fast, <span style="font-weight:600">in any language</span>',voiceLabel:"Talk",triggerBackground:"linear-gradient(135deg, #0066CC, #0088EE)",primaryGradient:"linear-gradient(135deg, #0066CC, #0088EE)",primaryColor:"#0066CC",primaryHoverColor:"#0077DD",textColor:"#1a1a2e",idleCircleBackground:"linear-gradient(135deg, #1a1a2e, #16213e)",softBackground:"rgba(0,102,204,0.08)",softBorder:"1px solid rgba(0,102,204,0.16)",softSpinnerBorder:"3px solid rgba(0,102,204,0.18)",primaryShadow:"0 2px 10px rgba(0,102,204,0.22)",userBubbleShadow:"0 2px 12px rgba(0,102,204,0.25)",phoneDropShadow:"drop-shadow(0 0 6px rgba(0,102,204,0.45))",popupBorder:"1px solid rgba(200,210,230,0.50)",popupShadow:"0 24px 64px rgba(0,0,0,0.15), 0 0 0 1px rgba(200,210,230,0.50)",modeButtonBackground:"white",modeButtonBorder:"1px solid #e5e7eb",modeButtonIconColor:"#0066CC",modeButtonTextColor:"#1a1a2e",glowPulse:`0%, 100% { box-shadow: 0 0 0 0 rgba(0,102,204,0.55), 0 8px 32px rgba(0,102,204,0.35); } 2 50% { box-shadow: 0 0 0 10px rgba(0,102,204,0.10), 0 12px 40px rgba(0,102,204,0.35); }`,micGlowActive:`0% { box-shadow: 0 0 18px 8px rgba(249,218,221,0.65), 0 0 44px 20px rgba(249,218,221,0.25); } 3 50% { box-shadow: 0 0 28px 14px rgba(204,224,245,0.65), 0 0 56px 28px rgba(204,224,245,0.25); } 4 100% { box-shadow: 0 0 18px 8px rgba(249,218,221,0.65), 0 0 44px 20px rgba(249,218,221,0.25); }`},support:{headerTitle:"WriteText.ai Support",selectHeading:`We're here to help, <span style="font-weight:600">in any language</span>`,voiceLabel:"Talk",triggerBackground:"linear-gradient(135deg, rgb(26, 26, 26), rgb(96, 96, 96))",primaryGradient:"linear-gradient(135deg, rgb(26, 26, 26), rgb(96, 96, 96))",primaryColor:"#1A1A1A",primaryHoverColor:"#606060",textColor:"#1A1A1A",idleCircleBackground:"linear-gradient(135deg, #1A1A1A, #606060)",softBackground:"rgba(128,128,128,0.08)",softBorder:"1px solid rgba(128,128,128,0.16)",softSpinnerBorder:"3px solid rgba(128,128,128,0.18)",primaryShadow:"0 2px 10px rgba(128,128,128,0.22)",userBubbleShadow:"0 2px 12px rgba(128,128,128,0.25)",phoneDropShadow:"drop-shadow(0 0 6px rgba(128,128,128,0.45))",popupBorder:"1px solid rgba(210,210,210,0.50)",popupShadow:"0 24px 64px rgba(0,0,0,0.15), 0 0 0 1px rgba(210,210,210,0.50)",modeButtonBackground:"white",modeButtonBorder:"1px solid #e5e7eb",modeButtonIconColor:"#1A1A1A",modeButtonTextColor:"#1A1A1A",glowPulse:`0%, 100% { 5 box-shadow: 6 0 0 0 0 rgba(128, 128, 128, 0.55), 7 0 8px 32px rgba(128, 128, 128, 0.35); 8 } 9 50% { 10 box-shadow: 11 0 0 0 10px rgba(128, 128, 128, 0.10), 12 0 12px 40px rgba(128, 128, 128, 0.35); 13 }`,micGlowActive:`0% { box-shadow: 0 0 18px 8px rgba(128,128,128,0.38), 0 0 44px 20px rgba(128,128,128,0.16); } 14 50% { box-shadow: 0 0 28px 14px rgba(96,96,96,0.38), 0 0 56px 28px rgba(96,96,96,0.16); } 15 100% { box-shadow: 0 0 18px 8px rgba(128,128,128,0.38), 0 0 44px 20px rgba(128,128,128,0.16); }`}};function Qe(e){return String(e||"").toLowerCase()==="support"?"support":"sales"}function re(){return qt[Qe(l.styleMode)]}let n={isOpen:!1,isClosing:!1,isRinging:!1,isGreeting:!1,showEndConfirm:!1,conversationState:"idle",widgetMode:"select",sessionId:null,messages:[],audioLevel:0,interimTranscript:"",hasUserSpoken:!1,copied:!1,chatInput:"",chatSending:!1,showLangTooltip:!0,isMicMuted:!1},ke=null,se=null,J=null,k=null,ve=null,vt=!1,X=null,Ze=0,$=null,M=!1,K=null,m=null,h=null,et=null,Q=null,Me=null,Te=null,Z=null,le=!1,ce=!1,T=!1,Le=null,H=!1,Ae=null,Ie=null,E=!1,L=!1,P=!1,de="sales",A=null,N=null,Re=new Set,W=new Map,ye=!1,Ee=new Set,x=[];const yt=180;let I=0,q="",tt=!1;const nt=["Hello","Hola","Bonjour","Hallo","\u4F60\u597D","\u0645\u0631\u062D\u0628\u0627","Ciao","Ol\xE1","\u3053\u3093\u306B\u3061\u306F","\uC548\uB155\uD558\uC138\uC694","Hej","\u041F\u0440\u0438\u0432\u0435\u0442"];let Pe=0,xe=!0,ee=null,V,G,it,S,xt,Oe,pe,we,te,ue,ot,O,ne,U,fe,ie,wt,bt,Be,ge,be,B,C,Se,St,_e,oe,De,_;function Gt(){if(document.getElementById("vcw-styles"))return;var e=re();const t=document.createElement("style");t.id="vcw-styles",t.textContent=` 16 @import url('https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700;800&display=swap'); 17 .vcw-root, .vcw-root * { box-sizing: border-box; margin: 0; padding: 0; } 18 .vcw-root { font-family: 'Manrope', sans-serif; -webkit-font-smoothing: antialiased; } 19 @keyframes vcw-float-idle { 20 0%, 100% { transform: translateY(0px); } 21 50% { transform: translateY(-5px); } 22 } 23 @keyframes vcw-glow-pulse { 24 ${e.glowPulse} 25 } 26 @keyframes vcw-popup-expand { 27 from { opacity: 0; transform: scale(0.5) translateY(16px); transform-origin: bottom right; } 28 to { opacity: 1; transform: scale(1) translateY(0); transform-origin: bottom right; } 29 } 30 @keyframes vcw-popup-collapse { 31 from { opacity: 1; transform: scale(1) translateY(0); transform-origin: bottom right; } 32 to { opacity: 0; transform: scale(0.5) translateY(16px); transform-origin: bottom right; } 33 } 34 @keyframes vcw-mic-glow-active { 35 ${e.micGlowActive} 36 } 37 @keyframes vcw-waiting-ring { 38 0% { transform: scale(1); opacity: 0.7; } 39 70% { transform: scale(1.7); opacity: 0; } 40 100% { transform: scale(1.7); opacity: 0; } 41 } 42 @keyframes vcw-thinking-pulse { 43 0%, 100% { transform: scale(0.7); opacity: 0.3; background: ${e.primaryColor}; } 44 50% { transform: scale(1.15); opacity: 1; background: ${e.primaryHoverColor}; } 45 } 46 @keyframes vcw-phone-vibrate { 47 0% { transform: rotate(0deg) translateX(0); } 48 15% { transform: rotate(-12deg) translateX(-3px); } 49 30% { transform: rotate(12deg) translateX(3px); } 50 45% { transform: rotate(-10deg) translateX(-2px); } 51 60% { transform: rotate(10deg) translateX(2px); } 52 75% { transform: rotate(-6deg) translateX(-1px); } 53 90% { transform: rotate(6deg) translateX(1px); } 54 100% { transform: rotate(0deg) translateX(0); } 55 } 56 @keyframes vcw-shimmer { 57 0% { background-position: -200% center; } 58 100% { background-position: 200% center; } 59 } 60 @keyframes vcw-spin { to { transform: rotate(360deg); } } 61 @keyframes vcw-msg-in-user { 62 from { opacity: 0; transform: translateX(12px); } 63 to { opacity: 1; transform: translateX(0); } 64 } 65 @keyframes vcw-msg-in-ai { 66 from { opacity: 0; transform: translateX(-12px); } 67 to { opacity: 1; transform: translateX(0); } 68 } 69 @keyframes vcw-fade-in { 70 from { opacity: 0; transform: translateY(4px); } 71 to { opacity: 1; transform: translateY(0); } 72 } 73 .vcw-mic-glow-active { animation: vcw-mic-glow-active 1.4s ease-in-out infinite; } 74 .vcw-mic-waiting-pulse { animation: vcw-glow-pulse 1.8s ease-in-out infinite; } 75 .vcw-copy-btn { transition: background 0.2s ease; } 76 .vcw-copy-btn:hover { background: rgba(255,255,255,0.30) !important; } 77 .vcw-chat-messages { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.15) transparent; } 78 .vcw-chat-messages::-webkit-scrollbar { width: 4px; } 79 .vcw-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; } 80 .vcw-chat-input:focus { outline: none; box-shadow: 0 0 0 2px ${e.primaryColor}; } 81 .vcw-send-btn:hover:not(:disabled) { opacity: 0.9; } 82 .vcw-send-btn:active:not(:disabled) { transform: scale(0.95); } 83 .vcw-send-btn:disabled { opacity: 0.4;
83 cursor: not-allowed; } 84 .vcw-mode-btn { transition: all 0.2s ease; } 85 .vcw-mode-btn:hover { transform: scale(1.03); } 86 .vcw-mode-btn:active { transform: scale(0.97); } 87 .vcw-log-pane { 88 flex-shrink: 0; 89 border-top: 1px solid rgba(0,0,0,0.08); 90 background: #0f172a; 91 color: #e2e8f0; 92 padding: 10px 12px; 93 max-height: 148px; 94 display: flex; 95 flex-direction: column; 96 gap: 8px; 97 } 98 .vcw-log-pane.vcw-hidden { display: none; } 99 .vcw-log-title { 100 font-size: 10px; 101 font-weight: 700; 102 letter-spacing: 0.08em; 103 text-transform: uppercase; 104 opacity: 0.85; 105 } 106 .vcw-log-lines { 107 overflow-y: auto; 108 max-height: 108px; 109 font-size: 10px; 110 line-height: 1.45; 111 font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 112 display: flex; 113 flex-direction: column; 114 gap: 4px; 115 } 116 .vcw-log-line { 117 white-space: pre-wrap; 118 word-break: break-word; 119 opacity: 0.92; 120 } 121 `,document.head.appendChild(t)}function a(e,t,i){const o=document.createElement(e);return t&&Object.keys(t).forEach(r=>{r==="style"&&typeof t[r]=="object"?Object.assign(o.style,t[r]):r==="className"?o.className=t[r]:r.startsWith("on")&&typeof t[r]=="function"?o.addEventListener(r.slice(2).toLowerCase(),t[r]):o.setAttribute(r,t[r])}),i&&(typeof i=="string"?o.textContent=i:Array.isArray(i)?i.forEach(r=>r&&o.appendChild(r)):o.appendChild(i)),o}function Ce(){return Math.random().toString(36).slice(2,9)}function Ct(e){return e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Ne(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Ut(e){const t=String(e??""),i=/(https?:\/\/[^\s<]+|(?:writetext\.ai|writext\.ai|wordpress\.org)\/[^\s<]+)/gi;let o=0,r="",p;for(;(p=i.exec(t))!==null;){const s=p[0],u=p.index,g=s.endsWith("."),d=g?s.slice(0,-1):s;r+=Ne(t.slice(o,u));const b=/^https?:\/\//i.test(d)?d:`https://${d}`;r+=`<a href="${Ne(b)}" target="_blank" rel="noopener noreferrer">${Ne(d)}</a>`,g&&(r+="."),o=u+s.length}return r+=Ne(t.slice(o)),r}function F(e,t,i,o,r,p){const s=document.createElementNS("http://www.w3.org/2000/svg","svg");return s.setAttribute("viewBox",e),s.setAttribute("width",t),s.setAttribute("height",i),s.setAttribute("fill","none"),r&&(s.setAttribute("stroke",r),s.setAttribute("stroke-width",p||"2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round")),s.innerHTML=o,s}function Ve(e,t){return F("0 0 24 24",e,e,'<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" x2="12" y1="19" y2="22"/>',t,"2")}function kt(e,t){return F("0 0 24 24",e,e,'<path d="M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91"/><line x1="23" x2="1" y1="1" y2="23"/>',t,"2")}function Yt(e,t){return F("0 0 24 24",e,e,'<line x1="18" x2="6" y1="6" y2="18"/><line x1="6" x2="18" y1="6" y2="18"/>',t,"2")}function Mt(e,t){return F("0 0 24 24",e,e,'<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>',t,"2")}function Jt(e,t){return F("0 0 24 24",e,e,'<polyline points="20 6 9 17 4 12"/>',t,"2")}function Xt(e,t){return F("0 0 24 24",e,e,'<line x1="22" x2="11" y1="2" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>',t,"2")}function $t(e,t){return F("0 0 24 24",e,e,'<polyline points="4 7 9 12 4 17"/><line x1="11" x2="20" y1="18" y2="18"/>',t,"2")}function Kt(e,t){return F("0 0 24 24",e,e,'<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>',t,"1.6")}function Qt(e,t){return F("0 0 24 24",e,e,'<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',t,"1.6")}function he(){return l.backendUrl||window.location.origin}function Zt(){return{pageUrl:window.location.href,referrer:document.referrer||"",userAgent:navigator.userAgent||"",language:navigator.language||"",timeZone:(Intl&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().timeZone:"")||"",origin:window.location.origin||""}}async function en(e){if(!(!N||!e))try{await fetch(he()+"/api/sessions/"+encodeURIComponent(N)+"/realt
121ime",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callId:e})})}catch(t){c("Failed to persist realtime call id",t&&t.message||String(t))}}async function Fe(e){if(!(!N||!e||!e.id||!e.content)&&!Re.has(e.id)){Re.add(e.id);try{await fetch(he()+"/api/sessions/"+encodeURIComponent(N)+"/messages",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messageId:e.id,role:e.role,content:e.content})})}catch(t){Re.delete(e.id),c("Failed to persist conversation message",t&&t.message||String(t))}}}async function ze(e,t){if(!(!N||!e))try{await fetch(he()+"/api/sessions/"+encodeURIComponent(N)+"/status",{method:"POST",headers:{"Content-Type":"application/json"},keepalive:!0,body:JSON.stringify({status:e,endReason:t||null})})}catch(i){c("Failed to persist conversation status",i&&i.message||String(i))}}function at(e){Z&&(clearTimeout(Z),Z=null);const t=Te;Me=null,Te=null,e&&t&&t(e)}function rt(e){Z&&(clearTimeout(Z),Z=null);const t=Me;Me=null,Te=null,t&&t(e||"")}function st(){le&&M&&n.widgetMode==="chat"&&(!h||h.readyState!=="open"||(le=!1,n.chatSending=!0,n.conversationState="processing",ae(["text"]),c("Initial chat response.create sent"),f()))}function tn(e){var t=typeof e=="number"?e:1e4;return new Promise(function(i,o){var r=Date.now();function p(){var s=!!h&&h.readyState==="open",u=!!Q;if(M&&s&&u){i();return}if(Date.now()-r>=t){o(new Error("Timed out waiting for voice session readiness"));return}setTimeout(p,50)}p()})}async function nn(e){const t=await fetch(he()+"/api/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:e,widget:"dual",metadata:Zt()})});if(!t.ok){const o=await t.text();throw c("Token request failed ("+t.status+")",o),new Error("Token request failed: "+t.status+" "+o)}var i=await t.json();return c("Token received",{model:i&&i.model,hasVectorStore:!!(i&&i.vectorStoreId),voice:i&&i.voice,activeAgent:i&&i.activeAgent}),N=i&&i.sessionDocumentId||null,de=ct(i&&i.activeAgent||"sales")||"sales",i}function on(){return!m||m.iceGatheringState==="complete"?Promise.resolve():new Promise(function(e){function t(){(!m||m.iceGatheringState==="complete")&&(m&&m.removeEventListener("icegatheringstatechange",t),e())}m.addEventListener("icegatheringstatechange",t)})}async function an(e,t){c("Exchanging SDP with realtime endpoint");const i=await fetch(l.realtimeUrl,{method:"POST",headers:{"Content-Type":"application/sdp",Authorization:"Bearer "+e},body:t});if(!i.ok){const s=await i.text();throw c("SDP exchange failed ("+i.status+")",s),new Error("SDP exchange failed: "+i.status+" "+s)}const o=i.headers.get("Location")||i.headers.get("location"),r=o?o.split("/").filter(Boolean).pop():null;return{answer:await i.text(),callId:r}}async function rn(e,t){const i=e.token;if(!i)throw new Error("Missing token in /api/token response");m=new RTCPeerConnection({iceServers:[],bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"}),m.ontrack=function(s){K||(K=new MediaStream),s.streams[0].getAudioTracks().forEach(function(u){K.addTrack(u)}),oe&&(oe.srcObject=K,oe.play().catch(function(){}))},m.oniceconnectionstatechange=function(){m&&(c("ICE state: "+(m.iceConnectionState||"unknown")),(m.iceConnectionState==="failed"||m.iceConnectionState==="disconnected")&&(n.conversationState="idle",f()))},h=m.createDataChannel("oai-events"),h.onopen=function(){c("Data channel ready"),st()},h.onmessage=function(s){Tn(s.data)},t==="voice"&&k?k.getTracks().forEach(function(s){m.addTrack(s,k)}):m.addTransceiver("audio",{direction:"recvonly"});const o=await m.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!1});await m.setLocalDescription(o),await on();const r=m.localDescription&&m.localDescription.sdp;if(!r)throw new Error("Missing SDP offer");const p=await an(i,r);await m.setRemoteDescription({type:"answer",sdp:p.answer}),Q=p.callId||null,c("Remote SDP answer set"),Q&&(c("Received callId: "+Q),en(Q))}function lt(e){if(!e||e.type!=="message")return"";for(var t=e.content||[],i=0;i<t.length;i++){var o=t[i];if((o.type==="output_text"||o.type==="text")&&o.text)return String(o.text).trim()}return""}function sn(e){const t=e&&e.output||[];for(var i=0;i<t.length;i++){var o=lt(t[i]);if(o)return o}return""}
121function Y(e){n.isMicMuted=!!e,k&&k.getAudioTracks().forEach(function(t){t.enabled=!n.isMicMuted}),c(n.isMicMuted?"Microphone muted":"Microphone unmuted")}function ln(){Y(!n.isMicMuted),n.isMicMuted?n.conversationState="waiting":n.conversationState="listening",f()}function ae(e,t){if(!(!h||h.readyState!=="open")){var i=l.instructions||"You are a concise, friendly website guide.";t&&(i+=` 122 123`+t);var o={output_modalities:e,instructions:i};e.indexOf("audio")>=0&&(o.audio={output:{voice:l.voice}}),h.send(JSON.stringify({type:"response.create",response:o}))}}function ct(e){var t=String(e||"").trim().toLowerCase().replace(/[\s-]+/g,"_");return t==="howto"&&(t="how_to"),(t==="tech_support"||t==="techsupport")&&(t="technical_support"),["sales","support","technical_support","how_to","workflow"].indexOf(t)>=0?t:""}function dt(){Le&&(clearTimeout(Le),Le=null)}function Tt(){dt(),!(!l.maxVoiceConversationMs||l.maxVoiceConversationMs<=0)&&(Le=setTimeout(function(){hn()},l.maxVoiceConversationMs),c("Voice conversation limit timer started",{ms:l.maxVoiceConversationMs}))}function je(){Ae&&(clearTimeout(Ae),Ae=null)}function pt(){Ie&&(clearTimeout(Ie),Ie=null)}function D(){je(),pt()}function ut(e){return String(e||"").toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim()}function cn(e){var t=ut(e);return/\b(anything else|any other questions|any more questions|more questions|other questions|help with anything else|help you with anything else|have any more questions|do you have any more questions)\b/.test(t)}function dn(e){var t=ut(e);return/\b(no|nope|nah|that s all|thats all|no that s all|no thats all|no thank you|no thanks|nothing else|no more questions|i don t have any more questions|i dont have any more questions)\b/.test(t)}function pn(e){var t=ut(e);return/\b(goodbye|bye bye|bye|see you|see ya|talk to you later|have a nice day)\b/.test(t)?!0:/\b(thank you|thanks|thank you very much|thanks a lot)\b/.test(t)&&/\b(goodbye|bye|see you|have a nice day)\b/.test(t)}function He(e){D(),E=!1,L=!1,P=!1,Y(!0),n.widgetMode==="voice"&&n.conversationState!=="idle"&&(n.conversationState="waiting"),c(e||"Microphone muted automatically"),f()}function Lt(){je(),!(!M||n.widgetMode!=="voice"||n.isMicMuted)&&(T||H||E||L||n.isRinging||n.conversationState==="speaking"||n.conversationState==="processing"||!l.voiceSilencePromptMs||l.voiceSilencePromptMs<=0||(Ae=setTimeout(function(){fn()},l.voiceSilencePromptMs),c("Voice silence prompt timer started",{ms:l.voiceSilencePromptMs})))}function un(){pt(),!(!l.voiceSilenceCloseMs||l.voiceSilenceCloseMs<=0)&&(Ie=setTimeout(function(){He("No reply after still-there prompt; microphone muted automatically")},l.voiceSilenceCloseMs),c("Voice silence close timer started",{ms:l.voiceSilenceCloseMs}))}function At(e){n.widgetMode!=="voice"||!e||(P=cn(e),P&&c("Assistant asked whether there are more questions"))}function fn(){if(je(),!(!M||n.widgetMode!=="voice"||n.isMicMuted)&&!(T||H||E||L)){if(c("Voice silence threshold reached; asking if visitor is still there"),E=!0,L=!1,P=!1,n.conversationState="speaking",f(),!h||h.readyState!=="open"){He("Realtime channel unavailable during still-there prompt; microphone muted automatically");return}ae(["audio"],"Say exactly this message and nothing else: "+l.voiceSilencePromptMessage)}}function gn(e){if(!(n.widgetMode!=="voice"||!e)){if(je(),L&&(L=!1,pt(),c("Visitor replied after still-there prompt")),pn(e)){He("Visitor said goodbye; microphone muted automatically");return}if(P&&dn(e)){He("Visitor indicated there are no more questions; microphone muted automatically");return}P=!1}}function It(e){if(ht(),Bt(),ke&&(ke.close().catch(function(){}),ke=null),Ee.clear(),n.showEndConfirm=!1,n.messages=[],n.sessionId=null,n.conversationState="idle",n.interimTranscript="",n.hasUserSpoken=!1,n.audioLevel=0,n.isRinging=!1,n.isGreeting=!1,n.copied=!1,n.widgetMode="select",n.chatInput="",n.chatSending=!1,n.isMicMuted=!1,le=!1,ce=!1,T=!1,H=!1,D(),E=!1,L=!1,P=!1,de="sales",A=null,N=null,Re.clear(),n.showLangTooltip=!0,$&&(clearTimeout($),$=null),e){n.isClosing=!0,f(),setTimeout(function(){n.isOpen=!1,n.isClosing=!1,f()},260);return}n.isOpen=!0,n.isClosing=!1,f()}function Rt(){c("Voice conversation limit playback finished; ending session"),ze("ended","time_limit_reached"),It(!1)}function hn(){if(dt(),D(),!(!M||n.widgetMode!=="voice"||H)){if(c("Voice conversation limit reached; sending final closing message"),H=!0,n.showEndConfirm=!1,n.isGreeting=!1,Y(!0),n.conversationState="speaking",f(),!h||h.readyState!=="open"){Rt();return}ae(["audio"],"Say exactly this message and nothing else: "+l.voiceConversationLimitMessage)}}function ft(e){return typeof e.arguments=="string"?JSON.parse(e.arguments||"{}"):e.arguments||{}}function z(e,t){!h||h.readyState!=="open"||!e||h.send(JSON.stringify({type:"conversation.item.create",item:{type:"function_call_output",call_id:e,output:JSON.stringify(t)}}))}function j(){ae(n.widgetMode==="chat"?["text"]:["audio"]),c("Follow-up response.create sent")}function mn(e){var t=typeof e=="string"?e.trim():"";if(!t)throw new Error("Missing url");var i;try{i=new URL(t,window.location.origin)}catch{throw new Error("Invalid url")}if(i.protocol!=="http:"&&i.protocol!=="https:")throw new Error("Only http and https links are allowed");return i.toString()}function Et(e){var t=null;try{t=window.open("","_blank")}catch{}if(t){try{t.opener=null}catch{}try{t.location.replace(e)}catch{t.location.href=e}return{opened:!0,blocked:!1,browserReturnedNull:!1,usedAnchorFallback:!1,windowHandleAvailable:!0}}var i=!1;try{var o=document.createElement("a");o.href=e,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",(document.body||document.documentElement).appendChild(o),o.click(),o.remove(),i=!0}catch{}return{opened:i,blocked:!i,browserReturnedNull:!0,usedAnchorFallback:i,windowHandleAvailable:!1}}function vn(){var e=navigator.userAgent||"",t=/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>
1231,i=/AppleWebKit/i.test(e),o=/CriOS|FxiOS|EdgiOS|OPiOS|YaBrowser/i.test(e);return!!(t&&i&&!o)}function yn(e){return!e||!e.opened?!0:vn()&&!e.windowHandleAvailable}function xn(e,t){A={url:e,label:t||"Open link"},f()}function Pt(){A=null}function wn(){if(!(!A||!A.url)){var e=Et(A.url);c("Manual link open tapped",{url:A.url,browserReturnedNull:e.browserReturnedNull,usedAnchorFallback:e.usedAnchorFallback}),e.opened&&(Pt(),f())}}function Ot(e){if(!A||!A.url)return null;var t=re(),i=A.label||"Open link";return a("div",{style:{display:"flex",flexDirection:e?"row":"column",alignItems:"center",justifyContent:"center",gap:e?"8px":"10px",padding:e?"0 12px":"10px 12px",maxWidth:e?"100%":"calc(100% - 24px)",borderRadius:"14px",background:t.softBackground,border:t.softBorder}},[a("div",{style:{fontSize:e?"11px":"12px",color:t.textColor,textAlign:"center",lineHeight:"1.4"}},e?"Tap to open the link":"Safari needs a direct tap to open this link."),a("button",{type:"button",style:{border:"none",borderRadius:"10px",padding:e?"7px 12px":"9px 14px",background:t.primaryGradient,color:"white",fontSize:e?"11px":"12px",fontWeight:"700",cursor:"pointer",boxShadow:t.primaryShadow},onClick:wn},i)])}async function bn(e){if(!(!h||h.readyState!=="open")){if(!et){c("Vector search requested without vectorStoreId"),z(e.call_id,{error:"Missing vectorStoreId"}),j();return}try{var t=ft(e),i=(t.query||"").trim(),o=Number(t.topK||2);c("Executing vector search",{query:i,topK:o});var r=await fetch(he()+"/api/vector-search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:i,topK:o,vectorStoreId:et})});if(!r.ok){var p=await r.text();throw new Error(p||"Vector search failed")}var s=await r.json();z(e.call_id,s&&s.results||[]),c("Function output sent",{results:(s&&s.results||[]).length}),j()}catch(u){c("Vector search failed",u&&u.message||String(u)),z(e.call_id,{error:u&&u.message||String(u)}),j()}}}async function Sn(e){if(!(!h||h.readyState!=="open"))try{var t=ft(e),i=mn(t.url),o=typeof t.label=="string"?t.label.trim():"";c("Opening link",{url:i,label:o||null});var r=Et(i),p=yn(r);p?xn(i,o||"Open link"):Pt(),z(e.call_id,{opened:r.opened,blocked:r.blocked,browserReturnedNull:r.browserReturnedNull,usedAnchorFallback:r.usedAnchorFallback,windowHandleAvailable:r.windowHandleAvailable,userActionRequired:p,url:i,label:o||null}),r.opened?c("Link open attempted in new tab",{url:i,browserReturnedNull:r.browserReturnedNull,usedAnchorFallback:r.usedAnchorFallback,userActionRequired:p}):c("Link open was blocked by the browser",{url:i}),j()}catch(s){c("Open link failed",s&&s.message||String(s)),z(e.call_id,{error:s&&s.message||String(s)}),j()}}async function Cn(e){if(!(!h||h.readyState!=="open")){if(!N){z(e.call_id,{error:"Missing sessionDocumentId"}),j();return}try{var t=ft(e),i=ct(t.agent);if(!i)throw new Error("Invalid agent");var o=typeof t.reason=="string"?t.reason.trim():"";c("Routing to specialist agent",{agent:i,reason:o||null});var r=await fetch(he()+"/api/sessions/"+encodeURIComponent(N)+"/route-agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:i,previousAgent:de||null,reason:o||null,source:"tool"})});if(!r.ok){var p=await r.text();throw new Error(p||"Agent routing failed")}var s=await r.json();de=ct(s&&s.activeAgent||i)||i,s&&s.instructions&&(l.instructions=s.instructions),z(e.call_id,{activeAgent:de,switched:!0,reason:o||null}),c("Active agent updated",{activeAgent:de}),j()}catch(u){c("Agent routing failed",u&&u.message||String(u)),z(e.call_id,{error:u&&u.message||String(u)}),j()}}}async function kn(e){c("Unknown function call requested",{name:e&&e.name,arguments:e&&e.arguments}),z(e&&e.call_id,{error:"Unsupported function: "+(e&&e.name||"unknown")}),j()}function We(e){if(e){var t=n.messages[n.messages.length-1];if(!(t&&t.role==="assistant"&&t.content===e)){var i={id:Ce(),role:"assistant",content:e,timestamp:new Date};n.messages.push(i),Fe(i),At(e),T||(n.isGreeting=!1),n.widgetMode==="chat"&&(n.chatSending=!1,rt(e),me()),f()}}}function qe(e,t,i){if(!(!e||!t)){var o=W.get(e),r=null;if(o){for(var p=n.messages.length-1;p>=0;p--)if(n.messages[p].id===o){r=n.messages[p];break}}r||(o=Ce(),r={id:o,role:"assistant",content:"",timestamp:new Date},n.messages.push(r),W.set(e,o)),r.content=i?t:r.content+t,T||(n.isGreeting=!1),n.widgetMode==="chat"?(n.chatSending=!1,me(),Mn()):f()}}function gt(e){var t=null,i=e?W.get(e):null;if(i){for(var o=n.messages.length-1;o>=0;o--)if(n.messages[o].id===i){t=n.messages[o];break}}if(e&&W.delete(e),t&&t.content&&(Fe(t),At(t.content)),n.widgetMode==="chat"){var r=n.messages[n.messages.length-1];r&&r.role==="assistant"&&r.content&&rt(r.content)}}function Mn(){ye||(ye=!0,requestAnimationFrame(function(){ye=!1,n.widgetMode==="chat"&&Xe()}))}function Tn(e){var t;try{t=JSON.parse(e)}catch{c("Received non-JSON event frame");return}if(l.verboseEventLogs&&t.type!=="response.audio.delta"&&t.type!=="response.output_audio.delta"&&c("Event: "+t.type,t),t.type==="input_audio_buffer.speech_started"){D(),n.widgetMode==="voice"&&!n.isMicMuted&&(n.conversationState="listening",f());return}if(t.type==="input_audio_buffer.speech_stopped"){D(),n.widgetMode==="voice"&&(n.conversationState="processing",f());return}if(t.type==="conversation.item.input_audio_transcription.completed"){var i=(t.transcript||"").trim();if(!i)return;gn(i),n.hasUserSpoken=!0;var o={id:Ce(),role:"user",content:i,timestamp:new Date};n.messages.push(o),Fe(o),n.isGreeting=!1,f();return}if(t.type==="response.created"){D(),n.conversationState="processing",f();return}if(t.type==="response.audio_transcript.delta"||t.type==="response.output_audio_transcript.delta"){D(),n.widgetMode==="voice"&&(n.conversationState="speaking",f());return}if(t.type==="output_audio_buffer.stopped"){if(n.widgetMode==="voice"){if(T&&(T=!1,n.isGreeting=!1,Y(!1),c("Initial voice greeting playback finished; microphone unmuted")),H){H=!1,Rt();return}if(E){E=!1,L=!0,n.conversationState="listening",c("Still-there prompt playback finished; waiting for visitor reply"),un(),f();return}n.conversationState=n.isMicMuted?"waiting":"listening",n.isMicMuted||Lt(),f()}return}if(!(t.type==="response.audio.done"||t.type==="response.output_audio.done")){if(t.type==="response.audio_transcript.done"||t.type==="response.output_audio_transcript.done"){var r=(t.transcript||"").trim();We(r);return}if(t.type==="response.text.delta"||t.type==="response.output_text.delta"){var p=t.delta||"";p&&t.item_id&&qe(t.item_id,p,!1);return}if(t.type==="response.text.done"||t.type==="response.output_text.done"){var s=(t.text||"").trim();s&&t.item_id&&(qe(t.item_id,s,!0),gt(t.item_id));return}if(t.type==="response.output_item.done"){var u=t.item||null;if(u&&u.type==="function_call"){c("Function call output item completed",{name:u.name,call_id:u.call_id,status:u.status}),n.widgetMode==="chat"&&(n.conversationState="processing",n.chatSending=!0,me(),f());return}var g=lt(t.item);if(g){var d=t.item&&t.item.id;d&&W.has(d)?(qe(d,g,!0),gt(d)):We(g)}return}if(t.type==="response.done"){c("Response done",t);for(var w=t.response&&t.response.output||[],b=!1,R=0;R<w.length;R++){var y=w[R];y.type==="function_call"&&(b=!0,y.name==="search"?(c("Function call requested: search",y.arguments),bn(y)):y.name==="route_agent"?(c("Function call requested: route_agent",y.arguments),Cn(y)):y.name==="open_link"?(c("Function call requested: open_link",y.arguments),Sn(y)):kn(y))}var v=sn(t.response);if(v){var mt=w.filter(function(Ke){return Ke&&Ke.type==="message"&<(Ke)});if(mt.length>0){var Fn=mt[mt.length-1],$e=Fn.id;$e&&W.has($e)?(qe($e,v,!0),gt($e)):We(v)}else We(v)}n.widgetMode==="chat"&&(b&&!v?(n.conversationState="processing",n.chatSending=!0):(n.conversationState="waiting",n.chatSending=!1,v||rt("")),f());return}t.type==="error"&&(c("Realtime error event",t),at(new Error("Realtime error")),ze("failed","realtime_error"),n.chatSending=!1,n.conversationState="idle",f())}}async function Ge(e){if(!M)try{c("Starting realtime session",{mode:e}),n.conversationState="connecting",f(),e==="voice"&&!k&&(k=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0},video:!1}
123),n.isMicMuted&&k.getAudioTracks().forEach(function(i){i.enabled=!1}),c("Microphone granted"),Rn(k));var t=await nn(e);et=t.vectorStoreId||null,t.model&&(l.model=t.model),t.voice&&(l.voice=t.voice),t.instructions&&(l.instructions=t.instructions),await rn(t,e),M=!0,n.sessionId=Q||Ce(),n.conversationState=e==="chat"?"waiting":"listening",vt=!0,e==="voice"?(n.isGreeting=!0,ce?c("Deferring initial voice response.create until ringing completes"):(Tt(),ae(["audio"],"Start with the suggested opening"),c("Initial response.create sent"))):(Y(!0),st()),c("Connected with model "+l.model),f()}catch(i){c("Realtime start failed",i&&i.message||String(i)),ze("failed","session_start_failed"),ht(),n.conversationState="idle",f()}}function ht(){if(c("Stopping realtime session"),M=!1,vt=!1,at(),W.clear(),ye=!1,le=!1,ce=!1,T=!1,dt(),H=!1,D(),E=!1,L=!1,P=!1,h)try{h.close()}catch{}if(m)try{m.close()}catch{}h=null,m=null,Q=null,K&&(K.getTracks().forEach(function(e){e.stop()}),K=null),oe&&(oe.srcObject=null),En(),n.isMicMuted=!1}async function Ln(e){if(!h||h.readyState!=="open")throw new Error("Realtime channel is not ready");return new Promise(function(t,i){Me=t,Te=i,Z=setTimeout(function(){at(new Error("Chat response timeout"))},25e3),h.send(JSON.stringify({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:e}]}})),ae(["text"])})}function An(){try{const e=new(window.AudioContext||window.webkitAudioContext);ke=e;const t=.4,i=.2,o=.8,r=[0,t+i,t+i+t+o,t+i+t+o+t+i];return r.forEach(function(p){var s=e.currentTime+p;[440,480].forEach(function(u){var g=e.createOscillator(),d=e.createGain();g.type="sine",g.frequency.value=u,d.gain.setValueAtTime(0,s),d.gain.linearRampToValueAtTime(.18,s+.02),d.gain.setValueAtTime(.18,s+t-.02),d.gain.linearRampToValueAtTime(0,s+t),g.connect(d),d.connect(e.destination),g.start(s),g.stop(s+t)})}),r[3]+t}catch{return 1.2}}function In(e){if(X)return;const t=e.getContext("2d");if(!t)return;const i=window.devicePixelRatio||1;e.width=e.offsetWidth*i,e.height=e.offsetHeight*i,t.scale(i,i);const o=e.offsetWidth,r=e.offsetHeight,p=[{tm:4,amp:28,wl:.018,lw:1.5,c:"rgba(255,255,255,0.90)",ph:0},{tm:2,amp:18,wl:.022,lw:1.2,c:"rgba(255,255,255,0.65)",ph:1.2},{tm:1,amp:12,wl:.014,lw:1,c:"rgba(255,255,255,0.50)",ph:2.4},{tm:3,amp:22,wl:.02,lw:1.3,c:"rgba(255,255,255,0.75)",ph:.6},{tm:1.5,amp:10,wl:.026,lw:.8,c:"rgba(255,255,255,0.40)",ph:3}];function s(){t.clearRect(0,0,e.width,e.height);var u=1+n.audioLevel*1.2;p.forEach(function(g){t.beginPath(),t.lineWidth=g.lw,t.strokeStyle=g.c;for(var d=0;d<=o;d+=2){var w=r/2+Math.sin(d*g.wl+Ze*g.tm+g.ph)*g.amp*u;d===0?t.moveTo(d,w):t.lineTo(d,w)}t.stroke()}),Ze+=.04,X=requestAnimationFrame(s)}s()}function Bt(){X&&(cancelAnimationFrame(X),X=null),Ze=0}function Rn(e){se=new(window.AudioContext||window.webkitAudioContext),J=se.createAnalyser(),J.fftSize=256,se.createMediaStreamSource(e).connect(J);var t=new Uint8Array(J.frequencyBinCount);function i(){J&&(J.getByteFrequencyData(t),n.audioLevel=t.reduce(function(o,r){return o+r},0)/t.length/128,jt(),ve=requestAnimationFrame(i))}ve=requestAnimationFrame(i)}function En(){ve&&(cancelAnimationFrame(ve),ve=null),se&&(se.close().catch(function(){}),se=null),J=null,k&&(k.getTracks().forEach(function(e){e.stop()}),k=null),n.audioLevel=0}async function _t(){var e=n.chatInput.trim();if(!(!e||n.chatSending)){n.chatInput="",n.chatSending=!0;var t={id:Ce(),role:"user",content:e,timestamp:new Date};n.messages.push(t),Fe(t),C&&(C.value=""),Xe(),me();try{M||await Ge("chat"),await Ln(e)}catch{}n.chatSending=!1,Xe(),me(),C&&C.focus()}}function Dt(){n.widgetMode="voice",n.isRinging=!0,T=!1,D(),E=!1,L=!1,P=!1,Y(!0),f();var e=An()*1e3+200,t=new Promise(function(o){setTimeout(o,e)});ce=!0;var i=(async function(){M&&!k&&ht(),await Ge("voice"),await tn(1e4)})();Promise.all([t,i]).then(function(){n.isRinging=!1,M&&(n.isGreeting=!0,T=!0,Y(!0),Tt(),ae(["audio"],"Start with the suggested opening"),c("Initial response.create sent"),n.conversationState="speaking"),ce=!1,f()}).catch(function(){ce=!1,n.isRinging=!1,f()})}async function Nt(){n.widgetMode="chat",M||await Ge("chat"),D(),E=!1,L=!1,P=!1,Y(!0),W.clear(),ye=!1,Ee.clear(),n.messages=[],le=!0,st(),f(),C&&C.focus()}function Ue(){n.isOpen=!0,n.isClosing=!1,n.widgetMode="select",n.showEndConfirm=!1,n.showLangTooltip=!0,f()}function Pn(){if(n.isOpen&&n.widgetMode==="voice"&&(n.conversationState!=="idle"||n.messages.filter(e=>e.role==="user").length>0)){n.showEndConfirm=!0,f();return}if(n.isOpen&&n.widgetMode==="chat"&&n.messages.filter(e=>e.role==="user").length>0){n.showEndConfirm=!0,f();return}Ye()}function Ye(){ze("ended","user_closed"),It(!0)}function On(){if(!M){Ge("voice");return}ln(),n.widgetMode==="voice"&&(n.isMicMuted?(D(),L=!1,E=!1,P=!1):Lt(
123))}function Bn(){if(n.messages.length===0)return;const e=n.messages.map(function(t){return"["+(t.role==="user"?"You":l.brandName)+" "+Ct(t.timestamp)+`] 124`+t.content}).join(` 125 126`);navigator.clipboard.writeText(e).then(function(){n.copied=!0,Vt(),$&&clearTimeout($),$=setTimeout(function(){n.copied=!1,Vt(),$=null},2e3)}).catch(function(){})}function Vt(){ge&&(ge.innerHTML="",n.copied?ge.appendChild(Jt(16,"#86efac")):ge.appendChild(Mt(16,"white")))}function me(){Se&&(Se.disabled=!n.chatInput.trim()||n.chatSending)}function c(e,t){if(l.debugLogs){var i=new Date().toLocaleTimeString(),o="["+i+"] "+e;if(t!==void 0)try{o+=" "+(typeof t=="string"?t:JSON.stringify(t))}catch{o+=" "+String(t)}x.push(o),x.length>yt&&(x=x.slice(x.length-yt)),l.consoleDebugLogs&&console.debug("[VoiceChatWidget]",o),_n()}}function _n(){tt||(tt=!0,requestAnimationFrame(function(){tt=!1,Je()}))}function Je(){if(!(!De||!_)){be&&(be.style.display=l.debugLogs?"flex":"none",be.style.opacity=l.showLogPane?"1":"0.8");var e=!!l.debugLogs&&!!l.showLogPane;if(De.classList.toggle("vcw-hidden",!e),!!e){if(x.length===0){_.innerHTML='<div class="vcw-log-line">No events yet.</div>',I=0,q="";return}I>x.length&&(I=0,q="",_.innerHTML="");var t=q!==(x[0]||"");if(I===x.length&&t&&(I=0,_.innerHTML=""),I===0)_.innerHTML=x.map(function(p){return'<div class="vcw-log-line">'+p.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")+"</div>"}).join(""),I=x.length,q=x[0]||"";else if(I<x.length){for(var i=document.createDocumentFragment(),o=I;o<x.length;o++){var r=document.createElement("div");r.className="vcw-log-line",r.textContent=x[o],i.appendChild(r)}_.appendChild(i),I=x.length,q||(q=x[0]||"")}_.scrollTop=_.scrollHeight}}}function Ft(e,t){var i=t||{};l.debugLogs=!!e,typeof i.showLogPane=="boolean"&&(l.showLogPane=i.showLogPane),typeof i.consoleDebugLogs=="boolean"&&(l.consoleDebugLogs=i.consoleDebugLogs),typeof i.verboseEventLogs=="boolean"&&(l.verboseEventLogs=i.verboseEventLogs),l.debugLogs||(x=[],I=0,q="",_&&(_.innerHTML="")),l.showLogPane&&(I=0,q=""),Je()}function Dn(){l.debugLogs&&(l.showLogPane=!l.showLogPane,Je())}function Nn(){ee||(Pe=0,xe=!0,ee=setInterval(()=>{xe=!1,zt(),setTimeout(()=>{Pe=(Pe+1)%nt.length,xe=!0,zt()},300)},1800))}function Vn(){ee&&(clearInterval(ee),ee=null)}function zt(){if(!fe)return;const e=fe.querySelector("span");e&&(e.textContent=nt[Pe],e.style.opacity=xe?"1":"0",e.style.transform=xe?"translateY(0)":"translateY(-6px)")}function jt(){if(!O)return;const e=n.widgetMode==="voice"&&T&&n.conversationState==="speaking",t=n.widgetMode==="voice"&&n.isMicMuted&&n.conversationState!=="idle"&&!e,i=n.conversationState==="speaking"&&!t,o=n.conversationState==="listening"&&!t,r=t?1:i?1.25:o?1+n.audioLevel*.18:1;O.style.transform="scale("+r+")",ne&&ne.parentElement&&(ne.parentElement.style.opacity=i?"1":"0"),U&&(U.style.opacity=i?"0":"1"),O.classList.toggle("vcw-mic-glow-active",i||o),O.classList.toggle("vcw-mic-waiting-pulse",n.conversationState==="waiting"&&!t)}
126function Xe(){if(B){var e=re();B.innerHTML="";var t=n.widgetMode==="chat"&&n.messages.length===0&&!n.chatSending&&(le||n.conversationState==="connecting"||n.conversationState==="processing");if(t){var i=a("div",{style:{flex:"1",minHeight:"180px",display:"flex",alignItems:"center",justifyContent:"center"}}),o=a("div",{style:{width:"28px",height:"28px",border:e.softSpinnerBorder,borderTopColor:e.primaryColor,borderRadius:"50%",animation:"vcw-spin 1s linear infinite",display:"flex",alignItems:"center",justifyContent:"center"}});i.appendChild(o),B.appendChild(i),B.scrollTop=0;return}if(A){var r=a("div",{style:{display:"flex",justifyContent:"center"}});r.appendChild(Ot(!1)),B.appendChild(r)}if(n.messages.forEach(function(g){var d=g.role==="user",w=!Ee.has(g.id);w&&Ee.add(g.id);var b=a("div",{style:{display:"flex",flexDirection:"column",gap:"4px",alignItems:d?"flex-end":"flex-start",animation:w?d?"vcw-msg-in-user 0.3s ease":"vcw-msg-in-ai 0.3s ease":"none"}}),R=a("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"0 4px"}},[a("span",{style:{fontSize:"10px",fontWeight:"600",color:"#888",textTransform:"uppercase",letterSpacing:"0.08em"}},d?"You":l.brandName),a("span",{style:{fontSize:"10px",color:"rgba(136,136,136,0.6)"}},Ct(g.timestamp))]);b.appendChild(R);var y=a("div",{style:{maxWidth:"88%",borderRadius:"16px",padding:"10px 16px",fontSize:"13px",lineHeight:"1.6",background:d?e.primaryGradient:"rgba(0,0,0,0.04)",color:d?"white":e.textColor,borderTopRightRadius:d?"4px":"16px",borderTopLeftRadius:d?"16px":"4px",boxShadow:d?e.userBubbleShadow:"none",border:d?"none":"1px solid rgba(0,0,0,0.08)"}});d?y.textContent=g.content:y.innerHTML=Ut(g.content),b.appendChild(y),B.appendChild(b)}),n.chatSending){for(var p=a("div",{style:{display:"flex",alignItems:"flex-start"}}),s=a("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 16px"}}),u=0;u<3;u++)s.appendChild(a("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:e.primaryColor,animation:"vcw-thinking-pulse 1.2s ease-in-out infinite",animationDelay:u*.3+"s"}}));p.appendChild(s),B.appendChild(p)}B.scrollTop=B.scrollHeight}}function Ht(){_e&&(_e.style.display=n.showLangTooltip&&!n.chatInput?"flex":"none")}function f(){V||Wt();var e=re(),t=G.querySelector(".vcw-btn-icon");t&&(t.innerHTML="",n.isOpen?t.appendChild(n.widgetMode==="voice"?kt(24,"white"):Yt(24,"white")):t.appendChild(Ve(28,"white"))),G.style.animation=n.isOpen?"none":"vcw-float-idle 3.5s ease-in-out infinite, vcw-glow-pulse 2.2s ease-in-out infinite",it.style.display=n.isOpen?"none":"flex";var i=n.widgetMode==="chat"?"min(480px, calc(100vh - 112px))":"min(260px, calc(100vh - 112px))";n.isOpen||n.isClosing?(S.style.display="flex",S.style.height=i,S.style.animation=n.isClosing?"vcw-popup-collapse 0.25s cubic-bezier(0.4,0,0.6,1) forwards":"vcw-popup-expand 0.38s cubic-bezier(0.34,1.56,0.64,1) forwards"):S.style.display="none",Oe&&(Oe.textContent=re().headerTitle),ot.style.display=n.showEndConfirm?"flex":"none",pe.style.display=n.widgetMode==="select"?"flex":"none",we.style.display=n.widgetMode==="voice"&&n.isRinging?"flex":"none",te.style.display=n.widgetMode==="voice"&&!n.isRinging?"flex":"none",ue.style.display=n.widgetMode==="chat"?"flex":"none",Be&&(Be.style.display=(n.widgetMode==="voice"||n.widgetMode==="chat")&&!n.isRinging?"flex":"none");var o=n.conversationState==="speaking",r=n.widgetMode==="voice"&&T&&n.conversationState==="speaking",p=n.widgetMode==="voice"&&n.isMicMuted&&n.conversationState!=="idle"&&!r,s=n.conversationState==="idle"||p?e.idleCircleBackground:e.primaryGradient;if(O&&(O.style.background=s,O.style.cursor=o?"default":"pointer",jt(),o&&!X&&ne?In(ne):!o&&X&&Bt()),U)if(U.innerHTML="",n.conversationState==="processing"){var u=a("div",{style:{width:"20px",height:"20px",border:"2px solid rgba(255,255,255,0.4)",borderTopColor:"white",borderRadius:"50%",animation:"vcw-spin 1s linear infinite"}});U.appendChild(u)}else U.appendChild(Ve(24,"white"));if(fe){var g=n.conversationState==="speaking"&&n.isGreeting;fe.style.opacity=g?"1":"0",g&&!ee?Nn():!g&&ee&&Vn()}if(ie){if(ie.innerHTML="",A){var d=Ot(!0);d&&ie.appendChild(d)}else if(n.conversationState==="processing"){for(var w=a("div",{style:{display:"flex",alignItems:"center",gap:"8px"}}),b=0;b<3;b++)w.appendChild(a("div",{style:{width:"8px",height:"8px",borderRadius:"50%",background:e.primaryColor,animation:"vcw-thinking-pulse 1.2s ease-in-out infinite",animationDelay:b*.3+"s"}}));ie.appendChild(w)}else if(n.conversationState==="idle"){var R=n.messages.filter(function(y){return y.role==="user"}).length>0;ie.appendChild(a("p",{style:{fontSize:R?"11px":"12px",color:"#888"}},R?"Conversation paused":"Tap the mic to start"))}}n.widgetMode==="chat"&&(Xe(),Ht()),Je()}function Wt(){var e=re();V=a("div",{className:"vcw-root"});var t=a("div",{style:{position:"fixed",bottom:"24px",right:"34px",zIndex:"60",width:"64px",height:"64px"}});it=a("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none"}},[a("div",{style:{padding:"6px 12px",borderRadius:"12px",color:"white",fontSize:"12px",fontWeight:"600",whiteSpace:"nowrap",background:"#1a1a1a",boxShadow:"0 4px 14px rgba(0,0,0,0.35)",letterSpacing:"0.02em"}},l.label),a("div",{style:{width:"0",height:"0",borderLeft:"7px solid transparent",borderRight:"7px solid transparent",borderTop:"7px solid #1a1a1a"}})]),t.appendChild(it),G=a("button",{style:{width:"64px",height:"64px",borderRadius:"50%",border:"none",display:"flex",alignItems:"center",justifyContent:"center",background:e.triggerBackgroun
126d,boxShadow:"0 4px 24px rgba(0,0,0,0.25)",cursor:"pointer",transition:"transform 200ms cubic-bezier(0.34,1.56,0.64,1)"},onClick:function(){n.isOpen?Pn():Ue()}},[a("div",{className:"vcw-btn-icon"},Ve(28,"white"))]),G.onmouseenter=function(){G.style.transform="scale(1.1)"},G.onmouseleave=function(){G.style.transform="scale(1)"},t.appendChild(G),V.appendChild(t),S=a("div",{style:{position:"fixed",bottom:"88px",right:"16px",zIndex:"50",width:"min(360px, calc(100vw - 32px))",height:"min(260px, calc(100vh - 112px))",borderRadius:"24px",overflow:"hidden",display:"none",flexDirection:"column",background:"rgba(255,255,255,0.90)",backdropFilter:"blur(28px) saturate(200%)",WebkitBackdropFilter:"blur(28px) saturate(200%)",border:e.popupBorder,boxShadow:e.popupShadow,transition:"height 0.3s cubic-bezier(0.34, 1.56, 0.64, 1)"}}),Oe=a("p",{style:{color:"white",fontWeight:"600",fontSize:"14px"}},e.headerTitle);var i=a("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:"12px"}},[Oe]);ge=a("div",{style:{display:"flex",alignItems:"center",justifyContent:"center"}},Mt(16,"white")),Be=a("button",{className:"vcw-copy-btn",style:{width:"32px",height:"32px",borderRadius:"50%",border:"none",background:"rgba(255,255,255,0.20)",cursor:"pointer",display:"none",alignItems:"center",justifyContent:"center"},title:"Copy transcript",onClick:Bn},ge),be=a("button",{className:"vcw-copy-btn",style:{width:"32px",height:"32px",borderRadius:"50%",border:"none",background:"rgba(255,255,255,0.20)",cursor:"pointer",display:"none",alignItems:"center",justifyContent:"center"},title:"Toggle logs",onClick:Dn},$t(14,"white")),bt=a("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:"6px"}},[be,Be]),xt=a("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 20px",height:"48px",flexShrink:"0",position:"relative",overflow:"hidden",background:e.triggerBackground}},[a("div",{style:{position:"absolute",inset:"0",opacity:"0.2",pointerEvents:"none",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent)",backgroundSize:"200% 100%",animation:"vcw-shimmer 3s ease-in-out infinite"}}),i,bt]),S.appendChild(xt),ot=a("div",{style:{position:"absolute",inset:"0",zIndex:"10",display:"none",alignItems:"center",justifyContent:"center",padding:"24px",background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)"}},[a("div",{style:{width:"100%",borderRadius:"16px",padding:"24px",display:"flex",flexDirection:"column",gap:"16px",textAlign:"center",background:"white",border:"1px solid #e5e7eb"}},[a("div",{style:{width:"48px",height:"48px",borderRadius:"50%",margin:"0 auto",display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(239,68,68,0.12)"}},kt(20,"#ef4444")),a("div",{},[a("p",{style:{fontWeight:"600",fontSize:"14px",marginBottom:"4px"}},"End conversation?"),a("p",{style:{fontSize:"12px",color:"#888"}},"Are you sure you want to end this conversation?")]),a("div",{style:{display:"flex",gap:"8px"}},[a("button",{style:{flex:"1",padding:"10px",borderRadius:"12px",fontSize:"14px",fontWeight:"500",color:"#888",background:"transparent",border:"none",cursor:"pointer"},onClick:function(){n.showEndConfirm=!1,f()}},"Keep talking"),a("button",{style:{flex:"1",padding:"10px",borderRadius:"12px",fontSize:"14px",fontWeight:"600",color:"white",background:"linear-gradient(135deg, #ef4444, #dc2626)",border:"none",cursor:"pointer"},onClick:Ye},"End session")])])]),S.appendChild(ot),pe=a("div",{style:{flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"20px",padding:"16px 24px"}});var o=a("p",{style:{fontSize:"14px",fontWeight:"400",color:e.textColor,textAlign:"center"}});o.innerHTML=e.selectHeading,pe.appendChild(o);var r=a("div",{style:{display:"flex",gap:"12px",width:"100%"}}),p=a("button",{className:"vcw-mode-btn",style:{flex:"1",display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",padding:"20px 0",borderRadius:"16px",cursor:"pointer",background:e.modeButtonBackground,border:e.modeButtonBorder,boxShadow:"0 2px 12px rgba(0,0,0,0.06)"},onClick:Dt},[Kt(32,e.modeButtonIconColor),a("span",{style:{color:e.modeButtonTextColor,fontSize:"13px",fontWeight:"600"}},e.voiceLabel)]);r.appendChild(p);var s=a("button",{className:"vcw-mode-btn",style:{flex:"1",display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",padding:"20px 0",borderRadius:"16px",cursor:"pointer",background:e.modeButtonBackgroun
126d,border:e.modeButtonBorder,boxShadow:"0 2px 12px rgba(0,0,0,0.06)"},onClick:Nt},[Qt(32,e.modeButtonIconColor),a("span",{style:{color:e.modeButtonTextColor,fontSize:"13px",fontWeight:"600"}},"Chat")]);r.appendChild(s),pe.appendChild(r),pe.appendChild(a("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"11px",color:"#999",letterSpacing:"0.02em",marginTop:"4px"}},[a("span",{style:{color:"#999"}},"Powered by "+l.brandName),a("span",{style:{color:"#999"}},"\u2022"),a("a",{href:"https://platform.writetext.ai/privacy",target:"_blank",rel:"noopener noreferrer",style:{color:"#999",textDecoration:"underline",textUnderlineOffset:"2px",transition:"color 0.2s ease"},onMouseenter:function(v){v.currentTarget.style.color="#000"},onMouseleave:function(v){v.currentTarget.style.color="#999"}},"Privacy Policy")])),S.appendChild(pe),we=a("div",{style:{flex:"1",display:"none",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"16px",padding:"0 24px"}});var u=a("div",{style:{position:"relative",width:"80px",height:"80px",display:"flex",alignItems:"center",justifyContent:"center"}});u.appendChild(a("div",{style:{position:"absolute",width:"64px",height:"64px",borderRadius:"50%",border:"1px solid "+e.primaryColor,animation:"vcw-waiting-ring 1.4s ease-out infinite",opacity:"0.5"}})),u.appendChild(a("div",{style:{position:"absolute",width:"64px",height:"64px",borderRadius:"50%",border:"1px solid "+e.primaryColor,animation:"vcw-waiting-ring 1.4s ease-out 0.5s infinite",opacity:"0.3"}}));var g=a("div",{style:{animation:"vcw-phone-vibrate 0.35s ease-in-out infinite",position:"relative",zIndex:"1"}}),d=a("img");d.setAttribute("src",l.phoneIconUrl),d.setAttribute("width","40"),d.setAttribute("height","40"),d.setAttribute("alt","Phone ringing"),d.style.filter=e.phoneDropShadow,g.appendChild(d),u.appendChild(g),we.appendChild(u),we.appendChild(a("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"}},[a("p",{style:{fontSize:"14px",fontWeight:"600",color:e.textColor}},"Calling "+l.brandName+" digital assistant"),a("p",{style:{fontSize:"11px",color:"#888"}},"Connecting...")])),S.appendChild(we),te=a("div",{style:{flex:"1",position:"relative",display:"none",flexDirection:"column"}}),fe=a("div",{style:{position:"absolute",top:"calc(50% - 10px)",left:"50%",transform:"translate(-50%, -74px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2",opacity:"0",transition:"opacity 300ms ease",pointerEvents:"none"}},[a("span",{style:{fontSize:"clamp(1rem, 4vw, 1.25rem)",fontWeight:"500",background:e.primaryGradient,WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text",display:"block",minWidth:"8ch",textAlign:"center",transition:"opacity 0.28s ease, transform 0.28s ease"}},nt[0])]),te.appendChild(fe);var w=a("div",{style:{position:"absolute",top:"calc(50% - 10px)",left:"50%",transform:"translate(-50%, -50%)",width:"64px",height:"64px",zIndex:"1"}});O=a("div",{style:{width:"64px",height:"64px",borderRadius:"50%",background:e.primaryGradient,overflow:"hidden",position:"relative",cursor:"pointer",transition:"transform 200ms cubic-bezier(0.4,0,0.2,1), background 200ms ease, box-shadow 200ms ease",boxShadow:"0 2px 12px rgba(0,0,0,0.08)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:On});var b=a("div",{style:{position:"absolute",inset:"0",opacity:"0",transition:"opacity 150ms ease",pointerEvents:"none"}});ne=a("canvas",{style:{width:"100%",height:"100%",position:"absolute",inset:"0"}}),b.appendChild(ne),O.appendChild(b),U=a("div",{style:{position:"relative",zIndex:"1",opacity:"1",transition:"opacity 150ms ease",display:"flex",alignItems:"center",justifyContent:"center"}},Ve(24,"white")),O.appendChild(U),w.appendChild(O),te.appendChild(w),ie=a("div",{style:{position:"absolute",bottom:"20px",left:"0",right:"0",display:"flex",alignItems:"center",justifyContent:"center",height:"36px",zIndex:"2"}}),te.appendChild(ie),wt=a("div",{style:{position:"absolute",bottom:"7px",left:"0",right:"0",display:"flex",justifyContent:"center",zIndex:"2"}},[a("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"11px",color:"#999",letterSpacing:"0.02em"}},[a("span",{style:{color:"#999"}},"Powered by "+l.brandName),a("span",{style:{color:"#999"}},"\u2022"),a("a",{href:"https://platform.writetext.ai/privacy",target:"_blank",rel:"noopener noreferrer",style:{color:"#999",textDecoration:"underline",textUnderlineOffset:"2px",transition:"color 0.2s ease"},onMouseenter:function(v){v.currentTarget.style.color="#000"},onMouseleave:function(v){v.currentTarget.style.color="#999"}},"Privacy Policy")])]),te.appendChild(wt),S.appendChild(te),ue=a("div",{style:{flex:"1",display:"none",flexDirection:"column",overflow:"hidden"}}),B=a("div",{className:"vcw-chat-messages",style:{flex:"1",overflowY:"auto",padding:"12px 16px",display:"flex",flexDirection:"column",gap:"12px"}}),ue.appendChild(B),_e=a("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",paddingBottom:"6px",animation:"vcw-fade-in 0.3s ease-out"}},[a("div",{style:{padding:"6px 12px",borderRadius:"8px",background:"#1a1a1a",color:"white",fontSize:"11px",fontWeight:"500",whiteSpace:"nowrap",boxShadow:"0 2px 8px rgba(0,0,0,0.2)"}},"Ask me in any language"),a("div",{style:{width:"0",height:"0",borderLeft:"6px solid transparent",borderRight:"6px solid transparent",borderTop:"6px solid #1a1a1a"}})]),ue.appendChild(_e);var R=a("div",{style:{flexShrink:"0",padding:"12px 16px",borderTop:"1px solid rgba(0,0,0,0.08)"}}),y=a("div",{style:{display:"flex",alignItems:"center",gap:"8px"}});C=a("input",{className:"vcw-chat-input",style:{flex:"1",padding:"10px 16px",borderRadius:"12px",background:"rgba(0,0,0,0.04)",border:"1px solid rgba(0,0,0,0.08)",fontSize:"14px",color:e.textColor,transition:"all 0.2s ease"}}),C.setAttribute("type","text"),C.setAttribute("placeholder","Type a message"),C.addEventListener("input",function(){n.chatInput=C.value,C.value.length>0&&(n.showLangTooltip=!1),me(),Ht()}),C.addEventListener("keydown",function(v){v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),_t())}),y.appendChild(C),Se=a("button",{className:"vcw-send-btn",style:{width:"40px",height:"40px",borderRadius:"12px",border:"none",background:e.primaryGradient,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"all 0.2s ease"},onClick:_t},Xt(16,"white")),Se.disabled=!0,y.appendChild(Se),R.appendChild(y),St=a("div",{style:{display:"flex",justifyContent:"center",marginTop:"8px"}},[a("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"11px",color:"#999",letterSpacing:"0.02em"}},[a("span",{style:{color:"#999"}},"Powered by "+l.brandName),a("span",{style:{color:"#999"}},"\u2022"),a("a",{href:"https://platform.writetext.ai/privacy",target:"_blank",rel:"noopener noreferrer",style:{color:"#999",textDecoration:"underline",textUnderlineOffset:"2px",transition:"color 0.2s ease"},onMouseenter:function(v){v.currentTarget.style.color="#000"},onMouseleave:function(v){v.currentTarget.style.color="#999"}},"Privacy Policy")])]),R.appendChild(St),ue.appendChild(R),S.appendChild(ue),De=a("div",{className:"vcw-log-pane vcw-hidden"},[a("div",{className:"vcw-log-title"},"Realtime logs"),_=a("div",{className:"vcw-log-lines"})]),S.appendChild(De),oe=a("audio",{style:{display:"none"},autoplay:"",playsinline:""}),S.appendChild(oe),V.appendChild(S),document.body.appendChild(V)}window.VoiceChatWidget={init:function(e){if(e){var t=Object.assign({},e);!t.styleMode&&typeof t.mode=="string"&&(t.styleMode=t.mode),t.styleMode=Qe(t.styleMode||l.styleMode),Object.assign(l,t)}else l.styleMode=Qe(l.styleMode);Gt(),Wt(),f(),Ft(l.debugLogs,{showLogPane:l.showLogPane,consoleDebugLogs:l.consoleDebugLogs,verboseEventLogs:l.verboseEventLogs})},setDebugLogging:function(e,t){Ft(e,t||{})},open:Ue,close:Ye,openVoice:function(){Ue(),setTimeout(Dt,50)},openChat:function(){Ue(),setTimeout(Nt,50)},destroy:function(){Ye(),V&&V.parentNode&&V.parentNode.removeChild(V),V=null}}})(); 127//# sourceMappingURL=voice-chat-widget-dual.min.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.