@livelayer/react 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),qn=require("@livelayer/sdk"),ut=require("livekit-client");class tn extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function nn(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[c,f]=n.useState(null),[p,g]=n.useState(null),[l,u]=n.useState(null),[S,R]=n.useState(!1),[k,x]=n.useState(null),v=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const L={onConnectionStateChange:T=>{o(T),T==="connected"&&x(null)},onAgentStateChange:s,onTranscript:T=>d([...T]),onAgentConfig:f,onAudioTrack:T=>u(T),onVideoTrack:T=>g(T),onVideoTrackRemoved:()=>g(null),onError:T=>x(T),onDataMessage:T=>{var j;(j=C.current)==null||j.call(C,T)},onResumabilityChange:R},$=new qn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},L);return v.current=$,o("idle"),s("idle"),d([]),f(null),g(null),u(null),R(!1),x(null),()=>{var T;(T=$.destroy)==null||T.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const L=v.current;if(L)try{await L.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),M=n.useCallback(()=>{const L=v.current;L&&L.disconnect()},[]),b=n.useCallback(()=>{var L;return((L=v.current)==null?void 0:L.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:c,videoElement:p,audioElement:l,canResume:S,error:k,connect:E,disconnect:M,getRoom:b,session:v.current}}function rn(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),d=n.useCallback(()=>{const l=r.current;if(!l){i.current=null;return}(!a.current||a.current.length!==l.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(l.frequencyBinCount)));const u=a.current;l.getByteFrequencyData(u);let S=0;for(let k=0;k<u.length;k++)S+=u[k];const R=S/u.length/255;for(const k of s.current)try{k(R)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(d)},[]),c=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const l=new AudioContext,u=l.createAnalyser();u.fftSize=64,u.connect(l.destination),e.current=l,r.current=u},[]),f=n.useCallback(l=>{if(c(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const u=e.current.createMediaElementSource(l);u.connect(r.current),o.current=u}catch(u){console.warn("[useAudioLevel] createMediaElementSource failed:",u);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[c,d]),p=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),g=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(p(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[p]),{attach:f,detach:p,subscribe:g}}function on(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),d=n.useCallback(async g=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=g,i(null);try{const l=await ut.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.localParticipant.publishTrack(l),s.current=l,r(l.isMuted)}catch(l){const u=l instanceof Error&&l.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(u),l}},[]),c=n.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),r(!1)):(g.mute(),r(!0)))},[]),f=n.useCallback(()=>{const g=s.current,l=a.current;if(g&&l){try{l.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,a.current=null,r(!1)},[]),p=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:c,setupMic:d,teardownMic:f,clearError:p}}const Fn={resolution:{width:640,height:480,frameRate:24}};function sn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,c]=n.useState(""),f=n.useRef(null),p=n.useRef(null),g=n.useCallback(v=>{f.current=v},[]),l=n.useCallback(()=>{const v=f.current,C=p.current;if(C&&v){const E=v.localParticipant.getTrackPublication(ut.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else C.stop()}p.current=null,a(null),r(!1)},[]),u=n.useCallback(async v=>{const C=f.current;if(C){i(null);try{const E={...Fn};v&&(E.deviceId=v);const M=await ut.createLocalVideoTrack(E);await C.localParticipant.publishTrack(M),p.current=M;const b=M.attach();a(b),r(!0),v&&c(v);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const M=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(M)}}},[]),S=n.useCallback(async()=>{e?l():await u(d||void 0)},[e,d,l,u]),R=n.useCallback(async v=>{l(),await u(v)},[l,u]),k=n.useCallback(()=>{l(),f.current=null,i(null),c("")},[l]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{p.current&&p.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:S,switchDevice:R,attachRoom:g,teardown:k,clearError:x}}function an(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),c=n.useCallback(u=>{d.current=u},[]),f=n.useCallback(()=>a(null),[]),p=n.useCallback(async()=>{const u=d.current;if(u){if(e){try{await u.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1);return}i(null);try{await u.localParticipant.setScreenShareEnabled(!0);let S=0;const R=()=>{const k=u.localParticipant.getTrackPublication(ut.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();a(x),r(!0);try{u.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}S++<10?setTimeout(R,100):r(!0)};R()}catch(S){const R=S instanceof Error?S.name:"";R!=="NotAllowedError"&&R!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,f]),g=n.useCallback(()=>{const u=d.current;if(u&&e)try{u.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1),i(null),d.current=null},[e,f]),l=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:p,attachRoom:c,teardown:g,clearError:l}}function ln(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(d=>d.kind==="audioinput")),i(a.filter(d=>d.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:o,refresh:s}}function cn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[c,f]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){f(!1);return}const p=new AbortController,g=r||"https://app.livelayer.studio";return f(!0),d(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:p.signal}).then(async l=>{if(!l.ok){const u=await l.json().catch(()=>({}));throw new Error(u.error||`HTTP ${l.status}`)}return l.json()}).then(l=>{p.signal.aborted||(s(l),f(!1))}).catch(l=>{p.signal.aborted||(d(l instanceof Error?l.message:"Agent lookup failed"),f(!1))}),()=>p.abort()},[e,r,o]),{info:i,error:a,loading:c}}function Un(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Vn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function un({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,c=n.useCallback(f=>{f!==d&&(i||a(f),o==null||o(f))},[d,i,o]);return[d,c]}const Yn=["hidden","minimized","expanded"];function Gn(e){return e&&Yn.includes(e)?e:null}function dn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[c,f]=un({value:e,defaultValue:r,onChange:p=>{e===void 0&&!s&&Vn(a,p),o==null||o(p)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const p=Gn(Un(a));p&&p!==c&&f(p)},[]),[c,f]}const Kn=640;function fn(e=Kn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Ot="__llHistoryPatched",dt="ll:pathname";function Jn(){if(typeof window>"u"||window.history[Ot])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history[Ot]=!0}function Ht(){return typeof window>"u"?"/":window.location.pathname||"/"}function pn(e){const[r,o]=n.useState(()=>e??Ht());return n.useEffect(()=>{if(e!==void 0)return;Jn();const i=()=>o(Ht());return i(),window.addEventListener("popstate",i),window.addEventListener(dt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(dt,i)}},[e]),e??r}const Wt=new Map,Xn=/[\\^$+?.()|{}[\]]/g;function Qn(e){return e.replace(Xn,"\\$&")}function Zn(e){const r=Wt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),c=Qn(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),f=new RegExp(`^${c}\\/?$`);return Wt.set(e,f),f}function er(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Zn(e).test(o)}function hn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):er(e,r)}function Bt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(hn(o,r))return!0;return!1}function mn(e,r,o){return e===void 0?!0:Bt(o,e)?!1:r&&r.length>0?Bt(r,e):!0}function gn(e,r,o){return n.useMemo(()=>mn(e,r,o),[e,r,o])}function tr(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function nr(e){const r=n.useMemo(()=>tr(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(f=>{try{new Audio(`${o}${f}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),d=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),c=n.useCallback(f=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(f){if(i.current)return;try{const p=new Audio(`${o}/audio/thinking-sound.mp3`);p.loop=!0,p.volume=.3,p.play().catch(()=>{i.current=null}),i.current=p}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:d,setThinking:c}),[a,d,c])}const qt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Ft=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})}),rr=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),or={left:180,right:0,up:-90,down:90},Ut=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${or[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function ir(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const yn="ll-hidden-tab-center-y",sr=5,Vt=16;function ar(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(yn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Yt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(yn,String(e))}catch{}}const lr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d})=>{const c=ir(e),f=c==="right"?"left":"right",p=r?80:72,g=!!a,[l,u]=n.useState(null),[S,R]=n.useState(!1),k=n.useRef(null),x=n.useRef(!1),v=n.useCallback(j=>{if(typeof window>"u")return j;const A=p/2,z=Vt+A,F=window.innerHeight-Vt-A;return F<z?Math.max(z,j):Math.max(z,Math.min(F,j))},[p]);n.useEffect(()=>{const j=ar();u(v(j??window.innerHeight/2));const A=()=>{u(z=>z===null?null:v(z))};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[v]);const C=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&l!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}k.current={startClientY:j.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(j=>{const A=k.current;if(!A)return;const z=j.clientY-A.startClientY;!A.moved&&Math.abs(z)>sr&&(A.moved=!0,R(!0)),A.moved&&u(v(A.startCenterY+z))},[v]),M=n.useCallback(j=>{const A=k.current;if(A){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}k.current=null,A.moved&&(R(!1),x.current=!0,u(z=>(z!==null&&Yt(z),z)))}},[]),b=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),L=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const A=j.key==="ArrowUp"?-8:8;u(z=>{if(z===null)return z;const F=v(z+A);return Yt(F),F})}},[v]),$=["ll-hidden",`ll-hidden--${c}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,S?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),T=l===null?void 0:{top:`${l-p/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:C,onPointerMove:E,onPointerUp:M,onPointerCancel:M,onClick:b,onKeyDown:L,"aria-label":s,"data-position":e,style:T,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Ut,{direction:f,className:"ll-hidden__chevron"})})},cr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),c=n.useRef([]),f=n.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,u)=>.5+u*g%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let u=0;u<r;u++){const S=c.current[u];if(!S)continue;const R=Math.max(i,l*o*f[u]);S.style.height=`${R}px`}}),[e,r,o,i,f]);const p=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:p,"aria-hidden":"true",children:Array.from({length:r},(g,l)=>t.jsx("div",{ref:u=>{c.current[l]=u},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},l))})},ur=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:c,onToggleMute:f,onClose:p})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:c,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(cr,{audioLevel:d,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),f()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),f())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ft,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:c,"aria-label":`Expand ${o} widget`,children:t.jsx(Ft,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:p,"aria-label":"Close widget",children:t.jsx(rr,{className:"ll-minimized__icon"})})]})]})}),dr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),c=n.useRef(e);if(n.useEffect(()=>{c.current!==e&&(c.current=e,d(!1))},[e]),!e)return null;const f={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:f,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},fr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,d]=n.useState(null);return n.useEffect(()=>{if(!e){d(null);return}const c=o.current;if(!c)return;const f=c.offsetTop,p=c.offsetLeft,g=c.offsetWidth;c.offsetHeight,d({top:f-8,left:p+g/2})},[e,o]),n.useEffect(()=>{if(!e)return;const c=p=>{const g=p.target,l=s.current,u=o.current;l&&l.contains(g)||u&&u.contains(g)||r()},f=p=>{p.key==="Escape"&&(p.stopPropagation(),r())};return document.addEventListener("mousedown",c),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",f)}},[e,r,o]),!e||a===null?null:t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"absolute",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i})},pr=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:d,allowScreenShare:c,isSpeakerMuted:f,onToggleSpeaker:p,allowTyping:g,isTypingOpen:l,onToggleTyping:u,onDisconnect:S})=>{const[R,k]=n.useState(!1),x=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:v=>v.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(bn,{muted:e})}),t.jsx("button",{ref:x,type:"button",className:`ll-tool ${R?"is-on":""}`,onClick:()=>k(v=>!v),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":R,children:t.jsx(hr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:S,"aria-label":"End conversation",children:t.jsx(_n,{})})]}),t.jsxs(fr,{open:R,onClose:()=>k(!1),anchorRef:x,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),k(!1)},children:[t.jsx(vn,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),c&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{d(),k(!1)},children:[t.jsx(xn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${f?"is-on":""}`,onClick:()=>{p(),k(!1)},children:[t.jsx(wn,{muted:f}),t.jsx("span",{children:f?"Unmute speaker":"Mute speaker"})]}),g&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${l?"is-on":""}`,onClick:()=>{u(),k(!1)},children:[t.jsx(mr,{}),t.jsx("span",{children:l?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function hr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function mr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const gr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:c,currentTeamMemberId:f,isSwitchingTeamMember:p,teamSwitcherOpen:g,onToggleTeamSwitcher:l,onSelectTeamMember:u,languageMenuOpen:S,onToggleLanguageMenu:R,connectionState:k,agentState:x,transcript:v,canResume:C,needsUserGesture:E,error:M,isMuted:b,micError:L,micDevices:$,isCameraEnabled:T,cameraPreviewEl:j,cameraDevices:A,activeCameraId:z,isScreenShareEnabled:F,screenPreviewEl:ee,isSpeakerMuted:K,allowCamera:ve,allowScreenShare:se,allowTyping:pe,showMinimize:ae=!0,chromeless:te=!1,compactControls:ne=!1,transforming:tt,transformingLabel:Be,avatarVideoContainerRef:nt,agentVideoEl:X,onConnect:qe,onDisconnect:Fe,onRetry:rt,onResumeAudio:Ue,onToggleMute:be,onToggleCamera:we,onSwitchCameraDevice:Ae,onToggleScreenShare:_e,onToggleSpeaker:ke,onSendMessage:je,onMinimize:Ce,onClose:H,onClearMicError:pt})=>{var Pe;const Se=((c==null?void 0:c.length)??0)>1,Me=k==="connecting"||k==="connected",Q=k==="connected",Ve=k==="idle"||k==="disconnected"||k==="error",[Le,Te]=n.useState(!1);n.useEffect(()=>{if(!X){Te(!1);return}if(!X.paused&&X.readyState>=2){Te(!0);return}Te(!1);const m=()=>Te(!0);return X.addEventListener("playing",m),X.addEventListener("loadeddata",m),()=>{X.removeEventListener("playing",m),X.removeEventListener("loadeddata",m)}},[X]);const[ht,he]=n.useState(!1);n.useEffect(()=>{if(!Q){he(!1);return}if(Le)return;const m=setTimeout(()=>he(!0),8e3);return()=>clearTimeout(m)},[Q,Le]);const Y=k==="connecting"||Q&&!!i&&!Le&&!ht,Ye=n.useRef(null),Ee=n.useRef(null);n.useEffect(()=>{const m=Ye.current;m&&(m.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",m.appendChild(j)))},[j]),n.useEffect(()=>{const m=Ee.current;m&&(m.innerHTML="",ee&&(ee.style.width="100%",ee.style.height="100%",ee.style.objectFit="contain",m.appendChild(ee)))},[ee]);const[re,J]=n.useState(!1),[le,me]=n.useState(!1);n.useEffect(()=>{if(!re&&!le&&!S&&!g)return;const m=()=>{J(!1),me(!1),S&&R(),g&&l()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[re,le,S,g,R,l]);const[Z,ce]=n.useState(!1),Ne=n.useCallback(()=>ce(m=>!m),[]),[ge,ot]=n.useState(""),Ge=n.useCallback(m=>{m.preventDefault();const W=ge.trim();W&&(je(W),ot(""))},[ge,je]),Ke=d.productName||"Live Layer";let ue=null,oe=null;for(let m=v.length-1;m>=0;m--){const W=v[m];if(!ue&&W.role==="agent"?ue=W:!oe&&W.role==="user"&&(oe=W),ue&&oe)break}const Ie=Q?(ue==null?void 0:ue.text)||null:a||null,it=Q&&(oe==null?void 0:oe.text)||null,mt=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:mt,"data-position":e,"data-state":Q?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(dr,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!Q&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:nt,className:"ll-expanded__video"}),Y&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:p?"Switching...":"Connecting..."})]}),E&&Q&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Ue,children:[t.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("path",{d:"M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z"})}),t.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),tt&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":Be,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:Be})]}),Me?t.jsxs(t.Fragment,{children:[!ne&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!te&&t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{Se&&(m.stopPropagation(),l())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(at,{})]}),Se&&g&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:c==null?void 0:c.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===f?"is-active":""}`,onClick:()=>u(m.id),role:"option","aria-selected":m.id===f,children:[m.avatarImageUrl&&t.jsx("img",{src:m.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:m.name}),m.role&&t.jsx("span",{className:"ll-hmenu__role",children:m.role})]},m.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:m=>{m.stopPropagation(),R()},"aria-haspopup":"listbox","aria-expanded":S,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(at,{})]}),S&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[ae!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Ce,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Kt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:H,"aria-label":"End call",title:"End call",children:t.jsx(Gt,{})})]})]}),ne&&t.jsxs("div",{className:"ll-compact-status","data-state":x,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:x})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ke}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[ae!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Ce,"aria-label":"Minimize widget",children:t.jsx(Kt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:H,"aria-label":"Close widget",children:t.jsx(Gt,{})})]})]}),Ve&&(()=>{const m=C?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",W=C?"Pick up where you left off":null,De=!M;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:qe,"aria-label":m,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),W&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:W}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:qe,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(T||F)?"is-visible":""}`,children:[t.jsx("div",{ref:Ee,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ye,className:!F&&T?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[Ie&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ie})}),it&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:it})}),!te&&!ne&&t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[se&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:_e,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(xn,{})}),ve&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${T?"is-on":""}`,onClick:we,"aria-label":T?"Turn off camera":"Turn on camera",title:T?"Stop camera":"Start camera",children:t.jsx(vn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${T?"is-on":""}`,onClick:m=>{m.stopPropagation(),me(W=>!W),J(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":le,children:t.jsx(at,{})}),le&&A.length>0&&t.jsx(Jt,{label:"Camera",devices:A,activeId:z,onPick:m=>{me(!1),Ae(m)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${b?"is-muted":""}`,onClick:be,"aria-label":b?"Unmute microphone":"Mute microphone",title:b?"Unmute":"Mute",children:t.jsx(bn,{muted:b})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${b?"is-muted":""}`,onClick:m=>{m.stopPropagation(),J(W=>!W),me(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":re,children:t.jsx(at,{})}),re&&$.length>0&&t.jsx(Jt,{label:"Microphone",devices:$,activeId:"",onPick:()=>J(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${K?"is-muted":""}`,onClick:ke,"aria-label":K?"Unmute speaker":"Mute speaker",title:K?"Unmute speaker":"Mute speaker",children:t.jsx(wn,{muted:K})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Fe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(_n,{})})]}),!te&&ne&&t.jsx(pr,{isMuted:b,onToggleMute:be,isCameraEnabled:T,onToggleCamera:we,allowCamera:ve,isScreenShareEnabled:F,onToggleScreenShare:_e,allowScreenShare:se,isSpeakerMuted:K,onToggleSpeaker:ke,allowTyping:pe,isTypingOpen:Z,onToggleTyping:Ne,onDisconnect:Fe}),!te&&pe&&(ne?Z:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ge,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ge,onChange:m=>ot(m.target.value),"aria-label":"Message the agent"}),ge.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(yr,{})})]})]}):null,(()=>{if(L&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:L}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:pt,"aria-label":"Dismiss",children:"×"})]});if(!M||k!=="error")return null;let m="Failed to connect",W="Try again";return M==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":M==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":M==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":M==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":M==="CONNECT_FAILED"?m="Connection failed. Check your network.":M.length<80&&(m=M),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:m}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:rt,children:W})]})})()]})};function at(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Gt(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Kt(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function xn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function vn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function bn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function wn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function yr(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function _n(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Jt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const d=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":d,children:[d&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),xr=['[data-ll-private="true"]',".ll-widget"];function jt(e){let r=e;for(;r;){for(const o of xr)if(r.matches(o))return!0;r=r.parentElement}return!1}function ft(e){if(jt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const lt=4096,vr=20,br=20,wr=10,_r=10,kr=30,jr=20,Xt=500,Cr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ze(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Cr)if(r.matches(o))return!0;r=r.parentElement}return!1}function et(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function Qt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function fe(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Oe(e){return e.length}function kn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",d=Array.from(o.querySelectorAll("[data-ll-region]")),c=[];for(const b of d){if(c.length>=wr)break;if(Ze(b)||!et(b))continue;const L=b.getAttribute("data-ll-region")??"",$=b.getAttribute("data-ll-intent")??void 0,T=fe((b.innerText||b.textContent||"").trim(),Xt*2);!L||!T||c.push({id:L,intent:$,text:T})}const f=[],p=["H1","H2","H3","H4","H5","H6"],g=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of g){if(Ze(b)||!et(b))continue;const L=(b.textContent||"").trim();L&&f.push(`${b.tagName}: ${fe(L,200)}`)}const l=Array.from(o.querySelectorAll("p, li"));for(const b of l){if(Ze(b)||!et(b)||p.includes(b.tagName))continue;const L=(b.textContent||"").trim();L.length>10&&f.push(fe(L,Xt))}const u=f.join(`
2
- `),S=[],R=Array.from(o.querySelectorAll("a[href]"));for(const b of R){if(S.length>=vr)break;if(Ze(b)||!et(b))continue;const L=b.getAttribute("href")||"",$=(b.textContent||"").trim();!L||!$||S.push({href:L,text:fe($,100)})}const k=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const b of x){if(k.length>=br)break;if(Ze(b)||!ft(b)||!et(b))continue;const L=Qt(b),$=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();L&&k.push({label:fe(L,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const b of v){if(C.length>=_r)break;if(jt(b))continue;const L=b.getAttribute("data-ll-form")||"";if(!L)continue;const $=b.getAttribute("data-ll-intent")||void 0,T=Array.from(b.querySelectorAll("[data-ll-field]")),j=[];for(const A of T){if(j.length>=kr)break;if(!ft(A))continue;const z=A.getAttribute("data-ll-field")||"";if(!z)continue;const F=Qt(A)||z,ee=A instanceof HTMLInputElement?A.type:A.tagName.toLowerCase(),K={name:z,label:fe(F,100),type:ee};if(A.required===!0&&(K.required=!0),A instanceof HTMLSelectElement){const se=[];for(let pe=0;pe<A.options.length&&!(se.length>=jr);pe++){const ae=A.options[pe];if(!ae||ae.disabled)continue;const te=ae.value||"",ne=(ae.textContent||"").trim()||te;!te&&!ne||se.push({value:te,label:fe(ne,60)})}se.length>0&&(K.options=se)}const ve=typeof A.validationMessage=="string"?A.validationMessage:"";ve&&(K.validationMessage=fe(ve,200)),j.push(K)}C.push({id:L,intent:$,fields:j})}const E={url:i,title:a,pathname:s,regions:c,visibleText:u,visibleLinks:S,visibleFields:k,forms:C,extras:e};let M=Oe(JSON.stringify(E.regions))+Oe(E.visibleText)+Oe(JSON.stringify(E.visibleLinks))+Oe(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleFields.length>0;)E.visibleFields.pop(),M=Oe(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),M-=80;return Oe(E.visibleText)>lt&&(E.visibleText=fe(E.visibleText,lt-100)),E}let He=null;function kt(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(He&&He.key===s&&o-He.at<1e3)return He.ctx;const a=kn(e,r);return He={key:s,at:o,ctx:a},a}function jn(){He=null}const Sr=200;function Cn(e){const r=String(e.href||"");return{href:r,text:String(e.text??e.title??r),internal:e.internal??!0,title:e.title,description:e.description}}function Lr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Sn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const d of a){if(s.length>=Sr)break;if(jt(d))continue;const c=d.getAttribute("href")||"";if(!Lr(c))continue;let f=c,p=!0;try{if(typeof window<"u"){const l=new URL(c,o);p=l.origin===o,p&&c.startsWith("http")&&(f=l.pathname+l.search+l.hash)}}catch{continue}if(i.has(f))continue;i.add(f);const g=(d.textContent||"").trim().slice(0,120);s.push({href:f,text:g,internal:p})}return s}let We=null;const Er=5e3;function ct(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(We&&We.pathname===r&&e-We.at<Er)return We.routes;const o=Sn();return We={at:e,pathname:r,routes:o},o}function Ln(){We=null}function Nr(e,r){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,r):e.value=r}function Rr(e,r,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),d=a==null?void 0:a.set,c=r==="true"||r==="1"||r==="on";d?d.call(e,c):e.checked=c,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}Nr(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Ar(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const r=window.getComputedStyle(e);return!(r.overflowY==="hidden"||r.overflowY==="clip")}function Mr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function Tr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,o=0;for(const i of e){if(!Mr(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const a=s.width*s.height;a>o&&(o=a,r=i)}return r}function Ir(){if(typeof window>"u")return null;if(Ar())return window;const e=Tr();return e||window}function Zt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Pr(e){var r,o;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const Dr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]),En=n.forwardRef(function(r,o){var Mt,Tt,It,Pt,Dt,$t,zt;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:d,sessionBody:c,soundEffects:f,experienceMode:p="WIDGET",autoConnect:g=!1,displayMode:l,defaultDisplayMode:u="expanded",onDisplayModeChange:S,position:R="bottom-right",mobileBreakpoint:k=640,persistKey:x="ll-widget",disablePersistence:v=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:M,idleLoopUrl:b,greeting:L,avatarImageUrl:$,agentName:T,branding:j={},allowCamera:A=!0,allowScreenShare:z=!0,allowTyping:F=!0,showMinimize:ee=!0,chromeless:K=!1,compactControls:ve=!1,transforming:se=!1,transformingLabel:pe="Transforming…",showOn:ae,hideOn:te,pathname:ne,onNavigate:tt,onScrollToSelector:Be,getPageContext:nt,pageContextExtras:X,getRoutes:qe,onScrollPage:Fe,onClick:rt,capabilities:Ue,onConnect:be,onDisconnect:we,onTranscript:Ae,onAgentState:_e,onConnectionStateChange:ke,onAgentEvent:je,onAgentCommand:Ce,controlledSession:H,className:pt,style:Se,zIndex:Me=2147483647}=r,Q=pn(ne),Ve=gn(Q,ae,te);n.useEffect(()=>{jn(),Ln()},[Q]);const Le=E!==void 0,[Te,ht]=n.useState(()=>{var y;return E??((y=C==null?void 0:C[0])==null?void 0:y.id)}),he=Le?E:Te,Y=n.useMemo(()=>(C==null?void 0:C.find(y=>y.id===he))??null,[C,he]),Ye=(Y==null?void 0:Y.agentId)??i,Ee=p==="EMBEDDED",[re,J]=dn({value:Ee?"expanded":l,defaultValue:Ee?"expanded":u,onChange:S,persistKey:x,disablePersistence:Ee||v}),le=fn(k),me=rn(),Z=on(),ce=sn(),Ne=an(),ge=ln(),[ot,Ge]=n.useState(!1),[Ke,ue]=n.useState(!1),[oe,Ie]=n.useState(!1),[it,mt]=n.useState(!1),[Pe,m]=n.useState(!1),W=nr({baseUrl:a,config:f}),De=n.useRef(W);De.current=W;const gt=n.useRef(tt),yt=n.useRef(Be),xt=n.useRef(Fe),vt=n.useRef(rt),Ct=n.useRef(nt),St=n.useRef(X),Lt=n.useRef(qe),bt=n.useRef(Ue),ie=n.useRef(null);gt.current=tt,yt.current=Be,xt.current=Fe,vt.current=rt,Ct.current=nt,St.current=X,Lt.current=qe,bt.current=Ue;function ye(y){const h=bt.current;return h?h.includes(y):!0}function xe(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Je=n.useCallback(y=>{var q,de,Re,$e;const h=y;if(!(!h.type||typeof h.type!="string")){if(je==null||je({eventName:h.type,data:y}),h.type==="navigate"){if(!ye("navigate")){xe("navigate","navigate");return}const _=typeof h.href=="string"?h.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(De.current.playPageChange(),gt.current){try{gt.current(_)}catch(N){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,N)}return}if(typeof document<"u"){const N=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(N){N.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(N){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,N)}return}if(h.type==="scroll_to"){if(!ye("scroll")){xe("scroll_to","scroll");return}const _=typeof h.selector=="string"?h.selector:null;if(!_)return;const N=h.behavior==="instant"?"instant":"smooth";if(yt.current){try{yt.current(_,N)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:N,block:"start"})}return}if(h.type==="request_page_context"){if(!ye("read_page")){xe("request_page_context","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,N=(q=ie.current)==null?void 0:q.call(ie),D=B=>{const I=N,V=I==null?void 0:I.localParticipant;if(V!=null&&V.publishData)try{const G=_?{...B,requestId:_}:B,ze=new TextEncoder().encode(JSON.stringify(G));V.publishData(ze,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},P=St.current,O=Ct.current;try{if(O){const B=O(P);if(B instanceof Promise){D({type:"page_context_pending"}),B.then(I=>D({type:"page_context",context:I})).catch(I=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",I),D({type:"page_context",context:kt(P)})});return}D({type:"page_context",context:B});return}D({type:"page_context",context:kt(P)})}catch(B){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",B),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:P}})}return}if(h.type==="scroll_page"){if(!ye("scroll")){xe("scroll_page","scroll");return}const _=h.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const N=h.behavior==="instant"?"instant":"smooth";if(xt.current){try{xt.current(_,N)}catch(I){console.warn("[LiveLayer] onScrollPage threw.",I)}return}if(typeof window>"u")return;const D={behavior:N},P=Ir(),O=I=>{P instanceof Window?P.scrollBy({top:I,...D}):P.scrollBy({top:I,...D})},B=I=>{P instanceof Window?P.scrollTo({top:I,...D}):P.scrollTo({top:I,...D})};_==="up"?O(-Zt(P)):_==="down"?O(Zt(P)):B(_==="top"?0:Pr(P));return}if(h.type==="click"){if(!ye("click")){xe("click","click");return}const _=typeof h.selector=="string"?h.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(vt.current){try{vt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let N=null;try{N=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!N){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(de=N.click)==null||de.call(N);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!ye("fill_forms")){xe(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&De.current.playConfirmation();const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const N=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!N){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const P=typeof h.fieldName=="string"?h.fieldName:null;if(!P){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const O=N.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!O){console.warn(`[LiveLayer] focus_field: no field "${P}" in form "${_}".`);return}if(!ft(O)){console.warn(`[LiveLayer] focus_field: field "${P}" is privacy-protected and not focusable.`);return}O.focus();return}const D=h.values&&typeof h.values=="object"?h.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[P,O]of Object.entries(D)){if(typeof O!="string")continue;const B=N.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] fill_form: no field "${P}" in form "${_}". Skipping.`);continue}if(!ft(B)){console.warn(`[LiveLayer] fill_form: field "${P}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Rr(B,O)}catch(I){console.warn(`[LiveLayer] fill_form: failed to set "${P}".`,I)}}return}if(h.type==="submit_form"){if(!ye("submit_forms")){xe("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}De.current.playConfirmation();const N=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!N){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof h.requestId=="string"?h.requestId:void 0,P=(Re=ie.current)==null?void 0:Re.call(ie),O=V=>{const G=P,ze=G==null?void 0:G.localParticipant;if(ze!=null&&ze.publishData)try{const Wn=D?{...V,requestId:D}:V,Bn=new TextEncoder().encode(JSON.stringify(Wn));ze.publishData(Bn,{reliable:!0})}catch{}};let B=!1;const I=()=>{B=!0,O({type:"form_submitted",formId:_})};N.addEventListener("submit",I,{once:!0});try{typeof N.requestSubmit=="function"?N.requestSubmit():N.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),N.removeEventListener("submit",I),O({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{B||(N.removeEventListener("submit",I),O({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!ye("read_page")){xe("request_routes","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,D=($e=ie.current)==null?void 0:$e.call(ie),P=D==null?void 0:D.localParticipant;if(!(P!=null&&P.publishData))return;const O=I=>{try{const V=_?{type:"routes",routes:I,requestId:_}:{type:"routes",routes:I},G=new TextEncoder().encode(JSON.stringify(V));P.publishData(G,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},B=Lt.current;if(B){try{const I=B(),V=G=>{if(!Array.isArray(G)){O([]);return}O(G.map(Cn).slice(0,200))};I instanceof Promise?I.then(V).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),O(ct())}):V(I)}catch(I){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",I),O(ct())}return}try{O(ct())}catch(I){console.warn("[LiveLayer] request_routes: extractRoutes threw.",I)}return}Dr.has(h.type)||Ce==null||Ce(h)}},[Ce,je]),U=nn({agentId:H?"__controlled__":Ye,baseUrl:a,apiKey:s,sessionEndpoint:d,sessionBody:c,onDataMessage:H?void 0:Je});n.useEffect(()=>{if(H!=null&&H.subscribeToDataMessages)return H.subscribeToDataMessages(Je)},[H,Je]),ie.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var q;if(typeof window>"u")return;const y=((q=window.location)==null?void 0:q.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=de=>{try{Je(de)}catch(Re){console.warn("[LiveLayer] simulate-command threw:",Re)}},()=>{delete window.__livelayerSimulateCommand}},[Je]);const w=n.useMemo(()=>H?{connectionState:H.connectionState,agentState:H.agentState,transcript:H.transcript,videoElement:H.videoElement,audioElement:H.audioElement,canResume:H.canResume,error:H.error,agentConfig:null,connect:async()=>{await H.onConnect()},disconnect:()=>H.onDisconnect(),getRoom:U.getRoom,isControlled:!0}:{connectionState:U.connectionState,agentState:U.agentState,transcript:U.transcript,videoElement:U.videoElement,audioElement:U.audioElement,canResume:U.canResume,error:U.error,agentConfig:U.agentConfig,connect:U.connect,disconnect:U.disconnect,getRoom:U.getRoom,isControlled:!1},[H,U]),Et=n.useRef(w);Et.current=w,n.useImperativeHandle(o,()=>({sendData:async y=>{var de,Re;const h=(Re=(de=Et.current)==null?void 0:de.getRoom)==null?void 0:Re.call(de),q=h==null?void 0:h.localParticipant;if(q!=null&&q.publishData)try{const $e=new TextEncoder().encode(JSON.stringify(y));await q.publishData($e,{reliable:!0})}catch($e){console.warn("[AvatarWidget] sendData failed:",$e)}}}),[]);const Nt=n.useRef(null);n.useEffect(()=>{const y=w.videoElement,h=Nt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[w.videoElement]),n.useEffect(()=>{const y=w.audioElement;if(!y)return;me.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(q=>{(q==null?void 0:q.name)==="NotAllowedError"&&Ge(!0)}),()=>{me.detach()}},[w.audioElement]),n.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const y=w.getRoom();if(y)return Z.setupMic(y).catch(()=>{}),ce.attachRoom(y),Ne.attachRoom(y),ge.refresh(),()=>{Z.teardownMic(),ce.teardown(),Ne.teardown()}},[w.isControlled,w.connectionState]),n.useEffect(()=>{const y=w.audioElement;y&&(y.muted=Pe)},[w.audioElement,Pe]);const Rn=n.useCallback(y=>{const h=w.getRoom();if(h)try{const q=new TextEncoder().encode(JSON.stringify({type:"user_message",text:y}));h.localParticipant.publishData(q,{reliable:!0})}catch{}},[w]),An=n.useCallback(()=>{m(y=>!y)},[]);n.useEffect(()=>{ke==null||ke(w.connectionState),w.connectionState==="connected"?be==null||be():w.connectionState==="disconnected"&&(we==null||we())},[w.connectionState,be,we,ke]),n.useEffect(()=>{Ae==null||Ae(w.transcript)},[w.transcript,Ae]),n.useEffect(()=>{_e==null||_e(w.agentState)},[w.agentState,_e]),n.useEffect(()=>{W.setThinking(w.agentState==="thinking")},[w.agentState,W]);const Rt=n.useRef(!1);n.useEffect(()=>{w.isControlled||!g||Rt.current||Ve&&w.connectionState==="idle"&&(Rt.current=!0,w.connect())},[g,w.connectionState,w,Ve]);const Mn=n.useCallback(y=>{const h=C==null?void 0:C.find(q=>q.id===y);h&&(Ie(!1),y!==he&&(ue(!0),w.disconnect(),Le||ht(y),M==null||M(h)))},[C,he,w,Le,M]);n.useEffect(()=>{Ke&&w.connectionState==="connected"&&ue(!1)},[w.connectionState,Ke]),n.useEffect(()=>{if(!oe)return;const y=h=>{h.key==="Escape"&&Ie(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[oe]);const Tn=!!$||!!(Y!=null&&Y.avatarImageUrl)||w.isControlled,Xe=cn(Ye,a,Tn);Ue===void 0&&((Mt=Xe.info)!=null&&Mt.capabilities)&&(bt.current=Xe.info.capabilities);const st=(Y==null?void 0:Y.name)??T??((Tt=w.agentConfig)==null?void 0:Tt.name)??((It=Xe.info)==null?void 0:It.name)??"Live Layer",wt=(Y==null?void 0:Y.avatarImageUrl)??$??((Pt=w.agentConfig)==null?void 0:Pt.avatarImageUrl)??((Dt=Xe.info)==null?void 0:Dt.avatarImageUrl)??null,In=b??(($t=w.agentConfig)==null?void 0:$t.idleLoopUrl)??((zt=Xe.info)==null?void 0:zt.idleLoopUrl)??null,Pn=L??null,Dn=n.useCallback(()=>J("expanded"),[J]),$n=n.useCallback(()=>J("minimized"),[J]),At=n.useCallback(()=>{w.disconnect(),J("hidden")},[w,J]),zn=n.useCallback(()=>{const y=w.audioElement;y&&y.play().then(()=>Ge(!1)).catch(()=>{})},[w.audioElement]),On=n.useCallback(()=>{Ge(!1),w.connect()},[w]),Qe={...Se,...Ee?{}:{zIndex:Me}};j.primaryColor&&(Qe["--ll-color-primary"]=j.primaryColor),j.accentColor&&(Qe["--ll-color-accent"]=j.accentColor),j.backgroundColor&&(Qe["--ll-color-bg"]=j.backgroundColor),j.textColor&&(Qe["--ll-color-fg"]=j.textColor);const Hn=["ll-widget",`ll-widget--${re}`,`ll-widget--${le?"mobile":"desktop"}`,pt].filter(Boolean).join(" ");return Ve?t.jsxs("div",{className:Hn,style:Qe,"data-display-mode":re,"data-position":R,"data-experience-mode":p==="EMBEDDED"?"embedded":"widget",children:[re==="hidden"&&t.jsx(lr,{position:R,isMobile:le,isSpeaking:w.agentState==="speaking",onExpand:()=>J("expanded"),label:`Open ${st} widget`,avatarImageUrl:wt,agentName:st}),re==="minimized"&&t.jsx(ur,{position:R,isMobile:le,agentName:st,avatarImageUrl:wt,agentState:w.agentState,isMuted:Z.isMuted,audioLevel:me,onExpand:Dn,onToggleMute:Z.toggleMute,onClose:At}),re==="expanded"&&t.jsx(gr,{position:R,isMobile:le,agentName:st,avatarImageUrl:wt,idleLoopUrl:In,greeting:Pn,branding:j,teamMembers:C,currentTeamMemberId:he,isSwitchingTeamMember:Ke,teamSwitcherOpen:oe,onToggleTeamSwitcher:()=>Ie(y=>!y),onSelectTeamMember:Mn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:Z.isMuted,micDevices:ge.mics,isCameraEnabled:ce.isEnabled,cameraPreviewEl:ce.previewEl,cameraDevices:ge.cameras,activeCameraId:ce.activeDeviceId,isScreenShareEnabled:Ne.isEnabled,screenPreviewEl:Ne.previewEl,isSpeakerMuted:Pe,allowCamera:A,allowScreenShare:z,allowTyping:F,showMinimize:ee,chromeless:K,compactControls:ve,transforming:se,transformingLabel:pe,languageMenuOpen:it,onToggleLanguageMenu:()=>mt(y=>!y),needsUserGesture:ot,canResume:w.canResume,micError:Z.micError,error:w.error,avatarVideoContainerRef:Nt,agentVideoEl:w.videoElement,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:On,onResumeAudio:zn,onToggleMute:Z.toggleMute,onToggleCamera:()=>void ce.toggle(),onSwitchCameraDevice:y=>void ce.switchDevice(y),onToggleScreenShare:()=>void Ne.toggle(),onToggleSpeaker:An,onSendMessage:Rn,onMinimize:$n,onClose:At,onClearMicError:Z.clearError})]}):null});En.displayName="AvatarWidgetInner";const Nn=n.forwardRef(function(r,o){return t.jsx(tn,{children:t.jsx(En,{...r,ref:o})})});Nn.displayName="AvatarWidget";const $r=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:d})=>{const c=n.useRef(null),f=n.useRef(null),p=n.useRef(s);p.current=s;const g=n.useCallback(l=>{var S;const u=l.detail;(S=p.current)==null||S.call(p,u)},[]);return n.useEffect(()=>{const l=c.current;if(!l)return;const u=document.createElement("livelayer-widget");return u.setAttribute("agent-id",e),r&&u.setAttribute("base-url",r),o&&u.setAttribute("api-key",o),i&&u.setAttribute("mode",i),u.addEventListener("agent-event",g),l.appendChild(u),f.current=u,()=>{u.removeEventListener("agent-event",g),l.removeChild(u),f.current=null}},[e]),n.useEffect(()=>{f.current&&(i?f.current.setAttribute("mode",i):f.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:c,className:a,style:d})},zr=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:d},c){return n.createElement(i,{ref:c,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},d)}),Or=n.forwardRef(function({id:r,intent:o,children:i,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":o,...s,children:i})}),Hr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,d={name:i,"data-ll-field":i};let c;if("as"in r&&r.as==="textarea"){const{name:f,label:p,labelClassName:g,as:l,...u}=r;c=t.jsx("textarea",{ref:o,...d,...u})}else if("as"in r&&r.as==="select"){const{name:f,label:p,labelClassName:g,as:l,children:u,...S}=r;c=t.jsx("select",{ref:o,...d,...S,children:u})}else{const{name:f,label:p,labelClassName:g,as:l,...u}=r;c=t.jsx("input",{ref:o,...d,...u})}return s===void 0?c:t.jsxs("label",{className:a,children:[s,c]})});let en=1;function Wr({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,d]=n.useState([]),[c,f]=n.useState(""),[p,g]=n.useState(!1),l=n.useRef(new Set),u=n.useRef([]),S=n.useRef(p);S.current=p,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(u.current.length===0||S.current)return;const v=u.current.splice(0,u.current.length);d(C=>[...v.reverse(),...C].slice(0,200))},100);return()=>clearInterval(x)},[]);const R=n.useRef(!1);if(n.useEffect(()=>{!e||R.current||(R.current=!0,e(x=>{u.current.push({id:en++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,v=console.log,C=(E,M)=>function(...b){try{const L=typeof b[0]=="string"?b[0]:"";L.startsWith("[LiveLayer]")&&u.current.push({id:en++,ts:Date.now(),kind:E,type:L.slice(0,120),data:{args:b.slice(1).map($=>qr($))}})}catch{}return M.apply(this,b)};return console.warn=C("warn",x),console.log=C("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=a.filter(x=>{if(!c)return!0;const v=c.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>g(x=>!x),style:_t(p?"#f59e0b":"transparent"),title:"Pause / resume capture",children:p?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{d([]),u.current=[]},style:_t("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:_t("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:c,onChange:x=>f(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),qn=require("@livelayer/sdk"),ut=require("livekit-client");class tn extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function nn(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[c,f]=n.useState(null),[p,g]=n.useState(null),[l,u]=n.useState(null),[S,R]=n.useState(!1),[k,x]=n.useState(null),v=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const L={onConnectionStateChange:T=>{o(T),T==="connected"&&x(null)},onAgentStateChange:s,onTranscript:T=>d([...T]),onAgentConfig:f,onAudioTrack:T=>u(T),onVideoTrack:T=>g(T),onVideoTrackRemoved:()=>g(null),onError:T=>x(T),onDataMessage:T=>{var j;(j=C.current)==null||j.call(C,T)},onResumabilityChange:R},$=new qn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},L);return v.current=$,o("idle"),s("idle"),d([]),f(null),g(null),u(null),R(!1),x(null),()=>{var T;(T=$.destroy)==null||T.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const L=v.current;if(L)try{await L.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),M=n.useCallback(()=>{const L=v.current;L&&L.disconnect()},[]),b=n.useCallback(()=>{var L;return((L=v.current)==null?void 0:L.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:c,videoElement:p,audioElement:l,canResume:S,error:k,connect:E,disconnect:M,getRoom:b,session:v.current}}function rn(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),d=n.useCallback(()=>{const l=r.current;if(!l){i.current=null;return}(!a.current||a.current.length!==l.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(l.frequencyBinCount)));const u=a.current;l.getByteFrequencyData(u);let S=0;for(let k=0;k<u.length;k++)S+=u[k];const R=S/u.length/255;for(const k of s.current)try{k(R)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(d)},[]),c=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const l=new AudioContext,u=l.createAnalyser();u.fftSize=64,u.connect(l.destination),e.current=l,r.current=u},[]),f=n.useCallback(l=>{if(c(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const u=e.current.createMediaElementSource(l);u.connect(r.current),o.current=u}catch(u){console.warn("[useAudioLevel] createMediaElementSource failed:",u);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[c,d]),p=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),g=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(p(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[p]),{attach:f,detach:p,subscribe:g}}function on(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),d=n.useCallback(async g=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=g,i(null);try{const l=await ut.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.localParticipant.publishTrack(l),s.current=l,r(l.isMuted)}catch(l){const u=l instanceof Error&&l.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(u),l}},[]),c=n.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),r(!1)):(g.mute(),r(!0)))},[]),f=n.useCallback(()=>{const g=s.current,l=a.current;if(g&&l){try{l.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,a.current=null,r(!1)},[]),p=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:c,setupMic:d,teardownMic:f,clearError:p}}const Fn={resolution:{width:640,height:480,frameRate:24}};function sn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,c]=n.useState(""),f=n.useRef(null),p=n.useRef(null),g=n.useCallback(v=>{f.current=v},[]),l=n.useCallback(()=>{const v=f.current,C=p.current;if(C&&v){const E=v.localParticipant.getTrackPublication(ut.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else C.stop()}p.current=null,a(null),r(!1)},[]),u=n.useCallback(async v=>{const C=f.current;if(C){i(null);try{const E={...Fn};v&&(E.deviceId=v);const M=await ut.createLocalVideoTrack(E);await C.localParticipant.publishTrack(M),p.current=M;const b=M.attach();a(b),r(!0),v&&c(v);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const M=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(M)}}},[]),S=n.useCallback(async()=>{e?l():await u(d||void 0)},[e,d,l,u]),R=n.useCallback(async v=>{l(),await u(v)},[l,u]),k=n.useCallback(()=>{l(),f.current=null,i(null),c("")},[l]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{p.current&&p.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:S,switchDevice:R,attachRoom:g,teardown:k,clearError:x}}function an(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),c=n.useCallback(u=>{d.current=u},[]),f=n.useCallback(()=>a(null),[]),p=n.useCallback(async()=>{const u=d.current;if(u){if(e){try{await u.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1);return}i(null);try{await u.localParticipant.setScreenShareEnabled(!0);let S=0;const R=()=>{const k=u.localParticipant.getTrackPublication(ut.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();a(x),r(!0);try{u.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}S++<10?setTimeout(R,100):r(!0)};R()}catch(S){const R=S instanceof Error?S.name:"";R!=="NotAllowedError"&&R!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,f]),g=n.useCallback(()=>{const u=d.current;if(u&&e)try{u.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1),i(null),d.current=null},[e,f]),l=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:p,attachRoom:c,teardown:g,clearError:l}}function ln(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(d=>d.kind==="audioinput")),i(a.filter(d=>d.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:o,refresh:s}}function cn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[c,f]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){f(!1);return}const p=new AbortController,g=r||"https://app.livelayer.studio";return f(!0),d(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:p.signal}).then(async l=>{if(!l.ok){const u=await l.json().catch(()=>({}));throw new Error(u.error||`HTTP ${l.status}`)}return l.json()}).then(l=>{p.signal.aborted||(s(l),f(!1))}).catch(l=>{p.signal.aborted||(d(l instanceof Error?l.message:"Agent lookup failed"),f(!1))}),()=>p.abort()},[e,r,o]),{info:i,error:a,loading:c}}function Un(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Vn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function un({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,c=n.useCallback(f=>{f!==d&&(i||a(f),o==null||o(f))},[d,i,o]);return[d,c]}const Yn=["hidden","minimized","expanded"];function Gn(e){return e&&Yn.includes(e)?e:null}function dn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[c,f]=un({value:e,defaultValue:r,onChange:p=>{e===void 0&&!s&&Vn(a,p),o==null||o(p)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const p=Gn(Un(a));p&&p!==c&&f(p)},[]),[c,f]}const Kn=640;function fn(e=Kn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Ot="__llHistoryPatched",dt="ll:pathname";function Jn(){if(typeof window>"u"||window.history[Ot])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history[Ot]=!0}function Ht(){return typeof window>"u"?"/":window.location.pathname||"/"}function pn(e){const[r,o]=n.useState(()=>e??Ht());return n.useEffect(()=>{if(e!==void 0)return;Jn();const i=()=>o(Ht());return i(),window.addEventListener("popstate",i),window.addEventListener(dt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(dt,i)}},[e]),e??r}const Wt=new Map,Xn=/[\\^$+?.()|{}[\]]/g;function Qn(e){return e.replace(Xn,"\\$&")}function Zn(e){const r=Wt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),c=Qn(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),f=new RegExp(`^${c}\\/?$`);return Wt.set(e,f),f}function er(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Zn(e).test(o)}function hn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):er(e,r)}function Bt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(hn(o,r))return!0;return!1}function mn(e,r,o){return e===void 0?!0:Bt(o,e)?!1:r&&r.length>0?Bt(r,e):!0}function gn(e,r,o){return n.useMemo(()=>mn(e,r,o),[e,r,o])}function tr(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function nr(e){const r=n.useMemo(()=>tr(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(f=>{try{new Audio(`${o}${f}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),d=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),c=n.useCallback(f=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(f){if(i.current)return;try{const p=new Audio(`${o}/audio/thinking-sound.mp3`);p.loop=!0,p.volume=.3,p.play().catch(()=>{i.current=null}),i.current=p}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:d,setThinking:c}),[a,d,c])}const qt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Ft=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})}),rr=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),or={left:180,right:0,up:-90,down:90},Ut=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${or[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function ir(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const yn="ll-hidden-tab-center-y",sr=5,Vt=16;function ar(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(yn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Yt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(yn,String(e))}catch{}}const lr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d})=>{const c=ir(e),f=c==="right"?"left":"right",p=r?80:72,g=!!a,[l,u]=n.useState(null),[S,R]=n.useState(!1),k=n.useRef(null),x=n.useRef(!1),v=n.useCallback(j=>{if(typeof window>"u")return j;const A=p/2,z=Vt+A,F=window.innerHeight-Vt-A;return F<z?Math.max(z,j):Math.max(z,Math.min(F,j))},[p]);n.useEffect(()=>{const j=ar();u(v(j??window.innerHeight/2));const A=()=>{u(z=>z===null?null:v(z))};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[v]);const C=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&l!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}k.current={startClientY:j.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(j=>{const A=k.current;if(!A)return;const z=j.clientY-A.startClientY;!A.moved&&Math.abs(z)>sr&&(A.moved=!0,R(!0)),A.moved&&u(v(A.startCenterY+z))},[v]),M=n.useCallback(j=>{const A=k.current;if(A){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}k.current=null,A.moved&&(R(!1),x.current=!0,u(z=>(z!==null&&Yt(z),z)))}},[]),b=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),L=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const A=j.key==="ArrowUp"?-8:8;u(z=>{if(z===null)return z;const F=v(z+A);return Yt(F),F})}},[v]),$=["ll-hidden",`ll-hidden--${c}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,S?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),T=l===null?void 0:{top:`${l-p/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:C,onPointerMove:E,onPointerUp:M,onPointerCancel:M,onClick:b,onKeyDown:L,"aria-label":s,"data-position":e,style:T,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Ut,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Ut,{direction:f,className:"ll-hidden__chevron"})})},cr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),c=n.useRef([]),f=n.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,u)=>.5+u*g%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let u=0;u<r;u++){const S=c.current[u];if(!S)continue;const R=Math.max(i,l*o*f[u]);S.style.height=`${R}px`}}),[e,r,o,i,f]);const p=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:p,"aria-hidden":"true",children:Array.from({length:r},(g,l)=>t.jsx("div",{ref:u=>{c.current[l]=u},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},l))})},ur=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:c,onToggleMute:f,onClose:p})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:c,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(cr,{audioLevel:d,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),f()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),f())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ft,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:c,"aria-label":`Expand ${o} widget`,children:t.jsx(Ft,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:p,"aria-label":"Close widget",children:t.jsx(rr,{className:"ll-minimized__icon"})})]})]})}),dr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),c=n.useRef(e);if(n.useEffect(()=>{c.current!==e&&(c.current=e,d(!1))},[e]),!e)return null;const f={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:f,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},fr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,d]=n.useState(null);return n.useEffect(()=>{if(!e){d(null);return}const c=o.current;if(!c)return;const f=c.offsetTop,p=c.offsetLeft,g=c.offsetWidth;c.offsetHeight,d({top:f-8,left:p+g/2})},[e,o]),n.useEffect(()=>{if(!e)return;const c=p=>{const g=p.target,l=s.current,u=o.current;l&&l.contains(g)||u&&u.contains(g)||r()},f=p=>{p.key==="Escape"&&(p.stopPropagation(),r())};return document.addEventListener("mousedown",c),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",f)}},[e,r,o]),!e||a===null?null:t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"absolute",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i})},pr=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:d,allowScreenShare:c,isSpeakerMuted:f,onToggleSpeaker:p,allowTyping:g,isTypingOpen:l,onToggleTyping:u,onDisconnect:S})=>{const[R,k]=n.useState(!1),x=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:v=>v.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(bn,{muted:e})}),t.jsx("button",{ref:x,type:"button",className:`ll-tool ${R?"is-on":""}`,onClick:()=>k(v=>!v),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":R,children:t.jsx(hr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:S,"aria-label":"End conversation",children:t.jsx(_n,{})})]}),t.jsxs(fr,{open:R,onClose:()=>k(!1),anchorRef:x,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),k(!1)},children:[t.jsx(vn,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),c&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{d(),k(!1)},children:[t.jsx(xn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${f?"is-on":""}`,onClick:()=>{p(),k(!1)},children:[t.jsx(wn,{muted:f}),t.jsx("span",{children:f?"Unmute speaker":"Mute speaker"})]}),g&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${l?"is-on":""}`,onClick:()=>{u(),k(!1)},children:[t.jsx(mr,{}),t.jsx("span",{children:l?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function hr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function mr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const gr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:c,currentTeamMemberId:f,isSwitchingTeamMember:p,teamSwitcherOpen:g,onToggleTeamSwitcher:l,onSelectTeamMember:u,languageMenuOpen:S,onToggleLanguageMenu:R,connectionState:k,agentState:x,transcript:v,canResume:C,needsUserGesture:E,error:M,isMuted:b,micError:L,micDevices:$,isCameraEnabled:T,cameraPreviewEl:j,cameraDevices:A,activeCameraId:z,isScreenShareEnabled:F,screenPreviewEl:te,isSpeakerMuted:K,allowCamera:ve,allowScreenShare:se,allowTyping:pe,showMinimize:ae=!0,chromeless:ne=!1,compactControls:J=!1,transforming:tt,transformingLabel:Be,avatarVideoContainerRef:nt,agentVideoEl:Q,onConnect:qe,onDisconnect:Fe,onRetry:rt,onResumeAudio:Ue,onToggleMute:be,onToggleCamera:we,onSwitchCameraDevice:Ae,onToggleScreenShare:_e,onToggleSpeaker:ke,onSendMessage:je,onMinimize:Ce,onClose:H,onClearMicError:pt})=>{var Pe;const Se=((c==null?void 0:c.length)??0)>1,Me=k==="connecting"||k==="connected",Z=k==="connected",Ve=k==="idle"||k==="disconnected"||k==="error",[Le,Te]=n.useState(!1);n.useEffect(()=>{if(!Q){Te(!1);return}if(!Q.paused&&Q.readyState>=2){Te(!0);return}Te(!1);const m=()=>Te(!0);return Q.addEventListener("playing",m),Q.addEventListener("loadeddata",m),()=>{Q.removeEventListener("playing",m),Q.removeEventListener("loadeddata",m)}},[Q]);const[ht,he]=n.useState(!1);n.useEffect(()=>{if(!Z){he(!1);return}if(Le)return;const m=setTimeout(()=>he(!0),8e3);return()=>clearTimeout(m)},[Z,Le]);const Y=k==="connecting"||Z&&!!i&&!Le&&!ht,Ye=n.useRef(null),Ee=n.useRef(null);n.useEffect(()=>{const m=Ye.current;m&&(m.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",m.appendChild(j)))},[j]),n.useEffect(()=>{const m=Ee.current;m&&(m.innerHTML="",te&&(te.style.width="100%",te.style.height="100%",te.style.objectFit="contain",m.appendChild(te)))},[te]);const[re,X]=n.useState(!1),[le,me]=n.useState(!1);n.useEffect(()=>{if(!re&&!le&&!S&&!g)return;const m=()=>{X(!1),me(!1),S&&R(),g&&l()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[re,le,S,g,R,l]);const[ee,ce]=n.useState(!1),Ne=n.useCallback(()=>ce(m=>!m),[]),[ge,ot]=n.useState(""),Ge=n.useCallback(m=>{m.preventDefault();const W=ge.trim();W&&(je(W),ot(""))},[ge,je]),Ke=d.productName||"Live Layer";let ue=null,oe=null;for(let m=v.length-1;m>=0;m--){const W=v[m];if(!ue&&W.role==="agent"?ue=W:!oe&&W.role==="user"&&(oe=W),ue&&oe)break}const Ie=Z?(ue==null?void 0:ue.text)||null:a||null,it=Z&&(oe==null?void 0:oe.text)||null,mt=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:mt,"data-position":e,"data-state":Z?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(dr,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!Z&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:nt,className:"ll-expanded__video"}),Y&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:p?"Switching...":"Connecting..."})]}),E&&Z&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Ue,children:[t.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("path",{d:"M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z"})}),t.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),tt&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":Be,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:Be})]}),Me?t.jsxs(t.Fragment,{children:[!J&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!ne&&t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{Se&&(m.stopPropagation(),l())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(at,{})]}),Se&&g&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:c==null?void 0:c.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===f?"is-active":""}`,onClick:()=>u(m.id),role:"option","aria-selected":m.id===f,children:[m.avatarImageUrl&&t.jsx("img",{src:m.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:m.name}),m.role&&t.jsx("span",{className:"ll-hmenu__role",children:m.role})]},m.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:m=>{m.stopPropagation(),R()},"aria-haspopup":"listbox","aria-expanded":S,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(at,{})]}),S&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[ae!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Ce,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Kt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:H,"aria-label":"End call",title:"End call",children:t.jsx(Gt,{})})]})]}),J&&t.jsxs("div",{className:"ll-compact-status","data-state":x,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:x})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ke}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[ae!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Ce,"aria-label":"Minimize widget",children:t.jsx(Kt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:H,"aria-label":"Close widget",children:t.jsx(Gt,{})})]})]}),Ve&&(()=>{const m=C?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",W=C?"Pick up where you left off":null,De=!M;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:qe,"aria-label":m,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),W&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:W}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:qe,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(T||F)?"is-visible":""}`,children:[t.jsx("div",{ref:Ee,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ye,className:!F&&T?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[!J&&Ie&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ie})}),!J&&it&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:it})}),!ne&&!J&&t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[se&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:_e,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(xn,{})}),ve&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${T?"is-on":""}`,onClick:we,"aria-label":T?"Turn off camera":"Turn on camera",title:T?"Stop camera":"Start camera",children:t.jsx(vn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${T?"is-on":""}`,onClick:m=>{m.stopPropagation(),me(W=>!W),X(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":le,children:t.jsx(at,{})}),le&&A.length>0&&t.jsx(Jt,{label:"Camera",devices:A,activeId:z,onPick:m=>{me(!1),Ae(m)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${b?"is-muted":""}`,onClick:be,"aria-label":b?"Unmute microphone":"Mute microphone",title:b?"Unmute":"Mute",children:t.jsx(bn,{muted:b})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${b?"is-muted":""}`,onClick:m=>{m.stopPropagation(),X(W=>!W),me(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":re,children:t.jsx(at,{})}),re&&$.length>0&&t.jsx(Jt,{label:"Microphone",devices:$,activeId:"",onPick:()=>X(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${K?"is-muted":""}`,onClick:ke,"aria-label":K?"Unmute speaker":"Mute speaker",title:K?"Unmute speaker":"Mute speaker",children:t.jsx(wn,{muted:K})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Fe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(_n,{})})]}),!ne&&J&&t.jsx(pr,{isMuted:b,onToggleMute:be,isCameraEnabled:T,onToggleCamera:we,allowCamera:ve,isScreenShareEnabled:F,onToggleScreenShare:_e,allowScreenShare:se,isSpeakerMuted:K,onToggleSpeaker:ke,allowTyping:pe,isTypingOpen:ee,onToggleTyping:Ne,onDisconnect:Fe}),!ne&&pe&&(J?ee:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ge,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ge,onChange:m=>ot(m.target.value),"aria-label":"Message the agent"}),ge.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(yr,{})})]})]}):null,(()=>{if(L&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:L}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:pt,"aria-label":"Dismiss",children:"×"})]});if(!M||k!=="error")return null;let m="Failed to connect",W="Try again";return M==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":M==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":M==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":M==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":M==="CONNECT_FAILED"?m="Connection failed. Check your network.":M.length<80&&(m=M),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:m}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:rt,children:W})]})})()]})};function at(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Gt(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Kt(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function xn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function vn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function bn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function wn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function yr(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function _n(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Jt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const d=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":d,children:[d&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),xr=['[data-ll-private="true"]',".ll-widget"];function jt(e){let r=e;for(;r;){for(const o of xr)if(r.matches(o))return!0;r=r.parentElement}return!1}function ft(e){if(jt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const lt=4096,vr=20,br=20,wr=10,_r=10,kr=30,jr=20,Xt=500,Cr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ze(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Cr)if(r.matches(o))return!0;r=r.parentElement}return!1}function et(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function Qt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function fe(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Oe(e){return e.length}function kn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",d=Array.from(o.querySelectorAll("[data-ll-region]")),c=[];for(const b of d){if(c.length>=wr)break;if(Ze(b)||!et(b))continue;const L=b.getAttribute("data-ll-region")??"",$=b.getAttribute("data-ll-intent")??void 0,T=fe((b.innerText||b.textContent||"").trim(),Xt*2);!L||!T||c.push({id:L,intent:$,text:T})}const f=[],p=["H1","H2","H3","H4","H5","H6"],g=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of g){if(Ze(b)||!et(b))continue;const L=(b.textContent||"").trim();L&&f.push(`${b.tagName}: ${fe(L,200)}`)}const l=Array.from(o.querySelectorAll("p, li"));for(const b of l){if(Ze(b)||!et(b)||p.includes(b.tagName))continue;const L=(b.textContent||"").trim();L.length>10&&f.push(fe(L,Xt))}const u=f.join(`
2
+ `),S=[],R=Array.from(o.querySelectorAll("a[href]"));for(const b of R){if(S.length>=vr)break;if(Ze(b)||!et(b))continue;const L=b.getAttribute("href")||"",$=(b.textContent||"").trim();!L||!$||S.push({href:L,text:fe($,100)})}const k=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const b of x){if(k.length>=br)break;if(Ze(b)||!ft(b)||!et(b))continue;const L=Qt(b),$=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();L&&k.push({label:fe(L,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const b of v){if(C.length>=_r)break;if(jt(b))continue;const L=b.getAttribute("data-ll-form")||"";if(!L)continue;const $=b.getAttribute("data-ll-intent")||void 0,T=Array.from(b.querySelectorAll("[data-ll-field]")),j=[];for(const A of T){if(j.length>=kr)break;if(!ft(A))continue;const z=A.getAttribute("data-ll-field")||"";if(!z)continue;const F=Qt(A)||z,te=A instanceof HTMLInputElement?A.type:A.tagName.toLowerCase(),K={name:z,label:fe(F,100),type:te};if(A.required===!0&&(K.required=!0),A instanceof HTMLSelectElement){const se=[];for(let pe=0;pe<A.options.length&&!(se.length>=jr);pe++){const ae=A.options[pe];if(!ae||ae.disabled)continue;const ne=ae.value||"",J=(ae.textContent||"").trim()||ne;!ne&&!J||se.push({value:ne,label:fe(J,60)})}se.length>0&&(K.options=se)}const ve=typeof A.validationMessage=="string"?A.validationMessage:"";ve&&(K.validationMessage=fe(ve,200)),j.push(K)}C.push({id:L,intent:$,fields:j})}const E={url:i,title:a,pathname:s,regions:c,visibleText:u,visibleLinks:S,visibleFields:k,forms:C,extras:e};let M=Oe(JSON.stringify(E.regions))+Oe(E.visibleText)+Oe(JSON.stringify(E.visibleLinks))+Oe(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleFields.length>0;)E.visibleFields.pop(),M=Oe(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),M-=80;return Oe(E.visibleText)>lt&&(E.visibleText=fe(E.visibleText,lt-100)),E}let He=null;function kt(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(He&&He.key===s&&o-He.at<1e3)return He.ctx;const a=kn(e,r);return He={key:s,at:o,ctx:a},a}function jn(){He=null}const Sr=200;function Cn(e){const r=String(e.href||"");return{href:r,text:String(e.text??e.title??r),internal:e.internal??!0,title:e.title,description:e.description}}function Lr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Sn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const d of a){if(s.length>=Sr)break;if(jt(d))continue;const c=d.getAttribute("href")||"";if(!Lr(c))continue;let f=c,p=!0;try{if(typeof window<"u"){const l=new URL(c,o);p=l.origin===o,p&&c.startsWith("http")&&(f=l.pathname+l.search+l.hash)}}catch{continue}if(i.has(f))continue;i.add(f);const g=(d.textContent||"").trim().slice(0,120);s.push({href:f,text:g,internal:p})}return s}let We=null;const Er=5e3;function ct(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(We&&We.pathname===r&&e-We.at<Er)return We.routes;const o=Sn();return We={at:e,pathname:r,routes:o},o}function Ln(){We=null}function Nr(e,r){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,r):e.value=r}function Rr(e,r,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),d=a==null?void 0:a.set,c=r==="true"||r==="1"||r==="on";d?d.call(e,c):e.checked=c,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}Nr(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Ar(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const r=window.getComputedStyle(e);return!(r.overflowY==="hidden"||r.overflowY==="clip")}function Mr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function Tr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,o=0;for(const i of e){if(!Mr(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const a=s.width*s.height;a>o&&(o=a,r=i)}return r}function Ir(){if(typeof window>"u")return null;if(Ar())return window;const e=Tr();return e||window}function Zt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Pr(e){var r,o;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const Dr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]),En=n.forwardRef(function(r,o){var Mt,Tt,It,Pt,Dt,$t,zt;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:d,sessionBody:c,soundEffects:f,experienceMode:p="WIDGET",autoConnect:g=!1,displayMode:l,defaultDisplayMode:u="expanded",onDisplayModeChange:S,position:R="bottom-right",mobileBreakpoint:k=640,persistKey:x="ll-widget",disablePersistence:v=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:M,idleLoopUrl:b,greeting:L,avatarImageUrl:$,agentName:T,branding:j={},allowCamera:A=!0,allowScreenShare:z=!0,allowTyping:F=!0,showMinimize:te=!0,chromeless:K=!1,compactControls:ve=!1,transforming:se=!1,transformingLabel:pe="Transforming…",showOn:ae,hideOn:ne,pathname:J,onNavigate:tt,onScrollToSelector:Be,getPageContext:nt,pageContextExtras:Q,getRoutes:qe,onScrollPage:Fe,onClick:rt,capabilities:Ue,onConnect:be,onDisconnect:we,onTranscript:Ae,onAgentState:_e,onConnectionStateChange:ke,onAgentEvent:je,onAgentCommand:Ce,controlledSession:H,className:pt,style:Se,zIndex:Me=2147483647}=r,Z=pn(J),Ve=gn(Z,ae,ne);n.useEffect(()=>{jn(),Ln()},[Z]);const Le=E!==void 0,[Te,ht]=n.useState(()=>{var y;return E??((y=C==null?void 0:C[0])==null?void 0:y.id)}),he=Le?E:Te,Y=n.useMemo(()=>(C==null?void 0:C.find(y=>y.id===he))??null,[C,he]),Ye=(Y==null?void 0:Y.agentId)??i,Ee=p==="EMBEDDED",[re,X]=dn({value:Ee?"expanded":l,defaultValue:Ee?"expanded":u,onChange:S,persistKey:x,disablePersistence:Ee||v}),le=fn(k),me=rn(),ee=on(),ce=sn(),Ne=an(),ge=ln(),[ot,Ge]=n.useState(!1),[Ke,ue]=n.useState(!1),[oe,Ie]=n.useState(!1),[it,mt]=n.useState(!1),[Pe,m]=n.useState(!1),W=nr({baseUrl:a,config:f}),De=n.useRef(W);De.current=W;const gt=n.useRef(tt),yt=n.useRef(Be),xt=n.useRef(Fe),vt=n.useRef(rt),Ct=n.useRef(nt),St=n.useRef(Q),Lt=n.useRef(qe),bt=n.useRef(Ue),ie=n.useRef(null);gt.current=tt,yt.current=Be,xt.current=Fe,vt.current=rt,Ct.current=nt,St.current=Q,Lt.current=qe,bt.current=Ue;function ye(y){const h=bt.current;return h?h.includes(y):!0}function xe(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Je=n.useCallback(y=>{var q,de,Re,$e;const h=y;if(!(!h.type||typeof h.type!="string")){if(je==null||je({eventName:h.type,data:y}),h.type==="navigate"){if(!ye("navigate")){xe("navigate","navigate");return}const _=typeof h.href=="string"?h.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(De.current.playPageChange(),gt.current){try{gt.current(_)}catch(N){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,N)}return}if(typeof document<"u"){const N=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(N){N.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(N){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,N)}return}if(h.type==="scroll_to"){if(!ye("scroll")){xe("scroll_to","scroll");return}const _=typeof h.selector=="string"?h.selector:null;if(!_)return;const N=h.behavior==="instant"?"instant":"smooth";if(yt.current){try{yt.current(_,N)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:N,block:"start"})}return}if(h.type==="request_page_context"){if(!ye("read_page")){xe("request_page_context","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,N=(q=ie.current)==null?void 0:q.call(ie),D=B=>{const I=N,V=I==null?void 0:I.localParticipant;if(V!=null&&V.publishData)try{const G=_?{...B,requestId:_}:B,ze=new TextEncoder().encode(JSON.stringify(G));V.publishData(ze,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},P=St.current,O=Ct.current;try{if(O){const B=O(P);if(B instanceof Promise){D({type:"page_context_pending"}),B.then(I=>D({type:"page_context",context:I})).catch(I=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",I),D({type:"page_context",context:kt(P)})});return}D({type:"page_context",context:B});return}D({type:"page_context",context:kt(P)})}catch(B){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",B),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:P}})}return}if(h.type==="scroll_page"){if(!ye("scroll")){xe("scroll_page","scroll");return}const _=h.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const N=h.behavior==="instant"?"instant":"smooth";if(xt.current){try{xt.current(_,N)}catch(I){console.warn("[LiveLayer] onScrollPage threw.",I)}return}if(typeof window>"u")return;const D={behavior:N},P=Ir(),O=I=>{P instanceof Window?P.scrollBy({top:I,...D}):P.scrollBy({top:I,...D})},B=I=>{P instanceof Window?P.scrollTo({top:I,...D}):P.scrollTo({top:I,...D})};_==="up"?O(-Zt(P)):_==="down"?O(Zt(P)):B(_==="top"?0:Pr(P));return}if(h.type==="click"){if(!ye("click")){xe("click","click");return}const _=typeof h.selector=="string"?h.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(vt.current){try{vt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let N=null;try{N=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!N){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(de=N.click)==null||de.call(N);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!ye("fill_forms")){xe(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&De.current.playConfirmation();const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const N=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!N){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const P=typeof h.fieldName=="string"?h.fieldName:null;if(!P){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const O=N.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!O){console.warn(`[LiveLayer] focus_field: no field "${P}" in form "${_}".`);return}if(!ft(O)){console.warn(`[LiveLayer] focus_field: field "${P}" is privacy-protected and not focusable.`);return}O.focus();return}const D=h.values&&typeof h.values=="object"?h.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[P,O]of Object.entries(D)){if(typeof O!="string")continue;const B=N.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] fill_form: no field "${P}" in form "${_}". Skipping.`);continue}if(!ft(B)){console.warn(`[LiveLayer] fill_form: field "${P}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Rr(B,O)}catch(I){console.warn(`[LiveLayer] fill_form: failed to set "${P}".`,I)}}return}if(h.type==="submit_form"){if(!ye("submit_forms")){xe("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}De.current.playConfirmation();const N=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!N){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof h.requestId=="string"?h.requestId:void 0,P=(Re=ie.current)==null?void 0:Re.call(ie),O=V=>{const G=P,ze=G==null?void 0:G.localParticipant;if(ze!=null&&ze.publishData)try{const Wn=D?{...V,requestId:D}:V,Bn=new TextEncoder().encode(JSON.stringify(Wn));ze.publishData(Bn,{reliable:!0})}catch{}};let B=!1;const I=()=>{B=!0,O({type:"form_submitted",formId:_})};N.addEventListener("submit",I,{once:!0});try{typeof N.requestSubmit=="function"?N.requestSubmit():N.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),N.removeEventListener("submit",I),O({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{B||(N.removeEventListener("submit",I),O({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!ye("read_page")){xe("request_routes","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,D=($e=ie.current)==null?void 0:$e.call(ie),P=D==null?void 0:D.localParticipant;if(!(P!=null&&P.publishData))return;const O=I=>{try{const V=_?{type:"routes",routes:I,requestId:_}:{type:"routes",routes:I},G=new TextEncoder().encode(JSON.stringify(V));P.publishData(G,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},B=Lt.current;if(B){try{const I=B(),V=G=>{if(!Array.isArray(G)){O([]);return}O(G.map(Cn).slice(0,200))};I instanceof Promise?I.then(V).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),O(ct())}):V(I)}catch(I){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",I),O(ct())}return}try{O(ct())}catch(I){console.warn("[LiveLayer] request_routes: extractRoutes threw.",I)}return}Dr.has(h.type)||Ce==null||Ce(h)}},[Ce,je]),U=nn({agentId:H?"__controlled__":Ye,baseUrl:a,apiKey:s,sessionEndpoint:d,sessionBody:c,onDataMessage:H?void 0:Je});n.useEffect(()=>{if(H!=null&&H.subscribeToDataMessages)return H.subscribeToDataMessages(Je)},[H,Je]),ie.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var q;if(typeof window>"u")return;const y=((q=window.location)==null?void 0:q.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=de=>{try{Je(de)}catch(Re){console.warn("[LiveLayer] simulate-command threw:",Re)}},()=>{delete window.__livelayerSimulateCommand}},[Je]);const w=n.useMemo(()=>H?{connectionState:H.connectionState,agentState:H.agentState,transcript:H.transcript,videoElement:H.videoElement,audioElement:H.audioElement,canResume:H.canResume,error:H.error,agentConfig:null,connect:async()=>{await H.onConnect()},disconnect:()=>H.onDisconnect(),getRoom:U.getRoom,isControlled:!0}:{connectionState:U.connectionState,agentState:U.agentState,transcript:U.transcript,videoElement:U.videoElement,audioElement:U.audioElement,canResume:U.canResume,error:U.error,agentConfig:U.agentConfig,connect:U.connect,disconnect:U.disconnect,getRoom:U.getRoom,isControlled:!1},[H,U]),Et=n.useRef(w);Et.current=w,n.useImperativeHandle(o,()=>({sendData:async y=>{var de,Re;const h=(Re=(de=Et.current)==null?void 0:de.getRoom)==null?void 0:Re.call(de),q=h==null?void 0:h.localParticipant;if(q!=null&&q.publishData)try{const $e=new TextEncoder().encode(JSON.stringify(y));await q.publishData($e,{reliable:!0})}catch($e){console.warn("[AvatarWidget] sendData failed:",$e)}}}),[]);const Nt=n.useRef(null);n.useEffect(()=>{const y=w.videoElement,h=Nt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[w.videoElement]),n.useEffect(()=>{const y=w.audioElement;if(!y)return;me.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(q=>{(q==null?void 0:q.name)==="NotAllowedError"&&Ge(!0)}),()=>{me.detach()}},[w.audioElement]),n.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const y=w.getRoom();if(y)return ee.setupMic(y).catch(()=>{}),ce.attachRoom(y),Ne.attachRoom(y),ge.refresh(),()=>{ee.teardownMic(),ce.teardown(),Ne.teardown()}},[w.isControlled,w.connectionState]),n.useEffect(()=>{const y=w.audioElement;y&&(y.muted=Pe)},[w.audioElement,Pe]);const Rn=n.useCallback(y=>{const h=w.getRoom();if(h)try{const q=new TextEncoder().encode(JSON.stringify({type:"user_message",text:y}));h.localParticipant.publishData(q,{reliable:!0})}catch{}},[w]),An=n.useCallback(()=>{m(y=>!y)},[]);n.useEffect(()=>{ke==null||ke(w.connectionState),w.connectionState==="connected"?be==null||be():w.connectionState==="disconnected"&&(we==null||we())},[w.connectionState,be,we,ke]),n.useEffect(()=>{Ae==null||Ae(w.transcript)},[w.transcript,Ae]),n.useEffect(()=>{_e==null||_e(w.agentState)},[w.agentState,_e]),n.useEffect(()=>{W.setThinking(w.agentState==="thinking")},[w.agentState,W]);const Rt=n.useRef(!1);n.useEffect(()=>{w.isControlled||!g||Rt.current||Ve&&w.connectionState==="idle"&&(Rt.current=!0,w.connect())},[g,w.connectionState,w,Ve]);const Mn=n.useCallback(y=>{const h=C==null?void 0:C.find(q=>q.id===y);h&&(Ie(!1),y!==he&&(ue(!0),w.disconnect(),Le||ht(y),M==null||M(h)))},[C,he,w,Le,M]);n.useEffect(()=>{Ke&&w.connectionState==="connected"&&ue(!1)},[w.connectionState,Ke]),n.useEffect(()=>{if(!oe)return;const y=h=>{h.key==="Escape"&&Ie(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[oe]);const Tn=!!$||!!(Y!=null&&Y.avatarImageUrl)||w.isControlled,Xe=cn(Ye,a,Tn);Ue===void 0&&((Mt=Xe.info)!=null&&Mt.capabilities)&&(bt.current=Xe.info.capabilities);const st=(Y==null?void 0:Y.name)??T??((Tt=w.agentConfig)==null?void 0:Tt.name)??((It=Xe.info)==null?void 0:It.name)??"Live Layer",wt=(Y==null?void 0:Y.avatarImageUrl)??$??((Pt=w.agentConfig)==null?void 0:Pt.avatarImageUrl)??((Dt=Xe.info)==null?void 0:Dt.avatarImageUrl)??null,In=b??(($t=w.agentConfig)==null?void 0:$t.idleLoopUrl)??((zt=Xe.info)==null?void 0:zt.idleLoopUrl)??null,Pn=L??null,Dn=n.useCallback(()=>X("expanded"),[X]),$n=n.useCallback(()=>X("minimized"),[X]),At=n.useCallback(()=>{w.disconnect(),X("hidden")},[w,X]),zn=n.useCallback(()=>{const y=w.audioElement;y&&y.play().then(()=>Ge(!1)).catch(()=>{})},[w.audioElement]),On=n.useCallback(()=>{Ge(!1),w.connect()},[w]),Qe={...Se,...Ee?{}:{zIndex:Me}};j.primaryColor&&(Qe["--ll-color-primary"]=j.primaryColor),j.accentColor&&(Qe["--ll-color-accent"]=j.accentColor),j.backgroundColor&&(Qe["--ll-color-bg"]=j.backgroundColor),j.textColor&&(Qe["--ll-color-fg"]=j.textColor);const Hn=["ll-widget",`ll-widget--${re}`,`ll-widget--${le?"mobile":"desktop"}`,pt].filter(Boolean).join(" ");return Ve?t.jsxs("div",{className:Hn,style:Qe,"data-display-mode":re,"data-position":R,"data-experience-mode":p==="EMBEDDED"?"embedded":"widget",children:[re==="hidden"&&t.jsx(lr,{position:R,isMobile:le,isSpeaking:w.agentState==="speaking",onExpand:()=>X("expanded"),label:`Open ${st} widget`,avatarImageUrl:wt,agentName:st}),re==="minimized"&&t.jsx(ur,{position:R,isMobile:le,agentName:st,avatarImageUrl:wt,agentState:w.agentState,isMuted:ee.isMuted,audioLevel:me,onExpand:Dn,onToggleMute:ee.toggleMute,onClose:At}),re==="expanded"&&t.jsx(gr,{position:R,isMobile:le,agentName:st,avatarImageUrl:wt,idleLoopUrl:In,greeting:Pn,branding:j,teamMembers:C,currentTeamMemberId:he,isSwitchingTeamMember:Ke,teamSwitcherOpen:oe,onToggleTeamSwitcher:()=>Ie(y=>!y),onSelectTeamMember:Mn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:ee.isMuted,micDevices:ge.mics,isCameraEnabled:ce.isEnabled,cameraPreviewEl:ce.previewEl,cameraDevices:ge.cameras,activeCameraId:ce.activeDeviceId,isScreenShareEnabled:Ne.isEnabled,screenPreviewEl:Ne.previewEl,isSpeakerMuted:Pe,allowCamera:A,allowScreenShare:z,allowTyping:F,showMinimize:te,chromeless:K,compactControls:ve,transforming:se,transformingLabel:pe,languageMenuOpen:it,onToggleLanguageMenu:()=>mt(y=>!y),needsUserGesture:ot,canResume:w.canResume,micError:ee.micError,error:w.error,avatarVideoContainerRef:Nt,agentVideoEl:w.videoElement,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:On,onResumeAudio:zn,onToggleMute:ee.toggleMute,onToggleCamera:()=>void ce.toggle(),onSwitchCameraDevice:y=>void ce.switchDevice(y),onToggleScreenShare:()=>void Ne.toggle(),onToggleSpeaker:An,onSendMessage:Rn,onMinimize:$n,onClose:At,onClearMicError:ee.clearError})]}):null});En.displayName="AvatarWidgetInner";const Nn=n.forwardRef(function(r,o){return t.jsx(tn,{children:t.jsx(En,{...r,ref:o})})});Nn.displayName="AvatarWidget";const $r=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:d})=>{const c=n.useRef(null),f=n.useRef(null),p=n.useRef(s);p.current=s;const g=n.useCallback(l=>{var S;const u=l.detail;(S=p.current)==null||S.call(p,u)},[]);return n.useEffect(()=>{const l=c.current;if(!l)return;const u=document.createElement("livelayer-widget");return u.setAttribute("agent-id",e),r&&u.setAttribute("base-url",r),o&&u.setAttribute("api-key",o),i&&u.setAttribute("mode",i),u.addEventListener("agent-event",g),l.appendChild(u),f.current=u,()=>{u.removeEventListener("agent-event",g),l.removeChild(u),f.current=null}},[e]),n.useEffect(()=>{f.current&&(i?f.current.setAttribute("mode",i):f.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:c,className:a,style:d})},zr=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:d},c){return n.createElement(i,{ref:c,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},d)}),Or=n.forwardRef(function({id:r,intent:o,children:i,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":o,...s,children:i})}),Hr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,d={name:i,"data-ll-field":i};let c;if("as"in r&&r.as==="textarea"){const{name:f,label:p,labelClassName:g,as:l,...u}=r;c=t.jsx("textarea",{ref:o,...d,...u})}else if("as"in r&&r.as==="select"){const{name:f,label:p,labelClassName:g,as:l,children:u,...S}=r;c=t.jsx("select",{ref:o,...d,...S,children:u})}else{const{name:f,label:p,labelClassName:g,as:l,...u}=r;c=t.jsx("input",{ref:o,...d,...u})}return s===void 0?c:t.jsxs("label",{className:a,children:[s,c]})});let en=1;function Wr({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,d]=n.useState([]),[c,f]=n.useState(""),[p,g]=n.useState(!1),l=n.useRef(new Set),u=n.useRef([]),S=n.useRef(p);S.current=p,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(u.current.length===0||S.current)return;const v=u.current.splice(0,u.current.length);d(C=>[...v.reverse(),...C].slice(0,200))},100);return()=>clearInterval(x)},[]);const R=n.useRef(!1);if(n.useEffect(()=>{!e||R.current||(R.current=!0,e(x=>{u.current.push({id:en++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,v=console.log,C=(E,M)=>function(...b){try{const L=typeof b[0]=="string"?b[0]:"";L.startsWith("[LiveLayer]")&&u.current.push({id:en++,ts:Date.now(),kind:E,type:L.slice(0,120),data:{args:b.slice(1).map($=>qr($))}})}catch{}return M.apply(this,b)};return console.warn=C("warn",x),console.log=C("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=a.filter(x=>{if(!c)return!0;const v=c.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>g(x=>!x),style:_t(p?"#f59e0b":"transparent"),title:"Pause / resume capture",children:p?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{d([]),u.current=[]},style:_t("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:_t("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:c,onChange:x=>f(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
3
3
  type: "navigate",
4
4
  href: "/about"
5
5
  })`})]}):k.map(x=>t.jsx(Br,{entry:x,expanded:l.current.has(x.id),onToggle:()=>{l.current.has(x.id)?l.current.delete(x.id):l.current.add(x.id),d(v=>[...v])}},x.id))})]})}function Br({entry:e,expanded:r,onToggle:o}){const i=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:o,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:i,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function _t(e){return{background:e,color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:999,padding:"3px 8px",fontSize:10,cursor:"pointer"}}function qr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Fr(){const[e,r]=n.useState([]),o=n.useCallback(s=>{r(a=>{const d=a.findIndex(c=>c.id===s.id);if(d>=0){const c=a.slice();return c[d]=s,c}return[...a,s]})},[]),i=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:o,clear:i,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=Nn;exports.ErrorBoundary=tn;exports.LiveLayerDebugPanel=Wr;exports.LiveLayerField=Hr;exports.LiveLayerForm=Or;exports.LiveLayerRegion=zr;exports.LiveLayerWidget=$r;exports.clearPageContextCache=jn;exports.clearRoutesCache=Ln;exports.extractPageContext=kn;exports.extractRoutes=Sn;exports.getCachedPageContext=kt;exports.getCachedRoutes=ct;exports.matchesPattern=hn;exports.normalizeRouteInput=Cn;exports.shouldRenderAtPath=mn;exports.useAgentInfo=cn;exports.useAudioLevel=rn;exports.useCameraState=sn;exports.useDisplayMode=un;exports.useDisplayModePersistence=dn;exports.useIsMobile=fn;exports.useLiveKitSession=nn;exports.useMediaDevices=ln;exports.useMicrophoneState=on;exports.usePathname=pn;exports.useRouteMatch=gn;exports.useScreenShareState=an;exports.useTranscript=Fr;
package/dist/index.mjs CHANGED
@@ -1263,18 +1263,18 @@ const xr = ({
1263
1263
  cameraDevices: D,
1264
1264
  activeCameraId: q,
1265
1265
  isScreenShareEnabled: G,
1266
- screenPreviewEl: oe,
1266
+ screenPreviewEl: ie,
1267
1267
  isSpeakerMuted: Z,
1268
1268
  allowCamera: ke,
1269
1269
  allowScreenShare: de,
1270
1270
  allowTyping: ye,
1271
1271
  showMinimize: ue = !0,
1272
- chromeless: ie = !1,
1273
- compactControls: le = !1,
1272
+ chromeless: le = !1,
1273
+ compactControls: ee = !1,
1274
1274
  transforming: st,
1275
1275
  transformingLabel: Ve,
1276
1276
  avatarVideoContainerRef: ct,
1277
- agentVideoEl: te,
1277
+ agentVideoEl: ne,
1278
1278
  onConnect: Ye,
1279
1279
  onDisconnect: Ge,
1280
1280
  onRetry: dt,
@@ -1290,45 +1290,45 @@ const xr = ({
1290
1290
  onClearMicError: vt
1291
1291
  }) => {
1292
1292
  var He;
1293
- const Re = ((s == null ? void 0 : s.length) ?? 0) > 1, $e = C === "connecting" || C === "connected", ne = C === "connected", Ke = C === "idle" || C === "disconnected" || C === "error", [Te, ze] = L(!1);
1293
+ const Re = ((s == null ? void 0 : s.length) ?? 0) > 1, $e = C === "connecting" || C === "connected", re = C === "connected", Ke = C === "idle" || C === "disconnected" || C === "error", [Te, ze] = L(!1);
1294
1294
  N(() => {
1295
- if (!te) {
1295
+ if (!ne) {
1296
1296
  ze(!1);
1297
1297
  return;
1298
1298
  }
1299
- if (!te.paused && te.readyState >= 2) {
1299
+ if (!ne.paused && ne.readyState >= 2) {
1300
1300
  ze(!0);
1301
1301
  return;
1302
1302
  }
1303
1303
  ze(!1);
1304
1304
  const h = () => ze(!0);
1305
- return te.addEventListener("playing", h), te.addEventListener("loadeddata", h), () => {
1306
- te.removeEventListener("playing", h), te.removeEventListener("loadeddata", h);
1305
+ return ne.addEventListener("playing", h), ne.addEventListener("loadeddata", h), () => {
1306
+ ne.removeEventListener("playing", h), ne.removeEventListener("loadeddata", h);
1307
1307
  };
1308
- }, [te]);
1308
+ }, [ne]);
1309
1309
  const [bt, ve] = L(!1);
1310
1310
  N(() => {
1311
- if (!ne) {
1311
+ if (!re) {
1312
1312
  ve(!1);
1313
1313
  return;
1314
1314
  }
1315
1315
  if (Te) return;
1316
1316
  const h = setTimeout(() => ve(!0), 8e3);
1317
1317
  return () => clearTimeout(h);
1318
- }, [ne, Te]);
1319
- const X = C === "connecting" || ne && !!o && !Te && !bt, Xe = E(null), Ie = E(null);
1318
+ }, [re, Te]);
1319
+ const X = C === "connecting" || re && !!o && !Te && !bt, Xe = E(null), Ie = E(null);
1320
1320
  N(() => {
1321
1321
  const h = Xe.current;
1322
1322
  h && (h.innerHTML = "", S && (S.style.width = "100%", S.style.height = "100%", S.style.objectFit = "cover", S.style.transform = "scaleX(-1)", h.appendChild(S)));
1323
1323
  }, [S]), N(() => {
1324
1324
  const h = Ie.current;
1325
- h && (h.innerHTML = "", oe && (oe.style.width = "100%", oe.style.height = "100%", oe.style.objectFit = "contain", h.appendChild(oe)));
1326
- }, [oe]);
1327
- const [ae, ee] = L(!1), [fe, be] = L(!1);
1325
+ h && (h.innerHTML = "", ie && (ie.style.width = "100%", ie.style.height = "100%", ie.style.objectFit = "contain", h.appendChild(ie)));
1326
+ }, [ie]);
1327
+ const [ae, te] = L(!1), [fe, be] = L(!1);
1328
1328
  N(() => {
1329
1329
  if (!ae && !fe && !R && !m) return;
1330
1330
  const h = () => {
1331
- ee(!1), be(!1), R && P(), m && a();
1331
+ te(!1), be(!1), R && P(), m && a();
1332
1332
  };
1333
1333
  return document.addEventListener("click", h), () => document.removeEventListener("click", h);
1334
1334
  }, [
@@ -1339,7 +1339,7 @@ const xr = ({
1339
1339
  P,
1340
1340
  a
1341
1341
  ]);
1342
- const [re, pe] = L(!1), Me = x(() => pe((h) => !h), []), [we, ut] = L(""), Qe = x(
1342
+ const [oe, pe] = L(!1), Me = x(() => pe((h) => !h), []), [we, ut] = L(""), Qe = x(
1343
1343
  (h) => {
1344
1344
  h.preventDefault();
1345
1345
  const j = we.trim();
@@ -1352,7 +1352,7 @@ const xr = ({
1352
1352
  const j = b[h];
1353
1353
  if (!he && j.role === "agent" ? he = j : !se && j.role === "user" && (se = j), he && se) break;
1354
1354
  }
1355
- const Oe = ne ? (he == null ? void 0 : he.text) || null : l || null, ft = ne && (se == null ? void 0 : se.text) || null, wt = [
1355
+ const Oe = re ? (he == null ? void 0 : he.text) || null : l || null, ft = re && (se == null ? void 0 : se.text) || null, wt = [
1356
1356
  "ll-expanded",
1357
1357
  t ? "ll-expanded--mobile" : "ll-expanded--desktop"
1358
1358
  ].join(" ");
@@ -1361,7 +1361,7 @@ const xr = ({
1361
1361
  {
1362
1362
  className: wt,
1363
1363
  "data-position": e,
1364
- "data-state": ne ? "connected" : $e ? "connecting" : "idle",
1364
+ "data-state": re ? "connected" : $e ? "connecting" : "idle",
1365
1365
  role: "dialog",
1366
1366
  "aria-label": `${r} widget`,
1367
1367
  children: [
@@ -1374,7 +1374,7 @@ const xr = ({
1374
1374
  className: "ll-expanded__bg-img"
1375
1375
  }
1376
1376
  ) : /* @__PURE__ */ n("div", { className: "ll-expanded__bg-fallback", children: /* @__PURE__ */ n("span", { className: "ll-expanded__bg-initial", children: ((He = r == null ? void 0 : r.charAt(0)) == null ? void 0 : He.toUpperCase()) || "A" }) }),
1377
- i && !ne && /* @__PURE__ */ n(
1377
+ i && !re && /* @__PURE__ */ n(
1378
1378
  "video",
1379
1379
  {
1380
1380
  className: "ll-expanded__bg-idle",
@@ -1391,7 +1391,7 @@ const xr = ({
1391
1391
  /* @__PURE__ */ n("div", { className: "ll-expanded__spinner" }),
1392
1392
  /* @__PURE__ */ n("p", { className: "ll-expanded__overlay-text", children: f ? "Switching..." : "Connecting..." })
1393
1393
  ] }),
1394
- I && ne && /* @__PURE__ */ g(
1394
+ I && re && /* @__PURE__ */ g(
1395
1395
  "button",
1396
1396
  {
1397
1397
  type: "button",
@@ -1417,8 +1417,8 @@ const xr = ({
1417
1417
  }
1418
1418
  ),
1419
1419
  $e ? /* @__PURE__ */ g(lt, { children: [
1420
- !le && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar", children: [
1421
- !ie && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar-left", children: [
1420
+ !ee && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar", children: [
1421
+ !le && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar-left", children: [
1422
1422
  /* @__PURE__ */ g("div", { className: "ll-expanded__pill-wrap", children: [
1423
1423
  /* @__PURE__ */ g(
1424
1424
  "button",
@@ -1539,7 +1539,7 @@ const xr = ({
1539
1539
  )
1540
1540
  ] })
1541
1541
  ] }),
1542
- le && /* @__PURE__ */ g("div", { className: "ll-compact-status", "data-state": v, children: [
1542
+ ee && /* @__PURE__ */ g("div", { className: "ll-compact-status", "data-state": v, children: [
1543
1543
  /* @__PURE__ */ n("span", { className: "ll-compact-status__dot", "aria-hidden": !0 }),
1544
1544
  /* @__PURE__ */ n("span", { className: "ll-compact-status__label", children: v })
1545
1545
  ] })
@@ -1626,7 +1626,7 @@ const xr = ({
1626
1626
  }
1627
1627
  ),
1628
1628
  $e ? /* @__PURE__ */ g("div", { className: "ll-expanded__bottom", children: [
1629
- Oe && /* @__PURE__ */ n(
1629
+ !ee && Oe && /* @__PURE__ */ n(
1630
1630
  "div",
1631
1631
  {
1632
1632
  className: "ll-expanded__transcript ll-expanded__transcript--agent",
@@ -1634,7 +1634,7 @@ const xr = ({
1634
1634
  children: /* @__PURE__ */ n("p", { className: "ll-expanded__transcript-text", children: Oe })
1635
1635
  }
1636
1636
  ),
1637
- ft && /* @__PURE__ */ n(
1637
+ !ee && ft && /* @__PURE__ */ n(
1638
1638
  "div",
1639
1639
  {
1640
1640
  className: "ll-expanded__transcript ll-expanded__transcript--user",
@@ -1642,7 +1642,7 @@ const xr = ({
1642
1642
  children: /* @__PURE__ */ n("p", { className: "ll-expanded__transcript-text", children: ft })
1643
1643
  }
1644
1644
  ),
1645
- !ie && !le && /* @__PURE__ */ g("div", { className: "ll-toolbar", onClick: (h) => h.stopPropagation(), children: [
1645
+ !le && !ee && /* @__PURE__ */ g("div", { className: "ll-toolbar", onClick: (h) => h.stopPropagation(), children: [
1646
1646
  de && /* @__PURE__ */ n(
1647
1647
  "button",
1648
1648
  {
@@ -1672,7 +1672,7 @@ const xr = ({
1672
1672
  type: "button",
1673
1673
  className: `ll-tool ll-tool--right ${z ? "is-on" : ""}`,
1674
1674
  onClick: (h) => {
1675
- h.stopPropagation(), be((j) => !j), ee(!1);
1675
+ h.stopPropagation(), be((j) => !j), te(!1);
1676
1676
  },
1677
1677
  "aria-label": "Camera devices",
1678
1678
  "aria-haspopup": "listbox",
@@ -1710,7 +1710,7 @@ const xr = ({
1710
1710
  type: "button",
1711
1711
  className: `ll-tool ll-tool--right ${w ? "is-muted" : ""}`,
1712
1712
  onClick: (h) => {
1713
- h.stopPropagation(), ee((j) => !j), be(!1);
1713
+ h.stopPropagation(), te((j) => !j), be(!1);
1714
1714
  },
1715
1715
  "aria-label": "Microphone devices",
1716
1716
  "aria-haspopup": "listbox",
@@ -1724,7 +1724,7 @@ const xr = ({
1724
1724
  label: "Microphone",
1725
1725
  devices: B,
1726
1726
  activeId: "",
1727
- onPick: () => ee(!1)
1727
+ onPick: () => te(!1)
1728
1728
  }
1729
1729
  )
1730
1730
  ] }),
@@ -1751,7 +1751,7 @@ const xr = ({
1751
1751
  }
1752
1752
  )
1753
1753
  ] }),
1754
- !ie && le && /* @__PURE__ */ n(
1754
+ !le && ee && /* @__PURE__ */ n(
1755
1755
  br,
1756
1756
  {
1757
1757
  isMuted: w,
@@ -1765,12 +1765,12 @@ const xr = ({
1765
1765
  isSpeakerMuted: Z,
1766
1766
  onToggleSpeaker: Ee,
1767
1767
  allowTyping: ye,
1768
- isTypingOpen: re,
1768
+ isTypingOpen: oe,
1769
1769
  onToggleTyping: Me,
1770
1770
  onDisconnect: Ge
1771
1771
  }
1772
1772
  ),
1773
- !ie && ye && (le ? re : !0) && /* @__PURE__ */ g("form", { className: "ll-message-input", onSubmit: Qe, children: [
1773
+ !le && ye && (ee ? oe : !0) && /* @__PURE__ */ g("form", { className: "ll-message-input", onSubmit: Qe, children: [
1774
1774
  /* @__PURE__ */ n(
1775
1775
  "input",
1776
1776
  {
@@ -2055,18 +2055,18 @@ function Ir(e, t = {}) {
2055
2055
  if (!yt(D)) continue;
2056
2056
  const q = D.getAttribute("data-ll-field") || "";
2057
2057
  if (!q) continue;
2058
- const G = rn(D) || q, oe = D instanceof HTMLInputElement ? D.type : D.tagName.toLowerCase(), Z = {
2058
+ const G = rn(D) || q, ie = D instanceof HTMLInputElement ? D.type : D.tagName.toLowerCase(), Z = {
2059
2059
  name: q,
2060
2060
  label: ge(G, 100),
2061
- type: oe
2061
+ type: ie
2062
2062
  };
2063
2063
  if (D.required === !0 && (Z.required = !0), D instanceof HTMLSelectElement) {
2064
2064
  const de = [];
2065
2065
  for (let ye = 0; ye < D.options.length && !(de.length >= Rr); ye++) {
2066
2066
  const ue = D.options[ye];
2067
2067
  if (!ue || ue.disabled) continue;
2068
- const ie = ue.value || "", le = (ue.textContent || "").trim() || ie;
2069
- !ie && !le || de.push({ value: ie, label: ge(le, 60) });
2068
+ const le = ue.value || "", ee = (ue.textContent || "").trim() || le;
2069
+ !le && !ee || de.push({ value: le, label: ge(ee, 60) });
2070
2070
  }
2071
2071
  de.length > 0 && (Z.options = de);
2072
2072
  }
@@ -2268,18 +2268,18 @@ const Yr = /* @__PURE__ */ new Set([
2268
2268
  allowCamera: D = !0,
2269
2269
  allowScreenShare: q = !0,
2270
2270
  allowTyping: G = !0,
2271
- showMinimize: oe = !0,
2271
+ showMinimize: ie = !0,
2272
2272
  chromeless: Z = !1,
2273
2273
  compactControls: ke = !1,
2274
2274
  transforming: de = !1,
2275
2275
  transformingLabel: ye = "Transforming…",
2276
2276
  showOn: ue,
2277
- hideOn: ie,
2278
- pathname: le,
2277
+ hideOn: le,
2278
+ pathname: ee,
2279
2279
  onNavigate: st,
2280
2280
  onScrollToSelector: Ve,
2281
2281
  getPageContext: ct,
2282
- pageContextExtras: te,
2282
+ pageContextExtras: ne,
2283
2283
  getRoutes: Ye,
2284
2284
  onScrollPage: Ge,
2285
2285
  onClick: dt,
@@ -2295,26 +2295,26 @@ const Yr = /* @__PURE__ */ new Set([
2295
2295
  className: vt,
2296
2296
  style: Re,
2297
2297
  zIndex: $e = 2147483647
2298
- } = t, ne = Zn(le), Ke = lr(ne, ue, ie);
2298
+ } = t, re = Zn(ee), Ke = lr(re, ue, le);
2299
2299
  N(() => {
2300
2300
  Mr(), Hr();
2301
- }, [ne]);
2301
+ }, [re]);
2302
2302
  const Te = I !== void 0, [ze, bt] = L(() => {
2303
2303
  var y;
2304
2304
  return I ?? ((y = A == null ? void 0 : A[0]) == null ? void 0 : y.id);
2305
2305
  }), ve = Te ? I : ze, X = je(
2306
2306
  () => (A == null ? void 0 : A.find((y) => y.id === ve)) ?? null,
2307
2307
  [A, ve]
2308
- ), Xe = (X == null ? void 0 : X.agentId) ?? o, Ie = f === "EMBEDDED", [ae, ee] = Jn({
2308
+ ), Xe = (X == null ? void 0 : X.agentId) ?? o, Ie = f === "EMBEDDED", [ae, te] = Jn({
2309
2309
  value: Ie ? "expanded" : a,
2310
2310
  defaultValue: Ie ? "expanded" : c,
2311
2311
  onChange: R,
2312
2312
  persistKey: v,
2313
2313
  disablePersistence: Ie || b
2314
- }), fe = Xn(C), be = zn(), re = On(), pe = Wn(), Me = Bn(), we = qn(), [ut, Qe] = L(!1), [Ze, he] = L(!1), [se, Oe] = L(!1), [ft, wt] = L(!1), [He, h] = L(!1), j = sr({ baseUrl: l, config: u }), et = E(j);
2314
+ }), fe = Xn(C), be = zn(), oe = On(), pe = Wn(), Me = Bn(), we = qn(), [ut, Qe] = L(!1), [Ze, he] = L(!1), [se, Oe] = L(!1), [ft, wt] = L(!1), [He, h] = L(!1), j = sr({ baseUrl: l, config: u }), et = E(j);
2315
2315
  et.current = j;
2316
- const _t = E(st), xt = E(Ve), kt = E(Ge), Lt = E(dt), Rt = E(ct), Tt = E(te), It = E(Ye), Ct = E(Je), ce = E(null);
2317
- _t.current = st, xt.current = Ve, kt.current = Ge, Lt.current = dt, Rt.current = ct, Tt.current = te, It.current = Ye, Ct.current = Je;
2316
+ const _t = E(st), xt = E(Ve), kt = E(Ge), Lt = E(dt), Rt = E(ct), Tt = E(ne), It = E(Ye), Ct = E(Je), ce = E(null);
2317
+ _t.current = st, xt.current = Ve, kt.current = Ge, Lt.current = dt, Rt.current = ct, Tt.current = ne, It.current = Ye, Ct.current = Je;
2318
2318
  function _e(y) {
2319
2319
  const p = Ct.current;
2320
2320
  return p ? p.includes(y) : !0;
@@ -2826,9 +2826,9 @@ const Yr = /* @__PURE__ */ new Set([
2826
2826
  if (_.isControlled || _.connectionState !== "connected") return;
2827
2827
  const y = _.getRoom();
2828
2828
  if (y)
2829
- return re.setupMic(y).catch(() => {
2829
+ return oe.setupMic(y).catch(() => {
2830
2830
  }), pe.attachRoom(y), Me.attachRoom(y), we.refresh(), () => {
2831
- re.teardownMic(), pe.teardown(), Me.teardown();
2831
+ oe.teardownMic(), pe.teardown(), Me.teardown();
2832
2832
  };
2833
2833
  }, [_.isControlled, _.connectionState]), N(() => {
2834
2834
  const y = _.audioElement;
@@ -2884,12 +2884,12 @@ const Yr = /* @__PURE__ */ new Set([
2884
2884
  }, [se]);
2885
2885
  const bn = !!B || !!(X != null && X.avatarImageUrl) || _.isControlled, nt = Fn(Xe, l, bn);
2886
2886
  Je === void 0 && ((zt = nt.info) != null && zt.capabilities) && (Ct.current = nt.info.capabilities);
2887
- const pt = (X == null ? void 0 : X.name) ?? z ?? ((Ot = _.agentConfig) == null ? void 0 : Ot.name) ?? ((Ht = nt.info) == null ? void 0 : Ht.name) ?? "Live Layer", St = (X == null ? void 0 : X.avatarImageUrl) ?? B ?? ((Wt = _.agentConfig) == null ? void 0 : Wt.avatarImageUrl) ?? ((Bt = nt.info) == null ? void 0 : Bt.avatarImageUrl) ?? null, wn = w ?? ((qt = _.agentConfig) == null ? void 0 : qt.idleLoopUrl) ?? ((Ft = nt.info) == null ? void 0 : Ft.idleLoopUrl) ?? null, _n = T ?? null, xn = x(() => ee("expanded"), [ee]), kn = x(
2888
- () => ee("minimized"),
2889
- [ee]
2887
+ const pt = (X == null ? void 0 : X.name) ?? z ?? ((Ot = _.agentConfig) == null ? void 0 : Ot.name) ?? ((Ht = nt.info) == null ? void 0 : Ht.name) ?? "Live Layer", St = (X == null ? void 0 : X.avatarImageUrl) ?? B ?? ((Wt = _.agentConfig) == null ? void 0 : Wt.avatarImageUrl) ?? ((Bt = nt.info) == null ? void 0 : Bt.avatarImageUrl) ?? null, wn = w ?? ((qt = _.agentConfig) == null ? void 0 : qt.idleLoopUrl) ?? ((Ft = nt.info) == null ? void 0 : Ft.idleLoopUrl) ?? null, _n = T ?? null, xn = x(() => te("expanded"), [te]), kn = x(
2888
+ () => te("minimized"),
2889
+ [te]
2890
2890
  ), $t = x(() => {
2891
- _.disconnect(), ee("hidden");
2892
- }, [_, ee]), Ln = x(() => {
2891
+ _.disconnect(), te("hidden");
2892
+ }, [_, te]), Ln = x(() => {
2893
2893
  const y = _.audioElement;
2894
2894
  y && y.play().then(() => Qe(!1)).catch(() => {
2895
2895
  });
@@ -2921,7 +2921,7 @@ const Yr = /* @__PURE__ */ new Set([
2921
2921
  position: P,
2922
2922
  isMobile: fe,
2923
2923
  isSpeaking: _.agentState === "speaking",
2924
- onExpand: () => ee("expanded"),
2924
+ onExpand: () => te("expanded"),
2925
2925
  label: `Open ${pt} widget`,
2926
2926
  avatarImageUrl: St,
2927
2927
  agentName: pt
@@ -2935,10 +2935,10 @@ const Yr = /* @__PURE__ */ new Set([
2935
2935
  agentName: pt,
2936
2936
  avatarImageUrl: St,
2937
2937
  agentState: _.agentState,
2938
- isMuted: re.isMuted,
2938
+ isMuted: oe.isMuted,
2939
2939
  audioLevel: be,
2940
2940
  onExpand: xn,
2941
- onToggleMute: re.toggleMute,
2941
+ onToggleMute: oe.toggleMute,
2942
2942
  onClose: $t
2943
2943
  }
2944
2944
  ),
@@ -2961,7 +2961,7 @@ const Yr = /* @__PURE__ */ new Set([
2961
2961
  connectionState: _.connectionState,
2962
2962
  agentState: _.agentState,
2963
2963
  transcript: _.transcript,
2964
- isMuted: re.isMuted,
2964
+ isMuted: oe.isMuted,
2965
2965
  micDevices: we.mics,
2966
2966
  isCameraEnabled: pe.isEnabled,
2967
2967
  cameraPreviewEl: pe.previewEl,
@@ -2973,7 +2973,7 @@ const Yr = /* @__PURE__ */ new Set([
2973
2973
  allowCamera: D,
2974
2974
  allowScreenShare: q,
2975
2975
  allowTyping: G,
2976
- showMinimize: oe,
2976
+ showMinimize: ie,
2977
2977
  chromeless: Z,
2978
2978
  compactControls: ke,
2979
2979
  transforming: de,
@@ -2982,7 +2982,7 @@ const Yr = /* @__PURE__ */ new Set([
2982
2982
  onToggleLanguageMenu: () => wt((y) => !y),
2983
2983
  needsUserGesture: ut,
2984
2984
  canResume: _.canResume,
2985
- micError: re.micError,
2985
+ micError: oe.micError,
2986
2986
  error: _.error,
2987
2987
  avatarVideoContainerRef: Pt,
2988
2988
  agentVideoEl: _.videoElement,
@@ -2990,7 +2990,7 @@ const Yr = /* @__PURE__ */ new Set([
2990
2990
  onDisconnect: () => _.disconnect(),
2991
2991
  onRetry: Cn,
2992
2992
  onResumeAudio: Ln,
2993
- onToggleMute: re.toggleMute,
2993
+ onToggleMute: oe.toggleMute,
2994
2994
  onToggleCamera: () => void pe.toggle(),
2995
2995
  onSwitchCameraDevice: (y) => void pe.switchDevice(y),
2996
2996
  onToggleScreenShare: () => void Me.toggle(),
@@ -2998,7 +2998,7 @@ const Yr = /* @__PURE__ */ new Set([
2998
2998
  onSendMessage: gn,
2999
2999
  onMinimize: kn,
3000
3000
  onClose: $t,
3001
- onClearMicError: re.clearError
3001
+ onClearMicError: oe.clearError
3002
3002
  }
3003
3003
  )
3004
3004
  ]
package/dist/styles.css CHANGED
@@ -1477,9 +1477,18 @@
1477
1477
 
1478
1478
  /* ── Compact toolbar (3-button) ────────────────────────────
1479
1479
  Used when compactControls=true. Renders mic | ••• | end-call,
1480
- with secondary controls tucked behind the OverflowPopover. */
1480
+ with secondary controls tucked behind the OverflowPopover.
1481
+
1482
+ Sized to fit a 140px-wide slot: the parent .ll-expanded__bottom
1483
+ has 12px insets on each side (116px usable). Three 40px buttons
1484
+ need 120px + gaps, so we bleed past the inset with negative
1485
+ margins and tighten the gap. flex-wrap:nowrap is critical —
1486
+ without it the mic stacks above the ••• and end-call. */
1481
1487
  .ll-toolbar--compact {
1482
- gap: 12px; /* roomier than the standard toolbar's 4px since only 3 buttons */
1488
+ gap: 6px;
1489
+ flex-wrap: nowrap;
1490
+ margin-left: -8px;
1491
+ margin-right: -8px;
1483
1492
  }
1484
1493
 
1485
1494
  /* ── Overflow popover items: language pill ─────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livelayer/react",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "LiveLayer agent widget for React — avatar video, team switching, responsive layouts, full-fidelity embed",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",