@flowengage/react-chatbot 0.2.8 → 0.2.9

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.
@@ -323,16 +323,16 @@ class ScribeAudioProcessor extends AudioWorkletProcessor {
323
323
 
324
324
  registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
325
325
 
326
- `),bh,xh;(function(e){e.PCM_8000=`pcm_8000`,e.PCM_16000=`pcm_16000`,e.PCM_22050=`pcm_22050`,e.PCM_24000=`pcm_24000`,e.PCM_44100=`pcm_44100`,e.PCM_48000=`pcm_48000`,e.ULAW_8000=`ulaw_8000`})(bh||={}),function(e){e.MANUAL=`manual`,e.VAD=`vad`}(xh||={});var Sh=class e{static getWebSocketUri(t=e.DEFAULT_BASE_URI){return`${t}/v1/speech-to-text/realtime`}static buildWebSocketUri(t){let n=e.getWebSocketUri(t.baseUri),r=new URLSearchParams;if(r.append(`model_id`,t.modelId),r.append(`token`,t.token),t.commitStrategy!==void 0&&r.append(`commit_strategy`,t.commitStrategy),t.audioFormat!==void 0&&r.append(`audio_format`,t.audioFormat),t.vadSilenceThresholdSecs!==void 0){if(t.vadSilenceThresholdSecs<=.3||t.vadSilenceThresholdSecs>3)throw Error(`vadSilenceThresholdSecs must be between 0.3 and 3.0`);r.append(`vad_silence_threshold_secs`,t.vadSilenceThresholdSecs.toString())}if(t.vadThreshold!==void 0){if(t.vadThreshold<.1||t.vadThreshold>.9)throw Error(`vadThreshold must be between 0.1 and 0.9`);r.append(`vad_threshold`,t.vadThreshold.toString())}if(t.minSpeechDurationMs!==void 0){if(t.minSpeechDurationMs<=50||t.minSpeechDurationMs>2e3)throw Error(`minSpeechDurationMs must be between 50 and 2000`);r.append(`min_speech_duration_ms`,t.minSpeechDurationMs.toString())}if(t.minSilenceDurationMs!==void 0){if(t.minSilenceDurationMs<=50||t.minSilenceDurationMs>2e3)throw Error(`minSilenceDurationMs must be between 50 and 2000`);r.append(`min_silence_duration_ms`,t.minSilenceDurationMs.toString())}t.languageCode!==void 0&&r.append(`language_code`,t.languageCode),t.includeTimestamps!==void 0&&r.append(`include_timestamps`,t.includeTimestamps?`true`:`false`);let i=r.toString();return i?`${n}?${i}`:n}static connect(t){if(!t.modelId)throw Error(`modelId is required`);let n=new vh(`microphone`in t&&t.microphone?16e3:t.sampleRate),r=e.buildWebSocketUri(t),i=new WebSocket(r);return`microphone`in t&&t.microphone&&i.addEventListener(`open`,()=>{e.streamFromMicrophone(t,n)}),n.setWebSocket(i),n}static async streamFromMicrophone(e,t){try{var n,r,i;let a=await navigator.mediaDevices.getUserMedia({audio:{deviceId:e.microphone?.deviceId,echoCancellation:(n=e.microphone?.echoCancellation)==null||n,noiseSuppression:(r=e.microphone?.noiseSuppression)==null||r,autoGainControl:(i=e.microphone?.autoGainControl)==null||i,channelCount:e.microphone?.channelCount??1,sampleRate:{ideal:16e3}}}),o=new AudioContext({sampleRate:16e3});await yh(o.audioWorklet);let s=o.createMediaStreamSource(a),c=new AudioWorkletNode(o,`scribeAudioProcessor`);c.port.onmessage=e=>{let{audioData:n}=e.data,r=new Uint8Array(n),i=``;for(let e=0;e<r.length;e++)i+=String.fromCharCode(r[e]);let a=btoa(i);t.send({audioBase64:a})},s.connect(c),o.state===`suspended`&&await o.resume(),t._audioCleanup=()=>{a.getTracks().forEach(e=>{e.stop()}),s.disconnect(),c.disconnect(),o.close()}}catch(e){throw console.error(`Failed to start microphone streaming:`,e),e}}};Sh.DEFAULT_BASE_URI=`wss://api.elevenlabs.io`;var Ch=class extends Jm{static startSession(e){return e.textOnly?dh.startSession(e):gh.startSession(e)}};function wh(...e){en()&&console.log(`[FlowEngage:voice-tools]`,...e)}function Th(e){if(e.labels&&e.labels.length)return e.labels[0].textContent?.trim()||null;let t=e.id;if(t)try{let e=document.querySelector(`label[for="${CSS.escape(t)}"]`);if(e)return e.textContent?.trim()||null}catch{let e=document.querySelector(`label[for="${t.replace(/"/g,`\\"`)}"]`);if(e)return e.textContent?.trim()||null}let n=e.parentElement;for(let e=0;e<4&&n;e+=1){if(n.tagName===`LABEL`)return n.textContent?.trim()||null;n=n.parentElement}return null}function Eh(){return Array.from(document.querySelectorAll(`input, select, textarea`)).filter(e=>{let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0})}function Dh(){return Eh().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:Th(e),placeholder:e.placeholder||null}))}function Oh(){return Array.from(document.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}).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 kh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.name,e.id,e.placeholder,Th(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`)].filter(Boolean).map(e=>String(e).toLowerCase()),i=0;for(let e of r){if(!e)continue;if(e.includes(n)||n.includes(e)){i=Math.max(i,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);i=Math.max(i,r/t.length*88)}return i}function Ah(e,t){let n=null,r=0;for(let i of e){let e=kh(i,t);e>r&&(r=e,n=i)}return!n||r<38?null:n}function jh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.textContent,e.value,e.getAttribute(`aria-label`),e.getAttribute(`title`)].filter(Boolean).join(` `).toLowerCase().replace(/\s+/g,` `);if(r.includes(n))return 100;let i=n.split(/\s+/).filter(e=>e.length>1);if(!i.length)return 0;let a=0;for(let e of i)r.includes(e)&&(a+=1);return a/i.length*92}function Mh(e){let t=Array.from(document.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}),n=null,r=0;for(let i of t){let t=jh(i,e);t>r&&(r=t,n=i)}return!n||r<36?null:n}function Nh(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 Ph(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 Fh(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 Ih(e,t){let n=e.tagName,r=(e.type||``).toLowerCase();if(n===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(r===`checkbox`||r===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let i=String(t);if(n===`INPUT`||n===`TEXTAREA`){let t=n===`TEXTAREA`?window.HTMLTextAreaElement.prototype:window.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(t,`value`);r?.set?r.set.call(e,i):e.value=i}else e.value=i;return e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0}function Lh(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``);return{navigate_to_page:async e=>{wh(`navigate_to_page ▶ raw parameters:`,e);let t=Nh(e),n=Ph(t),r=t.section_text??t.sectionText??t.section;if(wh(`navigate_to_page · coerced:`,{url:n,sectionText:r}),!n){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return wh(`navigate_to_page ✖`,e),e}try{if(wh(`navigate_to_page → shadowNavigate`,n),await cn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=rn(null,r);e&&an(e),wh(`navigate_to_page · highlight`,{sectionText:r,found:!!e})}let e=`OK_NAVIGATION ${n}`;return wh(`navigate_to_page ✓`,e),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return wh(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{wh(`highlight_on_page ▶`,e);let t=Nh(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=rn(n||null,r||null);return i?(an(i),wh(`highlight_on_page ✓`),`Highlighted the section.`):(wh(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{wh(`search_site_content ▶`,e);let r=Fh(Nh(e));if(wh(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return wh(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return wh(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return wh(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;wh(`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(wh(`search_site_content · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return wh(`search_site_content ✖`,e),e}let o=a.results||[];return wh(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return wh(`search_site_content ✖`,t),t}},list_page_forms:async()=>{let e=Dh(),t=Oh();return wh(`list_page_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key can be label text, placeholder (e.g. Enter Website URL), name, or id. After filling, use click_page_button with button_text (e.g. Conduct Audit) to submit.`})},fill_form_fields:async e=>{let t=Nh(e)?.fields;if(wh(`fill_form_fields ▶`,{fieldCount:Array.isArray(t)?t.length:0}),!Array.isArray(t)||t.length===0)return`No fields provided. Use list_page_forms first.`;let n=Eh(),r=[];for(let e of t){let t=e?.field_key??e?.fieldKey,i=e?.value;if(t==null||i==null)continue;let a=Ah(n,String(t));a&&(Ih(a,i),r.push(String(t)))}if(!r.length)return wh(`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. website url, Enter Website URL).`;let i=`Filled fields: ${r.join(`, `)}`;return wh(`fill_form_fields ✓`,i),i},click_page_button:async e=>{let t=Nh(e),n=(t.button_text??t.buttonText??t.text??``).trim();if(wh(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=Mh(n);if(!r)return wh(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{r.click();let e=`OK_CLICK ${(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`}`;return wh(`click_page_button ✓`,e),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return wh(`click_page_button ✖`,t),t}}}}var Rh={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)`},zh={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Bh({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,g]=(0,v.useState)([]),_=(0,v.useRef)(null),y=(0,v.useRef)(null);(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;g([]);let o=Lh({siteId:n||null,apiBaseUrl:r||null}),s=await Ch.startSession({agentId:e,clientTools:o,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()};a.current=[...a.current,i],g(e=>[...e,i])},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,_.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.`)}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(()=>{}):_.current&&_.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let b=(0,v.useCallback)(async()=>{try{await _.current?.endSession?.()}catch{}_.current=null,m(!1),u(`idle`),typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]),x=l===`listening`||l===`speaking`,ee=zh[l]||zh.idle,te=Rh[l]||Rh.idle;return(0,O.jsxs)(`div`,{ref:y,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,O.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[x&&(0,O.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ee}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),x&&(0,O.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ee}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,O.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:te,border:`3px solid ${ee}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:l===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${te}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,O.jsx)(vn,{size:44,color:ee})})]}),(0,O.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`)]}),h.length>0&&(0,O.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:h.map((e,t)=>(0,O.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,O.jsx)(`div`,{style:{maxWidth:`85%`,padding:`8px 12px`,borderRadius:`14px`,fontSize:`13px`,lineHeight:1.5,background:e.sender===`user`?`var(--flowengage-primary)`:`#f3f4f6`,color:e.sender===`user`?`#fff`:`#111827`},children:e.message})},t))}),(0,O.jsxs)(`button`,{onClick:b,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,O.jsx)(yn,{size:18}),`End Voice Session`]}),(0,O.jsx)(`style`,{children:`
326
+ `),bh,xh;(function(e){e.PCM_8000=`pcm_8000`,e.PCM_16000=`pcm_16000`,e.PCM_22050=`pcm_22050`,e.PCM_24000=`pcm_24000`,e.PCM_44100=`pcm_44100`,e.PCM_48000=`pcm_48000`,e.ULAW_8000=`ulaw_8000`})(bh||={}),function(e){e.MANUAL=`manual`,e.VAD=`vad`}(xh||={});var Sh=class e{static getWebSocketUri(t=e.DEFAULT_BASE_URI){return`${t}/v1/speech-to-text/realtime`}static buildWebSocketUri(t){let n=e.getWebSocketUri(t.baseUri),r=new URLSearchParams;if(r.append(`model_id`,t.modelId),r.append(`token`,t.token),t.commitStrategy!==void 0&&r.append(`commit_strategy`,t.commitStrategy),t.audioFormat!==void 0&&r.append(`audio_format`,t.audioFormat),t.vadSilenceThresholdSecs!==void 0){if(t.vadSilenceThresholdSecs<=.3||t.vadSilenceThresholdSecs>3)throw Error(`vadSilenceThresholdSecs must be between 0.3 and 3.0`);r.append(`vad_silence_threshold_secs`,t.vadSilenceThresholdSecs.toString())}if(t.vadThreshold!==void 0){if(t.vadThreshold<.1||t.vadThreshold>.9)throw Error(`vadThreshold must be between 0.1 and 0.9`);r.append(`vad_threshold`,t.vadThreshold.toString())}if(t.minSpeechDurationMs!==void 0){if(t.minSpeechDurationMs<=50||t.minSpeechDurationMs>2e3)throw Error(`minSpeechDurationMs must be between 50 and 2000`);r.append(`min_speech_duration_ms`,t.minSpeechDurationMs.toString())}if(t.minSilenceDurationMs!==void 0){if(t.minSilenceDurationMs<=50||t.minSilenceDurationMs>2e3)throw Error(`minSilenceDurationMs must be between 50 and 2000`);r.append(`min_silence_duration_ms`,t.minSilenceDurationMs.toString())}t.languageCode!==void 0&&r.append(`language_code`,t.languageCode),t.includeTimestamps!==void 0&&r.append(`include_timestamps`,t.includeTimestamps?`true`:`false`);let i=r.toString();return i?`${n}?${i}`:n}static connect(t){if(!t.modelId)throw Error(`modelId is required`);let n=new vh(`microphone`in t&&t.microphone?16e3:t.sampleRate),r=e.buildWebSocketUri(t),i=new WebSocket(r);return`microphone`in t&&t.microphone&&i.addEventListener(`open`,()=>{e.streamFromMicrophone(t,n)}),n.setWebSocket(i),n}static async streamFromMicrophone(e,t){try{var n,r,i;let a=await navigator.mediaDevices.getUserMedia({audio:{deviceId:e.microphone?.deviceId,echoCancellation:(n=e.microphone?.echoCancellation)==null||n,noiseSuppression:(r=e.microphone?.noiseSuppression)==null||r,autoGainControl:(i=e.microphone?.autoGainControl)==null||i,channelCount:e.microphone?.channelCount??1,sampleRate:{ideal:16e3}}}),o=new AudioContext({sampleRate:16e3});await yh(o.audioWorklet);let s=o.createMediaStreamSource(a),c=new AudioWorkletNode(o,`scribeAudioProcessor`);c.port.onmessage=e=>{let{audioData:n}=e.data,r=new Uint8Array(n),i=``;for(let e=0;e<r.length;e++)i+=String.fromCharCode(r[e]);let a=btoa(i);t.send({audioBase64:a})},s.connect(c),o.state===`suspended`&&await o.resume(),t._audioCleanup=()=>{a.getTracks().forEach(e=>{e.stop()}),s.disconnect(),c.disconnect(),o.close()}}catch(e){throw console.error(`Failed to start microphone streaming:`,e),e}}};Sh.DEFAULT_BASE_URI=`wss://api.elevenlabs.io`;var Ch=class extends Jm{static startSession(e){return e.textOnly?dh.startSession(e):gh.startSession(e)}};function wh(...e){en()&&console.log(`[FlowEngage:voice-tools]`,...e)}var Th=`#flowengage-root, .flowengage-shell`;function Eh(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(Th)}catch{return!1}}function Dh(e){if(e.labels&&e.labels.length)return e.labels[0].textContent?.trim()||null;let t=e.id;if(t)try{let e=document.querySelector(`label[for="${CSS.escape(t)}"]`);if(e)return e.textContent?.trim()||null}catch{let e=document.querySelector(`label[for="${t.replace(/"/g,`\\"`)}"]`);if(e)return e.textContent?.trim()||null}let n=e.parentElement;for(let e=0;e<4&&n;e+=1){if(n.tagName===`LABEL`)return n.textContent?.trim()||null;n=n.parentElement}return null}function Oh(){return Array.from(document.querySelectorAll(`input, select, textarea`)).filter(e=>{if(Eh(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0})}function kh(){return Oh().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:Dh(e),placeholder:e.placeholder||null}))}function Ah(){return Array.from(document.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}).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 jh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.name,e.id,e.placeholder,Dh(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`)].filter(Boolean).map(e=>String(e).toLowerCase()),i=0;for(let e of r){if(!e)continue;if(e.includes(n)||n.includes(e)){i=Math.max(i,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);i=Math.max(i,r/t.length*88)}return i}var Mh=28;function Nh(e,t){let n=null,r=0;for(let i of e){let e=jh(i,t);e>r&&(r=e,n=i)}return!n||r<Mh?null:n}function Ph(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,Dh(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<50?null:a}function Fh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=[e.textContent,e.value,e.getAttribute(`aria-label`),e.getAttribute(`title`)].filter(Boolean).join(` `).toLowerCase().replace(/\s+/g,` `);if(r.includes(n))return 100;let i=n.split(/\s+/).filter(e=>e.length>1);if(!i.length)return 0;let a=0;for(let e of i)r.includes(e)&&(a+=1);return a/i.length*92}function Ih(e){let t=Array.from(document.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=window.getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}),n=null,r=0;for(let i of t){let t=Fh(i,e);t>r&&(r=t,n=i)}return!n||r<36?null:n}function Lh(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 Rh(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 zh(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 Bh(e,t){try{e.scrollIntoView({block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let n=e.tagName,r=(e.type||``).toLowerCase();if(n===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(r===`checkbox`||r===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let i=String(t);if(n===`INPUT`||n===`TEXTAREA`){let t=n===`TEXTAREA`?window.HTMLTextAreaElement.prototype:window.HTMLInputElement.prototype,r=Object.getOwnPropertyDescriptor(t,`value`);r?.set?r.set.call(e,i):e.value=i}else e.value=i;try{e.dispatchEvent(new InputEvent(`input`,{bubbles:!0,cancelable:!0,inputType:`insertText`,data:i}))}catch{e.dispatchEvent(new Event(`input`,{bubbles:!0}))}return e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0}function Vh(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``);return{navigate_to_page:async e=>{wh(`navigate_to_page ▶ raw parameters:`,e);let t=Lh(e),n=Rh(t),r=t.section_text??t.sectionText??t.section;if(wh(`navigate_to_page · coerced:`,{url:n,sectionText:r}),!n){let e=`Missing url: pass a string url, path like /pricing, or JSON with a url field.`;return wh(`navigate_to_page ✖`,e),e}try{if(wh(`navigate_to_page → shadowNavigate`,n),await cn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=rn(null,r);e&&an(e),wh(`navigate_to_page · highlight`,{sectionText:r,found:!!e})}let e=`OK_NAVIGATION ${n}`;return wh(`navigate_to_page ✓`,e),e}catch(e){let t=`Navigation error: ${e?.message||String(e)}`;return wh(`navigate_to_page ✖`,t),t}},highlight_on_page:async e=>{wh(`highlight_on_page ▶`,e);let t=Lh(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=rn(n||null,r||null);return i?(an(i),wh(`highlight_on_page ✓`),`Highlighted the section.`):(wh(`highlight_on_page ✖ no element`),`Could not find that section on the page.`)},search_site_content:async e=>{wh(`search_site_content ▶`,e);let r=zh(Lh(e));if(wh(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return wh(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return wh(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return wh(`search_site_content ✖ no api base`),`API base URL is missing; cannot search.`;try{let e=`${n}/api/site-tools/search`;wh(`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(wh(`search_site_content · HTTP`,i.status,`success:`,a.success),!a.success){let e=a.error||`Search failed.`;return wh(`search_site_content ✖`,e),e}let o=a.results||[];return wh(`search_site_content ✓`,`${o.length} result(s)`,o.slice(0,3).map(e=>e?.url||e)),JSON.stringify(o)}catch(e){let t=`Search error: ${e.message||`network`}`;return wh(`search_site_content ✖`,t),t}},list_page_forms:async()=>{let e=kh(),t=Ah();return wh(`list_page_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key can be label text, placeholder (e.g. Enter Website URL), name, or id. After filling, use click_page_button with button_text (e.g. Conduct Audit) to submit.`})},fill_form_fields:async e=>{try{let t=Lh(e),n=t?.fields;if(!n&&Array.isArray(t)&&t.length>0&&t[0]?.field_key!=null&&(n=t),wh(`fill_form_fields ▶`,{fieldCount:Array.isArray(n)?n.length:0}),!Array.isArray(n)||n.length===0)return`No fields provided. Use list_page_forms first.`;let r=[];for(let e of n){let t=e?.field_key??e?.fieldKey,n=e?.value;if(t==null||n==null)continue;let i=Oh(),a=Nh(i,String(t));a||=Ph(i,String(t),n),a&&(Bh(a,n),r.push(String(t)))}if(!r.length)return wh(`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 i=`Filled fields: ${r.join(`, `)}`;return wh(`fill_form_fields ✓`,i),i}catch(e){let t=`fill_form_fields error: ${e?.message||String(e)}`;return wh(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Lh(e),n=(t.button_text??t.buttonText??t.text??``).trim();if(wh(`click_page_button ▶`,n),!n)return`Missing button_text: pass the visible label, e.g. Conduct Audit.`;let r=Ih(n);if(!r)return wh(`click_page_button ✖ no match`),`Could not find a button matching "${n}". Call list_page_forms to see button texts.`;try{try{r.scrollIntoView({block:`center`,inline:`nearest`})}catch{r.scrollIntoView(!0)}r.focus?.(),r.click();let e=`OK_CLICK ${(r.textContent||r.value||r.getAttribute(`aria-label`)||``).trim().slice(0,80)||`button`}`;return wh(`click_page_button ✓`,e),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return wh(`click_page_button ✖`,t),t}}}}var Hh={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)`},Uh={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Wh({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,g]=(0,v.useState)([]),_=(0,v.useRef)(null),y=(0,v.useRef)(null);(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;g([]);let o=Vh({siteId:n||null,apiBaseUrl:r||null}),s=await Ch.startSession({agentId:e,clientTools:o,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()};a.current=[...a.current,i],g(e=>[...e,i])},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,_.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.`)}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(()=>{}):_.current&&_.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let b=(0,v.useCallback)(async()=>{try{await _.current?.endSession?.()}catch{}_.current=null,m(!1),u(`idle`),typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]),x=l===`listening`||l===`speaking`,ee=Uh[l]||Uh.idle,te=Hh[l]||Hh.idle;return(0,O.jsxs)(`div`,{ref:y,style:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,flex:1,gap:`24px`,padding:`24px 20px`,background:`transparent`},children:[(0,O.jsxs)(`div`,{style:{position:`relative`,width:`140px`,height:`140px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:[x&&(0,O.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ee}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),x&&(0,O.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ee}`,animation:`fe-orb-pulse 1.4s ease-in-out 0.35s infinite`,opacity:.4}}),(0,O.jsx)(`div`,{style:{width:`140px`,height:`140px`,borderRadius:`50%`,background:te,border:`3px solid ${ee}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:l===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${te}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,O.jsx)(vn,{size:44,color:ee})})]}),(0,O.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`)]}),h.length>0&&(0,O.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:h.map((e,t)=>(0,O.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,O.jsx)(`div`,{style:{maxWidth:`85%`,padding:`8px 12px`,borderRadius:`14px`,fontSize:`13px`,lineHeight:1.5,background:e.sender===`user`?`var(--flowengage-primary)`:`#f3f4f6`,color:e.sender===`user`?`#fff`:`#111827`},children:e.message})},t))}),(0,O.jsxs)(`button`,{onClick:b,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,O.jsx)(yn,{size:18}),`End Voice Session`]}),(0,O.jsx)(`style`,{children:`
327
327
  @keyframes fe-orb-pulse {
328
328
  0% { transform: scale(1); opacity: 0.6; }
329
329
  50% { transform: scale(1.18); opacity: 0.15; }
330
330
  100% { transform: scale(1); opacity: 0.6; }
331
331
  }
332
- `})]})}var Vh=[{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`}],Hh=()=>(0,O.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,O.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,O.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,O.jsx)(`style`,{children:`
332
+ `})]})}var Gh=[{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`}],Kh=()=>(0,O.jsx)(`div`,{style:{display:`flex`,marginBottom:`12px`,justifyContent:`flex-start`},children:(0,O.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,O.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,O.jsx)(`style`,{children:`
333
333
  @keyframes fe-dot-bounce {
334
334
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
335
335
  40% { transform: translateY(-5px); opacity: 1; }
336
336
  }
337
- `})]})});function Uh(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isVoiceMode:p,isRateLimited:m,rateLimitMessage:h,isConversationEnded:g,incomingCall:_,activeCallId:y,callConnectionState:b,callConnectedAt:x,isCallMuted:ee,webRTCError:te,language:S,historyRef:ne,onMessageSync:re,endConversation:ie,acceptCall:ae,rejectCall:oe,endWebRTCCall:se,toggleCallMute:ce,dismissCallError:le,captureVisitorEmail:ue,openWidget:de,closeWidget:fe,sendMessage:C,setVoiceMode:w,startTyping:pe,stopTyping:me,updateTypingDraft:he}=$t(),[ge,_e]=(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)(l||``),[Oe,T]=(0,v.useState)(``),ke=t?.widgetSettings||{},Ae=n?.widgetSettings||{},je={...ke.branding||{},...Ae.branding||{}},Me={...ke.theme||{},...Ae.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=Ae.recommendations?.[S]||ke.recommendations?.[S]||Vh,Re=Ae.greetings?.[S]||ke.greetings?.[S],ze=je.chatButtonText||`Chat with us`,Be=je.headerName||t?.websiteName||`OpenSense Labs`,Ve=je.logoUrl||null,E=je.hideWatermark||!1,He=Ae.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ue=t?.siteId||n?.siteId||null,We=t?.apiBaseUrl||``,Ge=je.fallbackAgentName||`Agent`,Ke=je.botLabel||`AI`,qe=_?.agentName||c||Ge,Je=!l&&i.length===0;(0,v.useEffect)(()=>{De(l||``),l&&T(``)},[l]),(0,v.useEffect)(()=>{if(!x||b!==`connected`){Te(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||Te(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]),(0,v.useEffect)(()=>{if(!s||p||g){he(``),me();return}if(!ge.trim()){he(``),me();return}pe();let e=window.setTimeout(()=>{he(ge)},120),t=window.setTimeout(()=>{me()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[ge,s,p,g,pe,me,he]);let Ye=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Xe=async e=>{if(e.preventDefault(),g)return;if(Je){let e=Ee.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){T(`Please enter a valid email to start the chat.`);return}await ue(e),T(``);return}if(!ge.trim())return;let t=ge.trim(),n=Ye(Se);_e(``),Ce(null),await C(t,``,n)},Ze=async()=>{if(Je){T(`Please share your email before starting a call.`);return}if(p){w(!1);return}xe(null);try{ye(await navigator.mediaDevices.getUserMedia({audio:!0})),w(!0)}catch(e){xe(e.message||`Could not access microphone.`)}},Qe=()=>{ve&&(ve.getTracks().forEach(e=>e.stop()),ye(null)),w(!1)},$e=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,O.jsxs)(`div`,{className:`flowengage-shell`,"data-open":a?`true`:`false`,style:Ie,children:[(0,O.jsx)(En,{isOpen:a,openWidget:de,launcherText:ze,primaryColor:Ne,posInline:Fe}),a&&(0,O.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!p?`linear-gradient(to bottom, ${Ne} 0%, ${Ne} 70%, white 85%)`:`white`},children:[(0,O.jsx)(kn,{logoUrl:Ve,brandName:Be,agentName:c,fallbackAgentName:Ge,activeScreen:o,branding:je,isConversationEnded:g,endConversation:ie,closeWidget:fe,isInitial:i.length===0&&!p,botLabel:Ke}),(0,O.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:p?(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Bh,{agentId:He,chatId:r,siteId:Ue,apiBaseUrl:We,historyRef:ne,onMessageSync:re,onEnd:Qe})},`voice`):i.length===0?(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Pn,{greetings:Re,recommendations:Le,onSendMessage:C,visitorEmail:l,emailInput:Ee,setEmailInput:De,emailError:Oe,setEmailError:T,onCaptureEmail:ue,botLabel:Ke})},`welcome`):(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Nn,{chatHistory:i,isAiTyping:d,isAgentTyping:u,setReplyContext:Ce,TypingDots:Hh})},`history`)}),(0,O.jsx)(Rn,{webRTCError:te,micError:be,setMicError:xe,dismissCallError:le,incomingCall:_,rejectCall:oe,acceptCall:ae,activeCallId:y,callConnectionState:b,formatCallDuration:$e,callDurationSeconds:we,endWebRTCCall:se,isCallMuted:ee,toggleCallMute:ce,isAIVoiceActive:p,currentCallAgentName:qe,isRateLimited:m,rateLimitMessage:h}),!p&&(0,O.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,O.jsx)(Fn,{input:ge,setInput:_e,onSubmit:Xe,isConversationEnded:g,callUiActive:!!(_||y),handleToggleVoice:Ze,activeScreen:o,inputDisabled:f||m||g,replyContext:Se,clearReplyContext:()=>Ce(null),requiresEmail:Je,emailInput:Ee,setEmailInput:De,emailError:Oe})}),!E&&(0,O.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,O.jsxs)(`div`,{children:[`Powered by `,(0,O.jsx)(`span`,{style:{color:`#3b82f6`},children:`Flow`}),(0,O.jsx)(`span`,{style:{color:`#ef4444`},children:`Engage`})]})})]})]}):null}var Wh=`/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */
338
- @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-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}.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}.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}.uppercase{text-transform:uppercase}.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}.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,)}.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-ease{syntax:"*";inherits:false}`,Gh=null,Kh=!1;function qh(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=Wh,document.head.appendChild(e)}function Jh(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function Yh({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Kh){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.`),Jh(()=>Yh({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),qh(),Gh=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};Gh.render(v.createElement(gn,{siteId:e,language:t,config:a},v.createElement(Uh))),Kh=!0}var Xh={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Jh(()=>Yh({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):Jh(()=>Yh({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){Gh&&=(Gh.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Kh=!1}},Zh=()=>{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}};Jh(()=>Yh({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,Zh):Zh(),typeof window<`u`&&(window.FlowEngage=Xh),Xh})();
337
+ `})]})});function qh(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,visitorEmail:l,isAgentTyping:u,isAiTyping:d,isLoading:f,isVoiceMode:p,isRateLimited:m,rateLimitMessage:h,isConversationEnded:g,incomingCall:_,activeCallId:y,callConnectionState:b,callConnectedAt:x,isCallMuted:ee,webRTCError:te,language:S,historyRef:ne,onMessageSync:re,endConversation:ie,acceptCall:ae,rejectCall:oe,endWebRTCCall:se,toggleCallMute:ce,dismissCallError:le,captureVisitorEmail:ue,openWidget:de,closeWidget:fe,sendMessage:C,setVoiceMode:w,startTyping:pe,stopTyping:me,updateTypingDraft:he}=$t(),[ge,_e]=(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)(l||``),[Oe,T]=(0,v.useState)(``),ke=t?.widgetSettings||{},Ae=n?.widgetSettings||{},je={...ke.branding||{},...Ae.branding||{}},Me={...ke.theme||{},...Ae.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=Ae.recommendations?.[S]||ke.recommendations?.[S]||Gh,Re=Ae.greetings?.[S]||ke.greetings?.[S],ze=je.chatButtonText||`Chat with us`,Be=je.headerName||t?.websiteName||`OpenSense Labs`,Ve=je.logoUrl||null,E=je.hideWatermark||!1,He=Ae.elevenLabsAgentId||t?.elevenLabsAgentId||null,Ue=t?.siteId||n?.siteId||null,We=t?.apiBaseUrl||``,Ge=je.fallbackAgentName||`Agent`,Ke=je.botLabel||`AI`,qe=_?.agentName||c||Ge,Je=!l&&i.length===0;(0,v.useEffect)(()=>{De(l||``),l&&T(``)},[l]),(0,v.useEffect)(()=>{if(!x||b!==`connected`){Te(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||Te(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[x,b]),(0,v.useEffect)(()=>{if(!s||p||g){he(``),me();return}if(!ge.trim()){he(``),me();return}pe();let e=window.setTimeout(()=>{he(ge)},120),t=window.setTimeout(()=>{me()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[ge,s,p,g,pe,me,he]);let Ye=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Xe=async e=>{if(e.preventDefault(),g)return;if(Je){let e=Ee.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){T(`Please enter a valid email to start the chat.`);return}await ue(e),T(``);return}if(!ge.trim())return;let t=ge.trim(),n=Ye(Se);_e(``),Ce(null),await C(t,``,n)},Ze=async()=>{if(Je){T(`Please share your email before starting a call.`);return}if(p){w(!1);return}xe(null);try{ye(await navigator.mediaDevices.getUserMedia({audio:!0})),w(!0)}catch(e){xe(e.message||`Could not access microphone.`)}},Qe=()=>{ve&&(ve.getTracks().forEach(e=>e.stop()),ye(null)),w(!1)},$e=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,O.jsxs)(`div`,{className:`flowengage-shell`,"data-open":a?`true`:`false`,style:Ie,children:[(0,O.jsx)(En,{isOpen:a,openWidget:de,launcherText:ze,primaryColor:Ne,posInline:Fe}),a&&(0,O.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!p?`linear-gradient(to bottom, ${Ne} 0%, ${Ne} 70%, white 85%)`:`white`},children:[(0,O.jsx)(kn,{logoUrl:Ve,brandName:Be,agentName:c,fallbackAgentName:Ge,activeScreen:o,branding:je,isConversationEnded:g,endConversation:ie,closeWidget:fe,isInitial:i.length===0&&!p,botLabel:Ke}),(0,O.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:p?(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Wh,{agentId:He,chatId:r,siteId:Ue,apiBaseUrl:We,historyRef:ne,onMessageSync:re,onEnd:Qe})},`voice`):i.length===0?(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Pn,{greetings:Re,recommendations:Le,onSendMessage:C,visitorEmail:l,emailInput:Ee,setEmailInput:De,emailError:Oe,setEmailError:T,onCaptureEmail:ue,botLabel:Ke})},`welcome`):(0,O.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,O.jsx)(Nn,{chatHistory:i,isAiTyping:d,isAgentTyping:u,setReplyContext:Ce,TypingDots:Kh})},`history`)}),(0,O.jsx)(Rn,{webRTCError:te,micError:be,setMicError:xe,dismissCallError:le,incomingCall:_,rejectCall:oe,acceptCall:ae,activeCallId:y,callConnectionState:b,formatCallDuration:$e,callDurationSeconds:we,endWebRTCCall:se,isCallMuted:ee,toggleCallMute:ce,isAIVoiceActive:p,currentCallAgentName:qe,isRateLimited:m,rateLimitMessage:h}),!p&&(0,O.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,O.jsx)(Fn,{input:ge,setInput:_e,onSubmit:Xe,isConversationEnded:g,callUiActive:!!(_||y),handleToggleVoice:Ze,activeScreen:o,inputDisabled:f||m||g,replyContext:Se,clearReplyContext:()=>Ce(null),requiresEmail:Je,emailInput:Ee,setEmailInput:De,emailError:Oe})}),!E&&(0,O.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,O.jsxs)(`div`,{children:[`Powered by `,(0,O.jsx)(`span`,{style:{color:`#3b82f6`},children:`Flow`}),(0,O.jsx)(`span`,{style:{color:`#ef4444`},children:`Engage`})]})})]})]}):null}var Jh=`/*! tailwindcss v4.2.2 | MIT License | https://tailwindcss.com */
338
+ @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-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}.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}.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}.uppercase{text-transform:uppercase}.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}.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,)}.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-ease{syntax:"*";inherits:false}`,Yh=null,Xh=!1;function Zh(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=Jh,document.head.appendChild(e)}function Qh(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function $h({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Xh){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.`),Qh(()=>$h({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),Zh(),Yh=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};Yh.render(v.createElement(gn,{siteId:e,language:t,config:a},v.createElement(qh))),Xh=!0}var eg={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Qh(()=>$h({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):Qh(()=>$h({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){Yh&&=(Yh.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Xh=!1}},tg=()=>{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}};Qh(()=>$h({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,tg):tg(),typeof window<`u`&&(window.FlowEngage=eg),eg})();