@livelayer/react 0.15.2 → 0.15.3

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"),r=require("react"),Mt=require("react-dom"),Xe=require("@livelayer/sdk"),vt=require("livekit-client");class bn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){var o,l;(l=(o=this.props).onError)==null||l.call(o,n,i)}render(){var n;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:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function xn(e){const[n,i]=r.useState("idle"),[o,l]=r.useState("idle"),[s,c]=r.useState([]),[a,u]=r.useState(null),[h,w]=r.useState(null),[g,p]=r.useState(null),[R,_]=r.useState(!1),[v,f]=r.useState(null),m=r.useRef(null),k=r.useRef(e.onDataMessage);k.current=e.onDataMessage,r.useEffect(()=>{const x={onConnectionStateChange:P=>{i(P),P==="connected"&&f(null)},onAgentStateChange:l,onTranscript:P=>c([...P]),onAgentConfig:u,onAudioTrack:P=>p(P),onVideoTrack:P=>w(P),onVideoTrackRemoved:()=>w(null),onError:P=>f(P),onDataMessage:P=>{var H;(H=k.current)==null||H.call(k,P)},onResumabilityChange:_},A=new Xe.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},x);return m.current=A,i("idle"),l("idle"),c([]),u(null),w(null),p(null),_(!1),f(null),()=>{var P;(P=A.destroy)==null||P.call(A),m.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const x=m.current;if(x)try{await x.connect()}catch(A){throw f(A instanceof Error?A.message:String(A)),A}},[]),j=r.useCallback(()=>{const x=m.current;x&&x.disconnect()},[]),O=r.useCallback(()=>{var x;return((x=m.current)==null?void 0:x.getRoom())??null},[]);return{connectionState:n,agentState:o,transcript:s,agentConfig:a,videoElement:h,audioElement:g,canResume:R,error:v,connect:E,disconnect:j,getRoom:O,session:m.current}}function wn(){const e=r.useRef(null),n=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),l=r.useCallback(()=>{const _=n.current;if(_.size===0){i.current=null;return}let v=0;for(const{analyser:f,buffer:m}of _.values()){f.getByteFrequencyData(m);let k=0;for(let j=0;j<m.length;j++)k+=m[j];const E=k/m.length/255;E>v&&(v=E)}for(const f of o.current)try{f(v)}catch(m){console.error("[useAudioLevel] subscriber threw:",m)}i.current=requestAnimationFrame(l)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&n.current.size>0&&(i.current=requestAnimationFrame(l))},[l]),a=r.useCallback(_=>{const v=n.current.get(_);if(v){try{v.node.disconnect()}catch{}try{v.analyser.disconnect()}catch{}n.current.delete(_)}},[]),u=r.useCallback((_,v)=>{const f=s();if(!f)return;a(_);const m=v(f);if(!m)return;const k=f.createAnalyser();k.fftSize=64;try{m.connect(k)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}n.current.set(_,{analyser:k,node:m,buffer:new Uint8Array(new ArrayBuffer(k.frequencyBinCount))}),c()},[a,s,c]),h=r.useCallback((_,v="agent")=>{u(v,f=>{try{return f.createMediaElementSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",v,m),null}})},[u]),w=r.useCallback((_,v="mic")=>{u(v,f=>{try{return f.createMediaStreamSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",v,m),null}})},[u]),g=r.useCallback(_=>{a(_),n.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[a]),p=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(n.current.keys()))a(_)},[a]),R=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(p(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[p]),{attach:h,attachStream:w,detach:p,detachSlot:g,subscribe:R}}function dr(e){const n=e==null?void 0:e.mediaStreamTrack;return n?new MediaStream([n]):null}function _n(){const[e,n]=r.useState(!1),[i,o]=r.useState(""),[l,s]=r.useState(null),c=r.useRef(null),a=r.useRef(null),u=r.useCallback(async v=>{var f,m;if(c.current&&a.current){try{await a.current.localParticipant.unpublishTrack(c.current)}catch{}c.current.stop(),c.current=null}a.current=v,s(null);try{const k=await vt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await v.localParticipant.publishTrack(k),c.current=k,n(k.isMuted);const E=(m=(f=k.mediaStreamTrack)==null?void 0:f.getSettings)==null?void 0:m.call(f);E!=null&&E.deviceId&&o(E.deviceId)}catch(k){const E=k instanceof Error&&k.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw s(E),k}},[]),h=r.useCallback(v=>{a.current=v},[]),w=r.useCallback(async v=>{const f=a.current;if(f)try{await f.switchActiveDevice("audioinput",v),o(v)}catch(m){console.warn("[useMicrophoneState] switchDevice failed:",m)}},[]),g=r.useCallback(async()=>{const v=a.current,f=!e;if(n(f),!!v)try{await v.localParticipant.setMicrophoneEnabled(!f)}catch(m){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",m),n(!f)}},[e]),p=r.useCallback(()=>{const v=c.current,f=a.current;if(v&&f){try{f.localParticipant.unpublishTrack(v)}catch{}v.stop()}c.current=null,a.current=null,n(!1),o("")},[]),R=r.useCallback(()=>s(null),[]),_=r.useCallback(()=>dr(c.current),[]);return{isMuted:e,activeDeviceId:i,micError:l,toggleMute:g,setupMic:u,attachRoom:h,switchDevice:w,teardownMic:p,clearError:R,getMicStream:_}}const fr={resolution:{width:640,height:480,frameRate:24}};function kn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),[c,a]=r.useState(""),u=r.useRef(null),h=r.useRef(null),w=r.useCallback(m=>{u.current=m},[]),g=r.useCallback(()=>{var E;const m=u.current,k=h.current;if(k&&m){const j=m.localParticipant.getTrackPublication(vt.Track.Source.Camera),x=(j==null?void 0:j.track)??k;try{m.localParticipant.unpublishTrack(x)}catch{}try{(E=x.stop)==null||E.call(x)}catch{}}h.current=null,s(null),n(!1)},[]),p=r.useCallback(async m=>{const k=u.current;if(k){o(null);try{const E={...fr};m&&(E.deviceId=m);const j=await vt.createLocalVideoTrack(E);await k.localParticipant.publishTrack(j),h.current=j;const O=j.attach();s(O),n(!0),m&&a(m);try{k.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const j=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(j)}}},[]),R=r.useCallback(async()=>{e?g():await p(c||void 0)},[e,c,g,p]),_=r.useCallback(async m=>{g(),await p(m)},[g,p]),v=r.useCallback(()=>{g(),u.current=null,o(null),a("")},[g]),f=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{h.current&&h.current.stop()},[]),{isEnabled:e,error:i,previewEl:l,activeDeviceId:c,toggle:R,switchDevice:_,attachRoom:w,teardown:v,clearError:f}}function Cn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),c=r.useRef(null),a=r.useCallback(p=>{c.current=p},[]),u=r.useCallback(()=>s(null),[]),h=r.useCallback(async()=>{const p=c.current;if(p){if(e){try{await p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1);return}o(null);try{await p.localParticipant.setScreenShareEnabled(!0);let R=0;const _=()=>{const v=p.localParticipant.getTrackPublication(vt.Track.Source.ScreenShare);if(v!=null&&v.track){const f=v.track.attach();s(f),n(!0);try{p.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}R++<10?setTimeout(_,100):n(!0)};_()}catch(R){const _=R instanceof Error?R.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),n(!1)}}},[e,u]),w=r.useCallback(()=>{const p=c.current;if(p&&e)try{p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1),o(null),c.current=null},[e,u]),g=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:l,toggle:h,attachRoom:a,teardown:w,clearError:g}}function Ln(){const[e,n]=r.useState([]),[i,o]=r.useState([]),l=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();n(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(l(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void l();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[l]),{mics:e,cameras:i,refresh:l}}function Sn(e,n,i=!1){const[o,l]=r.useState(null),[s,c]=r.useState(null),[a,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const h=new AbortController,w=n||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:h.signal}).then(async g=>{if(!g.ok){const p=await g.json().catch(()=>({}));throw new Error(p.error||`HTTP ${g.status}`)}return g.json()}).then(g=>{h.signal.aborted||(l(g),u(!1))}).catch(g=>{h.signal.aborted||(c(g instanceof Error?g.message:"Agent lookup failed"),u(!1))}),()=>h.abort()},[e,n,i]),{info:o,error:s,loading:a}}function En(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function pr(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function jn({value:e,defaultValue:n="expanded",onChange:i}={}){const o=e!==void 0,[l,s]=r.useState(n),c=o?e:l,a=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,a]}const hr=["hidden","minimized","expanded"];function mr(e){return e&&hr.includes(e)?e:null}function Rn({value:e,defaultValue:n="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:l=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[a,u]=jn({value:e,defaultValue:n,onChange:h=>{e===void 0&&!l&&pr(s,h),i==null||i(h)}});return r.useEffect(()=>{if(c.current||(c.current=!0,l||e!==void 0))return;const h=mr(En(s));h&&h!==a&&u(h)},[]),[a,u]}const gr=640;function Nn(e=gr){const[n,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,l=window.matchMedia(o),s=()=>i(l.matches);return s(),typeof l.addEventListener=="function"?(l.addEventListener("change",s),()=>l.removeEventListener("change",s)):(l.addListener(s),()=>{l.removeListener(s)})},[e]),n}const Zt="__llHistoryPatched",bt="ll:pathname";function yr(){if(typeof window>"u"||window.history[Zt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history.replaceState=function(...i){const o=n.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history[Zt]=!0}function Qt(){return typeof window>"u"?"/":window.location.pathname||"/"}function An(e){const[n,i]=r.useState(()=>e??Qt());return r.useEffect(()=>{if(e!==void 0)return;yr();const o=()=>i(Qt());return o(),window.addEventListener("popstate",o),window.addEventListener(bt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(bt,o)}},[e]),e??n}const en=new Map,vr=/[\\^$+?.()|{}[\]]/g;function br(e){return e.replace(vr,"\\$&")}function xr(e){const n=en.get(e);if(n)return n;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",l="",s=i.replace(/\*\*/g,o).replace(/\*/g,l),a=br(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(l,"g"),"[^/]+"),u=new RegExp(`^${a}\\/?$`);return en.set(e,u),u}function wr(e,n){const i=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return xr(e).test(i)}function In(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):wr(e,n)}function tn(e,n){if(!e||e.length===0)return!1;for(const i of e)if(In(i,n))return!0;return!1}function Mn(e,n,i){return e===void 0?!0:tn(i,e)?!1:n&&n.length>0?tn(n,e):!0}function Tn(e,n,i){return r.useMemo(()=>Mn(e,n,i),[e,n,i])}function _r(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 kr(e){const n=r.useMemo(()=>_r(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),l=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{n.navigate&&l("/audio/page-change-sound.mp3")},[n.navigate,l]),c=r.useCallback(()=>{n.action&&l("/audio/confirmation-sound.mp3")},[n.action,l]),a=r.useCallback(u=>{if(!n.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const h=new Audio(`${i}/audio/thinking-sound.mp3`);h.loop=!0,h.volume=.3,h.play().catch(()=>{o.current=null}),o.current=h}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,n.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:a}),[s,c,a])}const nn=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,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:n,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"})}),rn=({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"})}),Cr=({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"})}),Lr={left:180,right:0,up:-90,down:90},on=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Lr[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Sr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const Pn="ll-hidden-tab-center-y",Er=5,sn=16;function jr(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Pn);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function an(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Pn,String(e))}catch{}}const Rr=({position:e,isMobile:n,isSpeaking:i,onExpand:o,label:l="Open widget",avatarImageUrl:s,agentName:c,containerEl:a})=>{const u=Sr(e),h=u==="right"?"left":"right",w=n?80:72,g=!!s,p=!!a,[R,_]=r.useState(null),[v,f]=r.useState(!1),m=r.useRef(null),k=r.useRef(!1),E=r.useCallback(D=>{if(typeof window>"u")return D;const F=w/2,S=sn+F,K=window.innerHeight-sn-F;return K<S?Math.max(S,D):Math.max(S,Math.min(K,D))},[w]);r.useEffect(()=>{if(p){_(null);return}const D=jr();_(E(D??window.innerHeight/2));const F=()=>{_(S=>S===null?null:E(S))};return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[E,p]);const j=r.useCallback(D=>{if(!p&&!(D.pointerType==="mouse"&&D.button!==0)&&R!==null){try{D.currentTarget.setPointerCapture(D.pointerId)}catch{}m.current={startClientY:D.clientY,startCenterY:R,moved:!1}}},[R,p]),O=r.useCallback(D=>{const F=m.current;if(!F)return;const S=D.clientY-F.startClientY;!F.moved&&Math.abs(S)>Er&&(F.moved=!0,f(!0)),F.moved&&_(E(F.startCenterY+S))},[E]),x=r.useCallback(D=>{const F=m.current;if(F){try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}m.current=null,F.moved&&(f(!1),k.current=!0,_(S=>(S!==null&&an(S),S)))}},[]),A=r.useCallback(()=>{if(k.current){k.current=!1;return}o()},[o]),P=r.useCallback(D=>{if(D.key==="ArrowUp"||D.key==="ArrowDown"){D.preventDefault();const F=D.key==="ArrowUp"?-8:8;_(S=>{if(S===null)return S;const K=E(S+F);return an(K),K})}},[E]),H=["ll-hidden",`ll-hidden--${u}`,n?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,v?"is-dragging":null,g?"ll-hidden--with-avatar":null,p?"ll-hidden--scoped":null].filter(Boolean).join(" "),Z=R===null?void 0:{top:`${R-w/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:H,onPointerDown:j,onPointerMove:O,onPointerUp:x,onPointerCancel:x,onClick:A,onKeyDown:P,"aria-label":l,"data-position":e,style:Z,children:g?t.jsxs(t.Fragment,{children:[t.jsx(on,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(on,{direction:h,className:"ll-hidden__chevron"})})},Nr=({audioLevel:e,bars:n=20,maxHeight:i=20,minHeight:o=4,className:l,barClassName:s})=>{const c=r.useRef(null),a=r.useRef([]),u=r.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:n},(g,p)=>.5+p*w%1*.5)},[n]);r.useEffect(()=>e.subscribe(g=>{for(let p=0;p<n;p++){const R=a.current[p];if(!R)continue;const _=Math.max(o,g*i*u[p]);R.style.height=`${_}px`}}),[e,n,i,o,u]);const h=["ll-waveform",l].filter(Boolean).join(" ");return t.jsx("div",{ref:c,className:h,"aria-hidden":"true",children:Array.from({length:n},(w,g)=>t.jsx("div",{ref:p=>{a.current[g]=p},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},g))})},Ar=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,agentState:l,isMuted:s,audioLevel:c,onExpand:a,onToggleMute:u,onClose:h})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:a,"aria-label":`Expand ${i} widget`,children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Nr,{audioLevel:c,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:w=>{w.stopPropagation(),u()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx(rn,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[o?t.jsx("img",{src:o,alt:i,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:i}),t.jsx("span",{className:"ll-minimized__state",children:l==="speaking"?"Speaking":l==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:a,"aria-label":`Expand ${i} widget`,children:t.jsx(rn,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:h,"aria-label":"Close widget",children:t.jsx(Cr,{className:"ll-minimized__icon"})})]})]})}),Ir=({src:e,alt:n,preCannedPlaying:i=!1,className:o,style:l})=>{const[s,c]=r.useState(!1),a=r.useRef(e);if(r.useEffect(()=>{a.current!==e&&(a.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...l};return t.jsx("img",{src:e,alt:n,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},Mr="#E06540";function Tr({size:e=14,className:n,fill:i=Mr}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:n,"aria-hidden":!0,children:[t.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),t.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),t.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const Pr=8,ln=8,Dr=({open:e,onClose:n,anchorRef:i,children:o})=>{const l=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const a=i.current;if(!a)return;const u=()=>{const h=a.getBoundingClientRect(),w={top:h.top-Pr,left:h.left+h.width/2},g=ln+90,p=window.innerWidth-ln-90;w.left<g&&(w.left=g),w.left>p&&(w.left=p),c(w)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const a=h=>{const w=h.target,g=l.current,p=i.current;g&&g.contains(w)||p&&p.contains(w)||n()},u=h=>{h.key==="Escape"&&(h.stopPropagation(),n())};return document.addEventListener("mousedown",a),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",u)}},[e,n,i]),!e||s===null||typeof document>"u"?null:Mt.createPortal(t.jsx("div",{ref:l,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},$r=({isMuted:e,onToggleMute:n,isCameraEnabled:i,onToggleCamera:o,allowCamera:l,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:a,isSpeakerMuted:u,onToggleSpeaker:h,allowTyping:w,isTypingOpen:g,onToggleTyping:p,onDisconnect:R})=>{const[_,v]=r.useState(!1),f=r.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:m=>m.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:n,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(zn,{muted:e})}),t.jsx("button",{ref:f,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>v(m=>!m),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:t.jsx(zr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:R,"aria-label":"End conversation",children:t.jsx(On,{})})]}),t.jsxs(Dr,{open:_,onClose:()=>v(!1),anchorRef:f,children:[l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),v(!1)},children:[t.jsx($n,{}),t.jsx("span",{children:i?"Stop camera":"Start camera"})]}),a&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),v(!1)},children:[t.jsx(Dn,{}),t.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{h(),v(!1)},children:[t.jsx(Hn,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),w&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${g?"is-on":""}`,onClick:()=>{p(),v(!1)},children:[t.jsx(Hr,{}),t.jsx("span",{children:g?"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 zr(){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 Hr(){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 Or=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,idleLoopUrl:l,greeting:s,branding:c,teamMembers:a,currentTeamMemberId:u,isSwitchingTeamMember:h,teamSwitcherOpen:w,onToggleTeamSwitcher:g,onSelectTeamMember:p,languageMenuOpen:R,onToggleLanguageMenu:_,connectionState:v,agentState:f,transcript:m,canResume:k,needsUserGesture:E,error:j,isMuted:O,micError:x,micDevices:A,activeMicId:P,isCameraEnabled:H,cameraPreviewEl:Z,cameraDevices:D,activeCameraId:F,isScreenShareEnabled:S,screenPreviewEl:K,isSpeakerMuted:ge,allowCamera:se,allowScreenShare:Te,allowTyping:Pe,showMinimize:Y=!0,showClose:Ce=!0,chromeless:ye=!1,compactControls:$=!1,transforming:te,transformingLabel:W,avatarVideoContainerRef:ce,agentVideoEl:U,onConnect:Ze,onDisconnect:Qe,onRetry:ut,onResumeAudio:et,onToggleMute:Le,onSwitchMicDevice:De,onToggleCamera:Se,onSwitchCameraDevice:$e,onToggleScreenShare:Ee,onToggleSpeaker:je,onSendMessage:Re,onMinimize:Ne,onClose:I,onClearMicError:xt})=>{var Ue;const Ae=((a==null?void 0:a.length)??0)>1,ze=v==="connecting"||v==="connected",ue=v==="connected",tt=v==="idle"||v==="disconnected"||v==="error",[Ie,He]=r.useState(!1);r.useEffect(()=>{if(!U){He(!1);return}if(!U.paused&&U.readyState>=2){He(!0);return}He(!1);const y=()=>He(!0);return U.addEventListener("playing",y),U.addEventListener("loadeddata",y),()=>{U.removeEventListener("playing",y),U.removeEventListener("loadeddata",y)}},[U]);const[wt,xe]=r.useState(!1);r.useEffect(()=>{if(!ue){xe(!1);return}if(Ie)return;const y=setTimeout(()=>xe(!0),8e3);return()=>clearTimeout(y)},[ue,Ie]);const ne=v==="connecting"||ue&&!!o&&!Ie&&!wt,nt=r.useRef(null),ae=r.useRef(null);r.useEffect(()=>{const y=nt.current;y&&(y.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="cover",Z.style.transform="scaleX(-1)",y.appendChild(Z)))},[Z]),r.useEffect(()=>{const y=ae.current;y&&(y.innerHTML="",K&&(K.style.width="100%",K.style.height="100%",K.style.objectFit="contain",y.appendChild(K)))},[K]);const[oe,rt]=r.useState(!1),[Oe,we]=r.useState(!1),Fe=r.useRef(null),it=r.useRef(null);r.useEffect(()=>{if(!oe&&!Oe&&!R&&!w)return;const y=()=>{rt(!1),we(!1),R&&_(),w&&g()};return document.addEventListener("click",y),()=>document.removeEventListener("click",y)},[oe,Oe,R,w,_,g]);const[le,ve]=r.useState(!1),_t=r.useCallback(()=>ve(y=>!y),[]),[Be,_e]=r.useState(""),re=r.useCallback(y=>{y.preventDefault();const G=Be.trim();G&&(Re(G),_e(""))},[Be,Re]),de=c.productName||"Live Layer",Me=!c.productName;let fe=null,ke=null;for(let y=m.length-1;y>=0;y--){const G=m[y];if(!fe&&G.role==="agent"?fe=G:!ke&&G.role==="user"&&(ke=G),fe&&ke)break}const We=ue?(fe==null?void 0:fe.text)||null:s||null,qe=ue&&(ke==null?void 0:ke.text)||null,dt=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:dt,"data-position":e,"data-state":ue?"connected":ze?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Ir,{src:o,alt:i,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Ue=i==null?void 0:i.charAt(0))==null?void 0:Ue.toUpperCase())||"A"})}),l&&!ue&&t.jsx("video",{className:"ll-expanded__bg-idle",src:l,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:ce,className:"ll-expanded__video"}),ne&&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:h?"Switching...":"Connecting..."})]}),E&&ue&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:et,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"})]}),te&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":W,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:W})]}),ze?t.jsxs(t.Fragment,{children:[!$&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!ye&&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:y=>{Ae&&(y.stopPropagation(),g())},"aria-haspopup":Ae?"listbox":void 0,"aria-expanded":Ae?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),Ae&&t.jsx(mt,{})]}),Ae&&w&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.stopPropagation(),role:"listbox",children:a==null?void 0:a.map(y=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${y.id===u?"is-active":""}`,onClick:()=>p(y.id),role:"option","aria-selected":y.id===u,children:[y.avatarImageUrl&&t.jsx("img",{src:y.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:y.name}),y.role&&t.jsx("span",{className:"ll-hmenu__role",children:y.role})]},y.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:y=>{y.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":R,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(mt,{})]}),R&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.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--${f}`,children:f})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Ne,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"End call",title:"End call",children:t.jsx(cn,{})})]})]}),$&&t.jsxs("div",{className:"ll-compact-status","data-state":f,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:f})]})]}):!$&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[Me?t.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[t.jsx(Tr,{size:14,className:"ll-expanded__brand-mark"}),t.jsx("span",{children:de})]}):t.jsx("span",{className:"ll-expanded__brand",children:de}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Ne,"aria-label":"Minimize widget",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"Close widget",children:t.jsx(cn,{})})]})]}),tt&&(()=>{const y=k?"Resume session":v==="disconnected"?"Reconnect to agent":"Start video call",G=!j;return t.jsxs(t.Fragment,{children:[G&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Ze,"aria-label":y,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:y})]}),!$&&t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Ze,"aria-label":y,children:y})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${ze&&(H||S)?"is-visible":""}`,children:[t.jsx("div",{ref:ae,className:S?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:nt,className:!S&&H?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),ze?t.jsxs("div",{className:"ll-expanded__bottom",children:[!$&&We&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:We})}),!$&&qe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:qe})}),!ye&&!$&&t.jsxs("div",{className:"ll-toolbar",onClick:y=>y.stopPropagation(),children:[Te&&t.jsx("button",{type:"button",className:`ll-tool ${S?"is-on":""}`,onClick:Ee,"aria-label":S?"Stop sharing screen":"Share screen",title:S?"Stop sharing":"Share screen",children:t.jsx(Dn,{})}),se&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${H?"is-on":""}`,onClick:Se,"aria-label":H?"Turn off camera":"Turn on camera",title:H?"Stop camera":"Start camera",children:t.jsx($n,{})}),t.jsx("button",{ref:it,type:"button",className:`ll-tool ll-tool--right ${H?"is-on":""}`,onClick:y=>{y.stopPropagation(),we(G=>!G),rt(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Oe,children:t.jsx(mt,{})}),Oe&&D.length>0&&t.jsx(dn,{label:"Camera",devices:D,activeId:F,anchorRef:it,onPick:y=>{we(!1),$e(y)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-muted":""}`,onClick:Le,"aria-label":O?"Unmute microphone":"Mute microphone",title:O?"Unmute":"Mute",children:t.jsx(zn,{muted:O})}),t.jsx("button",{ref:Fe,type:"button",className:`ll-tool ll-tool--right ${O?"is-muted":""}`,onClick:y=>{y.stopPropagation(),rt(G=>!G),we(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":oe,children:t.jsx(mt,{})}),oe&&A.length>0&&t.jsx(dn,{label:"Microphone",devices:A,activeId:P,anchorRef:Fe,onPick:y=>{rt(!1),De(y)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${ge?"is-muted":""}`,onClick:je,"aria-label":ge?"Unmute speaker":"Mute speaker",title:ge?"Unmute speaker":"Mute speaker",children:t.jsx(Hn,{muted:ge})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Qe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(On,{})})]}),!ye&&$&&t.jsx($r,{isMuted:O,onToggleMute:Le,isCameraEnabled:H,onToggleCamera:Se,allowCamera:se,isScreenShareEnabled:S,onToggleScreenShare:Ee,allowScreenShare:Te,isSpeakerMuted:ge,onToggleSpeaker:je,allowTyping:Pe,isTypingOpen:le,onToggleTyping:_t,onDisconnect:Qe}),!ye&&Pe&&($?le:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:re,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:Be,onChange:y=>_e(y.target.value),"aria-label":"Message the agent"}),Be.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Fr,{})})]})]}):null,(()=>{if(x&&v!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:x}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:xt,"aria-label":"Dismiss",children:"×"})]});if(!j||v!=="error")return null;let y="Failed to connect",G="Try again";return j==="MIC_PERMISSION_DENIED"?y="Microphone blocked. Allow access to talk.":j==="MIC_NOT_FOUND"?y="No microphone found. Plug one in + retry.":j==="MIC_UNAVAILABLE"?y="Mic unavailable. Check other apps using it.":j==="AGENT_TIMEOUT"?y="Agent didn't pick up. Try again.":j==="CONNECT_FAILED"?y="Connection failed. Check your network.":j.length<80&&(y=j),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:y}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:ut,children:G})]})})()]})};function mt(){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 cn(){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 un(){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 Dn(){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 $n(){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 zn({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 Hn({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 Fr(){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 On(){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 dn=({label:e,devices:n,activeId:i,onPick:o,anchorRef:l})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const a=()=>{const u=l.current;if(!u)return;const h=u.getBoundingClientRect(),w=126,g=window.innerWidth-16-110,p=h.left+h.width/2;c({top:h.top-8,left:Math.max(w,Math.min(g,p))})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[l]),s===null||typeof document>"u"?null:Mt.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:a=>a.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((a,u)=>{const h=i===a.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${h?"is-active":""}`,onClick:()=>o(a.deviceId),role:"option","aria-selected":h,children:[h&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:a.label||`${e} ${u+1}`})]},a.deviceId||u)})]}),document.body)},Br=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Tt(e){let n=e;for(;n;){for(const i of Br)if(n.matches(i))return!0;n=n.parentElement}return!1}function At(e){if(Tt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const gt=4096,Wr=20,qr=20,Ur=10,Vr=10,Yr=30,Gr=20,fn=500,Kr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function lt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const i of Kr)if(n.matches(i))return!0;n=n.parentElement}return!1}function ct(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<i&&n.left<o}function pn(e){const n=e.getAttribute("id");if(n){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const a of Array.from(o.childNodes))if(a.nodeType===Node.TEXT_NODE){const u=(a.textContent||"").trim();u&&s.push(u)}else if(a instanceof HTMLElement){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a instanceof HTMLButtonElement)continue;const u=(a.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const l=e.getAttribute("placeholder");return l?l.trim():""}function ee(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Jr(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Xr(e){const n=e.getAttribute("aria-label");if(n)return n.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let l=e.parentElement;for(let s=0;l&&s<4;s++,l=l.parentElement){const c=l.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const a=c.textContent.trim();if(a&&a.length<80)return a}}return null}function Ge(e){return e.length}function Fn(e,n={}){const i=n.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",l=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),a=[];for(const x of c){if(a.length>=Ur)break;if(lt(x)||!ct(x))continue;const A=x.getAttribute("data-ll-region")??"",P=x.getAttribute("data-ll-intent")??void 0,H=ee((x.innerText||x.textContent||"").trim(),fn*2);!A||!H||a.push({id:A,intent:P,text:H})}const u=[],h=["H1","H2","H3","H4","H5","H6"],w=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of w){if(lt(x)||!ct(x))continue;const A=(x.textContent||"").trim();A&&u.push(`${x.tagName}: ${ee(A,200)}`)}const g=Array.from(i.querySelectorAll("p, li"));for(const x of g){if(lt(x)||!ct(x)||h.includes(x.tagName))continue;const A=(x.textContent||"").trim();A.length>10&&u.push(ee(A,fn))}const p=u.join(`
2
- `),R=[],_=Array.from(i.querySelectorAll("a[href]"));for(const x of _){if(R.length>=Wr)break;if(lt(x)||!ct(x))continue;const A=x.getAttribute("href")||"",P=(x.textContent||"").trim();!A||!P||R.push({href:A,text:ee(P,100)})}const v=[],f=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of f){if(v.length>=qr)break;if(lt(x)||!At(x)||!ct(x))continue;const A=pn(x),P=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();A&&v.push({label:ee(A,100),type:P})}const m=Array.from(i.querySelectorAll("form")),k=[];let E=0;for(const x of m){if(k.length>=Vr)break;if(Tt(x)||x.matches(".ll-widget *, .ll-widget"))continue;const A=x.getAttribute("id")||x.getAttribute("name")||Jr(x.getAttribute("data-ll-intent"))||`form_${E++}`,P=x.getAttribute("data-ll-intent")||Xr(x)||void 0,H=Array.from(x.querySelectorAll("input, textarea, select")),Z=[];let D=0;const F=new Set;for(const S of H){if(Z.length>=Yr)break;if(!At(S))continue;if(S instanceof HTMLInputElement){const $=S.type;if($==="submit"||$==="button"||$==="reset"||$==="hidden"||$==="image"||$==="file")continue}const K=S.getAttribute("name")||"",ge=S.getAttribute("id")||"";let se=K||ge||`field_${D}`;F.has(se)&&(se=`${se}__${D}`),F.add(se),D++;const Te=pn(S)||se,Pe=S instanceof HTMLInputElement?S.type:S.tagName.toLowerCase(),Y={name:se,label:ee(Te,100),type:Pe};S.required===!0&&(Y.required=!0);const Ce=S.getAttribute("placeholder");if(Ce&&(Y.placeholder=ee(Ce.trim(),100)),S instanceof HTMLInputElement||S instanceof HTMLTextAreaElement){const $=S.getAttribute("minlength");if($!==null){const W=parseInt($,10);!Number.isNaN(W)&&W>=0&&(Y.minLength=W)}const te=S.getAttribute("maxlength");if(te!==null){const W=parseInt(te,10);!Number.isNaN(W)&&W>=0&&(Y.maxLength=W)}}if(S instanceof HTMLInputElement){const $=S.getAttribute("min");$!==null&&(Y.min=ee($,50));const te=S.getAttribute("max");te!==null&&(Y.max=ee(te,50));const W=S.getAttribute("step");W!==null&&(Y.step=ee(W,20));const ce=S.getAttribute("pattern");ce!==null&&(Y.pattern=ee(ce,200));const U=(S.getAttribute("autocomplete")||"").toLowerCase();U&&U!=="off"&&!U.startsWith("cc-")&&(Y.autocomplete=ee(U,50))}if(S instanceof HTMLSelectElement){const $=[];for(let te=0;te<S.options.length&&!($.length>=Gr);te++){const W=S.options[te];if(!W||W.disabled)continue;const ce=W.value||"",U=(W.textContent||"").trim()||ce;!ce&&!U||$.push({value:ce,label:ee(U,60)})}$.length>0&&(Y.options=$)}const ye=typeof S.validationMessage=="string"?S.validationMessage:"";ye&&(Y.validationMessage=ee(ye,200)),Z.push(Y)}k.push({id:A,intent:P,fields:Z})}const j={url:o,title:s,pathname:l,regions:a,visibleText:p,visibleLinks:R,visibleFields:v,forms:k,extras:e};let O=Ge(JSON.stringify(j.regions))+Ge(j.visibleText)+Ge(JSON.stringify(j.visibleLinks))+Ge(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleFields.length>0;)j.visibleFields.pop(),O=Ge(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleLinks.length>0;)j.visibleLinks.pop(),O-=80;return Ge(j.visibleText)>gt&&(j.visibleText=ee(j.visibleText,gt-100)),j}let Ke=null;function It(e,n={}){const i=Date.now(),l=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Ke&&Ke.key===l&&i-Ke.at<1e3)return Ke.ctx;const s=Fn(e,n);return Ke={key:l,at:i,ctx:s},s}function Bn(){Ke=null}const Zr=200;function Wn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function Qr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function qn(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,l=[],s=Array.from(n.querySelectorAll("a[href]"));for(const c of s){if(l.length>=Zr)break;if(Tt(c))continue;const a=c.getAttribute("href")||"";if(!Qr(a))continue;let u=a,h=!0;try{if(typeof window<"u"){const g=new URL(a,i);h=g.origin===i,h&&a.startsWith("http")&&(u=g.pathname+g.search+g.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const w=(c.textContent||"").trim().slice(0,120);l.push({href:u,text:w,internal:h})}return l}let Je=null;const ei=5e3;function yt(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(Je&&Je.pathname===n&&e-Je.at<ei)return Je.routes;const i=qn();return Je={at:e,pathname:n,routes:i},i}function Un(){Je=null}function hn(e){if(e instanceof HTMLInputElement){const n=e.type;if(n==="submit"||n==="button"||n==="reset"||n==="hidden"||n==="image"||n==="file")return!1}return!0}function ti(e,n){return e.getAttribute("name")||e.getAttribute("id")||`field_${n}`}function ni(e,n){if(!n)return null;try{const s=e.querySelector(`[name="${n.replace(/"/g,'\\"')}"]`);if(s&&hn(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const l=new Map;for(const s of i){if(!hn(s))continue;const c=ti(s,o);let a=c;if(l.has(c)&&(a=`${c}__${o}`),a===n)return s;l.set(c,s),o++}return null}function mn(e,n){const i=ni(e,n);return i?At(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function ri(e,n){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),l=o==null?void 0:o.set;l?l.call(e,n):e.value=n}function ii(e,n,i={}){const o=i.triggerInput??!0,l=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,a=n==="true"||n==="1"||n==="on";c?c.call(e,a):e.checked=a,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}ri(e,n),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function gn(e,n){if(!n)return null;const i=n.replace(/"/g,'\\"');try{const c=e.querySelector(`form#${CSS.escape(n)}`);if(c)return c}catch{}const o=e.querySelector(`form[name="${i}"]`);if(o)return o;const l=e.querySelector(`form[data-ll-intent="${i}"]`);if(l)return l;const s=Array.from(e.querySelectorAll("form"));for(const c of s){const a=c.getAttribute("data-ll-intent");if(a&&oi(a)===n)return c}if(/^form_\d+$/.test(n)){const c=parseInt(n.slice(5),10);let a=0;for(const u of s)if(!(u.id||u.getAttribute("name")||u.getAttribute("data-ll-intent"))){if(a===c)return u;a++}}return null}function oi(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function si(){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 n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function ai(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function li(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,i=0;for(const o of e){if(!ai(o))continue;const l=o.getBoundingClientRect();if(l.bottom<=0||l.top>=window.innerHeight||l.right<=0||l.left>=window.innerWidth||l.width<=0||l.height<=0||o.closest(".ll-widget"))continue;const s=l.width*l.height;s>i&&(i=s,n=o)}return n}function ci(){if(typeof window>"u")return null;if(si())return window;const e=li();return e||window}function yn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ui(e){var n,i;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const di=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","task_field_updated","task_completed"]),Vn=r.forwardRef(function(n,i){var Ut,Vt,Yt,Gt,Kt,Jt,Xt;const{agentId:o,apiKey:l,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:a,soundEffects:u,experienceMode:h="WIDGET",autoConnect:w=!1,displayMode:g,defaultDisplayMode:p,onDisplayModeChange:R,position:_="bottom-right",mobileBreakpoint:v=640,persistKey:f="ll-widget",disablePersistence:m=!1,teamMembers:k,currentTeamMemberId:E,onTeamMemberChange:j,idleLoopUrl:O,greeting:x,avatarImageUrl:A,agentName:P,branding:H={},allowCamera:Z=!0,allowScreenShare:D=!0,allowTyping:F=!0,showMinimize:S,showClose:K,chromeless:ge=!1,floatingChromeContainer:se=null,compactControls:Te=!1,transforming:Pe=!1,transformingLabel:Y="Transforming…",showOn:Ce,hideOn:ye,pathname:$,onNavigate:te,onScrollToSelector:W,getPageContext:ce,pageContextExtras:U,getRoutes:Ze,onScrollPage:Qe,onClick:ut,capabilities:et,onConnect:Le,onDisconnect:De,onTranscript:Se,onAgentState:$e,onConnectionStateChange:Ee,onAgentEvent:je,onAgentCommand:Re,onCollect:Ne,controlledSession:I,className:xt,style:Ae,zIndex:ze=2147483647}=n,ue=An($),tt=Tn(ue,Ce,ye);r.useEffect(()=>{Bn(),Un()},[ue]);const Ie=E!==void 0,[He,wt]=r.useState(()=>{var b;return E??((b=k==null?void 0:k[0])==null?void 0:b.id)}),xe=Ie?E:He,ne=r.useMemo(()=>(k==null?void 0:k.find(b=>b.id===xe))??null,[k,xe]),nt=(ne==null?void 0:ne.agentId)??o,ae=h==="EMBEDDED",oe=Nn(v),Oe=p??(oe?"minimized":"expanded"),[we,Fe]=Rn({value:g,defaultValue:Oe,onChange:R,persistKey:f,disablePersistence:ae||m}),it=r.useRef(!1);r.useEffect(()=>{it.current||g!==void 0||p!==void 0||ae||m||En(`${f}:display-mode`)||(oe&&we==="expanded"&&Fe("minimized"),it.current=!0)},[oe,we,p,g,ae,m,f,Fe]);const le=ae?"expanded":we,ve=ae?()=>{}:Fe,_t=S??!ae,Be=K??!ae,_e=wn(),re=_n(),de=kn(),Me=Cn(),fe=Ln(),[ke,We]=r.useState(!1),[qe,dt]=r.useState(!1),[Ue,y]=r.useState(!1),[G,Kn]=r.useState(!1),[kt,Jn]=r.useState(!1),ft=kr({baseUrl:s,config:u}),pt=r.useRef(ft);pt.current=ft;const Ct=r.useRef(te),Lt=r.useRef(W),St=r.useRef(Qe),Et=r.useRef(ut),Pt=r.useRef(ce),Dt=r.useRef(U),$t=r.useRef(Ze),jt=r.useRef(et),pe=r.useRef(null);Ct.current=te,Lt.current=W,St.current=Qe,Et.current=ut,Pt.current=ce,Dt.current=U,$t.current=Ze,jt.current=et;function he(b){const d=jt.current;return d?d.includes(b):!0}function me(b,d){console.warn(`[LiveLayer] Agent command "${b}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const ot=r.useCallback(b=>{var V,Q,be,at;const d=b;if(!(!d.type||typeof d.type!="string")){if(je==null||je({eventName:d.type,data:b}),d.type==="navigate"){if(!he("navigate")){me("navigate","navigate");return}const C=typeof d.href=="string"?d.href:null;if(!C){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(pt.current.playPageChange(),Ct.current){try{Ct.current(C)}catch(N){console.warn(`[LiveLayer] onNavigate threw for "${C}". Falling back. Error:`,N)}return}if(typeof document<"u"){const N=document.querySelector(`a[href="${C.replace(/"/g,'\\"')}"]`);if(N){N.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",C),window.dispatchEvent(new PopStateEvent("popstate"))}catch(N){console.warn(`[LiveLayer] history.pushState fallback failed for "${C}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,N)}return}if(d.type==="scroll_to"){if(!he("scroll")){me("scroll_to","scroll");return}const C=typeof d.selector=="string"?d.selector:null;if(!C)return;const N=d.behavior==="instant"?"instant":"smooth";if(Lt.current){try{Lt.current(C,N)}catch(z){console.warn("[LiveLayer] onScrollToSelector threw.",z)}return}if(typeof document<"u"){let z=null;try{z=document.querySelector(C)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${C}".`);return}if(!z){console.warn(`[LiveLayer] scroll_to: no element matched "${C}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}z.scrollIntoView({behavior:N,block:"start"})}return}if(d.type==="request_page_context"){if(!he("read_page")){me("request_page_context","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,N=(V=pe.current)==null?void 0:V.call(pe),z=q=>{const M=N,X=M==null?void 0:M.localParticipant;if(X!=null&&X.publishData)try{const ie=C?{...q,requestId:C}:q,Ye=new TextEncoder().encode(JSON.stringify(ie));X.publishData(Ye,{reliable:!0})}catch(ie){console.warn("[LiveLayer] publishData failed.",ie)}},T=Dt.current,B=Pt.current;try{if(B){const q=B(T);if(q instanceof Promise){z({type:"page_context_pending"}),q.then(M=>z({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),z({type:"page_context",context:It(T)})});return}z({type:"page_context",context:q});return}z({type:"page_context",context:It(T)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),z({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:T}})}return}if(d.type==="scroll_page"){if(!he("scroll")){me("scroll_page","scroll");return}const C=d.direction;if(C!=="up"&&C!=="down"&&C!=="top"&&C!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(C)}". Expected up | down | top | bottom.`);return}const N=d.behavior==="instant"?"instant":"smooth";if(St.current){try{St.current(C,N)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const z={behavior:N},T=ci(),B=M=>{T instanceof Window?T.scrollBy({top:M,...z}):T.scrollBy({top:M,...z})},q=M=>{T instanceof Window?T.scrollTo({top:M,...z}):T.scrollTo({top:M,...z})};C==="up"?B(-yn(T)):C==="down"?B(yn(T)):q(C==="top"?0:ui(T));return}if(d.type==="click"){if(!he("click")){me("click","click");return}const C=typeof d.selector=="string"?d.selector:null;if(!C){console.warn("[LiveLayer] click: missing selector.");return}if(Et.current){try{Et.current(C)}catch(z){console.warn("[LiveLayer] onClick threw.",z)}return}if(typeof document>"u")return;let N=null;try{N=document.querySelector(C)}catch{console.warn(`[LiveLayer] click: invalid selector "${C}".`);return}if(!N){console.warn(`[LiveLayer] click: no element matched "${C}". 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}(Q=N.click)==null||Q.call(N);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!he("fill_forms")){me(d.type,"fill_forms");return}if(typeof document>"u")return;d.type==="fill_form"&&pt.current.playConfirmation();const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn(`[LiveLayer] ${d.type}: missing formId.`);return}const N=gn(document,C);if(!N){console.warn(`[LiveLayer] ${d.type}: no <form> matched id="${C}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(N.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(d.type==="focus_field"){const T=typeof d.fieldName=="string"?d.fieldName:null;if(!T){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=mn(N,T);if(B.el===null){B.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${T}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}B.el.focus();return}const z=d.values&&typeof d.values=="object"?d.values:null;if(!z){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[T,B]of Object.entries(z)){if(typeof B!="string")continue;const q=mn(N,T);if(q.el===null){q.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${T}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{ii(q.el,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${T}".`,M)}}return}if(d.type==="submit_form"){if(!he("submit_forms")){me("submit_form","submit_forms");return}if(typeof document>"u")return;const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn("[LiveLayer] submit_form: missing formId.");return}pt.current.playConfirmation();const N=gn(document,C);if(!N){console.warn(`[LiveLayer] submit_form: no <form> matched id="${C}" (or matching name / data-ll-intent slug).`);return}if(N.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const z=typeof d.requestId=="string"?d.requestId:void 0,T=(be=pe.current)==null?void 0:be.call(pe),B=X=>{const ie=T,Ye=ie==null?void 0:ie.localParticipant;if(Ye!=null&&Ye.publishData)try{const cr=z?{...X,requestId:z}:X,ur=new TextEncoder().encode(JSON.stringify(cr));Ye.publishData(ur,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:C})};N.addEventListener("submit",M,{once:!0});try{typeof N.requestSubmit=="function"?N.requestSubmit():N.submit()}catch(X){console.warn("[LiveLayer] submit_form: requestSubmit threw.",X),N.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"exception"});return}setTimeout(()=>{q||(N.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!he("read_page")){me("request_routes","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,z=(at=pe.current)==null?void 0:at.call(pe),T=z==null?void 0:z.localParticipant;if(!(T!=null&&T.publishData))return;const B=M=>{try{const X=C?{type:"routes",routes:M,requestId:C}:{type:"routes",routes:M},ie=new TextEncoder().encode(JSON.stringify(X));T.publishData(ie,{reliable:!0})}catch(X){console.warn("[LiveLayer] request_routes: publishData failed.",X)}},q=$t.current;if(q){try{const M=q(),X=ie=>{if(!Array.isArray(ie)){B([]);return}B(ie.map(Wn).slice(0,200))};M instanceof Promise?M.then(X).catch(ie=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",ie),B(yt())}):X(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(yt())}return}try{B(yt())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}if(d.type==="task_field_updated"){if(!he("collect_data")){me("task_field_updated","collect_data");return}const C={phase:"field",fieldId:typeof d.fieldId=="string"?d.fieldId:"",fieldName:typeof d.fieldName=="string"?d.fieldName:typeof d.fieldId=="string"?d.fieldId:"",value:typeof d.value=="string"?d.value:"",kind:typeof d.kind=="string"?d.kind:"text",source:d.source==="slide"?"slide":d.source==="page"?"page":"agent",...typeof d.slideId=="string"?{slideId:d.slideId}:{},...typeof d.formId=="string"?{formId:d.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:C}))}catch{}return}if(d.type==="task_completed"){if(!he("collect_data")){me("task_completed","collect_data");return}const C=d.result;if(!C||typeof C!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:C}}))}catch{}try{Ne==null||Ne(C)}catch(N){console.warn("[LiveLayer] onCollect threw.",N)}return}di.has(d.type)||Re==null||Re(d)}},[Re,je,Ne]),J=xn({agentId:I?"__controlled__":nt,baseUrl:s,apiKey:l,sessionEndpoint:c,sessionBody:a,onDataMessage:I?void 0:ot});r.useEffect(()=>{if(I!=null&&I.subscribeToDataMessages)return I.subscribeToDataMessages(ot)},[I,ot]),pe.current=()=>{var b;return(b=J.getRoom)==null?void 0:b.call(J)},r.useEffect(()=>{var V;if(typeof window>"u")return;const b=((V=window.location)==null?void 0:V.hostname)||"";if(b==="localhost"||b==="127.0.0.1"||b==="0.0.0.0"||b.endsWith(".local")||b.endsWith(".test"))return window.__livelayerSimulateCommand=Q=>{try{ot(Q)}catch(be){console.warn("[LiveLayer] simulate-command threw:",be)}},()=>{delete window.__livelayerSimulateCommand}},[ot]);const L=r.useMemo(()=>I?{connectionState:I.connectionState,agentState:I.agentState,transcript:I.transcript,videoElement:I.videoElement,audioElement:I.audioElement,canResume:I.canResume,error:I.error,agentConfig:null,connect:async()=>{await I.onConnect()},disconnect:()=>I.onDisconnect(),getRoom:J.getRoom,isControlled:!0}:{connectionState:J.connectionState,agentState:J.agentState,transcript:J.transcript,videoElement:J.videoElement,audioElement:J.audioElement,canResume:J.canResume,error:J.error,agentConfig:J.agentConfig,connect:J.connect,disconnect:J.disconnect,getRoom:J.getRoom,isControlled:!1},[I,J]),zt=r.useRef(L);zt.current=L;const Ht=r.useRef(I);Ht.current=I,r.useImperativeHandle(i,()=>({sendData:async b=>{var be,at;const d=Ht.current;if(d!=null&&d.publishData){try{await d.publishData(b)}catch(C){console.warn("[AvatarWidget] sendData (controlled) failed:",C)}return}const V=(at=(be=zt.current)==null?void 0:be.getRoom)==null?void 0:at.call(be),Q=V==null?void 0:V.localParticipant;if(Q!=null&&Q.publishData)try{const C=new TextEncoder().encode(JSON.stringify(b));await Q.publishData(C,{reliable:!0})}catch(C){console.warn("[AvatarWidget] sendData failed:",C)}}}),[]);const Ot=r.useRef(null);r.useEffect(()=>{const b=L.videoElement,d=Ot.current;if(!(!b||!d))return d.appendChild(b),()=>{b.parentNode===d&&d.removeChild(b)}},[L.videoElement]),r.useEffect(()=>{const b=L.audioElement;if(!b)return;const d=document.createElement("div");d.className="ll-audio-sink",d.setAttribute("aria-hidden","true"),d.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",d.appendChild(b),document.body.appendChild(d),_e.attach(b);const V=b.play();return V&&typeof V.catch=="function"&&V.catch(Q=>{(Q==null?void 0:Q.name)==="NotAllowedError"&&We(!0)}),()=>{_e.detach(),b.parentNode===d&&d.removeChild(b),d.parentNode===document.body&&document.body.removeChild(d)}},[L.audioElement]),r.useEffect(()=>{if(L.isControlled||L.connectionState!=="connected")return;const b=L.getRoom();if(b)return re.setupMic(b).then(()=>{const d=re.getMicStream();d&&_e.attachStream(d,"mic")}).catch(()=>{}),()=>{_e.detachSlot("mic"),re.teardownMic()}},[L.isControlled,L.connectionState]),r.useEffect(()=>{var d;if(L.connectionState!=="connected")return;const b=L.isControlled?(d=I==null?void 0:I.getRoom)==null?void 0:d.call(I):L.getRoom();if(b)return de.attachRoom(b),Me.attachRoom(b),L.isControlled&&re.attachRoom(b),fe.refresh(),()=>{de.teardown(),Me.teardown()}},[L.isControlled,L.connectionState,I]),r.useEffect(()=>{const b=L.audioElement;b&&(b.muted=kt)},[L.audioElement,kt]);const Xn=r.useCallback(b=>{const d={type:"user_message",text:b};if(I!=null&&I.publishData){try{I.publishData(d)}catch{}return}const V=L.getRoom();if(V)try{const Q=new TextEncoder().encode(JSON.stringify(d));V.localParticipant.publishData(Q,{reliable:!0})}catch{}},[L,I]),Zn=r.useCallback(()=>{Jn(b=>!b)},[]);r.useEffect(()=>{Ee==null||Ee(L.connectionState),L.connectionState==="connected"?Le==null||Le():L.connectionState==="disconnected"&&(De==null||De())},[L.connectionState,Le,De,Ee]),r.useEffect(()=>{Se==null||Se(L.transcript)},[L.transcript,Se]),r.useEffect(()=>{$e==null||$e(L.agentState)},[L.agentState,$e]),r.useEffect(()=>{ft.setThinking(L.agentState==="thinking")},[L.agentState,ft]);const Ft=r.useRef(!1);r.useEffect(()=>{!w||Ft.current||tt&&L.connectionState==="idle"&&(Ft.current=!0,L.connect())},[w,L.connectionState,L,tt]);const Qn=r.useCallback(b=>{const d=k==null?void 0:k.find(V=>V.id===b);d&&(y(!1),b!==xe&&(dt(!0),L.disconnect(),Ie||wt(b),j==null||j(d)))},[k,xe,L,Ie,j]);r.useEffect(()=>{qe&&L.connectionState==="connected"&&dt(!1)},[L.connectionState,qe]),r.useEffect(()=>{if(!Ue)return;const b=d=>{d.key==="Escape"&&y(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Ue]);const er=!!A||!!(ne!=null&&ne.avatarImageUrl)||L.isControlled,st=Sn(nt,s,er);et===void 0&&((Ut=st.info)!=null&&Ut.capabilities)&&(jt.current=st.info.capabilities);const ht=(ne==null?void 0:ne.name)??P??((Vt=L.agentConfig)==null?void 0:Vt.name)??((Yt=st.info)==null?void 0:Yt.name)??"Live Layer",Rt=(ne==null?void 0:ne.avatarImageUrl)??A??((Gt=L.agentConfig)==null?void 0:Gt.avatarImageUrl)??((Kt=st.info)==null?void 0:Kt.avatarImageUrl)??null,tr=O??((Jt=L.agentConfig)==null?void 0:Jt.idleLoopUrl)??((Xt=st.info)==null?void 0:Xt.idleLoopUrl)??null,nr=x??null,rr=r.useCallback(()=>ve("expanded"),[ve]),ir=r.useCallback(()=>ve("minimized"),[ve]),Bt=r.useCallback(()=>{L.disconnect(),ve("hidden")},[L,ve]),or=r.useCallback(()=>{const b=L.audioElement;b&&b.play().then(()=>We(!1)).catch(()=>{})},[L.audioElement]),sr=r.useCallback(()=>{We(!1),L.connect()},[L]),Ve={...Ae,...ae?{}:{zIndex:ze}};H.primaryColor&&(Ve["--ll-color-primary"]=H.primaryColor),H.accentColor&&(Ve["--ll-color-accent"]=H.accentColor),H.backgroundColor&&(Ve["--ll-color-bg"]=H.backgroundColor),H.textColor&&(Ve["--ll-color-fg"]=H.textColor);const ar=["ll-widget",`ll-widget--${le}`,`ll-widget--${oe?"mobile":"desktop"}`,xt].filter(Boolean).join(" ");if(!tt)return null;const lr=t.jsx("div",{className:ar,style:Ve,"data-display-mode":le,"data-position":_,"data-experience-mode":h==="EMBEDDED"?"embedded":"widget",children:le==="expanded"&&t.jsx(Or,{position:_,isMobile:oe,agentName:ht,avatarImageUrl:Rt,idleLoopUrl:tr,greeting:nr,branding:H,teamMembers:k,currentTeamMemberId:xe,isSwitchingTeamMember:qe,teamSwitcherOpen:Ue,onToggleTeamSwitcher:()=>y(b=>!b),onSelectTeamMember:Qn,connectionState:L.connectionState,agentState:L.agentState,transcript:L.transcript,isMuted:re.isMuted,micDevices:fe.mics,activeMicId:re.activeDeviceId,isCameraEnabled:de.isEnabled,cameraPreviewEl:de.previewEl,cameraDevices:fe.cameras,activeCameraId:de.activeDeviceId,isScreenShareEnabled:Me.isEnabled,screenPreviewEl:Me.previewEl,isSpeakerMuted:kt,allowCamera:Z,allowScreenShare:D,allowTyping:F,showMinimize:_t,showClose:Be,chromeless:ge,compactControls:Te,transforming:Pe,transformingLabel:Y,languageMenuOpen:G,onToggleLanguageMenu:()=>Kn(b=>!b),needsUserGesture:ke,canResume:L.canResume,micError:re.micError,error:L.error,avatarVideoContainerRef:Ot,agentVideoEl:L.videoElement,onConnect:()=>void L.connect(),onDisconnect:()=>L.disconnect(),onRetry:sr,onResumeAudio:or,onToggleMute:re.toggleMute,onSwitchMicDevice:b=>void re.switchDevice(b),onToggleCamera:()=>void de.toggle(),onSwitchCameraDevice:b=>void de.switchDevice(b),onToggleScreenShare:()=>void Me.toggle(),onToggleSpeaker:Zn,onSendMessage:Xn,onMinimize:ir,onClose:Bt,onClearMicError:re.clearError})}),Wt=!ae&&(le==="hidden"||le==="minimized")?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${le}`,`ll-widget--${oe?"mobile":"desktop"}`].join(" "),style:Ve,"data-display-mode":le,"data-position":_,children:[le==="hidden"&&t.jsx(Rr,{position:_,isMobile:oe,isSpeaking:L.agentState==="speaking",onExpand:()=>ve("expanded"),label:`Open ${ht} widget`,avatarImageUrl:Rt,agentName:ht,containerEl:se}),le==="minimized"&&t.jsx(Ar,{position:_,isMobile:oe,agentName:ht,avatarImageUrl:Rt,agentState:L.agentState,isMuted:re.isMuted,audioLevel:_e,onExpand:rr,onToggleMute:re.toggleMute,onClose:Bt})]}):null,qt=se??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[lr,Wt&&qt&&Mt.createPortal(Wt,qt)]})});Vn.displayName="AvatarWidgetInner";const Yn=r.forwardRef(function(n,i){return t.jsx(bn,{children:t.jsx(Vn,{...n,ref:i})})});Yn.displayName="AvatarWidget";const fi=({agentId:e,baseUrl:n,apiKey:i,mode:o,onAgentEvent:l,className:s,style:c})=>{const a=r.useRef(null),u=r.useRef(null),h=r.useRef(l);h.current=l;const w=r.useCallback(g=>{var R;const p=g.detail;(R=h.current)==null||R.call(h,p)},[]);return r.useEffect(()=>{const g=a.current;if(!g)return;const p=document.createElement("livelayer-widget");return p.setAttribute("agent-id",e),n&&p.setAttribute("base-url",n),i&&p.setAttribute("api-key",i),o&&p.setAttribute("mode",o),p.addEventListener("agent-event",w),g.appendChild(p),u.current=p,()=>{p.removeEventListener("agent-event",w),g.removeChild(p),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:a,className:s,style:c})},pi=r.forwardRef(function({id:n,intent:i,as:o="div",className:l,style:s,children:c},a){return r.createElement(o,{ref:a,"data-ll-region":n,"data-ll-intent":i,className:l,style:s},c)});function hi(e={}){const{onFieldUpdate:n,onComplete:i,source:o="all"}=e,[l,s]=r.useState({}),[c,a]=r.useState(!1),[u,h]=r.useState(null),w=r.useRef(n),g=r.useRef(i),p=r.useRef(o);r.useEffect(()=>{w.current=n,g.current=i,p.current=o},[n,i,o]);const R=r.useCallback(()=>{s({}),a(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=v=>{var m,k;const f=v.detail;if(f){if(f.phase==="field"){if(p.current!=="all"&&f.source!==p.current)return;a(!0),s(E=>E[f.fieldName]===f.value?E:{...E,[f.fieldName]:f.value});try{(m=w.current)==null||m.call(w,f)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(f.phase==="complete"){const E=f.result;if(p.current!=="all"&&E.source!==p.current)return;h(E),a(!1);try{(k=g.current)==null||k.call(g,E)}catch(j){console.warn("[LiveLayer] useCollect onComplete threw.",j)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:l,isCollecting:c,lastResult:u,reset:R}}let vn=1;function mi({onMount:e,defaultOpen:n=!1,storageKey:i="ll-debug-open"}){const[o,l]=r.useState(n),[s,c]=r.useState([]),[a,u]=r.useState(""),[h,w]=r.useState(!1),g=r.useRef(new Set),p=r.useRef([]),R=r.useRef(h);R.current=h,r.useEffect(()=>{try{const f=localStorage.getItem(i);f==="1"&&l(!0),f==="0"&&l(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const f=m=>{(m.metaKey||m.ctrlKey)&&m.shiftKey&&m.key.toLowerCase()==="l"&&(m.preventDefault(),l(k=>!k))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),r.useEffect(()=>{const f=setInterval(()=>{if(p.current.length===0||R.current)return;const m=p.current.splice(0,p.current.length);c(k=>[...m.reverse(),...k].slice(0,200))},100);return()=>clearInterval(f)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(f=>{p.current.push({id:vn++,ts:Date.now(),kind:"event",type:f.eventName,data:f.data})}))},[e]),r.useEffect(()=>{const f=console.warn,m=console.log,k=(E,j)=>function(...O){try{const x=typeof O[0]=="string"?O[0]:"";x.startsWith("[LiveLayer]")&&p.current.push({id:vn++,ts:Date.now(),kind:E,type:x.slice(0,120),data:{args:O.slice(1).map(A=>yi(A))}})}catch{}return j.apply(this,O)};return console.warn=k("warn",f),console.log=k("log",m),()=>{console.warn=f,console.log=m}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>l(!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 v=s.filter(f=>{if(!a)return!0;const m=a.toLowerCase();return f.type.toLowerCase().includes(m)||JSON.stringify(f.data||{}).toLowerCase().includes(m)});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:[s.length," event",s.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>w(f=>!f),style:Nt(h?"#f59e0b":"transparent"),title:"Pause / resume capture",children:h?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{c([]),p.current=[]},style:Nt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>l(!1),style:Nt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:a,onChange:f=>u(f.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:v.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"),r=require("react"),Mt=require("react-dom"),Xe=require("@livelayer/sdk"),vt=require("livekit-client");class bn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){var o,l;(l=(o=this.props).onError)==null||l.call(o,n,i)}render(){var n;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:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function xn(e){const[n,i]=r.useState("idle"),[o,l]=r.useState("idle"),[s,c]=r.useState([]),[a,u]=r.useState(null),[h,w]=r.useState(null),[g,p]=r.useState(null),[R,_]=r.useState(!1),[b,f]=r.useState(null),m=r.useRef(null),k=r.useRef(e.onDataMessage);k.current=e.onDataMessage,r.useEffect(()=>{const x={onConnectionStateChange:P=>{i(P),P==="connected"&&f(null)},onAgentStateChange:l,onTranscript:P=>c([...P]),onAgentConfig:u,onAudioTrack:P=>p(P),onVideoTrack:P=>w(P),onVideoTrackRemoved:()=>w(null),onError:P=>f(P),onDataMessage:P=>{var H;(H=k.current)==null||H.call(k,P)},onResumabilityChange:_},A=new Xe.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},x);return m.current=A,i("idle"),l("idle"),c([]),u(null),w(null),p(null),_(!1),f(null),()=>{var P;(P=A.destroy)==null||P.call(A),m.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const x=m.current;if(x)try{await x.connect()}catch(A){throw f(A instanceof Error?A.message:String(A)),A}},[]),j=r.useCallback(()=>{const x=m.current;x&&x.disconnect()},[]),O=r.useCallback(()=>{var x;return((x=m.current)==null?void 0:x.getRoom())??null},[]);return{connectionState:n,agentState:o,transcript:s,agentConfig:a,videoElement:h,audioElement:g,canResume:R,error:b,connect:E,disconnect:j,getRoom:O,session:m.current}}function wn(){const e=r.useRef(null),n=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),l=r.useCallback(()=>{const _=n.current;if(_.size===0){i.current=null;return}let b=0;for(const{analyser:f,buffer:m}of _.values()){f.getByteFrequencyData(m);let k=0;for(let j=0;j<m.length;j++)k+=m[j];const E=k/m.length/255;E>b&&(b=E)}for(const f of o.current)try{f(b)}catch(m){console.error("[useAudioLevel] subscriber threw:",m)}i.current=requestAnimationFrame(l)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&n.current.size>0&&(i.current=requestAnimationFrame(l))},[l]),a=r.useCallback(_=>{const b=n.current.get(_);if(b){try{b.node.disconnect()}catch{}try{b.analyser.disconnect()}catch{}n.current.delete(_)}},[]),u=r.useCallback((_,b)=>{const f=s();if(!f)return;a(_);const m=b(f);if(!m)return;const k=f.createAnalyser();k.fftSize=64;try{m.connect(k)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}n.current.set(_,{analyser:k,node:m,buffer:new Uint8Array(new ArrayBuffer(k.frequencyBinCount))}),c()},[a,s,c]),h=r.useCallback((_,b="agent")=>{u(b,f=>{try{return f.createMediaElementSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",b,m),null}})},[u]),w=r.useCallback((_,b="mic")=>{u(b,f=>{try{return f.createMediaStreamSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",b,m),null}})},[u]),g=r.useCallback(_=>{a(_),n.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[a]),p=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(n.current.keys()))a(_)},[a]),R=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(p(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[p]),{attach:h,attachStream:w,detach:p,detachSlot:g,subscribe:R}}function dr(e){const n=e==null?void 0:e.mediaStreamTrack;return n?new MediaStream([n]):null}function _n(){const[e,n]=r.useState(!1),[i,o]=r.useState(""),[l,s]=r.useState(null),c=r.useRef(null),a=r.useRef(null),u=r.useCallback(async b=>{var f,m;if(c.current&&a.current){try{await a.current.localParticipant.unpublishTrack(c.current)}catch{}c.current.stop(),c.current=null}a.current=b,s(null);try{const k=await vt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await b.localParticipant.publishTrack(k),c.current=k,n(k.isMuted);const E=(m=(f=k.mediaStreamTrack)==null?void 0:f.getSettings)==null?void 0:m.call(f);E!=null&&E.deviceId&&o(E.deviceId)}catch(k){const E=k instanceof Error&&k.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw s(E),k}},[]),h=r.useCallback(b=>{a.current=b},[]),w=r.useCallback(async b=>{const f=a.current;if(f)try{await f.switchActiveDevice("audioinput",b),o(b)}catch(m){console.warn("[useMicrophoneState] switchDevice failed:",m)}},[]),g=r.useCallback(async()=>{const b=a.current,f=!e;if(n(f),!!b)try{await b.localParticipant.setMicrophoneEnabled(!f)}catch(m){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",m),n(!f)}},[e]),p=r.useCallback(()=>{const b=c.current,f=a.current;if(b&&f){try{f.localParticipant.unpublishTrack(b)}catch{}b.stop()}c.current=null,a.current=null,n(!1),o("")},[]),R=r.useCallback(()=>s(null),[]),_=r.useCallback(()=>dr(c.current),[]);return{isMuted:e,activeDeviceId:i,micError:l,toggleMute:g,setupMic:u,attachRoom:h,switchDevice:w,teardownMic:p,clearError:R,getMicStream:_}}const fr={resolution:{width:640,height:480,frameRate:24}};function kn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),[c,a]=r.useState(""),u=r.useRef(null),h=r.useRef(null),w=r.useCallback(m=>{u.current=m},[]),g=r.useCallback(()=>{var E;const m=u.current,k=h.current;if(k&&m){const j=m.localParticipant.getTrackPublication(vt.Track.Source.Camera),x=(j==null?void 0:j.track)??k;try{m.localParticipant.unpublishTrack(x)}catch{}try{(E=x.stop)==null||E.call(x)}catch{}}h.current=null,s(null),n(!1)},[]),p=r.useCallback(async m=>{const k=u.current;if(k){o(null);try{const E={...fr};m&&(E.deviceId=m);const j=await vt.createLocalVideoTrack(E);await k.localParticipant.publishTrack(j),h.current=j;const O=j.attach();s(O),n(!0),m&&a(m);try{k.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const j=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(j)}}},[]),R=r.useCallback(async()=>{e?g():await p(c||void 0)},[e,c,g,p]),_=r.useCallback(async m=>{g(),await p(m)},[g,p]),b=r.useCallback(()=>{g(),u.current=null,o(null),a("")},[g]),f=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{h.current&&h.current.stop()},[]),{isEnabled:e,error:i,previewEl:l,activeDeviceId:c,toggle:R,switchDevice:_,attachRoom:w,teardown:b,clearError:f}}function Cn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),c=r.useRef(null),a=r.useCallback(p=>{c.current=p},[]),u=r.useCallback(()=>s(null),[]),h=r.useCallback(async()=>{const p=c.current;if(p){if(e){try{await p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1);return}o(null);try{await p.localParticipant.setScreenShareEnabled(!0);let R=0;const _=()=>{const b=p.localParticipant.getTrackPublication(vt.Track.Source.ScreenShare);if(b!=null&&b.track){const f=b.track.attach();s(f),n(!0);try{p.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}R++<10?setTimeout(_,100):n(!0)};_()}catch(R){const _=R instanceof Error?R.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),n(!1)}}},[e,u]),w=r.useCallback(()=>{const p=c.current;if(p&&e)try{p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1),o(null),c.current=null},[e,u]),g=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:l,toggle:h,attachRoom:a,teardown:w,clearError:g}}function Ln(){const[e,n]=r.useState([]),[i,o]=r.useState([]),l=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();n(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(l(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void l();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[l]),{mics:e,cameras:i,refresh:l}}function Sn(e,n,i=!1){const[o,l]=r.useState(null),[s,c]=r.useState(null),[a,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const h=new AbortController,w=n||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:h.signal}).then(async g=>{if(!g.ok){const p=await g.json().catch(()=>({}));throw new Error(p.error||`HTTP ${g.status}`)}return g.json()}).then(g=>{h.signal.aborted||(l(g),u(!1))}).catch(g=>{h.signal.aborted||(c(g instanceof Error?g.message:"Agent lookup failed"),u(!1))}),()=>h.abort()},[e,n,i]),{info:o,error:s,loading:a}}function En(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function pr(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function jn({value:e,defaultValue:n="expanded",onChange:i}={}){const o=e!==void 0,[l,s]=r.useState(n),c=o?e:l,a=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,a]}const hr=["hidden","minimized","expanded"];function mr(e){return e&&hr.includes(e)?e:null}function Rn({value:e,defaultValue:n="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:l=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[a,u]=jn({value:e,defaultValue:n,onChange:h=>{e===void 0&&!l&&pr(s,h),i==null||i(h)}});return r.useEffect(()=>{if(c.current||(c.current=!0,l||e!==void 0))return;const h=mr(En(s));h&&h!==a&&u(h)},[]),[a,u]}const gr=640;function Nn(e=gr){const[n,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,l=window.matchMedia(o),s=()=>i(l.matches);return s(),typeof l.addEventListener=="function"?(l.addEventListener("change",s),()=>l.removeEventListener("change",s)):(l.addListener(s),()=>{l.removeListener(s)})},[e]),n}const Zt="__llHistoryPatched",bt="ll:pathname";function yr(){if(typeof window>"u"||window.history[Zt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history.replaceState=function(...i){const o=n.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history[Zt]=!0}function Qt(){return typeof window>"u"?"/":window.location.pathname||"/"}function An(e){const[n,i]=r.useState(()=>e??Qt());return r.useEffect(()=>{if(e!==void 0)return;yr();const o=()=>i(Qt());return o(),window.addEventListener("popstate",o),window.addEventListener(bt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(bt,o)}},[e]),e??n}const en=new Map,vr=/[\\^$+?.()|{}[\]]/g;function br(e){return e.replace(vr,"\\$&")}function xr(e){const n=en.get(e);if(n)return n;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",l="",s=i.replace(/\*\*/g,o).replace(/\*/g,l),a=br(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(l,"g"),"[^/]+"),u=new RegExp(`^${a}\\/?$`);return en.set(e,u),u}function wr(e,n){const i=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return xr(e).test(i)}function In(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):wr(e,n)}function tn(e,n){if(!e||e.length===0)return!1;for(const i of e)if(In(i,n))return!0;return!1}function Mn(e,n,i){return e===void 0?!0:tn(i,e)?!1:n&&n.length>0?tn(n,e):!0}function Tn(e,n,i){return r.useMemo(()=>Mn(e,n,i),[e,n,i])}function _r(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 kr(e){const n=r.useMemo(()=>_r(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),l=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{n.navigate&&l("/audio/page-change-sound.mp3")},[n.navigate,l]),c=r.useCallback(()=>{n.action&&l("/audio/confirmation-sound.mp3")},[n.action,l]),a=r.useCallback(u=>{if(!n.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const h=new Audio(`${i}/audio/thinking-sound.mp3`);h.loop=!0,h.volume=.3,h.play().catch(()=>{o.current=null}),o.current=h}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,n.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:a}),[s,c,a])}const nn=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,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:n,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"})}),rn=({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"})}),Cr=({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"})}),Lr={left:180,right:0,up:-90,down:90},on=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Lr[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Sr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const Pn="ll-hidden-tab-center-y",Er=5,sn=16;function jr(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Pn);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function an(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Pn,String(e))}catch{}}const Rr=({position:e,isMobile:n,isSpeaking:i,onExpand:o,label:l="Open widget",avatarImageUrl:s,agentName:c,containerEl:a})=>{const u=Sr(e),h=u==="right"?"left":"right",w=n?80:72,g=!!s,p=!!a,[R,_]=r.useState(null),[b,f]=r.useState(!1),m=r.useRef(null),k=r.useRef(!1),E=r.useCallback(D=>{if(typeof window>"u")return D;const F=w/2,S=sn+F,K=window.innerHeight-sn-F;return K<S?Math.max(S,D):Math.max(S,Math.min(K,D))},[w]);r.useEffect(()=>{if(p){_(null);return}const D=jr();_(E(D??window.innerHeight/2));const F=()=>{_(S=>S===null?null:E(S))};return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[E,p]);const j=r.useCallback(D=>{if(!p&&!(D.pointerType==="mouse"&&D.button!==0)&&R!==null){try{D.currentTarget.setPointerCapture(D.pointerId)}catch{}m.current={startClientY:D.clientY,startCenterY:R,moved:!1}}},[R,p]),O=r.useCallback(D=>{const F=m.current;if(!F)return;const S=D.clientY-F.startClientY;!F.moved&&Math.abs(S)>Er&&(F.moved=!0,f(!0)),F.moved&&_(E(F.startCenterY+S))},[E]),x=r.useCallback(D=>{const F=m.current;if(F){try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}m.current=null,F.moved&&(f(!1),k.current=!0,_(S=>(S!==null&&an(S),S)))}},[]),A=r.useCallback(()=>{if(k.current){k.current=!1;return}o()},[o]),P=r.useCallback(D=>{if(D.key==="ArrowUp"||D.key==="ArrowDown"){D.preventDefault();const F=D.key==="ArrowUp"?-8:8;_(S=>{if(S===null)return S;const K=E(S+F);return an(K),K})}},[E]),H=["ll-hidden",`ll-hidden--${u}`,n?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,b?"is-dragging":null,g?"ll-hidden--with-avatar":null,p?"ll-hidden--scoped":null].filter(Boolean).join(" "),Z=R===null?void 0:{top:`${R-w/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:H,onPointerDown:j,onPointerMove:O,onPointerUp:x,onPointerCancel:x,onClick:A,onKeyDown:P,"aria-label":l,"data-position":e,style:Z,children:g?t.jsxs(t.Fragment,{children:[t.jsx(on,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(on,{direction:h,className:"ll-hidden__chevron"})})},Nr=({audioLevel:e,bars:n=20,maxHeight:i=20,minHeight:o=4,className:l,barClassName:s})=>{const c=r.useRef(null),a=r.useRef([]),u=r.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:n},(g,p)=>.5+p*w%1*.5)},[n]);r.useEffect(()=>e.subscribe(g=>{for(let p=0;p<n;p++){const R=a.current[p];if(!R)continue;const _=Math.max(o,g*i*u[p]);R.style.height=`${_}px`}}),[e,n,i,o,u]);const h=["ll-waveform",l].filter(Boolean).join(" ");return t.jsx("div",{ref:c,className:h,"aria-hidden":"true",children:Array.from({length:n},(w,g)=>t.jsx("div",{ref:p=>{a.current[g]=p},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},g))})},Ar=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,agentState:l,isMuted:s,audioLevel:c,onExpand:a,onToggleMute:u,onClose:h})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:a,"aria-label":`Expand ${i} widget`,children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Nr,{audioLevel:c,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:w=>{w.stopPropagation(),u()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx(rn,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[o?t.jsx("img",{src:o,alt:i,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:i}),t.jsx("span",{className:"ll-minimized__state",children:l==="speaking"?"Speaking":l==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:a,"aria-label":`Expand ${i} widget`,children:t.jsx(rn,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:h,"aria-label":"Close widget",children:t.jsx(Cr,{className:"ll-minimized__icon"})})]})]})}),Ir=({src:e,alt:n,preCannedPlaying:i=!1,className:o,style:l})=>{const[s,c]=r.useState(!1),a=r.useRef(e);if(r.useEffect(()=>{a.current!==e&&(a.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...l};return t.jsx("img",{src:e,alt:n,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},Mr="#E06540";function Tr({size:e=14,className:n,fill:i=Mr}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:n,"aria-hidden":!0,children:[t.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),t.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),t.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const Pr=8,ln=8,Dr=({open:e,onClose:n,anchorRef:i,children:o})=>{const l=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const a=i.current;if(!a)return;const u=()=>{const h=a.getBoundingClientRect(),w={top:h.top-Pr,left:h.left+h.width/2},g=ln+90,p=window.innerWidth-ln-90;w.left<g&&(w.left=g),w.left>p&&(w.left=p),c(w)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const a=h=>{const w=h.target,g=l.current,p=i.current;g&&g.contains(w)||p&&p.contains(w)||n()},u=h=>{h.key==="Escape"&&(h.stopPropagation(),n())};return document.addEventListener("mousedown",a),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",u)}},[e,n,i]),!e||s===null||typeof document>"u"?null:Mt.createPortal(t.jsx("div",{ref:l,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},$r=({isMuted:e,onToggleMute:n,isCameraEnabled:i,onToggleCamera:o,allowCamera:l,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:a,isSpeakerMuted:u,onToggleSpeaker:h,allowTyping:w,isTypingOpen:g,onToggleTyping:p,onDisconnect:R})=>{const[_,b]=r.useState(!1),f=r.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:m=>m.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:n,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(zn,{muted:e})}),t.jsx("button",{ref:f,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>b(m=>!m),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:t.jsx(zr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:R,"aria-label":"End conversation",children:t.jsx(On,{})})]}),t.jsxs(Dr,{open:_,onClose:()=>b(!1),anchorRef:f,children:[l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),b(!1)},children:[t.jsx($n,{}),t.jsx("span",{children:i?"Stop camera":"Start camera"})]}),a&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),b(!1)},children:[t.jsx(Dn,{}),t.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{h(),b(!1)},children:[t.jsx(Hn,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),w&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${g?"is-on":""}`,onClick:()=>{p(),b(!1)},children:[t.jsx(Hr,{}),t.jsx("span",{children:g?"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 zr(){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 Hr(){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 Or=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,idleLoopUrl:l,greeting:s,branding:c,teamMembers:a,currentTeamMemberId:u,isSwitchingTeamMember:h,teamSwitcherOpen:w,onToggleTeamSwitcher:g,onSelectTeamMember:p,languageMenuOpen:R,onToggleLanguageMenu:_,connectionState:b,agentState:f,transcript:m,canResume:k,needsUserGesture:E,error:j,isMuted:O,micError:x,micDevices:A,activeMicId:P,isCameraEnabled:H,cameraPreviewEl:Z,cameraDevices:D,activeCameraId:F,isScreenShareEnabled:S,screenPreviewEl:K,isSpeakerMuted:ge,allowCamera:se,allowScreenShare:Te,allowTyping:Pe,showMinimize:Y=!0,showClose:Ce=!0,chromeless:ye=!1,compactControls:$=!1,transforming:te,transformingLabel:W,avatarVideoContainerRef:ce,agentVideoEl:U,onConnect:Ze,onDisconnect:Qe,onRetry:ut,onResumeAudio:et,onToggleMute:Le,onSwitchMicDevice:De,onToggleCamera:Se,onSwitchCameraDevice:$e,onToggleScreenShare:Ee,onToggleSpeaker:je,onSendMessage:Re,onMinimize:Ne,onClose:I,onClearMicError:xt})=>{var Ue;const Ae=((a==null?void 0:a.length)??0)>1,ze=b==="connecting"||b==="connected",ue=b==="connected",tt=b==="idle"||b==="disconnected"||b==="error",[Ie,He]=r.useState(!1);r.useEffect(()=>{if(!U){He(!1);return}if(!U.paused&&U.readyState>=2){He(!0);return}He(!1);const y=()=>He(!0);return U.addEventListener("playing",y),U.addEventListener("loadeddata",y),()=>{U.removeEventListener("playing",y),U.removeEventListener("loadeddata",y)}},[U]);const[wt,xe]=r.useState(!1);r.useEffect(()=>{if(!ue){xe(!1);return}if(Ie)return;const y=setTimeout(()=>xe(!0),8e3);return()=>clearTimeout(y)},[ue,Ie]);const ne=b==="connecting"||ue&&!!o&&!Ie&&!wt,nt=r.useRef(null),ae=r.useRef(null);r.useEffect(()=>{const y=nt.current;y&&(y.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="cover",Z.style.transform="scaleX(-1)",y.appendChild(Z)))},[Z]),r.useEffect(()=>{const y=ae.current;y&&(y.innerHTML="",K&&(K.style.width="100%",K.style.height="100%",K.style.objectFit="contain",y.appendChild(K)))},[K]);const[oe,rt]=r.useState(!1),[Oe,we]=r.useState(!1),Fe=r.useRef(null),it=r.useRef(null);r.useEffect(()=>{if(!oe&&!Oe&&!R&&!w)return;const y=()=>{rt(!1),we(!1),R&&_(),w&&g()};return document.addEventListener("click",y),()=>document.removeEventListener("click",y)},[oe,Oe,R,w,_,g]);const[le,ve]=r.useState(!1),_t=r.useCallback(()=>ve(y=>!y),[]),[Be,_e]=r.useState(""),re=r.useCallback(y=>{y.preventDefault();const G=Be.trim();G&&(Re(G),_e(""))},[Be,Re]),de=c.productName||"Live Layer",Me=!c.productName;let fe=null,ke=null;for(let y=m.length-1;y>=0;y--){const G=m[y];if(!fe&&G.role==="agent"?fe=G:!ke&&G.role==="user"&&(ke=G),fe&&ke)break}const We=ue?(fe==null?void 0:fe.text)||null:s||null,qe=ue&&(ke==null?void 0:ke.text)||null,dt=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:dt,"data-position":e,"data-state":ue?"connected":ze?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Ir,{src:o,alt:i,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Ue=i==null?void 0:i.charAt(0))==null?void 0:Ue.toUpperCase())||"A"})}),l&&!ue&&t.jsx("video",{className:"ll-expanded__bg-idle",src:l,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:ce,className:"ll-expanded__video"}),ne&&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:h?"Switching...":"Connecting..."})]}),E&&ue&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:et,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"})]}),te&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":W,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:W})]}),ze?t.jsxs(t.Fragment,{children:[!$&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!ye&&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:y=>{Ae&&(y.stopPropagation(),g())},"aria-haspopup":Ae?"listbox":void 0,"aria-expanded":Ae?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),Ae&&t.jsx(mt,{})]}),Ae&&w&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.stopPropagation(),role:"listbox",children:a==null?void 0:a.map(y=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${y.id===u?"is-active":""}`,onClick:()=>p(y.id),role:"option","aria-selected":y.id===u,children:[y.avatarImageUrl&&t.jsx("img",{src:y.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:y.name}),y.role&&t.jsx("span",{className:"ll-hmenu__role",children:y.role})]},y.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:y=>{y.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":R,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(mt,{})]}),R&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.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--${f}`,children:f})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Ne,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"End call",title:"End call",children:t.jsx(cn,{})})]})]}),$&&t.jsxs("div",{className:"ll-compact-status","data-state":f,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:f})]})]}):!$&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[Me?t.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[t.jsx(Tr,{size:14,className:"ll-expanded__brand-mark"}),t.jsx("span",{children:de})]}):t.jsx("span",{className:"ll-expanded__brand",children:de}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Ne,"aria-label":"Minimize widget",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"Close widget",children:t.jsx(cn,{})})]})]}),tt&&(()=>{const y=k?"Resume session":b==="disconnected"?"Reconnect to agent":"Start video call",G=!j;return t.jsxs(t.Fragment,{children:[G&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Ze,"aria-label":y,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:y})]}),!$&&t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Ze,"aria-label":y,children:y})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${ze&&(H||S)?"is-visible":""}`,children:[t.jsx("div",{ref:ae,className:S?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:nt,className:!S&&H?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),ze?t.jsxs("div",{className:"ll-expanded__bottom",children:[!$&&We&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:We})}),!$&&qe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:qe})}),!ye&&!$&&t.jsxs("div",{className:"ll-toolbar",onClick:y=>y.stopPropagation(),children:[Te&&t.jsx("button",{type:"button",className:`ll-tool ${S?"is-on":""}`,onClick:Ee,"aria-label":S?"Stop sharing screen":"Share screen",title:S?"Stop sharing":"Share screen",children:t.jsx(Dn,{})}),se&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${H?"is-on":""}`,onClick:Se,"aria-label":H?"Turn off camera":"Turn on camera",title:H?"Stop camera":"Start camera",children:t.jsx($n,{})}),t.jsx("button",{ref:it,type:"button",className:`ll-tool ll-tool--right ${H?"is-on":""}`,onClick:y=>{y.stopPropagation(),we(G=>!G),rt(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Oe,children:t.jsx(mt,{})}),Oe&&D.length>0&&t.jsx(dn,{label:"Camera",devices:D,activeId:F,anchorRef:it,onPick:y=>{we(!1),$e(y)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-muted":""}`,onClick:Le,"aria-label":O?"Unmute microphone":"Mute microphone",title:O?"Unmute":"Mute",children:t.jsx(zn,{muted:O})}),t.jsx("button",{ref:Fe,type:"button",className:`ll-tool ll-tool--right ${O?"is-muted":""}`,onClick:y=>{y.stopPropagation(),rt(G=>!G),we(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":oe,children:t.jsx(mt,{})}),oe&&A.length>0&&t.jsx(dn,{label:"Microphone",devices:A,activeId:P,anchorRef:Fe,onPick:y=>{rt(!1),De(y)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${ge?"is-muted":""}`,onClick:je,"aria-label":ge?"Unmute speaker":"Mute speaker",title:ge?"Unmute speaker":"Mute speaker",children:t.jsx(Hn,{muted:ge})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Qe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(On,{})})]}),!ye&&$&&t.jsx($r,{isMuted:O,onToggleMute:Le,isCameraEnabled:H,onToggleCamera:Se,allowCamera:se,isScreenShareEnabled:S,onToggleScreenShare:Ee,allowScreenShare:Te,isSpeakerMuted:ge,onToggleSpeaker:je,allowTyping:Pe,isTypingOpen:le,onToggleTyping:_t,onDisconnect:Qe}),!ye&&Pe&&($?le:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:re,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:Be,onChange:y=>_e(y.target.value),"aria-label":"Message the agent"}),Be.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Fr,{})})]})]}):null,(()=>{if(x&&b!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:x}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:xt,"aria-label":"Dismiss",children:"×"})]});if(!j||b!=="error")return null;let y="Failed to connect",G="Try again";return j==="MIC_PERMISSION_DENIED"?y="Microphone blocked. Allow access to talk.":j==="MIC_NOT_FOUND"?y="No microphone found. Plug one in + retry.":j==="MIC_UNAVAILABLE"?y="Mic unavailable. Check other apps using it.":j==="AGENT_TIMEOUT"?y="Agent didn't pick up. Try again.":j==="CONNECT_FAILED"?y="Connection failed. Check your network.":j.length<80&&(y=j),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:y}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:ut,children:G})]})})()]})};function mt(){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 cn(){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 un(){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 Dn(){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 $n(){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 zn({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 Hn({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 Fr(){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 On(){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 dn=({label:e,devices:n,activeId:i,onPick:o,anchorRef:l})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const a=()=>{const u=l.current;if(!u)return;const h=u.getBoundingClientRect(),w=126,g=window.innerWidth-16-110,p=h.left+h.width/2;c({top:h.top-8,left:Math.max(w,Math.min(g,p))})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[l]),s===null||typeof document>"u"?null:Mt.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:a=>a.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((a,u)=>{const h=i===a.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${h?"is-active":""}`,onClick:()=>o(a.deviceId),role:"option","aria-selected":h,children:[h&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:a.label||`${e} ${u+1}`})]},a.deviceId||u)})]}),document.body)},Br=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Tt(e){let n=e;for(;n;){for(const i of Br)if(n.matches(i))return!0;n=n.parentElement}return!1}function At(e){if(Tt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const gt=4096,Wr=20,qr=20,Ur=10,Vr=10,Yr=30,Gr=20,fn=500,Kr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function lt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const i of Kr)if(n.matches(i))return!0;n=n.parentElement}return!1}function ct(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<i&&n.left<o}function pn(e){const n=e.getAttribute("id");if(n){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const a of Array.from(o.childNodes))if(a.nodeType===Node.TEXT_NODE){const u=(a.textContent||"").trim();u&&s.push(u)}else if(a instanceof HTMLElement){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a instanceof HTMLButtonElement)continue;const u=(a.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const l=e.getAttribute("placeholder");return l?l.trim():""}function ee(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Jr(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Xr(e){const n=e.getAttribute("aria-label");if(n)return n.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let l=e.parentElement;for(let s=0;l&&s<4;s++,l=l.parentElement){const c=l.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const a=c.textContent.trim();if(a&&a.length<80)return a}}return null}function Ge(e){return e.length}function Fn(e,n={}){const i=n.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",l=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),a=[];for(const x of c){if(a.length>=Ur)break;if(lt(x)||!ct(x))continue;const A=x.getAttribute("data-ll-region")??"",P=x.getAttribute("data-ll-intent")??void 0,H=ee((x.innerText||x.textContent||"").trim(),fn*2);!A||!H||a.push({id:A,intent:P,text:H})}const u=[],h=["H1","H2","H3","H4","H5","H6"],w=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of w){if(lt(x)||!ct(x))continue;const A=(x.textContent||"").trim();A&&u.push(`${x.tagName}: ${ee(A,200)}`)}const g=Array.from(i.querySelectorAll("p, li"));for(const x of g){if(lt(x)||!ct(x)||h.includes(x.tagName))continue;const A=(x.textContent||"").trim();A.length>10&&u.push(ee(A,fn))}const p=u.join(`
2
+ `),R=[],_=Array.from(i.querySelectorAll("a[href]"));for(const x of _){if(R.length>=Wr)break;if(lt(x)||!ct(x))continue;const A=x.getAttribute("href")||"",P=(x.textContent||"").trim();!A||!P||R.push({href:A,text:ee(P,100)})}const b=[],f=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of f){if(b.length>=qr)break;if(lt(x)||!At(x)||!ct(x))continue;const A=pn(x),P=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();A&&b.push({label:ee(A,100),type:P})}const m=Array.from(i.querySelectorAll("form")),k=[];let E=0;for(const x of m){if(k.length>=Vr)break;if(Tt(x)||x.matches(".ll-widget *, .ll-widget"))continue;const A=x.getAttribute("id")||x.getAttribute("name")||Jr(x.getAttribute("data-ll-intent"))||`form_${E++}`,P=x.getAttribute("data-ll-intent")||Xr(x)||void 0,H=Array.from(x.querySelectorAll("input, textarea, select")),Z=[];let D=0;const F=new Set;for(const S of H){if(Z.length>=Yr)break;if(!At(S))continue;if(S instanceof HTMLInputElement){const $=S.type;if($==="submit"||$==="button"||$==="reset"||$==="hidden"||$==="image"||$==="file")continue}const K=S.getAttribute("name")||"",ge=S.getAttribute("id")||"";let se=K||ge||`field_${D}`;F.has(se)&&(se=`${se}__${D}`),F.add(se),D++;const Te=pn(S)||se,Pe=S instanceof HTMLInputElement?S.type:S.tagName.toLowerCase(),Y={name:se,label:ee(Te,100),type:Pe};S.required===!0&&(Y.required=!0);const Ce=S.getAttribute("placeholder");if(Ce&&(Y.placeholder=ee(Ce.trim(),100)),S instanceof HTMLInputElement||S instanceof HTMLTextAreaElement){const $=S.getAttribute("minlength");if($!==null){const W=parseInt($,10);!Number.isNaN(W)&&W>=0&&(Y.minLength=W)}const te=S.getAttribute("maxlength");if(te!==null){const W=parseInt(te,10);!Number.isNaN(W)&&W>=0&&(Y.maxLength=W)}}if(S instanceof HTMLInputElement){const $=S.getAttribute("min");$!==null&&(Y.min=ee($,50));const te=S.getAttribute("max");te!==null&&(Y.max=ee(te,50));const W=S.getAttribute("step");W!==null&&(Y.step=ee(W,20));const ce=S.getAttribute("pattern");ce!==null&&(Y.pattern=ee(ce,200));const U=(S.getAttribute("autocomplete")||"").toLowerCase();U&&U!=="off"&&!U.startsWith("cc-")&&(Y.autocomplete=ee(U,50))}if(S instanceof HTMLSelectElement){const $=[];for(let te=0;te<S.options.length&&!($.length>=Gr);te++){const W=S.options[te];if(!W||W.disabled)continue;const ce=W.value||"",U=(W.textContent||"").trim()||ce;!ce&&!U||$.push({value:ce,label:ee(U,60)})}$.length>0&&(Y.options=$)}const ye=typeof S.validationMessage=="string"?S.validationMessage:"";ye&&(Y.validationMessage=ee(ye,200)),Z.push(Y)}k.push({id:A,intent:P,fields:Z})}const j={url:o,title:s,pathname:l,regions:a,visibleText:p,visibleLinks:R,visibleFields:b,forms:k,extras:e};let O=Ge(JSON.stringify(j.regions))+Ge(j.visibleText)+Ge(JSON.stringify(j.visibleLinks))+Ge(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleFields.length>0;)j.visibleFields.pop(),O=Ge(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleLinks.length>0;)j.visibleLinks.pop(),O-=80;return Ge(j.visibleText)>gt&&(j.visibleText=ee(j.visibleText,gt-100)),j}let Ke=null;function It(e,n={}){const i=Date.now(),l=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Ke&&Ke.key===l&&i-Ke.at<1e3)return Ke.ctx;const s=Fn(e,n);return Ke={key:l,at:i,ctx:s},s}function Bn(){Ke=null}const Zr=200;function Wn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function Qr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function qn(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,l=[],s=Array.from(n.querySelectorAll("a[href]"));for(const c of s){if(l.length>=Zr)break;if(Tt(c))continue;const a=c.getAttribute("href")||"";if(!Qr(a))continue;let u=a,h=!0;try{if(typeof window<"u"){const g=new URL(a,i);h=g.origin===i,h&&a.startsWith("http")&&(u=g.pathname+g.search+g.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const w=(c.textContent||"").trim().slice(0,120);l.push({href:u,text:w,internal:h})}return l}let Je=null;const ei=5e3;function yt(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(Je&&Je.pathname===n&&e-Je.at<ei)return Je.routes;const i=qn();return Je={at:e,pathname:n,routes:i},i}function Un(){Je=null}function hn(e){if(e instanceof HTMLInputElement){const n=e.type;if(n==="submit"||n==="button"||n==="reset"||n==="hidden"||n==="image"||n==="file")return!1}return!0}function ti(e,n){return e.getAttribute("name")||e.getAttribute("id")||`field_${n}`}function ni(e,n){if(!n)return null;try{const s=e.querySelector(`[name="${n.replace(/"/g,'\\"')}"]`);if(s&&hn(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const l=new Map;for(const s of i){if(!hn(s))continue;const c=ti(s,o);let a=c;if(l.has(c)&&(a=`${c}__${o}`),a===n)return s;l.set(c,s),o++}return null}function mn(e,n){const i=ni(e,n);return i?At(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function ri(e,n){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),l=o==null?void 0:o.set;l?l.call(e,n):e.value=n}function ii(e,n,i={}){const o=i.triggerInput??!0,l=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,a=n==="true"||n==="1"||n==="on";c?c.call(e,a):e.checked=a,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}ri(e,n),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function gn(e,n){if(!n)return null;const i=n.replace(/"/g,'\\"');try{const c=e.querySelector(`form#${CSS.escape(n)}`);if(c)return c}catch{}const o=e.querySelector(`form[name="${i}"]`);if(o)return o;const l=e.querySelector(`form[data-ll-intent="${i}"]`);if(l)return l;const s=Array.from(e.querySelectorAll("form"));for(const c of s){const a=c.getAttribute("data-ll-intent");if(a&&oi(a)===n)return c}if(/^form_\d+$/.test(n)){const c=parseInt(n.slice(5),10);let a=0;for(const u of s)if(!(u.id||u.getAttribute("name")||u.getAttribute("data-ll-intent"))){if(a===c)return u;a++}}return null}function oi(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function si(){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 n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function ai(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function li(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,i=0;for(const o of e){if(!ai(o))continue;const l=o.getBoundingClientRect();if(l.bottom<=0||l.top>=window.innerHeight||l.right<=0||l.left>=window.innerWidth||l.width<=0||l.height<=0||o.closest(".ll-widget"))continue;const s=l.width*l.height;s>i&&(i=s,n=o)}return n}function ci(){if(typeof window>"u")return null;if(si())return window;const e=li();return e||window}function yn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ui(e){var n,i;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const di=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","task_field_updated","task_completed"]),Vn=r.forwardRef(function(n,i){var Ut,Vt,Yt,Gt,Kt,Jt,Xt;const{agentId:o,apiKey:l,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:a,soundEffects:u,experienceMode:h="WIDGET",autoConnect:w=!1,displayMode:g,defaultDisplayMode:p,onDisplayModeChange:R,position:_="bottom-right",mobileBreakpoint:b=640,persistKey:f="ll-widget",disablePersistence:m=!1,teamMembers:k,currentTeamMemberId:E,onTeamMemberChange:j,idleLoopUrl:O,greeting:x,avatarImageUrl:A,agentName:P,branding:H={},allowCamera:Z=!0,allowScreenShare:D=!0,allowTyping:F=!0,showMinimize:S,showClose:K,chromeless:ge=!1,floatingChromeContainer:se=null,compactControls:Te=!1,transforming:Pe=!1,transformingLabel:Y="Transforming…",showOn:Ce,hideOn:ye,pathname:$,onNavigate:te,onScrollToSelector:W,getPageContext:ce,pageContextExtras:U,getRoutes:Ze,onScrollPage:Qe,onClick:ut,capabilities:et,onConnect:Le,onDisconnect:De,onTranscript:Se,onAgentState:$e,onConnectionStateChange:Ee,onAgentEvent:je,onAgentCommand:Re,onCollect:Ne,controlledSession:I,className:xt,style:Ae,zIndex:ze=2147483647}=n,ue=An($),tt=Tn(ue,Ce,ye);r.useEffect(()=>{Bn(),Un()},[ue]);const Ie=E!==void 0,[He,wt]=r.useState(()=>{var v;return E??((v=k==null?void 0:k[0])==null?void 0:v.id)}),xe=Ie?E:He,ne=r.useMemo(()=>(k==null?void 0:k.find(v=>v.id===xe))??null,[k,xe]),nt=(ne==null?void 0:ne.agentId)??o,ae=h==="EMBEDDED",oe=Nn(b),Oe=p??(oe?"minimized":"expanded"),[we,Fe]=Rn({value:g,defaultValue:Oe,onChange:R,persistKey:f,disablePersistence:ae||m}),it=r.useRef(!1);r.useEffect(()=>{if(it.current||g!==void 0||p!==void 0||ae||m)return;const v=En(`${f}:display-mode`);v&&v!=="expanded"||(oe&&we==="expanded"&&Fe("minimized"),it.current=!0)},[oe,we,p,g,ae,m,f,Fe]);const le=ae?"expanded":we,ve=ae?()=>{}:Fe,_t=S??!ae,Be=K??!ae,_e=wn(),re=_n(),de=kn(),Me=Cn(),fe=Ln(),[ke,We]=r.useState(!1),[qe,dt]=r.useState(!1),[Ue,y]=r.useState(!1),[G,Kn]=r.useState(!1),[kt,Jn]=r.useState(!1),ft=kr({baseUrl:s,config:u}),pt=r.useRef(ft);pt.current=ft;const Ct=r.useRef(te),Lt=r.useRef(W),St=r.useRef(Qe),Et=r.useRef(ut),Pt=r.useRef(ce),Dt=r.useRef(U),$t=r.useRef(Ze),jt=r.useRef(et),pe=r.useRef(null);Ct.current=te,Lt.current=W,St.current=Qe,Et.current=ut,Pt.current=ce,Dt.current=U,$t.current=Ze,jt.current=et;function he(v){const d=jt.current;return d?d.includes(v):!0}function me(v,d){console.warn(`[LiveLayer] Agent command "${v}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const ot=r.useCallback(v=>{var V,Q,be,at;const d=v;if(!(!d.type||typeof d.type!="string")){if(je==null||je({eventName:d.type,data:v}),d.type==="navigate"){if(!he("navigate")){me("navigate","navigate");return}const C=typeof d.href=="string"?d.href:null;if(!C){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(pt.current.playPageChange(),Ct.current){try{Ct.current(C)}catch(N){console.warn(`[LiveLayer] onNavigate threw for "${C}". Falling back. Error:`,N)}return}if(typeof document<"u"){const N=document.querySelector(`a[href="${C.replace(/"/g,'\\"')}"]`);if(N){N.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",C),window.dispatchEvent(new PopStateEvent("popstate"))}catch(N){console.warn(`[LiveLayer] history.pushState fallback failed for "${C}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,N)}return}if(d.type==="scroll_to"){if(!he("scroll")){me("scroll_to","scroll");return}const C=typeof d.selector=="string"?d.selector:null;if(!C)return;const N=d.behavior==="instant"?"instant":"smooth";if(Lt.current){try{Lt.current(C,N)}catch(z){console.warn("[LiveLayer] onScrollToSelector threw.",z)}return}if(typeof document<"u"){let z=null;try{z=document.querySelector(C)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${C}".`);return}if(!z){console.warn(`[LiveLayer] scroll_to: no element matched "${C}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}z.scrollIntoView({behavior:N,block:"start"})}return}if(d.type==="request_page_context"){if(!he("read_page")){me("request_page_context","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,N=(V=pe.current)==null?void 0:V.call(pe),z=q=>{const M=N,X=M==null?void 0:M.localParticipant;if(X!=null&&X.publishData)try{const ie=C?{...q,requestId:C}:q,Ye=new TextEncoder().encode(JSON.stringify(ie));X.publishData(Ye,{reliable:!0})}catch(ie){console.warn("[LiveLayer] publishData failed.",ie)}},T=Dt.current,B=Pt.current;try{if(B){const q=B(T);if(q instanceof Promise){z({type:"page_context_pending"}),q.then(M=>z({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),z({type:"page_context",context:It(T)})});return}z({type:"page_context",context:q});return}z({type:"page_context",context:It(T)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),z({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:T}})}return}if(d.type==="scroll_page"){if(!he("scroll")){me("scroll_page","scroll");return}const C=d.direction;if(C!=="up"&&C!=="down"&&C!=="top"&&C!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(C)}". Expected up | down | top | bottom.`);return}const N=d.behavior==="instant"?"instant":"smooth";if(St.current){try{St.current(C,N)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const z={behavior:N},T=ci(),B=M=>{T instanceof Window?T.scrollBy({top:M,...z}):T.scrollBy({top:M,...z})},q=M=>{T instanceof Window?T.scrollTo({top:M,...z}):T.scrollTo({top:M,...z})};C==="up"?B(-yn(T)):C==="down"?B(yn(T)):q(C==="top"?0:ui(T));return}if(d.type==="click"){if(!he("click")){me("click","click");return}const C=typeof d.selector=="string"?d.selector:null;if(!C){console.warn("[LiveLayer] click: missing selector.");return}if(Et.current){try{Et.current(C)}catch(z){console.warn("[LiveLayer] onClick threw.",z)}return}if(typeof document>"u")return;let N=null;try{N=document.querySelector(C)}catch{console.warn(`[LiveLayer] click: invalid selector "${C}".`);return}if(!N){console.warn(`[LiveLayer] click: no element matched "${C}". 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}(Q=N.click)==null||Q.call(N);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!he("fill_forms")){me(d.type,"fill_forms");return}if(typeof document>"u")return;d.type==="fill_form"&&pt.current.playConfirmation();const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn(`[LiveLayer] ${d.type}: missing formId.`);return}const N=gn(document,C);if(!N){console.warn(`[LiveLayer] ${d.type}: no <form> matched id="${C}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(N.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(d.type==="focus_field"){const T=typeof d.fieldName=="string"?d.fieldName:null;if(!T){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=mn(N,T);if(B.el===null){B.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${T}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}B.el.focus();return}const z=d.values&&typeof d.values=="object"?d.values:null;if(!z){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[T,B]of Object.entries(z)){if(typeof B!="string")continue;const q=mn(N,T);if(q.el===null){q.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${T}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{ii(q.el,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${T}".`,M)}}return}if(d.type==="submit_form"){if(!he("submit_forms")){me("submit_form","submit_forms");return}if(typeof document>"u")return;const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn("[LiveLayer] submit_form: missing formId.");return}pt.current.playConfirmation();const N=gn(document,C);if(!N){console.warn(`[LiveLayer] submit_form: no <form> matched id="${C}" (or matching name / data-ll-intent slug).`);return}if(N.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const z=typeof d.requestId=="string"?d.requestId:void 0,T=(be=pe.current)==null?void 0:be.call(pe),B=X=>{const ie=T,Ye=ie==null?void 0:ie.localParticipant;if(Ye!=null&&Ye.publishData)try{const cr=z?{...X,requestId:z}:X,ur=new TextEncoder().encode(JSON.stringify(cr));Ye.publishData(ur,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:C})};N.addEventListener("submit",M,{once:!0});try{typeof N.requestSubmit=="function"?N.requestSubmit():N.submit()}catch(X){console.warn("[LiveLayer] submit_form: requestSubmit threw.",X),N.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"exception"});return}setTimeout(()=>{q||(N.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!he("read_page")){me("request_routes","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,z=(at=pe.current)==null?void 0:at.call(pe),T=z==null?void 0:z.localParticipant;if(!(T!=null&&T.publishData))return;const B=M=>{try{const X=C?{type:"routes",routes:M,requestId:C}:{type:"routes",routes:M},ie=new TextEncoder().encode(JSON.stringify(X));T.publishData(ie,{reliable:!0})}catch(X){console.warn("[LiveLayer] request_routes: publishData failed.",X)}},q=$t.current;if(q){try{const M=q(),X=ie=>{if(!Array.isArray(ie)){B([]);return}B(ie.map(Wn).slice(0,200))};M instanceof Promise?M.then(X).catch(ie=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",ie),B(yt())}):X(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(yt())}return}try{B(yt())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}if(d.type==="task_field_updated"){if(!he("collect_data")){me("task_field_updated","collect_data");return}const C={phase:"field",fieldId:typeof d.fieldId=="string"?d.fieldId:"",fieldName:typeof d.fieldName=="string"?d.fieldName:typeof d.fieldId=="string"?d.fieldId:"",value:typeof d.value=="string"?d.value:"",kind:typeof d.kind=="string"?d.kind:"text",source:d.source==="slide"?"slide":d.source==="page"?"page":"agent",...typeof d.slideId=="string"?{slideId:d.slideId}:{},...typeof d.formId=="string"?{formId:d.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:C}))}catch{}return}if(d.type==="task_completed"){if(!he("collect_data")){me("task_completed","collect_data");return}const C=d.result;if(!C||typeof C!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:C}}))}catch{}try{Ne==null||Ne(C)}catch(N){console.warn("[LiveLayer] onCollect threw.",N)}return}di.has(d.type)||Re==null||Re(d)}},[Re,je,Ne]),J=xn({agentId:I?"__controlled__":nt,baseUrl:s,apiKey:l,sessionEndpoint:c,sessionBody:a,onDataMessage:I?void 0:ot});r.useEffect(()=>{if(I!=null&&I.subscribeToDataMessages)return I.subscribeToDataMessages(ot)},[I,ot]),pe.current=()=>{var v;return(v=J.getRoom)==null?void 0:v.call(J)},r.useEffect(()=>{var V;if(typeof window>"u")return;const v=((V=window.location)==null?void 0:V.hostname)||"";if(v==="localhost"||v==="127.0.0.1"||v==="0.0.0.0"||v.endsWith(".local")||v.endsWith(".test"))return window.__livelayerSimulateCommand=Q=>{try{ot(Q)}catch(be){console.warn("[LiveLayer] simulate-command threw:",be)}},()=>{delete window.__livelayerSimulateCommand}},[ot]);const L=r.useMemo(()=>I?{connectionState:I.connectionState,agentState:I.agentState,transcript:I.transcript,videoElement:I.videoElement,audioElement:I.audioElement,canResume:I.canResume,error:I.error,agentConfig:null,connect:async()=>{await I.onConnect()},disconnect:()=>I.onDisconnect(),getRoom:J.getRoom,isControlled:!0}:{connectionState:J.connectionState,agentState:J.agentState,transcript:J.transcript,videoElement:J.videoElement,audioElement:J.audioElement,canResume:J.canResume,error:J.error,agentConfig:J.agentConfig,connect:J.connect,disconnect:J.disconnect,getRoom:J.getRoom,isControlled:!1},[I,J]),zt=r.useRef(L);zt.current=L;const Ht=r.useRef(I);Ht.current=I,r.useImperativeHandle(i,()=>({sendData:async v=>{var be,at;const d=Ht.current;if(d!=null&&d.publishData){try{await d.publishData(v)}catch(C){console.warn("[AvatarWidget] sendData (controlled) failed:",C)}return}const V=(at=(be=zt.current)==null?void 0:be.getRoom)==null?void 0:at.call(be),Q=V==null?void 0:V.localParticipant;if(Q!=null&&Q.publishData)try{const C=new TextEncoder().encode(JSON.stringify(v));await Q.publishData(C,{reliable:!0})}catch(C){console.warn("[AvatarWidget] sendData failed:",C)}}}),[]);const Ot=r.useRef(null);r.useEffect(()=>{const v=L.videoElement,d=Ot.current;if(!(!v||!d))return d.appendChild(v),()=>{v.parentNode===d&&d.removeChild(v)}},[L.videoElement]),r.useEffect(()=>{const v=L.audioElement;if(!v)return;const d=document.createElement("div");d.className="ll-audio-sink",d.setAttribute("aria-hidden","true"),d.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",d.appendChild(v),document.body.appendChild(d),_e.attach(v);const V=v.play();return V&&typeof V.catch=="function"&&V.catch(Q=>{(Q==null?void 0:Q.name)==="NotAllowedError"&&We(!0)}),()=>{_e.detach(),v.parentNode===d&&d.removeChild(v),d.parentNode===document.body&&document.body.removeChild(d)}},[L.audioElement]),r.useEffect(()=>{if(L.isControlled||L.connectionState!=="connected")return;const v=L.getRoom();if(v)return re.setupMic(v).then(()=>{const d=re.getMicStream();d&&_e.attachStream(d,"mic")}).catch(()=>{}),()=>{_e.detachSlot("mic"),re.teardownMic()}},[L.isControlled,L.connectionState]),r.useEffect(()=>{var d;if(L.connectionState!=="connected")return;const v=L.isControlled?(d=I==null?void 0:I.getRoom)==null?void 0:d.call(I):L.getRoom();if(v)return de.attachRoom(v),Me.attachRoom(v),L.isControlled&&re.attachRoom(v),fe.refresh(),()=>{de.teardown(),Me.teardown()}},[L.isControlled,L.connectionState,I]),r.useEffect(()=>{const v=L.audioElement;v&&(v.muted=kt)},[L.audioElement,kt]);const Xn=r.useCallback(v=>{const d={type:"user_message",text:v};if(I!=null&&I.publishData){try{I.publishData(d)}catch{}return}const V=L.getRoom();if(V)try{const Q=new TextEncoder().encode(JSON.stringify(d));V.localParticipant.publishData(Q,{reliable:!0})}catch{}},[L,I]),Zn=r.useCallback(()=>{Jn(v=>!v)},[]);r.useEffect(()=>{Ee==null||Ee(L.connectionState),L.connectionState==="connected"?Le==null||Le():L.connectionState==="disconnected"&&(De==null||De())},[L.connectionState,Le,De,Ee]),r.useEffect(()=>{Se==null||Se(L.transcript)},[L.transcript,Se]),r.useEffect(()=>{$e==null||$e(L.agentState)},[L.agentState,$e]),r.useEffect(()=>{ft.setThinking(L.agentState==="thinking")},[L.agentState,ft]);const Ft=r.useRef(!1);r.useEffect(()=>{!w||Ft.current||tt&&L.connectionState==="idle"&&(Ft.current=!0,L.connect())},[w,L.connectionState,L,tt]);const Qn=r.useCallback(v=>{const d=k==null?void 0:k.find(V=>V.id===v);d&&(y(!1),v!==xe&&(dt(!0),L.disconnect(),Ie||wt(v),j==null||j(d)))},[k,xe,L,Ie,j]);r.useEffect(()=>{qe&&L.connectionState==="connected"&&dt(!1)},[L.connectionState,qe]),r.useEffect(()=>{if(!Ue)return;const v=d=>{d.key==="Escape"&&y(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[Ue]);const er=!!A||!!(ne!=null&&ne.avatarImageUrl)||L.isControlled,st=Sn(nt,s,er);et===void 0&&((Ut=st.info)!=null&&Ut.capabilities)&&(jt.current=st.info.capabilities);const ht=(ne==null?void 0:ne.name)??P??((Vt=L.agentConfig)==null?void 0:Vt.name)??((Yt=st.info)==null?void 0:Yt.name)??"Live Layer",Rt=(ne==null?void 0:ne.avatarImageUrl)??A??((Gt=L.agentConfig)==null?void 0:Gt.avatarImageUrl)??((Kt=st.info)==null?void 0:Kt.avatarImageUrl)??null,tr=O??((Jt=L.agentConfig)==null?void 0:Jt.idleLoopUrl)??((Xt=st.info)==null?void 0:Xt.idleLoopUrl)??null,nr=x??null,rr=r.useCallback(()=>ve("expanded"),[ve]),ir=r.useCallback(()=>ve("minimized"),[ve]),Bt=r.useCallback(()=>{L.disconnect(),ve("hidden")},[L,ve]),or=r.useCallback(()=>{const v=L.audioElement;v&&v.play().then(()=>We(!1)).catch(()=>{})},[L.audioElement]),sr=r.useCallback(()=>{We(!1),L.connect()},[L]),Ve={...Ae,...ae?{}:{zIndex:ze}};H.primaryColor&&(Ve["--ll-color-primary"]=H.primaryColor),H.accentColor&&(Ve["--ll-color-accent"]=H.accentColor),H.backgroundColor&&(Ve["--ll-color-bg"]=H.backgroundColor),H.textColor&&(Ve["--ll-color-fg"]=H.textColor);const ar=["ll-widget",`ll-widget--${le}`,`ll-widget--${oe?"mobile":"desktop"}`,xt].filter(Boolean).join(" ");if(!tt)return null;const lr=t.jsx("div",{className:ar,style:Ve,"data-display-mode":le,"data-position":_,"data-experience-mode":h==="EMBEDDED"?"embedded":"widget",children:le==="expanded"&&t.jsx(Or,{position:_,isMobile:oe,agentName:ht,avatarImageUrl:Rt,idleLoopUrl:tr,greeting:nr,branding:H,teamMembers:k,currentTeamMemberId:xe,isSwitchingTeamMember:qe,teamSwitcherOpen:Ue,onToggleTeamSwitcher:()=>y(v=>!v),onSelectTeamMember:Qn,connectionState:L.connectionState,agentState:L.agentState,transcript:L.transcript,isMuted:re.isMuted,micDevices:fe.mics,activeMicId:re.activeDeviceId,isCameraEnabled:de.isEnabled,cameraPreviewEl:de.previewEl,cameraDevices:fe.cameras,activeCameraId:de.activeDeviceId,isScreenShareEnabled:Me.isEnabled,screenPreviewEl:Me.previewEl,isSpeakerMuted:kt,allowCamera:Z,allowScreenShare:D,allowTyping:F,showMinimize:_t,showClose:Be,chromeless:ge,compactControls:Te,transforming:Pe,transformingLabel:Y,languageMenuOpen:G,onToggleLanguageMenu:()=>Kn(v=>!v),needsUserGesture:ke,canResume:L.canResume,micError:re.micError,error:L.error,avatarVideoContainerRef:Ot,agentVideoEl:L.videoElement,onConnect:()=>void L.connect(),onDisconnect:()=>L.disconnect(),onRetry:sr,onResumeAudio:or,onToggleMute:re.toggleMute,onSwitchMicDevice:v=>void re.switchDevice(v),onToggleCamera:()=>void de.toggle(),onSwitchCameraDevice:v=>void de.switchDevice(v),onToggleScreenShare:()=>void Me.toggle(),onToggleSpeaker:Zn,onSendMessage:Xn,onMinimize:ir,onClose:Bt,onClearMicError:re.clearError})}),Wt=!ae&&(le==="hidden"||le==="minimized")?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${le}`,`ll-widget--${oe?"mobile":"desktop"}`].join(" "),style:Ve,"data-display-mode":le,"data-position":_,children:[le==="hidden"&&t.jsx(Rr,{position:_,isMobile:oe,isSpeaking:L.agentState==="speaking",onExpand:()=>ve("expanded"),label:`Open ${ht} widget`,avatarImageUrl:Rt,agentName:ht,containerEl:se}),le==="minimized"&&t.jsx(Ar,{position:_,isMobile:oe,agentName:ht,avatarImageUrl:Rt,agentState:L.agentState,isMuted:re.isMuted,audioLevel:_e,onExpand:rr,onToggleMute:re.toggleMute,onClose:Bt})]}):null,qt=se??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[lr,Wt&&qt&&Mt.createPortal(Wt,qt)]})});Vn.displayName="AvatarWidgetInner";const Yn=r.forwardRef(function(n,i){return t.jsx(bn,{children:t.jsx(Vn,{...n,ref:i})})});Yn.displayName="AvatarWidget";const fi=({agentId:e,baseUrl:n,apiKey:i,mode:o,onAgentEvent:l,className:s,style:c})=>{const a=r.useRef(null),u=r.useRef(null),h=r.useRef(l);h.current=l;const w=r.useCallback(g=>{var R;const p=g.detail;(R=h.current)==null||R.call(h,p)},[]);return r.useEffect(()=>{const g=a.current;if(!g)return;const p=document.createElement("livelayer-widget");return p.setAttribute("agent-id",e),n&&p.setAttribute("base-url",n),i&&p.setAttribute("api-key",i),o&&p.setAttribute("mode",o),p.addEventListener("agent-event",w),g.appendChild(p),u.current=p,()=>{p.removeEventListener("agent-event",w),g.removeChild(p),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:a,className:s,style:c})},pi=r.forwardRef(function({id:n,intent:i,as:o="div",className:l,style:s,children:c},a){return r.createElement(o,{ref:a,"data-ll-region":n,"data-ll-intent":i,className:l,style:s},c)});function hi(e={}){const{onFieldUpdate:n,onComplete:i,source:o="all"}=e,[l,s]=r.useState({}),[c,a]=r.useState(!1),[u,h]=r.useState(null),w=r.useRef(n),g=r.useRef(i),p=r.useRef(o);r.useEffect(()=>{w.current=n,g.current=i,p.current=o},[n,i,o]);const R=r.useCallback(()=>{s({}),a(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=b=>{var m,k;const f=b.detail;if(f){if(f.phase==="field"){if(p.current!=="all"&&f.source!==p.current)return;a(!0),s(E=>E[f.fieldName]===f.value?E:{...E,[f.fieldName]:f.value});try{(m=w.current)==null||m.call(w,f)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(f.phase==="complete"){const E=f.result;if(p.current!=="all"&&E.source!==p.current)return;h(E),a(!1);try{(k=g.current)==null||k.call(g,E)}catch(j){console.warn("[LiveLayer] useCollect onComplete threw.",j)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:l,isCollecting:c,lastResult:u,reset:R}}let vn=1;function mi({onMount:e,defaultOpen:n=!1,storageKey:i="ll-debug-open"}){const[o,l]=r.useState(n),[s,c]=r.useState([]),[a,u]=r.useState(""),[h,w]=r.useState(!1),g=r.useRef(new Set),p=r.useRef([]),R=r.useRef(h);R.current=h,r.useEffect(()=>{try{const f=localStorage.getItem(i);f==="1"&&l(!0),f==="0"&&l(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const f=m=>{(m.metaKey||m.ctrlKey)&&m.shiftKey&&m.key.toLowerCase()==="l"&&(m.preventDefault(),l(k=>!k))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),r.useEffect(()=>{const f=setInterval(()=>{if(p.current.length===0||R.current)return;const m=p.current.splice(0,p.current.length);c(k=>[...m.reverse(),...k].slice(0,200))},100);return()=>clearInterval(f)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(f=>{p.current.push({id:vn++,ts:Date.now(),kind:"event",type:f.eventName,data:f.data})}))},[e]),r.useEffect(()=>{const f=console.warn,m=console.log,k=(E,j)=>function(...O){try{const x=typeof O[0]=="string"?O[0]:"";x.startsWith("[LiveLayer]")&&p.current.push({id:vn++,ts:Date.now(),kind:E,type:x.slice(0,120),data:{args:O.slice(1).map(A=>yi(A))}})}catch{}return j.apply(this,O)};return console.warn=k("warn",f),console.log=k("log",m),()=>{console.warn=f,console.log=m}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>l(!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 b=s.filter(f=>{if(!a)return!0;const m=a.toLowerCase();return f.type.toLowerCase().includes(m)||JSON.stringify(f.data||{}).toLowerCase().includes(m)});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:[s.length," event",s.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>w(f=>!f),style:Nt(h?"#f59e0b":"transparent"),title:"Pause / resume capture",children:h?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{c([]),p.current=[]},style:Nt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>l(!1),style:Nt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:a,onChange:f=>u(f.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:b.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
- })`})]}):v.map(f=>t.jsx(gi,{entry:f,expanded:g.current.has(f.id),onToggle:()=>{g.current.has(f.id)?g.current.delete(f.id):g.current.add(f.id),c(m=>[...m])}},f.id))})]})}function gi({entry:e,expanded:n,onToggle:i}){const o=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",l=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:i,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:l}),t.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),n&&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 Nt(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 yi(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Gn(e){const n=JSON.stringify(e);r.useEffect(()=>Xe.registerFields(e),[n])}function vi({fields:e,children:n}){return Gn(e),t.jsx(t.Fragment,{children:n})}function bi(){const[e,n]=r.useState([]),i=r.useCallback(l=>{n(s=>{const c=s.findIndex(a=>a.id===l.id);if(c>=0){const a=s.slice();return a[c]=l,a}return[...s,l]})},[]),o=r.useCallback(()=>n([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>Xe.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>Xe.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>Xe.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>Xe.setFieldValue});exports.AvatarWidget=Yn;exports.ErrorBoundary=bn;exports.FieldProvider=vi;exports.LiveLayerDebugPanel=mi;exports.LiveLayerRegion=pi;exports.LiveLayerWidget=fi;exports.clearPageContextCache=Bn;exports.clearRoutesCache=Un;exports.extractPageContext=Fn;exports.extractRoutes=qn;exports.getCachedPageContext=It;exports.getCachedRoutes=yt;exports.matchesPattern=In;exports.normalizeRouteInput=Wn;exports.shouldRenderAtPath=Mn;exports.useAgentInfo=Sn;exports.useAudioLevel=wn;exports.useCameraState=kn;exports.useCollect=hi;exports.useDisplayMode=jn;exports.useDisplayModePersistence=Rn;exports.useIsMobile=Nn;exports.useLiveKitSession=xn;exports.useMediaDevices=Ln;exports.useMicrophoneState=_n;exports.usePathname=An;exports.useRegisterFields=Gn;exports.useRouteMatch=Tn;exports.useScreenShareState=Cn;exports.useTranscript=bi;
5
+ })`})]}):b.map(f=>t.jsx(gi,{entry:f,expanded:g.current.has(f.id),onToggle:()=>{g.current.has(f.id)?g.current.delete(f.id):g.current.add(f.id),c(m=>[...m])}},f.id))})]})}function gi({entry:e,expanded:n,onToggle:i}){const o=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",l=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:i,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:l}),t.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),n&&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 Nt(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 yi(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Gn(e){const n=JSON.stringify(e);r.useEffect(()=>Xe.registerFields(e),[n])}function vi({fields:e,children:n}){return Gn(e),t.jsx(t.Fragment,{children:n})}function bi(){const[e,n]=r.useState([]),i=r.useCallback(l=>{n(s=>{const c=s.findIndex(a=>a.id===l.id);if(c>=0){const a=s.slice();return a[c]=l,a}return[...s,l]})},[]),o=r.useCallback(()=>n([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>Xe.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>Xe.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>Xe.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>Xe.setFieldValue});exports.AvatarWidget=Yn;exports.ErrorBoundary=bn;exports.FieldProvider=vi;exports.LiveLayerDebugPanel=mi;exports.LiveLayerRegion=pi;exports.LiveLayerWidget=fi;exports.clearPageContextCache=Bn;exports.clearRoutesCache=Un;exports.extractPageContext=Fn;exports.extractRoutes=qn;exports.getCachedPageContext=It;exports.getCachedRoutes=yt;exports.matchesPattern=In;exports.normalizeRouteInput=Wn;exports.shouldRenderAtPath=Mn;exports.useAgentInfo=Sn;exports.useAudioLevel=wn;exports.useCameraState=kn;exports.useCollect=hi;exports.useDisplayMode=jn;exports.useDisplayModePersistence=Rn;exports.useIsMobile=Nn;exports.useLiveKitSession=xn;exports.useMediaDevices=Ln;exports.useMicrophoneState=_n;exports.usePathname=An;exports.useRegisterFields=Gn;exports.useRouteMatch=Tn;exports.useScreenShareState=Cn;exports.useTranscript=bi;
package/dist/index.mjs CHANGED
@@ -36,7 +36,7 @@ class rr extends Jn {
36
36
  }
37
37
  }
38
38
  function ir(e) {
39
- const [t, r] = N("idle"), [i, a] = N("idle"), [o, s] = N([]), [l, c] = N(null), [p, w] = N(null), [m, f] = N(null), [T, _] = N(!1), [y, u] = N(null), h = M(null), L = M(e.onDataMessage);
39
+ const [t, r] = N("idle"), [i, a] = N("idle"), [o, s] = N([]), [l, c] = N(null), [p, w] = N(null), [m, f] = N(null), [T, _] = N(!1), [v, u] = N(null), h = M(null), L = M(e.onDataMessage);
40
40
  L.current = e.onDataMessage, R(() => {
41
41
  const b = {
42
42
  onConnectionStateChange: (O) => {
@@ -98,7 +98,7 @@ function ir(e) {
98
98
  videoElement: p,
99
99
  audioElement: m,
100
100
  canResume: T,
101
- error: y,
101
+ error: v,
102
102
  connect: A,
103
103
  disconnect: I,
104
104
  getRoom: U,
@@ -112,17 +112,17 @@ function or() {
112
112
  r.current = null;
113
113
  return;
114
114
  }
115
- let y = 0;
115
+ let v = 0;
116
116
  for (const { analyser: u, buffer: h } of _.values()) {
117
117
  u.getByteFrequencyData(h);
118
118
  let L = 0;
119
119
  for (let I = 0; I < h.length; I++) L += h[I];
120
120
  const A = L / h.length / 255;
121
- A > y && (y = A);
121
+ A > v && (v = A);
122
122
  }
123
123
  for (const u of i.current)
124
124
  try {
125
- u(y);
125
+ u(v);
126
126
  } catch (h) {
127
127
  console.error("[useAudioLevel] subscriber threw:", h);
128
128
  }
@@ -130,24 +130,24 @@ function or() {
130
130
  }, []), o = E(() => e.current ? e.current : typeof window > "u" || typeof AudioContext > "u" ? null : (e.current = new AudioContext(), e.current), []), s = E(() => {
131
131
  r.current === null && t.current.size > 0 && (r.current = requestAnimationFrame(a));
132
132
  }, [a]), l = E((_) => {
133
- const y = t.current.get(_);
134
- if (y) {
133
+ const v = t.current.get(_);
134
+ if (v) {
135
135
  try {
136
- y.node.disconnect();
136
+ v.node.disconnect();
137
137
  } catch {
138
138
  }
139
139
  try {
140
- y.analyser.disconnect();
140
+ v.analyser.disconnect();
141
141
  } catch {
142
142
  }
143
143
  t.current.delete(_);
144
144
  }
145
145
  }, []), c = E(
146
- (_, y) => {
146
+ (_, v) => {
147
147
  const u = o();
148
148
  if (!u) return;
149
149
  l(_);
150
- const h = y(u);
150
+ const h = v(u);
151
151
  if (!h) return;
152
152
  const L = u.createAnalyser();
153
153
  L.fftSize = 64;
@@ -165,14 +165,14 @@ function or() {
165
165
  },
166
166
  [l, o, s]
167
167
  ), p = E(
168
- (_, y = "agent") => {
169
- c(y, (u) => {
168
+ (_, v = "agent") => {
169
+ c(v, (u) => {
170
170
  try {
171
171
  return u.createMediaElementSource(_);
172
172
  } catch (h) {
173
173
  return console.warn(
174
174
  "[useAudioLevel] createMediaElementSource failed for slot",
175
- y,
175
+ v,
176
176
  h
177
177
  ), null;
178
178
  }
@@ -180,14 +180,14 @@ function or() {
180
180
  },
181
181
  [c]
182
182
  ), w = E(
183
- (_, y = "mic") => {
184
- c(y, (u) => {
183
+ (_, v = "mic") => {
184
+ c(v, (u) => {
185
185
  try {
186
186
  return u.createMediaStreamSource(_);
187
187
  } catch (h) {
188
188
  return console.warn(
189
189
  "[useAudioLevel] createMediaStreamSource failed for slot",
190
- y,
190
+ v,
191
191
  h
192
192
  ), null;
193
193
  }
@@ -222,7 +222,7 @@ function lr(e) {
222
222
  return t ? new MediaStream([t]) : null;
223
223
  }
224
224
  function ar() {
225
- const [e, t] = N(!1), [r, i] = N(""), [a, o] = N(null), s = M(null), l = M(null), c = E(async (y) => {
225
+ const [e, t] = N(!1), [r, i] = N(""), [a, o] = N(null), s = M(null), l = M(null), c = E(async (v) => {
226
226
  var u, h;
227
227
  if (s.current && l.current) {
228
228
  try {
@@ -231,45 +231,45 @@ function ar() {
231
231
  }
232
232
  s.current.stop(), s.current = null;
233
233
  }
234
- l.current = y, o(null);
234
+ l.current = v, o(null);
235
235
  try {
236
236
  const L = await tr({
237
237
  echoCancellation: !0,
238
238
  noiseSuppression: !0
239
239
  });
240
- await y.localParticipant.publishTrack(L), s.current = L, t(L.isMuted);
240
+ await v.localParticipant.publishTrack(L), s.current = L, t(L.isMuted);
241
241
  const A = (h = (u = L.mediaStreamTrack) == null ? void 0 : u.getSettings) == null ? void 0 : h.call(u);
242
242
  A != null && A.deviceId && i(A.deviceId);
243
243
  } catch (L) {
244
244
  const A = L instanceof Error && L.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
245
245
  throw o(A), L;
246
246
  }
247
- }, []), p = E((y) => {
248
- l.current = y;
249
- }, []), w = E(async (y) => {
247
+ }, []), p = E((v) => {
248
+ l.current = v;
249
+ }, []), w = E(async (v) => {
250
250
  const u = l.current;
251
251
  if (u)
252
252
  try {
253
- await u.switchActiveDevice("audioinput", y), i(y);
253
+ await u.switchActiveDevice("audioinput", v), i(v);
254
254
  } catch (h) {
255
255
  console.warn("[useMicrophoneState] switchDevice failed:", h);
256
256
  }
257
257
  }, []), m = E(async () => {
258
- const y = l.current, u = !e;
259
- if (t(u), !!y)
258
+ const v = l.current, u = !e;
259
+ if (t(u), !!v)
260
260
  try {
261
- await y.localParticipant.setMicrophoneEnabled(!u);
261
+ await v.localParticipant.setMicrophoneEnabled(!u);
262
262
  } catch (h) {
263
263
  console.warn("[useMicrophoneState] setMicrophoneEnabled failed:", h), t(!u);
264
264
  }
265
265
  }, [e]), f = E(() => {
266
- const y = s.current, u = l.current;
267
- if (y && u) {
266
+ const v = s.current, u = l.current;
267
+ if (v && u) {
268
268
  try {
269
- u.localParticipant.unpublishTrack(y);
269
+ u.localParticipant.unpublishTrack(v);
270
270
  } catch {
271
271
  }
272
- y.stop();
272
+ v.stop();
273
273
  }
274
274
  s.current = null, l.current = null, t(!1), i("");
275
275
  }, []), T = E(() => o(null), []), _ = E(() => lr(s.current), []);
@@ -332,7 +332,7 @@ function cr() {
332
332
  e ? m() : await f(s || void 0);
333
333
  }, [e, s, m, f]), _ = E(async (h) => {
334
334
  m(), await f(h);
335
- }, [m, f]), y = E(() => {
335
+ }, [m, f]), v = E(() => {
336
336
  m(), c.current = null, i(null), l("");
337
337
  }, [m]), u = E(() => i(null), []);
338
338
  return R(() => () => {
@@ -345,7 +345,7 @@ function cr() {
345
345
  toggle: T,
346
346
  switchDevice: _,
347
347
  attachRoom: w,
348
- teardown: y,
348
+ teardown: v,
349
349
  clearError: u
350
350
  };
351
351
  }
@@ -368,9 +368,9 @@ function dr() {
368
368
  await f.localParticipant.setScreenShareEnabled(!0);
369
369
  let T = 0;
370
370
  const _ = () => {
371
- const y = f.localParticipant.getTrackPublication(Cn.Source.ScreenShare);
372
- if (y != null && y.track) {
373
- const u = y.track.attach();
371
+ const v = f.localParticipant.getTrackPublication(Cn.Source.ScreenShare);
372
+ if (v != null && v.track) {
373
+ const u = v.track.attach();
374
374
  o(u), t(!0);
375
375
  try {
376
376
  f.localParticipant.publishData(
@@ -756,7 +756,7 @@ const $r = ({
756
756
  agentName: s,
757
757
  containerEl: l
758
758
  }) => {
759
- const c = Tr(e), p = c === "right" ? "left" : "right", w = t ? 80 : 72, m = !!o, f = !!l, [T, _] = N(null), [y, u] = N(!1), h = M(null), L = M(!1), A = E(
759
+ const c = Tr(e), p = c === "right" ? "left" : "right", w = t ? 80 : 72, m = !!o, f = !!l, [T, _] = N(null), [v, u] = N(!1), h = M(null), L = M(!1), A = E(
760
760
  (B) => {
761
761
  if (typeof window > "u") return B;
762
762
  const j = w / 2, S = dn + j, Z = window.innerHeight - dn - j;
@@ -835,7 +835,7 @@ const $r = ({
835
835
  `ll-hidden--${c}`,
836
836
  t ? "ll-hidden--mobile" : "ll-hidden--desktop",
837
837
  r ? "ll-hidden--speaking" : null,
838
- y ? "is-dragging" : null,
838
+ v ? "is-dragging" : null,
839
839
  m ? "ll-hidden--with-avatar" : null,
840
840
  f ? "ll-hidden--scoped" : null
841
841
  ].filter(Boolean).join(" "), ne = T === null ? void 0 : { top: `${T - w / 2}px`, transform: "none" };
@@ -1194,7 +1194,7 @@ const Wr = 8, fn = 8, qr = ({
1194
1194
  onToggleTyping: f,
1195
1195
  onDisconnect: T
1196
1196
  }) => {
1197
- const [_, y] = N(!1), u = M(null);
1197
+ const [_, v] = N(!1), u = M(null);
1198
1198
  return /* @__PURE__ */ x(He, { children: [
1199
1199
  /* @__PURE__ */ x(
1200
1200
  "div",
@@ -1219,7 +1219,7 @@ const Wr = 8, fn = 8, qr = ({
1219
1219
  ref: u,
1220
1220
  type: "button",
1221
1221
  className: `ll-tool ${_ ? "is-on" : ""}`,
1222
- onClick: () => y((h) => !h),
1222
+ onClick: () => v((h) => !h),
1223
1223
  "aria-label": "More controls",
1224
1224
  "aria-haspopup": "menu",
1225
1225
  "aria-expanded": _,
@@ -1243,7 +1243,7 @@ const Wr = 8, fn = 8, qr = ({
1243
1243
  qr,
1244
1244
  {
1245
1245
  open: _,
1246
- onClose: () => y(!1),
1246
+ onClose: () => v(!1),
1247
1247
  anchorRef: u,
1248
1248
  children: [
1249
1249
  a && /* @__PURE__ */ x(
@@ -1252,7 +1252,7 @@ const Wr = 8, fn = 8, qr = ({
1252
1252
  type: "button",
1253
1253
  className: `ll-overflow-popover__item ${r ? "is-on" : ""}`,
1254
1254
  onClick: () => {
1255
- i(), y(!1);
1255
+ i(), v(!1);
1256
1256
  },
1257
1257
  children: [
1258
1258
  /* @__PURE__ */ n(An, {}),
@@ -1266,7 +1266,7 @@ const Wr = 8, fn = 8, qr = ({
1266
1266
  type: "button",
1267
1267
  className: `ll-overflow-popover__item ${o ? "is-on" : ""}`,
1268
1268
  onClick: () => {
1269
- s(), y(!1);
1269
+ s(), v(!1);
1270
1270
  },
1271
1271
  children: [
1272
1272
  /* @__PURE__ */ n(Nn, {}),
@@ -1280,7 +1280,7 @@ const Wr = 8, fn = 8, qr = ({
1280
1280
  type: "button",
1281
1281
  className: `ll-overflow-popover__item ${c ? "is-on" : ""}`,
1282
1282
  onClick: () => {
1283
- p(), y(!1);
1283
+ p(), v(!1);
1284
1284
  },
1285
1285
  children: [
1286
1286
  /* @__PURE__ */ n(Mn, { muted: c }),
@@ -1294,7 +1294,7 @@ const Wr = 8, fn = 8, qr = ({
1294
1294
  type: "button",
1295
1295
  className: `ll-overflow-popover__item ${m ? "is-on" : ""}`,
1296
1296
  onClick: () => {
1297
- f(), y(!1);
1297
+ f(), v(!1);
1298
1298
  },
1299
1299
  children: [
1300
1300
  /* @__PURE__ */ n(Vr, {}),
@@ -1370,7 +1370,7 @@ const Yr = ({
1370
1370
  onSelectTeamMember: f,
1371
1371
  languageMenuOpen: T,
1372
1372
  onToggleLanguageMenu: _,
1373
- connectionState: y,
1373
+ connectionState: v,
1374
1374
  agentState: u,
1375
1375
  transcript: h,
1376
1376
  canResume: L,
@@ -1414,7 +1414,7 @@ const Yr = ({
1414
1414
  onClearMicError: Lt
1415
1415
  }) => {
1416
1416
  var Je;
1417
- const Pe = ((l == null ? void 0 : l.length) ?? 0) > 1, qe = y === "connecting" || y === "connected", he = y === "connected", lt = y === "idle" || y === "disconnected" || y === "error", [$e, Ue] = N(!1);
1417
+ const Pe = ((l == null ? void 0 : l.length) ?? 0) > 1, qe = v === "connecting" || v === "connected", he = v === "connected", lt = v === "idle" || v === "disconnected" || v === "error", [$e, Ue] = N(!1);
1418
1418
  R(() => {
1419
1419
  if (!K) {
1420
1420
  Ue(!1);
@@ -1440,7 +1440,7 @@ const Yr = ({
1440
1440
  const g = setTimeout(() => ke(!0), 8e3);
1441
1441
  return () => clearTimeout(g);
1442
1442
  }, [he, $e]);
1443
- const le = y === "connecting" || he && !!i && !$e && !kt, at = M(null), ue = M(null);
1443
+ const le = v === "connecting" || he && !!i && !$e && !kt, at = M(null), ue = M(null);
1444
1444
  R(() => {
1445
1445
  const g = at.current;
1446
1446
  g && (g.innerHTML = "", ne && (ne.style.width = "100%", ne.style.height = "100%", ne.style.objectFit = "cover", ne.style.transform = "scaleX(-1)", g.appendChild(ne)));
@@ -1713,7 +1713,7 @@ const Yr = ({
1713
1713
  ] })
1714
1714
  ),
1715
1715
  lt && /* @__PURE__ */ (() => {
1716
- const g = L ? "Resume session" : y === "disconnected" ? "Reconnect to agent" : "Start video call";
1716
+ const g = L ? "Resume session" : v === "disconnected" ? "Reconnect to agent" : "Start video call";
1717
1717
  return /* @__PURE__ */ x(He, { children: [
1718
1718
  !I && /* @__PURE__ */ x(
1719
1719
  "button",
@@ -1940,7 +1940,7 @@ const Yr = ({
1940
1940
  ] })
1941
1941
  ] }) : null,
1942
1942
  (() => {
1943
- if (b && y !== "error")
1943
+ if (b && v !== "error")
1944
1944
  return /* @__PURE__ */ x("div", { className: "ll-expanded__banner", role: "alert", children: [
1945
1945
  /* @__PURE__ */ n("span", { children: b }),
1946
1946
  /* @__PURE__ */ n(
@@ -1954,7 +1954,7 @@ const Yr = ({
1954
1954
  }
1955
1955
  )
1956
1956
  ] });
1957
- if (!I || y !== "error") return null;
1957
+ if (!I || v !== "error") return null;
1958
1958
  let g = "Failed to connect", Q = "Try again";
1959
1959
  return I === "MIC_PERMISSION_DENIED" ? g = "Microphone blocked. Allow access to talk." : I === "MIC_NOT_FOUND" ? g = "No microphone found. Plug one in + retry." : I === "MIC_UNAVAILABLE" ? g = "Mic unavailable. Check other apps using it." : I === "AGENT_TIMEOUT" ? g = "Agent didn't pick up. Try again." : I === "CONNECT_FAILED" ? g = "Connection failed. Check your network." : I.length < 80 && (g = I), /* @__PURE__ */ x("div", { className: "ll-expanded__banner ll-expanded__banner--error", role: "alert", children: [
1960
1960
  /* @__PURE__ */ n("span", { children: g }),
@@ -2251,16 +2251,16 @@ function oi(e, t = {}) {
2251
2251
  const P = b.getAttribute("href") || "", O = (b.textContent || "").trim();
2252
2252
  !P || !O || T.push({ href: P, text: ie(O, 100) });
2253
2253
  }
2254
- const y = [], u = Array.from(
2254
+ const v = [], u = Array.from(
2255
2255
  r.querySelectorAll(
2256
2256
  "input, textarea, select"
2257
2257
  )
2258
2258
  );
2259
2259
  for (const b of u) {
2260
- if (y.length >= Xr) break;
2260
+ if (v.length >= Xr) break;
2261
2261
  if (pt(b) || !Pt(b) || !ht(b)) continue;
2262
2262
  const P = yn(b), O = b instanceof HTMLInputElement ? b.type : b.tagName.toLowerCase();
2263
- P && y.push({ label: ie(P, 100), type: O });
2263
+ P && v.push({ label: ie(P, 100), type: O });
2264
2264
  }
2265
2265
  const h = Array.from(r.querySelectorAll("form")), L = [];
2266
2266
  let A = 0;
@@ -2337,7 +2337,7 @@ function oi(e, t = {}) {
2337
2337
  regions: l,
2338
2338
  visibleText: f,
2339
2339
  visibleLinks: T,
2340
- visibleFields: y,
2340
+ visibleFields: v,
2341
2341
  forms: L,
2342
2342
  extras: e
2343
2343
  };
@@ -2598,7 +2598,7 @@ const Li = /* @__PURE__ */ new Set([
2598
2598
  defaultDisplayMode: f,
2599
2599
  onDisplayModeChange: T,
2600
2600
  position: _ = "bottom-right",
2601
- mobileBreakpoint: y = 640,
2601
+ mobileBreakpoint: v = 640,
2602
2602
  persistKey: u = "ll-widget",
2603
2603
  disablePersistence: h = !1,
2604
2604
  teamMembers: L,
@@ -2647,12 +2647,12 @@ const Li = /* @__PURE__ */ new Set([
2647
2647
  li(), fi();
2648
2648
  }, [he]);
2649
2649
  const $e = A !== void 0, [Ue, kt] = N(() => {
2650
- var v;
2651
- return A ?? ((v = L == null ? void 0 : L[0]) == null ? void 0 : v.id);
2650
+ var y;
2651
+ return A ?? ((y = L == null ? void 0 : L[0]) == null ? void 0 : y.id);
2652
2652
  }), ke = $e ? A : Ue, le = nt(
2653
- () => (L == null ? void 0 : L.find((v) => v.id === ke)) ?? null,
2653
+ () => (L == null ? void 0 : L.find((y) => y.id === ke)) ?? null,
2654
2654
  [L, ke]
2655
- ), at = (le == null ? void 0 : le.agentId) ?? i, ue = p === "EMBEDDED", ce = br(y), je = f ?? (ce ? "minimized" : "expanded"), [Ce, Ve] = yr({
2655
+ ), at = (le == null ? void 0 : le.agentId) ?? i, ue = p === "EMBEDDED", ce = br(v), je = f ?? (ce ? "minimized" : "expanded"), [Ce, Ve] = yr({
2656
2656
  value: m,
2657
2657
  defaultValue: je,
2658
2658
  onChange: T,
@@ -2660,7 +2660,9 @@ const Li = /* @__PURE__ */ new Set([
2660
2660
  disablePersistence: ue || h
2661
2661
  }), ct = M(!1);
2662
2662
  R(() => {
2663
- ct.current || m !== void 0 || f !== void 0 || ue || h || En(`${u}:display-mode`) || (ce && Ce === "expanded" && Ve("minimized"), ct.current = !0);
2663
+ if (ct.current || m !== void 0 || f !== void 0 || ue || h) return;
2664
+ const y = En(`${u}:display-mode`);
2665
+ y && y !== "expanded" || (ce && Ce === "expanded" && Ve("minimized"), ct.current = !0);
2664
2666
  }, [
2665
2667
  ce,
2666
2668
  Ce,
@@ -2676,21 +2678,21 @@ const Li = /* @__PURE__ */ new Set([
2676
2678
  vt.current = yt;
2677
2679
  const St = M(oe), Nt = M(Y), At = M(it), It = M(mt), Ot = M(pe), Bt = M(K), Ft = M(rt), Mt = M(ot), ye = M(null);
2678
2680
  St.current = oe, Nt.current = Y, At.current = it, It.current = mt, Ot.current = pe, Bt.current = K, Ft.current = rt, Mt.current = ot;
2679
- function ve(v) {
2681
+ function ve(y) {
2680
2682
  const d = Mt.current;
2681
- return d ? d.includes(v) : !0;
2683
+ return d ? d.includes(y) : !0;
2682
2684
  }
2683
- function be(v, d) {
2685
+ function be(y, d) {
2684
2686
  console.warn(
2685
- `[LiveLayer] Agent command "${v}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`
2687
+ `[LiveLayer] Agent command "${y}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`
2686
2688
  );
2687
2689
  }
2688
2690
  const dt = E(
2689
- (v) => {
2691
+ (y) => {
2690
2692
  var J, re, Le, ft;
2691
- const d = v;
2693
+ const d = y;
2692
2694
  if (!(!d.type || typeof d.type != "string")) {
2693
- if (Re == null || Re({ eventName: d.type, data: v }), d.type === "navigate") {
2695
+ if (Re == null || Re({ eventName: d.type, data: y }), d.type === "navigate") {
2694
2696
  if (!ve("navigate")) {
2695
2697
  be("navigate", "navigate");
2696
2698
  return;
@@ -3142,13 +3144,13 @@ const Li = /* @__PURE__ */ new Set([
3142
3144
  if ($ != null && $.subscribeToDataMessages)
3143
3145
  return $.subscribeToDataMessages(dt);
3144
3146
  }, [$, dt]), ye.current = () => {
3145
- var v;
3146
- return (v = ee.getRoom) == null ? void 0 : v.call(ee);
3147
+ var y;
3148
+ return (y = ee.getRoom) == null ? void 0 : y.call(ee);
3147
3149
  }, R(() => {
3148
3150
  var J;
3149
3151
  if (typeof window > "u") return;
3150
- const v = ((J = window.location) == null ? void 0 : J.hostname) || "";
3151
- if (v === "localhost" || v === "127.0.0.1" || v === "0.0.0.0" || v.endsWith(".local") || v.endsWith(".test"))
3152
+ const y = ((J = window.location) == null ? void 0 : J.hostname) || "";
3153
+ if (y === "localhost" || y === "127.0.0.1" || y === "0.0.0.0" || y.endsWith(".local") || y.endsWith(".test"))
3152
3154
  return window.__livelayerSimulateCommand = (re) => {
3153
3155
  try {
3154
3156
  dt(re);
@@ -3196,12 +3198,12 @@ const Li = /* @__PURE__ */ new Set([
3196
3198
  qt.current = $, Xn(
3197
3199
  r,
3198
3200
  () => ({
3199
- sendData: async (v) => {
3201
+ sendData: async (y) => {
3200
3202
  var Le, ft;
3201
3203
  const d = qt.current;
3202
3204
  if (d != null && d.publishData) {
3203
3205
  try {
3204
- await d.publishData(v);
3206
+ await d.publishData(y);
3205
3207
  } catch (k) {
3206
3208
  console.warn("[AvatarWidget] sendData (controlled) failed:", k);
3207
3209
  }
@@ -3210,7 +3212,7 @@ const Li = /* @__PURE__ */ new Set([
3210
3212
  const J = (ft = (Le = Wt.current) == null ? void 0 : Le.getRoom) == null ? void 0 : ft.call(Le), re = J == null ? void 0 : J.localParticipant;
3211
3213
  if (re != null && re.publishData)
3212
3214
  try {
3213
- const k = new TextEncoder().encode(JSON.stringify(v));
3215
+ const k = new TextEncoder().encode(JSON.stringify(y));
3214
3216
  await re.publishData(k, { reliable: !0 });
3215
3217
  } catch (k) {
3216
3218
  console.warn("[AvatarWidget] sendData failed:", k);
@@ -3221,27 +3223,27 @@ const Li = /* @__PURE__ */ new Set([
3221
3223
  );
3222
3224
  const Ut = M(null);
3223
3225
  R(() => {
3224
- const v = C.videoElement, d = Ut.current;
3225
- if (!(!v || !d))
3226
- return d.appendChild(v), () => {
3227
- v.parentNode === d && d.removeChild(v);
3226
+ const y = C.videoElement, d = Ut.current;
3227
+ if (!(!y || !d))
3228
+ return d.appendChild(y), () => {
3229
+ y.parentNode === d && d.removeChild(y);
3228
3230
  };
3229
3231
  }, [C.videoElement]), R(() => {
3230
- const v = C.audioElement;
3231
- if (!v) return;
3232
+ const y = C.audioElement;
3233
+ if (!y) return;
3232
3234
  const d = document.createElement("div");
3233
- d.className = "ll-audio-sink", d.setAttribute("aria-hidden", "true"), d.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;", d.appendChild(v), document.body.appendChild(d), Ee.attach(v);
3234
- const J = v.play();
3235
+ d.className = "ll-audio-sink", d.setAttribute("aria-hidden", "true"), d.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;", d.appendChild(y), document.body.appendChild(d), Ee.attach(y);
3236
+ const J = y.play();
3235
3237
  return J && typeof J.catch == "function" && J.catch((re) => {
3236
3238
  (re == null ? void 0 : re.name) === "NotAllowedError" && Ge(!0);
3237
3239
  }), () => {
3238
- Ee.detach(), v.parentNode === d && d.removeChild(v), d.parentNode === document.body && document.body.removeChild(d);
3240
+ Ee.detach(), y.parentNode === d && d.removeChild(y), d.parentNode === document.body && document.body.removeChild(d);
3239
3241
  };
3240
3242
  }, [C.audioElement]), R(() => {
3241
3243
  if (C.isControlled || C.connectionState !== "connected") return;
3242
- const v = C.getRoom();
3243
- if (v)
3244
- return ae.setupMic(v).then(() => {
3244
+ const y = C.getRoom();
3245
+ if (y)
3246
+ return ae.setupMic(y).then(() => {
3245
3247
  const d = ae.getMicStream();
3246
3248
  d && Ee.attachStream(d, "mic");
3247
3249
  }).catch(() => {
@@ -3251,17 +3253,17 @@ const Li = /* @__PURE__ */ new Set([
3251
3253
  }, [C.isControlled, C.connectionState]), R(() => {
3252
3254
  var d;
3253
3255
  if (C.connectionState !== "connected") return;
3254
- const v = C.isControlled ? (d = $ == null ? void 0 : $.getRoom) == null ? void 0 : d.call($) : C.getRoom();
3255
- if (v)
3256
- return me.attachRoom(v), ze.attachRoom(v), C.isControlled && ae.attachRoom(v), ge.refresh(), () => {
3256
+ const y = C.isControlled ? (d = $ == null ? void 0 : $.getRoom) == null ? void 0 : d.call($) : C.getRoom();
3257
+ if (y)
3258
+ return me.attachRoom(y), ze.attachRoom(y), C.isControlled && ae.attachRoom(y), ge.refresh(), () => {
3257
3259
  me.teardown(), ze.teardown();
3258
3260
  };
3259
3261
  }, [C.isControlled, C.connectionState, $]), R(() => {
3260
- const v = C.audioElement;
3261
- v && (v.muted = Et);
3262
+ const y = C.audioElement;
3263
+ y && (y.muted = Et);
3262
3264
  }, [C.audioElement, Et]);
3263
- const $n = E((v) => {
3264
- const d = { type: "user_message", text: v };
3265
+ const $n = E((y) => {
3266
+ const d = { type: "user_message", text: y };
3265
3267
  if ($ != null && $.publishData) {
3266
3268
  try {
3267
3269
  $.publishData(d);
@@ -3277,7 +3279,7 @@ const Li = /* @__PURE__ */ new Set([
3277
3279
  } catch {
3278
3280
  }
3279
3281
  }, [C, $]), zn = E(() => {
3280
- Pn((v) => !v);
3282
+ Pn((y) => !y);
3281
3283
  }, []);
3282
3284
  R(() => {
3283
3285
  Me == null || Me(C.connectionState), C.connectionState === "connected" ? Ae == null || Ae() : C.connectionState === "disconnected" && (Fe == null || Fe());
@@ -3293,9 +3295,9 @@ const Li = /* @__PURE__ */ new Set([
3293
3295
  !w || jt.current || lt && C.connectionState === "idle" && (jt.current = !0, C.connect());
3294
3296
  }, [w, C.connectionState, C, lt]);
3295
3297
  const Hn = E(
3296
- (v) => {
3297
- const d = L == null ? void 0 : L.find((J) => J.id === v);
3298
- d && (g(!1), v !== ke && (gt(!0), C.disconnect(), $e || kt(v), I == null || I(d)));
3298
+ (y) => {
3299
+ const d = L == null ? void 0 : L.find((J) => J.id === y);
3300
+ d && (g(!1), y !== ke && (gt(!0), C.disconnect(), $e || kt(y), I == null || I(d)));
3299
3301
  },
3300
3302
  [
3301
3303
  L,
@@ -3309,10 +3311,10 @@ const Li = /* @__PURE__ */ new Set([
3309
3311
  Ke && C.connectionState === "connected" && gt(!1);
3310
3312
  }, [C.connectionState, Ke]), R(() => {
3311
3313
  if (!Je) return;
3312
- const v = (d) => {
3314
+ const y = (d) => {
3313
3315
  d.key === "Escape" && g(!1);
3314
3316
  };
3315
- return window.addEventListener("keydown", v), () => window.removeEventListener("keydown", v);
3317
+ return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
3316
3318
  }, [Je]);
3317
3319
  const On = !!P || !!(le != null && le.avatarImageUrl) || C.isControlled, ut = fr(at, o, On);
3318
3320
  ot === void 0 && ((Kt = ut.info) != null && Kt.capabilities) && (Mt.current = ut.info.capabilities);
@@ -3322,8 +3324,8 @@ const Li = /* @__PURE__ */ new Set([
3322
3324
  ), Vt = E(() => {
3323
3325
  C.disconnect(), xe("hidden");
3324
3326
  }, [C, xe]), Un = E(() => {
3325
- const v = C.audioElement;
3326
- v && v.play().then(() => Ge(!1)).catch(() => {
3327
+ const y = C.audioElement;
3328
+ y && y.play().then(() => Ge(!1)).catch(() => {
3327
3329
  });
3328
3330
  }, [C.audioElement]), jn = E(() => {
3329
3331
  Ge(!1), C.connect();
@@ -3361,7 +3363,7 @@ const Li = /* @__PURE__ */ new Set([
3361
3363
  currentTeamMemberId: ke,
3362
3364
  isSwitchingTeamMember: Ke,
3363
3365
  teamSwitcherOpen: Je,
3364
- onToggleTeamSwitcher: () => g((v) => !v),
3366
+ onToggleTeamSwitcher: () => g((y) => !y),
3365
3367
  onSelectTeamMember: Hn,
3366
3368
  connectionState: C.connectionState,
3367
3369
  agentState: C.agentState,
@@ -3386,7 +3388,7 @@ const Li = /* @__PURE__ */ new Set([
3386
3388
  transforming: Be,
3387
3389
  transformingLabel: X,
3388
3390
  languageMenuOpen: Q,
3389
- onToggleLanguageMenu: () => Dn((v) => !v),
3391
+ onToggleLanguageMenu: () => Dn((y) => !y),
3390
3392
  needsUserGesture: Se,
3391
3393
  canResume: C.canResume,
3392
3394
  micError: ae.micError,
@@ -3398,9 +3400,9 @@ const Li = /* @__PURE__ */ new Set([
3398
3400
  onRetry: jn,
3399
3401
  onResumeAudio: Un,
3400
3402
  onToggleMute: ae.toggleMute,
3401
- onSwitchMicDevice: (v) => void ae.switchDevice(v),
3403
+ onSwitchMicDevice: (y) => void ae.switchDevice(y),
3402
3404
  onToggleCamera: () => void me.toggle(),
3403
- onSwitchCameraDevice: (v) => void me.switchDevice(v),
3405
+ onSwitchCameraDevice: (y) => void me.switchDevice(y),
3404
3406
  onToggleScreenShare: () => void ze.toggle(),
3405
3407
  onToggleSpeaker: zn,
3406
3408
  onSendMessage: $n,
@@ -3518,9 +3520,9 @@ function zi(e = {}) {
3518
3520
  }, []);
3519
3521
  return R(() => {
3520
3522
  if (typeof window > "u") return;
3521
- const _ = (y) => {
3523
+ const _ = (v) => {
3522
3524
  var h, L;
3523
- const u = y.detail;
3525
+ const u = v.detail;
3524
3526
  if (u) {
3525
3527
  if (u.phase === "field") {
3526
3528
  if (f.current !== "all" && u.source !== f.current)
@@ -3640,7 +3642,7 @@ function Hi({
3640
3642
  children: "🛰 LL debug"
3641
3643
  }
3642
3644
  );
3643
- const y = o.filter((u) => {
3645
+ const v = o.filter((u) => {
3644
3646
  if (!l) return !0;
3645
3647
  const h = l.toLowerCase();
3646
3648
  return u.type.toLowerCase().includes(h) || JSON.stringify(u.data || {}).toLowerCase().includes(h);
@@ -3749,7 +3751,7 @@ function Hi({
3749
3751
  overflowY: "auto",
3750
3752
  padding: "0 8px 8px"
3751
3753
  },
3752
- children: y.length === 0 ? /* @__PURE__ */ x(
3754
+ children: v.length === 0 ? /* @__PURE__ */ x(
3753
3755
  "div",
3754
3756
  {
3755
3757
  style: {
@@ -3779,7 +3781,7 @@ function Hi({
3779
3781
  )
3780
3782
  ]
3781
3783
  }
3782
- ) : y.map((u) => /* @__PURE__ */ n(
3784
+ ) : v.map((u) => /* @__PURE__ */ n(
3783
3785
  Ci,
3784
3786
  {
3785
3787
  entry: u,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livelayer/react",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "description": "LiveLayer agent widget for React — avatar video, team switching, responsive layouts, full-fidelity embed",
5
5
  "keywords": [
6
6
  "livelayer",