@flowengage/react-chatbot 0.2.13 → 0.2.16

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){$t()&&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){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function Oh(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(!Eh(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function kh(e){let t=e.ownerDocument||document;if(e.labels&&e.labels.length)return e.labels[0].textContent?.trim()||null;let n=e.id;if(n)try{let e=t.querySelector(`label[for="${CSS.escape(n)}"]`);if(e)return e.textContent?.trim()||null}catch{let e=t.querySelector(`label[for="${n.replace(/"/g,`\\"`)}"]`);if(e)return e.textContent?.trim()||null}let r=e.parentElement;for(let e=0;e<4&&r;e+=1){if(r.tagName===`LABEL`)return r.textContent?.trim()||null;r=r.parentElement}return null}function Ah(){let e=[];return Oh(t=>{e.push(...Array.from(t.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=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function jh(){return Ah().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:kh(e),placeholder:e.placeholder||null}))}function Mh(){let e=[];return Oh(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function Nh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,kh(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`)].filter(Boolean).map(e=>String(e).toLowerCase()),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var Ph=28;function Fh(e,t){let n=null,r=0;for(let i of e){let e=Nh(i,t);e>r&&(r=e,n=i)}return!n||r<Ph?null:n}function Ih(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,kh(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 Lh(e){if(!e||typeof e!=`string`)return null;let t=null;return Oh(n=>{try{let r=n.getElementById(e);r&&!Eh(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Rh(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=Lh(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Lh(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 zh(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 Bh(e){let t=[];Oh(e=>{t.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let n=null,r=0;for(let i of t){let t=zh(i,e);t>r&&(r=t,n=i)}return!n||r<36?null:n}function Vh(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 Hh(e){let t=Vh(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 Uh(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!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 Wh(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 Gh(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 Kh(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=e.ownerDocument?.defaultView||window,r=n===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,a=Object.getOwnPropertyDescriptor(r,`value`);a?.set?a.set.call(e,i):e.value=i}else e.value=i;let a={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...a,inputType:`insertText`,data:i}))}catch{e.dispatchEvent(new Event(`input`,a))}e.dispatchEvent(new Event(`change`,a));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}return!0}function qh(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i={navigate_to_page:async e=>{wh(`navigate_to_page ▶ raw parameters:`,e);let t=Vh(e),n=Wh(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 sn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=nn(null,r);e&&rn(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=Vh(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=nn(n||null,r||null);return i?(rn(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=Gh(Vh(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=jh(),t=Mh();return wh(`list_page_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: use placeholder/label text, name (e.g. url), id (e.g. url-input or #url-input), or name:url / id:url-input. Then click_page_button (e.g. Conduct Audit).`})},fill_form_fields:async e=>{try{wh(`fill_form_fields ▶ raw:`,e);let t=Hh(e);if(!t.length&&r){let e=Uh(r());e.length&&(wh(`fill_form_fields · inferred from last user utterance (model omitted usable fields):`,e),t=e)}if(wh(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms, then fill_form_fields with { "fields": [ { "field_key": "url or Enter Website URL", "value": "https://..." } ] }. Do not call with empty {}.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;let i=Ah(),a=Rh(i,String(t));a||=Fh(i,String(t)),a||=Ih(i,String(t),r),a&&(Kh(a,r),n.push(String(t)))}if(!n.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=`OK_FILLED: ${n.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=Vh(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=Bh(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}}};return{...i,navigateToPage:i.navigate_to_page,highlightOnPage:i.highlight_on_page,searchSiteContent:i.search_site_content,listPageForms:i.list_page_forms,fillFormFields:i.fill_form_fields,clickPageButton:i.click_page_button}}function Jh(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=$t();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 Yh={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)`},Xh={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Zh({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),b=(0,v.useRef)(``);(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;g([]),b.current=``;let o=Jh(qh({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>b.current})),s=await Ch.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`&&(b.current=r),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 x=(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]),ee=l===`listening`||l===`speaking`,te=Xh[l]||Xh.idle,S=Yh[l]||Yh.idle;return(0,k.jsxs)(`div`,{ref:y,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)(_n,{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`)]}),h.length>0&&(0,k.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:h.map((e,t)=>(0,k.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,k.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,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)(vn,{size:18}),`End Voice Session`]}),(0,k.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){$t()&&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){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function Oh(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(!Eh(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function kh(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function Ah(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 kh(r.join(` `))}if(e.labels&&e.labels.length)return kh(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return kh(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return kh(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return kh(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=kh(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 kh(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return kh(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?kh(o):null}function jh(){let e=[];return Oh(t=>{e.push(...Array.from(t.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||e.readOnly)return!1;try{let t=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function Mh(){return jh().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:Ah(e),placeholder:e.placeholder||null}))}function Nh(){let e=[];return Oh(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function Ph(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function Fh(e){let t=Ph(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function Ih(e,t){let n=Fh(t);if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,Ah(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>Ph(e)),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var Lh=28;function Rh(e,t){let n=null,r=0;for(let i of e){let e=Ih(i,t);e>r&&(r=e,n=i)}return!n||r<Lh?null:n}function zh(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,Ah(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 Bh(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function Vh(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 Hh(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 Uh(e){if(!Hh(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,Ah(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 Wh(e,t,n){let r=String(t??``),i=String(n??``),a=qh(e,r)||Rh(e,r)||zh(e,r,i);if(!a)return[];let o=new Set([a]);if(Bh(i)&&Vh(r))for(let t of e)t!==a&&Uh(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 Gh(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 Kh(e){if(!e||typeof e!=`string`)return null;let t=null;return Oh(n=>{try{let r=n.getElementById(e);r&&!Eh(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function qh(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=Kh(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Kh(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 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 Yh(e,t){let n=[];Oh(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(Eh(e)||e.disabled)return!1;try{let t=Dh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Jh(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=Gh(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function Xh(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 Zh(e){let t=Xh(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 Qh(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 $h(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 eg(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 tg(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,t,n){if(!n?.skipScroll)try{e.scrollIntoView({block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase();if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let a=String(t);if(r===`INPUT`||r===`TEXTAREA`){let t=e.ownerDocument?.defaultView||window,n=r===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,`value`);i?.set?i.set.call(e,a):e.value=a}else e.value=a;let o={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...o,inputType:`insertText`,data:a}))}catch{e.dispatchEvent(new Event(`input`,o))}e.dispatchEvent(new Event(`change`,o));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,o)),e.dispatchEvent(new Event(`change`,o))}catch{}})}catch{}return!0}function rg(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async e=>{wh(`navigate_to_page ▶ raw parameters:`,e);let t=Xh(e),n=eg(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 sn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=nn(null,r);e&&rn(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=Xh(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=nn(n||null,r||null);return i?(rn(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=tg(Xh(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=Mh(),t=Nh();return wh(`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{wh(`fill_form_fields ▶ raw:`,e);let t=Zh(e);if(!t.length&&r){let e=r(),n=Qh(e);n.length?wh(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=$h(e),n.length&&wh(`fill_form_fields · inferred contact fields from last user utterance (empty tool params):`,n)),n.length&&(t=n)}if(wh(`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.`;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=jh(),o=Wh(a,String(t),r);if(o.length){o.forEach((e,t)=>{ng(e,r,{skipScroll:t>0})}),i=o,n.push(String(t));continue}let s=qh(a,String(t));s||=Rh(a,String(t)),s||=zh(a,String(t),r),s&&(ng(s,r),i=[s],n.push(String(t)))}if(!n.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 a=`OK_FILLED: ${n.join(`, `)}`;return wh(`fill_form_fields ✓`,a),a}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=Xh(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=Yh(n,i);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}}};return{...a,navigateToPage:a.navigate_to_page,highlightOnPage:a.highlight_on_page,searchSiteContent:a.search_site_content,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=$t();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 ag={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)`},og={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function sg({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),b=(0,v.useRef)(``);(0,v.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;g([]),b.current=``;let o=ig(rg({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>b.current})),s=await Ch.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`&&(b.current=r),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 x=(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]),ee=l===`listening`||l===`speaking`,te=og[l]||og.idle,S=ag[l]||ag.idle;return(0,k.jsxs)(`div`,{ref:y,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)(_n,{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`)]}),h.length>0&&(0,k.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:h.map((e,t)=>(0,k.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,k.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,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)(vn,{size:18}),`End Voice Session`]}),(0,k.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 Qh=[{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`}],$h=()=>(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:`
332
+ `})]})}var cg=[{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`}],lg=()=>(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:`
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 eg(){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}=Qt(),[ge,_e]=(0,v.useState)(``),[T,ve]=(0,v.useState)(null),[ye,be]=(0,v.useState)(null),[xe,Se]=(0,v.useState)(null),[Ce,we]=(0,v.useState)(0),[Te,Ee]=(0,v.useState)(l||``),[De,E]=(0,v.useState)(``),Oe=t?.widgetSettings||{},ke=n?.widgetSettings||{},Ae={...Oe.branding||{},...ke.branding||{}},je={...Oe.theme||{},...ke.theme||{}},Me=je.primaryColor||`#3B82F6`,Ne=je.accentColor||`#1D4ED8`,Pe=(je.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Fe={"--flowengage-primary":Me,"--flowengage-accent":Ne,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:Pe},Ie=ke.recommendations?.[S]||Oe.recommendations?.[S]||Qh,Le=ke.greetings?.[S]||Oe.greetings?.[S],Re=Ae.chatButtonText||`Chat with us`,ze=Ae.headerName||t?.websiteName||`OpenSense Labs`,Be=Ae.logoUrl||null,D=Ae.hideWatermark||!1,Ve=ke.elevenLabsAgentId||t?.elevenLabsAgentId||null,He=t?.siteId||n?.siteId||null,Ue=t?.apiBaseUrl||``,We=Ae.fallbackAgentName||`Agent`,Ge=Ae.botLabel||`AI`,Ke=_?.agentName||c||We,qe=!l&&i.length===0;(0,v.useEffect)(()=>{Ee(l||``),l&&E(``)},[l]),(0,v.useEffect)(()=>{if(!x||b!==`connected`){we(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||we(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 Je=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Ye=async e=>{if(e.preventDefault(),g)return;if(qe){let e=Te.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){E(`Please enter a valid email to start the chat.`);return}await ue(e),E(``);return}if(!ge.trim())return;let t=ge.trim(),n=Je(xe);_e(``),Se(null),await C(t,``,n)},Xe=async()=>{if(qe){E(`Please share your email before starting a call.`);return}if(p){w(!1);return}be(null);try{ve(await navigator.mediaDevices.getUserMedia({audio:!0})),w(!0)}catch(e){be(e.message||`Could not access microphone.`)}},Ze=()=>{T&&(T.getTracks().forEach(e=>e.stop()),ve(null)),w(!1)},Qe=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:Fe,children:[(0,k.jsx)(Tn,{isOpen:a,openWidget:de,launcherText:Re,primaryColor:Me,posInline:Pe}),a&&(0,k.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!p?`linear-gradient(to bottom, ${Me} 0%, ${Me} 70%, white 85%)`:`white`},children:[(0,k.jsx)(On,{logoUrl:Be,brandName:ze,agentName:c,fallbackAgentName:We,activeScreen:o,branding:Ae,isConversationEnded:g,endConversation:ie,closeWidget:fe,isInitial:i.length===0&&!p,botLabel:Ge}),(0,k.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:p?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Zh,{agentId:Ve,chatId:r,siteId:He,apiBaseUrl:Ue,historyRef:ne,onMessageSync:re,onEnd:Ze})},`voice`):i.length===0?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Nn,{greetings:Le,recommendations:Ie,onSendMessage:C,visitorEmail:l,emailInput:Te,setEmailInput:Ee,emailError:De,setEmailError:E,onCaptureEmail:ue,botLabel:Ge})},`welcome`):(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Mn,{chatHistory:i,isAiTyping:d,isAgentTyping:u,setReplyContext:Se,TypingDots:$h})},`history`)}),(0,k.jsx)(Ln,{webRTCError:te,micError:ye,setMicError:be,dismissCallError:le,incomingCall:_,rejectCall:oe,acceptCall:ae,activeCallId:y,callConnectionState:b,formatCallDuration:Qe,callDurationSeconds:Ce,endWebRTCCall:se,isCallMuted:ee,toggleCallMute:ce,isAIVoiceActive:p,currentCallAgentName:Ke,isRateLimited:m,rateLimitMessage:h}),!p&&(0,k.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,k.jsx)(Pn,{input:ge,setInput:_e,onSubmit:Ye,isConversationEnded:g,callUiActive:!!(_||y),handleToggleVoice:Xe,activeScreen:o,inputDisabled:f||m||g,replyContext:xe,clearReplyContext:()=>Se(null),requiresEmail:qe,emailInput:Te,setEmailInput:Ee,emailError:De})}),!D&&(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 tg=`/*! 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}`,ng=null,rg=!1;function ig(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=tg,document.head.appendChild(e)}function ag(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function og({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(rg){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.`),ag(()=>og({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),ig(),ng=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};ng.render(v.createElement(hn,{siteId:e,language:t,config:a},v.createElement(eg))),rg=!0}var sg={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>ag(()=>og({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):ag(()=>og({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){ng&&=(ng.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),rg=!1}},cg=()=>{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}};ag(()=>og({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,cg):cg(),typeof window<`u`&&(window.FlowEngage=sg),sg})();
337
+ `})]})});function ug(){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}=Qt(),[ge,_e]=(0,v.useState)(``),[T,ve]=(0,v.useState)(null),[ye,be]=(0,v.useState)(null),[xe,Se]=(0,v.useState)(null),[Ce,we]=(0,v.useState)(0),[Te,Ee]=(0,v.useState)(l||``),[De,E]=(0,v.useState)(``),Oe=t?.widgetSettings||{},ke=n?.widgetSettings||{},Ae={...Oe.branding||{},...ke.branding||{}},je={...Oe.theme||{},...ke.theme||{}},Me=je.primaryColor||`#3B82F6`,Ne=je.accentColor||`#1D4ED8`,Pe=(je.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Fe={"--flowengage-primary":Me,"--flowengage-accent":Ne,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:Pe},Ie=ke.recommendations?.[S]||Oe.recommendations?.[S]||cg,Le=ke.greetings?.[S]||Oe.greetings?.[S],Re=Ae.chatButtonText||`Chat with us`,ze=Ae.headerName||t?.websiteName||`OpenSense Labs`,Be=Ae.logoUrl||null,D=Ae.hideWatermark||!1,Ve=ke.elevenLabsAgentId||t?.elevenLabsAgentId||null,He=t?.siteId||n?.siteId||null,Ue=t?.apiBaseUrl||``,We=Ae.fallbackAgentName||`Agent`,Ge=Ae.botLabel||`AI`,Ke=_?.agentName||c||We,qe=!l&&i.length===0;(0,v.useEffect)(()=>{Ee(l||``),l&&E(``)},[l]),(0,v.useEffect)(()=>{if(!x||b!==`connected`){we(0);return}let e=()=>{let e=new Date(x).getTime();isNaN(e)||we(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 Je=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,Ye=async e=>{if(e.preventDefault(),g)return;if(qe){let e=Te.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){E(`Please enter a valid email to start the chat.`);return}await ue(e),E(``);return}if(!ge.trim())return;let t=ge.trim(),n=Je(xe);_e(``),Se(null),await C(t,``,n)},Xe=async()=>{if(qe){E(`Please share your email before starting a call.`);return}if(p){w(!1);return}be(null);try{ve(await navigator.mediaDevices.getUserMedia({audio:!0})),w(!0)}catch(e){be(e.message||`Could not access microphone.`)}},Ze=()=>{T&&(T.getTracks().forEach(e=>e.stop()),ve(null)),w(!1)},Qe=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:Fe,children:[(0,k.jsx)(Tn,{isOpen:a,openWidget:de,launcherText:Re,primaryColor:Me,posInline:Pe}),a&&(0,k.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!p?`linear-gradient(to bottom, ${Me} 0%, ${Me} 70%, white 85%)`:`white`},children:[(0,k.jsx)(On,{logoUrl:Be,brandName:ze,agentName:c,fallbackAgentName:We,activeScreen:o,branding:Ae,isConversationEnded:g,endConversation:ie,closeWidget:fe,isInitial:i.length===0&&!p,botLabel:Ge}),(0,k.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:p?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(sg,{agentId:Ve,chatId:r,siteId:He,apiBaseUrl:Ue,historyRef:ne,onMessageSync:re,onEnd:Ze})},`voice`):i.length===0?(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Nn,{greetings:Le,recommendations:Ie,onSendMessage:C,visitorEmail:l,emailInput:Te,setEmailInput:Ee,emailError:De,setEmailError:E,onCaptureEmail:ue,botLabel:Ge})},`welcome`):(0,k.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,k.jsx)(Mn,{chatHistory:i,isAiTyping:d,isAgentTyping:u,setReplyContext:Se,TypingDots:lg})},`history`)}),(0,k.jsx)(Ln,{webRTCError:te,micError:ye,setMicError:be,dismissCallError:le,incomingCall:_,rejectCall:oe,acceptCall:ae,activeCallId:y,callConnectionState:b,formatCallDuration:Qe,callDurationSeconds:Ce,endWebRTCCall:se,isCallMuted:ee,toggleCallMute:ce,isAIVoiceActive:p,currentCallAgentName:Ke,isRateLimited:m,rateLimitMessage:h}),!p&&(0,k.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,k.jsx)(Pn,{input:ge,setInput:_e,onSubmit:Ye,isConversationEnded:g,callUiActive:!!(_||y),handleToggleVoice:Xe,activeScreen:o,inputDisabled:f||m||g,replyContext:xe,clearReplyContext:()=>Se(null),requiresEmail:qe,emailInput:Te,setEmailInput:Ee,emailError:De})}),!D&&(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 dg=`/*! 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}`,fg=null,pg=!1;function mg(){if(typeof document>`u`||document.getElementById(`flowengage-styles`))return;let e=document.createElement(`style`);e.id=`flowengage-styles`,e.innerHTML=dg,document.head.appendChild(e)}function hg(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function gg({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(pg){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.`),hg(()=>gg({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),mg(),fg=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};fg.render(v.createElement(hn,{siteId:e,language:t,config:a},v.createElement(ug))),pg=!0}var _g={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>hg(()=>gg({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):hg(()=>gg({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){fg&&=(fg.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),pg=!1}},vg=()=>{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}};hg(()=>gg({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,vg):vg(),typeof window<`u`&&(window.FlowEngage=_g),_g})();
@@ -315,15 +315,15 @@ class ScribeAudioProcessor extends AudioWorkletProcessor {
315
315
 
316
316
  registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
317
317
 
318
- `),uh,dh;(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`})(uh||={}),function(e){e.MANUAL=`manual`,e.VAD=`vad`}(dh||={});var fh=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 ch(`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 lh(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}}};fh.DEFAULT_BASE_URI=`wss://api.elevenlabs.io`;var ph=class extends Rm{static startSession(e){return e.textOnly?th.startSession(e):oh.startSession(e)}};function $(...e){Yt()&&console.log(`[FlowEngage:voice-tools]`,...e)}var mh=`#flowengage-root, .flowengage-shell`;function hh(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(mh)}catch{return!1}}function gh(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function _h(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(!hh(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function vh(e){let t=e.ownerDocument||document;if(e.labels&&e.labels.length)return e.labels[0].textContent?.trim()||null;let n=e.id;if(n)try{let e=t.querySelector(`label[for="${CSS.escape(n)}"]`);if(e)return e.textContent?.trim()||null}catch{let e=t.querySelector(`label[for="${n.replace(/"/g,`\\"`)}"]`);if(e)return e.textContent?.trim()||null}let r=e.parentElement;for(let e=0;e<4&&r;e+=1){if(r.tagName===`LABEL`)return r.textContent?.trim()||null;r=r.parentElement}return null}function yh(){let e=[];return _h(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(hh(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function bh(){return yh().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:vh(e),placeholder:e.placeholder||null}))}function xh(){let e=[];return _h(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(hh(e)||e.disabled)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function Sh(e,t){let n=String(t||``).toLowerCase().trim();if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,vh(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`)].filter(Boolean).map(e=>String(e).toLowerCase()),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var Ch=28;function wh(e,t){let n=null,r=0;for(let i of e){let e=Sh(i,t);e>r&&(r=e,n=i)}return!n||r<Ch?null:n}function Th(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,vh(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 Eh(e){if(!e||typeof e!=`string`)return null;let t=null;return _h(n=>{try{let r=n.getElementById(e);r&&!hh(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Dh(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=Eh(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Eh(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 Oh(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 kh(e){let t=[];_h(e=>{t.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(hh(e)||e.disabled)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let n=null,r=0;for(let i of t){let t=Oh(i,e);t>r&&(r=t,n=i)}return!n||r<36?null:n}function Ah(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 jh(e){let t=Ah(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 Mh(e){if(!e||typeof e!=`string`)return[];let t=e.trim();if(!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 Nh(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 Ph(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 Fh(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=e.ownerDocument?.defaultView||window,r=n===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,a=Object.getOwnPropertyDescriptor(r,`value`);a?.set?a.set.call(e,i):e.value=i}else e.value=i;let a={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...a,inputType:`insertText`,data:i}))}catch{e.dispatchEvent(new Event(`input`,a))}e.dispatchEvent(new Event(`change`,a));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,a)),e.dispatchEvent(new Event(`change`,a))}catch{}})}catch{}return!0}function Ih(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i={navigate_to_page:async e=>{$(`navigate_to_page ▶ raw parameters:`,e);let t=Ah(e),n=Nh(t),r=t.section_text??t.sectionText??t.section;if($(`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 $(`navigate_to_page ✖`,e),e}try{if($(`navigate_to_page → shadowNavigate`,n),await nn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=Qt(null,r);e&&$t(e),$(`navigate_to_page · highlight`,{sectionText:r,found:!!e})}let e=`OK_NAVIGATION ${n}`;return $(`navigate_to_page ✓`,e),e}catch(e){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=Ah(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=Qt(n||null,r||null);return i?($t(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=Ph(Ah(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return $(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`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),!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){let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},list_page_forms:async()=>{let e=bh(),t=xh();return $(`list_page_forms ✓`,`${e.length} field(s)`,`${t.length} button(s)`),JSON.stringify({fields:e,buttons:t,hint:`field_key: use placeholder/label text, name (e.g. url), id (e.g. url-input or #url-input), or name:url / id:url-input. Then click_page_button (e.g. Conduct Audit).`})},fill_form_fields:async e=>{try{$(`fill_form_fields ▶ raw:`,e);let t=jh(e);if(!t.length&&r){let e=Mh(r());e.length&&($(`fill_form_fields · inferred from last user utterance (model omitted usable fields):`,e),t=e)}if($(`fill_form_fields · normalized fields:`,t),!t.length)return`No fields provided. Call list_page_forms, then fill_form_fields with { "fields": [ { "field_key": "url or Enter Website URL", "value": "https://..." } ] }. Do not call with empty {}.`;let n=[];for(let e of t){let t=e?.field_key??e?.fieldKey,r=e?.value;if(t==null||r==null)continue;let i=yh(),a=Dh(i,String(t));a||=wh(i,String(t)),a||=Th(i,String(t),r),a&&(Fh(a,r),n.push(String(t)))}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 i=`OK_FILLED: ${n.join(`, `)}`;return $(`fill_form_fields ✓`,i),i}catch(e){let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=Ah(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.`;let r=kh(n);if(!r)return $(`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 $(`click_page_button ✓`,e),e}catch(e){let t=`Click failed: ${e?.message||String(e)}`;return $(`click_page_button ✖`,t),t}}};return{...i,navigateToPage:i.navigate_to_page,highlightOnPage:i.highlight_on_page,searchSiteContent:i.search_site_content,listPageForms:i.list_page_forms,fillFormFields:i.fill_form_fields,clickPageButton:i.click_page_button}}function Lh(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Yt();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 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[d,f]=(0,l.useState)(`idle`),[p,ee]=(0,l.useState)(null),[m,te]=(0,l.useState)(!1),[ne,re]=(0,l.useState)([]),ie=(0,l.useRef)(null),ae=(0,l.useRef)(null),h=(0,l.useRef)(``);(0,l.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;re([]),h.current=``;let o=Lh(Ih({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>h.current})),s=await ph.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`&&(h.current=r),a.current=[...a.current,i],re(e=>[...e,i])},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),f(`error`),ee(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),te(!1),f(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,ie.current=s,te(!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.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),f(`error`),ee(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):ie.current&&ie.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let oe=(0,l.useCallback)(async()=>{try{await ie.current?.endSession?.()}catch{}ie.current=null,te(!1),f(`idle`),typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]),se=d===`listening`||d===`speaking`,ce=zh[d]||zh.idle,g=Rh[d]||Rh.idle;return(0,u.jsxs)(`div`,{ref:ae,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:[se&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ce}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),se&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ce}`,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:g,border:`3px solid ${ce}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:d===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${g}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,u.jsx)(fn,{size:44,color:ce})})]}),(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`)]}),ne.length>0&&(0,u.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:ne.map((e,t)=>(0,u.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,u.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,u.jsxs)(`button`,{onClick:oe,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)(pn,{size:18}),`End Voice Session`]}),(0,u.jsx)(`style`,{children:`
318
+ `),uh,dh;(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`})(uh||={}),function(e){e.MANUAL=`manual`,e.VAD=`vad`}(dh||={});var fh=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 ch(`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 lh(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}}};fh.DEFAULT_BASE_URI=`wss://api.elevenlabs.io`;var ph=class extends Rm{static startSession(e){return e.textOnly?th.startSession(e):oh.startSession(e)}};function $(...e){Yt()&&console.log(`[FlowEngage:voice-tools]`,...e)}var mh=`#flowengage-root, .flowengage-shell`;function hh(e){if(!e||typeof e.closest!=`function`)return!1;try{return!!e.closest(mh)}catch{return!1}}function gh(e){try{let t=e.ownerDocument?.defaultView;if(t)return t.getComputedStyle(e)}catch{}return window.getComputedStyle(e)}function _h(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(!hh(e))try{let t=e.contentDocument;t&&n(t)}catch{}}typeof document<`u`&&n(document)}function vh(e){return e==null?null:String(e).replace(/\u00a0/g,` `).replace(/\s*\*+\s*$/u,``).replace(/\s+/g,` `).trim()}function yh(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 vh(r.join(` `))}if(e.labels&&e.labels.length)return vh(e.labels[0].textContent);let r=e.id;if(r)try{let e=t.querySelector(`label[for="${CSS.escape(r)}"]`);if(e)return vh(e.textContent)}catch{let e=t.querySelector(`label[for="${r.replace(/"/g,`\\"`)}"]`);if(e)return vh(e.textContent)}let i=e.previousElementSibling;for(let e=0;e<6&&i;e+=1){if(i.tagName===`LABEL`)return vh(i.textContent);let e=(i.className||``).toString().toLowerCase();if(/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)){let e=vh(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 vh(a.textContent);let e=a.querySelector?.(`:scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']`);if(e?.textContent)return vh(e.textContent);a=a.parentElement}let o=e.getAttribute(`aria-label`);return o?vh(o):null}function bh(){let e=[];return _h(t=>{e.push(...Array.from(t.querySelectorAll(`input, select, textarea`)).filter(e=>{if(hh(e))return!1;let t=(e.type||``).toLowerCase();if([`hidden`,`submit`,`button`,`image`].includes(t)||e.disabled||e.readOnly)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e}function xh(){return bh().map((e,t)=>({formIndex:0,fieldIndex:t,tag:e.tagName,type:e.type||`text`,name:e.name||null,id:e.id||null,label:yh(e),placeholder:e.placeholder||null}))}function Sh(){let e=[];return _h(t=>{e.push(...Array.from(t.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(hh(e)||e.disabled)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))}),e.slice(0,60).map((e,t)=>({index:t,text:(e.textContent||e.value||``).replace(/\s+/g,` `).trim().slice(0,120)||null,ariaLabel:e.getAttribute(`aria-label`),type:e.type||e.tagName}))}function Ch(e){return String(e||``).toLowerCase().replace(/\u00a0/g,` `).replace(/\*/g,``).replace(/\s+/g,` `).trim()}function wh(e){let t=Ch(e);return t=t.replace(/\s+field\s*$/i,``).trim(),t}function Th(e,t){let n=wh(t);if(!n)return 0;let r=(e.name||``).toLowerCase(),i=(e.id||``).toLowerCase();if(r===`url`&&/url|website|domain|site|audit/.test(n)||(i===`url-input`||i.endsWith(`-url-input`))&&/url|website|domain|site|audit/.test(n))return 100;let a=[e.name,e.id,e.placeholder,yh(e),e.getAttribute(`aria-label`),e.getAttribute(`title`),e.getAttribute(`data-testid`),e.getAttribute(`autocomplete`)].filter(Boolean).map(e=>Ch(e)),o=0;for(let e of a){if(!e)continue;if(e.includes(n)||n.includes(e)){o=Math.max(o,100);continue}let t=n.split(/\s+/).filter(e=>e.length>1);if(!t.length)continue;let r=0;for(let n of t)e.includes(n)&&(r+=1);o=Math.max(o,r/t.length*88)}return o}var Eh=28;function Dh(e,t){let n=null,r=0;for(let i of e){let e=Th(i,t);e>r&&(r=e,n=i)}return!n||r<Eh?null:n}function Oh(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,yh(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 kh(e){let t=String(e??``).trim();return t?/^https?:\/\//i.test(t)?!0:/\.\w{2,}(\/|\s|$)/.test(t):!1}function Ah(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 jh(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 Mh(e){if(!jh(e))return!1;let t=(e.name||``).toLowerCase(),n=(e.id||``).toLowerCase(),r=[e.name,e.id,e.placeholder,yh(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 Nh(e,t,n){let r=String(t??``),i=String(n??``),a=Ih(e,r)||Dh(e,r)||Oh(e,r,i);if(!a)return[];let o=new Set([a]);if(kh(i)&&Ah(r))for(let t of e)t!==a&&Mh(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 Ph(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 Fh(e){if(!e||typeof e!=`string`)return null;let t=null;return _h(n=>{try{let r=n.getElementById(e);r&&!hh(r)&&r.matches?.(`input, select, textarea`)&&(t=r)}catch{}}),t}function Ih(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=Fh(i[1]);if(e)return e}let a=n.startsWith(`#`)?n.slice(1):n;if(/^[\w-]+$/.test(a)){let e=Fh(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 Lh(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 Rh(e,t){let n=[];_h(e=>{n.push(...Array.from(e.querySelectorAll(`button, [role="button"], input[type="submit"], input[type="button"]`)).filter(e=>{if(hh(e)||e.disabled)return!1;try{let t=gh(e);if(t.display===`none`||t.visibility===`hidden`)return!1}catch{}return!0}))});let r=0,i=n.map(t=>({el:t,s:Lh(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=Ph(n,r);i<t&&(t=i,e=n)}return e}return a[0]}function zh(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 Bh(e){let t=zh(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 Vh(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 Hh(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 Uh(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 Wh(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 Gh(e,t,n){if(!n?.skipScroll)try{e.scrollIntoView({block:`center`,inline:`nearest`})}catch{try{e.scrollIntoView(!0)}catch{}}try{e.focus({preventScroll:!0})}catch{try{e.focus()}catch{}}let r=e.tagName,i=(e.type||``).toLowerCase();if(r===`SELECT`)return e.value=String(t),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;if(i===`checkbox`||i===`radio`)return e.checked=[`1`,`true`,`yes`,`on`].includes(String(t).toLowerCase().trim()),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0})),!0;let a=String(t);if(r===`INPUT`||r===`TEXTAREA`){let t=e.ownerDocument?.defaultView||window,n=r===`TEXTAREA`?t.HTMLTextAreaElement.prototype:t.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(n,`value`);i?.set?i.set.call(e,a):e.value=a}else e.value=a;let o={bubbles:!0,cancelable:!0,composed:!0};try{e.dispatchEvent(new InputEvent(`input`,{...o,inputType:`insertText`,data:a}))}catch{e.dispatchEvent(new Event(`input`,o))}e.dispatchEvent(new Event(`change`,o));try{queueMicrotask(()=>{try{e.dispatchEvent(new Event(`input`,o)),e.dispatchEvent(new Event(`change`,o))}catch{}})}catch{}return!0}function Kh(e){let t=e.siteId||null,n=(e.apiBaseUrl||``).replace(/\/$/,``),r=typeof e.getLastUserVoiceText==`function`?e.getLastUserVoiceText:null,i=[],a={navigate_to_page:async e=>{$(`navigate_to_page ▶ raw parameters:`,e);let t=zh(e),n=Uh(t),r=t.section_text??t.sectionText??t.section;if($(`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 $(`navigate_to_page ✖`,e),e}try{if($(`navigate_to_page → shadowNavigate`,n),await nn(n),await new Promise(e=>setTimeout(e,400)),r&&typeof r==`string`){let e=Qt(null,r);e&&$t(e),$(`navigate_to_page · highlight`,{sectionText:r,found:!!e})}let e=`OK_NAVIGATION ${n}`;return $(`navigate_to_page ✓`,e),e}catch(e){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=zh(e),n=t?.section_id||t?.sectionId,r=t?.section_text||t?.sectionText,i=Qt(n||null,r||null);return i?($t(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=Wh(zh(e));if($(`search_site_content · query:`,r,`siteId:`,t,`apiBase:`,n||`(empty)`),!r)return $(`search_site_content ✖ missing query`),`Missing query parameter.`;if(!t)return $(`search_site_content ✖ no siteId`),`Site is not configured for search.`;if(!n)return $(`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),!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){let t=`Search error: ${e.message||`network`}`;return $(`search_site_content ✖`,t),t}},list_page_forms:async()=>{let e=xh(),t=Sh();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=Bh(e);if(!t.length&&r){let e=r(),n=Vh(e);n.length?$(`fill_form_fields · inferred URL from last user utterance (model omitted usable fields):`,n):(n=Hh(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.`;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=bh(),o=Nh(a,String(t),r);if(o.length){o.forEach((e,t)=>{Gh(e,r,{skipScroll:t>0})}),i=o,n.push(String(t));continue}let s=Ih(a,String(t));s||=Dh(a,String(t)),s||=Oh(a,String(t),r),s&&(Gh(s,r),i=[s],n.push(String(t)))}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){let t=`fill_form_fields error: ${e?.message||String(e)}`;return $(`fill_form_fields ✖`,t),t}},click_page_button:async e=>{let t=zh(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.`;let r=Rh(n,i);if(!r)return $(`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 $(`click_page_button ✓`,e),e}catch(e){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,listPageForms:a.list_page_forms,fillFormFields:a.fill_form_fields,clickPageButton:a.click_page_button}}function qh(e){return!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,async n=>{let r=Yt();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 Jh={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)`},Yh={idle:`#6366f1`,listening:`#10b981`,speaking:`#f59e0b`,error:`#ef4444`};function Xh({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,ee]=(0,l.useState)(null),[m,te]=(0,l.useState)(!1),[ne,re]=(0,l.useState)([]),ie=(0,l.useRef)(null),ae=(0,l.useRef)(null),h=(0,l.useRef)(``);(0,l.useEffect)(()=>{let t=!1,i=null;return(async()=>{try{if(await navigator.mediaDevices.getUserMedia({audio:!0}),t)return;re([]),h.current=``;let o=qh(Kh({siteId:n||null,apiBaseUrl:r||null,getLastUserVoiceText:()=>h.current})),s=await ph.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`&&(h.current=r),a.current=[...a.current,i],re(e=>[...e,i])},onError:e=>{t||(console.error(`[VoiceInterface] ElevenLabs error`,e),f(`error`),ee(`Voice session encountered an error.`))},onDisconnect:()=>{t||(console.log(`[VoiceInterface] session disconnected`),te(!1),f(`idle`))}});if(t){s.endSession().catch(()=>{});return}i=s,ie.current=s,te(!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.`)}catch{}typeof c==`function`&&c()}catch(e){t||(console.error(`[VoiceInterface] startSession failed`,e),f(`error`),ee(`Could not start voice session. Please try again.`))}})(),()=>{t=!0,i?i.endSession().catch(()=>{}):ie.current&&ie.current.endSession().catch(()=>{})}},[e,n,r,a,c]);let oe=(0,l.useCallback)(async()=>{try{await ie.current?.endSession?.()}catch{}ie.current=null,te(!1),f(`idle`),typeof s==`function`&&await s(a.current),typeof i==`function`&&i()},[a,s,i]),se=d===`listening`||d===`speaking`,ce=Yh[d]||Yh.idle,g=Jh[d]||Jh.idle;return(0,u.jsxs)(`div`,{ref:ae,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:[se&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-16px`,borderRadius:`50%`,border:`2px solid ${ce}`,animation:`fe-orb-pulse 1.4s ease-in-out infinite`,opacity:.6}}),se&&(0,u.jsx)(`div`,{style:{position:`absolute`,inset:`-8px`,borderRadius:`50%`,border:`2px solid ${ce}`,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:g,border:`3px solid ${ce}`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.35s ease`,transform:d===`speaking`?`scale(1.08)`:`scale(1)`,boxShadow:`0 0 40px ${g}, 0 8px 32px rgba(0,0,0,0.08)`},children:(0,u.jsx)(fn,{size:44,color:ce})})]}),(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`)]}),ne.length>0&&(0,u.jsx)(`div`,{style:{width:`100%`,maxHeight:`160px`,overflowY:`auto`,display:`flex`,flexDirection:`column`,gap:`8px`,padding:`0 4px`},children:ne.map((e,t)=>(0,u.jsx)(`div`,{style:{display:`flex`,justifyContent:e.sender===`user`?`flex-end`:`flex-start`},children:(0,u.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,u.jsxs)(`button`,{onClick:oe,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)(pn,{size:18}),`End Voice Session`]}),(0,u.jsx)(`style`,{children:`
319
319
  @keyframes fe-orb-pulse {
320
320
  0% { transform: scale(1); opacity: 0.6; }
321
321
  50% { transform: scale(1.18); opacity: 0.15; }
322
322
  100% { transform: scale(1); opacity: 0.6; }
323
323
  }
324
- `})]})}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,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:`
324
+ `})]})}var Zh=[{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`}],Qh=()=>(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:`
325
325
  @keyframes fe-dot-bounce {
326
326
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
327
327
  40% { transform: translateY(-5px); opacity: 1; }
328
328
  }
329
- `})]})});function Uh(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,visitorEmail:d,isAgentTyping:f,isAiTyping:p,isLoading:ee,isVoiceMode:m,isRateLimited:te,rateLimitMessage:ne,isConversationEnded:re,incomingCall:ie,activeCallId:ae,callConnectionState:h,callConnectedAt:oe,isCallMuted:se,webRTCError:ce,language:g,historyRef:_,onMessageSync:le,endConversation:ue,acceptCall:de,rejectCall:fe,endWebRTCCall:pe,toggleCallMute:me,dismissCallError:he,captureVisitorEmail:ge,openWidget:_e,closeWidget:ve,sendMessage:ye,setVoiceMode:be,startTyping:xe,stopTyping:Se,updateTypingDraft:Ce}=Jt(),[we,Te]=(0,l.useState)(``),[Ee,De]=(0,l.useState)(null),[Oe,ke]=(0,l.useState)(null),[Ae,je]=(0,l.useState)(null),[Me,v]=(0,l.useState)(0),[Ne,Pe]=(0,l.useState)(d||``),[Fe,y]=(0,l.useState)(``),Ie=t?.widgetSettings||{},Le=n?.widgetSettings||{},Re={...Ie.branding||{},...Le.branding||{}},ze={...Ie.theme||{},...Le.theme||{}},Be=ze.primaryColor||`#3B82F6`,Ve=ze.accentColor||`#1D4ED8`,He=(ze.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Ue={"--flowengage-primary":Be,"--flowengage-accent":Ve,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:He},We=Le.recommendations?.[g]||Ie.recommendations?.[g]||Vh,Ge=Le.greetings?.[g]||Ie.greetings?.[g],Ke=Re.chatButtonText||`Chat with us`,b=Re.headerName||t?.websiteName||`OpenSense Labs`,x=Re.logoUrl||null,S=Re.hideWatermark||!1,qe=Le.elevenLabsAgentId||t?.elevenLabsAgentId||null,Je=t?.siteId||n?.siteId||null,Ye=t?.apiBaseUrl||``,Xe=Re.fallbackAgentName||`Agent`,Ze=Re.botLabel||`AI`,Qe=ie?.agentName||c||Xe,$e=!d&&i.length===0;(0,l.useEffect)(()=>{Pe(d||``),d&&y(``)},[d]),(0,l.useEffect)(()=>{if(!oe||h!==`connected`){v(0);return}let e=()=>{let e=new Date(oe).getTime();isNaN(e)||v(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[oe,h]),(0,l.useEffect)(()=>{if(!s||m||re){Ce(``),Se();return}if(!we.trim()){Ce(``),Se();return}xe();let e=window.setTimeout(()=>{Ce(we)},120),t=window.setTimeout(()=>{Se()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[we,s,m,re,xe,Se,Ce]);let et=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,tt=async e=>{if(e.preventDefault(),re)return;if($e){let e=Ne.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){y(`Please enter a valid email to start the chat.`);return}await ge(e),y(``);return}if(!we.trim())return;let t=we.trim(),n=et(Ae);Te(``),je(null),await ye(t,``,n)},nt=async()=>{if($e){y(`Please share your email before starting a call.`);return}if(m){be(!1);return}ke(null);try{De(await navigator.mediaDevices.getUserMedia({audio:!0})),be(!0)}catch(e){ke(e.message||`Could not access microphone.`)}},rt=()=>{Ee&&(Ee.getTracks().forEach(e=>e.stop()),De(null)),be(!1)},it=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:Ue,children:[(0,u.jsx)(bn,{isOpen:a,openWidget:_e,launcherText:Ke,primaryColor:Be,posInline:He}),a&&(0,u.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!m?`linear-gradient(to bottom, ${Be} 0%, ${Be} 70%, white 85%)`:`white`},children:[(0,u.jsx)(Cn,{logoUrl:x,brandName:b,agentName:c,fallbackAgentName:Xe,activeScreen:o,branding:Re,isConversationEnded:re,endConversation:ue,closeWidget:ve,isInitial:i.length===0&&!m,botLabel:Ze}),(0,u.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:m?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Bh,{agentId:qe,chatId:r,siteId:Je,apiBaseUrl:Ye,historyRef:_,onMessageSync:le,onEnd:rt})},`voice`):i.length===0?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(On,{greetings:Ge,recommendations:We,onSendMessage:ye,visitorEmail:d,emailInput:Ne,setEmailInput:Pe,emailError:Fe,setEmailError:y,onCaptureEmail:ge,botLabel:Ze})},`welcome`):(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Dn,{chatHistory:i,isAiTyping:p,isAgentTyping:f,setReplyContext:je,TypingDots:Hh})},`history`)}),(0,u.jsx)(Mn,{webRTCError:ce,micError:Oe,setMicError:ke,dismissCallError:he,incomingCall:ie,rejectCall:fe,acceptCall:de,activeCallId:ae,callConnectionState:h,formatCallDuration:it,callDurationSeconds:Me,endWebRTCCall:pe,isCallMuted:se,toggleCallMute:me,isAIVoiceActive:m,currentCallAgentName:Qe,isRateLimited:te,rateLimitMessage:ne}),!m&&(0,u.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,u.jsx)(kn,{input:we,setInput:Te,onSubmit:tt,isConversationEnded:re,callUiActive:!!(ie||ae),handleToggleVoice:nt,activeScreen:o,inputDisabled:ee||te||re,replyContext:Ae,clearReplyContext:()=>je(null),requiresEmail:$e,emailInput:Ne,setEmailInput:Pe,emailError:Fe})}),!S&&(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=un,exports.FlowEngageWidget=Uh,exports.useFlowEngage=Jt;
329
+ `})]})});function $h(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,visitorEmail:d,isAgentTyping:f,isAiTyping:p,isLoading:ee,isVoiceMode:m,isRateLimited:te,rateLimitMessage:ne,isConversationEnded:re,incomingCall:ie,activeCallId:ae,callConnectionState:h,callConnectedAt:oe,isCallMuted:se,webRTCError:ce,language:g,historyRef:_,onMessageSync:le,endConversation:ue,acceptCall:de,rejectCall:fe,endWebRTCCall:pe,toggleCallMute:me,dismissCallError:he,captureVisitorEmail:ge,openWidget:_e,closeWidget:ve,sendMessage:ye,setVoiceMode:be,startTyping:xe,stopTyping:Se,updateTypingDraft:Ce}=Jt(),[we,Te]=(0,l.useState)(``),[Ee,De]=(0,l.useState)(null),[Oe,ke]=(0,l.useState)(null),[Ae,je]=(0,l.useState)(null),[Me,v]=(0,l.useState)(0),[Ne,Pe]=(0,l.useState)(d||``),[Fe,y]=(0,l.useState)(``),Ie=t?.widgetSettings||{},Le=n?.widgetSettings||{},Re={...Ie.branding||{},...Le.branding||{}},ze={...Ie.theme||{},...Le.theme||{}},Be=ze.primaryColor||`#3B82F6`,Ve=ze.accentColor||`#1D4ED8`,He=(ze.position||`bottom-right`)===`bottom-left`?{left:`1.5rem`,bottom:`1.5rem`}:{right:`1.5rem`,bottom:`1.5rem`},Ue={"--flowengage-primary":Be,"--flowengage-accent":Ve,position:`fixed`,zIndex:999999,border:`none`,outline:`none`,fontFamily:`ui-sans-serif, system-ui, sans-serif`,...a?{}:He},We=Le.recommendations?.[g]||Ie.recommendations?.[g]||Zh,Ge=Le.greetings?.[g]||Ie.greetings?.[g],Ke=Re.chatButtonText||`Chat with us`,b=Re.headerName||t?.websiteName||`OpenSense Labs`,x=Re.logoUrl||null,S=Re.hideWatermark||!1,qe=Le.elevenLabsAgentId||t?.elevenLabsAgentId||null,Je=t?.siteId||n?.siteId||null,Ye=t?.apiBaseUrl||``,Xe=Re.fallbackAgentName||`Agent`,Ze=Re.botLabel||`AI`,Qe=ie?.agentName||c||Xe,$e=!d&&i.length===0;(0,l.useEffect)(()=>{Pe(d||``),d&&y(``)},[d]),(0,l.useEffect)(()=>{if(!oe||h!==`connected`){v(0);return}let e=()=>{let e=new Date(oe).getTime();isNaN(e)||v(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[oe,h]),(0,l.useEffect)(()=>{if(!s||m||re){Ce(``),Se();return}if(!we.trim()){Ce(``),Se();return}xe();let e=window.setTimeout(()=>{Ce(we)},120),t=window.setTimeout(()=>{Se()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[we,s,m,re,xe,Se,Ce]);let et=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null,tt=async e=>{if(e.preventDefault(),re)return;if($e){let e=Ne.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)){y(`Please enter a valid email to start the chat.`);return}await ge(e),y(``);return}if(!we.trim())return;let t=we.trim(),n=et(Ae);Te(``),je(null),await ye(t,``,n)},nt=async()=>{if($e){y(`Please share your email before starting a call.`);return}if(m){be(!1);return}ke(null);try{De(await navigator.mediaDevices.getUserMedia({audio:!0})),be(!0)}catch(e){ke(e.message||`Could not access microphone.`)}},rt=()=>{Ee&&(Ee.getTracks().forEach(e=>e.stop()),De(null)),be(!1)},it=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:Ue,children:[(0,u.jsx)(bn,{isOpen:a,openWidget:_e,launcherText:Ke,primaryColor:Be,posInline:He}),a&&(0,u.jsxs)(`div`,{className:`flowengage-chat-panel`,style:{background:i.length===0&&!m?`linear-gradient(to bottom, ${Be} 0%, ${Be} 70%, white 85%)`:`white`},children:[(0,u.jsx)(Cn,{logoUrl:x,brandName:b,agentName:c,fallbackAgentName:Xe,activeScreen:o,branding:Re,isConversationEnded:re,endConversation:ue,closeWidget:ve,isInitial:i.length===0&&!m,botLabel:Ze}),(0,u.jsx)(`div`,{style:{flex:1,overflowY:`auto`,display:`flex`,flexDirection:`column`},className:`flowengage-content-wrapper`,children:m?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Xh,{agentId:qe,chatId:r,siteId:Je,apiBaseUrl:Ye,historyRef:_,onMessageSync:le,onEnd:rt})},`voice`):i.length===0?(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(On,{greetings:Ge,recommendations:We,onSendMessage:ye,visitorEmail:d,emailInput:Ne,setEmailInput:Pe,emailError:Fe,setEmailError:y,onCaptureEmail:ge,botLabel:Ze})},`welcome`):(0,u.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`},className:`fe-screen-fade-in`,children:(0,u.jsx)(Dn,{chatHistory:i,isAiTyping:p,isAgentTyping:f,setReplyContext:je,TypingDots:Qh})},`history`)}),(0,u.jsx)(Mn,{webRTCError:ce,micError:Oe,setMicError:ke,dismissCallError:he,incomingCall:ie,rejectCall:fe,acceptCall:de,activeCallId:ae,callConnectionState:h,formatCallDuration:it,callDurationSeconds:Me,endWebRTCCall:pe,isCallMuted:se,toggleCallMute:me,isAIVoiceActive:m,currentCallAgentName:Qe,isRateLimited:te,rateLimitMessage:ne}),!m&&(0,u.jsx)(`div`,{style:{position:`relative`,zIndex:1},children:(0,u.jsx)(kn,{input:we,setInput:Te,onSubmit:tt,isConversationEnded:re,callUiActive:!!(ie||ae),handleToggleVoice:nt,activeScreen:o,inputDisabled:ee||te||re,replyContext:Ae,clearReplyContext:()=>je(null),requiresEmail:$e,emailInput:Ne,setEmailInput:Pe,emailError:Fe})}),!S&&(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=un,exports.FlowEngageWidget=$h,exports.useFlowEngage=Jt;
@@ -21708,24 +21708,48 @@ function yh(e) {
21708
21708
  typeof document < "u" && n(document);
21709
21709
  }
21710
21710
  function bh(e) {
21711
- let t = e.ownerDocument || document;
21712
- if (e.labels && e.labels.length) return e.labels[0].textContent?.trim() || null;
21713
- let n = e.id;
21714
- if (n) try {
21715
- let e = t.querySelector(`label[for="${CSS.escape(n)}"]`);
21716
- if (e) return e.textContent?.trim() || null;
21711
+ return e == null ? null : String(e).replace(/\u00a0/g, " ").replace(/\s*\*+\s*$/u, "").replace(/\s+/g, " ").trim();
21712
+ }
21713
+ function xh(e) {
21714
+ let t = e.ownerDocument || document, n = e.getAttribute("aria-labelledby");
21715
+ if (n) {
21716
+ let e = n.trim().split(/\s+/).filter(Boolean), r = [];
21717
+ for (let n of e) try {
21718
+ let e = t.getElementById(n);
21719
+ e?.textContent && r.push(e.textContent.trim());
21720
+ } catch {}
21721
+ if (r.length) return bh(r.join(" "));
21722
+ }
21723
+ if (e.labels && e.labels.length) return bh(e.labels[0].textContent);
21724
+ let r = e.id;
21725
+ if (r) try {
21726
+ let e = t.querySelector(`label[for="${CSS.escape(r)}"]`);
21727
+ if (e) return bh(e.textContent);
21717
21728
  } catch {
21718
- let e = t.querySelector(`label[for="${n.replace(/"/g, "\\\"")}"]`);
21719
- if (e) return e.textContent?.trim() || null;
21729
+ let e = t.querySelector(`label[for="${r.replace(/"/g, "\\\"")}"]`);
21730
+ if (e) return bh(e.textContent);
21731
+ }
21732
+ let i = e.previousElementSibling;
21733
+ for (let e = 0; e < 6 && i; e += 1) {
21734
+ if (i.tagName === "LABEL") return bh(i.textContent);
21735
+ let e = (i.className || "").toString().toLowerCase();
21736
+ if (/chakra-form__label|formlabel|field-label|form-label|mui-form-label/.test(e)) {
21737
+ let e = bh(i.textContent);
21738
+ if (e) return e;
21739
+ }
21740
+ i = i.previousElementSibling;
21720
21741
  }
21721
- let r = e.parentElement;
21722
- for (let e = 0; e < 4 && r; e += 1) {
21723
- if (r.tagName === "LABEL") return r.textContent?.trim() || null;
21724
- r = r.parentElement;
21742
+ let a = e.parentElement;
21743
+ for (let e = 0; e < 5 && a; e += 1) {
21744
+ if (a.tagName === "LABEL") return bh(a.textContent);
21745
+ let e = a.querySelector?.(":scope > label, :scope > [class*='FormLabel'], :scope > [class*='form__label']");
21746
+ if (e?.textContent) return bh(e.textContent);
21747
+ a = a.parentElement;
21725
21748
  }
21726
- return null;
21749
+ let o = e.getAttribute("aria-label");
21750
+ return o ? bh(o) : null;
21727
21751
  }
21728
- function xh() {
21752
+ function Sh() {
21729
21753
  let e = [];
21730
21754
  return yh((t) => {
21731
21755
  e.push(...Array.from(t.querySelectorAll("input, select, textarea")).filter((e) => {
@@ -21736,7 +21760,7 @@ function xh() {
21736
21760
  "submit",
21737
21761
  "button",
21738
21762
  "image"
21739
- ].includes(t) || e.disabled) return !1;
21763
+ ].includes(t) || e.disabled || e.readOnly) return !1;
21740
21764
  try {
21741
21765
  let t = vh(e);
21742
21766
  if (t.display === "none" || t.visibility === "hidden") return !1;
@@ -21745,19 +21769,19 @@ function xh() {
21745
21769
  }));
21746
21770
  }), e;
21747
21771
  }
21748
- function Sh() {
21749
- return xh().map((e, t) => ({
21772
+ function Ch() {
21773
+ return Sh().map((e, t) => ({
21750
21774
  formIndex: 0,
21751
21775
  fieldIndex: t,
21752
21776
  tag: e.tagName,
21753
21777
  type: e.type || "text",
21754
21778
  name: e.name || null,
21755
21779
  id: e.id || null,
21756
- label: bh(e),
21780
+ label: xh(e),
21757
21781
  placeholder: e.placeholder || null
21758
21782
  }));
21759
21783
  }
21760
- function Ch() {
21784
+ function wh() {
21761
21785
  let e = [];
21762
21786
  return yh((t) => {
21763
21787
  e.push(...Array.from(t.querySelectorAll("button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"]")).filter((e) => {
@@ -21775,8 +21799,15 @@ function Ch() {
21775
21799
  type: e.type || e.tagName
21776
21800
  }));
21777
21801
  }
21778
- function wh(e, t) {
21779
- let n = String(t || "").toLowerCase().trim();
21802
+ function Th(e) {
21803
+ return String(e || "").toLowerCase().replace(/\u00a0/g, " ").replace(/\*/g, "").replace(/\s+/g, " ").trim();
21804
+ }
21805
+ function Eh(e) {
21806
+ let t = Th(e);
21807
+ return t = t.replace(/\s+field\s*$/i, "").trim(), t;
21808
+ }
21809
+ function Dh(e, t) {
21810
+ let n = Eh(t);
21780
21811
  if (!n) return 0;
21781
21812
  let r = (e.name || "").toLowerCase(), i = (e.id || "").toLowerCase();
21782
21813
  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;
@@ -21784,11 +21815,12 @@ function wh(e, t) {
21784
21815
  e.name,
21785
21816
  e.id,
21786
21817
  e.placeholder,
21787
- bh(e),
21818
+ xh(e),
21788
21819
  e.getAttribute("aria-label"),
21789
21820
  e.getAttribute("title"),
21790
- e.getAttribute("data-testid")
21791
- ].filter(Boolean).map((e) => String(e).toLowerCase()), o = 0;
21821
+ e.getAttribute("data-testid"),
21822
+ e.getAttribute("autocomplete")
21823
+ ].filter(Boolean).map((e) => Th(e)), o = 0;
21792
21824
  for (let e of a) {
21793
21825
  if (!e) continue;
21794
21826
  if (e.includes(n) || n.includes(e)) {
@@ -21803,16 +21835,16 @@ function wh(e, t) {
21803
21835
  }
21804
21836
  return o;
21805
21837
  }
21806
- var Th = 28;
21807
- function Eh(e, t) {
21838
+ var Oh = 28;
21839
+ function kh(e, t) {
21808
21840
  let n = null, r = 0;
21809
21841
  for (let i of e) {
21810
- let e = wh(i, t);
21842
+ let e = Dh(i, t);
21811
21843
  e > r && (r = e, n = i);
21812
21844
  }
21813
- return !n || r < Th ? null : n;
21845
+ return !n || r < Oh ? null : n;
21814
21846
  }
21815
- function Dh(e, t, n) {
21847
+ function Ah(e, t, n) {
21816
21848
  let r = String(t || "").toLowerCase().trim(), i = String(n || "").trim();
21817
21849
  if (!(/^https?:\/\//i.test(i) || /\.\w{2,}(\/|\s|$)/.test(i) || r.includes("url") || r.includes("website") || r.includes("domain") || r.includes("site"))) return null;
21818
21850
  let a = null, o = 0;
@@ -21832,7 +21864,7 @@ function Dh(e, t, n) {
21832
21864
  t.name,
21833
21865
  t.id,
21834
21866
  t.placeholder,
21835
- bh(t),
21867
+ xh(t),
21836
21868
  t.getAttribute("aria-label"),
21837
21869
  t.getAttribute("autocomplete")
21838
21870
  ].filter(Boolean).join(" ").toLowerCase();
@@ -21840,7 +21872,65 @@ function Dh(e, t, n) {
21840
21872
  }
21841
21873
  return !a || o < 42 ? null : a;
21842
21874
  }
21843
- function Oh(e) {
21875
+ function jh(e) {
21876
+ let t = String(e ?? "").trim();
21877
+ return t ? /^https?:\/\//i.test(t) ? !0 : /\.\w{2,}(\/|\s|$)/.test(t) : !1;
21878
+ }
21879
+ function Mh(e) {
21880
+ let t = String(e ?? "").toLowerCase().trim();
21881
+ 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;
21882
+ }
21883
+ function Nh(e) {
21884
+ if (!e || e.tagName !== "INPUT" && e.tagName !== "TEXTAREA") return !1;
21885
+ let t = (e.type || "").toLowerCase();
21886
+ return ![
21887
+ "hidden",
21888
+ "submit",
21889
+ "button",
21890
+ "checkbox",
21891
+ "radio",
21892
+ "file"
21893
+ ].includes(t);
21894
+ }
21895
+ function Ph(e) {
21896
+ if (!Nh(e)) return !1;
21897
+ let t = (e.name || "").toLowerCase(), n = (e.id || "").toLowerCase(), r = [
21898
+ e.name,
21899
+ e.id,
21900
+ e.placeholder,
21901
+ xh(e),
21902
+ e.getAttribute("aria-label")
21903
+ ].filter(Boolean).join(" ").toLowerCase();
21904
+ 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);
21905
+ }
21906
+ function Fh(e, t, n) {
21907
+ let r = String(t ?? ""), i = String(n ?? ""), a = Rh(e, r) || kh(e, r) || Ah(e, r, i);
21908
+ if (!a) return [];
21909
+ let o = new Set([a]);
21910
+ if (jh(i) && Mh(r)) for (let t of e) t !== a && Ph(t) && o.add(t);
21911
+ let s = Array.from(o);
21912
+ return s.sort((e, t) => {
21913
+ if (e === t) return 0;
21914
+ let n = e.compareDocumentPosition(t);
21915
+ return n & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : n & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0;
21916
+ }), s;
21917
+ }
21918
+ function Ih(e, t) {
21919
+ try {
21920
+ if (!e?.getBoundingClientRect || !t?.getBoundingClientRect) return Infinity;
21921
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), i = {
21922
+ x: n.left + n.width / 2,
21923
+ y: n.top + n.height / 2
21924
+ }, a = {
21925
+ x: r.left + r.width / 2,
21926
+ y: r.top + r.height / 2
21927
+ };
21928
+ return Math.hypot(i.x - a.x, i.y - a.y);
21929
+ } catch {
21930
+ return Infinity;
21931
+ }
21932
+ }
21933
+ function Lh(e) {
21844
21934
  if (!e || typeof e != "string") return null;
21845
21935
  let t = null;
21846
21936
  return yh((n) => {
@@ -21850,7 +21940,7 @@ function Oh(e) {
21850
21940
  } catch {}
21851
21941
  }), t;
21852
21942
  }
21853
- function kh(e, t) {
21943
+ function Rh(e, t) {
21854
21944
  let n = String(t ?? "").trim();
21855
21945
  if (!n) return null;
21856
21946
  let r = n.match(/^name:\s*([\w.-]+)$/i);
@@ -21860,12 +21950,12 @@ function kh(e, t) {
21860
21950
  }
21861
21951
  let i = n.match(/^id:\s*([\w.-]+)$/i);
21862
21952
  if (i) {
21863
- let e = Oh(i[1]);
21953
+ let e = Lh(i[1]);
21864
21954
  if (e) return e;
21865
21955
  }
21866
21956
  let a = n.startsWith("#") ? n.slice(1) : n;
21867
21957
  if (/^[\w-]+$/.test(a)) {
21868
- let e = Oh(a);
21958
+ let e = Lh(a);
21869
21959
  if (e) return e;
21870
21960
  }
21871
21961
  let o = n.toLowerCase().replace(/\s+/g, " ");
@@ -21875,7 +21965,7 @@ function kh(e, t) {
21875
21965
  }
21876
21966
  return null;
21877
21967
  }
21878
- function Ah(e, t) {
21968
+ function zh(e, t) {
21879
21969
  let n = String(t || "").toLowerCase().trim();
21880
21970
  if (!n) return 0;
21881
21971
  let r = [
@@ -21891,10 +21981,10 @@ function Ah(e, t) {
21891
21981
  for (let e of i) r.includes(e) && (a += 1);
21892
21982
  return a / i.length * 92;
21893
21983
  }
21894
- function jh(e) {
21895
- let t = [];
21984
+ function Bh(e, t) {
21985
+ let n = [];
21896
21986
  yh((e) => {
21897
- t.push(...Array.from(e.querySelectorAll("button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"]")).filter((e) => {
21987
+ n.push(...Array.from(e.querySelectorAll("button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"]")).filter((e) => {
21898
21988
  if (_h(e) || e.disabled) return !1;
21899
21989
  try {
21900
21990
  let t = vh(e);
@@ -21903,14 +21993,26 @@ function jh(e) {
21903
21993
  return !0;
21904
21994
  }));
21905
21995
  });
21906
- let n = null, r = 0;
21907
- for (let i of t) {
21908
- let t = Ah(i, e);
21909
- t > r && (r = t, n = i);
21996
+ let r = 0, i = n.map((t) => ({
21997
+ el: t,
21998
+ s: zh(t, e)
21999
+ }));
22000
+ for (let { s: e } of i) e > r && (r = e);
22001
+ if (r < 36) return null;
22002
+ let a = i.filter(({ s: e }) => e === r).map(({ el: e }) => e);
22003
+ if (a.length === 1) return a[0];
22004
+ let o = Array.isArray(t) ? t.filter((e) => e && e.isConnected) : [];
22005
+ if (o.length) {
22006
+ let e = a[0], t = Infinity;
22007
+ for (let n of a) for (let r of o) {
22008
+ let i = Ih(n, r);
22009
+ i < t && (t = i, e = n);
22010
+ }
22011
+ return e;
21910
22012
  }
21911
- return !n || r < 36 ? null : n;
22013
+ return a[0];
21912
22014
  }
21913
- function Mh(e) {
22015
+ function Vh(e) {
21914
22016
  if (e == null) return {};
21915
22017
  if (typeof e == "string") {
21916
22018
  let t = e.trim();
@@ -21923,8 +22025,8 @@ function Mh(e) {
21923
22025
  }
21924
22026
  return e;
21925
22027
  }
21926
- function Nh(e) {
21927
- let t = Mh(e);
22028
+ function Hh(e) {
22029
+ let t = Vh(e);
21928
22030
  if (Array.isArray(t) && t.length > 0) {
21929
22031
  let e = t[0];
21930
22032
  if (e?.field_key != null || e?.fieldKey != null) return t.map((e) => ({
@@ -21952,10 +22054,10 @@ function Nh(e) {
21952
22054
  value: e?.value ?? e?.Value
21953
22055
  })) : [];
21954
22056
  }
21955
- function Ph(e) {
22057
+ function Uh(e) {
21956
22058
  if (!e || typeof e != "string") return [];
21957
22059
  let t = e.trim();
21958
- if (!t) return [];
22060
+ if (!t || /\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\b/i.test(t)) return [];
21959
22061
  let n = t.match(/https?:\/\/[^\s<>"']+/i);
21960
22062
  if (n) return [{
21961
22063
  field_key: "url",
@@ -21971,18 +22073,54 @@ function Ph(e) {
21971
22073
  }
21972
22074
  return [];
21973
22075
  }
21974
- function Fh(e) {
22076
+ function Wh(e) {
22077
+ if (!e || typeof e != "string") return [];
22078
+ let t = e.trim();
22079
+ if (!t) return [];
22080
+ let n = [], r = /* @__PURE__ */ new Set(), i = /\b([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\b/i, a = (e, t) => {
22081
+ let i = String(t ?? "").trim().replace(/^["']|["']$/g, "");
22082
+ if (!i || i.length > 800) return;
22083
+ let a = `${e}\0${i}`;
22084
+ r.has(a) || (r.add(a), n.push({
22085
+ field_key: e,
22086
+ value: i
22087
+ }));
22088
+ }, o = t.match(/^\s*([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,})\s*$/i);
22089
+ if (o) return a("Email Address", o[1]), n;
22090
+ 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);
22091
+ 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) {
22092
+ let e = s[1].trim();
22093
+ e.length > 1 && e.length < 120 && !/@/.test(e) && a("Full Name", e);
22094
+ }
22095
+ 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) {
22096
+ let e = s[1].trim();
22097
+ e.length > 0 && a("Message", e);
22098
+ }
22099
+ if (!n.some((e) => /email/i.test(String(e.field_key)))) {
22100
+ let e = t.match(i);
22101
+ if (e) {
22102
+ 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();
22103
+ if (t.length <= 96 && r.length <= 36) return a("Email Address", e[1]), n;
22104
+ }
22105
+ }
22106
+ if (n.length === 0) {
22107
+ 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());
22108
+ n && t.length >= 16 && !i.test(t) && !r && a("Message", t);
22109
+ }
22110
+ return n;
22111
+ }
22112
+ function Gh(e) {
21975
22113
  if (!e || typeof e != "object") return null;
21976
22114
  let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
21977
22115
  return t == null ? null : String(t).trim() || null;
21978
22116
  }
21979
- function Ih(e) {
22117
+ function Kh(e) {
21980
22118
  if (!e || typeof e != "object") return null;
21981
22119
  let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
21982
22120
  return t == null ? null : String(t).trim() || null;
21983
22121
  }
21984
- function Lh(e, t) {
21985
- try {
22122
+ function qh(e, t, n) {
22123
+ if (!n?.skipScroll) try {
21986
22124
  e.scrollIntoView({
21987
22125
  block: "center",
21988
22126
  inline: "nearest"
@@ -21999,48 +22137,48 @@ function Lh(e, t) {
21999
22137
  e.focus();
22000
22138
  } catch {}
22001
22139
  }
22002
- let n = e.tagName, r = (e.type || "").toLowerCase();
22003
- if (n === "SELECT") return e.value = String(t), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 })), !0;
22004
- if (r === "checkbox" || r === "radio") return e.checked = [
22140
+ let r = e.tagName, i = (e.type || "").toLowerCase();
22141
+ if (r === "SELECT") return e.value = String(t), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 })), !0;
22142
+ if (i === "checkbox" || i === "radio") return e.checked = [
22005
22143
  "1",
22006
22144
  "true",
22007
22145
  "yes",
22008
22146
  "on"
22009
22147
  ].includes(String(t).toLowerCase().trim()), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 })), !0;
22010
- let i = String(t);
22011
- if (n === "INPUT" || n === "TEXTAREA") {
22012
- let t = e.ownerDocument?.defaultView || window, r = n === "TEXTAREA" ? t.HTMLTextAreaElement.prototype : t.HTMLInputElement.prototype, a = Object.getOwnPropertyDescriptor(r, "value");
22013
- a?.set ? a.set.call(e, i) : e.value = i;
22014
- } else e.value = i;
22015
- let a = {
22148
+ let a = String(t);
22149
+ if (r === "INPUT" || r === "TEXTAREA") {
22150
+ let t = e.ownerDocument?.defaultView || window, n = r === "TEXTAREA" ? t.HTMLTextAreaElement.prototype : t.HTMLInputElement.prototype, i = Object.getOwnPropertyDescriptor(n, "value");
22151
+ i?.set ? i.set.call(e, a) : e.value = a;
22152
+ } else e.value = a;
22153
+ let o = {
22016
22154
  bubbles: !0,
22017
22155
  cancelable: !0,
22018
22156
  composed: !0
22019
22157
  };
22020
22158
  try {
22021
22159
  e.dispatchEvent(new InputEvent("input", {
22022
- ...a,
22160
+ ...o,
22023
22161
  inputType: "insertText",
22024
- data: i
22162
+ data: a
22025
22163
  }));
22026
22164
  } catch {
22027
- e.dispatchEvent(new Event("input", a));
22165
+ e.dispatchEvent(new Event("input", o));
22028
22166
  }
22029
- e.dispatchEvent(new Event("change", a));
22167
+ e.dispatchEvent(new Event("change", o));
22030
22168
  try {
22031
22169
  queueMicrotask(() => {
22032
22170
  try {
22033
- e.dispatchEvent(new Event("input", a)), e.dispatchEvent(new Event("change", a));
22171
+ e.dispatchEvent(new Event("input", o)), e.dispatchEvent(new Event("change", o));
22034
22172
  } catch {}
22035
22173
  });
22036
22174
  } catch {}
22037
22175
  return !0;
22038
22176
  }
22039
- function Rh(e) {
22040
- let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = {
22177
+ function Jh(e) {
22178
+ let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
22041
22179
  navigate_to_page: async (e) => {
22042
22180
  $("navigate_to_page ▶ raw parameters:", e);
22043
- let t = Mh(e), n = Fh(t), r = t.section_text ?? t.sectionText ?? t.section;
22181
+ let t = Vh(e), n = Gh(t), r = t.section_text ?? t.sectionText ?? t.section;
22044
22182
  if ($("navigate_to_page · coerced:", {
22045
22183
  url: n,
22046
22184
  sectionText: r
@@ -22065,12 +22203,12 @@ function Rh(e) {
22065
22203
  },
22066
22204
  highlight_on_page: async (e) => {
22067
22205
  $("highlight_on_page ▶", e);
22068
- let t = Mh(e), n = t?.section_id || t?.sectionId, r = t?.section_text || t?.sectionText, i = $t(n || null, r || null);
22206
+ let t = Vh(e), n = t?.section_id || t?.sectionId, r = t?.section_text || t?.sectionText, i = $t(n || null, r || null);
22069
22207
  return i ? (en(i), $("highlight_on_page ✓"), "Highlighted the section.") : ($("highlight_on_page ✖ no element"), "Could not find that section on the page.");
22070
22208
  },
22071
22209
  search_site_content: async (e) => {
22072
22210
  $("search_site_content ▶", e);
22073
- let r = Ih(Mh(e));
22211
+ let r = Kh(Vh(e));
22074
22212
  if ($("search_site_content · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), !r) return $("search_site_content ✖ missing query"), "Missing query parameter.";
22075
22213
  if (!t) return $("search_site_content ✖ no siteId"), "Site is not configured for search.";
22076
22214
  if (!n) return $("search_site_content ✖ no api base"), "API base URL is missing; cannot search.";
@@ -22098,41 +22236,48 @@ function Rh(e) {
22098
22236
  }
22099
22237
  },
22100
22238
  list_page_forms: async () => {
22101
- let e = Sh(), t = Ch();
22239
+ let e = Ch(), t = wh();
22102
22240
  return $("list_page_forms ✓", `${e.length} field(s)`, `${t.length} button(s)`), JSON.stringify({
22103
22241
  fields: e,
22104
22242
  buttons: t,
22105
- hint: "field_key: use placeholder/label text, name (e.g. url), id (e.g. url-input or #url-input), or name:url / id:url-input. Then click_page_button (e.g. Conduct Audit)."
22243
+ 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."
22106
22244
  });
22107
22245
  },
22108
22246
  fill_form_fields: async (e) => {
22109
22247
  try {
22110
22248
  $("fill_form_fields ▶ raw:", e);
22111
- let t = Nh(e);
22249
+ let t = Hh(e);
22112
22250
  if (!t.length && r) {
22113
- let e = Ph(r());
22114
- e.length && ($("fill_form_fields · inferred from last user utterance (model omitted usable fields):", e), t = e);
22251
+ let e = r(), n = Uh(e);
22252
+ n.length ? $("fill_form_fields · inferred URL from last user utterance (model omitted usable fields):", n) : (n = Wh(e), n.length && $("fill_form_fields · inferred contact fields from last user utterance (empty tool params):", n)), n.length && (t = n);
22115
22253
  }
22116
- if ($("fill_form_fields · normalized fields:", t), !t.length) return "No fields provided. Call list_page_forms, then fill_form_fields with { \"fields\": [ { \"field_key\": \"url or Enter Website URL\", \"value\": \"https://...\" } ] }. Do not call with empty {}.";
22254
+ 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.";
22117
22255
  let n = [];
22118
22256
  for (let e of t) {
22119
22257
  let t = e?.field_key ?? e?.fieldKey, r = e?.value;
22120
22258
  if (t == null || r == null) continue;
22121
- let i = xh(), a = kh(i, String(t));
22122
- a ||= Eh(i, String(t)), a ||= Dh(i, String(t), r), a && (Lh(a, r), n.push(String(t)));
22259
+ let a = Sh(), o = Fh(a, String(t), r);
22260
+ if (o.length) {
22261
+ o.forEach((e, t) => {
22262
+ qh(e, r, { skipScroll: t > 0 });
22263
+ }), i = o, n.push(String(t));
22264
+ continue;
22265
+ }
22266
+ let s = Rh(a, String(t));
22267
+ s ||= kh(a, String(t)), s ||= Ah(a, String(t), r), s && (qh(s, r), i = [s], n.push(String(t)));
22123
22268
  }
22124
22269
  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.";
22125
- let i = `OK_FILLED: ${n.join(", ")}`;
22126
- return $("fill_form_fields ✓", i), i;
22270
+ let a = `OK_FILLED: ${n.join(", ")}`;
22271
+ return $("fill_form_fields ✓", a), a;
22127
22272
  } catch (e) {
22128
22273
  let t = `fill_form_fields error: ${e?.message || String(e)}`;
22129
22274
  return $("fill_form_fields ✖", t), t;
22130
22275
  }
22131
22276
  },
22132
22277
  click_page_button: async (e) => {
22133
- let t = Mh(e), n = (t.button_text ?? t.buttonText ?? t.text ?? "").trim();
22278
+ let t = Vh(e), n = (t.button_text ?? t.buttonText ?? t.text ?? "").trim();
22134
22279
  if ($("click_page_button ▶", n), !n) return "Missing button_text: pass the visible label, e.g. Conduct Audit.";
22135
- let r = jh(n);
22280
+ let r = Bh(n, i);
22136
22281
  if (!r) return $("click_page_button ✖ no match"), `Could not find a button matching "${n}". Call list_page_forms to see button texts.`;
22137
22282
  try {
22138
22283
  try {
@@ -22153,18 +22298,18 @@ function Rh(e) {
22153
22298
  }
22154
22299
  };
22155
22300
  return {
22156
- ...i,
22157
- navigateToPage: i.navigate_to_page,
22158
- highlightOnPage: i.highlight_on_page,
22159
- searchSiteContent: i.search_site_content,
22160
- listPageForms: i.list_page_forms,
22161
- fillFormFields: i.fill_form_fields,
22162
- clickPageButton: i.click_page_button
22301
+ ...a,
22302
+ navigateToPage: a.navigate_to_page,
22303
+ highlightOnPage: a.highlight_on_page,
22304
+ searchSiteContent: a.search_site_content,
22305
+ listPageForms: a.list_page_forms,
22306
+ fillFormFields: a.fill_form_fields,
22307
+ clickPageButton: a.click_page_button
22163
22308
  };
22164
22309
  }
22165
22310
  //#endregion
22166
22311
  //#region src/utils/wrapVoiceToolsForLogging.js
22167
- function zh(e) {
22312
+ function Yh(e) {
22168
22313
  return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
22169
22314
  let r = Xt();
22170
22315
  r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
@@ -22174,18 +22319,18 @@ function zh(e) {
22174
22319
  }
22175
22320
  //#endregion
22176
22321
  //#region src/components/VoiceInterface.jsx
22177
- var Bh = {
22322
+ var Xh = {
22178
22323
  idle: "rgba(99,102,241,0.18)",
22179
22324
  listening: "rgba(16,185,129,0.25)",
22180
22325
  speaking: "rgba(245,158,11,0.25)",
22181
22326
  error: "rgba(239,68,68,0.2)"
22182
- }, Vh = {
22327
+ }, Zh = {
22183
22328
  idle: "#6366f1",
22184
22329
  listening: "#10b981",
22185
22330
  speaking: "#f59e0b",
22186
22331
  error: "#ef4444"
22187
22332
  };
22188
- function Hh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
22333
+ function Qh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
22189
22334
  let [ee, te] = s("idle"), [h, ne] = s(null), [re, ie] = s(!1), [ae, oe] = s([]), se = o(null), g = o(null), ce = o("");
22190
22335
  i(() => {
22191
22336
  let t = !1, n = null;
@@ -22193,7 +22338,7 @@ function Hh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22193
22338
  try {
22194
22339
  if (await navigator.mediaDevices.getUserMedia({ audio: !0 }), t) return;
22195
22340
  oe([]), ce.current = "";
22196
- let i = zh(Rh({
22341
+ let i = Yh(Jh({
22197
22342
  siteId: r || null,
22198
22343
  apiBaseUrl: a || null,
22199
22344
  getLastUserVoiceText: () => ce.current
@@ -22261,7 +22406,7 @@ function Hh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22261
22406
  d,
22262
22407
  p,
22263
22408
  c
22264
- ]), ue = ee === "listening" || ee === "speaking", de = Vh[ee] || Vh.idle, _ = Bh[ee] || Bh.idle;
22409
+ ]), ue = ee === "listening" || ee === "speaking", de = Zh[ee] || Zh.idle, _ = Xh[ee] || Xh.idle;
22265
22410
  return /* @__PURE__ */ u("div", {
22266
22411
  ref: g,
22267
22412
  style: {
@@ -22396,7 +22541,7 @@ function Hh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22396
22541
  }
22397
22542
  //#endregion
22398
22543
  //#region src/components/FlowEngageWidget.jsx
22399
- var Uh = [
22544
+ var $h = [
22400
22545
  {
22401
22546
  key: "become_client",
22402
22547
  label: "Become a Client"
@@ -22417,7 +22562,7 @@ var Uh = [
22417
22562
  key: "looking_for_job",
22418
22563
  label: "Looking for a Job"
22419
22564
  }
22420
- ], Wh = () => /* @__PURE__ */ l("div", {
22565
+ ], eg = () => /* @__PURE__ */ l("div", {
22421
22566
  style: {
22422
22567
  display: "flex",
22423
22568
  marginBottom: "12px",
@@ -22448,7 +22593,7 @@ var Uh = [
22448
22593
  } }, 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 " })]
22449
22594
  })
22450
22595
  });
22451
- function Gh() {
22596
+ function tg() {
22452
22597
  let { status: e, runtimeConfig: t, resolvedConfig: n, chatId: r, chatHistory: a, isOpen: o, activeScreen: c, isHumanHandled: d, agentName: f, visitorEmail: p, isAgentTyping: m, isAiTyping: ee, isLoading: te, isVoiceMode: h, isRateLimited: ne, rateLimitMessage: re, isConversationEnded: ie, incomingCall: ae, activeCallId: oe, callConnectionState: se, callConnectedAt: g, isCallMuted: ce, webRTCError: le, language: ue, historyRef: de, onMessageSync: _, endConversation: v, 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 } = Yt(), [Te, Ee] = s(""), [De, Oe] = s(null), [ke, Ae] = s(null), [je, Me] = s(null), [Ne, y] = s(0), [Pe, Fe] = s(p || ""), [Ie, Le] = s(""), b = t?.widgetSettings || {}, Re = n?.widgetSettings || {}, ze = {
22453
22598
  ...b.branding || {},
22454
22599
  ...Re.branding || {}
@@ -22470,7 +22615,7 @@ function Gh() {
22470
22615
  outline: "none",
22471
22616
  fontFamily: "ui-sans-serif, system-ui, sans-serif",
22472
22617
  ...o ? {} : Ue
22473
- }, Ge = Re.recommendations?.[ue] || b.recommendations?.[ue] || Uh, Ke = Re.greetings?.[ue] || b.greetings?.[ue], qe = ze.chatButtonText || "Chat with us", Je = ze.headerName || t?.websiteName || "OpenSense Labs", x = ze.logoUrl || null, S = ze.hideWatermark || !1, C = Re.elevenLabsAgentId || t?.elevenLabsAgentId || null, Ye = t?.siteId || n?.siteId || null, Xe = t?.apiBaseUrl || "", Ze = ze.fallbackAgentName || "Agent", Qe = ze.botLabel || "AI", $e = ae?.agentName || f || Ze, et = !p && a.length === 0;
22618
+ }, Ge = Re.recommendations?.[ue] || b.recommendations?.[ue] || $h, Ke = Re.greetings?.[ue] || b.greetings?.[ue], qe = ze.chatButtonText || "Chat with us", Je = ze.headerName || t?.websiteName || "OpenSense Labs", x = ze.logoUrl || null, S = ze.hideWatermark || !1, C = Re.elevenLabsAgentId || t?.elevenLabsAgentId || null, Ye = t?.siteId || n?.siteId || null, Xe = t?.apiBaseUrl || "", Ze = ze.fallbackAgentName || "Agent", Qe = ze.botLabel || "AI", $e = ae?.agentName || f || Ze, et = !p && a.length === 0;
22474
22619
  i(() => {
22475
22620
  Fe(p || ""), p && Le("");
22476
22621
  }, [p]), i(() => {
@@ -22593,7 +22738,7 @@ function Gh() {
22593
22738
  flexDirection: "column"
22594
22739
  },
22595
22740
  className: "fe-screen-fade-in",
22596
- children: /* @__PURE__ */ l(Hh, {
22741
+ children: /* @__PURE__ */ l(Qh, {
22597
22742
  agentId: C,
22598
22743
  chatId: r,
22599
22744
  siteId: Ye,
@@ -22633,7 +22778,7 @@ function Gh() {
22633
22778
  isAiTyping: ee,
22634
22779
  isAgentTyping: m,
22635
22780
  setReplyContext: Me,
22636
- TypingDots: Wh
22781
+ TypingDots: eg
22637
22782
  })
22638
22783
  }, "history")
22639
22784
  }),
@@ -22709,4 +22854,4 @@ function Gh() {
22709
22854
  }) : null;
22710
22855
  }
22711
22856
  //#endregion
22712
- export { dn as FlowEngageProvider, Gh as FlowEngageWidget, Yt as useFlowEngage };
22857
+ export { dn as FlowEngageProvider, tg as FlowEngageWidget, Yt as useFlowEngage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "0.2.13",
3
+ "version": "0.2.16",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",