@flowengage/react-chatbot 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/flowengage-embed.js
CHANGED
|
@@ -470,16 +470,16 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
470
470
|
<path d="M4 2L19 10.5L11 12.8L8 20L4 2Z"
|
|
471
471
|
fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
|
|
472
472
|
filter="url(#${Q}-csh)"/>
|
|
473
|
-
</svg>`,ng=null,rg=!1;function ig(){return(!ng||!ng.isConnected)&&(ng=document.createElement(`div`),ng.id=`${Q}-cursor`,ng.innerHTML=tg,document.body.appendChild(ng),rg=!1),ng}async function ag(e){if(typeof document>`u`||!e)return;Vh();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=ig();rg||=(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 ug(360)}function og(e=!1){ng&&(e?(ng.classList.remove(`${Q}-cursor-visible`),rg=!1):(ng.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{rg=!1},250)))}async function sg(e){ng&&(ng.classList.add(`${Q}-cursor-click`),await ug(280),ng.classList.remove(`${Q}-cursor-click`))}function cg(e){if(!e||typeof document>`u`)return;Vh();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)}async function lg(e,t,n){if(!e||!t)return;if(!(t.length<=72&&!/^https?:\/\//i.test(t)&&!/^\d+$/.test(t))){n(e,t);return}let r={bubbles:!0,cancelable:!0,composed:!0};n(e,``),e.dispatchEvent(new Event(`input`,r));for(let i=1;i<=t.length;i++){n(e,t.slice(0,i));try{e.dispatchEvent(new InputEvent(`input`,{...r,inputType:`insertText`,data:t[i-1]}))}catch{e.dispatchEvent(new Event(`input`,r))}await ug(28+Math.random()*27)}e.dispatchEvent(new Event(`change`,r))}function ug(e){return new Promise(t=>setTimeout(t,e))}function $(...e){nn()&&console.log(`[FlowEngage:voice-tools]`,...e)}var dg=`#flowengage-root, .flowengage-shell`;function fg(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(dg)}catch{return!1}}function pg(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function mg(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(!fg(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function hg(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function gg(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 hg(r.join(` `))}if(e.labels&&e.labels.length)return hg(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return hg(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return hg(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return hg(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=hg(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 hg(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return hg(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?hg(o):null}function _g(){let e=[];return mg(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(fg(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}try{if(e.offsetWidth===0&&e.offsetHeight===0)return!1}catch{}return!0}))}),e}function vg(){return _g().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:gg(e),placeholder:e.placeholder||null}))}function yg(){let e=[];return mg(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(fg(e)||e.disabled)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)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 bg(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function xg(e){let t=bg(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function Sg(e,t){let n=xg(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.type||``).toLowerCase();if(a===`email`&&/email|e-mail|mail/.test(n))return 100;if(a===`tel`&&/phone|mobile|tel|cell/.test(n))return 95;if(a===`url`&&/url|website|domain|link/.test(n))return 100;let o=[e.name,e.id,e.placeholder,gg(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>bg(e)),s=0;for(let e of o){if(!e)continue;if(e===n){s=100;break}if(e.includes(n)||n.includes(e)){s=Math.max(s,96);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);let i=r/t.length;i>0&&(s=Math.max(s,i*88))}return s}var Cg=22;function wg(e,t){let n=null,r=0;for(let i of e){let e=Sg(i,t);e>r&&(r=e,n=i)}return!n||r<Cg?null:n}function Tg(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,gg(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 Eg(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function Dg(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 Og(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 kg(e){if(!Og(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,gg(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 Ag(e,t,n){let r=String(t??``),i=String(n??``),a=Ng(e,r)||wg(e,r)||Tg(e,r,i);if(!a)return[];let o=new Set([a]);if(Eg(i)&&Dg(r))for(let t of e)t!==a&&kg(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 jg(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 Mg(e){if(!e||typeof e!=`string`)return null;let t=null;return mg(n=>{try{let r=n.getElementById(e);r&&!fg(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Ng(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=Mg(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Mg(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 Pg(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===n)return 100;if(r.includes(n))return 98;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 Fg(e,t){let n=[];mg(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(fg(e)||e.disabled)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Pg(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=jg(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function Ig(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 Lg(e){let t=Ig(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 Rg(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 zg(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 Bg(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 Vg(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 Hg(e){let t=e.ownerDocument?.defaultView||window,n=e.tagName===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`);return(e,t)=>{try{e._valueTracker&&e._valueTracker.setValue(``)}catch{}r?.set?r.set.call(e,t):e.value=t}}async function Ug(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{await ag(e)}catch{}try{$h(e)}catch{}await new Promise(e=>setTimeout(e,180));try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase(),a={bubbles:!0,cancelable:!0,composed:!0};if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a)),eg(e),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),eg(e),!0;let o=String(t);r===`INPUT`||r===`TEXTAREA`?await lg(e,o,Hg(e)):(e.value=o,e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a));try{e.focus({preventScroll:!0})}catch{}try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}try{eg(e)}catch{}return!0}function Wg(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async n=>{$(`navigate_to_page ▶ raw parameters:`,n);let r=Ig(n),i=Bg(r),a=r.section_text??r.sectionText??r.section;if($(`navigate_to_page · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`navigate_to_page ✖`,e),e}if(Gh(`Navigating to ${i.replace(/^https?:\/\/[^/]+/,``)||`/`}…`),Xh(),!await mn(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){Zh(),Kh(200);let e=`That page is not available in the site index; answer without navigating.`;return $(`navigate_to_page ✖ blocked`,e),e}try{if($(`navigate_to_page → shadowNavigate`,i),await gn(i,{sectionText:a||void 0}),await new Promise(e=>setTimeout(e,600)),Zh(),Kh(300),a&&typeof a==`string`){let e=ln(null,a);e&&un(e),$(`navigate_to_page · highlight`,{sectionText:a,found:!!e})}let e=`OK_NAVIGATION ${i}`;return $(`navigate_to_page ✓`,e),e}catch(e){Zh(),Kh(200);let t=`Navigation error: ${e?.message||String(e)}`;return $(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{$(`highlight_on_page ▶`,e);let t=Ig(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=ln(n||null,r||null);return i?(un(i),$(`highlight_on_page ✓`),`Highlighted the section.`):($(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{$(`search_site_content ▶`,e);let r=Vg(Ig(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),Gh(`Searching site content…`,{spinner:!0}),!r)return Kh(),$(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return Kh(),$(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return Kh(),$(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`search_site_content → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`search_site_content · HTTP`,i.status,`success:`,a.success),Kh(200),!a.success){let e=a.error||`Search failed.`;return $(`search_site_content ✖`,e),e}let o=a.results||[];return $(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){Kh();let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},end_voice_session:async()=>($(`end_voice_session ▶`),Gh(`Ending voice session…`,{icon:`👋`,spinner:!1,duration:2e3}),og(!0),Qh(),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),list_page_forms:async()=>{let e=vg(),t=yg();return $(`list_page_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, fill_form_fields sets all matching URL inputs. click_page_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},fill_form_fields:async e=>{try{$(`fill_form_fields ▶ raw:`,e);let t=Lg(e);if(!t.length&&r){let e=r(),n=Rg(e);n.length?$(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=zg(e),n.length&&$(`fill_form_fields · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms for field_key strings, then fill_form_fields 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.`;t.length>1&&Gh(`Filling ${t.length} fields…`);let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;Gh(`Filling ${t}…`),$(`fill_form_fields · processing field:`,t,`=`,r);let a=_g();$(`fill_form_fields · visible inputs count:`,a.length);let o=Ag(a,String(t),r);if(o.length){for(let e=0;e<o.length;e++)await Ug(o[e],r,{skipScroll:e>0}),await new Promise(e=>setTimeout(e,80));i=o,n.push(String(t));continue}let s=Ng(a,String(t));s||=wg(a,String(t)),s||=Tg(a,String(t),r),s?(await Ug(s,r),i=[s],n.push(String(t))):$(`fill_form_fields · no match for field:`,t)}Kh(400);try{og()}catch{}if(!n.length)return $(`fill_form_fields ✖ no matches`),`Could not match any fields. Call list_page_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 $(`fill_form_fields ✓`,a),a}catch(e){Kh(),Qh(),og(!0);let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Ig(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;Gh(`Clicking "${n}"…`);let r=Fg(n,i);if(!r)return Kh(200),$(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{try{r.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}try{await ag(r)}catch{}try{cg(r)}catch{}try{await sg(r)}catch{}r.focus?.(),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`;Kh(600);try{og()}catch{}Qh();let t=`OK_CLICK ${e}`;return $(`click_page_button ✓`,t),t}catch(e){Kh(200),og(!0);let t=`Click failed: ${e?.message||String(e)}`;return $(`click_page_button ✖`,t),t}}};return{...a,navigateToPage:a.navigate_to_page,highlightOnPage:a.highlight_on_page,searchSiteContent:a.search_site_content,endVoiceSession:a.end_voice_session,listPageForms:a.list_page_forms,fillFormFields:a.fill_form_fields,clickPageButton:a.click_page_button}}function Gg(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=nn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i=await t(n),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 Kg={idle:`rgba(99,102,241,0.18)`,listening:`rgba(16,185,129,0.25)`,speaking:`rgba(245,158,11,0.25)`,error:`rgba(239,68,68,0.2)`},qg={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Jg(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 Yg({agentId:e,chatId:t,siteId:n,apiBaseUrl:r,onEnd:i,historyRef:a,hasSyncedRef:o,onMessageSync:s,onStartSync:c}){let[l,u]=(0,v.useState)(`idle`),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useRef)(``),y=(0,v.useRef)(async()=>{}),b=(0,v.useRef)(!1),x=(0,v.useCallback)(async()=>{try{await h.current?.endSession?.()}catch{}h.current=null,m(!1),u(`idle`),b.current=!1,typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]);y.current=x,(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;a.current=[],_.current=``,b.current=!1;let o=Gg(Wg({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{queueMicrotask(()=>{b.current||(b.current=!0,y.current?.())})}})),s=await Bh.startSession({agentId:e,clientTools:o,onUnhandledClientToolCall:e=>{console.error(`[VoiceInterface] ElevenLabs requested a client tool that is not registered in the widget:`,e?.tool_name,e?.parameters,`Add a matching handler in voiceClientTools (snake_case and camelCase are both supported).`)},onModeChange:({mode:e})=>{t||u(e===`speaking`?`speaking`:`listening`)},onMessage:e=>{if(t)return;let n=e.role===`user`?`user`:`bot`,r=e.message||e.text||e.content||``;if(!r)return;let i={sender:n,message:r,timestamp:new Date().toISOString()};n===`user`&&(_.current=r),a.current=[...a.current,i],Jg(n,r)&&queueMicrotask(()=>{b.current||(b.current=!0,y.current?.())})},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),u(`error`),f(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),m(!1),u(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,h.current=s,m(!0),u(`listening`);try{let e=typeof window<`u`?window.location.href:``,t=``;try{t=await o.list_page_forms()}catch{t=`[]`}s.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${n||`unknown`}. Page fields/buttons JSON: ${t}. Navigation: search_site_content then navigate_to_page with section_text when relevant — no permission ask. Forms: use fill_form_fields then click_page_button (e.g. Conduct Audit) when the user wants to submit. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end; you may also say you are ending the voice session.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),u(`error`),f(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):h.current&&h.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let ee=l===`listening`||l===`speaking`,te=qg[l]||qg.idle,S=Kg[l]||Kg.idle;return(0,k.jsxs)(`div`,{ref:g,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,k.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[ee&&(0,k.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${te}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),ee&&(0,k.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${te}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,k.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:S,border:`3px solid ${te}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:l===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${S}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,k.jsx)(Dn,{size:44,color:te})})]}),(0,k.jsxs)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:l===`error`?`#ef4444`:`#374151`,letterSpacing:`0.01em`,textAlign:`center`},children:[l===`idle`&&`Starting voice session…`,l===`listening`&&`Listening…`,l===`speaking`&&`AI is speaking…`,l===`error`&&(d||`Error`)]}),(0,k.jsxs)(`button`,{onClick:x,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`12px 24px`,borderRadius:`999px`,background:`#fee2e2`,color:`#dc2626`,border:`1px solid #fca5a5`,fontWeight:600,fontSize:`14px`,cursor:`pointer`,transition:`all 0.2s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#fecaca`},onMouseLeave:e=>{e.currentTarget.style.background=`#fee2e2`},children:[(0,k.jsx)(On,{size:18}),`End Voice Session`]}),(0,k.jsx)(`style`,{children:`
|
|
473
|
+
</svg>`,ng=null,rg=!1;function ig(){return(!ng||!ng.isConnected)&&(ng=document.createElement(`div`),ng.id=`${Q}-cursor`,ng.innerHTML=tg,document.body.appendChild(ng),rg=!1),ng}async function ag(e){if(typeof document>`u`||!e)return;Vh();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=ig();rg||=(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 ug(360)}function og(e=!1){ng&&(e?(ng.classList.remove(`${Q}-cursor-visible`),rg=!1):(ng.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{rg=!1},250)))}async function sg(e){ng&&(ng.classList.add(`${Q}-cursor-click`),await ug(280),ng.classList.remove(`${Q}-cursor-click`))}function cg(e){if(!e||typeof document>`u`)return;Vh();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)}async function lg(e,t,n){if(!e||!t)return;if(!(t.length<=72&&!/^https?:\/\//i.test(t)&&!/^\d+$/.test(t))){n(e,t);return}let r={bubbles:!0,cancelable:!0,composed:!0};n(e,``),e.dispatchEvent(new Event(`input`,r));for(let i=1;i<=t.length;i++){n(e,t.slice(0,i));try{e.dispatchEvent(new InputEvent(`input`,{...r,inputType:`insertText`,data:t[i-1]}))}catch{e.dispatchEvent(new Event(`input`,r))}await ug(28+Math.random()*27)}e.dispatchEvent(new Event(`change`,r))}function ug(e){return new Promise(t=>setTimeout(t,e))}function $(...e){nn()&&console.log(`[FlowEngage:voice-tools]`,...e)}var dg=`#flowengage-root, .flowengage-shell`;function fg(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(dg)}catch{return!1}}function pg(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function mg(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(!fg(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function hg(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function gg(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 hg(r.join(` `))}if(e.labels&&e.labels.length)return hg(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return hg(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return hg(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return hg(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=hg(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 hg(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return hg(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?hg(o):null}function _g(){let e=[];return mg(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(fg(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}try{if(e.offsetWidth===0&&e.offsetHeight===0)return!1}catch{}return!0}))}),e}function vg(){return _g().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:gg(e),placeholder:e.placeholder||null}))}function yg(){let e=[];return mg(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(fg(e)||e.disabled)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)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 bg(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function xg(e){let t=bg(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function Sg(e,t){let n=xg(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.type||``).toLowerCase();if(a===`email`&&/email|e-mail|mail/.test(n))return 100;if(a===`tel`&&/phone|mobile|tel|cell/.test(n))return 95;if(a===`url`&&/url|website|domain|link/.test(n))return 100;let o=[e.name,e.id,e.placeholder,gg(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>bg(e)),s=0;for(let e of o){if(!e)continue;if(e===n){s=100;break}if(e.includes(n)||n.includes(e)){s=Math.max(s,96);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);let i=r/t.length;i>0&&(s=Math.max(s,i*88))}return s}var Cg=22;function wg(e,t){let n=null,r=0;for(let i of e){let e=Sg(i,t);e>r&&(r=e,n=i)}return!n||r<Cg?null:n}function Tg(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,gg(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 Eg(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function Dg(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 Og(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 kg(e){if(!Og(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,gg(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 Ag(e,t,n){let r=String(t??``),i=String(n??``),a=Ng(e,r)||wg(e,r)||Tg(e,r,i);if(!a)return[];let o=new Set([a]);if(Eg(i)&&Dg(r))for(let t of e)t!==a&&kg(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 jg(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 Mg(e){if(!e||typeof e!=`string`)return null;let t=null;return mg(n=>{try{let r=n.getElementById(e);r&&!fg(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Ng(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=Mg(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Mg(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 Pg(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===n)return 100;if(r.includes(n))return 98;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 Fg(e,t){let n=[];mg(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(fg(e)||e.disabled)return!1;try{let t=pg(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Pg(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=jg(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function Ig(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 Lg(e){let t=Ig(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 Rg(e){if(!e||typeof e!=`string`)return e;let t=e.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?t:(t=t.replace(/\s+at\s+the\s+rate\s*(of)?\s+/gi,`@`),t=t.replace(/\s+at\s+/gi,`@`),t=t.replace(/\s+dot\s+/gi,`.`),t=t.replace(/\s+/g,``),t=t.replace(/\.{2,}/g,`.`).replace(/\.$/,``),t)}function zg(e){if(!e||typeof e!=`string`)return e;let t={zero:`0`,one:`1`,two:`2`,three:`3`,four:`4`,five:`5`,six:`6`,seven:`7`,eight:`8`,nine:`9`,oh:`0`,o:`0`},n=e.toLowerCase().trim();for(let[e,r]of Object.entries(t))n=n.replace(RegExp(`\\b${e}\\b`,`g`),r);return n=n.replace(/[^\d+]/g,``),n}function Bg(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 Vg(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=Rg(t),s=i.test(o),c=o.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);if(c)return a(`Email Address`,c[1]),n;if(!i.test(t)&&s){let e=o.match(i);if(e)return a(`Email Address`,e[1]),n}let l=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(l&&a(`Full Name`,l[1]),l=t.match(/\bfull\s*name,?\s*(?:please\s+)?(?:enter|type|put)\s+(.+?)(?:\.|$|!|\?)/i),l&&a(`Full Name`,l[1]),l=t.match(/\bfull\s*name\s*(?:is|:|please\s+enter|-)\s*(.+?)(?:\.|$|(?=\s+(?:and|my\s+email|email|message))\b)/i),l&&a(`Full Name`,l[1]),l=t.match(/\b(.+?)\s+for\s+(?:the\s+)?full\s*name\b/i),l){let e=l[1].trim();e.length>1&&e.length<120&&!/@/.test(e)&&a(`Full Name`,e)}if(l=t.match(/\b(?:email|e-mail)(?:\s*address)?\s*(?:is|:|please\s+use|enter|-)\s*([^\s@]+@[^\s@]+\.[^\s,]+)/i),l&&a(`Email Address`,l[1]),l=t.match(/\b(?:enter|type|put)\s+([^\s@]+@[^\s@]+\.[^\s,]+)\s+in(?:to)?\s+(?:the\s+)?(?:email|e-mail)/i),l&&a(`Email Address`,l[1]),l=t.match(/\b(?:message|comment)\s*(?:is|:|please\s+enter|-)\s*(.+)$/is),l){let e=l[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 Hg(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 Ug(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 Wg(e){let t=e.ownerDocument?.defaultView||window,n=e.tagName===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`);return(e,t)=>{try{e._valueTracker&&e._valueTracker.setValue(``)}catch{}r?.set?r.set.call(e,t):e.value=t}}async function Gg(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{await ag(e)}catch{}try{$h(e)}catch{}await new Promise(e=>setTimeout(e,180));try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase(),a={bubbles:!0,cancelable:!0,composed:!0};if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a)),eg(e),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),eg(e),!0;let o=String(t);r===`INPUT`||r===`TEXTAREA`?await lg(e,o,Wg(e)):(e.value=o,e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a));try{e.focus({preventScroll:!0})}catch{}try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}try{eg(e)}catch{}return!0}function Kg(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async n=>{$(`navigate_to_page ▶ raw parameters:`,n);let r=Ig(n),i=Hg(r),a=r.section_text??r.sectionText??r.section;if($(`navigate_to_page · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`navigate_to_page ✖`,e),e}if(Gh(`Navigating to ${i.replace(/^https?:\/\/[^/]+/,``)||`/`}…`),Xh(),!await mn(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){Zh(),Kh(200);let e=`That page is not available in the site index; answer without navigating.`;return $(`navigate_to_page ✖ blocked`,e),e}try{if($(`navigate_to_page → shadowNavigate`,i),await gn(i,{sectionText:a||void 0}),await new Promise(e=>setTimeout(e,600)),Zh(),Kh(300),a&&typeof a==`string`){let e=ln(null,a);e&&un(e),$(`navigate_to_page · highlight`,{sectionText:a,found:!!e})}let e=``;try{let t=vg(),n=yg();if(t.length>0){let r=t.map(e=>e.label||e.placeholder||e.name||e.id).filter(Boolean).join(`, `),i=n.map(e=>e.text).filter(Boolean).join(`, `);e=` This page has a form with fields: [${r}]`+(i?` and buttons: [${i}].`:`.`)+` Call list_page_forms then start filling.`}}catch{}let t=`OK_NAVIGATION ${i}${e}`;return $(`navigate_to_page ✓`,t),t}catch(e){Zh(),Kh(200);let t=`Navigation error: ${e?.message||String(e)}`;return $(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{$(`highlight_on_page ▶`,e);let t=Ig(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=ln(n||null,r||null);return i?(un(i),$(`highlight_on_page ✓`),`Highlighted the section.`):($(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{$(`search_site_content ▶`,e);let r=Ug(Ig(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),Gh(`Searching site content…`,{spinner:!0}),!r)return Kh(),$(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return Kh(),$(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return Kh(),$(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`search_site_content → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`search_site_content · HTTP`,i.status,`success:`,a.success),Kh(200),!a.success){let e=a.error||`Search failed.`;return $(`search_site_content ✖`,e),e}let o=a.results||[];return $(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){Kh();let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},end_voice_session:async()=>($(`end_voice_session ▶`),Gh(`Ending voice session…`,{icon:`👋`,spinner:!1,duration:2e3}),og(!0),Qh(),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),list_page_forms:async()=>{let e=vg(),t=yg();return $(`list_page_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, fill_form_fields sets all matching URL inputs. click_page_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},fill_form_fields:async e=>{try{$(`fill_form_fields ▶ raw:`,e);let t=Lg(e);if(!t.length&&r){let e=r(),n=Bg(e);n.length?$(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=Vg(e),n.length&&$(`fill_form_fields · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms for field_key strings, then fill_form_fields 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.`;t.length>1&&Gh(`Filling ${t.length} fields…`);let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;let a=String(t).toLowerCase();/email|e-mail|mail/.test(a)?r=Rg(r):/phone|mobile|tel|cell/.test(a)&&(r=zg(r)),Gh(`Filling ${t}…`),$(`fill_form_fields · processing field:`,t,`=`,r);let o=_g();$(`fill_form_fields · visible inputs count:`,o.length);let s=Ag(o,String(t),r);if(s.length){for(let e=0;e<s.length;e++)await Gg(s[e],r,{skipScroll:e>0}),await new Promise(e=>setTimeout(e,80));i=s,n.push(String(t));continue}let c=Ng(o,String(t));c||=wg(o,String(t)),c||=Tg(o,String(t),r),c?(await Gg(c,r),i=[c],n.push(String(t))):$(`fill_form_fields · no match for field:`,t)}Kh(400);try{og()}catch{}if(!n.length)return $(`fill_form_fields ✖ no matches`),`Could not match any fields. Call list_page_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 $(`fill_form_fields ✓`,a),a}catch(e){Kh(),Qh(),og(!0);let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Ig(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;Gh(`Clicking "${n}"…`);let r=Fg(n,i);if(!r)return Kh(200),$(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{try{r.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}try{await ag(r)}catch{}try{cg(r)}catch{}try{await sg(r)}catch{}r.focus?.(),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`;Kh(600);try{og()}catch{}Qh();let t=`OK_CLICK ${e}`;return $(`click_page_button ✓`,t),t}catch(e){Kh(200),og(!0);let t=`Click failed: ${e?.message||String(e)}`;return $(`click_page_button ✖`,t),t}}};return{...a,navigateToPage:a.navigate_to_page,highlightOnPage:a.highlight_on_page,searchSiteContent:a.search_site_content,endVoiceSession:a.end_voice_session,listPageForms:a.list_page_forms,fillFormFields:a.fill_form_fields,clickPageButton:a.click_page_button}}function qg(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=nn();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i=await t(n),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 Jg={idle:`rgba(99,102,241,0.18)`,listening:`rgba(16,185,129,0.25)`,speaking:`rgba(245,158,11,0.25)`,error:`rgba(239,68,68,0.2)`},Yg={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Xg(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 Zg({agentId:e,chatId:t,siteId:n,apiBaseUrl:r,onEnd:i,historyRef:a,hasSyncedRef:o,onMessageSync:s,onStartSync:c}){let[l,u]=(0,v.useState)(`idle`),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useRef)(``),y=(0,v.useRef)(async()=>{}),b=(0,v.useRef)(!1),x=(0,v.useCallback)(async()=>{try{await h.current?.endSession?.()}catch{}h.current=null,m(!1),u(`idle`),b.current=!1,typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]);y.current=x,(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;a.current=[],_.current=``,b.current=!1;let o=qg(Kg({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>_.current,requestEndSession:()=>{queueMicrotask(()=>{b.current||(b.current=!0,y.current?.())})}})),s=await Bh.startSession({agentId:e,clientTools:o,onUnhandledClientToolCall:e=>{console.error(`[VoiceInterface] ElevenLabs requested a client tool that is not registered in the widget:`,e?.tool_name,e?.parameters,`Add a matching handler in voiceClientTools (snake_case and camelCase are both supported).`)},onModeChange:({mode:e})=>{t||u(e===`speaking`?`speaking`:`listening`)},onMessage:e=>{if(t)return;let n=e.role===`user`?`user`:`bot`,r=e.message||e.text||e.content||``;if(!r)return;let i={sender:n,message:r,timestamp:new Date().toISOString()};n===`user`&&(_.current=r),a.current=[...a.current,i],Xg(n,r)&&queueMicrotask(()=>{b.current||(b.current=!0,y.current?.())})},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),u(`error`),f(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),m(!1),u(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,h.current=s,m(!0),u(`listening`);try{let e=typeof window<`u`?window.location.href:``,t=``;try{t=await o.list_page_forms()}catch{t=`[]`}let r=``;try{let e=await o.search_site_content({query:`pages`}),t=typeof e==`string`?JSON.parse(e):e;Array.isArray(t)&&t.length&&(r=` Site pages available: ${t.map(e=>`${e.title||``} (${e.url||``})`).join(`, `)}.`)}catch{}s.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${n||`unknown`}. Page fields/buttons JSON: ${t}.${r} Navigation: when the user wants to go to any page (contact, pricing, about, services, etc.), call search_site_content then navigate_to_page immediately — never ask permission. After navigating to a page with a form, call list_page_forms and proactively start helping the user fill it. Forms: use fill_form_fields then click_page_button (e.g. Conduct Audit, Send Message) when the user wants to submit. Fill each field immediately after the user answers — never skip ahead. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),u(`error`),f(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):h.current&&h.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let ee=l===`listening`||l===`speaking`,te=Yg[l]||Yg.idle,S=Jg[l]||Jg.idle;return(0,k.jsxs)(`div`,{ref:g,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,k.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[ee&&(0,k.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${te}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),ee&&(0,k.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${te}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,k.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:S,border:`3px solid ${te}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:l===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${S}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,k.jsx)(Dn,{size:44,color:te})})]}),(0,k.jsxs)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:l===`error`?`#ef4444`:`#374151`,letterSpacing:`0.01em`,textAlign:`center`},children:[l===`idle`&&`Starting voice session…`,l===`listening`&&`Listening…`,l===`speaking`&&`AI is speaking…`,l===`error`&&(d||`Error`)]}),(0,k.jsxs)(`button`,{onClick:x,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`12px 24px`,borderRadius:`999px`,background:`#fee2e2`,color:`#dc2626`,border:`1px solid #fca5a5`,fontWeight:600,fontSize:`14px`,cursor:`pointer`,transition:`all 0.2s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#fecaca`},onMouseLeave:e=>{e.currentTarget.style.background=`#fee2e2`},children:[(0,k.jsx)(On,{size:18}),`End Voice Session`]}),(0,k.jsx)(`style`,{children:`
|
|
474
474
|
@keyframes fe-orb-pulse {
|
|
475
475
|
0% { transform: scale(1); opacity: 0.6; }
|
|
476
476
|
50% { transform: scale(1.18); opacity: 0.15; }
|
|
477
477
|
100% { transform: scale(1); opacity: 0.6; }
|
|
478
478
|
}
|
|
479
|
-
`})]})}var
|
|
479
|
+
`})]})}var Qg=[{key:`become_client`,label:`Become a Client`},{key:`sales_enquiry`,label:`Sales Enquiry`},{key:`learn_services`,label:`Learn about our Services`},{key:`get_support`,label:`Get Support`},{key:`looking_for_job`,label:`Looking for a Job`}],$g=()=>(0,k.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,color:`#111827`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[[0,1,2].map(e=>(0,k.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)),(0,k.jsx)(`style`,{children:`
|
|
480
480
|
@keyframes fe-dot-bounce {
|
|
481
481
|
0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
|
|
482
482
|
40% { transform: translateY(-5px); opacity: 1; }
|
|
483
483
|
}
|
|
484
|
-
`})]})});function
|
|
485
|
-
@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-border-style:solid;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-ease:initial}}:root,:host{--spacing:.25rem;--ease-in-out:cubic-bezier(.4, 0, .2, 1);--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.start{inset-inline-start:var(--spacing)}.end{inset-inline-end:var(--spacing)}.container{width:100%}@media (width>=40rem){.container{max-width:40rem}}@media (width>=48rem){.container{max-width:48rem}}@media (width>=64rem){.container{max-width:64rem}}@media (width>=80rem){.container{max-width:80rem}}@media (width>=96rem){.container{max-width:96rem}}.block{display:block}.flex{display:flex}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.flex-shrink{flex-shrink:1}.transform{transform:var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,)}.border{border-style:var(--tw-border-style);border-width:1px}.ring{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.backdrop-filter{-webkit-backdrop-filter:var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.flowengage-shell,.flowengage-shell *{font-family:inherit}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(423px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, #2b70b5 50%, #f59e0b 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{animation-timing-function:cubic-bezier(.8,0,1,1);transform:translateY(-25%)}50%{animation-timing-function:cubic-bezier(0,0,.2,1);transform:none}}@keyframes pulse{50%{opacity:.5}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-primary) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}`,e_=null,t_=!1;function n_(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=$g,document.head.appendChild(e)}function r_(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function i_({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(t_){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),r_(()=>i_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let i=document.createElement(`div`);i.id=`flowengage-root`,document.body.appendChild(i),n_(),e_=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};e_.render(v.createElement(wn,{siteId:e,language:t,config:a},v.createElement(Qg))),t_=!0}var a_={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>r_(()=>i_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):r_(()=>i_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){e_&&=(e_.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),t_=!1}},o_=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};r_(()=>i_({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,o_):o_(),typeof window<`u`&&(window.FlowEngage=a_),a_})();
|
|
484
|
+
`})]})});function e_(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,agentHeadshot:l,visitorEmail:u,isAgentTyping:d,isAiTyping:f,isLoading:p,isVoiceMode:m,isRateLimited:h,rateLimitMessage:g,isConversationEnded:_,incomingCall:y,activeCallId:b,callConnectionState:x,callConnectedAt:ee,isCallMuted:te,webRTCError:S,language:ne,historyRef:re,onMessageSync:ie,endConversation:ae,acceptCall:oe,rejectCall:se,endWebRTCCall:ce,toggleCallMute:le,dismissCallError:ue,captureVisitorEmail:de,openWidget:fe,closeWidget:C,sendMessage:w,setVoiceMode:pe,startTyping:me,stopTyping:he,updateTypingDraft:ge}=tn(),[_e,T]=(0,v.useState)(``),[ve,ye]=(0,v.useState)(null),[be,xe]=(0,v.useState)(null),[Se,Ce]=(0,v.useState)(null),[we,Te]=(0,v.useState)(0),[Ee,De]=(0,v.useState)(u||``),[Oe,ke]=(0,v.useState)(``);(0,v.useEffect)(()=>{try{sn()}catch{}},[]);let E=t?.widgetSettings||{},Ae=n?.widgetSettings||{},je={...Ae.branding||{},...E.branding||{}},Me={...Ae.theme||{},...E.theme||{}},Ne=Me.primaryColor||`#3B82F6`,Pe=Me.accentColor||`#1D4ED8`,Fe=(Me.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Ie={"--flowengage-primary":Ne,"--flowengage-accent":Pe,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:Fe},Le=E.recommendations?.[ne]||Ae.recommendations?.[ne]||Qg,Re=E.greetings?.[ne]||Ae.greetings?.[ne],ze=je.chatButtonText||`Chat with us`,Be=je.headerName||t?.websiteName||`OpenSense Labs`,Ve=je.logoUrl||null,He=je.hideWatermark||!1,D=Ae.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ue=t?.siteId||n?.siteId||null,We=t?.apiBaseUrl||``,Ge=je.fallbackAgentName||`Agent`,Ke=je.botLabel||`AI`,qe=l&&String(l).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Je=y?.agentName||c||Ge,Ye=i.some(e=>e.sender===`user`),Xe=(0,v.useMemo)(()=>{let e=i.findIndex(e=>e.sender===`user`);return e===-1?!1:i.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[i]),Ze=!u&&Ye&&Xe;(0,v.useEffect)(()=>{De(u||``),u&&ke(``)},[u]),(0,v.useEffect)(()=>{if(!ee||x!==`connected`){Te(0);return}let e=()=>{let e=new Date(ee).getTime();isNaN(e)||Te(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[ee,x]),(0,v.useEffect)(()=>{if(!s||m||_){ge(``),he();return}if(!_e.trim()){ge(``),he();return}me();let e=window.setTimeout(()=>{ge(_e)},120),t=window.setTimeout(()=>{he()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[_e,s,m,_,me,he,ge]);let Qe=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,$e=async e=>{if(e.preventDefault(),_)return;if(Ze){let e=Ee.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){ke(`Please enter a valid email so we can continue helping you.`);return}await de(e),ke(``);return}if(!_e.trim())return;let t=_e.trim(),n=Qe(Se);T(``),Ce(null),await w(t,``,n)},et=async()=>{if(Ze){ke(`Please share your email before starting a call.`);return}if(m){pe(!1);return}xe(null);try{ye(await navigator.mediaDevices.getUserMedia({audio:!0})),pe(!0)}catch(e){xe(e.message||`Could not access microphone.`)}},tt=()=>{ve&&(ve.getTracks().forEach(e=>e.stop()),ye(null)),pe(!1)},nt=e=>{let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`};return e===`ready`?(0,k.jsxs)(`div`,{className:`flowengage-shell`,"data-open":a?`true`:`false`,style:Ie,children:[(0,k.jsx)(Fn,{isOpen:a,openWidget:fe,launcherText:ze,primaryColor:Ne,posInline:Fe}),a&&(0,k.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!m?`linear-gradient(to bottom, ${Ne} 0%, ${Ne} 70%, white 85%)`:`white`},children:[(0,k.jsx)(Bn,{logoUrl:Ve,brandName:Be,agentName:c,fallbackAgentName:Ge,activeScreen:o,branding:je,isConversationEnded:_,endConversation:ae,closeWidget:C,isInitial:i.length===0&&!m,botLabel:Ke,agentAvatarUrl:o===`agent`?qe:null,primaryColor:Ne}),(0,k.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:m?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Zg,{agentId:D,chatId:r,siteId:Ue,apiBaseUrl:We,historyRef:re,onMessageSync:ie,onEnd:tt})},`voice`):i.length===0?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Jn,{greetings:Re,recommendations:Le,onSendMessage:w})},`welcome`):(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Gn,{chatHistory:i,isAiTyping:f,isAgentTyping:d,setReplyContext:Ce,TypingDots:$g,primaryColor:Ne,agentHeadshot:qe,agentDisplayName:c||Ge})},`history`)}),(0,k.jsx)(Qn,{webRTCError:S,micError:be,setMicError:xe,dismissCallError:ue,incomingCall:y,rejectCall:se,acceptCall:oe,activeCallId:b,callConnectionState:x,formatCallDuration:nt,callDurationSeconds:we,endWebRTCCall:ce,isCallMuted:te,toggleCallMute:le,isAIVoiceActive:m,currentCallAgentName:Je,isRateLimited:h,rateLimitMessage:g}),!m&&(0,k.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,k.jsx)(Yn,{input:_e,setInput:T,onSubmit:$e,isConversationEnded:_,callUiActive:!!(y||b),handleToggleVoice:et,activeScreen:o,inputDisabled:p||h||_,replyContext:Se,clearReplyContext:()=>Ce(null),requiresEmail:Ze,emailInput:Ee,setEmailInput:De,emailError:Oe})}),!He&&(0,k.jsx)(`div`,{style:{position:`relative`,zIndex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`12px`,paddingTop:`12px`,paddingBottom:`16px`,fontSize:`12px`,color:`#9ca3af`},children:(0,k.jsxs)(`div`,{children:[`Powered by `,(0,k.jsx)(`span`,{style:{color:`#3b82f6`},children:`Flow`}),(0,k.jsx)(`span`,{style:{color:`#ef4444`},children:`Engage`})]})})]})]}):null}var t_=`/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */
|
|
485
|
+
@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-border-style:solid;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-ease:initial}}:root,:host{--spacing:.25rem;--ease-in-out:cubic-bezier(.4, 0, .2, 1);--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.start{inset-inline-start:var(--spacing)}.end{inset-inline-end:var(--spacing)}.container{width:100%}@media (width>=40rem){.container{max-width:40rem}}@media (width>=48rem){.container{max-width:48rem}}@media (width>=64rem){.container{max-width:64rem}}@media (width>=80rem){.container{max-width:80rem}}@media (width>=96rem){.container{max-width:96rem}}.block{display:block}.flex{display:flex}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.flex-shrink{flex-shrink:1}.transform{transform:var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,)}.border{border-style:var(--tw-border-style);border-width:1px}.ring{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.backdrop-filter{-webkit-backdrop-filter:var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.flowengage-shell,.flowengage-shell *{font-family:inherit}.flowengage-chat-panel{border:none;border-radius:0;outline:none;flex-direction:column;width:100%;height:100%;display:flex;position:relative;overflow:hidden;box-shadow:0 20px 50px #00000026}@media (width>=768px){.flowengage-chat-panel{border-radius:24px;width:min(423px,100vw - 40px);height:min(700px,100vh - 120px)}}.flowengage-shell[data-open=true]{inset:0}@media (width>=768px){.flowengage-shell[data-open=true]{inset:auto 1.5rem 1.5rem auto}}.flowengage-logo-fallback{background:conic-gradient(from 180deg, var(--flowengage-primary) 0%, #2b70b5 50%, #f59e0b 100%)}.fe-bot-message p{margin:0 0 .5em}.fe-bot-message p:last-child{margin-bottom:0}.fe-bot-message ul,.fe-bot-message ol{margin:.4em 0 .4em 1.2em;padding:0}.fe-bot-message li{margin-bottom:.25em}.fe-bot-message strong{font-weight:600}.fe-bot-message a{color:var(--flowengage-primary);text-decoration:underline}.fe-bot-message a:hover{opacity:.8}.incoming-call-overlay{z-index:1000;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#1a1a2ef2;justify-content:center;align-items:center;transition:all .3s ease-in-out;display:flex;position:absolute;left:0;right:0}.incoming-call-overlay.bottom-mode{border-top:2px solid #ffffff1a;min-height:120px;animation:.4s cubic-bezier(.16,1,.3,1) slideUpBanner;top:auto;bottom:0;box-shadow:0 -10px 30px #00000080}.incoming-call-overlay.header-mode{border-bottom:2px solid #ffffff1a;min-height:80px;animation:.4s cubic-bezier(.16,1,.3,1) slideDownBanner;top:0;bottom:auto;box-shadow:0 10px 30px #00000080}.incoming-call-container{justify-content:space-between;align-items:center;gap:14px;width:100%;padding:14px 16px;display:flex}.incoming-call-container.connected-layout{flex-direction:column;justify-content:center;align-items:stretch;gap:14px}.call-connected-top{justify-content:space-between;align-items:center;gap:16px;width:100%;display:flex}.call-connected-identity{flex:1;align-items:center;gap:14px;min-width:0;display:flex}.call-icon-wrapper{color:#fff;z-index:1;border-radius:9999px;flex-shrink:0;justify-content:center;align-items:center;width:54px;height:54px;margin-right:4px;display:flex;position:relative}.call-icon-wrapper.incoming{background:linear-gradient(135deg,#4caf50,#45a049);animation:1s ease-in-out infinite bounce}.call-icon-wrapper.connecting{background:linear-gradient(135deg,#2196f3,#1976d2)}.call-icon-wrapper.connected{background:linear-gradient(135deg,#4caf50,#45a049)}.call-pulse-animation{z-index:-1;background:#4caf504d;border-radius:50%;width:120px;height:120px;animation:1.5s ease-out infinite pulse;position:absolute}.call-connecting-animation{z-index:-1;border:3px solid #0000;border-top-color:#2196f3;border-radius:50%;width:100px;height:100px;animation:1s linear infinite spin;position:absolute}.call-info-group{flex-direction:column;flex:1;min-width:0;margin-right:8px;display:flex}.call-title{color:#fff;white-space:normal;text-overflow:clip;margin:0;font-size:16px;font-weight:700;line-height:1.2;overflow:visible}.call-subtitle{color:#ffffffb3;white-space:normal;text-overflow:clip;margin:4px 0 0;font-size:12px;line-height:1.35;overflow:visible}.call-timer{text-align:center;color:#fff;flex-shrink:0;min-width:54px;font-size:13px;font-weight:700}.call-actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.call-actions.connected{justify-content:center;width:100%}.flowengage-call-btn{cursor:pointer;color:#fff;border:none;border-radius:8px;justify-content:center;align-items:center;gap:6px;min-width:92px;padding:8px 12px;font-size:12px;font-weight:600;line-height:1;transition:transform .2s,box-shadow .2s,background .2s;display:flex}.flowengage-call-btn svg{flex-shrink:0;display:block}.flowengage-call-btn span{justify-content:center;align-items:center;line-height:1;display:flex}.flowengage-call-btn.icon-only{border-radius:9999px;width:46px;min-width:46px;height:46px;padding:0}.flowengage-call-btn-accept{background:linear-gradient(135deg,#4caf50,#45a049);box-shadow:0 8px 24px #4caf5066}.flowengage-call-btn-reject,.flowengage-call-btn-end{background:linear-gradient(135deg,#f44336,#d32f2f);box-shadow:0 4px 12px #f4433666}.flowengage-call-btn-mute{background:#ffffff1a;border:2px solid #fff3}.flowengage-call-btn-mute.active{background:#f443364d;border-color:#f44336}.flowengage-call-btn:hover:not(:disabled){transform:scale(1.05)}.incoming-call-overlay.header-mode .flowengage-call-btn{border-radius:9999px!important;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important}.incoming-call-overlay.header-mode .flowengage-call-btn span{display:none!important}.incoming-call-overlay.header-mode .call-icon-wrapper{width:40px;height:40px;margin-right:0}.incoming-call-overlay.header-mode .call-info-group{min-width:0}.incoming-call-overlay.header-mode .call-title,.incoming-call-overlay.header-mode .call-subtitle{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=640px){.incoming-call-container{align-items:flex-start;gap:10px;padding:12px 14px}.incoming-call-container.connected-layout{align-items:stretch}.call-connected-top{flex-direction:column;align-items:flex-start;gap:10px}.call-connected-identity{width:100%}.call-info-group{margin-right:0}.call-actions{flex-wrap:wrap;align-self:stretch;gap:6px}.call-actions.connected{justify-content:stretch}.call-actions.connected .flowengage-call-btn{flex:1}.flowengage-call-btn{min-width:78px;padding:8px 10px}}@keyframes slideUpBanner{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes slideDownBanner{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes bounce{0%,to{animation-timing-function:cubic-bezier(.8,0,1,1);transform:translateY(-25%)}50%{animation-timing-function:cubic-bezier(0,0,.2,1);transform:none}}@keyframes pulse{50%{opacity:.5}}@keyframes spin{to{transform:rotate(360deg)}}.fe-screen-fade-in{animation:.4s cubic-bezier(.16,1,.3,1) forwards feFadeIn}@keyframes feFadeIn{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.flowengage-initial-bg{background-color:#fff;position:relative;overflow:hidden}.flowengage-initial-bg:before{content:"";background:linear-gradient(to bottom, var(--flowengage-primary) 0%, var(--flowengage-primary) 55%, white 82%);opacity:0;pointer-events:none;z-index:0;transition:opacity .6s cubic-bezier(.4,0,.2,1);position:absolute;inset:0}.flowengage-initial-bg.is-initial:before{opacity:1}.flowengage-content-wrapper{z-index:1;flex-direction:column;flex:1;min-height:0;display:flex;position:relative}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}`,n_=null,r_=!1;function i_(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=t_,document.head.appendChild(e)}function a_(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function o_({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(r_){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),a_(()=>o_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let i=document.createElement(`div`);i.id=`flowengage-root`,document.body.appendChild(i),i_(),n_=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};n_.render(v.createElement(wn,{siteId:e,language:t,config:a},v.createElement(e_))),r_=!0}var s_={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>a_(()=>o_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):a_(()=>o_({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){n_&&=(n_.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),r_=!1}},c_=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};a_(()=>o_({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,c_):c_(),typeof window<`u`&&(window.FlowEngage=s_),s_})();
|
|
@@ -462,15 +462,15 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
|
|
|
462
462
|
<path d="M4 2L19 10.5L11 12.8L8 20L4 2Z"
|
|
463
463
|
fill="white" stroke="#1e1b4b" stroke-width="1.6" stroke-linejoin="round"
|
|
464
464
|
filter="url(#${Q}-csh)"/>
|
|
465
|
-
</svg>`,Gh=null,Kh=!1;function qh(){return(!Gh||!Gh.isConnected)&&(Gh=document.createElement(`div`),Gh.id=`${Q}-cursor`,Gh.innerHTML=Wh,document.body.appendChild(Gh),Kh=!1),Gh}async function Jh(e){if(typeof document>`u`||!e)return;Ah();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=qh();Kh||=(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 $h(360)}function Yh(e=!1){Gh&&(e?(Gh.classList.remove(`${Q}-cursor-visible`),Kh=!1):(Gh.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{Kh=!1},250)))}async function Xh(e){Gh&&(Gh.classList.add(`${Q}-cursor-click`),await $h(280),Gh.classList.remove(`${Q}-cursor-click`))}function Zh(e){if(!e||typeof document>`u`)return;Ah();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)}async function Qh(e,t,n){if(!e||!t)return;if(!(t.length<=72&&!/^https?:\/\//i.test(t)&&!/^\d+$/.test(t))){n(e,t);return}let r={bubbles:!0,cancelable:!0,composed:!0};n(e,``),e.dispatchEvent(new Event(`input`,r));for(let i=1;i<=t.length;i++){n(e,t.slice(0,i));try{e.dispatchEvent(new InputEvent(`input`,{...r,inputType:`insertText`,data:t[i-1]}))}catch{e.dispatchEvent(new Event(`input`,r))}await $h(28+Math.random()*27)}e.dispatchEvent(new Event(`change`,r))}function $h(e){return new Promise(t=>setTimeout(t,e))}function $(...e){Xt()&&console.log(`[FlowEngage:voice-tools]`,...e)}var eg=`#flowengage-root, .flowengage-shell`;function tg(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(eg)}catch{return!1}}function ng(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function rg(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(!tg(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function ig(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function ag(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 ig(r.join(` `))}if(e.labels&&e.labels.length)return ig(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return ig(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return ig(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return ig(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=ig(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 ig(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return ig(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?ig(o):null}function og(){let e=[];return rg(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(tg(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}try{if(e.offsetWidth===0&&e.offsetHeight===0)return!1}catch{}return!0}))}),e}function sg(){return og().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:ag(e),placeholder:e.placeholder||null}))}function cg(){let e=[];return rg(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(tg(e)||e.disabled)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)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 lg(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function ug(e){let t=lg(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function dg(e,t){let n=ug(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.type||``).toLowerCase();if(a===`email`&&/email|e-mail|mail/.test(n))return 100;if(a===`tel`&&/phone|mobile|tel|cell/.test(n))return 95;if(a===`url`&&/url|website|domain|link/.test(n))return 100;let o=[e.name,e.id,e.placeholder,ag(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>lg(e)),s=0;for(let e of o){if(!e)continue;if(e===n){s=100;break}if(e.includes(n)||n.includes(e)){s=Math.max(s,96);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);let i=r/t.length;i>0&&(s=Math.max(s,i*88))}return s}var fg=22;function pg(e,t){let n=null,r=0;for(let i of e){let e=dg(i,t);e>r&&(r=e,n=i)}return!n||r<fg?null:n}function mg(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,ag(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 hg(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function gg(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 _g(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 vg(e){if(!_g(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,ag(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 yg(e,t,n){let r=String(t??``),i=String(n??``),a=Sg(e,r)||pg(e,r)||mg(e,r,i);if(!a)return[];let o=new Set([a]);if(hg(i)&&gg(r))for(let t of e)t!==a&&vg(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 bg(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 xg(e){if(!e||typeof e!=`string`)return null;let t=null;return rg(n=>{try{let r=n.getElementById(e);r&&!tg(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Sg(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=xg(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=xg(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 Cg(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===n)return 100;if(r.includes(n))return 98;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 wg(e,t){let n=[];rg(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(tg(e)||e.disabled)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Cg(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=bg(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function Tg(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 Eg(e){let t=Tg(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 Dg(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 Og(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 kg(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 Ag(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 jg(e){let t=e.ownerDocument?.defaultView||window,n=e.tagName===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`);return(e,t)=>{try{e._valueTracker&&e._valueTracker.setValue(``)}catch{}r?.set?r.set.call(e,t):e.value=t}}async function Mg(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{await Jh(e)}catch{}try{Hh(e)}catch{}await new Promise(e=>setTimeout(e,180));try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase(),a={bubbles:!0,cancelable:!0,composed:!0};if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a)),Uh(e),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),Uh(e),!0;let o=String(t);r===`INPUT`||r===`TEXTAREA`?await Qh(e,o,jg(e)):(e.value=o,e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a));try{e.focus({preventScroll:!0})}catch{}try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}try{Uh(e)}catch{}return!0}function Ng(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async n=>{$(`navigate_to_page ▶ raw parameters:`,n);let r=Tg(n),i=kg(r),a=r.section_text??r.sectionText??r.section;if($(`navigate_to_page · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`navigate_to_page ✖`,e),e}if(Ph(`Navigating to ${i.replace(/^https?:\/\/[^/]+/,``)||`/`}…`),zh(),!await cn(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){Bh(),Fh(200);let e=`That page is not available in the site index; answer without navigating.`;return $(`navigate_to_page ✖ blocked`,e),e}try{if($(`navigate_to_page → shadowNavigate`,i),await un(i,{sectionText:a||void 0}),await new Promise(e=>setTimeout(e,600)),Bh(),Fh(300),a&&typeof a==`string`){let e=nn(null,a);e&&rn(e),$(`navigate_to_page · highlight`,{sectionText:a,found:!!e})}let e=`OK_NAVIGATION ${i}`;return $(`navigate_to_page ✓`,e),e}catch(e){Bh(),Fh(200);let t=`Navigation error: ${e?.message||String(e)}`;return $(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{$(`highlight_on_page ▶`,e);let t=Tg(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=nn(n||null,r||null);return i?(rn(i),$(`highlight_on_page ✓`),`Highlighted the section.`):($(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{$(`search_site_content ▶`,e);let r=Ag(Tg(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),Ph(`Searching site content…`,{spinner:!0}),!r)return Fh(),$(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return Fh(),$(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return Fh(),$(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`search_site_content → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`search_site_content · HTTP`,i.status,`success:`,a.success),Fh(200),!a.success){let e=a.error||`Search failed.`;return $(`search_site_content ✖`,e),e}let o=a.results||[];return $(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){Fh();let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},end_voice_session:async()=>($(`end_voice_session ▶`),Ph(`Ending voice session…`,{icon:`👋`,spinner:!1,duration:2e3}),Yh(!0),Vh(),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),list_page_forms:async()=>{let e=sg(),t=cg();return $(`list_page_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, fill_form_fields sets all matching URL inputs. click_page_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},fill_form_fields:async e=>{try{$(`fill_form_fields ▶ raw:`,e);let t=Eg(e);if(!t.length&&r){let e=r(),n=Dg(e);n.length?$(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=Og(e),n.length&&$(`fill_form_fields · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms for field_key strings, then fill_form_fields 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.`;t.length>1&&Ph(`Filling ${t.length} fields…`);let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;Ph(`Filling ${t}…`),$(`fill_form_fields · processing field:`,t,`=`,r);let a=og();$(`fill_form_fields · visible inputs count:`,a.length);let o=yg(a,String(t),r);if(o.length){for(let e=0;e<o.length;e++)await Mg(o[e],r,{skipScroll:e>0}),await new Promise(e=>setTimeout(e,80));i=o,n.push(String(t));continue}let s=Sg(a,String(t));s||=pg(a,String(t)),s||=mg(a,String(t),r),s?(await Mg(s,r),i=[s],n.push(String(t))):$(`fill_form_fields · no match for field:`,t)}Fh(400);try{Yh()}catch{}if(!n.length)return $(`fill_form_fields ✖ no matches`),`Could not match any fields. Call list_page_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 $(`fill_form_fields ✓`,a),a}catch(e){Fh(),Vh(),Yh(!0);let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Tg(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;Ph(`Clicking "${n}"…`);let r=wg(n,i);if(!r)return Fh(200),$(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{try{r.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}try{await Jh(r)}catch{}try{Zh(r)}catch{}try{await Xh(r)}catch{}r.focus?.(),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`;Fh(600);try{Yh()}catch{}Vh();let t=`OK_CLICK ${e}`;return $(`click_page_button ✓`,t),t}catch(e){Fh(200),Yh(!0);let t=`Click failed: ${e?.message||String(e)}`;return $(`click_page_button ✖`,t),t}}};return{...a,navigateToPage:a.navigate_to_page,highlightOnPage:a.highlight_on_page,searchSiteContent:a.search_site_content,endVoiceSession:a.end_voice_session,listPageForms:a.list_page_forms,fillFormFields:a.fill_form_fields,clickPageButton:a.click_page_button}}function Pg(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Xt();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i=await t(n),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 Fg={idle:`rgba(99,102,241,0.18)`,listening:`rgba(16,185,129,0.25)`,speaking:`rgba(245,158,11,0.25)`,error:`rgba(239,68,68,0.2)`},Ig={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Lg(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 Rg({agentId:e,chatId:t,siteId:n,apiBaseUrl:r,onEnd:i,historyRef:a,hasSyncedRef:o,onMessageSync:s,onStartSync:c}){let[d,f]=(0,l.useState)(`idle`),[p,m]=(0,l.useState)(null),[ee,h]=(0,l.useState)(!1),g=(0,l.useRef)(null),_=(0,l.useRef)(null),te=(0,l.useRef)(``),v=(0,l.useRef)(async()=>{}),ne=(0,l.useRef)(!1),re=(0,l.useCallback)(async()=>{try{await g.current?.endSession?.()}catch{}g.current=null,h(!1),f(`idle`),ne.current=!1,typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]);v.current=re,(0,l.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;a.current=[],te.current=``,ne.current=!1;let o=Pg(Ng({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>te.current,requestEndSession:()=>{queueMicrotask(()=>{ne.current||(ne.current=!0,v.current?.())})}})),s=await kh.startSession({agentId:e,clientTools:o,onUnhandledClientToolCall:e=>{console.error(`[VoiceInterface] ElevenLabs requested a client tool that is not registered in the widget:`,e?.tool_name,e?.parameters,`Add a matching handler in voiceClientTools (snake_case and camelCase are both supported).`)},onModeChange:({mode:e})=>{t||f(e===`speaking`?`speaking`:`listening`)},onMessage:e=>{if(t)return;let n=e.role===`user`?`user`:`bot`,r=e.message||e.text||e.content||``;if(!r)return;let i={sender:n,message:r,timestamp:new Date().toISOString()};n===`user`&&(te.current=r),a.current=[...a.current,i],Lg(n,r)&&queueMicrotask(()=>{ne.current||(ne.current=!0,v.current?.())})},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),f(`error`),m(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),h(!1),f(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,g.current=s,h(!0),f(`listening`);try{let e=typeof window<`u`?window.location.href:``,t=``;try{t=await o.list_page_forms()}catch{t=`[]`}s.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${n||`unknown`}. Page fields/buttons JSON: ${t}. Navigation: search_site_content then navigate_to_page with section_text when relevant — no permission ask. Forms: use fill_form_fields then click_page_button (e.g. Conduct Audit) when the user wants to submit. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end; you may also say you are ending the voice session.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),f(`error`),m(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):g.current&&g.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let ie=d===`listening`||d===`speaking`,ae=Ig[d]||Ig.idle,oe=Fg[d]||Fg.idle;return(0,u.jsxs)(`div`,{ref:_,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,u.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[ie&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ae}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),ie&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ae}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,u.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:oe,border:`3px solid ${ae}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:d===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${oe}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,u.jsx)(bn,{size:44,color:ae})})]}),(0,u.jsxs)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:d===`error`?`#ef4444`:`#374151`,letterSpacing:`0.01em`,textAlign:`center`},children:[d===`idle`&&`Starting voice session…`,d===`listening`&&`Listening…`,d===`speaking`&&`AI is speaking…`,d===`error`&&(p||`Error`)]}),(0,u.jsxs)(`button`,{onClick:re,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`12px 24px`,borderRadius:`999px`,background:`#fee2e2`,color:`#dc2626`,border:`1px solid #fca5a5`,fontWeight:600,fontSize:`14px`,cursor:`pointer`,transition:`all 0.2s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#fecaca`},onMouseLeave:e=>{e.currentTarget.style.background=`#fee2e2`},children:[(0,u.jsx)(xn,{size:18}),`End Voice Session`]}),(0,u.jsx)(`style`,{children:`
|
|
465
|
+
</svg>`,Gh=null,Kh=!1;function qh(){return(!Gh||!Gh.isConnected)&&(Gh=document.createElement(`div`),Gh.id=`${Q}-cursor`,Gh.innerHTML=Wh,document.body.appendChild(Gh),Kh=!1),Gh}async function Jh(e){if(typeof document>`u`||!e)return;Ah();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=qh();Kh||=(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 $h(360)}function Yh(e=!1){Gh&&(e?(Gh.classList.remove(`${Q}-cursor-visible`),Kh=!1):(Gh.classList.remove(`${Q}-cursor-visible`),setTimeout(()=>{Kh=!1},250)))}async function Xh(e){Gh&&(Gh.classList.add(`${Q}-cursor-click`),await $h(280),Gh.classList.remove(`${Q}-cursor-click`))}function Zh(e){if(!e||typeof document>`u`)return;Ah();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)}async function Qh(e,t,n){if(!e||!t)return;if(!(t.length<=72&&!/^https?:\/\//i.test(t)&&!/^\d+$/.test(t))){n(e,t);return}let r={bubbles:!0,cancelable:!0,composed:!0};n(e,``),e.dispatchEvent(new Event(`input`,r));for(let i=1;i<=t.length;i++){n(e,t.slice(0,i));try{e.dispatchEvent(new InputEvent(`input`,{...r,inputType:`insertText`,data:t[i-1]}))}catch{e.dispatchEvent(new Event(`input`,r))}await $h(28+Math.random()*27)}e.dispatchEvent(new Event(`change`,r))}function $h(e){return new Promise(t=>setTimeout(t,e))}function $(...e){Xt()&&console.log(`[FlowEngage:voice-tools]`,...e)}var eg=`#flowengage-root, .flowengage-shell`;function tg(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(eg)}catch{return!1}}function ng(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function rg(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(!tg(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function ig(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function ag(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 ig(r.join(` `))}if(e.labels&&e.labels.length)return ig(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return ig(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return ig(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return ig(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=ig(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 ig(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return ig(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?ig(o):null}function og(){let e=[];return rg(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(tg(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}try{if(e.offsetWidth===0&&e.offsetHeight===0)return!1}catch{}return!0}))}),e}function sg(){return og().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:ag(e),placeholder:e.placeholder||null}))}function cg(){let e=[];return rg(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(tg(e)||e.disabled)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)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 lg(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function ug(e){let t=lg(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function dg(e,t){let n=ug(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.type||``).toLowerCase();if(a===`email`&&/email|e-mail|mail/.test(n))return 100;if(a===`tel`&&/phone|mobile|tel|cell/.test(n))return 95;if(a===`url`&&/url|website|domain|link/.test(n))return 100;let o=[e.name,e.id,e.placeholder,ag(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>lg(e)),s=0;for(let e of o){if(!e)continue;if(e===n){s=100;break}if(e.includes(n)||n.includes(e)){s=Math.max(s,96);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);let i=r/t.length;i>0&&(s=Math.max(s,i*88))}return s}var fg=22;function pg(e,t){let n=null,r=0;for(let i of e){let e=dg(i,t);e>r&&(r=e,n=i)}return!n||r<fg?null:n}function mg(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,ag(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 hg(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function gg(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 _g(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 vg(e){if(!_g(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,ag(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 yg(e,t,n){let r=String(t??``),i=String(n??``),a=Sg(e,r)||pg(e,r)||mg(e,r,i);if(!a)return[];let o=new Set([a]);if(hg(i)&&gg(r))for(let t of e)t!==a&&vg(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 bg(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 xg(e){if(!e||typeof e!=`string`)return null;let t=null;return rg(n=>{try{let r=n.getElementById(e);r&&!tg(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Sg(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=xg(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=xg(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 Cg(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===n)return 100;if(r.includes(n))return 98;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 wg(e,t){let n=[];rg(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(tg(e)||e.disabled)return!1;try{let t=ng(e);if(t.display===`none`||t.visibility===`hidden`||parseFloat(t.opacity)===0)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Cg(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=bg(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function Tg(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 Eg(e){let t=Tg(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 Dg(e){if(!e||typeof e!=`string`)return e;let t=e.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?t:(t=t.replace(/\s+at\s+the\s+rate\s*(of)?\s+/gi,`@`),t=t.replace(/\s+at\s+/gi,`@`),t=t.replace(/\s+dot\s+/gi,`.`),t=t.replace(/\s+/g,``),t=t.replace(/\.{2,}/g,`.`).replace(/\.$/,``),t)}function Og(e){if(!e||typeof e!=`string`)return e;let t={zero:`0`,one:`1`,two:`2`,three:`3`,four:`4`,five:`5`,six:`6`,seven:`7`,eight:`8`,nine:`9`,oh:`0`,o:`0`},n=e.toLowerCase().trim();for(let[e,r]of Object.entries(t))n=n.replace(RegExp(`\\b${e}\\b`,`g`),r);return n=n.replace(/[^\d+]/g,``),n}function kg(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 Ag(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=Dg(t),s=i.test(o),c=o.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);if(c)return a(`Email Address`,c[1]),n;if(!i.test(t)&&s){let e=o.match(i);if(e)return a(`Email Address`,e[1]),n}let l=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(l&&a(`Full Name`,l[1]),l=t.match(/\bfull\s*name,?\s*(?:please\s+)?(?:enter|type|put)\s+(.+?)(?:\.|$|!|\?)/i),l&&a(`Full Name`,l[1]),l=t.match(/\bfull\s*name\s*(?:is|:|please\s+enter|-)\s*(.+?)(?:\.|$|(?=\s+(?:and|my\s+email|email|message))\b)/i),l&&a(`Full Name`,l[1]),l=t.match(/\b(.+?)\s+for\s+(?:the\s+)?full\s*name\b/i),l){let e=l[1].trim();e.length>1&&e.length<120&&!/@/.test(e)&&a(`Full Name`,e)}if(l=t.match(/\b(?:email|e-mail)(?:\s*address)?\s*(?:is|:|please\s+use|enter|-)\s*([^\s@]+@[^\s@]+\.[^\s,]+)/i),l&&a(`Email Address`,l[1]),l=t.match(/\b(?:enter|type|put)\s+([^\s@]+@[^\s@]+\.[^\s,]+)\s+in(?:to)?\s+(?:the\s+)?(?:email|e-mail)/i),l&&a(`Email Address`,l[1]),l=t.match(/\b(?:message|comment)\s*(?:is|:|please\s+enter|-)\s*(.+)$/is),l){let e=l[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 jg(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 Mg(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 Ng(e){let t=e.ownerDocument?.defaultView||window,n=e.tagName===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`);return(e,t)=>{try{e._valueTracker&&e._valueTracker.setValue(``)}catch{}r?.set?r.set.call(e,t):e.value=t}}async function Pg(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{await Jh(e)}catch{}try{Hh(e)}catch{}await new Promise(e=>setTimeout(e,180));try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase(),a={bubbles:!0,cancelable:!0,composed:!0};if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a)),Uh(e),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a)),Uh(e),!0;let o=String(t);r===`INPUT`||r===`TEXTAREA`?await Qh(e,o,Ng(e)):(e.value=o,e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))),e.dispatchEvent(new Event(`change`,a)),e.dispatchEvent(new Event(`blur`,a));try{e.focus({preventScroll:!0})}catch{}try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}try{Uh(e)}catch{}return!0}function Fg(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async n=>{$(`navigate_to_page ▶ raw parameters:`,n);let r=Tg(n),i=jg(r),a=r.section_text??r.sectionText??r.section;if($(`navigate_to_page · coerced:`,{url:i,sectionText:a}),!i){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return $(`navigate_to_page ✖`,e),e}if(Ph(`Navigating to ${i.replace(/^https?:\/\/[^/]+/,``)||`/`}…`),zh(),!await cn(i,{siteId:t,apiBaseUrl:e.apiBaseUrl})){Bh(),Fh(200);let e=`That page is not available in the site index; answer without navigating.`;return $(`navigate_to_page ✖ blocked`,e),e}try{if($(`navigate_to_page → shadowNavigate`,i),await un(i,{sectionText:a||void 0}),await new Promise(e=>setTimeout(e,600)),Bh(),Fh(300),a&&typeof a==`string`){let e=nn(null,a);e&&rn(e),$(`navigate_to_page · highlight`,{sectionText:a,found:!!e})}let e=``;try{let t=sg(),n=cg();if(t.length>0){let r=t.map(e=>e.label||e.placeholder||e.name||e.id).filter(Boolean).join(`, `),i=n.map(e=>e.text).filter(Boolean).join(`, `);e=` This page has a form with fields: [${r}]`+(i?` and buttons: [${i}].`:`.`)+` Call list_page_forms then start filling.`}}catch{}let t=`OK_NAVIGATION ${i}${e}`;return $(`navigate_to_page ✓`,t),t}catch(e){Bh(),Fh(200);let t=`Navigation error: ${e?.message||String(e)}`;return $(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{$(`highlight_on_page ▶`,e);let t=Tg(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=nn(n||null,r||null);return i?(rn(i),$(`highlight_on_page ✓`),`Highlighted the section.`):($(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{$(`search_site_content ▶`,e);let r=Mg(Tg(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),Ph(`Searching site content…`,{spinner:!0}),!r)return Fh(),$(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return Fh(),$(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return Fh(),$(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;$(`search_site_content → POST`,e);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({siteId:t,query:r,currentUrl:typeof window<`u`?window.location.href:``})}),a=await i.json();if($(`search_site_content · HTTP`,i.status,`success:`,a.success),Fh(200),!a.success){let e=a.error||`Search failed.`;return $(`search_site_content ✖`,e),e}let o=a.results||[];return $(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){Fh();let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},end_voice_session:async()=>($(`end_voice_session ▶`),Ph(`Ending voice session…`,{icon:`👋`,spinner:!1,duration:2e3}),Yh(!0),Vh(),typeof e.requestEndSession==`function`&&e.requestEndSession(),`Voice session is ending.`),list_page_forms:async()=>{let e=sg(),t=cg();return $(`list_page_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, fill_form_fields sets all matching URL inputs. click_page_button picks the Conduct Audit nearest the filled field when labels duplicate.`})},fill_form_fields:async e=>{try{$(`fill_form_fields ▶ raw:`,e);let t=Eg(e);if(!t.length&&r){let e=r(),n=kg(e);n.length?$(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=Ag(e),n.length&&$(`fill_form_fields · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if($(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms for field_key strings, then fill_form_fields 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.`;t.length>1&&Ph(`Filling ${t.length} fields…`);let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;let a=String(t).toLowerCase();/email|e-mail|mail/.test(a)?r=Dg(r):/phone|mobile|tel|cell/.test(a)&&(r=Og(r)),Ph(`Filling ${t}…`),$(`fill_form_fields · processing field:`,t,`=`,r);let o=og();$(`fill_form_fields · visible inputs count:`,o.length);let s=yg(o,String(t),r);if(s.length){for(let e=0;e<s.length;e++)await Pg(s[e],r,{skipScroll:e>0}),await new Promise(e=>setTimeout(e,80));i=s,n.push(String(t));continue}let c=Sg(o,String(t));c||=pg(o,String(t)),c||=mg(o,String(t),r),c?(await Pg(c,r),i=[c],n.push(String(t))):$(`fill_form_fields · no match for field:`,t)}Fh(400);try{Yh()}catch{}if(!n.length)return $(`fill_form_fields ✖ no matches`),`Could not match any fields. Call list_page_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 $(`fill_form_fields ✓`,a),a}catch(e){Fh(),Vh(),Yh(!0);let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Tg(e),n=(t.button_text??t.buttonText??t.text??``).trim();if($(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;Ph(`Clicking "${n}"…`);let r=wg(n,i);if(!r)return Fh(200),$(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{try{r.scrollIntoView({behavior:`smooth`,block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}try{await Jh(r)}catch{}try{Zh(r)}catch{}try{await Xh(r)}catch{}r.focus?.(),r.click();let e=(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`;Fh(600);try{Yh()}catch{}Vh();let t=`OK_CLICK ${e}`;return $(`click_page_button ✓`,t),t}catch(e){Fh(200),Yh(!0);let t=`Click failed: ${e?.message||String(e)}`;return $(`click_page_button ✖`,t),t}}};return{...a,navigateToPage:a.navigate_to_page,highlightOnPage:a.highlight_on_page,searchSiteContent:a.search_site_content,endVoiceSession:a.end_voice_session,listPageForms:a.list_page_forms,fillFormFields:a.fill_form_fields,clickPageButton:a.click_page_button}}function Ig(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Xt();r?console.log(`[FlowEngage:voice-tool] ▶`,e,n):console.info(`[FlowEngage] voice tool » ${e}`);let i=await t(n),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 Lg={idle:`rgba(99,102,241,0.18)`,listening:`rgba(16,185,129,0.25)`,speaking:`rgba(245,158,11,0.25)`,error:`rgba(239,68,68,0.2)`},Rg={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function zg(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 Bg({agentId:e,chatId:t,siteId:n,apiBaseUrl:r,onEnd:i,historyRef:a,hasSyncedRef:o,onMessageSync:s,onStartSync:c}){let[d,f]=(0,l.useState)(`idle`),[p,m]=(0,l.useState)(null),[ee,h]=(0,l.useState)(!1),g=(0,l.useRef)(null),_=(0,l.useRef)(null),te=(0,l.useRef)(``),v=(0,l.useRef)(async()=>{}),ne=(0,l.useRef)(!1),re=(0,l.useCallback)(async()=>{try{await g.current?.endSession?.()}catch{}g.current=null,h(!1),f(`idle`),ne.current=!1,typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]);v.current=re,(0,l.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;a.current=[],te.current=``,ne.current=!1;let o=Ig(Fg({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>te.current,requestEndSession:()=>{queueMicrotask(()=>{ne.current||(ne.current=!0,v.current?.())})}})),s=await kh.startSession({agentId:e,clientTools:o,onUnhandledClientToolCall:e=>{console.error(`[VoiceInterface] ElevenLabs requested a client tool that is not registered in the widget:`,e?.tool_name,e?.parameters,`Add a matching handler in voiceClientTools (snake_case and camelCase are both supported).`)},onModeChange:({mode:e})=>{t||f(e===`speaking`?`speaking`:`listening`)},onMessage:e=>{if(t)return;let n=e.role===`user`?`user`:`bot`,r=e.message||e.text||e.content||``;if(!r)return;let i={sender:n,message:r,timestamp:new Date().toISOString()};n===`user`&&(te.current=r),a.current=[...a.current,i],zg(n,r)&&queueMicrotask(()=>{ne.current||(ne.current=!0,v.current?.())})},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),f(`error`),m(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),h(!1),f(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,g.current=s,h(!0),f(`listening`);try{let e=typeof window<`u`?window.location.href:``,t=``;try{t=await o.list_page_forms()}catch{t=`[]`}let r=``;try{let e=await o.search_site_content({query:`pages`}),t=typeof e==`string`?JSON.parse(e):e;Array.isArray(t)&&t.length&&(r=` Site pages available: ${t.map(e=>`${e.title||``} (${e.url||``})`).join(`, `)}.`)}catch{}s.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${n||`unknown`}. Page fields/buttons JSON: ${t}.${r} Navigation: when the user wants to go to any page (contact, pricing, about, services, etc.), call search_site_content then navigate_to_page immediately — never ask permission. After navigating to a page with a form, call list_page_forms and proactively start helping the user fill it. Forms: use fill_form_fields then click_page_button (e.g. Conduct Audit, Send Message) when the user wants to submit. Fill each field immediately after the user answers — never skip ahead. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),f(`error`),m(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):g.current&&g.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let ie=d===`listening`||d===`speaking`,ae=Rg[d]||Rg.idle,oe=Lg[d]||Lg.idle;return(0,u.jsxs)(`div`,{ref:_,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,u.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[ie&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ae}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),ie&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ae}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,u.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:oe,border:`3px solid ${ae}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:d===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${oe}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,u.jsx)(bn,{size:44,color:ae})})]}),(0,u.jsxs)(`div`,{style:{fontSize:`15px`,fontWeight:600,color:d===`error`?`#ef4444`:`#374151`,letterSpacing:`0.01em`,textAlign:`center`},children:[d===`idle`&&`Starting voice session…`,d===`listening`&&`Listening…`,d===`speaking`&&`AI is speaking…`,d===`error`&&(p||`Error`)]}),(0,u.jsxs)(`button`,{onClick:re,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`12px 24px`,borderRadius:`999px`,background:`#fee2e2`,color:`#dc2626`,border:`1px solid #fca5a5`,fontWeight:600,fontSize:`14px`,cursor:`pointer`,transition:`all 0.2s ease`},onMouseEnter:e=>{e.currentTarget.style.background=`#fecaca`},onMouseLeave:e=>{e.currentTarget.style.background=`#fee2e2`},children:[(0,u.jsx)(xn,{size:18}),`End Voice Session`]}),(0,u.jsx)(`style`,{children:`
|
|
466
466
|
@keyframes fe-orb-pulse {
|
|
467
467
|
0% { transform: scale(1); opacity: 0.6; }
|
|
468
468
|
50% { transform: scale(1.18); opacity: 0.15; }
|
|
469
469
|
100% { transform: scale(1); opacity: 0.6; }
|
|
470
470
|
}
|
|
471
|
-
`})]})}var
|
|
471
|
+
`})]})}var Vg=[{key:`become_client`,label:`Become a Client`},{key:`sales_enquiry`,label:`Sales Enquiry`},{key:`learn_services`,label:`Learn about our Services`},{key:`get_support`,label:`Get Support`},{key:`looking_for_job`,label:`Looking for a Job`}],Hg=()=>(0,u.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,u.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`5px`,padding:`12px 16px`,borderRadius:`18px`,background:`#fff`,color:`#111827`,boxShadow:`0 2px 6px rgba(0,0,0,0.04)`},children:[[0,1,2].map(e=>(0,u.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)),(0,u.jsx)(`style`,{children:`
|
|
472
472
|
@keyframes fe-dot-bounce {
|
|
473
473
|
0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
|
|
474
474
|
40% { transform: translateY(-5px); opacity: 1; }
|
|
475
475
|
}
|
|
476
|
-
`})]})});function
|
|
476
|
+
`})]})});function Ug(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,agentHeadshot:d,visitorEmail:f,isAgentTyping:p,isAiTyping:m,isLoading:ee,isVoiceMode:h,isRateLimited:g,rateLimitMessage:_,isConversationEnded:te,incomingCall:v,activeCallId:ne,callConnectionState:re,callConnectedAt:ie,isCallMuted:ae,webRTCError:oe,language:se,historyRef:ce,onMessageSync:y,endConversation:le,acceptCall:ue,rejectCall:de,endWebRTCCall:fe,toggleCallMute:pe,dismissCallError:me,captureVisitorEmail:he,openWidget:ge,closeWidget:_e,sendMessage:ve,setVoiceMode:ye,startTyping:be,stopTyping:xe,updateTypingDraft:Se}=Yt(),[Ce,we]=(0,l.useState)(``),[Te,Ee]=(0,l.useState)(null),[De,Oe]=(0,l.useState)(null),[ke,Ae]=(0,l.useState)(null),[je,Me]=(0,l.useState)(0),[Ne,b]=(0,l.useState)(f||``),[Pe,Fe]=(0,l.useState)(``);(0,l.useEffect)(()=>{try{en()}catch{}},[]);let x=t?.widgetSettings||{},Ie=n?.widgetSettings||{},Le={...Ie.branding||{},...x.branding||{}},Re={...Ie.theme||{},...x.theme||{}},ze=Re.primaryColor||`#3B82F6`,Be=Re.accentColor||`#1D4ED8`,Ve=(Re.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},He={"--flowengage-primary":ze,"--flowengage-accent":Be,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:Ve},Ue=x.recommendations?.[se]||Ie.recommendations?.[se]||Vg,We=x.greetings?.[se]||Ie.greetings?.[se],Ge=Le.chatButtonText||`Chat with us`,Ke=Le.headerName||t?.websiteName||`OpenSense Labs`,S=Le.logoUrl||null,C=Le.hideWatermark||!1,w=Ie.elevenLabsAgentId||t?.elevenLabsAgentId||null,qe=t?.siteId||n?.siteId||null,Je=t?.apiBaseUrl||``,Ye=Le.fallbackAgentName||`Agent`,Xe=Le.botLabel||`AI`,Ze=d&&String(d).trim()||t?.ownerProfileImageUrl&&String(t.ownerProfileImageUrl).trim()||null,Qe=v?.agentName||c||Ye,$e=i.some(e=>e.sender===`user`),et=(0,l.useMemo)(()=>{let e=i.findIndex(e=>e.sender===`user`);return e===-1?!1:i.slice(e+1).some(e=>e.sender===`bot`||e.sender===`ai`||e.sender===`agent`)},[i]),tt=!f&&$e&&et;(0,l.useEffect)(()=>{b(f||``),f&&Fe(``)},[f]),(0,l.useEffect)(()=>{if(!ie||re!==`connected`){Me(0);return}let e=()=>{let e=new Date(ie).getTime();isNaN(e)||Me(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[ie,re]),(0,l.useEffect)(()=>{if(!s||h||te){Se(``),xe();return}if(!Ce.trim()){Se(``),xe();return}be();let e=window.setTimeout(()=>{Se(Ce)},120),t=window.setTimeout(()=>{xe()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[Ce,s,h,te,be,xe,Se]);let nt=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,rt=async e=>{if(e.preventDefault(),te)return;if(tt){let e=Ne.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){Fe(`Please enter a valid email so we can continue helping you.`);return}await he(e),Fe(``);return}if(!Ce.trim())return;let t=Ce.trim(),n=nt(ke);we(``),Ae(null),await ve(t,``,n)},it=async()=>{if(tt){Fe(`Please share your email before starting a call.`);return}if(h){ye(!1);return}Oe(null);try{Ee(await navigator.mediaDevices.getUserMedia({audio:!0})),ye(!0)}catch(e){Oe(e.message||`Could not access microphone.`)}},at=()=>{Te&&(Te.getTracks().forEach(e=>e.stop()),Ee(null)),ye(!1)},ot=e=>{let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`};return e===`ready`?(0,u.jsxs)(`div`,{className:`flowengage-shell`,"data-open":a?`true`:`false`,style:He,children:[(0,u.jsx)(On,{isOpen:a,openWidget:ge,launcherText:Ge,primaryColor:ze,posInline:Ve}),a&&(0,u.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!h?`linear-gradient(to bottom, ${ze} 0%, ${ze} 70%, white 85%)`:`white`},children:[(0,u.jsx)(Nn,{logoUrl:S,brandName:Ke,agentName:c,fallbackAgentName:Ye,activeScreen:o,branding:Le,isConversationEnded:te,endConversation:le,closeWidget:_e,isInitial:i.length===0&&!h,botLabel:Xe,agentAvatarUrl:o===`agent`?Ze:null,primaryColor:ze}),(0,u.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:h?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Bg,{agentId:w,chatId:r,siteId:qe,apiBaseUrl:Je,historyRef:ce,onMessageSync:y,onEnd:at})},`voice`):i.length===0?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Vn,{greetings:We,recommendations:Ue,onSendMessage:ve})},`welcome`):(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Rn,{chatHistory:i,isAiTyping:m,isAgentTyping:p,setReplyContext:Ae,TypingDots:Hg,primaryColor:ze,agentHeadshot:Ze,agentDisplayName:c||Ye})},`history`)}),(0,u.jsx)(Gn,{webRTCError:oe,micError:De,setMicError:Oe,dismissCallError:me,incomingCall:v,rejectCall:de,acceptCall:ue,activeCallId:ne,callConnectionState:re,formatCallDuration:ot,callDurationSeconds:je,endWebRTCCall:fe,isCallMuted:ae,toggleCallMute:pe,isAIVoiceActive:h,currentCallAgentName:Qe,isRateLimited:g,rateLimitMessage:_}),!h&&(0,u.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,u.jsx)(Hn,{input:Ce,setInput:we,onSubmit:rt,isConversationEnded:te,callUiActive:!!(v||ne),handleToggleVoice:it,activeScreen:o,inputDisabled:ee||g||te,replyContext:ke,clearReplyContext:()=>Ae(null),requiresEmail:tt,emailInput:Ne,setEmailInput:b,emailError:Pe})}),!C&&(0,u.jsx)(`div`,{style:{position:`relative`,zIndex:1,display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`12px`,paddingTop:`12px`,paddingBottom:`16px`,fontSize:`12px`,color:`#9ca3af`},children:(0,u.jsxs)(`div`,{children:[`Powered by `,(0,u.jsx)(`span`,{style:{color:`#3b82f6`},children:`Flow`}),(0,u.jsx)(`span`,{style:{color:`#ef4444`},children:`Engage`})]})})]})]}):null}exports.FlowEngageProvider=_n,exports.FlowEngageWidget=Ug,exports.useFlowEngage=Yt;
|
|
@@ -22526,6 +22526,30 @@ function Og(e) {
|
|
|
22526
22526
|
})) : [];
|
|
22527
22527
|
}
|
|
22528
22528
|
function kg(e) {
|
|
22529
|
+
if (!e || typeof e != "string") return e;
|
|
22530
|
+
let t = e.trim();
|
|
22531
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t) ? t : (t = t.replace(/\s+at\s+the\s+rate\s*(of)?\s+/gi, "@"), t = t.replace(/\s+at\s+/gi, "@"), t = t.replace(/\s+dot\s+/gi, "."), t = t.replace(/\s+/g, ""), t = t.replace(/\.{2,}/g, ".").replace(/\.$/, ""), t);
|
|
22532
|
+
}
|
|
22533
|
+
function Ag(e) {
|
|
22534
|
+
if (!e || typeof e != "string") return e;
|
|
22535
|
+
let t = {
|
|
22536
|
+
zero: "0",
|
|
22537
|
+
one: "1",
|
|
22538
|
+
two: "2",
|
|
22539
|
+
three: "3",
|
|
22540
|
+
four: "4",
|
|
22541
|
+
five: "5",
|
|
22542
|
+
six: "6",
|
|
22543
|
+
seven: "7",
|
|
22544
|
+
eight: "8",
|
|
22545
|
+
nine: "9",
|
|
22546
|
+
oh: "0",
|
|
22547
|
+
o: "0"
|
|
22548
|
+
}, n = e.toLowerCase().trim();
|
|
22549
|
+
for (let [e, r] of Object.entries(t)) n = n.replace(RegExp(`\\b${e}\\b`, "g"), r);
|
|
22550
|
+
return n = n.replace(/[^\d+]/g, ""), n;
|
|
22551
|
+
}
|
|
22552
|
+
function jg(e) {
|
|
22529
22553
|
if (!e || typeof e != "string") return [];
|
|
22530
22554
|
let t = e.trim();
|
|
22531
22555
|
if (!t || /\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\b/i.test(t)) return [];
|
|
@@ -22544,7 +22568,7 @@ function kg(e) {
|
|
|
22544
22568
|
}
|
|
22545
22569
|
return [];
|
|
22546
22570
|
}
|
|
22547
|
-
function
|
|
22571
|
+
function Mg(e) {
|
|
22548
22572
|
if (!e || typeof e != "string") return [];
|
|
22549
22573
|
let t = e.trim();
|
|
22550
22574
|
if (!t) return [];
|
|
@@ -22556,15 +22580,19 @@ function Ag(e) {
|
|
|
22556
22580
|
field_key: e,
|
|
22557
22581
|
value: i
|
|
22558
22582
|
}));
|
|
22559
|
-
}, o = t.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);
|
|
22560
|
-
if (
|
|
22561
|
-
|
|
22562
|
-
|
|
22563
|
-
|
|
22583
|
+
}, o = kg(t), s = i.test(o), c = o.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);
|
|
22584
|
+
if (c) return a("Email Address", c[1]), n;
|
|
22585
|
+
if (!i.test(t) && s) {
|
|
22586
|
+
let e = o.match(i);
|
|
22587
|
+
if (e) return a("Email Address", e[1]), n;
|
|
22588
|
+
}
|
|
22589
|
+
let l = 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);
|
|
22590
|
+
if (l && a("Full Name", l[1]), l = t.match(/\bfull\s*name,?\s*(?:please\s+)?(?:enter|type|put)\s+(.+?)(?:\.|$|!|\?)/i), l && a("Full Name", l[1]), l = t.match(/\bfull\s*name\s*(?:is|:|please\s+enter|-)\s*(.+?)(?:\.|$|(?=\s+(?:and|my\s+email|email|message))\b)/i), l && a("Full Name", l[1]), l = t.match(/\b(.+?)\s+for\s+(?:the\s+)?full\s*name\b/i), l) {
|
|
22591
|
+
let e = l[1].trim();
|
|
22564
22592
|
e.length > 1 && e.length < 120 && !/@/.test(e) && a("Full Name", e);
|
|
22565
22593
|
}
|
|
22566
|
-
if (
|
|
22567
|
-
let e =
|
|
22594
|
+
if (l = t.match(/\b(?:email|e-mail)(?:\s*address)?\s*(?:is|:|please\s+use|enter|-)\s*([^\s@]+@[^\s@]+\.[^\s,]+)/i), l && a("Email Address", l[1]), l = t.match(/\b(?:enter|type|put)\s+([^\s@]+@[^\s@]+\.[^\s,]+)\s+in(?:to)?\s+(?:the\s+)?(?:email|e-mail)/i), l && a("Email Address", l[1]), l = t.match(/\b(?:message|comment)\s*(?:is|:|please\s+enter|-)\s*(.+)$/is), l) {
|
|
22595
|
+
let e = l[1].trim();
|
|
22568
22596
|
e.length > 0 && a("Message", e);
|
|
22569
22597
|
}
|
|
22570
22598
|
if (!n.some((e) => /email/i.test(String(e.field_key)))) {
|
|
@@ -22580,17 +22608,17 @@ function Ag(e) {
|
|
|
22580
22608
|
}
|
|
22581
22609
|
return n;
|
|
22582
22610
|
}
|
|
22583
|
-
function
|
|
22611
|
+
function Ng(e) {
|
|
22584
22612
|
if (!e || typeof e != "object") return null;
|
|
22585
22613
|
let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
|
|
22586
22614
|
return t == null ? null : String(t).trim() || null;
|
|
22587
22615
|
}
|
|
22588
|
-
function
|
|
22616
|
+
function Pg(e) {
|
|
22589
22617
|
if (!e || typeof e != "object") return null;
|
|
22590
22618
|
let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
|
|
22591
22619
|
return t == null ? null : String(t).trim() || null;
|
|
22592
22620
|
}
|
|
22593
|
-
function
|
|
22621
|
+
function Fg(e) {
|
|
22594
22622
|
let t = e.ownerDocument?.defaultView || window, n = e.tagName === "TEXTAREA" ? t.HTMLTextAreaElement.prototype : t.HTMLInputElement.prototype, r = Object.getOwnPropertyDescriptor(n, "value");
|
|
22595
22623
|
return (e, t) => {
|
|
22596
22624
|
try {
|
|
@@ -22599,7 +22627,7 @@ function Ng(e) {
|
|
|
22599
22627
|
r?.set ? r.set.call(e, t) : e.value = t;
|
|
22600
22628
|
};
|
|
22601
22629
|
}
|
|
22602
|
-
async function
|
|
22630
|
+
async function Ig(e, t, n) {
|
|
22603
22631
|
if (!n?.skipScroll) try {
|
|
22604
22632
|
e.scrollIntoView({
|
|
22605
22633
|
behavior: "smooth",
|
|
@@ -22638,7 +22666,7 @@ async function Pg(e, t, n) {
|
|
|
22638
22666
|
"on"
|
|
22639
22667
|
].includes(String(t).toLowerCase().trim()), e.dispatchEvent(new Event("input", a)), e.dispatchEvent(new Event("change", a)), Gh(e), !0;
|
|
22640
22668
|
let o = String(t);
|
|
22641
|
-
r === "INPUT" || r === "TEXTAREA" ? await eg(e, o,
|
|
22669
|
+
r === "INPUT" || r === "TEXTAREA" ? await eg(e, o, Fg(e)) : (e.value = o, e.dispatchEvent(new Event("input", a)), e.dispatchEvent(new Event("change", a))), e.dispatchEvent(new Event("change", a)), e.dispatchEvent(new Event("blur", a));
|
|
22642
22670
|
try {
|
|
22643
22671
|
e.focus({ preventScroll: !0 });
|
|
22644
22672
|
} catch {}
|
|
@@ -22654,11 +22682,11 @@ async function Pg(e, t, n) {
|
|
|
22654
22682
|
} catch {}
|
|
22655
22683
|
return !0;
|
|
22656
22684
|
}
|
|
22657
|
-
function
|
|
22685
|
+
function Lg(e) {
|
|
22658
22686
|
let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
|
|
22659
22687
|
navigate_to_page: async (n) => {
|
|
22660
22688
|
$("navigate_to_page ▶ raw parameters:", n);
|
|
22661
|
-
let r = Dg(n), i =
|
|
22689
|
+
let r = Dg(n), i = Ng(r), a = r.section_text ?? r.sectionText ?? r.section;
|
|
22662
22690
|
if ($("navigate_to_page · coerced:", {
|
|
22663
22691
|
url: i,
|
|
22664
22692
|
sectionText: a
|
|
@@ -22682,8 +22710,16 @@ function Fg(e) {
|
|
|
22682
22710
|
found: !!e
|
|
22683
22711
|
});
|
|
22684
22712
|
}
|
|
22685
|
-
let e =
|
|
22686
|
-
|
|
22713
|
+
let e = "";
|
|
22714
|
+
try {
|
|
22715
|
+
let t = lg(), n = ug();
|
|
22716
|
+
if (t.length > 0) {
|
|
22717
|
+
let r = t.map((e) => e.label || e.placeholder || e.name || e.id).filter(Boolean).join(", "), i = n.map((e) => e.text).filter(Boolean).join(", ");
|
|
22718
|
+
e = ` This page has a form with fields: [${r}]` + (i ? ` and buttons: [${i}].` : ".") + " Call list_page_forms then start filling.";
|
|
22719
|
+
}
|
|
22720
|
+
} catch {}
|
|
22721
|
+
let t = `OK_NAVIGATION ${i}${e}`;
|
|
22722
|
+
return $("navigate_to_page ✓", t), t;
|
|
22687
22723
|
} catch (e) {
|
|
22688
22724
|
Hh(), Lh(200);
|
|
22689
22725
|
let t = `Navigation error: ${e?.message || String(e)}`;
|
|
@@ -22697,7 +22733,7 @@ function Fg(e) {
|
|
|
22697
22733
|
},
|
|
22698
22734
|
search_site_content: async (e) => {
|
|
22699
22735
|
$("search_site_content ▶", e);
|
|
22700
|
-
let r =
|
|
22736
|
+
let r = Pg(Dg(e));
|
|
22701
22737
|
if ($("search_site_content · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), Ih("Searching site content…", { spinner: !0 }), !r) return Lh(), $("search_site_content ✖ missing query"), "Missing query parameter.";
|
|
22702
22738
|
if (!t) return Lh(), $("search_site_content ✖ no siteId"), "Site is not configured for search.";
|
|
22703
22739
|
if (!n) return Lh(), $("search_site_content ✖ no api base"), "API base URL is missing; cannot search.";
|
|
@@ -22743,8 +22779,8 @@ function Fg(e) {
|
|
|
22743
22779
|
$("fill_form_fields ▶ raw:", e);
|
|
22744
22780
|
let t = Og(e);
|
|
22745
22781
|
if (!t.length && r) {
|
|
22746
|
-
let e = r(), n =
|
|
22747
|
-
n.length ? $("fill_form_fields · inferred URL from last user utterance (model omitted usable fields):", n) : (n =
|
|
22782
|
+
let e = r(), n = jg(e);
|
|
22783
|
+
n.length ? $("fill_form_fields · inferred URL from last user utterance (model omitted usable fields):", n) : (n = Mg(e), n.length && $("fill_form_fields · inferred contact fields from last user utterance (empty tool params):", n)), n.length && (t = n);
|
|
22748
22784
|
}
|
|
22749
22785
|
if ($("fill_form_fields · normalized fields:", t), !t.length) return "No fields provided. Call list_page_forms for field_key strings, then fill_form_fields 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.";
|
|
22750
22786
|
t.length > 1 && Ih(`Filling ${t.length} fields…`);
|
|
@@ -22752,17 +22788,18 @@ function Fg(e) {
|
|
|
22752
22788
|
for (let e of t) {
|
|
22753
22789
|
let t = e?.field_key ?? e?.fieldKey, r = e?.value;
|
|
22754
22790
|
if (t == null || r == null) continue;
|
|
22755
|
-
|
|
22756
|
-
|
|
22757
|
-
|
|
22758
|
-
|
|
22759
|
-
|
|
22760
|
-
|
|
22761
|
-
|
|
22791
|
+
let a = String(t).toLowerCase();
|
|
22792
|
+
/email|e-mail|mail/.test(a) ? r = kg(r) : /phone|mobile|tel|cell/.test(a) && (r = Ag(r)), Ih(`Filling ${t}…`), $("fill_form_fields · processing field:", t, "=", r);
|
|
22793
|
+
let o = cg();
|
|
22794
|
+
$("fill_form_fields · visible inputs count:", o.length);
|
|
22795
|
+
let s = xg(o, String(t), r);
|
|
22796
|
+
if (s.length) {
|
|
22797
|
+
for (let e = 0; e < s.length; e++) await Ig(s[e], r, { skipScroll: e > 0 }), await new Promise((e) => setTimeout(e, 80));
|
|
22798
|
+
i = s, n.push(String(t));
|
|
22762
22799
|
continue;
|
|
22763
22800
|
}
|
|
22764
|
-
let
|
|
22765
|
-
|
|
22801
|
+
let c = wg(o, String(t));
|
|
22802
|
+
c ||= hg(o, String(t)), c ||= gg(o, String(t), r), c ? (await Ig(c, r), i = [c], n.push(String(t))) : $("fill_form_fields · no match for field:", t);
|
|
22766
22803
|
}
|
|
22767
22804
|
Lh(400);
|
|
22768
22805
|
try {
|
|
@@ -22831,7 +22868,7 @@ function Fg(e) {
|
|
|
22831
22868
|
}
|
|
22832
22869
|
//#endregion
|
|
22833
22870
|
//#region src/utils/wrapVoiceToolsForLogging.js
|
|
22834
|
-
function
|
|
22871
|
+
function Rg(e) {
|
|
22835
22872
|
return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
|
|
22836
22873
|
let r = Zt();
|
|
22837
22874
|
r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
|
|
@@ -22841,22 +22878,22 @@ function Ig(e) {
|
|
|
22841
22878
|
}
|
|
22842
22879
|
//#endregion
|
|
22843
22880
|
//#region src/components/VoiceInterface.jsx
|
|
22844
|
-
var
|
|
22881
|
+
var zg = {
|
|
22845
22882
|
idle: "rgba(99,102,241,0.18)",
|
|
22846
22883
|
listening: "rgba(16,185,129,0.25)",
|
|
22847
22884
|
speaking: "rgba(245,158,11,0.25)",
|
|
22848
22885
|
error: "rgba(239,68,68,0.2)"
|
|
22849
|
-
},
|
|
22886
|
+
}, Bg = {
|
|
22850
22887
|
idle: "#6366f1",
|
|
22851
22888
|
listening: "#10b981",
|
|
22852
22889
|
speaking: "#f59e0b",
|
|
22853
22890
|
error: "#ef4444"
|
|
22854
22891
|
};
|
|
22855
|
-
function
|
|
22892
|
+
function Vg(e, t) {
|
|
22856
22893
|
let n = (t || "").trim();
|
|
22857
22894
|
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;
|
|
22858
22895
|
}
|
|
22859
|
-
function
|
|
22896
|
+
function Hg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
|
|
22860
22897
|
let [h, g] = s("idle"), [ee, te] = s(null), [_, ne] = s(!1), re = o(null), ie = o(null), ae = o(""), oe = o(async () => {}), se = o(!1), v = n(async () => {
|
|
22861
22898
|
try {
|
|
22862
22899
|
await re.current?.endSession?.();
|
|
@@ -22873,7 +22910,7 @@ function Bg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
22873
22910
|
try {
|
|
22874
22911
|
if (await navigator.mediaDevices.getUserMedia({ audio: !0 }), t) return;
|
|
22875
22912
|
d.current = [], ae.current = "", se.current = !1;
|
|
22876
|
-
let i =
|
|
22913
|
+
let i = Rg(Lg({
|
|
22877
22914
|
siteId: r || null,
|
|
22878
22915
|
apiBaseUrl: a || null,
|
|
22879
22916
|
getLastUserVoiceText: () => ae.current,
|
|
@@ -22900,7 +22937,7 @@ function Bg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
22900
22937
|
message: r,
|
|
22901
22938
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
22902
22939
|
};
|
|
22903
|
-
n === "user" && (ae.current = r), d.current = [...d.current, i],
|
|
22940
|
+
n === "user" && (ae.current = r), d.current = [...d.current, i], Vg(n, r) && queueMicrotask(() => {
|
|
22904
22941
|
se.current || (se.current = !0, oe.current?.());
|
|
22905
22942
|
});
|
|
22906
22943
|
},
|
|
@@ -22923,7 +22960,12 @@ function Bg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
22923
22960
|
} catch {
|
|
22924
22961
|
t = "[]";
|
|
22925
22962
|
}
|
|
22926
|
-
|
|
22963
|
+
let n = "";
|
|
22964
|
+
try {
|
|
22965
|
+
let e = await i.search_site_content({ query: "pages" }), t = typeof e == "string" ? JSON.parse(e) : e;
|
|
22966
|
+
Array.isArray(t) && t.length && (n = ` Site pages available: ${t.map((e) => `${e.title || ""} (${e.url || ""})`).join(", ")}.`);
|
|
22967
|
+
} catch {}
|
|
22968
|
+
o.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${r || "unknown"}. Page fields/buttons JSON: ${t}.${n} Navigation: when the user wants to go to any page (contact, pricing, about, services, etc.), call search_site_content then navigate_to_page immediately — never ask permission. After navigating to a page with a form, call list_page_forms and proactively start helping the user fill it. Forms: use fill_form_fields then click_page_button (e.g. Conduct Audit, Send Message) when the user wants to submit. Fill each field immediately after the user answers — never skip ahead. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end.`);
|
|
22927
22969
|
} catch {}
|
|
22928
22970
|
typeof m == "function" && m();
|
|
22929
22971
|
} catch (e) {
|
|
@@ -22939,7 +22981,7 @@ function Bg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
22939
22981
|
d,
|
|
22940
22982
|
m
|
|
22941
22983
|
]);
|
|
22942
|
-
let ce = h === "listening" || h === "speaking", le =
|
|
22984
|
+
let ce = h === "listening" || h === "speaking", le = Bg[h] || Bg.idle, ue = zg[h] || zg.idle;
|
|
22943
22985
|
return /* @__PURE__ */ u("div", {
|
|
22944
22986
|
ref: ie,
|
|
22945
22987
|
style: {
|
|
@@ -23045,7 +23087,7 @@ function Bg({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
23045
23087
|
}
|
|
23046
23088
|
//#endregion
|
|
23047
23089
|
//#region src/components/FlowEngageWidget.jsx
|
|
23048
|
-
var
|
|
23090
|
+
var Ug = [
|
|
23049
23091
|
{
|
|
23050
23092
|
key: "become_client",
|
|
23051
23093
|
label: "Become a Client"
|
|
@@ -23066,7 +23108,7 @@ var Vg = [
|
|
|
23066
23108
|
key: "looking_for_job",
|
|
23067
23109
|
label: "Looking for a Job"
|
|
23068
23110
|
}
|
|
23069
|
-
],
|
|
23111
|
+
], Wg = () => /* @__PURE__ */ l("div", {
|
|
23070
23112
|
style: {
|
|
23071
23113
|
display: "flex",
|
|
23072
23114
|
marginBottom: "12px",
|
|
@@ -23097,7 +23139,7 @@ var Vg = [
|
|
|
23097
23139
|
} }, e)), /* @__PURE__ */ l("style", { children: "\n @keyframes fe-dot-bounce {\n 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }\n 40% { transform: translateY(-5px); opacity: 1; }\n }\n " })]
|
|
23098
23140
|
})
|
|
23099
23141
|
});
|
|
23100
|
-
function
|
|
23142
|
+
function Gg() {
|
|
23101
23143
|
let { status: e, runtimeConfig: t, resolvedConfig: n, chatId: r, chatHistory: o, isOpen: c, activeScreen: d, isHumanHandled: f, agentName: p, agentHeadshot: m, visitorEmail: h, isAgentTyping: g, isAiTyping: ee, isLoading: te, isVoiceMode: _, isRateLimited: ne, rateLimitMessage: re, isConversationEnded: ie, incomingCall: ae, activeCallId: oe, callConnectionState: se, callConnectedAt: v, isCallMuted: ce, webRTCError: le, language: ue, historyRef: y, onMessageSync: b, endConversation: de, acceptCall: fe, rejectCall: pe, endWebRTCCall: me, toggleCallMute: he, dismissCallError: ge, captureVisitorEmail: _e, openWidget: ve, closeWidget: ye, sendMessage: be, setVoiceMode: xe, startTyping: Se, stopTyping: Ce, updateTypingDraft: we } = Xt(), [Te, Ee] = s(""), [De, Oe] = s(null), [ke, Ae] = s(null), [je, Me] = s(null), [Ne, Pe] = s(0), [x, Fe] = s(h || ""), [Ie, Le] = s("");
|
|
23102
23144
|
i(() => {
|
|
23103
23145
|
try {
|
|
@@ -23125,7 +23167,7 @@ function Ug() {
|
|
|
23125
23167
|
outline: "none",
|
|
23126
23168
|
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
23127
23169
|
...c ? {} : Ue
|
|
23128
|
-
}, Ge = S.recommendations?.[ue] || Re.recommendations?.[ue] ||
|
|
23170
|
+
}, Ge = S.recommendations?.[ue] || Re.recommendations?.[ue] || Ug, Ke = S.greetings?.[ue] || Re.greetings?.[ue], qe = ze.chatButtonText || "Chat with us", Je = ze.headerName || t?.websiteName || "OpenSense Labs", C = ze.logoUrl || null, w = ze.hideWatermark || !1, T = Re.elevenLabsAgentId || t?.elevenLabsAgentId || null, Ye = t?.siteId || n?.siteId || null, Xe = t?.apiBaseUrl || "", Ze = ze.fallbackAgentName || "Agent", Qe = ze.botLabel || "AI", $e = m && String(m).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, et = ae?.agentName || p || Ze, tt = o.some((e) => e.sender === "user"), nt = a(() => {
|
|
23129
23171
|
let e = o.findIndex((e) => e.sender === "user");
|
|
23130
23172
|
return e === -1 ? !1 : o.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
|
|
23131
23173
|
}, [o]), rt = !h && tt && nt;
|
|
@@ -23253,7 +23295,7 @@ function Ug() {
|
|
|
23253
23295
|
flexDirection: "column"
|
|
23254
23296
|
},
|
|
23255
23297
|
className: "fe-screen-fade-in",
|
|
23256
|
-
children: /* @__PURE__ */ l(
|
|
23298
|
+
children: /* @__PURE__ */ l(Hg, {
|
|
23257
23299
|
agentId: T,
|
|
23258
23300
|
chatId: r,
|
|
23259
23301
|
siteId: Ye,
|
|
@@ -23286,7 +23328,7 @@ function Ug() {
|
|
|
23286
23328
|
isAiTyping: ee,
|
|
23287
23329
|
isAgentTyping: g,
|
|
23288
23330
|
setReplyContext: Me,
|
|
23289
|
-
TypingDots:
|
|
23331
|
+
TypingDots: Wg,
|
|
23290
23332
|
primaryColor: Ve,
|
|
23291
23333
|
agentHeadshot: $e,
|
|
23292
23334
|
agentDisplayName: p || Ze
|
|
@@ -23365,4 +23407,4 @@ function Ug() {
|
|
|
23365
23407
|
}) : null;
|
|
23366
23408
|
}
|
|
23367
23409
|
//#endregion
|
|
23368
|
-
export { vn as FlowEngageProvider,
|
|
23410
|
+
export { vn as FlowEngageProvider, Gg as FlowEngageWidget, Xt as useFlowEngage };
|