@flowengage/react-chatbot 1.9.10 → 1.9.12

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.
@@ -609,8 +609,8 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
609
609
  <path d="M4 2L19 10.5L11 12.8L8 20L4 2Z"
610
610
  fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
611
611
  filter="url(#${Q}-csh)"/>
612
- </svg>`,ID=null,LD=!1;function RD(){return(!ID||!ID.isConnected)&&(ID=document.createElement(`div`),ID.id=`${Q}-cursor`,ID.innerHTML=FD,document.body.appendChild(ID),LD=!1),ID}async function zD(e){if(typeof document>`u`||!e)return;xD();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=RD();LD||=(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 UD(360)}function BD(e=!1){ID&&(e?(ID.classList.remove(`${Q}-cursor-visible`),LD=!1):(ID.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{LD=!1},250)))}async function VD(e){ID&&(ID.classList.add(`${Q}-cursor-click`),await UD(280),ID.classList.remove(`${Q}-cursor-click`))}function HD(e){if(!e||typeof document>`u`)return;xD();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 UD(e){return new Promise(t=>setTimeout(t,e))}function $(...e){gn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function WD(e){return new Promise(t=>setTimeout(t,e))}var GD=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function KD(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(GD)}catch{return!1}}function qD(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function JD(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(!KD(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function YD(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function XD(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 YD(r.join(` `))}if(e.labels&&e.labels.length)return YD(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return YD(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return YD(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return YD(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=YD(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 YD(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return YD(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?YD(o):null}function ZD(){let e=[];return JD(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(KD(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=qD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function QD(){return ZD().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:XD(e),placeholder:e.placeholder||null}))}function $D(){let e=[];return JD(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(KD(e)||e.disabled)return!1;try{let t=qD(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 eO(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function tO(e){let t=eO(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function nO(e,t){let n=tO(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,XD(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>eO(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 rO=28;function iO(e,t){let n=null,r=0;for(let i of e){let e=nO(i,t);e>r&&(r=e,n=i)}return!n||r<rO?null:n}function aO(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,XD(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 oO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function sO(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 cO(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 lO(e){if(!cO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,XD(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 uO(e,t,n){let r=String(t??``),i=String(n??``),a=pO(e,r)||iO(e,r)||aO(e,r,i);if(!a)return[];let o=new Set([a]);if(oO(i)&&sO(r))for(let t of e)t!==a&&lO(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 dO(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 fO(e){if(!e||typeof e!=`string`)return null;let t=null;return JD(n=>{try{let r=n.getElementById(e);r&&!KD(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function pO(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=fO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=fO(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 mO(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 hO(e,t){let n=[];JD(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(KD(e)||e.disabled)return!1;try{let t=qD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:mO(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=dO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function gO(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 _O(e){let t=gO(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 vO(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 yO(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 bO(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 xO(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 SO(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 CO(){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 wO(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 r=gO(n),i=bO(r),a=r.section_text??r.sectionText??r.section;if($(`flowengage_navigate · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(!await On(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`That page is not available in the site index; answer without navigating.`;return $(`flowengage_navigate ✖ blocked`,e),e}if(on)try{TD(`Navigating to ${i}...`,{spinner:!0}),AD(),ME(),$(`flowengage_navigate → proxy FE_DOM_NAVIGATE`,i),await ln(`FE_DOM_NAVIGATE`,{url:i}),await WD(600),a&&typeof a==`string`&&($(`flowengage_navigate · proxy FE_DOM_HIGHLIGHT`,a),await ln(`FE_DOM_HIGHLIGHT`,{sectionText:a}));let e=`OK_NAVIGATION ${i}`;return $(`flowengage_navigate ✓ (iframe proxy)`,e),TD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),TD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{jD(),ED(900)}try{if(TD(`Navigating to ${i}...`,{spinner:!0}),AD(),ME(),RE(),$(`flowengage_navigate → shadowNavigate`,i),await An(i),await WD(400),CO(),a&&typeof a==`string`){let e=Cn(null,a);e&&CE(()=>LE(e)),$(`flowengage_navigate · highlight`,{sectionText:a,found:!!e})}let e=`OK_NAVIGATION ${i}`;return $(`flowengage_navigate ✓`,e),TD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),TD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{jD(),ED(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=gO(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(on){let e=r||n||null;if(!e)return $(`flowengage_highlight ✖ no text`),`Could not find that section on the page.`;$(`flowengage_highlight → proxy FE_DOM_HIGHLIGHT`,e);let t=await ln(`FE_DOM_HIGHLIGHT`,{sectionText:e});return $(`flowengage_highlight ✓ (iframe proxy)`,t),t||`Highlighted the section.`}let i=Cn(n||null,r||null);return i?(LE(i),$(`flowengage_highlight ✓`),`Highlighted the section.`):($(`flowengage_highlight ✖ no element`),`Could not find that section on the page.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=gO(e),n=t?.section_text||t?.sectionText||``;if(on){$(`flowengage_read_content → proxy FE_DOM_READ_CONTENT`,n);let e=await ln(`FE_DOM_READ_CONTENT`,{sectionText:n});return $(`flowengage_read_content ✓ (iframe proxy)`,`${String(e||``).length} chars`),e||`No readable content found on this page.`}try{let e=``;if(n){let t=Cn(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(`
613
- `)}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=xO(gO(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:on?dn():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=gO(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()=>{if(on){$(`flowengage_list_forms → proxy FE_DOM_LIST_FORMS`);let e=await ln(`FE_DOM_LIST_FORMS`);return $(`flowengage_list_forms ✓ (iframe proxy)`),e}let e=QD(),t=$D();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=>{if(on)try{$(`flowengage_fill_form ▶ (iframe proxy) raw:`,e),MD();let t=_O(e);if(!t.length&&r){let e=r(),n=vO(e);n.length||(n=yO(e)),n.length&&($(`flowengage_fill_form · inferred from utterance:`,n),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 {}.`;TD(`Filling form...`,{spinner:!0});let n=await ln(`FE_DOM_FILL_FORM`,{fields:t});return $(`flowengage_fill_form ✓ (iframe proxy)`,n),TD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),n}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),TD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),MD(),ED(700)}try{$(`flowengage_fill_form ▶ raw:`,e),MD();let t=_O(e);if(!t.length&&r){let e=r(),n=vO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=yO(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;TD(`Filling ${String(t)}...`,{spinner:!0});let a=ZD(),o=uO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())ND(t),await zD(t),SO(t,r,{skipScroll:e>0}),PD(t),await WD(120);i=o,n.push(String(t));continue}let s=pO(a,String(t));s||=iO(a,String(t)),s||=aO(a,String(t),r),s&&(ND(s),await zD(s),SO(s,r),PD(s),await WD(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),TD(`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),TD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),MD(),ED(700)}},flowengage_click_button:async e=>{let t=gO(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.`;if(on){TD(`Clicking ${n}...`,{spinner:!0});try{let e=await ln(`FE_DOM_CLICK_BUTTON`,{text:n});return $(`flowengage_click_button ✓ (iframe proxy)`,e),TD(`Clicked`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),TD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),ED(700)}}let r=hO(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{TD(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await zD(r),r.focus?.(),await VD(r),HD(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),TD(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),TD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),ED(700)}}};return{...a,navigateToPage:a.flowengage_navigate,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 TO(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=gn();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 EO={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function DO(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 OO(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 kO({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,P.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,P.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function AO({title:e}){return(0,P.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 jO(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 MO({orbColors:e,...t}){return(0,P.jsx)(bD,{colors:e,...t})}function NO({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a}){let o=n||EO.green,s=OO(o),c=a?72:94,l=(0,P.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:a?`14px`:`18px`},children:[(0,P.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,P.jsx)(yp.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:a?`16px`:`18px`,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,P.jsxs)(yp.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`8px`,flexWrap:`nowrap`},children:[(0,P.jsx)(`button`,{onClick:r,style:{padding:a?`9px 20px`:`10px 28px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:a?`14px`:`15px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${o}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,P.jsx)(`button`,{onClick:i,style:{padding:a?`9px 16px`:`10px 22px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:600,fontSize:a?`14px`:`15px`,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,P.jsx)(yp.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,P.jsx)(MO,{size:c,orbColors:t})})]});return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(yp.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.4},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,P.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`},children:l}):l]})}function PO({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a}){let o=n||EO.green,s=OO(o);return(0,P.jsxs)(yp.div,{initial:{scale:50/300,borderRadius:`50%`},animate:{scale:1,borderRadius:`24px`},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:`bottom right`,background:`white`,padding:`28px 28px 24px`,width:`300px`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`20px`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,P.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,P.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,P.jsx)(MO,{size:82,orbColors:t}),(0,P.jsx)(`p`,{style:{margin:0,fontSize:`17px`,fontWeight:600,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,P.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,width:`100%`},children:[(0,P.jsx)(`button`,{onClick:r,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:`15px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${o}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,P.jsx)(`button`,{onClick:i,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:600,fontSize:`15px`,border:`2px 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 FO({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=(0,b.useRef)(null),h=(0,b.useRef)(``),g=(0,b.useRef)(async()=>{}),_=(0,b.useRef)(!1),v=(0,b.useRef)(!1),y=(0,b.useRef)(!1),x=(0,b.useRef)(!1),ee=(0,b.useRef)(`minimized`),S=(0,b.useRef)(null),C=(0,b.useRef)(null),te=(0,b.useRef)(!1),w=(0,b.useCallback)((e=`minimized`)=>{ee.current=e,x.current=!0,queueMicrotask(()=>{_.current||(_.current=!0,g.current?.())})},[o]),ne=(0,b.useCallback)(async e=>{x.current=!0;try{await m.current?.endSession?.()}catch{}m.current=null,l(`idle`),d(!1),_.current=!1,te.current=!1;try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return g.current=()=>ne(ee.current===`chat`?t:n),(0,b.useEffect)(()=>{v.current=u},[u]),(0,b.useEffect)(()=>{let e=!1,n=null,s=async()=>{if(C.current=s,!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],h.current=``,_.current=!1,y.current=!1,x.current=!1,ee.current=`minimized`,AE(!0),ME();let t=TO(wO({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>h.current,requestEndSession:()=>{w()}})),s=await hE.startSession({agentId:r,clientTools:t,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||(l(t===`speaking`?`speaking`:`listening`),parent.postMessage({type:`AGENT_MODE`,mode:t},`*`),t===`speaking`?TE():EE())},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;r&&(n===`user`&&(h.current=r,ME(),RE()),n===`bot`&&(BE(r,!0),DE(r.trim().split(/\s+/).length)),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],jO(n,r)&&w(`minimized`))},onError:t=>{if(!e&&!x.current&&!y.current)if(y.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t}),!te.current)te.current=!0,m.current=null,setTimeout(async()=>{if(!e){y.current=!1,_.current=!1;try{await C.current?.()}catch{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`),l(`error`),w(`chat`)}}},1500);else{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`);try{m.current?.setMicMuted?.(!0)}catch{}d(!0),l(`error`),w(`chat`)}},onDisconnect:()=>{if(!e&&!x.current&&!y.current){y.current=!0,console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:o.current?.length||0,lastUserText:h.current||``,wasMuted:v.current});try{m.current?.setMicMuted?.(!0)}catch{}d(!0),ME(),RE(),AE(!1),w(`chat`)}}});if(e){s.endSession().catch(()=>{});return}n=s,m.current=s,l(`listening`),te.current=!1;try{sessionStorage.setItem(`el_conv_${i}`,s.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.flowengage_list_forms()}catch{}s.sendContextualUpdate(`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`),ee.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}};return s(),()=>{e=!0,x.current=!0,(n||m.current)?.endSession?.().catch(()=>{})}},[r,i,a,w]),(0,b.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;S.current&&!S.current.contains(t)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,P.jsx)(P.Fragment,{children:(0,P.jsxs)(`div`,{style:{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,P.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,P.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,P.jsx)(MO,{size:94,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,P.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,P.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,P.jsx)(`button`,{onClick:async()=>{if(m.current)try{u?(await m.current.setMicMuted?.(!1),d(!1)):(await m.current.setMicMuted?.(!0),d(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`44px`,height:`44px`,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)`},children:u?(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,P.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,P.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,P.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,P.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`,fill:`currentColor`,stroke:`none`}),(0,P.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]})}),(0,P.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:S,children:[(0,P.jsx)(`button`,{onClick:()=>p(e=>!e),style:{width:`44px`,height:`44px`,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)`},children:(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,P.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.8`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.8`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.8`})]})}),f&&(0,P.jsxs)(`div`,{style:{position:`absolute`,bottom:`54px`,right:0,zIndex:9999,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,P.jsxs)(`button`,{onClick:()=>{p(!1),ee.current=`chat`,ne(t)},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,P.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`path`,{d:`M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z`})}),`Enter Chat Mode`]}),(0,P.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,P.jsxs)(`button`,{onClick:()=>{p(!1),ee.current=`minimized`,ne(n)},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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,P.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`End Conversation`]})]})]})]})]})})}function IO({orbColors:e}){return(0,P.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,P.jsx)(MO,{size:36,orbColors:e})})}var LO=()=>(0,P.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,P.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,P.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 RO({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:ae,emailError:oe,replyContext:se,setReplyContext:ce,webRTCError:le,micError:ue,setMicError:T,dismissCallError:E,incomingCall:de,rejectCall:fe,acceptCall:pe,activeCallId:me,callConnectionState:D,isCallMuted:O,toggleCallMute:he,endWebRTCCall:ge,formatCallDuration:_e,callDurationSeconds:ve,onCollapse:ye,onStartVoice:be,showPoweredBy:xe}){let Se=c.length>0,Ce=y||x||v,we=!!(de||me),[Te,Ee]=(0,b.useState)(!1),De=(0,b.useRef)(null);return(0,b.useEffect)(()=>{if(!Te)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;De.current&&!De.current.contains(t)&&Ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Te]),(0,P.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,inset:0,width:`100%`,height:`100dvh`,background:r,borderRadius:0,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(390px, 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:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,P.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 18px 14px`,background:`transparent`,flexShrink:0},children:[(0,P.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,P.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,P.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,P.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,P.jsx)(kO,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,P.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,P.jsx)(AO,{title:e.chatTitle})})}),(0,P.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,P.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,P.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:De,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>Ee(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,P.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,P.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Te&&(0,P.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,P.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(!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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,P.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,P.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(!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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,P.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`Close Conversation`]})]})]})]}),(0,P.jsx)(dD,{webRTCError:le,micError:ue,setMicError:T,dismissCallError:E,incomingCall:de,rejectCall:fe,acceptCall:pe,activeCallId:me,callConnectionState:D,formatCallDuration:_e,callDurationSeconds:ve,endWebRTCCall:ge,isCallMuted:O,toggleCallMute:he,isAIVoiceActive:!1,currentCallAgentName:f||m,isRateLimited:x,rateLimitMessage:ee}),(0,P.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`},children:Se?(0,P.jsx)(sD,{chatHistory:c,isAiTyping:l,isAgentTyping:u,setReplyContext:ce,TypingDots:LO,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,P.jsx)(IO,{orbColors:t})}):(0,P.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,P.jsx)(MO,{size:94,orbColors:t}),(0,P.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,P.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,P.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,P.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:re?`6px 0 0`:`12px 0 0`},children:(0,P.jsx)(cD,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:we,handleToggleVoice:be,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:Ce,replyContext:se,clearReplyContext:()=>ce(null),onFileSelect:C,selectedFile:S,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:ae,emailError:oe,inputPlaceholder:e.inputPlaceholder})}),(0,P.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:xe&&(0,P.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,P.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function zO(){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:ae,endConversation:oe,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:ue,dismissCallError:T,startTyping:E,stopTyping:de,updateTypingDraft:fe}=hn();(0,b.useEffect)(()=>{try{xn()}catch{}},[]);let pe=t?.widgetSettings||{},me=n?.widgetSettings||{},D={...pe.branding||{},...me.branding||{}},O={...pe.theme||{},...me.theme||{}},he=Array.isArray(O.orbColors)&&O.orbColors.length>0?O.orbColors:null,ge=he?.[0]||O.primaryColor||`#3B82F6`,_e=O.position||`bottom-right`,ve=D.fallbackAgentName||`Agent`,ye=DO(he??O.chatBgColors),be=D.logo||D.logoUrl||null,xe=S||`en`,Se=pe.recommendations?.[xe]||[],Ce=(me.recommendations?.[xe]??Se).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),we=Array.isArray(D.quickChatOptions)&&D.quickChatOptions.length>0?D.quickChatOptions:Ce,Te=D.hideWatermark===!0?!1:D.showPoweredBy!==!1,Ee=D.chatbotEnabled!==!1&&O.chatbotEnabled!==!1,De=pe.greetings?.[S]||me.greetings?.[S]||D.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Oe={entryPrompt:D.entryPrompt||`Do you want to explore in a new way?`,yesLabel:D.yesLabel||`Yes`,laterLabel:D.laterLabel||`Later`,connectionTitle:D.connectionTitle||`How would you like to connect?`,voiceLabel:D.voiceLabel||`Voice`,textLabel:D.textLabel||`Text`,chatTitle:D.headerName||`Chat with FlowEngage`,introGreeting:De,inputPlaceholder:D.inputPlaceholder||`Type your message`,analysingLabel:D.analysingLabel||`analysing...`},ke=me.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ae=t?.siteId||n?.siteId||null,k=t?.apiBaseUrl||``,je=(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]),Me=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Ne=r.some(e=>e.sender===`user`),Pe=(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]),Fe=!l&&Ne&&Pe,Ie=!!(me._dashboardLivePreview||pe._dashboardLivePreview),[Le,Re]=(0,b.useState)(()=>Ie?`text_chat`:`entry_prompt`),[ze,Be]=(0,b.useState)(``),[Ve,He]=(0,b.useState)(null),[A,j]=(0,b.useState)(l||``),[Ue,M]=(0,b.useState)(``),[We,Ge]=(0,b.useState)(0),[Ke,qe]=(0,b.useState)(null),[Je,Ye]=(0,b.useState)(null),[Xe,Ze]=(0,b.useState)(``),[Qe,$e]=(0,b.useState)(!1),et=(0,b.useRef)(null),tt=(0,b.useRef)(!1);(0,b.useLayoutEffect)(()=>{e!==`ready`||tt.current||(tt.current=!0,r.length>0&&Re(`minimized_orb`))},[e,r]);let[nt,rt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>rt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{j(l||``),l&&M(``)},[l]),(0,b.useEffect)(()=>{Le===`minimized_orb`?parent.postMessage({type:`WIDGET_MINIMIZED`},`*`):Le!==`voice_mode`&&parent.postMessage({type:`WIDGET_OPEN`},`*`)},[Le]);let it=(0,b.useCallback)(()=>{Ye(null),Ze(``)},[]),at=(0,b.useCallback)(e=>{let t=nD(e);if(t){Ye(null),Ze(t);return}Ye(e),Ze(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){Ge(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||Ge(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]),(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){et.current=null;return}(g?.callId||v===`connecting`||v===`connected`)&&(!(!i||Le===`minimized_orb`||Le===`voice_mode`)&&et.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:Le,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),et.current=e,Le===`voice_mode`&&ae?.(!1),re?.(),Re(`text_chat`)))},[_,v,g?.callId,i,re,ae,Le]),(0,b.useEffect)(()=>{if(!o||h){fe?.(``),de?.();return}if(!ze.trim()||Je){fe?.(``),de?.();return}E?.();let e=window.setTimeout(()=>fe?.(ze),120),t=window.setTimeout(()=>de?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[ze,Je,o,h,E,de,fe]);let ot=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,st=async e=>{if(e.preventDefault(),h)return;if(Fe){let e=A.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){M(`Please enter a valid email so we can continue helping you.`);return}await ie(e),M(``);return}let t=ot(Ve);if(!ze.trim()&&!Je)return;if(Je){try{$e(!0),Ze(``);let e=await ne(Je),n=e?.data||e,r=ze.trim()||`Shared file: ${iD(Je)}`;Be(``),He(null),it(),await w(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||Je.name,fileType:n?.fileType||Je.type,fileSize:n?.fileSize||Je.size}})}catch(e){Ze(e?.message||`Failed to upload the selected file.`)}finally{$e(!1)}return}let n=ze.trim();Be(``),He(null),await w(n,``,t)},ct=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},lt=(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]),ut=nt&&(Le===`text_chat`||Le===`entry_prompt`)?{inset:0}:_e===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},dt=()=>Re(`minimized_orb`),ft=()=>Re(`connection_modal`),pt=()=>{re({notifyChatInitiated:!0}),ae?.(!0),Re(`voice_mode`)},mt=()=>{re({notifyChatInitiated:!0}),ae?.(!1),Re(`text_chat`)},ht=()=>{ae?.(!1),dt()};return e!==`ready`||!Ee?null:(0,P.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...ut},children:[Le===`entry_prompt`&&(0,P.jsx)(NO,{copy:Oe,orbColors:he,primaryColor:ge,onYes:pt,onLater:dt,isMobile:nt}),Le===`minimized_orb`&&(0,P.jsx)(yp.div,{layoutId:`fe-main-orb`,initial:{scale:94/50},animate:{scale:1},transition:{type:`spring`,stiffness:220,damping:26},style:{transformOrigin:`bottom right`,display:`inline-block`},children:(0,P.jsx)(MO,{size:50,orbColors:he,onClick:ft})}),Le===`connection_modal`&&(0,P.jsx)(PO,{copy:Oe,orbColors:he,primaryColor:ge,onVoice:pt,onText:mt,onClose:dt}),Le===`voice_mode`&&(0,P.jsx)(FO,{orbColors:he,onEnterChat:mt,onEndChat:ht,agentId:ke,siteId:Ae,apiBaseUrl:k,historyRef:C,onMessageSync:te},`voice`),Le===`text_chat`&&(0,P.jsx)(RO,{copy:Oe,orbColors:he,primaryColor:ge,chatBgGradient:ye,logo:be,quickChatOptions:we,onQuickChatSelect:lt,isMobile:nt,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:je,agentHeadshot:Me,fallbackAgentName:ve,input:ze,setInput:Be,onSubmit:st,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:Je,onFileSelect:at,onRemoveSelectedFile:it,attachmentError:Xe,isUploadingAttachment:Qe,requiresEmail:Fe,emailInput:A,setEmailInput:j,emailError:Ue,replyContext:Ve,setReplyContext:He,webRTCError:ee,micError:Ke,setMicError:qe,dismissCallError:T,incomingCall:g,rejectCall:ce,acceptCall:se,activeCallId:_,callConnectionState:v,isCallMuted:x,toggleCallMute:ue,endWebRTCCall:le,formatCallDuration:ct,callDurationSeconds:We,onCollapse:dt,onStartVoice:pt,onEndConversation:oe,showPoweredBy:Te}),(0,P.jsx)(`style`,{children:`
612
+ </svg>`,ID=null,LD=!1;function RD(){return(!ID||!ID.isConnected)&&(ID=document.createElement(`div`),ID.id=`${Q}-cursor`,ID.innerHTML=FD,document.body.appendChild(ID),LD=!1),ID}async function zD(e){if(typeof document>`u`||!e)return;xD();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=RD();LD||=(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 UD(360)}function BD(e=!1){ID&&(e?(ID.classList.remove(`${Q}-cursor-visible`),LD=!1):(ID.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{LD=!1},250)))}async function VD(e){ID&&(ID.classList.add(`${Q}-cursor-click`),await UD(280),ID.classList.remove(`${Q}-cursor-click`))}function HD(e){if(!e||typeof document>`u`)return;xD();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 UD(e){return new Promise(t=>setTimeout(t,e))}function $(...e){gn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function WD(e){return new Promise(t=>setTimeout(t,e))}var GD=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function KD(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(GD)}catch{return!1}}function qD(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function JD(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(!KD(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function YD(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function XD(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 YD(r.join(` `))}if(e.labels&&e.labels.length)return YD(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return YD(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return YD(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return YD(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=YD(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 YD(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return YD(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?YD(o):null}function ZD(){let e=[];return JD(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(KD(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=qD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function QD(){return ZD().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:XD(e),placeholder:e.placeholder||null}))}function $D(){let e=[];return JD(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(KD(e)||e.disabled)return!1;try{let t=qD(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 eO(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function tO(e){let t=eO(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function nO(e,t){let n=tO(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,XD(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>eO(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 rO=28;function iO(e,t){let n=null,r=0;for(let i of e){let e=nO(i,t);e>r&&(r=e,n=i)}return!n||r<rO?null:n}function aO(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,XD(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 oO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function sO(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 cO(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 lO(e){if(!cO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,XD(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 uO(e,t,n){let r=String(t??``),i=String(n??``),a=pO(e,r)||iO(e,r)||aO(e,r,i);if(!a)return[];let o=new Set([a]);if(oO(i)&&sO(r))for(let t of e)t!==a&&lO(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 dO(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 fO(e){if(!e||typeof e!=`string`)return null;let t=null;return JD(n=>{try{let r=n.getElementById(e);r&&!KD(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function pO(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=fO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=fO(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 mO(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 hO(e,t){let n=[];JD(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(KD(e)||e.disabled)return!1;try{let t=qD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:mO(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=dO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function gO(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 _O(e){let t=gO(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 vO(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 yO(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 bO(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 xO(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 SO(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 CO(){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 wO(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=typeof e.getHistory==`function`?e.getHistory:null,a=[],o={flowengage_navigate:async n=>{$(`flowengage_navigate ▶ raw parameters:`,n);let r=gO(n),a=bO(r),o=r.section_text??r.sectionText??r.section;if($(`flowengage_navigate · coerced:`,{url:a,sectionText:o}),!a){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(!await On(a,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`That page is not available in the site index; answer without navigating.`;return $(`flowengage_navigate ✖ blocked`,e),e}if(on)try{TD(`Navigating to ${a}...`,{spinner:!0}),AD(),ME();try{sessionStorage.setItem(`_fe_voice_nav`,JSON.stringify({ts:Date.now(),to:a}));let e=i?.()||[];e.length>0&&sessionStorage.setItem(`_fe_voice_transcript`,JSON.stringify(e.slice(-30)))}catch{}$(`flowengage_navigate → proxy FE_DOM_NAVIGATE`,a),await ln(`FE_DOM_NAVIGATE`,{url:a}),await WD(600),o&&typeof o==`string`&&($(`flowengage_navigate · proxy FE_DOM_HIGHLIGHT`,o),await ln(`FE_DOM_HIGHLIGHT`,{sectionText:o}));let e=`OK_NAVIGATION ${a}`;return $(`flowengage_navigate ✓ (iframe proxy)`,e),TD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),TD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{jD(),ED(900)}try{if(TD(`Navigating to ${a}...`,{spinner:!0}),AD(),ME(),RE(),$(`flowengage_navigate → shadowNavigate`,a),await An(a),await WD(400),CO(),o&&typeof o==`string`){let e=Cn(null,o);e&&CE(()=>LE(e)),$(`flowengage_navigate · highlight`,{sectionText:o,found:!!e})}let e=`OK_NAVIGATION ${a}`;return $(`flowengage_navigate ✓`,e),TD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),TD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{jD(),ED(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=gO(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(on){let e=r||n||null;if(!e)return $(`flowengage_highlight ✖ no text`),`Could not find that section on the page.`;$(`flowengage_highlight → proxy FE_DOM_HIGHLIGHT`,e);let t=await ln(`FE_DOM_HIGHLIGHT`,{sectionText:e});return $(`flowengage_highlight ✓ (iframe proxy)`,t),t||`Highlighted the section.`}let i=Cn(n||null,r||null);return i?(LE(i),$(`flowengage_highlight ✓`),`Highlighted the section.`):($(`flowengage_highlight ✖ no element`),`Could not find that section on the page.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=gO(e),n=t?.section_text||t?.sectionText||``;if(on){$(`flowengage_read_content → proxy FE_DOM_READ_CONTENT`,n);let e=await ln(`FE_DOM_READ_CONTENT`,{sectionText:n});return $(`flowengage_read_content ✓ (iframe proxy)`,`${String(e||``).length} chars`),e||`No readable content found on this page.`}try{let e=``;if(n){let t=Cn(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(`
613
+ `)}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=xO(gO(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:on?dn():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=gO(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()=>{if(on){$(`flowengage_list_forms → proxy FE_DOM_LIST_FORMS`);let e=await ln(`FE_DOM_LIST_FORMS`);return $(`flowengage_list_forms ✓ (iframe proxy)`),e}let e=QD(),t=$D();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=>{if(on)try{$(`flowengage_fill_form ▶ (iframe proxy) raw:`,e),MD();let t=_O(e);if(!t.length&&r){let e=r(),n=vO(e);n.length||(n=yO(e)),n.length&&($(`flowengage_fill_form · inferred from utterance:`,n),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 {}.`;TD(`Filling form...`,{spinner:!0});let n=await ln(`FE_DOM_FILL_FORM`,{fields:t});return $(`flowengage_fill_form ✓ (iframe proxy)`,n),TD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),n}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),TD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),MD(),ED(700)}try{$(`flowengage_fill_form ▶ raw:`,e),MD();let t=_O(e);if(!t.length&&r){let e=r(),n=vO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=yO(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;TD(`Filling ${String(t)}...`,{spinner:!0});let i=ZD(),o=uO(i,String(t),r);if(o.length){for(let[e,t]of o.entries())ND(t),await zD(t),SO(t,r,{skipScroll:e>0}),PD(t),await WD(120);a=o,n.push(String(t));continue}let s=pO(i,String(t));s||=iO(i,String(t)),s||=aO(i,String(t),r),s&&(ND(s),await zD(s),SO(s,r),PD(s),await WD(120),a=[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 i=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,i),TD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),i}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),TD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),MD(),ED(700)}},flowengage_click_button:async e=>{let t=gO(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.`;if(on){TD(`Clicking ${n}...`,{spinner:!0});try{let e=await ln(`FE_DOM_CLICK_BUTTON`,{text:n});return $(`flowengage_click_button ✓ (iframe proxy)`,e),TD(`Clicked`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),TD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),ED(700)}}let r=hO(n,a);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{TD(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await zD(r),r.focus?.(),await VD(r),HD(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),TD(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),TD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{BD(),ED(700)}}};return{...o,navigateToPage:o.flowengage_navigate,highlightOnPage:o.flowengage_highlight,searchSiteContent:o.flowengage_search,getPageContent:o.flowengage_page_content,endVoiceSession:o.flowengage_end_session,listPageForms:o.flowengage_list_forms,fillFormFields:o.flowengage_fill_form,clickPageButton:o.flowengage_click_button}}function TO(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=gn();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 EO={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function DO(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 OO(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 kO({logo:e,style:t}){if(!e)return null;if(typeof e==`string`)return(0,P.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,P.jsx)(`span`,{className:`fe-logo-slot`,style:{display:`inline-flex`,alignItems:`center`,flexShrink:0,overflow:`hidden`,...t},children:n}):null}function AO({title:e}){return(0,P.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 jO(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 MO({orbColors:e,...t}){return(0,P.jsx)(bD,{colors:e,...t})}function NO({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a}){let o=n||EO.green,s=OO(o),c=a?72:94,l=(0,P.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:a?`14px`:`18px`},children:[(0,P.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,P.jsx)(yp.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:a?`16px`:`18px`,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,P.jsxs)(yp.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`8px`,flexWrap:`nowrap`},children:[(0,P.jsx)(`button`,{onClick:r,style:{padding:a?`9px 20px`:`10px 28px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:a?`14px`:`15px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${o}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,P.jsx)(`button`,{onClick:i,style:{padding:a?`9px 16px`:`10px 22px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:600,fontSize:a?`14px`:`15px`,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,P.jsx)(yp.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,P.jsx)(MO,{size:c,orbColors:t})})]});return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(yp.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.4},style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.72)`,zIndex:-1}}),a?(0,P.jsx)(`div`,{style:{position:`absolute`,bottom:0,left:0,right:0,padding:`24px 20px 40px`,overflow:`hidden`},children:l}):l]})}function PO({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a}){let o=n||EO.green,s=OO(o);return(0,P.jsxs)(yp.div,{initial:{scale:50/300,borderRadius:`50%`},animate:{scale:1,borderRadius:`24px`},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:`bottom right`,background:`white`,padding:`28px 28px 24px`,width:`300px`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`20px`,boxShadow:`0 20px 60px rgba(0,0,0,0.2)`,position:`relative`,overflow:`hidden`},children:[(0,P.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,P.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,P.jsx)(MO,{size:82,orbColors:t}),(0,P.jsx)(`p`,{style:{margin:0,fontSize:`17px`,fontWeight:600,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,P.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,width:`100%`},children:[(0,P.jsx)(`button`,{onClick:r,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:`15px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${o}55`},onMouseEnter:e=>{e.currentTarget.style.transform=`scale(1.03)`},onMouseLeave:e=>{e.currentTarget.style.transform=`scale(1)`},children:e.voiceLabel}),(0,P.jsx)(`button`,{onClick:i,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:600,fontSize:`15px`,border:`2px 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 FO({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=(0,b.useRef)(null),h=(0,b.useRef)(``),g=(0,b.useRef)(async()=>{}),_=(0,b.useRef)(!1),v=(0,b.useRef)(!1),y=(0,b.useRef)(!1),x=(0,b.useRef)(!1),ee=(0,b.useRef)(`minimized`),S=(0,b.useRef)(null),C=(0,b.useRef)(null),te=(0,b.useRef)(!1),w=(0,b.useCallback)((e=`minimized`)=>{ee.current=e,x.current=!0,queueMicrotask(()=>{_.current||(_.current=!0,g.current?.())})},[o]),ne=(0,b.useCallback)(async e=>{x.current=!0;try{await m.current?.endSession?.()}catch{}m.current=null,l(`idle`),d(!1),_.current=!1,te.current=!1;try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return g.current=()=>ne(ee.current===`chat`?t:n),(0,b.useEffect)(()=>{v.current=u},[u]),(0,b.useEffect)(()=>{let e=!1,n=null,s=async()=>{if(C.current=s,!r){l(`error`);return}try{if((await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),e)return;o.current=[],h.current=``,_.current=!1,y.current=!1,x.current=!1,ee.current=`minimized`,AE(!0),ME();let t=TO(wO({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>h.current,requestEndSession:()=>{w()}})),s=await hE.startSession({agentId:r,clientTools:t,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||(l(t===`speaking`?`speaking`:`listening`),parent.postMessage({type:`AGENT_MODE`,mode:t},`*`),t===`speaking`?TE():EE())},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;r&&(n===`user`&&(h.current=r,ME(),RE()),n===`bot`&&(BE(r,!0),DE(r.trim().split(/\s+/).length)),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],jO(n,r)&&w(`minimized`))},onError:t=>{if(!e&&!x.current&&!y.current)if(y.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t}),!te.current)te.current=!0,m.current=null,setTimeout(async()=>{if(!e){y.current=!1,_.current=!1;try{await C.current?.()}catch{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`),l(`error`),w(`chat`)}}},1500);else{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`);try{m.current?.setMicMuted?.(!0)}catch{}d(!0),l(`error`),w(`chat`)}},onDisconnect:()=>{if(!e&&!x.current&&!y.current){y.current=!0,console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:o.current?.length||0,lastUserText:h.current||``,wasMuted:v.current});try{m.current?.setMicMuted?.(!0)}catch{}d(!0),ME(),RE(),AE(!1),w(`chat`)}}});if(e){s.endSession().catch(()=>{});return}n=s,m.current=s,l(`listening`),te.current=!1;try{sessionStorage.setItem(`el_conv_${i}`,s.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.flowengage_list_forms()}catch{}s.sendContextualUpdate(`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`),ee.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}};return s(),()=>{e=!0,x.current=!0,(n||m.current)?.endSession?.().catch(()=>{})}},[r,i,a,w]),(0,b.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;S.current&&!S.current.contains(t)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,P.jsx)(P.Fragment,{children:(0,P.jsxs)(`div`,{style:{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,P.jsxs)(`div`,{style:{position:`relative`},children:[c===`listening`&&(0,P.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,P.jsx)(MO,{size:94,voiceState:c,isMuted:u,orbColors:e})]}),c===`error`&&(0,P.jsx)(`span`,{style:{color:`#f87171`,fontSize:`13px`,fontWeight:500},children:`Could not start voice session.`}),(0,P.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,alignItems:`center`},children:[(0,P.jsx)(`button`,{onClick:async()=>{if(m.current)try{u?(await m.current.setMicMuted?.(!1),d(!1)):(await m.current.setMicMuted?.(!0),d(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`44px`,height:`44px`,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)`},children:u?(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,P.jsx)(`path`,{d:`M9 9v3a3 3 0 005.12 2.12M15 9.34V4a3 3 0 00-5.94-.6`}),(0,P.jsx)(`path`,{d:`M17 16.95A7 7 0 015 12v-2m14 0v2a7 7 0 01-.11 1.23`}),(0,P.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`23`}),(0,P.jsx)(`line`,{x1:`8`,y1:`23`,x2:`16`,y2:`23`})]}):(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`,fill:`currentColor`,stroke:`none`}),(0,P.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]})}),(0,P.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:S,children:[(0,P.jsx)(`button`,{onClick:()=>p(e=>!e),style:{width:`44px`,height:`44px`,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)`},children:(0,P.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,P.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.8`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.8`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.8`})]})}),f&&(0,P.jsxs)(`div`,{style:{position:`absolute`,bottom:`54px`,right:0,zIndex:9999,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,P.jsxs)(`button`,{onClick:()=>{p(!1),ee.current=`chat`,ne(t)},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,P.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`path`,{d:`M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z`})}),`Enter Chat Mode`]}),(0,P.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,P.jsxs)(`button`,{onClick:()=>{p(!1),ee.current=`minimized`,ne(n)},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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,P.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`End Conversation`]})]})]})]})]})})}function IO({orbColors:e}){return(0,P.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,P.jsx)(MO,{size:36,orbColors:e})})}var LO=()=>(0,P.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,P.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,P.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 RO({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:ae,emailError:oe,replyContext:se,setReplyContext:ce,webRTCError:le,micError:ue,setMicError:T,dismissCallError:E,incomingCall:de,rejectCall:fe,acceptCall:pe,activeCallId:me,callConnectionState:D,isCallMuted:O,toggleCallMute:he,endWebRTCCall:ge,formatCallDuration:_e,callDurationSeconds:ve,onCollapse:ye,onStartVoice:be,showPoweredBy:xe}){let Se=c.length>0,Ce=y||x||v,we=!!(de||me),[Te,Ee]=(0,b.useState)(!1),De=(0,b.useRef)(null);return(0,b.useEffect)(()=>{if(!Te)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;De.current&&!De.current.contains(t)&&Ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Te]),(0,P.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,inset:0,width:`100%`,height:`100dvh`,background:r,borderRadius:0,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(390px, 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:`fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)`},children:[(0,P.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`40px minmax(0, 1fr) 40px`,alignItems:`center`,columnGap:`14px`,padding:`16px 18px 14px`,background:`transparent`,flexShrink:0},children:[(0,P.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,P.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,P.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}),(0,P.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,P.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`,justifyContent:`center`,height:`40px`},children:i?(0,P.jsx)(kO,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,P.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,P.jsx)(AO,{title:e.chatTitle})})}),(0,P.jsx)(`div`,{style:{minWidth:0,display:`flex`,alignItems:`center`},children:(0,P.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,P.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:De,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>Ee(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,P.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,P.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.5`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.5`}),(0,P.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.5`})]})}),Te&&(0,P.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,P.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(!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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M12 1a4 4 0 014 4v6a4 4 0 01-8 0V5a4 4 0 014-4z`}),(0,P.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]}),`Enter Voice Mode`]}),(0,P.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(!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,P.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,P.jsx)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,P.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`Close Conversation`]})]})]})]}),(0,P.jsx)(dD,{webRTCError:le,micError:ue,setMicError:T,dismissCallError:E,incomingCall:de,rejectCall:fe,acceptCall:pe,activeCallId:me,callConnectionState:D,formatCallDuration:_e,callDurationSeconds:ve,endWebRTCCall:ge,isCallMuted:O,toggleCallMute:he,isAIVoiceActive:!1,currentCallAgentName:f||m,isRateLimited:x,rateLimitMessage:ee}),(0,P.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`},children:Se?(0,P.jsx)(sD,{chatHistory:c,isAiTyping:l,isAgentTyping:u,setReplyContext:ce,TypingDots:LO,primaryColor:n,agentHeadshot:p,agentDisplayName:f||m,botAvatarNode:(0,P.jsx)(IO,{orbColors:t})}):(0,P.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`22px`,padding:`28px 24px`},children:[(0,P.jsx)(MO,{size:94,orbColors:t}),(0,P.jsx)(`p`,{style:{margin:0,textAlign:`center`,fontSize:`16px`,color:`#374151`,lineHeight:1.55,maxWidth:`270px`},children:e.introGreeting}),a.length>0&&(0,P.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,justifyContent:`center`,width:`100%`,padding:`0 8px`},children:a.map(e=>(0,P.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,P.jsx)(`div`,{style:{background:`transparent`,flexShrink:0,position:`relative`,zIndex:1,padding:re?`6px 0 0`:`12px 0 0`},children:(0,P.jsx)(cD,{input:h,setInput:g,onSubmit:_,isConversationEnded:v,callUiActive:we,handleToggleVoice:be,showVoiceToggle:d===`agent`,activeScreen:d,inputDisabled:Ce,replyContext:se,clearReplyContext:()=>ce(null),onFileSelect:C,selectedFile:S,onRemoveSelectedFile:te,attachmentError:w,isUploadingAttachment:ne,requiresEmail:re,emailInput:ie,setEmailInput:ae,emailError:oe,inputPlaceholder:e.inputPlaceholder})}),(0,P.jsx)(`div`,{style:{flexShrink:0,textAlign:`center`,padding:`12px 20px 18px`,pointerEvents:`none`},children:xe&&(0,P.jsxs)(`span`,{style:{fontSize:`11px`,color:`#9ca3af`,letterSpacing:`0.01em`,userSelect:`none`},children:[`Powered by `,(0,P.jsx)(`strong`,{style:{fontWeight:600,color:`#6b7280`},children:`FlowEngage`})]})})]})}function zO(){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:ae,endConversation:oe,acceptCall:se,rejectCall:ce,endWebRTCCall:le,toggleCallMute:ue,dismissCallError:T,startTyping:E,stopTyping:de,updateTypingDraft:fe}=hn();(0,b.useEffect)(()=>{try{xn()}catch{}},[]);let pe=t?.widgetSettings||{},me=n?.widgetSettings||{},D={...pe.branding||{},...me.branding||{}},O={...pe.theme||{},...me.theme||{}},he=Array.isArray(O.orbColors)&&O.orbColors.length>0?O.orbColors:null,ge=he?.[0]||O.primaryColor||`#3B82F6`,_e=O.position||`bottom-right`,ve=D.fallbackAgentName||`Agent`,ye=DO(he??O.chatBgColors),be=D.logo||D.logoUrl||null,xe=S||`en`,Se=pe.recommendations?.[xe]||[],Ce=(me.recommendations?.[xe]??Se).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),we=Array.isArray(D.quickChatOptions)&&D.quickChatOptions.length>0?D.quickChatOptions:Ce,Te=D.hideWatermark===!0?!1:D.showPoweredBy!==!1,Ee=D.chatbotEnabled!==!1&&O.chatbotEnabled!==!1,De=pe.greetings?.[S]||me.greetings?.[S]||D.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Oe={entryPrompt:D.entryPrompt||`Do you want to explore in a new way?`,yesLabel:D.yesLabel||`Yes`,laterLabel:D.laterLabel||`Later`,connectionTitle:D.connectionTitle||`How would you like to connect?`,voiceLabel:D.voiceLabel||`Voice`,textLabel:D.textLabel||`Text`,chatTitle:D.headerName||`Chat with FlowEngage`,introGreeting:De,inputPlaceholder:D.inputPlaceholder||`Type your message`,analysingLabel:D.analysingLabel||`analysing...`},ke=me.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ae=t?.siteId||n?.siteId||null,k=t?.apiBaseUrl||``,je=(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]),Me=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Ne=r.some(e=>e.sender===`user`),Pe=(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]),Fe=!l&&Ne&&Pe,Ie=!!(me._dashboardLivePreview||pe._dashboardLivePreview),[Le,Re]=(0,b.useState)(()=>Ie?`text_chat`:`entry_prompt`),[ze,Be]=(0,b.useState)(``),[Ve,He]=(0,b.useState)(null),[A,j]=(0,b.useState)(l||``),[Ue,M]=(0,b.useState)(``),[We,Ge]=(0,b.useState)(0),[Ke,qe]=(0,b.useState)(null),[Je,Ye]=(0,b.useState)(null),[Xe,Ze]=(0,b.useState)(``),[Qe,$e]=(0,b.useState)(!1),et=(0,b.useRef)(null),tt=(0,b.useRef)(!1);(0,b.useLayoutEffect)(()=>{e!==`ready`||tt.current||(tt.current=!0,r.length>0&&Re(`minimized_orb`))},[e,r]);let[nt,rt]=(0,b.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,b.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>rt(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,b.useEffect)(()=>{j(l||``),l&&M(``)},[l]),(0,b.useEffect)(()=>{Le===`minimized_orb`?parent.postMessage({type:`WIDGET_MINIMIZED`},`*`):Le!==`voice_mode`&&parent.postMessage({type:`WIDGET_OPEN`},`*`)},[Le]);let it=(0,b.useCallback)(()=>{Ye(null),Ze(``)},[]),at=(0,b.useCallback)(e=>{let t=nD(e);if(t){Ye(null),Ze(t);return}Ye(e),Ze(``)},[]);(0,b.useEffect)(()=>{if(!y||v!==`connected`){Ge(0);return}let e=()=>{let e=new Date(y).getTime();isNaN(e)||Ge(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[y,v]),(0,b.useEffect)(()=>{let e=g?.callId||_||null;if(!e){et.current=null;return}(g?.callId||v===`connecting`||v===`connected`)&&(!(!i||Le===`minimized_orb`||Le===`voice_mode`)&&et.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:Le,hasIncomingCall:!!g?.callId,activeCallId:_,callConnectionState:v}),et.current=e,Le===`voice_mode`&&ae?.(!1),re?.(),Re(`text_chat`)))},[_,v,g?.callId,i,re,ae,Le]),(0,b.useEffect)(()=>{if(!o||h){fe?.(``),de?.();return}if(!ze.trim()||Je){fe?.(``),de?.();return}E?.();let e=window.setTimeout(()=>fe?.(ze),120),t=window.setTimeout(()=>de?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[ze,Je,o,h,E,de,fe]);let ot=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,st=async e=>{if(e.preventDefault(),h)return;if(Fe){let e=A.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){M(`Please enter a valid email so we can continue helping you.`);return}await ie(e),M(``);return}let t=ot(Ve);if(!ze.trim()&&!Je)return;if(Je){try{$e(!0),Ze(``);let e=await ne(Je),n=e?.data||e,r=ze.trim()||`Shared file: ${iD(Je)}`;Be(``),He(null),it(),await w(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||Je.name,fileType:n?.fileType||Je.type,fileSize:n?.fileSize||Je.size}})}catch(e){Ze(e?.message||`Failed to upload the selected file.`)}finally{$e(!1)}return}let n=ze.trim();Be(``),He(null),await w(n,``,t)},ct=e=>{let t=Math.floor(e/60);return`${String(t).padStart(2,`0`)}:${String(e%60).padStart(2,`0`)}`},lt=(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]),ut=nt&&(Le===`text_chat`||Le===`entry_prompt`)?{inset:0}:_e===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},dt=()=>Re(`minimized_orb`),ft=()=>Re(`connection_modal`),pt=()=>{re({notifyChatInitiated:!0}),ae?.(!0),Re(`voice_mode`)},mt=(0,b.useRef)(!1);(0,b.useEffect)(()=>{if(!mt.current)try{let e=sessionStorage.getItem(`_fe_voice_nav`);if(!e)return;let t=JSON.parse(e);if(!t?.ts||Date.now()-t.ts>9e3){sessionStorage.removeItem(`_fe_voice_nav`);return}sessionStorage.removeItem(`_fe_voice_nav`),mt.current=!0,pt()}catch{}});let ht=()=>{re({notifyChatInitiated:!0}),ae?.(!1),Re(`text_chat`)},gt=()=>{ae?.(!1),dt()};return e!==`ready`||!Ee?null:(0,P.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...ut},children:[Le===`entry_prompt`&&(0,P.jsx)(NO,{copy:Oe,orbColors:he,primaryColor:ge,onYes:pt,onLater:dt,isMobile:nt}),Le===`minimized_orb`&&(0,P.jsx)(yp.div,{layoutId:`fe-main-orb`,initial:{scale:94/50},animate:{scale:1},transition:{type:`spring`,stiffness:220,damping:26},style:{transformOrigin:`bottom right`,display:`inline-block`},children:(0,P.jsx)(MO,{size:50,orbColors:he,onClick:ft})}),Le===`connection_modal`&&(0,P.jsx)(PO,{copy:Oe,orbColors:he,primaryColor:ge,onVoice:pt,onText:ht,onClose:dt}),Le===`voice_mode`&&(0,P.jsx)(FO,{orbColors:he,onEnterChat:ht,onEndChat:gt,agentId:ke,siteId:Ae,apiBaseUrl:k,historyRef:C,onMessageSync:te},`voice`),Le===`text_chat`&&(0,P.jsx)(RO,{copy:Oe,orbColors:he,primaryColor:ge,chatBgGradient:ye,logo:be,quickChatOptions:we,onQuickChatSelect:lt,isMobile:nt,chatHistory:r,isAiTyping:d,isAgentTyping:u,activeScreen:a,agentName:je,agentHeadshot:Me,fallbackAgentName:ve,input:ze,setInput:Be,onSubmit:st,isConversationEnded:h,isLoading:f,isRateLimited:p,rateLimitMessage:m,selectedFile:Je,onFileSelect:at,onRemoveSelectedFile:it,attachmentError:Xe,isUploadingAttachment:Qe,requiresEmail:Fe,emailInput:A,setEmailInput:j,emailError:Ue,replyContext:Ve,setReplyContext:He,webRTCError:ee,micError:Ke,setMicError:qe,dismissCallError:T,incomingCall:g,rejectCall:ce,acceptCall:se,activeCallId:_,callConnectionState:v,isCallMuted:x,toggleCallMute:ue,endWebRTCCall:le,formatCallDuration:ct,callDurationSeconds:We,onCollapse:dt,onStartVoice:pt,onEndConversation:oe,showPoweredBy:Te}),(0,P.jsx)(`style`,{children:`
614
614
  /* Force any SVG (or img) inside LogoSlot to fill the container height
615
615
  regardless of whether the component forwards its style prop. */
616
616
  .fe-logo-slot svg,
@@ -601,8 +601,8 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
601
601
  <path d="M4 2L19 10.5L11 12.8L8 20L4 2Z"
602
602
  fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
603
603
  filter="url(#${Q}-csh)"/>
604
- </svg>`,jD=null,MD=!1;function ND(){return(!jD||!jD.isConnected)&&(jD=document.createElement(`div`),jD.id=`${Q}-cursor`,jD.innerHTML=AD,document.body.appendChild(jD),MD=!1),jD}async function PD(e){if(typeof document>`u`||!e)return;gD();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=ND();MD||=(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 RD(360)}function FD(e=!1){jD&&(e?(jD.classList.remove(`${Q}-cursor-visible`),MD=!1):(jD.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{MD=!1},250)))}async function ID(e){jD&&(jD.classList.add(`${Q}-cursor-click`),await RD(280),jD.classList.remove(`${Q}-cursor-click`))}function LD(e){if(!e||typeof document>`u`)return;gD();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 RD(e){return new Promise(t=>setTimeout(t,e))}function $(...e){dn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function zD(e){return new Promise(t=>setTimeout(t,e))}var BD=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function VD(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(BD)}catch{return!1}}function HD(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function UD(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(!VD(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function WD(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function GD(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 WD(r.join(` `))}if(e.labels&&e.labels.length)return WD(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return WD(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return WD(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return WD(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=WD(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 WD(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return WD(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?WD(o):null}function KD(){let e=[];return UD(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(VD(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=HD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function qD(){return KD().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:GD(e),placeholder:e.placeholder||null}))}function JD(){let e=[];return UD(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(VD(e)||e.disabled)return!1;try{let t=HD(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 YD(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function XD(e){let t=YD(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function ZD(e,t){let n=XD(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,GD(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>YD(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 QD=28;function $D(e,t){let n=null,r=0;for(let i of e){let e=ZD(i,t);e>r&&(r=e,n=i)}return!n||r<QD?null:n}function eO(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,GD(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 tO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function nO(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 rO(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 iO(e){if(!rO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,GD(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 aO(e,t,n){let r=String(t??``),i=String(n??``),a=cO(e,r)||$D(e,r)||eO(e,r,i);if(!a)return[];let o=new Set([a]);if(tO(i)&&nO(r))for(let t of e)t!==a&&iO(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 oO(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 sO(e){if(!e||typeof e!=`string`)return null;let t=null;return UD(n=>{try{let r=n.getElementById(e);r&&!VD(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function cO(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=sO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=sO(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 lO(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 uO(e,t){let n=[];UD(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(VD(e)||e.disabled)return!1;try{let t=HD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:lO(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=oO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function dO(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 fO(e){let t=dO(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 pO(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 mO(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 hO(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 gO(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 _O(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 vO(){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 yO(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 r=dO(n),i=hO(r),a=r.section_text??r.sectionText??r.section;if($(`flowengage_navigate · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(!await Cn(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`That page is not available in the site index; answer without navigating.`;return $(`flowengage_navigate ✖ blocked`,e),e}if(en)try{bD(`Navigating to ${i}...`,{spinner:!0}),TD(),DE(),$(`flowengage_navigate → proxy FE_DOM_NAVIGATE`,i),await rn(`FE_DOM_NAVIGATE`,{url:i}),await zD(600),a&&typeof a==`string`&&($(`flowengage_navigate · proxy FE_DOM_HIGHLIGHT`,a),await rn(`FE_DOM_HIGHLIGHT`,{sectionText:a}));let e=`OK_NAVIGATION ${i}`;return $(`flowengage_navigate ✓ (iframe proxy)`,e),bD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),bD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{ED(),xD(900)}try{if(bD(`Navigating to ${i}...`,{spinner:!0}),TD(),DE(),NE(),$(`flowengage_navigate → shadowNavigate`,i),await Tn(i),await zD(400),vO(),a&&typeof a==`string`){let e=vn(null,a);e&&vE(()=>ME(e)),$(`flowengage_navigate · highlight`,{sectionText:a,found:!!e})}let e=`OK_NAVIGATION ${i}`;return $(`flowengage_navigate ✓`,e),bD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),bD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{ED(),xD(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=dO(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(en){let e=r||n||null;if(!e)return $(`flowengage_highlight ✖ no text`),`Could not find that section on the page.`;$(`flowengage_highlight → proxy FE_DOM_HIGHLIGHT`,e);let t=await rn(`FE_DOM_HIGHLIGHT`,{sectionText:e});return $(`flowengage_highlight ✓ (iframe proxy)`,t),t||`Highlighted the section.`}let i=vn(n||null,r||null);return i?(ME(i),$(`flowengage_highlight ✓`),`Highlighted the section.`):($(`flowengage_highlight ✖ no element`),`Could not find that section on the page.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=dO(e),n=t?.section_text||t?.sectionText||``;if(en){$(`flowengage_read_content → proxy FE_DOM_READ_CONTENT`,n);let e=await rn(`FE_DOM_READ_CONTENT`,{sectionText:n});return $(`flowengage_read_content ✓ (iframe proxy)`,`${String(e||``).length} chars`),e||`No readable content found on this page.`}try{let e=``;if(n){let t=vn(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(`
605
- `)}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=gO(dO(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:en?on():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=dO(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()=>{if(en){$(`flowengage_list_forms → proxy FE_DOM_LIST_FORMS`);let e=await rn(`FE_DOM_LIST_FORMS`);return $(`flowengage_list_forms ✓ (iframe proxy)`),e}let e=qD(),t=JD();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=>{if(en)try{$(`flowengage_fill_form ▶ (iframe proxy) raw:`,e),DD();let t=fO(e);if(!t.length&&r){let e=r(),n=pO(e);n.length||(n=mO(e)),n.length&&($(`flowengage_fill_form · inferred from utterance:`,n),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 {}.`;bD(`Filling form...`,{spinner:!0});let n=await rn(`FE_DOM_FILL_FORM`,{fields:t});return $(`flowengage_fill_form ✓ (iframe proxy)`,n),bD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),n}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),bD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),DD(),xD(700)}try{$(`flowengage_fill_form ▶ raw:`,e),DD();let t=fO(e);if(!t.length&&r){let e=r(),n=pO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=mO(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;bD(`Filling ${String(t)}...`,{spinner:!0});let a=KD(),o=aO(a,String(t),r);if(o.length){for(let[e,t]of o.entries())OD(t),await PD(t),_O(t,r,{skipScroll:e>0}),kD(t),await zD(120);i=o,n.push(String(t));continue}let s=cO(a,String(t));s||=$D(a,String(t)),s||=eO(a,String(t),r),s&&(OD(s),await PD(s),_O(s,r),kD(s),await zD(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),bD(`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),bD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),DD(),xD(700)}},flowengage_click_button:async e=>{let t=dO(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.`;if(en){bD(`Clicking ${n}...`,{spinner:!0});try{let e=await rn(`FE_DOM_CLICK_BUTTON`,{text:n});return $(`flowengage_click_button ✓ (iframe proxy)`,e),bD(`Clicked`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),bD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),xD(700)}}let r=uO(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{bD(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await PD(r),r.focus?.(),await ID(r),LD(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),bD(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),bD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),xD(700)}}};return{...a,navigateToPage:a.flowengage_navigate,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 bO(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=dn();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 xO={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function SO(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 CO(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 wO({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 TO({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 EO(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 DO({orbColors:e,...t}){return(0,f.jsx)(hD,{colors:e,...t})}function OO({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a}){let o=n||xO.green,s=CO(o),c=a?72:94,l=(0,f.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:a?`14px`:`18px`},children:[(0,f.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,f.jsx)(Sp.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:a?`16px`:`18px`,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)(Sp.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`8px`,flexWrap:`nowrap`},children:[(0,f.jsx)(`button`,{onClick:r,style:{padding:a?`9px 20px`:`10px 28px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:a?`14px`:`15px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${o}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:{padding:a?`9px 16px`:`10px 22px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:600,fontSize:a?`14px`:`15px`,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)(Sp.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)(DO,{size:c,orbColors:t})})]});return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Sp.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.4},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`},children:l}):l]})}function kO({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a}){let o=n||xO.green,s=CO(o);return(0,f.jsxs)(Sp.div,{initial:{scale:50/300,borderRadius:`50%`},animate:{scale:1,borderRadius:`24px`},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:`bottom right`,background:`white`,padding:`28px 28px 24px`,width:`300px`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`20px`,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)(DO,{size:82,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,fontSize:`17px`,fontWeight:600,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,width:`100%`},children:[(0,f.jsx)(`button`,{onClick:r,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:`15px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${o}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:{flex:1,padding:`12px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:600,fontSize:`15px`,border:`2px 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 AO({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.useRef)(null),_=(0,d.useRef)(``),v=(0,d.useRef)(async()=>{}),y=(0,d.useRef)(!1),b=(0,d.useRef)(!1),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),ee=(0,d.useRef)(`minimized`),te=(0,d.useRef)(null),ne=(0,d.useRef)(null),re=(0,d.useRef)(!1),ie=(0,d.useCallback)((e=`minimized`)=>{ee.current=e,S.current=!0,queueMicrotask(()=>{y.current||(y.current=!0,v.current?.())})},[o]),ae=(0,d.useCallback)(async e=>{S.current=!0;try{await g.current?.endSession?.()}catch{}g.current=null,l(`idle`),p(!1),y.current=!1,re.current=!1;try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return v.current=()=>ae(ee.current===`chat`?t:n),(0,d.useEffect)(()=>{b.current=u},[u]),(0,d.useEffect)(()=>{let e=!1,n=null,s=async()=>{if(ne.current=s,!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,x.current=!1,S.current=!1,ee.current=`minimized`,TE(!0),DE();let t=bO(yO({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{ie()}})),s=await dE.startSession({agentId:r,clientTools:t,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||(l(t===`speaking`?`speaking`:`listening`),parent.postMessage({type:`AGENT_MODE`,mode:t},`*`),t===`speaking`?bE():xE())},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;r&&(n===`user`&&(_.current=r,DE(),NE()),n===`bot`&&(FE(r,!0),SE(r.trim().split(/\s+/).length)),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],EO(n,r)&&ie(`minimized`))},onError:t=>{if(!e&&!S.current&&!x.current)if(x.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t}),!re.current)re.current=!0,g.current=null,setTimeout(async()=>{if(!e){x.current=!1,y.current=!1;try{await ne.current?.()}catch{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`),l(`error`),ie(`chat`)}}},1500);else{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`);try{g.current?.setMicMuted?.(!0)}catch{}p(!0),l(`error`),ie(`chat`)}},onDisconnect:()=>{if(!e&&!S.current&&!x.current){x.current=!0,console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:o.current?.length||0,lastUserText:_.current||``,wasMuted:b.current});try{g.current?.setMicMuted?.(!0)}catch{}p(!0),DE(),NE(),TE(!1),ie(`chat`)}}});if(e){s.endSession().catch(()=>{});return}n=s,g.current=s,l(`listening`),re.current=!1;try{sessionStorage.setItem(`el_conv_${i}`,s.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.flowengage_list_forms()}catch{}s.sendContextualUpdate(`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`),ee.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}};return s(),()=>{e=!0,S.current=!0,(n||g.current)?.endSession?.().catch(()=>{})}},[r,i,a,ie]),(0,d.useEffect)(()=>{if(!m)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;te.current&&!te.current.contains(t)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[m]),(0,f.jsx)(f.Fragment,{children:(0,f.jsxs)(`div`,{style:{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)(DO,{size:94,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(g.current)try{u?(await g.current.setMicMuted?.(!1),p(!1)):(await g.current.setMicMuted?.(!0),p(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`44px`,height:`44px`,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)`},children:u?(0,f.jsxs)(`svg`,{width:`18`,height:`18`,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.jsxs)(`svg`,{width:`18`,height:`18`,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`,fill:`currentColor`,stroke:`none`}),(0,f.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]})}),(0,f.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:te,children:[(0,f.jsx)(`button`,{onClick:()=>h(e=>!e),style:{width:`44px`,height:`44px`,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)`},children:(0,f.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.8`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.8`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.8`})]})}),m&&(0,f.jsxs)(`div`,{style:{position:`absolute`,bottom:`54px`,right:0,zIndex:9999,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`,{onClick:()=>{h(!1),ee.current=`chat`,ae(t)},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:`M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z`})}),`Enter Chat Mode`]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ee.current=`minimized`,ae(n)},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)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,f.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`End Conversation`]})]})]})]})]})})}function jO({orbColors:e}){return(0,f.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(DO,{size:36,orbColors:e})})}var MO=()=>(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 NO({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,incomingCall:ge,rejectCall:_e,acceptCall:ve,activeCallId:ye,callConnectionState:C,isCallMuted:be,toggleCallMute:xe,endWebRTCCall:Se,formatCallDuration:Ce,callDurationSeconds:we,onCollapse:Te,onStartVoice:Ee,showPoweredBy:De}){let Oe=c.length>0,ke=x||S||b,Ae=!!(ge||ye),[je,Me]=(0,d.useState)(!1),Ne=(0,d.useRef)(null);return(0,d.useEffect)(()=>{if(!je)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ne.current&&!Ne.current.contains(t)&&Me(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[je]),(0,f.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,inset:0,width:`100%`,height:`100dvh`,background:r,borderRadius:0,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(390px, 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:`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 18px 14px`,background:`transparent`,flexShrink:0},children:[(0,f.jsx)(`button`,{onClick:Te,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)(wO,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,f.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,f.jsx)(TO,{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:Ne,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>Me(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`})]})}),je&&(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:()=>{Me(!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 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:()=>{Me(!1),Te?.()},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)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,f.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`Close Conversation`]})]})]})]}),(0,f.jsx)(oD,{webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,incomingCall:ge,rejectCall:_e,acceptCall:ve,activeCallId:ye,callConnectionState:C,formatCallDuration:Ce,callDurationSeconds:we,endWebRTCCall:Se,isCallMuted:be,toggleCallMute:xe,isAIVoiceActive:!1,currentCallAgentName:m||g,isRateLimited:S,rateLimitMessage:ee}),(0,f.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`},children:Oe?(0,f.jsx)(nD,{chatHistory:c,isAiTyping:l,isAgentTyping:u,setReplyContext:de,TypingDots:MO,primaryColor:n,agentHeadshot:h,agentDisplayName:m||g,botAvatarNode:(0,f.jsx)(jO,{orbColors:t})}):(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)(DO,{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)(rD,{input:_,setInput:v,onSubmit:y,isConversationEnded:b,callUiActive:Ae,handleToggleVoice:Ee,showVoiceToggle:p===`agent`,activeScreen:p,inputDisabled:ke,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:De&&(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 PO(){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:ie,uploadChatFile:ae,openWidget:oe,captureVisitorEmail:se,setVoiceMode:ce,endConversation:le,acceptCall:ue,rejectCall:de,endWebRTCCall:fe,toggleCallMute:pe,dismissCallError:me,startTyping:he,stopTyping:ge,updateTypingDraft:_e}=un();(0,d.useEffect)(()=>{try{gn()}catch{}},[]);let ve=t?.widgetSettings||{},ye=n?.widgetSettings||{},C={...ve.branding||{},...ye.branding||{}},be={...ve.theme||{},...ye.theme||{}},xe=Array.isArray(be.orbColors)&&be.orbColors.length>0?be.orbColors:null,Se=xe?.[0]||be.primaryColor||`#3B82F6`,Ce=be.position||`bottom-right`,we=C.fallbackAgentName||`Agent`,Te=SO(xe??be.chatBgColors),Ee=C.logo||C.logoUrl||null,De=te||`en`,Oe=ve.recommendations?.[De]||[],ke=(ye.recommendations?.[De]??Oe).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Ae=Array.isArray(C.quickChatOptions)&&C.quickChatOptions.length>0?C.quickChatOptions:ke,je=C.hideWatermark===!0?!1:C.showPoweredBy!==!1,Me=C.chatbotEnabled!==!1&&be.chatbotEnabled!==!1,Ne=ve.greetings?.[te]||ye.greetings?.[te]||C.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Pe={entryPrompt:C.entryPrompt||`Do you want to explore in a new way?`,yesLabel:C.yesLabel||`Yes`,laterLabel:C.laterLabel||`Later`,connectionTitle:C.connectionTitle||`How would you like to connect?`,voiceLabel:C.voiceLabel||`Voice`,textLabel:C.textLabel||`Text`,chatTitle:C.headerName||`Chat with FlowEngage`,introGreeting:Ne,inputPlaceholder:C.inputPlaceholder||`Type your message`,analysingLabel:C.analysingLabel||`analysing...`},Fe=ye.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ie=t?.siteId||n?.siteId||null,w=t?.apiBaseUrl||``,Le=(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]),Re=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,T=r.some(e=>e.sender===`user`),ze=(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]),Be=!l&&T&&ze,Ve=!!(ye._dashboardLivePreview||ve._dashboardLivePreview),[He,Ue]=(0,d.useState)(()=>Ve?`text_chat`:`entry_prompt`),[We,Ge]=(0,d.useState)(``),[Ke,qe]=(0,d.useState)(null),[E,D]=(0,d.useState)(l||``),[Je,Ye]=(0,d.useState)(``),[Xe,Ze]=(0,d.useState)(0),[Qe,$e]=(0,d.useState)(null),[O,et]=(0,d.useState)(null),[tt,nt]=(0,d.useState)(``),[rt,it]=(0,d.useState)(!1),at=(0,d.useRef)(null),ot=(0,d.useRef)(!1);(0,d.useLayoutEffect)(()=>{e!==`ready`||ot.current||(ot.current=!0,r.length>0&&Ue(`minimized_orb`))},[e,r]);let[st,ct]=(0,d.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,d.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>ct(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,d.useEffect)(()=>{D(l||``),l&&Ye(``)},[l]),(0,d.useEffect)(()=>{He===`minimized_orb`?parent.postMessage({type:`WIDGET_MINIMIZED`},`*`):He!==`voice_mode`&&parent.postMessage({type:`WIDGET_OPEN`},`*`)},[He]);let lt=(0,d.useCallback)(()=>{et(null),nt(``)},[]),ut=(0,d.useCallback)(e=>{let t=ZE(e);if(t){et(null),nt(t);return}et(e),nt(``)},[]);(0,d.useEffect)(()=>{if(!x||b!==`connected`){Ze(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||Ze(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]),(0,d.useEffect)(()=>{let e=v?.callId||y||null;if(!e){at.current=null;return}(v?.callId||b===`connecting`||b===`connected`)&&(!(!i||He===`minimized_orb`||He===`voice_mode`)&&at.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:He,hasIncomingCall:!!v?.callId,activeCallId:y,callConnectionState:b}),at.current=e,He===`voice_mode`&&ce?.(!1),oe?.(),Ue(`text_chat`)))},[y,b,v?.callId,i,oe,ce,He]),(0,d.useEffect)(()=>{if(!o||_){_e?.(``),ge?.();return}if(!We.trim()||O){_e?.(``),ge?.();return}he?.();let e=window.setTimeout(()=>_e?.(We),120),t=window.setTimeout(()=>ge?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[We,O,o,_,he,ge,_e]);let dt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,ft=async e=>{if(e.preventDefault(),_)return;if(Be){let e=E.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){Ye(`Please enter a valid email so we can continue helping you.`);return}await se(e),Ye(``);return}let t=dt(Ke);if(!We.trim()&&!O)return;if(O){try{it(!0),nt(``);let e=await ae(O),n=e?.data||e,r=We.trim()||`Shared file: ${$E(O)}`;Ge(``),qe(null),lt(),await ie(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||O.name,fileType:n?.fileType||O.type,fileSize:n?.fileSize||O.size}})}catch(e){nt(e?.message||`Failed to upload the selected file.`)}finally{it(!1)}return}let n=We.trim();Ge(``),qe(null),await ie(n,``,t)},pt=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 ie(t.trim(),``)},[_,m,ie]),ht=st&&(He===`text_chat`||He===`entry_prompt`)?{inset:0}:Ce===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},gt=()=>Ue(`minimized_orb`),_t=()=>Ue(`connection_modal`),vt=()=>{oe({notifyChatInitiated:!0}),ce?.(!0),Ue(`voice_mode`)},yt=()=>{oe({notifyChatInitiated:!0}),ce?.(!1),Ue(`text_chat`)},bt=()=>{ce?.(!1),gt()};return e!==`ready`||!Me?null:(0,f.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...ht},children:[He===`entry_prompt`&&(0,f.jsx)(OO,{copy:Pe,orbColors:xe,primaryColor:Se,onYes:vt,onLater:gt,isMobile:st}),He===`minimized_orb`&&(0,f.jsx)(Sp.div,{layoutId:`fe-main-orb`,initial:{scale:94/50},animate:{scale:1},transition:{type:`spring`,stiffness:220,damping:26},style:{transformOrigin:`bottom right`,display:`inline-block`},children:(0,f.jsx)(DO,{size:50,orbColors:xe,onClick:_t})}),He===`connection_modal`&&(0,f.jsx)(kO,{copy:Pe,orbColors:xe,primaryColor:Se,onVoice:vt,onText:yt,onClose:gt}),He===`voice_mode`&&(0,f.jsx)(AO,{orbColors:xe,onEnterChat:yt,onEndChat:bt,agentId:Fe,siteId:Ie,apiBaseUrl:w,historyRef:ne,onMessageSync:re},`voice`),He===`text_chat`&&(0,f.jsx)(NO,{copy:Pe,orbColors:xe,primaryColor:Se,chatBgGradient:Te,logo:Ee,quickChatOptions:Ae,onQuickChatSelect:mt,isMobile:st,chatHistory:r,isAiTyping:p,isAgentTyping:u,activeScreen:a,agentName:Le,agentHeadshot:Re,fallbackAgentName:we,input:We,setInput:Ge,onSubmit:ft,isConversationEnded:_,isLoading:m,isRateLimited:h,rateLimitMessage:g,selectedFile:O,onFileSelect:ut,onRemoveSelectedFile:lt,attachmentError:tt,isUploadingAttachment:rt,requiresEmail:Be,emailInput:E,setEmailInput:D,emailError:Je,replyContext:Ke,setReplyContext:qe,webRTCError:ee,micError:Qe,setMicError:$e,dismissCallError:me,incomingCall:v,rejectCall:de,acceptCall:ue,activeCallId:y,callConnectionState:b,isCallMuted:S,toggleCallMute:pe,endWebRTCCall:fe,formatCallDuration:pt,callDurationSeconds:Xe,onCollapse:gt,onStartVoice:vt,onEndConversation:le,showPoweredBy:je}),(0,f.jsx)(`style`,{children:`
604
+ </svg>`,jD=null,MD=!1;function ND(){return(!jD||!jD.isConnected)&&(jD=document.createElement(`div`),jD.id=`${Q}-cursor`,jD.innerHTML=AD,document.body.appendChild(jD),MD=!1),jD}async function PD(e){if(typeof document>`u`||!e)return;gD();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=ND();MD||=(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 RD(360)}function FD(e=!1){jD&&(e?(jD.classList.remove(`${Q}-cursor-visible`),MD=!1):(jD.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{MD=!1},250)))}async function ID(e){jD&&(jD.classList.add(`${Q}-cursor-click`),await RD(280),jD.classList.remove(`${Q}-cursor-click`))}function LD(e){if(!e||typeof document>`u`)return;gD();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 RD(e){return new Promise(t=>setTimeout(t,e))}function $(...e){dn()&&console.log(`[FlowEngage:voice-tools]`,...e)}function zD(e){return new Promise(t=>setTimeout(t,e))}var BD=`#flowengage-root, .flowengage-shell, .flowengage-widget-root`;function VD(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(BD)}catch{return!1}}function HD(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function UD(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(!VD(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function WD(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function GD(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 WD(r.join(` `))}if(e.labels&&e.labels.length)return WD(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return WD(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return WD(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return WD(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=WD(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 WD(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return WD(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?WD(o):null}function KD(){let e=[];return UD(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(VD(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=HD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function qD(){return KD().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:GD(e),placeholder:e.placeholder||null}))}function JD(){let e=[];return UD(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(VD(e)||e.disabled)return!1;try{let t=HD(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 YD(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function XD(e){let t=YD(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function ZD(e,t){let n=XD(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,GD(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>YD(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 QD=28;function $D(e,t){let n=null,r=0;for(let i of e){let e=ZD(i,t);e>r&&(r=e,n=i)}return!n||r<QD?null:n}function eO(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,GD(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 tO(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function nO(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 rO(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 iO(e){if(!rO(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,GD(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 aO(e,t,n){let r=String(t??``),i=String(n??``),a=cO(e,r)||$D(e,r)||eO(e,r,i);if(!a)return[];let o=new Set([a]);if(tO(i)&&nO(r))for(let t of e)t!==a&&iO(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 oO(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 sO(e){if(!e||typeof e!=`string`)return null;let t=null;return UD(n=>{try{let r=n.getElementById(e);r&&!VD(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function cO(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=sO(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=sO(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 lO(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 uO(e,t){let n=[];UD(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(VD(e)||e.disabled)return!1;try{let t=HD(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:lO(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=oO(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function dO(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 fO(e){let t=dO(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 pO(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 mO(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 hO(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 gO(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 _O(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 vO(){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 yO(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=typeof e.getHistory==`function`?e.getHistory:null,a=[],o={flowengage_navigate:async n=>{$(`flowengage_navigate ▶ raw parameters:`,n);let r=dO(n),a=hO(r),o=r.section_text??r.sectionText??r.section;if($(`flowengage_navigate · coerced:`,{url:a,sectionText:o}),!a){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`flowengage_navigate ✖`,e),e}if(!await Cn(a,{siteId:t,apiBaseUrl:e.apiBaseUrl})){let e=`That page is not available in the site index; answer without navigating.`;return $(`flowengage_navigate ✖ blocked`,e),e}if(en)try{bD(`Navigating to ${a}...`,{spinner:!0}),TD(),DE();try{sessionStorage.setItem(`_fe_voice_nav`,JSON.stringify({ts:Date.now(),to:a}));let e=i?.()||[];e.length>0&&sessionStorage.setItem(`_fe_voice_transcript`,JSON.stringify(e.slice(-30)))}catch{}$(`flowengage_navigate → proxy FE_DOM_NAVIGATE`,a),await rn(`FE_DOM_NAVIGATE`,{url:a}),await zD(600),o&&typeof o==`string`&&($(`flowengage_navigate · proxy FE_DOM_HIGHLIGHT`,o),await rn(`FE_DOM_HIGHLIGHT`,{sectionText:o}));let e=`OK_NAVIGATION ${a}`;return $(`flowengage_navigate ✓ (iframe proxy)`,e),bD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),bD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{ED(),xD(900)}try{if(bD(`Navigating to ${a}...`,{spinner:!0}),TD(),DE(),NE(),$(`flowengage_navigate → shadowNavigate`,a),await Tn(a),await zD(400),vO(),o&&typeof o==`string`){let e=vn(null,o);e&&vE(()=>ME(e)),$(`flowengage_navigate · highlight`,{sectionText:o,found:!!e})}let e=`OK_NAVIGATION ${a}`;return $(`flowengage_navigate ✓`,e),bD(`Navigation complete`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return $(`flowengage_navigate ✖`,t),bD(`Navigation failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{ED(),xD(900)}},flowengage_highlight:async e=>{$(`flowengage_highlight ▶`,e);let t=dO(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText;if(en){let e=r||n||null;if(!e)return $(`flowengage_highlight ✖ no text`),`Could not find that section on the page.`;$(`flowengage_highlight → proxy FE_DOM_HIGHLIGHT`,e);let t=await rn(`FE_DOM_HIGHLIGHT`,{sectionText:e});return $(`flowengage_highlight ✓ (iframe proxy)`,t),t||`Highlighted the section.`}let i=vn(n||null,r||null);return i?(ME(i),$(`flowengage_highlight ✓`),`Highlighted the section.`):($(`flowengage_highlight ✖ no element`),`Could not find that section on the page.`)},flowengage_read_content:async e=>{$(`flowengage_read_content ▶`,e);let t=dO(e),n=t?.section_text||t?.sectionText||``;if(en){$(`flowengage_read_content → proxy FE_DOM_READ_CONTENT`,n);let e=await rn(`FE_DOM_READ_CONTENT`,{sectionText:n});return $(`flowengage_read_content ✓ (iframe proxy)`,`${String(e||``).length} chars`),e||`No readable content found on this page.`}try{let e=``;if(n){let t=vn(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(`
605
+ `)}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=gO(dO(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:en?on():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=dO(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()=>{if(en){$(`flowengage_list_forms → proxy FE_DOM_LIST_FORMS`);let e=await rn(`FE_DOM_LIST_FORMS`);return $(`flowengage_list_forms ✓ (iframe proxy)`),e}let e=qD(),t=JD();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=>{if(en)try{$(`flowengage_fill_form ▶ (iframe proxy) raw:`,e),DD();let t=fO(e);if(!t.length&&r){let e=r(),n=pO(e);n.length||(n=mO(e)),n.length&&($(`flowengage_fill_form · inferred from utterance:`,n),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 {}.`;bD(`Filling form...`,{spinner:!0});let n=await rn(`FE_DOM_FILL_FORM`,{fields:t});return $(`flowengage_fill_form ✓ (iframe proxy)`,n),bD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),n}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),bD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),DD(),xD(700)}try{$(`flowengage_fill_form ▶ raw:`,e),DD();let t=fO(e);if(!t.length&&r){let e=r(),n=pO(e);n.length?$(`flowengage_fill_form · inferred URL from last user utterance (model omitted usable fields):`,n):(n=mO(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;bD(`Filling ${String(t)}...`,{spinner:!0});let i=KD(),o=aO(i,String(t),r);if(o.length){for(let[e,t]of o.entries())OD(t),await PD(t),_O(t,r,{skipScroll:e>0}),kD(t),await zD(120);a=o,n.push(String(t));continue}let s=cO(i,String(t));s||=$D(i,String(t)),s||=eO(i,String(t),r),s&&(OD(s),await PD(s),_O(s,r),kD(s),await zD(120),a=[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 i=`OK_FILLED: ${n.join(`, `)}`;return $(`flowengage_fill_form ✓`,i),bD(`Form filled`,{spinner:!1,icon:`✅`,duration:1100}),i}catch(e){let t=`flowengage_fill_form error: ${e?.message||String(e)}`;return $(`flowengage_fill_form ✖`,t),bD(`Failed to fill form`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),DD(),xD(700)}},flowengage_click_button:async e=>{let t=dO(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.`;if(en){bD(`Clicking ${n}...`,{spinner:!0});try{let e=await rn(`FE_DOM_CLICK_BUTTON`,{text:n});return $(`flowengage_click_button ✓ (iframe proxy)`,e),bD(`Clicked`,{spinner:!1,icon:`✅`,duration:1200}),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),bD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),xD(700)}}let r=uO(n,a);if(!r)return $(`flowengage_click_button ✖ no match`),`Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;try{bD(`Clicking ${n}...`,{spinner:!0});try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}await PD(r),r.focus?.(),await ID(r),LD(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),bD(`Clicked ${e}`,{spinner:!1,icon:`✅`,duration:1200}),t}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`flowengage_click_button ✖`,t),bD(`Click failed`,{spinner:!1,icon:`⚠️`,duration:1800}),t}finally{FD(),xD(700)}}};return{...o,navigateToPage:o.flowengage_navigate,highlightOnPage:o.flowengage_highlight,searchSiteContent:o.flowengage_search,getPageContent:o.flowengage_page_content,endVoiceSession:o.flowengage_end_session,listPageForms:o.flowengage_list_forms,fillFormFields:o.flowengage_fill_form,clickPageButton:o.flowengage_click_button}}function bO(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=dn();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 xO={blue:`#135bd8`,red:`#ef334b`,yellow:`#ffbd2e`,dark:`#0d1b2a`,highlight:`rgba(255,255,255,0.9)`,green:`#10b981`};function SO(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 CO(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 wO({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 TO({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 EO(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 DO({orbColors:e,...t}){return(0,f.jsx)(hD,{colors:e,...t})}function OO({copy:e,orbColors:t,primaryColor:n,onYes:r,onLater:i,isMobile:a}){let o=n||xO.green,s=CO(o),c=a?72:94,l=(0,f.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:a?`14px`:`18px`},children:[(0,f.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,f.jsx)(Sp.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:a?`16px`:`18px`,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)(Sp.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{type:`spring`,stiffness:260,damping:24,delay:.54},style:{display:`flex`,gap:`8px`,flexWrap:`nowrap`},children:[(0,f.jsx)(`button`,{onClick:r,style:{padding:a?`9px 20px`:`10px 28px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:a?`14px`:`15px`,border:`none`,cursor:`pointer`,whiteSpace:`nowrap`,boxShadow:`0 4px 16px ${o}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:{padding:a?`9px 16px`:`10px 22px`,borderRadius:`999px`,background:`transparent`,color:`white`,fontWeight:600,fontSize:a?`14px`:`15px`,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)(Sp.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)(DO,{size:c,orbColors:t})})]});return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Sp.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.4},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`},children:l}):l]})}function kO({copy:e,orbColors:t,primaryColor:n,onVoice:r,onText:i,onClose:a}){let o=n||xO.green,s=CO(o);return(0,f.jsxs)(Sp.div,{initial:{scale:50/300,borderRadius:`50%`},animate:{scale:1,borderRadius:`24px`},transition:{type:`spring`,stiffness:260,damping:26},style:{transformOrigin:`bottom right`,background:`white`,padding:`28px 28px 24px`,width:`300px`,display:`flex`,flexDirection:`column`,alignItems:`center`,gap:`20px`,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)(DO,{size:82,orbColors:t}),(0,f.jsx)(`p`,{style:{margin:0,fontSize:`17px`,fontWeight:600,color:`#111827`,textAlign:`center`,lineHeight:1.4},children:e.connectionTitle}),(0,f.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,width:`100%`},children:[(0,f.jsx)(`button`,{onClick:r,style:{flex:1,padding:`12px`,borderRadius:`999px`,background:o,color:s,fontWeight:700,fontSize:`15px`,border:`none`,cursor:`pointer`,transition:`transform 0.15s ease`,boxShadow:`0 4px 12px ${o}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:{flex:1,padding:`12px`,borderRadius:`999px`,background:`transparent`,color:`#111827`,fontWeight:600,fontSize:`15px`,border:`2px 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 AO({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.useRef)(null),_=(0,d.useRef)(``),v=(0,d.useRef)(async()=>{}),y=(0,d.useRef)(!1),b=(0,d.useRef)(!1),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),ee=(0,d.useRef)(`minimized`),te=(0,d.useRef)(null),ne=(0,d.useRef)(null),re=(0,d.useRef)(!1),ie=(0,d.useCallback)((e=`minimized`)=>{ee.current=e,S.current=!0,queueMicrotask(()=>{y.current||(y.current=!0,v.current?.())})},[o]),ae=(0,d.useCallback)(async e=>{S.current=!0;try{await g.current?.endSession?.()}catch{}g.current=null,l(`idle`),p(!1),y.current=!1,re.current=!1;try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}typeof s==`function`&&await s(o.current),e?.()},[o,s,i]);return v.current=()=>ae(ee.current===`chat`?t:n),(0,d.useEffect)(()=>{b.current=u},[u]),(0,d.useEffect)(()=>{let e=!1,n=null,s=async()=>{if(ne.current=s,!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,x.current=!1,S.current=!1,ee.current=`minimized`,TE(!0),DE();let t=bO(yO({siteId:i||null,apiBaseUrl:a||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{ie()}})),s=await dE.startSession({agentId:r,clientTools:t,onUnhandledClientToolCall:e=>console.error(`[FlowEngage] Unhandled tool:`,e?.tool_name),onModeChange:({mode:t})=>{e||(l(t===`speaking`?`speaking`:`listening`),parent.postMessage({type:`AGENT_MODE`,mode:t},`*`),t===`speaking`?bE():xE())},onMessage:t=>{if(e)return;let n=t.role===`user`?`user`:`bot`,r=t.message||t.text||t.content||``;r&&(n===`user`&&(_.current=r,DE(),NE()),n===`bot`&&(FE(r,!0),SE(r.trim().split(/\s+/).length)),o.current=[...o.current,{sender:n,message:r,timestamp:new Date().toISOString()}],EO(n,r)&&ie(`minimized`))},onError:t=>{if(!e&&!S.current&&!x.current)if(x.current=!0,console.error(`[FlowEngageVoiceCall] session:error`,{message:t?.message,name:t?.name,raw:t}),!re.current)re.current=!0,g.current=null,setTimeout(async()=>{if(!e){x.current=!1,y.current=!1;try{await ne.current?.()}catch{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`),l(`error`),ie(`chat`)}}},1500);else{try{sessionStorage.removeItem(`el_conv_${i}`)}catch{}parent.postMessage({type:`AGENT_ERROR`},`*`);try{g.current?.setMicMuted?.(!0)}catch{}p(!0),l(`error`),ie(`chat`)}},onDisconnect:()=>{if(!e&&!S.current&&!x.current){x.current=!0,console.warn(`[FlowEngageVoiceCall] session:disconnected`,{historyCount:o.current?.length||0,lastUserText:_.current||``,wasMuted:b.current});try{g.current?.setMicMuted?.(!0)}catch{}p(!0),DE(),NE(),TE(!1),ie(`chat`)}}});if(e){s.endSession().catch(()=>{});return}n=s,g.current=s,l(`listening`),re.current=!1;try{sessionStorage.setItem(`el_conv_${i}`,s.getId())}catch{}parent.postMessage({type:`AGENT_EXPAND`},`*`);try{let e=typeof window<`u`?window.location.href:``,n=`[]`;try{n=await t.flowengage_list_forms()}catch{}s.sendContextualUpdate(`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`),ee.current=`chat`,window.setTimeout(()=>{e||t?.()},0))}};return s(),()=>{e=!0,S.current=!0,(n||g.current)?.endSession?.().catch(()=>{})}},[r,i,a,ie]),(0,d.useEffect)(()=>{if(!m)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;te.current&&!te.current.contains(t)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[m]),(0,f.jsx)(f.Fragment,{children:(0,f.jsxs)(`div`,{style:{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)(DO,{size:94,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(g.current)try{u?(await g.current.setMicMuted?.(!1),p(!1)):(await g.current.setMicMuted?.(!0),p(!0))}catch{}},title:u?`Unmute`:`Mute`,style:{width:`44px`,height:`44px`,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)`},children:u?(0,f.jsxs)(`svg`,{width:`18`,height:`18`,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.jsxs)(`svg`,{width:`18`,height:`18`,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`,fill:`currentColor`,stroke:`none`}),(0,f.jsx)(`path`,{d:`M19 10a7 7 0 01-14 0M12 19v4M8 23h8`})]})}),(0,f.jsxs)(`div`,{style:{position:`relative`,isolation:`isolate`,zIndex:10},ref:te,children:[(0,f.jsx)(`button`,{onClick:()=>h(e=>!e),style:{width:`44px`,height:`44px`,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)`},children:(0,f.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1.8`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1.8`}),(0,f.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1.8`})]})}),m&&(0,f.jsxs)(`div`,{style:{position:`absolute`,bottom:`54px`,right:0,zIndex:9999,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`,{onClick:()=>{h(!1),ee.current=`chat`,ae(t)},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:`M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z`})}),`Enter Chat Mode`]}),(0,f.jsx)(`div`,{style:{height:`1px`,background:`rgba(255,255,255,0.07)`,margin:`0 14px`}}),(0,f.jsxs)(`button`,{onClick:()=>{h(!1),ee.current=`minimized`,ae(n)},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)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,f.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`End Conversation`]})]})]})]})]})})}function jO({orbColors:e}){return(0,f.jsx)(`div`,{style:{flexShrink:0,width:`36px`,height:`36px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(DO,{size:36,orbColors:e})})}var MO=()=>(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 NO({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,incomingCall:ge,rejectCall:_e,acceptCall:ve,activeCallId:ye,callConnectionState:C,isCallMuted:be,toggleCallMute:xe,endWebRTCCall:Se,formatCallDuration:Ce,callDurationSeconds:we,onCollapse:Te,onStartVoice:Ee,showPoweredBy:De}){let Oe=c.length>0,ke=x||S||b,Ae=!!(ge||ye),[je,Me]=(0,d.useState)(!1),Ne=(0,d.useRef)(null);return(0,d.useEffect)(()=>{if(!je)return;let e=e=>{let t=e.composedPath?.()?.[0]||e.target;Ne.current&&!Ne.current.contains(t)&&Me(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[je]),(0,f.jsxs)(`div`,{style:s?{"--flowengage-primary":n,"--flowengage-accent":n,position:`fixed`,inset:0,width:`100%`,height:`100dvh`,background:r,borderRadius:0,display:`flex`,flexDirection:`column`,overflow:`hidden`,animation:`fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)`}:{"--flowengage-primary":n,"--flowengage-accent":n,width:`min(390px, 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:`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 18px 14px`,background:`transparent`,flexShrink:0},children:[(0,f.jsx)(`button`,{onClick:Te,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)(wO,{logo:i,style:{height:`34px`,width:`100%`,maxWidth:`96px`}}):(0,f.jsx)(`div`,{style:{width:`40px`,height:`40px`,flexShrink:0},children:(0,f.jsx)(TO,{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:Ne,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>Me(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`})]})}),je&&(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:()=>{Me(!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 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:()=>{Me(!1),Te?.()},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)(`path`,{d:`M10.68 13.31a16 16 0 003.41 2.6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7 2 2 0 011.72 2v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.42 19.42 0 013.07 8.62 19.79 19.79 0 01.1 2 2 2 0 012.11 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.18 7.84`}),(0,f.jsx)(`line`,{x1:`23`,y1:`1`,x2:`1`,y2:`23`})]}),`Close Conversation`]})]})]})]}),(0,f.jsx)(oD,{webRTCError:fe,micError:pe,setMicError:me,dismissCallError:he,incomingCall:ge,rejectCall:_e,acceptCall:ve,activeCallId:ye,callConnectionState:C,formatCallDuration:Ce,callDurationSeconds:we,endWebRTCCall:Se,isCallMuted:be,toggleCallMute:xe,isAIVoiceActive:!1,currentCallAgentName:m||g,isRateLimited:S,rateLimitMessage:ee}),(0,f.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,background:`transparent`},children:Oe?(0,f.jsx)(nD,{chatHistory:c,isAiTyping:l,isAgentTyping:u,setReplyContext:de,TypingDots:MO,primaryColor:n,agentHeadshot:h,agentDisplayName:m||g,botAvatarNode:(0,f.jsx)(jO,{orbColors:t})}):(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)(DO,{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)(rD,{input:_,setInput:v,onSubmit:y,isConversationEnded:b,callUiActive:Ae,handleToggleVoice:Ee,showVoiceToggle:p===`agent`,activeScreen:p,inputDisabled:ke,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:De&&(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 PO(){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:ie,uploadChatFile:ae,openWidget:oe,captureVisitorEmail:se,setVoiceMode:ce,endConversation:le,acceptCall:ue,rejectCall:de,endWebRTCCall:fe,toggleCallMute:pe,dismissCallError:me,startTyping:he,stopTyping:ge,updateTypingDraft:_e}=un();(0,d.useEffect)(()=>{try{gn()}catch{}},[]);let ve=t?.widgetSettings||{},ye=n?.widgetSettings||{},C={...ve.branding||{},...ye.branding||{}},be={...ve.theme||{},...ye.theme||{}},xe=Array.isArray(be.orbColors)&&be.orbColors.length>0?be.orbColors:null,Se=xe?.[0]||be.primaryColor||`#3B82F6`,Ce=be.position||`bottom-right`,we=C.fallbackAgentName||`Agent`,Te=SO(xe??be.chatBgColors),Ee=C.logo||C.logoUrl||null,De=te||`en`,Oe=ve.recommendations?.[De]||[],ke=(ye.recommendations?.[De]??Oe).filter(e=>String(e?.label??``).trim()).map((e,t)=>({id:e.key||`qr-${t}`,label:e.label,message:e.label,text:e.label})),Ae=Array.isArray(C.quickChatOptions)&&C.quickChatOptions.length>0?C.quickChatOptions:ke,je=C.hideWatermark===!0?!1:C.showPoweredBy!==!1,Me=C.chatbotEnabled!==!1&&be.chatbotEnabled!==!1,Ne=ve.greetings?.[te]||ye.greetings?.[te]||C.introGreeting||`Hello, I'm here to help you know more about OpenSense Labs.`,Pe={entryPrompt:C.entryPrompt||`Do you want to explore in a new way?`,yesLabel:C.yesLabel||`Yes`,laterLabel:C.laterLabel||`Later`,connectionTitle:C.connectionTitle||`How would you like to connect?`,voiceLabel:C.voiceLabel||`Voice`,textLabel:C.textLabel||`Text`,chatTitle:C.headerName||`Chat with FlowEngage`,introGreeting:Ne,inputPlaceholder:C.inputPlaceholder||`Type your message`,analysingLabel:C.analysingLabel||`analysing...`},Fe=ye.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ie=t?.siteId||n?.siteId||null,w=t?.apiBaseUrl||``,Le=(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]),Re=c&&String(c).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,T=r.some(e=>e.sender===`user`),ze=(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]),Be=!l&&T&&ze,Ve=!!(ye._dashboardLivePreview||ve._dashboardLivePreview),[He,Ue]=(0,d.useState)(()=>Ve?`text_chat`:`entry_prompt`),[We,Ge]=(0,d.useState)(``),[Ke,qe]=(0,d.useState)(null),[E,D]=(0,d.useState)(l||``),[Je,Ye]=(0,d.useState)(``),[Xe,Ze]=(0,d.useState)(0),[Qe,$e]=(0,d.useState)(null),[O,et]=(0,d.useState)(null),[tt,nt]=(0,d.useState)(``),[rt,it]=(0,d.useState)(!1),at=(0,d.useRef)(null),ot=(0,d.useRef)(!1);(0,d.useLayoutEffect)(()=>{e!==`ready`||ot.current||(ot.current=!0,r.length>0&&Ue(`minimized_orb`))},[e,r]);let[st,ct]=(0,d.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 640px)`).matches);(0,d.useEffect)(()=>{let e=window.matchMedia(`(max-width: 640px)`),t=e=>ct(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,d.useEffect)(()=>{D(l||``),l&&Ye(``)},[l]),(0,d.useEffect)(()=>{He===`minimized_orb`?parent.postMessage({type:`WIDGET_MINIMIZED`},`*`):He!==`voice_mode`&&parent.postMessage({type:`WIDGET_OPEN`},`*`)},[He]);let lt=(0,d.useCallback)(()=>{et(null),nt(``)},[]),ut=(0,d.useCallback)(e=>{let t=ZE(e);if(t){et(null),nt(t);return}et(e),nt(``)},[]);(0,d.useEffect)(()=>{if(!x||b!==`connected`){Ze(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||Ze(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]),(0,d.useEffect)(()=>{let e=v?.callId||y||null;if(!e){at.current=null;return}(v?.callId||b===`connecting`||b===`connected`)&&(!(!i||He===`minimized_orb`||He===`voice_mode`)&&at.current===e||(console.log(`[FlowEngageWidget] forcing call UI to front`,{forcedKey:e,isOpen:i,surface:He,hasIncomingCall:!!v?.callId,activeCallId:y,callConnectionState:b}),at.current=e,He===`voice_mode`&&ce?.(!1),oe?.(),Ue(`text_chat`)))},[y,b,v?.callId,i,oe,ce,He]),(0,d.useEffect)(()=>{if(!o||_){_e?.(``),ge?.();return}if(!We.trim()||O){_e?.(``),ge?.();return}he?.();let e=window.setTimeout(()=>_e?.(We),120),t=window.setTimeout(()=>ge?.(),1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[We,O,o,_,he,ge,_e]);let dt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,ft=async e=>{if(e.preventDefault(),_)return;if(Be){let e=E.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){Ye(`Please enter a valid email so we can continue helping you.`);return}await se(e),Ye(``);return}let t=dt(Ke);if(!We.trim()&&!O)return;if(O){try{it(!0),nt(``);let e=await ae(O),n=e?.data||e,r=We.trim()||`Shared file: ${$E(O)}`;Ge(``),qe(null),lt(),await ie(r,``,t,{type:`file`,metadata:{fileUrl:n?.fileUrl,fileName:n?.fileName||O.name,fileType:n?.fileType||O.type,fileSize:n?.fileSize||O.size}})}catch(e){nt(e?.message||`Failed to upload the selected file.`)}finally{it(!1)}return}let n=We.trim();Ge(``),qe(null),await ie(n,``,t)},pt=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 ie(t.trim(),``)},[_,m,ie]),ht=st&&(He===`text_chat`||He===`entry_prompt`)?{inset:0}:Ce===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},gt=()=>Ue(`minimized_orb`),_t=()=>Ue(`connection_modal`),vt=()=>{oe({notifyChatInitiated:!0}),ce?.(!0),Ue(`voice_mode`)},yt=(0,d.useRef)(!1);(0,d.useEffect)(()=>{if(!yt.current)try{let e=sessionStorage.getItem(`_fe_voice_nav`);if(!e)return;let t=JSON.parse(e);if(!t?.ts||Date.now()-t.ts>9e3){sessionStorage.removeItem(`_fe_voice_nav`);return}sessionStorage.removeItem(`_fe_voice_nav`),yt.current=!0,vt()}catch{}});let bt=()=>{oe({notifyChatInitiated:!0}),ce?.(!1),Ue(`text_chat`)},xt=()=>{ce?.(!1),gt()};return e!==`ready`||!Me?null:(0,f.jsxs)(`div`,{className:`flowengage-widget-root`,style:{position:`fixed`,zIndex:999999,...ht},children:[He===`entry_prompt`&&(0,f.jsx)(OO,{copy:Pe,orbColors:xe,primaryColor:Se,onYes:vt,onLater:gt,isMobile:st}),He===`minimized_orb`&&(0,f.jsx)(Sp.div,{layoutId:`fe-main-orb`,initial:{scale:94/50},animate:{scale:1},transition:{type:`spring`,stiffness:220,damping:26},style:{transformOrigin:`bottom right`,display:`inline-block`},children:(0,f.jsx)(DO,{size:50,orbColors:xe,onClick:_t})}),He===`connection_modal`&&(0,f.jsx)(kO,{copy:Pe,orbColors:xe,primaryColor:Se,onVoice:vt,onText:bt,onClose:gt}),He===`voice_mode`&&(0,f.jsx)(AO,{orbColors:xe,onEnterChat:bt,onEndChat:xt,agentId:Fe,siteId:Ie,apiBaseUrl:w,historyRef:ne,onMessageSync:re},`voice`),He===`text_chat`&&(0,f.jsx)(NO,{copy:Pe,orbColors:xe,primaryColor:Se,chatBgGradient:Te,logo:Ee,quickChatOptions:Ae,onQuickChatSelect:mt,isMobile:st,chatHistory:r,isAiTyping:p,isAgentTyping:u,activeScreen:a,agentName:Le,agentHeadshot:Re,fallbackAgentName:we,input:We,setInput:Ge,onSubmit:ft,isConversationEnded:_,isLoading:m,isRateLimited:h,rateLimitMessage:g,selectedFile:O,onFileSelect:ut,onRemoveSelectedFile:lt,attachmentError:tt,isUploadingAttachment:rt,requiresEmail:Be,emailInput:E,setEmailInput:D,emailError:Je,replyContext:Ke,setReplyContext:qe,webRTCError:ee,micError:Qe,setMicError:$e,dismissCallError:me,incomingCall:v,rejectCall:de,acceptCall:ue,activeCallId:y,callConnectionState:b,isCallMuted:S,toggleCallMute:pe,endWebRTCCall:fe,formatCallDuration:pt,callDurationSeconds:Xe,onCollapse:gt,onStartVoice:vt,onEndConversation:le,showPoweredBy:je}),(0,f.jsx)(`style`,{children:`
606
606
  /* Force any SVG (or img) inside LogoSlot to fill the container height
607
607
  regardless of whether the component forwards its style prop. */
608
608
  .fe-logo-slot svg,
@@ -28218,18 +28218,18 @@ function jO() {
28218
28218
  });
28219
28219
  }
28220
28220
  function MO(e) {
28221
- let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
28221
+ let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = typeof e.getHistory == "function" ? e.getHistory : null, a = [], o = {
28222
28222
  flowengage_navigate: async (n) => {
28223
28223
  $("flowengage_navigate ▶ raw parameters:", n);
28224
- let r = wO(n), i = OO(r), a = r.section_text ?? r.sectionText ?? r.section;
28224
+ let r = wO(n), a = OO(r), o = r.section_text ?? r.sectionText ?? r.section;
28225
28225
  if ($("flowengage_navigate · coerced:", {
28226
- url: i,
28227
- sectionText: a
28228
- }), !i) {
28226
+ url: a,
28227
+ sectionText: o
28228
+ }), !a) {
28229
28229
  let e = "Missing url: pass a string url, path like /pricing, or JSON with a url field.";
28230
28230
  return $("flowengage_navigate ✖", e), e;
28231
28231
  }
28232
- if (!await Pn(i, {
28232
+ if (!await Pn(a, {
28233
28233
  siteId: t,
28234
28234
  apiBaseUrl: e.apiBaseUrl
28235
28235
  })) {
@@ -28237,8 +28237,17 @@ function MO(e) {
28237
28237
  return $("flowengage_navigate ✖ blocked", e), e;
28238
28238
  }
28239
28239
  if (fn) try {
28240
- ND(`Navigating to ${i}...`, { spinner: !0 }), RD(), BE(), $("flowengage_navigate → proxy FE_DOM_NAVIGATE", i), await hn("FE_DOM_NAVIGATE", { url: i }), await QD(600), a && typeof a == "string" && ($("flowengage_navigate · proxy FE_DOM_HIGHLIGHT", a), await hn("FE_DOM_HIGHLIGHT", { sectionText: a }));
28241
- let e = `OK_NAVIGATION ${i}`;
28240
+ ND(`Navigating to ${a}...`, { spinner: !0 }), RD(), BE();
28241
+ try {
28242
+ sessionStorage.setItem("_fe_voice_nav", JSON.stringify({
28243
+ ts: Date.now(),
28244
+ to: a
28245
+ }));
28246
+ let e = i?.() || [];
28247
+ e.length > 0 && sessionStorage.setItem("_fe_voice_transcript", JSON.stringify(e.slice(-30)));
28248
+ } catch {}
28249
+ $("flowengage_navigate → proxy FE_DOM_NAVIGATE", a), await hn("FE_DOM_NAVIGATE", { url: a }), await QD(600), o && typeof o == "string" && ($("flowengage_navigate · proxy FE_DOM_HIGHLIGHT", o), await hn("FE_DOM_HIGHLIGHT", { sectionText: o }));
28250
+ let e = `OK_NAVIGATION ${a}`;
28242
28251
  return $("flowengage_navigate ✓ (iframe proxy)", e), ND("Navigation complete", {
28243
28252
  spinner: !1,
28244
28253
  icon: "✅",
@@ -28255,14 +28264,14 @@ function MO(e) {
28255
28264
  zD(), PD(900);
28256
28265
  }
28257
28266
  try {
28258
- if (ND(`Navigating to ${i}...`, { spinner: !0 }), RD(), BE(), KE(), $("flowengage_navigate → shadowNavigate", i), await In(i), await QD(400), jO(), a && typeof a == "string") {
28259
- let e = kn(null, a);
28267
+ if (ND(`Navigating to ${a}...`, { spinner: !0 }), RD(), BE(), KE(), $("flowengage_navigate → shadowNavigate", a), await In(a), await QD(400), jO(), o && typeof o == "string") {
28268
+ let e = kn(null, o);
28260
28269
  e && jE(() => GE(e)), $("flowengage_navigate · highlight", {
28261
- sectionText: a,
28270
+ sectionText: o,
28262
28271
  found: !!e
28263
28272
  });
28264
28273
  }
28265
- let e = `OK_NAVIGATION ${i}`;
28274
+ let e = `OK_NAVIGATION ${a}`;
28266
28275
  return $("flowengage_navigate ✓", e), ND("Navigation complete", {
28267
28276
  spinner: !1,
28268
28277
  icon: "✅",
@@ -28434,22 +28443,22 @@ function MO(e) {
28434
28443
  let t = e?.field_key ?? e?.fieldKey, r = e?.value;
28435
28444
  if (t == null || r == null) continue;
28436
28445
  ND(`Filling ${String(t)}...`, { spinner: !0 });
28437
- let a = aO(), o = vO(a, String(t), r);
28446
+ let i = aO(), o = vO(i, String(t), r);
28438
28447
  if (o.length) {
28439
28448
  for (let [e, t] of o.entries()) VD(t), await qD(t), AO(t, r, { skipScroll: e > 0 }), HD(t), await QD(120);
28440
- i = o, n.push(String(t));
28449
+ a = o, n.push(String(t));
28441
28450
  continue;
28442
28451
  }
28443
- let s = xO(a, String(t));
28444
- s ||= fO(a, String(t)), s ||= pO(a, String(t), r), s && (VD(s), await qD(s), AO(s, r), HD(s), await QD(120), i = [s], n.push(String(t)));
28452
+ let s = xO(i, String(t));
28453
+ s ||= fO(i, String(t)), s ||= pO(i, String(t), r), s && (VD(s), await qD(s), AO(s, r), HD(s), await QD(120), a = [s], n.push(String(t)));
28445
28454
  }
28446
28455
  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.";
28447
- let a = `OK_FILLED: ${n.join(", ")}`;
28448
- return $("flowengage_fill_form ✓", a), ND("Form filled", {
28456
+ let i = `OK_FILLED: ${n.join(", ")}`;
28457
+ return $("flowengage_fill_form ✓", i), ND("Form filled", {
28449
28458
  spinner: !1,
28450
28459
  icon: "✅",
28451
28460
  duration: 1100
28452
- }), a;
28461
+ }), i;
28453
28462
  } catch (e) {
28454
28463
  let t = `flowengage_fill_form error: ${e?.message || String(e)}`;
28455
28464
  return $("flowengage_fill_form ✖", t), ND("Failed to fill form", {
@@ -28484,7 +28493,7 @@ function MO(e) {
28484
28493
  JD(), PD(700);
28485
28494
  }
28486
28495
  }
28487
- let r = CO(n, i);
28496
+ let r = CO(n, a);
28488
28497
  if (!r) return $("flowengage_click_button ✖ no match"), `Could not find a button matching "${n}". Call flowengage_list_forms to see button texts.`;
28489
28498
  try {
28490
28499
  ND(`Clicking ${n}...`, { spinner: !0 });
@@ -28516,15 +28525,15 @@ function MO(e) {
28516
28525
  }
28517
28526
  };
28518
28527
  return {
28519
- ...a,
28520
- navigateToPage: a.flowengage_navigate,
28521
- highlightOnPage: a.flowengage_highlight,
28522
- searchSiteContent: a.flowengage_search,
28523
- getPageContent: a.flowengage_page_content,
28524
- endVoiceSession: a.flowengage_end_session,
28525
- listPageForms: a.flowengage_list_forms,
28526
- fillFormFields: a.flowengage_fill_form,
28527
- clickPageButton: a.flowengage_click_button
28528
+ ...o,
28529
+ navigateToPage: o.flowengage_navigate,
28530
+ highlightOnPage: o.flowengage_highlight,
28531
+ searchSiteContent: o.flowengage_search,
28532
+ getPageContent: o.flowengage_page_content,
28533
+ endVoiceSession: o.flowengage_end_session,
28534
+ listPageForms: o.flowengage_list_forms,
28535
+ fillFormFields: o.flowengage_fill_form,
28536
+ clickPageButton: o.flowengage_click_button
28528
28537
  };
28529
28538
  }
28530
28539
  //#endregion
@@ -29990,9 +29999,22 @@ function qO() {
29990
29999
  bottom: "1.5rem"
29991
30000
  }, bt = () => qe("minimized_orb"), xt = () => qe("connection_modal"), St = () => {
29992
30001
  ce({ notifyChatInitiated: !0 }), ue?.(!0), qe("voice_mode");
29993
- }, Ct = () => {
30002
+ }, Ct = p(!1);
30003
+ c(() => {
30004
+ if (!Ct.current) try {
30005
+ let e = sessionStorage.getItem("_fe_voice_nav");
30006
+ if (!e) return;
30007
+ let t = JSON.parse(e);
30008
+ if (!t?.ts || Date.now() - t.ts > 9e3) {
30009
+ sessionStorage.removeItem("_fe_voice_nav");
30010
+ return;
30011
+ }
30012
+ sessionStorage.removeItem("_fe_voice_nav"), Ct.current = !0, St();
30013
+ } catch {}
30014
+ });
30015
+ let wt = () => {
29994
30016
  ce({ notifyChatInitiated: !0 }), ue?.(!1), qe("text_chat");
29995
- }, wt = () => {
30017
+ }, Tt = () => {
29996
30018
  ue?.(!1), bt();
29997
30019
  };
29998
30020
  return e !== "ready" || !Fe ? null : /* @__PURE__ */ _("div", {
@@ -30035,13 +30057,13 @@ function qO() {
30035
30057
  orbColors: we,
30036
30058
  primaryColor: Te,
30037
30059
  onVoice: St,
30038
- onText: Ct,
30060
+ onText: wt,
30039
30061
  onClose: bt
30040
30062
  }),
30041
30063
  Ke === "voice_mode" && /* @__PURE__ */ g(UO, {
30042
30064
  orbColors: we,
30043
- onEnterChat: Ct,
30044
- onEndChat: wt,
30065
+ onEnterChat: wt,
30066
+ onEndChat: Tt,
30045
30067
  agentId: D,
30046
30068
  siteId: Re,
30047
30069
  apiBaseUrl: ze,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "1.9.10",
3
+ "version": "1.9.12",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",