@flowengage/react-chatbot 2.1.21 → 2.1.23
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.
package/dist/flowengage-embed.js
CHANGED
|
@@ -640,7 +640,7 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
640
640
|
fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
|
|
641
641
|
filter="url(#${Q}-csh)"/>
|
|
642
642
|
</svg>`,yO=null,bO=!1;function xO(){return(!yO||!yO.isConnected)&&(yO=document.createElement(`div`),yO.id=`${Q}-cursor`,yO.innerHTML=vO,document.body.appendChild(yO),bO=!1),yO}async function SO(e){if(typeof document>`u`||!e)return;iO();let t;try{t=e.getBoundingClientRect()}catch{return}let n=t.left+Math.min(16,t.width*.2),r=t.top+Math.min(12,t.height*.25),i=xO();bO||=(i.style.transition=`none`,i.style.left=`${window.innerWidth/2}px`,i.style.top=`${window.innerHeight*.4}px`,i.classList.add(`${Q}-cursor-visible`),i.offsetHeight,i.style.transition=`left 0.32s cubic-bezier(0.25,0.46,0.45,0.94), top 0.32s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.2s ease`,!0),i.style.left=`${n}px`,i.style.top=`${r}px`,await EO(360)}function CO(e=!1){yO&&(e?(yO.classList.remove(`${Q}-cursor-visible`),bO=!1):(yO.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{bO=!1},250)))}async function wO(e){yO&&(yO.classList.add(`${Q}-cursor-click`),await EO(280),yO.classList.remove(`${Q}-cursor-click`))}function TO(e){if(!e||typeof document>`u`)return;iO();let t;try{t=e.getBoundingClientRect()}catch{return}let n=e.style.position,r=e.style.overflow,i=window.getComputedStyle(e).position;[`relative`,`absolute`,`fixed`,`sticky`].includes(i)||(e.style.position=`relative`),e.style.overflow=`hidden`;let a=document.createElement(`span`);a.className=`${Q}-ripple`;let o=Math.max(t.width,t.height)*1.2;Object.assign(a.style,{width:`${o}px`,height:`${o}px`,left:`${t.width/2-o/2}px`,top:`${t.height/2-o/2}px`}),e.appendChild(a),setTimeout(()=>{a.remove(),e.style.position=n,e.style.overflow=r},650)}function EO(e){return new Promise(t=>setTimeout(t,e))}function $(...e){Mn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function DO(e){return new Promise(t=>setTimeout(t,e))}var OO=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function kO(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(OO)}catch{return!1}}function AO(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function jO(e){let t=new Set;function n(r){if(!r||t.has(r))return;t.add(r),e(r);let i=r.querySelectorAll(`iframe`);for(let e of i)if(!kO(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function MO(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function NO(e){let t=e.ownerDocument||document,n=e.getAttribute(`aria-labelledby`);if(n){let e=n.trim().split(/\s+/).filter(Boolean),r=[];for(let n of e)try{let e=t.getElementById(n);e?.textContent&&r.push(e.textContent.trim())}catch{}if(r.length)return MO(r.join(` `))}if(e.labels&&e.labels.length)return MO(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return MO(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return MO(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return MO(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=MO(i.textContent);if(e)return e}i=i.previousElementSibling}let a=e.parentElement;for(let e=0;e<5&&a;e+=1){if(a.tagName===`LABEL`)return MO(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return MO(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?MO(o):null}function PO(){let e=[];return jO(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(kO(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=AO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function FO(){return PO().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:NO(e),placeholder:e.placeholder||null}))}function IO(){let e=[];return jO(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(kO(e)||e.disabled)return!1;try{let t=AO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function LO(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function RO(e){let t=LO(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function zO(e,t){let n=RO(t);if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,NO(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>LO(e)),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var BO=28;function VO(e,t){let n=null,r=0;for(let i of e){let e=zO(i,t);e>r&&(r=e,n=i)}return!n||r<BO?null:n}function HO(e,t,n){let r=String(t||``).toLowerCase().trim(),i=String(n||``).trim();if(!(/^https?:\/\//i.test(i)||/\.\w{2,}(\/|\s|$)/.test(i)||r.includes(`url`)||r.includes(`website`)||r.includes(`domain`)||r.includes(`site`)))return null;let a=null,o=0;for(let t of e){if(t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`)continue;let e=(t.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`checkbox`,`radio`].includes(e))continue;let n=0;(e===`url`||e===`text`||e===`search`)&&(n+=45);let r=[t.name,t.id,t.placeholder,NO(t),t.getAttribute(`aria-label`),t.getAttribute(`autocomplete`)].filter(Boolean).join(` `).toLowerCase();/(website|url|domain|site\s*url)/.test(r)&&(n+=55),n>o&&(o=n,a=t)}return!a||o<42?null:a}function UO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function WO(e){let t=String(e??``).toLowerCase().trim();return t?!!(t===`url`||t===`website`||t===`website url`||t===`website_url`||t===`enter website url`||t.includes(`website`)||t.includes(`domain`)||/(enter\s+website|site\s*url|page\s*url)/.test(t)):!1}function GO(e){if(!e||e.tagName!==`INPUT`&&e.tagName!==`TEXTAREA`)return!1;let t=(e.type||``).toLowerCase();return![`hidden`,`submit`,`button`,`checkbox`,`radio`,`file`].includes(t)}function KO(e){if(!GO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,NO(e),e.getAttribute(`aria-label`)].filter(Boolean).join(` `).toLowerCase();return t===`url`||n===`url-input`||n.endsWith(`-url-input`)||/(website\s*url|enter\s+website|site\s*url)/.test(r)||/(website|domain)/.test(r)&&/(url|site)/.test(r)}function qO(e,t,n){let r=String(t??``),i=String(n??``),a=XO(e,r)||VO(e,r)||HO(e,r,i);if(!a)return[];let o=new Set([a]);if(UO(i)&&WO(r))for(let t of e)t!==a&&KO(t)&&o.add(t);let s=Array.from(o);return s.sort((e,t)=>{if(e===t)return 0;let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0}),s}function JO(e,t){try{if(!e?.getBoundingClientRect||!t?.getBoundingClientRect)return 1/0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i={x:n.left+n.width/2,y:n.top+n.height/2},a={x:r.left+r.width/2,y:r.top+r.height/2};return Math.hypot(i.x-a.x,i.y-a.y)}catch{return 1/0}}function YO(e){if(!e||typeof e!=`string`)return null;let t=null;return jO(n=>{try{let r=n.getElementById(e);r&&!kO(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function XO(e,t){let n=String(t??``).trim();if(!n)return null;let r=n.match(/^name:\s*([\w.-]+)$/i);if(r){let t=r[1];for(let n of e)if(n.name===t)return n}let i=n.match(/^id:\s*([\w.-]+)$/i);if(i){let e=YO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=YO(a);if(e)return e}let o=n.toLowerCase().replace(/\s+/g,` `);if(o===`url`||o===`website`||o===`website url`||o===`website_url`||o===`enter website url`)for(let t of e){let e=(t.name||``).toLowerCase(),n=(t.id||``).toLowerCase();if(e===`url`||n===`url-input`||n.endsWith(`-url-input`))return t}return null}function ZO(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.textContent,e.value,e.getAttribute(`aria-label`),e.getAttribute(`title`)].filter(Boolean).join(` `).toLowerCase().replace(/\s+/g,` `);if(r.includes(n))return 100;let i=n.split(/\s+/).filter(e=>e.length>1);if(!i.length)return 0;let a=0;for(let e of i)r.includes(e)&&(a+=1);return a/i.length*92}function QO(e,t){let n=[];jO(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(kO(e)||e.disabled)return!1;try{let t=AO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:ZO(t,e)}));for(let{s:e}of i)e>r&&(r=e);if(r<36)return null;let a=i.filter(({s:e})=>e===r).map(({el:e})=>e);if(a.length===1)return a[0];let o=Array.isArray(t)?t.filter(e=>e&&e.isConnected):[];if(o.length){let e=a[0],t=1/0;for(let n of a)for(let r of o){let i=JO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function $O(e){if(e==null)return{};if(typeof e==`string`){let t=e.trim();if(!t)return{};try{return JSON.parse(t)}catch{return{url:t}}}return e}function ek(e){let t=$O(e);if(Array.isArray(t)&&t.length>0){let e=t[0];if(e?.field_key!=null||e?.fieldKey!=null)return t.map(e=>({field_key:e.field_key??e.fieldKey,value:e.value}))}if(!t||typeof t!=`object`)return[];let n=t.fields??t.Fields??t.field_list??t.fieldList??t.data?.fields;if(typeof n==`string`)try{n=JSON.parse(n)}catch{n=null}n&&!Array.isArray(n)&&typeof n==`object`&&(n=Object.values(n)),(!n||n.length===0)&&(t.field_key!=null||t.fieldKey!=null)&&t.value!=null&&(n=[{field_key:t.field_key??t.fieldKey,value:t.value}]);let r=t.website_url??t.websiteUrl??t.url??t.website??t.domain??t.site_url??t.siteUrl;return(!n||n.length===0)&&r!=null&&String(r).trim()&&(n=[{field_key:t.field_key??t.fieldKey??`url`,value:String(r).trim()}]),Array.isArray(n)?n.map(e=>({field_key:e?.field_key??e?.fieldKey,value:e?.value??e?.Value})):[]}function tk(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!t||/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\b/i.test(t))return[];let n=t.match(/https?:\/\/[^\s<>"']+/i);if(n)return[{field_key:`url`,value:n[0].replace(/[.,;:)]+$/,``)}];let r=t.match(/\b(?:[\w-]+\.)+[a-z]{2,}\b/i);if(r){let e=r[0].replace(/[.,;:)]+$/,``);return/^https?:/i.test(e)||(e=`https://${e}`),[{field_key:`url`,value:e}]}return[]}function nk(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!t)return[];let n=[],r=new Set,i=/\b([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\b/i,a=(e,t)=>{let i=String(t??``).trim().replace(/^["']|["']$/g,``);if(!i||i.length>800)return;let a=`${e}\0${i}`;r.has(a)||(r.add(a),n.push({field_key:e,value:i}))},o=t.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);if(o)return a(`Email Address`,o[1]),n;let s=t.match(/\b(?:please\s+)?(?:enter|type|put)\s+(.+?)\s+in(?:to)?\s+(?:the\s+)?(?:full\s*name|full\s*name\s*field|name\s*field)\b/i);if(s&&a(`Full Name`,s[1]),s=t.match(/\bfull\s*name,?\s*(?:please\s+)?(?:enter|type|put)\s+(.+?)(?:\.|$|!|\?)/i),s&&a(`Full Name`,s[1]),s=t.match(/\bfull\s*name\s*(?:is|:|please\s+enter|-)\s*(.+?)(?:\.|$|(?=\s+(?:and|my\s+email|email|message))\b)/i),s&&a(`Full Name`,s[1]),s=t.match(/\b(.+?)\s+for\s+(?:the\s+)?full\s*name\b/i),s){let e=s[1].trim();e.length>1&&e.length<120&&!/@/.test(e)&&a(`Full Name`,e)}if(s=t.match(/\b(?:email|e-mail)(?:\s*address)?\s*(?:is|:|please\s+use|enter|-)\s*([^\s@]+@[^\s@]+\.[^\s,]+)/i),s&&a(`Email Address`,s[1]),s=t.match(/\b(?:enter|type|put)\s+([^\s@]+@[^\s@]+\.[^\s,]+)\s+in(?:to)?\s+(?:the\s+)?(?:email|e-mail)/i),s&&a(`Email Address`,s[1]),s=t.match(/\b(?:message|comment)\s*(?:is|:|please\s+enter|-)\s*(.+)$/is),s){let e=s[1].trim();e.length>0&&a(`Message`,e)}if(!n.some(e=>/email/i.test(String(e.field_key)))){let e=t.match(i);if(e){let r=t.replace(e[0],``).trim().replace(/^(please|it's|it is|use|is|my email is|e-?mail is)\s*/i,``).replace(/[.,;:!?]+$/,``).trim();if(t.length<=96&&r.length<=36)return a(`Email Address`,e[1]),n}}if(n.length===0){let e=t.split(/\s+/).filter(Boolean).length,n=/[.!?]/.test(t)||e>=6||t.length>=24&&e>=5||t.length>=42,r=/^[A-Z][a-z]+\s+[A-Z][a-z]+$/.test(t.trim());n&&t.length>=16&&!i.test(t)&&!r&&a(`Message`,t)}return n}function rk(e){if(!e||typeof e!=`object`)return null;let t=e.url??e.target_url??e.page_url??e.pageUrl??e.link??e.href??e.path;return t==null?null:String(t).trim()||null}function ik(e){if(!e||typeof e!=`object`)return null;let t=e.query??e.q??e.search??e.text??e.keywords;return t==null?null:String(t).trim()||null}function ak(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase();if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let a=String(t);if(r===`INPUT`||r===`TEXTAREA`){let t=e.ownerDocument?.defaultView||window,n=r===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,`value`);i?.set?i.set.call(e,a):e.value=a}else e.value=a;let o={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...o,inputType:`insertText`,data:a}))}catch{e.dispatchEvent(new Event(`input`,o))}e.dispatchEvent(new Event(`change`,o));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,o)),e.dispatchEvent(new Event(`change`,o))}catch{}})}catch{}return!0}function ok(){let e={};document.querySelectorAll(`h1, h2, h3, h4, h5, h6`).forEach(t=>{if(t.id)return;let n=t.textContent.trim();if(!n)return;let r=n.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``).substring(0,60);if(e[r]){let t=2;for(;e[r+`-`+t];)t++;r=r+`-`+t}e[r]=!0,t.id=r})}function sk(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={flowengage_navigate:async n=>{$(`flowengage_navigate ▶ raw parameters:`,n);let i=$O(n),a=rk(i),o=i.section_text??i.sectionText??i.section,s=Array.isArray(i.expected_landmarks)?i.expected_landmarks:Array.isArray(i.expectedLandmarks)?i.expectedLandmarks:[];if($(`flowengage_navigate · coerced:`,{url:a,sectionText:o,expectedLandmarks:s}),!a){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(typeof window<`u`)try{let e=new URL(a,window.location.href);e.origin!==window.location.origin&&/^https?:$/i.test(e.protocol)&&(a=e.pathname+e.search+e.hash,$(`flowengage_navigate · normalized cross-origin URL to path:`,a))}catch{}if(!await dr(a,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`Page "${a}" could not be verified. Call flowengage_search with keywords from the topic to find the correct URL, then navigate to the URL from the search results.`;return $(`flowengage_navigate ✖ blocked`,e),e}try{cO(`Navigating to ${a}...`,{spinner:!0}),pO(),$D(),rO();try{let e=r?r():``;if(e&&t){let n=ZD([{sender:`user`,message:e}]);n&&De(t,n)}}catch{}return je(),t&&typeof window<`u`&&Fe(t,window.location.href),$(`flowengage_navigate → real navigation`,a),setTimeout(()=>{try{window.location.assign(a)}catch{}},150),`OK_NAVIGATE_RELOADING. Navigating to the page now; the voice session will resume automatically. Do not speak until the user speaks first after the page loads.`}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),cO(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{mO(),lO(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=$O(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;ok();let i=or(n||null,r||null);return!i&&r&&(await new Promise(e=>setTimeout(e,500)),ok(),i=or(null,r)),i?(nO(i),$(`flowengage_highlight ✓`,r||n),`OK_HIGHLIGHT: "${r||n}"`):($(`flowengage_highlight ✖ no element for:`,r||n),`Could not find "${r||n}" on the current page. Try a shorter phrase matching a visible heading.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=$O(e),n=t?.section_text||t?.sectionText||``;try{let e=``;if(n){let t=or(null,n);if(!t)return`Could not find section "${n}" on the page.`;let r=[t.textContent.trim()],i=t.nextElementSibling;for(;i&&!/^H[1-3]$/i.test(i.tagName);){let e=i.textContent.trim();e&&r.push(e),i=i.nextElementSibling}e=r.join(`
|
|
643
|
-
`)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`flowengage_read_content ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`flowengage_read_content ✖`,e.message),`Could not read page content: ${e.message}`}},flowengage_search:async e=>{$(`flowengage_search ▶`,e);let r=ik($O(e));if($(`flowengage_search · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`flowengage_search ✖ missing query`),`Missing query parameter.`;if(!t)return $(`flowengage_search ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`flowengage_search ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`flowengage_search → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`flowengage_search · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return $(`flowengage_search ✖`,e),e}let o=a.results||[];return $(`flowengage_search ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return $(`flowengage_search ✖`,t),t}},flowengage_page_content:async e=>{$(`flowengage_page_content ▶`,e);let r=$O(e),i=r?.url||r?.page_url||``;if($(`flowengage_page_content · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`flowengage_page_content ✖ missing url`),`Missing url parameter.`;if(!t)return $(`flowengage_page_content ✖ no siteId`),`Site is not configured.`;if(!n)return $(`flowengage_page_content ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`flowengage_page_content → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`flowengage_page_content · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`flowengage_page_content ✖`,e),e}return $(`flowengage_page_content ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`flowengage_page_content ✖`,t),t}},flowengage_end_session:async()=>($(`flowengage_end_session ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),flowengage_list_forms:async()=>{let e=FO(),t=IO();return $(`flowengage_list_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: placeholder/label, name (e.g. url), id (e.g. url-input). If the page has two URL boxes, flowengage_fill_form sets all matching URL inputs. flowengage_click_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},flowengage_fill_form:async e=>{try{$(`flowengage_fill_form ▶ raw:`,e),hO();let t=ek(e);if(!t.length&&r){let e=r(),n=tk(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=nk(e),n.length&&$(`flowengage_fill_form · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`flowengage_fill_form · normalized fields:`,t),!t.length)return`No fields provided. Call flowengage_list_forms for field_key strings, then flowengage_fill_form with { "fields": [ { "field_key": "<label or placeholder from list>", "value": "<user value>" } ] }. Never use empty {}. Pass the value the user just said (email, message, name, URL) in fields.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;cO(`Filling ${String(t)}...`,{spinner:!0});let a=PO(),o=qO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())gO(t),await SO(t),ak(t,r,{skipScroll:e>0}),_O(t),await DO(120);i=o,n.push(String(t));continue}let s=XO(a,String(t));s||=VO(a,String(t)),s||=HO(a,String(t),r),s&&(gO(s),await SO(s),ak(s,r),_O(s),await DO(120),i=[s],n.push(String(t)))}if(!n.length)return $(`flowengage_fill_form ✖ no matches`),`Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.`;let a=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,a),cO(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),a}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),cO(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{CO(),hO(),lO(700)}},flowengage_click_button:async e=>{let t=$O(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`flowengage_click_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=QO(n,i);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{cO(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await SO(r),r.focus?.(),await wO(r),TO(r),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`flowengage_click_button ✓`,t),cO(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),cO(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{CO(),lO(700)}}};return{...a,highlightOnPage:a.flowengage_highlight,searchSiteContent:a.flowengage_search,getPageContent:a.flowengage_page_content,endVoiceSession:a.flowengage_end_session,listPageForms:a.flowengage_list_forms,fillFormFields:a.flowengage_fill_form,clickPageButton:a.flowengage_click_button}}function ck(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Mn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var lk={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function uk(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function dk(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function fk({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,N.jsx)(`img`,{src:e,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}});let n=typeof e==`function`?b.createElement(e):b.isValidElement(e)?e:null;return n?(0,N.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function pk({title:e}){return(0,N.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function mk(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||/\b(that'?s all|we'?re done)\b/i.test(n)||e===`bot`&&(/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))||/^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)):!1}function hk({orbColors:e,...t}){return(0,N.jsx)(HD,{colors:e,...t})}function gk({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||lk.green,c=dk(s),l=a?72:94,u=(0,N.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,N.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,N.jsx)(cm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:a?void 0:`210px`},children:e.entryPrompt}),(0,N.jsxs)(cm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,N.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,N.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,N.jsx)(cm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,N.jsx)(hk,{size:l,orbColors:t})})]});return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(cm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,N.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,N.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function _k({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||lk.green,l=dk(c);return(0,N.jsxs)(cm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,N.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,N.jsx)(hk,{size:72,orbColors:t}),(0,N.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,N.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,N.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,N.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function vk({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,historyRef:o,onMessageSync:s}){let[c,l]=(0,b.useState)(`idle`),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(0),g=(0,b.useRef)(null),_=(0,b.useRef)(``),v=(0,b.useRef)(async()=>{}),y=(0,b.useRef)(!1),x=(0,b.useRef)(!1),ee=(0,b.useRef)(!1),S=(0,b.useRef)(!1),C=(0,b.useRef)(`minimized`),te=(0,b.useRef)(null),w=(0,b.useCallback)((e=`minimized`)=>{C.current=e,S.current=!0,queueMicrotask(()=>{y.current||(y.current=!0,v.current?.())})},[o]),ne=(0,b.useCallback)(async e=>{S.current=!0;try{await g.current?.endSession?.()}catch{}if(g.current=null,l(`idle`),d(!1),y.current=!1,br(),i)try{ke(i)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return v.current=()=>ne(C.current===`chat`?t:n),(0,b.useEffect)(()=>{x.current=u},[u]),(0,b.useEffect)(()=>{let e=!1,n=null;return(async()=>{if(!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],_.current=``,y.current=!1,ee.current=!1,S.current=!1,C.current=`minimized`,yr({onBeforeNavigate:()=>{if(i&&o.current.length>0)try{let e=ZD(o.current);e&&De(i,e)}catch{}if(i&&typeof window<`u`)try{Fe(i,window.location.href)}catch{}je()}});let t=ck(sk({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{w()}})),s=i?Oe(i):null,c=!!s?.transcript,u=c&&i?D(i):null,f={agentId:r,clientTools:t},p=await aD.startSession({...f,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||l(t===`speaking`?`speaking`:`listening`)},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;if(r){if(n===`user`&&(_.current=r),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],i)try{let e=ZD(o.current);e&&De(i,e)}catch{}mk(n,r)&&w(`minimized`)}},onError:t=>{if(!e&&!S.current&&!ee.current&&!Ne()){ee.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{g.current?.setMicMuted?.(!0)}catch{}d(!0),l(`error`),w(`chat`)}},onDisconnect:()=>{if(e||S.current||ee.current||Ne())return;let t=o.current?.length||0;if(console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:t,lastUserText:_.current||``,wasMuted:x.current}),t===0&&m===0){ee.current=!0,console.warn(`[FlowEngageVoiceCall] immediate disconnect, retrying once`),h(1);return}ee.current=!0;try{g.current?.setMicMuted?.(!0)}catch{}d(!0),w(`chat`)}});if(e){p.endSession().catch(()=>{});return}n=p,g.current=p,l(`listening`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.list_page_forms()}catch{}let r=c?`AGENT-DRIVEN NAVIGATION. You navigated the visitor to a new page. `+(u?.previousPage?`They came FROM: ${u.previousPage}. `:``)+`Current page URL: ${e}. Do NOT say "Hello". Do NOT re-introduce yourself. Speak ONE short sentence acknowledging the new page and offering help. Example: "I can see we're now on the Pricing page — feel free to ask me anything about it." Keep it to one sentence, natural and conversational.\nPrior conversation:\n${s.transcript}\n\n`:`Greet the visitor with a short, warm, friendly opening message. Be natural and conversational. `;p.sendContextualUpdate(r+`Current page: ${e}. SiteId: ${i||`unknown`}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`)}catch{}}catch(n){e||(console.error(`[FlowEngage] startSession failed`,n),l(`error`),C.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}})(),()=>{e=!0,S.current=!0,br(),(n||g.current)?.endSession?.().catch(()=>{})}},[r,i,a,w,m]),(0,b.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;te.current&&!te.current.contains(t)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,N.jsxs)(`div`,{ref:te,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[(0,N.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,N.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Listening...`}),(0,N.jsx)(hk,{size:72,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,N.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,N.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,N.jsx)(`button`,{onClick:async()=>{if(g.current)try{u?(await g.current.setMicMuted?.(!1),d(!1)):(await g.current.setMicMuted?.(!0),d(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:u?`#7f1d1d`:`#1f2937`,border:u?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:u?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:u?(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,N.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,N.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,N.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,N.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,N.jsx)(oD,{size:16,color:`currentColor`})}),(0,N.jsx)(`button`,{onClick:()=>p(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,N.jsx)(mD,{size:16,color:`currentColor`})})]}),f&&(0,N.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,N.jsxs)(`button`,{onClick:()=>{p(!1),C.current=`chat`,ne(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(hD,{}),`Enter Chat Mode`]}),(0,N.jsxs)(`button`,{onClick:()=>{p(!1),C.current=`minimized`,ne(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(gD,{}),`End Conversation`]}),(0,N.jsx)(`button`,{onClick:()=>p(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,N.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,N.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function yk({orbColors:e}){return(0,N.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,N.jsx)(hk,{size:36,orbColors:e})})}var bk=()=>(0,N.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,N.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,N.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function xk({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:d,agentName:f,agentHeadshot:p,fallbackAgentName:m,input:h,setInput:g,onSubmit:_,isConversationEnded:v,isLoading:y,isRateLimited:x,rateLimitMessage:ee,selectedFile:S,onFileSelect:C,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:T,emailError:ae,replyContext:oe,setReplyContext:se,webRTCError:ce,micError:le,setMicError:E,dismissCallError:ue,activeCallId:de,isCallMuted:fe,toggleCallMute:pe,endWebRTCCall:me,formatCallDuration:he,callDurationSeconds:ge,isCallMinimized:_e,onExpand:ve,onCollapse:ye,onStartVoice:be,onNewChat:xe,onEndConversation:Se,showPoweredBy:Ce,getVisitorChatHistory:we,getVisitorChatThread:Te,resumeChat:Ee,isSessionRestoring:De,isClosing:Oe}){let ke=c.length>0,Ae=y||x||v,je=!!de,[Me,Ne]=(0,b.useState)(!1),[Pe,Fe]=(0,b.useState)(!1),[D,Ie]=(0,b.useState)([]),[Le,Re]=(0,b.useState)(!1),[ze,Be]=(0,b.useState)(null),[Ve,He]=(0,b.useState)([]),Ue=(0,b.useRef)(null),We=async()=>{Ne(!1),Fe(!0),Re(!0),Be(null);try{let e=await we();e?.data&&Ie(e.data)}catch(e){console.error(e)}finally{Re(!1)}},Ge=async e=>{Fe(!1),Ee?.(e.chatId)};return(0,b.useEffect)(()=>{if(!Me)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ue.current&&!Ue.current.contains(t)&&Ne(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Me]),(0,N.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`8px`,right:`8px`,bottom:0,width:`calc(100% - 16px)`,height:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Oe?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Oe?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,N.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:`transparent`,flexShrink:0},children:[(0,N.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,N.jsx)(`button`,{onClick:ye,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(0,N.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:`minmax(72px, 40%) minmax(0, 60%)`,alignItems:`center`},children:[(0,N.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,N.jsx)(fk,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,N.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,N.jsx)(pk,{title:e.chatTitle})})}),(0,N.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,N.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]}),(0,N.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:Ue,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ne(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,N.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,N.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,N.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,N.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Me&&(0,N.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),be?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,N.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),xe?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,N.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new conversation`]}),we&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:We,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),ye?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,N.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,N.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,N.jsx)(ND,{webRTCError:ce,micError:le,setMicError:E,dismissCallError:ue,isRateLimited:x,rateLimitMessage:ee}),_e&&(0,N.jsx)(XD,{agentName:f,agentHeadshot:p,fallbackAgentName:m,callDurationSeconds:ge,isCallMuted:fe,formatCallDuration:he,toggleCallMute:pe,endWebRTCCall:me,onExpand:ve,primaryColor:n}),(0,N.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[Pe?(0,N.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,N.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:ze?(0,N.jsxs)(`button`,{onClick:()=>Be(null),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,N.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Back to List`})]}):(0,N.jsxs)(`button`,{onClick:()=>Fe(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,N.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,N.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:Le&&!ze?(0,N.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):ze?(0,N.jsxs)(`div`,{style:{padding:`20px 16px`},children:[Ve.length===0?(0,N.jsx)(`div`,{style:{color:`#9ca3af`,textAlign:`center`,marginTop:`20px`,fontSize:`14px`},children:`No messages`}):null,Ve.map((e,t)=>(0,N.jsx)(`div`,{style:{marginBottom:`16px`,display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,N.jsx)(`div`,{style:{maxWidth:`85%`,background:e.sender===`user`?n:`#f3f4f6`,color:e.sender===`user`?`white`:`#111827`,padding:`10px 14px`,borderRadius:`14px`,fontSize:`15px`,lineHeight:1.4,wordBreak:`break-word`},children:e.content})},e._id||t))]}):D.length>0?(0,N.jsx)(`div`,{children:D.map(e=>(0,N.jsxs)(`div`,{onClick:()=>Ge(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,N.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,N.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,N.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,ke?(0,N.jsx)(jD,{chatHistory:c,isAiTyping:l,isLoading:y,isAgentTyping:u,setReplyContext:se,TypingDots:bk,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,N.jsx)(yk,{orbColors:t})}):De?(0,N.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,N.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,N.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,N.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,N.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,N.jsx)(hk,{size:94,orbColors:t}),(0,N.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,N.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,N.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),(0,N.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:re?`6px 0 0`:`12px 0 0`},children:(0,N.jsx)(MD,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:je,handleToggleVoice:be,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:Ae,replyContext:oe,clearReplyContext:()=>se(null),onFileSelect:C,selectedFile:S,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:T,emailError:ae,inputPlaceholder:e.inputPlaceholder})}),(0,N.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:Ce&&(0,N.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,N.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function Sk(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:v,callConnectedAt:y,isCallMuted:x,webRTCError:ee,language:S,historyRef:C,onMessageSync:te,sendMessage:w,uploadChatFile:ne,openWidget:re,captureVisitorEmail:ie,setVoiceMode:T,endConversation:ae,startNewChat:oe,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:de,dismissCallError:fe,startTyping:pe,stopTyping:me,updateTypingDraft:he,getVisitorChatHistory:ge,getVisitorChatThread:_e,resumeChat:ve,isSessionRestoring:ye}=jn();(0,b.useEffect)(()=>{try{ir()}catch{}},[]);let be=t?.widgetSettings||{},xe=n?.widgetSettings||{},Se={...be.branding||{},...xe.branding||{}},Ce={...be.theme||{},...xe.theme||{}},we={...be.features||{},...xe.features||{}},Te=we.voice!==!1,Ee=Array.isArray(Ce.orbColors)&&Ce.orbColors.length>0?Ce.orbColors:null,De=Ce.buttonColor||Ce.primaryColor||Ee?.[0]||`#3B82F6`,Ae=Ce.position||`bottom-right`,je=Se.fallbackAgentName||`Agent`,Ne=uk(Ee??Ce.chatBgColors),Pe=Se.logo||Se.logoUrl||null,Fe=S||`en`,D=be.recommendations?.[Fe]||[],Ie=(xe.recommendations?.[Fe]??D).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Le=Array.isArray(Se.quickChatOptions)&&Se.quickChatOptions.length>0?Se.quickChatOptions:Ie,Re=Se.hideWatermark===!0?!1:Se.showPoweredBy!==!1,ze=Se.chatbotEnabled!==!1&&Ce.chatbotEnabled!==!1,Be=be.greetings?.[S]||xe.greetings?.[S]||Se.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Ve={entryPrompt:Se.entryPrompt||`Do you want to explore in a new way?`,yesLabel:Se.yesLabel||`Yes`,laterLabel:Se.laterLabel||`Later`,connectionTitle:Se.connectionTitle||`How would you like to connect?`,voiceLabel:Se.voiceLabel||`Voice`,textLabel:Se.textLabel||`Text`,chatTitle:Se.headerName||`Chat with FlowEngage`,introGreeting:Be,inputPlaceholder:Se.inputPlaceholder||`Type your message`,analysingLabel:Se.analysingLabel||`analysing...`},He=xe.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ue=t?.siteId||n?.siteId||null,We=t?.apiBaseUrl||``,Ge=(0,b.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Ke=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,qe=r.some(e=>e.sender===`user`),Je=(0,b.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),Ye=!l&&qe&&Je,Xe=!!(xe._dashboardLivePreview||be._dashboardLivePreview),[Ze,O]=(0,b.useState)(()=>Xe?`text_chat`:`entry_prompt`),[k,A]=(0,b.useState)(``),[Qe,$e]=(0,b.useState)(null),[et,tt]=(0,b.useState)(l||``),[nt,rt]=(0,b.useState)(``),[it,at]=(0,b.useState)(0),[ot,st]=(0,b.useState)(null),[ct,lt]=(0,b.useState)(null),[ut,dt]=(0,b.useState)(``),[ft,pt]=(0,b.useState)(!1),[mt,ht]=(0,b.useState)(!1),[gt,_t]=(0,b.useState)(!1),vt=(0,b.useRef)(null),yt=(0,b.useRef)(!1);(0,b.useLayoutEffect)(()=>{if(e!==`ready`||yt.current)return;if(yt.current=!0,!Te){O(`minimized_orb`);return}let t=!1;try{t=hr().shouldResumeVoice}catch{}let n=Me(),r=Ue?Oe(Ue):null,i=n||!!r?.transcript;if(t){re?.({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`);return}if(Ue)try{ke(Ue)}catch{}if(i){re?.({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`);return}if(E(Ue)){O(`minimized_orb`);return}},[e,r]);let[bt,xt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>xt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{tt(l||``),l&&rt(``)},[l]);let St=(0,b.useCallback)(()=>{lt(null),dt(``)},[]),Ct=(0,b.useCallback)(e=>{let t=ED(e);if(t){lt(null),dt(t);return}lt(e),dt(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){at(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||at(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]);let wt=(0,b.useCallback)(()=>{O(`call_screen`),ht(!1)},[]),Tt=(0,b.useCallback)(()=>{O(`text_chat`),ht(!0)},[]);(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){vt.current=null;return}if(g?.callId||v===`connecting`||v===`connected`){if(Ze===`minimized_orb`&&mt&&_&&!g?.callId){vt.current=e;return}!(!i||Ze===`minimized_orb`||Ze===`voice_mode`)&&vt.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:Ze,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),vt.current=e,Ze===`voice_mode`&&T?.(!1),re?.(),wt())}},[_,v,wt,g?.callId,i,re,T,Ze]),(0,b.useEffect)(()=>{!g&&!_&&Ze===`call_screen`&&O(`text_chat`)},[g,_,Ze]),(0,b.useEffect)(()=>{!_&&mt&&ht(!1)},[_,mt]),(0,b.useEffect)(()=>{if(!o||h){he?.(``),me?.();return}if(!k.trim()||ct){he?.(``);let e=window.setTimeout(()=>me?.(),100);return()=>window.clearTimeout(e)}pe?.();let e=window.setTimeout(()=>he?.(k),120),t=window.setTimeout(()=>me?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[k,ct,o,h,pe,me,he]);let Et=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Dt=async e=>{if(e.preventDefault(),h)return;if(Ye){let e=et.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){rt(`Please enter a valid email so we can continue helping you.`);return}await ie(e),rt(``);return}let t=Et(Qe);if(!k.trim()&&!ct)return;if(ct){try{pt(!0),dt(``);let e=await ne(ct),n=e?.data||e,r=k.trim()||`Shared file: ${OD(ct)}`;A(``),$e(null),St(),await w(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||ct.name,fileType:n?.fileType||ct.type,fileSize:n?.fileSize||ct.size}})}catch(e){dt(e?.message||`Failed to upload the selected file.`)}finally{pt(!1)}return}let n=k.trim();A(``),$e(null),await w(n,``,t)},Ot=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},kt=(0,b.useCallback)(async e=>{if(h||f)return;let t=e.message||e.label||e.text||``;t.trim()&&await w(t.trim(),``)},[h,f,w]),At=bt&&Ze===`entry_prompt`?{inset:0}:bt&&Ze===`text_chat`?{left:0,right:0,bottom:0}:bt&&Ze===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:bt&&Ze===`connection_modal`?{left:`28px`,right:`12px`,bottom:`12px`}:Ze===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ae===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`}}:Ae===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},jt=(0,b.useCallback)(()=>{Ze!==`minimized_orb`&&(_t(!0),setTimeout(()=>{O(`minimized_orb`),_t(!1)},280))},[Ze]),Mt=()=>O(`connection_modal`),Nt=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}re({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`)},Pt=()=>{re({notifyChatInitiated:!0}),T?.(!1),O(`text_chat`)},Ft=()=>{T?.(!1),jt()};return e!==`ready`||!ze||we.chat===!1?null:(0,N.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...At},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[Ze===`entry_prompt`&&(0,N.jsx)(gk,{copy:Ve,orbColors:Ee,primaryColor:De,onYes:()=>{ue(Ue),Nt()},onLater:()=>{ue(Ue),jt()},isMobile:bt,isClosing:gt}),Ze===`minimized_orb`&&(0,N.jsxs)(cm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ae===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[_&&mt&&(0,N.jsxs)(`button`,{type:`button`,onClick:wt,style:{maxWidth:bt?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,N.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,N.jsxs)(`span`,{style:{minWidth:0},children:[(0,N.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:v===`connected`?`Call in progress`:`Call is active`}),(0,N.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:v===`connected`?`${Ot(it)} with ${Ge}`:`Tap to return to ${Ge}`})]})]}),(0,N.jsx)(hk,{size:50,orbColors:Ee,onClick:_&&mt?wt:Te?Mt:Pt})]}),Ze===`connection_modal`&&(0,N.jsx)(_k,{copy:Ve,orbColors:Ee,primaryColor:De,onVoice:Nt,onText:Pt,onClose:jt,isMobile:bt,isClosing:gt}),Ze===`voice_mode`&&(0,N.jsx)(vk,{orbColors:Ee,onEnterChat:Pt,onEndChat:Ft,agentId:He,siteId:Ue,apiBaseUrl:We,historyRef:C,onMessageSync:te},`voice`),Ze===`call_screen`&&(0,N.jsx)(YD,{incomingCall:g,activeCallId:_,callConnectionState:v,callDurationSeconds:it,isCallMuted:x,agentName:Ge,agentHeadshot:Ke,fallbackAgentName:je,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:de,formatCallDuration:Ot,onMinimize:Tt,primaryColor:De,orbColors:Ee,chatHistory:r}),Ze===`text_chat`&&(0,N.jsx)(xk,{isClosing:gt,copy:Ve,orbColors:Ee,primaryColor:De,chatBgGradient:Ne,logo:Pe,quickChatOptions:Le,onQuickChatSelect:kt,isMobile:bt,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:Ge,agentHeadshot:Ke,fallbackAgentName:je,input:k,setInput:A,onSubmit:Dt,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:ct,onFileSelect:Ct,onRemoveSelectedFile:St,attachmentError:ut,isUploadingAttachment:ft,requiresEmail:Ye,emailInput:et,setEmailInput:tt,emailError:nt,replyContext:Qe,setReplyContext:$e,webRTCError:ee,micError:ot,setMicError:st,dismissCallError:fe,activeCallId:_,isCallMuted:x,toggleCallMute:de,endWebRTCCall:le,formatCallDuration:Ot,callDurationSeconds:it,onCollapse:jt,onStartVoice:Nt,onNewChat:oe,onEndConversation:ae,onMinimize:Tt,onExpand:wt,isCallMinimized:mt&&!!_,showPoweredBy:Re,getVisitorChatHistory:ge,getVisitorChatThread:_e,resumeChat:ve,isSessionRestoring:ye}),(0,N.jsx)(`style`,{children:`
|
|
643
|
+
`)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`flowengage_read_content ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`flowengage_read_content ✖`,e.message),`Could not read page content: ${e.message}`}},flowengage_search:async e=>{$(`flowengage_search ▶`,e);let r=ik($O(e));if($(`flowengage_search · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`flowengage_search ✖ missing query`),`Missing query parameter.`;if(!t)return $(`flowengage_search ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`flowengage_search ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`flowengage_search → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`flowengage_search · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return $(`flowengage_search ✖`,e),e}let o=a.results||[];return $(`flowengage_search ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return $(`flowengage_search ✖`,t),t}},flowengage_page_content:async e=>{$(`flowengage_page_content ▶`,e);let r=$O(e),i=r?.url||r?.page_url||``;if($(`flowengage_page_content · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`flowengage_page_content ✖ missing url`),`Missing url parameter.`;if(!t)return $(`flowengage_page_content ✖ no siteId`),`Site is not configured.`;if(!n)return $(`flowengage_page_content ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`flowengage_page_content → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`flowengage_page_content · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`flowengage_page_content ✖`,e),e}return $(`flowengage_page_content ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`flowengage_page_content ✖`,t),t}},flowengage_end_session:async()=>($(`flowengage_end_session ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),flowengage_list_forms:async()=>{let e=FO(),t=IO();return $(`flowengage_list_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: placeholder/label, name (e.g. url), id (e.g. url-input). If the page has two URL boxes, flowengage_fill_form sets all matching URL inputs. flowengage_click_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},flowengage_fill_form:async e=>{try{$(`flowengage_fill_form ▶ raw:`,e),hO();let t=ek(e);if(!t.length&&r){let e=r(),n=tk(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=nk(e),n.length&&$(`flowengage_fill_form · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`flowengage_fill_form · normalized fields:`,t),!t.length)return`No fields provided. Call flowengage_list_forms for field_key strings, then flowengage_fill_form with { "fields": [ { "field_key": "<label or placeholder from list>", "value": "<user value>" } ] }. Never use empty {}. Pass the value the user just said (email, message, name, URL) in fields.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;cO(`Filling ${String(t)}...`,{spinner:!0});let a=PO(),o=qO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())gO(t),await SO(t),ak(t,r,{skipScroll:e>0}),_O(t),await DO(120);i=o,n.push(String(t));continue}let s=XO(a,String(t));s||=VO(a,String(t)),s||=HO(a,String(t),r),s&&(gO(s),await SO(s),ak(s,r),_O(s),await DO(120),i=[s],n.push(String(t)))}if(!n.length)return $(`flowengage_fill_form ✖ no matches`),`Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.`;let a=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,a),cO(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),a}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),cO(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{CO(),hO(),lO(700)}},flowengage_click_button:async e=>{let t=$O(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`flowengage_click_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=QO(n,i);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{cO(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await SO(r),r.focus?.(),await wO(r),TO(r),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`flowengage_click_button ✓`,t),cO(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),cO(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{CO(),lO(700)}}};return{...a,highlightOnPage:a.flowengage_highlight,searchSiteContent:a.flowengage_search,getPageContent:a.flowengage_page_content,endVoiceSession:a.flowengage_end_session,listPageForms:a.flowengage_list_forms,fillFormFields:a.flowengage_fill_form,clickPageButton:a.flowengage_click_button}}function ck(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Mn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var lk={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function uk(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function dk(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function fk({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,N.jsx)(`img`,{src:e,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}});let n=typeof e==`function`?b.createElement(e):b.isValidElement(e)?e:null;return n?(0,N.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function pk({title:e}){return(0,N.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function mk(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||/\b(that'?s all|we'?re done)\b/i.test(n)||e===`bot`&&(/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))||/^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)):!1}function hk({orbColors:e,...t}){return(0,N.jsx)(HD,{colors:e,...t})}function gk({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||lk.green,c=dk(s),l=a?72:94,u=(0,N.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,N.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,N.jsx)(cm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:a?void 0:`210px`},children:e.entryPrompt}),(0,N.jsxs)(cm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,N.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,N.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,N.jsx)(cm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,N.jsx)(hk,{size:l,orbColors:t})})]});return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(cm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,N.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,N.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function _k({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||lk.green,l=dk(c);return(0,N.jsxs)(cm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,N.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,N.jsx)(hk,{size:72,orbColors:t}),(0,N.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,N.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,N.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,N.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function vk(e){try{let t=(new URL(e).pathname.split(`/`).filter(Boolean).pop()||``).replace(/\.(html?|php|aspx?)$/i,``).replace(/[-_+]/g,` `).trim();return t?t.charAt(0).toUpperCase()+t.slice(1):`Home`}catch{return`this page`}}function yk({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,historyRef:o,onMessageSync:s}){let[c,l]=(0,b.useState)(`idle`),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(0),g=(0,b.useRef)(null),_=(0,b.useRef)(``),v=(0,b.useRef)(async()=>{}),y=(0,b.useRef)(!1),x=(0,b.useRef)(!1),ee=(0,b.useRef)(!1),S=(0,b.useRef)(!1),C=(0,b.useRef)(`minimized`),te=(0,b.useRef)(null),w=(0,b.useCallback)((e=`minimized`)=>{C.current=e,S.current=!0,queueMicrotask(()=>{y.current||(y.current=!0,v.current?.())})},[o]),ne=(0,b.useCallback)(async e=>{S.current=!0;try{await g.current?.endSession?.()}catch{}if(g.current=null,l(`idle`),d(!1),y.current=!1,br(),i)try{ke(i)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return v.current=()=>ne(C.current===`chat`?t:n),(0,b.useEffect)(()=>{x.current=u},[u]),(0,b.useEffect)(()=>{let e=!1,n=null;return(async()=>{if(!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],_.current=``,y.current=!1,ee.current=!1,S.current=!1,C.current=`minimized`,yr({onBeforeNavigate:()=>{if(i&&o.current.length>0)try{let e=ZD(o.current);e&&De(i,e)}catch{}if(i&&typeof window<`u`)try{Fe(i,window.location.href)}catch{}je()}});let t=ck(sk({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{w()}})),s=i?Oe(i):null,c=!!s?.transcript,u=c&&i?D(i):null,f=typeof window<`u`?window.location.href:``,p={agentId:r,clientTools:t,overrides:{agent:{firstMessage:c?`I can see we're now on the ${vk(f)} page — feel free to ask me anything about it.`:`Hello! How can I help you today?`}}},v=null;typeof WebSocket<`u`&&(v=WebSocket.prototype.send,WebSocket.prototype.send=function(e){if(typeof e==`string`)try{let t=JSON.parse(e);if(t.type===`conversation_initiation_client_data`&&t.conversation_config_override){let n=t.conversation_config_override;n.tts&&Object.keys(n.tts).length===0&&delete n.tts,n.conversation&&Object.keys(n.conversation).length===0&&delete n.conversation,e=JSON.stringify(t)}}catch{}return v.call(this,e)});let b;try{b=await aD.startSession({...p,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||l(t===`speaking`?`speaking`:`listening`)},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;if(r){if(n===`user`&&(_.current=r),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],i)try{let e=ZD(o.current);e&&De(i,e)}catch{}mk(n,r)&&w(`minimized`)}},onError:t=>{if(!e&&!S.current&&!ee.current&&!Ne()){ee.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{g.current?.setMicMuted?.(!0)}catch{}d(!0),l(`error`),w(`chat`)}},onDisconnect:()=>{if(e||S.current||ee.current||Ne())return;let t=o.current?.length||0;if(console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:t,lastUserText:_.current||``,wasMuted:x.current}),t===0&&m===0){ee.current=!0,console.warn(`[FlowEngageVoiceCall] immediate disconnect, retrying once`),h(1);return}ee.current=!0;try{g.current?.setMicMuted?.(!0)}catch{}d(!0),w(`chat`)}})}finally{v&&(WebSocket.prototype.send=v)}if(e){b.endSession().catch(()=>{});return}n=b,g.current=b,l(`listening`);try{let e=`[]`;try{e=await t.list_page_forms()}catch{}let n=c&&s?.transcript?`Navigation context: agent navigated from ${u?.previousPage||`previous page`} to ${f}.\nPrior conversation:\n${s.transcript}\n\n`:``;b.sendContextualUpdate(n+`Current page: ${f}. SiteId: ${i||`unknown`}. Forms: ${e}. Voice: call end_voice_session or say you are ending the session to stop.`)}catch{}}catch(n){e||(console.error(`[FlowEngage] startSession failed`,n),l(`error`),C.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}})(),()=>{e=!0,S.current=!0,br(),(n||g.current)?.endSession?.().catch(()=>{})}},[r,i,a,w,m]),(0,b.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;te.current&&!te.current.contains(t)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,N.jsxs)(`div`,{ref:te,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[(0,N.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,N.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Listening...`}),(0,N.jsx)(hk,{size:72,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,N.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,N.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,N.jsx)(`button`,{onClick:async()=>{if(g.current)try{u?(await g.current.setMicMuted?.(!1),d(!1)):(await g.current.setMicMuted?.(!0),d(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:u?`#7f1d1d`:`#1f2937`,border:u?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:u?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:u?(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,N.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,N.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,N.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,N.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,N.jsx)(oD,{size:16,color:`currentColor`})}),(0,N.jsx)(`button`,{onClick:()=>p(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,N.jsx)(mD,{size:16,color:`currentColor`})})]}),f&&(0,N.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,N.jsxs)(`button`,{onClick:()=>{p(!1),C.current=`chat`,ne(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(hD,{}),`Enter Chat Mode`]}),(0,N.jsxs)(`button`,{onClick:()=>{p(!1),C.current=`minimized`,ne(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(gD,{}),`End Conversation`]}),(0,N.jsx)(`button`,{onClick:()=>p(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,N.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,N.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function bk({orbColors:e}){return(0,N.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,N.jsx)(hk,{size:36,orbColors:e})})}var xk=()=>(0,N.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,N.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,N.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function Sk({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:d,agentName:f,agentHeadshot:p,fallbackAgentName:m,input:h,setInput:g,onSubmit:_,isConversationEnded:v,isLoading:y,isRateLimited:x,rateLimitMessage:ee,selectedFile:S,onFileSelect:C,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:T,emailError:ae,replyContext:oe,setReplyContext:se,webRTCError:ce,micError:le,setMicError:E,dismissCallError:ue,activeCallId:de,isCallMuted:fe,toggleCallMute:pe,endWebRTCCall:me,formatCallDuration:he,callDurationSeconds:ge,isCallMinimized:_e,onExpand:ve,onCollapse:ye,onStartVoice:be,onNewChat:xe,onEndConversation:Se,showPoweredBy:Ce,getVisitorChatHistory:we,getVisitorChatThread:Te,resumeChat:Ee,isSessionRestoring:De,isClosing:Oe}){let ke=c.length>0,Ae=y||x||v,je=!!de,[Me,Ne]=(0,b.useState)(!1),[Pe,Fe]=(0,b.useState)(!1),[D,Ie]=(0,b.useState)([]),[Le,Re]=(0,b.useState)(!1),[ze,Be]=(0,b.useState)(null),[Ve,He]=(0,b.useState)([]),Ue=(0,b.useRef)(null),We=async()=>{Ne(!1),Fe(!0),Re(!0),Be(null);try{let e=await we();e?.data&&Ie(e.data)}catch(e){console.error(e)}finally{Re(!1)}},Ge=async e=>{Fe(!1),Ee?.(e.chatId)};return(0,b.useEffect)(()=>{if(!Me)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ue.current&&!Ue.current.contains(t)&&Ne(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Me]),(0,N.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`8px`,right:`8px`,bottom:0,width:`calc(100% - 16px)`,height:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Oe?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Oe?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,N.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:`transparent`,flexShrink:0},children:[(0,N.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,N.jsx)(`button`,{onClick:ye,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(0,N.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:`minmax(72px, 40%) minmax(0, 60%)`,alignItems:`center`},children:[(0,N.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,N.jsx)(fk,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,N.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,N.jsx)(pk,{title:e.chatTitle})})}),(0,N.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,N.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]}),(0,N.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:Ue,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ne(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,N.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,N.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,N.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,N.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Me&&(0,N.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),be?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,N.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),xe?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,N.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new conversation`]}),we&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:We,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),(0,N.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{Ne(!1),ye?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,N.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,N.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,N.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,N.jsx)(ND,{webRTCError:ce,micError:le,setMicError:E,dismissCallError:ue,isRateLimited:x,rateLimitMessage:ee}),_e&&(0,N.jsx)(XD,{agentName:f,agentHeadshot:p,fallbackAgentName:m,callDurationSeconds:ge,isCallMuted:fe,formatCallDuration:he,toggleCallMute:pe,endWebRTCCall:me,onExpand:ve,primaryColor:n}),(0,N.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[Pe?(0,N.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,N.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:ze?(0,N.jsxs)(`button`,{onClick:()=>Be(null),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,N.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Back to List`})]}):(0,N.jsxs)(`button`,{onClick:()=>Fe(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,N.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,N.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,N.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:Le&&!ze?(0,N.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):ze?(0,N.jsxs)(`div`,{style:{padding:`20px 16px`},children:[Ve.length===0?(0,N.jsx)(`div`,{style:{color:`#9ca3af`,textAlign:`center`,marginTop:`20px`,fontSize:`14px`},children:`No messages`}):null,Ve.map((e,t)=>(0,N.jsx)(`div`,{style:{marginBottom:`16px`,display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,N.jsx)(`div`,{style:{maxWidth:`85%`,background:e.sender===`user`?n:`#f3f4f6`,color:e.sender===`user`?`white`:`#111827`,padding:`10px 14px`,borderRadius:`14px`,fontSize:`15px`,lineHeight:1.4,wordBreak:`break-word`},children:e.content})},e._id||t))]}):D.length>0?(0,N.jsx)(`div`,{children:D.map(e=>(0,N.jsxs)(`div`,{onClick:()=>Ge(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,N.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,N.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,N.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,ke?(0,N.jsx)(jD,{chatHistory:c,isAiTyping:l,isLoading:y,isAgentTyping:u,setReplyContext:se,TypingDots:xk,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,N.jsx)(bk,{orbColors:t})}):De?(0,N.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,N.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,N.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,N.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,N.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,N.jsx)(hk,{size:94,orbColors:t}),(0,N.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,N.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,N.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),(0,N.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:re?`6px 0 0`:`12px 0 0`},children:(0,N.jsx)(MD,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:je,handleToggleVoice:be,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:Ae,replyContext:oe,clearReplyContext:()=>se(null),onFileSelect:C,selectedFile:S,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:T,emailError:ae,inputPlaceholder:e.inputPlaceholder})}),(0,N.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:Ce&&(0,N.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,N.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function Ck(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:v,callConnectedAt:y,isCallMuted:x,webRTCError:ee,language:S,historyRef:C,onMessageSync:te,sendMessage:w,uploadChatFile:ne,openWidget:re,captureVisitorEmail:ie,setVoiceMode:T,endConversation:ae,startNewChat:oe,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:de,dismissCallError:fe,startTyping:pe,stopTyping:me,updateTypingDraft:he,getVisitorChatHistory:ge,getVisitorChatThread:_e,resumeChat:ve,isSessionRestoring:ye}=jn();(0,b.useEffect)(()=>{try{ir()}catch{}},[]);let be=t?.widgetSettings||{},xe=n?.widgetSettings||{},Se={...be.branding||{},...xe.branding||{}},Ce={...be.theme||{},...xe.theme||{}},we={...be.features||{},...xe.features||{}},Te=we.voice!==!1,Ee=Array.isArray(Ce.orbColors)&&Ce.orbColors.length>0?Ce.orbColors:null,De=Ce.buttonColor||Ce.primaryColor||Ee?.[0]||`#3B82F6`,Ae=Ce.position||`bottom-right`,je=Se.fallbackAgentName||`Agent`,Ne=uk(Ee??Ce.chatBgColors),Pe=Se.logo||Se.logoUrl||null,Fe=S||`en`,D=be.recommendations?.[Fe]||[],Ie=(xe.recommendations?.[Fe]??D).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Le=Array.isArray(Se.quickChatOptions)&&Se.quickChatOptions.length>0?Se.quickChatOptions:Ie,Re=Se.hideWatermark===!0?!1:Se.showPoweredBy!==!1,ze=Se.chatbotEnabled!==!1&&Ce.chatbotEnabled!==!1,Be=be.greetings?.[S]||xe.greetings?.[S]||Se.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Ve={entryPrompt:Se.entryPrompt||`Do you want to explore in a new way?`,yesLabel:Se.yesLabel||`Yes`,laterLabel:Se.laterLabel||`Later`,connectionTitle:Se.connectionTitle||`How would you like to connect?`,voiceLabel:Se.voiceLabel||`Voice`,textLabel:Se.textLabel||`Text`,chatTitle:Se.headerName||`Chat with FlowEngage`,introGreeting:Be,inputPlaceholder:Se.inputPlaceholder||`Type your message`,analysingLabel:Se.analysingLabel||`analysing...`},He=xe.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ue=t?.siteId||n?.siteId||null,We=t?.apiBaseUrl||``,Ge=(0,b.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Ke=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,qe=r.some(e=>e.sender===`user`),Je=(0,b.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),Ye=!l&&qe&&Je,Xe=!!(xe._dashboardLivePreview||be._dashboardLivePreview),[Ze,O]=(0,b.useState)(()=>Xe?`text_chat`:`entry_prompt`),[k,A]=(0,b.useState)(``),[Qe,$e]=(0,b.useState)(null),[et,tt]=(0,b.useState)(l||``),[nt,rt]=(0,b.useState)(``),[it,at]=(0,b.useState)(0),[ot,st]=(0,b.useState)(null),[ct,lt]=(0,b.useState)(null),[ut,dt]=(0,b.useState)(``),[ft,pt]=(0,b.useState)(!1),[mt,ht]=(0,b.useState)(!1),[gt,_t]=(0,b.useState)(!1),vt=(0,b.useRef)(null),yt=(0,b.useRef)(!1);(0,b.useLayoutEffect)(()=>{if(e!==`ready`||yt.current)return;if(yt.current=!0,!Te){O(`minimized_orb`);return}let t=!1;try{t=hr().shouldResumeVoice}catch{}let n=Me(),r=Ue?Oe(Ue):null,i=n||!!r?.transcript;if(t){re?.({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`);return}if(Ue)try{ke(Ue)}catch{}if(i){re?.({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`);return}if(E(Ue)){O(`minimized_orb`);return}},[e,r]);let[bt,xt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>xt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{tt(l||``),l&&rt(``)},[l]);let St=(0,b.useCallback)(()=>{lt(null),dt(``)},[]),Ct=(0,b.useCallback)(e=>{let t=ED(e);if(t){lt(null),dt(t);return}lt(e),dt(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){at(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||at(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]);let wt=(0,b.useCallback)(()=>{O(`call_screen`),ht(!1)},[]),Tt=(0,b.useCallback)(()=>{O(`text_chat`),ht(!0)},[]);(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){vt.current=null;return}if(g?.callId||v===`connecting`||v===`connected`){if(Ze===`minimized_orb`&&mt&&_&&!g?.callId){vt.current=e;return}!(!i||Ze===`minimized_orb`||Ze===`voice_mode`)&&vt.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:Ze,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),vt.current=e,Ze===`voice_mode`&&T?.(!1),re?.(),wt())}},[_,v,wt,g?.callId,i,re,T,Ze]),(0,b.useEffect)(()=>{!g&&!_&&Ze===`call_screen`&&O(`text_chat`)},[g,_,Ze]),(0,b.useEffect)(()=>{!_&&mt&&ht(!1)},[_,mt]),(0,b.useEffect)(()=>{if(!o||h){he?.(``),me?.();return}if(!k.trim()||ct){he?.(``);let e=window.setTimeout(()=>me?.(),100);return()=>window.clearTimeout(e)}pe?.();let e=window.setTimeout(()=>he?.(k),120),t=window.setTimeout(()=>me?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[k,ct,o,h,pe,me,he]);let Et=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Dt=async e=>{if(e.preventDefault(),h)return;if(Ye){let e=et.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){rt(`Please enter a valid email so we can continue helping you.`);return}await ie(e),rt(``);return}let t=Et(Qe);if(!k.trim()&&!ct)return;if(ct){try{pt(!0),dt(``);let e=await ne(ct),n=e?.data||e,r=k.trim()||`Shared file: ${OD(ct)}`;A(``),$e(null),St(),await w(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||ct.name,fileType:n?.fileType||ct.type,fileSize:n?.fileSize||ct.size}})}catch(e){dt(e?.message||`Failed to upload the selected file.`)}finally{pt(!1)}return}let n=k.trim();A(``),$e(null),await w(n,``,t)},Ot=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},kt=(0,b.useCallback)(async e=>{if(h||f)return;let t=e.message||e.label||e.text||``;t.trim()&&await w(t.trim(),``)},[h,f,w]),At=bt&&Ze===`entry_prompt`?{inset:0}:bt&&Ze===`text_chat`?{left:0,right:0,bottom:0}:bt&&Ze===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:bt&&Ze===`connection_modal`?{left:`28px`,right:`12px`,bottom:`12px`}:Ze===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ae===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`}}:Ae===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},jt=(0,b.useCallback)(()=>{Ze!==`minimized_orb`&&(_t(!0),setTimeout(()=>{O(`minimized_orb`),_t(!1)},280))},[Ze]),Mt=()=>O(`connection_modal`),Nt=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}re({notifyChatInitiated:!0}),T?.(!0),O(`voice_mode`)},Pt=()=>{re({notifyChatInitiated:!0}),T?.(!1),O(`text_chat`)},Ft=()=>{T?.(!1),jt()};return e!==`ready`||!ze||we.chat===!1?null:(0,N.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...At},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[Ze===`entry_prompt`&&(0,N.jsx)(gk,{copy:Ve,orbColors:Ee,primaryColor:De,onYes:()=>{ue(Ue),Nt()},onLater:()=>{ue(Ue),jt()},isMobile:bt,isClosing:gt}),Ze===`minimized_orb`&&(0,N.jsxs)(cm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ae===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[_&&mt&&(0,N.jsxs)(`button`,{type:`button`,onClick:wt,style:{maxWidth:bt?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,N.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,N.jsxs)(`span`,{style:{minWidth:0},children:[(0,N.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:v===`connected`?`Call in progress`:`Call is active`}),(0,N.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:v===`connected`?`${Ot(it)} with ${Ge}`:`Tap to return to ${Ge}`})]})]}),(0,N.jsx)(hk,{size:50,orbColors:Ee,onClick:_&&mt?wt:Te?Mt:Pt})]}),Ze===`connection_modal`&&(0,N.jsx)(_k,{copy:Ve,orbColors:Ee,primaryColor:De,onVoice:Nt,onText:Pt,onClose:jt,isMobile:bt,isClosing:gt}),Ze===`voice_mode`&&(0,N.jsx)(yk,{orbColors:Ee,onEnterChat:Pt,onEndChat:Ft,agentId:He,siteId:Ue,apiBaseUrl:We,historyRef:C,onMessageSync:te},`voice`),Ze===`call_screen`&&(0,N.jsx)(YD,{incomingCall:g,activeCallId:_,callConnectionState:v,callDurationSeconds:it,isCallMuted:x,agentName:Ge,agentHeadshot:Ke,fallbackAgentName:je,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:de,formatCallDuration:Ot,onMinimize:Tt,primaryColor:De,orbColors:Ee,chatHistory:r}),Ze===`text_chat`&&(0,N.jsx)(Sk,{isClosing:gt,copy:Ve,orbColors:Ee,primaryColor:De,chatBgGradient:Ne,logo:Pe,quickChatOptions:Le,onQuickChatSelect:kt,isMobile:bt,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:Ge,agentHeadshot:Ke,fallbackAgentName:je,input:k,setInput:A,onSubmit:Dt,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:ct,onFileSelect:Ct,onRemoveSelectedFile:St,attachmentError:ut,isUploadingAttachment:ft,requiresEmail:Ye,emailInput:et,setEmailInput:tt,emailError:nt,replyContext:Qe,setReplyContext:$e,webRTCError:ee,micError:ot,setMicError:st,dismissCallError:fe,activeCallId:_,isCallMuted:x,toggleCallMute:de,endWebRTCCall:le,formatCallDuration:Ot,callDurationSeconds:it,onCollapse:jt,onStartVoice:Nt,onNewChat:oe,onEndConversation:ae,onMinimize:Tt,onExpand:wt,isCallMinimized:mt&&!!_,showPoweredBy:Re,getVisitorChatHistory:ge,getVisitorChatThread:_e,resumeChat:ve,isSessionRestoring:ye}),(0,N.jsx)(`style`,{children:`
|
|
644
644
|
/* Force any SVG (or img) inside LogoSlot to fill the container height
|
|
645
645
|
regardless of whether the component forwards its style prop. */
|
|
646
646
|
.fe-logo-slot svg,
|
|
@@ -659,4 +659,4 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
659
659
|
@keyframes fe-orb-bar-3 { from{height:8px} to{height:20px} }
|
|
660
660
|
@keyframes fe-orb-bar-4 { from{height:6px} to{height:16px} }
|
|
661
661
|
@keyframes fe-dot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.5} 40%{transform:translateY(-5px);opacity:1} }
|
|
662
|
-
`})]})}var Ck=`:host{all:initial;box-sizing:border-box!important;color:#111827!important;-webkit-font-smoothing:antialiased!important;z-index:2147483647!important;background:0 0!important;border:none!important;margin:0!important;padding:0!important;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif!important;font-size:16px!important;line-height:1.5!important;display:block!important;position:relative!important}:host *,:host :before,:host :after{box-sizing:border-box}.flowengage-widget-root{-moz-osx-font-smoothing:grayscale;text-rendering:optimizelegibility;color:#111827!important;-webkit-font-smoothing:antialiased!important;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif!important;font-size:16px!important;line-height:1.5!important}.flowengage-widget-root *,.flowengage-widget-root :before,.flowengage-widget-root :after{font-family:inherit!important}.flowengage-widget-root input,.flowengage-widget-root textarea,.flowengage-widget-root button,.flowengage-widget-root select,.flowengage-widget-root optgroup,.flowengage-widget-root option{font-size:inherit;line-height:inherit;font-family:inherit!important}.flowengage-shell,.flowengage-shell *{font-family:inherit!important}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}.flowengage-chat-text-input{margin:0!important}.flowengage-chat-text-input:focus{box-shadow:none!important;border:none!important;outline:none!important}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(350px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, var(--flowengage-accent) 45%, var(--flowengage-primary) 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes pulse{0%{opacity:1;transform:scale(.8)}to{opacity:0;transform:scale(2)}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-accent) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}`,wk=null,Tk=!1;function Ek(){let e=document.createElement(`div`);e.id=`flowengage-root`;let t=e.attachShadow({mode:`open`}),n=document.createElement(`style`);n.textContent=Ck,t.appendChild(n);let r=document.createElement(`div`);return r.setAttribute(`data-flowengage-mount`,`true`),r.className=`flowengage-widget-root`,t.appendChild(r),{host:e,mount:r}}function Dk(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function Ok({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Tk){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),Dk(()=>Ok({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let{host:i,mount:a}=Ek();document.body.appendChild(i),wk=(0,x.createRoot)(a);let o={widgetSettings:n,...r&&{apiBaseUrl:r}};wk.render(b.createElement(Ar,{siteId:e,language:t,config:o},b.createElement(Sk))),Tk=!0}var kk={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Dk(()=>Ok({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):Dk(()=>Ok({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){wk&&=(wk.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Tk=!1}},Ak=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};Dk(()=>Ok({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,Ak):Ak(),typeof window<`u`&&(window.FlowEngage=kk),kk})();
|
|
662
|
+
`})]})}var wk=`:host{all:initial;box-sizing:border-box!important;color:#111827!important;-webkit-font-smoothing:antialiased!important;z-index:2147483647!important;background:0 0!important;border:none!important;margin:0!important;padding:0!important;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif!important;font-size:16px!important;line-height:1.5!important;display:block!important;position:relative!important}:host *,:host :before,:host :after{box-sizing:border-box}.flowengage-widget-root{-moz-osx-font-smoothing:grayscale;text-rendering:optimizelegibility;color:#111827!important;-webkit-font-smoothing:antialiased!important;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif!important;font-size:16px!important;line-height:1.5!important}.flowengage-widget-root *,.flowengage-widget-root :before,.flowengage-widget-root :after{font-family:inherit!important}.flowengage-widget-root input,.flowengage-widget-root textarea,.flowengage-widget-root button,.flowengage-widget-root select,.flowengage-widget-root optgroup,.flowengage-widget-root option{font-size:inherit;line-height:inherit;font-family:inherit!important}.flowengage-shell,.flowengage-shell *{font-family:inherit!important}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}.flowengage-chat-text-input{margin:0!important}.flowengage-chat-text-input:focus{box-shadow:none!important;border:none!important;outline:none!important}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(350px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, var(--flowengage-accent) 45%, var(--flowengage-primary) 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes pulse{0%{opacity:1;transform:scale(.8)}to{opacity:0;transform:scale(2)}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-accent) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}`,Tk=null,Ek=!1;function Dk(){let e=document.createElement(`div`);e.id=`flowengage-root`;let t=e.attachShadow({mode:`open`}),n=document.createElement(`style`);n.textContent=wk,t.appendChild(n);let r=document.createElement(`div`);return r.setAttribute(`data-flowengage-mount`,`true`),r.className=`flowengage-widget-root`,t.appendChild(r),{host:e,mount:r}}function Ok(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function kk({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Ek){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),Ok(()=>kk({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let{host:i,mount:a}=Dk();document.body.appendChild(i),Tk=(0,x.createRoot)(a);let o={widgetSettings:n,...r&&{apiBaseUrl:r}};Tk.render(b.createElement(Ar,{siteId:e,language:t,config:o},b.createElement(Ck))),Ek=!0}var Ak={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Ok(()=>kk({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):Ok(()=>kk({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){Tk&&=(Tk.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Ek=!1}},jk=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};Ok(()=>kk({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,jk):jk(),typeof window<`u`&&(window.FlowEngage=Ak),Ak})();
|
|
@@ -632,7 +632,7 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
632
632
|
fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
|
|
633
633
|
filter="url(#${Q}-csh)"/>
|
|
634
634
|
</svg>`,mO=null,hO=!1;function gO(){return(!mO||!mO.isConnected)&&(mO=document.createElement(`div`),mO.id=`${Q}-cursor`,mO.innerHTML=pO,document.body.appendChild(mO),hO=!1),mO}async function _O(e){if(typeof document>`u`||!e)return;$D();let t;try{t=e.getBoundingClientRect()}catch{return}let n=t.left+Math.min(16,t.width*.2),r=t.top+Math.min(12,t.height*.25),i=gO();hO||=(i.style.transition=`none`,i.style.left=`${window.innerWidth/2}px`,i.style.top=`${window.innerHeight*.4}px`,i.classList.add(`${Q}-cursor-visible`),i.offsetHeight,i.style.transition=`left 0.32s cubic-bezier(0.25,0.46,0.45,0.94), top 0.32s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.2s ease`,!0),i.style.left=`${n}px`,i.style.top=`${r}px`,await xO(360)}function vO(e=!1){mO&&(e?(mO.classList.remove(`${Q}-cursor-visible`),hO=!1):(mO.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{hO=!1},250)))}async function yO(e){mO&&(mO.classList.add(`${Q}-cursor-click`),await xO(280),mO.classList.remove(`${Q}-cursor-click`))}function bO(e){if(!e||typeof document>`u`)return;$D();let t;try{t=e.getBoundingClientRect()}catch{return}let n=e.style.position,r=e.style.overflow,i=window.getComputedStyle(e).position;[`relative`,`absolute`,`fixed`,`sticky`].includes(i)||(e.style.position=`relative`),e.style.overflow=`hidden`;let a=document.createElement(`span`);a.className=`${Q}-ripple`;let o=Math.max(t.width,t.height)*1.2;Object.assign(a.style,{width:`${o}px`,height:`${o}px`,left:`${t.width/2-o/2}px`,top:`${t.height/2-o/2}px`}),e.appendChild(a),setTimeout(()=>{a.remove(),e.style.position=n,e.style.overflow=r},650)}function xO(e){return new Promise(t=>setTimeout(t,e))}function $(...e){Tn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function SO(e){return new Promise(t=>setTimeout(t,e))}var CO=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function wO(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(CO)}catch{return!1}}function TO(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function EO(e){let t=new Set;function n(r){if(!r||t.has(r))return;t.add(r),e(r);let i=r.querySelectorAll(`iframe`);for(let e of i)if(!wO(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function DO(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function OO(e){let t=e.ownerDocument||document,n=e.getAttribute(`aria-labelledby`);if(n){let e=n.trim().split(/\s+/).filter(Boolean),r=[];for(let n of e)try{let e=t.getElementById(n);e?.textContent&&r.push(e.textContent.trim())}catch{}if(r.length)return DO(r.join(` `))}if(e.labels&&e.labels.length)return DO(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return DO(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return DO(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return DO(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=DO(i.textContent);if(e)return e}i=i.previousElementSibling}let a=e.parentElement;for(let e=0;e<5&&a;e+=1){if(a.tagName===`LABEL`)return DO(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return DO(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?DO(o):null}function kO(){let e=[];return EO(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(wO(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=TO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function AO(){return kO().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:OO(e),placeholder:e.placeholder||null}))}function jO(){let e=[];return EO(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(wO(e)||e.disabled)return!1;try{let t=TO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function MO(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function NO(e){let t=MO(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function PO(e,t){let n=NO(t);if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,OO(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>MO(e)),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var FO=28;function IO(e,t){let n=null,r=0;for(let i of e){let e=PO(i,t);e>r&&(r=e,n=i)}return!n||r<FO?null:n}function LO(e,t,n){let r=String(t||``).toLowerCase().trim(),i=String(n||``).trim();if(!(/^https?:\/\//i.test(i)||/\.\w{2,}(\/|\s|$)/.test(i)||r.includes(`url`)||r.includes(`website`)||r.includes(`domain`)||r.includes(`site`)))return null;let a=null,o=0;for(let t of e){if(t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`)continue;let e=(t.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`checkbox`,`radio`].includes(e))continue;let n=0;(e===`url`||e===`text`||e===`search`)&&(n+=45);let r=[t.name,t.id,t.placeholder,OO(t),t.getAttribute(`aria-label`),t.getAttribute(`autocomplete`)].filter(Boolean).join(` `).toLowerCase();/(website|url|domain|site\s*url)/.test(r)&&(n+=55),n>o&&(o=n,a=t)}return!a||o<42?null:a}function RO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function zO(e){let t=String(e??``).toLowerCase().trim();return t?!!(t===`url`||t===`website`||t===`website url`||t===`website_url`||t===`enter website url`||t.includes(`website`)||t.includes(`domain`)||/(enter\s+website|site\s*url|page\s*url)/.test(t)):!1}function BO(e){if(!e||e.tagName!==`INPUT`&&e.tagName!==`TEXTAREA`)return!1;let t=(e.type||``).toLowerCase();return![`hidden`,`submit`,`button`,`checkbox`,`radio`,`file`].includes(t)}function VO(e){if(!BO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,OO(e),e.getAttribute(`aria-label`)].filter(Boolean).join(` `).toLowerCase();return t===`url`||n===`url-input`||n.endsWith(`-url-input`)||/(website\s*url|enter\s+website|site\s*url)/.test(r)||/(website|domain)/.test(r)&&/(url|site)/.test(r)}function HO(e,t,n){let r=String(t??``),i=String(n??``),a=GO(e,r)||IO(e,r)||LO(e,r,i);if(!a)return[];let o=new Set([a]);if(RO(i)&&zO(r))for(let t of e)t!==a&&VO(t)&&o.add(t);let s=Array.from(o);return s.sort((e,t)=>{if(e===t)return 0;let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0}),s}function UO(e,t){try{if(!e?.getBoundingClientRect||!t?.getBoundingClientRect)return 1/0;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i={x:n.left+n.width/2,y:n.top+n.height/2},a={x:r.left+r.width/2,y:r.top+r.height/2};return Math.hypot(i.x-a.x,i.y-a.y)}catch{return 1/0}}function WO(e){if(!e||typeof e!=`string`)return null;let t=null;return EO(n=>{try{let r=n.getElementById(e);r&&!wO(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function GO(e,t){let n=String(t??``).trim();if(!n)return null;let r=n.match(/^name:\s*([\w.-]+)$/i);if(r){let t=r[1];for(let n of e)if(n.name===t)return n}let i=n.match(/^id:\s*([\w.-]+)$/i);if(i){let e=WO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=WO(a);if(e)return e}let o=n.toLowerCase().replace(/\s+/g,` `);if(o===`url`||o===`website`||o===`website url`||o===`website_url`||o===`enter website url`)for(let t of e){let e=(t.name||``).toLowerCase(),n=(t.id||``).toLowerCase();if(e===`url`||n===`url-input`||n.endsWith(`-url-input`))return t}return null}function KO(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.textContent,e.value,e.getAttribute(`aria-label`),e.getAttribute(`title`)].filter(Boolean).join(` `).toLowerCase().replace(/\s+/g,` `);if(r.includes(n))return 100;let i=n.split(/\s+/).filter(e=>e.length>1);if(!i.length)return 0;let a=0;for(let e of i)r.includes(e)&&(a+=1);return a/i.length*92}function qO(e,t){let n=[];EO(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(wO(e)||e.disabled)return!1;try{let t=TO(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:KO(t,e)}));for(let{s:e}of i)e>r&&(r=e);if(r<36)return null;let a=i.filter(({s:e})=>e===r).map(({el:e})=>e);if(a.length===1)return a[0];let o=Array.isArray(t)?t.filter(e=>e&&e.isConnected):[];if(o.length){let e=a[0],t=1/0;for(let n of a)for(let r of o){let i=UO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function JO(e){if(e==null)return{};if(typeof e==`string`){let t=e.trim();if(!t)return{};try{return JSON.parse(t)}catch{return{url:t}}}return e}function YO(e){let t=JO(e);if(Array.isArray(t)&&t.length>0){let e=t[0];if(e?.field_key!=null||e?.fieldKey!=null)return t.map(e=>({field_key:e.field_key??e.fieldKey,value:e.value}))}if(!t||typeof t!=`object`)return[];let n=t.fields??t.Fields??t.field_list??t.fieldList??t.data?.fields;if(typeof n==`string`)try{n=JSON.parse(n)}catch{n=null}n&&!Array.isArray(n)&&typeof n==`object`&&(n=Object.values(n)),(!n||n.length===0)&&(t.field_key!=null||t.fieldKey!=null)&&t.value!=null&&(n=[{field_key:t.field_key??t.fieldKey,value:t.value}]);let r=t.website_url??t.websiteUrl??t.url??t.website??t.domain??t.site_url??t.siteUrl;return(!n||n.length===0)&&r!=null&&String(r).trim()&&(n=[{field_key:t.field_key??t.fieldKey??`url`,value:String(r).trim()}]),Array.isArray(n)?n.map(e=>({field_key:e?.field_key??e?.fieldKey,value:e?.value??e?.Value})):[]}function XO(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!t||/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\b/i.test(t))return[];let n=t.match(/https?:\/\/[^\s<>"']+/i);if(n)return[{field_key:`url`,value:n[0].replace(/[.,;:)]+$/,``)}];let r=t.match(/\b(?:[\w-]+\.)+[a-z]{2,}\b/i);if(r){let e=r[0].replace(/[.,;:)]+$/,``);return/^https?:/i.test(e)||(e=`https://${e}`),[{field_key:`url`,value:e}]}return[]}function ZO(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!t)return[];let n=[],r=new Set,i=/\b([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\b/i,a=(e,t)=>{let i=String(t??``).trim().replace(/^["']|["']$/g,``);if(!i||i.length>800)return;let a=`${e}\0${i}`;r.has(a)||(r.add(a),n.push({field_key:e,value:i}))},o=t.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);if(o)return a(`Email Address`,o[1]),n;let s=t.match(/\b(?:please\s+)?(?:enter|type|put)\s+(.+?)\s+in(?:to)?\s+(?:the\s+)?(?:full\s*name|full\s*name\s*field|name\s*field)\b/i);if(s&&a(`Full Name`,s[1]),s=t.match(/\bfull\s*name,?\s*(?:please\s+)?(?:enter|type|put)\s+(.+?)(?:\.|$|!|\?)/i),s&&a(`Full Name`,s[1]),s=t.match(/\bfull\s*name\s*(?:is|:|please\s+enter|-)\s*(.+?)(?:\.|$|(?=\s+(?:and|my\s+email|email|message))\b)/i),s&&a(`Full Name`,s[1]),s=t.match(/\b(.+?)\s+for\s+(?:the\s+)?full\s*name\b/i),s){let e=s[1].trim();e.length>1&&e.length<120&&!/@/.test(e)&&a(`Full Name`,e)}if(s=t.match(/\b(?:email|e-mail)(?:\s*address)?\s*(?:is|:|please\s+use|enter|-)\s*([^\s@]+@[^\s@]+\.[^\s,]+)/i),s&&a(`Email Address`,s[1]),s=t.match(/\b(?:enter|type|put)\s+([^\s@]+@[^\s@]+\.[^\s,]+)\s+in(?:to)?\s+(?:the\s+)?(?:email|e-mail)/i),s&&a(`Email Address`,s[1]),s=t.match(/\b(?:message|comment)\s*(?:is|:|please\s+enter|-)\s*(.+)$/is),s){let e=s[1].trim();e.length>0&&a(`Message`,e)}if(!n.some(e=>/email/i.test(String(e.field_key)))){let e=t.match(i);if(e){let r=t.replace(e[0],``).trim().replace(/^(please|it's|it is|use|is|my email is|e-?mail is)\s*/i,``).replace(/[.,;:!?]+$/,``).trim();if(t.length<=96&&r.length<=36)return a(`Email Address`,e[1]),n}}if(n.length===0){let e=t.split(/\s+/).filter(Boolean).length,n=/[.!?]/.test(t)||e>=6||t.length>=24&&e>=5||t.length>=42,r=/^[A-Z][a-z]+\s+[A-Z][a-z]+$/.test(t.trim());n&&t.length>=16&&!i.test(t)&&!r&&a(`Message`,t)}return n}function QO(e){if(!e||typeof e!=`object`)return null;let t=e.url??e.target_url??e.page_url??e.pageUrl??e.link??e.href??e.path;return t==null?null:String(t).trim()||null}function $O(e){if(!e||typeof e!=`object`)return null;let t=e.query??e.q??e.search??e.text??e.keywords;return t==null?null:String(t).trim()||null}function ek(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase();if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let a=String(t);if(r===`INPUT`||r===`TEXTAREA`){let t=e.ownerDocument?.defaultView||window,n=r===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,`value`);i?.set?i.set.call(e,a):e.value=a}else e.value=a;let o={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...o,inputType:`insertText`,data:a}))}catch{e.dispatchEvent(new Event(`input`,o))}e.dispatchEvent(new Event(`change`,o));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,o)),e.dispatchEvent(new Event(`change`,o))}catch{}})}catch{}return!0}function tk(){let e={};document.querySelectorAll(`h1, h2, h3, h4, h5, h6`).forEach(t=>{if(t.id)return;let n=t.textContent.trim();if(!n)return;let r=n.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``).substring(0,60);if(e[r]){let t=2;for(;e[r+`-`+t];)t++;r=r+`-`+t}e[r]=!0,t.id=r})}function nk(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={flowengage_navigate:async n=>{$(`flowengage_navigate ▶ raw parameters:`,n);let i=JO(n),a=QO(i),o=i.section_text??i.sectionText??i.section,s=Array.isArray(i.expected_landmarks)?i.expected_landmarks:Array.isArray(i.expectedLandmarks)?i.expectedLandmarks:[];if($(`flowengage_navigate · coerced:`,{url:a,sectionText:o,expectedLandmarks:s}),!a){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(typeof window<`u`)try{let e=new URL(a,window.location.href);e.origin!==window.location.origin&&/^https?:$/i.test(e.protocol)&&(a=e.pathname+e.search+e.hash,$(`flowengage_navigate · normalized cross-origin URL to path:`,a))}catch{}if(!await ir(a,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`Page "${a}" could not be verified. Call flowengage_search with keywords from the topic to find the correct URL, then navigate to the URL from the search results.`;return $(`flowengage_navigate ✖ blocked`,e),e}try{rO(`Navigating to ${a}...`,{spinner:!0}),cO(),JD(),QD();try{let e=r?r():``;if(e&&t){let n=KD([{sender:`user`,message:e}]);n&&Se(t,n)}}catch{}return Ee(),t&&typeof window<`u`&&Ae(t,window.location.href),$(`flowengage_navigate → real navigation`,a),setTimeout(()=>{try{window.location.assign(a)}catch{}},150),`OK_NAVIGATE_RELOADING. Navigating to the page now; the voice session will resume automatically. Do not speak until the user speaks first after the page loads.`}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),rO(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{lO(),iO(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=JO(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;tk();let i=$n(n||null,r||null);return!i&&r&&(await new Promise(e=>setTimeout(e,500)),tk(),i=$n(null,r)),i?(ZD(i),$(`flowengage_highlight ✓`,r||n),`OK_HIGHLIGHT: "${r||n}"`):($(`flowengage_highlight ✖ no element for:`,r||n),`Could not find "${r||n}" on the current page. Try a shorter phrase matching a visible heading.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=JO(e),n=t?.section_text||t?.sectionText||``;try{let e=``;if(n){let t=$n(null,n);if(!t)return`Could not find section "${n}" on the page.`;let r=[t.textContent.trim()],i=t.nextElementSibling;for(;i&&!/^H[1-3]$/i.test(i.tagName);){let e=i.textContent.trim();e&&r.push(e),i=i.nextElementSibling}e=r.join(`
|
|
635
|
-
`)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`flowengage_read_content ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`flowengage_read_content ✖`,e.message),`Could not read page content: ${e.message}`}},flowengage_search:async e=>{$(`flowengage_search ▶`,e);let r=$O(JO(e));if($(`flowengage_search · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`flowengage_search ✖ missing query`),`Missing query parameter.`;if(!t)return $(`flowengage_search ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`flowengage_search ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`flowengage_search → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`flowengage_search · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return $(`flowengage_search ✖`,e),e}let o=a.results||[];return $(`flowengage_search ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return $(`flowengage_search ✖`,t),t}},flowengage_page_content:async e=>{$(`flowengage_page_content ▶`,e);let r=JO(e),i=r?.url||r?.page_url||``;if($(`flowengage_page_content · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`flowengage_page_content ✖ missing url`),`Missing url parameter.`;if(!t)return $(`flowengage_page_content ✖ no siteId`),`Site is not configured.`;if(!n)return $(`flowengage_page_content ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`flowengage_page_content → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`flowengage_page_content · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`flowengage_page_content ✖`,e),e}return $(`flowengage_page_content ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`flowengage_page_content ✖`,t),t}},flowengage_end_session:async()=>($(`flowengage_end_session ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),flowengage_list_forms:async()=>{let e=AO(),t=jO();return $(`flowengage_list_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: placeholder/label, name (e.g. url), id (e.g. url-input). If the page has two URL boxes, flowengage_fill_form sets all matching URL inputs. flowengage_click_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},flowengage_fill_form:async e=>{try{$(`flowengage_fill_form ▶ raw:`,e),uO();let t=YO(e);if(!t.length&&r){let e=r(),n=XO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=ZO(e),n.length&&$(`flowengage_fill_form · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`flowengage_fill_form · normalized fields:`,t),!t.length)return`No fields provided. Call flowengage_list_forms for field_key strings, then flowengage_fill_form with { "fields": [ { "field_key": "<label or placeholder from list>", "value": "<user value>" } ] }. Never use empty {}. Pass the value the user just said (email, message, name, URL) in fields.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;rO(`Filling ${String(t)}...`,{spinner:!0});let a=kO(),o=HO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())dO(t),await _O(t),ek(t,r,{skipScroll:e>0}),fO(t),await SO(120);i=o,n.push(String(t));continue}let s=GO(a,String(t));s||=IO(a,String(t)),s||=LO(a,String(t),r),s&&(dO(s),await _O(s),ek(s,r),fO(s),await SO(120),i=[s],n.push(String(t)))}if(!n.length)return $(`flowengage_fill_form ✖ no matches`),`Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.`;let a=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,a),rO(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),a}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),rO(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{vO(),uO(),iO(700)}},flowengage_click_button:async e=>{let t=JO(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`flowengage_click_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=qO(n,i);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{rO(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await _O(r),r.focus?.(),await yO(r),bO(r),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`flowengage_click_button ✓`,t),rO(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),rO(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{vO(),iO(700)}}};return{...a,highlightOnPage:a.flowengage_highlight,searchSiteContent:a.flowengage_search,getPageContent:a.flowengage_page_content,endVoiceSession:a.flowengage_end_session,listPageForms:a.flowengage_list_forms,fillFormFields:a.flowengage_fill_form,clickPageButton:a.flowengage_click_button}}function rk(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Tn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var ik={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function ak(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function ok(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function sk({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,f.jsx)(`img`,{src:e,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}});let n=typeof e==`function`?d.default.createElement(e):d.default.isValidElement(e)?e:null;return n?(0,f.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function ck({title:e}){return(0,f.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function lk(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||/\b(that'?s all|we'?re done)\b/i.test(n)||e===`bot`&&(/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))||/^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)):!1}function uk({orbColors:e,...t}){return(0,f.jsx)(LD,{colors:e,...t})}function dk({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||ik.green,c=ok(s),l=a?72:94,u=(0,f.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,f.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,f.jsx)(dm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:a?void 0:`210px`},children:e.entryPrompt}),(0,f.jsxs)(dm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,f.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,f.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,f.jsx)(dm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,f.jsx)(uk,{size:l,orbColors:t})})]});return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(dm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,f.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,f.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function fk({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||ik.green,l=ok(c);return(0,f.jsxs)(dm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,f.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,f.jsx)(uk,{size:72,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,f.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,f.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function pk({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,historyRef:o,onMessageSync:s}){let[c,l]=(0,d.useState)(`idle`),[u,p]=(0,d.useState)(!1),[m,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(0),v=(0,d.useRef)(null),y=(0,d.useRef)(``),b=(0,d.useRef)(async()=>{}),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),ee=(0,d.useRef)(!1),te=(0,d.useRef)(!1),ne=(0,d.useRef)(`minimized`),re=(0,d.useRef)(null),ie=(0,d.useCallback)((e=`minimized`)=>{ne.current=e,te.current=!0,queueMicrotask(()=>{x.current||(x.current=!0,b.current?.())})},[o]),ae=(0,d.useCallback)(async e=>{te.current=!0;try{await v.current?.endSession?.()}catch{}if(v.current=null,l(`idle`),p(!1),x.current=!1,pr(),i)try{we(i)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return b.current=()=>ae(ne.current===`chat`?t:n),(0,d.useEffect)(()=>{S.current=u},[u]),(0,d.useEffect)(()=>{let e=!1,n=null;return(async()=>{if(!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],y.current=``,x.current=!1,ee.current=!1,te.current=!1,ne.current=`minimized`,fr({onBeforeNavigate:()=>{if(i&&o.current.length>0)try{let e=KD(o.current);e&&Se(i,e)}catch{}if(i&&typeof window<`u`)try{Ae(i,window.location.href)}catch{}Ee()}});let t=rk(nk({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>y.current,requestEndSession:()=>{ie()}})),s=i?Ce(i):null,c=!!s?.transcript,u=c&&i?je(i):null,d={agentId:r,clientTools:t},f=await eD.startSession({...d,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||l(t===`speaking`?`speaking`:`listening`)},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;if(r){if(n===`user`&&(y.current=r),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],i)try{let e=KD(o.current);e&&Se(i,e)}catch{}lk(n,r)&&ie(`minimized`)}},onError:t=>{if(!e&&!te.current&&!ee.current&&!Oe()){ee.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{v.current?.setMicMuted?.(!0)}catch{}p(!0),l(`error`),ie(`chat`)}},onDisconnect:()=>{if(e||te.current||ee.current||Oe())return;let t=o.current?.length||0;if(console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:t,lastUserText:y.current||``,wasMuted:S.current}),t===0&&g===0){ee.current=!0,console.warn(`[FlowEngageVoiceCall] immediate disconnect, retrying once`),_(1);return}ee.current=!0;try{v.current?.setMicMuted?.(!0)}catch{}p(!0),ie(`chat`)}});if(e){f.endSession().catch(()=>{});return}n=f,v.current=f,l(`listening`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.list_page_forms()}catch{}let r=c?`AGENT-DRIVEN NAVIGATION. You navigated the visitor to a new page. `+(u?.previousPage?`They came FROM: ${u.previousPage}. `:``)+`Current page URL: ${e}. Do NOT say "Hello". Do NOT re-introduce yourself. Speak ONE short sentence acknowledging the new page and offering help. Example: "I can see we're now on the Pricing page — feel free to ask me anything about it." Keep it to one sentence, natural and conversational.\nPrior conversation:\n${s.transcript}\n\n`:`Greet the visitor with a short, warm, friendly opening message. Be natural and conversational. `;f.sendContextualUpdate(r+`Current page: ${e}. SiteId: ${i||`unknown`}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`)}catch{}}catch(n){e||(console.error(`[FlowEngage] startSession failed`,n),l(`error`),ne.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}})(),()=>{e=!0,te.current=!0,pr(),(n||v.current)?.endSession?.().catch(()=>{})}},[r,i,a,ie,g]),(0,d.useEffect)(()=>{if(!m)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;re.current&&!re.current.contains(t)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[m]),(0,f.jsxs)(`div`,{ref:re,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[(0,f.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,f.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Listening...`}),(0,f.jsx)(uk,{size:72,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,f.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,f.jsx)(`button`,{onClick:async()=>{if(v.current)try{u?(await v.current.setMicMuted?.(!1),p(!1)):(await v.current.setMicMuted?.(!0),p(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:u?`#7f1d1d`:`#1f2937`,border:u?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:u?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:u?(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,f.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,f.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,f.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,f.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,f.jsx)(tD,{size:16,color:`currentColor`})}),(0,f.jsx)(`button`,{onClick:()=>h(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,f.jsx)(lD,{size:16,color:`currentColor`})})]}),m&&(0,f.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ne.current=`chat`,ae(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(uD,{}),`Enter Chat Mode`]}),(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ne.current=`minimized`,ae(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(dD,{}),`End Conversation`]}),(0,f.jsx)(`button`,{onClick:()=>h(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,f.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function mk({orbColors:e}){return(0,f.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(uk,{size:36,orbColors:e})})}var hk=()=>(0,f.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,f.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,f.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function gk({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:p,agentName:m,agentHeadshot:h,fallbackAgentName:g,input:_,setInput:v,onSubmit:y,isConversationEnded:b,isLoading:x,isRateLimited:S,rateLimitMessage:ee,selectedFile:te,onFileSelect:ne,onRemoveSelectedFile:re,attachmentError:ie,isUploadingAttachment:ae,requiresEmail:oe,emailInput:se,setEmailInput:ce,emailError:le,replyContext:ue,setReplyContext:de,webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,activeCallId:ge,isCallMuted:_e,toggleCallMute:ve,endWebRTCCall:ye,formatCallDuration:be,callDurationSeconds:xe,isCallMinimized:Se,onExpand:Ce,onCollapse:we,onStartVoice:Te,onNewChat:Ee,onEndConversation:De,showPoweredBy:Oe,getVisitorChatHistory:ke,getVisitorChatThread:Ae,resumeChat:je,isSessionRestoring:Me,isClosing:Ne}){let Pe=c.length>0,Fe=x||S||b,Ie=!!ge,[Le,Re]=(0,d.useState)(!1),[ze,Be]=(0,d.useState)(!1),[Ve,He]=(0,d.useState)([]),[Ue,C]=(0,d.useState)(!1),[We,Ge]=(0,d.useState)(null),[Ke,qe]=(0,d.useState)([]),w=(0,d.useRef)(null),Je=async()=>{Re(!1),Be(!0),C(!0),Ge(null);try{let e=await ke();e?.data&&He(e.data)}catch(e){console.error(e)}finally{C(!1)}},Ye=async e=>{Be(!1),je?.(e.chatId)};return(0,d.useEffect)(()=>{if(!Le)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;w.current&&!w.current.contains(t)&&Re(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Le]),(0,f.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`8px`,right:`8px`,bottom:0,width:`calc(100% - 16px)`,height:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Ne?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Ne?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,f.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:`transparent`,flexShrink:0},children:[(0,f.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,f.jsx)(`button`,{onClick:we,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(0,f.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:`minmax(72px, 40%) minmax(0, 60%)`,alignItems:`center`},children:[(0,f.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,f.jsx)(sk,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,f.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,f.jsx)(ck,{title:e.chatTitle})})}),(0,f.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,f.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]}),(0,f.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:w,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>Re(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,f.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Le&&(0,f.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),Te?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,f.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),Ee?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,f.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new conversation`]}),ke&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:Je,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),we?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,f.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,f.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,f.jsx)(OD,{webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,isRateLimited:S,rateLimitMessage:ee}),Se&&(0,f.jsx)(GD,{agentName:m,agentHeadshot:h,fallbackAgentName:g,callDurationSeconds:xe,isCallMuted:_e,formatCallDuration:be,toggleCallMute:ve,endWebRTCCall:ye,onExpand:Ce,primaryColor:n}),(0,f.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[ze?(0,f.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,f.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:We?(0,f.jsxs)(`button`,{onClick:()=>Ge(null),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,f.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Back to List`})]}):(0,f.jsxs)(`button`,{onClick:()=>Be(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,f.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,f.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:Ue&&!We?(0,f.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):We?(0,f.jsxs)(`div`,{style:{padding:`20px 16px`},children:[Ke.length===0?(0,f.jsx)(`div`,{style:{color:`#9ca3af`,textAlign:`center`,marginTop:`20px`,fontSize:`14px`},children:`No messages`}):null,Ke.map((e,t)=>(0,f.jsx)(`div`,{style:{marginBottom:`16px`,display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,f.jsx)(`div`,{style:{maxWidth:`85%`,background:e.sender===`user`?n:`#f3f4f6`,color:e.sender===`user`?`white`:`#111827`,padding:`10px 14px`,borderRadius:`14px`,fontSize:`15px`,lineHeight:1.4,wordBreak:`break-word`},children:e.content})},e._id||t))]}):Ve.length>0?(0,f.jsx)(`div`,{children:Ve.map(e=>(0,f.jsxs)(`div`,{onClick:()=>Ye(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,f.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,f.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,f.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,Pe?(0,f.jsx)(ED,{chatHistory:c,isAiTyping:l,isLoading:x,isAgentTyping:u,setReplyContext:de,TypingDots:hk,primaryColor:n,agentHeadshot:h,agentDisplayName:m||g,botAvatarNode:(0,f.jsx)(mk,{orbColors:t})}):Me?(0,f.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,f.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,f.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,f.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,f.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,f.jsx)(uk,{size:94,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,f.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,f.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),(0,f.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:oe?`6px 0 0`:`12px 0 0`},children:(0,f.jsx)(DD,{input:_,setInput:v,onSubmit:y,isConversationEnded:b,callUiActive:Ie,handleToggleVoice:Te,showVoiceToggle:p===`agent`,activeScreen:p,inputDisabled:Fe,replyContext:ue,clearReplyContext:()=>de(null),onFileSelect:ne,selectedFile:te,onRemoveSelectedFile:re,attachmentError:ie,isUploadingAttachment:ae,requiresEmail:oe,emailInput:se,setEmailInput:ce,emailError:le,inputPlaceholder:e.inputPlaceholder})}),(0,f.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:Oe&&(0,f.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,f.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function _k(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:p,isLoading:m,isRateLimited:h,rateLimitMessage:g,isConversationEnded:_,incomingCall:v,activeCallId:y,callConnectionState:b,callConnectedAt:x,isCallMuted:S,webRTCError:ee,language:te,historyRef:ne,onMessageSync:re,sendMessage:oe,uploadChatFile:se,openWidget:ce,captureVisitorEmail:le,setVoiceMode:ue,endConversation:de,startNewChat:fe,acceptCall:pe,rejectCall:me,endWebRTCCall:he,toggleCallMute:ge,dismissCallError:_e,startTyping:ve,stopTyping:ye,updateTypingDraft:be,getVisitorChatHistory:xe,getVisitorChatThread:Se,resumeChat:Te,isSessionRestoring:Ee}=wn();(0,d.useEffect)(()=>{try{Zn()}catch{}},[]);let Oe=t?.widgetSettings||{},ke=n?.widgetSettings||{},Ae={...Oe.branding||{},...ke.branding||{}},je={...Oe.theme||{},...ke.theme||{}},Me={...Oe.features||{},...ke.features||{}},Ne=Me.voice!==!1,Pe=Array.isArray(je.orbColors)&&je.orbColors.length>0?je.orbColors:null,Fe=je.buttonColor||je.primaryColor||Pe?.[0]||`#3B82F6`,Ie=je.position||`bottom-right`,Le=Ae.fallbackAgentName||`Agent`,Re=ak(Pe??je.chatBgColors),ze=Ae.logo||Ae.logoUrl||null,Be=te||`en`,Ve=Oe.recommendations?.[Be]||[],He=(ke.recommendations?.[Be]??Ve).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Ue=Array.isArray(Ae.quickChatOptions)&&Ae.quickChatOptions.length>0?Ae.quickChatOptions:He,C=Ae.hideWatermark===!0?!1:Ae.showPoweredBy!==!1,We=Ae.chatbotEnabled!==!1&&je.chatbotEnabled!==!1,Ge=Oe.greetings?.[te]||ke.greetings?.[te]||Ae.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Ke={entryPrompt:Ae.entryPrompt||`Do you want to explore in a new way?`,yesLabel:Ae.yesLabel||`Yes`,laterLabel:Ae.laterLabel||`Later`,connectionTitle:Ae.connectionTitle||`How would you like to connect?`,voiceLabel:Ae.voiceLabel||`Voice`,textLabel:Ae.textLabel||`Text`,chatTitle:Ae.headerName||`Chat with FlowEngage`,introGreeting:Ge,inputPlaceholder:Ae.inputPlaceholder||`Type your message`,analysingLabel:Ae.analysingLabel||`analysing...`},qe=ke.elevenLabsAgentId||t?.elevenLabsAgentId||null,w=t?.siteId||n?.siteId||null,Je=t?.apiBaseUrl||``,Ye=(0,d.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Xe=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Ze=r.some(e=>e.sender===`user`),Qe=(0,d.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),$e=!l&&Ze&&Qe,et=!!(ke._dashboardLivePreview||Oe._dashboardLivePreview),[tt,T]=(0,d.useState)(()=>et?`text_chat`:`entry_prompt`),[E,D]=(0,d.useState)(``),[nt,rt]=(0,d.useState)(null),[O,it]=(0,d.useState)(l||``),[at,ot]=(0,d.useState)(``),[st,ct]=(0,d.useState)(0),[lt,ut]=(0,d.useState)(null),[dt,ft]=(0,d.useState)(null),[pt,mt]=(0,d.useState)(``),[ht,gt]=(0,d.useState)(!1),[_t,vt]=(0,d.useState)(!1),[yt,bt]=(0,d.useState)(!1),xt=(0,d.useRef)(null),St=(0,d.useRef)(!1);(0,d.useLayoutEffect)(()=>{if(e!==`ready`||St.current)return;if(St.current=!0,!Ne){T(`minimized_orb`);return}let t=!1;try{t=cr().shouldResumeVoice}catch{}let n=De(),r=w?Ce(w):null,i=n||!!r?.transcript;if(t){ce?.({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`);return}if(w)try{we(w)}catch{}if(i){ce?.({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`);return}if(ie(w)){T(`minimized_orb`);return}},[e,r]);let[Ct,wt]=(0,d.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,d.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>wt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,d.useEffect)(()=>{it(l||``),l&&ot(``)},[l]);let Tt=(0,d.useCallback)(()=>{ft(null),mt(``)},[]),Et=(0,d.useCallback)(e=>{let t=xD(e);if(t){ft(null),mt(t);return}ft(e),mt(``)},[]);(0,d.useEffect)(()=>{if(!x||b!==`connected`){ct(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||ct(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]);let Dt=(0,d.useCallback)(()=>{T(`call_screen`),vt(!1)},[]),Ot=(0,d.useCallback)(()=>{T(`text_chat`),vt(!0)},[]);(0,d.useEffect)(()=>{let e=v?.callId||y||null;if(!e){xt.current=null;return}if(v?.callId||b===`connecting`||b===`connected`){if(tt===`minimized_orb`&&_t&&y&&!v?.callId){xt.current=e;return}!(!i||tt===`minimized_orb`||tt===`voice_mode`)&&xt.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:tt,hasIncomingCall:!!v?.callId,activeCallId:y,callConnectionState:b}),xt.current=e,tt===`voice_mode`&&ue?.(!1),ce?.(),Dt())}},[y,b,Dt,v?.callId,i,ce,ue,tt]),(0,d.useEffect)(()=>{!v&&!y&&tt===`call_screen`&&T(`text_chat`)},[v,y,tt]),(0,d.useEffect)(()=>{!y&&_t&&vt(!1)},[y,_t]),(0,d.useEffect)(()=>{if(!o||_){be?.(``),ye?.();return}if(!E.trim()||dt){be?.(``);let e=window.setTimeout(()=>ye?.(),100);return()=>window.clearTimeout(e)}ve?.();let e=window.setTimeout(()=>be?.(E),120),t=window.setTimeout(()=>ye?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[E,dt,o,_,ve,ye,be]);let kt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,At=async e=>{if(e.preventDefault(),_)return;if($e){let e=O.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){ot(`Please enter a valid email so we can continue helping you.`);return}await le(e),ot(``);return}let t=kt(nt);if(!E.trim()&&!dt)return;if(dt){try{gt(!0),mt(``);let e=await se(dt),n=e?.data||e,r=E.trim()||`Shared file: ${CD(dt)}`;D(``),rt(null),Tt(),await oe(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||dt.name,fileType:n?.fileType||dt.type,fileSize:n?.fileSize||dt.size}})}catch(e){mt(e?.message||`Failed to upload the selected file.`)}finally{gt(!1)}return}let n=E.trim();D(``),rt(null),await oe(n,``,t)},jt=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},Mt=(0,d.useCallback)(async e=>{if(_||m)return;let t=e.message||e.label||e.text||``;t.trim()&&await oe(t.trim(),``)},[_,m,oe]),Nt=Ct&&tt===`entry_prompt`?{inset:0}:Ct&&tt===`text_chat`?{left:0,right:0,bottom:0}:Ct&&tt===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:Ct&&tt===`connection_modal`?{left:`28px`,right:`12px`,bottom:`12px`}:tt===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ie===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`}}:Ie===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Pt=(0,d.useCallback)(()=>{tt!==`minimized_orb`&&(bt(!0),setTimeout(()=>{T(`minimized_orb`),bt(!1)},280))},[tt]),Ft=()=>T(`connection_modal`),It=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}ce({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`)},Lt=()=>{ce({notifyChatInitiated:!0}),ue?.(!1),T(`text_chat`)},Rt=()=>{ue?.(!1),Pt()};return e!==`ready`||!We||Me.chat===!1?null:(0,f.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...Nt},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[tt===`entry_prompt`&&(0,f.jsx)(dk,{copy:Ke,orbColors:Pe,primaryColor:Fe,onYes:()=>{ae(w),It()},onLater:()=>{ae(w),Pt()},isMobile:Ct,isClosing:yt}),tt===`minimized_orb`&&(0,f.jsxs)(dm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ie===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[y&&_t&&(0,f.jsxs)(`button`,{type:`button`,onClick:Dt,style:{maxWidth:Ct?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,f.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,f.jsxs)(`span`,{style:{minWidth:0},children:[(0,f.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:b===`connected`?`Call in progress`:`Call is active`}),(0,f.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:b===`connected`?`${jt(st)} with ${Ye}`:`Tap to return to ${Ye}`})]})]}),(0,f.jsx)(uk,{size:50,orbColors:Pe,onClick:y&&_t?Dt:Ne?Ft:Lt})]}),tt===`connection_modal`&&(0,f.jsx)(fk,{copy:Ke,orbColors:Pe,primaryColor:Fe,onVoice:It,onText:Lt,onClose:Pt,isMobile:Ct,isClosing:yt}),tt===`voice_mode`&&(0,f.jsx)(pk,{orbColors:Pe,onEnterChat:Lt,onEndChat:Rt,agentId:qe,siteId:w,apiBaseUrl:Je,historyRef:ne,onMessageSync:re},`voice`),tt===`call_screen`&&(0,f.jsx)(WD,{incomingCall:v,activeCallId:y,callConnectionState:b,callDurationSeconds:st,isCallMuted:S,agentName:Ye,agentHeadshot:Xe,fallbackAgentName:Le,acceptCall:pe,rejectCall:me,endWebRTCCall:he,toggleCallMute:ge,formatCallDuration:jt,onMinimize:Ot,primaryColor:Fe,orbColors:Pe,chatHistory:r}),tt===`text_chat`&&(0,f.jsx)(gk,{isClosing:yt,copy:Ke,orbColors:Pe,primaryColor:Fe,chatBgGradient:Re,logo:ze,quickChatOptions:Ue,onQuickChatSelect:Mt,isMobile:Ct,chatHistory:r,isAiTyping:p,isAgentTyping:u,activeScreen:a,agentName:Ye,agentHeadshot:Xe,fallbackAgentName:Le,input:E,setInput:D,onSubmit:At,isConversationEnded:_,isLoading:m,isRateLimited:h,rateLimitMessage:g,selectedFile:dt,onFileSelect:Et,onRemoveSelectedFile:Tt,attachmentError:pt,isUploadingAttachment:ht,requiresEmail:$e,emailInput:O,setEmailInput:it,emailError:at,replyContext:nt,setReplyContext:rt,webRTCError:ee,micError:lt,setMicError:ut,dismissCallError:_e,activeCallId:y,isCallMuted:S,toggleCallMute:ge,endWebRTCCall:he,formatCallDuration:jt,callDurationSeconds:st,onCollapse:Pt,onStartVoice:It,onNewChat:fe,onEndConversation:de,onMinimize:Ot,onExpand:Dt,isCallMinimized:_t&&!!y,showPoweredBy:C,getVisitorChatHistory:xe,getVisitorChatThread:Se,resumeChat:Te,isSessionRestoring:Ee}),(0,f.jsx)(`style`,{children:`
|
|
635
|
+
`)}else{let t=(document.querySelector(`main`)||document.querySelector(`article`)||document.querySelector(`[role="main"]`)||document.querySelector(`#content`)||document.querySelector(`.content`)||document.body).cloneNode(!0);t.querySelectorAll(`nav, footer, header, aside, script, style, noscript, .nav, .footer, .header, .sidebar`).forEach(e=>e.remove()),e=t.textContent.replace(/\s+/g,` `).trim()}return e.length>8e3&&(e=e.substring(0,8e3)+`... (truncated)`),$(`flowengage_read_content ✓`,`${e.length} chars`),e||`No readable content found on this page.`}catch(e){return $(`flowengage_read_content ✖`,e.message),`Could not read page content: ${e.message}`}},flowengage_search:async e=>{$(`flowengage_search ▶`,e);let r=$O(JO(e));if($(`flowengage_search · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`flowengage_search ✖ missing query`),`Missing query parameter.`;if(!t)return $(`flowengage_search ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`flowengage_search ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`flowengage_search → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`flowengage_search · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return $(`flowengage_search ✖`,e),e}let o=a.results||[];return $(`flowengage_search ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return $(`flowengage_search ✖`,t),t}},flowengage_page_content:async e=>{$(`flowengage_page_content ▶`,e);let r=JO(e),i=r?.url||r?.page_url||``;if($(`flowengage_page_content · url:`,i,`siteId:`,t,`apiBase:`,n||`(empty)`),!i)return $(`flowengage_page_content ✖ missing url`),`Missing url parameter.`;if(!t)return $(`flowengage_page_content ✖ no siteId`),`Site is not configured.`;if(!n)return $(`flowengage_page_content ✖ no api base`),`API base URL is missing; cannot fetch page content.`;try{let e=`${n}/api/site-tools/page-content`;$(`flowengage_page_content → POST`,e);let r=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,url:i})}),a=await r.json();if($(`flowengage_page_content · HTTP`,r.status,`success:`,a.success),!a.success){let e=a.error||`Failed to get page content.`;return $(`flowengage_page_content ✖`,e),e}return $(`flowengage_page_content ✓`,`title: ${a.title}`,`sections: ${(a.sections||[]).length}`,`content: ${(a.content||``).length} chars`),JSON.stringify({title:a.title,url:a.url,sections:a.sections,content:a.content})}catch(e){let t=`Page content error: ${e.message||`network`}`;return $(`flowengage_page_content ✖`,t),t}},flowengage_end_session:async()=>($(`flowengage_end_session ▶`),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),flowengage_list_forms:async()=>{let e=AO(),t=jO();return $(`flowengage_list_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: placeholder/label, name (e.g. url), id (e.g. url-input). If the page has two URL boxes, flowengage_fill_form sets all matching URL inputs. flowengage_click_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},flowengage_fill_form:async e=>{try{$(`flowengage_fill_form ▶ raw:`,e),uO();let t=YO(e);if(!t.length&&r){let e=r(),n=XO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=ZO(e),n.length&&$(`flowengage_fill_form · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`flowengage_fill_form · normalized fields:`,t),!t.length)return`No fields provided. Call flowengage_list_forms for field_key strings, then flowengage_fill_form with { "fields": [ { "field_key": "<label or placeholder from list>", "value": "<user value>" } ] }. Never use empty {}. Pass the value the user just said (email, message, name, URL) in fields.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;rO(`Filling ${String(t)}...`,{spinner:!0});let a=kO(),o=HO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())dO(t),await _O(t),ek(t,r,{skipScroll:e>0}),fO(t),await SO(120);i=o,n.push(String(t));continue}let s=GO(a,String(t));s||=IO(a,String(t)),s||=LO(a,String(t),r),s&&(dO(s),await _O(s),ek(s,r),fO(s),await SO(120),i=[s],n.push(String(t)))}if(!n.length)return $(`flowengage_fill_form ✖ no matches`),`Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.`;let a=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,a),rO(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),a}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),rO(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{vO(),uO(),iO(700)}},flowengage_click_button:async e=>{let t=JO(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`flowengage_click_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=qO(n,i);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{rO(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await _O(r),r.focus?.(),await yO(r),bO(r),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`,t=`OK_CLICK ${e}`;return $(`flowengage_click_button ✓`,t),rO(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),rO(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{vO(),iO(700)}}};return{...a,highlightOnPage:a.flowengage_highlight,searchSiteContent:a.flowengage_search,getPageContent:a.flowengage_page_content,endVoiceSession:a.flowengage_end_session,listPageForms:a.flowengage_list_forms,fillFormFields:a.flowengage_fill_form,clickPageButton:a.flowengage_click_button}}function rk(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Tn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i;try{i=await t(n)}catch(t){let n=`Tool error: ${t?.message||String(t)}`;return console.error(`[FlowEngage] voice tool ${e} threw:`,t),n}let a=typeof i==`string`?i.length>220?`${i.slice(0,220)}…`:i:String(i);return r?console.log(`[FlowEngage:voice-tool] ◀`,e,a):console.info(`[FlowEngage] voice tool « ${e}:`,a),i}]))}var ik={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function ak(e){if(!Array.isArray(e)||e.length<2)return`linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa`;let[t,n,r]=e;return e.length>=3&&r?[`radial-gradient(ellipse 80% 70% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 70% 80% at 110% 30%, ${n}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 60% at 50% 110%, ${r}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `):[`radial-gradient(ellipse 80% 100% at -10% 50%, ${t}1a 0%, transparent 70%)`,`radial-gradient(ellipse 80% 100% at 110% 50%, ${n}1a 0%, transparent 70%)`,`#f7f8fa`].join(`, `)}function ok(e){if(!e||typeof e!=`string`)return`#1a1a1a`;let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4;return .2126*o(r)+.7152*o(i)+.0722*o(a)>.179?`#1a1a1a`:`#ffffff`}function sk({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,f.jsx)(`img`,{src:e,alt:``,style:{objectFit:`contain`,flexShrink:0,display:`block`,...t}});let n=typeof e==`function`?d.default.createElement(e):d.default.isValidElement(e)?e:null;return n?(0,f.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function ck({title:e}){return(0,f.jsx)(`div`,{style:{width:`100%`,height:`100%`,borderRadius:`16px`,background:`linear-gradient(135deg, rgba(59,130,246,0.16) 0%, rgba(59,130,246,0.08) 100%)`,color:`#2563eb`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,letterSpacing:`-0.03em`},children:String(e||`FE`).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()||``).join(``)||`FE`})}function lk(e,t){let n=(t||``).trim();return n?!!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n)||/\b(hang\s+up|disconnect)\b/i.test(n)||/\b(that'?s all|we'?re done)\b/i.test(n)||e===`bot`&&(/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n)||/\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n)||/\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n)||/\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n)||/\b(wrapping\s+up|signing\s+off)\b/i.test(n))||/^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)):!1}function uk({orbColors:e,...t}){return(0,f.jsx)(LD,{colors:e,...t})}function dk({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a,isClosing:o}){let s=n||ik.green,c=ok(s),l=a?72:94,u=(0,f.jsxs)(`div`,{style:{display:`flex`,alignItems:a?`flex-end`:`center`,gap:a?`7px`:`9px`},children:[(0,f.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,f.jsx)(dm.p,{initial:{x:-16,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.36},style:{margin:`0 0 14px`,fontSize:`14px`,fontWeight:700,color:`white`,lineHeight:1.4,textShadow:`0 1px 4px rgba(0,0,0,0.35)`,maxWidth:a?void 0:`210px`},children:e.entryPrompt}),(0,f.jsxs)(dm.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`16px`,flexWrap:`nowrap`},children:[(0,f.jsx)(`button`,{onClick:r,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:s,color:c,fontWeight:400,fontSize:`14px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${s}66`,transition:`transform 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.04)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.yesLabel}),(0,f.jsx)(`button`,{onClick:i,style:{height:`31px`,boxSizing:`border-box`,padding:`0 16px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:400,fontSize:`14px`,border:`2px solid rgba(255,255,255,0.55)`,cursor:`pointer`,whiteSpace:`nowrap`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.9)`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`rgba(255,255,255,0.55)`},children:e.laterLabel})]})]}),(0,f.jsx)(dm.div,{initial:{x:120,opacity:0},animate:{x:0,opacity:1},transition:{type:`spring`,stiffness:220,damping:22,delay:0},style:{flexShrink:0},children:(0,f.jsx)(uk,{size:l,orbColors:t})})]});return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(dm.div,{initial:{opacity:0},animate:{opacity:o?0:1},transition:{duration:.28},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,f.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`,animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u}):(0,f.jsx)(`div`,{style:{animation:o?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:``},children:u})]})}function fk({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a,isMobile:o,isClosing:s}){let c=n||ik.green,l=ok(c);return(0,f.jsxs)(dm.div,{initial:{scale:50/350,borderRadius:`50%`},animate:s?{scale:50/350,opacity:0,borderRadius:`50%`}:{scale:1,borderRadius:`16px`,opacity:1},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:o?`bottom center`:`bottom right`,background:`white`,width:o?`100%`:`350px`,height:`245px`,padding:`24px 40px 32px`,boxSizing:`border-box`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`space-between`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,f.jsx)(`button`,{onClick:a,style:{position:`absolute`,top:`14px`,right:`14px`,background:`none`,border:`none`,cursor:`pointer`,color:`#9ca3af`,padding:`4px`,display:`flex`,alignItems:`center`,justifyContent:`center`,borderRadius:`50%`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#374151`},onMouseLeave:e=>{e.currentTarget.style.color=`#9ca3af`},children:(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,f.jsx)(uk,{size:72,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,fontSize:`16px`,fontWeight:400,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`16px`,width:`100%`},children:[(0,f.jsx)(`button`,{onClick:r,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:c,color:l,fontWeight:400,fontSize:`16px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${c}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,f.jsx)(`button`,{onClick:i,style:{width:`127px`,height:`43px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:400,fontSize:`16px`,border:`1.5px solid #d1d5db`,cursor:`pointer`,transition:`border-color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.borderColor=`#6b7280`},onMouseLeave:e=>{e.currentTarget.style.borderColor=`#d1d5db`},children:e.textLabel})]})]})}function pk(e){try{let t=(new URL(e).pathname.split(`/`).filter(Boolean).pop()||``).replace(/\.(html?|php|aspx?)$/i,``).replace(/[-_+]/g,` `).trim();return t?t.charAt(0).toUpperCase()+t.slice(1):`Home`}catch{return`this page`}}function mk({orbColors:e,onEnterChat:t,onEndChat:n,agentId:r,siteId:i,apiBaseUrl:a,historyRef:o,onMessageSync:s}){let[c,l]=(0,d.useState)(`idle`),[u,p]=(0,d.useState)(!1),[m,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(0),v=(0,d.useRef)(null),y=(0,d.useRef)(``),b=(0,d.useRef)(async()=>{}),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),ee=(0,d.useRef)(!1),te=(0,d.useRef)(!1),ne=(0,d.useRef)(`minimized`),re=(0,d.useRef)(null),ie=(0,d.useCallback)((e=`minimized`)=>{ne.current=e,te.current=!0,queueMicrotask(()=>{x.current||(x.current=!0,b.current?.())})},[o]),ae=(0,d.useCallback)(async e=>{te.current=!0;try{await v.current?.endSession?.()}catch{}if(v.current=null,l(`idle`),p(!1),x.current=!1,pr(),i)try{we(i)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return b.current=()=>ae(ne.current===`chat`?t:n),(0,d.useEffect)(()=>{S.current=u},[u]),(0,d.useEffect)(()=>{let e=!1,n=null;return(async()=>{if(!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],y.current=``,x.current=!1,ee.current=!1,te.current=!1,ne.current=`minimized`,fr({onBeforeNavigate:()=>{if(i&&o.current.length>0)try{let e=KD(o.current);e&&Se(i,e)}catch{}if(i&&typeof window<`u`)try{Ae(i,window.location.href)}catch{}Ee()}});let t=rk(nk({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>y.current,requestEndSession:()=>{ie()}})),s=i?Ce(i):null,c=!!s?.transcript,u=c&&i?je(i):null,d=typeof window<`u`?window.location.href:``,f={agentId:r,clientTools:t,overrides:{agent:{firstMessage:c?`I can see we're now on the ${pk(d)} page — feel free to ask me anything about it.`:`Hello! How can I help you today?`}}},m=null;typeof WebSocket<`u`&&(m=WebSocket.prototype.send,WebSocket.prototype.send=function(e){if(typeof e==`string`)try{let t=JSON.parse(e);if(t.type===`conversation_initiation_client_data`&&t.conversation_config_override){let n=t.conversation_config_override;n.tts&&Object.keys(n.tts).length===0&&delete n.tts,n.conversation&&Object.keys(n.conversation).length===0&&delete n.conversation,e=JSON.stringify(t)}}catch{}return m.call(this,e)});let h;try{h=await eD.startSession({...f,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||l(t===`speaking`?`speaking`:`listening`)},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;if(r){if(n===`user`&&(y.current=r),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],i)try{let e=KD(o.current);e&&Se(i,e)}catch{}lk(n,r)&&ie(`minimized`)}},onError:t=>{if(!e&&!te.current&&!ee.current&&!Oe()){ee.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t});try{v.current?.setMicMuted?.(!0)}catch{}p(!0),l(`error`),ie(`chat`)}},onDisconnect:()=>{if(e||te.current||ee.current||Oe())return;let t=o.current?.length||0;if(console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:t,lastUserText:y.current||``,wasMuted:S.current}),t===0&&g===0){ee.current=!0,console.warn(`[FlowEngageVoiceCall] immediate disconnect, retrying once`),_(1);return}ee.current=!0;try{v.current?.setMicMuted?.(!0)}catch{}p(!0),ie(`chat`)}})}finally{m&&(WebSocket.prototype.send=m)}if(e){h.endSession().catch(()=>{});return}n=h,v.current=h,l(`listening`);try{let e=`[]`;try{e=await t.list_page_forms()}catch{}let n=c&&s?.transcript?`Navigation context: agent navigated from ${u?.previousPage||`previous page`} to ${d}.\nPrior conversation:\n${s.transcript}\n\n`:``;h.sendContextualUpdate(n+`Current page: ${d}. SiteId: ${i||`unknown`}. Forms: ${e}. Voice: call end_voice_session or say you are ending the session to stop.`)}catch{}}catch(n){e||(console.error(`[FlowEngage] startSession failed`,n),l(`error`),ne.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}})(),()=>{e=!0,te.current=!0,pr(),(n||v.current)?.endSession?.().catch(()=>{})}},[r,i,a,ie,g]),(0,d.useEffect)(()=>{if(!m)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;re.current&&!re.current.contains(t)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[m]),(0,f.jsxs)(`div`,{ref:re,style:{position:`relative`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`14px`,animation:`fe-orb-slide-up 0.42s cubic-bezier(0.16,1,0.3,1)`},children:[(0,f.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,f.jsx)(`span`,{style:{position:`absolute`,right:`100%`,marginRight:`18px`,top:`50%`,transform:`translateY(-50%)`,color:`white`,fontSize:`18px`,fontWeight:600,letterSpacing:`0.01em`,textShadow:`0 2px 4px rgba(0,0,0,0.4)`,whiteSpace:`nowrap`},children:`Listening...`}),(0,f.jsx)(uk,{size:72,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,f.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,f.jsx)(`button`,{onClick:async()=>{if(v.current)try{u?(await v.current.setMicMuted?.(!1),p(!1)):(await v.current.setMicMuted?.(!0),p(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:u?`#7f1d1d`:`#1f2937`,border:u?`1.5px solid #ef4444`:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:u?`#f87171`:`white`,transition:`all 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:u?(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,f.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,f.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,f.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,f.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,f.jsx)(tD,{size:16,color:`currentColor`})}),(0,f.jsx)(`button`,{onClick:()=>h(e=>!e),style:{width:`24px`,height:`24px`,borderRadius:`50%`,background:`#1f2937`,border:`1.5px solid #4b5563`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`,transition:`background 0.2s ease`,boxShadow:`0 2px 8px rgba(0,0,0,0.4)`,padding:0,flexShrink:0},children:(0,f.jsx)(lD,{size:16,color:`currentColor`})})]}),m&&(0,f.jsxs)(`div`,{style:{position:`absolute`,bottom:0,right:0,width:`230px`,zIndex:9999,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,animation:`fe-orb-fade-in 0.18s ease`,padding:`12px 12px 40px`},children:[(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ne.current=`chat`,ae(t)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(uD,{}),`Enter Chat Mode`]}),(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ne.current=`minimized`,ae(n)},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`12px 16px`,background:`none`,border:`none`,color:`#E30C12`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`,borderRadius:`8px`,whiteSpace:`nowrap`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(227,12,18,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(dD,{}),`End Conversation`]}),(0,f.jsx)(`button`,{onClick:()=>h(!1),style:{position:`absolute`,bottom:`8px`,right:`8px`,width:`24px`,height:`24px`,borderRadius:`50%`,background:`rgba(255,255,255,0.15)`,border:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`pointer`,color:`white`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.25)`},onMouseLeave:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.15)`},children:(0,f.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})]})}function hk({orbColors:e}){return(0,f.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(uk,{size:36,orbColors:e})})}var gk=()=>(0,f.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,f.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[0,1,2].map(e=>(0,f.jsx)(`span`,{style:{width:`7px`,height:`7px`,borderRadius:`50%`,background:`#9ca3af`,animation:`fe-dot-bounce 1.2s ease-in-out ${e*.2}s infinite`,display:`inline-block`}},e))})});function _k({copy:e,orbColors:t,primaryColor:n,chatBgGradient:r,logo:i,quickChatOptions:a,onQuickChatSelect:o,isMobile:s,chatHistory:c,isAiTyping:l,isAgentTyping:u,activeScreen:p,agentName:m,agentHeadshot:h,fallbackAgentName:g,input:_,setInput:v,onSubmit:y,isConversationEnded:b,isLoading:x,isRateLimited:S,rateLimitMessage:ee,selectedFile:te,onFileSelect:ne,onRemoveSelectedFile:re,attachmentError:ie,isUploadingAttachment:ae,requiresEmail:oe,emailInput:se,setEmailInput:ce,emailError:le,replyContext:ue,setReplyContext:de,webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,activeCallId:ge,isCallMuted:_e,toggleCallMute:ve,endWebRTCCall:ye,formatCallDuration:be,callDurationSeconds:xe,isCallMinimized:Se,onExpand:Ce,onCollapse:we,onStartVoice:Te,onNewChat:Ee,onEndConversation:De,showPoweredBy:Oe,getVisitorChatHistory:ke,getVisitorChatThread:Ae,resumeChat:je,isSessionRestoring:Me,isClosing:Ne}){let Pe=c.length>0,Fe=x||S||b,Ie=!!ge,[Le,Re]=(0,d.useState)(!1),[ze,Be]=(0,d.useState)(!1),[Ve,He]=(0,d.useState)([]),[Ue,C]=(0,d.useState)(!1),[We,Ge]=(0,d.useState)(null),[Ke,qe]=(0,d.useState)([]),w=(0,d.useRef)(null),Je=async()=>{Re(!1),Be(!0),C(!0),Ge(null);try{let e=await ke();e?.data&&He(e.data)}catch(e){console.error(e)}finally{C(!1)}},Ye=async e=>{Be(!1),je?.(e.chatId)};return(0,d.useEffect)(()=>{if(!Le)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;w.current&&!w.current.contains(t)&&Re(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Le]),(0,f.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,left:`8px`,right:`8px`,bottom:0,width:`calc(100% - 16px)`,height:`90dvh`,background:r,borderRadius:`16px 16px 0 0`,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:Ne?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,background:r,borderRadius:`22px`,boxShadow:`0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08)`,display:`flex`,flexDirection:`column`,overflow:`hidden`,position:`relative`,animation:Ne?`fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards`:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,f.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 10px 14px`,background:`transparent`,flexShrink:0},children:[(0,f.jsx)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:(0,f.jsx)(`button`,{onClick:we,style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},children:(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})}),(0,f.jsxs)(`div`,{style:{minWidth:0,maxWidth:s?`100%`:`250px`,width:`100%`,justifySelf:`center`,display:`grid`,gridTemplateColumns:`minmax(72px, 40%) minmax(0, 60%)`,alignItems:`center`},children:[(0,f.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,f.jsx)(sk,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,f.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,f.jsx)(ck,{title:e.chatTitle})})}),(0,f.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,f.jsx)(`span`,{style:{fontSize:`15px`,fontWeight:600,color:`#111827`,letterSpacing:`-0.01em`,lineHeight:1.2,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.chatTitle,children:e.chatTitle})})]}),(0,f.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:w,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>Re(e=>!e),style:{width:`40px`,height:`40px`,background:`none`,border:`none`,cursor:`pointer`,color:`#6b7280`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`4px`,borderRadius:`10px`,transition:`color 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.color=`#111827`},onMouseLeave:e=>{e.currentTarget.style.color=`#6b7280`},"aria-label":`Chat options`,children:(0,f.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Le&&(0,f.jsxs)(`div`,{style:{position:`absolute`,top:`34px`,right:0,background:`rgba(15,22,36,0.96)`,backdropFilter:`blur(14px)`,WebkitBackdropFilter:`blur(14px)`,borderRadius:`16px`,overflow:`hidden`,boxShadow:`0 10px 40px rgba(0,0,0,0.45)`,minWidth:`210px`,border:`1px solid rgba(255,255,255,0.07)`,animation:`fe-orb-fade-in 0.18s ease`},children:[(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),Te?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,f.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),Ee?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`path`,{d:`M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7`}),(0,f.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z`})]}),`Start new conversation`]}),ke&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:Je,style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`white`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(255,255,255,0.08)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`path`,{d:`M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z`})}),`Chat history`]})]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{type:`button`,onClick:()=>{Re(!1),we?.()},style:{display:`flex`,alignItems:`center`,gap:`12px`,width:`100%`,padding:`14px 18px`,background:`none`,border:`none`,color:`#f87171`,fontSize:`14px`,fontWeight:500,cursor:`pointer`,textAlign:`left`,transition:`background 0.15s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(248,113,113,0.1)`},onMouseLeave:e=>{e.currentTarget.style.background=`none`},children:[(0,f.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,f.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,f.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`Close conversation`]})]})]})]}),(0,f.jsx)(OD,{webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,isRateLimited:S,rateLimitMessage:ee}),Se&&(0,f.jsx)(GD,{agentName:m,agentHeadshot:h,fallbackAgentName:g,callDurationSeconds:xe,isCallMuted:_e,formatCallDuration:be,toggleCallMute:ve,endWebRTCCall:ye,onExpand:Ce,primaryColor:n}),(0,f.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`,position:`relative`},children:[ze?(0,f.jsxs)(`div`,{style:{position:`absolute`,inset:0,background:`white`,zIndex:20,display:`flex`,flexDirection:`column`,animation:`fe-orb-fade-in 0.2s ease`},children:[(0,f.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,padding:`16px`,borderBottom:`1px solid #f3f4f6`,flexShrink:0},children:We?(0,f.jsxs)(`button`,{onClick:()=>Ge(null),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,f.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Back to List`})]}):(0,f.jsxs)(`button`,{onClick:()=>Be(!1),style:{background:`none`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,color:`#6b7280`},children:[(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,f.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),(0,f.jsx)(`span`,{style:{marginLeft:`8px`,fontWeight:500,fontSize:`15px`},children:`Return to Chat`})]})}),(0,f.jsx)(`div`,{style:{flex:1,overflowY:`auto`,position:`relative`},children:Ue&&!We?(0,f.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#6b7280`,fontSize:`14px`},children:`Loading past conversations...`}):We?(0,f.jsxs)(`div`,{style:{padding:`20px 16px`},children:[Ke.length===0?(0,f.jsx)(`div`,{style:{color:`#9ca3af`,textAlign:`center`,marginTop:`20px`,fontSize:`14px`},children:`No messages`}):null,Ke.map((e,t)=>(0,f.jsx)(`div`,{style:{marginBottom:`16px`,display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,f.jsx)(`div`,{style:{maxWidth:`85%`,background:e.sender===`user`?n:`#f3f4f6`,color:e.sender===`user`?`white`:`#111827`,padding:`10px 14px`,borderRadius:`14px`,fontSize:`15px`,lineHeight:1.4,wordBreak:`break-word`},children:e.content})},e._id||t))]}):Ve.length>0?(0,f.jsx)(`div`,{children:Ve.map(e=>(0,f.jsxs)(`div`,{onClick:()=>Ye(e),style:{padding:`16px 20px`,borderBottom:`1px solid #f3f4f6`,cursor:`pointer`,transition:`background 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.background=`#f9fafb`,onMouseLeave:e=>e.currentTarget.style.background=`white`,children:[(0,f.jsxs)(`div`,{style:{fontSize:`12px`,color:`#6b7280`,marginBottom:`6px`,fontWeight:500},children:[new Date(e.createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),` at `,new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})]}),(0,f.jsx)(`div`,{style:{fontSize:`14.5px`,color:`#111827`,opacity:.9,overflow:`hidden`,textOverflow:`ellipsis`,display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,lineHeight:1.4},children:e.message||`Conversation`})]},e.chatId))}):(0,f.jsx)(`div`,{style:{padding:`40px 20px`,textAlign:`center`,color:`#9ca3af`,fontSize:`14px`},children:`No previous chats found.`})})]}):null,Pe?(0,f.jsx)(ED,{chatHistory:c,isAiTyping:l,isLoading:x,isAgentTyping:u,setReplyContext:de,TypingDots:gk,primaryColor:n,agentHeadshot:h,agentDisplayName:m||g,botAvatarNode:(0,f.jsx)(hk,{orbColors:t})}):Me?(0,f.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`16px`},children:[(0,f.jsx)(`div`,{style:{width:`28px`,height:`28px`,border:`3px solid #f3f4f6`,borderTop:`3px solid ${n}`,borderRadius:`50%`,animation:`spin 1s linear infinite`},children:(0,f.jsx)(`style`,{children:`@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`})}),(0,f.jsx)(`div`,{style:{color:`#6b7280`,fontSize:`14px`,fontWeight:500,animation:`fe-orb-fade-in 1s infinite alternate`},children:`Loading chat...`})]}):(0,f.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,f.jsx)(uk,{size:94,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,f.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,f.jsx)(`button`,{onClick:()=>o?.(e),style:{padding:`8px 16px`,borderRadius:`999px`,background:`white`,border:`1.5px solid ${n}33`,color:n||`#374151`,fontSize:`13px`,fontWeight:500,cursor:`pointer`,transition:`all 0.15s ease`,boxShadow:`0 1px 4px rgba(0,0,0,0.06)`},onMouseEnter:e=>{e.currentTarget.style.background=`${n}12`,e.currentTarget.style.borderColor=n},onMouseLeave:e=>{e.currentTarget.style.background=`white`,e.currentTarget.style.borderColor=`${n}33`},children:e.label||e.text},e.id))})]})]}),(0,f.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:oe?`6px 0 0`:`12px 0 0`},children:(0,f.jsx)(DD,{input:_,setInput:v,onSubmit:y,isConversationEnded:b,callUiActive:Ie,handleToggleVoice:Te,showVoiceToggle:p===`agent`,activeScreen:p,inputDisabled:Fe,replyContext:ue,clearReplyContext:()=>de(null),onFileSelect:ne,selectedFile:te,onRemoveSelectedFile:re,attachmentError:ie,isUploadingAttachment:ae,requiresEmail:oe,emailInput:se,setEmailInput:ce,emailError:le,inputPlaceholder:e.inputPlaceholder})}),(0,f.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:Oe&&(0,f.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,f.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function vk(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatHistory:r,isOpen:i,activeScreen:a,isHumanHandled:o,agentName:s,agentHeadshot:c,visitorEmail:l,isAgentTyping:u,isAiTyping:p,isLoading:m,isRateLimited:h,rateLimitMessage:g,isConversationEnded:_,incomingCall:v,activeCallId:y,callConnectionState:b,callConnectedAt:x,isCallMuted:S,webRTCError:ee,language:te,historyRef:ne,onMessageSync:re,sendMessage:oe,uploadChatFile:se,openWidget:ce,captureVisitorEmail:le,setVoiceMode:ue,endConversation:de,startNewChat:fe,acceptCall:pe,rejectCall:me,endWebRTCCall:he,toggleCallMute:ge,dismissCallError:_e,startTyping:ve,stopTyping:ye,updateTypingDraft:be,getVisitorChatHistory:xe,getVisitorChatThread:Se,resumeChat:Te,isSessionRestoring:Ee}=wn();(0,d.useEffect)(()=>{try{Zn()}catch{}},[]);let Oe=t?.widgetSettings||{},ke=n?.widgetSettings||{},Ae={...Oe.branding||{},...ke.branding||{}},je={...Oe.theme||{},...ke.theme||{}},Me={...Oe.features||{},...ke.features||{}},Ne=Me.voice!==!1,Pe=Array.isArray(je.orbColors)&&je.orbColors.length>0?je.orbColors:null,Fe=je.buttonColor||je.primaryColor||Pe?.[0]||`#3B82F6`,Ie=je.position||`bottom-right`,Le=Ae.fallbackAgentName||`Agent`,Re=ak(Pe??je.chatBgColors),ze=Ae.logo||Ae.logoUrl||null,Be=te||`en`,Ve=Oe.recommendations?.[Be]||[],He=(ke.recommendations?.[Be]??Ve).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Ue=Array.isArray(Ae.quickChatOptions)&&Ae.quickChatOptions.length>0?Ae.quickChatOptions:He,C=Ae.hideWatermark===!0?!1:Ae.showPoweredBy!==!1,We=Ae.chatbotEnabled!==!1&&je.chatbotEnabled!==!1,Ge=Oe.greetings?.[te]||ke.greetings?.[te]||Ae.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Ke={entryPrompt:Ae.entryPrompt||`Do you want to explore in a new way?`,yesLabel:Ae.yesLabel||`Yes`,laterLabel:Ae.laterLabel||`Later`,connectionTitle:Ae.connectionTitle||`How would you like to connect?`,voiceLabel:Ae.voiceLabel||`Voice`,textLabel:Ae.textLabel||`Text`,chatTitle:Ae.headerName||`Chat with FlowEngage`,introGreeting:Ge,inputPlaceholder:Ae.inputPlaceholder||`Type your message`,analysingLabel:Ae.analysingLabel||`analysing...`},qe=ke.elevenLabsAgentId||t?.elevenLabsAgentId||null,w=t?.siteId||n?.siteId||null,Je=t?.apiBaseUrl||``,Ye=(0,d.useMemo)(()=>s&&String(s).trim()||t?.ownerName&&String(t.ownerName).trim()||t?.websiteName&&String(t.websiteName).trim()||`Agent`,[s,t?.ownerName,t?.websiteName]),Xe=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Ze=r.some(e=>e.sender===`user`),Qe=(0,d.useMemo)(()=>{let e=r.findIndex(e=>e.sender===`user`);return e===-1?!1:r.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[r]),$e=!l&&Ze&&Qe,et=!!(ke._dashboardLivePreview||Oe._dashboardLivePreview),[tt,T]=(0,d.useState)(()=>et?`text_chat`:`entry_prompt`),[E,D]=(0,d.useState)(``),[nt,rt]=(0,d.useState)(null),[O,it]=(0,d.useState)(l||``),[at,ot]=(0,d.useState)(``),[st,ct]=(0,d.useState)(0),[lt,ut]=(0,d.useState)(null),[dt,ft]=(0,d.useState)(null),[pt,mt]=(0,d.useState)(``),[ht,gt]=(0,d.useState)(!1),[_t,vt]=(0,d.useState)(!1),[yt,bt]=(0,d.useState)(!1),xt=(0,d.useRef)(null),St=(0,d.useRef)(!1);(0,d.useLayoutEffect)(()=>{if(e!==`ready`||St.current)return;if(St.current=!0,!Ne){T(`minimized_orb`);return}let t=!1;try{t=cr().shouldResumeVoice}catch{}let n=De(),r=w?Ce(w):null,i=n||!!r?.transcript;if(t){ce?.({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`);return}if(w)try{we(w)}catch{}if(i){ce?.({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`);return}if(ie(w)){T(`minimized_orb`);return}},[e,r]);let[Ct,wt]=(0,d.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,d.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>wt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,d.useEffect)(()=>{it(l||``),l&&ot(``)},[l]);let Tt=(0,d.useCallback)(()=>{ft(null),mt(``)},[]),Et=(0,d.useCallback)(e=>{let t=xD(e);if(t){ft(null),mt(t);return}ft(e),mt(``)},[]);(0,d.useEffect)(()=>{if(!x||b!==`connected`){ct(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||ct(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]);let Dt=(0,d.useCallback)(()=>{T(`call_screen`),vt(!1)},[]),Ot=(0,d.useCallback)(()=>{T(`text_chat`),vt(!0)},[]);(0,d.useEffect)(()=>{let e=v?.callId||y||null;if(!e){xt.current=null;return}if(v?.callId||b===`connecting`||b===`connected`){if(tt===`minimized_orb`&&_t&&y&&!v?.callId){xt.current=e;return}!(!i||tt===`minimized_orb`||tt===`voice_mode`)&&xt.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:tt,hasIncomingCall:!!v?.callId,activeCallId:y,callConnectionState:b}),xt.current=e,tt===`voice_mode`&&ue?.(!1),ce?.(),Dt())}},[y,b,Dt,v?.callId,i,ce,ue,tt]),(0,d.useEffect)(()=>{!v&&!y&&tt===`call_screen`&&T(`text_chat`)},[v,y,tt]),(0,d.useEffect)(()=>{!y&&_t&&vt(!1)},[y,_t]),(0,d.useEffect)(()=>{if(!o||_){be?.(``),ye?.();return}if(!E.trim()||dt){be?.(``);let e=window.setTimeout(()=>ye?.(),100);return()=>window.clearTimeout(e)}ve?.();let e=window.setTimeout(()=>be?.(E),120),t=window.setTimeout(()=>ye?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[E,dt,o,_,ve,ye,be]);let kt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,At=async e=>{if(e.preventDefault(),_)return;if($e){let e=O.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){ot(`Please enter a valid email so we can continue helping you.`);return}await le(e),ot(``);return}let t=kt(nt);if(!E.trim()&&!dt)return;if(dt){try{gt(!0),mt(``);let e=await se(dt),n=e?.data||e,r=E.trim()||`Shared file: ${CD(dt)}`;D(``),rt(null),Tt(),await oe(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||dt.name,fileType:n?.fileType||dt.type,fileSize:n?.fileSize||dt.size}})}catch(e){mt(e?.message||`Failed to upload the selected file.`)}finally{gt(!1)}return}let n=E.trim();D(``),rt(null),await oe(n,``,t)},jt=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},Mt=(0,d.useCallback)(async e=>{if(_||m)return;let t=e.message||e.label||e.text||``;t.trim()&&await oe(t.trim(),``)},[_,m,oe]),Nt=Ct&&tt===`entry_prompt`?{inset:0}:Ct&&tt===`text_chat`?{left:0,right:0,bottom:0}:Ct&&tt===`call_screen`?{left:0,right:0,bottom:0,height:`90dvh`,overflow:`hidden`,borderRadius:`16px 16px 0 0`}:Ct&&tt===`connection_modal`?{left:`28px`,right:`12px`,bottom:`12px`}:tt===`call_screen`?{width:`min(350px, calc(100vw - 40px))`,height:`min(640px, calc(100vh - 120px))`,borderRadius:`22px`,overflow:`hidden`,...Ie===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`}}:Ie===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Pt=(0,d.useCallback)(()=>{tt!==`minimized_orb`&&(bt(!0),setTimeout(()=>{T(`minimized_orb`),bt(!1)},280))},[tt]),Ft=()=>T(`connection_modal`),It=()=>{try{let e=window.AudioContext||window.webkitAudioContext;if(e){let t=new e;t.resume().catch(()=>{}),setTimeout(()=>t.close().catch(()=>{}),3e3)}}catch{}ce({notifyChatInitiated:!0}),ue?.(!0),T(`voice_mode`)},Lt=()=>{ce({notifyChatInitiated:!0}),ue?.(!1),T(`text_chat`)},Rt=()=>{ue?.(!1),Pt()};return e!==`ready`||!We||Me.chat===!1?null:(0,f.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...Nt},onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),children:[tt===`entry_prompt`&&(0,f.jsx)(dk,{copy:Ke,orbColors:Pe,primaryColor:Fe,onYes:()=>{ae(w),It()},onLater:()=>{ae(w),Pt()},isMobile:Ct,isClosing:yt}),tt===`minimized_orb`&&(0,f.jsxs)(dm.div,{layoutId:`fe-main-orb`,initial:{scale:.4,opacity:0},animate:{scale:1,opacity:1},transition:{type:`spring`,stiffness:280,damping:18},style:{transformOrigin:`bottom right`,display:`inline-flex`,flexDirection:`column`,alignItems:Ie===`bottom-left`?`flex-start`:`flex-end`,gap:`10px`},children:[y&&_t&&(0,f.jsxs)(`button`,{type:`button`,onClick:Dt,style:{maxWidth:Ct?`220px`:`240px`,padding:`10px 14px`,borderRadius:`18px`,border:`1px solid rgba(255,255,255,0.7)`,background:`rgba(255,255,255,0.94)`,backdropFilter:`blur(18px)`,WebkitBackdropFilter:`blur(18px)`,boxShadow:`0 10px 26px rgba(15,23,42,0.14)`,display:`flex`,alignItems:`center`,gap:`10px`,cursor:`pointer`,textAlign:`left`},children:[(0,f.jsx)(`span`,{style:{width:`9px`,height:`9px`,borderRadius:`50%`,background:`#22c55e`,boxShadow:`0 0 0 4px rgba(34,197,94,0.16)`,flexShrink:0}}),(0,f.jsxs)(`span`,{style:{minWidth:0},children:[(0,f.jsx)(`span`,{style:{display:`block`,fontSize:`12px`,fontWeight:700,color:`#111827`,lineHeight:1.2},children:b===`connected`?`Call in progress`:`Call is active`}),(0,f.jsx)(`span`,{style:{display:`block`,fontSize:`11px`,color:`#6b7280`,lineHeight:1.3,marginTop:`2px`,whiteSpace:`nowrap`},children:b===`connected`?`${jt(st)} with ${Ye}`:`Tap to return to ${Ye}`})]})]}),(0,f.jsx)(uk,{size:50,orbColors:Pe,onClick:y&&_t?Dt:Ne?Ft:Lt})]}),tt===`connection_modal`&&(0,f.jsx)(fk,{copy:Ke,orbColors:Pe,primaryColor:Fe,onVoice:It,onText:Lt,onClose:Pt,isMobile:Ct,isClosing:yt}),tt===`voice_mode`&&(0,f.jsx)(mk,{orbColors:Pe,onEnterChat:Lt,onEndChat:Rt,agentId:qe,siteId:w,apiBaseUrl:Je,historyRef:ne,onMessageSync:re},`voice`),tt===`call_screen`&&(0,f.jsx)(WD,{incomingCall:v,activeCallId:y,callConnectionState:b,callDurationSeconds:st,isCallMuted:S,agentName:Ye,agentHeadshot:Xe,fallbackAgentName:Le,acceptCall:pe,rejectCall:me,endWebRTCCall:he,toggleCallMute:ge,formatCallDuration:jt,onMinimize:Ot,primaryColor:Fe,orbColors:Pe,chatHistory:r}),tt===`text_chat`&&(0,f.jsx)(_k,{isClosing:yt,copy:Ke,orbColors:Pe,primaryColor:Fe,chatBgGradient:Re,logo:ze,quickChatOptions:Ue,onQuickChatSelect:Mt,isMobile:Ct,chatHistory:r,isAiTyping:p,isAgentTyping:u,activeScreen:a,agentName:Ye,agentHeadshot:Xe,fallbackAgentName:Le,input:E,setInput:D,onSubmit:At,isConversationEnded:_,isLoading:m,isRateLimited:h,rateLimitMessage:g,selectedFile:dt,onFileSelect:Et,onRemoveSelectedFile:Tt,attachmentError:pt,isUploadingAttachment:ht,requiresEmail:$e,emailInput:O,setEmailInput:it,emailError:at,replyContext:nt,setReplyContext:rt,webRTCError:ee,micError:lt,setMicError:ut,dismissCallError:_e,activeCallId:y,isCallMuted:S,toggleCallMute:ge,endWebRTCCall:he,formatCallDuration:jt,callDurationSeconds:st,onCollapse:Pt,onStartVoice:It,onNewChat:fe,onEndConversation:de,onMinimize:Ot,onExpand:Dt,isCallMinimized:_t&&!!y,showPoweredBy:C,getVisitorChatHistory:xe,getVisitorChatThread:Se,resumeChat:Te,isSessionRestoring:Ee}),(0,f.jsx)(`style`,{children:`
|
|
636
636
|
/* Force any SVG (or img) inside LogoSlot to fill the container height
|
|
637
637
|
regardless of whether the component forwards its style prop. */
|
|
638
638
|
.fe-logo-slot svg,
|
|
@@ -651,4 +651,4 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
651
651
|
@keyframes fe-orb-bar-3 { from{height:8px} to{height:20px} }
|
|
652
652
|
@keyframes fe-orb-bar-4 { from{height:6px} to{height:16px} }
|
|
653
653
|
@keyframes fe-dot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.5} 40%{transform:translateY(-5px);opacity:1} }
|
|
654
|
-
`})]})}exports.AnimatedOrb=LD,exports.FlowEngageProvider=Sr,exports.FlowEngageWidget=
|
|
654
|
+
`})]})}exports.AnimatedOrb=LD,exports.FlowEngageProvider=Sr,exports.FlowEngageWidget=vk,exports.useFlowEngage=wn;
|
|
@@ -30102,7 +30102,15 @@ function Tk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
|
|
|
30102
30102
|
]
|
|
30103
30103
|
});
|
|
30104
30104
|
}
|
|
30105
|
-
function Ek(
|
|
30105
|
+
function Ek(e) {
|
|
30106
|
+
try {
|
|
30107
|
+
let t = (new URL(e).pathname.split("/").filter(Boolean).pop() || "").replace(/\.(html?|php|aspx?)$/i, "").replace(/[-_+]/g, " ").trim();
|
|
30108
|
+
return t ? t.charAt(0).toUpperCase() + t.slice(1) : "Home";
|
|
30109
|
+
} catch {
|
|
30110
|
+
return "this page";
|
|
30111
|
+
}
|
|
30112
|
+
}
|
|
30113
|
+
function Dk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, historyRef: s, onMessageSync: l }) {
|
|
30106
30114
|
let [u, d] = m("idle"), [f, h] = m(!1), [v, y] = m(!1), [b, x] = m(0), S = p(null), C = p(""), w = p(async () => {}), T = p(!1), ee = p(!1), te = p(!1), ne = p(!1), re = p("minimized"), ie = p(null), ae = o((e = "minimized") => {
|
|
30107
30115
|
re.current = e, ne.current = !0, queueMicrotask(() => {
|
|
30108
30116
|
T.current || (T.current = !0, w.current?.());
|
|
@@ -30149,73 +30157,90 @@ function Ek({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
|
|
|
30149
30157
|
requestEndSession: () => {
|
|
30150
30158
|
ae();
|
|
30151
30159
|
}
|
|
30152
|
-
})), o = i ? Me(i) : null, c = !!o?.transcript, l = c && i ? Be(i) : null, u = {
|
|
30160
|
+
})), o = i ? Me(i) : null, c = !!o?.transcript, l = c && i ? Be(i) : null, u = typeof window < "u" ? window.location.href : "", f = {
|
|
30153
30161
|
agentId: r,
|
|
30154
|
-
clientTools: t
|
|
30155
|
-
|
|
30156
|
-
|
|
30157
|
-
|
|
30158
|
-
|
|
30159
|
-
|
|
30160
|
-
|
|
30161
|
-
|
|
30162
|
-
|
|
30163
|
-
let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
|
|
30164
|
-
if (r) {
|
|
30165
|
-
if (n === "user" && (C.current = r), s.current = [...s.current, {
|
|
30166
|
-
sender: n,
|
|
30167
|
-
message: r,
|
|
30168
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
30169
|
-
}], i) try {
|
|
30170
|
-
let e = aO(s.current);
|
|
30171
|
-
e && je(i, e);
|
|
30172
|
-
} catch {}
|
|
30173
|
-
Sk(n, r) && ae("minimized");
|
|
30162
|
+
clientTools: t,
|
|
30163
|
+
overrides: { agent: { firstMessage: c ? `I can see we're now on the ${Ek(u)} page — feel free to ask me anything about it.` : "Hello! How can I help you today?" } }
|
|
30164
|
+
}, p = null;
|
|
30165
|
+
typeof WebSocket < "u" && (p = WebSocket.prototype.send, WebSocket.prototype.send = function(e) {
|
|
30166
|
+
if (typeof e == "string") try {
|
|
30167
|
+
let t = JSON.parse(e);
|
|
30168
|
+
if (t.type === "conversation_initiation_client_data" && t.conversation_config_override) {
|
|
30169
|
+
let n = t.conversation_config_override;
|
|
30170
|
+
n.tts && Object.keys(n.tts).length === 0 && delete n.tts, n.conversation && Object.keys(n.conversation).length === 0 && delete n.conversation, e = JSON.stringify(t);
|
|
30174
30171
|
}
|
|
30175
|
-
}
|
|
30176
|
-
|
|
30177
|
-
|
|
30178
|
-
|
|
30179
|
-
|
|
30180
|
-
|
|
30181
|
-
|
|
30182
|
-
|
|
30172
|
+
} catch {}
|
|
30173
|
+
return p.call(this, e);
|
|
30174
|
+
});
|
|
30175
|
+
let m;
|
|
30176
|
+
try {
|
|
30177
|
+
m = await pD.startSession({
|
|
30178
|
+
...f,
|
|
30179
|
+
onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
|
|
30180
|
+
onModeChange: ({ mode: t }) => {
|
|
30181
|
+
e || d(t === "speaking" ? "speaking" : "listening");
|
|
30182
|
+
},
|
|
30183
|
+
onMessage: (t) => {
|
|
30184
|
+
if (e) return;
|
|
30185
|
+
let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
|
|
30186
|
+
if (r) {
|
|
30187
|
+
if (n === "user" && (C.current = r), s.current = [...s.current, {
|
|
30188
|
+
sender: n,
|
|
30189
|
+
message: r,
|
|
30190
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
30191
|
+
}], i) try {
|
|
30192
|
+
let e = aO(s.current);
|
|
30193
|
+
e && je(i, e);
|
|
30194
|
+
} catch {}
|
|
30195
|
+
Sk(n, r) && ae("minimized");
|
|
30196
|
+
}
|
|
30197
|
+
},
|
|
30198
|
+
onError: (t) => {
|
|
30199
|
+
if (!e && !ne.current && !te.current && !Le()) {
|
|
30200
|
+
te.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
|
|
30201
|
+
message: t?.message,
|
|
30202
|
+
name: t?.name,
|
|
30203
|
+
raw: t
|
|
30204
|
+
});
|
|
30205
|
+
try {
|
|
30206
|
+
S.current?.setMicMuted?.(!0);
|
|
30207
|
+
} catch {}
|
|
30208
|
+
h(!0), d("error"), ae("chat");
|
|
30209
|
+
}
|
|
30210
|
+
},
|
|
30211
|
+
onDisconnect: () => {
|
|
30212
|
+
if (e || ne.current || te.current || Le()) return;
|
|
30213
|
+
let t = s.current?.length || 0;
|
|
30214
|
+
if (console.warn("[FlowEngageVoiceCall] session:disconnected", {
|
|
30215
|
+
historyCount: t,
|
|
30216
|
+
lastUserText: C.current || "",
|
|
30217
|
+
wasMuted: ee.current
|
|
30218
|
+
}), t === 0 && b === 0) {
|
|
30219
|
+
te.current = !0, console.warn("[FlowEngageVoiceCall] immediate disconnect, retrying once"), x(1);
|
|
30220
|
+
return;
|
|
30221
|
+
}
|
|
30222
|
+
te.current = !0;
|
|
30183
30223
|
try {
|
|
30184
30224
|
S.current?.setMicMuted?.(!0);
|
|
30185
30225
|
} catch {}
|
|
30186
|
-
h(!0),
|
|
30187
|
-
}
|
|
30188
|
-
},
|
|
30189
|
-
onDisconnect: () => {
|
|
30190
|
-
if (e || ne.current || te.current || Le()) return;
|
|
30191
|
-
let t = s.current?.length || 0;
|
|
30192
|
-
if (console.warn("[FlowEngageVoiceCall] session:disconnected", {
|
|
30193
|
-
historyCount: t,
|
|
30194
|
-
lastUserText: C.current || "",
|
|
30195
|
-
wasMuted: ee.current
|
|
30196
|
-
}), t === 0 && b === 0) {
|
|
30197
|
-
te.current = !0, console.warn("[FlowEngageVoiceCall] immediate disconnect, retrying once"), x(1);
|
|
30198
|
-
return;
|
|
30226
|
+
h(!0), ae("chat");
|
|
30199
30227
|
}
|
|
30200
|
-
|
|
30201
|
-
|
|
30202
|
-
|
|
30203
|
-
|
|
30204
|
-
h(!0), ae("chat");
|
|
30205
|
-
}
|
|
30206
|
-
});
|
|
30228
|
+
});
|
|
30229
|
+
} finally {
|
|
30230
|
+
p && (WebSocket.prototype.send = p);
|
|
30231
|
+
}
|
|
30207
30232
|
if (e) {
|
|
30208
|
-
|
|
30233
|
+
m.endSession().catch(() => {});
|
|
30209
30234
|
return;
|
|
30210
30235
|
}
|
|
30211
|
-
n =
|
|
30236
|
+
n = m, S.current = m, d("listening");
|
|
30212
30237
|
try {
|
|
30213
|
-
let e =
|
|
30238
|
+
let e = "[]";
|
|
30214
30239
|
try {
|
|
30215
|
-
|
|
30240
|
+
e = await t.list_page_forms();
|
|
30216
30241
|
} catch {}
|
|
30217
|
-
let
|
|
30218
|
-
|
|
30242
|
+
let n = c && o?.transcript ? `Navigation context: agent navigated from ${l?.previousPage || "previous page"} to ${u}.\nPrior conversation:\n${o.transcript}\n\n` : "";
|
|
30243
|
+
m.sendContextualUpdate(n + `Current page: ${u}. SiteId: ${i || "unknown"}. Forms: ${e}. Voice: call end_voice_session or say you are ending the session to stop.`);
|
|
30219
30244
|
} catch {}
|
|
30220
30245
|
} catch (n) {
|
|
30221
30246
|
e || (console.error("[FlowEngage] startSession failed", n), d("error"), re.current = "chat", window.setTimeout(() => {
|
|
@@ -30493,7 +30518,7 @@ function Ek({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
|
|
|
30493
30518
|
]
|
|
30494
30519
|
});
|
|
30495
30520
|
}
|
|
30496
|
-
function
|
|
30521
|
+
function Ok({ orbColors: e }) {
|
|
30497
30522
|
return /* @__PURE__ */ g("div", {
|
|
30498
30523
|
style: {
|
|
30499
30524
|
flexShrink: 0,
|
|
@@ -30509,7 +30534,7 @@ function Dk({ orbColors: e }) {
|
|
|
30509
30534
|
})
|
|
30510
30535
|
});
|
|
30511
30536
|
}
|
|
30512
|
-
var
|
|
30537
|
+
var kk = () => /* @__PURE__ */ g("div", {
|
|
30513
30538
|
style: {
|
|
30514
30539
|
display: "flex",
|
|
30515
30540
|
marginBottom: "12px",
|
|
@@ -30539,7 +30564,7 @@ var Ok = () => /* @__PURE__ */ g("div", {
|
|
|
30539
30564
|
} }, e))
|
|
30540
30565
|
})
|
|
30541
30566
|
});
|
|
30542
|
-
function
|
|
30567
|
+
function Ak({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: ie, attachmentError: ae, isUploadingAttachment: oe, requiresEmail: se, emailInput: E, setEmailInput: ce, emailError: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, onEndConversation: De, showPoweredBy: Oe, getVisitorChatHistory: ke, getVisitorChatThread: Ae, resumeChat: je, isSessionRestoring: Me, isClosing: Ne }) {
|
|
30543
30568
|
let Pe = l.length > 0, Fe = T || ee || w, Ie = !!ge, [Le, Re] = m(!1), [ze, Be] = m(!1), [D, Ve] = m([]), [He, Ue] = m(!1), [We, Ge] = m(null), [Ke, qe] = m([]), Je = p(null), Ye = async () => {
|
|
30544
30569
|
Re(!1), Be(!0), Ue(!0), Ge(null);
|
|
30545
30570
|
try {
|
|
@@ -31163,11 +31188,11 @@ function kk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
|
|
|
31163
31188
|
isLoading: T,
|
|
31164
31189
|
isAgentTyping: d,
|
|
31165
31190
|
setReplyContext: de,
|
|
31166
|
-
TypingDots:
|
|
31191
|
+
TypingDots: kk,
|
|
31167
31192
|
primaryColor: n,
|
|
31168
31193
|
agentHeadshot: y,
|
|
31169
31194
|
agentDisplayName: v || b,
|
|
31170
|
-
botAvatarNode: /* @__PURE__ */ g(
|
|
31195
|
+
botAvatarNode: /* @__PURE__ */ g(Ok, { orbColors: t })
|
|
31171
31196
|
}) : Me ? /* @__PURE__ */ _("div", {
|
|
31172
31197
|
style: {
|
|
31173
31198
|
flex: 1,
|
|
@@ -31316,7 +31341,7 @@ function kk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
|
|
|
31316
31341
|
]
|
|
31317
31342
|
});
|
|
31318
31343
|
}
|
|
31319
|
-
function
|
|
31344
|
+
function jk() {
|
|
31320
31345
|
let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: ee, callConnectedAt: te, isCallMuted: ne, webRTCError: re, language: ie, historyRef: ae, onMessageSync: oe, sendMessage: se, uploadChatFile: E, openWidget: ce, captureVisitorEmail: le, setVoiceMode: ue, endConversation: de, startNewChat: fe, acceptCall: he, rejectCall: ge, endWebRTCCall: _e, toggleCallMute: ve, dismissCallError: ye, startTyping: be, stopTyping: xe, updateTypingDraft: Se, getVisitorChatHistory: Ce, getVisitorChatThread: we, resumeChat: Te, isSessionRestoring: Ee } = Pn();
|
|
31321
31346
|
c(() => {
|
|
31322
31347
|
try {
|
|
@@ -31689,7 +31714,7 @@ function Ak() {
|
|
|
31689
31714
|
isMobile: Et,
|
|
31690
31715
|
isClosing: St
|
|
31691
31716
|
}),
|
|
31692
|
-
k === "voice_mode" && /* @__PURE__ */ g(
|
|
31717
|
+
k === "voice_mode" && /* @__PURE__ */ g(Dk, {
|
|
31693
31718
|
orbColors: Fe,
|
|
31694
31719
|
onEnterChat: Bt,
|
|
31695
31720
|
onEndChat: Vt,
|
|
@@ -31718,7 +31743,7 @@ function Ak() {
|
|
|
31718
31743
|
orbColors: Fe,
|
|
31719
31744
|
chatHistory: r
|
|
31720
31745
|
}),
|
|
31721
|
-
k === "text_chat" && /* @__PURE__ */ g(
|
|
31746
|
+
k === "text_chat" && /* @__PURE__ */ g(Ak, {
|
|
31722
31747
|
isClosing: St,
|
|
31723
31748
|
copy: Je,
|
|
31724
31749
|
orbColors: Fe,
|
|
@@ -31781,4 +31806,4 @@ function Ak() {
|
|
|
31781
31806
|
});
|
|
31782
31807
|
}
|
|
31783
31808
|
//#endregion
|
|
31784
|
-
export { XD as AnimatedOrb, Mr as FlowEngageProvider,
|
|
31809
|
+
export { XD as AnimatedOrb, Mr as FlowEngageProvider, jk as FlowEngageWidget, Pn as useFlowEngage };
|